|
PostgreSQL Source Code git master
|
#include "postgres_fe.h"#include <curl/curl.h>#include <math.h>#include <unistd.h>#include "common/jsonapi.h"#include "mb/pg_wchar.h"#include "oauth-curl.h"#include "fe-auth-oauth.h"#include "libpq-int.h"#include "oauth-debug.h"

Go to the source code of this file.
Data Structures | |
| struct | provider |
| struct | device_authz |
| struct | token_error |
| struct | token |
| struct | async_ctx |
| struct | json_field |
| struct | oauth_parse |
Enumerations | |
| enum | OAuthStep { OAUTH_STEP_INIT = 0 , OAUTH_STEP_DISCOVERY , OAUTH_STEP_DEVICE_AUTHORIZATION , OAUTH_STEP_TOKEN_REQUEST , OAUTH_STEP_WAIT_INTERVAL } |
| #define actx_error | ( | ACTX, | |
| FMT, | |||
| ... | |||
| ) | appendPQExpBuffer(&(ACTX)->errbuf, libpq_gettext(FMT), ##__VA_ARGS__) |
Definition at line 419 of file oauth-curl.c.
| #define actx_error_internal | ( | ACTX, | |
| FMT, | |||
| ... | |||
| ) | appendPQExpBuffer(&(ACTX)->errbuf, FMT, ##__VA_ARGS__) |
Definition at line 422 of file oauth-curl.c.
Definition at line 425 of file oauth-curl.c.
| #define CHECK_GETINFO | ( | ACTX, | |
| INFO, | |||
| OUT, | |||
| FAILACTION | |||
| ) |
Definition at line 455 of file oauth-curl.c.
| #define CHECK_MSETOPT | ( | ACTX, | |
| OPT, | |||
| VAL, | |||
| FAILACTION | |||
| ) |
Definition at line 433 of file oauth-curl.c.
| #define CHECK_SETOPT | ( | ACTX, | |
| OPT, | |||
| VAL, | |||
| FAILACTION | |||
| ) |
Definition at line 444 of file oauth-curl.c.
Definition at line 1957 of file oauth-curl.c.
| #define HTTPS_SCHEME "https://" |
Definition at line 2267 of file oauth-curl.c.
| #define MAX_OAUTH_NESTING_LEVEL 16 |
Definition at line 89 of file oauth-curl.c.
| #define MAX_OAUTH_RESPONSE_SIZE (256 * 1024) |
Definition at line 75 of file oauth-curl.c.
| #define OAUTH_GRANT_TYPE_DEVICE_CODE "urn:ietf:params:oauth:grant-type:device_code" |
Definition at line 2268 of file oauth-curl.c.
| #define oauth_parse_set_error | ( | ctx, | |
| fmt, | |||
| ... | |||
| ) | appendPQExpBuffer((ctx)->errbuf, libpq_gettext(fmt), ##__VA_ARGS__) |
Definition at line 509 of file oauth-curl.c.
| #define oauth_parse_set_error_internal | ( | ctx, | |
| fmt, | |||
| ... | |||
| ) | appendPQExpBuffer((ctx)->errbuf, fmt, ##__VA_ARGS__) |
Definition at line 512 of file oauth-curl.c.
| #define PG_CURL_IGNORE_DEPRECATION | ( | x | ) | CURL_IGNORE_DEPRECATION(x;) |
Definition at line 1964 of file oauth-curl.c.
Definition at line 497 of file oauth-curl.c.
Definition at line 496 of file oauth-curl.c.
| Enumerator | |
|---|---|
| OAUTH_STEP_INIT | |
| OAUTH_STEP_DISCOVERY | |
| OAUTH_STEP_DEVICE_AUTHORIZATION | |
| OAUTH_STEP_TOKEN_REQUEST | |
| OAUTH_STEP_WAIT_INTERVAL | |
Definition at line 206 of file oauth-curl.c.
|
static |
Definition at line 2335 of file oauth-curl.c.
References actx_error, build_urlencoded(), CHECK_SETOPT, cleanup(), fb(), free, password, success, urlencode(), and username.
Referenced by start_device_authz(), and start_token_request().
|
static |
Definition at line 379 of file oauth-curl.c.
References appendPQExpBuffer(), appendPQExpBufferStr(), PQExpBufferData::data, async_ctx::errbuf, fb(), PQExpBufferData::len, libpq_gettext, PQExpBufferDataBroken, and resetPQExpBuffer().
Referenced by pg_fe_run_oauth_flow_impl(), and pg_start_oauthbearer().
Definition at line 1876 of file oauth-curl.c.
References actx_error, appendBinaryPQExpBuffer(), buf, fb(), len, MAX_OAUTH_RESPONSE_SIZE, and PQExpBufferBroken.
Referenced by restore_one_database(), RestoreArchive(), SetOutput(), and start_request().
|
static |
Definition at line 2070 of file oauth-curl.c.
References appendBinaryPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), buf, fb(), and termPQExpBuffer().
Referenced by build_urlencoded(), and urlencode().
Definition at line 2128 of file oauth-curl.c.
References append_urlencoded(), appendPQExpBufferChar(), buf, and value.
Referenced by add_client_identification(), start_device_authz(), and start_token_request().
Definition at line 812 of file oauth-curl.c.
References actx_error, Assert, CHECK_GETINFO, fb(), i, pg_strncasecmp(), and type.
Referenced by parse_oauth_json().
Definition at line 2276 of file oauth-curl.c.
References actx_error, Assert, provider::device_authorization_endpoint, fb(), HTTPS_SCHEME, provider::issuer, OAUTHDEBUG_UNSAFE_HTTP, pg_strncasecmp(), and provider::token_endpoint.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2231 of file oauth-curl.c.
References actx_error, Assert, fb(), and provider::issuer.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1449 of file oauth-curl.c.
References actx_error_internal, and fb().
Referenced by pg_fe_run_oauth_flow_impl().
|
static |
Definition at line 1672 of file oauth-curl.c.
References appendPQExpBuffer(), appendPQExpBufferChar(), buf, data, fb(), fprintf, i, initPQExpBuffer(), termPQExpBuffer(), and type.
Referenced by setup_curl_handles().
Definition at line 1640 of file oauth-curl.c.
References fb(), set_timer(), and timer_expired().
Referenced by pg_fe_run_oauth_flow_impl().
|
static |
Definition at line 1971 of file oauth-curl.c.
References actx_error, actx_error_str, err(), fb(), PG_CURL_IGNORE_DEPRECATION, PGRES_POLLING_FAILED, PGRES_POLLING_OK, and PGRES_POLLING_READING.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2449 of file oauth-curl.c.
References actx_error, CHECK_GETINFO, err(), fb(), free_token_error(), libpq_gettext, parse_device_authz(), parse_token_error(), and record_token_error().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2166 of file oauth-curl.c.
References actx_error, CHECK_GETINFO, fb(), libpq_gettext, and parse_provider().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2537 of file oauth-curl.c.
References actx_error, CHECK_GETINFO, fb(), libpq_gettext, parse_access_token(), and parse_token_error().
Referenced by handle_token_response().
Definition at line 291 of file oauth-curl.c.
References close, err(), fb(), fprintf, free, free_device_authz(), free_provider(), libpq_gettext, PGINVALID_SOCKET, and termPQExpBuffer().
Referenced by pg_fe_cleanup_oauth_flow().
|
static |
Definition at line 143 of file oauth-curl.c.
References device_authz::device_code, device_authz::expires_in_str, free, device_authz::interval_str, device_authz::user_code, device_authz::verification_uri, and device_authz::verification_uri_complete.
Referenced by free_async_ctx().
Definition at line 115 of file oauth-curl.c.
References provider::device_authorization_endpoint, fb(), free, provider::grant_types_supported, provider::issuer, and provider::token_endpoint.
Referenced by free_async_ctx().
Definition at line 194 of file oauth-curl.c.
References fb(), free, and free_token_error().
Referenced by handle_token_response().
|
static |
Definition at line 168 of file oauth-curl.c.
Referenced by finish_device_authz(), and free_token().
Definition at line 2584 of file oauth-curl.c.
References token::access_token, actx_error, Assert, err(), fb(), finish_token_request(), free_token(), record_token_error(), and success.
Referenced by pg_fe_run_oauth_flow_impl().
|
static |
Definition at line 2690 of file oauth-curl.c.
References fb(), libpq_gettext, PG_BOOL_NO, PG_BOOL_UNKNOWN, PG_BOOL_YES, pglock_thread, and pgunlock_thread.
Referenced by pg_start_oauthbearer().
|
static |
Definition at line 684 of file oauth-curl.c.
References oauth_parse::active, Assert, fb(), JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, json_field::name, oauth_parse::nested, oauth_parse_set_error_internal, and json_field::type.
Referenced by parse_oauth_json().
|
static |
Definition at line 652 of file oauth-curl.c.
References oauth_parse::active, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, MAX_OAUTH_NESTING_LEVEL, oauth_parse::nested, oauth_parse_set_error, report_type_mismatch(), and json_field::type.
Referenced by parse_oauth_json().
|
static |
Definition at line 629 of file oauth-curl.c.
References oauth_parse::active, Assert, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, json_field::name, oauth_parse::nested, and oauth_parse_set_error_internal.
Referenced by parse_oauth_json().
|
static |
Definition at line 574 of file oauth-curl.c.
References oauth_parse::active, json_field::array, Assert, fb(), oauth_parse::fields, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, name, json_field::name, oauth_parse::nested, oauth_parse_set_error, oauth_parse_set_error_internal, json_field::scalar, and json_field::type.
Referenced by parse_oauth_json().
|
static |
Definition at line 549 of file oauth-curl.c.
References oauth_parse::active, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, MAX_OAUTH_NESTING_LEVEL, oauth_parse::nested, oauth_parse_set_error, and report_type_mismatch().
Referenced by parse_oauth_json().
|
static |
Definition at line 712 of file oauth-curl.c.
References oauth_parse::active, json_field::array, Assert, fb(), JSON_OUT_OF_MEMORY, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, JSON_TOKEN_STRING, json_field::name, oauth_parse::nested, oauth_parse_set_error, oauth_parse_set_error_internal, report_type_mismatch(), json_field::scalar, type, and json_field::type.
Referenced by parse_oauth_json().
Definition at line 1183 of file oauth-curl.c.
References fb(), JSON_TOKEN_STRING, parse_oauth_json(), and PG_OAUTH_REQUIRED.
Referenced by finish_token_request().
|
static |
Definition at line 1069 of file oauth-curl.c.
References Assert, device_authz::device_code, device_authz::expires_in, device_authz::expires_in_str, fb(), device_authz::interval, device_authz::interval_str, JSON_TOKEN_NUMBER, JSON_TOKEN_STRING, parse_expires_in(), parse_interval(), parse_oauth_json(), PG_OAUTH_OPTIONAL, PG_OAUTH_REQUIRED, device_authz::user_code, device_authz::verification_uri, and device_authz::verification_uri_complete.
Referenced by finish_device_authz().
Definition at line 1050 of file oauth-curl.c.
References fb(), and parse_json_number().
Referenced by parse_device_authz().
Definition at line 1024 of file oauth-curl.c.
References fb(), OAUTHDEBUG_UNSAFE_DOS_ENDPOINT, and parse_json_number().
Referenced by parse_device_authz().
Definition at line 989 of file oauth-curl.c.
Referenced by parse_expires_in(), and parse_interval().
|
static |
Definition at line 871 of file oauth-curl.c.
References actx_error, actx_error_str, json_field::array, JsonSemAction::array_end, JsonSemAction::array_start, check_content_type(), cleanup(), err(), oauth_parse::errbuf, fb(), oauth_parse::fields, freeJsonLexContext(), json_errdetail(), JSON_SEM_ACTION_FAILED, JSON_SUCCESS, makeJsonLexContextCstringLen(), json_field::name, oauth_json_array_end(), oauth_json_array_start(), oauth_json_object_end(), oauth_json_object_field_start(), oauth_json_object_start(), oauth_json_scalar(), JsonSemAction::object_end, JsonSemAction::object_field_start, JsonSemAction::object_start, pg_encoding_verifymbstr(), pg_parse_json(), PG_UTF8, json_field::required, JsonSemAction::scalar, json_field::scalar, sem, JsonSemAction::semstate, setJsonLexContextOwnsTokens(), and success.
Referenced by parse_access_token(), parse_device_authz(), parse_provider(), and parse_token_error().
Definition at line 958 of file oauth-curl.c.
References provider::device_authorization_endpoint, fb(), provider::grant_types_supported, provider::issuer, JSON_TOKEN_ARRAY_START, JSON_TOKEN_STRING, parse_oauth_json(), PG_OAUTH_OPTIONAL, PG_OAUTH_REQUIRED, and provider::token_endpoint.
Referenced by finish_discovery().
|
static |
Definition at line 1123 of file oauth-curl.c.
References err(), fb(), JSON_TOKEN_STRING, libpq_gettext, parse_oauth_json(), PG_OAUTH_OPTIONAL, PG_OAUTH_REQUIRED, and result.
Referenced by finish_device_authz(), and finish_token_request().
|
static |
Definition at line 355 of file oauth-curl.c.
References Assert, explicit_bzero(), fb(), free, and free_async_ctx().
Referenced by pg_start_oauthbearer().
|
static |
Definition at line 2996 of file oauth-curl.c.
References conn, fb(), fprintf, OAUTHDEBUG_CALL_COUNT, pg_fe_run_oauth_flow_impl(), PGRES_POLLING_FAILED, PGRES_POLLING_OK, pq_block_sigpipe(), pq_reset_sigpipe(), and result.
Referenced by pg_start_oauthbearer().
|
static |
Definition at line 2797 of file oauth-curl.c.
References append_actx_error(), check_for_device_flow(), check_issuer(), comb_multiplexer(), conn, drain_timer_events(), drive_request(), fb(), finish_device_authz(), finish_discovery(), handle_token_response(), libpq_gettext, async_ctx::mux, OAUTH_STEP_DEVICE_AUTHORIZATION, OAUTH_STEP_DISCOVERY, OAUTH_STEP_INIT, OAUTH_STEP_TOKEN_REQUEST, OAUTH_STEP_WAIT_INTERVAL, PGRES_POLLING_FAILED, PGRES_POLLING_OK, PGRES_POLLING_READING, prompt_user(), set_timer(), start_device_authz(), start_discovery(), and start_token_request().
Referenced by pg_fe_run_oauth_flow().
| int pg_start_oauthbearer | ( | PGconn * | conn, |
| PGoauthBearerRequestV2 * | request | ||
| ) |
Definition at line 3063 of file oauth-curl.c.
References append_actx_error(), Assert, calloc, conn, fb(), initialize_curl(), initPQExpBuffer(), _PQconninfoOption::keyword, libpq_gettext, oauth_parse_debug_flags(), pg_fe_cleanup_oauth_flow(), pg_fe_run_oauth_flow(), PGINVALID_SOCKET, PQconninfo(), PQconninfoFree(), setup_curl_handles(), and setup_multiplexer().
Definition at line 2645 of file oauth-curl.c.
References actx_error, conn, fb(), fprintf, libpq_gettext, PQAUTHDATA_PROMPT_OAUTH_DEVICE, PQgetAuthDataHook(), and _PGpromptOAuthDevice::verification_uri.
Referenced by pg_fe_run_oauth_flow_impl().
|
static |
Definition at line 1151 of file oauth-curl.c.
References actx_error, actx_error_str, appendPQExpBuffer(), CHECK_GETINFO, err(), fb(), and gettext_noop.
Referenced by finish_device_authz(), and handle_token_response().
|
static |
Definition at line 1283 of file oauth-curl.c.
References actx_error_internal, Assert, fb(), i, lengthof, and socket.
Referenced by setup_curl_handles().
Definition at line 1618 of file oauth-curl.c.
References fb(), and set_timer().
Referenced by setup_curl_handles().
|
static |
Definition at line 516 of file oauth-curl.c.
References oauth_parse::active, Assert, fb(), gettext_noop, JSON_TOKEN_ARRAY_START, JSON_TOKEN_NUMBER, JSON_TOKEN_STRING, json_field::name, oauth_parse_set_error, and json_field::type.
Referenced by oauth_json_array_start(), oauth_json_object_start(), and oauth_json_scalar().
Definition at line 1497 of file oauth-curl.c.
References actx_error_internal, and fb().
Referenced by drain_timer_events(), pg_fe_run_oauth_flow_impl(), and register_timer().
Definition at line 1755 of file oauth-curl.c.
References actx_error, CHECK_MSETOPT, CHECK_SETOPT, debug_callback(), fb(), OAUTHDEBUG_UNSAFE_HTTP, OAUTHDEBUG_UNSAFE_TRACE, register_socket(), and register_timer().
Referenced by pg_start_oauthbearer().
Definition at line 1225 of file oauth-curl.c.
References actx_error_internal, and fb().
Referenced by pg_start_oauthbearer().
Definition at line 2419 of file oauth-curl.c.
References actx_error, add_client_identification(), Assert, build_urlencoded(), CHECK_SETOPT, conn, fb(), PQExpBufferBroken, resetPQExpBuffer(), and start_request().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2157 of file oauth-curl.c.
References CHECK_SETOPT, async_ctx::discovery_uri, fb(), and start_request().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1916 of file oauth-curl.c.
References actx_error, append_data(), CHECK_SETOPT, err(), fb(), and resetPQExpBuffer().
Referenced by start_device_authz(), start_discovery(), and start_token_request().
Definition at line 2506 of file oauth-curl.c.
References actx_error, add_client_identification(), Assert, build_urlencoded(), CHECK_SETOPT, conn, fb(), OAUTH_GRANT_TYPE_DEVICE_CODE, PQExpBufferBroken, resetPQExpBuffer(), and start_request().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1594 of file oauth-curl.c.
References actx_error, fb(), and PQsocketPoll().
Referenced by drain_timer_events().
Definition at line 2113 of file oauth-curl.c.
References append_urlencoded(), buf, fb(), initPQExpBuffer(), and PQExpBufferDataBroken.
Referenced by add_client_identification().