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"
194 {
"service",
"PGSERVICE", NULL, NULL,
195 "Database-Service",
"", 20,
196 offsetof(
struct pg_conn, pgservice)},
198 {
"user",
"PGUSER", NULL, NULL,
199 "Database-User",
"", 20,
200 offsetof(
struct pg_conn, pguser)},
202 {
"password",
"PGPASSWORD", NULL, NULL,
203 "Database-Password",
"*", 20,
204 offsetof(
struct pg_conn, pgpass)},
206 {
"passfile",
"PGPASSFILE", NULL, NULL,
207 "Database-Password-File",
"", 64,
208 offsetof(
struct pg_conn, pgpassfile)},
211 "Channel-Binding",
"", 8,
212 offsetof(
struct pg_conn, channel_binding)},
214 {
"connect_timeout",
"PGCONNECT_TIMEOUT", NULL, NULL,
215 "Connect-timeout",
"", 10,
216 offsetof(
struct pg_conn, connect_timeout)},
218 {
"dbname",
"PGDATABASE", NULL, NULL,
219 "Database-Name",
"", 20,
222 {
"host",
"PGHOST", NULL, NULL,
223 "Database-Host",
"", 40,
226 {
"hostaddr",
"PGHOSTADDR", NULL, NULL,
227 "Database-Host-IP-Address",
"", 45,
228 offsetof(
struct pg_conn, pghostaddr)},
230 {
"port",
"PGPORT", DEF_PGPORT_STR, NULL,
231 "Database-Port",
"", 6,
234 {
"client_encoding",
"PGCLIENTENCODING", NULL, NULL,
235 "Client-Encoding",
"", 10,
236 offsetof(
struct pg_conn, client_encoding_initial)},
239 "Backend-Options",
"", 40,
240 offsetof(
struct pg_conn, pgoptions)},
242 {
"application_name",
"PGAPPNAME", NULL, NULL,
243 "Application-Name",
"", 64,
244 offsetof(
struct pg_conn, appname)},
246 {
"fallback_application_name", NULL, NULL, NULL,
247 "Fallback-Application-Name",
"", 64,
248 offsetof(
struct pg_conn, fbappname)},
250 {
"keepalives", NULL, NULL, NULL,
251 "TCP-Keepalives",
"", 1,
252 offsetof(
struct pg_conn, keepalives)},
254 {
"keepalives_idle", NULL, NULL, NULL,
255 "TCP-Keepalives-Idle",
"", 10,
256 offsetof(
struct pg_conn, keepalives_idle)},
258 {
"keepalives_interval", NULL, NULL, NULL,
259 "TCP-Keepalives-Interval",
"", 10,
260 offsetof(
struct pg_conn, keepalives_interval)},
262 {
"keepalives_count", NULL, NULL, NULL,
263 "TCP-Keepalives-Count",
"", 10,
264 offsetof(
struct pg_conn, keepalives_count)},
266 {
"tcp_user_timeout", NULL, NULL, NULL,
267 "TCP-User-Timeout",
"", 10,
268 offsetof(
struct pg_conn, pgtcp_user_timeout)},
278 offsetof(
struct pg_conn, sslmode)},
281 "SSL-Negotiation",
"", 9,
282 offsetof(
struct pg_conn, sslnegotiation)},
284 {
"sslcompression",
"PGSSLCOMPRESSION",
"0", NULL,
285 "SSL-Compression",
"", 1,
286 offsetof(
struct pg_conn, sslcompression)},
288 {
"sslcert",
"PGSSLCERT", NULL, NULL,
289 "SSL-Client-Cert",
"", 64,
290 offsetof(
struct pg_conn, sslcert)},
292 {
"sslkey",
"PGSSLKEY", NULL, NULL,
293 "SSL-Client-Key",
"", 64,
294 offsetof(
struct pg_conn, sslkey)},
296 {
"sslcertmode",
"PGSSLCERTMODE", NULL, NULL,
297 "SSL-Client-Cert-Mode",
"", 8,
298 offsetof(
struct pg_conn, sslcertmode)},
300 {
"sslpassword", NULL, NULL, NULL,
301 "SSL-Client-Key-Password",
"*", 20,
302 offsetof(
struct pg_conn, sslpassword)},
304 {
"sslrootcert",
"PGSSLROOTCERT", NULL, NULL,
305 "SSL-Root-Certificate",
"", 64,
306 offsetof(
struct pg_conn, sslrootcert)},
308 {
"sslcrl",
"PGSSLCRL", NULL, NULL,
309 "SSL-Revocation-List",
"", 64,
310 offsetof(
struct pg_conn, sslcrl)},
312 {
"sslcrldir",
"PGSSLCRLDIR", NULL, NULL,
313 "SSL-Revocation-List-Dir",
"", 64,
314 offsetof(
struct pg_conn, sslcrldir)},
316 {
"sslsni",
"PGSSLSNI",
"1", NULL,
318 offsetof(
struct pg_conn, sslsni)},
320 {
"requirepeer",
"PGREQUIREPEER", NULL, NULL,
321 "Require-Peer",
"", 10,
322 offsetof(
struct pg_conn, requirepeer)},
324 {
"require_auth",
"PGREQUIREAUTH", NULL, NULL,
325 "Require-Auth",
"", 14,
326 offsetof(
struct pg_conn, require_auth)},
328 {
"min_protocol_version",
"PGMINPROTOCOLVERSION",
330 "Min-Protocol-Version",
"", 6,
331 offsetof(
struct pg_conn, min_protocol_version)},
333 {
"max_protocol_version",
"PGMAXPROTOCOLVERSION",
335 "Max-Protocol-Version",
"", 6,
336 offsetof(
struct pg_conn, max_protocol_version)},
338 {
"ssl_min_protocol_version",
"PGSSLMINPROTOCOLVERSION",
"TLSv1.2", NULL,
339 "SSL-Minimum-Protocol-Version",
"", 8,
342 {
"ssl_max_protocol_version",
"PGSSLMAXPROTOCOLVERSION", NULL, NULL,
343 "SSL-Maximum-Protocol-Version",
"", 8,
351 "GSSENC-Mode",
"", 8,
352 offsetof(
struct pg_conn, gssencmode)},
355 {
"krbsrvname",
"PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
356 "Kerberos-service-name",
"", 20,
357 offsetof(
struct pg_conn, krbsrvname)},
359 {
"gsslib",
"PGGSSLIB", NULL, NULL,
360 "GSS-library",
"", 7,
361 offsetof(
struct pg_conn, gsslib)},
363 {
"gssdelegation",
"PGGSSDELEGATION",
"0", NULL,
364 "GSS-delegation",
"", 1,
365 offsetof(
struct pg_conn, gssdelegation)},
367 {
"replication", NULL, NULL, NULL,
368 "Replication",
"D", 5,
369 offsetof(
struct pg_conn, replication)},
371 {
"target_session_attrs",
"PGTARGETSESSIONATTRS",
373 "Target-Session-Attrs",
"", 15,
374 offsetof(
struct pg_conn, target_session_attrs)},
376 {
"load_balance_hosts",
"PGLOADBALANCEHOSTS",
378 "Load-Balance-Hosts",
"", 8,
379 offsetof(
struct pg_conn, load_balance_hosts)},
381 {
"scram_client_key", NULL, NULL, NULL,
"SCRAM-Client-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
382 offsetof(
struct pg_conn, scram_client_key)},
384 {
"scram_server_key", NULL, NULL, NULL,
"SCRAM-Server-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
385 offsetof(
struct pg_conn, scram_server_key)},
388 {
"oauth_issuer", NULL, NULL, NULL,
389 "OAuth-Issuer",
"", 40,
390 offsetof(
struct pg_conn, oauth_issuer)},
392 {
"oauth_client_id", NULL, NULL, NULL,
393 "OAuth-Client-ID",
"", 40,
394 offsetof(
struct pg_conn, oauth_client_id)},
396 {
"oauth_client_secret", NULL, NULL, NULL,
397 "OAuth-Client-Secret",
"", 40,
398 offsetof(
struct pg_conn, oauth_client_secret)},
400 {
"oauth_scope", NULL, NULL, NULL,
401 "OAuth-Scope",
"", 15,
402 offsetof(
struct pg_conn, oauth_scope)},
404 {
"sslkeylogfile", NULL, NULL, NULL,
405 "SSL-Key-Log-File",
"D", 64,
406 offsetof(
struct pg_conn, sslkeylogfile)},
409 {NULL, NULL, NULL, NULL,
417 "PGDATESTYLE",
"datestyle"
436#define SASL_MECHANISM_COUNT lengthof(supported_sasl_mechs)
444#if defined(USE_SSL) || defined(ENABLE_GSS)
445static int encryption_negotiation_failed(
PGconn *
conn);
465 bool use_defaults,
int expand_dbname);
478 const char *keyword);
480 const char *keyword,
const char *
value,
481 PQExpBuffer errorMessage,
bool ignoreMissing,
bool uri_decode);
483 const char *keyword);
495 const char *
username,
const char *pgpassfile);
561 if (
conn->gcred != GSS_C_NO_CREDENTIAL)
563 gss_release_cred(&min_s, &
conn->gcred);
564 conn->gcred = GSS_C_NO_CREDENTIAL;
567 gss_delete_sec_context(&min_s, &
conn->gctx, GSS_C_NO_BUFFER);
569 gss_release_name(&min_s, &
conn->gtarg_nam);
570 if (
conn->gss_SendBuffer)
573 conn->gss_SendBuffer = NULL;
575 if (
conn->gss_RecvBuffer)
578 conn->gss_RecvBuffer = NULL;
580 if (
conn->gss_ResultBuffer)
583 conn->gss_ResultBuffer = NULL;
585 conn->gssenc =
false;
589 if (
conn->sspitarget)
592 conn->sspitarget = NULL;
596 FreeCredentialsHandle(
conn->sspicred);
598 conn->sspicred = NULL;
602 DeleteSecurityContext(
conn->sspictx);
604 conn->sspictx = NULL;
622 while (queue != NULL)
653 while (notify != NULL)
657 notify = notify->
next;
664 while (pstatus != NULL)
668 pstatus = pstatus->
next;
759 const char *
const *
values,
777 const char *
const *
values,
861 const char *
const *
values,
881 true, expand_dbname);
882 if (connOptions == NULL)
999 char **connmember = (
char **) ((
char *)
conn +
option->connofs);
1002 *connmember = strdup(tmp);
1003 if (*connmember == NULL)
1032 if (
option->connofs >= 0)
1034 const char **tmp = (
const char **) ((
char *) srcConn +
option->connofs);
1038 char **dstConnmember = (
char **) ((
char *) dstConn +
option->connofs);
1041 free(*dstConnmember);
1042 *dstConnmember = strdup(*tmp);
1043 if (*dstConnmember == NULL)
1074 if (connOptions == NULL)
1130 char *s = *startptr;
1139 while (*
e !=
'\0' && *
e !=
',')
1141 *more = (*
e ==
',');
1144 p = (
char *)
malloc(
sizeof(
char) * (
len + 1));
1165 struct timeval tval = {0};
1172 rseed = ((uintptr_t)
conn) ^
1174 ((
uint64) tval.tv_usec) ^
1199 "conn->allowed_sasl_mechs[] is not sufficiently large for holding all supported SASL mechanisms");
1318 else if (ch->
host != NULL && ch->
host[0] !=
'\0')
1342 if (ch->
host == NULL)
1370 if (
i == 1 && !more)
1448 if (pwhost == NULL || pwhost[0] ==
'\0')
1469 bool negated =
false;
1479 for (first =
true, more =
true; more; first =
false)
1534 if (strcmp(method,
"password") == 0)
1538 else if (strcmp(method,
"md5") == 0)
1542 else if (strcmp(method,
"gss") == 0)
1547 else if (strcmp(method,
"sspi") == 0)
1559 else if (strcmp(method,
"scram-sha-256") == 0)
1563 else if (strcmp(method,
"oauth") == 0)
1571 else if (strcmp(method,
"none") == 0)
1600 "require_auth", method);
1641 "internal error: no space in allowed_sasl_mechs");
1692 bool allowed =
false;
1711 if (!negated && allowed)
1713 else if (negated && !allowed)
1842 libpq_append_conn_error(
conn,
"weak sslmode \"%s\" may not be used with sslnegotiation=direct (use \"require\", \"verify-ca\", or \"verify-full\")",
1878 "ssl_min_protocol_version",
1886 "ssl_max_protocol_version",
1929#ifndef HAVE_SSL_CTX_SET_CERT_CB
2003 "target_session_attrs",
2074 "load_balance_hosts",
2201 if (connOptions != NULL)
2229 const char *pgtty,
const char *
dbName,
const char *login,
2291 if (pgoptions && pgoptions[0] !=
'\0')
2299 if (login && login[0] !=
'\0')
2307 if (pwd && pwd[0] !=
'\0')
2348 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_NODELAY,
2373 if (addr->ss_family == AF_INET)
2376 &((
struct sockaddr_in *) addr)->sin_addr.s_addr,
2378 host_addr, host_addr_len) == NULL)
2379 host_addr[0] =
'\0';
2381 else if (addr->ss_family == AF_INET6)
2384 &((
struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
2386 host_addr, host_addr_len) == NULL)
2387 host_addr[0] =
'\0';
2390 host_addr[0] =
'\0';
2406 char service[NI_MAXHOST];
2410 service,
sizeof(service),
2413 libpq_gettext(
"connection to server on socket \"%s\" failed: "),
2418 const char *displayed_host;
2419 const char *displayed_port;
2427 if (displayed_port == NULL || displayed_port[0] ==
'\0')
2428 displayed_port = DEF_PGPORT_STR;
2437 strcmp(displayed_host, host_addr) != 0)
2439 libpq_gettext(
"connection to server at \"%s\" (%s), port %s failed: "),
2440 displayed_host, host_addr,
2444 libpq_gettext(
"connection to server at \"%s\", port %s failed: "),
2488 return val != 0 ? 1 : 0;
2509#ifdef PG_TCP_KEEPALIVE_IDLE
2510 if (setsockopt(
conn->
sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
2511 (
char *) &idle,
sizeof(idle)) < 0)
2517 PG_TCP_KEEPALIVE_IDLE_STR,
2538 "keepalives_interval"))
2544 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPINTVL,
2573 "keepalives_count"))
2579 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPCNT,
2580 (
char *) &count,
sizeof(count)) < 0)
2595#ifdef SIO_KEEPALIVE_VALS
2605 struct tcp_keepalive ka;
2614 ka.keepalivetime = idle * 1000;
2615 ka.keepaliveinterval =
interval * 1000;
2643 "keepalives_interval"))
2649 "WSAIoctl",
"SIO_KEEPALIVE_VALS",
2670 "tcp_user_timeout"))
2676#ifdef TCP_USER_TIMEOUT
2677 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
2678 (
char *) &timeout,
sizeof(timeout)) < 0)
2707 goto connect_errReturn;
2718 "libpq is incorrectly linked to backend functions\n");
2719 goto connect_errReturn;
2784 int last_whichhost = -2;
2785 int last_whichaddr = -2;
2907 bool reset_connection_state_machine =
false;
2908 bool need_new_connection =
false;
2974 reset_connection_state_machine =
true;
2985 struct addrinfo hint;
2986 struct addrinfo *addrlist;
3029 MemSet(&hint, 0,
sizeof(hint));
3030 hint.ai_socktype = SOCK_STREAM;
3031 hint.ai_family = AF_UNSPEC;
3034 if (ch->
port == NULL || ch->
port[0] ==
'\0')
3035 thisport = DEF_PGPORT;
3041 if (thisport < 1 || thisport > 65535)
3055 if (ret || !addrlist)
3064 hint.ai_flags = AI_NUMERICHOST;
3067 if (ret || !addrlist)
3076 hint.ai_family = AF_UNIX;
3092 if (ret || !addrlist)
3136 reset_connection_state_machine =
true;
3141 if (reset_connection_state_machine)
3154 reset_connection_state_machine =
false;
3155 need_new_connection =
true;
3159 if (need_new_connection)
3176 need_new_connection =
false;
3184#define ENCRYPTION_NEGOTIATION_FAILED(msg) \
3186 switch (encryption_negotiation_failed(conn)) \
3189 libpq_append_conn_error(conn, (msg)); \
3190 goto error_return; \
3192 conn->status = CONNECTION_MADE; \
3193 return PGRES_POLLING_WRITING; \
3195 need_new_connection = true; \
3205#define CONNECTION_FAILED() \
3207 if (connection_failed(conn)) \
3209 need_new_connection = true; \
3213 goto error_return; \
3230 char host_addr[NI_MAXHOST];
3260 "GSSAPI encryption required but it is not supported over a local socket");
3263 if (
conn->gcred == GSS_C_NO_CREDENTIAL)
3268 "GSSAPI encryption required but no credential cache");
3299 sock_type = SOCK_STREAM;
3308 sock_type |= SOCK_CLOEXEC;
3316 sock_type |= SOCK_NONBLOCK;
3355 if (addr_cur->
family != AF_UNIX)
3364#ifndef SOCK_NONBLOCK
3376 if (fcntl(
conn->
sock, F_SETFD, FD_CLOEXEC) == -1)
3386 if (addr_cur->
family != AF_UNIX)
3394 if (usekeepalives < 0)
3399 else if (usekeepalives == 0)
3405 SOL_SOCKET, SO_KEEPALIVE,
3406 (
char *) &on,
sizeof(on)) < 0)
3419#ifdef SIO_KEEPALIVE_VALS
3420 else if (!prepKeepalivesWin32(
conn))
3466 if (setsockopt(
conn->
sock, SOL_SOCKET, SO_NOSIGPIPE,
3467 (
char *) &optval,
sizeof(optval)) == 0)
3532 if (getsockopt(
conn->
sock, SOL_SOCKET, SO_ERROR,
3533 (
char *) &optval, &optlen) == -1)
3539 else if (optval != 0)
3575 char *remote_username;
3587 if (errno == ENOSYS)
3598 if (remote_username == NULL)
3605 free(remote_username);
3608 free(remote_username);
3796 else if (SSLok ==
'N')
3811 else if (SSLok ==
'E')
3885 else if (rdresult == 0)
3927 else if (gss_ok !=
'G')
4038 (msgLength < 8 || msgLength > 2000))
4044 (msgLength < 8 || msgLength > 2000))
4050#define MAX_ERRLEN 30000
4100 if (avail < msgLength)
4211 need_new_connection =
true;
4251 "internal error: async authentication has no handler");
4276 "internal error: async cleanup did not release polling socket");
4299 "internal error: async authentication did not set a socket for polling");
4346 const char *sqlstate;
4354 need_new_connection =
true;
4386 bool read_only_server;
4406 "SHOW transaction_read_only"))
4419 read_only_server : !read_only_server)
4464 "SELECT pg_catalog.pg_is_in_recovery()"))
4584 if (strncmp(
val,
"on", 2) == 0)
4606 "SHOW transaction_read_only");
4640 if (strncmp(
val,
"t", 1) == 0)
4656 "SELECT pg_is_in_recovery()");
4669 "invalid connection state %d, probably indicative of memory corruption",
4707 "GSSAPI encryption required but it is not supported over a local socket");
4756#if defined(USE_SSL) || defined(ENABLE_GSS)
4800 int remaining_methods;
4802#define SELECT_NEXT_METHOD(method) \
4804 if ((remaining_methods & method) != 0) \
4806 conn->current_enc_method = method; \
4831 remaining_methods &= ~ENC_GSSAPI;
4836 "GSSAPI encryption required but no credential cache");
4863#undef SELECT_NEXT_METHOD
4950 static bool wsastartup_done =
false;
4952 if (!wsastartup_done)
4956 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
4958 wsastartup_done =
true;
5158 struct addrinfo *ai = addrlist;
5399 const void *
buf,
size_t buf_len)
5422#define LDAP_URL "ldap://"
5423#define LDAP_DEF_PORT 389
5424#define PGLDAP_TIMEOUT 2
5426#define ld_is_sp_tab(x) ((x) == ' ' || (x) == '\t')
5427#define ld_is_nl_cr(x) ((x) == '\r' || (x) == '\n')
5453 int port = LDAP_DEF_PORT,
5476 char *attrs[2] = {NULL, NULL};
5481 LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0};
5483 if ((url = strdup(purl)) == NULL)
5498 "invalid LDAP URL \"%s\": scheme must be ldap://", purl);
5509 p = strchr(url + strlen(LDAP_URL),
'/');
5510 if (p == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5513 "invalid LDAP URL \"%s\": missing distinguished name",
5522 if ((p = strchr(dn,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5525 "invalid LDAP URL \"%s\": must have exactly one attribute",
5534 if ((p = strchr(attrs[0],
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5537 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5546 if ((p = strchr(scopestr,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5549 "invalid LDAP URL \"%s\": no filter",
5556 if ((p = strchr(filter,
'?')) != NULL)
5560 if ((p1 = strchr(
hostname,
':')) != NULL)
5567 lport = strtol(
portstr, &endptr, 10);
5568 if (*
portstr ==
'\0' || *endptr !=
'\0' || errno || lport < 0 || lport > 65535)
5571 "invalid LDAP URL \"%s\": invalid port number",
5580 if (strchr(attrs[0],
',') != NULL)
5583 "invalid LDAP URL \"%s\": must have exactly one attribute",
5591 scope = LDAP_SCOPE_BASE;
5593 scope = LDAP_SCOPE_ONELEVEL;
5595 scope = LDAP_SCOPE_SUBTREE;
5599 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5627 if (ldap_connect(ld, &time) != LDAP_SUCCESS)
5636 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5644 if ((msgid = ldap_simple_bind(ld, NULL, NULL)) == -1)
5654 if ((rc = ldap_result(ld, msgid, LDAP_MSG_ALL, &time, &res)) == -1 ||
5668 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5678 if ((rc = ldap_search_st(ld, dn, scope, filter, attrs, 0, &time, &res))
5683 libpq_append_error(errorMessage,
"lookup on LDAP server failed: %s", ldap_err2string(rc));
5690 if ((rc = ldap_count_entries(ld, res)) != 1)
5703 if ((entry = ldap_first_entry(ld, res)) == NULL)
5714 if ((
values = ldap_get_values_len(ld, entry, attrs[0])) == NULL)
5729 ldap_value_free_len(
values);
5737 size +=
values[
i]->bv_len + 1;
5738 if ((result =
malloc(size)) == NULL)
5741 ldap_value_free_len(
values);
5754 ldap_value_free_len(
values);
5758 oldstate =
state = 0;
5759 for (p = result; *p !=
'\0'; ++p)
5764 if (!ld_is_sp_tab(*p) && !ld_is_nl_cr(*p))
5771 if (ld_is_sp_tab(*p))
5776 else if (ld_is_nl_cr(*p))
5779 "missing \"=\" after \"%s\" in connection info string",
5795 else if (!ld_is_sp_tab(*p))
5798 "missing \"=\" after \"%s\" in connection info string",
5811 else if (ld_is_nl_cr(*p))
5813 optval = optname + strlen(optname);
5816 else if (!ld_is_sp_tab(*p))
5823 if (ld_is_sp_tab(*p) || ld_is_nl_cr(*p))
5835 else if (*p ==
'\\')
5846 if (
state == 0 && oldstate != 0)
5848 found_keyword =
false;
5851 if (strcmp(
options[
i].keyword, optname) == 0)
5863 found_keyword =
true;
5884 "unterminated quoted string in connection info string");
5909 bool group_found =
false;
5911 struct stat stat_buf;
5918 if (service == NULL)
5919 service = getenv(
"PGSERVICE");
5922 if (service == NULL)
5929 if ((env = getenv(
"PGSERVICEFILE")) != NULL)
5930 strlcpy(serviceFile, env,
sizeof(serviceFile));
5938 if (
stat(serviceFile, &stat_buf) != 0)
5943 if (group_found || status != 0)
5953 getenv(
"PGSYSCONFDIR") ? getenv(
"PGSYSCONFDIR") : SYSCONFDIR);
5954 if (
stat(serviceFile, &stat_buf) != 0)
5973 const char *service,
5985 *group_found =
false;
5987 f = fopen(serviceFile,
"r");
5994 while ((line = fgets(
buf,
sizeof(
buf), f)) != NULL)
6000 if (strlen(line) >=
sizeof(
buf) - 1)
6003 "line %d too long in service file \"%s\"",
6012 while (
len > 0 && isspace((
unsigned char) line[
len - 1]))
6016 while (*line && isspace((
unsigned char) line[0]))
6020 if (line[0] ==
'\0' || line[0] ==
'#')
6032 if (strncmp(line + 1, service, strlen(service)) == 0 &&
6033 line[strlen(service) + 1] ==
']')
6034 *group_found =
true;
6036 *group_found =
false;
6050 if (strncmp(line,
"ldap", 4) == 0)
6052 int rc = ldapServiceLookup(line,
options, errorMessage);
6070 val = strchr(line,
'=');
6074 "syntax error in service file \"%s\", line %d",
6082 if (strcmp(
key,
"service") == 0)
6085 "nested service specifications not supported in service file \"%s\", line %d",
6096 found_keyword =
false;
6109 found_keyword =
true;
6117 "syntax error in service file \"%s\", line %d",
6161 if (connOptions == NULL &&
errmsg)
6281 if ((
buf = strdup(conninfo)) == NULL)
6292 if (isspace((
unsigned char) *cp))
6304 if (isspace((
unsigned char) *cp))
6309 if (!isspace((
unsigned char) *cp))
6322 "missing \"=\" after \"%s\" in connection info string",
6333 if (!isspace((
unsigned char) *cp))
6346 if (isspace((
unsigned char) *cp))
6370 libpq_append_error(errorMessage,
"unterminated quoted string in connection info string");
6457 const char *pvalue =
values[
i];
6460 if (strcmp(pname,
"dbname") == 0 && pvalue)
6470 if (dbname_options == NULL)
6491 const char *pvalue =
values[
i];
6493 if (pvalue != NULL && pvalue[0] !=
'\0')
6498 if (strcmp(
option->keyword, pname) == 0)
6503 if (
option->keyword == NULL)
6516 if (strcmp(pname,
"dbname") == 0 && dbname_options)
6520 for (str_option = dbname_options; str_option->
keyword != NULL; str_option++)
6522 if (str_option->
val != NULL)
6526 for (k = 0;
options[k].keyword; k++)
6550 dbname_options = NULL;
6603 *sslrootcert = NULL;
6620 if (strcmp(
option->keyword,
"sslrootcert") == 0)
6629 if (
option->envvar != NULL)
6631 if ((tmp = getenv(
option->envvar)) != NULL)
6650 if (strcmp(
option->keyword,
"sslmode") == 0)
6652 const char *requiresslenv = getenv(
"PGREQUIRESSL");
6654 if (requiresslenv != NULL && requiresslenv[0] ==
'1')
6671 sslmode_default =
option;
6678 if (
option->compiled != NULL)
6697 if (strcmp(
option->keyword,
"user") == 0)
6709 if (sslmode_default && sslrootcert)
6711 if (sslrootcert->val && strcmp(sslrootcert->val,
"system") == 0)
6715 sslmode_default->
val = strdup(
"verify-full");
6716 if (!sslmode_default->
val)
6794 char prevchar =
'\0';
6797 bool retval =
false;
6820 if (prefix_len == 0)
6824 "invalid URI propagated to internal parser routine: \"%s\"",
6828 start += prefix_len;
6832 while (*p && *p !=
'@' && *p !=
'/')
6843 while (*p !=
':' && *p !=
'@')
6852 errorMessage,
false,
true))
6855 if (prevchar ==
':')
6865 errorMessage,
false,
true))
6896 while (*p && *p !=
']')
6901 "end of string reached when looking for matching \"]\" in IPv6 host address in URI: \"%s\"",
6908 "IPv6 host address may not be empty in URI: \"%s\"",
6920 if (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
6923 "unexpected character \"%c\" at position %d in URI (expected \":\" or \"/\"): \"%s\"",
6924 *p, (
int) (p -
buf + 1), uri);
6937 while (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
6947 if (prevchar ==
':')
6949 const char *
port = ++p;
6951 while (*p && *p !=
'/' && *p !=
'?' && *p !=
',')
6960 if (prevchar !=
',')
6970 if (hostbuf.
data[0] &&
6972 errorMessage,
false,
true))
6974 if (portbuf.
data[0] &&
6976 errorMessage,
false,
true))
6979 if (prevchar && prevchar !=
'?')
6981 const char *
dbname = ++p;
6984 while (*p && *p !=
'?')
6997 errorMessage,
false,
true))
7034 char *keyword = params;
7037 bool malloced =
false;
7052 "extra key/value separator \"=\" in URI query parameter: \"%s\"",
7060 else if (*p ==
'&' || *p ==
'\0')
7072 "missing key/value separator \"=\" in URI query parameter: \"%s\"",
7084 if (keyword == NULL)
7101 if (strcmp(keyword,
"ssl") == 0 &&
7102 strcmp(
value,
"true") == 0)
7108 keyword =
"sslmode";
7117 oldmsglen = errorMessage->
len;
7119 errorMessage,
true,
false))
7122 if (errorMessage->
len == oldmsglen)
7124 "invalid URI query parameter: \"%s\"",
7165 const char *q =
str;
7176 for (
const char *s = q; *s ==
' '; s++)
7187 if (*q ==
' ' || *q ==
'\0')
7208 "invalid percent-encoded token: \"%s\"",
7218 "forbidden value %%00 in percent-encoded value: \"%s\"",
7230 for (
const char *s = q; *s ==
' '; s++)
7240 "unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead",
7263 if (
'0' <= digit && digit <=
'9')
7264 *
value = digit -
'0';
7265 else if (
'A' <= digit && digit <=
'F')
7266 *
value = digit -
'A' + 10;
7267 else if (
'a' <= digit && digit <=
'f')
7268 *
value = digit -
'a' + 10;
7283 const char *keyword)
7309 const char *keyword,
const char *
value,
7321 if (strcmp(keyword,
"requiressl") == 0)
7323 keyword =
"sslmode";
7324 if (
value[0] ==
'1')
7335 "invalid connection option \"%s\"",
7343 if (value_copy == NULL)
7349 value_copy = strdup(
value);
7350 if (value_copy == NULL)
7378 if (strcmp(
option->keyword, keyword) == 0)
7408 if (connOptions != NULL)
7419 connmember = (
char **) ((
char *)
conn +
option->connofs);
7423 &errorBuf,
true,
false);
7436 if (connOptions == NULL)
7578 if (!
conn || !paramName)
7580 for (pstatus =
conn->
pstatus; pstatus != NULL; pstatus = pstatus->
next)
7582 if (strcmp(pstatus->
name, paramName) == 0)
7583 return pstatus->
value;
7720 static const char query[] =
"set client_encoding to '%s'";
7735 if (
sizeof(qbuf) < (
sizeof(query) + strlen(
encoding)))
7842 fprintf(stderr,
"%s", message);
7854 bool bslash =
false;
7860 if (tbuf[0] ==
'*' && tbuf[1] ==
':')
7864 if (*tbuf ==
'\\' && !bslash)
7869 if (*tbuf ==
':' && *ttok == 0 && !bslash)
7888 const char *
username,
const char *pgpassfile)
7892 struct stat stat_buf;
7914 if (
port == NULL ||
port[0] ==
'\0')
7915 port = DEF_PGPORT_STR;
7918 fp = fopen(pgpassfile,
"r");
7923 if (
fstat(fileno(fp), &stat_buf) != 0)
7932 libpq_gettext(
"WARNING: password file \"%s\" is not a plain file\n"),
7942 libpq_gettext(
"WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n"),
7958 while (!feof(fp) && !ferror(fp))
7965 if (fgets(
buf.data +
buf.len,
buf.maxlen -
buf.len, fp) == NULL)
7970 if (!(
buf.len > 0 &&
buf.data[
buf.len - 1] ==
'\n') && !feof(fp))
7974 if (
buf.data[0] !=
'#')
8006 for (p1 = p2 = ret; *p1 !=
':' && *p1 !=
'\0'; ++p1, ++p2)
8008 if (*p1 ==
'\\' && p1[1] !=
'\0')
8063 if (!version || strlen(version) == 0)
8089 if (min == NULL || max == NULL || strlen(min) == 0 || strlen(max) == 0)
8141 home = getenv(
"HOME");
8142 if (home && home[0])
8149 struct passwd pwbuf;
8154 rc = getpwuid_r(geteuid(), &pwbuf,
tmpbuf,
sizeof tmpbuf, &pw);
8161 char tmppath[MAX_PATH];
8163 ZeroMemory(tmppath,
sizeof(tmppath));
8164 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, tmppath) != S_OK)
8178 const char *context)
8189 numval = strtol(
value, &end, 10);
8195 if (
value == end || errno != 0 || numval != (
int) numval)
8202 while (*end !=
'\0' && isspace((
unsigned char) *end))
8223 const char *context)
8225 if (strcmp(
value,
"latest") == 0)
8230 if (strcmp(
value,
"3.0") == 0)
8238 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,...)
void libpq_append_conn_error(PGconn *conn, 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)
#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)