pollita Fri Jan 5 03:57:57 2007 UTC
Modified files:
/php-src NEWS
/php-src/ext/session php_session.h session.c CREDITS
Log:
Allow ext/session to use ext/hash's algorithms for generating IDs
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2134&r2=1.2135&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2134 php-src/NEWS:1.2135
--- php-src/NEWS:1.2134 Sat Dec 16 19:15:25 2006
+++ php-src/NEWS Fri Jan 5 03:57:56 2007
@@ -54,6 +54,7 @@
. stream_resolve_include_path(). (Sara)
- Added shm_has_var() function. (Mike)
- Added str_getcsv() function. (Sara)
+- Added ext/hash support to ext/session's ID generator. (Sara)
- Fixed bug #39504 (xmlwriter_write_dtd_entity() creates Attlist tag,
not enity). (Hannes Magnusson)
http://cvs.php.net/viewvc.cgi/php-src/ext/session/php_session.h?r1=1.112&r2=1.113&diff_format=u
Index: php-src/ext/session/php_session.h
diff -u php-src/ext/session/php_session.h:1.112
php-src/ext/session/php_session.h:1.113
--- php-src/ext/session/php_session.h:1.112 Fri Jan 5 02:07:59 2007
+++ php-src/ext/session/php_session.h Fri Jan 5 03:57:57 2007
@@ -16,13 +16,17 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_session.h,v 1.112 2007/01/05 02:07:59 pollita Exp $ */
+/* $Id: php_session.h,v 1.113 2007/01/05 03:57:57 pollita Exp $ */
#ifndef PHP_SESSION_H
#define PHP_SESSION_H
#include "ext/standard/php_var.h"
+#ifdef HAVE_HASH_EXT
+# include "ext/hash/php_hash.h"
+#endif
+
#define PHP_SESSION_API 20020330
#define PS_OPEN_ARGS void **mod_data, const char *save_path, const char
*session_name TSRMLS_DC
@@ -121,6 +125,9 @@
zend_bool apply_trans_sid; /* whether or not to enable trans-sid
for the current request */
long hash_func;
+#ifdef HAVE_HASH_EXT
+ php_hash_ops *hash_ops;
+#endif
long hash_bits_per_character;
int send_cookie;
int define_sid;
http://cvs.php.net/viewvc.cgi/php-src/ext/session/session.c?r1=1.463&r2=1.464&diff_format=u
Index: php-src/ext/session/session.c
diff -u php-src/ext/session/session.c:1.463 php-src/ext/session/session.c:1.464
--- php-src/ext/session/session.c:1.463 Fri Jan 5 02:07:59 2007
+++ php-src/ext/session/session.c Fri Jan 5 03:57:57 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: session.c,v 1.463 2007/01/05 02:07:59 pollita Exp $ */
+/* $Id: session.c,v 1.464 2007/01/05 03:57:57 pollita Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -218,7 +218,8 @@
enum {
PS_HASH_FUNC_MD5,
- PS_HASH_FUNC_SHA1
+ PS_HASH_FUNC_SHA1,
+ PS_HASH_FUNC_OTHER
};
/* returns a pointer to the byte after the last valid character in out */
@@ -259,11 +260,15 @@
return out;
}
+#define PS_ID_INITIAL_SIZE 100
PHPAPI char *php_session_create_id(PS_CREATE_SID_ARGS)
{
PHP_MD5_CTX md5_context;
PHP_SHA1_CTX sha1_context;
- unsigned char digest[21];
+#ifdef HAVE_HASH_EXT
+ void *hash_context;
+#endif
+ unsigned char *digest;
int digest_len;
int j;
char *buf;
@@ -282,7 +287,7 @@
remote_addr = Z_STRVAL_PP(token);
}
- buf = emalloc(100);
+ buf = emalloc(PS_ID_INITIAL_SIZE);
/* maximum 15+19+19+10 bytes */
sprintf(buf, "%.15s%ld%ld%0.8F", remote_addr ? remote_addr : "",
@@ -299,6 +304,20 @@
PHP_SHA1Update(&sha1_context, (unsigned char *) buf,
strlen(buf));
digest_len = 20;
break;
+#ifdef HAVE_HASH_EXT
+ case PS_HASH_FUNC_OTHER:
+ if (!PS(hash_ops)) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR,
"Invalid session hash function");
+ efree(buf);
+ return NULL;
+ }
+
+ hash_context = emalloc(PS(hash_ops)->context_size);
+ PS(hash_ops)->hash_init(hash_context);
+ PS(hash_ops)->hash_update(hash_context, (unsigned char
*) buf, strlen(buf));
+ digest_len = PS(hash_ops)->digest_size;
+ break;
+#endif /* HAVE_HASH_EXT */
default:
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid
session hash function");
efree(buf);
@@ -325,6 +344,11 @@
case PS_HASH_FUNC_SHA1:
PHP_SHA1Update(&sha1_context,
rbuf, n);
break;
+#ifdef HAVE_HASH_EXT
+ case PS_HASH_FUNC_OTHER:
+
PS(hash_ops)->hash_update(hash_context, rbuf, n);
+ break;
+#endif /* HAVE_HASH_EXT */
}
to_read -= n;
}
@@ -332,6 +356,7 @@
}
}
+ digest = emalloc(digest_len + 1);
switch (PS(hash_func)) {
case PS_HASH_FUNC_MD5:
PHP_MD5Final(digest, &md5_context);
@@ -339,6 +364,12 @@
case PS_HASH_FUNC_SHA1:
PHP_SHA1Final(digest, &sha1_context);
break;
+#ifdef HAVE_HASH_EXT
+ case PS_HASH_FUNC_OTHER:
+ PS(hash_ops)->hash_final(digest, hash_context);
+ efree(hash_context);
+ break;
+#endif /* HAVE_HASH_EXT */
}
if (PS(hash_bits_per_character) < 4
@@ -347,7 +378,14 @@
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The ini setting
hash_bits_per_character is out of range (should be 4, 5, or 6) - using 4 for
now");
}
+
+ if (PS_ID_INITIAL_SIZE < ((digest_len + 2) * (8 /
PS(hash_bits_per_character))) ) {
+ /* 100 bytes is enough for most, but not all hash algos */
+ buf = erealloc(buf, (digest_len + 2) * (8 /
PS(hash_bits_per_character)) );
+ }
+
j = (int) (bin_to_readable((char *)digest, digest_len, buf,
PS(hash_bits_per_character)) - buf);
+ efree(digest);
if (newlen) {
*newlen = j;
@@ -526,6 +564,53 @@
return SUCCESS;
}
+static PHP_INI_MH(OnUpdateHashFunc)
+{
+ long val;
+ char *endptr = NULL;
+
+#ifdef HAVE_HASH_EXT
+ PS(hash_ops) = NULL;
+#endif
+
+ val = strtol(new_value, &endptr, 10);
+ if (endptr && (*endptr == '\0')) {
+ /* Numeric value */
+ PS(hash_func) = val ? 1 : 0;
+
+ return SUCCESS;
+ }
+
+ if (new_value_length == (sizeof("md5") - 1) &&
+ strncasecmp(new_value, "md5", sizeof("md5") - 1) == 0) {
+ PS(hash_func) = PS_HASH_FUNC_MD5;
+
+ return SUCCESS;
+ }
+
+ if (new_value_length == (sizeof("sha1") - 1) &&
+ strncasecmp(new_value, "sha1", sizeof("sha1") - 1) == 0) {
+ PS(hash_func) = PS_HASH_FUNC_SHA1;
+
+ return SUCCESS;
+ }
+
+#ifdef HAVE_HASH_EXT
+{
+ php_hash_ops *ops = php_hash_fetch_ops(new_value, new_value_length);
+
+ if (ops) {
+ PS(hash_func) = PS_HASH_FUNC_OTHER;
+ PS(hash_ops) = ops;
+
+ return SUCCESS;
+ }
+}
+#endif /* HAVE_HASH_EXT */
+
+ return FAILURE;
+}
+
/* {{{ PHP_INI
*/
PHP_INI_BEGIN()
@@ -550,7 +635,7 @@
STD_PHP_INI_ENTRY("session.cache_limiter", "nocache",
PHP_INI_ALL, OnUpdateString, cache_limiter, php_ps_globals, ps_globals)
STD_PHP_INI_ENTRY("session.cache_expire", "180",
PHP_INI_ALL, OnUpdateLong, cache_expire, php_ps_globals, ps_globals)
PHP_INI_ENTRY("session.use_trans_sid", "0",
PHP_INI_ALL, OnUpdateTransSid)
- STD_PHP_INI_ENTRY("session.hash_function", "0",
PHP_INI_ALL, OnUpdateLong, hash_func, php_ps_globals, ps_globals)
+ PHP_INI_ENTRY("session.hash_function", "0",
PHP_INI_ALL, OnUpdateHashFunc)
STD_PHP_INI_ENTRY("session.hash_bits_per_character", "4",
PHP_INI_ALL, OnUpdateLong, hash_bits_per_character, php_ps_globals,
ps_globals)
/* Commented out until future discussion */
http://cvs.php.net/viewvc.cgi/php-src/ext/session/CREDITS?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/session/CREDITS
diff -u php-src/ext/session/CREDITS:1.1 php-src/ext/session/CREDITS:1.2
--- php-src/ext/session/CREDITS:1.1 Mon Nov 20 10:31:35 2000
+++ php-src/ext/session/CREDITS Fri Jan 5 03:57:57 2007
@@ -1,2 +1,2 @@
Sessions
-Sascha Schumann, Andrei Zmievski
+Sascha Schumann, Andrei Zmievski, Sara Golemon
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php