PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
oauth.h File Reference
#include "libpq/libpq-be.h"
#include "libpq/sasl.h"
Include dependency graph for oauth.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ValidatorModuleState
 
struct  ValidatorModuleResult
 
struct  OAuthValidatorCallbacks
 

Macros

#define PG_OAUTH_VALIDATOR_MAGIC   0x20250220
 

Typedefs

typedef struct ValidatorModuleState ValidatorModuleState
 
typedef struct ValidatorModuleResult ValidatorModuleResult
 
typedef void(* ValidatorStartupCB) (ValidatorModuleState *state)
 
typedef void(* ValidatorShutdownCB) (ValidatorModuleState *state)
 
typedef bool(* ValidatorValidateCB) (const ValidatorModuleState *state, const char *token, const char *role, ValidatorModuleResult *result)
 
typedef struct OAuthValidatorCallbacks OAuthValidatorCallbacks
 
typedef const OAuthValidatorCallbacks *(* OAuthValidatorModuleInit) (void)
 

Functions

PGDLLEXPORT const OAuthValidatorCallbacks_PG_oauth_validator_module_init (void)
 
bool check_oauth_validator (HbaLine *hba, int elevel, char **err_msg)
 

Variables

PGDLLIMPORT char * oauth_validator_libraries_string
 
const pg_be_sasl_mech pg_be_oauth_mech
 

Macro Definition Documentation

◆ PG_OAUTH_VALIDATOR_MAGIC

#define PG_OAUTH_VALIDATOR_MAGIC   0x20250220

Definition at line 74 of file oauth.h.

Typedef Documentation

◆ OAuthValidatorCallbacks

◆ OAuthValidatorModuleInit

typedef const OAuthValidatorCallbacks *(* OAuthValidatorModuleInit) (void)

Definition at line 90 of file oauth.h.

◆ ValidatorModuleResult

◆ ValidatorModuleState

◆ ValidatorShutdownCB

typedef void(* ValidatorShutdownCB) (ValidatorModuleState *state)

Definition at line 63 of file oauth.h.

◆ ValidatorStartupCB

typedef void(* ValidatorStartupCB) (ValidatorModuleState *state)

Definition at line 62 of file oauth.h.

◆ ValidatorValidateCB

typedef bool(* ValidatorValidateCB) (const ValidatorModuleState *state, const char *token, const char *role, ValidatorModuleResult *result)

Definition at line 64 of file oauth.h.

Function Documentation

◆ _PG_oauth_validator_module_init()

PGDLLEXPORT const OAuthValidatorCallbacks * _PG_oauth_validator_module_init ( void  )

Definition at line 35 of file fail_validator.c.

36{
37 return &validator_callbacks;
38}
static const OAuthValidatorCallbacks validator_callbacks

References validator_callbacks.

◆ check_oauth_validator()

bool check_oauth_validator ( HbaLine hba,
int  elevel,
char **  err_msg 
)

Definition at line 820 of file auth-oauth.c.

821{
822 int line_num = hbaline->linenumber;
823 const char *file_name = hbaline->sourcefile;
824 char *rawstring;
825 List *elemlist = NIL;
826
827 *err_msg = NULL;
828
830 {
831 ereport(elevel,
832 errcode(ERRCODE_CONFIG_FILE_ERROR),
833 errmsg("oauth_validator_libraries must be set for authentication method %s",
834 "oauth"),
835 errcontext("line %d of configuration file \"%s\"",
836 line_num, file_name));
837 *err_msg = psprintf("oauth_validator_libraries must be set for authentication method %s",
838 "oauth");
839 return false;
840 }
841
842 /* SplitDirectoriesString needs a modifiable copy */
844
845 if (!SplitDirectoriesString(rawstring, ',', &elemlist))
846 {
847 /* syntax error in list */
848 ereport(elevel,
849 errcode(ERRCODE_CONFIG_FILE_ERROR),
850 errmsg("invalid list syntax in parameter \"%s\"",
851 "oauth_validator_libraries"));
852 *err_msg = psprintf("invalid list syntax in parameter \"%s\"",
853 "oauth_validator_libraries");
854 goto done;
855 }
856
857 if (!hbaline->oauth_validator)
858 {
859 if (elemlist->length == 1)
860 {
861 hbaline->oauth_validator = pstrdup(linitial(elemlist));
862 goto done;
863 }
864
865 ereport(elevel,
866 errcode(ERRCODE_CONFIG_FILE_ERROR),
867 errmsg("authentication method \"oauth\" requires argument \"validator\" to be set when oauth_validator_libraries contains multiple options"),
868 errcontext("line %d of configuration file \"%s\"",
869 line_num, file_name));
870 *err_msg = "authentication method \"oauth\" requires argument \"validator\" to be set when oauth_validator_libraries contains multiple options";
871 goto done;
872 }
873
874 foreach_ptr(char, allowed, elemlist)
875 {
876 if (strcmp(allowed, hbaline->oauth_validator) == 0)
877 goto done;
878 }
879
880 ereport(elevel,
881 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
882 errmsg("validator \"%s\" is not permitted by %s",
883 hbaline->oauth_validator, "oauth_validator_libraries"),
884 errcontext("line %d of configuration file \"%s\"",
885 line_num, file_name));
886 *err_msg = psprintf("validator \"%s\" is not permitted by %s",
887 hbaline->oauth_validator, "oauth_validator_libraries");
888
889done:
890 list_free_deep(elemlist);
891 pfree(rawstring);
892
893 return (*err_msg == NULL);
894}
char * oauth_validator_libraries_string
Definition: auth-oauth.c:34
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define errcontext
Definition: elog.h:196
#define ereport(elevel,...)
Definition: elog.h:149
void list_free_deep(List *list)
Definition: list.c:1560
char * pstrdup(const char *in)
Definition: mcxt.c:1699
void pfree(void *pointer)
Definition: mcxt.c:1524
#define NIL
Definition: pg_list.h:68
#define foreach_ptr(type, var, lst)
Definition: pg_list.h:469
#define linitial(l)
Definition: pg_list.h:178
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
Definition: pg_list.h:54
int length
Definition: pg_list.h:56
bool SplitDirectoriesString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3652

References ereport, errcode(), errcontext, errmsg(), foreach_ptr, List::length, HbaLine::linenumber, linitial, list_free_deep(), NIL, HbaLine::oauth_validator, oauth_validator_libraries_string, pfree(), psprintf(), pstrdup(), HbaLine::sourcefile, and SplitDirectoriesString().

Referenced by parse_hba_line().

Variable Documentation

◆ oauth_validator_libraries_string

PGDLLIMPORT char* oauth_validator_libraries_string
extern

Definition at line 34 of file auth-oauth.c.

Referenced by check_oauth_validator().

◆ pg_be_oauth_mech

const pg_be_sasl_mech pg_be_oauth_mech
extern

Definition at line 48 of file auth-oauth.c.

Referenced by ClientAuthentication().