summaryrefslogtreecommitdiffstats
path: root/contrib/slapd-modules/ppm/ppm_test.c
blob: 520aa0aff557223cb7dc88aabb00c0987057f711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include "ppm.h"

int main(int argc, char *argv[])
{
  /*
   * argv[1]: user
   * argv[2]: password
   * argv[3]: configuration file
   */

  int ret = 1;

  if(argc > 2)
  {
    printf("Testing user %s password: '%s' against %s policy config file \n",
            argv[1], argv[2], argv[3]
          );

    /* format user entry */
    char *errmsg = NULL;
    Entry pEntry;
    pEntry.e_nname.bv_val=argv[1];
    pEntry.e_name.bv_val=argv[1];

    /* get configuration file content */
    struct berval pArg;
    FILE *fp;
    if ((fp = fopen(argv[3],"r")) == NULL)
    {
      fprintf(stderr,"Unable to open config file for reading\n");
      return ret;
    }
    char *fcontent = NULL;
    fseek(fp, 0, SEEK_END);
    long fsize = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    fcontent = malloc(fsize);
    fread(fcontent, 1, fsize, fp);
    fclose(fp);
    pArg.bv_val = fcontent;
  
    ppm_test=1; // enable ppm_test for informing ppm not to use syslog

    ret = check_password(argv[2], &errmsg, &pEntry, &pArg);

    if(ret == 0)
    {
      printf("Password is OK!\n");
    }
    else
    {
      printf("Password failed checks : %s\n", errmsg);
    }

    ber_memfree(errmsg);
    return ret;

  }

  return ret;
}