LCOV - differential code coverage report
Current view: top level - src/test/modules/ldap_password_func - ldap_password_func.c (source / functions) Coverage Total Hit UNC GNC
Current: Differential Code Coverage HEAD vs 15 Lines: 88.2 % 17 15 2 15
Current Date: 2023-04-08 17:13:01 Functions: 75.0 % 4 3 1 3
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 [..60] days: 88.2 % 17 15 2 15
Legend: Lines: hit not hit Function coverage date bins:
[..60] days: 75.0 % 4 3 1 3

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*-------------------------------------------------------------------------
                                  2                 :  *
                                  3                 :  * Copyright (c) 2022, 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/libpq.h"
                                 19                 : #include "libpq/libpq-be.h"
                                 20                 : #include "libpq/auth.h"
                                 21                 : #include "utils/guc.h"
                                 22                 : 
   25 andrew                     23 GNC           4 : PG_MODULE_MAGIC;
                                 24                 : 
                                 25                 : void        _PG_init(void);
                                 26                 : void        _PG_fini(void);
                                 27                 : 
                                 28                 : /* hook function */
                                 29                 : static char *rot13_passphrase(char *password);
                                 30                 : 
                                 31                 : /*
                                 32                 :  * Module load callback
                                 33                 :  */
                                 34                 : void
                                 35               4 : _PG_init(void)
                                 36                 : {
                                 37               4 :     ldap_password_hook = rot13_passphrase;
                                 38               4 : }
                                 39                 : 
                                 40                 : void
   25 andrew                     41 UNC           0 : _PG_fini(void)
                                 42                 : {
                                 43                 :     /* do  nothing yet */
                                 44               0 : }
                                 45                 : 
                                 46                 : static char *
   25 andrew                     47 GNC           2 : rot13_passphrase(char *pw)
                                 48                 : {
                                 49               2 :     size_t      size = strlen(pw) + 1;
                                 50                 : 
                                 51               2 :     char       *new_pw = (char *) palloc(size);
                                 52                 : 
                                 53               2 :     strlcpy(new_pw, pw, size);
                                 54              14 :     for (char *p = new_pw; *p; p++)
                                 55                 :     {
                                 56              12 :         char        c = *p;
                                 57                 : 
                                 58              12 :         if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
                                 59               4 :             *p = c + 13;
                                 60               8 :         else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
                                 61               7 :             *p = c - 13;
                                 62                 :     }
                                 63                 : 
                                 64               2 :     return new_pw;
                                 65                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a