2 #######################################
3 # Name: ossec-add-ung.pl
4 # Desc: Add ossec users and groups on OSX using the NetInfo cmds.
8 # for vi: set tabstop=4
11 # v0.1 - Initial coding.
12 # v0.2 - Modified script to use subroutines. It gets the job done,
13 # but more work required to add further functionality. -CL
14 # v0.2.1 - Modified the user add lines to have the users disabled
15 # from the start ('*' was missing in passwd field). -CL
16 #######################################
18 # Variables and whatnot
19 my ($debug, $oUid, $oGid, @inUseUids, @inUseGids, $rev, $revDate);
21 $revDate = '30-Aug-2006';
23 $fName = "/tmp/niusers.tmp";
26 $NILOAD = "/usr/bin/niload";
27 $NIRPT = "/usr/bin/nireport";
28 $NIUTIL = "/usr/bin/niutil";
29 $SORT = "/usr/bin/sort";
30 $GREP = "/usr/bin/grep";
31 $SUDO = "/usr/bin/sudo";
37 #######################################
38 #######################################
40 #######################################
42 @inUseUids = `$NIRPT . /users uid | $GREP "^5[0-9][0-9]" | $SORT -ru`;
43 @inUseGids = `$NIRPT . /groups gid | $GREP "^5[0-9][0-9]" | $SORT -ru`;
45 foreach (@inUseUids) {
47 print "In use UID: $_\n" if $debug;
53 print "Next available UID: $oUid\n" if $debug;
55 foreach (@inUseGids) {
57 print "In use GID: $_\n" if $debug;
63 print "Next available GID: $oGid\n" if $debug;
66 sub createUsersGroups {
67 print "Sub - UID is: $oUid\n" if $debug;
68 print "Sub - GID is: $oGid\n" if $debug;
70 my $oUidM = $oUid + 1;
71 my $oUidE = $oUid + 2;
72 my $oUidR = $oUid + 3;
74 $niPid = open (NIFH, "| $SUDO $NILOAD -v group /");
75 print "Adding ossec group\n" if $debug;
76 print NIFH "ossec:*:" . $oGid . ":ossec,ossecm,ossecr\n";
79 $fh = open (NITMP, ">$fName") or die "Unable to create temp file: $!\n";
81 print "Adding ossec users\n" if $debug;
82 print NITMP "ossec:*:" . $oUid . ":" . $oGid . "::0:0:ossec acct:/var/ossec:/sbin/nologin\n";
83 print NITMP "ossecm:*:" . $oUidM . ":" . $oGid . "::0:0:ossecm acct:/var/ossec:/sbin/nologin\n";
84 print NITMP "ossecr:*:" . $oUidR . ":" . $oGid . "::0:0:ossecr acct:/var/ossec:/sbin/nologin\n";
87 $rtnVal = system("$SUDO $NILOAD -v passwd / < $fName");
88 print "Return value from syscmd: $rtnVal\n" if $debug;