diff options
author | Graham.Dumpleton <devnull@localhost> | 2009-03-20 11:52:06 +0000 |
---|---|---|
committer | Graham.Dumpleton <devnull@localhost> | 2009-03-20 11:52:06 +0000 |
commit | bd99ee607324d5d3de18c364bab2915ccc17ead4 (patch) | |
tree | 8f00036ce5c47b1670eb8fb1274a7e22f2e809a9 | |
parent | 3aa61653b08559de77ea0ba6c39d957ccc97cde9 (diff) | |
download | mod_wsgi-bd99ee607324d5d3de18c364bab2915ccc17ead4.tar.gz |
Backport changed to ensure that LOGNAME, USER and USERNAME are updated in
daemon process if they are set, to reflect actual user. See issue #129.
-rw-r--r-- | mod_wsgi.c | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -3750,6 +3750,71 @@ static InterpreterObject *newInterpreterObject(const char *name, } /* + * If running in daemon process, override as appropriate + * the USER, USERNAME or LOGNAME environment variables + * so that they match the user that the process is running + * as. Need to do this else we inherit the value from the + * Apache parent process which is likely wrong as will be + * root or the user than ran sudo when Apache started. + * Can't update these for normal Apache child processes + * as that would change the expected environment of other + * Apache modules. + */ + +#ifndef WIN32 + if (wsgi_daemon_pool) { + module = PyImport_ImportModule("os"); + + if (module) { + PyObject *dict = NULL; + PyObject *key = NULL; + PyObject *value = NULL; + + dict = PyModule_GetDict(module); + object = PyDict_GetItemString(dict, "environ"); + + if (object) { + struct passwd *pwent; + + pwent = getpwuid(geteuid()); + + if (getenv("USER")) { + key = PyString_FromString("USER"); + value = PyString_FromString(pwent->pw_name); + + PyObject_SetItem(object, key, value); + + Py_DECREF(key); + Py_DECREF(value); + } + + if (getenv("USERNAME")) { + key = PyString_FromString("USERNAME"); + value = PyString_FromString(pwent->pw_name); + + PyObject_SetItem(object, key, value); + + Py_DECREF(key); + Py_DECREF(value); + } + + if (getenv("LOGNAME")) { + key = PyString_FromString("LOGNAME"); + value = PyString_FromString(pwent->pw_name); + + PyObject_SetItem(object, key, value); + + Py_DECREF(key); + Py_DECREF(value); + } + } + + Py_DECREF(module); + } + } +#endif + + /* * If running in daemon process, override HOME environment * variable so that is matches the home directory of the * user that the process is running as. Need to do this as |