[Pkg-shadow-devel] [Git][debian/adduser][debian/latest] 5 commits: copy over find_unused_* functions from upstream testsuites
Marc Haber (@zugschlus)
gitlab at salsa.debian.org
Fri Mar 27 10:01:43 GMT 2026
Marc Haber pushed to branch debian/latest at Debian / adduser
Commits:
aa90dad5 by Marc Haber at 2026-03-27T10:33:35+01:00
copy over find_unused_* functions from upstream testsuites
Closes: #1015781
- - - - -
e3bca5b4 by Marc Haber at 2026-03-27T10:33:35+01:00
rewrite find_unused_name
Git-Dch: ignore
- - - - -
1457deeb by Marc Haber at 2026-03-27T10:36:28+01:00
adapt indent to 4 spaces
Git-Dch: ignore
- - - - -
0452d690 by Marc Haber at 2026-03-27T10:36:28+01:00
adapt upstream tests to new find_unused_name signature
and give mode identifyable test user names
Git-Dch: ignore
- - - - -
19046fc8 by Marc Haber at 2026-03-27T10:36:28+01:00
modify clones.t to use find_unused_name
Git-Dch: ignore
- - - - -
14 changed files:
- debian/tests/f/clones.t
- debian/tests/lib/AdduserTestsCommon.pm
- testsuite/lib_test.pm
- testsuite/test01.pl
- testsuite/test02.pl
- testsuite/test03.pl
- testsuite/test04.pl
- testsuite/test05.pl
- testsuite/test06.pl
- testsuite/test07.pl
- testsuite/test08.pl
- testsuite/test09.pl
- testsuite/test10.pl
- testsuite/test11.pl
Changes:
=====================================
debian/tests/f/clones.t
=====================================
@@ -7,8 +7,8 @@ use diagnostics;
use strict;
use warnings;
-my $name1='ausclone1';
-my $name2='ausclone2';
+my $name1=find_unused_name('aus1clone');
+my $name2=find_unused_name('aus2clone');
use AdduserTestsCommon;
=====================================
debian/tests/lib/AdduserTestsCommon.pm
=====================================
@@ -69,6 +69,82 @@ sub in_range {
return ($id >= $first && $id <= $last);
}
+sub find_unused_uid {
+ my ($mode) = @_;
+ my $low_uid, my $high_uid;
+ if ($mode =~ /"user"/i) {
+ $low_uid = 10000;
+ $high_uid = 11000;
+ } else {
+ $low_uid = 700;
+ $high_uid = 800;
+ }
+ setpwent();
+ my $uid = $low_uid;
+ while (($uid <= $high_uid) && (defined(getpwuid($uid)))) {$uid++;}
+ endpwent();
+
+ if (($uid <= $high_uid) && (! defined(getpwuid($uid)))) {
+ return $uid;
+ }
+ else {
+ print "Cannot find an unused uid in range ($low_uid - $high_uid)\nExiting ...\n";
+ return 1;
+ }
+}
+
+sub find_unused_name {
+ my ($user_prefix) = @_;
+ $user_prefix //= '';
+
+ my $re = qr/^\Q$user_prefix\E(\d+)$/;
+
+ my $max_user = 0;
+ setpwent();
+ while (defined(my $name = getpwent())) {
+ if ($name =~ $re) {
+ $max_user = $1 if $1 > $max_user;
+ }
+ }
+ endpwent();
+
+ my $max_group = 0;
+ setgrent();
+ while (defined(my $name = getgrent())) {
+ if ($name =~ $re) {
+ $max_group = $1 if $1 > $max_group;
+ }
+ }
+ endgrent();
+
+ my $next = ($max_user > $max_group ? $max_user : $max_group) + 1;
+ return $user_prefix . $next;
+}
+
+sub find_unused_gid {
+ my ($mode) = @_;
+ my $low_gid, my $high_gid;
+ if ($mode =~ /"user"/i) {
+ $low_gid = 10000;
+ $high_gid = 11000;
+ } else {
+ $low_gid = 700;
+ $high_gid = 800;
+ }
+ setgrent();
+ my $gid = $low_gid;
+ while (($gid <= $high_gid) && (defined(getgrgid($gid)))) { $gid++;}
+ endgrent();
+
+ if (($gid <= $high_gid) && (! defined(getgrgid($gid)))) {
+ return $gid;
+ }
+ else {
+ print "Cannot find an unused gid in range ($low_gid - $high_gid)\nExiting ...\n";
+ return 1;
+ }
+}
+
sub assert_command_success {
system(@_);
is($? >> 8, 0, "command success: @_");
=====================================
testsuite/lib_test.pm
=====================================
@@ -3,7 +3,6 @@
use strict;
use Debian::AdduserCommon;
-
# helper routines
my %add_config;
@@ -14,170 +13,181 @@ my @deluserconf=("/etc/deluser.conf");
%add_config = read_config(@adduserconf);
%del_config = read_config(@deluserconf);
-my $user_prefix = "addusertest";
-
use constant {
SYS_MIN => 100,
SYS_MAX => 999,
};
sub assert {
- my ($cond) = @_;
- if ($cond) {
- print "Test failed\n";
- exit 1;
- }
+ my ($cond) = @_;
+ if ($cond) {
+ print "Test failed\n";
+ exit 1;
+ }
}
sub find_unused_uid {
- my ($mode) = @_;
- my $low_uid, my $high_uid;
- if ($mode =~ /"user"/i) {
- $low_uid = $add_config{"first_uid"};
- $high_uid = $add_config{"last_uid"};
- } else {
- $low_uid = $add_config{"first_system_uid"};
- $high_uid = $add_config{"last_system_uid"};
- }
- setpwent();
- my $uid = $low_uid;
- while (($uid <= $high_uid) && (defined(getpwuid($uid)))) {$uid++;}
- endpwent();
-
- if (($uid <= $high_uid) && (! defined(getpwuid($uid)))) {
- return $uid;
- }
- else {
- print "Haven't found a unused uid in range ($low_uid - $high_uid)\nExiting ...\n";
- return 1;
- }
+ my ($mode) = @_;
+ my $low_uid, my $high_uid;
+ if ($mode =~ /"user"/i) {
+ $low_uid = $add_config{"first_uid"};
+ $high_uid = $add_config{"last_uid"};
+ } else {
+ $low_uid = $add_config{"first_system_uid"};
+ $high_uid = $add_config{"last_system_uid"};
+ }
+ setpwent();
+ my $uid = $low_uid;
+ while (($uid <= $high_uid) && (defined(getpwuid($uid)))) {$uid++;}
+ endpwent();
+
+ if (($uid <= $high_uid) && (! defined(getpwuid($uid)))) {
+ return $uid;
+ }
+ else {
+ print "Cannot find an unused uid in range ($low_uid - $high_uid)\nExiting ...\n";
+ return 1;
+ }
}
sub find_unused_name {
- my $i = 1;
- setpwent();
- while (my $name = getpwent) {
- if ($name =~ /$user_prefix(\d+)/) {
- $i = $1>$i?$1:$i;
+ my ($user_prefix) = @_;
+ $user_prefix //= '';
+
+ my $re = qr/^\Q$user_prefix\E(\d+)$/;
+
+ my $max_user = 0;
+ setpwent();
+ while (defined(my $name = getpwent())) {
+ if ($name =~ $re) {
+ $max_user = $1 if $1 > $max_user;
+ }
}
- }
- endpwent();
- my $j = 1;
- setgrent();
- while (my $name = getgrent) {
- if ($name =~ /$user_prefix(\d+)/) {
- $j = $1>$j?$1:$j;
+ endpwent();
+
+ my $max_group = 0;
+ setgrent();
+ while (defined(my $name = getgrent())) {
+ if ($name =~ $re) {
+ $max_group = $1 if $1 > $max_group;
+ }
}
- }
- endgrent();
- return "$user_prefix".(($i>$j)?++$i:++$j);
+ endgrent();
+
+ my $next = ($max_user > $max_group ? $max_user : $max_group) + 1;
+ return $user_prefix . $next;
}
sub find_unused_gid {
- my ($mode) = @_;
- my $low_gid, my $high_gid;
- if ($mode =~ /"user"/i) {
- $low_gid = $add_config{"first_gid"};
- $high_gid = $add_config{"last_gid"};
- } else {
- $low_gid = $add_config{"first_system_gid"};
- $high_gid = $add_config{"last_system_gid"};
- }
- setgrent();
- my $gid = $low_gid;
- while (($gid <= $high_gid) && (defined(getgrgid($gid)))) { $gid++;}
- endgrent();
-
- if (($gid <= $high_gid) && (! defined(getgrgid($gid)))) {
- return $gid;
- }
- else {
- print "Haven't found a unused gid in range ($low_gid - $high_gid)\nExiting ...\n";
- return 1;
- }
+ my ($mode) = @_;
+ my $low_gid, my $high_gid;
+ if ($mode =~ /"user"/i) {
+ $low_gid = $add_config{"first_gid"};
+ $high_gid = $add_config{"last_gid"};
+ } else {
+ $low_gid = $add_config{"first_system_gid"};
+ $high_gid = $add_config{"last_system_gid"};
+ }
+ setgrent();
+ my $gid = $low_gid;
+ while (($gid <= $high_gid) && (defined(getgrgid($gid)))) { $gid++;}
+ endgrent();
+
+ if (($gid <= $high_gid) && (! defined(getgrgid($gid)))) {
+ return $gid;
+ }
+ else {
+ print "Cannot find an unused gid in range ($low_gid - $high_gid)\nExiting ...\n";
+ return 1;
+ }
}
# checking routines
sub check_user_exist {
- my ($username,$uid) = @_;
-
- my @ent = getpwnam ($username);
- if (!@ent) {
- print "user $username does not exist\n";
- return 1;
- }
- if (( defined($uid)) && ($ent[2] != $uid)) {
- printf "uid $uid does not match %s\n",$ent[2];
- return 1;
- }
- print "user $username exists\n";
- return 0;
+ my ($username,$uid) = @_;
+
+ my @ent = getpwnam ($username);
+ if (!@ent) {
+ print "user $username does not exist\n";
+ return 1;
+ }
+ if (( defined($uid)) && ($ent[2] != $uid)) {
+ printf "uid $uid does not match %s\n",$ent[2];
+ return 1;
+ }
+ print "user $username exists\n";
+ return 0;
}
sub check_user_not_exist {
- my ($username) = @_;
+ my ($username) = @_;
- if (defined(getpwnam($username))) {
- print "user $username exists\n";
- return 1;
- }
- print "user $username does not exist\n";
- return 0;
+ if (defined(getpwnam($username))) {
+ print "user $username exists\n";
+ return 1;
+ }
+ print "user $username does not exist\n";
+ return 0;
}
#####################
sub check_homedir_exist {
- my ($username, $homedir) = @_;
- my $dir = (getpwnam($username))[7];
- if ((defined($homedir)) && (! $dir eq $homedir)) {
- print "check_homedir_exist: wrong homedir ($homedir != $dir)\n";
- return 1;
- }
- if (! -d $dir) {
- print "check_homedir_exist: there's no home directory $dir\n";
- return 1;
- }
- return 0;
+ my ($username, $homedir) = @_;
+ my $dir = (getpwnam($username))[7];
+ if ((defined($homedir)) && (! $dir eq $homedir)) {
+ print "check_homedir_exist: wrong homedir ($homedir != $dir)\n";
+ return 1;
+ }
+ if (! -d $dir) {
+ print "check_homedir_exist: there's no home directory $dir\n";
+ return 1;
+ }
+ return 0;
}
sub check_dir_exist {
- my ($dir) = @_;
- if (! -d $dir) {
- print "check_dir_exist: $dir does not exist\n";
- return 1;
- }
- return 0;
+ 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) {
- print "check_homedir_not_exist: there's a home directory $homedir\n";
- return 1;
- }
- return 0;
+ my ($homedir) = @_;
+ if ( -d $homedir) {
+ print "check_homedir_not_exist: there's a home directory $homedir\n";
+ return 1;
+ }
+ return 0;
}
sub check_user_homedir_eq {
- my ($username, $dir) = @_;
- my $userdir = (getpwnam($username))[7];
+ my ($username, $dir) = @_;
+ my $userdir = (getpwnam($username))[7];
- return ($userdir eq $dir) ? 0 : 1;
+ return ($userdir eq $dir) ? 0 : 1;
}
sub check_user_comment {
- my ($username, $comment) = @_;
- my $usercomment = (getpwnam($username))[6];
+ my ($username, $comment) = @_;
+ my $usercomment = (getpwnam($username))[6];
- return ($usercomment eq $comment) ? 0 : 1;
+ return ($usercomment eq $comment) ? 0 : 1;
}
sub check_user_homedir_not_exist {
my ($username) = @_;
+ my $dir = (getpwnam($username))[7];
+ if ( -d $dir) {
+ print "check_user_homedir_not_exist: there's a home directory $dir\n";
+ return 1;
+ }
return 0;
}
=====================================
testsuite/test01.pl
=====================================
@@ -9,7 +9,7 @@ use strict;
use lib_test;
my $groupname = "nogroup";
-my $username = find_unused_name();
+my $username = find_unused_name("adduser01test");
my $cmd = "adduser --system $username";
if (!defined (getpwnam($username))) {
=====================================
testsuite/test02.pl
=====================================
@@ -23,7 +23,7 @@ BEGIN {
}
my $groupname = "nogroup";
-my $username = find_unused_name();
+my $username = find_unused_name("adduser02test");
my $homedir = "/home/$username";
my $cmd;
=====================================
testsuite/test03.pl
=====================================
@@ -9,7 +9,7 @@ use strict;
use lib_test;
my $groupname = "nogroup";
-my $username = find_unused_name();
+my $username = find_unused_name("adduser03test");
my $cmd = "adduser --system --no-create-home $username";
my $homedir = "/nonexistent";
=====================================
testsuite/test04.pl
=====================================
@@ -9,7 +9,7 @@ use strict;
use lib_test;
my $groupname = "nogroup";
-my $username = find_unused_name();
+my $username = find_unused_name("adduser04test");
my $homedir = "/var/$username";
my $cmd = "adduser --system --home $homedir --no-create-home $username";
=====================================
testsuite/test05.pl
=====================================
@@ -9,7 +9,7 @@ use strict;
use lib_test;
my $groupname = "nogroup";
-my $username = find_unused_name();
+my $username = find_unused_name("adduser05test");
my $want_uid = find_unused_uid("system");
my $cmd = "adduser --system --uid $want_uid $username";
=====================================
testsuite/test06.pl
=====================================
@@ -8,7 +8,7 @@
use strict;
use lib_test;
-my $username = find_unused_name();
+my $username = find_unused_name("adduser06test");
my $want_uid = find_unused_uid("system");
my $want_gid = 0;
=====================================
testsuite/test07.pl
=====================================
@@ -7,7 +7,7 @@
use strict;
use lib_test;
-my $username = find_unused_name();
+my $username = find_unused_name("adduser07test");
my $cmd = "adduser --system $username";
=====================================
testsuite/test08.pl
=====================================
@@ -12,7 +12,7 @@
use strict;
use lib_test;
-my $username = find_unused_name();
+my $username = find_unused_name("adduser08utest");
my $cmd = "adduser --comment test --disabled-password --add-extra-groups $username";
my %config;
@@ -36,7 +36,7 @@ if (!defined (getpwnam($username))) {
print "ok\n";
}
-my $newgroup = find_unused_name();
+my $newgroup = find_unused_name("adduser08gtest");
$cmd = "addgroup $newgroup";
unless (defined getgrnam($newgroup)) {
@@ -91,7 +91,7 @@ unless (!defined getgrnam($newgroup)) {
print "ok\n";
}
-$newgroup = find_unused_name();
+$newgroup = find_unused_name("adduser08ngtest");
$cmd = "adduser --group $newgroup";
unless (defined getgrnam($newgroup)) {
@@ -119,7 +119,7 @@ unless (!defined getgrnam($newgroup)) {
print "ok\n";
}
-my $sysusername = find_unused_name();
+my $sysusername = find_unused_name("adduser08sutest");
$cmd = "adduser --system --comment test --disabled-password --add-extra-groups $sysusername";
if (!defined (getpwnam($sysusername))) {
=====================================
testsuite/test09.pl
=====================================
@@ -14,7 +14,7 @@ use lib_test;
my $error;
my $output;
-my $groupname = find_unused_name();
+my $groupname = find_unused_name("adduser09gtest");
my $cmd = "addgroup $groupname";
if (!defined (getgrnam($groupname))) {
@@ -39,7 +39,7 @@ 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$/ ) {
+if ($output !~ /^fatal: The group `adduser09gtest\d+' already exists\.\n$/ ) {
print "failed\n $cmd returned unexpected output ($output)\n";
exit 1;
}
@@ -56,7 +56,7 @@ 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.$/ ) {
+if ($output !~ /^fatal: The group `adduser09gtest\d+' already exists, but is not a system group. Exiting.$/ ) {
print "failed\n $cmd returned unexpected output ($output)\n";
exit 1;
}
@@ -75,7 +75,7 @@ if ($error ne 53) {
}
print "ok\n";
-my $sysgroupname = find_unused_name();
+my $sysgroupname = find_unused_name("adduser09sgtest");
$cmd = "addgroup --system $sysgroupname";
if (!defined (getgrnam($sysgroupname))) {
@@ -115,7 +115,7 @@ 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\.$/ ) {
+if ($output !~ /^fatal: The group `adduser09sgtest\d+' already exists\.$/ ) {
print "failed\n $cmd returned unexpected output ($output)\n";
exit 1;
}
=====================================
testsuite/test10.pl
=====================================
@@ -15,7 +15,7 @@ my $username;
my $susername;
my $num;
-$username = find_unused_name();
+$username = find_unused_name("adduser10test");
$num = 0;
assert(check_user_not_exist ($username));
@@ -223,7 +223,7 @@ assert(check_user_not_exist ($username));
#=======================
# system user
-$susername = find_unused_name();
+$susername = find_unused_name("adduser10stest");
assert(check_user_not_exist ($susername));
# unlock a non-existing system ccount
=====================================
testsuite/test11.pl
=====================================
@@ -4,7 +4,7 @@
use strict;
use lib_test;
-my $username = find_unused_name();
+my $username = find_unused_name("adduser11test");
my $comment;
my $cmd;
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/8b28a9c3823fbfefea8bcfd69ec86aa5bd509d2f...19046fc8ecac3fdbd7569c6cfcb2c6152932bf56
--
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/8b28a9c3823fbfefea8bcfd69ec86aa5bd509d2f...19046fc8ecac3fdbd7569c6cfcb2c6152932bf56
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/20260327/117f5f16/attachment-0001.htm>
More information about the Pkg-shadow-devel
mailing list