1/*-------------------------------------------------------------------------
4 * The front-end (client) GSSAPI common code
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/interfaces/libpq/fe-gssapi-common.c
11 *-------------------------------------------------------------------------
22 * Fetch all errors of a specific type and append to "str".
23 * Each error string is preceded by a space.
30 OM_uint32 msg_ctx = 0;
34 if (gss_display_status(&lmin_s,
stat,
type, GSS_C_NO_OID,
35 &msg_ctx, &lmsg) != GSS_S_COMPLETE)
39 gss_release_buffer(&lmin_s, &lmsg);
44 * GSSAPI errors contain two parts; put both into conn->errorMessage.
48 OM_uint32 maj_stat, OM_uint32 min_stat)
58 * Check if we can acquire credentials at all (and yield them if so).
65 gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
67 major = gss_acquire_cred(&minor, GSS_C_NO_NAME, 0, GSS_C_NO_OID_SET,
68 GSS_C_INITIATE, &cred, NULL, NULL);
69 if (major != GSS_S_COMPLETE)
79 * Try to load service name for a connection
87 gss_buffer_desc temp_gbuf;
90 if (
conn->gtarg_nam != NULL)
91 /* Already taken care of - move along */
95 if (!(host && host[0] !=
'0円'))
102 * Import service principal name so the proper ticket can be acquired by
106 temp_gbuf.value = (
char *)
malloc(maxlen);
107 if (!temp_gbuf.value)
112 snprintf(temp_gbuf.value, maxlen,
"%s@%s",
114 temp_gbuf.length = strlen(temp_gbuf.value);
116 maj_stat = gss_import_name(&min_stat, &temp_gbuf,
117 GSS_C_NT_HOSTBASED_SERVICE, &
conn->gtarg_nam);
118 free(temp_gbuf.value);
120 if (maj_stat != GSS_S_COMPLETE)
char * PQhost(const PGconn *conn)
void pg_GSS_error(const char *mprefix, PGconn *conn, OM_uint32 maj_stat, OM_uint32 min_stat)
int pg_GSS_load_servicename(PGconn *conn)
static void pg_GSS_error_int(PQExpBuffer str, OM_uint32 stat, int type)
bool pg_GSS_have_cred_cache(gss_cred_id_t *cred_out)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
PQExpBufferData errorMessage