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 {
"user",
"PGUSER", NULL, NULL,
205 "Database-User",
"", 20,
206 offsetof(
struct pg_conn, pguser)},
208 {
"password",
"PGPASSWORD", NULL, NULL,
209 "Database-Password",
"*", 20,
210 offsetof(
struct pg_conn, pgpass)},
212 {
"passfile",
"PGPASSFILE", NULL, NULL,
213 "Database-Password-File",
"", 64,
214 offsetof(
struct pg_conn, pgpassfile)},
217 "Channel-Binding",
"", 8,
218 offsetof(
struct pg_conn, channel_binding)},
220 {
"connect_timeout",
"PGCONNECT_TIMEOUT", NULL, NULL,
221 "Connect-timeout",
"", 10,
222 offsetof(
struct pg_conn, connect_timeout)},
224 {
"dbname",
"PGDATABASE", NULL, NULL,
225 "Database-Name",
"", 20,
228 {
"host",
"PGHOST", NULL, NULL,
229 "Database-Host",
"", 40,
232 {
"hostaddr",
"PGHOSTADDR", NULL, NULL,
233 "Database-Host-IP-Address",
"", 45,
234 offsetof(
struct pg_conn, pghostaddr)},
236 {
"port",
"PGPORT", DEF_PGPORT_STR, NULL,
237 "Database-Port",
"", 6,
240 {
"client_encoding",
"PGCLIENTENCODING", NULL, NULL,
241 "Client-Encoding",
"", 10,
242 offsetof(
struct pg_conn, client_encoding_initial)},
245 "Backend-Options",
"", 40,
246 offsetof(
struct pg_conn, pgoptions)},
248 {
"application_name",
"PGAPPNAME", NULL, NULL,
249 "Application-Name",
"", 64,
250 offsetof(
struct pg_conn, appname)},
252 {
"fallback_application_name", NULL, NULL, NULL,
253 "Fallback-Application-Name",
"", 64,
254 offsetof(
struct pg_conn, fbappname)},
256 {
"keepalives", NULL, NULL, NULL,
257 "TCP-Keepalives",
"", 1,
258 offsetof(
struct pg_conn, keepalives)},
260 {
"keepalives_idle", NULL, NULL, NULL,
261 "TCP-Keepalives-Idle",
"", 10,
262 offsetof(
struct pg_conn, keepalives_idle)},
264 {
"keepalives_interval", NULL, NULL, NULL,
265 "TCP-Keepalives-Interval",
"", 10,
266 offsetof(
struct pg_conn, keepalives_interval)},
268 {
"keepalives_count", NULL, NULL, NULL,
269 "TCP-Keepalives-Count",
"", 10,
270 offsetof(
struct pg_conn, keepalives_count)},
272 {
"tcp_user_timeout", NULL, NULL, NULL,
273 "TCP-User-Timeout",
"", 10,
274 offsetof(
struct pg_conn, pgtcp_user_timeout)},
284 offsetof(
struct pg_conn, sslmode)},
287 "SSL-Negotiation",
"", 9,
288 offsetof(
struct pg_conn, sslnegotiation)},
290 {
"sslcompression",
"PGSSLCOMPRESSION",
"0", NULL,
291 "SSL-Compression",
"", 1,
292 offsetof(
struct pg_conn, sslcompression)},
294 {
"sslcert",
"PGSSLCERT", NULL, NULL,
295 "SSL-Client-Cert",
"", 64,
296 offsetof(
struct pg_conn, sslcert)},
298 {
"sslkey",
"PGSSLKEY", NULL, NULL,
299 "SSL-Client-Key",
"", 64,
300 offsetof(
struct pg_conn, sslkey)},
302 {
"sslcertmode",
"PGSSLCERTMODE", NULL, NULL,
303 "SSL-Client-Cert-Mode",
"", 8,
304 offsetof(
struct pg_conn, sslcertmode)},
306 {
"sslpassword", NULL, NULL, NULL,
307 "SSL-Client-Key-Password",
"*", 20,
308 offsetof(
struct pg_conn, sslpassword)},
310 {
"sslrootcert",
"PGSSLROOTCERT", NULL, NULL,
311 "SSL-Root-Certificate",
"", 64,
312 offsetof(
struct pg_conn, sslrootcert)},
314 {
"sslcrl",
"PGSSLCRL", NULL, NULL,
315 "SSL-Revocation-List",
"", 64,
316 offsetof(
struct pg_conn, sslcrl)},
318 {
"sslcrldir",
"PGSSLCRLDIR", NULL, NULL,
319 "SSL-Revocation-List-Dir",
"", 64,
320 offsetof(
struct pg_conn, sslcrldir)},
322 {
"sslsni",
"PGSSLSNI",
"1", NULL,
324 offsetof(
struct pg_conn, sslsni)},
326 {
"requirepeer",
"PGREQUIREPEER", NULL, NULL,
327 "Require-Peer",
"", 10,
328 offsetof(
struct pg_conn, requirepeer)},
330 {
"require_auth",
"PGREQUIREAUTH", NULL, NULL,
331 "Require-Auth",
"", 14,
332 offsetof(
struct pg_conn, require_auth)},
334 {
"min_protocol_version",
"PGMINPROTOCOLVERSION",
336 "Min-Protocol-Version",
"", 6,
337 offsetof(
struct pg_conn, min_protocol_version)},
339 {
"max_protocol_version",
"PGMAXPROTOCOLVERSION",
341 "Max-Protocol-Version",
"", 6,
342 offsetof(
struct pg_conn, max_protocol_version)},
344 {
"ssl_min_protocol_version",
"PGSSLMINPROTOCOLVERSION",
"TLSv1.2", NULL,
345 "SSL-Minimum-Protocol-Version",
"", 8,
348 {
"ssl_max_protocol_version",
"PGSSLMAXPROTOCOLVERSION", NULL, NULL,
349 "SSL-Maximum-Protocol-Version",
"", 8,
357 "GSSENC-Mode",
"", 8,
358 offsetof(
struct pg_conn, gssencmode)},
361 {
"krbsrvname",
"PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
362 "Kerberos-service-name",
"", 20,
363 offsetof(
struct pg_conn, krbsrvname)},
365 {
"gsslib",
"PGGSSLIB", NULL, NULL,
366 "GSS-library",
"", 7,
367 offsetof(
struct pg_conn, gsslib)},
369 {
"gssdelegation",
"PGGSSDELEGATION",
"0", NULL,
370 "GSS-delegation",
"", 1,
371 offsetof(
struct pg_conn, gssdelegation)},
373 {
"replication", NULL, NULL, NULL,
374 "Replication",
"D", 5,
375 offsetof(
struct pg_conn, replication)},
377 {
"target_session_attrs",
"PGTARGETSESSIONATTRS",
379 "Target-Session-Attrs",
"", 15,
380 offsetof(
struct pg_conn, target_session_attrs)},
382 {
"load_balance_hosts",
"PGLOADBALANCEHOSTS",
384 "Load-Balance-Hosts",
"", 8,
385 offsetof(
struct pg_conn, load_balance_hosts)},
387 {
"scram_client_key", NULL, NULL, NULL,
"SCRAM-Client-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
388 offsetof(
struct pg_conn, scram_client_key)},
390 {
"scram_server_key", NULL, NULL, NULL,
"SCRAM-Server-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
391 offsetof(
struct pg_conn, scram_server_key)},
394 {
"oauth_issuer", NULL, NULL, NULL,
395 "OAuth-Issuer",
"", 40,
396 offsetof(
struct pg_conn, oauth_issuer)},
398 {
"oauth_client_id", NULL, NULL, NULL,
399 "OAuth-Client-ID",
"", 40,
400 offsetof(
struct pg_conn, oauth_client_id)},
402 {
"oauth_client_secret", NULL, NULL, NULL,
403 "OAuth-Client-Secret",
"*", 40,
404 offsetof(
struct pg_conn, oauth_client_secret)},
406 {
"oauth_scope", NULL, NULL, NULL,
407 "OAuth-Scope",
"", 15,
408 offsetof(
struct pg_conn, oauth_scope)},
410 {
"sslkeylogfile", NULL, NULL, NULL,
411 "SSL-Key-Log-File",
"D", 64,
412 offsetof(
struct pg_conn, sslkeylogfile)},
415 {NULL, NULL, NULL, NULL,
423 "PGDATESTYLE",
"datestyle"
442#define SASL_MECHANISM_COUNT lengthof(supported_sasl_mechs)
450#if defined(USE_SSL) || defined(ENABLE_GSS)
451static int encryption_negotiation_failed(
PGconn *
conn);
471 bool use_defaults,
int expand_dbname);
484 const char *keyword);
486 const char *keyword,
const char *
value,
487 PQExpBuffer errorMessage,
bool ignoreMissing,
bool uri_decode);
489 const char *keyword);
501 const char *
username,
const char *pgpassfile);
567 if (
conn->gcred != GSS_C_NO_CREDENTIAL)
569 gss_release_cred(&min_s, &
conn->gcred);
570 conn->gcred = GSS_C_NO_CREDENTIAL;
573 gss_delete_sec_context(&min_s, &
conn->gctx, GSS_C_NO_BUFFER);
575 gss_release_name(&min_s, &
conn->gtarg_nam);
576 if (
conn->gss_SendBuffer)
579 conn->gss_SendBuffer = NULL;
581 if (
conn->gss_RecvBuffer)
584 conn->gss_RecvBuffer = NULL;
586 if (
conn->gss_ResultBuffer)
589 conn->gss_ResultBuffer = NULL;
591 conn->gssenc =
false;
595 if (
conn->sspitarget)
598 conn->sspitarget = NULL;
602 FreeCredentialsHandle(
conn->sspicred);
604 conn->sspicred = NULL;
608 DeleteSecurityContext(
conn->sspictx);
610 conn->sspictx = NULL;
628 while (queue != NULL)
659 while (notify != NULL)
663 notify = notify->
next;
670 while (pstatus != NULL)
674 pstatus = pstatus->
next;
765 const char *
const *
values,
783 const char *
const *
values,
867 const char *
const *
values,
887 true, expand_dbname);
888 if (connOptions == NULL)
1005 char **connmember = (
char **) ((
char *)
conn +
option->connofs);
1008 *connmember = strdup(tmp);
1009 if (*connmember == NULL)
1038 if (
option->connofs >= 0)
1040 const char **tmp = (
const char **) ((
char *) srcConn +
option->connofs);
1044 char **dstConnmember = (
char **) ((
char *) dstConn +
option->connofs);
1047 free(*dstConnmember);
1048 *dstConnmember = strdup(*tmp);
1049 if (*dstConnmember == NULL)
1080 if (connOptions == NULL)
1136 char *s = *startptr;
1145 while (*
e !=
'\0' && *
e !=
',')
1147 *more = (*
e ==
',');
1150 p = (
char *)
malloc(
sizeof(
char) * (
len + 1));
1171 struct timeval tval = {0};
1178 rseed = ((uintptr_t)
conn) ^
1180 ((
uint64) tval.tv_usec) ^
1205 "conn->allowed_sasl_mechs[] is not sufficiently large for holding all supported SASL mechanisms");
1324 else if (ch->
host != NULL && ch->
host[0] !=
'\0')
1348 if (ch->
host == NULL)
1376 if (
i == 1 && !more)
1454 if (pwhost == NULL || pwhost[0] ==
'\0')
1475 bool negated =
false;
1485 for (first =
true, more =
true; more; first =
false)
1540 if (strcmp(method,
"password") == 0)
1544 else if (strcmp(method,
"md5") == 0)
1548 else if (strcmp(method,
"gss") == 0)
1553 else if (strcmp(method,
"sspi") == 0)
1565 else if (strcmp(method,
"scram-sha-256") == 0)
1569 else if (strcmp(method,
"oauth") == 0)
1577 else if (strcmp(method,
"none") == 0)
1606 "require_auth", method);
1647 "internal error: no space in allowed_sasl_mechs");
1698 bool allowed =
false;
1717 if (!negated && allowed)
1719 else if (negated && !allowed)
1848 libpq_append_conn_error(
conn,
"weak sslmode \"%s\" may not be used with sslnegotiation=direct (use \"require\", \"verify-ca\", or \"verify-full\")",
1884 "ssl_min_protocol_version",
1892 "ssl_max_protocol_version",
1935#ifndef HAVE_SSL_CTX_SET_CERT_CB
2009 "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;
5164 struct addrinfo *ai = addrlist;
5405 const void *
buf,
size_t buf_len)
5428#define LDAP_URL "ldap://"
5429#define LDAP_DEF_PORT 389
5430#define PGLDAP_TIMEOUT 2
5432#define ld_is_sp_tab(x) ((x) == ' ' || (x) == '\t')
5433#define ld_is_nl_cr(x) ((x) == '\r' || (x) == '\n')
5459 int port = LDAP_DEF_PORT,
5482 char *attrs[2] = {NULL, NULL};
5487 LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0};
5489 if ((url = strdup(purl)) == NULL)
5504 "invalid LDAP URL \"%s\": scheme must be ldap://", purl);
5515 p = strchr(url + strlen(LDAP_URL),
'/');
5516 if (p == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5519 "invalid LDAP URL \"%s\": missing distinguished name",
5528 if ((p = strchr(dn,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5531 "invalid LDAP URL \"%s\": must have exactly one attribute",
5540 if ((p = strchr(attrs[0],
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5543 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5552 if ((p = strchr(scopestr,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5555 "invalid LDAP URL \"%s\": no filter",
5562 if ((p = strchr(filter,
'?')) != NULL)
5566 if ((p1 = strchr(
hostname,
':')) != NULL)
5573 lport = strtol(
portstr, &endptr, 10);
5574 if (*
portstr ==
'\0' || *endptr !=
'\0' || errno || lport < 0 || lport > 65535)
5577 "invalid LDAP URL \"%s\": invalid port number",
5586 if (strchr(attrs[0],
',') != NULL)
5589 "invalid LDAP URL \"%s\": must have exactly one attribute",
5597 scope = LDAP_SCOPE_BASE;
5599 scope = LDAP_SCOPE_ONELEVEL;
5601 scope = LDAP_SCOPE_SUBTREE;
5605 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5633 if (ldap_connect(ld, &time) != LDAP_SUCCESS)
5642 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5650 if ((msgid = ldap_simple_bind(ld, NULL, NULL)) == -1)
5660 if ((rc = ldap_result(ld, msgid, LDAP_MSG_ALL, &time, &res)) == -1 ||
5674 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5684 if ((rc = ldap_search_st(ld, dn, scope, filter, attrs, 0, &time, &res))
5689 libpq_append_error(errorMessage,
"lookup on LDAP server failed: %s", ldap_err2string(rc));
5696 if ((rc = ldap_count_entries(ld, res)) != 1)
5709 if ((entry = ldap_first_entry(ld, res)) == NULL)
5720 if ((
values = ldap_get_values_len(ld, entry, attrs[0])) == NULL)
5735 ldap_value_free_len(
values);
5743 size +=
values[
i]->bv_len + 1;
5744 if ((result =
malloc(size)) == NULL)
5747 ldap_value_free_len(
values);
5760 ldap_value_free_len(
values);
5764 oldstate =
state = 0;
5765 for (p = result; *p !=
'\0'; ++p)
5770 if (!ld_is_sp_tab(*p) && !ld_is_nl_cr(*p))
5777 if (ld_is_sp_tab(*p))
5782 else if (ld_is_nl_cr(*p))
5785 "missing \"=\" after \"%s\" in connection info string",
5801 else if (!ld_is_sp_tab(*p))
5804 "missing \"=\" after \"%s\" in connection info string",
5817 else if (ld_is_nl_cr(*p))
5819 optval = optname + strlen(optname);
5822 else if (!ld_is_sp_tab(*p))
5829 if (ld_is_sp_tab(*p) || ld_is_nl_cr(*p))
5841 else if (*p ==
'\\')
5852 if (
state == 0 && oldstate != 0)
5854 found_keyword =
false;
5857 if (strcmp(
options[
i].keyword, optname) == 0)
5869 found_keyword =
true;
5890 "unterminated quoted string in connection info string");
5915 bool group_found =
false;
5917 struct stat stat_buf;
5924 if (service == NULL)
5925 service = getenv(
"PGSERVICE");
5928 if (service == NULL)
5935 if ((env = getenv(
"PGSERVICEFILE")) != NULL)
5936 strlcpy(serviceFile, env,
sizeof(serviceFile));
5944 if (
stat(serviceFile, &stat_buf) != 0)
5949 if (group_found || status != 0)
5959 getenv(
"PGSYSCONFDIR") ? getenv(
"PGSYSCONFDIR") : SYSCONFDIR);
5960 if (
stat(serviceFile, &stat_buf) != 0)
5979 const char *service,
5991 *group_found =
false;
5993 f = fopen(serviceFile,
"r");
6000 while ((line = fgets(
buf,
sizeof(
buf), f)) != NULL)
6006 if (strlen(line) >=
sizeof(
buf) - 1)
6009 "line %d too long in service file \"%s\"",
6018 while (
len > 0 && isspace((
unsigned char) line[
len - 1]))
6022 while (*line && isspace((
unsigned char) line[0]))
6026 if (line[0] ==
'\0' || line[0] ==
'#')
6038 if (strncmp(line + 1, service, strlen(service)) == 0 &&
6039 line[strlen(service) + 1] ==
']')
6040 *group_found =
true;
6042 *group_found =
false;
6056 if (strncmp(line,
"ldap", 4) == 0)
6058 int rc = ldapServiceLookup(line,
options, errorMessage);
6076 val = strchr(line,
'=');
6080 "syntax error in service file \"%s\", line %d",
6088 if (strcmp(
key,
"service") == 0)
6091 "nested service specifications not supported in service file \"%s\", line %d",
6102 found_keyword =
false;
6115 found_keyword =
true;
6123 "syntax error in service file \"%s\", line %d",
6167 if (connOptions == NULL &&
errmsg)
6287 if ((
buf = strdup(conninfo)) == NULL)
6298 if (isspace((
unsigned char) *cp))
6310 if (isspace((
unsigned char) *cp))
6315 if (!isspace((
unsigned char) *cp))
6328 "missing \"=\" after \"%s\" in connection info string",
6339 if (!isspace((
unsigned char) *cp))
6352 if (isspace((
unsigned char) *cp))
6376 libpq_append_error(errorMessage,
"unterminated quoted string in connection info string");
6463 const char *pvalue =
values[
i];
6466 if (strcmp(pname,
"dbname") == 0 && pvalue)
6476 if (dbname_options == NULL)
6497 const char *pvalue =
values[
i];
6499 if (pvalue != NULL && pvalue[0] !=
'\0')
6504 if (strcmp(
option->keyword, pname) == 0)
6509 if (
option->keyword == NULL)
6522 if (strcmp(pname,
"dbname") == 0 && dbname_options)
6526 for (str_option = dbname_options; str_option->
keyword != NULL; str_option++)
6528 if (str_option->
val != NULL)
6532 for (k = 0;
options[k].keyword; k++)
6556 dbname_options = NULL;
6609 *sslrootcert = NULL;
6626 if (strcmp(
option->keyword,
"sslrootcert") == 0)
6635 if (
option->envvar != NULL)
6637 if ((tmp = getenv(
option->envvar)) != NULL)
6656 if (strcmp(
option->keyword,
"sslmode") == 0)
6658 const char *requiresslenv = getenv(
"PGREQUIRESSL");
6660 if (requiresslenv != NULL && requiresslenv[0] ==
'1')
6677 sslmode_default =
option;
6684 if (
option->compiled != NULL)
6703 if (strcmp(
option->keyword,
"user") == 0)
6715 if (sslmode_default && sslrootcert)
6717 if (sslrootcert->val && strcmp(sslrootcert->val,
"system") == 0)
6721 sslmode_default->
val = strdup(
"verify-full");
6722 if (!sslmode_default->
val)
6800 char prevchar =
'\0';
6803 bool retval =
false;
6826 if (prefix_len == 0)
6830 "invalid URI propagated to internal parser routine: \"%s\"",
6834 start += prefix_len;
6838 while (*p && *p !=
'@' && *p !=
'/')
6849 while (*p !=
':' && *p !=
'@')
6858 errorMessage,
false,
true))
6861 if (prevchar ==
':')
6871 errorMessage,
false,
true))
6902 while (*p && *p !=
']')
6907 "end of string reached when looking for matching \"]\" in IPv6 host address in URI: \"%s\"",
6914 "IPv6 host address may not be empty in URI: \"%s\"",
6926 if (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
6929 "unexpected character \"%c\" at position %d in URI (expected \":\" or \"/\"): \"%s\"",
6930 *p, (
int) (p -
buf + 1), uri);
6943 while (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
6953 if (prevchar ==
':')
6955 const char *
port = ++p;
6957 while (*p && *p !=
'/' && *p !=
'?' && *p !=
',')
6966 if (prevchar !=
',')
6976 if (hostbuf.
data[0] &&
6978 errorMessage,
false,
true))
6980 if (portbuf.
data[0] &&
6982 errorMessage,
false,
true))
6985 if (prevchar && prevchar !=
'?')
6987 const char *
dbname = ++p;
6990 while (*p && *p !=
'?')
7003 errorMessage,
false,
true))
7040 char *keyword = params;
7043 bool malloced =
false;
7058 "extra key/value separator \"=\" in URI query parameter: \"%s\"",
7066 else if (*p ==
'&' || *p ==
'\0')
7078 "missing key/value separator \"=\" in URI query parameter: \"%s\"",
7090 if (keyword == NULL)
7107 if (strcmp(keyword,
"ssl") == 0 &&
7108 strcmp(
value,
"true") == 0)
7114 keyword =
"sslmode";
7123 oldmsglen = errorMessage->
len;
7125 errorMessage,
true,
false))
7128 if (errorMessage->
len == oldmsglen)
7130 "invalid URI query parameter: \"%s\"",
7171 const char *q =
str;
7182 for (
const char *s = q; *s ==
' '; s++)
7193 if (*q ==
' ' || *q ==
'\0')
7214 "invalid percent-encoded token: \"%s\"",
7224 "forbidden value %%00 in percent-encoded value: \"%s\"",
7236 for (
const char *s = q; *s ==
' '; s++)
7246 "unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead",
7269 if (
'0' <= digit && digit <=
'9')
7270 *
value = digit -
'0';
7271 else if (
'A' <= digit && digit <=
'F')
7272 *
value = digit -
'A' + 10;
7273 else if (
'a' <= digit && digit <=
'f')
7274 *
value = digit -
'a' + 10;
7289 const char *keyword)
7315 const char *keyword,
const char *
value,
7327 if (strcmp(keyword,
"requiressl") == 0)
7329 keyword =
"sslmode";
7330 if (
value[0] ==
'1')
7341 "invalid connection option \"%s\"",
7349 if (value_copy == NULL)
7355 value_copy = strdup(
value);
7356 if (value_copy == NULL)
7384 if (strcmp(
option->keyword, keyword) == 0)
7414 if (connOptions != NULL)
7425 connmember = (
char **) ((
char *)
conn +
option->connofs);
7429 &errorBuf,
true,
false);
7442 if (connOptions == NULL)
7584 if (!
conn || !paramName)
7586 for (pstatus =
conn->
pstatus; pstatus != NULL; pstatus = pstatus->
next)
7588 if (strcmp(pstatus->
name, paramName) == 0)
7589 return pstatus->
value;
7726 static const char query[] =
"set client_encoding to '%s'";
7741 if (
sizeof(qbuf) < (
sizeof(query) + strlen(
encoding)))
7848 fprintf(stderr,
"%s", message);
7860 bool bslash =
false;
7866 if (tbuf[0] ==
'*' && tbuf[1] ==
':')
7870 if (*tbuf ==
'\\' && !bslash)
7875 if (*tbuf ==
':' && *ttok == 0 && !bslash)
7894 const char *
username,
const char *pgpassfile)
7898 struct stat stat_buf;
7920 if (
port == NULL ||
port[0] ==
'\0')
7921 port = DEF_PGPORT_STR;
7924 fp = fopen(pgpassfile,
"r");
7929 if (
fstat(fileno(fp), &stat_buf) != 0)
7938 libpq_gettext(
"WARNING: password file \"%s\" is not a plain file\n"),
7948 libpq_gettext(
"WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n"),
7964 while (!feof(fp) && !ferror(fp))
7971 if (fgets(
buf.data +
buf.len,
buf.maxlen -
buf.len, fp) == NULL)
7976 if (!(
buf.len > 0 &&
buf.data[
buf.len - 1] ==
'\n') && !feof(fp))
7980 if (
buf.data[0] !=
'#')
8012 for (p1 = p2 = ret; *p1 !=
':' && *p1 !=
'\0'; ++p1, ++p2)
8014 if (*p1 ==
'\\' && p1[1] !=
'\0')
8069 if (!version || strlen(version) == 0)
8095 if (min == NULL || max == NULL || strlen(min) == 0 || strlen(max) == 0)
8147 home = getenv(
"HOME");
8148 if (home && home[0])
8155 struct passwd pwbuf;
8160 rc = getpwuid_r(geteuid(), &pwbuf,
tmpbuf,
sizeof tmpbuf, &pw);
8167 char tmppath[MAX_PATH];
8169 ZeroMemory(tmppath,
sizeof(tmppath));
8170 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, tmppath) != S_OK)
8184 const char *context)
8195 numval = strtol(
value, &end, 10);
8201 if (
value == end || errno != 0 || numval != (
int) numval)
8208 while (*end !=
'\0' && isspace((
unsigned char) *end))
8229 const char *context)
8231 if (strcmp(
value,
"latest") == 0)
8236 if (strcmp(
value,
"3.0") == 0)
8244 if (strcmp(
value,
"3.2") == 0)
int pg_b64_decode(const char *src, int len, char *dst, int dstlen)
int pg_b64_dec_len(int srclen)
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)
char * PQservice(const PGconn *conn)
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)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
PGresult * PQgetResult(PGconn *conn)
ExecStatusType PQresultStatus(const PGresult *res)
void PQclear(PGresult *res)
int PQntuples(const PGresult *res)
char * PQresultErrorMessage(const PGresult *res)
int PQconsumeInput(PGconn *conn)
void pqClearAsyncResult(PGconn *conn)
char * PQresultErrorField(const PGresult *res, int fieldcode)
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 pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
int pqPutnchar(const char *s, size_t len, 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[]
@ 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
char * oauth_discovery_uri
void * scram_server_key_binary
PGTransactionStatusType xactStatus
const pg_fe_sasl_mech * sasl
size_t scram_client_key_len
char * ssl_max_protocol_version
PGTernaryBool in_hot_standby
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
void * scram_client_key_binary
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)