PostgreSQL Source Code git master
oauth-utils.c File Reference
#include "postgres_fe.h"
#include <signal.h>
#include "oauth-utils.h"
Include dependency graph for oauth-utils.c:

Go to the source code of this file.

Macros

#define SOCK_ERRNO   errno
 
#define SOCK_ERRNO_SET(e)   (errno = (e))
 

Functions

void libpq_oauth_init (pgthreadlock_t threadlock_impl, libpq_gettext_func gettext_impl, conn_errorMessage_func errmsg_impl, conn_oauth_client_id_func clientid_impl, conn_oauth_client_secret_func clientsecret_impl, conn_oauth_discovery_uri_func discoveryuri_impl, conn_oauth_issuer_id_func issuerid_impl, conn_oauth_scope_func scope_impl, conn_sasl_state_func saslstate_impl, set_conn_altsock_func setaltsock_impl, set_conn_oauth_token_func settoken_impl)
 
void libpq_append_conn_error (PGconn *conn, const char *fmt,...)
 
bool oauth_unsafe_debugging_enabled (void)
 
int pq_block_sigpipe (sigset_t *osigset, bool *sigpipe_pending)
 
void pq_reset_sigpipe (sigset_t *osigset, bool sigpipe_pending, bool got_epipe)
 

Variables

pgthreadlock_t pg_g_threadlock
 
static libpq_gettext_func libpq_gettext_impl
 
conn_errorMessage_func conn_errorMessage
 
conn_oauth_client_id_func conn_oauth_client_id
 
conn_oauth_client_secret_func conn_oauth_client_secret
 
conn_oauth_discovery_uri_func conn_oauth_discovery_uri
 
conn_oauth_issuer_id_func conn_oauth_issuer_id
 
conn_oauth_scope_func conn_oauth_scope
 
conn_sasl_state_func conn_sasl_state
 
set_conn_altsock_func set_conn_altsock
 
set_conn_oauth_token_func set_conn_oauth_token
 

Macro Definition Documentation

◆ SOCK_ERRNO

#define SOCK_ERRNO   errno

Definition at line 164 of file oauth-utils.c.

◆ SOCK_ERRNO_SET

#define SOCK_ERRNO_SET (   e)    (errno = (e))

Definition at line 165 of file oauth-utils.c.

Function Documentation

◆ libpq_append_conn_error()

void libpq_append_conn_error ( PGconn conn,
const char *  fmt,
  ... 
)

Definition at line 95 of file oauth-utils.c.

96{
97 int save_errno = errno;
98 bool done;
99 va_list args;
100 PQExpBuffer errorMessage = conn_errorMessage(conn);
101
102 Assert(fmt[strlen(fmt) - 1] != '\n');
103
104 if (PQExpBufferBroken(errorMessage))
105 return; /* already failed */
106
107 /* Loop in case we have to retry after enlarging the buffer. */
108 do
109 {
110 errno = save_errno;
111 va_start(args, fmt);
112 done = appendPQExpBufferVA(errorMessage, libpq_gettext(fmt), args);
113 va_end(args);
114 } while (!done);
115
116 appendPQExpBufferChar(errorMessage, '\n');
117}
Assert(PointerIsAligned(start, uint64))
conn_errorMessage_func conn_errorMessage
Definition: oauth-utils.c:38
#define libpq_gettext(x)
Definition: oauth-utils.h:86
bool appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args)
Definition: pqexpbuffer.c:294
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
#define PQExpBufferBroken(str)
Definition: pqexpbuffer.h:59
PGconn * conn
Definition: streamutil.c:52

References appendPQExpBufferChar(), appendPQExpBufferVA(), generate_unaccent_rules::args, Assert(), conn, conn_errorMessage, libpq_gettext, and PQExpBufferBroken.

Referenced by build_client_final_message(), build_client_first_message(), check_expected_areq(), client_initial_response(), connectFailureMessage(), connectNoDelay(), fillPGconn(), free_async_ctx(), getBackendKeyData(), handle_oauth_sasl_error(), handleSyncLoss(), init_allowed_encryption_methods(), initialize_curl(), initialize_SSL(), issuer_from_well_known_uri(), lo_create(), lo_export(), lo_import_internal(), lo_initialize(), lo_lseek64(), lo_read(), lo_tell64(), lo_truncate(), lo_truncate64(), lo_write(), oauth_exchange(), open_client_SSL(), openssl_verify_peer_name_matches_certificate_ip(), openssl_verify_peer_name_matches_certificate_name(), pg_fe_run_oauth_flow_impl(), pg_fe_sendauth(), pg_GSS_load_servicename(), pg_GSS_read(), pg_GSS_write(), pg_password_sendauth(), pg_SASL_continue(), pg_SASL_init(), pgpassfileWarning(), pgtls_get_peer_certificate_hash(), pgtls_read(), pgtls_write(), pq_verify_peer_name_matches_certificate(), pq_verify_peer_name_matches_certificate_ip(), pq_verify_peer_name_matches_certificate_name(), pqAllocCmdQueueEntry(), PQcancelCreate(), PQcancelPoll(), PQcancelStart(), pqConnectOptions2(), PQconnectPoll(), pqCopyPGconn(), PQencryptPasswordConn(), pqEndcopy3(), PQenterPipelineMode(), PQescapeByteaInternal(), PQescapeInternal(), PQescapeStringInternal(), PQexecStart(), PQexitPipelineMode(), PQfn(), pqFunctionCall3(), PQgetCopyData(), pqGetCopyData3(), pqGetErrorNotice3(), pqGetline3(), pqGetNegotiateProtocolVersion3(), PQgetResult(), pqParseInput3(), pqParseIntParam(), pqParseProtocolVersion(), pqPipelineProcessQueue(), pqPipelineSyncInternal(), pqPrepareAsyncResult(), PQputCopyData(), PQputCopyEnd(), pqSaveWriteError(), pqsecure_open_gss(), pqsecure_raw_read(), PQsendFlushRequest(), PQsendPrepare(), PQsendQueryGuts(), PQsendQueryInternal(), PQsendQueryParams(), PQsendQueryPrepared(), PQsendQueryStart(), PQsendTypedCommand(), PQsetdbLogin(), read_server_final_message(), read_server_first_message(), run_user_oauth_flow(), scram_exchange(), select_next_encryption_method(), setKeepalivesCount(), setKeepalivesIdle(), setKeepalivesInterval(), setTCPUserTimeout(), setup_oauth_parameters(), setup_token_request(), and store_conn_addrinfo().

◆ libpq_oauth_init()

void libpq_oauth_init ( pgthreadlock_t  threadlock_impl,
libpq_gettext_func  gettext_impl,
conn_errorMessage_func  errmsg_impl,
conn_oauth_client_id_func  clientid_impl,
conn_oauth_client_secret_func  clientsecret_impl,
conn_oauth_discovery_uri_func  discoveryuri_impl,
conn_oauth_issuer_id_func  issuerid_impl,
conn_oauth_scope_func  scope_impl,
conn_sasl_state_func  saslstate_impl,
set_conn_altsock_func  setaltsock_impl,
set_conn_oauth_token_func  settoken_impl 
)

Definition at line 65 of file oauth-utils.c.

76{
77 pg_g_threadlock = threadlock_impl;
78 libpq_gettext_impl = gettext_impl;
79 conn_errorMessage = errmsg_impl;
80 conn_oauth_client_id = clientid_impl;
81 conn_oauth_client_secret = clientsecret_impl;
82 conn_oauth_discovery_uri = discoveryuri_impl;
83 conn_oauth_issuer_id = issuerid_impl;
84 conn_oauth_scope = scope_impl;
85 conn_sasl_state = saslstate_impl;
86 set_conn_altsock = setaltsock_impl;
87 set_conn_oauth_token = settoken_impl;
88}
set_conn_oauth_token_func set_conn_oauth_token
Definition: oauth-utils.c:47
conn_oauth_client_secret_func conn_oauth_client_secret
Definition: oauth-utils.c:40
conn_sasl_state_func conn_sasl_state
Definition: oauth-utils.c:44
conn_oauth_client_id_func conn_oauth_client_id
Definition: oauth-utils.c:39
conn_oauth_scope_func conn_oauth_scope
Definition: oauth-utils.c:43
static libpq_gettext_func libpq_gettext_impl
Definition: oauth-utils.c:36
pgthreadlock_t pg_g_threadlock
Definition: oauth-utils.c:35
conn_oauth_issuer_id_func conn_oauth_issuer_id
Definition: oauth-utils.c:42
set_conn_altsock_func set_conn_altsock
Definition: oauth-utils.c:46
conn_oauth_discovery_uri_func conn_oauth_discovery_uri
Definition: oauth-utils.c:41

References conn_errorMessage, conn_oauth_client_id, conn_oauth_client_secret, conn_oauth_discovery_uri, conn_oauth_issuer_id, conn_oauth_scope, conn_sasl_state, libpq_gettext_impl, pg_g_threadlock, set_conn_altsock, and set_conn_oauth_token.

◆ oauth_unsafe_debugging_enabled()

bool oauth_unsafe_debugging_enabled ( void  )

Definition at line 149 of file oauth-utils.c.

150{
151 const char *env = getenv("PGOAUTHDEBUG");
152
153 return (env && strcmp(env, "UNSAFE") == 0);
154}

Referenced by pg_fe_run_oauth_flow_impl().

◆ pq_block_sigpipe()

int pq_block_sigpipe ( sigset_t *  osigset,
bool *  sigpipe_pending 
)

Definition at line 172 of file oauth-utils.c.

173{
174 sigset_t sigpipe_sigset;
175 sigset_t sigset;
176
177 sigemptyset(&sigpipe_sigset);
178 sigaddset(&sigpipe_sigset, SIGPIPE);
179
180 /* Block SIGPIPE and save previous mask for later reset */
181 SOCK_ERRNO_SET(pthread_sigmask(SIG_BLOCK, &sigpipe_sigset, osigset));
182 if (SOCK_ERRNO)
183 return -1;
184
185 /* We can have a pending SIGPIPE only if it was blocked before */
186 if (sigismember(osigset, SIGPIPE))
187 {
188 /* Is there a pending SIGPIPE? */
189 if (sigpending(&sigset) != 0)
190 return -1;
191
192 if (sigismember(&sigset, SIGPIPE))
193 *sigpipe_pending = true;
194 else
195 *sigpipe_pending = false;
196 }
197 else
198 *sigpipe_pending = false;
199
200 return 0;
201}
#define SOCK_ERRNO
Definition: oauth-utils.c:164
#define SOCK_ERRNO_SET(e)
Definition: oauth-utils.c:165
#define SIGPIPE
Definition: win32_port.h:163

References SIGPIPE, SOCK_ERRNO, and SOCK_ERRNO_SET.

Referenced by pg_fe_run_oauth_flow(), and PQprint().

◆ pq_reset_sigpipe()

void pq_reset_sigpipe ( sigset_t *  osigset,
bool  sigpipe_pending,
bool  got_epipe 
)

Definition at line 208 of file oauth-utils.c.

209{
210 int save_errno = SOCK_ERRNO;
211 int signo;
212 sigset_t sigset;
213
214 /* Clear SIGPIPE only if none was pending */
215 if (got_epipe && !sigpipe_pending)
216 {
217 if (sigpending(&sigset) == 0 &&
218 sigismember(&sigset, SIGPIPE))
219 {
220 sigset_t sigpipe_sigset;
221
222 sigemptyset(&sigpipe_sigset);
223 sigaddset(&sigpipe_sigset, SIGPIPE);
224
225 sigwait(&sigpipe_sigset, &signo);
226 }
227 }
228
229 /* Restore saved block mask */
230 pthread_sigmask(SIG_SETMASK, osigset, NULL);
231
232 SOCK_ERRNO_SET(save_errno);
233}

References SIGPIPE, SOCK_ERRNO, and SOCK_ERRNO_SET.

Referenced by pg_fe_run_oauth_flow(), and PQprint().

Variable Documentation

◆ conn_errorMessage

conn_errorMessage_func conn_errorMessage

Definition at line 38 of file oauth-utils.c.

Referenced by libpq_append_conn_error(), and libpq_oauth_init().

◆ conn_oauth_client_id

conn_oauth_client_id_func conn_oauth_client_id

Definition at line 39 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ conn_oauth_client_secret

conn_oauth_client_secret_func conn_oauth_client_secret

Definition at line 40 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ conn_oauth_discovery_uri

conn_oauth_discovery_uri_func conn_oauth_discovery_uri

Definition at line 41 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ conn_oauth_issuer_id

conn_oauth_issuer_id_func conn_oauth_issuer_id

Definition at line 42 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ conn_oauth_scope

conn_oauth_scope_func conn_oauth_scope

Definition at line 43 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ conn_sasl_state

conn_sasl_state_func conn_sasl_state

Definition at line 44 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ libpq_gettext_impl

libpq_gettext_func libpq_gettext_impl
static

Definition at line 36 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ pg_g_threadlock

pgthreadlock_t pg_g_threadlock

Definition at line 35 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ set_conn_altsock

set_conn_altsock_func set_conn_altsock

Definition at line 46 of file oauth-utils.c.

Referenced by libpq_oauth_init().

◆ set_conn_oauth_token

set_conn_oauth_token_func set_conn_oauth_token

Definition at line 47 of file oauth-utils.c.

Referenced by libpq_oauth_init().