PostgreSQL Source Code git master
|
#include "postgres.h"
#include <unistd.h>
#include <fcntl.h>
#include "common/oauth-common.h"
#include "fmgr.h"
#include "lib/stringinfo.h"
#include "libpq/auth.h"
#include "libpq/hba.h"
#include "libpq/oauth.h"
#include "libpq/sasl.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "utils/json.h"
#include "utils/varlena.h"
Go to the source code of this file.
Data Structures | |
struct | oauth_ctx |
Macros | |
#define | KVSEP 0x01 /* separator byte for key/value pairs */ |
#define | AUTH_KEY "auth" /* key containing the Authorization header */ |
#define | BEARER_SCHEME "Bearer " /* required header scheme (case-insensitive!) */ |
Enumerations | |
enum | oauth_state { OAUTH_STATE_INIT = 0 , OAUTH_STATE_ERROR , OAUTH_STATE_FINISHED } |
Functions | |
static void | oauth_get_mechanisms (Port *port, StringInfo buf) |
static void * | oauth_init (Port *port, const char *selected_mech, const char *shadow_pass) |
static int | oauth_exchange (void *opaq, const char *input, int inputlen, char **output, int *outputlen, const char **logdetail) |
static void | load_validator_library (const char *libname) |
static void | shutdown_validator_library (void *arg) |
static char * | sanitize_char (char c) |
static char * | parse_kvpairs_for_auth (char **input) |
static void | generate_error_response (struct oauth_ctx *ctx, char **output, int *outputlen) |
static bool | validate (Port *port, const char *auth) |
static void | validate_kvpair (const char *key, const char *val) |
static const char * | validate_token_format (const char *header) |
bool | check_oauth_validator (HbaLine *hbaline, int elevel, char **err_msg) |
Variables | |
char * | oauth_validator_libraries_string = NULL |
static ValidatorModuleState * | validator_module_state |
static const OAuthValidatorCallbacks * | ValidatorCallbacks |
const pg_be_sasl_mech | pg_be_oauth_mech |
#define AUTH_KEY "auth" /* key containing the Authorization header */ |
Definition at line 80 of file auth-oauth.c.
#define BEARER_SCHEME "Bearer " /* required header scheme (case-insensitive!) */ |
Definition at line 81 of file auth-oauth.c.
Definition at line 79 of file auth-oauth.c.
enum oauth_state |
Enumerator | |
---|---|
OAUTH_STATE_INIT | |
OAUTH_STATE_ERROR | |
OAUTH_STATE_FINISHED |
Definition at line 57 of file auth-oauth.c.
bool check_oauth_validator | ( | HbaLine * | hbaline, |
int | elevel, | ||
char ** | err_msg | ||
) |
Definition at line 820 of file auth-oauth.c.
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().
|
static |
Definition at line 485 of file auth-oauth.c.
References appendStringInfoString(), buf, ereport, errcode(), errdetail_log(), errmsg(), escape_json(), FATAL, initStringInfo(), oauth_ctx::issuer, output, pfree(), and oauth_ctx::scope.
Referenced by oauth_exchange().
|
static |
Definition at line 738 of file auth-oauth.c.
References Assert(), CurrentMemoryContext, ereport, errdetail(), errmsg(), ERROR, MemoryContextCallback::func, load_external_function(), OAuthValidatorCallbacks::magic, MemoryContextRegisterResetCallback(), palloc0(), PG_OAUTH_VALIDATOR_MAGIC, shutdown_validator_library(), OAuthValidatorCallbacks::startup_cb, ValidatorModuleState::sversion, OAuthValidatorCallbacks::validate_cb, validator_module_state, and ValidatorCallbacks.
Referenced by oauth_init().
|
static |
Definition at line 134 of file auth-oauth.c.
References Assert(), elog, ereport, errcode(), errdetail(), errmsg(), ERROR, explicit_bzero(), generate_error_response(), input, KVSEP, OAUTH_STATE_ERROR, OAUTH_STATE_FINISHED, OAUTH_STATE_INIT, output, parse_kvpairs_for_auth(), PG_SASL_EXCHANGE_CONTINUE, PG_SASL_EXCHANGE_FAILURE, PG_SASL_EXCHANGE_SUCCESS, oauth_ctx::port, pstrdup(), sanitize_char(), oauth_ctx::state, and validate().
|
static |
Definition at line 89 of file auth-oauth.c.
References appendStringInfoChar(), appendStringInfoString(), buf, and OAUTHBEARER_NAME.
|
static |
Definition at line 102 of file auth-oauth.c.
References Assert(), ereport, errcode(), errmsg(), ERROR, oauth_ctx::issuer, load_validator_library(), OAUTH_STATE_INIT, OAUTHBEARER_NAME, palloc0(), oauth_ctx::port, port, oauth_ctx::scope, and oauth_ctx::state.
|
static |
Definition at line 386 of file auth-oauth.c.
References AUTH_KEY, ereport, errcode(), errdetail(), errmsg(), ERROR, input, sort-test::key, KVSEP, pg_unreachable, validate_kvpair(), and value.
Referenced by oauth_exchange().
|
static |
|
static |
Definition at line 806 of file auth-oauth.c.
References OAuthValidatorCallbacks::shutdown_cb, validator_module_state, and ValidatorCallbacks.
Referenced by load_validator_library().
|
static |
Definition at line 638 of file auth-oauth.c.
References ClientConnectionInfo::authn_id, ValidatorModuleResult::authn_id, ValidatorModuleResult::authorized, check_usermap(), cleanup(), ereport, errcode(), errdetail_log(), errmsg(), FATAL, LOG, MyClientConnectionInfo, palloc0(), pfree(), port, set_authn_id(), STATUS_OK, token, OAuthValidatorCallbacks::validate_cb, validate_token_format(), validator_module_state, ValidatorCallbacks, and WARNING.
Referenced by attribute_reloptions(), bloptions(), brinoptions(), btoptions(), build_local_reloptions(), build_reloptions(), default_reloptions(), dioptions(), fillRelOptions(), ginoptions(), gistoptions(), hashoptions(), heap_reloptions(), index_opclass_options(), index_reloptions(), oauth_exchange(), parse_one_reloption(), parseLocalRelOptions(), parseRelOptions(), parseRelOptionsInternal(), partitioned_table_reloptions(), spgoptions(), tablespace_reloptions(), and view_reloptions().
|
static |
Definition at line 327 of file auth-oauth.c.
References ereport, errcode(), errdetail(), errmsg(), ERROR, sort-test::key, and val.
Referenced by parse_kvpairs_for_auth().
|
static |
Definition at line 556 of file auth-oauth.c.
References Assert(), BEARER_SCHEME, COMMERROR, ereport, errcode(), errdetail_log(), errmsg(), pg_strncasecmp(), and token.
Referenced by validate().
char* oauth_validator_libraries_string = NULL |
Definition at line 34 of file auth-oauth.c.
Referenced by check_oauth_validator().
const pg_be_sasl_mech pg_be_oauth_mech |
Definition at line 48 of file auth-oauth.c.
Referenced by ClientAuthentication().
|
static |
Definition at line 44 of file auth-oauth.c.
Referenced by load_validator_library(), shutdown_validator_library(), and validate().
|
static |
Definition at line 45 of file auth-oauth.c.
Referenced by load_validator_library(), shutdown_validator_library(), and validate().