new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / init / darwin-addusers.pl
1 #!/usr/bin/env perl
2 #######################################
3 # Name:    ossec-add-ung.pl
4 # Desc:    Add ossec users and groups on OSX using the NetInfo cmds
5 # Author:  Chuck L.
6 # License: GPL
7 ###
8 # for vi: set tabstop=4
9 #######################################
10
11 # Variables and whatnot
12 my ($debug, $oUid, $oGid, @inUseUids, @inUseGids, $rev, $revDate);
13 $rev     = '0.2-1';
14 $revDate = '30-Aug-2006';
15 $debug   = '0';
16 $fName   = "/tmp/niusers.tmp";
17
18 # Commands
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";
25
26 # Subroutine calls
27 findUsersGroups();
28 createUsersGroups();
29
30 sub findUsersGroups {
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`;
33
34     foreach (@inUseUids) {
35         chomp();
36         print "In use UID: $_\n" if $debug;
37         if ($oUid < $_) {
38             $oUid = $_;
39         }
40     }
41     $oUid++;
42     print "Next available UID: $oUid\n" if $debug;
43
44     foreach (@inUseGids) {
45         chomp();
46         print "In use GID: $_\n" if $debug;
47         if ($oGid < $_) {
48             $oGid = $_;
49         }
50     }
51     $oGid++;
52     print "Next available GID: $oGid\n" if $debug;
53 } # end sub
54
55 sub createUsersGroups {
56     print "Sub - UID is: $oUid\n" if $debug;
57     print "Sub - GID is: $oGid\n" if $debug;
58
59     my $oUidM = $oUid + 1;
60     my $oUidE = $oUid + 2;
61     my $oUidR = $oUid + 3;
62
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";
66     close (NIFH);
67
68     $fh = open (NITMP, ">$fName") or die "Unable to create temp file: $!\n";
69
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";
74
75     close ($fh);
76     $rtnVal = system("$SUDO $NILOAD -v passwd / < $fName");
77     print "Return value from syscmd: $rtnVal\n" if $debug;
78     unlink ($fName);
79
80 } # end sub
81