380{
382 const char *logdetail = NULL;
383
384
385
386
387
388
389
391
393
394
395
396
397
398
400 {
401
404 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
405 errmsg(
"client certificates can only be checked if a root certificate store is available")));
406
407
408
409
410
411
412
413 if (!
port->peer_cert_valid)
415 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
416 errmsg(
"connection requires a valid client certificate")));
417 }
418
419
420
421
422 switch (
port->hba->auth_method)
423 {
425
426
427
428
429
430
431
432
433
434
435
436 {
437 char hostinfo[NI_MAXHOST];
438 const char *encryption_state;
439
441 hostinfo, sizeof(hostinfo),
442 NULL, 0,
443 NI_NUMERICHOST);
444
445 encryption_state =
446#ifdef ENABLE_GSS
447 (
port->gss &&
port->gss->enc) ?
_(
"GSS encryption") :
448#endif
449#ifdef USE_SSL
450 port->ssl_in_use ?
_(
"SSL encryption") :
451#endif
453
456 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
457
458 errmsg(
"pg_hba.conf rejects replication connection for host \"%s\", user \"%s\", %s",
459 hostinfo,
port->user_name,
460 encryption_state)));
461 else
463 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
464
465 errmsg(
"pg_hba.conf rejects connection for host \"%s\", user \"%s\", database \"%s\", %s",
466 hostinfo,
port->user_name,
468 encryption_state)));
469 break;
470 }
471
473
474
475
476
477
478
479
480
481
482 {
483 char hostinfo[NI_MAXHOST];
484 const char *encryption_state;
485
487 hostinfo, sizeof(hostinfo),
488 NULL, 0,
489 NI_NUMERICHOST);
490
491 encryption_state =
492#ifdef ENABLE_GSS
493 (
port->gss &&
port->gss->enc) ?
_(
"GSS encryption") :
494#endif
495#ifdef USE_SSL
496 port->ssl_in_use ?
_(
"SSL encryption") :
497#endif
499
500#define HOSTNAME_LOOKUP_DETAIL(port) \
501 (port->remote_hostname ? \
502 (port->remote_hostname_resolv == +1 ? \
503 errdetail_log("Client IP address resolved to \"%s\", forward lookup matches.", \
504 port->remote_hostname) : \
505 port->remote_hostname_resolv == 0 ? \
506 errdetail_log("Client IP address resolved to \"%s\", forward lookup not checked.", \
507 port->remote_hostname) : \
508 port->remote_hostname_resolv == -1 ? \
509 errdetail_log("Client IP address resolved to \"%s\", forward lookup does not match.", \
510 port->remote_hostname) : \
511 port->remote_hostname_resolv == -2 ? \
512 errdetail_log("Could not translate client host name \"%s\" to IP address: %s.", \
513 port->remote_hostname, \
514 gai_strerror(port->remote_hostname_errcode)) : \
515 0) \
516 : (port->remote_hostname_resolv == -2 ? \
517 errdetail_log("Could not resolve client IP address to a host name: %s.", \
518 gai_strerror(port->remote_hostname_errcode)) : \
519 0))
520
523 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
524
525 errmsg(
"no pg_hba.conf entry for replication connection from host \"%s\", user \"%s\", %s",
526 hostinfo,
port->user_name,
527 encryption_state),
529 else
531 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
532
533 errmsg(
"no pg_hba.conf entry for host \"%s\", user \"%s\", database \"%s\", %s",
534 hostinfo,
port->user_name,
536 encryption_state),
538 break;
539 }
540
542#ifdef ENABLE_GSS
543
544 if (
port->gss == NULL)
545 port->gss = (pg_gssinfo *)
547 sizeof(pg_gssinfo));
548 port->gss->auth =
true;
549
550
551
552
553
555 status = pg_GSS_checkauth(
port);
556 else
557 {
559 status = pg_GSS_recvauth(
port);
560 }
561#else
563#endif
564 break;
565
567#ifdef ENABLE_SSPI
568 if (
port->gss == NULL)
569 port->gss = (pg_gssinfo *)
571 sizeof(pg_gssinfo));
573 status = pg_SSPI_recvauth(
port);
574#else
576#endif
577 break;
578
581 break;
582
585 break;
586
590 break;
591
594 break;
595
597#ifdef USE_PAM
598 status = CheckPAMAuth(
port,
port->user_name,
"");
599#else
601#endif
602 break;
603
605#ifdef USE_BSD_AUTH
606 status = CheckBSDAuth(
port,
port->user_name);
607#else
609#endif
610 break;
611
613#ifdef USE_LDAP
614 status = CheckLDAPAuth(
port);
615#else
617#endif
618 break;
621 break;
623
626 break;
629 break;
630 }
631
634 {
635
636
637
638
639#ifdef USE_SSL
640 status = CheckCertAuth(
port);
641#else
643#endif
644 }
645
649 {
650
651
652
653
654
655
657 errmsg(
"connection authenticated: user=\"%s\" method=%s "
658 "(%s:%d)",
660 port->hba->sourcefile,
port->hba->linenumber));
661 }
662
664 (*ClientAuthentication_hook) (
port, status);
665
668 else
670}
const pg_be_sasl_mech pg_be_oauth_mech
int CheckSASLAuth(const pg_be_sasl_mech *mech, Port *port, char *shadow_pass, const char **logdetail)
void sendAuthRequest(Port *port, AuthRequest areq, const void *extradata, int extralen)
static int CheckPWChallengeAuth(Port *port, const char **logdetail)
static int auth_peer(Port *port)
static int CheckRADIUSAuth(Port *port)
static void auth_failed(Port *port, int status, const char *logdetail)
ClientAuthentication_hook_type ClientAuthentication_hook
static int ident_inet(Port *port)
#define HOSTNAME_LOOKUP_DETAIL(port)
static int CheckPasswordAuth(Port *port, const char **logdetail)
@ LOG_CONNECTION_AUTHENTICATION
bool secure_loaded_verify_locations(void)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
void hba_getauthmethod(Port *port)
const char * hba_authname(UserAuth auth_method)
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
void * MemoryContextAllocZero(MemoryContext context, Size size)
MemoryContext TopMemoryContext
#define CHECK_FOR_INTERRUPTS()
ClientConnectionInfo MyClientConnectionInfo