36#include "pg_config_paths.h"
44#define _WIN32_IE 0x0500
70#define LDAP_DEPRECATED 1
72typedef struct timeval LDAP_TIMEVAL;
79#define PGPASSFILE ".pgpass"
81#define PGPASSFILE "pgpass.conf"
90#define ERRCODE_APPNAME_UNKNOWN "42704"
93#define ERRCODE_INVALID_PASSWORD "28P01"
95#define ERRCODE_CANNOT_CONNECT_NOW "57P03"
101#if defined(TCP_KEEPIDLE)
103#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPIDLE
104#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPIDLE"
105#elif defined(TCP_KEEPALIVE_THRESHOLD)
107#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE_THRESHOLD
108#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE_THRESHOLD"
109#elif defined(TCP_KEEPALIVE) && defined(__darwin__)
112#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE
113#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE"
120#define DefaultHost "localhost"
121#define DefaultOption ""
123#define DefaultChannelBinding "prefer"
125#define DefaultChannelBinding "disable"
127#define DefaultTargetSessionAttrs "any"
128#define DefaultLoadBalanceHosts "disable"
130#define DefaultSSLMode "prefer"
131#define DefaultSSLCertMode "allow"
133#define DefaultSSLMode "disable"
134#define DefaultSSLCertMode "disable"
136#define DefaultSSLNegotiation "postgres"
139#define DefaultGSSMode "prefer"
141#define DefaultGSSMode "disable"
201 {
"service",
"PGSERVICE", NULL, NULL,
202 "Database-Service",
"", 20,
203 offsetof(
struct pg_conn, pgservice)},
205 {
"servicefile",
"PGSERVICEFILE", NULL, NULL,
206 "Database-Service-File",
"", 64,
207 offsetof(
struct pg_conn, pgservicefile)},
209 {
"user",
"PGUSER", NULL, NULL,
210 "Database-User",
"", 20,
211 offsetof(
struct pg_conn, pguser)},
213 {
"password",
"PGPASSWORD", NULL, NULL,
214 "Database-Password",
"*", 20,
215 offsetof(
struct pg_conn, pgpass)},
217 {
"passfile",
"PGPASSFILE", NULL, NULL,
218 "Database-Password-File",
"", 64,
219 offsetof(
struct pg_conn, pgpassfile)},
222 "Channel-Binding",
"", 8,
223 offsetof(
struct pg_conn, channel_binding)},
225 {
"connect_timeout",
"PGCONNECT_TIMEOUT", NULL, NULL,
226 "Connect-timeout",
"", 10,
227 offsetof(
struct pg_conn, connect_timeout)},
229 {
"dbname",
"PGDATABASE", NULL, NULL,
230 "Database-Name",
"", 20,
233 {
"host",
"PGHOST", NULL, NULL,
234 "Database-Host",
"", 40,
237 {
"hostaddr",
"PGHOSTADDR", NULL, NULL,
238 "Database-Host-IP-Address",
"", 45,
239 offsetof(
struct pg_conn, pghostaddr)},
241 {
"port",
"PGPORT", DEF_PGPORT_STR, NULL,
242 "Database-Port",
"", 6,
245 {
"client_encoding",
"PGCLIENTENCODING", NULL, NULL,
246 "Client-Encoding",
"", 10,
247 offsetof(
struct pg_conn, client_encoding_initial)},
250 "Backend-Options",
"", 40,
251 offsetof(
struct pg_conn, pgoptions)},
253 {
"application_name",
"PGAPPNAME", NULL, NULL,
254 "Application-Name",
"", 64,
255 offsetof(
struct pg_conn, appname)},
257 {
"fallback_application_name", NULL, NULL, NULL,
258 "Fallback-Application-Name",
"", 64,
259 offsetof(
struct pg_conn, fbappname)},
261 {
"keepalives", NULL, NULL, NULL,
262 "TCP-Keepalives",
"", 1,
263 offsetof(
struct pg_conn, keepalives)},
265 {
"keepalives_idle", NULL, NULL, NULL,
266 "TCP-Keepalives-Idle",
"", 10,
267 offsetof(
struct pg_conn, keepalives_idle)},
269 {
"keepalives_interval", NULL, NULL, NULL,
270 "TCP-Keepalives-Interval",
"", 10,
271 offsetof(
struct pg_conn, keepalives_interval)},
273 {
"keepalives_count", NULL, NULL, NULL,
274 "TCP-Keepalives-Count",
"", 10,
275 offsetof(
struct pg_conn, keepalives_count)},
277 {
"tcp_user_timeout", NULL, NULL, NULL,
278 "TCP-User-Timeout",
"", 10,
279 offsetof(
struct pg_conn, pgtcp_user_timeout)},
289 offsetof(
struct pg_conn, sslmode)},
292 "SSL-Negotiation",
"", 9,
293 offsetof(
struct pg_conn, sslnegotiation)},
295 {
"sslcompression",
"PGSSLCOMPRESSION",
"0", NULL,
296 "SSL-Compression",
"", 1,
297 offsetof(
struct pg_conn, sslcompression)},
299 {
"sslcert",
"PGSSLCERT", NULL, NULL,
300 "SSL-Client-Cert",
"", 64,
301 offsetof(
struct pg_conn, sslcert)},
303 {
"sslkey",
"PGSSLKEY", NULL, NULL,
304 "SSL-Client-Key",
"", 64,
305 offsetof(
struct pg_conn, sslkey)},
307 {
"sslcertmode",
"PGSSLCERTMODE", NULL, NULL,
308 "SSL-Client-Cert-Mode",
"", 8,
309 offsetof(
struct pg_conn, sslcertmode)},
311 {
"sslpassword", NULL, NULL, NULL,
312 "SSL-Client-Key-Password",
"*", 20,
313 offsetof(
struct pg_conn, sslpassword)},
315 {
"sslrootcert",
"PGSSLROOTCERT", NULL, NULL,
316 "SSL-Root-Certificate",
"", 64,
317 offsetof(
struct pg_conn, sslrootcert)},
319 {
"sslcrl",
"PGSSLCRL", NULL, NULL,
320 "SSL-Revocation-List",
"", 64,
321 offsetof(
struct pg_conn, sslcrl)},
323 {
"sslcrldir",
"PGSSLCRLDIR", NULL, NULL,
324 "SSL-Revocation-List-Dir",
"", 64,
325 offsetof(
struct pg_conn, sslcrldir)},
327 {
"sslsni",
"PGSSLSNI",
"1", NULL,
329 offsetof(
struct pg_conn, sslsni)},
331 {
"requirepeer",
"PGREQUIREPEER", NULL, NULL,
332 "Require-Peer",
"", 10,
333 offsetof(
struct pg_conn, requirepeer)},
335 {
"require_auth",
"PGREQUIREAUTH", NULL, NULL,
336 "Require-Auth",
"", 14,
337 offsetof(
struct pg_conn, require_auth)},
339 {
"min_protocol_version",
"PGMINPROTOCOLVERSION",
341 "Min-Protocol-Version",
"", 6,
342 offsetof(
struct pg_conn, min_protocol_version)},
344 {
"max_protocol_version",
"PGMAXPROTOCOLVERSION",
346 "Max-Protocol-Version",
"", 6,
347 offsetof(
struct pg_conn, max_protocol_version)},
349 {
"ssl_min_protocol_version",
"PGSSLMINPROTOCOLVERSION",
"TLSv1.2", NULL,
350 "SSL-Minimum-Protocol-Version",
"", 8,
353 {
"ssl_max_protocol_version",
"PGSSLMAXPROTOCOLVERSION", NULL, NULL,
354 "SSL-Maximum-Protocol-Version",
"", 8,
362 "GSSENC-Mode",
"", 8,
363 offsetof(
struct pg_conn, gssencmode)},
366 {
"krbsrvname",
"PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
367 "Kerberos-service-name",
"", 20,
368 offsetof(
struct pg_conn, krbsrvname)},
370 {
"gsslib",
"PGGSSLIB", NULL, NULL,
371 "GSS-library",
"", 7,
372 offsetof(
struct pg_conn, gsslib)},
374 {
"gssdelegation",
"PGGSSDELEGATION",
"0", NULL,
375 "GSS-delegation",
"", 1,
376 offsetof(
struct pg_conn, gssdelegation)},
378 {
"replication", NULL, NULL, NULL,
379 "Replication",
"D", 5,
380 offsetof(
struct pg_conn, replication)},
382 {
"target_session_attrs",
"PGTARGETSESSIONATTRS",
384 "Target-Session-Attrs",
"", 15,
385 offsetof(
struct pg_conn, target_session_attrs)},
387 {
"load_balance_hosts",
"PGLOADBALANCEHOSTS",
389 "Load-Balance-Hosts",
"", 8,
390 offsetof(
struct pg_conn, load_balance_hosts)},
392 {
"scram_client_key", NULL, NULL, NULL,
"SCRAM-Client-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
393 offsetof(
struct pg_conn, scram_client_key)},
395 {
"scram_server_key", NULL, NULL, NULL,
"SCRAM-Server-Key",
"D",
SCRAM_MAX_KEY_LEN * 2,
396 offsetof(
struct pg_conn, scram_server_key)},
399 {
"oauth_issuer", NULL, NULL, NULL,
400 "OAuth-Issuer",
"", 40,
401 offsetof(
struct pg_conn, oauth_issuer)},
403 {
"oauth_client_id", NULL, NULL, NULL,
404 "OAuth-Client-ID",
"", 40,
405 offsetof(
struct pg_conn, oauth_client_id)},
407 {
"oauth_client_secret", NULL, NULL, NULL,
408 "OAuth-Client-Secret",
"*", 40,
409 offsetof(
struct pg_conn, oauth_client_secret)},
411 {
"oauth_scope", NULL, NULL, NULL,
412 "OAuth-Scope",
"", 15,
413 offsetof(
struct pg_conn, oauth_scope)},
415 {
"sslkeylogfile", NULL, NULL, NULL,
416 "SSL-Key-Log-File",
"D", 64,
417 offsetof(
struct pg_conn, sslkeylogfile)},
420 {NULL, NULL, NULL, NULL,
428 "PGDATESTYLE",
"datestyle"
447#define SASL_MECHANISM_COUNT lengthof(supported_sasl_mechs)
455#if defined(USE_SSL) || defined(ENABLE_GSS)
456static int encryption_negotiation_failed(
PGconn *
conn);
476 bool use_defaults,
int expand_dbname);
489 const char *keyword);
491 const char *keyword,
const char *
value,
492 PQExpBuffer errorMessage,
bool ignoreMissing,
bool uri_decode);
494 const char *keyword);
507 const char *pgpassfile,
const char **
errmsg);
573 if (
conn->gcred != GSS_C_NO_CREDENTIAL)
575 gss_release_cred(&min_s, &
conn->gcred);
576 conn->gcred = GSS_C_NO_CREDENTIAL;
579 gss_delete_sec_context(&min_s, &
conn->gctx, GSS_C_NO_BUFFER);
581 gss_release_name(&min_s, &
conn->gtarg_nam);
582 if (
conn->gss_SendBuffer)
585 conn->gss_SendBuffer = NULL;
587 if (
conn->gss_RecvBuffer)
590 conn->gss_RecvBuffer = NULL;
592 if (
conn->gss_ResultBuffer)
595 conn->gss_ResultBuffer = NULL;
597 conn->gssenc =
false;
601 if (
conn->sspitarget)
604 conn->sspitarget = NULL;
608 FreeCredentialsHandle(
conn->sspicred);
610 conn->sspicred = NULL;
614 DeleteSecurityContext(
conn->sspictx);
616 conn->sspictx = NULL;
634 while (queue != NULL)
665 while (notify != NULL)
669 notify = notify->
next;
676 while (pstatus != NULL)
680 pstatus = pstatus->
next;
771 const char *
const *
values,
789 const char *
const *
values,
873 const char *
const *
values,
893 true, expand_dbname);
894 if (connOptions == NULL)
1005 if (
option->connofs >= 0)
1011 char **connmember = (
char **) ((
char *)
conn +
option->connofs);
1014 *connmember = strdup(tmp);
1015 if (*connmember == NULL)
1044 if (
option->connofs >= 0)
1046 const char **tmp = (
const char **) ((
char *) srcConn +
option->connofs);
1050 char **dstConnmember = (
char **) ((
char *) dstConn +
option->connofs);
1053 free(*dstConnmember);
1054 *dstConnmember = strdup(*tmp);
1055 if (*dstConnmember == NULL)
1086 if (connOptions == NULL)
1142 char *s = *startptr;
1151 while (*
e !=
'\0' && *
e !=
',')
1153 *more = (*
e ==
',');
1156 p = (
char *)
malloc(
sizeof(
char) * (
len + 1));
1177 struct timeval tval = {0};
1184 rseed = ((uintptr_t)
conn) ^
1186 ((
uint64) tval.tv_usec) ^
1211 "conn->allowed_sasl_mechs[] is not sufficiently large for holding all supported SASL mechanisms");
1330 else if (ch->
host != NULL && ch->
host[0] !=
'\0')
1354 if (ch->
host == NULL)
1382 if (
i == 1 && !more)
1459 const char *password_errmsg = NULL;
1461 if (pwhost == NULL || pwhost[0] ==
'\0')
1472 if (password_errmsg != NULL)
1490 bool negated =
false;
1500 for (first =
true, more =
true; more; first =
false)
1555 if (strcmp(method,
"password") == 0)
1559 else if (strcmp(method,
"md5") == 0)
1563 else if (strcmp(method,
"gss") == 0)
1568 else if (strcmp(method,
"sspi") == 0)
1580 else if (strcmp(method,
"scram-sha-256") == 0)
1584 else if (strcmp(method,
"oauth") == 0)
1592 else if (strcmp(method,
"none") == 0)
1621 "require_auth", method);
1662 "internal error: no space in allowed_sasl_mechs");
1713 bool allowed =
false;
1732 if (!negated && allowed)
1734 else if (negated && !allowed)
1863 libpq_append_conn_error(
conn,
"weak sslmode \"%s\" may not be used with sslnegotiation=direct (use \"require\", \"verify-ca\", or \"verify-full\")",
1899 "ssl_min_protocol_version",
1907 "ssl_max_protocol_version",
1950#ifndef HAVE_SSL_CTX_SET_CERT_CB
2024 "target_session_attrs",
2091 "load_balance_hosts",
2218 if (connOptions != NULL)
2246 const char *pgtty,
const char *
dbName,
const char *login,
2308 if (pgoptions && pgoptions[0] !=
'\0')
2316 if (login && login[0] !=
'\0')
2324 if (pwd && pwd[0] !=
'\0')
2365 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_NODELAY,
2390 if (addr->ss_family == AF_INET)
2393 &((
struct sockaddr_in *) addr)->sin_addr.s_addr,
2395 host_addr, host_addr_len) == NULL)
2396 host_addr[0] =
'\0';
2398 else if (addr->ss_family == AF_INET6)
2401 &((
struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
2403 host_addr, host_addr_len) == NULL)
2404 host_addr[0] =
'\0';
2407 host_addr[0] =
'\0';
2423 char service[NI_MAXHOST];
2427 service,
sizeof(service),
2430 libpq_gettext(
"connection to server on socket \"%s\" failed: "),
2435 const char *displayed_host;
2436 const char *displayed_port;
2444 if (displayed_port == NULL || displayed_port[0] ==
'\0')
2445 displayed_port = DEF_PGPORT_STR;
2454 strcmp(displayed_host, host_addr) != 0)
2456 libpq_gettext(
"connection to server at \"%s\" (%s), port %s failed: "),
2457 displayed_host, host_addr,
2461 libpq_gettext(
"connection to server at \"%s\", port %s failed: "),
2505 return val != 0 ? 1 : 0;
2526#ifdef PG_TCP_KEEPALIVE_IDLE
2527 if (setsockopt(
conn->
sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
2528 (
char *) &idle,
sizeof(idle)) < 0)
2534 PG_TCP_KEEPALIVE_IDLE_STR,
2555 "keepalives_interval"))
2561 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPINTVL,
2590 "keepalives_count"))
2596 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPCNT,
2597 (
char *) &count,
sizeof(count)) < 0)
2612#ifdef SIO_KEEPALIVE_VALS
2622 struct tcp_keepalive ka;
2631 ka.keepalivetime = idle * 1000;
2632 ka.keepaliveinterval =
interval * 1000;
2660 "keepalives_interval"))
2666 "WSAIoctl",
"SIO_KEEPALIVE_VALS",
2687 "tcp_user_timeout"))
2693#ifdef TCP_USER_TIMEOUT
2694 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
2695 (
char *) &timeout,
sizeof(timeout)) < 0)
2724 goto connect_errReturn;
2735 "libpq is incorrectly linked to backend functions\n");
2736 goto connect_errReturn;
2801 int last_whichhost = -2;
2802 int last_whichaddr = -2;
2924 bool reset_connection_state_machine =
false;
2925 bool need_new_connection =
false;
2991 reset_connection_state_machine =
true;
3002 struct addrinfo hint;
3003 struct addrinfo *addrlist;
3046 MemSet(&hint, 0,
sizeof(hint));
3047 hint.ai_socktype = SOCK_STREAM;
3048 hint.ai_family = AF_UNSPEC;
3051 if (ch->
port == NULL || ch->
port[0] ==
'\0')
3052 thisport = DEF_PGPORT;
3058 if (thisport < 1 || thisport > 65535)
3072 if (ret || !addrlist)
3081 hint.ai_flags = AI_NUMERICHOST;
3084 if (ret || !addrlist)
3093 hint.ai_family = AF_UNIX;
3109 if (ret || !addrlist)
3153 reset_connection_state_machine =
true;
3158 if (reset_connection_state_machine)
3171 reset_connection_state_machine =
false;
3172 need_new_connection =
true;
3176 if (need_new_connection)
3193 need_new_connection =
false;
3201#define ENCRYPTION_NEGOTIATION_FAILED(msg) \
3203 switch (encryption_negotiation_failed(conn)) \
3206 libpq_append_conn_error(conn, (msg)); \
3207 goto error_return; \
3209 conn->status = CONNECTION_MADE; \
3210 return PGRES_POLLING_WRITING; \
3212 need_new_connection = true; \
3222#define CONNECTION_FAILED() \
3224 if (connection_failed(conn)) \
3226 need_new_connection = true; \
3230 goto error_return; \
3247 char host_addr[NI_MAXHOST];
3277 "GSSAPI encryption required but it is not supported over a local socket");
3280 if (
conn->gcred == GSS_C_NO_CREDENTIAL)
3285 "GSSAPI encryption required but no credential cache");
3316 sock_type = SOCK_STREAM;
3325 sock_type |= SOCK_CLOEXEC;
3333 sock_type |= SOCK_NONBLOCK;
3372 if (addr_cur->
family != AF_UNIX)
3381#ifndef SOCK_NONBLOCK
3393 if (fcntl(
conn->
sock, F_SETFD, FD_CLOEXEC) == -1)
3403 if (addr_cur->
family != AF_UNIX)
3411 if (usekeepalives < 0)
3416 else if (usekeepalives == 0)
3422 SOL_SOCKET, SO_KEEPALIVE,
3423 (
char *) &on,
sizeof(on)) < 0)
3436#ifdef SIO_KEEPALIVE_VALS
3437 else if (!prepKeepalivesWin32(
conn))
3483 if (setsockopt(
conn->
sock, SOL_SOCKET, SO_NOSIGPIPE,
3484 (
char *) &optval,
sizeof(optval)) == 0)
3549 if (getsockopt(
conn->
sock, SOL_SOCKET, SO_ERROR,
3550 (
char *) &optval, &optlen) == -1)
3556 else if (optval != 0)
3592 char *remote_username;
3604 if (errno == ENOSYS)
3615 if (remote_username == NULL)
3622 free(remote_username);
3625 free(remote_username);
3813 else if (SSLok ==
'N')
3828 else if (SSLok ==
'E')
3902 else if (rdresult == 0)
3944 else if (gss_ok !=
'G')
4055 (msgLength < 8 || msgLength > 2000))
4061 (msgLength < 8 || msgLength > 2000))
4067#define MAX_ERRLEN 30000
4117 if (avail < msgLength)
4228 need_new_connection =
true;
4268 "internal error: async authentication has no handler");
4293 "internal error: async cleanup did not release polling socket");
4316 "internal error: async authentication did not set a socket for polling");
4363 const char *sqlstate;
4371 need_new_connection =
true;
4403 bool read_only_server;
4423 "SHOW transaction_read_only"))
4436 read_only_server : !read_only_server)
4481 "SELECT pg_catalog.pg_is_in_recovery()"))
4601 if (strncmp(
val,
"on", 2) == 0)
4623 "SHOW transaction_read_only");
4657 if (strncmp(
val,
"t", 1) == 0)
4673 "SELECT pg_is_in_recovery()");
4686 "invalid connection state %d, probably indicative of memory corruption",
4724 "GSSAPI encryption required but it is not supported over a local socket");
4773#if defined(USE_SSL) || defined(ENABLE_GSS)
4817 int remaining_methods;
4819#define SELECT_NEXT_METHOD(method) \
4821 if ((remaining_methods & method) != 0) \
4823 conn->current_enc_method = method; \
4848 remaining_methods &= ~ENC_GSSAPI;
4853 "GSSAPI encryption required but no credential cache");
4880#undef SELECT_NEXT_METHOD
4967 static bool wsastartup_done =
false;
4969 if (!wsastartup_done)
4973 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
4975 wsastartup_done =
true;
5184 struct addrinfo *ai = addrlist;
5425 const void *
buf,
size_t buf_len)
5448#define LDAP_URL "ldap://"
5449#define LDAP_DEF_PORT 389
5450#define PGLDAP_TIMEOUT 2
5452#define ld_is_sp_tab(x) ((x) == ' ' || (x) == '\t')
5453#define ld_is_nl_cr(x) ((x) == '\r' || (x) == '\n')
5479 int port = LDAP_DEF_PORT,
5502 char *attrs[2] = {NULL, NULL};
5507 LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0};
5508 int ldapversion = LDAP_VERSION3;
5510 if ((url = strdup(purl)) == NULL)
5525 "invalid LDAP URL \"%s\": scheme must be ldap://", purl);
5536 p = strchr(url + strlen(LDAP_URL),
'/');
5537 if (p == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5540 "invalid LDAP URL \"%s\": missing distinguished name",
5549 if ((p = strchr(dn,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5552 "invalid LDAP URL \"%s\": must have exactly one attribute",
5561 if ((p = strchr(attrs[0],
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5564 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5573 if ((p = strchr(scopestr,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5576 "invalid LDAP URL \"%s\": no filter",
5583 if ((p = strchr(filter,
'?')) != NULL)
5587 if ((p1 = strchr(
hostname,
':')) != NULL)
5594 lport = strtol(
portstr, &endptr, 10);
5595 if (*
portstr ==
'\0' || *endptr !=
'\0' || errno || lport < 0 || lport > 65535)
5598 "invalid LDAP URL \"%s\": invalid port number",
5607 if (strchr(attrs[0],
',') != NULL)
5610 "invalid LDAP URL \"%s\": must have exactly one attribute",
5618 scope = LDAP_SCOPE_BASE;
5620 scope = LDAP_SCOPE_ONELEVEL;
5622 scope = LDAP_SCOPE_SUBTREE;
5626 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5640 if ((rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldapversion)) != LDAP_SUCCESS)
5643 ldap_err2string(rc));
5663 if (ldap_connect(ld, &time) != LDAP_SUCCESS)
5672 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5680 if ((msgid = ldap_simple_bind(ld, NULL, NULL)) == -1)
5690 if ((rc = ldap_result(ld, msgid, LDAP_MSG_ALL, &time, &res)) == -1 ||
5704 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5714 if ((rc = ldap_search_st(ld, dn, scope, filter, attrs, 0, &time, &res))
5719 libpq_append_error(errorMessage,
"lookup on LDAP server failed: %s", ldap_err2string(rc));
5726 if ((rc = ldap_count_entries(ld, res)) != 1)
5739 if ((entry = ldap_first_entry(ld, res)) == NULL)
5750 if ((
values = ldap_get_values_len(ld, entry, attrs[0])) == NULL)
5765 ldap_value_free_len(
values);
5774 if (
values[
i]->bv_len >= INT_MAX ||
5775 size > (INT_MAX - (
values[
i]->bv_len + 1)))
5778 "connection info string size exceeds the maximum allowed (%d)",
5780 ldap_value_free_len(
values);
5785 size +=
values[
i]->bv_len + 1;
5788 if ((result =
malloc(size)) == NULL)
5791 ldap_value_free_len(
values);
5804 ldap_value_free_len(
values);
5808 oldstate =
state = 0;
5809 for (p = result; *p !=
'\0'; ++p)
5814 if (!ld_is_sp_tab(*p) && !ld_is_nl_cr(*p))
5821 if (ld_is_sp_tab(*p))
5826 else if (ld_is_nl_cr(*p))
5829 "missing \"=\" after \"%s\" in connection info string",
5845 else if (!ld_is_sp_tab(*p))
5848 "missing \"=\" after \"%s\" in connection info string",
5861 else if (ld_is_nl_cr(*p))
5863 optval = optname + strlen(optname);
5866 else if (!ld_is_sp_tab(*p))
5873 if (ld_is_sp_tab(*p) || ld_is_nl_cr(*p))
5885 else if (*p ==
'\\')
5896 if (
state == 0 && oldstate != 0)
5898 found_keyword =
false;
5901 if (strcmp(
options[
i].keyword, optname) == 0)
5913 found_keyword =
true;
5934 "unterminated quoted string in connection info string");
5960 bool group_found =
false;
5962 struct stat stat_buf;
5969 if (service == NULL)
5970 service = getenv(
"PGSERVICE");
5973 if (service == NULL)
5981 if (service_fname != NULL)
5982 strlcpy(serviceFile, service_fname,
sizeof(serviceFile));
5983 else if ((env = getenv(
"PGSERVICEFILE")) != NULL)
5984 strlcpy(serviceFile, env,
sizeof(serviceFile));
5992 if (
stat(serviceFile, &stat_buf) != 0)
5997 if (group_found || status != 0)
6007 getenv(
"PGSYSCONFDIR") ? getenv(
"PGSYSCONFDIR") : SYSCONFDIR);
6008 if (
stat(serviceFile, &stat_buf) != 0)
6027 const char *service,
6039 *group_found =
false;
6041 f = fopen(serviceFile,
"r");
6048 while ((line = fgets(
buf,
sizeof(
buf), f)) != NULL)
6054 if (strlen(line) >=
sizeof(
buf) - 1)
6057 "line %d too long in service file \"%s\"",
6066 while (
len > 0 && isspace((
unsigned char) line[
len - 1]))
6070 while (*line && isspace((
unsigned char) line[0]))
6074 if (line[0] ==
'\0' || line[0] ==
'#')
6086 if (strncmp(line + 1, service, strlen(service)) == 0 &&
6087 line[strlen(service) + 1] ==
']')
6088 *group_found =
true;
6090 *group_found =
false;
6104 if (strncmp(line,
"ldap", 4) == 0)
6106 int rc = ldapServiceLookup(line,
options, errorMessage);
6124 val = strchr(line,
'=');
6128 "syntax error in service file \"%s\", line %d",
6136 if (strcmp(
key,
"service") == 0)
6139 "nested \"service\" specifications not supported in service file \"%s\", line %d",
6146 if (strcmp(
key,
"servicefile") == 0)
6149 "nested \"servicefile\" specifications not supported in service file \"%s\", line %d",
6160 found_keyword =
false;
6173 found_keyword =
true;
6181 "syntax error in service file \"%s\", line %d",
6198 if (*group_found && result == 0)
6202 if (strcmp(
options[
i].keyword,
"servicefile") != 0)
6209 options[
i].val = strdup(serviceFile);
6252 if (connOptions == NULL &&
errmsg)
6372 if ((
buf = strdup(conninfo)) == NULL)
6383 if (isspace((
unsigned char) *cp))
6395 if (isspace((
unsigned char) *cp))
6400 if (!isspace((
unsigned char) *cp))
6413 "missing \"=\" after \"%s\" in connection info string",
6424 if (!isspace((
unsigned char) *cp))
6437 if (isspace((
unsigned char) *cp))
6461 libpq_append_error(errorMessage,
"unterminated quoted string in connection info string");
6548 const char *pvalue =
values[
i];
6551 if (strcmp(pname,
"dbname") == 0 && pvalue)
6561 if (dbname_options == NULL)
6582 const char *pvalue =
values[
i];
6584 if (pvalue != NULL && pvalue[0] !=
'\0')
6589 if (strcmp(
option->keyword, pname) == 0)
6594 if (
option->keyword == NULL)
6607 if (strcmp(pname,
"dbname") == 0 && dbname_options)
6611 for (str_option = dbname_options; str_option->
keyword != NULL; str_option++)
6613 if (str_option->
val != NULL)
6617 for (k = 0;
options[k].keyword; k++)
6641 dbname_options = NULL;
6694 *sslrootcert = NULL;
6711 if (strcmp(
option->keyword,
"sslrootcert") == 0)
6720 if (
option->envvar != NULL)
6722 if ((tmp = getenv(
option->envvar)) != NULL)
6741 if (strcmp(
option->keyword,
"sslmode") == 0)
6743 const char *requiresslenv = getenv(
"PGREQUIRESSL");
6745 if (requiresslenv != NULL && requiresslenv[0] ==
'1')
6762 sslmode_default =
option;
6769 if (
option->compiled != NULL)
6788 if (strcmp(
option->keyword,
"user") == 0)
6800 if (sslmode_default && sslrootcert)
6802 if (sslrootcert->val && strcmp(sslrootcert->val,
"system") == 0)
6806 sslmode_default->
val = strdup(
"verify-full");
6807 if (!sslmode_default->
val)
6885 char prevchar =
'\0';
6888 bool retval =
false;
6911 if (prefix_len == 0)
6915 "invalid URI propagated to internal parser routine: \"%s\"",
6919 start += prefix_len;
6923 while (*p && *p !=
'@' && *p !=
'/')
6934 while (*p !=
':' && *p !=
'@')
6943 errorMessage,
false,
true))
6946 if (prevchar ==
':')
6956 errorMessage,
false,
true))
6987 while (*p && *p !=
']')
6992 "end of string reached when looking for matching \"]\" in IPv6 host address in URI: \"%s\"",
6999 "IPv6 host address may not be empty in URI: \"%s\"",
7011 if (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
7014 "unexpected character \"%c\" at position %d in URI (expected \":\" or \"/\"): \"%s\"",
7015 *p, (
int) (p -
buf + 1), uri);
7028 while (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
7038 if (prevchar ==
':')
7040 const char *
port = ++p;
7042 while (*p && *p !=
'/' && *p !=
'?' && *p !=
',')
7051 if (prevchar !=
',')
7061 if (hostbuf.
data[0] &&
7063 errorMessage,
false,
true))
7065 if (portbuf.
data[0] &&
7067 errorMessage,
false,
true))
7070 if (prevchar && prevchar !=
'?')
7072 const char *
dbname = ++p;
7075 while (*p && *p !=
'?')
7088 errorMessage,
false,
true))
7125 char *keyword = params;
7128 bool malloced =
false;
7143 "extra key/value separator \"=\" in URI query parameter: \"%s\"",
7151 else if (*p ==
'&' || *p ==
'\0')
7163 "missing key/value separator \"=\" in URI query parameter: \"%s\"",
7175 if (keyword == NULL)
7192 if (strcmp(keyword,
"ssl") == 0 &&
7193 strcmp(
value,
"true") == 0)
7199 keyword =
"sslmode";
7208 oldmsglen = errorMessage->
len;
7210 errorMessage,
true,
false))
7213 if (errorMessage->
len == oldmsglen)
7215 "invalid URI query parameter: \"%s\"",
7256 const char *q =
str;
7267 for (
const char *s = q; *s ==
' '; s++)
7278 if (*q ==
' ' || *q ==
'\0')
7299 "invalid percent-encoded token: \"%s\"",
7309 "forbidden value %%00 in percent-encoded value: \"%s\"",
7321 for (
const char *s = q; *s ==
' '; s++)
7331 "unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead",
7354 if (
'0' <= digit && digit <=
'9')
7355 *
value = digit -
'0';
7356 else if (
'A' <= digit && digit <=
'F')
7357 *
value = digit -
'A' + 10;
7358 else if (
'a' <= digit && digit <=
'f')
7359 *
value = digit -
'a' + 10;
7374 const char *keyword)
7400 const char *keyword,
const char *
value,
7412 if (strcmp(keyword,
"requiressl") == 0)
7414 keyword =
"sslmode";
7415 if (
value[0] ==
'1')
7426 "invalid connection option \"%s\"",
7434 if (value_copy == NULL)
7440 value_copy = strdup(
value);
7441 if (value_copy == NULL)
7469 if (strcmp(
option->keyword, keyword) == 0)
7499 if (connOptions != NULL)
7510 connmember = (
char **) ((
char *)
conn +
option->connofs);
7514 &errorBuf,
true,
false);
7527 if (connOptions == NULL)
7617 return DEF_PGPORT_STR;
7663 if (!
conn || !paramName)
7665 for (pstatus =
conn->
pstatus; pstatus != NULL; pstatus = pstatus->
next)
7667 if (strcmp(pstatus->
name, paramName) == 0)
7668 return pstatus->
value;
7805 static const char query[] =
"set client_encoding to '%s'";
7820 if (
sizeof(qbuf) < (
sizeof(query) + strlen(
encoding)))
7927 fprintf(stderr,
"%s", message);
7939 bool bslash =
false;
7945 if (tbuf[0] ==
'*' && tbuf[1] ==
':')
7949 if (*tbuf ==
'\\' && !bslash)
7954 if (*tbuf ==
':' && *ttok == 0 && !bslash)
7979 const char *pgpassfile,
const char **
errmsg)
7983 struct stat stat_buf;
8007 if (
port == NULL ||
port[0] ==
'\0')
8008 port = DEF_PGPORT_STR;
8011 fp = fopen(pgpassfile,
"r");
8016 if (
fstat(fileno(fp), &stat_buf) != 0)
8025 libpq_gettext(
"WARNING: password file \"%s\" is not a plain file\n"),
8035 libpq_gettext(
"WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n"),
8051 while (!feof(fp) && !ferror(fp))
8061 if (fgets(
buf.data +
buf.len,
buf.maxlen -
buf.len, fp) == NULL)
8066 if (!(
buf.len > 0 &&
buf.data[
buf.len - 1] ==
'\n') && !feof(fp))
8070 if (
buf.data[0] !=
'#')
8102 for (p1 = p2 = ret; *p1 !=
':' && *p1 !=
'\0'; ++p1, ++p2)
8104 if (*p1 ==
'\\' && p1[1] !=
'\0')
8159 if (!version || strlen(version) == 0)
8185 if (min == NULL || max == NULL || strlen(min) == 0 || strlen(max) == 0)
8237 home = getenv(
"HOME");
8238 if (home && home[0])
8245 struct passwd pwbuf;
8250 rc = getpwuid_r(geteuid(), &pwbuf,
tmpbuf,
sizeof tmpbuf, &pw);
8257 char tmppath[MAX_PATH];
8259 ZeroMemory(tmppath,
sizeof(tmppath));
8260 if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, tmppath) != S_OK)
8274 const char *context)
8285 numval = strtol(
value, &end, 10);
8291 if (
value == end || errno != 0 || numval != (
int) numval)
8298 while (*end !=
'\0' && isspace((
unsigned char) *end))
8319 const char *context)
8321 if (strcmp(
value,
"latest") == 0)
8326 if (strcmp(
value,
"3.0") == 0)
8334 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 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)
static char * passwordFromFile(const char *hostname, const char *port, const char *dbname, const char *username, const char *pgpassfile, const char **errmsg)
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)