Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * Copyright (c) 2022-2025, 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 "fmgr.h"
19 : : #include "libpq/auth.h"
20 : :
906 andrew@dunslane.net 21 :UBC 0 : PG_MODULE_MAGIC;
22 : :
23 : : void _PG_init(void);
24 : :
25 : : /* hook function */
26 : : static char *rot13_passphrase(char *password);
27 : :
28 : : /*
29 : : * Module load callback
30 : : */
31 : : void
32 : 0 : _PG_init(void)
33 : : {
34 : 0 : ldap_password_hook = rot13_passphrase;
35 : 0 : }
36 : :
37 : : static char *
38 : 0 : rot13_passphrase(char *pw)
39 : : {
40 : 0 : size_t size = strlen(pw) + 1;
41 : :
42 : 0 : char *new_pw = (char *) palloc(size);
43 : :
44 : 0 : strlcpy(new_pw, pw, size);
45 [ # # ]: 0 : for (char *p = new_pw; *p; p++)
46 : : {
47 : 0 : char c = *p;
48 : :
49 [ # # # # : 0 : if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
# # # # ]
50 : 0 : *p = c + 13;
51 [ # # # # : 0 : else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
# # # # ]
52 : 0 : *p = c - 13;
53 : : }
54 : :
55 : 0 : return new_pw;
56 : : }
|