APG v2.2.0

This commit is contained in:
Adel I. Mirzazhanov
2003-07-28 16:26:03 +07:00
committed by skinc
parent 900ff5ea18
commit df3f864b46
33 changed files with 1655 additions and 386 deletions

View File

@@ -1,5 +1,5 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
@@ -53,8 +53,14 @@ check_pass(char *pass, char *dict)
{
FILE *dct;
char *string;
string = (char *) calloc(1,MAX_DICT_STRING_SIZE);
char *tmp;
if( (string = (char *) calloc(1,MAX_DICT_STRING_SIZE)) == NULL)
return(-1);
#ifdef APG_DEBUG
fprintf (stdout, "DEBUG> check_pass: ck pass: %s\n", pass);
fflush (stdout);
#endif /* APG_DEBUG */
/*
** Open dict file an report of error
*/
@@ -63,12 +69,20 @@ check_pass(char *pass, char *dict)
while ((fgets(string, MAX_DICT_STRING_SIZE, dct) != NULL))
{
string = strtok (string," \t\n\0");
tmp = strtok (string," \t\n\0");
if( tmp != NULL)
string = tmp;
else
continue;
if(strlen(string) != strlen(pass)) continue;
else if (strncmp(string, pass, strlen(pass)) == 0)
{
free ( (void *)string);
fclose (dct);
#ifdef APG_DEBUG
fprintf (stdout, "DEBUG> check_pass: password found in dictionary: %s\n", pass);
fflush (stdout);
#endif /* APG_DEBUG */
return (1);
}
}
@@ -97,14 +111,79 @@ bloom_check_pass (char *word, char *filter)
int ret = 0;
FILE *f_filter;
h_val filter_size = 0L;
f_mode flt_mode = 0x00;
if ( (f_filter = open_filter(filter,"r")) == NULL)
return(-1);
filter_size = get_filtersize(f_filter);
ret = check_word (word, f_filter, filter_size);
flt_mode = get_filtermode(f_filter);
ret = check_word (word, f_filter, filter_size, flt_mode);
close_filter(f_filter);
return(ret);
}
/*
** paranoid_bloom_check_pass() - routine that checks if password or any
** substring of the password exist in dictionary using Bloom filter.
** INPUT:
** char * - password to check.
** char * - bloom-filter filename.
** USHORT - minimum substring length
** OUTPUT:
** int
** -1 - error
** 1 - password exist in dictionary
** 0 - password does not exist in dictionary
** NOTES:
** none.
*/
int
paranoid_bloom_check_pass (char * password, char *filter, USHORT s_len)
{
char * substring;
int len = strlen(password); /* string length */
int c_substr_start_pos = 0; /* current start position */
int substr_len = 0; /* substring length (LEN-I >= substr_len >= 2) */
int k = 0; /* counter */
int c = 0; /* counter */
int ret = 0;
if (s_len < 2) s_len = 2;
if (s_len > len) return (bloom_check_pass(password, filter));
#ifdef APG_DEBUG
fprintf (stdout, "DEBUG> paranoid_bloom_check_pass: ck pass: %s\n", password);
fflush (stdout);
#endif /* APG_DEBUG */
if ((substring = (char *)calloc(1, (size_t)len))==NULL)
return (-1);
for (c_substr_start_pos = 0; c_substr_start_pos <= len-s_len; c_substr_start_pos++)
for (substr_len = s_len; substr_len <= len-c_substr_start_pos; substr_len++)
{
c = 0;
for (k = c_substr_start_pos; k <= c_substr_start_pos + substr_len-1; k++)
{
substring[c]=password[k];
c++;
}
#ifdef APG_DEBUG
fprintf (stdout, "DEBUG> paranoid_bloom_check_pass: ck substr: %s\n", substring);
fflush (stdout);
#endif /* APG_DEBUG */
if((ret = bloom_check_pass(substring, filter)) == 1)
{
#ifdef APG_DEBUG
fprintf (stdout, "DEBUG> paranoid_bloom_check_pass: substr found in filter: %s\n", substring);
fflush (stdout);
#endif /* APG_DEBUG */
return(1);
}
else if (ret == -1) return(-1);
(void)memset(substring,0,(size_t)len);
}
return(0);
}
/*
** filter_check_pass() - routine that checks password against filter string
**
@@ -128,6 +207,12 @@ filter_check_pass(const char * word, unsigned int cond)
int cl_ret = 0;
int nb_ret = 0;
int ss_ret = 0;
#ifdef APG_DEBUG
fprintf (stdout, "DEBUG> filter_check_pass: ck pass: %s\n", word);
fflush (stdout);
#endif /* APG_DEBUG */
if ((cond & S_SS) > 0)
for (i=0; i < 94; i++)
if ((smbl[i].type & S_SS) > 0)
@@ -156,6 +241,10 @@ filter_check_pass(const char * word, unsigned int cond)
if (((cond & S_CL) > 0) &&(cl_ret != 1)) return (1);
if (((cond & S_NB) > 0) &&(nb_ret != 1)) return (1);
#ifdef APG_DEBUG
fprintf (stdout, "DEBUG> filter_check_pass: password %s pass the filter\n", word);
fflush (stdout);
#endif /* APG_DEBUG */
return(0);
}