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
9 #######################################
11 # Variables and whatnot
12 my ($debug, $oUid, $oGid, @inUseUids, @inUseGids, $rev, $revDate);
14 $revDate = '30-Aug-2006';
16 $fName = "/tmp/niusers.tmp";
19 $NILOAD = "/usr/bin/niload";
20 $NIRPT = "/usr/bin/nireport";
21 $NIUTIL = "/usr/bin/niutil";
22 $SORT = "/usr/bin/sort";
23 $GREP = "/usr/bin/grep";
24 $SUDO = "/usr/bin/sudo";
31 @inUseUids = `$NIRPT . /users uid | $GREP "^5[0-9][0-9]" | $SORT -ru`;
32 @inUseGids = `$NIRPT . /groups gid | $GREP "^5[0-9][0-9]" | $SORT -ru`;
34 foreach (@inUseUids) {
36 print "In use UID: $_\n" if $debug;
42 print "Next available UID: $oUid\n" if $debug;
44 foreach (@inUseGids) {
46 print "In use GID: $_\n" if $debug;
52 print "Next available GID: $oGid\n" if $debug;
55 sub createUsersGroups {
56 print "Sub - UID is: $oUid\n" if $debug;
57 print "Sub - GID is: $oGid\n" if $debug;
59 my $oUidM = $oUid + 1;
60 my $oUidE = $oUid + 2;
61 my $oUidR = $oUid + 3;
63 $niPid = open (NIFH, "| $SUDO $NILOAD -v group /");
64 print "Adding ossec group\n" if $debug;
65 print NIFH "ossec:*:" . $oGid . ":ossec,ossecm,ossecr\n";
68 $fh = open (NITMP, ">$fName") or die "Unable to create temp file: $!\n";
70 print "Adding ossec users\n" if $debug;
71 print NITMP "ossec:*:" . $oUid . ":" . $oGid . "::0:0:ossec acct:/var/ossec:/sbin/nologin\n";
72 print NITMP "ossecm:*:" . $oUidM . ":" . $oGid . "::0:0:ossecm acct:/var/ossec:/sbin/nologin\n";
73 print NITMP "ossecr:*:" . $oUidR . ":" . $oGid . "::0:0:ossecr acct:/var/ossec:/sbin/nologin\n";
76 $rtnVal = system("$SUDO $NILOAD -v passwd / < $fName");
77 print "Return value from syscmd: $rtnVal\n" if $debug;