PostgreSQL Source Code  git master
ssl_passphrase_func.c File Reference
#include "postgres.h"
#include <float.h>
#include <stdio.h>
#include "libpq/libpq.h"
#include "libpq/libpq-be.h"
#include "utils/guc.h"
Include dependency graph for ssl_passphrase_func.c:

Go to the source code of this file.

Functions

static int rot13_passphrase (char *buf, int size, int rwflag, void *userdata)
 
static void set_rot13 (SSL_CTX *context, bool isServerStart)
 
void _PG_init (void)
 

Variables

 PG_MODULE_MAGIC
 
static char * ssl_passphrase = NULL
 

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 35 of file ssl_passphrase_func.c.

36 {
37  /* Define custom GUC variable. */
38  DefineCustomStringVariable("ssl_passphrase.passphrase",
39  "passphrase before transformation",
40  NULL,
42  NULL,
43  PGC_SIGHUP,
44  0, /* no flags required */
45  NULL,
46  NULL,
47  NULL);
48 
49  MarkGUCPrefixReserved("ssl_passphrase");
50 
51  if (ssl_passphrase)
53 }
openssl_tls_init_hook_typ openssl_tls_init_hook
void DefineCustomStringVariable(const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
Definition: guc.c:5026
void MarkGUCPrefixReserved(const char *className)
Definition: guc.c:5087
@ PGC_SIGHUP
Definition: guc.h:71
static char * ssl_passphrase
static void set_rot13(SSL_CTX *context, bool isServerStart)

References DefineCustomStringVariable(), MarkGUCPrefixReserved(), openssl_tls_init_hook, PGC_SIGHUP, set_rot13(), and ssl_passphrase.

◆ rot13_passphrase()

static int rot13_passphrase ( char *  buf,
int  size,
int  rwflag,
void *  userdata 
)
static

Definition at line 67 of file ssl_passphrase_func.c.

68 {
69 
70  Assert(ssl_passphrase != NULL);
71  strlcpy(buf, ssl_passphrase, size);
72  for (char *p = buf; *p; p++)
73  {
74  char c = *p;
75 
76  if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
77  *p = c + 13;
78  else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
79  *p = c - 13;
80  }
81 
82  return strlen(buf);
83 }
Assert(fmt[strlen(fmt) - 1] !='\n')
static char * buf
Definition: pg_test_fsync.c:67
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
char * c

References Assert(), buf, ssl_passphrase, and strlcpy().

Referenced by set_rot13().

◆ set_rot13()

static void set_rot13 ( SSL_CTX *  context,
bool  isServerStart 
)
static

Definition at line 56 of file ssl_passphrase_func.c.

57 {
58  /* warn if the user has set ssl_passphrase_command */
61  (errmsg("ssl_passphrase_command setting ignored by ssl_passphrase_func module")));
62 
63  SSL_CTX_set_default_passwd_cb(context, rot13_passphrase);
64 }
char * ssl_passphrase_command
Definition: be-secure.c:45
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define WARNING
Definition: elog.h:32
#define ereport(elevel,...)
Definition: elog.h:145
static int rot13_passphrase(char *buf, int size, int rwflag, void *userdata)

References ereport, errmsg(), rot13_passphrase(), ssl_passphrase_command, and WARNING.

Referenced by _PG_init().

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 21 of file ssl_passphrase_func.c.

◆ ssl_passphrase

char* ssl_passphrase = NULL
static

Definition at line 23 of file ssl_passphrase_func.c.

Referenced by _PG_init(), and rot13_passphrase().