original) (raw)
PostgreSQL Source Code: src/interfaces/libpq/fe-secure.c File Reference (#include "[postgres_fe.h](postgres%5F%5Ffe%5F8h%5Fsource.html)"
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <[sys/socket.h](socket%5F8h%5Fsource.html)>
#include <[unistd.h](unistd%5F8h%5Fsource.html)>
#include <[netdb.h](netdb%5F8h%5Fsource.html)>
#include <[netinet/in.h](in%5F8h%5Fsource.html)>
#include <[netinet/tcp.h](tcp%5F8h%5Fsource.html)>
#include <[arpa/inet.h](port%5F2win32%5F2arpa%5F2inet%5F8h%5Fsource.html)>
#include <sys/stat.h>
#include <pthread.h>
#include "[fe-auth.h](fe-auth%5F8h%5Fsource.html)"
#include "[libpq-fe.h](libpq-fe%5F8h%5Fsource.html)"
#include "[libpq-int.h](libpq-int%5F8h%5Fsource.html)"
Go to the source code of this file.
Macros | |
---|---|
#define | SIGPIPE_MASKED(conn) ((conn)->sigpipe_so | |
#define | DECLARE_SIGPIPE_INFO(spinfo) struct sigpipe_info spinfo |
#define | DISABLE_SIGPIPE(conn, spinfo, failaction) |
#define | REMEMBER_EPIPE(spinfo, cond) |
#define | RESTORE_SIGPIPE(conn, spinfo) |
◆ DECLARE_SIGPIPE_INFO
| #define DECLARE_SIGPIPE_INFO | ( | | spinfo | ) | struct sigpipe_info spinfo | | ------------------------------ | - | | ------ | - | ----------------------------------------------------------- |
◆ DISABLE_SIGPIPE
| #define DISABLE_SIGPIPE | ( | | conn, | | ------------------------ | - | | ------------------------------------------------------------------- | | | spinfo, | | | | | | failaction | | | | | ) | | | |
Value:
do { \
(spinfo).got_epipe = false; \
{ \
&(spinfo).sigpipe_pending) < 0) \
failaction; \
} \
} while (0)
#define SIGPIPE_MASKED(conn)
int pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending)
Definition at line 66 of file fe-secure.c.
◆ REMEMBER_EPIPE
| #define REMEMBER_EPIPE | ( | | spinfo, | | ----------------------- | - | | ------- | | | cond | | | | | ) | | | |
Value:
do { \
if (cond) \
(spinfo).got_epipe = true; \
} while (0)
Definition at line 77 of file fe-secure.c.
◆ RESTORE_SIGPIPE
| #define RESTORE_SIGPIPE | ( | | conn, | | ------------------------ | - | | ------------------------------------------------------------------- | | | spinfo | | | | | ) | | | |
Value:
do { \
pq_reset_sigpipe(&(spinfo).oldsigmask, (spinfo).sigpipe_pending, \
(spinfo).got_epipe); \
} while (0)
Definition at line 83 of file fe-secure.c.
◆ SIGPIPE_MASKED
| #define SIGPIPE_MASKED | ( | | conn | ) | ((conn)->sigpipe_so || (conn)->sigpipe_flag) | | ----------------------- | - | | ------------------------------------------------------------------ | - | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
◆ pq_block_sigpipe()
int pq_block_sigpipe | ( | sigset_t * | osigset, |
---|---|---|---|
bool * | sigpipe_pending | ||
) |
Definition at line 504 of file fe-secure.c.
505{
506 sigset_t sigpipe_sigset;
507 sigset_t sigset;
508
509 sigemptyset(&sigpipe_sigset);
510 sigaddset(&sigpipe_sigset, SIGPIPE);
511
512
513 SOCK_ERRNO_SET(pthread_sigmask(SIG_BLOCK, &sigpipe_sigset, osigset));
515 return -1;
516
517
518 if (sigismember(osigset, SIGPIPE))
519 {
520
521 if (sigpending(&sigset) != 0)
522 return -1;
523
524 if (sigismember(&sigset, SIGPIPE))
525 *sigpipe_pending = true;
526 else
527 *sigpipe_pending = false;
528 }
529 else
530 *sigpipe_pending = false;
531
532 return 0;
533}
#define SOCK_ERRNO_SET(e)
References SIGPIPE, SOCK_ERRNO, and SOCK_ERRNO_SET.
◆ pq_reset_sigpipe()
void pq_reset_sigpipe | ( | sigset_t * | osigset, |
---|---|---|---|
bool | sigpipe_pending, | ||
bool | got_epipe | ||
) |
Definition at line 554 of file fe-secure.c.
555{
557 int signo;
558 sigset_t sigset;
559
560
561 if (got_epipe && !sigpipe_pending)
562 {
563 if (sigpending(&sigset) == 0 &&
564 sigismember(&sigset, SIGPIPE))
565 {
566 sigset_t sigpipe_sigset;
567
568 sigemptyset(&sigpipe_sigset);
569 sigaddset(&sigpipe_sigset, SIGPIPE);
570
571 sigwait(&sigpipe_sigset, &signo);
572 }
573 }
574
575
576 pthread_sigmask(SIG_SETMASK, osigset, NULL);
577
579}
References SIGPIPE, SOCK_ERRNO, and SOCK_ERRNO_SET.
◆ PQdefaultSSLKeyPassHook_OpenSSL()
int PQdefaultSSLKeyPassHook_OpenSSL | ( | char * | buf, |
---|---|---|---|
int | size, | ||
PGconn * | conn | ||
) |
◆ PQgetgssctx()
void * PQgetgssctx | ( | PGconn * | conn | ) |
---|
Definition at line 483 of file fe-secure.c.
484{
485 return NULL;
486}
◆ PQgetssl()
void * PQgetssl | ( | PGconn * | conn | ) |
---|
Definition at line 428 of file fe-secure.c.
429{
430 return NULL;
431}
◆ PQgetSSLKeyPassHook_OpenSSL()
Definition at line 461 of file fe-secure.c.
462{
463 return NULL;
464}
◆ PQgssEncInUse()
int PQgssEncInUse | ( | PGconn * | conn | ) |
---|
◆ PQinitOpenSSL()
void PQinitOpenSSL | ( | int | do_ssl, |
---|---|---|---|
int | do_crypto | ||
) |
◆ PQinitSSL()
void PQinitSSL | ( | int | do_init | ) |
---|
◆ pqsecure_close()
void pqsecure_close | ( | PGconn * | conn | ) |
---|
◆ pqsecure_open_client()
◆ pqsecure_raw_read()
ssize_t pqsecure_raw_read | ( | PGconn * | conn, |
---|---|---|---|
void * | ptr, | ||
size_t | len | ||
) |
Definition at line 193 of file fe-secure.c.
194{
195 ssize_t n;
196 int result_errno = 0;
198
200
202
203 if (n < 0)
204 {
206
207
208 switch (result_errno)
209 {
210#ifdef EAGAIN
212#endif
213#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
215#endif
217
218 break;
219
220 case EPIPE:
223 "\tThis probably means the server terminated abnormally\n"
224 "\tbefore or while processing the request.");
225 break;
226
227 case 0:
228
229 n = 0;
230 break;
231
232 default:
235 sebuf, sizeof(sebuf)));
236 break;
237 }
238 }
239
240
242
243 return n;
244}
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
#define PG_STRERROR_R_BUFLEN
#define recv(s, buf, len, flags)
References conn, EAGAIN, ECONNRESET, EINTR, EWOULDBLOCK, len, libpq_append_conn_error(), PG_STRERROR_R_BUFLEN, recv, pg_conn::sock, SOCK_ERRNO, SOCK_ERRNO_SET, and SOCK_STRERROR.
Referenced by gss_read(), pg_GSS_read(), pgconn_bio_read(), and pqsecure_read().
◆ pqsecure_raw_write()
ssize_t pqsecure_raw_write | ( | PGconn * | conn, |
---|---|---|---|
const void * | ptr, | ||
size_t | len | ||
) |
Definition at line 316 of file fe-secure.c.
317{
318 ssize_t n;
319 int flags = 0;
320 int result_errno = 0;
321 char msgbuf[1024];
323
325
326
327
328
329
330
331
332
334 return len;
335
336#ifdef MSG_NOSIGNAL
338 flags |= MSG_NOSIGNAL;
339
340retry_masked:
341#endif
342
344
346
347 if (n < 0)
348 {
350
351
352
353
354
355
356#ifdef MSG_NOSIGNAL
357 if (flags != 0 && result_errno == EINVAL)
358 {
360 flags = 0;
361 goto retry_masked;
362 }
363#endif
364
365
366 switch (result_errno)
367 {
368#ifdef EAGAIN
370#endif
371#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
373#endif
375
376 break;
377
378 case EPIPE:
379
381
382
383
386
387
388 snprintf(msgbuf, sizeof(msgbuf),
389 libpq_gettext("server closed the connection unexpectedly\n"
390 "\tThis probably means the server terminated abnormally\n"
391 "\tbefore or while processing the request."));
392
393 strlcat(msgbuf, "\n", sizeof(msgbuf));
395
397 break;
398
399 default:
401
402
403 snprintf(msgbuf, sizeof(msgbuf),
404 libpq_gettext("could not send data to server: %s"),
406 sebuf, sizeof(sebuf)));
407
408 strlcat(msgbuf, "\n", sizeof(msgbuf));
410
412 break;
413 }
414 }
415
417
418
420
421 return n;
422}
#define REMEMBER_EPIPE(spinfo, cond)
#define DISABLE_SIGPIPE(conn, spinfo, failaction)
#define DECLARE_SIGPIPE_INFO(spinfo)
#define RESTORE_SIGPIPE(conn, spinfo)
size_t strlcat(char *dst, const char *src, size_t siz)
#define send(s, buf, len, flags)
References conn, DECLARE_SIGPIPE_INFO, DISABLE_SIGPIPE, EAGAIN, ECONNRESET, EINTR, EWOULDBLOCK, len, libpq_gettext, PG_STRERROR_R_BUFLEN, REMEMBER_EPIPE, RESTORE_SIGPIPE, send, pg_conn::sigpipe_flag, snprintf, pg_conn::sock, SOCK_ERRNO, SOCK_ERRNO_SET, SOCK_STRERROR, strlcat(), pg_conn::write_err_msg, and pg_conn::write_failed.
Referenced by pg_GSS_write(), pgconn_bio_write(), pqsecure_open_gss(), and pqsecure_write().
◆ pqsecure_read()
ssize_t pqsecure_read | ( | PGconn * | conn, |
---|---|---|---|
void * | ptr, | ||
size_t | len | ||
) |
Definition at line 167 of file fe-secure.c.
168{
169 ssize_t n;
170
171#ifdef USE_SSL
173 {
175 }
176 else
177#endif
178#ifdef ENABLE_GSS
179 if (conn->gssenc)
180 {
182 }
183 else
184#endif
185 {
187 }
188
189 return n;
190}
ssize_t pg_GSS_read(PGconn *conn, void *ptr, size_t len)
ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len)
ssize_t pqsecure_raw_read(PGconn *conn, void *ptr, size_t len)
References conn, len, pg_GSS_read(), pgtls_read(), pqsecure_raw_read(), and pg_conn::ssl_in_use.
Referenced by pqReadData().
◆ pqsecure_write()
ssize_t pqsecure_write | ( | PGconn * | conn, |
---|---|---|---|
const void * | ptr, | ||
size_t | len | ||
) |
Definition at line 267 of file fe-secure.c.
268{
269 ssize_t n;
270
271#ifdef USE_SSL
273 {
275 }
276 else
277#endif
278#ifdef ENABLE_GSS
279 if (conn->gssenc)
280 {
282 }
283 else
284#endif
285 {
287 }
288
289 return n;
290}
ssize_t pg_GSS_write(PGconn *conn, const void *ptr, size_t len)
ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len)
ssize_t pqsecure_raw_write(PGconn *conn, const void *ptr, size_t len)
References conn, len, pg_GSS_write(), pgtls_write(), pqsecure_raw_write(), and pg_conn::ssl_in_use.
Referenced by pqSendSome().
◆ PQsetSSLKeyPassHook_OpenSSL()
◆ PQsslAttribute()
const char * PQsslAttribute | ( | PGconn * | conn, |
---|---|---|---|
const char * | attribute_name | ||
) |
Definition at line 440 of file fe-secure.c.
441{
442 return NULL;
443}
◆ PQsslAttributeNames()
const char *const * PQsslAttributeNames | ( | PGconn * | conn | ) |
---|
Definition at line 446 of file fe-secure.c.
447{
448 static const char *const result[] = {NULL};
449
450 return result;
451}
◆ PQsslInUse()
int PQsslInUse | ( | PGconn * | conn | ) |
---|
◆ PQsslStruct()
void * PQsslStruct | ( | PGconn * | conn, |
---|---|---|---|
const char * | struct_name | ||
) |
Definition at line 434 of file fe-secure.c.
435{
436 return NULL;
437}