2015-01-03 17:22:58 +08:00
|
|
|
/*
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2014-09-20 00:33:14 +08:00
|
|
|
| PHP Version 7 |
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2016-01-02 01:19:27 +08:00
|
|
|
| Copyright (c) 1997-2016 The PHP Group |
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
1999-09-17 13:40:59 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
1999-09-17 13:40:59 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 16:29:35 +08:00
|
|
|
| Author: Sascha Schumann <sascha@schumann.cx> |
|
1999-09-17 13:40:59 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2001-06-06 22:32:27 +08:00
|
|
|
/* $Id$ */
|
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
#include "php.h"
|
|
|
|
#include "php_session.h"
|
|
|
|
#include "mod_user.h"
|
|
|
|
|
|
|
|
ps_module ps_mod_user = {
|
2015-01-21 18:13:59 +08:00
|
|
|
PS_MOD_UPDATE_TIMESTAMP(user)
|
1999-09-17 13:40:59 +08:00
|
|
|
};
|
|
|
|
|
2014-03-28 18:46:25 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval)
|
1999-09-17 13:40:59 +08:00
|
|
|
{
|
|
|
|
int i;
|
2014-12-14 06:06:14 +08:00
|
|
|
if (call_user_function(EG(function_table), NULL, func, retval, argc, argv) == FAILURE) {
|
2014-03-29 20:17:59 +08:00
|
|
|
zval_ptr_dtor(retval);
|
|
|
|
ZVAL_UNDEF(retval);
|
2014-05-03 16:06:27 +08:00
|
|
|
} else if (Z_ISUNDEF_P(retval)) {
|
2014-03-29 20:17:59 +08:00
|
|
|
ZVAL_NULL(retval);
|
|
|
|
}
|
2000-02-11 21:41:30 +08:00
|
|
|
for (i = 0; i < argc; i++) {
|
2001-01-07 18:32:06 +08:00
|
|
|
zval_ptr_dtor(&argv[i]);
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-14 06:28:15 +08:00
|
|
|
#define STDVARS \
|
2014-03-28 18:46:25 +08:00
|
|
|
zval retval; \
|
2008-03-08 07:20:32 +08:00
|
|
|
int ret = FAILURE
|
|
|
|
|
|
|
|
#define PSF(a) PS(mod_user_names).name.ps_##a
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2014-05-16 05:00:15 +08:00
|
|
|
#define FINISH \
|
2014-07-07 23:21:23 +08:00
|
|
|
if (Z_TYPE(retval) != IS_UNDEF) { \
|
|
|
|
if (Z_TYPE(retval) == IS_TRUE) { \
|
|
|
|
ret = SUCCESS; \
|
|
|
|
} else if (Z_TYPE(retval) == IS_FALSE) { \
|
|
|
|
ret = FAILURE; \
|
2014-08-26 01:24:55 +08:00
|
|
|
} else if ((Z_TYPE(retval) == IS_LONG) && (Z_LVAL(retval) == -1)) { \
|
2014-05-16 05:00:15 +08:00
|
|
|
/* BC for clever users - Deprecate me */ \
|
|
|
|
ret = FAILURE; \
|
2014-08-26 01:24:55 +08:00
|
|
|
} else if ((Z_TYPE(retval) == IS_LONG) && (Z_LVAL(retval) == 0)) { \
|
2014-05-16 05:00:15 +08:00
|
|
|
/* BC for clever users - Deprecate me */ \
|
|
|
|
ret = SUCCESS; \
|
|
|
|
} else { \
|
2014-07-08 03:19:11 +08:00
|
|
|
if (!EG(exception)) { \
|
2014-12-14 06:06:14 +08:00
|
|
|
php_error_docref(NULL, E_WARNING, \
|
2014-07-08 03:19:11 +08:00
|
|
|
"Session callback expects true/false return value"); \
|
|
|
|
} \
|
2014-05-16 05:00:15 +08:00
|
|
|
ret = FAILURE; \
|
2014-07-07 23:21:23 +08:00
|
|
|
zval_ptr_dtor(&retval); \
|
2014-05-16 05:00:15 +08:00
|
|
|
} \
|
|
|
|
} \
|
1999-09-17 13:40:59 +08:00
|
|
|
return ret
|
|
|
|
|
|
|
|
PS_OPEN_FUNC(user)
|
|
|
|
{
|
2014-03-28 18:46:25 +08:00
|
|
|
zval args[2];
|
2011-09-14 06:28:15 +08:00
|
|
|
STDVARS;
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (Z_ISUNDEF(PSF(open))) {
|
2014-12-14 06:06:14 +08:00
|
|
|
php_error_docref(NULL, E_WARNING,
|
2012-01-29 05:02:09 +08:00
|
|
|
"user session functions not defined");
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2012-01-29 05:02:09 +08:00
|
|
|
return FAILURE;
|
|
|
|
}
|
2009-05-19 00:10:09 +08:00
|
|
|
|
2015-01-29 18:48:50 +08:00
|
|
|
ZVAL_STRING(&args[0], (char*)save_path);
|
|
|
|
ZVAL_STRING(&args[1], (char*)session_name);
|
2009-05-19 00:10:09 +08:00
|
|
|
|
2016-01-15 12:47:45 +08:00
|
|
|
zend_try {
|
2016-01-15 15:24:22 +08:00
|
|
|
ps_call_handler(&PSF(open), 2, args, &retval);
|
2016-01-15 12:47:45 +08:00
|
|
|
} zend_catch {
|
|
|
|
PS(session_status) = php_session_none;
|
2016-01-15 15:24:22 +08:00
|
|
|
if (!Z_ISUNDEF(retval)) {
|
2016-01-15 12:47:45 +08:00
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
}
|
|
|
|
zend_bailout();
|
|
|
|
} zend_end_try();
|
|
|
|
|
2011-09-14 06:28:15 +08:00
|
|
|
PS(mod_user_implemented) = 1;
|
2009-05-19 00:10:09 +08:00
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_CLOSE_FUNC(user)
|
|
|
|
{
|
2012-08-15 00:15:34 +08:00
|
|
|
zend_bool bailout = 0;
|
2011-09-14 06:28:15 +08:00
|
|
|
STDVARS;
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2011-09-14 06:28:15 +08:00
|
|
|
if (!PS(mod_user_implemented)) {
|
|
|
|
/* already closed */
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2012-08-15 00:15:34 +08:00
|
|
|
zend_try {
|
2014-12-14 06:06:14 +08:00
|
|
|
ps_call_handler(&PSF(close), 0, NULL, &retval);
|
2012-08-15 00:15:34 +08:00
|
|
|
} zend_catch {
|
|
|
|
bailout = 1;
|
|
|
|
} zend_end_try();
|
|
|
|
|
2012-08-15 01:25:31 +08:00
|
|
|
PS(mod_user_implemented) = 0;
|
|
|
|
|
2012-08-15 00:15:34 +08:00
|
|
|
if (bailout) {
|
2014-05-03 16:06:27 +08:00
|
|
|
if (!Z_ISUNDEF(retval)) {
|
2012-08-15 00:15:34 +08:00
|
|
|
zval_ptr_dtor(&retval);
|
|
|
|
}
|
|
|
|
zend_bailout();
|
|
|
|
}
|
|
|
|
|
1999-09-17 13:40:59 +08:00
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_READ_FUNC(user)
|
|
|
|
{
|
2014-03-28 18:46:25 +08:00
|
|
|
zval args[1];
|
1999-09-17 13:40:59 +08:00
|
|
|
STDVARS;
|
|
|
|
|
2015-01-29 18:48:50 +08:00
|
|
|
ZVAL_STR_COPY(&args[0], key);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ps_call_handler(&PSF(read), 1, args, &retval);
|
2009-05-19 00:10:09 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (!Z_ISUNDEF(retval)) {
|
2014-03-28 18:46:25 +08:00
|
|
|
if (Z_TYPE(retval) == IS_STRING) {
|
2014-08-26 01:24:55 +08:00
|
|
|
*val = zend_string_copy(Z_STR(retval));
|
1999-09-17 13:40:59 +08:00
|
|
|
ret = SUCCESS;
|
|
|
|
}
|
2001-01-07 18:32:06 +08:00
|
|
|
zval_ptr_dtor(&retval);
|
1999-09-17 13:40:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_WRITE_FUNC(user)
|
|
|
|
{
|
2014-03-28 18:46:25 +08:00
|
|
|
zval args[2];
|
1999-09-17 13:40:59 +08:00
|
|
|
STDVARS;
|
2009-05-19 00:10:09 +08:00
|
|
|
|
2015-01-29 18:48:50 +08:00
|
|
|
ZVAL_STR_COPY(&args[0], key);
|
|
|
|
ZVAL_STR_COPY(&args[1], val);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ps_call_handler(&PSF(write), 2, args, &retval);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_DESTROY_FUNC(user)
|
|
|
|
{
|
2014-03-28 18:46:25 +08:00
|
|
|
zval args[1];
|
1999-09-17 13:40:59 +08:00
|
|
|
STDVARS;
|
|
|
|
|
2015-01-29 18:48:50 +08:00
|
|
|
ZVAL_STR_COPY(&args[0], key);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ps_call_handler(&PSF(destroy), 1, args, &retval);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
PS_GC_FUNC(user)
|
|
|
|
{
|
2014-03-28 18:46:25 +08:00
|
|
|
zval args[1];
|
1999-09-17 13:40:59 +08:00
|
|
|
STDVARS;
|
|
|
|
|
2015-01-29 18:48:50 +08:00
|
|
|
ZVAL_LONG(&args[0], maxlifetime);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ps_call_handler(&PSF(gc), 1, args, &retval);
|
1999-09-17 13:40:59 +08:00
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
2001-06-06 22:32:27 +08:00
|
|
|
|
2012-06-15 22:06:47 +08:00
|
|
|
PS_CREATE_SID_FUNC(user)
|
|
|
|
{
|
|
|
|
/* maintain backwards compatibility */
|
2014-05-03 16:06:27 +08:00
|
|
|
if (!Z_ISUNDEF(PSF(create_sid))) {
|
2014-03-28 18:46:25 +08:00
|
|
|
zend_string *id = NULL;
|
|
|
|
zval retval;
|
2012-06-15 22:06:47 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ps_call_handler(&PSF(create_sid), 0, NULL, &retval);
|
2012-06-15 22:06:47 +08:00
|
|
|
|
2014-05-03 16:06:27 +08:00
|
|
|
if (!Z_ISUNDEF(retval)) {
|
2014-03-28 18:46:25 +08:00
|
|
|
if (Z_TYPE(retval) == IS_STRING) {
|
2014-08-26 01:24:55 +08:00
|
|
|
id = zend_string_copy(Z_STR(retval));
|
2012-06-15 22:06:47 +08:00
|
|
|
}
|
|
|
|
zval_ptr_dtor(&retval);
|
2014-03-28 18:46:25 +08:00
|
|
|
} else {
|
2015-07-21 17:18:36 +08:00
|
|
|
php_error_docref(NULL, E_ERROR, "No session id returned by function");
|
2012-06-15 22:06:47 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!id) {
|
2015-07-21 17:18:36 +08:00
|
|
|
php_error_docref(NULL, E_ERROR, "Session id must be a string");
|
2012-06-15 22:06:47 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* function as defined by PS_MOD */
|
2014-12-14 06:06:14 +08:00
|
|
|
return php_session_create_id(mod_data);
|
2012-06-15 22:06:47 +08:00
|
|
|
}
|
|
|
|
|
2015-01-21 18:13:59 +08:00
|
|
|
PS_VALIDATE_SID_FUNC(user)
|
|
|
|
{
|
|
|
|
/* maintain backwards compatibility */
|
|
|
|
if (!Z_ISUNDEF(PSF(validate_sid))) {
|
|
|
|
zval args[1];
|
|
|
|
STDVARS;
|
|
|
|
|
2015-01-29 18:48:50 +08:00
|
|
|
ZVAL_STR_COPY(&args[0], key);
|
2015-01-21 18:13:59 +08:00
|
|
|
|
|
|
|
ps_call_handler(&PSF(validate_sid), 1, args, &retval);
|
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dummy function defined by PS_MOD */
|
2015-03-08 19:24:50 +08:00
|
|
|
return php_session_validate_sid(mod_data, key);
|
2015-01-21 18:13:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PS_UPDATE_TIMESTAMP_FUNC(user)
|
|
|
|
{
|
|
|
|
zval args[2];
|
|
|
|
STDVARS;
|
|
|
|
|
2015-01-29 18:48:50 +08:00
|
|
|
ZVAL_STR_COPY(&args[0], key);
|
|
|
|
ZVAL_STR_COPY(&args[1], val);
|
2015-01-21 18:13:59 +08:00
|
|
|
|
|
|
|
/* maintain backwards compatibility */
|
|
|
|
if (!Z_ISUNDEF(PSF(update_timestamp))) {
|
|
|
|
ps_call_handler(&PSF(update_timestamp), 2, args, &retval);
|
|
|
|
} else {
|
|
|
|
ps_call_handler(&PSF(write), 2, args, &retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
FINISH;
|
|
|
|
}
|
|
|
|
|
2001-06-06 22:32:27 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-06-06 22:32:27 +08:00
|
|
|
*/
|