PostgreSQL Source Code  git master
ldap_password_func.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * Copyright (c) 2022-2024, PostgreSQL Global Development Group
4  *
5  * ldap_password_func.c
6  *
7  * Loadable PostgreSQL module to mutate the ldapbindpasswd. This
8  * implementation just hands back the configured password rot13'd.
9  *
10  *-------------------------------------------------------------------------
11  */
12 
13 #include "postgres.h"
14 
15 #include <float.h>
16 #include <stdio.h>
17 
18 #include "libpq/auth.h"
19 #include "libpq/libpq.h"
20 #include "libpq/libpq-be.h"
21 #include "utils/guc.h"
22 
24 
25 void _PG_init(void);
26 
27 /* hook function */
28 static char *rot13_passphrase(char *password);
29 
30 /*
31  * Module load callback
32  */
33 void
34 _PG_init(void)
35 {
37 }
38 
39 static char *
41 {
42  size_t size = strlen(pw) + 1;
43 
44  char *new_pw = (char *) palloc(size);
45 
46  strlcpy(new_pw, pw, size);
47  for (char *p = new_pw; *p; p++)
48  {
49  char c = *p;
50 
51  if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
52  *p = c + 13;
53  else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
54  *p = c - 13;
55  }
56 
57  return new_pw;
58 }
PGDLLIMPORT auth_password_hook_typ ldap_password_hook
static char * rot13_passphrase(char *password)
void _PG_init(void)
PG_MODULE_MAGIC
void * palloc(Size size)
Definition: mcxt.c:1317
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
char * c
static pg_noinline void Size size
Definition: slab.c:607
static char * password
Definition: streamutil.c:54