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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
/*
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1.Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** 2.Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3.The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
** OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
** GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
** restrict.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "restrict.h"
extern struct sym smbl[94];
/*
** check_pass() - routine that checks if password exist in dictionary
** INPUT:
** char * - password to check.
** char * - dictionary filename.
** OUTPUT:
** int
** -1 - error
** 1 - password exist in dictionary
** 0 - password does not exist in dictionary
** NOTES:
** none.
*/
int
check_pass(char *pass, char *dict)
{
FILE *dct;
char *string;
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
*/
if ( (dct = fopen(dict,"r")) == NULL)
return(-1);
while ((fgets(string, MAX_DICT_STRING_SIZE, dct) != NULL))
{
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);
}
}
free ( (void *)string);
fclose (dct);
return (0);
}
/*
** bloom_check_pass() - routine that checks if password exist in dictionary
** using Bloom filter.
** INPUT:
** char * - password to check.
** char * - bloom-filter filename.
** OUTPUT:
** int
** -1 - error
** 1 - password exist in dictionary
** 0 - password does not exist in dictionary
** NOTES:
** none.
*/
int
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);
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
**
** INPUT:
** char * - password to check.
** char * - bloom-filter filename.
** OUTPUT:
** int
** -1 - error
** 1 - password do not pass the filter
** 0 - password pass the filter
** NOTES:
** none.
*/
int
filter_check_pass(const char * word, unsigned int cond)
{
int i = 0;
int sl_ret = 0;
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)
if ((strchr(word,smbl[i].ch)) != NULL)
ss_ret = 1;
i = 0;
if ((cond & S_SL) > 0)
for (i=0; i < 94; i++)
if ((smbl[i].type & S_SL) > 0)
if ((strchr(word,smbl[i].ch)) != NULL)
sl_ret = 1;
i = 0;
if ((cond & S_CL) > 0)
for (i=0; i < 94; i++)
if ((smbl[i].type & S_CL) > 0)
if ((strchr(word,smbl[i].ch)) != NULL)
cl_ret = 1;
i = 0;
if ((cond & S_NB) > 0)
for (i=0; i < 94; i++)
if ((smbl[i].type & S_NB) > 0)
if ((strchr(word,smbl[i].ch)) != NULL)
nb_ret = 1;
if (((cond & S_SS) > 0) &&(ss_ret != 1)) return (1);
if (((cond & S_SL) > 0) &&(sl_ret != 1)) return (1);
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);
}
/*
** set_exclude_list() - set up character list that should
** be excluded from password generation process
**
** INPUT:
** char * - string of characters.
** OUTPUT:
** int - return code
** 0 - OK
** -1 - char_string is too long (max 93)
** NOTES:
** none.
*/
int set_exclude_list(const char * char_string)
{
int i = 0;
if (strlen(char_string) > 93)
return(-1);
for(i=0; i < 94; i++)
if ((strchr(char_string, smbl[i].ch)) != NULL)
smbl[i].type = smbl[i].type | S_RS;
return(0);
}
|