Author: mhabersack
Date: 2007-07-18 17:13:47 -0400 (Wed, 18 Jul 2007)
New Revision: 82244

Modified:
   trunk/mod_mono/ChangeLog
   trunk/mod_mono/src/mod_mono.c
Log:
2007-07-18  Marek Habersack  <[EMAIL PROTECTED]>

        * src/mod_mono.c (mono_child_init): if APR has uid/gid support and
        we're not compiling for WIN32, start the backends from the module
        post config handler, it avoids launching of many backends on
        startup


Modified: trunk/mod_mono/ChangeLog
===================================================================
--- trunk/mod_mono/ChangeLog    2007-07-18 21:13:23 UTC (rev 82243)
+++ trunk/mod_mono/ChangeLog    2007-07-18 21:13:47 UTC (rev 82244)
@@ -1,3 +1,10 @@
+2007-07-18  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * src/mod_mono.c (mono_child_init): if APR has uid/gid support and
+       we're not compiling for WIN32, start the backends from the module
+       post config handler, it avoids launching of many backends on
+       startup.
+
 2007-07-14  Marek Habersack  <[EMAIL PROTECTED]>
 
        * src/mod_mono.c (do_command): added error logging

Modified: trunk/mod_mono/src/mod_mono.c
===================================================================
--- trunk/mod_mono/src/mod_mono.c       2007-07-18 21:13:23 UTC (rev 82243)
+++ trunk/mod_mono/src/mod_mono.c       2007-07-18 21:13:47 UTC (rev 82244)
@@ -30,6 +30,7 @@
 #define DEBUG_LEVEL 0
 
 #include "mod_mono.h"
+#include "unixd.h"
 
 static int send_table (apr_pool_t *pool, apr_table_t *table, apr_socket_t 
*sock);
 
@@ -1080,7 +1081,9 @@
        int max_cpu_time = 0;
        int status;
        char is_master;
-
+  apr_uid_t cur_uid;
+  apr_gid_t cur_gid;
+  
        /* Running mod-mono-server not requested */
        if (!strcasecmp (config->run_xsp, "false")) {
                DEBUG_PRINT (1, "Not running mod-mono-server: %s", 
config->run_xsp);
@@ -1146,6 +1149,27 @@
 
        setsid ();
        chdir ("/");
+
+#ifdef 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 (0, "switching forked process group to %u", 
(unsigned)unixd_config.group_id);
+    if (setgid (unixd_config.group_id) == -1)
+      ap_log_error (APLOG_MARK, APLOG_ALERT, errno, STATUS_AND_SERVER,
+                    "setgid: unable to set group id to %u",
+                    (unsigned)unixd_config.group_id);
+
+    DEBUG_PRINT (0, "switching forked process user to %s", 
unixd_config.user_name);
+    if (setuid (unixd_config.user_id) == -1)
+      ap_log_error (APLOG_MARK, APLOG_ALERT, errno, STATUS_AND_SERVER,
+                    "setuid: unable to set user id to %u",
+                    (unsigned)unixd_config.user_id);
+  }
+#endif
+  
        if (config->umask_value == NULL)
                umask (0077);
        else {
@@ -1802,7 +1826,8 @@
 {
        void *data;
        const char *userdata_key = "mono_module_init";
-
+  module_cfg *config;
+  
        /*
         * mono_init_handler() will be called twice, and if it's a DSO then all
         * static data from the first call will be lost. Only set up our static
@@ -1821,6 +1846,11 @@
        pconf = s->process->pconf;
        apr_pool_cleanup_register (pconf, s, terminate_xsp, 
apr_pool_cleanup_null);
 
+#if defined (APR_HAS_USER) && !defined (WIN32)
+  config = ap_get_module_config (s->module_config, &mono_module);
+       start_xsp (config, 0, NULL);
+#endif
+  
        return OK;
 }
 #endif
@@ -1834,12 +1864,13 @@
 #endif
        )
 {
-       module_cfg *config;
-
+#if defined (APR_HAS_USER) || defined (WIN32)
+  module_cfg *config;
        DEBUG_PRINT (0, "Mono Child Init");
-       config = ap_get_module_config (s->module_config, &mono_module);
 
+  config = ap_get_module_config (s->module_config, &mono_module);
        start_xsp (config, 0, NULL);
+#endif
 }
 
 #ifdef APACHE13

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to