35#include "pg_config_paths.h"
43#define _WIN32_IE 0x0500
69#define LDAP_DEPRECATED 1
71typedef struct timeval LDAP_TIMEVAL;
78#define PGPASSFILE ".pgpass"
80#define PGPASSFILE "pgpass.conf"
89#define ERRCODE_APPNAME_UNKNOWN "42704"
92#define ERRCODE_INVALID_PASSWORD "28P01"
94#define ERRCODE_CANNOT_CONNECT_NOW "57P03"
100#if defined(TCP_KEEPIDLE)
102#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPIDLE
103#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPIDLE"
104#elif defined(TCP_KEEPALIVE_THRESHOLD)
106#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE_THRESHOLD
107#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE_THRESHOLD"
108#elif defined(TCP_KEEPALIVE) && defined(__darwin__)
111#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE
112#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE"
119#define DefaultHost "localhost"
120#define DefaultOption ""
122#define DefaultChannelBinding "prefer"
124#define DefaultChannelBinding "disable"
126#define DefaultTargetSessionAttrs "any"
127#define DefaultLoadBalanceHosts "disable"
129#define DefaultSSLMode "prefer"
130#define DefaultSSLCertMode "allow"
132#define DefaultSSLMode "disable"
133#define DefaultSSLCertMode "disable"
135#define DefaultSSLNegotiation "postgres"
138#define DefaultGSSMode "prefer"
140#define DefaultGSSMode "disable"
200 {
"service",
"PGSERVICE", NULL, NULL,
201 "Database-Service",
"", 20,
202 offsetof(
struct pg_conn, pgservice)},
204 {
"servicefile",
"PGSERVICEFILE", NULL, NULL,
205 "Database-Service-File",
"", 64,
206 offsetof(
struct pg_conn, pgservicefile)},
208 {
"user",
"PGUSER", NULL, NULL,
209 "Database-User",
"", 20,
210 offsetof(
struct pg_conn, pguser)},
212 {
"password",
"PGPASSWORD", NULL, NULL,
213 "Database-Password",
"*", 20,
214 offsetof(
struct pg_conn, pgpass)},
216 {
"passfile",
"PGPASSFILE", NULL, NULL,
217 "Database-Password-File",
"", 64,
218 offsetof(
struct pg_conn, pgpassfile)},
221 "Channel-Binding",
"", 8,
222 offsetof(
struct pg_conn, channel_binding)},
224 {
"connect_timeout",
"PGCONNECT_TIMEOUT", NULL, NULL,
225 "Connect-timeout",
"", 10,
226 offsetof(
struct pg_conn, connect_timeout)},
228 {
"dbname",
"PGDATABASE", NULL, NULL,
229 "Database-Name",
"", 20,
232 {
"host",
"PGHOST", NULL, NULL,
233 "Database-Host",
"", 40,
236 {
"hostaddr",
"PGHOSTADDR", NULL, NULL,
237 "Database-Host-IP-Address",
"", 45,
238 offsetof(
struct pg_conn, pghostaddr)},
240 {
"port",
"PGPORT", DEF_PGPORT_STR, NULL,
241 "Database-Port",
"", 6,
244 {
"client_encoding",
"PGCLIENTENCODING", NULL, NULL,
245 "Client-Encoding",
"", 10,
246 offsetof(
struct pg_conn, client_encoding_initial)},
249 "Backend-Options",
"", 40,
250 offsetof(
struct pg_conn, pgoptions)},
252 {
"application_name",
"PGAPPNAME", NULL, NULL,
253 "Application-Name",
"", 64,
254 offsetof(
struct pg_conn, appname)},
256 {
"fallback_application_name", NULL, NULL, NULL,
257 "Fallback-Application-Name",
"", 64,
258 offsetof(
struct pg_conn, fbappname)},
260 {
"keepalives", NULL, NULL, NULL,
261 "TCP-Keepalives",
"", 1,
262 offsetof(
struct pg_conn, keepalives)},
264 {
"keepalives_idle", NULL, NULL, NULL,
265 "TCP-Keepalives-Idle",
"", 10,
266 offsetof(
struct pg_conn, keepalives_idle)},
268 {
"keepalives_interval", NULL, NULL, NULL,
269 "TCP-Keepalives-Interval",
"", 10,
270 offsetof(
struct pg_conn, keepalives_interval)},
272 {
"keepalives_count", NULL, NULL, NULL,
273 "TCP-Keepalives-Count",
"", 10,
274 offsetof(
struct pg_conn, keepalives_count)},
276 {
"tcp_user_timeout", NULL, NULL, NULL,
277 "TCP-User-Timeout",
"", 10,
278 offsetof(
struct pg_conn, pgtcp_user_timeout)},
288 offsetof(
struct pg_conn, sslmode)},
291 "SSL-Negotiation",
"", 9,
292 offsetof(
struct pg_conn, sslnegotiation)},
294 {
"sslcompression",
"PGSSLCOMPRESSION",
"0", NULL,
295 "SSL-Compression",
"", 1,
296 offsetof(
struct pg_conn, sslcompression)},
298 {
"sslcert",
"PGSSLCERT", NULL, NULL,
299 "SSL-Client-Cert",
"", 64,
300 offsetof(
struct pg_conn, sslcert)},
302 {
"sslkey",
"PGSSLKEY", NULL, NULL,
303 "SSL-Client-Key",
"", 64,
304 offsetof(
struct pg_conn, sslkey)},
306 {
"sslcertmode",
"PGSSLCERTMODE", NULL, NULL,
307 "SSL-Client-Cert-Mode",
"", 8,
308 offsetof(
struct pg_conn, sslcertmode)},
310 {
"sslpassword", NULL, NULL, NULL,
311 "SSL-Client-Key-Password",
"*", 20,
312 offsetof(
struct pg_conn, sslpassword)},
314 {
"sslrootcert",
"PGSSLROOTCERT", NULL, NULL,
315 "SSL-Root-Certificate",
"", 64,
316 offsetof(
struct pg_conn, sslrootcert)},
318 {
"sslcrl",
"PGSSLCRL", NULL, NULL,
319 "SSL-Revocation-List",
"", 64,
320 offsetof(
struct pg_conn, sslcrl)},
322 {
"sslcrldir",
"PGSSLCRLDIR", NULL, NULL,
323 "SSL-Revocation-List-Dir",
"", 64,
324 offsetof(
struct pg_conn, sslcrldir)},
326 {
"sslsni",
"PGSSLSNI",
"1", NULL,
328 offsetof(
struct pg_conn, sslsni)},
330 {
"requirepeer",
"PGREQUIREPEER", NULL, NULL,
331 "Require-Peer",
"", 10,
332 offsetof(
struct pg_conn, requirepeer)},
334 {
"require_auth",
"PGREQUIREAUTH", NULL, NULL,
335 "Require-Auth",
"", 14,
336 offsetof(
struct pg_conn, require_auth)},
338 {
"min_protocol_version",
"PGMINPROTOCOLVERSION",
340 "Min-Protocol-Version",
"", 6,
341 offsetof(
struct pg_conn, min_protocol_version)},
343 {
"max_protocol_version",
"PGMAXPROTOCOLVERSION",
345 "Max-Protocol-Version",
"", 6,
346 offsetof(
struct pg_conn, max_protocol_version)},
348 {
"ssl_min_protocol_version",
"PGSSLMINPROTOCOLVERSION",
"TLSv1.2", NULL,
349 "SSL-Minimum-Protocol-Version",
"", 8,
352 {
"ssl_max_protocol_version",
"PGSSLMAXPROTOCOLVERSION", NULL, NULL,
353 "SSL-Maximum-Protocol-Version",
"", 8,
361 "GSSENC-Mode",
"", 8,
362 offsetof(
struct pg_conn, gssencmode)},
365 {
"krbsrvname",
"PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
366 "Kerberos-service-name",
"", 20,
367 offsetof(
struct pg_conn, krbsrvname)},
369 {
"gsslib",
"PGGSSLIB", NULL, NULL,
370 "GSS-library",
"", 7,
371 offsetof(
struct pg_conn, gsslib)},
373 {
"gssdelegation",
"PGGSSDELEGATION",
"0", NULL,
374 "GSS-delegation",
"", 1,
375 offsetof(
struct pg_conn, gssdelegation)},
377 {
"replication", NULL, NULL, NULL,
378 "Replication",
"D", 5,
379 offsetof(
struct pg_conn, replication)},
381 {
"target_session_attrs",
"PGTARGETSESSIONATTRS",
383 "Target-Session-Attrs",
"", 15,
384 offsetof(
struct pg_conn, target_session_attrs)},
386 {
"load_balance_hosts",
"PGLOADBALANCEHOSTS",
388 "Load-Balance-Hosts",
"", 8,
389 offsetof(
struct pg_conn, load_balance_hosts)},
391 {
"scram_client_key", NULL, NULL, NULL,
"SCRAM-Client-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
392 offsetof(
struct pg_conn, scram_client_key)},
394 {
"scram_server_key", NULL, NULL, NULL,
"SCRAM-Server-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
395 offsetof(
struct pg_conn, scram_server_key)},
398 {
"oauth_issuer", NULL, NULL, NULL,
399 "OAuth-Issuer",
"", 40,
400 offsetof(
struct pg_conn, oauth_issuer)},
402 {
"oauth_client_id", NULL, NULL, NULL,
403 "OAuth-Client-ID",
"", 40,
404 offsetof(
struct pg_conn, oauth_client_id)},
406 {
"oauth_client_secret", NULL, NULL, NULL,
407 "OAuth-Client-Secret",
"*", 40,
408 offsetof(
struct pg_conn, oauth_client_secret)},
410 {
"oauth_scope", NULL, NULL, NULL,
411 "OAuth-Scope",
"", 15,
412 offsetof(
struct pg_conn, oauth_scope)},
414 {
"sslkeylogfile", NULL, NULL, NULL,
415 "SSL-Key-Log-File",
"D", 64,
416 offsetof(
struct pg_conn, sslkeylogfile)},
419 {NULL, NULL, NULL, NULL,
427 "PGDATESTYLE",
"datestyle"
446#define SASL_MECHANISM_COUNT lengthof(supported_sasl_mechs)
454#if defined(USE_SSL) || defined(ENABLE_GSS)
455static int encryption_negotiation_failed(
PGconn *
conn);
475 bool use_defaults,
int expand_dbname);
488 const char *keyword);
490 const char *keyword,
const char *
value,
491 PQExpBuffer errorMessage,
bool ignoreMissing,
bool uri_decode);
493 const char *keyword);
505 const char *
username,
const char *pgpassfile);
571 if (
conn->gcred != GSS_C_NO_CREDENTIAL)
573 gss_release_cred(&min_s, &
conn->gcred);
574 conn->gcred = GSS_C_NO_CREDENTIAL;
577 gss_delete_sec_context(&min_s, &
conn->gctx, GSS_C_NO_BUFFER);
579 gss_release_name(&min_s, &
conn->gtarg_nam);
580 if (
conn->gss_SendBuffer)
583 conn->gss_SendBuffer = NULL;
585 if (
conn->gss_RecvBuffer)
588 conn->gss_RecvBuffer = NULL;
590 if (
conn->gss_ResultBuffer)
593 conn->gss_ResultBuffer = NULL;
595 conn->gssenc =
false;
599 if (
conn->sspitarget)
602 conn->sspitarget = NULL;
606 FreeCredentialsHandle(
conn->sspicred);
608 conn->sspicred = NULL;
612 DeleteSecurityContext(
conn->sspictx);
614 conn->sspictx = NULL;
632 while (queue != NULL)
663 while (notify != NULL)
667 notify = notify->
next;
674 while (pstatus != NULL)
678 pstatus = pstatus->
next;
769 const char *
const *
values,
787 const char *
const *
values,
871 const char *
const *
values,
891 true, expand_dbname);
892 if (connOptions == NULL)
1003 if (
option->connofs >= 0)
1009 char **connmember = (
char **) ((
char *)
conn +
option->connofs);
1012 *connmember = strdup(tmp);
1013 if (*connmember == NULL)
1042 if (
option->connofs >= 0)
1044 const char **tmp = (
const char **) ((
char *) srcConn +
option->connofs);
1048 char **dstConnmember = (
char **) ((
char *) dstConn +
option->connofs);
1051 free(*dstConnmember);
1052 *dstConnmember = strdup(*tmp);
1053 if (*dstConnmember == NULL)
1084 if (connOptions == NULL)
1140 char *s = *startptr;
1149 while (*
e !=
'\0' && *
e !=
',')
1151 *more = (*
e ==
',');
1154 p = (
char *)
malloc(
sizeof(
char) * (
len + 1));
1175 struct timeval tval = {0};
1182 rseed = ((uintptr_t)
conn) ^
1184 ((
uint64) tval.tv_usec) ^
1209 "conn->allowed_sasl_mechs[] is not sufficiently large for holding all supported SASL mechanisms");
1328 else if (ch->
host != NULL && ch->
host[0] !=
'\0')
1352 if (ch->
host == NULL)
1380 if (
i == 1 && !more)
1458 if (pwhost == NULL || pwhost[0] ==
'\0')
1479 bool negated =
false;
1489 for (first =
true, more =
true; more; first =
false)
1544 if (strcmp(method,
"password") == 0)
1548 else if (strcmp(method,
"md5") == 0)
1552 else if (strcmp(method,
"gss") == 0)
1557 else if (strcmp(method,
"sspi") == 0)
1569 else if (strcmp(method,
"scram-sha-256") == 0)
1573 else if (strcmp(method,
"oauth") == 0)
1581 else if (strcmp(method,
"none") == 0)
1610 "require_auth", method);
1651 "internal error: no space in allowed_sasl_mechs");
1702 bool allowed =
false;
1721 if (!negated && allowed)
1723 else if (negated && !allowed)
1852 libpq_append_conn_error(
conn,
"weak sslmode \"%s\" may not be used with sslnegotiation=direct (use \"require\", \"verify-ca\", or \"verify-full\")",
1888 "ssl_min_protocol_version",
1896 "ssl_max_protocol_version",
1939#ifndef HAVE_SSL_CTX_SET_CERT_CB
2013 "target_session_attrs",
2080 "load_balance_hosts",
2207 if (connOptions != NULL)
2235 const char *pgtty,
const char *
dbName,
const char *login,
2297 if (pgoptions && pgoptions[0] !=
'\0')
2305 if (login && login[0] !=
'\0')
2313 if (pwd && pwd[0] !=
'\0')
2354 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_NODELAY,
2379 if (addr->ss_family == AF_INET)
2382 &((
struct sockaddr_in *) addr)->sin_addr.s_addr,
2384 host_addr, host_addr_len) == NULL)
2385 host_addr[0] =
'\0';
2387 else if (addr->ss_family == AF_INET6)
2390 &((
struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
2392 host_addr, host_addr_len) == NULL)
2393 host_addr[0] =
'\0';
2396 host_addr[0] =
'\0';
2412 char service[NI_MAXHOST];
2416 service,
sizeof(service),
2419 libpq_gettext(
"connection to server on socket \"%s\" failed: "),
2424 const char *displayed_host;
2425 const char *displayed_port;
2433 if (displayed_port == NULL || displayed_port[0] ==
'\0')
2434 displayed_port = DEF_PGPORT_STR;
2443 strcmp(displayed_host, host_addr) != 0)
2445 libpq_gettext(
"connection to server at \"%s\" (%s), port %s failed: "),
2446 displayed_host, host_addr,
2450 libpq_gettext(
"connection to server at \"%s\", port %s failed: "),
2494 return val != 0 ? 1 : 0;
2515#ifdef PG_TCP_KEEPALIVE_IDLE
2516 if (setsockopt(
conn->
sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
2517 (
char *) &idle,
sizeof(idle)) < 0)
2523 PG_TCP_KEEPALIVE_IDLE_STR,
2544 "keepalives_interval"))
2550 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPINTVL,
2579 "keepalives_count"))
2585 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPCNT,
2586 (
char *) &count,
sizeof(count)) < 0)
2601#ifdef SIO_KEEPALIVE_VALS
2611 struct tcp_keepalive ka;
2620 ka.keepalivetime = idle * 1000;
2621 ka.keepaliveinterval =
interval * 1000;
2649 "keepalives_interval"))
2655 "WSAIoctl",
"SIO_KEEPALIVE_VALS",
2676 "tcp_user_timeout"))
2682#ifdef TCP_USER_TIMEOUT
2683 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
2684 (
char *) &timeout,
sizeof(timeout)) < 0)
2713 goto connect_errReturn;
2724 "libpq is incorrectly linked to backend functions\n");
2725 goto connect_errReturn;
2790 int last_whichhost = -2;
2791 int last_whichaddr = -2;
2913 bool reset_connection_state_machine =
false;
2914 bool need_new_connection =
false;
2980 reset_connection_state_machine =
true;
2991 struct addrinfo hint;
2992 struct addrinfo *addrlist;
3035 MemSet(&hint, 0,
sizeof(hint));
3036 hint.ai_socktype = SOCK_STREAM;
3037 hint.ai_family = AF_UNSPEC;
3040 if (ch->
port == NULL || ch->
port[0] ==
'\0')
3041 thisport = DEF_PGPORT;
3047 if (thisport < 1 || thisport > 65535)
3061 if (ret || !addrlist)
3070 hint.ai_flags = AI_NUMERICHOST;
3073 if (ret || !addrlist)
3082 hint.ai_family = AF_UNIX;
3098 if (ret || !addrlist)
3142 reset_connection_state_machine =
true;
3147 if (reset_connection_state_machine)
3160 reset_connection_state_machine =
false;
3161 need_new_connection =
true;
3165 if (need_new_connection)
3182 need_new_connection =
false;
3190#define ENCRYPTION_NEGOTIATION_FAILED(msg) \
3192 switch (encryption_negotiation_failed(conn)) \
3195 libpq_append_conn_error(conn, (msg)); \
3196 goto error_return; \
3198 conn->status = CONNECTION_MADE; \
3199 return PGRES_POLLING_WRITING; \
3201 need_new_connection = true; \
3211#define CONNECTION_FAILED() \
3213 if (connection_failed(conn)) \
3215 need_new_connection = true; \
3219 goto error_return; \
3236 char host_addr[NI_MAXHOST];
3266 "GSSAPI encryption required but it is not supported over a local socket");
3269 if (
conn->gcred == GSS_C_NO_CREDENTIAL)
3274 "GSSAPI encryption required but no credential cache");
3305 sock_type = SOCK_STREAM;
3314 sock_type |= SOCK_CLOEXEC;
3322 sock_type |= SOCK_NONBLOCK;
3361 if (addr_cur->
family != AF_UNIX)
3370#ifndef SOCK_NONBLOCK
3382 if (fcntl(
conn->
sock, F_SETFD, FD_CLOEXEC) == -1)
3392 if (addr_cur->
family != AF_UNIX)
3400 if (usekeepalives < 0)
3405 else if (usekeepalives == 0)
3411 SOL_SOCKET, SO_KEEPALIVE,
3412 (
char *) &on,
sizeof(on)) < 0)
3425#ifdef SIO_KEEPALIVE_VALS
3426 else if (!prepKeepalivesWin32(
conn))
3472 if (setsockopt(
conn->
sock, SOL_SOCKET, SO_NOSIGPIPE,
3473 (
char *) &optval,
sizeof(optval)) == 0)
3538 if (getsockopt(
conn->
sock, SOL_SOCKET, SO_ERROR,
3539 (
char *) &optval, &optlen) == -1)
3545 else if (optval != 0)
3581 char *remote_username;
3593 if (errno == ENOSYS)
3604 if (remote_username == NULL)
3611 free(remote_username);
3614 free(remote_username);
3802 else if (SSLok ==
'N')
3817 else if (SSLok ==
'E')
3891 else if (rdresult == 0)
3933 else if (gss_ok !=
'G')
4044 (msgLength < 8 || msgLength > 2000))
4050 (msgLength < 8 || msgLength > 2000))
4056#define MAX_ERRLEN 30000
4106 if (avail < msgLength)
4217 need_new_connection =
true;
4257 "internal error: async authentication has no handler");
4282 "internal error: async cleanup did not release polling socket");
4305 "internal error: async authentication did not set a socket for polling");
4352 const char *sqlstate;
4360 need_new_connection =
true;
4392 bool read_only_server;
4412 "SHOW transaction_read_only"))
4425 read_only_server : !read_only_server)
4470 "SELECT pg_catalog.pg_is_in_recovery()"))
4590 if (strncmp(
val,
"on", 2) == 0)
4612 "SHOW transaction_read_only");
4646 if (strncmp(
val,
"t", 1) == 0)
4662 "SELECT pg_is_in_recovery()");
4675 "invalid connection state %d, probably indicative of memory corruption",
4713 "GSSAPI encryption required but it is not supported over a local socket");
4762#if defined(USE_SSL) || defined(ENABLE_GSS)
4806 int remaining_methods;
4808#define SELECT_NEXT_METHOD(method) \
4810 if ((remaining_methods & method) != 0) \
4812 conn->current_enc_method = method; \
4837 remaining_methods &= ~ENC_GSSAPI;
4842 "GSSAPI encryption required but no credential cache");
4869#undef SELECT_NEXT_METHOD
4956 static bool wsastartup_done =
false;
4958 if (!wsastartup_done)
4962 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
4964 wsastartup_done =
true;
5173 struct addrinfo *ai = addrlist;
5414 const void *
buf,
size_t buf_len)
5437#define LDAP_URL "ldap://"
5438#define LDAP_DEF_PORT 389
5439#define PGLDAP_TIMEOUT 2
5441#define ld_is_sp_tab(x) ((x) == ' ' || (x) == '\t')
5442#define ld_is_nl_cr(x) ((x) == '\r' || (x) == '\n')
5468 int port = LDAP_DEF_PORT,
5491 char *attrs[2] = {NULL, NULL};
5496 LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0};
5497 int ldapversion = LDAP_VERSION3;
5499 if ((url = strdup(purl)) == NULL)
5514 "invalid LDAP URL \"%s\": scheme must be ldap://", purl);
5525 p = strchr(url + strlen(LDAP_URL),
'/');
5526 if (p == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5529 "invalid LDAP URL \"%s\": missing distinguished name",
5538 if ((p = strchr(dn,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5541 "invalid LDAP URL \"%s\": must have exactly one attribute",
5550 if ((p = strchr(attrs[0],
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5553 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5562 if ((p = strchr(scopestr,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5565 "invalid LDAP URL \"%s\": no filter",
5572 if ((p = strchr(filter,
'?')) != NULL)
5576 if ((p1 = strchr(
hostname,
':')) != NULL)
5583 lport = strtol(
portstr, &endptr, 10);
5584 if (*
portstr ==
'\0' || *endptr !=
'\0' || errno || lport < 0 || lport > 65535)
5587 "invalid LDAP URL \"%s\": invalid port number",
5596 if (strchr(attrs[0],
',') != NULL)
5599 "invalid LDAP URL \"%s\": must have exactly one attribute",
5607 scope = LDAP_SCOPE_BASE;
5609 scope = LDAP_SCOPE_ONELEVEL;
5611 scope = LDAP_SCOPE_SUBTREE;
5615 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5629 if ((rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldapversion)) != LDAP_SUCCESS)
5632 ldap_err2string(rc));
5652 if (ldap_connect(ld, &time) != LDAP_SUCCESS)
5661 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5669 if ((msgid = ldap_simple_bind(ld, NULL, NULL)) == -1)
5679 if ((rc = ldap_result(ld, msgid, LDAP_MSG_ALL, &time, &res)) == -1 ||
5693 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5703 if ((rc = ldap_search_st(ld, dn, scope, filter, attrs, 0, &time, &res))
5708 libpq_append_error(errorMessage,
"lookup on LDAP server failed: %s", ldap_err2string(rc));
5715 if ((rc = ldap_count_entries(ld, res)) != 1)
5728 if ((entry = ldap_first_entry(ld, res)) == NULL)
5739 if ((
values = ldap_get_values_len(ld, entry, attrs[0])) == NULL)
5754 ldap_value_free_len(
values);
5762 size +=
values[
i]->bv_len + 1;
5763 if ((result =
malloc(size)) == NULL)
5766 ldap_value_free_len(
values);
5779 ldap_value_free_len(
values);
5783 oldstate =
state = 0;
5784 for (p = result; *p !=
'\0'; ++p)
5789 if (!ld_is_sp_tab(*p) && !ld_is_nl_cr(*p))
5796 if (ld_is_sp_tab(*p))
5801 else if (ld_is_nl_cr(*p))
5804 "missing \"=\" after \"%s\" in connection info string",
5820 else if (!ld_is_sp_tab(*p))
5823 "missing \"=\" after \"%s\" in connection info string",
5836 else if (ld_is_nl_cr(*p))
5838 optval = optname + strlen(optname);
5841 else if (!ld_is_sp_tab(*p))
5848 if (ld_is_sp_tab(*p) || ld_is_nl_cr(*p))
5860 else if (*p ==
'\\')
5871 if (
state == 0 && oldstate != 0)
5873 found_keyword =
false;
5876 if (strcmp(
options[
i].keyword, optname) == 0)
5888 found_keyword =
true;
5909 "unterminated quoted string in connection info string");
5935 bool group_found =
false;
5937 struct stat stat_buf;
5944 if (service == NULL)
5945 service = getenv(
"PGSERVICE");
5948 if (service == NULL)
5956 if (service_fname != NULL)
5957 strlcpy(serviceFile, service_fname,
sizeof(serviceFile));
5958 else if ((env = getenv(
"PGSERVICEFILE")) != NULL)
5959 strlcpy(serviceFile, env,
sizeof(serviceFile));
5967 if (
stat(serviceFile, &stat_buf) != 0)
5972 if (group_found || status != 0)
5982 getenv(
"PGSYSCONFDIR") ? getenv(
"PGSYSCONFDIR") : SYSCONFDIR);
5983 if (
stat(serviceFile, &stat_buf) != 0)
6002 const char *service,
6014 *group_found =
false;
6016 f = fopen(serviceFile,
"r");
6023 while ((line = fgets(
buf,
sizeof(
buf), f)) != NULL)
6029 if (strlen(line) >=
sizeof(
buf) - 1)
6032 "line %d too long in service file \"%s\"",
6041 while (
len > 0 && isspace((
unsigned char) line[
len - 1]))
6045 while (*line && isspace((
unsigned char) line[0]))
6049 if (line[0] ==
'\0' || line[0] ==
'#')
6061 if (strncmp(line + 1, service, strlen(service)) == 0 &&
6062 line[strlen(service) + 1] ==
']')
6063 *group_found =
true;
6065 *group_found =
false;
6079 if (strncmp(line,
"ldap", 4) == 0)
6081 int rc = ldapServiceLookup(line,
options, errorMessage);
6099 val = strchr(line,
'=');
6103 "syntax error in service file \"%s\", line %d",
6111 if (strcmp(
key,
"service") == 0)
6114 "nested \"service\" specifications not supported in service file \"%s\", line %d",
6121 if (strcmp(
key,
"servicefile") == 0)
6124 "nested \"servicefile\" specifications not supported in service file \"%s\", line %d",
6135 found_keyword =
false;
6148 found_keyword =
true;
6156 "syntax error in service file \"%s\", line %d",
6173 if (*group_found && result == 0)
6177 if (strcmp(
options[
i].keyword,
"servicefile") != 0)
6184 options[
i].val = strdup(serviceFile);
6227 if (connOptions == NULL &&
errmsg)
6347 if ((
buf = strdup(conninfo)) == NULL)
6358 if (isspace((
unsigned char) *cp))
6370 if (isspace((
unsigned char) *cp))
6375 if (!isspace((
unsigned char) *cp))
6388 "missing \"=\" after \"%s\" in connection info string",
6399 if (!isspace((
unsigned char) *cp))
6412 if (isspace((
unsigned char) *cp))
6436 libpq_append_error(errorMessage,
"unterminated quoted string in connection info string");
6523 const char *pvalue =
values[
i];
6526 if (strcmp(pname,
"dbname") == 0 && pvalue)
6536 if (dbname_options == NULL)
6557 const char *pvalue =
values[
i];
6559 if (pvalue != NULL && pvalue[0] !=
'\0')
6564 if (strcmp(
option->keyword, pname) == 0)
6569 if (
option->keyword == NULL)
6582 if (strcmp(pname,
"dbname") == 0 && dbname_options)
6586 for (str_option = dbname_options; str_option->
keyword != NULL; str_option++)
6588 if (str_option->
val != NULL)
6592 for (k = 0;
options[k].keyword; k++)
6616 dbname_options = NULL;
6669 *sslrootcert = NULL;
6686 if (strcmp(
option->keyword,
"sslrootcert") == 0)
6695 if (
option->envvar != NULL)
6697 if ((tmp = getenv(
option->envvar)) != NULL)
6716 if (strcmp(
option->keyword,
"sslmode") == 0)
6718 const char *requiresslenv = getenv(
"PGREQUIRESSL");
6720 if (requiresslenv != NULL && requiresslenv[0] ==
'1')
6737 sslmode_default =
option;
6744 if (
option->compiled != NULL)
6763 if (strcmp(
option->keyword,
"user") == 0)
6775 if (sslmode_default && sslrootcert)
6777 if (sslrootcert->val && strcmp(sslrootcert->val,
"system") == 0)
6781 sslmode_default->
val = strdup(
"verify-full");
6782 if (!sslmode_default->
val)
6860 char prevchar =
'\0';
6863 bool retval =
false;
6886 if (prefix_len == 0)
6890 "invalid URI propagated to internal parser routine: \"%s\"",
6894 start += prefix_len;
6898 while (*p && *p !=
'@' && *p !=
'/')
6909 while (*p !=
':' && *p !=
'@')
6918 errorMessage,
false,
true))
6921 if (prevchar ==
':')
6931 errorMessage,
false,
true))
6962 while (*p && *p !=
']')
6967 "end of string reached when looking for matching \"]\" in IPv6 host address in URI: \"%s\"",
6974 "IPv6 host address may not be empty in URI: \"%s\"",
6986 if (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
6989 "unexpected character \"%c\" at position %d in URI (expected \":\" or \"/\"): \"%s\"",
6990 *p, (
int) (p -
buf + 1), uri);
7003 while (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
7013 if (prevchar ==
':')
7015 const char *
port = ++p;
7017 while (*p && *p !=
'/' && *p !=
'?' && *p !=
',')
7026 if (prevchar !=
',')
7036 if (hostbuf.
data[0] &&
7038 errorMessage,
false,
true))
7040 if (portbuf.
data[0] &&
7042 errorMessage,
false,
true))
7045 if (prevchar && prevchar !=
'?')
7047 const char *
dbname = ++p;
7050 while (*p && *p !=
'?')
7063 errorMessage,
false,
true))
7100 char *keyword = params;
7103 bool malloced =
false;
7118 "extra key/value separator \"=\" in URI query parameter: \"%s\"",
7126 else if (*p ==
'&' || *p ==
'\0')
7138 "missing key/value separator \"=\" in URI query parameter: \"%s\"",
7150 if (keyword == NULL)
7167 if (strcmp(keyword,
"ssl") == 0 &&
7168 strcmp(
value,
"true") == 0)
7174 keyword =
"sslmode";
7183 oldmsglen = errorMessage->
len;
7185 errorMessage,
true,
false))
7188 if (errorMessage->
len == oldmsglen)
7190 "invalid URI query parameter: \"%s\"",
7231 const char *q =
str;
7242 for (
const char *s = q; *s ==
' '; s++)
7253 if (*q ==
' ' || *q ==
'\0')
7274 "invalid percent-encoded token: \"%s\"",
7284 "forbidden value %%00 in percent-encoded value: \"%s\"",
7296 for (
const char *s = q; *s ==
' '; s++)
7306 "unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead",
7329 if (
'0' <= digit && digit <=
'9')
7330 *
value = digit -
'0';
7331 else if (
'A' <= digit && digit <=
'F')
7332 *
value = digit -
'A' + 10;
7333 else if (
'a' <= digit && digit <=
'f')
7334 *
value = digit -
'a' + 10;
7349 const char *keyword)
7375 const char *keyword,
const char *
value,
7387 if (strcmp(keyword,
"requiressl") == 0)
7389 keyword =
"sslmode";
7390 if (
value[0] ==
'1')
7401 "invalid connection option \"%s\"",
7409 if (value_copy == NULL)
7415 value_copy = strdup(
value);
7416 if (value_copy == NULL)
7444 if (strcmp(
option->keyword, keyword) == 0)
7474 if (connOptions != NULL)
7485 connmember = (
char **) ((
char *)
conn +
option->connofs);
7489 &errorBuf,
true,
false);
7502 if (connOptions == NULL)
7592 return DEF_PGPORT_STR;
7638 if (!
conn || !paramName)
7640 for (pstatus =
conn->
pstatus; pstatus != NULL; pstatus = pstatus->
next)
7642 if (strcmp(pstatus->
name, paramName) == 0)
7643 return pstatus->
value;
7780 static const char query[] =
"set client_encoding to '%s'";
7795 if (
sizeof(qbuf) < (
sizeof(query) + strlen(
encoding)))
7902 fprintf(stderr,
"%s", message);
7914 bool bslash =
false;
7920 if (tbuf[0] ==
'*' && tbuf[1] ==
':')
7924 if (*tbuf ==
'\\' && !bslash)
7929 if (*tbuf ==
':' && *ttok == 0 && !bslash)
7948 const char *
username,
const char *pgpassfile)
7952 struct stat stat_buf;
7974 if (
port == NULL ||
port[0] ==
'\0')
7975 port = DEF_PGPORT_STR;
7978 fp = fopen(pgpassfile,
"r");
7983 if (
fstat(fileno(fp), &stat_buf) != 0)
7992 libpq_gettext(
"WARNING: password file \"%s\" is not a plain file\n"),
8002 libpq_gettext(
"WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n"),
8018 while (!feof(fp) && !ferror(fp))
8025 if (fgets(
buf.data +
buf.len,
buf.maxlen -
buf.len, fp) == NULL)
8030 if (!(
buf.len > 0 &&
buf.data[
buf.len - 1] ==
'\n') && !feof(fp))
8034 if (
buf.data[0] !=
'#')
8066 for (p1 = p2 = ret; *p1 !=
':' && *p1 !=
'\0'; ++p1, ++p2)
8068 if (*p1 ==
'\\' && p1[1] !=
'\0')
8123 if (!version || strlen(version) == 0)
8149 if (min == NULL || max == NULL || strlen(min) == 0 || strlen(max) == 0)
8201 home = getenv(
"HOME");
8202 if (home && home[0])
8209 struct passwd pwbuf;
8214 rc = getpwuid_r(geteuid(), &pwbuf,
tmpbuf,
sizeof tmpbuf, &pw);
8221 char tmppath[MAX_PATH];
8223 ZeroMemory(tmppath,
sizeof(tmppath));
8224 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, tmppath) != S_OK)
8238 const char *context)
8249 numval = strtol(
value, &end, 10);
8255 if (
value == end || errno != 0 || numval != (
int) numval)
8262 while (*end !=
'\0' && isspace((
unsigned char) *end))
8283 const char *context)
8285 if (strcmp(
value,
"latest") == 0)
8290 if (strcmp(
value,
"3.0") == 0)
8298 if (strcmp(
value,
"3.2") == 0)
int pg_b64_dec_len(int srclen)
int pg_b64_decode(const char *src, int len, uint8 *dst, int dstlen)
int ssl_min_protocol_version
int ssl_max_protocol_version
static Datum values[MAXATTR]
static void cleanup(void)
#define MemSet(start, val, len)
#define StaticAssertDecl(condition, errmessage)
#define fprintf(file, fmt, msg)
int errmsg(const char *fmt,...)
void err(int eval, const char *fmt,...)
const pg_fe_sasl_mech pg_oauth_mech
void pqClearOAuthToken(PGconn *conn)
const pg_fe_sasl_mech pg_scram_mech
int pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn, bool *async)
char * pg_fe_getauthname(PQExpBuffer errorMessage)
char * pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
int PQsendCancelRequest(PGconn *cancelConn)
PostgresPollingStatusType PQcancelPoll(PGcancelConn *cancelConn)
static void pqFreeCommandQueue(PGcmdQueueEntry *queue)
int PQserverVersion(const PGconn *conn)
static const char * conninfo_getval(PQconninfoOption *connOptions, const char *keyword)
int PQprotocolVersion(const PGconn *conn)
void pqDropConnection(PGconn *conn, bool flushInput)
int PQresetStart(PGconn *conn)
static bool connectOptions1(PGconn *conn, const char *conninfo)
static const PQEnvironmentOption EnvironmentOptions[]
#define CONNECTION_FAILED()
bool pqConnectOptions2(PGconn *conn)
static PQconninfoOption * conninfo_init(PQExpBuffer errorMessage)
static void sendTerminateConn(PGconn *conn)
char * PQoptions(const PGconn *conn)
static int setKeepalivesCount(PGconn *conn)
static PQconninfoOption * parse_connection_string(const char *connstr, PQExpBuffer errorMessage, bool use_defaults)
static int useKeepalives(PGconn *conn)
char * PQdb(const PGconn *conn)
static void defaultNoticeReceiver(void *arg, const PGresult *res)
static int uri_prefix_length(const char *connstr)
static bool pqParseProtocolVersion(const char *value, ProtocolVersion *result, PGconn *conn, const char *context)
static int store_conn_addrinfo(PGconn *conn, struct addrinfo *addrlist)
static int parseServiceFile(const char *serviceFile, const char *service, PQconninfoOption *options, PQExpBuffer errorMessage, bool *group_found)
static void connectFailureMessage(PGconn *conn, int errorno)
static char * passwordFromFile(const char *hostname, const char *port, const char *dbname, const char *username, const char *pgpassfile)
static bool sslVerifyProtocolRange(const char *min, const char *max)
static void default_threadlock(int acquire)
int PQfullProtocolVersion(const PGconn *conn)
static void libpq_prng_init(PGconn *conn)
void PQreset(PGconn *conn)
void pqClosePGconn(PGconn *conn)
bool pqGetHomeDirectory(char *buf, int bufsize)
struct _internalPQconninfoOption internalPQconninfoOption
static const char short_uri_designator[]
static void release_conn_addrinfo(PGconn *conn)
char * PQport(const PGconn *conn)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
static int count_comma_separated_elems(const char *input)
static bool conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
static bool select_next_encryption_method(PGconn *conn, bool have_valid_connection)
PGconn * PQconnectdb(const char *conninfo)
char * PQhost(const PGconn *conn)
#define ERRCODE_APPNAME_UNKNOWN
static bool conninfo_uri_parse_params(char *params, PQconninfoOption *connOptions, PQExpBuffer errorMessage)
int PQconnectionUsedPassword(const PGconn *conn)
static void clear_allowed_sasl_mechs(PGconn *conn)
PQconninfoOption * PQconninfo(PGconn *conn)
static char * conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
static int setKeepalivesInterval(PGconn *conn)
static void fill_allowed_sasl_mechs(PGconn *conn)
static int setKeepalivesIdle(PGconn *conn)
PostgresPollingStatusType PQconnectPoll(PGconn *conn)
void PQconninfoFree(PQconninfoOption *connOptions)
#define DefaultChannelBinding
bool pqParseIntParam(const char *value, int *result, PGconn *conn, const char *context)
static void defaultNoticeProcessor(void *arg, const char *message)
static void pgpassfileWarning(PGconn *conn)
char * PQtty(const PGconn *conn)
static int index_of_allowed_sasl_mech(PGconn *conn, const pg_fe_sasl_mech *mech)
static PGPing internal_ping(PGconn *conn)
static PQconninfoOption * conninfo_find(PQconninfoOption *connOptions, const char *keyword)
static const char uri_designator[]
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
static bool sslVerifyProtocolVersion(const char *version)
#define SELECT_NEXT_METHOD(method)
int PQconnectionNeedsPassword(const PGconn *conn)
char * PQpass(const PGconn *conn)
PostgresPollingStatusType PQresetPoll(PGconn *conn)
int PQconnectionUsedGSSAPI(const PGconn *conn)
static PQconninfoOption * conninfo_uri_parse(const char *uri, PQExpBuffer errorMessage, bool use_defaults)
void pqReleaseConnHosts(PGconn *conn)
static void emitHostIdentityInfo(PGconn *conn, const char *host_addr)
static bool connection_failed(PGconn *conn)
pgthreadlock_t pg_g_threadlock
ConnStatusType PQstatus(const PGconn *conn)
PGconn * PQconnectStart(const char *conninfo)
static int setTCPUserTimeout(PGconn *conn)
static PQconninfoOption * conninfo_array_parse(const char *const *keywords, const char *const *values, PQExpBuffer errorMessage, bool use_defaults, int expand_dbname)
int PQclientEncoding(const PGconn *conn)
PGconn * PQconnectStartParams(const char *const *keywords, const char *const *values, int expand_dbname)
static PQconninfoOption * conninfo_parse(const char *conninfo, PQExpBuffer errorMessage, bool use_defaults)
void PQfinish(PGconn *conn)
static void pqDropServerData(PGconn *conn)
PGconn * pqMakeEmptyPGconn(void)
PGPing PQping(const char *conninfo)
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
#define DefaultLoadBalanceHosts
static int connectNoDelay(PGconn *conn)
#define DefaultSSLNegotiation
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
PGconn * PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, const char *login, const char *pwd)
char * PQhostaddr(const PGconn *conn)
int PQbackendPID(const PGconn *conn)
PQconninfoOption * PQconndefaults(void)
static PQconninfoOption * conninfo_storeval(PQconninfoOption *connOptions, const char *keyword, const char *value, PQExpBuffer errorMessage, bool ignoreMissing, bool uri_decode)
static bool conninfo_uri_parse_options(PQconninfoOption *options, const char *uri, PQExpBuffer errorMessage)
int pqConnectDBStart(PGconn *conn)
static void getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
char * PQuser(const PGconn *conn)
static void freePGconn(PGconn *conn)
bool pqCopyPGconn(PGconn *srcConn, PGconn *dstConn)
static char * pwdfMatchesString(char *buf, const char *token)
PGpipelineStatus PQpipelineStatus(const PGconn *conn)
static bool get_hexdigit(char digit, int *value)
#define ERRCODE_INVALID_PASSWORD
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
#define SASL_MECHANISM_COUNT
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
#define DefaultSSLCertMode
#define ERRCODE_CANNOT_CONNECT_NOW
static const internalPQconninfoOption PQconninfoOptions[]
#define ENCRYPTION_NEGOTIATION_FAILED(msg)
static bool recognized_connection_string(const char *connstr)
#define DefaultTargetSessionAttrs
static int parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
char * PQerrorMessage(const PGconn *conn)
static bool init_allowed_encryption_methods(PGconn *conn)
static const pg_fe_sasl_mech * supported_sasl_mechs[]
PGPing PQpingParams(const char *const *keywords, const char *const *values, int expand_dbname)
int PQsocket(const PGconn *conn)
int pqConnectDBComplete(PGconn *conn)
int PQsetClientEncoding(PGconn *conn, const char *encoding)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
static char * parse_comma_separated_list(char **startptr, bool *more)
int pqPacketSend(PGconn *conn, char pack_type, const void *buf, size_t buf_len)
static bool fillPGconn(PGconn *conn, PQconninfoOption *connOptions)
pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler)
int PQsendQueryContinue(PGconn *conn, const char *query)
int PQconsumeInput(PGconn *conn)
void pqClearAsyncResult(PGconn *conn)
int PQisBusy(PGconn *conn)
PGresult * PQexec(PGconn *conn, const char *query)
bool pg_GSS_have_cred_cache(gss_cred_id_t *cred_out)
int pqReadData(PGconn *conn)
int pqFlush(PGconn *conn)
void pqParseDone(PGconn *conn, int newInStart)
int pqPutMsgStart(char msg_type, PGconn *conn)
int pqGetc(char *result, PGconn *conn)
int pqGetInt(int *result, size_t bytes, PGconn *conn)
int pqPutnchar(const void *s, size_t len, PGconn *conn)
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
pg_usec_time_t PQgetCurrentTimeUSec(void)
void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...)
int pqWaitTimed(int forRead, int forWrite, PGconn *conn, pg_usec_time_t end_time)
int pqGets_append(PQExpBuffer buf, PGconn *conn)
int pqPutMsgEnd(PGconn *conn)
char * pqBuildStartupPacket3(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)
int pqGetNegotiateProtocolVersion3(PGconn *conn)
int pqGetErrorNotice3(PGconn *conn, bool isError)
PostgresPollingStatusType pqsecure_open_gss(PGconn *conn)
PostgresPollingStatusType pqsecure_open_client(PGconn *conn)
void pqsecure_close(PGconn *conn)
void pqTraceOutputCharResponse(PGconn *conn, const char *responseType, char response)
Assert(PointerIsAligned(start, uint64))
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
static const JsonPathKeyword keywords[]
#define PQresultErrorMessage
#define PQresultErrorField
@ CONNECTION_AUTHENTICATING
@ CONNECTION_CHECK_STANDBY
@ CONNECTION_AWAITING_RESPONSE
@ CONNECTION_CHECK_WRITABLE
@ CONNECTION_CHECK_TARGET
void(* pgthreadlock_t)(int acquire)
void(* PQnoticeReceiver)(void *arg, const PGresult *res)
void(* PQnoticeProcessor)(void *arg, const char *message)
PostgresPollingStatusType
#define pqClearConnErrorState(conn)
@ SERVER_TYPE_PREFER_STANDBY_PASS2
@ SERVER_TYPE_PREFER_STANDBY
bool pg_link_canary_is_frontend(void)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
#define DEFAULT_PGSOCKET_DIR
static const char * connstr
uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
#define pg_prng_strong_seed(state)
#define pg_encoding_to_char
static const char * pghost
static const char * pgport
static const char * dbName
#define PG_STRERROR_R_BUFLEN
int pg_strcasecmp(const char *s1, const char *s2)
char * pg_inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
bool pg_set_noblock(pgsocket sock)
void explicit_bzero(void *buf, size_t len)
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
int getpeereid(int sock, uid_t *uid, gid_t *gid)
#define PG_PROTOCOL_MAJOR(v)
#define PG_PROTOCOL_EARLIEST
#define PG_PROTOCOL_FULL(v)
static bool is_unixsock_path(const char *path)
#define PG_PROTOCOL_LATEST
#define UNIXSOCK_PATH(path, port, sockdir)
#define UNIXSOCK_PATH_BUFLEN
#define NEGOTIATE_GSS_CODE
#define NEGOTIATE_SSL_CODE
#define PG_PROTOCOL(m, n)
void initPQExpBuffer(PQExpBuffer str)
int enlargePQExpBuffer(PQExpBuffer str, size_t needed)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferBroken(str)
#define PQExpBufferDataBroken(buf)
#define AUTH_REQ_SASL_CONT
#define PqMsg_AuthenticationRequest
#define PqMsg_NegotiateProtocolVersion
#define AUTH_REQ_PASSWORD
#define AUTH_REQ_GSS_CONT
#define PqMsg_ErrorResponse
#define AUTH_REQ_SASL_FIN
int pthread_mutex_unlock(pthread_mutex_t *mp)
int pthread_mutex_lock(pthread_mutex_t *mp)
#define PTHREAD_MUTEX_INITIALIZER
#define SCRAM_MAX_KEY_LEN
#define SCRAM_SHA_256_DEFAULT_ITERATIONS
const char * gai_strerror(int ecode)
int pg_strip_crlf(char *str)
PQnoticeReceiver noticeRec
PQnoticeProcessor noticeProc
struct sockaddr_storage addr
struct pgParameterStatus * next
uint8 * scram_client_key_binary
char * oauth_discovery_uri
PGTransactionStatusType xactStatus
const pg_fe_sasl_mech * sasl
size_t scram_client_key_len
char * ssl_max_protocol_version
PGTernaryBool in_hot_standby
uint8 * scram_server_key_binary
void(* cleanup_async_auth)(PGconn *conn)
bool client_finished_auth
PGcmdQueueEntry * cmd_queue_recycle
ProtocolVersion min_pversion
uint32 allowed_auth_methods
char * target_session_attrs
PGcmdQueueEntry * cmd_queue_tail
PQExpBufferData workBuffer
char * oauth_client_secret
char * max_protocol_version
char * load_balance_hosts
PGTernaryBool default_transaction_read_only
pgParameterStatus * pstatus
char * min_protocol_version
char * client_encoding_initial
char * keepalives_interval
char * pgtcp_user_timeout
char * ssl_min_protocol_version
PQExpBufferData errorMessage
ProtocolVersion max_pversion
PostgresPollingStatusType(* async_auth)(PGconn *conn)
PGAsyncStatusType asyncStatus
PGLoadBalanceType load_balance_type
int scram_sha_256_iterations
PGpipelineStatus pipelineStatus
uint8 allowed_enc_methods
PGNoticeHooks noticeHooks
PGTargetServerType target_server_type
size_t scram_server_key_len
PGcmdQueueEntry * cmd_queue_head
const pg_fe_sasl_mech * allowed_sasl_mechs[2]
PGContextVisibility show_context
void(* free)(void *state)
PGNoticeHooks noticeHooks
ExecStatusType resultStatus
static StringInfoData tmpbuf
#define socket(af, type, protocol)
#define connect(s, name, namelen)
int gettimeofday(struct timeval *tp, void *tzp)