PostgreSQL Source Code git master
fe-auth.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <pwd.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netdb.h>
#include "common/md5.h"
#include "common/oauth-common.h"
#include "common/scram-common.h"
#include "fe-auth.h"
#include "fe-auth-sasl.h"
#include "fe-auth-oauth.h"
#include "libpq-fe.h"
Include dependency graph for fe-auth.c:

Go to the source code of this file.

Macros

#define auth_method_allowed(conn, type)    (((conn)->allowed_auth_methods & (1 << (type))) != 0)
 
#define MAX_ALGORITHM_NAME_LEN   50
 

Functions

static int pg_SASL_init (PGconn *conn, int payloadlen, bool *async)
 
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)
 
static const char * auth_method_description (AuthRequest areq)
 
static bool check_expected_areq (AuthRequest areq, PGconn *conn)
 
int pg_fe_sendauth (AuthRequest areq, int payloadlen, PGconn *conn, bool *async)
 
char * pg_fe_getusername (uid_t user_id, PQExpBuffer errorMessage)
 
char * pg_fe_getauthname (PQExpBuffer errorMessage)
 
char * PQencryptPassword (const char *passwd, const char *user)
 
char * PQencryptPasswordConn (PGconn *conn, const char *passwd, const char *user, const char *algorithm)
 
PGresultPQchangePassword (PGconn *conn, const char *user, const char *passwd)
 
PQauthDataHook_type PQgetAuthDataHook (void)
 
void PQsetAuthDataHook (PQauthDataHook_type hook)
 
int PQdefaultAuthDataHook (PGauthData type, PGconn *conn, void *data)
 

Variables

PQauthDataHook_type PQauthDataHook = PQdefaultAuthDataHook
 

Macro Definition Documentation

◆ auth_method_allowed

#define auth_method_allowed (   conn,
  type 
)     (((conn)->allowed_auth_methods & (1 << (type))) != 0)

Definition at line 894 of file fe-auth.c.

◆ MAX_ALGORITHM_NAME_LEN

#define MAX_ALGORITHM_NAME_LEN   50

Function Documentation

◆ auth_method_description()

static const char * auth_method_description ( AuthRequest  areq)
static

Definition at line 868 of file fe-auth.c.

869{
870 switch (areq)
871 {
873 return libpq_gettext("server requested a cleartext password");
874 case AUTH_REQ_MD5:
875 return libpq_gettext("server requested a hashed password");
876 case AUTH_REQ_GSS:
878 return libpq_gettext("server requested GSSAPI authentication");
879 case AUTH_REQ_SSPI:
880 return libpq_gettext("server requested SSPI authentication");
881 case AUTH_REQ_SASL:
884 return libpq_gettext("server requested SASL authentication");
885 }
886
887 return libpq_gettext("server requested an unknown authentication type");
888}
#define libpq_gettext(x)
Definition: libpq-int.h:934
#define AUTH_REQ_SSPI
Definition: protocol.h:83
#define AUTH_REQ_SASL_CONT
Definition: protocol.h:85
#define AUTH_REQ_GSS
Definition: protocol.h:81
#define AUTH_REQ_MD5
Definition: protocol.h:79
#define AUTH_REQ_PASSWORD
Definition: protocol.h:77
#define AUTH_REQ_GSS_CONT
Definition: protocol.h:82
#define AUTH_REQ_SASL
Definition: protocol.h:84
#define AUTH_REQ_SASL_FIN
Definition: protocol.h:86

References 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, and libpq_gettext.

Referenced by check_expected_areq().

◆ check_expected_areq()

static bool check_expected_areq ( AuthRequest  areq,
PGconn conn 
)
static

Definition at line 903 of file fe-auth.c.

904{
905 bool result = true;
906 const char *reason = NULL;
907
909 "AUTH_REQ_MAX overflows the allowed_auth_methods bitmask");
910
911 if (conn->sslcertmode[0] == 'r' /* require */
912 && areq == AUTH_REQ_OK)
913 {
914 /*
915 * Trade off a little bit of complexity to try to get these error
916 * messages as precise as possible.
917 */
919 {
920 libpq_append_conn_error(conn, "server did not request an SSL certificate");
921 return false;
922 }
923 else if (!conn->ssl_cert_sent)
924 {
925 libpq_append_conn_error(conn, "server accepted connection without a valid SSL certificate");
926 return false;
927 }
928 }
929
930 /*
931 * If the user required a specific auth method, or specified an allowed
932 * set, then reject all others here, and make sure the server actually
933 * completes an authentication exchange.
934 */
935 if (conn->require_auth)
936 {
937 switch (areq)
938 {
939 case AUTH_REQ_OK:
940
941 /*
942 * Check to make sure we've actually finished our exchange (or
943 * else that the user has allowed an authentication-less
944 * connection).
945 *
946 * If the user has allowed both SCRAM and unauthenticated
947 * (trust) connections, then this check will silently accept
948 * partial SCRAM exchanges, where a misbehaving server does
949 * not provide its verifier before sending an OK. This is
950 * consistent with historical behavior, but it may be a point
951 * to revisit in the future, since it could allow a server
952 * that doesn't know the user's password to silently harvest
953 * material for a brute force attack.
954 */
956 break;
957
958 /*
959 * No explicit authentication request was made by the server
960 * -- or perhaps it was made and not completed, in the case of
961 * SCRAM -- but there is one special case to check. If the
962 * user allowed "gss", then a GSS-encrypted channel also
963 * satisfies the check.
964 */
965#ifdef ENABLE_GSS
966 if (auth_method_allowed(conn, AUTH_REQ_GSS) && conn->gssenc)
967 {
968 /*
969 * If implicit GSS auth has already been performed via GSS
970 * encryption, we don't need to have performed an
971 * AUTH_REQ_GSS exchange. This allows require_auth=gss to
972 * be combined with gssencmode, since there won't be an
973 * explicit authentication request in that case.
974 */
975 }
976 else
977#endif
978 {
979 reason = libpq_gettext("server did not complete authentication");
980 result = false;
981 }
982
983 break;
984
986 case AUTH_REQ_MD5:
987 case AUTH_REQ_GSS:
989 case AUTH_REQ_SSPI:
990 case AUTH_REQ_SASL:
993
994 /*
995 * We don't handle these with the default case, to avoid
996 * bit-shifting past the end of the allowed_auth_methods mask
997 * if the server sends an unexpected AuthRequest.
998 */
999 result = auth_method_allowed(conn, areq);
1000 break;
1001
1002 default:
1003 result = false;
1004 break;
1005 }
1006 }
1007
1008 if (!result)
1009 {
1010 if (!reason)
1011 reason = auth_method_description(areq);
1012
1013 libpq_append_conn_error(conn, "authentication method requirement \"%s\" failed: %s",
1014 conn->require_auth, reason);
1015 return result;
1016 }
1017
1018 /*
1019 * When channel_binding=require, we must protect against two cases: (1) we
1020 * must not respond to non-SASL authentication requests, which might leak
1021 * information such as the client's password; and (2) even if we receive
1022 * AUTH_REQ_OK, we still must ensure that channel binding has happened in
1023 * order to authenticate the server.
1024 */
1025 if (conn->channel_binding[0] == 'r' /* require */ )
1026 {
1027 switch (areq)
1028 {
1029 case AUTH_REQ_SASL:
1030 case AUTH_REQ_SASL_CONT:
1031 case AUTH_REQ_SASL_FIN:
1032 break;
1033 case AUTH_REQ_OK:
1035 {
1036 libpq_append_conn_error(conn, "channel binding required, but server authenticated client without channel binding");
1037 result = false;
1038 }
1039 break;
1040 default:
1041 libpq_append_conn_error(conn, "channel binding required but not supported by server's authentication request");
1042 result = false;
1043 break;
1044 }
1045 }
1046
1047 return result;
1048}
#define StaticAssertDecl(condition, errmessage)
Definition: c.h:907
static const char * auth_method_description(AuthRequest areq)
Definition: fe-auth.c:868
#define auth_method_allowed(conn, type)
Definition: fe-auth.c:894
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
Definition: fe-misc.c:1381
#define AUTH_REQ_MAX
Definition: protocol.h:87
#define AUTH_REQ_OK
Definition: protocol.h:74
PGconn * conn
Definition: streamutil.c:52
char * require_auth
Definition: libpq-int.h:431
char * channel_binding
Definition: libpq-int.h:403
const pg_fe_sasl_mech * sasl
Definition: libpq-int.h:599
bool client_finished_auth
Definition: libpq-int.h:521
char * sslcertmode
Definition: libpq-int.h:417
uint32 allowed_auth_methods
Definition: libpq-int.h:517
bool auth_required
Definition: libpq-int.h:515
bool ssl_cert_requested
Definition: libpq-int.h:610
bool ssl_cert_sent
Definition: libpq-int.h:611
void * sasl_state
Definition: libpq-int.h:600
bool(* channel_bound)(void *state)
Definition: fe-auth-sasl.h:136

References pg_conn::allowed_auth_methods, auth_method_allowed, auth_method_description(), AUTH_REQ_GSS, AUTH_REQ_GSS_CONT, AUTH_REQ_MAX, AUTH_REQ_MD5, AUTH_REQ_OK, AUTH_REQ_PASSWORD, AUTH_REQ_SASL, AUTH_REQ_SASL_CONT, AUTH_REQ_SASL_FIN, AUTH_REQ_SSPI, pg_conn::auth_required, pg_conn::channel_binding, pg_fe_sasl_mech::channel_bound, pg_conn::client_finished_auth, conn, libpq_append_conn_error(), libpq_gettext, pg_conn::require_auth, pg_conn::sasl, pg_conn::sasl_state, pg_conn::ssl_cert_requested, pg_conn::ssl_cert_sent, pg_conn::sslcertmode, and StaticAssertDecl.

Referenced by pg_fe_sendauth().

◆ pg_fe_getauthname()

char * pg_fe_getauthname ( PQExpBuffer  errorMessage)

Definition at line 1344 of file fe-auth.c.

1345{
1346#ifdef WIN32
1347 return pg_fe_getusername(0, errorMessage);
1348#else
1349 return pg_fe_getusername(geteuid(), errorMessage);
1350#endif
1351}
char * pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
Definition: fe-auth.c:1286

References pg_fe_getusername().

Referenced by conninfo_add_defaults(), and pqConnectOptions2().

◆ pg_fe_getusername()

char * pg_fe_getusername ( uid_t  user_id,
PQExpBuffer  errorMessage 
)

Definition at line 1286 of file fe-auth.c.

1287{
1288 char *result = NULL;
1289 const char *name = NULL;
1290
1291#ifdef WIN32
1292 /* Microsoft recommends buffer size of UNLEN+1, where UNLEN = 256 */
1293 char username[256 + 1];
1294 DWORD namesize = sizeof(username);
1295#else
1296 struct passwd pwbuf;
1297 struct passwd *pw = NULL;
1298 char buf[1024];
1299 int rc;
1300#endif
1301
1302#ifdef WIN32
1303 if (GetUserName(username, &namesize))
1304 name = username;
1305 else if (errorMessage)
1306 libpq_append_error(errorMessage,
1307 "user name lookup failure: error code %lu",
1308 GetLastError());
1309#else
1310 rc = getpwuid_r(user_id, &pwbuf, buf, sizeof buf, &pw);
1311 if (rc != 0)
1312 {
1313 errno = rc;
1314 if (errorMessage)
1315 libpq_append_error(errorMessage, "could not look up local user ID %ld: %m", (long) user_id);
1316 }
1317 else if (!pw)
1318 {
1319 if (errorMessage)
1320 libpq_append_error(errorMessage, "local user with ID %ld does not exist", (long) user_id);
1321 }
1322 else
1323 name = pw->pw_name;
1324#endif
1325
1326 if (name)
1327 {
1328 result = strdup(name);
1329 if (result == NULL && errorMessage)
1330 libpq_append_error(errorMessage, "out of memory");
1331 }
1332
1333 return result;
1334}
void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...)
Definition: fe-misc.c:1352
static char * username
Definition: initdb.c:153
static char * buf
Definition: pg_test_fsync.c:72
const char * name

References buf, libpq_append_error(), name, and username.

Referenced by pg_fe_getauthname(), and PQconnectPoll().

◆ pg_fe_sendauth()

int pg_fe_sendauth ( AuthRequest  areq,
int  payloadlen,
PGconn conn,
bool *  async 
)

Definition at line 1066 of file fe-auth.c.

1067{
1068 int oldmsglen;
1069
1070 *async = false;
1071
1072 if (!check_expected_areq(areq, conn))
1073 return STATUS_ERROR;
1074
1075 switch (areq)
1076 {
1077 case AUTH_REQ_OK:
1078 break;
1079
1080 case AUTH_REQ_KRB4:
1081 libpq_append_conn_error(conn, "Kerberos 4 authentication not supported");
1082 return STATUS_ERROR;
1083
1084 case AUTH_REQ_KRB5:
1085 libpq_append_conn_error(conn, "Kerberos 5 authentication not supported");
1086 return STATUS_ERROR;
1087
1088#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
1089 case AUTH_REQ_GSS:
1090#if !defined(ENABLE_SSPI)
1091 /* no native SSPI, so use GSSAPI library for it */
1092 case AUTH_REQ_SSPI:
1093#endif
1094 {
1095 int r;
1096
1097 pglock_thread();
1098
1099 /*
1100 * If we have both GSS and SSPI support compiled in, use SSPI
1101 * support by default. This is overridable by a connection
1102 * string parameter. Note that when using SSPI we still leave
1103 * the negotiate parameter off, since we want SSPI to use the
1104 * GSSAPI kerberos protocol. For actual SSPI negotiate
1105 * protocol, we use AUTH_REQ_SSPI.
1106 */
1107#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1108 if (conn->gsslib && (pg_strcasecmp(conn->gsslib, "gssapi") == 0))
1109 r = pg_GSS_startup(conn, payloadlen);
1110 else
1111 r = pg_SSPI_startup(conn, 0, payloadlen);
1112#elif defined(ENABLE_GSS) && !defined(ENABLE_SSPI)
1113 r = pg_GSS_startup(conn, payloadlen);
1114#elif !defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1115 r = pg_SSPI_startup(conn, 0, payloadlen);
1116#endif
1117 if (r != STATUS_OK)
1118 {
1119 /* Error message already filled in. */
1121 return STATUS_ERROR;
1122 }
1124 }
1125 break;
1126
1127 case AUTH_REQ_GSS_CONT:
1128 {
1129 int r;
1130
1131 pglock_thread();
1132#if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1133 if (conn->usesspi)
1134 r = pg_SSPI_continue(conn, payloadlen);
1135 else
1136 r = pg_GSS_continue(conn, payloadlen);
1137#elif defined(ENABLE_GSS) && !defined(ENABLE_SSPI)
1138 r = pg_GSS_continue(conn, payloadlen);
1139#elif !defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1140 r = pg_SSPI_continue(conn, payloadlen);
1141#endif
1142 if (r != STATUS_OK)
1143 {
1144 /* Error message already filled in. */
1146 return STATUS_ERROR;
1147 }
1149 }
1150 break;
1151#else /* defined(ENABLE_GSS) || defined(ENABLE_SSPI) */
1152 /* No GSSAPI *or* SSPI support */
1153 case AUTH_REQ_GSS:
1154 case AUTH_REQ_GSS_CONT:
1155 libpq_append_conn_error(conn, "GSSAPI authentication not supported");
1156 return STATUS_ERROR;
1157#endif /* defined(ENABLE_GSS) || defined(ENABLE_SSPI) */
1158
1159#ifdef ENABLE_SSPI
1160 case AUTH_REQ_SSPI:
1161
1162 /*
1163 * SSPI has its own startup message so libpq can decide which
1164 * method to use. Indicate to pg_SSPI_startup that we want SSPI
1165 * negotiation instead of Kerberos.
1166 */
1167 pglock_thread();
1168 if (pg_SSPI_startup(conn, 1, payloadlen) != STATUS_OK)
1169 {
1170 /* Error message already filled in. */
1172 return STATUS_ERROR;
1173 }
1175 break;
1176#else
1177
1178 /*
1179 * No SSPI support. However, if we have GSSAPI but not SSPI
1180 * support, AUTH_REQ_SSPI will have been handled in the codepath
1181 * for AUTH_REQ_GSS above, so don't duplicate the case label in
1182 * that case.
1183 */
1184#if !defined(ENABLE_GSS)
1185 case AUTH_REQ_SSPI:
1186 libpq_append_conn_error(conn, "SSPI authentication not supported");
1187 return STATUS_ERROR;
1188#endif /* !define(ENABLE_GSS) */
1189#endif /* ENABLE_SSPI */
1190
1191
1192 case AUTH_REQ_CRYPT:
1193 libpq_append_conn_error(conn, "Crypt authentication not supported");
1194 return STATUS_ERROR;
1195
1196 case AUTH_REQ_MD5:
1197 case AUTH_REQ_PASSWORD:
1198 {
1199 char *password;
1200
1201 conn->password_needed = true;
1203 if (password == NULL)
1204 password = conn->pgpass;
1205 if (password == NULL || password[0] == '\0')
1206 {
1209 return STATUS_ERROR;
1210 }
1212 {
1214 "fe_sendauth: error sending password authentication\n");
1215 return STATUS_ERROR;
1216 }
1217
1218 /* We expect no further authentication requests. */
1219 conn->client_finished_auth = true;
1220 break;
1221 }
1222
1223 case AUTH_REQ_SASL:
1224
1225 /*
1226 * The request contains the name (as assigned by IANA) of the
1227 * authentication mechanism.
1228 */
1229 if (pg_SASL_init(conn, payloadlen, async) != STATUS_OK)
1230 {
1231 /* pg_SASL_init already set the error message */
1232 return STATUS_ERROR;
1233 }
1234 break;
1235
1236 case AUTH_REQ_SASL_CONT:
1237 case AUTH_REQ_SASL_FIN:
1238 {
1239 bool final = false;
1240
1241 if (conn->sasl_state == NULL)
1242 {
1244 "fe_sendauth: invalid authentication request from server: AUTH_REQ_SASL_CONT without AUTH_REQ_SASL\n");
1245 return STATUS_ERROR;
1246 }
1247 oldmsglen = conn->errorMessage.len;
1248
1249 if (areq == AUTH_REQ_SASL_FIN)
1250 final = true;
1251
1252 if (pg_SASL_continue(conn, payloadlen, final, async) != STATUS_OK)
1253 {
1254 /*
1255 * Append a generic error message unless pg_SASL_continue
1256 * did set a more specific one already.
1257 */
1258 if (conn->errorMessage.len == oldmsglen)
1260 "fe_sendauth: error in SASL authentication\n");
1261 return STATUS_ERROR;
1262 }
1263 break;
1264 }
1265
1266 default:
1267 libpq_append_conn_error(conn, "authentication method %u not supported", areq);
1268 return STATUS_ERROR;
1269 }
1270
1271 return STATUS_OK;
1272}
#define STATUS_OK
Definition: c.h:1140
#define STATUS_ERROR
Definition: c.h:1141
static bool check_expected_areq(AuthRequest areq, PGconn *conn)
Definition: fe-auth.c:903
static int pg_SASL_continue(PGconn *conn, int payloadlen, bool final, bool *async)
Definition: fe-auth.c:704
static int pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
Definition: fe-auth.c:796
static int pg_SASL_init(PGconn *conn, int payloadlen, bool *async)
Definition: fe-auth.c:435
#define PQnoPasswordSupplied
Definition: libpq-fe.h:633
#define pglock_thread()
Definition: libpq-int.h:732
#define pgunlock_thread()
Definition: libpq-int.h:733
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
#define AUTH_REQ_KRB5
Definition: protocol.h:76
#define AUTH_REQ_KRB4
Definition: protocol.h:75
#define AUTH_REQ_CRYPT
Definition: protocol.h:78
static char * password
Definition: streamutil.c:51
char * password
Definition: libpq-int.h:369
char * pgpass
Definition: libpq-int.h:401
PQExpBufferData errorMessage
Definition: libpq-int.h:671
char * gsslib
Definition: libpq-int.h:425
int whichhost
Definition: libpq-int.h:483
pg_conn_host * connhost
Definition: libpq-int.h:484
bool password_needed
Definition: libpq-int.h:508

References appendPQExpBufferStr(), AUTH_REQ_CRYPT, AUTH_REQ_GSS, AUTH_REQ_GSS_CONT, AUTH_REQ_KRB4, AUTH_REQ_KRB5, AUTH_REQ_MD5, AUTH_REQ_OK, AUTH_REQ_PASSWORD, AUTH_REQ_SASL, AUTH_REQ_SASL_CONT, AUTH_REQ_SASL_FIN, AUTH_REQ_SSPI, check_expected_areq(), pg_conn::client_finished_auth, conn, pg_conn::connhost, pg_conn::errorMessage, pg_conn::gsslib, PQExpBufferData::len, libpq_append_conn_error(), password, pg_conn_host::password, pg_conn::password_needed, pg_password_sendauth(), pg_SASL_continue(), pg_SASL_init(), pg_strcasecmp(), pglock_thread, pg_conn::pgpass, pgunlock_thread, PQnoPasswordSupplied, pg_conn::sasl_state, STATUS_ERROR, STATUS_OK, and pg_conn::whichhost.

Referenced by PQconnectPoll().

◆ pg_password_sendauth()

static int pg_password_sendauth ( PGconn conn,
const char *  password,
AuthRequest  areq 
)
static

Definition at line 796 of file fe-auth.c.

797{
798 int ret;
799 char *crypt_pwd = NULL;
800 const char *pwd_to_send;
801 char md5Salt[4];
802
803 /* Read the salt from the AuthenticationMD5Password message. */
804 if (areq == AUTH_REQ_MD5)
805 {
806 if (pqGetnchar(md5Salt, 4, conn))
807 return STATUS_ERROR; /* shouldn't happen */
808 }
809
810 /* finished parsing, trace server-to-client message */
811 if (conn->Pfdebug)
813
814 /* Encrypt the password if needed. */
815
816 switch (areq)
817 {
818 case AUTH_REQ_MD5:
819 {
820 char *crypt_pwd2;
821 const char *errstr = NULL;
822
823 /* Allocate enough space for two MD5 hashes */
824 crypt_pwd = malloc(2 * (MD5_PASSWD_LEN + 1));
825 if (!crypt_pwd)
826 {
827 libpq_append_conn_error(conn, "out of memory");
828 return STATUS_ERROR;
829 }
830
831 crypt_pwd2 = crypt_pwd + MD5_PASSWD_LEN + 1;
833 strlen(conn->pguser), crypt_pwd2,
834 &errstr))
835 {
836 libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
837 free(crypt_pwd);
838 return STATUS_ERROR;
839 }
840 if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"), md5Salt,
841 4, crypt_pwd, &errstr))
842 {
843 libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
844 free(crypt_pwd);
845 return STATUS_ERROR;
846 }
847
848 pwd_to_send = crypt_pwd;
849 break;
850 }
852 pwd_to_send = password;
853 break;
854 default:
855 return STATUS_ERROR;
856 }
859 pwd_to_send, strlen(pwd_to_send) + 1);
860 free(crypt_pwd);
861 return ret;
862}
int pqPacketSend(PGconn *conn, char pack_type, const void *buf, size_t buf_len)
Definition: fe-connect.c:5332
int pqGetnchar(char *s, size_t len, PGconn *conn)
Definition: fe-misc.c:165
void pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
Definition: fe-trace.c:624
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
#define AUTH_RESPONSE_PASSWORD
Definition: libpq-int.h:344
#define MD5_PASSWD_LEN
Definition: md5.h:26
bool pg_md5_encrypt(const char *passwd, const char *salt, size_t salt_len, char *buf, const char **errstr)
Definition: md5_common.c:145
#define PqMsg_PasswordMessage
Definition: protocol.h:31
char current_auth_response
Definition: libpq-int.h:523
char * inBuffer
Definition: libpq-int.h:564
int inStart
Definition: libpq-int.h:566
char * pguser
Definition: libpq-int.h:400
FILE * Pfdebug
Definition: libpq-int.h:452

References AUTH_REQ_MD5, AUTH_REQ_PASSWORD, AUTH_RESPONSE_PASSWORD, conn, pg_conn::current_auth_response, free, pg_conn::inBuffer, pg_conn::inStart, libpq_append_conn_error(), malloc, MD5_PASSWD_LEN, password, pg_conn::Pfdebug, pg_md5_encrypt(), pg_conn::pguser, pqGetnchar(), PqMsg_PasswordMessage, pqPacketSend(), pqTraceOutputMessage(), and STATUS_ERROR.

Referenced by pg_fe_sendauth().

◆ pg_SASL_continue()

static int pg_SASL_continue ( PGconn conn,
int  payloadlen,
bool  final,
bool *  async 
)
static

Definition at line 704 of file fe-auth.c.

705{
706 char *output;
707 int outputlen;
708 int res;
709 char *challenge;
710 SASLStatus status;
711
712 /* Read the SASL challenge from the AuthenticationSASLContinue message. */
713 challenge = malloc(payloadlen + 1);
714 if (!challenge)
715 {
716 libpq_append_conn_error(conn, "out of memory allocating SASL buffer (%d)",
717 payloadlen);
718 return STATUS_ERROR;
719 }
720
721 if (pqGetnchar(challenge, payloadlen, conn))
722 {
723 free(challenge);
724 return STATUS_ERROR;
725 }
726
727 /* finished parsing, trace server-to-client message */
728 if (conn->Pfdebug)
730
731 /* For safety and convenience, ensure the buffer is NULL-terminated. */
732 challenge[payloadlen] = '\0';
733
734 status = conn->sasl->exchange(conn->sasl_state, final,
735 challenge, payloadlen,
736 &output, &outputlen);
737 free(challenge); /* don't need the input anymore */
738
739 if (status == SASL_ASYNC)
740 {
741 /*
742 * The mechanism should have set up the necessary callbacks; all we
743 * need to do is signal the caller.
744 */
745 *async = true;
746
747 /*
748 * The mechanism may optionally generate some output to send before
749 * switching over to async auth, so continue onwards.
750 */
751 }
752
753 if (final && status == SASL_CONTINUE)
754 {
755 if (outputlen != 0)
756 free(output);
757
758 libpq_append_conn_error(conn, "AuthenticationSASLFinal received from server, but SASL authentication was not completed");
759 return STATUS_ERROR;
760 }
761
762 /*
763 * If the exchange is not completed yet, we need to make sure that the
764 * SASL mechanism has generated a message to send back.
765 */
766 if (output == NULL && status == SASL_CONTINUE)
767 {
768 libpq_append_conn_error(conn, "no client response found after SASL exchange success");
769 return STATUS_ERROR;
770 }
771
772 /*
773 * SASL allows zero-length responses, so this check uses "output" and not
774 * "outputlen" to allow the case of an empty message.
775 */
776 if (output)
777 {
778 /*
779 * Send the SASL response to the server.
780 */
782 res = pqPacketSend(conn, PqMsg_SASLResponse, output, outputlen);
783 free(output);
784
785 if (res != STATUS_OK)
786 return STATUS_ERROR;
787 }
788
789 if (status == SASL_FAILED)
790 return STATUS_ERROR;
791
792 return STATUS_OK;
793}
SASLStatus
Definition: fe-auth-sasl.h:29
@ SASL_ASYNC
Definition: fe-auth-sasl.h:33
@ SASL_CONTINUE
Definition: fe-auth-sasl.h:32
@ SASL_FAILED
Definition: fe-auth-sasl.h:31
FILE * output
#define AUTH_RESPONSE_SASL
Definition: libpq-int.h:346
#define PqMsg_SASLResponse
Definition: protocol.h:33
SASLStatus(* exchange)(void *state, bool final, char *input, int inputlen, char **output, int *outputlen)
Definition: fe-auth-sasl.h:117

References AUTH_RESPONSE_SASL, conn, pg_conn::current_auth_response, pg_fe_sasl_mech::exchange, free, pg_conn::inBuffer, pg_conn::inStart, libpq_append_conn_error(), malloc, output, pg_conn::Pfdebug, pqGetnchar(), PqMsg_SASLResponse, pqPacketSend(), pqTraceOutputMessage(), pg_conn::sasl, SASL_ASYNC, SASL_CONTINUE, SASL_FAILED, pg_conn::sasl_state, STATUS_ERROR, and STATUS_OK.

Referenced by pg_fe_sendauth().

◆ pg_SASL_init()

static int pg_SASL_init ( PGconn conn,
int  payloadlen,
bool *  async 
)
static

Definition at line 435 of file fe-auth.c.

436{
437 char *initialresponse = NULL;
438 int initialresponselen;
439 const char *selected_mechanism;
440 PQExpBufferData mechanism_buf;
441 char *password = NULL;
442 SASLStatus status;
443
444 initPQExpBuffer(&mechanism_buf);
445
446 if (conn->channel_binding[0] == 'r' && /* require */
448 {
449 libpq_append_conn_error(conn, "channel binding required, but SSL not in use");
450 goto error;
451 }
452
453 if (conn->sasl_state && !conn->async_auth)
454 {
455 libpq_append_conn_error(conn, "duplicate SASL authentication request");
456 goto error;
457 }
458
459 /*
460 * Parse the list of SASL authentication mechanisms in the
461 * AuthenticationSASL message, and select the best mechanism that we
462 * support. Mechanisms are listed by order of decreasing importance.
463 */
464 selected_mechanism = NULL;
465 for (;;)
466 {
467 if (pqGets(&mechanism_buf, conn))
468 {
470 "fe_sendauth: invalid authentication request from server: invalid list of authentication mechanisms\n");
471 goto error;
472 }
473 if (PQExpBufferDataBroken(mechanism_buf))
474 goto oom_error;
475
476 /* An empty string indicates end of list */
477 if (mechanism_buf.data[0] == '\0')
478 break;
479
480 /*
481 * Select the mechanism to use. Pick SCRAM-SHA-256-PLUS over anything
482 * else if a channel binding type is set and if the client supports it
483 * (and did not set channel_binding=disable). Pick SCRAM-SHA-256 if
484 * nothing else has already been picked. If we add more mechanisms, a
485 * more refined priority mechanism might become necessary.
486 */
487 if (strcmp(mechanism_buf.data, SCRAM_SHA_256_PLUS_NAME) == 0)
488 {
489 if (conn->ssl_in_use)
490 {
491 /* The server has offered SCRAM-SHA-256-PLUS. */
492
493#ifdef USE_SSL
494 /*
495 * The client supports channel binding, which is chosen if
496 * channel_binding is not disabled.
497 */
498 if (conn->channel_binding[0] != 'd') /* disable */
499 {
500 selected_mechanism = SCRAM_SHA_256_PLUS_NAME;
502 conn->password_needed = true;
503 }
504#else
505 /*
506 * The client does not support channel binding. If it is
507 * required, complain immediately instead of the error below
508 * which would be confusing as the server is publishing
509 * SCRAM-SHA-256-PLUS.
510 */
511 if (conn->channel_binding[0] == 'r') /* require */
512 {
513 libpq_append_conn_error(conn, "channel binding is required, but client does not support it");
514 goto error;
515 }
516#endif
517 }
518 else
519 {
520 /*
521 * The server offered SCRAM-SHA-256-PLUS, but the connection
522 * is not SSL-encrypted. That's not sane. Perhaps SSL was
523 * stripped by a proxy? There's no point in continuing,
524 * because the server will reject the connection anyway if we
525 * try authenticate without channel binding even though both
526 * the client and server supported it. The SCRAM exchange
527 * checks for that, to prevent downgrade attacks.
528 */
529 libpq_append_conn_error(conn, "server offered SCRAM-SHA-256-PLUS authentication over a non-SSL connection");
530 goto error;
531 }
532 }
533 else if (strcmp(mechanism_buf.data, SCRAM_SHA_256_NAME) == 0 &&
534 !selected_mechanism)
535 {
536 selected_mechanism = SCRAM_SHA_256_NAME;
538 conn->password_needed = true;
539 }
540 else if (strcmp(mechanism_buf.data, OAUTHBEARER_NAME) == 0 &&
541 !selected_mechanism)
542 {
543 selected_mechanism = OAUTHBEARER_NAME;
545 conn->password_needed = false;
546 }
547 }
548
549 if (!selected_mechanism)
550 {
551 libpq_append_conn_error(conn, "none of the server's SASL authentication mechanisms are supported");
552 goto error;
553 }
554
555 /* Make sure require_auth is satisfied. */
556 if (conn->require_auth)
557 {
558 bool allowed = false;
559
560 for (int i = 0; i < lengthof(conn->allowed_sasl_mechs); i++)
561 {
563 {
564 allowed = true;
565 break;
566 }
567 }
568
569 if (!allowed)
570 {
571 libpq_append_conn_error(conn, "authentication method requirement \"%s\" failed: server requested %s authentication",
572 conn->require_auth, selected_mechanism);
573 goto error;
574 }
575 }
576
577 if (conn->channel_binding[0] == 'r' && /* require */
578 strcmp(selected_mechanism, SCRAM_SHA_256_PLUS_NAME) != 0)
579 {
580 libpq_append_conn_error(conn, "channel binding is required, but server did not offer an authentication method that supports channel binding");
581 goto error;
582 }
583
584 /*
585 * Now that the SASL mechanism has been chosen for the exchange,
586 * initialize its state information.
587 */
588
589 /*
590 * First, select the password to use for the exchange, complaining if
591 * there isn't one and the selected SASL mechanism needs it.
592 */
594 {
596 if (password == NULL)
598 if (password == NULL || password[0] == '\0')
599 {
602 goto error;
603 }
604 }
605
606 /* finished parsing, trace server-to-client message */
607 if (conn->Pfdebug)
609
610 Assert(conn->sasl);
611
612 if (!conn->sasl_state)
613 {
614 /*
615 * Initialize the SASL state information with all the information
616 * gathered during the initial exchange.
617 *
618 * Note: Only tls-unique is supported for the moment.
619 */
621 password,
622 selected_mechanism);
623 if (!conn->sasl_state)
624 goto oom_error;
625 }
626 else
627 {
628 /*
629 * This is only possible if we're returning from an async loop.
630 * Disconnect it now.
631 */
633 conn->async_auth = NULL;
634 }
635
636 /* Get the mechanism-specific Initial Client Response, if any */
637 status = conn->sasl->exchange(conn->sasl_state, false,
638 NULL, -1,
639 &initialresponse, &initialresponselen);
640
641 if (status == SASL_FAILED)
642 goto error;
643
644 if (status == SASL_ASYNC)
645 {
646 /*
647 * The mechanism should have set up the necessary callbacks; all we
648 * need to do is signal the caller.
649 *
650 * In non-assertion builds, this postcondition is enforced at time of
651 * use in PQconnectPoll().
652 */
655
656 *async = true;
657 return STATUS_OK;
658 }
659
660 /*
661 * Build a SASLInitialResponse message, and send it.
662 */
664 goto error;
665 if (pqPuts(selected_mechanism, conn))
666 goto error;
667 if (initialresponse)
668 {
669 if (pqPutInt(initialresponselen, 4, conn))
670 goto error;
671 if (pqPutnchar(initialresponse, initialresponselen, conn))
672 goto error;
673 }
675 if (pqPutMsgEnd(conn))
676 goto error;
677
678 if (pqFlush(conn))
679 goto error;
680
681 termPQExpBuffer(&mechanism_buf);
682 free(initialresponse);
683
684 return STATUS_OK;
685
686error:
687 termPQExpBuffer(&mechanism_buf);
688 free(initialresponse);
689 return STATUS_ERROR;
690
691oom_error:
692 termPQExpBuffer(&mechanism_buf);
693 free(initialresponse);
694 libpq_append_conn_error(conn, "out of memory");
695 return STATUS_ERROR;
696}
#define lengthof(array)
Definition: c.h:759
const pg_fe_sasl_mech pg_oauth_mech
Definition: fe-auth-oauth.c:35
const pg_fe_sasl_mech pg_scram_mech
Definition: fe-auth-scram.c:33
int pqPutInt(int value, size_t bytes, PGconn *conn)
Definition: fe-misc.c:253
int pqFlush(PGconn *conn)
Definition: fe-misc.c:968
int pqPutMsgStart(char msg_type, PGconn *conn)
Definition: fe-misc.c:473
int pqGets(PQExpBuffer buf, PGconn *conn)
Definition: fe-misc.c:136
int pqPutnchar(const char *s, size_t len, PGconn *conn)
Definition: fe-misc.c:202
int pqPuts(const char *s, PGconn *conn)
Definition: fe-misc.c:152
int pqPutMsgEnd(PGconn *conn)
Definition: fe-misc.c:532
Assert(PointerIsAligned(start, uint64))
int i
Definition: isn.c:74
#define AUTH_RESPONSE_SASL_INITIAL
Definition: libpq-int.h:345
#define OAUTHBEARER_NAME
Definition: oauth-common.h:17
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
#define PQExpBufferDataBroken(buf)
Definition: pqexpbuffer.h:67
#define PqMsg_SASLInitialResponse
Definition: protocol.h:32
#define SCRAM_SHA_256_PLUS_NAME
Definition: scram-common.h:21
#define SCRAM_SHA_256_NAME
Definition: scram-common.h:20
static void error(void)
Definition: sql-dyntest.c:147
void(* cleanup_async_auth)(PGconn *conn)
Definition: libpq-int.h:529
void * scram_client_key_binary
Definition: libpq-int.h:545
PostgresPollingStatusType(* async_auth)(PGconn *conn)
Definition: libpq-int.h:528
const pg_fe_sasl_mech * allowed_sasl_mechs[2]
Definition: libpq-int.h:519
bool ssl_in_use
Definition: libpq-int.h:608
void *(* init)(PGconn *conn, const char *password, const char *mech)
Definition: fe-auth-sasl.h:66

References pg_conn::allowed_sasl_mechs, appendPQExpBufferStr(), Assert(), pg_conn::async_auth, AUTH_RESPONSE_SASL_INITIAL, pg_conn::channel_binding, pg_conn::cleanup_async_auth, conn, pg_conn::connhost, pg_conn::current_auth_response, PQExpBufferData::data, error(), pg_conn::errorMessage, pg_fe_sasl_mech::exchange, free, i, pg_conn::inBuffer, pg_fe_sasl_mech::init, initPQExpBuffer(), pg_conn::inStart, lengthof, libpq_append_conn_error(), OAUTHBEARER_NAME, password, pg_conn_host::password, pg_conn::password_needed, pg_conn::Pfdebug, pg_oauth_mech, pg_scram_mech, pg_conn::pgpass, PQExpBufferDataBroken, pqFlush(), pqGets(), PqMsg_SASLInitialResponse, PQnoPasswordSupplied, pqPutInt(), pqPutMsgEnd(), pqPutMsgStart(), pqPutnchar(), pqPuts(), pqTraceOutputMessage(), pg_conn::require_auth, pg_conn::sasl, SASL_ASYNC, SASL_FAILED, pg_conn::sasl_state, pg_conn::scram_client_key_binary, SCRAM_SHA_256_NAME, SCRAM_SHA_256_PLUS_NAME, pg_conn::ssl_in_use, STATUS_ERROR, STATUS_OK, termPQExpBuffer(), and pg_conn::whichhost.

Referenced by pg_fe_sendauth().

◆ PQchangePassword()

PGresult * PQchangePassword ( PGconn conn,
const char *  user,
const char *  passwd 
)

Definition at line 1531 of file fe-auth.c.

1532{
1533 char *encrypted_password = PQencryptPasswordConn(conn, passwd,
1534 user, NULL);
1535
1536 if (!encrypted_password)
1537 {
1538 /* PQencryptPasswordConn() already registered the error */
1539 return NULL;
1540 }
1541 else
1542 {
1543 char *fmtpw = PQescapeLiteral(conn, encrypted_password,
1544 strlen(encrypted_password));
1545
1546 /* no longer needed, so clean up now */
1547 PQfreemem(encrypted_password);
1548
1549 if (!fmtpw)
1550 {
1551 /* PQescapeLiteral() already registered the error */
1552 return NULL;
1553 }
1554 else
1555 {
1556 char *fmtuser = PQescapeIdentifier(conn, user, strlen(user));
1557
1558 if (!fmtuser)
1559 {
1560 /* PQescapeIdentifier() already registered the error */
1561 PQfreemem(fmtpw);
1562 return NULL;
1563 }
1564 else
1565 {
1567 PGresult *res;
1568
1570 printfPQExpBuffer(&buf, "ALTER USER %s PASSWORD %s",
1571 fmtuser, fmtpw);
1572
1573 res = PQexec(conn, buf.data);
1574
1575 /* clean up */
1577 PQfreemem(fmtuser);
1578 PQfreemem(fmtpw);
1579
1580 return res;
1581 }
1582 }
1583 }
1584}
char * PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm)
Definition: fe-auth.c:1406
void PQfreemem(void *ptr)
Definition: fe-exec.c:4032
char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)
Definition: fe-exec.c:4363
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2262
char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)
Definition: fe-exec.c:4369
static char * user
Definition: pg_regress.c:119
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:235

References buf, conn, initPQExpBuffer(), PQencryptPasswordConn(), PQescapeIdentifier(), PQescapeLiteral(), PQexec(), PQfreemem(), printfPQExpBuffer(), termPQExpBuffer(), and user.

Referenced by exec_command_password().

◆ PQdefaultAuthDataHook()

int PQdefaultAuthDataHook ( PGauthData  type,
PGconn conn,
void *  data 
)

Definition at line 1601 of file fe-auth.c.

1602{
1603 return 0; /* handle nothing */
1604}

Referenced by PQsetAuthDataHook().

◆ PQencryptPassword()

char * PQencryptPassword ( const char *  passwd,
const char *  user 
)

Definition at line 1363 of file fe-auth.c.

1364{
1365 char *crypt_pwd;
1366 const char *errstr = NULL;
1367
1368 crypt_pwd = malloc(MD5_PASSWD_LEN + 1);
1369 if (!crypt_pwd)
1370 return NULL;
1371
1372 if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr))
1373 {
1374 free(crypt_pwd);
1375 return NULL;
1376 }
1377
1378 return crypt_pwd;
1379}

References free, malloc, MD5_PASSWD_LEN, pg_md5_encrypt(), and user.

◆ PQencryptPasswordConn()

char * PQencryptPasswordConn ( PGconn conn,
const char *  passwd,
const char *  user,
const char *  algorithm 
)

Definition at line 1406 of file fe-auth.c.

1408{
1409#define MAX_ALGORITHM_NAME_LEN 50
1410 char algobuf[MAX_ALGORITHM_NAME_LEN + 1];
1411 char *crypt_pwd = NULL;
1412
1413 if (!conn)
1414 return NULL;
1415
1417
1418 /* If no algorithm was given, ask the server. */
1419 if (algorithm == NULL)
1420 {
1421 PGresult *res;
1422 char *val;
1423
1424 res = PQexec(conn, "show password_encryption");
1425 if (res == NULL)
1426 {
1427 /* PQexec() should've set conn->errorMessage already */
1428 return NULL;
1429 }
1430 if (PQresultStatus(res) != PGRES_TUPLES_OK)
1431 {
1432 /* PQexec() should've set conn->errorMessage already */
1433 PQclear(res);
1434 return NULL;
1435 }
1436 if (PQntuples(res) != 1 || PQnfields(res) != 1)
1437 {
1438 PQclear(res);
1439 libpq_append_conn_error(conn, "unexpected shape of result set returned for SHOW");
1440 return NULL;
1441 }
1442 val = PQgetvalue(res, 0, 0);
1443
1444 if (strlen(val) > MAX_ALGORITHM_NAME_LEN)
1445 {
1446 PQclear(res);
1447 libpq_append_conn_error(conn, "\"password_encryption\" value too long");
1448 return NULL;
1449 }
1450 strcpy(algobuf, val);
1451 PQclear(res);
1452
1453 algorithm = algobuf;
1454 }
1455
1456 /*
1457 * Also accept "on" and "off" as aliases for "md5", because
1458 * password_encryption was a boolean before PostgreSQL 10. We refuse to
1459 * send the password in plaintext even if it was "off".
1460 */
1461 if (strcmp(algorithm, "on") == 0 ||
1462 strcmp(algorithm, "off") == 0)
1463 algorithm = "md5";
1464
1465 /*
1466 * Ok, now we know what algorithm to use
1467 */
1468 if (strcmp(algorithm, "scram-sha-256") == 0)
1469 {
1470 const char *errstr = NULL;
1471
1472 crypt_pwd = pg_fe_scram_build_secret(passwd,
1474 &errstr);
1475 if (!crypt_pwd)
1476 libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
1477 }
1478 else if (strcmp(algorithm, "md5") == 0)
1479 {
1480 crypt_pwd = malloc(MD5_PASSWD_LEN + 1);
1481 if (crypt_pwd)
1482 {
1483 const char *errstr = NULL;
1484
1485 if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr))
1486 {
1487 libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
1488 free(crypt_pwd);
1489 crypt_pwd = NULL;
1490 }
1491 }
1492 else
1493 libpq_append_conn_error(conn, "out of memory");
1494 }
1495 else
1496 {
1497 libpq_append_conn_error(conn, "unrecognized password encryption algorithm \"%s\"",
1498 algorithm);
1499 return NULL;
1500 }
1501
1502 return crypt_pwd;
1503}
char * pg_fe_scram_build_secret(const char *password, int iterations, const char **errstr)
#define MAX_ALGORITHM_NAME_LEN
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3876
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3411
void PQclear(PGresult *res)
Definition: fe-exec.c:721
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3481
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3489
long val
Definition: informix.c:689
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:127
#define pqClearConnErrorState(conn)
Definition: libpq-int.h:907
int scram_sha_256_iterations
Definition: libpq-int.h:601

References conn, free, libpq_append_conn_error(), malloc, MAX_ALGORITHM_NAME_LEN, MD5_PASSWD_LEN, pg_fe_scram_build_secret(), pg_md5_encrypt(), PGRES_TUPLES_OK, PQclear(), pqClearConnErrorState, PQexec(), PQgetvalue(), PQnfields(), PQntuples(), PQresultStatus(), pg_conn::scram_sha_256_iterations, user, and val.

Referenced by main(), and PQchangePassword().

◆ PQgetAuthDataHook()

PQauthDataHook_type PQgetAuthDataHook ( void  )

Definition at line 1589 of file fe-auth.c.

1590{
1591 return PQauthDataHook;
1592}
PQauthDataHook_type PQauthDataHook
Definition: fe-auth.c:1586

References PQauthDataHook.

◆ PQsetAuthDataHook()

void PQsetAuthDataHook ( PQauthDataHook_type  hook)

Definition at line 1595 of file fe-auth.c.

1596{
1597 PQauthDataHook = hook ? hook : PQdefaultAuthDataHook;
1598}
int PQdefaultAuthDataHook(PGauthData type, PGconn *conn, void *data)
Definition: fe-auth.c:1601

References PQauthDataHook, and PQdefaultAuthDataHook().

Referenced by main().

Variable Documentation

◆ PQauthDataHook