return retval;
}
-#define STDVARS \
+#define STDVARS1 \
zval *retval; \
- int ret = FAILURE; \
- ps_user *mdata = PS_GET_MOD_DATA(); \
+ int ret = FAILURE
+
+#define STDVARS \
+ STDVARS1; \
+ char *mdata = PS_GET_MOD_DATA(); \
if (!mdata) \
return FAILURE
-#define PSF(a) mdata->name.ps_##a
+#define PSF(a) PS(mod_user_names).name.ps_##a
#define FINISH \
if (retval) { \
PS_OPEN_FUNC(user)
{
zval *args[2];
- STDVARS;
+ static char dummy = 0;
+ STDVARS1;
SESS_ZVAL_STRING(save_path, args[0]);
SESS_ZVAL_STRING(session_name, args[1]);
retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
+ if (retval) {
+ /* This is necessary to fool the session module. Yes, it's safe to
+ * use a static. Neither mod_user nor the session module itself will
+ * ever touch this pointer. It could be set to 0xDEADBEEF for all the
+ * difference it makes, but for the sake of paranoia it's set to some
+ * valid value.
+ */
+ PS_SET_MOD_DATA(&dummy);
+ }
FINISH;
}
PS_CLOSE_FUNC(user)
{
- int i;
- STDVARS;
+ STDVARS1;
retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
- for (i = 0; i < 6; i++)
- zval_ptr_dtor(&mdata->names[i]);
- efree(mdata);
-
PS_SET_MOD_DATA(NULL);
FINISH;
{
zval **args[6];
int i;
- ps_user *mdata;
char *name;
if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_array_ex(6, args) == FAILURE)
zend_alter_ini_entry("session.save_handler", sizeof("session.save_handler"), "user", sizeof("user")-1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
- mdata = emalloc(sizeof(*mdata));
-
for (i = 0; i < 6; i++) {
+ if (PS(mod_user_names).names[i] != NULL) {
+ zval_ptr_dtor(&PS(mod_user_names).names[i]);
+ }
Z_ADDREF_PP(args[i]);
- mdata->names[i] = *args[i];
+ PS(mod_user_names).names[i] = *args[i];
}
-
- PS(mod_data) = (void *) mdata;
RETURN_TRUE;
}
PS(id) = NULL;
PS(session_status) = php_session_none;
PS(mod_data) = NULL;
+ /* Do NOT init PS(mod_user_names) here! */
PS(http_session_vars) = NULL;
}
zval_ptr_dtor(&PS(http_session_vars));
PS(http_session_vars) = NULL;
}
+ /* Do NOT destroy PS(mod_user_names) here! */
if (PS(mod_data)) {
zend_try {
PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
PHP_RSHUTDOWN_FUNCTION(session)
{
+ int i;
+
php_session_flush(TSRMLS_C);
php_rshutdown_session_globals(TSRMLS_C);
+ /* this should NOT be done in php_rshutdown_session_globals() */
+ for (i = 0; i < 6; i++) {
+ if (PS(mod_user_names).names[i] != NULL) {
+ zval_ptr_dtor(&PS(mod_user_names).names[i]);
+ }
+ }
return SUCCESS;
}
static PHP_GINIT_FUNCTION(ps)
{
+ int i;
+
ps_globals->save_path = NULL;
ps_globals->session_name = NULL;
ps_globals->id = NULL;
ps_globals->mod = NULL;
ps_globals->mod_data = NULL;
ps_globals->session_status = php_session_none;
+ for (i = 0; i < 6; i++) {
+ ps_globals->mod_user_names.names[i] = NULL;
+ }
ps_globals->http_session_vars = NULL;
}