85 (
errmsg(
"SSL configuration could not be loaded in child process")));
127 char remote_host[NI_MAXHOST];
128 char remote_port[NI_MAXSERV];
164 port->remote_host =
"";
165 port->remote_port =
"";
185 remote_host[0] =
'\0';
186 remote_port[0] =
'\0';
188 remote_host,
sizeof(remote_host),
189 remote_port,
sizeof(remote_port),
190 (
log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV)) != 0)
208 (
errmsg(
"connection received: host=%s port=%s",
213 (
errmsg(
"connection received: host=%s",
230 strspn(remote_host,
"0123456789.") < strlen(remote_host) &&
231 strspn(remote_host,
"0123456789ABCDEFabcdef:") < strlen(remote_host))
277 errmsg(
"the database system is starting up")));
283 errmsg(
"the database system is not yet accepting connections"),
284 errdetail(
"Consistent recovery state has not been yet reached.")));
288 errmsg(
"the database system is not accepting connections"),
289 errdetail(
"Hot standby mode is disabled.")));
294 errmsg(
"the database system is shutting down")));
299 errmsg(
"the database system is in recovery mode")));
303 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
304 errmsg(
"sorry, too many clients already")));
315 sigprocmask(SIG_SETMASK, &
BlockSig, NULL);
343 if (
port->database_name[0] !=
'\0')
346 if (
port->remote_port[0] !=
'\0')
371 if (firstbyte == EOF)
380 if (firstbyte != 0x16)
410 if (!
port->alpn_used)
413 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
414 errmsg(
"received direct SSL connection request without ALPN protocol negotiation extension")));
420 (
errmsg(
"direct SSL connection accepted")));
430 (
errmsg(
"direct SSL connection rejected")));
486 if (!ssl_done && !gss_done)
488 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
489 errmsg(
"incomplete startup packet")));
500 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
501 errmsg(
"invalid length of startup packet")));
516 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
517 errmsg(
"incomplete startup packet")));
532 int32 cancelAuthCode;
537 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
538 errmsg(
"invalid length of startup packet")));
573 (
errmsg(
"SSLRequest accepted")));
576 (
errmsg(
"SSLRequest rejected")));
585 errmsg(
"failed to send SSL negotiation response: %m")));
602 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
603 errmsg(
"received unencrypted data after SSL request"),
604 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
619 if (
port->laddr.addr.ss_family != AF_UNIX)
627 (
errmsg(
"GSSENCRequest accepted")));
630 (
errmsg(
"GSSENCRequest rejected")));
639 errmsg(
"failed to send GSSAPI negotiation response: %m")));
656 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
657 errmsg(
"received unencrypted data after GSSAPI encryption request"),
658 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
680 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
681 errmsg(
"unsupported frontend protocol %u.%u: server supports %u.0 to %u.%u",
696 List *unrecognized_protocol_options =
NIL;
707 char *nameptr =
buf + offset;
711 if (*nameptr ==
'\0')
713 valoffset = offset + strlen(nameptr) + 1;
714 if (valoffset >=
len)
716 valptr =
buf + valoffset;
718 if (strcmp(nameptr,
"database") == 0)
720 else if (strcmp(nameptr,
"user") == 0)
722 else if (strcmp(nameptr,
"options") == 0)
724 else if (strcmp(nameptr,
"replication") == 0)
733 if (strcmp(valptr,
"database") == 0)
740 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
741 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
744 errhint(
"Valid values are: \"false\", 0, \"true\", 1, \"database\".")));
746 else if (strncmp(nameptr,
"_pq_.", 5) == 0)
753 unrecognized_protocol_options =
770 if (strcmp(nameptr,
"application_name") == 0)
775 offset = valoffset + strlen(valptr) + 1;
782 if (offset !=
len - 1)
784 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
785 errmsg(
"invalid startup packet layout: expected terminator as last byte")));
794 unrecognized_protocol_options !=
NIL)
799 if (
port->user_name == NULL ||
port->user_name[0] ==
'\0')
801 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
802 errmsg(
"no PostgreSQL user name specified in startup packet")));
805 if (
port->database_name == NULL ||
port->database_name[0] ==
'\0')
822 port->database_name[0] =
'\0';
854 foreach(lc, unrecognized_protocol_options)
bool Trace_connection_negotiation
static void SendNegotiateProtocolVersion(List *unrecognized_protocol_options)
void BackendMain(char *startup_data, size_t startup_data_len)
static void process_startup_packet_die(SIGNAL_ARGS)
static void StartupPacketTimeoutHandler(void)
static void BackendInitialize(ClientSocket *client_sock, CAC_state cac)
static int ProcessSSLStartup(Port *port)
static int ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
ssize_t secure_open_gssapi(Port *port)
int secure_initialize(bool isServerStart)
ssize_t secure_write(Port *port, void *ptr, size_t len)
int secure_open_server(Port *port)
bool parse_bool(const char *value, bool *result)
#define Assert(condition)
int errcode_for_socket_access(void)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void ReserveExternalFD(void)
#define ERRCODE_CANNOT_CONNECT_NOW
struct ClientSocket * MyClientSocket
ProtocolVersion FrontendProtocol
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
void check_on_shmem_exit_lists_are_empty(void)
List * lappend(List *list, void *datum)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
const char * GetBackendTypeDesc(BackendType backendType)
BackendType MyBackendType
static int list_length(const List *l)
pqsigfunc pqsignal(int signo, pqsigfunc func)
CommandDest whereToSendOutput
void PostgresMain(const char *dbname, const char *username)
bool ClientAuthInProgress
void processCancelRequest(int backendPID, int32 cancelAuthCode)
int AuthenticationTimeout
PGDLLIMPORT bool LoadedSSL
int pq_getbytes(char *s, size_t len)
Port * pq_init(ClientSocket *client_sock)
ssize_t pq_buffer_remaining_data(void)
void pq_startmsgread(void)
#define PG_PROTOCOL_MAJOR(v)
#define PG_PROTOCOL_EARLIEST
#define CANCEL_REQUEST_CODE
#define MAX_STARTUP_PACKET_LENGTH
#define PG_PROTOCOL_LATEST
#define NEGOTIATE_GSS_CODE
#define NEGOTIATE_SSL_CODE
#define PG_PROTOCOL_MINOR(v)
#define PqMsg_NegotiateProtocolVersion
void init_ps_display(const char *fixed_part)
static void set_ps_display(const char *activity)
MemoryContextSwitchTo(old_ctx)
void pg_usleep(long microsec)
const char * gai_strerror(int ecode)
char * pg_clean_ascii(const char *str, int alloc_flags)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
CAC_state canAcceptConnections
void enable_timeout_after(TimeoutId id, int delay_ms)
void InitializeTimeouts(void)
void disable_timeout(TimeoutId id, bool keep_indicator)
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)