Added -s command line flag to suppress processing of system groups/users.
1 parent 4ae8b5d commit 081586c74745f47a110d81e455531849bb543981
@toor toor authored on 6 Apr 2005
Showing 1 changed file
View
87
mkapachepw.py
 
# Program Information
 
PROGNAME = "mkapachepw"
RCSID = "$Id: mkapachepw.py,v 1.115 2005/04/06 06:18:21 toor Exp $"
RCSID = "$Id: mkapachepw.py,v 1.116 2005/04/06 06:31:42 toor Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
eNOPREFIX = "'%s' Must Be Prefixed With '+' or '-' To Indicate Desired Action."
 
 
#####
# Informational Messages
#####
 
 
#####
# Usage Prompts
#####
 
uTable = [PROGNAME + " " + VERSION + " - %s\n" % COPYRIGHT,
"usage: " + PROGNAME + " [-GUguIihv] where,\n",
"usage: " + PROGNAME + " [-sGUguIihv] where,\n",
" -s do not process system password/group files (default: process these files)",
" -G list of groups to include (+group | +GID) or exclude (-group | -GID) (default: none)",
" -U list of users to include (+user | + UID) or exclude (-user | -UID) (default: none)",
" -g # smallest GID to include in output (default: 100)",
" -u # smallest UID to include in output (default: 100)",
 
enumerated = [] # Place to store command line in/exclude enumerations
groups = {} # Place to store group information
users = {} # Place to store user information
 
SYSFILES = True # Flag to enable/disable inclusion of system group/pw
 
 
#--------------------------- Code Begins Here ---------------------------------#
 
#----------------------------------------------------------#
 
 
#####
# Build An Internal List Of Groups And Users Before Doing Anything Else.
# Command Line Parsing May Need This Information.
#####
 
Protected = False
 
#####
# Build List Of Groups
#####
 
for group in grp.getgrall():
 
gname, gpw, gid, gmembers = group[:4]
 
groups[gname] = [gid, [], Protected]
for member in gmembers:
groups[gname][1].append(member)
 
#####
# Build A List Of Users
#####
 
for user in pwd.getpwall():
 
uname, pw, uid, gid = user[:4]
gname = grp.getgrgid(gid)[0]
users[uname] = [uid, pw, Protected]
if uname not in groups[gname][1]:
groups[gname][1].append(uname)
 
 
#####
# Command line processing - Process any options set in the
# environment first, and then those given on the command line
#####
 
if envopt:
OPTIONS = envopt.split() + OPTIONS
 
try:
opts, args = getopt.getopt(OPTIONS, '-G:U:g:u:I:i:hv')
opts, args = getopt.getopt(OPTIONS, '-sG:U:g:u:I:i:hv')
except getopt.GetoptError:
Usage()
sys.exit(1)
 
for opt, val in opts:
if opt == "-s":
SYSFILES = False
if opt == "-G":
enumerated.append([val, grp.getgrgid, GROUP])
if opt == "-U":
enumerated.append([val, pwd.getpwuid, USER])
Usage()
sys.exit(1)
 
#####
# Build List Of System Groups And Users
#####
 
 
# Can be suppressed with the -s command line argument
 
if SYSFILES:
Protected = False
 
#####
# Build List Of Groups
#####
 
for group in grp.getgrall():
 
gname, gpw, gid, gmembers = group[:4]
 
groups[gname] = [gid, [], Protected]
for member in gmembers:
groups[gname][1].append(member)
 
#####
# Build A List Of Users
#####
 
for user in pwd.getpwall():
 
uname, pw, uid, gid = user[:4]
gname = grp.getgrgid(gid)[0]
 
users[uname] = [uid, pw, Protected]
if uname not in groups[gname][1]:
groups[gname][1].append(uname)
 
 
#####
# Process Any Enumerated Inclusions/Exclusions
#####
 
for enum in enumerated: