s4-dns: Check DLZ_DLOPEN_VERSION for different BIND versions
[Samba.git] / examples / auth / crackcheck / crackcheck.c
blobac29b22592ea5baaae63d15b75d6a555bc7825be
1 #include <memory.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <ctype.h>
6 #include <crack.h>
8 void usage(char *command) {
9 char *c, *comm;
11 comm = command;
12 while ((c = strrchr(comm, '/')) != NULL) {
13 comm = c + 1;
16 fprintf(stderr, "Usage: %s [-c] [-s] [-d <dictionary>]\n\n", comm);
17 fprintf(stderr, " -c enables NT like complexity checks\n");
18 fprintf(stderr, " -d <dictionary file> for cracklib\n");
19 fprintf(stderr, " -s simple check use NT like checks ONLY\n\n");
20 fprintf(stderr, "The password is read via stdin.\n\n");
21 exit(-1);
24 int complexity(char* passwd)
26 /* TG 26.10.2005
27 * check password for complexity like MS Windows NT
30 int c_upper = 0;
31 int c_lower = 0;
32 int c_digit = 0;
33 int c_punct = 0;
34 int c_tot = 0;
35 int i, len;
37 if (!passwd) goto fail;
38 len = strlen(passwd);
40 for (i = 0; i < len; i++) {
42 if (c_tot >= 3) break;
44 if (isupper(passwd[i])) {
45 if (!c_upper) {
46 c_upper = 1;
47 c_tot += 1;
49 continue;
51 if (islower(passwd[i])) {
52 if (!c_lower) {
53 c_lower = 1;
54 c_tot += 1;
56 continue;
58 if (isdigit(passwd[i])) {
59 if (!c_digit) {
60 c_digit = 1;
61 c_tot += 1;
63 continue;
65 if (ispunct(passwd[i])) {
66 if (!c_punct) {
67 c_punct = 1;
68 c_tot += 1;
70 continue;
74 if ((c_tot) < 3) goto fail;
75 return 0;
77 fail:
78 fprintf(stderr, "ERR Complexity check failed\n\n");
79 return -4;
82 int main(int argc, char **argv) {
83 extern char *optarg;
84 int c, ret, complex_check = 0, simplex_check = 0;
86 char f[256];
87 char *dictionary = NULL;
88 char *password;
89 char *reply;
91 while ( (c = getopt(argc, argv, "d:cs")) != EOF){
92 switch(c) {
93 case 'd':
94 dictionary = strdup(optarg);
95 break;
96 case 'c':
97 complex_check = 1;
98 break;
99 case 's':
100 complex_check = 1;
101 simplex_check = 1;
102 break;
103 default:
104 usage(argv[0]);
108 if (!simplex_check && dictionary == NULL) {
109 fprintf(stderr, "ERR - Missing cracklib dictionary\n\n");
110 usage(argv[0]);
113 fflush(stdin);
114 password = fgets(f, sizeof(f), stdin);
116 if (password == NULL) {
117 fprintf(stderr, "ERR - Failed to read password\n\n");
118 exit(-2);
121 if (complex_check) {
122 ret = complexity(password);
123 if (ret) {
124 exit(ret);
128 if (simplex_check) {
129 exit(0);
132 reply = FascistCheck(password, dictionary);
133 if (reply != NULL) {
134 fprintf(stderr, "ERR - %s\n\n", reply);
135 exit(-3);
138 exit(0);