CVS update: php3/functions
| From: | rasmus | Date: | Tue, 22 Sep 1998 05:40:41 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1353@lists.php.net to get a copy of this message | ||
Date: Tuesday September 22, 1998 @ 1:40
Author: rasmus
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv7944/functions
Modified Files:
crypt.c
Log Message:
The crypt() stuff should be done now. Needs some testing especially from
someone with a BSD system that only uses md5-crypt.
Index: php3/functions/crypt.c
diff -c php3/functions/crypt.c:1.37 php3/functions/crypt.c:1.38
*** php3/functions/crypt.c:1.37 Mon Sep 21 23:02:36 1998
--- php3/functions/crypt.c Tue Sep 22 01:40:40 1998
***************
*** 28,34 ****
| Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: crypt.c,v 1.37 1998/09/22 03:02:36 rasmus Exp $ */
#include "php.h"
#include "internal_functions.h"
--- 28,34 ----
| Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
! /* $Id: crypt.c,v 1.38 1998/09/22 05:40:40 rasmus Exp $ */
#include "php.h"
#include "internal_functions.h"
***************
*** 72,98 ****
/*
The capabilities of the crypt() function is determined by the test programs
run by configure from aclocal.m4. They will set PHP3_STD_DES_CRYPT,
! PHP3_EXT_DES-CRYPT, PHP3_MD5_CRYPT and PHP3_BLOWFISH_CRYPT as appropriate
for the target platform
*/
static unsigned char itoa64[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
! void php3i_to64(char *s, long v, int n) {
while (--n >= 0) {
*s++ = itoa64[v&0x3f];
! v >>= 6;+
}
}
void php3_crypt(INTERNAL_FUNCTION_PARAMETERS)
{
! char salt[3] = { '\0', '\0', '\0' };
pval *arg1, *arg2;
- static char seedchars[] =
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
switch (ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &arg1)==FAILURE) {
--- 72,113 ----
/*
The capabilities of the crypt() function is determined by the test programs
run by configure from aclocal.m4. They will set PHP3_STD_DES_CRYPT,
! PHP3_EXT_DES_CRYPT, PHP3_MD5_CRYPT and PHP3_BLOWFISH_CRYPT as appropriate
for the target platform
*/
+ #ifdef PHP3_STD_DES_CRYPT
+ #define PHP3_MAX_SALT_LEN 2
+ #endif
+ #ifdef PHP3_EXT_DES_CRYPT
+ #undef PHP3_MAX_SALT_LEN
+ #define PHP3_MAX_SALT_LEN 9
+ #endif
+ #ifdef PHP3_MD5_CRYPT
+ #undef PHP3_MAX_SALT_LEN
+ #define PHP3_MAX_SALT_LEN 12
+ #endif
+ #ifdef PHP3_BLOWFISH_CRYPT
+ #undef PHP3_MAX_SALT_LEN
+ #define PHP3_MAX_SALT_LEN 17
+ #endif
static unsigned char itoa64[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
! static void php3i_to64(char *s, long v, int n) {
while (--n >= 0) {
*s++ = itoa64[v&0x3f];
! v >>= 6;
}
}
void php3_crypt(INTERNAL_FUNCTION_PARAMETERS)
{
! char salt[PHP3_MAX_SALT_LEN];
pval *arg1, *arg2;
+ salt[0]='\0';
+
switch (ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &arg1)==FAILURE) {
***************
*** 104,110 ****
RETURN_FALSE;
}
convert_to_string(arg2);
! memcpy(salt, arg2->value.str.val, MIN(2,arg2->value.str.len));
break;
default:
WRONG_PARAM_COUNT;
--- 119,125 ----
RETURN_FALSE;
}
convert_to_string(arg2);
! memcpy(salt, arg2->value.str.val, MIN(PHP3_MAX_SALT_LEN,arg2->value.str.len));
break;
default:
WRONG_PARAM_COUNT;
***************
*** 112,133 ****
}
convert_to_string(arg1);
! #if 0
! /* work in progress */
! to64(&salt[0], arc4random(), 2);
! salt[2] = '\0';
#endif
!
! srand(time(0) * getpid());
!
! if (!salt[0]) {
! salt[0] = seedchars[rand() % 64];
! }
!
! if (!salt[1]) {
! salt[1] = seedchars[rand() % 64];
}
- salt[2] = '\0';
return_value->value.str.val = (char *) crypt(arg1->value.str.val, salt);
return_value->value.str.len = strlen(return_value->value.str.val);
--- 127,148 ----
}
convert_to_string(arg1);
! /* The automatic salt generation only covers standard DES and md5-crypt */
! if(!*salt) {
! srand(time(0) * getpid());
!
! #ifdef PHP3_STD_DES_CRYPT
! php3i_to64(&salt[0], random(), 2);
! salt[2] = '\0';
! #else
! #if PHP3_MD5_CRYPT
! strcpy(salt, "$1$");
! to64(&salt[3], random(), 4);
! to64(&salt[7], random(), 4);
! strcpy(&salt[11], "$");
#endif
! #endif
}
return_value->value.str.val = (char *) crypt(arg1->value.str.val, salt);
return_value->value.str.len = strlen(return_value->value.str.val);
--
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