Provide place handlers for handling MySQL 4.1.x scrambled passwords.
Showing
1 changed file
with
45 additions
and
0 deletions
... | @@ -249,6 +249,51 @@ scramble_password (unsigned long *result, const char *password) | ... | @@ -249,6 +249,51 @@ scramble_password (unsigned long *result, const char *password) |
249 | result[1] = nr2 & (((unsigned long) 1L << 31) -1L); | 249 | result[1] = nr2 & (((unsigned long) 1L << 31) -1L); |
250 | } | 250 | } |
251 | 251 | ||
252 | #if 0 | ||
253 | static void | ||
254 | octet2hex (char *to, const unsigned char *str, unsigned len) | ||
255 | { | ||
256 | const char *str_end= str + len; | ||
257 | static char d[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
258 | |||
259 | for ( ; str != str_end; ++str) | ||
260 | { | ||
261 | *to++ = d[(*str & 0xF0) >> 4]; | ||
262 | *to++ = d[*str & 0x0F]; | ||
263 | } | ||
264 | *to= '\0'; | ||
265 | } | ||
266 | |||
267 | #define SHA1_HASH_SIZE 20 | ||
268 | int | ||
269 | mu_check_mysql_4x_password (const char *scrambled, const char *message) | ||
270 | { | ||
271 | struct sha1_ctx sha1_context; | ||
272 | uint8 hash_stage2[SHA1_HASH_SIZE]; | ||
273 | char to[2*SHA1_HASH_SIZE + 2]; | ||
274 | |||
275 | if (!to) | ||
276 | return 1; | ||
277 | |||
278 | /* stage 1: hash password */ | ||
279 | sha1_init_ctx (&sha1_context); | ||
280 | sha1_process_bytes (message, strlen (message), &sha1_context); | ||
281 | sha1_finish_ctx (&sha1_context, to); | ||
282 | |||
283 | /* stage 2: hash stage1 output */ | ||
284 | sha1_init_ctx (&sha1_context); | ||
285 | sha1_process_bytes (to, SHA1_HASH_SIZE, &sha1_context); | ||
286 | sha1_finish_ctx (&sha1_context, hash_stage2); | ||
287 | |||
288 | /* convert hash_stage2 to hex string */ | ||
289 | *to++= '*'; | ||
290 | octet2hex (to, hash_stage2, SHA1_HASH_SIZE); | ||
291 | |||
292 | /* Compare both strings */ | ||
293 | return memcmp (to, scrambled, strlen (scrambled)); | ||
294 | } | ||
295 | #endif | ||
296 | |||
252 | /* Check whether a plaintext password MESSAGE matches MySQL scrambled password | 297 | /* Check whether a plaintext password MESSAGE matches MySQL scrambled password |
253 | PASSWORD */ | 298 | PASSWORD */ |
254 | int | 299 | int | ... | ... |
-
Please register or sign in to post a comment