Ticket #1473: deluge-web-setuid.patch

File deluge-web-setuid.patch, 2.9 KB (added by cinderblock, 13 years ago)

Updated version that sets gid correctly and before uid

  • deluge/ui/web/web.py

     deluge/ui/web/web.py |   35 ++++++++++++++++++++++++++++++-----
     1 files changed, 30 insertions(+), 5 deletions(-)
    
    diff --git a/deluge/ui/web/web.py b/deluge/ui/web/web.py
    index a2b5765..23cabcd 100644
    a b def __init__(self): 
    5656        group.add_option("-b", "--base", dest="base", 
    5757            help="Set the base path that the ui is running on (proxying)", 
    5858            action="store", default=None) 
    59         group.add_option("-f", "--fork", dest="fork", 
    60             help="Fork the web interface process into the background", 
    61             action="store_true", default=False) 
     59        if not (deluge.common.windows_check() or deluge.common.osx_check()): 
     60            group.add_option("-f", "--fork", dest="fork", 
     61                help="Fork the web interface process into the background", 
     62                action="store_true", default=False) 
     63        group.add_option("-P", "--pidfile", dest="pidfile", type="str", 
     64            help="Use pidfile to store process id", 
     65            action="store", default=None) 
     66        if not deluge.common.windows_check(): 
     67            group.add_option("-U", "--user", dest="user", type="str", 
     68                help="User to switch to. Only use it when starting as root", 
     69                action="store", default=None) 
     70            group.add_option("-g", "--group", dest="group", type="str", 
     71                help="Group to switch to. Only use it when starting as root", 
     72                action="store", default=None) 
    6273        group.add_option("-p", "--port", dest="port", type="int", 
    6374            help="Sets the port to be used for the webserver", 
    6475            action="store", default=None) 
    def start(self): 
    8697        import deluge.common 
    8798        # Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/ 
    8899        # Section 1.7 
    89         if self.options.fork and not deluge.common.windows_check(): 
     100        if self.options.fork: 
    90101            # fork() so the parent can exit, returns control to the command line 
    91102            # or shell invoking the program. 
    92103            if os.fork(): 
    def start(self): 
    103114            # use that may prevent a filesystem unmount. 
    104115            import deluge.configmanager 
    105116            os.chdir(deluge.configmanager.get_config_dir()) 
    106          
     117 
     118        if self.options.pidfile: 
     119            open(self.options.pidfile, "wb").write("%d\n" % os.getpid()) 
     120 
     121        if self.options.group: 
     122            if not self.options.group.isdigit(): 
     123                import grp 
     124                self.options.group = grp.getgrnam(self.options.group)[2] 
     125            os.setuid(self.options.group) 
     126        if self.options.user: 
     127            if not self.options.user.isdigit(): 
     128                import pwd 
     129                self.options.user = pwd.getpwnam(self.options.user)[2] 
     130            os.setuid(self.options.user) 
     131 
    107132        import server 
    108133        self.__server = server.DelugeWeb() 
    109134