[Pkg-shadow-devel] [Git][debian/adduser][feature-refactor-existing] 5 commits: adapt test9 for new message output
Marc Haber (@zugschlus)
gitlab at salsa.debian.org
Sat Nov 1 08:24:57 GMT 2025
Marc Haber pushed to branch feature-refactor-existing at Debian / adduser
Commits:
d92eb8e6 by Marc Haber at 2025-11-01T09:19:57+01:00
adapt test9 for new message output
Git-Dch: ignore
- - - - -
49118ec3 by Marc Haber at 2025-11-01T09:19:59+01:00
adapt test to #109934 (EXISTING_HAS_PASSWORD)
Git-Dch: ignore
- - - - -
1679e780 by Marc Haber at 2025-11-01T09:19:59+01:00
document a new error case (#1099734, EXISTING_HAS_PASSWORD)
Git-Dch: ignore
- - - - -
28c5258d by Marc Haber at 2025-11-01T09:19:59+01:00
implement EXISTING_HAS_PASSWORD
Git-Dch: ignore
- - - - -
d5078067 by Marc Haber at 2025-11-01T09:19:59+01:00
improve documentation for check_user_group
Git-Dch: ignore
- - - - -
5 changed files:
- AdduserCommon.pm
- adduser
- debian/tests/f/adduser_system.t
- doc/adduser.8
- testsuite/test09.pl
Changes:
=====================================
AdduserCommon.pm
=====================================
@@ -101,6 +101,7 @@ use constant {
EXISTING_SYSTEM => 2,
EXISTING_ID_MISMATCH => 4,
EXISTING_LOCKED => 8,
+ EXISTING_HAS_PASSWORD => 16,
};
@EXPORT = (
@@ -136,6 +137,7 @@ use constant {
'EXISTING_SYSTEM',
'EXISTING_ID_MISMATCH',
'EXISTING_LOCKED',
+ 'EXISTING_HAS_PASSWORD',
'existing_user_status',
'existing_group_status',
);
@@ -594,6 +596,7 @@ END {
# EXISTING_SYSTEM => 2
# EXISTING_ID_MISMATCH => 4
# EXISTING_LOCKED => 8
+# EXISTING_HAS_PASSWORD => 16
# e.g. if the requested account name exists as a locked system user,
# return 8|2|1 == 11
sub existing_user_status {
@@ -602,11 +605,14 @@ sub existing_user_status {
my $ret = EXISTING_NOT_FOUND;
log_trace( "existing_user_status called with new_name %s, new_uid %s, first_system_uid %s, last_system_uid %s", $new_name, $new_uid, $config->{"first_system_uid"}, $config->{"last_system_uid"} );
if (($dummy1,$pw,$uid) = egetpwnam($new_name)) {
+ # user with the name exists
log_trace( "egetpwnam(%s) returns %s, %s, %s", $new_name, $dummy1, $pw, $uid );
$ret |= EXISTING_FOUND;
$ret |= EXISTING_ID_MISMATCH if (defined($new_uid) && $uid != $new_uid);
$ret |= EXISTING_SYSTEM if
(($uid >= $config->{"first_system_uid"}) && ($uid <= $config->{"last_system_uid"}));
+ $ret |= EXISTING_HAS_PASSWORD if
+ (defined $pw && $pw ne '' && $pw ne '!' && $pw !~ /^\*/);
$ret |= EXISTING_LOCKED if (substr($pw,0,1) eq "!"); # TODO: also check expiry?
}
log_trace( "existing_user_status returning %d", $ret );
@@ -629,6 +635,7 @@ sub existing_group_status {
my $ret = EXISTING_NOT_FOUND;
log_trace( "existing_group_status called with new_name %s, new_gid %s", $new_name, $new_gid );
if (($dummy1,$dummy2,$gid) = egetgrnam($new_name)) {
+ # group with the name exists
$ret |= EXISTING_FOUND;
$ret |= EXISTING_ID_MISMATCH if (defined($new_gid) && $gid != $new_gid);
$ret |= EXISTING_SYSTEM if
=====================================
adduser
=====================================
@@ -1147,12 +1147,21 @@ sub mktree {
return 1;
}
-# check_user_group: ???
+# check_user_group: Do checks regarding user, group, gid and group
+# requirement that are basically the same for normal users and
+# system users. Factored out to avoid code duplication.
# parameters:
# system: 0 if the user is not a system user, 1 otherwise
# return values:
-#
+# if the function returns, all requirements are met. otherwise
+# it exits() from the program with an appropriate exit code
# todo: not sure whether global variables apply fine here.
+# global variables used:
+# $make_group_also
+# $new_name
+# $new_uid
+# $ingroup_name
+# $gid_option
sub check_user_group {
my ($system) = @_;
log_debug( "check_user_group %s called, make_group_also %s", $system, $make_group_also );
=====================================
debian/tests/f/adduser_system.t
=====================================
@@ -12,6 +12,15 @@ 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');
@@ -196,7 +205,8 @@ assert_user_exists('aust');
assert_user_is_system('aust');
system('echo "aust:!foobar" | chpasswd --encrypted');
-ok(1, "set passwd to !foobar");
+# with #1099734 fixed, this should fail
+#assert_command_result_silent(RET_WRONG_OBJECT_PROPERTIES,
assert_command_success(
'/usr/sbin/adduser',
'--stdoutmsglevel=error', '--stderrmsglevel=error',
=====================================
doc/adduser.8
=====================================
@@ -259,6 +259,8 @@ Unless a shell is explicitly set with the \fB\-\-shell\fP option,
the new system user will have the shell set to
\fI/usr/sbin/nologin\fP.
\fBadduser \-\-system\fP does not set a password for the new account.
+It is an error if \fBadduser \-\-system\fP is called
+for an account that has a password.
Skeletal configuration files are not copied.
.PP
Other options will behave as for the creation of a regular user.
=====================================
testsuite/test09.pl
=====================================
@@ -56,7 +56,7 @@ if ($error ne 13) {
print "failed\n $cmd returned an errorcode != 13 ($error)\n";
exit $error;
}
-if ($output !~ /^err: The group `addusertest\d+' already exists and is not a system group. Exiting.$/ ) {
+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;
}
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/fca13c5bd5d933e9a5c668077c83b9aec0264d44...d5078067807af978f4e67286ac4e31dc52dfddaa
--
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/fca13c5bd5d933e9a5c668077c83b9aec0264d44...d5078067807af978f4e67286ac4e31dc52dfddaa
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/20251101/ffe64522/attachment-0001.htm>
More information about the Pkg-shadow-devel
mailing list