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)
 
void _PG_fini (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_fini()

void _PG_fini ( void  )

Definition at line 56 of file ssl_passphrase_func.c.

57 {
58  /* do nothing yet */
59 }

◆ _PG_init()

void _PG_init ( void  )

Definition at line 38 of file ssl_passphrase_func.c.

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

39 {
40  /* Define custom GUC variable. */
41  DefineCustomStringVariable("ssl_passphrase.passphrase",
42  "passphrase before transformation",
43  NULL,
45  NULL,
46  PGC_SIGHUP,
47  0, /* no flags required */
48  NULL,
49  NULL,
50  NULL);
51  if (ssl_passphrase)
53 }
static void set_rot13(SSL_CTX *context, bool isServerStart)
Definition: guc.h:72
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:8878
openssl_tls_init_hook_typ openssl_tls_init_hook
static char * ssl_passphrase

◆ rot13_passphrase()

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

Definition at line 73 of file ssl_passphrase_func.c.

References Assert, ssl_passphrase, and StrNCpy.

Referenced by set_rot13().

74 {
75 
76  Assert(ssl_passphrase != NULL);
77  StrNCpy(buf, ssl_passphrase, size);
78  for (char *p = buf; *p; p++)
79  {
80  char c = *p;
81 
82  if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
83  *p = c + 13;
84  else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
85  *p = c - 13;
86  }
87 
88  return strlen(buf);
89 
90 }
char * c
static char * buf
Definition: pg_test_fsync.c:67
#define Assert(condition)
Definition: c.h:738
#define StrNCpy(dst, src, len)
Definition: c.h:944
static char * ssl_passphrase

◆ set_rot13()

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

Definition at line 62 of file ssl_passphrase_func.c.

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

Referenced by _PG_init().

63 {
64  /* warn if the user has set ssl_passphrase_command */
67  (errmsg("ssl_passphrase_command setting ignored by ssl_passphrase_func module")));
68 
69  SSL_CTX_set_default_passwd_cb(context, rot13_passphrase);
70 }
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:144
static int rot13_passphrase(char *buf, int size, int rwflag, void *userdata)
int errmsg(const char *fmt,...)
Definition: elog.c:824
char * ssl_passphrase_command
Definition: be-secure.c:46

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 26 of file ssl_passphrase_func.c.

Referenced by _PG_init(), and rot13_passphrase().