Changeset View
Changeset View
Standalone View
Standalone View
saslauthd/__init__.py
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | def __init__(self): | ||||
conf.finalize_conf() | conf.finalize_conf() | ||||
try: | try: | ||||
utils.ensure_directory( | utils.ensure_directory( | ||||
os.path.dirname(conf.pidfile), | os.path.dirname(conf.pidfile), | ||||
conf.process_username, | conf.process_username, | ||||
conf.process_groupname | conf.process_groupname | ||||
) | ) | ||||
except Exception, errmsg: | except Exception as errmsg: | ||||
log.error(_("Could not create %r: %r") % (os.path.dirname(conf.pidfile), errmsg)) | log.error(_("Could not create %r: %r") % (os.path.dirname(conf.pidfile), errmsg)) | ||||
sys.exit(1) | sys.exit(1) | ||||
self.thread_count = 0 | self.thread_count = 0 | ||||
def run(self): | def run(self): | ||||
""" | """ | ||||
Run the SASL authentication daemon. | Run the SASL authentication daemon. | ||||
Show All 39 Lines | def run(self): | ||||
os.umask(old_umask) | os.umask(old_umask) | ||||
self.thread_count += 1 | self.thread_count += 1 | ||||
log.remove_stdout_handler() | log.remove_stdout_handler() | ||||
self.set_signal_handlers() | self.set_signal_handlers() | ||||
self.write_pid() | self.write_pid() | ||||
self.do_saslauthd() | self.do_saslauthd() | ||||
except SystemExit, e: | except SystemExit as e: | ||||
exitcode = e | exitcode = e | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
exitcode = 1 | exitcode = 1 | ||||
log.info(_("Interrupted by user")) | log.info(_("Interrupted by user")) | ||||
except AttributeError, e: | except AttributeError: | ||||
exitcode = 1 | exitcode = 1 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
print(_("Traceback occurred, please report a " + | print(_("Traceback occurred, please report a " + | ||||
"bug at https://issues.kolab.org"), | "bug at https://issues.kolab.org"), | ||||
file=sys.stderr) | file=sys.stderr) | ||||
except TypeError, e: | except TypeError as e: | ||||
exitcode = 1 | exitcode = 1 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
log.error(_("Type Error: %s") % e) | log.error(_("Type Error: %s") % e) | ||||
except: | except: | ||||
exitcode = 2 | exitcode = 2 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
print(_("Traceback occurred, please report a " + | print(_("Traceback occurred, please report a " + | ||||
"bug at https://issues.kolab.org"), | "bug at https://issues.kolab.org"), | ||||
Show All 30 Lines | def do_saslauthd(self): | ||||
max_tries = 20 | max_tries = 20 | ||||
cur_tries = 0 | cur_tries = 0 | ||||
bound = False | bound = False | ||||
while not bound: | while not bound: | ||||
cur_tries += 1 | cur_tries += 1 | ||||
try: | try: | ||||
(clientsocket, address) = s.accept() | (clientsocket, address) = s.accept() | ||||
bound = True | bound = True | ||||
except Exception, errmsg: | except Exception as errmsg: | ||||
log.error( | log.error( | ||||
_("kolab-saslauthd could not accept " + | _("kolab-saslauthd could not accept " + | ||||
"connections on socket: %r") % (errmsg) | "connections on socket: %r") % (errmsg) | ||||
) | ) | ||||
if cur_tries >= max_tries: | if cur_tries >= max_tries: | ||||
log.fatal(_("Maximum tries exceeded, exiting")) | log.fatal(_("Maximum tries exceeded, exiting")) | ||||
sys.exit(1) | sys.exit(1) | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | def _ensure_socket_dir(self): | ||||
conf.process_groupname | conf.process_groupname | ||||
) | ) | ||||
def _drop_privileges(self): | def _drop_privileges(self): | ||||
try: | try: | ||||
try: | try: | ||||
(ruid, euid, suid) = os.getresuid() | (ruid, euid, suid) = os.getresuid() | ||||
(rgid, egid, sgid) = os.getresgid() | (rgid, egid, sgid) = os.getresgid() | ||||
except AttributeError, errmsg: | except AttributeError: | ||||
ruid = os.getuid() | ruid = os.getuid() | ||||
rgid = os.getgid() | rgid = os.getgid() | ||||
if ruid == 0: | if ruid == 0: | ||||
# Means we can setreuid() / setregid() / setgroups() | # Means we can setreuid() / setregid() / setgroups() | ||||
if rgid == 0: | if rgid == 0: | ||||
# Get group entry details | # Get group entry details | ||||
try: | try: | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |