PostgreSQL Source Code git master
Loading...
Searching...
No Matches
fe-gssapi-common.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * fe-gssapi-common.c
4 * The front-end (client) GSSAPI common code
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/interfaces/libpq/fe-gssapi-common.c
11 *-------------------------------------------------------------------------
12 */
13
14#include "postgres_fe.h"
15
16#include "fe-gssapi-common.h"
17
18#include "libpq-int.h"
19#include "pqexpbuffer.h"
20
21/*
22 * Fetch all errors of a specific type and append to "str".
23 * Each error string is preceded by a space.
24 */
25static void
42
43/*
44 * GSSAPI errors contain two parts; put both into conn->errorMessage.
45 */
46void
56
57/*
58 * Check if we can acquire credentials at all (and yield them if so).
59 */
60bool
77
78/*
79 * Try to load service name for a connection
80 */
81int
83{
86 int maxlen;
88 char *host;
89
90 if (conn->gtarg_nam != NULL)
91 /* Already taken care of - move along */
92 return STATUS_OK;
93
94 host = PQhost(conn);
95 if (!(host && host[0] != '\0'))
96 {
97 libpq_append_conn_error(conn, "host name must be specified");
98 return STATUS_ERROR;
99 }
100
101 /*
102 * Import service principal name so the proper ticket can be acquired by
103 * the GSSAPI system.
104 */
105 maxlen = strlen(conn->krbsrvname) + strlen(host) + 2;
106 temp_gbuf.value = (char *) malloc(maxlen);
107 if (!temp_gbuf.value)
108 {
109 libpq_append_conn_error(conn, "out of memory");
110 return STATUS_ERROR;
111 }
112 snprintf(temp_gbuf.value, maxlen, "%s@%s",
113 conn->krbsrvname, host);
114 temp_gbuf.length = strlen(temp_gbuf.value);
115
117 GSS_C_NT_HOSTBASED_SERVICE, &conn->gtarg_nam);
118 free(temp_gbuf.value);
119
121 {
122 pg_GSS_error(libpq_gettext("GSSAPI name import error"),
123 conn,
125 return STATUS_ERROR;
126 }
127 return STATUS_OK;
128}
#define STATUS_OK
Definition c.h:1158
#define STATUS_ERROR
Definition c.h:1159
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)
const char * str
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
Definition oauth-utils.c:95
#define libpq_gettext(x)
Definition oauth-utils.h:86
#define snprintf
Definition port.h:260
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
static int fb(int x)
#define free(a)
#define malloc(a)
PGconn * conn
Definition streamutil.c:52
PQExpBufferData errorMessage
Definition libpq-int.h:683
char * krbsrvname
Definition libpq-int.h:419
const char * type