PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <netdb.h>
#include <time.h>
#include <unistd.h>
#include "common/ip.h"
#include "common/link-canary.h"
#include "common/scram-common.h"
#include "common/string.h"
#include "fe-auth.h"
#include "libpq-fe.h"
#include "libpq-int.h"
#include "mb/pg_wchar.h"
#include "pg_config_paths.h"
#include "port/pg_bswap.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pwd.h>
#include <pthread.h>
Go to the source code of this file.
Data Structures | |
struct | _internalPQconninfoOption |
Macros | |
#define | PGPASSFILE ".pgpass" |
#define | ERRCODE_APPNAME_UNKNOWN "42704" |
#define | ERRCODE_INVALID_PASSWORD "28P01" |
#define | ERRCODE_CANNOT_CONNECT_NOW "57P03" |
#define | DefaultHost "localhost" |
#define | DefaultOption "" |
#define | DefaultChannelBinding "disable" |
#define | DefaultTargetSessionAttrs "any" |
#define | DefaultLoadBalanceHosts "disable" |
#define | DefaultSSLMode "disable" |
#define | DefaultSSLCertMode "disable" |
#define | DefaultSSLNegotiation "postgres" |
#define | DefaultGSSMode "disable" |
#define | ENCRYPTION_NEGOTIATION_FAILED(msg) |
#define | CONNECTION_FAILED() |
#define | MAX_ERRLEN 30000 |
#define | SELECT_NEXT_METHOD(method) |
Typedefs | |
typedef struct _internalPQconninfoOption | internalPQconninfoOption |
Variables | |
static const internalPQconninfoOption | PQconninfoOptions [] |
static const PQEnvironmentOption | EnvironmentOptions [] |
static const char | uri_designator [] = "postgresql://" |
static const char | short_uri_designator [] = "postgres://" |
pgthreadlock_t | pg_g_threadlock = default_threadlock |
#define CONNECTION_FAILED | ( | ) |
#define DefaultChannelBinding "disable" |
Definition at line 122 of file fe-connect.c.
#define DefaultGSSMode "disable" |
Definition at line 138 of file fe-connect.c.
#define DefaultHost "localhost" |
Definition at line 117 of file fe-connect.c.
#define DefaultLoadBalanceHosts "disable" |
Definition at line 125 of file fe-connect.c.
#define DefaultOption "" |
Definition at line 118 of file fe-connect.c.
#define DefaultSSLCertMode "disable" |
Definition at line 131 of file fe-connect.c.
#define DefaultSSLMode "disable" |
Definition at line 130 of file fe-connect.c.
#define DefaultSSLNegotiation "postgres" |
Definition at line 133 of file fe-connect.c.
#define DefaultTargetSessionAttrs "any" |
Definition at line 124 of file fe-connect.c.
#define ENCRYPTION_NEGOTIATION_FAILED | ( | msg | ) |
#define ERRCODE_APPNAME_UNKNOWN "42704" |
Definition at line 87 of file fe-connect.c.
#define ERRCODE_CANNOT_CONNECT_NOW "57P03" |
Definition at line 92 of file fe-connect.c.
#define ERRCODE_INVALID_PASSWORD "28P01" |
Definition at line 90 of file fe-connect.c.
#define MAX_ERRLEN 30000 |
#define PGPASSFILE ".pgpass" |
Definition at line 76 of file fe-connect.c.
#define SELECT_NEXT_METHOD | ( | method | ) |
typedef struct _internalPQconninfoOption internalPQconninfoOption |
|
static |
Definition at line 2150 of file fe-connect.c.
References SockAddr::addr, appendPQExpBuffer(), conn, pg_conn::errorMessage, libpq_append_conn_error(), PG_STRERROR_R_BUFLEN, pg_conn::raddr, and SOCK_STRERROR.
Referenced by PQconnectPoll().
Definition at line 4396 of file fe-connect.c.
References Assert, conn, pg_conn::current_enc_method, pg_conn::failed_enc_methods, and select_next_encryption_method().
|
static |
Definition at line 2035 of file fe-connect.c.
References conn, libpq_append_conn_error(), PG_STRERROR_R_BUFLEN, pg_conn::sock, SOCK_ERRNO, and SOCK_STRERROR.
Referenced by PQconnectPoll().
Definition at line 998 of file fe-connect.c.
References conn, CONNECTION_BAD, pg_conn::errorMessage, fillPGconn(), parse_connection_string(), PQconninfoFree(), and pg_conn::status.
Referenced by PQconnectStart(), and PQsetdbLogin().
|
static |
Definition at line 6202 of file fe-connect.c.
References free, libpq_append_error(), parseServiceInfo(), pg_fe_getauthname(), option::val, and _PQconninfoOption::val.
Referenced by conninfo_array_parse(), conninfo_parse(), conninfo_uri_parse(), and PQconndefaults().
|
static |
Definition at line 6044 of file fe-connect.c.
References conninfo_add_defaults(), conninfo_init(), free, i, _PQconninfoOption::keyword, libpq_append_error(), options, parse_connection_string(), PQconninfoFree(), recognized_connection_string(), option::val, val, _PQconninfoOption::val, and values.
Referenced by PQconnectStartParams().
|
static |
Definition at line 6943 of file fe-connect.c.
Referenced by conninfo_getval(), and conninfo_storeval().
|
static |
Definition at line 6853 of file fe-connect.c.
References conninfo_find(), and option::val.
Referenced by fillPGconn(), and parseServiceInfo().
|
static |
Definition at line 5775 of file fe-connect.c.
References _internalPQconninfoOption::keyword, libpq_append_error(), malloc, MemSet, options, and PQconninfoOptions.
Referenced by conninfo_array_parse(), conninfo_parse(), conninfo_uri_parse(), PQconndefaults(), and PQconninfo().
|
static |
Definition at line 5868 of file fe-connect.c.
References buf, conninfo_add_defaults(), conninfo_init(), conninfo_storeval(), free, libpq_append_error(), options, and PQconninfoFree().
Referenced by parse_connection_string().
|
static |
Definition at line 6879 of file fe-connect.c.
References conninfo_find(), conninfo_uri_decode(), free, libpq_append_error(), option::val, and value.
Referenced by conninfo_parse(), conninfo_uri_parse_options(), conninfo_uri_parse_params(), and PQconninfo().
|
static |
Definition at line 6764 of file fe-connect.c.
References buf, free, get_hexdigit(), libpq_append_error(), malloc, and str.
Referenced by conninfo_storeval(), and conninfo_uri_parse_params().
|
static |
Definition at line 6337 of file fe-connect.c.
References conninfo_add_defaults(), conninfo_init(), conninfo_uri_parse_options(), options, and PQconninfoFree().
Referenced by parse_connection_string().
|
static |
Definition at line 6390 of file fe-connect.c.
References appendPQExpBufferChar(), appendPQExpBufferStr(), buf, cleanup(), conninfo_storeval(), conninfo_uri_parse_params(), PQExpBufferData::data, dbname, free, initPQExpBuffer(), libpq_append_error(), password, port, PQExpBufferDataBroken, start, termPQExpBuffer(), uri_prefix_length(), and user.
Referenced by conninfo_uri_parse().
|
static |
Definition at line 6631 of file fe-connect.c.
References conninfo_storeval(), conninfo_uri_decode(), free, PQExpBufferData::len, libpq_append_error(), and value.
Referenced by conninfo_uri_parse_options().
|
static |
Definition at line 1035 of file fe-connect.c.
References input.
Referenced by pqConnectOptions2().
|
static |
Definition at line 7784 of file fe-connect.c.
References Assert, PTHREAD_MUTEX_INITIALIZER, pthread_mutex_lock(), and pthread_mutex_unlock().
Referenced by PQregisterThreadLock().
|
static |
|
static |
Definition at line 7384 of file fe-connect.c.
References arg, pg_result::noticeHooks, PGNoticeHooks::noticeProc, PGNoticeHooks::noticeProcArg, PQresultErrorMessage(), and res.
Referenced by pqMakeEmptyPGconn().
|
static |
Definition at line 2094 of file fe-connect.c.
References SockAddr::addr, appendPQExpBuffer(), CHT_HOST_ADDRESS, conn, pg_conn::connhost, pg_conn::errorMessage, pg_conn_host::host, pg_conn_host::hostaddr, libpq_gettext, pg_getnameinfo_all(), pg_conn_host::port, pg_conn::raddr, SockAddr::salen, pg_conn_host::type, and pg_conn::whichhost.
Referenced by PQconnectPoll().
|
static |
Definition at line 919 of file fe-connect.c.
References conn, conninfo_getval(), free, libpq_append_conn_error(), and PQconninfoOptions.
Referenced by connectOptions1(), and PQconnectStartParams().
|
static |
Definition at line 4649 of file fe-connect.c.
References pg_conn::appname, pg_conn::channel_binding, pg_conn::client_encoding_initial, conn, PGEventConnDestroy::conn, pg_conn::connect_timeout, pg_conn::connip, pg_conn::dbName, pg_conn::errorMessage, pg_conn::events, explicit_bzero(), pg_conn::fbappname, free, pg_conn::gssdelegation, pg_conn::gssencmode, pg_conn::gsslib, i, pg_conn::inBuffer, pg_conn::keepalives, pg_conn::keepalives_count, pg_conn::keepalives_idle, pg_conn::keepalives_interval, pg_conn::krbsrvname, pg_conn::load_balance_hosts, PGEvent::name, pg_conn::nEvents, pg_conn::outBuffer, PGEvent::passThrough, PGEVT_CONNDESTROY, pg_conn::pghost, pg_conn::pghostaddr, pg_conn::pgoptions, pg_conn::pgpass, pg_conn::pgpassfile, pg_conn::pgport, pg_conn::pgtcp_user_timeout, pg_conn::pguser, pqReleaseConnHosts(), PGEvent::proc, release_conn_addrinfo(), pg_conn::replication, pg_conn::require_auth, pg_conn::requirepeer, pg_conn::rowBuf, pg_conn::ssl_max_protocol_version, pg_conn::ssl_min_protocol_version, pg_conn::sslcert, pg_conn::sslcertmode, pg_conn::sslcompression, pg_conn::sslcrl, pg_conn::sslcrldir, pg_conn::sslkey, pg_conn::sslmode, pg_conn::sslnegotiation, pg_conn::sslpassword, pg_conn::sslrootcert, pg_conn::sslsni, pg_conn::target_session_attrs, termPQExpBuffer(), pg_conn::workBuffer, and pg_conn::write_err_msg.
Referenced by PQfinish(), and pqMakeEmptyPGconn().
|
static |
Definition at line 6832 of file fe-connect.c.
References value.
Referenced by conninfo_uri_decode().
|
static |
Definition at line 2061 of file fe-connect.c.
References SockAddr::addr, conn, pg_inet_net_ntop(), and pg_conn::raddr.
Referenced by PQconnectPoll().
Definition at line 4306 of file fe-connect.c.
References SockAddr::addr, pg_conn::allowed_enc_methods, conn, pg_conn::current_enc_method, ENC_ERROR, ENC_GSSAPI, ENC_PLAINTEXT, ENC_SSL, pg_conn::gssencmode, libpq_append_conn_error(), pg_conn::raddr, select_next_encryption_method(), and pg_conn::sslmode.
Referenced by PQconnectPoll().
Definition at line 4486 of file fe-connect.c.
References pg_conn::auth_req_received, conn, CONNECTION_BAD, ERRCODE_CANNOT_CONNECT_NOW, pg_conn::last_sqlstate, pg_conn::options_valid, pqConnectDBComplete(), PQPING_NO_ATTEMPT, PQPING_NO_RESPONSE, PQPING_OK, PQPING_REJECT, and pg_conn::status.
Referenced by PQping(), and PQpingParams().
|
static |
Definition at line 1094 of file fe-connect.c.
References conn, gettimeofday(), pg_prng_seed(), pg_prng_strong_seed, and pg_conn::prng_state.
Referenced by pqConnectOptions2().
|
static |
|
static |
Definition at line 5814 of file fe-connect.c.
References conninfo_parse(), conninfo_uri_parse(), connstr, and uri_prefix_length().
Referenced by connectOptions1(), conninfo_array_parse(), and PQconninfoParse().
|
static |
Definition at line 5575 of file fe-connect.c.
References buf, exit(), i, sort-test::key, len, libpq_append_error(), and val.
Referenced by parseServiceInfo().
|
static |
Definition at line 5507 of file fe-connect.c.
References conninfo_getval(), libpq_append_error(), MAXPGPATH, parseServiceFile(), pqGetHomeDirectory(), snprintf, stat, and strlcpy().
Referenced by conninfo_add_defaults().
|
static |
Definition at line 7448 of file fe-connect.c.
References buf, dbname, DEFAULT_PGSOCKET_DIR, DefaultHost, enlargePQExpBuffer(), explicit_bzero(), fprintf, fstat, hostname, initPQExpBuffer(), is_unixsock_path(), len, libpq_gettext, p2, pg_strip_crlf(), port, pwdfMatchesString(), S_IRWXG, S_IRWXO, S_ISREG, stat::st_mode, termPQExpBuffer(), and username.
Referenced by pqConnectOptions2().
|
static |
Definition at line 7590 of file fe-connect.c.
References conn, pg_conn::connhost, ERRCODE_INVALID_PASSWORD, libpq_append_conn_error(), pg_conn_host::password, pg_conn::password_needed, PG_DIAG_SQLSTATE, pg_conn::pgpassfile, PQresultErrorField(), pg_conn::result, and pg_conn::whichhost.
Referenced by PQconnectPoll().
int PQbackendPID | ( | const PGconn * | conn | ) |
Definition at line 7216 of file fe-connect.c.
References pg_conn::be_pid, conn, CONNECTION_OK, and pg_conn::status.
Referenced by get_prompt(), libpqrcv_get_backend_pid(), main(), send_cancellable_query_impl(), and StartLogStreamer().
int PQclientEncoding | ( | const PGconn * | conn | ) |
Definition at line 7270 of file fe-connect.c.
References pg_conn::client_encoding, conn, CONNECTION_OK, and pg_conn::status.
Referenced by appendQualifiedRelation(), appendStringLiteralConn(), dblink_connect(), dblink_get_conn(), exec_command_encoding(), main(), processSQLNamePattern(), SendQuery(), setup_connection(), SyncVariables(), and vacuum_one_database().
void pqClosePGconn | ( | PGconn * | conn | ) |
Definition at line 4847 of file fe-connect.c.
References pg_conn::asyncStatus, pg_conn::cancelRequest, conn, CONNECTION_BAD, pg_conn::nonblocking, PGASYNC_IDLE, pg_conn::pipelineStatus, PQ_PIPELINE_OFF, pqClearAsyncResult(), pqClearConnErrorState, pqDropConnection(), pqDropServerData(), PQTRANS_IDLE, release_conn_addrinfo(), sendTerminateConn(), pg_conn::status, and pg_conn::xactStatus.
Referenced by PQcancelReset(), PQfinish(), PQreset(), and PQresetStart().
PQconninfoOption* PQconndefaults | ( | void | ) |
Definition at line 1882 of file fe-connect.c.
References conninfo_add_defaults(), conninfo_init(), initPQExpBuffer(), PQconninfoFree(), PQExpBufferDataBroken, and termPQExpBuffer().
Referenced by check_pghost_envvar(), dblink_fdw_validator(), do_connect(), get_connect_string(), GetDbnameFromConnectionOptions(), InitPgFdwOptions(), and main().
PGconn* PQconnectdb | ( | const char * | conninfo | ) |
Definition at line 745 of file fe-connect.c.
References conn, CONNECTION_BAD, pqConnectDBComplete(), PQconnectStart(), and pg_conn::status.
Referenced by connect_database(), get_db_conn(), and main().
int pqConnectDBComplete | ( | PGconn * | conn | ) |
Definition at line 2471 of file fe-connect.c.
References pg_conn::cancelRequest, conn, pg_conn::connect_timeout, CONNECTION_BAD, CONNECTION_NEEDED, end_time, flag(), PGRES_POLLING_OK, PGRES_POLLING_READING, PGRES_POLLING_WRITING, PQcancelPoll(), PQconnectPoll(), PQgetCurrentTimeUSec(), pqParseIntParam(), pqWaitTimed(), pg_conn::status, pg_conn::try_next_addr, pg_conn::whichaddr, and pg_conn::whichhost.
Referenced by internal_ping(), PQcancelBlocking(), PQconnectdb(), PQconnectdbParams(), PQreset(), and PQsetdbLogin().
PGconn* PQconnectdbParams | ( | const char *const * | keywords, |
const char *const * | values, | ||
int | expand_dbname | ||
) |
Definition at line 690 of file fe-connect.c.
References conn, CONNECTION_BAD, pqConnectDBComplete(), PQconnectStartParams(), pg_conn::status, and values.
Referenced by ConnectDatabase(), connectDatabase(), copy_connection(), doConnect(), ECPGconnect(), GetConnection(), main(), sql_conn(), and vacuumlo().
int pqConnectDBStart | ( | PGconn * | conn | ) |
Definition at line 2393 of file fe-connect.c.
References appendPQExpBufferStr(), pg_conn::cancelRequest, conn, CONNECTION_BAD, CONNECTION_NEEDED, pg_conn::errorMessage, pg_conn::inCursor, pg_conn::inEnd, pg_conn::inStart, pg_conn::options_valid, pg_conn::outCount, pg_link_canary_is_frontend(), PGRES_POLLING_WRITING, PQconnectPoll(), pqDropConnection(), SERVER_TYPE_PREFER_STANDBY, SERVER_TYPE_PREFER_STANDBY_PASS2, pg_conn::status, pg_conn::target_server_type, pg_conn::try_next_addr, pg_conn::try_next_host, and pg_conn::whichhost.
Referenced by PQcancelStart(), PQconnectStart(), PQconnectStartParams(), PQreset(), PQresetStart(), and PQsetdbLogin().
int PQconnectionNeedsPassword | ( | const PGconn * | conn | ) |
Definition at line 7233 of file fe-connect.c.
References conn, password, pg_conn::password_needed, and PQpass().
Referenced by ConnectDatabase(), connectDatabase(), do_connect(), doConnect(), GetConnection(), main(), sql_conn(), and vacuumlo().
int PQconnectionUsedGSSAPI | ( | const PGconn * | conn | ) |
Definition at line 7259 of file fe-connect.c.
References conn, and pg_conn::gssapi_used.
Referenced by dblink_security_check(), and pgfdw_security_check().
int PQconnectionUsedPassword | ( | const PGconn * | conn | ) |
Definition at line 7248 of file fe-connect.c.
References conn, and pg_conn::password_needed.
Referenced by ConnectDatabase(), dblink_security_check(), libpqrcv_connect(), and pgfdw_security_check().
Definition at line 1121 of file fe-connect.c.
References pg_conn::allowed_auth_methods, Assert, AUTH_REQ_GSS, AUTH_REQ_GSS_CONT, AUTH_REQ_MD5, AUTH_REQ_PASSWORD, AUTH_REQ_SASL, AUTH_REQ_SASL_CONT, AUTH_REQ_SASL_FIN, AUTH_REQ_SSPI, pg_conn::auth_required, calloc, pg_conn::channel_binding, CHT_HOST_ADDRESS, CHT_HOST_NAME, CHT_UNIX_SOCKET, pg_conn::client_encoding_initial, conn, CONNECTION_BAD, pg_conn::connhost, count_comma_separated_elems(), pg_conn::dbName, DEFAULT_PGSOCKET_DIR, DefaultChannelBinding, DefaultGSSMode, DefaultHost, DefaultSSLCertMode, DefaultSSLMode, DefaultSSLNegotiation, pg_conn::errorMessage, free, pg_conn::gssencmode, pg_conn_host::host, pg_conn_host::hostaddr, i, is_unixsock_path(), j, libpq_append_conn_error(), libpq_prng_init(), LOAD_BALANCE_DISABLE, pg_conn::load_balance_hosts, LOAD_BALANCE_RANDOM, pg_conn::load_balance_type, malloc, MAXPGPATH, pg_conn::nconnhost, pg_conn::options_valid, parse_comma_separated_list(), pg_conn_host::password, passwordFromFile(), pg_encoding_to_char, pg_fe_getauthname(), pg_get_encoding_from_locale(), pg_prng_uint64_range(), pg_conn::pghost, pg_conn::pghostaddr, pg_conn::pgpass, PGPASSFILE, pg_conn::pgpassfile, pg_conn::pgport, pg_conn::pguser, pg_conn_host::port, pqGetHomeDirectory(), pg_conn::prng_state, pg_conn::require_auth, SERVER_TYPE_ANY, SERVER_TYPE_PREFER_STANDBY, SERVER_TYPE_PRIMARY, SERVER_TYPE_READ_ONLY, SERVER_TYPE_READ_WRITE, SERVER_TYPE_STANDBY, snprintf, pg_conn::ssl_max_protocol_version, pg_conn::ssl_min_protocol_version, pg_conn::sslcertmode, pg_conn::sslmode, pg_conn::sslnegotiation, pg_conn::sslrootcert, sslVerifyProtocolRange(), sslVerifyProtocolVersion(), pg_conn::status, pg_conn::target_server_type, pg_conn::target_session_attrs, pg_conn_host::type, and pg_conn::whichhost.
Referenced by PQcancelCreate(), PQconnectStart(), PQconnectStartParams(), and PQsetdbLogin().
PostgresPollingStatusType PQconnectPoll | ( | PGconn * | conn | ) |
Definition at line 2597 of file fe-connect.c.