[Pkg-shadow-devel] [Git][debian/adduser][master] 3 commits: streamline formatting of adduser_system.d
Marc Haber (@zugschlus)
gitlab at salsa.debian.org
Sat Mar 15 20:57:25 GMT 2025
Marc Haber pushed to branch master at Debian / adduser
Commits:
52e4b268 by Marc Haber at 2025-03-15T17:54:29+01:00
streamline formatting of adduser_system.d
Git-Dch: ignore
- - - - -
40f4910f by Marc Haber at 2025-03-15T18:45:46+01:00
test adduser --home while checking stderr
Git-Dch: ignore
- - - - -
ec43b0c6 by Marc Haber at 2025-03-15T21:56:34+01:00
make adduser --system --home silent if directory exists
Closes: #1100032
- - - - -
2 changed files:
- adduser
- debian/tests/f/adduser_system.t
Changes:
=====================================
adduser
=====================================
@@ -680,7 +680,7 @@ if ($action eq "addsysuser") {
}
$primary_gid = $gid_option;
- create_homedir(0);
+ create_homedir(0, 1);
exit( $returnvalue );
}
@@ -919,7 +919,7 @@ if ($action eq "adduser") {
$returnvalue = RET_INVALID_NAME_FROM_USERADD;
}
- create_homedir (1); # copy skeleton data
+ create_homedir (1, 0); # copy skeleton data
# useradd without -p has left the account disabled (password string is '!')
my $yesexpr = langinfo(YESEXPR());
@@ -1054,20 +1054,22 @@ sub homedir {
# return values:
# none
sub create_homedir {
- my ($copy_skeleton) = @_;
+ my ($copy_skeleton, $system_user) = @_;
if ($home_dir =~ /^\/+nonexistent(\/|$)/) {
log_info( mtx("Not creating `%s'."), $home_dir );
} elsif ($no_create_home) {
log_info( mtx("Not creating home directory `%s' as requested."), $home_dir );
} elsif (-e $home_dir) {
- log_warn( mtx("The home directory `%s' already exists. Not touching this directory."),
- $home_dir );
- my @homedir_stat = stat($home_dir);
- my $home_uid = $homedir_stat[4];
- my $home_gid = $homedir_stat[5];
- if (($home_uid != $new_uid) || ($home_gid != $primary_gid)) {
- log_warn( mtx("Warning: The home directory `%s' does not belong to the user you are currently creating."), $home_dir );
+ if( !$system_user ) {
+ log_warn( mtx("The home directory `%s' already exists. Not touching this directory."),
+ $home_dir );
+ my @homedir_stat = stat($home_dir);
+ my $home_uid = $homedir_stat[4];
+ my $home_gid = $homedir_stat[5];
+ if (($home_uid != $new_uid) || ($home_gid != $primary_gid)) {
+ log_warn( mtx("Warning: The home directory `%s' does not belong to the user you are currently creating."), $home_dir );
+ }
}
} else {
log_info( mtx("Creating home directory `%s' ..."),$home_dir );
=====================================
debian/tests/f/adduser_system.t
=====================================
@@ -30,24 +30,31 @@ for (100..999) {
# 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_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_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_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);
@@ -72,11 +79,13 @@ 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_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);
@@ -98,109 +107,213 @@ assert_path_does_not_exist('/var/mail/aust2');
# (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_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',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-password',
- 'aust');
+ 'aust'
+);
assert_user_exists('aust');
assert_user_is_system('aust');
-assert_command_success('/usr/sbin/adduser',
- '--stdoutmsglevel=error', '--stderrmsglevel=error',
- '--system',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-password',
- 'aust');
+ '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_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',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-login',
- 'aust');
+ 'aust'
+);
assert_user_exists('aust');
assert_user_is_system('aust');
-assert_command_success('/usr/sbin/adduser',
- '--stdoutmsglevel=error', '--stderrmsglevel=error',
- '--system',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-login',
- 'aust');
+ '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_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',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-login',
- 'aust');
+ 'aust'
+);
assert_user_exists('aust');
assert_user_is_system('aust');
system('echo "aust:*" | chpasswd --encrypted');
-assert_command_success('/usr/sbin/adduser',
- '--stdoutmsglevel=error', '--stderrmsglevel=error',
- '--system',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-login',
- 'aust');
+ 'aust'
+);
assert_user_exists('aust');
assert_user_is_system('aust');
system('echo "aust:!foobar" | chpasswd --encrypted');
-assert_command_success('/usr/sbin/adduser',
- '--stdoutmsglevel=error', '--stderrmsglevel=error',
- '--system',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-login',
- 'aust');
+ 'aust'
+);
assert_user_exists('aust');
assert_user_is_system('aust');
system('echo "aust:*foobar" | chpasswd --encrypted');
-assert_command_success('/usr/sbin/adduser',
- '--stdoutmsglevel=error', '--stderrmsglevel=error',
- '--system',
+assert_command_success(
+ '/usr/sbin/adduser',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
'--disabled-login',
- 'aust');
+ '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
-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/delgroup',
- '--stdoutmsglevel=error', '--stderrmsglevel=error',
- '--system',
- 'aust2');
+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/delgroup',
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--system',
+ 'aust2'
+);
# vim: tabstop=4 shiftwidth=4 expandtab
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/1ac4e0ff28853c7775a9812837722f0830e297e1...ec43b0c63ad323267177362948955d8ecbdfdf94
--
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/1ac4e0ff28853c7775a9812837722f0830e297e1...ec43b0c63ad323267177362948955d8ecbdfdf94
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-shadow-devel/attachments/20250315/405564de/attachment-0001.htm>
More information about the Pkg-shadow-devel
mailing list