118 |
static int |
static int |
119 |
encrypt_ (char *clearpwstring, Crypt_Type crypttype, char **newpwentry) |
encrypt_ (char *clearpwstring, Crypt_Type crypttype, char **newpwentry) |
120 |
{ |
{ |
121 |
|
int result; |
122 |
|
#ifdef HAVE_LIBCRYPT |
123 |
unsigned long seed = random(); |
unsigned long seed = random(); |
124 |
char salt[12]; |
char salt[12]; |
125 |
char rawsalt[9]; |
char rawsalt[9]; |
127 |
"./0123456789ABCDEFGHIJKLMNOPQRST" |
"./0123456789ABCDEFGHIJKLMNOPQRST" |
128 |
"UVWXYZabcdefghijklmnopqrstuvwxyz"; |
"UVWXYZabcdefghijklmnopqrstuvwxyz"; |
129 |
const int SEEDCHARS_LEN = strlen (SEEDCHARS); |
const int SEEDCHARS_LEN = strlen (SEEDCHARS); |
|
int result; |
|
130 |
int i; |
int i; |
131 |
|
|
132 |
for (i = 0; i < 8; i++) |
for (i = 0; i < 8; i++) |
134 |
rawsalt[i] = SEEDCHARS[(seed/(i+1)) % SEEDCHARS_LEN]; |
rawsalt[i] = SEEDCHARS[(seed/(i+1)) % SEEDCHARS_LEN]; |
135 |
} |
} |
136 |
rawsalt[i] = '\0'; |
rawsalt[i] = '\0'; |
137 |
|
#endif |
138 |
|
|
139 |
switch (crypttype) |
switch (crypttype) |
140 |
{ |
{ |
141 |
case PLAIN: |
case PLAIN: |
162 |
exit (1); |
exit (1); |
163 |
} |
} |
164 |
|
|
165 |
|
if (result < 0) |
166 |
|
{ |
167 |
|
fprintf (stderr, "Memory allocation error\n"); |
168 |
|
exit (1); |
169 |
|
} |
170 |
|
|
171 |
/* Are we on a system that supports MD5? */ |
/* Are we on a system that supports MD5? */ |
172 |
return (crypttype == MD5 && strncmp ("$1$", *newpwentry, 3)) ? 1 : 0; |
return (crypttype == MD5 && strncmp ("$1$", *newpwentry, 3)) ? 1 : 0; |
173 |
} |
} |