LCOV - code coverage report
Current view: top level - src/test/modules/ldap_password_func - ldap_password_func.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 15 15
Test Date: 2026-03-03 18:14:56 Functions: 100.0 % 3 3
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  * Copyright (c) 2022-2026, 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              : 
      21            4 : 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            4 : _PG_init(void)
      33              : {
      34            4 :     ldap_password_hook = rot13_passphrase;
      35            4 : }
      36              : 
      37              : static char *
      38            2 : rot13_passphrase(char *pw)
      39              : {
      40            2 :     size_t      size = strlen(pw) + 1;
      41              : 
      42            2 :     char       *new_pw = (char *) palloc(size);
      43              : 
      44            2 :     strlcpy(new_pw, pw, size);
      45           14 :     for (char *p = new_pw; *p; p++)
      46              :     {
      47           12 :         char        c = *p;
      48              : 
      49           12 :         if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
      50            4 :             *p = c + 13;
      51            8 :         else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
      52            7 :             *p = c - 13;
      53              :     }
      54              : 
      55            2 :     return new_pw;
      56              : }
        

Generated by: LCOV version 2.0-1