PostgreSQL Source Code  git master
be-gssapi-common.c File Reference
#include "postgres.h"
#include "libpq/be-gssapi-common.h"
Include dependency graph for be-gssapi-common.c:

Go to the source code of this file.

Functions

static void pg_GSS_error_int (char *s, size_t len, OM_uint32 stat, int type)
 
void pg_GSS_error (const char *errmsg, OM_uint32 maj_stat, OM_uint32 min_stat)
 

Function Documentation

◆ pg_GSS_error()

void pg_GSS_error ( const char *  errmsg,
OM_uint32  maj_stat,
OM_uint32  min_stat 
)

Definition at line 75 of file be-gssapi-common.c.

References COMMERROR, ereport, errdetail_internal(), errmsg_internal(), and pg_GSS_error_int().

Referenced by be_gssapi_read(), be_gssapi_write(), CheckMD5Auth(), pg_GSS_read(), pg_GSS_write(), pqsecure_open_gss(), and secure_open_gssapi().

77 {
78  char msg_major[128],
79  msg_minor[128];
80 
81  /* Fetch major status message */
82  pg_GSS_error_int(msg_major, sizeof(msg_major), maj_stat, GSS_C_GSS_CODE);
83 
84  /* Fetch mechanism minor status message */
85  pg_GSS_error_int(msg_minor, sizeof(msg_minor), min_stat, GSS_C_MECH_CODE);
86 
87  /*
88  * errmsg_internal, since translation of the first part must be done
89  * before calling this function anyway.
90  */
92  (errmsg_internal("%s", errmsg),
93  errdetail_internal("%s: %s", msg_major, msg_minor)));
94 }
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1069
static void pg_GSS_error_int(char *s, size_t len, OM_uint32 stat, int type)
#define COMMERROR
Definition: elog.h:30
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ pg_GSS_error_int()

static void pg_GSS_error_int ( char *  s,
size_t  len,
OM_uint32  stat,
int  type 
)
static

Definition at line 25 of file be-gssapi-common.c.

References COMMERROR, elog, i, and Min.

Referenced by pg_GSS_error().

26 {
27  gss_buffer_desc gmsg;
28  size_t i = 0;
29  OM_uint32 lmin_s,
30  msg_ctx = 0;
31 
32  do
33  {
34  if (gss_display_status(&lmin_s, stat, type, GSS_C_NO_OID,
35  &msg_ctx, &gmsg) != GSS_S_COMPLETE)
36  break;
37  if (i > 0)
38  {
39  if (i < len)
40  s[i] = ' ';
41  i++;
42  }
43  if (i < len)
44  memcpy(s + i, gmsg.value, Min(len - i, gmsg.length));
45  i += gmsg.length;
46  gss_release_buffer(&lmin_s, &gmsg);
47  }
48  while (msg_ctx);
49 
50  /* add nul termination */
51  if (i < len)
52  s[i] = '\0';
53  else
54  {
55  elog(COMMERROR, "incomplete GSS error report");
56  s[len - 1] = '\0';
57  }
58 }
#define Min(x, y)
Definition: c.h:986
#define COMMERROR
Definition: elog.h:30
#define elog(elevel,...)
Definition: elog.h:232
int i