diff options
author | Tim Laszlo <tim.laszlo@gmail.com> | 2012-12-03 16:16:41 -0600 |
---|---|---|
committer | Tim Laszlo <tim.laszlo@gmail.com> | 2012-12-03 16:16:41 -0600 |
commit | 350db854319af526818c2ffcac285ae445b0213d (patch) | |
tree | d13d486ab856c37ad194653f46ac329bb75b3338 /tools | |
parent | a8c2c14b0bf39d101f3ecc4b3aafc01fabad02d5 (diff) | |
parent | 2983b0c358ef25e7c34ccdeb3ab1f8d6a6f9ae90 (diff) | |
download | bcfg2-350db854319af526818c2ffcac285ae445b0213d.tar.gz bcfg2-350db854319af526818c2ffcac285ae445b0213d.tar.bz2 bcfg2-350db854319af526818c2ffcac285ae445b0213d.zip |
Merge branch 'master' of github.com:Bcfg2/bcfg2
Diffstat (limited to 'tools')
-rw-r--r-- | tools/README | 4 | ||||
-rwxr-xr-x | tools/posixusers_baseline.py | 73 |
2 files changed, 77 insertions, 0 deletions
diff --git a/tools/README b/tools/README index 400cfc55c..335363898 100644 --- a/tools/README +++ b/tools/README @@ -82,6 +82,10 @@ pkgmgr_update.py - Update Pkgmgr XML files from a list of directories that contain RPMS +posixusers_baseline.py + - Create a Bundle with all base POSIXUser/POSIXGroup entries on a + client. + rpmlisting.py - Generate Pkgmgr XML files for RPM packages diff --git a/tools/posixusers_baseline.py b/tools/posixusers_baseline.py new file mode 100755 index 000000000..a4abca42d --- /dev/null +++ b/tools/posixusers_baseline.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python + +import grp +import sys +import logging +import lxml.etree +import Bcfg2.Logger +from Bcfg2.Client.Tools.POSIXUsers import POSIXUsers +from Bcfg2.Options import OptionParser, Option, get_bool, CLIENT_COMMON_OPTIONS + + +def get_setup(): + optinfo = CLIENT_COMMON_OPTIONS + optinfo['nouids'] = Option("Do not include UID numbers for users", + default=False, + cmd='--no-uids', + long_arg=True, + cook=get_bool) + optinfo['nogids'] = Option("Do not include GID numbers for groups", + default=False, + cmd='--no-gids', + long_arg=True, + cook=get_bool) + setup = OptionParser(optinfo) + setup.parse(sys.argv[1:]) + + if setup['args']: + print("posixuser_[baseline.py takes no arguments, only options") + print(setup.buildHelpMessage()) + raise SystemExit(1) + level = 30 + if setup['verbose']: + level = 20 + if setup['debug']: + level = 0 + Bcfg2.Logger.setup_logging('posixusers_baseline.py', + to_syslog=False, + level=level, + to_file=setup['logging']) + return setup + + +def main(): + setup = get_setup() + if setup['file']: + config = lxml.etree.parse(setup['file']).getroot() + else: + config = lxml.etree.Element("Configuration") + users = POSIXUsers(logging.getLogger('posixusers_baseline.py'), + setup, config) + + baseline = lxml.etree.Element("Bundle", name="posixusers_baseline") + for entry in users.FindExtra(): + data = users.existing[entry.tag][entry.get("name")] + for attr, idx in users.attr_mapping[entry.tag].items(): + if (entry.get(attr) or + (attr == 'uid' and setup['nouids']) or + (attr == 'gid' and setup['nogids'])): + continue + entry.set(attr, str(data[idx])) + if entry.tag == 'POSIXUser': + entry.set("group", grp.getgrgid(data[3])[0]) + for group in users.user_supplementary_groups(entry): + memberof = lxml.etree.SubElement(entry, "MemberOf") + memberof.text = group[0] + + entry.tag = "Bound" + entry.tag + baseline.append(entry) + + print(lxml.etree.tostring(baseline, pretty_print=True)) + +if __name__ == "__main__": + sys.exit(main()) |