diff options
author | Stef Walter <stef@thewalter.net> | 2008-06-09 15:40:26 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2008-06-09 15:40:26 +0000 |
commit | 2c2348a13a6252355716a0717bfe89de79e1f4f9 (patch) | |
tree | 27f93edf477ced692838c5b0fa2bdafd1e5f3d1c /slapd-pivot.py | |
parent | a9a6b62cf2abb833d54c60aa1363e5acfc3cdfd5 (diff) |
Put the socket file, unix user and group in the conf file
Diffstat (limited to 'slapd-pivot.py')
-rw-r--r-- | slapd-pivot.py | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/slapd-pivot.py b/slapd-pivot.py index 704c16e..c27ee2e 100644 --- a/slapd-pivot.py +++ b/slapd-pivot.py @@ -7,8 +7,6 @@ import pwd, grp import Backend, Pivot, Config SCRIPT = "slapd-pivot" -USER = None -GROUP = None PIDFILE = None class Log: @@ -30,12 +28,12 @@ def failure(msg, details = None): def usage(): - print >> sys.stderr, "usage: %s -f config [-d level] [-g group] [-p pidfile] [-u user]" % SCRIPT + print >> sys.stderr, "usage: %s -f config [-d level] [-p pidfile]" % SCRIPT sys.exit(2) def run_server(): - server = Backend.Server("/tmp/pivot-slapd.sock", Pivot.Database) + server = Backend.Server(Config.require("sock-file"), Pivot.Database) try: print >> sys.stderr, "%s starting up..." % SCRIPT server.serve_forever() @@ -44,27 +42,28 @@ def run_server(): def drop_privileges(): - global GROUP, USER - if GROUP: + group = Config.option("unix-group") + if group: try: - GROUP = int(GROUP) + group = int(group) except ValueError: try: - GROUP = grp.getgrgid(GROUP)[2] + group = grp.getgrgid(group)[2] except KeyError: - failure("invalid group: %s" % GROUP) - os.setegid(GROUP) + failure("invalid group: %s" % group) + os.setegid(group) - if USER: + user = Config.option("unix-user") + if user: try: - USER = int(USER) + user = int(user) except ValueError: try: - USER = pwd.getpwnam(USER)[2] + user = pwd.getpwnam(user)[2] except KeyError: - failure("invalid user: %s" % USER) - os.seteuid(USER) + failure("invalid user: %s" % user) + os.seteuid(user) def daemon(): @@ -119,15 +118,9 @@ if __name__ == '__main__': elif opt == '-f': config = oarg - elif opt == '-g': - GROUP = oarg - elif opt == '-p': PIDFILE = oarg - elif opt == '-u': - USER = oarg - # No extra arguments if args: usage() |