jani Mon Nov 5 12:39:44 2007 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/standard crypt.c
Log:
MFH
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/crypt.c?r1=1.62.2.1.2.6&r2=1.62.2.1.2.6.2.1&diff_format=u
Index: php-src/ext/standard/crypt.c
diff -u php-src/ext/standard/crypt.c:1.62.2.1.2.6
php-src/ext/standard/crypt.c:1.62.2.1.2.6.2.1
--- php-src/ext/standard/crypt.c:1.62.2.1.2.6 Mon Jan 1 09:36:08 2007
+++ php-src/ext/standard/crypt.c Mon Nov 5 12:39:44 2007
@@ -16,8 +16,10 @@
| Zeev Suraski <[EMAIL PROTECTED]> |
| Rasmus Lerdorf <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
- */
-/* $Id: crypt.c,v 1.62.2.1.2.6 2007/01/01 09:36:08 sebastian Exp $ */
+*/
+
+/* $Id: crypt.c,v 1.62.2.1.2.6.2.1 2007/11/05 12:39:44 jani Exp $ */
+
#include <stdlib.h>
#include "php.h"
@@ -53,12 +55,11 @@
#include "php_crypt.h"
#include "php_rand.h"
-/*
- The capabilities of the crypt() function is determined by the test programs
- run by configure from aclocal.m4. They will set PHP_STD_DES_CRYPT,
- PHP_EXT_DES_CRYPT, PHP_MD5_CRYPT and PHP_BLOWFISH_CRYPT as appropriate
- for the target platform
-*/
+/* The capabilities of the crypt() function is determined by the test programs
+ * run by configure from aclocal.m4. They will set PHP_STD_DES_CRYPT,
+ * PHP_EXT_DES_CRYPT, PHP_MD5_CRYPT and PHP_BLOWFISH_CRYPT as appropriate
+ * for the target platform. */
+
#if PHP_STD_DES_CRYPT
#define PHP_MAX_SALT_LEN 2
#endif
@@ -78,10 +79,8 @@
#define PHP_MAX_SALT_LEN 60
#endif
- /*
- * If the configure-time checks fail, we provide DES.
- * XXX: This is a hack. Fix the real problem
- */
+/* If the configure-time checks fail, we provide DES.
+ * XXX: This is a hack. Fix the real problem! */
#ifndef PHP_MAX_SALT_LEN
#define PHP_MAX_SALT_LEN 2
@@ -89,10 +88,9 @@
#define PHP_STD_DES_CRYPT 1
#endif
-
#define PHP_CRYPT_RAND php_rand(TSRMLS_C)
-PHP_MINIT_FUNCTION(crypt)
+PHP_MINIT_FUNCTION(crypt) /* {{{ */
{
REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", PHP_MAX_SALT_LEN, CONST_CS
| CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CRYPT_STD_DES", PHP_STD_DES_CRYPT, CONST_CS |
CONST_PERSISTENT);
@@ -102,33 +100,34 @@
return SUCCESS;
}
-
+/* }}} */
static unsigned char itoa64[] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-static void php_to64(char *s, long v, int n)
+static void php_to64(char *s, long v, int n) /* {{{ */
{
while (--n >= 0) {
- *s++ = itoa64[v&0x3f];
+ *s++ = itoa64[v&0x3f];
v >>= 6;
- }
-}
+ }
+}
+/* }}} */
/* {{{ proto string crypt(string str [, string salt])
- Encrypt a string */
+ Hash a string */
PHP_FUNCTION(crypt)
{
- char salt[PHP_MAX_SALT_LEN+1];
+ char salt[PHP_MAX_SALT_LEN + 1];
char *str, *salt_in = NULL;
int str_len, salt_in_len;
- salt[0]=salt[PHP_MAX_SALT_LEN]='\0';
+ salt[0] = salt[PHP_MAX_SALT_LEN] = '\0';
+
/* This will produce suitable results if people depend on DES-encryption
- available (passing always 2-character salt). At least for glibc6.1 */
- memset(&salt[1], '$', PHP_MAX_SALT_LEN-1);
+ * available (passing always 2-character salt). At least for glibc6.1 */
+ memset(&salt[1], '$', PHP_MAX_SALT_LEN - 1);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str,
&str_len,
- &salt_in,
&salt_in_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str,
&str_len, &salt_in, &salt_in_len) == FAILURE) {
return;
}
@@ -137,7 +136,7 @@
}
/* The automatic salt generation only covers standard DES and md5-crypt
*/
- if(!*salt) {
+ if (!*salt) {
#if PHP_MD5_CRYPT
strcpy(salt, "$1$");
php_to64(&salt[3], PHP_CRYPT_RAND, 4);
@@ -155,7 +154,7 @@
memset(&buffer, 0, sizeof(buffer));
#elif defined(CRYPT_R_CRYPTD)
CRYPTD buffer;
-#else
+#else
#error Data struct used by crypt_r() is unknown. Please report.
#endif
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php