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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
#! /usr/bin/perl -Idebian/tests/lib
# N.B. This test script is intended to serve as living documentation of the
# default behavior one can expect when creating a new system user. It should
# match the behavior as specified in the adduser(8) man page and vice versa.
# user name aust stands for "adduser test"
use diagnostics;
use strict;
use warnings;
use AdduserTestsCommon;
# how do I use a module from the package in question?
#use AdduserRetvalues;
use constant RET_OK => 0;
use constant RET_OBJECT_EXISTS => 11;
use constant RET_OBJECT_DOES_NOT_EXIST => 12;
use constant RET_WRONG_OBJECT_PROPERTIES => 13;
use constant RET_NO_PRIMARY_GID => 23;
END {
remove_tree('/home/aust');
remove_tree('/var/mail/aust');
}
my $uid;
# Ref: https://www.debian.org/doc/debian-policy/ch-opersys.html#uid-and-gid-classes
for (100..999) {
next if defined(getpwuid($_));
$uid = $_;
last;
}
# check whether two identical calls in a row do succeed
# result in a policy compliant user
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_user_does_not_exist('aust');
assert_path_does_not_exist('/nonexistent');
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_user_has_home_directory('aust', '/nonexistent');
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_user_has_uid('aust', $uid);
assert_group_does_not_exist('aust');
assert_primary_group_membership_exists('aust', 'nogroup');
assert_user_has_home_directory('aust', '/nonexistent');
assert_path_does_not_exist('/nonexistent');
assert_user_has_login_shell('aust', '/usr/sbin/nologin');
assert_user_has_disabled_password('aust');
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1004710
assert_path_does_not_exist('/var/mail/aust');
while (defined(getpwuid($uid))) {
$uid++;
}
assert_user_does_not_exist('aust2');
assert_path_does_not_exist('/nonexistent');
# create account with specified shell
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--shell', '/bin/sh',
'aust2'
);
assert_user_exists('aust2');
assert_user_is_system('aust');
assert_user_has_uid('aust2', $uid);
assert_group_does_not_exist('aust2');
assert_primary_group_membership_exists('aust2', 'nogroup');
assert_user_has_home_directory('aust2', '/nonexistent');
assert_path_does_not_exist('/nonexistent');
assert_user_has_login_shell('aust2', '/bin/sh');
assert_user_has_disabled_password('aust2');
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1004710
assert_path_does_not_exist('/var/mail/aust2');
# Ref: bug #1099470, create and recreate a passwordless account
# (this is actually the same as without --disabled password, but
# some packages still call that explicitly)
# This might cause some grief when we address #1008082 - #1008084
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_user_does_not_exist('aust');
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-password',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-password',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
# Ref: bug #1099470, create and recreate a locked account
# This might cause some grief when we address #1008082 - #1008084
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_user_does_not_exist('aust');
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-login',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-login',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
# create an account, set password to
# *, !, *something, !something
# explicitly, try to recreate account
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_user_does_not_exist('aust');
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-login',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
system('echo "aust:*" | chpasswd --encrypted');
ok(1, "set passwd to *");
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-login',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
system('echo "aust:!foobar" | chpasswd --encrypted');
# with #1099734 fixed, this should fail
assert_command_result_silent(RET_WRONG_OBJECT_PROPERTIES,
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-login',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
system('echo "aust:*foobar" | chpasswd --encrypted');
ok(1, "set passwd to *foobar");
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'--disabled-login',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
# ref #100032
# test --home
# we are testing with stdoutmsglevel warn so that we can catch
# non-silence on console.
# nb: adduser with pre-existing home directory with correct owner cannot
# be tested, and that would also be a coincidence.
# --home /var/lib/aust with directory not present
my $homedir='/var/lib/aust';
unlink($homedir);
rmdir($homedir);
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=warn',
'--home', $homedir,
'--no-create-home',
'--system',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_path_does_not_exist($homedir);
assert_user_has_home_directory('aust', $homedir);
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=warn',
'--home', $homedir,
'--system',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_path_is_a_directory($homedir);
assert_user_has_home_directory('aust', $homedir);
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
# --home /var/lib/aust with directory present and incorrect owner
mkdir($homedir);
chown(0, 0, $homedir);
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=warn',
'--home', $homedir,
'--system',
'aust'
);
assert_user_exists('aust');
assert_user_is_system('aust');
assert_path_is_a_directory($homedir);
assert_user_has_home_directory('aust', $homedir);
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
# clean up
# en passant test delgroup and deluser --group
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_command_success(
'/usr/sbin/deluser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust2'
);
assert_command_success(
'/usr/sbin/delgroup',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust'
);
assert_command_success(
'/usr/sbin/deluser',
'--group',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
'--system',
'aust2'
);
assert_user_does_not_exist('aust');
assert_user_does_not_exist('aust2');
assert_group_does_not_exist('aust');
assert_group_does_not_exist('aust2');
# vim: tabstop=4 shiftwidth=4 expandtab
|