PostgreSQL Source Code  git master
fe-gssapi-common.c File Reference
#include "postgres_fe.h"
#include "fe-gssapi-common.h"
#include "libpq-int.h"
#include "pqexpbuffer.h"
Include dependency graph for fe-gssapi-common.c:

Go to the source code of this file.

Functions

static void pg_GSS_error_int (PQExpBuffer str, OM_uint32 stat, int type)
 
void pg_GSS_error (const char *mprefix, PGconn *conn, OM_uint32 maj_stat, OM_uint32 min_stat)
 
bool pg_GSS_have_cred_cache (gss_cred_id_t *cred_out)
 
int pg_GSS_load_servicename (PGconn *conn)
 

Function Documentation

◆ pg_GSS_error()

void pg_GSS_error ( const char *  mprefix,
PGconn conn,
OM_uint32  maj_stat,
OM_uint32  min_stat 
)

Definition at line 47 of file fe-gssapi-common.c.

49 {
50  appendPQExpBuffer(&conn->errorMessage, "%s:", mprefix);
51  pg_GSS_error_int(&conn->errorMessage, maj_stat, GSS_C_GSS_CODE);
53  pg_GSS_error_int(&conn->errorMessage, min_stat, GSS_C_MECH_CODE);
55 }
static void pg_GSS_error_int(PQExpBuffer str, OM_uint32 stat, int type)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
PGconn * conn
Definition: streamutil.c:54
PQExpBufferData errorMessage
Definition: libpq-int.h:588

References appendPQExpBuffer(), appendPQExpBufferChar(), conn, pg_conn::errorMessage, and pg_GSS_error_int().

Referenced by pg_GSS_load_servicename().

◆ pg_GSS_error_int()

static void pg_GSS_error_int ( PQExpBuffer  str,
OM_uint32  stat,
int  type 
)
static

Definition at line 26 of file fe-gssapi-common.c.

27 {
28  OM_uint32 lmin_s;
29  gss_buffer_desc lmsg;
30  OM_uint32 msg_ctx = 0;
31 
32  do
33  {
34  if (gss_display_status(&lmin_s, stat, type, GSS_C_NO_OID,
35  &msg_ctx, &lmsg) != GSS_S_COMPLETE)
36  break;
38  appendBinaryPQExpBuffer(str, lmsg.value, lmsg.length);
39  gss_release_buffer(&lmin_s, &lmsg);
40  } while (msg_ctx);
41 }
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:397

References appendBinaryPQExpBuffer(), appendPQExpBufferChar(), generate_unaccent_rules::str, and generate_unaccent_rules::type.

Referenced by pg_GSS_error().

◆ pg_GSS_have_cred_cache()

bool pg_GSS_have_cred_cache ( gss_cred_id_t *  cred_out)

Definition at line 61 of file fe-gssapi-common.c.

62 {
63  OM_uint32 major,
64  minor;
65  gss_cred_id_t cred = GSS_C_NO_CREDENTIAL;
66 
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)
70  {
71  *cred_out = NULL;
72  return false;
73  }
74  *cred_out = cred;
75  return true;
76 }

Referenced by PQconnectPoll().

◆ pg_GSS_load_servicename()

int pg_GSS_load_servicename ( PGconn conn)

Definition at line 82 of file fe-gssapi-common.c.

83 {
84  OM_uint32 maj_stat,
85  min_stat;
86  int maxlen;
87  gss_buffer_desc temp_gbuf;
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 
116  maj_stat = gss_import_name(&min_stat, &temp_gbuf,
117  GSS_C_NT_HOSTBASED_SERVICE, &conn->gtarg_nam);
118  free(temp_gbuf.value);
119 
120  if (maj_stat != GSS_S_COMPLETE)
121  {
122  pg_GSS_error(libpq_gettext("GSSAPI name import error"),
123  conn,
124  maj_stat, min_stat);
125  return STATUS_ERROR;
126  }
127  return STATUS_OK;
128 }
#define STATUS_OK
Definition: c.h:1108
#define STATUS_ERROR
Definition: c.h:1109
char * PQhost(const PGconn *conn)
Definition: fe-connect.c:6622
void pg_GSS_error(const char *mprefix, PGconn *conn, OM_uint32 maj_stat, OM_uint32 min_stat)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
Definition: fe-misc.c:1312
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
#define libpq_gettext(x)
Definition: libpq-int.h:882
#define snprintf
Definition: port.h:238
char * krbsrvname
Definition: libpq-int.h:393

References conn, free, pg_conn::krbsrvname, libpq_append_conn_error(), libpq_gettext, malloc, pg_GSS_error(), PQhost(), snprintf, STATUS_ERROR, and STATUS_OK.

Referenced by pqsecure_open_gss().