[CalendarServer-changes] [1136] CalendarServer/branches/users/dreid/pid-removal-2

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 6 13:42:31 PST 2007


Revision: 1136
          http://trac.macosforge.org/projects/calendarserver/changeset/1136
Author:   dreid at apple.com
Date:     2007-02-06 13:42:31 -0800 (Tue, 06 Feb 2007)

Log Message:
-----------
Merge forward

Modified Paths:
--------------
    CalendarServer/branches/users/dreid/pid-removal-2/bin/caldavd
    CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd-test.plist
    CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd.plist
    CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/cluster.py
    CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/config.py
    CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/tap.py

Modified: CalendarServer/branches/users/dreid/pid-removal-2/bin/caldavd
===================================================================
--- CalendarServer/branches/users/dreid/pid-removal-2/bin/caldavd	2007-02-06 21:40:01 UTC (rev 1135)
+++ CalendarServer/branches/users/dreid/pid-removal-2/bin/caldavd	2007-02-06 21:42:31 UTC (rev 1136)
@@ -113,4 +113,4 @@
 
 export PYTHONPATH
 
-exec "${python}" "${twistdpath}" ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type};
+exec "${python}" "${twistdpath}" --profile=/tmp/caldavd.profile --nohotshot --savestats ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type};

Modified: CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd-test.plist
===================================================================
--- CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd-test.plist	2007-02-06 21:40:01 UTC (rev 1135)
+++ CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd-test.plist	2007-02-06 21:42:31 UTC (rev 1136)
@@ -49,6 +49,12 @@
   <key>SSLOnly</key>
   <false/>
 
+  <key>Username</key>
+  <string></string>
+
+  <key>Groupname</key>
+  <string></string>
+
   <key>SSLPrivateKey</key>
   <string>conf/server.pem</string>
 

Modified: CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd.plist
===================================================================
--- CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd.plist	2007-02-06 21:40:01 UTC (rev 1135)
+++ CalendarServer/branches/users/dreid/pid-removal-2/conf/caldavd.plist	2007-02-06 21:42:31 UTC (rev 1136)
@@ -36,6 +36,12 @@
   <key>ServerHostName</key>
   <string>localhost</string>
 
+  <key>Username</key>
+  <string>calendar</string>
+
+  <key>Groupname</key>
+  <string>calendar</string>
+
   <key>Port</key>
   <integer>8008</integer>
 

Modified: CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/cluster.py
===================================================================
--- CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/cluster.py	2007-02-06 21:40:01 UTC (rev 1135)
+++ CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/cluster.py	2007-02-06 21:42:31 UTC (rev 1136)
@@ -21,7 +21,7 @@
 import tempfile
 
 from twisted.runner import procmon
-
+from twisted.scripts.mktap import getid
 from twistedcaldav.config import config
 
 serviceTemplate = """
@@ -54,10 +54,6 @@
         self.port = port
         self.sslPort = sslPort
 
-        self.pidFile = os.path.join(
-            os.path.dirname(config.PIDFile),
-            '%s.pid' % (self.getName(),))
-
         self.interfaces = interfaces
 
     def getName(self):
@@ -75,7 +71,7 @@
             '-o', 'BindAddress=%s' % (','.join(self.interfaces),),
             '-o', 'Port=%s' % (self.port,),
             '-o', 'SSLPort=%s' % (self.sslPort,),
-            '-o', 'PIDFile=%s' % (self.pidFile,)]
+            '-o', 'PIDFile=None']
     
     def getHostLine(self, ssl=None):
         name = self.getName()
@@ -106,18 +102,23 @@
         bindAddress = config.BindAddress
 
     for p in xrange(0, config.MultiProcess['NumProcesses']):
-        port += 1
-        sslport += 1
+        if int(config.MultiProcess['NumProcesses']) > 1:
+            port += 1
+            sslport += 1
 
         process = TwistdSlaveProcess(config.twistdLocation,
                                      options['config'],
                                      bindAddress,
                                      port, sslport)
 
+        uid, gid = None, None
+        if config.Username or config.Groupname:
+            uid, gid = getid(config.Username, config.Groupname)
+            
         service.addProcess(process.getName(),
                            process.getCommandLine(),
-                           uid=options.parent['uid'],
-                           gid=options.parent['gid'],
+                           uid=uid,
+                           gid=gid,
                            env=parentEnv)
         
         if not config.SSLOnly:
@@ -126,7 +127,8 @@
         if config.SSLEnable:
             sslHosts.append(process.getHostLine(ssl=True))
 
-    if config.MultiProcess['LoadBalancer']['Enabled']: 
+    if (config.MultiProcess['LoadBalancer']['Enabled'] and 
+        config.MultiProcess['NumProcesses'] > 1):
         services = []
 
         if not config.BindAddress:

Modified: CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/config.py	2007-02-06 21:40:01 UTC (rev 1135)
+++ CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/config.py	2007-02-06 21:42:31 UTC (rev 1136)
@@ -72,6 +72,9 @@
 
     'ServerType': 'singleprocess',
 
+    'Username': 'daemon',
+    'Groupname': 'daemon',
+
     'MultiProcess': {
         'NumProcesses': 10,
         'LoadBalancer': {

Modified: CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/tap.py	2007-02-06 21:40:01 UTC (rev 1135)
+++ CalendarServer/branches/users/dreid/pid-removal-2/twistedcaldav/tap.py	2007-02-06 21:42:31 UTC (rev 1136)
@@ -29,6 +29,8 @@
 from twisted.application import internet, service
 from twisted.plugin import IPlugin
 
+from twisted.scripts.mktap import getid
+
 from twisted.cred.portal import Portal
 
 from twisted.web2.dav import auth
@@ -109,6 +111,9 @@
                 elif isinstance(defaultConfig[key], dict):
                     raise UsageError(
                         "We do not support dict options on the command line")
+                        
+                elif value == 'None':
+                    value = None
 
             self.overrides[key] = value
         else:
@@ -124,6 +129,26 @@
 
         config.update(self.overrides)
 
+        uid, gid = None, None
+
+        if self.parent['uid'] or self.parent['gid']:
+            uid, gid = getid(self.parent['uid'], 
+                             self.parent['gid'])
+
+        if uid:
+            if uid != os.getuid() and uid != 0:
+                import pwd
+                username = pwd.getpwuid(os.getuid())[0]
+                raise UsageError(("Only root can drop privileges "
+                                  "you are: %s" % (username,)))
+
+        if gid:
+            if gid != os.getgid() and gid != 0:
+                import grp
+                groupname = grp.getgrgid(os.getuid())[0]
+                raise UsageError(("Only root can drop privileges, "
+                                  "you are: %s" % (groupname,)))
+
         self.parent['logfile'] = config.ErrorLogFile
         self.parent['pidfile'] = config.PIDFile
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070206/5fe187f5/attachment.html


More information about the calendarserver-changes mailing list