Author: mhabersack
Date: 2007-09-25 19:23:42 -0400 (Tue, 25 Sep 2007)
New Revision: 86372
Modified:
trunk/mod_mono/ChangeLog
trunk/mod_mono/src/mod_mono.c
trunk/mod_mono/src/mod_mono.h
Log:
2007-09-26 Marek Habersack <[EMAIL PROTECTED]>
* src/mod_mono.c: added three wrapper functions to get the apache
configured user id, group id and user name.
(ensure_dashboard_initialized): attempt to remove the dashboard
file (if dashboard hasn't been created yet) as root, not as the
target user.
* src/mod_mono.h: unixd.h is not found in APACHE 1.3
Modified: trunk/mod_mono/ChangeLog
===================================================================
--- trunk/mod_mono/ChangeLog 2007-09-25 23:20:59 UTC (rev 86371)
+++ trunk/mod_mono/ChangeLog 2007-09-25 23:23:42 UTC (rev 86372)
@@ -1,3 +1,13 @@
+2007-09-26 Marek Habersack <[EMAIL PROTECTED]>
+
+ * src/mod_mono.c: added three wrapper functions to get the apache
+ configured user id, group id and user name.
+ (ensure_dashboard_initialized): attempt to remove the dashboard
+ file (if dashboard hasn't been created yet) as root, not as the
+ target user.
+
+ * src/mod_mono.h: unixd.h is not found in APACHE 1.3
+
2007-09-16 Joshua Tauberer <[EMAIL PROTECTED]>
* src/mod_mono.c (mono_execute_request): if it can't establish a
Modified: trunk/mod_mono/src/mod_mono.c
===================================================================
--- trunk/mod_mono/src/mod_mono.c 2007-09-25 23:20:59 UTC (rev 86371)
+++ trunk/mod_mono/src/mod_mono.c 2007-09-25 23:23:42 UTC (rev 86372)
@@ -307,36 +307,78 @@
}
}
+inline static uid_t
+apache_get_userid ()
+{
+#ifdef HAVE_UNIXD
+ return unixd_config.user_id;
+#else
+ return ap_user_id;
+#endif
+}
+
+inline static gid_t
+apache_get_groupid ()
+{
+#ifdef HAVE_UNIXD
+ return unixd_config.group_id;
+#elif
+ return ap_group_id;
+#endif
+}
+
+inline static char *
+apache_get_username ()
+{
+#ifdef HAVE_UNIXD
+ return unixd_config.user_name;
+#else
+ return ap_user_name;
+#endif
+}
+
static void
ensure_dashboard_initialized (module_cfg *config, xsp_data *xsp, apr_pool_t *p)
{
apr_status_t rv;
mode_t old_umask;
-#if defined (APR_HAS_USER) && defined (HAVE_UNIXD)
+#if defined (APR_HAS_USER)
apr_uid_t cur_uid;
apr_gid_t cur_gid;
int switch_back_to_root = 0;
- if (unixd_config.user_id == -1 || unixd_config.group_id == -1) {
+ if (apache_get_userid () == -1 || apache_get_groupid () == -1) {
ap_log_error (APLOG_MARK, APLOG_CRIT, STATUS_AND_SERVER,
"The unix daemon module not initialized yet.
Please make sure that "
"your mod_mono module is loaded after the
User/Group directives have "
"been parsed. Not initializing the dashboard.");
return;
}
+#endif
+
+ if (!xsp->dashboard_shm) {
+ DEBUG_PRINT (1, "removing dashboard file '%s' as root",
xsp->dashboard_file);
+ if (unlink (xsp->dashboard_file) == -1 && errno != ENOENT) {
+ ap_log_error (APLOG_MARK, APLOG_CRIT, STATUS_AND_SERVER,
+ "Failed to remove dashboard file '%s',
further actions impossible. %s",
+ xsp->dashboard_file, strerror (errno));
+ return;
+ }
+ }
+#if defined (APR_HAS_USER)
if (apr_uid_current (&cur_uid, &cur_gid, p) == APR_SUCCESS && cur_uid
== 0) {
DEBUG_PRINT (2, "Temporarily switching to target uid/gid");
switch_back_to_root = 1;
- if (setegid (unixd_config.group_id) == -1)
+ if (setegid (apache_get_groupid ()) == -1)
ap_log_error (APLOG_MARK, APLOG_ALERT,
STATUS_AND_SERVER,
"setegid: unable to set effective group
id to %u. %s",
- (unsigned)unixd_config.group_id, strerror
(errno));
+ (unsigned)apache_get_groupid (), strerror
(errno));
- if (seteuid (unixd_config.user_id) == -1)
+ if (seteuid (apache_get_userid ()) == -1)
ap_log_error (APLOG_MARK, APLOG_ALERT,
STATUS_AND_SERVER,
"seteuid: unable to set effective user id
to %u. %s",
- (unsigned)unixd_config.user_id, strerror
(errno));
+ (unsigned)apache_get_userid (), strerror
(errno));
}
#endif
@@ -366,12 +408,6 @@
rv = apr_shm_attach (&xsp->dashboard_shm, xsp->dashboard_file,
p);
if (rv != APR_SUCCESS) {
DEBUG_PRINT (1, "creating dashboard '%s'",
xsp->dashboard_file);
- if (unlink (xsp->dashboard_file) == -1 && errno !=
ENOENT) {
- ap_log_error (APLOG_MARK, APLOG_CRIT,
STATUS_AND_SERVER,
- "Failed to remove dashboard file
'%s', further actions impossible. %s",
- xsp->dashboard_file, strerror
(errno));
- goto restore_creds;
- }
old_umask = umask (0077);
rv = apr_shm_create (&xsp->dashboard_shm, sizeof
(dashboard_data), xsp->dashboard_file, p);
@@ -1415,11 +1451,11 @@
int max_cpu_time = 0;
int status;
char is_master;
-#if defined (APR_HAS_USER) && defined (HAVE_UNIXD)
+#if defined (APR_HAS_USER)
apr_uid_t cur_uid;
apr_gid_t cur_gid;
- if (unixd_config.user_id == -1 || unixd_config.group_id == -1) {
+ if (apache_get_userid () == -1 || apache_get_groupid () == -1) {
ap_log_error (APLOG_MARK, APLOG_CRIT, STATUS_AND_SERVER,
"The unix daemon module not initialized yet.
Please make sure that "
"your mod_mono module is loaded after the
User/Group directives have "
@@ -1494,23 +1530,23 @@
setsid ();
chdir ("/");
-#if defined (APR_HAS_USER) && defined (HAVE_UNIXD)
+#if defined (APR_HAS_USER)
/*
* Make sure the backend runs with proper uid/gid if we're forking
* from the module postconfig handler.
*/
if (apr_uid_current (&cur_uid, &cur_gid, pool) == APR_SUCCESS &&
cur_uid == 0) {
- DEBUG_PRINT (2, "switching forked process group to %u",
(unsigned)unixd_config.group_id);
- if (setgid (unixd_config.group_id) == -1)
+ DEBUG_PRINT (2, "switching forked process group to %u",
(unsigned)apache_get_groupid ());
+ if (setgid (apache_get_groupid ()) == -1)
ap_log_error (APLOG_MARK, APLOG_ALERT,
STATUS_AND_SERVER,
"setgid: unable to set group id to %u.
%s",
- (unsigned)unixd_config.group_id, strerror
(errno));
+ (unsigned)apache_get_groupid (), strerror
(errno));
- DEBUG_PRINT (2, "switching forked process user to %s",
unixd_config.user_name);
- if (setuid (unixd_config.user_id) == -1)
+ DEBUG_PRINT (2, "switching forked process user to %s",
apache_get_username ());
+ if (setuid (apache_get_userid ()) == -1)
ap_log_error (APLOG_MARK, APLOG_ALERT,
STATUS_AND_SERVER,
"setuid: unable to set user id to %u. %s",
- (unsigned)unixd_config.user_id, strerror
(errno));
+ (unsigned)apache_get_userid (), strerror
(errno));
}
#endif
Modified: trunk/mod_mono/src/mod_mono.h
===================================================================
--- trunk/mod_mono/src/mod_mono.h 2007-09-25 23:20:59 UTC (rev 86371)
+++ trunk/mod_mono/src/mod_mono.h 2007-09-25 23:23:42 UTC (rev 86372)
@@ -53,10 +53,14 @@
#include "http_config.h"
#include "apr_shm.h"
+#if defined (APACHE13)
+#include "http_conf_globals.h"
+#else
#if !defined (WIN32) && !defined (OS2) && !defined (BEOS) && !defined (NETWARE)
#define HAVE_UNIXD
#include "unixd.h"
#endif
+#endif
#ifdef APACHE13
/* Functions needed for making Apache 1.3 module as similar
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches