Bug #744: php don't work propertly with FreeBSD MD5 crypt()
| From: | vova at plugcom dot ru | Date: | Mon, 14 Sep 1998 06:59:15 +0000 |
| Subject: | Bug #744: php don't work propertly with FreeBSD MD5 crypt() | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1046@lists.php.net to get a copy of this message | ||
From: vova@plugcom.ru
Operating system: FreeBSD
PHP version: 3.0.3
PHP Bug Type: Misbehaving function
Bug description:
In FreeBSD with MD5 crypt(), 10-charcter SALT is used,
and crypted string consist of:
$1$SALT$CRYPTCHARS, for example:
$1$hGZ9u$8bRWSxRh3Kv/hyb9mRmoF1
standart php function crypt() cuts first two characters, so crypt() don't work (first 3
characters allways "$1$")
there is patch for functions/crypt.c it works corectly with FreeBSD MD5 and DES crypt()
*** ../php-3.0.3/functions/crypt.c.orig Fri May 15 12:57:19 1998
--- ../php-3.0.3/functions/crypt.c Sun Sep 13 09:27:06 1998
***************
*** 66,74 ****
--- 66,96 ----
"Crypt", crypt_functions, NULL, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES
};
+ #ifdef __FreeBSD__
+ static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
+ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+ void
+ to64(s, v, n)
+ char *s;
+ long v;
+ int n;
+ {
+ while (--n >= 0) {
+ *s++ = itoa64[v&0x3f];
+ v >>= 6;
+ }
+ }
+ #endif
+
void php3_crypt(INTERNAL_FUNCTION_PARAMETERS)
{
+ #ifdef __FreeBSD__
+ char salt[10];
+ struct timeval tv;
+ #else
char salt[4];
+ #endif
int arg_count = ARG_COUNT(ht);
pval *arg1, *arg2;
static char seedchars[] =
***************
*** 83,96 ****
--- 105,141 ----
salt[0] = '\0';
if (arg_count == 2) {
convert_to_string(arg2);
+ #ifdef __FreeBSD__
+ strncpy(salt, arg2->value.str.val, 9);
+ #else
strncpy(salt, arg2->value.str.val, 2);
+ #endif
}
if (!salt[0]) {
+ #ifdef __FreeBSD__
+ gettimeofday(&tv,0);
+ if (!strncmp(crypt("test", "xx"), "$1$", 3)) {
+ /* MD5 salt */
+ strncpy(&salt[0], "$1$", 3);
+ (void)srandom((int)time((time_t *)NULL));
+ to64(&salt[3], random(), 3);
+ to64(&salt[6], tv.tv_usec, 3);
+ salt[9] = '\0';
+ } else {
+ /* DES salt */
+ srandom(getpid() * tv.tv_usec);
+ to64(&salt[0], random(), 2);
+ salt[2] = '\0';
+ }
+ #else
srand(time(0) * getpid());
salt[0] = seedchars[rand() % 64];
salt[1] = seedchars[rand() % 64];
+ #endif
}
+ #ifndef __FreeBSD__
salt[2] = '\0';
+ #endif
return_value->value.str.val = (char *) crypt(arg1->value.str.val, salt);
return_value->value.str.len = strlen(return_value->value.str.val); /* can be optimized away
to 13? */
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net