[Pkg-shadow-devel] [Git][debian/adduser][master] 5 commits: deluser does not error out if File::Find missing
Marc Haber (@zugschlus)
gitlab at salsa.debian.org
Fri Mar 28 11:23:18 GMT 2025
Marc Haber pushed to branch master at Debian / adduser
Commits:
2328eedb by Marc Haber at 2025-03-28T12:20:48+01:00
deluser does not error out if File::Find missing
It errors out when --system is not given. If --system, it's only
a warning
- - - - -
7130f9d6 by Marc Haber at 2025-03-28T12:21:31+01:00
add check_dir_exist
Git-Dch: ignore
- - - - -
085710bd by Marc Haber at 2025-03-28T12:21:53+01:00
avoid deluser --remove-home if --remove-home is not being tested
Git-Dch: ignore
- - - - -
14b21bee by Marc Haber at 2025-03-28T12:22:19+01:00
rework test2.pl to handle File::Find not being present
And to test handling of --remove-home in both cases
Git-Dch: ignore
- - - - -
f2db0a59 by Marc Haber at 2025-03-28T12:22:46+01:00
run upstream test suite a second time without dependencies
Git-Dch: ignore
- - - - -
6 changed files:
- debian/tests/control
- deluser
- testsuite/lib_test.pm
- testsuite/test1.pl
- testsuite/test2.pl
- testsuite/test8.pl
Changes:
=====================================
debian/tests/control
=====================================
@@ -8,6 +8,11 @@ Depends: adduser, cron, perl, login
Restrictions: allow-stderr breaks-testbed needs-root
Features: test-name=upstream-test-suite-full
+Test-Command: cd testsuite/ && ./runsuite.sh
+Depends: adduser, login
+Restrictions: allow-stderr breaks-testbed needs-root
+Features: test-name=upstream-test-suite-minimal
+
Test-Command: /usr/sbin/adduser --system austc3
Depends: adduser, login
Restrictions: needs-root
=====================================
deluser
=====================================
@@ -234,12 +234,6 @@ foreach(keys(%pconfig)) {
$config{$_} = decode($charset, $pconfig{$_}) if ($pconfig{$_});
}
-if (($config{remove_home} || $config{remove_all_files} || $config{backup}) && ($install_more_packages)) {
- log_fatal( mtx("In order to use the --remove-home, --remove-all-files, and --backup features, you need to install the `perl' package. To accomplish that, run apt-get install perl.") );
- exit( RET_MORE_PACKAGES );
-}
-
-
my ($name, $passwd, $pw_uid, $pw_gid, $quota, $comment, $gcos, $pw_homedir, $shell, $expire, $maingroup);
if(defined($user)) {
@@ -273,6 +267,14 @@ if($action eq "deluser") {
# Also, "user does not exist" is only a warning with --system, but an
# error without --system.
if( $config{"system"} ) {
+ if (($config{remove_home} || $config{remove_all_files} || $config{backup}) && ($install_more_packages)) {
+ log_warn( mtx("In order to use the --remove-home, --remove-all-files, and --backup features, you need to install the `perl' package. To accomplish that, run apt-get install perl.") );
+ $config{remove_home}=undef;
+ $config{remove_all_files}=undef;
+ $config{backup}=undef;
+ $config{backup_to}=undef;
+ }
+
if( ($name, $passwd, $uid, $rest) = egetpwnam(encode($charset, $user)) ) {
if ( ($uid < $config{"first_system_uid"} ||
$uid > $config{"last_system_uid" } ) ) {
@@ -283,6 +285,11 @@ if($action eq "deluser") {
log_info( mtx("The user `%s' does not exist, but --system was given. Exiting."), $user);
exit( RET_OK );
}
+ } else {
+ if (($config{remove_home} || $config{remove_all_files} || $config{backup}) && ($install_more_packages)) {
+ log_fatal( mtx("In order to use the --remove-home, --remove-all-files, and --backup features, you need to install the `perl' package. To accomplish that, run apt-get install perl.") );
+ exit( RET_MORE_PACKAGES );
+ }
}
unless(exist_user($user)) {
=====================================
testsuite/lib_test.pm
=====================================
@@ -137,6 +137,16 @@ sub check_homedir_exist {
}
+sub check_dir_exist {
+ my ($dir) = @_;
+ if (! -d $dir) {
+ print "check_dir_exist: $dir does not exist\n";
+ return 1;
+ }
+ return 0;
+}
+
+
sub check_homedir_not_exist {
my ($homedir) = @_;
if ( -d $homedir) {
=====================================
testsuite/test1.pl
=====================================
@@ -27,7 +27,7 @@ if (!defined (getpwnam($username))) {
print "ok\n";
}
-$cmd = "deluser --remove-home $username";
+$cmd = "deluser $username";
if (defined (getpwnam($username))) {
my $homedir = (getpwnam($username))[7];
print "Testing $cmd... ";
=====================================
testsuite/test2.pl
=====================================
@@ -9,36 +9,134 @@
use strict;
use lib_test;
+my $file_find_present;
+
+BEGIN {
+ local $ENV{PERL_DL_NONLAZY}=1;
+ $file_find_present=1;
+ eval {
+ require File::Find;
+ };
+ if ($@) {
+ $file_find_present = 0;
+ }
+}
+
my $groupname = "nogroup";
my $username = find_unused_name();
my $homedir = "/home/$username";
-my $cmd = "adduser --system --home $homedir $username";
-
-if (!defined (getpwnam($username))) {
- print "Testing $cmd... ";
- `$cmd`;
- my $error = ($?>>8);
- if ($error) {
- print "failed\n adduser returned an errorcode != 0 ($error)\n";
- exit $error;
- }
- assert(check_user_exist ($username));
- assert(check_homedir_exist($username,$homedir));
- assert(check_group_exist($groupname));
- assert(check_user_in_group ($username,$groupname));
- print "ok\n";
+my $cmd;
+
+sub create_user {
+ my ($username, $groupname, $system, $homedir) = (@_);
+ my $cmd;
+ if( $system ) {
+ $cmd = "adduser --system --home $homedir $username";
+ } else {
+ $cmd = "adduser --disabled-password --comment foo --home $homedir $username";
+ }
+
+ if (!defined (getpwnam($username))) {
+ print "Testing $cmd... ";
+ `$cmd`;
+ my $error = ($?>>8);
+ if ($error) {
+ print "failed\n adduser returned an errorcode != 0 ($error)\n";
+ exit $error;
+ }
+ assert(check_user_exist ($username));
+ assert(check_homedir_exist($username, $homedir));
+ if( $system ) {
+ assert(check_group_exist($groupname));
+ assert(check_user_in_group ($username,$groupname));
+ } else {
+ assert(check_group_exist($username));
+ assert(check_user_in_group ($username,$username));
+ }
+ print "ok\n";
+ }
+}
+
+create_user($username, $groupname, 1, $homedir);
+# deluser without --remove-home _must_ always work
+$cmd = "deluser $username";
+if (defined (getpwnam($username))) {
+ print "Testing $cmd... ";
+ `$cmd`;
+ my $error = ($?>>8);
+ if ($error) {
+ print "failed\n deluser returned an errorcode != 0 ($error)\n";
+ exit $error;
+ }
+ assert(check_user_not_exist ($username));
+ assert(check_dir_exist($homedir));
+ `rm -rf $homedir`;
+ print "ok\n";
}
+create_user($username, $groupname, 0, $homedir);
+# deluser without --remove-home _must_ always work
+$cmd = "deluser $username";
+if (defined (getpwnam($username))) {
+ print "Testing $cmd... ";
+ `$cmd`;
+ my $error = ($?>>8);
+ if ($error) {
+ print "failed\n deluser returned an errorcode != 0 ($error)\n";
+ exit $error;
+ }
+ assert(check_user_not_exist ($username));
+ assert(check_dir_exist($homedir));
+ `rm -rf $homedir`;
+ print "ok\n";
+}
+
+create_user($username, $groupname, 1, $homedir);
+# deluser --system with --remove-home may spew a warning but must exit successfully
+$cmd = "deluser --system --remove-home $username";
+if (defined (getpwnam($username))) {
+ print "Testing $cmd... ";
+ `$cmd`;
+ my $error = ($?>>8);
+ if ($error) {
+ print "failed\n deluser returned an errorcode != 0 ($error)\n";
+ exit $error;
+ }
+ assert(check_user_not_exist ($username));
+ if( $file_find_present ) {
+ assert(check_homedir_not_exist($homedir));
+ } else {
+ assert(check_dir_exist($homedir));
+ `rm -rf $homedir`;
+ }
+ print "ok\n";
+}
+
+create_user($username, $groupname, 0, $homedir);
+# deluser with --remove-home may error out without File::Find
$cmd = "deluser --remove-home $username";
if (defined (getpwnam($username))) {
- print "Testing $cmd... ";
- `$cmd`;
- my $error = ($?>>8);
- if ($error) {
- print "failed\n deluser returned an errorcode != 0 ($error)\n";
- exit $error;
- }
- assert(check_user_not_exist ($username));
- assert(check_homedir_not_exist($homedir));
- print "ok\n";
+ print "Testing $cmd... ";
+ `$cmd`;
+ my $error = ($?>>8);
+ if ($error) {
+ if( $file_find_present ) {
+ print "failed\n deluser returned an errorcode != 0 ($error)\n";
+ exit $error;
+ } else {
+ if( $error == 56 ) {
+ `deluser $username`;
+ } else {
+ print "failed\n deluser (file::find not present) returned an errorcode != 0/56 ($error)\n";
+ }
+ print "failed\n deluser (file::find not present) returned an errorcode != 0 ($error)\n";
+ $error=0;
+ `rm -rf $homedir`;
+ }
+ }
+ assert(check_user_not_exist ($username));
+ assert(check_homedir_not_exist($homedir));
+ print "ok\n";
}
+
+# vim: tabstop=4 shiftwidth=4 expandtab
=====================================
testsuite/test8.pl
=====================================
@@ -64,7 +64,7 @@ if (defined (getpwnam($username))) {
print "ok\n";
}
-$cmd = "deluser --remove-home $username";
+$cmd = "deluser $username";
if (defined (getpwnam($username))) {
print "Testing $cmd... ";
`$cmd`;
@@ -75,6 +75,7 @@ if (defined (getpwnam($username))) {
}
assert(check_user_not_exist ($username));
print "ok\n";
+ `rm -rf /home/$username`;
}
$cmd = "delgroup $newgroup";
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/3ed813576e5df8197992130f7e343c246cce6f4e...f2db0a59e384d0de4688229ce9aaa0993efb8db4
--
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/3ed813576e5df8197992130f7e343c246cce6f4e...f2db0a59e384d0de4688229ce9aaa0993efb8db4
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/20250328/8ceaac6b/attachment-0001.htm>
More information about the Pkg-shadow-devel
mailing list