]> eyrie.org Git - kerberos/krb5-strength.git/blob - src/kadmin_plugin.c
Import the current krb5-strength code.
[kerberos/krb5-strength.git] / src / kadmin_plugin.c
1 /* cc -dynamiclib -o plugin.so ~/plugin.c -lcrack */
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <syslog.h>
6 #include <sys/stat.h>
7
8 #ifndef PATH_MAX
9 #define PATH_MAX 256
10 #endif
11
12 extern char * FascistCheck(char *passwd,char *dictpath) ; 
13
14 static struct lctx {
15     char *dict_file;
16 } l_context;
17
18 int pwcheck_init(void **context, const char *dict_file)
19 {
20     static char p[PATH_MAX];
21     static struct stat st;
22
23     strncpy(p, dict_file, PATH_MAX-5);
24     strncat(p, ".pwd", PATH_MAX);
25     p[PATH_MAX - 1] = '\0';
26     
27     if (lstat(p, &st) < 0)
28         return 1;
29
30     *context = &l_context;
31
32     l_context.dict_file = strdup(dict_file);
33     
34     return 0;
35 }
36
37 int pwcheck_check(void *context, const char *password, const char
38                   *princ, char *msg, int msglen)
39 {
40     char *msg2;
41
42     if (msg2 = FascistCheck((char *)password, ((struct lctx *)context)->dict_file))
43     {
44         strncpy(msg, msg2, msglen);
45         msg[msglen - 1] = '\0';
46         return 1;
47     }
48     
49     if (strcasecmp(password, princ) == 0) {
50         snprintf(msg, msglen, "You can't use \"%s\" as a password!",
51                  princ);
52         msg[msglen - 1] = '\0';
53         return 1;
54     }
55
56     return 0;
57 }
58
59 void pwcheck_close(void *context)
60 {
61     if (l_context.dict_file) free(l_context.dict_file);
62     l_context.dict_file = NULL;
63 }