34#ifdef HAVE_SYS_UCRED_H
174 if (!(host && host[0] !=
'\0'))
318 if (outbuf.cBuffers > 0)
320 if (outbuf.cBuffers != 1)
328 "SSPI returned invalid number of output buffers\n");
337 if (outbuf.pBuffers[0].cbBuffer > 0)
341 outbuf.pBuffers[0].pvBuffer, outbuf.pBuffers[0].cbBuffer))
408 if (!(host && host[0] !=
'\0'))
414 if (!
conn->sspitarget)
470 "fe_sendauth: invalid authentication request from server: invalid list of authentication mechanisms\n");
558 bool allowed =
false;
580 libpq_append_conn_error(
conn,
"channel binding is required, but server did not offer an authentication method that supports channel binding");
873 return libpq_gettext(
"server requested a cleartext password");
878 return libpq_gettext(
"server requested GSSAPI authentication");
880 return libpq_gettext(
"server requested SSPI authentication");
884 return libpq_gettext(
"server requested SASL authentication");
887 return libpq_gettext(
"server requested an unknown authentication type");
894#define auth_method_allowed(conn, type) \
895 (((conn)->allowed_auth_methods & (1 << (type))) != 0)
906 const char *reason =
NULL;
909 "AUTH_REQ_MAX overflows the allowed_auth_methods bitmask");
979 reason =
libpq_gettext(
"server did not complete authentication");
1088#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
1090#if !defined(ENABLE_SSPI)
1107#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1112#elif defined(ENABLE_GSS) && !defined(ENABLE_SSPI)
1114#elif !defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1132#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1137#elif defined(ENABLE_GSS) && !defined(ENABLE_SSPI)
1139#elif !defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1184#if !defined(ENABLE_GSS)
1214 "fe_sendauth: error sending password authentication\n");
1244 "fe_sendauth: invalid authentication request from server: AUTH_REQ_SASL_CONT without AUTH_REQ_SASL\n");
1260 "fe_sendauth: error in SASL authentication\n");
1288 char *result =
NULL;
1305 else if (errorMessage)
1307 "user name lookup failure: error code %lu",
1315 libpq_append_error(errorMessage,
"could not look up local user ID %ld: %m", (
long) user_id);
1320 libpq_append_error(errorMessage,
"local user with ID %ld does not exist", (
long) user_id);
1329 if (result ==
NULL && errorMessage)
1407 const char *algorithm)
1409#define MAX_ALGORITHM_NAME_LEN 50
1419 if (algorithm ==
NULL)
1424 res =
PQexec(
conn,
"show password_encryption");
1461 if (
strcmp(algorithm,
"on") == 0 ||
1462 strcmp(algorithm,
"off") == 0)
1468 if (
strcmp(algorithm,
"scram-sha-256") == 0)
1478 else if (
strcmp(algorithm,
"md5") == 0)
void pg_GSS_error(const char *errmsg, OM_uint32 maj_stat, OM_uint32 min_stat)
#define Assert(condition)
#define StaticAssertDecl(condition, errmessage)
const pg_fe_sasl_mech pg_oauth_mech
const pg_fe_sasl_mech pg_scram_mech
char * pg_fe_scram_build_secret(const char *password, int iterations, const char **errstr)
char * PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm)
#define MAX_ALGORITHM_NAME_LEN
static bool check_expected_areq(AuthRequest areq, PGconn *conn)
void PQsetAuthDataHook(PQauthDataHook_type hook)
PGresult * PQchangePassword(PGconn *conn, const char *user, const char *passwd)
PQauthDataHook_type PQauthDataHook
static int pg_SASL_continue(PGconn *conn, int payloadlen, bool final, bool *async)
static int pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
PQauthDataHook_type PQgetAuthDataHook(void)
int PQdefaultAuthDataHook(PGauthData type, PGconn *conn, void *data)
static int pg_SASL_init(PGconn *conn, int payloadlen, bool *async)
int pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn, bool *async)
char * pg_fe_getauthname(PQExpBuffer errorMessage)
char * PQencryptPassword(const char *passwd, const char *user)
static const char * auth_method_description(AuthRequest areq)
char * pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
#define auth_method_allowed(conn, type)
int pqPacketSend(PGconn *conn, char pack_type, const void *buf, size_t buf_len)
void PQfreemem(void *ptr)
char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)
PGresult * PQexec(PGconn *conn, const char *query)
char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)
int pg_GSS_load_servicename(PGconn *conn)
bool pg_GSS_have_cred_cache(gss_cred_id_t *cred_out)
int pqPutInt(int value, size_t bytes, PGconn *conn)
int pqFlush(PGconn *conn)
int pqPutMsgStart(char msg_type, PGconn *conn)
int pqGets(PQExpBuffer buf, PGconn *conn)
int pqPutnchar(const void *s, size_t len, PGconn *conn)
int pqPuts(const char *s, PGconn *conn)
void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...)
int pqGetnchar(void *s, size_t len, PGconn *conn)
int pqPutMsgEnd(PGconn *conn)
void pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
int(* PQauthDataHook_type)(PGauthData type, PGconn *conn, void *data)
#define PQnoPasswordSupplied
#define AUTH_RESPONSE_PASSWORD
#define AUTH_RESPONSE_SASL
#define AUTH_RESPONSE_SASL_INITIAL
#define pqClearConnErrorState(conn)
#define AUTH_RESPONSE_GSS
bool pg_md5_encrypt(const char *passwd, const uint8 *salt, size_t salt_len, char *buf, const char **errstr)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
#define pgunlock_thread()
static char buf[DEFAULT_XLOG_SEG_SIZE]
int pg_strcasecmp(const char *s1, const char *s2)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferDataBroken(buf)
#define AUTH_REQ_SASL_CONT
#define PqMsg_GSSResponse
#define PqMsg_SASLResponse
#define PqMsg_SASLInitialResponse
#define AUTH_REQ_PASSWORD
#define AUTH_REQ_GSS_CONT
#define PqMsg_PasswordMessage
#define AUTH_REQ_SASL_FIN
#define SCRAM_SHA_256_PLUS_NAME
#define SCRAM_SHA_256_NAME
uint8 * scram_client_key_binary
char current_auth_response
const pg_fe_sasl_mech * sasl
void(* cleanup_async_auth)(PGconn *conn)
bool client_finished_auth
uint32 allowed_auth_methods
PQExpBufferData errorMessage
PostgresPollingStatusType(* async_auth)(PGconn *conn)
int scram_sha_256_iterations
const pg_fe_sasl_mech * allowed_sasl_mechs[2]
bool(* channel_bound)(void *state)
SASLStatus(* exchange)(void *state, bool final, char *input, int inputlen, char **output, int *outputlen)
void *(* init)(PGconn *conn, const char *password, const char *mech)