diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-09-25 16:56:08 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-04 07:29:17 -0400 |
commit | a4e78fbed539e83b639dd22b0662554c9e837e23 (patch) | |
tree | a766aaa1bf6b015afceea3865fee42ba995550e5 /src/lib/Bcfg2/Options.py | |
parent | d33b0a4dac9842af98662b78a8b37620c622ecbf (diff) | |
download | bcfg2-a4e78fbed539e83b639dd22b0662554c9e837e23.tar.gz bcfg2-a4e78fbed539e83b639dd22b0662554c9e837e23.tar.bz2 bcfg2-a4e78fbed539e83b639dd22b0662554c9e837e23.zip |
drop privs options added, works in CherryPy
Diffstat (limited to 'src/lib/Bcfg2/Options.py')
-rw-r--r-- | src/lib/Bcfg2/Options.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/Bcfg2/Options.py b/src/lib/Bcfg2/Options.py index a436472e1..4fda79dfb 100644 --- a/src/lib/Bcfg2/Options.py +++ b/src/lib/Bcfg2/Options.py @@ -7,6 +7,8 @@ import os import re import shlex import sys +import grp +import pwd import Bcfg2.Client.Tools from Bcfg2.Compat import ConfigParser from Bcfg2.version import __version__ @@ -332,6 +334,24 @@ def get_bool(val): raise ValueError +def get_gid(val): + """ This takes a group name or gid and returns the corresponding + gid. """ + try: + return int(val) + except ValueError: + return int(grp.getgrnam(val)[2]) + + +def get_uid(val): + """ This takes a group name or gid and returns the corresponding + gid. """ + try: + return int(val) + except ValueError: + return int(pwd.getpwnam(val)[2]) + + # Options accepts keyword argument list with the following values: # default: default value for the option # cmd: command line switch @@ -522,6 +542,16 @@ SERVER_BACKEND = \ Option('Server Backend', default='best', cf=('server', 'backend')) +SERVER_DAEMON_USER = \ + Option('User to run the server daemon as', + default=0, + cf=('server', 'user'), + cook=get_uid) +SERVER_DAEMON_GROUP = \ + Option('Group to run the server daemon as', + default=0, + cf=('server', 'group'), + cook=get_gid) # database options DB_ENGINE = \ @@ -1000,7 +1030,9 @@ CLI_COMMON_OPTIONS = dict(configfile=CFILE, syslog=LOGGING_SYSLOG) DAEMON_COMMON_OPTIONS = dict(daemon=DAEMON, - listen_all=SERVER_LISTEN_ALL) + listen_all=SERVER_LISTEN_ALL, + daemon_uid=SERVER_DAEMON_USER, + daemon_gid=SERVER_DAEMON_GROUP) SERVER_COMMON_OPTIONS = dict(repo=SERVER_REPOSITORY, plugins=SERVER_PLUGINS, |