1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#! /usr/bin/perl -Idebian/tests/lib
# check functionality of setting explicit UID
use diagnostics;
use strict;
use warnings;
use AdduserTestsCommon;
my @quiet=("--stdoutmsglevel=error", '--stderrmsglevel=error');
my @testsysuid;
my @testsysgid;
my @testuid;
my @testgid;
my $numofids=10;
my $i=200;
my $maxuidgid=900;
while( $i++ < $maxuidgid ) {
if( !defined( getpwuid($i) ) ) {
push(@testsysuid,$i);
if( $#testsysuid > $numofids ) {
last;
}
}
}
if( $#testsysuid <= $numofids ) {
fail( "cannot find enough free system uids below $maxuidgid" );
}
$i=200;
while( $i++ < $maxuidgid ) {
if( !defined( getgrgid($i) ) ) {
push(@testsysgid,$i);
if( $#testsysgid > $numofids ) {
last;
}
}
}
if( $#testsysgid <= $numofids ) {
fail( "cannot find enough free system gids below $maxuidgid" );
}
$i=20000;
$maxuidgid=29000;
while( $i++ < $maxuidgid ) {
if( !defined( getpwuid($i) ) ) {
push(@testuid,$i);
if( $#testuid > $numofids ) {
last;
}
}
}
if( $#testuid <= $numofids ) {
fail( "cannot find enough free uids below $maxuidgid" );
}
$i=20000;
while( $i++ < $maxuidgid ) {
if( !defined( getgrgid($i) ) ) {
push(@testgid,$i);
if( $#testgid > $numofids ) {
last;
}
}
}
if( $#testgid <= $numofids ) {
fail( "cannot find enough free gids below $maxuidgid" );
}
my $gid;
my $uid;
# create empty system group with set gid
my $test1="mygroup1";
$gid=pop(@testsysgid);
assert_command_success('/usr/sbin/addgroup', @quiet,
'--system', '--gid', $gid, $test1);
assert_group_exists($test1);
assert_gid_exists($gid);
assert_group_gid_exists($test1, $gid);
# create empty group with set gid
my $test2="mygroup2";
$gid=pop(@testgid);
assert_command_success('/usr/sbin/addgroup', @quiet,
'--gid', $gid, $test2);
assert_group_exists($test2);
assert_gid_exists($gid);
assert_group_gid_exists($test2, $gid);
# create system user with set uid
my $test3="myuser3";
$uid=pop(@testsysuid);
assert_command_success('/usr/sbin/adduser', @quiet,
'--system', '--uid', $uid, $test3);
assert_user_exists($test3);
assert_uid_exists($uid);
assert_user_uid_exists($test3, $uid);
# create user with set uid
my $test4="myuser4";
$uid=pop(@testuid);
assert_command_success('/usr/sbin/adduser', @quiet,
'--no-create-home',
'--comment', '""', '--disabled-password',
'--ingroup', $test1,
'--uid', $uid, $test4);
assert_user_exists($test4);
assert_uid_exists($uid);
assert_user_uid_exists($test4, $uid);
# create user in non existing group
my $test5="myuser5";
$uid=pop(@testuid);
assert_command_failure_silent('/usr/sbin/adduser', @quiet,
'--no-create-home',
'--ingroup', "does-not-exist",
'--comment', '""', '--disabled-password',
$test5);
assert_user_does_not_exist($test5);
assert_group_does_not_exist($test5);
# create user with set uid, allowing group creation
my $test6="myuser6";
$uid=pop(@testuid);
assert_command_success('/usr/sbin/adduser', @quiet,
'--no-create-home',
'--comment', '""', '--disabled-password',
'--uid', $uid, $test6);
assert_user_exists($test6);
assert_uid_exists($uid);
assert_user_uid_exists($test6, $uid);
assert_group_exists($test6);
# vim: tabstop=4 shiftwidth=4 expandtab
|