PostgreSQL Source Code: src/interfaces/libpq-oauth/oauth-utils.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

18

19#include <signal.h>

20

22

23#ifndef USE_DYNAMIC_OAUTH

24#error oauth-utils.c is not supported in static builds

25#endif

26

27#ifdef LIBPQ_INT_H

28#error do not rely on libpq-int.h in dynamic builds of libpq-oauth

29#endif

30

31

32

33

34

37

45

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64void

67 conn_errorMessage_func errmsg_impl,

68 conn_oauth_client_id_func clientid_impl,

69 conn_oauth_client_secret_func clientsecret_impl,

70 conn_oauth_discovery_uri_func discoveryuri_impl,

71 conn_oauth_issuer_id_func issuerid_impl,

72 conn_oauth_scope_func scope_impl,

73 conn_sasl_state_func saslstate_impl,

74 set_conn_altsock_func setaltsock_impl,

75 set_conn_oauth_token_func settoken_impl)

76{

88}

89

90

91

92

93

94void

96{

97 int save_errno = errno;

98 bool done;

101

102 Assert(fmt[strlen(fmt) - 1] != '\n');

103

105 return;

106

107

108 do

109 {

110 errno = save_errno;

111 va_start(args, fmt);

113 va_end(args);

114 } while (!done);

115

117}

118

119#ifdef ENABLE_NLS

120

121

122

123

124char *

126{

128 {

129

130

131

132

133

134

135

136

138 }

139

141}

142

143#endif

144

145

146

147

148bool

150{

151 const char *env = getenv("PGOAUTHDEBUG");

152

153 return (env && strcmp(env, "UNSAFE") == 0);

154}

155

156

157

158

159

160#ifdef WIN32

161#define SOCK_ERRNO (WSAGetLastError())

162#define SOCK_ERRNO_SET(e) WSASetLastError(e)

163#else

164#define SOCK_ERRNO errno

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

166#endif

167

168

169

170

171int

173{

174 sigset_t sigpipe_sigset;

175 sigset_t sigset;

176

177 sigemptyset(&sigpipe_sigset);

178 sigaddset(&sigpipe_sigset, SIGPIPE);

179

180

181 SOCK_ERRNO_SET(pthread_sigmask(SIG_BLOCK, &sigpipe_sigset, osigset));

183 return -1;

184

185

186 if (sigismember(osigset, SIGPIPE))

187 {

188

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}

202

203

204

205

206

207void

209{

211 int signo;

212 sigset_t sigset;

213

214

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

230 pthread_sigmask(SIG_SETMASK, osigset, NULL);

231

233}

#define unconstify(underlying_type, expr)

Assert(PointerIsAligned(start, uint64))

void(* pgthreadlock_t)(int acquire)

set_conn_oauth_token_func set_conn_oauth_token

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

conn_oauth_client_secret_func conn_oauth_client_secret

conn_sasl_state_func conn_sasl_state

conn_oauth_client_id_func conn_oauth_client_id

int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending)

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)

conn_oauth_scope_func conn_oauth_scope

static libpq_gettext_func libpq_gettext_impl

pgthreadlock_t pg_g_threadlock

conn_oauth_issuer_id_func conn_oauth_issuer_id

set_conn_altsock_func set_conn_altsock

conn_oauth_discovery_uri_func conn_oauth_discovery_uri

#define SOCK_ERRNO_SET(e)

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

conn_errorMessage_func conn_errorMessage

bool oauth_unsafe_debugging_enabled(void)

char *(* libpq_gettext_func)(const char *msgid)

bool appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args)

void appendPQExpBufferChar(PQExpBuffer str, char ch)

#define PQExpBufferBroken(str)