diff --git a/mkapachepw.py b/mkapachepw.py index 3b0959f..db2814f 100755 --- a/mkapachepw.py +++ b/mkapachepw.py @@ -9,7 +9,7 @@ # 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 @@ -99,16 +99,12 @@ ##### -# 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)", @@ -128,6 +124,8 @@ 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 ---------------------------------# @@ -267,39 +265,6 @@ ##### -# 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 ##### @@ -310,12 +275,14 @@ 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": @@ -354,6 +321,43 @@ 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 #####