r2331: check password script code and example from trunk
[Samba.git] / examples / auth / crackcheck / crackcheck.c
blob338433779b0d6b0bbe99d881e1734cc215aa54c2
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 -d dictionary\n\n", comm);
17 fprintf(stderr, " -d dictionary file for cracklib\n\n");
18 fprintf(stderr, " The password is expected to be given via stdin.\n\n");
19 exit(-1);
22 int main(int argc, char **argv) {
23 extern char *optarg;
24 int c;
26 char f[256];
27 char *dictionary = NULL;
28 char *password;
29 char *reply;
31 while ( (c = getopt(argc, argv, "d:")) != EOF){
32 switch(c) {
33 case 'd':
34 dictionary = strdup(optarg);
35 break;
36 default:
37 usage(argv[0]);
41 if (dictionary == NULL) {
42 fprintf(stderr, "ERR - Wrong Command Line\n\n");
43 usage(argv[0]);
46 password = fgets(f, sizeof(f), stdin);
48 if (password == NULL) {
49 fprintf(stderr, "ERR - Failed to read password\n\n");
50 exit(-2);
53 reply = FascistCheck(password, dictionary);
54 if (reply != NULL) {
55 fprintf(stderr, "ERR - %s\n\n", reply);
56 exit(-3);
59 exit(0);