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

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

Variables

 PG_MODULE_MAGIC
 
static char * ssl_passphrase = NULL
 

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 37 of file ssl_passphrase_func.c.

38 {
39  /* Define custom GUC variable. */
40  DefineCustomStringVariable("ssl_passphrase.passphrase",
41  "passphrase before transformation",
42  NULL,
44  NULL,
45  PGC_SIGHUP,
46  0, /* no flags required */
47  NULL,
48  NULL,
49  NULL);
50 
51  MarkGUCPrefixReserved("ssl_passphrase");
52 
53  if (ssl_passphrase)
55 }
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:9564
void MarkGUCPrefixReserved(const char *className)
Definition: guc.c:9625
@ PGC_SIGHUP
Definition: guc.h:72
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 69 of file ssl_passphrase_func.c.

70 {
71 
72  Assert(ssl_passphrase != NULL);
73  strlcpy(buf, ssl_passphrase, size);
74  for (char *p = buf; *p; p++)
75  {
76  char c = *p;
77 
78  if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
79  *p = c + 13;
80  else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
81  *p = c - 13;
82  }
83 
84  return strlen(buf);
85 }
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 58 of file ssl_passphrase_func.c.

59 {
60  /* warn if the user has set ssl_passphrase_command */
63  (errmsg("ssl_passphrase_command setting ignored by ssl_passphrase_func module")));
64 
65  SSL_CTX_set_default_passwd_cb(context, rot13_passphrase);
66 }
char * ssl_passphrase_command
Definition: be-secure.c:47
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define WARNING
Definition: elog.h:30
#define ereport(elevel,...)
Definition: elog.h:143
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 25 of file ssl_passphrase_func.c.

Referenced by _PG_init(), and rot13_passphrase().