#!/usr/bin/perl -w # # Copyright (c) 2001 Sean P. Scanlon # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # ########################################### use strict; use constant NIUTIL => '/usr/bin/niutil'; my ($nofiles_gid, $qmail_gid); my %users = ( 'alias' => [ 'nofiles', '/var/qmail/alias' ], 'qmaild' => [ 'nofiles', '/var/qmail' ], 'qmaill' => [ 'nofiles', '/var/qmail' ], 'qmailp' => [ 'nofiles', '/var/qmail' ], 'qmailr' => [ 'qmail', '/var/qmail' ], 'qmailq' => [ 'qmail', '/var/qmail' ], 'qmails' => [ 'qmail', '/var/qmail' ] ); $nofiles_gid = getNextAvailGID(); print "Creating group nofiles with GID: $nofiles_gid\n"; system( sprintf("%s -create / /groups/nofiles", NIUTIL) ); system( sprintf("%s -createprop / /groups/nofiles gid %d", NIUTIL, $nofiles_gid) ); $qmail_gid = getNextAvailGID(); print "Creating group qmail with GID: $qmail_gid\n"; system( sprintf("%s -create / /groups/qmail", NIUTIL) ); system( sprintf("%s -createprop / /groups/qmail gid %d", NIUTIL, $qmail_gid) ); my %groups = ( 'nofiles' => $nofiles_gid, 'qmail' => $qmail_gid, ); foreach my $user (sort keys %users ) { print "Creating user: $user\n"; system( sprintf("%s -create / /users/%s", NIUTIL, $user) ); system( sprintf("%s -createprop / /users/%s uid %d", NIUTIL, $user, getNextAvailUID() ) ); system( sprintf("%s -createprop / /users/%s gid %d", NIUTIL, $user, $groups{ $users{$user}->[0] })); system( sprintf("%s -createprop / /users/%s home %s", NIUTIL, $user, $users{$user}->[1])); system( sprintf("%s -createprop / /users/%s shell /nonexistent", NIUTIL, $user) ); system( sprintf("%s -createprop / /users/%s passwd NONE", NIUTIL, $user) ); system( sprintf("%s -createprop / /users/%s realname '%s mail user'", NIUTIL, $user, $user) ); } sub getNextAvailUID { my $uid = `/usr/bin/nireport . /users uid | sort -n | tail -1`; chomp($uid); return $uid + 1 if $uid =~ /^[0-9]+/; } sub getNextAvailGID { my $gid = `/usr/bin/nireport . /groups gid | sort -n | tail -1`; chomp($gid); return $gid + 1; }