00001 #include <memory.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include <ctype.h>
00006 #include <crack.h>
00007
00008 void usage(char *command) {
00009 char *c, *comm;
00010
00011 comm = command;
00012 while ((c = strrchr(comm, '/')) != NULL) {
00013 comm = c + 1;
00014 }
00015
00016 fprintf(stderr, "Usage: %s [-c] [-s] [-d <dictionary>]\n\n", comm);
00017 fprintf(stderr, " -c enables NT like complexity checks\n");
00018 fprintf(stderr, " -d <dictionary file> for cracklib\n");
00019 fprintf(stderr, " -s simple check use NT like checks ONLY\n\n");
00020 fprintf(stderr, "The password is read via stdin.\n\n");
00021 exit(-1);
00022 }
00023
00024 int complexity(char* passwd)
00025 {
00026
00027
00028
00029
00030 int c_upper = 0;
00031 int c_lower = 0;
00032 int c_digit = 0;
00033 int c_punct = 0;
00034 int c_tot = 0;
00035 int i, len;
00036
00037 if (!passwd) goto fail;
00038 len = strlen(passwd);
00039
00040 for (i = 0; i < len; i++) {
00041
00042 if (c_tot >= 3) break;
00043
00044 if (isupper(passwd[i])) {
00045 if (!c_upper) {
00046 c_upper = 1;
00047 c_tot += 1;
00048 }
00049 continue;
00050 }
00051 if (islower(passwd[i])) {
00052 if (!c_lower) {
00053 c_lower = 1;
00054 c_tot += 1;
00055 }
00056 continue;
00057 }
00058 if (isdigit(passwd[i])) {
00059 if (!c_digit) {
00060 c_digit = 1;
00061 c_tot += 1;
00062 }
00063 continue;
00064 }
00065 if (ispunct(passwd[i])) {
00066 if (!c_punct) {
00067 c_punct = 1;
00068 c_tot += 1;
00069 }
00070 continue;
00071 }
00072 }
00073
00074 if ((c_tot) < 3) goto fail;
00075 return 0;
00076
00077 fail:
00078 fprintf(stderr, "ERR Complexity check failed\n\n");
00079 return -4;
00080 }
00081
00082 int main(int argc, char **argv) {
00083 extern char *optarg;
00084 int c, ret, complex_check = 0, simplex_check = 0;
00085
00086 char f[256];
00087 char *dictionary = NULL;
00088 char *password;
00089 char *reply;
00090
00091 while ( (c = getopt(argc, argv, "d:cs")) != EOF){
00092 switch(c) {
00093 case 'd':
00094 dictionary = strdup(optarg);
00095 break;
00096 case 'c':
00097 complex_check = 1;
00098 break;
00099 case 's':
00100 complex_check = 1;
00101 simplex_check = 1;
00102 break;
00103 default:
00104 usage(argv[0]);
00105 }
00106 }
00107
00108 if (!simplex_check && dictionary == NULL) {
00109 fprintf(stderr, "ERR - Missing cracklib dictionary\n\n");
00110 usage(argv[0]);
00111 }
00112
00113 fflush(stdin);
00114 password = fgets(f, sizeof(f), stdin);
00115
00116 if (password == NULL) {
00117 fprintf(stderr, "ERR - Failed to read password\n\n");
00118 exit(-2);
00119 }
00120
00121 if (complex_check) {
00122 ret = complexity(password);
00123 if (ret) {
00124 exit(ret);
00125 }
00126 }
00127
00128 if (simplex_check) {
00129 exit(0);
00130 }
00131
00132 reply = FascistCheck(password, dictionary);
00133 if (reply != NULL) {
00134 fprintf(stderr, "ERR - %s\n\n", reply);
00135 exit(-3);
00136 }
00137
00138 exit(0);
00139 }
00140