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
|
#!/usr/bin/perl -w
# expect:
# - a new non-system group $groupname
# - reading the group fails
# - reading the group as a system group fails
# - a new system group $groupname
# - reading the group succeeds
# - reading the group as a non-system group fails
use strict;
use lib_test;
my $error;
my $output;
my $groupname = find_unused_name();
my $cmd = "addgroup $groupname";
if (!defined (getgrnam($groupname))) {
print "Testing (9.1) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error) {
print "failed\n $cmd returned an errorcode != 0 ($error)\n";
exit $error;
}
assert(check_group_exist ($groupname));
print "ok\n";
}
# now testing whether adding the group again fails as it should
print "Testing (9.2) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error ne 11) {
print "failed\n $cmd returned an errorcode != 11 ($error)\n";
exit 1;
}
if ($output !~ /^fatal: The group `addusertest\d+' already exists\.\n$/ ) {
print "failed\n $cmd returned unexpected output ($output)\n";
exit 1;
}
print "ok\n";
# now testing whether adding the group again (as a system group)
# fails as it should (#405905)
$cmd = "addgroup --system $groupname";
print "Testing (9.3) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error ne 13) {
print "failed\n $cmd returned an errorcode != 13 ($error)\n";
exit $error;
}
if ($output !~ /^fatal: The group `addusertest\d+' already exists, but is not a system group. Exiting.$/ ) {
print "failed\n $cmd returned unexpected output ($output)\n";
exit 1;
}
print "ok\n";
# now testing whether trying to delete the group with --remove-home
# fails as it should
$cmd = "delgroup --system --remove-home $groupname";
print "Testing (9.4) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error ne 53) {
print "failed\n $cmd returned an errorcode != 53 ($error)\n";
exit $error;
}
print "ok\n";
my $sysgroupname = find_unused_name();
$cmd = "addgroup --system $sysgroupname";
if (!defined (getgrnam($sysgroupname))) {
print "Testing (9.5) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error) {
print "failed\n $cmd returned an errorcode != 0 ($error)\n";
exit $error;
}
assert(check_group_exist ($sysgroupname));
print "ok\n";
}
# now testing whether adding the group again passes as it should
# ("already exists as a system group")
$cmd = "addgroup --system $sysgroupname" ;
print "Testing (9.6) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error) {
print "failed\n $cmd returned an errorcode != 0 ($error)\n";
exit $error;
}
print "ok\n";
# now testing whether adding the group again (as a regular group)
# fails as it should
$cmd = "addgroup $sysgroupname";
print "Testing (9.7) $cmd... ";
$output=`$cmd 2>&1`;
$error = ($?>>8);
if ($error ne 11) {
print "failed\n $cmd returned an errorcode != 11 ($error)\n";
exit 1;
}
if ($output !~ /^fatal: The group `addusertest\d+' already exists\.$/ ) {
print "failed\n $cmd returned unexpected output ($output)\n";
exit 1;
}
print "ok\n";
|