def test_drop_privileges_not_root(os_getuid, os_setuid): # fakes out os.getuid to claim it's running as root os_getuid.return_value = 1000 unix.drop_privileges(501, 501) assert_true(os_getuid.called) assert_false(os_setuid.called)
def daemonize(self, args): log.setup(self.log_file) log.info("Daemonizing.") self.before_daemonize(args) if unix.still_running(self.name, pid_file_path=self.pid_path): log.error("%s still running. Aborting." % self.name) sys.exit(1) else: unix.daemonize(self.name, pid_file_path=self.pid_path) def shutdown_handler(signal, frame): self.shutdown(signal) sys.exit(0) unix.register_shutdown(shutdown_handler) self.before_jail(args) log.info("Setting up the chroot jail to: %s" % self.run_dir) unix.chroot_jail(self.run_dir) self.before_drop_privs(args) unix.drop_privileges(uid_name=self.uid, gid_name=self.gid) log.info("Server %s running." % self.name) self.start(args)
def test_drop_privileges(os_getuid, *calls): # fakes out os.getuid to claim it's running as root os_getuid.return_value = 0 unix.drop_privileges(501, 501) # now just confirm all the remaining system calls were called for i in calls: assert_true(i.called, "Failed to call %r" % i)