summaryrefslogtreecommitdiff
path: root/examples/auth/crackcheck/crackcheck.c
blob: 338433779b0d6b0bbe99d881e1734cc215aa54c2 (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
#include <memory.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <crack.h>

void usage(char *command) {
	char *c, *comm;

	comm = command;
	while ((c = strrchr(comm, '/')) != NULL) {
		comm = c + 1;
	}

	fprintf(stderr, "Usage: %s -d dictionary\n\n", comm);
	fprintf(stderr, "     -d dictionary file for cracklib\n\n");
	fprintf(stderr, "	The password is expected to be given via stdin.\n\n");
	exit(-1);
}

int main(int argc, char **argv) {
	extern char *optarg;
	int c;

	char f[256];
	char *dictionary = NULL;
	char *password;
	char *reply;

	while ( (c = getopt(argc, argv, "d:")) != EOF){
		switch(c) {
		case 'd':
			dictionary = strdup(optarg);
			break;
		default:
			usage(argv[0]);
		}
	}

	if (dictionary == NULL) {
		fprintf(stderr, "ERR - Wrong Command Line\n\n");
		usage(argv[0]);
	} 

	password = fgets(f, sizeof(f), stdin);

	if (password == NULL) {
		fprintf(stderr, "ERR - Failed to read password\n\n");
		exit(-2);
	}

	reply = FascistCheck(password, dictionary);
	if (reply != NULL) {
		fprintf(stderr, "ERR - %s\n\n", reply);
		exit(-3);
	}

	exit(0);

}