PostgreSQL Source Code  git master
fe-auth.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * fe-auth.c
4  * The front-end (client) authorization routines
5  *
6  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/interfaces/libpq/fe-auth.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 
15 /*
16  * INTERFACE ROUTINES
17  * frontend (client) routines:
18  * pg_fe_sendauth send authentication information
19  * pg_fe_getauthname get user's name according to the client side
20  * of the authentication system
21  */
22 
23 #include "postgres_fe.h"
24 
25 #ifdef WIN32
26 #include "win32.h"
27 #else
28 #include <unistd.h>
29 #include <fcntl.h>
30 #include <sys/param.h> /* for MAXHOSTNAMELEN on most */
31 #include <sys/socket.h>
32 #ifdef HAVE_SYS_UCRED_H
33 #include <sys/ucred.h>
34 #endif
35 #ifndef MAXHOSTNAMELEN
36 #include <netdb.h> /* for MAXHOSTNAMELEN on some */
37 #endif
38 #endif
39 
40 #include "common/md5.h"
41 #include "common/scram-common.h"
42 #include "fe-auth.h"
43 #include "fe-auth-sasl.h"
44 #include "libpq-fe.h"
45 
46 #ifdef ENABLE_GSS
47 /*
48  * GSSAPI authentication system.
49  */
50 
51 #include "fe-gssapi-common.h"
52 
53 /*
54  * Continue GSS authentication with next token as needed.
55  */
56 static int
57 pg_GSS_continue(PGconn *conn, int payloadlen)
58 {
59  OM_uint32 maj_stat,
60  min_stat,
61  lmin_s;
62  gss_buffer_desc ginbuf;
63  gss_buffer_desc goutbuf;
64 
65  /*
66  * On first call, there's no input token. On subsequent calls, read the
67  * input token into a GSS buffer.
68  */
69  if (conn->gctx != GSS_C_NO_CONTEXT)
70  {
71  ginbuf.length = payloadlen;
72  ginbuf.value = malloc(payloadlen);
73  if (!ginbuf.value)
74  {
75  libpq_append_conn_error(conn, "out of memory allocating GSSAPI buffer (%d)",
76  payloadlen);
77  return STATUS_ERROR;
78  }
79  if (pqGetnchar(ginbuf.value, payloadlen, conn))
80  {
81  /*
82  * Shouldn't happen, because the caller should've ensured that the
83  * whole message is already in the input buffer.
84  */
85  free(ginbuf.value);
86  return STATUS_ERROR;
87  }
88  }
89  else
90  {
91  ginbuf.length = 0;
92  ginbuf.value = NULL;
93  }
94 
95  maj_stat = gss_init_sec_context(&min_stat,
96  GSS_C_NO_CREDENTIAL,
97  &conn->gctx,
98  conn->gtarg_nam,
99  GSS_C_NO_OID,
100  GSS_C_MUTUAL_FLAG,
101  0,
102  GSS_C_NO_CHANNEL_BINDINGS,
103  (ginbuf.value == NULL) ? GSS_C_NO_BUFFER : &ginbuf,
104  NULL,
105  &goutbuf,
106  NULL,
107  NULL);
108 
109  free(ginbuf.value);
110 
111  if (goutbuf.length != 0)
112  {
113  /*
114  * GSS generated data to send to the server. We don't care if it's the
115  * first or subsequent packet, just send the same kind of password
116  * packet.
117  */
118  if (pqPacketSend(conn, 'p',
119  goutbuf.value, goutbuf.length) != STATUS_OK)
120  {
121  gss_release_buffer(&lmin_s, &goutbuf);
122  return STATUS_ERROR;
123  }
124  }
125  gss_release_buffer(&lmin_s, &goutbuf);
126 
127  if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED)
128  {
129  pg_GSS_error(libpq_gettext("GSSAPI continuation error"),
130  conn,
131  maj_stat, min_stat);
132  gss_release_name(&lmin_s, &conn->gtarg_nam);
133  if (conn->gctx)
134  gss_delete_sec_context(&lmin_s, &conn->gctx, GSS_C_NO_BUFFER);
135  return STATUS_ERROR;
136  }
137 
138  if (maj_stat == GSS_S_COMPLETE)
139  {
140  conn->client_finished_auth = true;
141  gss_release_name(&lmin_s, &conn->gtarg_nam);
142  }
143 
144  return STATUS_OK;
145 }
146 
147 /*
148  * Send initial GSS authentication token
149  */
150 static int
151 pg_GSS_startup(PGconn *conn, int payloadlen)
152 {
153  int ret;
154  char *host = conn->connhost[conn->whichhost].host;
155 
156  if (!(host && host[0] != '\0'))
157  {
158  libpq_append_conn_error(conn, "host name must be specified");
159  return STATUS_ERROR;
160  }
161 
162  if (conn->gctx)
163  {
164  libpq_append_conn_error(conn, "duplicate GSS authentication request");
165  return STATUS_ERROR;
166  }
167 
169  if (ret != STATUS_OK)
170  return ret;
171 
172  /*
173  * Initial packet is the same as a continuation packet with no initial
174  * context.
175  */
176  conn->gctx = GSS_C_NO_CONTEXT;
177 
178  return pg_GSS_continue(conn, payloadlen);
179 }
180 #endif /* ENABLE_GSS */
181 
182 
183 #ifdef ENABLE_SSPI
184 /*
185  * SSPI authentication system (Windows only)
186  */
187 
188 static void
189 pg_SSPI_error(PGconn *conn, const char *mprefix, SECURITY_STATUS r)
190 {
191  char sysmsg[256];
192 
193  if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS |
194  FORMAT_MESSAGE_FROM_SYSTEM,
195  NULL, r, 0,
196  sysmsg, sizeof(sysmsg), NULL) == 0)
197  appendPQExpBuffer(&conn->errorMessage, "%s: SSPI error %x\n",
198  mprefix, (unsigned int) r);
199  else
200  appendPQExpBuffer(&conn->errorMessage, "%s: %s (%x)\n",
201  mprefix, sysmsg, (unsigned int) r);
202 }
203 
204 /*
205  * Continue SSPI authentication with next token as needed.
206  */
207 static int
208 pg_SSPI_continue(PGconn *conn, int payloadlen)
209 {
210  SECURITY_STATUS r;
211  CtxtHandle newContext;
212  ULONG contextAttr;
213  SecBufferDesc inbuf;
214  SecBufferDesc outbuf;
215  SecBuffer OutBuffers[1];
216  SecBuffer InBuffers[1];
217  char *inputbuf = NULL;
218 
219  if (conn->sspictx != NULL)
220  {
221  /*
222  * On runs other than the first we have some data to send. Put this
223  * data in a SecBuffer type structure.
224  */
225  inputbuf = malloc(payloadlen);
226  if (!inputbuf)
227  {
228  libpq_append_conn_error(conn, "out of memory allocating SSPI buffer (%d)",
229  payloadlen);
230  return STATUS_ERROR;
231  }
232  if (pqGetnchar(inputbuf, payloadlen, conn))
233  {
234  /*
235  * Shouldn't happen, because the caller should've ensured that the
236  * whole message is already in the input buffer.
237  */
238  free(inputbuf);
239  return STATUS_ERROR;
240  }
241 
242  inbuf.ulVersion = SECBUFFER_VERSION;
243  inbuf.cBuffers = 1;
244  inbuf.pBuffers = InBuffers;
245  InBuffers[0].pvBuffer = inputbuf;
246  InBuffers[0].cbBuffer = payloadlen;
247  InBuffers[0].BufferType = SECBUFFER_TOKEN;
248  }
249 
250  OutBuffers[0].pvBuffer = NULL;
251  OutBuffers[0].BufferType = SECBUFFER_TOKEN;
252  OutBuffers[0].cbBuffer = 0;
253  outbuf.cBuffers = 1;
254  outbuf.pBuffers = OutBuffers;
255  outbuf.ulVersion = SECBUFFER_VERSION;
256 
257  r = InitializeSecurityContext(conn->sspicred,
258  conn->sspictx,
259  conn->sspitarget,
260  ISC_REQ_ALLOCATE_MEMORY,
261  0,
262  SECURITY_NETWORK_DREP,
263  (conn->sspictx == NULL) ? NULL : &inbuf,
264  0,
265  &newContext,
266  &outbuf,
267  &contextAttr,
268  NULL);
269 
270  /* we don't need the input anymore */
271  free(inputbuf);
272 
273  if (r != SEC_E_OK && r != SEC_I_CONTINUE_NEEDED)
274  {
275  pg_SSPI_error(conn, libpq_gettext("SSPI continuation error"), r);
276 
277  return STATUS_ERROR;
278  }
279 
280  if (conn->sspictx == NULL)
281  {
282  /* On first run, transfer retrieved context handle */
283  conn->sspictx = malloc(sizeof(CtxtHandle));
284  if (conn->sspictx == NULL)
285  {
286  libpq_append_conn_error(conn, "out of memory");
287  return STATUS_ERROR;
288  }
289  memcpy(conn->sspictx, &newContext, sizeof(CtxtHandle));
290  }
291 
292  /*
293  * If SSPI returned any data to be sent to the server (as it normally
294  * would), send this data as a password packet.
295  */
296  if (outbuf.cBuffers > 0)
297  {
298  if (outbuf.cBuffers != 1)
299  {
300  /*
301  * This should never happen, at least not for Kerberos
302  * authentication. Keep check in case it shows up with other
303  * authentication methods later.
304  */
306  "SSPI returned invalid number of output buffers\n");
307  return STATUS_ERROR;
308  }
309 
310  /*
311  * If the negotiation is complete, there may be zero bytes to send.
312  * The server is at this point not expecting any more data, so don't
313  * send it.
314  */
315  if (outbuf.pBuffers[0].cbBuffer > 0)
316  {
317  if (pqPacketSend(conn, 'p',
318  outbuf.pBuffers[0].pvBuffer, outbuf.pBuffers[0].cbBuffer))
319  {
320  FreeContextBuffer(outbuf.pBuffers[0].pvBuffer);
321  return STATUS_ERROR;
322  }
323  }
324  FreeContextBuffer(outbuf.pBuffers[0].pvBuffer);
325  }
326 
327  if (r == SEC_E_OK)
328  conn->client_finished_auth = true;
329 
330  /* Cleanup is handled by the code in freePGconn() */
331  return STATUS_OK;
332 }
333 
334 /*
335  * Send initial SSPI authentication token.
336  * If use_negotiate is 0, use kerberos authentication package which is
337  * compatible with Unix. If use_negotiate is 1, use the negotiate package
338  * which supports both kerberos and NTLM, but is not compatible with Unix.
339  */
340 static int
341 pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
342 {
343  SECURITY_STATUS r;
344  TimeStamp expire;
345  char *host = conn->connhost[conn->whichhost].host;
346 
347  if (conn->sspictx)
348  {
349  libpq_append_conn_error(conn, "duplicate SSPI authentication request");
350  return STATUS_ERROR;
351  }
352 
353  /*
354  * Retrieve credentials handle
355  */
356  conn->sspicred = malloc(sizeof(CredHandle));
357  if (conn->sspicred == NULL)
358  {
359  libpq_append_conn_error(conn, "out of memory");
360  return STATUS_ERROR;
361  }
362 
363  r = AcquireCredentialsHandle(NULL,
364  use_negotiate ? "negotiate" : "kerberos",
365  SECPKG_CRED_OUTBOUND,
366  NULL,
367  NULL,
368  NULL,
369  NULL,
370  conn->sspicred,
371  &expire);
372  if (r != SEC_E_OK)
373  {
374  pg_SSPI_error(conn, libpq_gettext("could not acquire SSPI credentials"), r);
375  free(conn->sspicred);
376  conn->sspicred = NULL;
377  return STATUS_ERROR;
378  }
379 
380  /*
381  * Compute target principal name. SSPI has a different format from GSSAPI,
382  * but not more complex. We can skip the @REALM part, because Windows will
383  * fill that in for us automatically.
384  */
385  if (!(host && host[0] != '\0'))
386  {
387  libpq_append_conn_error(conn, "host name must be specified");
388  return STATUS_ERROR;
389  }
390  conn->sspitarget = malloc(strlen(conn->krbsrvname) + strlen(host) + 2);
391  if (!conn->sspitarget)
392  {
393  libpq_append_conn_error(conn, "out of memory");
394  return STATUS_ERROR;
395  }
396  sprintf(conn->sspitarget, "%s/%s", conn->krbsrvname, host);
397 
398  /*
399  * Indicate that we're in SSPI authentication mode to make sure that
400  * pg_SSPI_continue is called next time in the negotiation.
401  */
402  conn->usesspi = 1;
403 
404  return pg_SSPI_continue(conn, payloadlen);
405 }
406 #endif /* ENABLE_SSPI */
407 
408 /*
409  * Initialize SASL authentication exchange.
410  */
411 static int
412 pg_SASL_init(PGconn *conn, int payloadlen)
413 {
414  char *initialresponse = NULL;
415  int initialresponselen;
416  bool done;
417  bool success;
418  const char *selected_mechanism;
419  PQExpBufferData mechanism_buf;
420  char *password;
421 
422  initPQExpBuffer(&mechanism_buf);
423 
424  if (conn->channel_binding[0] == 'r' && /* require */
425  !conn->ssl_in_use)
426  {
427  libpq_append_conn_error(conn, "channel binding required, but SSL not in use");
428  goto error;
429  }
430 
431  if (conn->sasl_state)
432  {
433  libpq_append_conn_error(conn, "duplicate SASL authentication request");
434  goto error;
435  }
436 
437  /*
438  * Parse the list of SASL authentication mechanisms in the
439  * AuthenticationSASL message, and select the best mechanism that we
440  * support. SCRAM-SHA-256-PLUS and SCRAM-SHA-256 are the only ones
441  * supported at the moment, listed by order of decreasing importance.
442  */
443  selected_mechanism = NULL;
444  for (;;)
445  {
446  if (pqGets(&mechanism_buf, conn))
447  {
449  "fe_sendauth: invalid authentication request from server: invalid list of authentication mechanisms\n");
450  goto error;
451  }
452  if (PQExpBufferDataBroken(mechanism_buf))
453  goto oom_error;
454 
455  /* An empty string indicates end of list */
456  if (mechanism_buf.data[0] == '\0')
457  break;
458 
459  /*
460  * Select the mechanism to use. Pick SCRAM-SHA-256-PLUS over anything
461  * else if a channel binding type is set and if the client supports it
462  * (and did not set channel_binding=disable). Pick SCRAM-SHA-256 if
463  * nothing else has already been picked. If we add more mechanisms, a
464  * more refined priority mechanism might become necessary.
465  */
466  if (strcmp(mechanism_buf.data, SCRAM_SHA_256_PLUS_NAME) == 0)
467  {
468  if (conn->ssl_in_use)
469  {
470  /* The server has offered SCRAM-SHA-256-PLUS. */
471 
472 #ifdef HAVE_PGTLS_GET_PEER_CERTIFICATE_HASH
473  /*
474  * The client supports channel binding, which is chosen if
475  * channel_binding is not disabled.
476  */
477  if (conn->channel_binding[0] != 'd') /* disable */
478  {
479  selected_mechanism = SCRAM_SHA_256_PLUS_NAME;
480  conn->sasl = &pg_scram_mech;
481  }
482 #else
483  /*
484  * The client does not support channel binding. If it is
485  * required, complain immediately instead of the error below
486  * which would be confusing as the server is publishing
487  * SCRAM-SHA-256-PLUS.
488  */
489  if (conn->channel_binding[0] == 'r') /* require */
490  {
491  libpq_append_conn_error(conn, "channel binding is required, but client does not support it");
492  goto error;
493  }
494 #endif
495  }
496  else
497  {
498  /*
499  * The server offered SCRAM-SHA-256-PLUS, but the connection
500  * is not SSL-encrypted. That's not sane. Perhaps SSL was
501  * stripped by a proxy? There's no point in continuing,
502  * because the server will reject the connection anyway if we
503  * try authenticate without channel binding even though both
504  * the client and server supported it. The SCRAM exchange
505  * checks for that, to prevent downgrade attacks.
506  */
507  libpq_append_conn_error(conn, "server offered SCRAM-SHA-256-PLUS authentication over a non-SSL connection");
508  goto error;
509  }
510  }
511  else if (strcmp(mechanism_buf.data, SCRAM_SHA_256_NAME) == 0 &&
512  !selected_mechanism)
513  {
514  selected_mechanism = SCRAM_SHA_256_NAME;
515  conn->sasl = &pg_scram_mech;
516  }
517  }
518 
519  if (!selected_mechanism)
520  {
521  libpq_append_conn_error(conn, "none of the server's SASL authentication mechanisms are supported");
522  goto error;
523  }
524 
525  if (conn->channel_binding[0] == 'r' && /* require */
526  strcmp(selected_mechanism, SCRAM_SHA_256_PLUS_NAME) != 0)
527  {
528  libpq_append_conn_error(conn, "channel binding is required, but server did not offer an authentication method that supports channel binding");
529  goto error;
530  }
531 
532  /*
533  * Now that the SASL mechanism has been chosen for the exchange,
534  * initialize its state information.
535  */
536 
537  /*
538  * First, select the password to use for the exchange, complaining if
539  * there isn't one. Currently, all supported SASL mechanisms require a
540  * password, so we can just go ahead here without further distinction.
541  */
542  conn->password_needed = true;
544  if (password == NULL)
545  password = conn->pgpass;
546  if (password == NULL || password[0] == '\0')
547  {
550  goto error;
551  }
552 
553  Assert(conn->sasl);
554 
555  /*
556  * Initialize the SASL state information with all the information gathered
557  * during the initial exchange.
558  *
559  * Note: Only tls-unique is supported for the moment.
560  */
562  password,
563  selected_mechanism);
564  if (!conn->sasl_state)
565  goto oom_error;
566 
567  /* Get the mechanism-specific Initial Client Response, if any */
569  NULL, -1,
570  &initialresponse, &initialresponselen,
571  &done, &success);
572 
573  if (done && !success)
574  goto error;
575 
576  /*
577  * Build a SASLInitialResponse message, and send it.
578  */
579  if (pqPutMsgStart('p', conn))
580  goto error;
581  if (pqPuts(selected_mechanism, conn))
582  goto error;
583  if (initialresponse)
584  {
585  if (pqPutInt(initialresponselen, 4, conn))
586  goto error;
587  if (pqPutnchar(initialresponse, initialresponselen, conn))
588  goto error;
589  }
590  if (pqPutMsgEnd(conn))
591  goto error;
592  if (pqFlush(conn))
593  goto error;
594 
595  termPQExpBuffer(&mechanism_buf);
596  free(initialresponse);
597 
598  return STATUS_OK;
599 
600 error:
601  termPQExpBuffer(&mechanism_buf);
602  free(initialresponse);
603  return STATUS_ERROR;
604 
605 oom_error:
606  termPQExpBuffer(&mechanism_buf);
607  free(initialresponse);
608  libpq_append_conn_error(conn, "out of memory");
609  return STATUS_ERROR;
610 }
611 
612 /*
613  * Exchange a message for SASL communication protocol with the backend.
614  * This should be used after calling pg_SASL_init to set up the status of
615  * the protocol.
616  */
617 static int
618 pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
619 {
620  char *output;
621  int outputlen;
622  bool done;
623  bool success;
624  int res;
625  char *challenge;
626 
627  /* Read the SASL challenge from the AuthenticationSASLContinue message. */
628  challenge = malloc(payloadlen + 1);
629  if (!challenge)
630  {
631  libpq_append_conn_error(conn, "out of memory allocating SASL buffer (%d)",
632  payloadlen);
633  return STATUS_ERROR;
634  }
635 
636  if (pqGetnchar(challenge, payloadlen, conn))
637  {
638  free(challenge);
639  return STATUS_ERROR;
640  }
641  /* For safety and convenience, ensure the buffer is NULL-terminated. */
642  challenge[payloadlen] = '\0';
643 
645  challenge, payloadlen,
646  &output, &outputlen,
647  &done, &success);
648  free(challenge); /* don't need the input anymore */
649 
650  if (final && !done)
651  {
652  if (outputlen != 0)
653  free(output);
654 
655  libpq_append_conn_error(conn, "AuthenticationSASLFinal received from server, but SASL authentication was not completed");
656  return STATUS_ERROR;
657  }
658 
659  /*
660  * If the exchange is not completed yet, we need to make sure that the
661  * SASL mechanism has generated a message to send back.
662  */
663  if (output == NULL && !done)
664  {
665  libpq_append_conn_error(conn, "no client response found after SASL exchange success");
666  return STATUS_ERROR;
667  }
668 
669  /*
670  * SASL allows zero-length responses, so this check uses "output" and not
671  * "outputlen" to allow the case of an empty message.
672  */
673  if (output)
674  {
675  /*
676  * Send the SASL response to the server.
677  */
678  res = pqPacketSend(conn, 'p', output, outputlen);
679  free(output);
680 
681  if (res != STATUS_OK)
682  return STATUS_ERROR;
683  }
684 
685  if (done && !success)
686  return STATUS_ERROR;
687 
688  return STATUS_OK;
689 }
690 
691 static int
693 {
694  int ret;
695  char *crypt_pwd = NULL;
696  const char *pwd_to_send;
697  char md5Salt[4];
698 
699  /* Read the salt from the AuthenticationMD5Password message. */
700  if (areq == AUTH_REQ_MD5)
701  {
702  if (pqGetnchar(md5Salt, 4, conn))
703  return STATUS_ERROR; /* shouldn't happen */
704  }
705 
706  /* Encrypt the password if needed. */
707 
708  switch (areq)
709  {
710  case AUTH_REQ_MD5:
711  {
712  char *crypt_pwd2;
713  const char *errstr = NULL;
714 
715  /* Allocate enough space for two MD5 hashes */
716  crypt_pwd = malloc(2 * (MD5_PASSWD_LEN + 1));
717  if (!crypt_pwd)
718  {
719  libpq_append_conn_error(conn, "out of memory");
720  return STATUS_ERROR;
721  }
722 
723  crypt_pwd2 = crypt_pwd + MD5_PASSWD_LEN + 1;
725  strlen(conn->pguser), crypt_pwd2,
726  &errstr))
727  {
728  libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
729  free(crypt_pwd);
730  return STATUS_ERROR;
731  }
732  if (!pg_md5_encrypt(crypt_pwd2 + strlen("md5"), md5Salt,
733  4, crypt_pwd, &errstr))
734  {
735  libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
736  free(crypt_pwd);
737  return STATUS_ERROR;
738  }
739 
740  pwd_to_send = crypt_pwd;
741  break;
742  }
743  case AUTH_REQ_PASSWORD:
744  pwd_to_send = password;
745  break;
746  default:
747  return STATUS_ERROR;
748  }
749  ret = pqPacketSend(conn, 'p', pwd_to_send, strlen(pwd_to_send) + 1);
750  free(crypt_pwd);
751  return ret;
752 }
753 
754 /*
755  * Translate a disallowed AuthRequest code into an error message.
756  */
757 static const char *
759 {
760  switch (areq)
761  {
762  case AUTH_REQ_PASSWORD:
763  return libpq_gettext("server requested a cleartext password");
764  case AUTH_REQ_MD5:
765  return libpq_gettext("server requested a hashed password");
766  case AUTH_REQ_GSS:
767  case AUTH_REQ_GSS_CONT:
768  return libpq_gettext("server requested GSSAPI authentication");
769  case AUTH_REQ_SSPI:
770  return libpq_gettext("server requested SSPI authentication");
771  case AUTH_REQ_SASL:
772  case AUTH_REQ_SASL_CONT:
773  case AUTH_REQ_SASL_FIN:
774  return libpq_gettext("server requested SASL authentication");
775  }
776 
777  return libpq_gettext("server requested an unknown authentication type");
778 }
779 
780 /*
781  * Convenience macro for checking the allowed_auth_methods bitmask. Caller
782  * must ensure that type is not greater than 31 (high bit of the bitmask).
783  */
784 #define auth_method_allowed(conn, type) \
785  (((conn)->allowed_auth_methods & (1 << (type))) != 0)
786 
787 /*
788  * Verify that the authentication request is expected, given the connection
789  * parameters. This is especially important when the client wishes to
790  * authenticate the server before any sensitive information is exchanged.
791  */
792 static bool
794 {
795  bool result = true;
796  const char *reason = NULL;
797 
798  StaticAssertDecl((sizeof(conn->allowed_auth_methods) * CHAR_BIT) > AUTH_REQ_MAX,
799  "AUTH_REQ_MAX overflows the allowed_auth_methods bitmask");
800 
801  /*
802  * If the user required a specific auth method, or specified an allowed
803  * set, then reject all others here, and make sure the server actually
804  * completes an authentication exchange.
805  */
806  if (conn->require_auth)
807  {
808  switch (areq)
809  {
810  case AUTH_REQ_OK:
811 
812  /*
813  * Check to make sure we've actually finished our exchange (or
814  * else that the user has allowed an authentication-less
815  * connection).
816  *
817  * If the user has allowed both SCRAM and unauthenticated
818  * (trust) connections, then this check will silently accept
819  * partial SCRAM exchanges, where a misbehaving server does
820  * not provide its verifier before sending an OK. This is
821  * consistent with historical behavior, but it may be a point
822  * to revisit in the future, since it could allow a server
823  * that doesn't know the user's password to silently harvest
824  * material for a brute force attack.
825  */
827  break;
828 
829  /*
830  * No explicit authentication request was made by the server
831  * -- or perhaps it was made and not completed, in the case of
832  * SCRAM -- but there is one special case to check. If the
833  * user allowed "gss", then a GSS-encrypted channel also
834  * satisfies the check.
835  */
836 #ifdef ENABLE_GSS
837  if (auth_method_allowed(conn, AUTH_REQ_GSS) && conn->gssenc)
838  {
839  /*
840  * If implicit GSS auth has already been performed via GSS
841  * encryption, we don't need to have performed an
842  * AUTH_REQ_GSS exchange. This allows require_auth=gss to
843  * be combined with gssencmode, since there won't be an
844  * explicit authentication request in that case.
845  */
846  }
847  else
848 #endif
849  {
850  reason = libpq_gettext("server did not complete authentication");
851  result = false;
852  }
853 
854  break;
855 
856  case AUTH_REQ_PASSWORD:
857  case AUTH_REQ_MD5:
858  case AUTH_REQ_GSS:
859  case AUTH_REQ_GSS_CONT:
860  case AUTH_REQ_SSPI:
861  case AUTH_REQ_SASL:
862  case AUTH_REQ_SASL_CONT:
863  case AUTH_REQ_SASL_FIN:
864 
865  /*
866  * We don't handle these with the default case, to avoid
867  * bit-shifting past the end of the allowed_auth_methods mask
868  * if the server sends an unexpected AuthRequest.
869  */
870  result = auth_method_allowed(conn, areq);
871  break;
872 
873  default:
874  result = false;
875  break;
876  }
877  }
878 
879  if (!result)
880  {
881  if (!reason)
882  reason = auth_method_description(areq);
883 
884  libpq_append_conn_error(conn, "auth method \"%s\" requirement failed: %s",
885  conn->require_auth, reason);
886  return result;
887  }
888 
889  /*
890  * When channel_binding=require, we must protect against two cases: (1) we
891  * must not respond to non-SASL authentication requests, which might leak
892  * information such as the client's password; and (2) even if we receive
893  * AUTH_REQ_OK, we still must ensure that channel binding has happened in
894  * order to authenticate the server.
895  */
896  if (conn->channel_binding[0] == 'r' /* require */ )
897  {
898  switch (areq)
899  {
900  case AUTH_REQ_SASL:
901  case AUTH_REQ_SASL_CONT:
902  case AUTH_REQ_SASL_FIN:
903  break;
904  case AUTH_REQ_OK:
906  {
907  libpq_append_conn_error(conn, "channel binding required, but server authenticated client without channel binding");
908  result = false;
909  }
910  break;
911  default:
912  libpq_append_conn_error(conn, "channel binding required but not supported by server's authentication request");
913  result = false;
914  break;
915  }
916  }
917 
918  return result;
919 }
920 
921 /*
922  * pg_fe_sendauth
923  * client demux routine for processing an authentication request
924  *
925  * The server has sent us an authentication challenge (or OK). Send an
926  * appropriate response. The caller has ensured that the whole message is
927  * now in the input buffer, and has already read the type and length of
928  * it. We are responsible for reading any remaining extra data, specific
929  * to the authentication method. 'payloadlen' is the remaining length in
930  * the message.
931  */
932 int
933 pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
934 {
935  int oldmsglen;
936 
937  if (!check_expected_areq(areq, conn))
938  return STATUS_ERROR;
939 
940  switch (areq)
941  {
942  case AUTH_REQ_OK:
943  break;
944 
945  case AUTH_REQ_KRB4:
946  libpq_append_conn_error(conn, "Kerberos 4 authentication not supported");
947  return STATUS_ERROR;
948 
949  case AUTH_REQ_KRB5:
950  libpq_append_conn_error(conn, "Kerberos 5 authentication not supported");
951  return STATUS_ERROR;
952 
953 #if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
954  case AUTH_REQ_GSS:
955 #if !defined(ENABLE_SSPI)
956  /* no native SSPI, so use GSSAPI library for it */
957  case AUTH_REQ_SSPI:
958 #endif
959  {
960  int r;
961 
962  pglock_thread();
963 
964  /*
965  * If we have both GSS and SSPI support compiled in, use SSPI
966  * support by default. This is overridable by a connection
967  * string parameter. Note that when using SSPI we still leave
968  * the negotiate parameter off, since we want SSPI to use the
969  * GSSAPI kerberos protocol. For actual SSPI negotiate
970  * protocol, we use AUTH_REQ_SSPI.
971  */
972 #if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
973  if (conn->gsslib && (pg_strcasecmp(conn->gsslib, "gssapi") == 0))
974  r = pg_GSS_startup(conn, payloadlen);
975  else
976  r = pg_SSPI_startup(conn, 0, payloadlen);
977 #elif defined(ENABLE_GSS) && !defined(ENABLE_SSPI)
978  r = pg_GSS_startup(conn, payloadlen);
979 #elif !defined(ENABLE_GSS) && defined(ENABLE_SSPI)
980  r = pg_SSPI_startup(conn, 0, payloadlen);
981 #endif
982  if (r != STATUS_OK)
983  {
984  /* Error message already filled in. */
985  pgunlock_thread();
986  return STATUS_ERROR;
987  }
988  pgunlock_thread();
989  }
990  break;
991 
992  case AUTH_REQ_GSS_CONT:
993  {
994  int r;
995 
996  pglock_thread();
997 #if defined(ENABLE_GSS) && defined(ENABLE_SSPI)
998  if (conn->usesspi)
999  r = pg_SSPI_continue(conn, payloadlen);
1000  else
1001  r = pg_GSS_continue(conn, payloadlen);
1002 #elif defined(ENABLE_GSS) && !defined(ENABLE_SSPI)
1003  r = pg_GSS_continue(conn, payloadlen);
1004 #elif !defined(ENABLE_GSS) && defined(ENABLE_SSPI)
1005  r = pg_SSPI_continue(conn, payloadlen);
1006 #endif
1007  if (r != STATUS_OK)
1008  {
1009  /* Error message already filled in. */
1010  pgunlock_thread();
1011  return STATUS_ERROR;
1012  }
1013  pgunlock_thread();
1014  }
1015  break;
1016 #else /* defined(ENABLE_GSS) || defined(ENABLE_SSPI) */
1017  /* No GSSAPI *or* SSPI support */
1018  case AUTH_REQ_GSS:
1019  case AUTH_REQ_GSS_CONT:
1020  libpq_append_conn_error(conn, "GSSAPI authentication not supported");
1021  return STATUS_ERROR;
1022 #endif /* defined(ENABLE_GSS) || defined(ENABLE_SSPI) */
1023 
1024 #ifdef ENABLE_SSPI
1025  case AUTH_REQ_SSPI:
1026 
1027  /*
1028  * SSPI has its own startup message so libpq can decide which
1029  * method to use. Indicate to pg_SSPI_startup that we want SSPI
1030  * negotiation instead of Kerberos.
1031  */
1032  pglock_thread();
1033  if (pg_SSPI_startup(conn, 1, payloadlen) != STATUS_OK)
1034  {
1035  /* Error message already filled in. */
1036  pgunlock_thread();
1037  return STATUS_ERROR;
1038  }
1039  pgunlock_thread();
1040  break;
1041 #else
1042 
1043  /*
1044  * No SSPI support. However, if we have GSSAPI but not SSPI
1045  * support, AUTH_REQ_SSPI will have been handled in the codepath
1046  * for AUTH_REQ_GSS above, so don't duplicate the case label in
1047  * that case.
1048  */
1049 #if !defined(ENABLE_GSS)
1050  case AUTH_REQ_SSPI:
1051  libpq_append_conn_error(conn, "SSPI authentication not supported");
1052  return STATUS_ERROR;
1053 #endif /* !define(ENABLE_GSS) */
1054 #endif /* ENABLE_SSPI */
1055 
1056 
1057  case AUTH_REQ_CRYPT:
1058  libpq_append_conn_error(conn, "Crypt authentication not supported");
1059  return STATUS_ERROR;
1060 
1061  case AUTH_REQ_MD5:
1062  case AUTH_REQ_PASSWORD:
1063  {
1064  char *password;
1065 
1066  conn->password_needed = true;
1068  if (password == NULL)
1069  password = conn->pgpass;
1070  if (password == NULL || password[0] == '\0')
1071  {
1074  return STATUS_ERROR;
1075  }
1077  {
1079  "fe_sendauth: error sending password authentication\n");
1080  return STATUS_ERROR;
1081  }
1082 
1083  /* We expect no further authentication requests. */
1084  conn->client_finished_auth = true;
1085  break;
1086  }
1087 
1088  case AUTH_REQ_SASL:
1089 
1090  /*
1091  * The request contains the name (as assigned by IANA) of the
1092  * authentication mechanism.
1093  */
1094  if (pg_SASL_init(conn, payloadlen) != STATUS_OK)
1095  {
1096  /* pg_SASL_init already set the error message */
1097  return STATUS_ERROR;
1098  }
1099  break;
1100 
1101  case AUTH_REQ_SASL_CONT:
1102  case AUTH_REQ_SASL_FIN:
1103  if (conn->sasl_state == NULL)
1104  {
1106  "fe_sendauth: invalid authentication request from server: AUTH_REQ_SASL_CONT without AUTH_REQ_SASL\n");
1107  return STATUS_ERROR;
1108  }
1109  oldmsglen = conn->errorMessage.len;
1110  if (pg_SASL_continue(conn, payloadlen,
1111  (areq == AUTH_REQ_SASL_FIN)) != STATUS_OK)
1112  {
1113  /* Use this message if pg_SASL_continue didn't supply one */
1114  if (conn->errorMessage.len == oldmsglen)
1116  "fe_sendauth: error in SASL authentication\n");
1117  return STATUS_ERROR;
1118  }
1119  break;
1120 
1121  default:
1122  libpq_append_conn_error(conn, "authentication method %u not supported", areq);
1123  return STATUS_ERROR;
1124  }
1125 
1126  return STATUS_OK;
1127 }
1128 
1129 
1130 /*
1131  * pg_fe_getusername
1132  *
1133  * Returns a pointer to malloc'd space containing the name of the
1134  * specified user_id. If there is an error, return NULL, and append
1135  * a suitable error message to *errorMessage if that's not NULL.
1136  *
1137  * Caution: on Windows, the user_id argument is ignored, and we always
1138  * fetch the current user's name.
1139  */
1140 char *
1141 pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
1142 {
1143  char *result = NULL;
1144  const char *name = NULL;
1145 
1146 #ifdef WIN32
1147  /* Microsoft recommends buffer size of UNLEN+1, where UNLEN = 256 */
1148  char username[256 + 1];
1149  DWORD namesize = sizeof(username);
1150 #else
1151  char pwdbuf[BUFSIZ];
1152 #endif
1153 
1154  /*
1155  * Some users are using configure --enable-thread-safety-force, so we
1156  * might as well do the locking within our library to protect getpwuid().
1157  * In fact, application developers can use getpwuid() in their application
1158  * if they use the locking call we provide, or install their own locking
1159  * function using PQregisterThreadLock().
1160  */
1161  pglock_thread();
1162 
1163 #ifdef WIN32
1164  if (GetUserName(username, &namesize))
1165  name = username;
1166  else if (errorMessage)
1167  libpq_append_error(errorMessage,
1168  "user name lookup failure: error code %lu",
1169  GetLastError());
1170 #else
1171  if (pg_get_user_name(user_id, pwdbuf, sizeof(pwdbuf)))
1172  name = pwdbuf;
1173  else if (errorMessage)
1174  appendPQExpBuffer(errorMessage, "%s\n", pwdbuf);
1175 #endif
1176 
1177  if (name)
1178  {
1179  result = strdup(name);
1180  if (result == NULL && errorMessage)
1181  libpq_append_error(errorMessage, "out of memory");
1182  }
1183 
1184  pgunlock_thread();
1185 
1186  return result;
1187 }
1188 
1189 /*
1190  * pg_fe_getauthname
1191  *
1192  * Returns a pointer to malloc'd space containing whatever name the user
1193  * has authenticated to the system. If there is an error, return NULL,
1194  * and append a suitable error message to *errorMessage if that's not NULL.
1195  */
1196 char *
1198 {
1199 #ifdef WIN32
1200  return pg_fe_getusername(0, errorMessage);
1201 #else
1202  return pg_fe_getusername(geteuid(), errorMessage);
1203 #endif
1204 }
1205 
1206 
1207 /*
1208  * PQencryptPassword -- exported routine to encrypt a password with MD5
1209  *
1210  * This function is equivalent to calling PQencryptPasswordConn with
1211  * "md5" as the encryption method, except that this doesn't require
1212  * a connection object. This function is deprecated, use
1213  * PQencryptPasswordConn instead.
1214  */
1215 char *
1216 PQencryptPassword(const char *passwd, const char *user)
1217 {
1218  char *crypt_pwd;
1219  const char *errstr = NULL;
1220 
1221  crypt_pwd = malloc(MD5_PASSWD_LEN + 1);
1222  if (!crypt_pwd)
1223  return NULL;
1224 
1225  if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr))
1226  {
1227  free(crypt_pwd);
1228  return NULL;
1229  }
1230 
1231  return crypt_pwd;
1232 }
1233 
1234 /*
1235  * PQencryptPasswordConn -- exported routine to encrypt a password
1236  *
1237  * This is intended to be used by client applications that wish to send
1238  * commands like ALTER USER joe PASSWORD 'pwd'. The password need not
1239  * be sent in cleartext if it is encrypted on the client side. This is
1240  * good because it ensures the cleartext password won't end up in logs,
1241  * pg_stat displays, etc. We export the function so that clients won't
1242  * be dependent on low-level details like whether the encryption is MD5
1243  * or something else.
1244  *
1245  * Arguments are a connection object, the cleartext password, the SQL
1246  * name of the user it is for, and a string indicating the algorithm to
1247  * use for encrypting the password. If algorithm is NULL, this queries
1248  * the server for the current 'password_encryption' value. If you wish
1249  * to avoid that, e.g. to avoid blocking, you can execute
1250  * 'show password_encryption' yourself before calling this function, and
1251  * pass it as the algorithm.
1252  *
1253  * Return value is a malloc'd string. The client may assume the string
1254  * doesn't contain any special characters that would require escaping.
1255  * On error, an error message is stored in the connection object, and
1256  * returns NULL.
1257  */
1258 char *
1259 PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
1260  const char *algorithm)
1261 {
1262 #define MAX_ALGORITHM_NAME_LEN 50
1263  char algobuf[MAX_ALGORITHM_NAME_LEN + 1];
1264  char *crypt_pwd = NULL;
1265 
1266  if (!conn)
1267  return NULL;
1268 
1270 
1271  /* If no algorithm was given, ask the server. */
1272  if (algorithm == NULL)
1273  {
1274  PGresult *res;
1275  char *val;
1276 
1277  res = PQexec(conn, "show password_encryption");
1278  if (res == NULL)
1279  {
1280  /* PQexec() should've set conn->errorMessage already */
1281  return NULL;
1282  }
1284  {
1285  /* PQexec() should've set conn->errorMessage already */
1286  PQclear(res);
1287  return NULL;
1288  }
1289  if (PQntuples(res) != 1 || PQnfields(res) != 1)
1290  {
1291  PQclear(res);
1292  libpq_append_conn_error(conn, "unexpected shape of result set returned for SHOW");
1293  return NULL;
1294  }
1295  val = PQgetvalue(res, 0, 0);
1296 
1297  if (strlen(val) > MAX_ALGORITHM_NAME_LEN)
1298  {
1299  PQclear(res);
1300  libpq_append_conn_error(conn, "password_encryption value too long");
1301  return NULL;
1302  }
1303  strcpy(algobuf, val);
1304  PQclear(res);
1305 
1306  algorithm = algobuf;
1307  }
1308 
1309  /*
1310  * Also accept "on" and "off" as aliases for "md5", because
1311  * password_encryption was a boolean before PostgreSQL 10. We refuse to
1312  * send the password in plaintext even if it was "off".
1313  */
1314  if (strcmp(algorithm, "on") == 0 ||
1315  strcmp(algorithm, "off") == 0)
1316  algorithm = "md5";
1317 
1318  /*
1319  * Ok, now we know what algorithm to use
1320  */
1321  if (strcmp(algorithm, "scram-sha-256") == 0)
1322  {
1323  const char *errstr = NULL;
1324 
1325  crypt_pwd = pg_fe_scram_build_secret(passwd, &errstr);
1326  if (!crypt_pwd)
1327  libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
1328  }
1329  else if (strcmp(algorithm, "md5") == 0)
1330  {
1331  crypt_pwd = malloc(MD5_PASSWD_LEN + 1);
1332  if (crypt_pwd)
1333  {
1334  const char *errstr = NULL;
1335 
1336  if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr))
1337  {
1338  libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
1339  free(crypt_pwd);
1340  crypt_pwd = NULL;
1341  }
1342  }
1343  else
1344  libpq_append_conn_error(conn, "out of memory");
1345  }
1346  else
1347  {
1348  libpq_append_conn_error(conn, "unrecognized password encryption algorithm \"%s\"",
1349  algorithm);
1350  return NULL;
1351  }
1352 
1353  return crypt_pwd;
1354 }
void pg_GSS_error(const char *errmsg, OM_uint32 maj_stat, OM_uint32 min_stat)
#define STATUS_OK
Definition: c.h:1159
#define StaticAssertDecl(condition, errmessage)
Definition: c.h:920
#define STATUS_ERROR
Definition: c.h:1160
const char * name
Definition: encode.c:571
char * pg_fe_scram_build_secret(const char *password, const char **errstr)
const pg_fe_sasl_mech pg_scram_mech
Definition: fe-auth-scram.c:33
#define MAX_ALGORITHM_NAME_LEN
static bool check_expected_areq(AuthRequest areq, PGconn *conn)
Definition: fe-auth.c:793
static int pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
Definition: fe-auth.c:618
static int pg_SASL_init(PGconn *conn, int payloadlen)
Definition: fe-auth.c:412
int pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
Definition: fe-auth.c:933
static int pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
Definition: fe-auth.c:692
char * PQencryptPassword(const char *passwd, const char *user)
Definition: fe-auth.c:1216
char * pg_fe_getauthname(PQExpBuffer errorMessage)
Definition: fe-auth.c:1197
static const char * auth_method_description(AuthRequest areq)
Definition: fe-auth.c:758
char * PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm)
Definition: fe-auth.c:1259
char * pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
Definition: fe-auth.c:1141
#define auth_method_allowed(conn, type)
Definition: fe-auth.c:784
int pqPacketSend(PGconn *conn, char pack_type, const void *buf, size_t buf_len)
Definition: fe-connect.c:4827
ExecStatusType PQresultStatus(const PGresult *res)
Definition: fe-exec.c:3240
int PQntuples(const PGresult *res)
Definition: fe-exec.c:3310
PGresult * PQexec(PGconn *conn, const char *query)
Definition: fe-exec.c:2225
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
Definition: fe-exec.c:3705
int PQnfields(const PGresult *res)
Definition: fe-exec.c:3318
int pg_GSS_load_servicename(PGconn *conn)
int pqPutInt(int value, size_t bytes, PGconn *conn)
Definition: fe-misc.c:254
int pqFlush(PGconn *conn)
Definition: fe-misc.c:954
int pqPutMsgStart(char msg_type, PGconn *conn)
Definition: fe-misc.c:459
int pqGetnchar(char *s, size_t len, PGconn *conn)
Definition: fe-misc.c:166
int pqGets(PQExpBuffer buf, PGconn *conn)
Definition: fe-misc.c:137
int pqPutnchar(const char *s, size_t len, PGconn *conn)
Definition: fe-misc.c:203
int pqPuts(const char *s, PGconn *conn)
Definition: fe-misc.c:153
void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...)
Definition: fe-misc.c:1283
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
Definition: fe-misc.c:1312
int pqPutMsgEnd(PGconn *conn)
Definition: fe-misc.c:518
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
FILE * output
long val
Definition: informix.c:664
static bool success
Definition: initdb.c:187
@ PGRES_TUPLES_OK
Definition: libpq-fe.h:100
#define PQnoPasswordSupplied
Definition: libpq-fe.h:561
#define libpq_gettext(x)
Definition: libpq-int.h:891
#define pqClearConnErrorState(conn)
Definition: libpq-int.h:864
#define pglock_thread()
Definition: libpq-int.h:668
#define pgunlock_thread()
Definition: libpq-int.h:669
Assert(fmt[strlen(fmt) - 1] !='\n')
#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:144
static char * user
Definition: pg_regress.c:93
const char * username
Definition: pgbench.c:306
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define sprintf
Definition: port.h:240
bool pg_get_user_name(uid_t user_id, char *buffer, size_t buflen)
Definition: thread.c:35
#define AUTH_REQ_SSPI
Definition: pqcomm.h:122
#define AUTH_REQ_SASL_CONT
Definition: pqcomm.h:124
#define AUTH_REQ_MAX
Definition: pqcomm.h:126
#define AUTH_REQ_GSS
Definition: pqcomm.h:120
#define AUTH_REQ_MD5
Definition: pqcomm.h:118
#define AUTH_REQ_KRB5
Definition: pqcomm.h:115
#define AUTH_REQ_OK
Definition: pqcomm.h:113
#define AUTH_REQ_KRB4
Definition: pqcomm.h:114
#define AUTH_REQ_PASSWORD
Definition: pqcomm.h:116
#define AUTH_REQ_GSS_CONT
Definition: pqcomm.h:121
#define AUTH_REQ_CRYPT
Definition: pqcomm.h:117
#define AUTH_REQ_SASL
Definition: pqcomm.h:123
uint32 AuthRequest
Definition: pqcomm.h:128
#define AUTH_REQ_SASL_FIN
Definition: pqcomm.h:125
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
Definition: pqexpbuffer.c:265
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
#define PQExpBufferDataBroken(buf)
Definition: pqexpbuffer.h:67
#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
static char * password
Definition: streamutil.c:53
PGconn * conn
Definition: streamutil.c:54
char * host
Definition: libpq-int.h:338
char * password
Definition: libpq-int.h:341
char * require_auth
Definition: libpq-int.h:399
char * channel_binding
Definition: libpq-int.h:374
const pg_fe_sasl_mech * sasl
Definition: libpq-int.h:525
char * pgpass
Definition: libpq-int.h:372
bool client_finished_auth
Definition: libpq-int.h:465
uint32 allowed_auth_methods
Definition: libpq-int.h:463
bool auth_required
Definition: libpq-int.h:461
char * pguser
Definition: libpq-int.h:371
PQExpBufferData errorMessage
Definition: libpq-int.h:597
char * krbsrvname
Definition: libpq-int.h:393
char * gsslib
Definition: libpq-int.h:394
void * sasl_state
Definition: libpq-int.h:526
int whichhost
Definition: libpq-int.h:430
pg_conn_host * connhost
Definition: libpq-int.h:431
bool ssl_in_use
Definition: libpq-int.h:529
bool password_needed
Definition: libpq-int.h:455
bool(* channel_bound)(void *state)
Definition: fe-auth-sasl.h:114
void *(* init)(PGconn *conn, const char *password, const char *mech)
Definition: fe-auth-sasl.h:54
void(* exchange)(void *state, char *input, int inputlen, char **output, int *outputlen, bool *done, bool *success)
Definition: fe-auth-sasl.h:95
int uid_t
Definition: win32_port.h:246