1 /* $NetBSD: ppm_test.c,v 1.2 2021/08/14 16:14:53 christos Exp $ */ 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include "ppm.h" 6 7 int main(int argc, char *argv[]) 8 { 9 /* 10 * argv[1]: user 11 * argv[2]: password 12 * argv[3]: configuration file 13 */ 14 15 int ret = 1; 16 17 if(argc > 2) 18 { 19 printf("Testing user %s password: '%s' against %s policy config file \n", 20 argv[1], argv[2], argv[3] 21 ); 22 23 /* format user entry */ 24 char *errmsg = NULL; 25 Entry pEntry; 26 pEntry.e_nname.bv_val=argv[1]; 27 pEntry.e_name.bv_val=argv[1]; 28 29 /* get configuration file content */ 30 struct berval pArg; 31 FILE *fp; 32 if ((fp = fopen(argv[3],"r")) == NULL) 33 { 34 fprintf(stderr,"Unable to open config file for reading\n"); 35 return ret; 36 } 37 char *fcontent = NULL; 38 fseek(fp, 0, SEEK_END); 39 long fsize = ftell(fp); 40 fseek(fp, 0, SEEK_SET); 41 fcontent = malloc(fsize); 42 fread(fcontent, 1, fsize, fp); 43 fclose(fp); 44 pArg.bv_val = fcontent; 45 46 ppm_test=1; // enable ppm_test for informing ppm not to use syslog 47 48 ret = check_password(argv[2], &errmsg, &pEntry, &pArg); 49 50 if(ret == 0) 51 { 52 printf("Password is OK!\n"); 53 } 54 else 55 { 56 printf("Password failed checks : %s\n", errmsg); 57 } 58 59 ber_memfree(errmsg); 60 return ret; 61 62 } 63 64 return ret; 65 } 66 67 68 69