#include "postgres_fe.h"
#include <curl/curl.h>
#include <math.h>
#include <unistd.h>
#include "common/jsonapi.h"
#include "fe-auth-oauth.h"
#include "mb/pg_wchar.h"
#include "oauth-curl.h"
#include "libpq-int.h"
Go to the source code of this file.
Definition at line 374 of file oauth-curl.c.
Definition at line 377 of file oauth-curl.c.
Definition at line 407 of file oauth-curl.c.
Definition at line 385 of file oauth-curl.c.
Definition at line 396 of file oauth-curl.c.
Definition at line 53 of file oauth-curl.c.
Definition at line 54 of file oauth-curl.c.
Definition at line 55 of file oauth-curl.c.
Definition at line 56 of file oauth-curl.c.
Definition at line 57 of file oauth-curl.c.
Definition at line 58 of file oauth-curl.c.
Definition at line 59 of file oauth-curl.c.
Definition at line 1919 of file oauth-curl.c.
Definition at line 2224 of file oauth-curl.c.
Definition at line 97 of file oauth-curl.c.
Definition at line 83 of file oauth-curl.c.
Definition at line 2225 of file oauth-curl.c.
Definition at line 461 of file oauth-curl.c.
Definition at line 449 of file oauth-curl.c.
Definition at line 448 of file oauth-curl.c.
Definition at line 61 of file oauth-curl.c.
Definition at line 62 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 214 of file oauth-curl.c.
Definition at line 2292 of file oauth-curl.c.
References actx_error, build_urlencoded(), CHECK_SETOPT, cleanup(), conn, conn_oauth_client_id, conn_oauth_client_secret, free, password, success, urlencode(), async_ctx::used_basic_auth, and username.
Referenced by start_device_authz(), and start_token_request().
Definition at line 1838 of file oauth-curl.c.
References actx_error, appendBinaryPQExpBuffer(), buf, PQExpBufferData::len, len, MAX_OAUTH_RESPONSE_SIZE, PQExpBufferBroken, and async_ctx::work_data.
Referenced by start_request().
Definition at line 2027 of file oauth-curl.c.
References appendBinaryPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), buf, and termPQExpBuffer().
Referenced by build_urlencoded(), and urlencode().
Definition at line 2085 of file oauth-curl.c.
References append_urlencoded(), appendPQExpBufferChar(), buf, sort-test::key, and value.
Referenced by add_client_identification(), start_device_authz(), and start_token_request().
Definition at line 761 of file oauth-curl.c.
References actx_error, Assert(), CHECK_GETINFO, i, pg_strncasecmp(), and type.
Referenced by parse_oauth_json().
Definition at line 2233 of file oauth-curl.c.
References actx_error, Assert(), async_ctx::debugging, provider::device_authorization_endpoint, HTTPS_SCHEME, provider::issuer, pg_strncasecmp(), async_ctx::provider, and provider::token_endpoint.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2188 of file oauth-curl.c.
References actx_error, Assert(), conn, conn_oauth_issuer_id, provider::issuer, and async_ctx::provider.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1399 of file oauth-curl.c.
References actx_error, and async_ctx::mux.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1622 of file oauth-curl.c.
References appendPQExpBuffer(), appendPQExpBufferChar(), buf, data, fprintf, i, initPQExpBuffer(), termPQExpBuffer(), and type.
Referenced by setup_curl_handles().
Definition at line 1590 of file oauth-curl.c.
References set_timer(), and timer_expired().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1927 of file oauth-curl.c.
References actx_error, actx_error_str, CURL_IGNORE_DEPRECATION, async_ctx::curlm, err(), async_ctx::errbuf, PQExpBufferData::len, PGRES_POLLING_FAILED, PGRES_POLLING_OK, PGRES_POLLING_READING, and async_ctx::running.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2407 of file oauth-curl.c.
References actx_error, async_ctx::authz, CHECK_GETINFO, err(), async_ctx::errctx, free_token_error(), parse_device_authz(), parse_token_error(), and record_token_error().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2123 of file oauth-curl.c.
References actx_error, CHECK_GETINFO, async_ctx::errctx, provider::grant_types_supported, parse_provider(), and async_ctx::provider.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2496 of file oauth-curl.c.
References actx_error, CHECK_GETINFO, token::err, async_ctx::errctx, parse_access_token(), and parse_token_error().
Referenced by handle_token_response().
Definition at line 288 of file oauth-curl.c.
References async_ctx::authz, close, conn, async_ctx::curl, async_ctx::curlm, err(), async_ctx::errbuf, free, free_device_authz(), free_provider(), async_ctx::headers, libpq_append_conn_error(), async_ctx::mux, PGINVALID_SOCKET, async_ctx::provider, termPQExpBuffer(), async_ctx::timerfd, and async_ctx::work_data.
Referenced by pg_fe_cleanup_oauth_flow().
Definition at line 151 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 123 of file oauth-curl.c.
References provider::device_authorization_endpoint, free, provider::grant_types_supported, provider::issuer, and provider::token_endpoint.
Referenced by free_async_ctx().
Definition at line 202 of file oauth-curl.c.
References token::access_token, token::err, free, free_token_error(), and token::token_type.
Referenced by handle_token_response().
Definition at line 176 of file oauth-curl.c.
Referenced by finish_device_authz(), and free_token().
Definition at line 2543 of file oauth-curl.c.
References token::access_token, actx_error, Assert(), async_ctx::authz, token::err, err(), token_error::error, finish_token_request(), free_token(), device_authz::interval, record_token_error(), and success.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2649 of file oauth-curl.c.
References conn, libpq_append_conn_error(), PG_BOOL_NO, PG_BOOL_UNKNOWN, PG_BOOL_YES, pglock_thread, and pgunlock_thread.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 633 of file oauth-curl.c.
References oauth_parse::active, Assert(), JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, json_field::name, oauth_parse::nested, oauth_parse_set_error, and json_field::type.
Referenced by parse_oauth_json().
Definition at line 601 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().
Definition at line 578 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.
Referenced by parse_oauth_json().
Definition at line 523 of file oauth-curl.c.
References oauth_parse::active, json_field::array, Assert(), oauth_parse::fields, JSON_SEM_ACTION_FAILED, JSON_SUCCESS, JSON_TOKEN_ARRAY_START, name, json_field::name, oauth_parse::nested, oauth_parse_set_error, json_field::scalar, json_field::target, and json_field::type.
Referenced by parse_oauth_json().
Definition at line 498 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().
Definition at line 661 of file oauth-curl.c.
References oauth_parse::active, json_field::array, Assert(), 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, report_type_mismatch(), json_field::scalar, json_field::target, type, and json_field::type.
Referenced by parse_oauth_json().
Definition at line 1132 of file oauth-curl.c.
References token::access_token, JSON_TOKEN_STRING, parse_oauth_json(), PG_OAUTH_REQUIRED, and token::token_type.
Referenced by finish_token_request().
Definition at line 1018 of file oauth-curl.c.
References Assert(), device_authz::device_code, device_authz::expires_in, device_authz::expires_in_str, 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 999 of file oauth-curl.c.
References parse_json_number().
Referenced by parse_device_authz().
Definition at line 973 of file oauth-curl.c.
References async_ctx::debugging, and parse_json_number().
Referenced by parse_device_authz().
Definition at line 938 of file oauth-curl.c.
References Assert().
Referenced by parse_expires_in(), and parse_interval().
Definition at line 820 of file oauth-curl.c.
References actx_error, actx_error_str, json_field::array, JsonSemAction::array_end, JsonSemAction::array_start, check_content_type(), cleanup(), PQExpBufferData::data, err(), async_ctx::errbuf, oauth_parse::errbuf, oauth_parse::fields, freeJsonLexContext(), json_errdetail(), JSON_SEM_ACTION_FAILED, JSON_SUCCESS, PQExpBufferData::len, 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(), success, json_field::target, and async_ctx::work_data.
Referenced by parse_access_token(), parse_device_authz(), parse_provider(), and parse_token_error().
Definition at line 907 of file oauth-curl.c.
References provider::device_authorization_endpoint, 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().
Definition at line 1072 of file oauth-curl.c.
References err(), async_ctx::errctx, JSON_TOKEN_STRING, parse_oauth_json(), PG_OAUTH_OPTIONAL, and PG_OAUTH_REQUIRED.
Referenced by finish_device_authz(), and finish_token_request().
Definition at line 355 of file oauth-curl.c.
References conn, conn_sasl_state, free_async_ctx(), PGINVALID_SOCKET, and set_conn_altsock.
Definition at line 3022 of file oauth-curl.c.
References Assert(), conn, conn_sasl_state, async_ctx::dbg_num_calls, async_ctx::debugging, fprintf, pg_fe_run_oauth_flow_impl(), PGRES_POLLING_FAILED, PGRES_POLLING_OK, pq_block_sigpipe(), and pq_reset_sigpipe().
Definition at line 2758 of file oauth-curl.c.
References appendPQExpBuffer(), appendPQExpBufferChar(), appendPQExpBufferStr(), async_ctx::authz, calloc, check_for_device_flow(), check_issuer(), comb_multiplexer(), conn, conn_errorMessage, conn_oauth_discovery_uri, conn_sasl_state, async_ctx::curl_err, PQExpBufferData::data, async_ctx::debugging, drain_timer_events(), drive_request(), async_ctx::errbuf, async_ctx::errctx, finish_device_authz(), finish_discovery(), handle_token_response(), initialize_curl(), initPQExpBuffer(), device_authz::interval, PQExpBufferData::len, libpq_append_conn_error(), libpq_gettext, async_ctx::mux, OAUTH_STEP_DEVICE_AUTHORIZATION, OAUTH_STEP_DISCOVERY, OAUTH_STEP_INIT, OAUTH_STEP_TOKEN_REQUEST, OAUTH_STEP_WAIT_INTERVAL, oauth_unsafe_debugging_enabled(), PGINVALID_SOCKET, PGRES_POLLING_FAILED, PGRES_POLLING_OK, PGRES_POLLING_READING, PQExpBufferDataBroken, prompt_user(), async_ctx::running, set_conn_altsock, set_conn_oauth_token, set_timer(), setup_curl_handles(), setup_multiplexer(), start_device_authz(), start_discovery(), start_token_request(), async_ctx::step, async_ctx::timerfd, async_ctx::user_prompted, and async_ctx::work_data.
Referenced by pg_fe_run_oauth_flow().
Definition at line 2604 of file oauth-curl.c.
References actx_error, async_ctx::authz, conn, device_authz::expires_in, fprintf, libpq_gettext, PQAUTHDATA_PROMPT_OAUTH_DEVICE, PQgetAuthDataHook(), device_authz::user_code, _PGpromptOAuthDevice::user_code, device_authz::verification_uri, _PGpromptOAuthDevice::verification_uri, and device_authz::verification_uri_complete.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1100 of file oauth-curl.c.
References actx_error, actx_error_str, appendPQExpBuffer(), CHECK_GETINFO, err(), async_ctx::errbuf, and async_ctx::used_basic_auth.
Referenced by finish_device_authz(), and handle_token_response().
Definition at line 1233 of file oauth-curl.c.
References actx_error, Assert(), i, lengthof, async_ctx::mux, and socket.
Referenced by setup_curl_handles().
Definition at line 1568 of file oauth-curl.c.
References set_timer().
Referenced by setup_curl_handles().
Definition at line 465 of file oauth-curl.c.
References oauth_parse::active, Assert(), 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 1447 of file oauth-curl.c.
References actx_error, async_ctx::mux, and async_ctx::timerfd.
Referenced by drain_timer_events(), pg_fe_run_oauth_flow_impl(), and register_timer().
Definition at line 1705 of file oauth-curl.c.
References actx_error, CHECK_MSETOPT, CHECK_SETOPT, async_ctx::curl, async_ctx::curl_err, async_ctx::curlm, debug_callback(), async_ctx::debugging, async_ctx::headers, register_socket(), and register_timer().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1174 of file oauth-curl.c.
References actx_error, async_ctx::mux, and async_ctx::timerfd.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2376 of file oauth-curl.c.
References actx_error, add_client_identification(), Assert(), build_urlencoded(), CHECK_SETOPT, conn, conn_oauth_client_id, conn_oauth_scope, PQExpBufferData::data, provider::device_authorization_endpoint, PQExpBufferBroken, async_ctx::provider, resetPQExpBuffer(), start_request(), and async_ctx::work_data.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 2114 of file oauth-curl.c.
References CHECK_SETOPT, and start_request().
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1878 of file oauth-curl.c.
References actx_error, append_data(), CHECK_SETOPT, async_ctx::curl, async_ctx::curlm, err(), resetPQExpBuffer(), async_ctx::running, and async_ctx::work_data.
Referenced by start_device_authz(), start_discovery(), and start_token_request().
Definition at line 2464 of file oauth-curl.c.
References actx_error, add_client_identification(), Assert(), async_ctx::authz, build_urlencoded(), CHECK_SETOPT, conn, conn_oauth_client_id, PQExpBufferData::data, device_authz::device_code, OAUTH_GRANT_TYPE_DEVICE_CODE, PQExpBufferBroken, async_ctx::provider, resetPQExpBuffer(), start_request(), provider::token_endpoint, and async_ctx::work_data.
Referenced by pg_fe_run_oauth_flow_impl().
Definition at line 1544 of file oauth-curl.c.
References actx_error, PQsocketPoll(), and async_ctx::timerfd.
Referenced by drain_timer_events().
Definition at line 2070 of file oauth-curl.c.
References append_urlencoded(), buf, initPQExpBuffer(), and PQExpBufferDataBroken.
Referenced by add_client_identification().