--- mod_wsgi.c.orig 2012-04-16 19:24:08.671074746 -0400 +++ mod_wsgi.c 2012-04-16 22:07:21.204504425 -0400 @@ -457,6 +457,7 @@ const char *python_home; const char *python_path; const char *python_eggs; + const char *python_hash_seed; int restrict_embedded; int restrict_stdin; @@ -526,6 +527,7 @@ object->python_home = NULL; object->python_path = NULL; object->python_eggs = NULL; + object->python_hash_seed = NULL; object->restrict_embedded = -1; object->restrict_stdin = -1; @@ -4750,6 +4752,32 @@ } } + if (wsgi_server_config->python_hash_seed != NULL) { + module = PyImport_ImportModule("os"); + + if (module) { + PyObject *dict = NULL; + PyObject *key = NULL; + + dict = PyModule_GetDict(module); + object = PyDict_GetItemString(dict, "environ"); + + if (object) { +#if PY_MAJOR_VERSION >= 3 + key = PyUnicode_FromString("PYTHONHASHSEED"); +#else + key = PyString_FromString("PYTHONHASHSEED"); +#endif + + PyObject_DelItem(object, key); + + Py_DECREF(key); + } + + Py_DECREF(module); + } + } + /* * Install user defined Python module search path. This is * added using site.addsitedir() so that any Python .pth @@ -5810,6 +5838,14 @@ _wputenv(L"PYTHONIOENCODING=cp1252:backslashreplace"); #endif + if (wsgi_server_config->python_hash_seed != NULL) { +#if defined(WIN32) + _putenv_s("PYTHONHASHSEED", wsgi_server_config->python_hash_seed); +#else + setenv("PYTHONHASHSEED", wsgi_server_config->python_hash_seed, 1); +#endif + } + /* Initialise Python. */ ap_log_error(APLOG_MARK, WSGI_LOG_INFO(0), wsgi_server, @@ -5827,6 +5863,10 @@ wsgi_python_initialized = 1; + if (wsgi_server_config->python_hash_seed != NULL) { + unsetenv("PYTHONHASHSEED"); + } + /* * Register cleanups to be performed on parent restart * or shutdown. This will destroy Python itself. @@ -7235,6 +7275,22 @@ return NULL; } +static const char *wsgi_set_python_hash_seed(cmd_parms *cmd, void *mconfig, + const char *f) +{ + const char *error = NULL; + WSGIServerConfig *sconfig = NULL; + + error = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (error != NULL) + return error; + + sconfig = ap_get_module_config(cmd->server->module_config, &wsgi_module); + sconfig->python_hash_seed = f; + + return NULL; +} + static const char *wsgi_set_restrict_embedded(cmd_parms *cmd, void *mconfig, const char *f) { @@ -9204,6 +9260,8 @@ RSRC_CONF, TAKE1, "Python module search path." }, { "WSGIPythonEggs", wsgi_set_python_eggs, NULL, RSRC_CONF, TAKE1, "Python eggs cache directory." }, + { "WSGIPythonHashSeed", wsgi_set_python_hash_seed, NULL, + RSRC_CONF, TAKE1, "Python hash seed." }, { "WSGIRestrictStdin", wsgi_set_restrict_stdin, NULL, RSRC_CONF, TAKE1, "Enable/Disable restrictions on use of STDIN." }, @@ -14890,6 +14948,8 @@ NULL, RSRC_CONF, "Python module search path."), AP_INIT_TAKE1("WSGIPythonEggs", wsgi_set_python_eggs, NULL, RSRC_CONF, "Python eggs cache directory."), + AP_INIT_RAW_ARGS("WSGIPythonHashSeed", wsgi_set_python_hash_seed, + NULL, RSRC_CONF, "Python hash seed."), #if defined(MOD_WSGI_WITH_DAEMONS) AP_INIT_TAKE1("WSGIRestrictEmbedded", wsgi_set_restrict_embedded,