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

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

Generated by: LCOV version 1.14