summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham.Dumpleton <devnull@localhost>2009-03-20 11:52:06 +0000
committerGraham.Dumpleton <devnull@localhost>2009-03-20 11:52:06 +0000
commitbd99ee607324d5d3de18c364bab2915ccc17ead4 (patch)
tree8f00036ce5c47b1670eb8fb1274a7e22f2e809a9
parent3aa61653b08559de77ea0ba6c39d957ccc97cde9 (diff)
downloadmod_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.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/mod_wsgi.c b/mod_wsgi.c
index de2db3c..463b467 100644
--- a/mod_wsgi.c
+++ b/mod_wsgi.c
@@ -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