[Pkg-shadow-devel] [Git][debian/adduser][zg/debian-bug-248500] 16 commits: fix typos and add missing spaces
Marc Haber (@zugschlus)
gitlab at salsa.debian.org
Thu Nov 26 13:15:02 GMT 2026
Marc Haber pushed to branch zg/debian-bug-248500 at Debian / adduser
Commits:
fe72b17f by Marc Haber at 2026-10-25T18:23:59+01:00
fix typos and add missing spaces
Thanks: Helge Kreutzmann
Closes: #1140472
- - - - -
084ebb2f by Marc Haber at 2026-10-25T18:25:01+01:00
Apply consistent formatting to packaging files
Run `debputy reformat --style black` and `wrap-and-sort -vast` to enforce
uniform deb822 formatting with one item per line. This makes future
changes to dependencies and other lists easier to track in git diffs.
No functional changes.
- - - - -
fccff133 by Marc Haber at 2026-10-25T18:25:26+01:00
Bump Debian Policy version to 4.7.4
No changes required after reviewing checklist at
https://www.debian.org/doc/debian-policy/upgrading-checklist.html#version-4_7_4
- - - - -
07363c0d by Marc Haber at 2026-10-25T18:25:38+01:00
Fix issues found by Shellcheck
Apply all fixes suggested by Shellcheck that can be applied automatically in
a way that is unlikely to change functionality, only make the syntax more
robust to protect from unintentional use and side effect.
- - - - -
96a1699e by Marc Haber at 2026-10-25T18:25:50+01:00
Fix spelling
Fix minor typos and spelling mistakes that can be automatically corrected.
No functional changes.
- - - - -
7f02f314 by Marc Haber at 2026-10-25T18:26:10+01:00
fix typos
Git-Dch: ignore
- - - - -
6090785b by Juanes at 2026-10-28T11:59:10+01:00
AdduserStatefile: add global values not tied to a user
- - - - -
1bc91cd2 by Juanes at 2026-10-28T11:59:10+01:00
adduser: do not hand out an id twice (Closes: #248500)
- - - - -
24c18481 by Juanes at 2026-10-28T11:59:10+01:00
document REUSE_IDS and ID_COUNTER_INIT
- - - - -
3d247c5b by Juanes at 2026-10-28T11:59:10+01:00
tests: cover the id counter
- - - - -
ee36dd24 by Juanes at 2026-10-28T11:59:10+01:00
tests: drop firstlastuidgid_orig.t
- - - - -
ed40e090 by Marc Haber at 2026-11-26T14:14:47+01:00
adapt autopkgtest to use REUSE_IDs
in s/uids/gidpool.t, set REUSE_IDS yes for some tests that would fail
otherwise. The alternative would be to rework the tests more
distinctively and I am not sure whether that's worth the effort
- - - - -
44ed496b by Marc Haber at 2026-11-26T14:14:47+01:00
adapt REUSE_IDS patch to use --ingroup's gid as uid if free
- - - - -
d6266406 by Marc Haber at 2026-11-26T14:14:47+01:00
add ingroup_uid.t to test --ingroup gid => uid mechnanism
- - - - -
de41407e by Marc Haber at 2026-11-26T14:14:47+01:00
adapt firstlastuidgid.t to REUSE_UIDs patch
- - - - -
4d32a479 by Marc Haber at 2026-11-26T14:14:47+01:00
keep separate id counters for uids and gids
keep separate id counters for uids and gids if the configured uid and
gid ranges differ. A single counter made the uid range look exhausted
as soon as gids above it had been handed out.
- - - - -
24 changed files:
- AdduserCommon.pm
- AdduserStatefile.pm
- adduser
- adduser.conf
- debian/NEWS
- debian/README
- debian/README.source
- debian/TODO
- debian/control
- debian/examples
- debian/links
- debian/manpages
- debian/tests/control
- debian/tests/f/cron_jobs.t
- debian/tests/f/firstlastuidgid.t
- − debian/tests/f/firstlastuidgid_orig.t
- + debian/tests/f/id_counter.t
- + debian/tests/f/ingroup_uid.t
- debian/tests/f/suidsgidpool.t
- debian/tests/f/uidgidpool.t
- debian/tests/f/valid_username.t
- debian/tests/lib/AdduserTestsCommon.pm
- debian/tests/no-autopkgtest
- doc/adduser.conf.5
Changes:
=====================================
AdduserCommon.pm
=====================================
@@ -154,6 +154,11 @@ use constant {
'existing_user_status',
'existing_group_status',
'range_intersection',
+ 'highest_used_id',
+ 'id_floor',
+ 'id_floor_uidgid',
+ 'id_counter_keys',
+ 'record_id_used',
'first_avail_uid',
'first_avail_gid',
'first_avail_uid_gid',
@@ -218,6 +223,143 @@ sub range_intersection {
return ($floor, $ceiling);
}
+# highest_used_id: return the highest id in use within a range, looking
+# at both users and groups
+# parameters:
+# min, max: the range
+# return values:
+# the highest id in use, or undef if no id of the range is in use
+sub highest_used_id {
+ my ($min, $max) = @_;
+ my $highest;
+
+ setpwent();
+ while (my @pw = getpwent()) {
+ my $id = $pw[2];
+ next if ($id < $min || $id > $max);
+ $highest = $id if (!defined($highest) || $id > $highest);
+ }
+ endpwent();
+
+ setgrent();
+ while (my @gr = getgrent()) {
+ my $id = $gr[2];
+ next if ($id < $min || $id > $max);
+ $highest = $id if (!defined($highest) || $id > $highest);
+ }
+ endgrent();
+
+ return $highest;
+}
+
+my %id_floor_warned;
+
+# id_floor: raise the lower bound of an id range so that ids which have
+# already been handed out by adduser are not handed out again
+# parameters:
+# min, max: the range from the configuration
+# key: the state file key holding the counter for this range
+# config: reference to the configuration hash
+# return values:
+# the lower bound to actually use
+sub id_floor {
+ my ($min, $max, $key, $config) = @_;
+
+ return $min if (!defined($key));
+ return $min if (($config->{"reuse_ids"} // "no") =~ /yes/i);
+
+ my $last = get_global_value($key);
+
+ if (!defined($last)) {
+ # no counter yet: this is the first time on this system
+ if (($config->{"id_counter_init"} // "first_free") eq "highest") {
+ my $highest = highest_used_id($min, $max);
+ $last = $highest if (defined($highest));
+ }
+ return $min if (!defined($last));
+ }
+
+ my $floor = ($last + 1 > $min) ? $last + 1 : $min;
+ log_trace("id_floor: counter %s is %s, range %s-%s starts at %s",
+ $key, $last, $min, $max, $floor);
+
+ if (!$id_floor_warned{$key}) {
+ # uid and gid floors are raised separately, warn only once
+ $id_floor_warned{$key} = 1;
+ if ($floor > $max) {
+ log_warn(mtx("All ids up to %d have already been assigned and REUSE_IDS is set to no."),
+ $last);
+ } elsif (($max - $floor + 1) <= (($max - $min + 1) / 10)) {
+ log_warn(mtx("Only %d ids are left in the range %d-%d with REUSE_IDS set to no."),
+ $max - $floor + 1, $min, $max);
+ }
+ }
+
+ return $floor;
+}
+
+# id_counter_keys: name the state file counters that belong to the
+# configured uid and gid ranges
+# If the uid range and the gid range are the same (which is the default),
+# uids and gids come from one pool and share one counter, so that an id
+# handed out as a gid is not handed out again as a uid. If the ranges
+# differ, an id of one range says nothing about the other: a gid in the
+# gid range could be above the whole uid range and would make the uid
+# range look exhausted. Then each of them has its own counter.
+# parameters:
+# config: reference to the configuration hash
+# system: true for the system uid/gid ranges
+# return values:
+# (uid counter key, gid counter key)
+sub id_counter_keys {
+ my ($config, $system) = @_;
+ my $p = $system ? 'system_' : '';
+ my $same = 1;
+ foreach my $b ('first', 'last') {
+ $same = 0 if (($config->{"${b}_${p}uid"} // '') ne ($config->{"${b}_${p}gid"} // ''));
+ }
+ return $system ? ('last_sys_id', 'last_sys_id') : ('last_id', 'last_id') if ($same);
+ return $system ? ('last_sys_uid', 'last_sys_gid') : ('last_uid', 'last_gid');
+}
+
+# id_floor_uidgid: the range in which a uid and a gid that have to be
+# identical can be searched, with the counters of both applied
+# parameters:
+# first_uid, last_uid: the uid range
+# first_gid, last_gid: the gid range
+# uid_key, gid_key: the counters, see id_counter_keys; undef if the
+# range was forced by the admin
+# config: reference to the configuration hash
+# return values:
+# (first, last) of the intersection of the two ranges
+sub id_floor_uidgid {
+ my ($first_uid, $last_uid, $first_gid, $last_gid, $uid_key, $gid_key, $config) = @_;
+ $first_uid = id_floor($first_uid, $last_uid, $uid_key, $config);
+ $first_gid = id_floor($first_gid, $last_gid, $gid_key, $config);
+ return range_intersection($first_uid, $last_uid, $first_gid, $last_gid);
+}
+
+# record_id_used: remember the highest id handed out by adduser in a range
+# parameters:
+# id: the id that has just been assigned
+# key: the state file key holding the counter for this range
+# config: reference to the configuration hash
+# return values:
+# none
+sub record_id_used {
+ my ($id, $key, $config) = @_;
+
+ return if (!defined($key));
+
+ return if (($config->{"reuse_ids"} // "no") =~ /yes/i);
+
+ my $last = get_global_value($key) // -1;
+ return if ($id <= $last);
+
+ log_trace("record_id_used: setting counter %s to %s", $key, $id);
+ set_global_value($key, $id);
+}
+
# first_avail_uid: return the first available uid in given range
# parameters:
# min, max: the range
@@ -231,12 +373,18 @@ sub range_intersection {
# reserved_uid_pool: hashref of ids reserved by other pending
# UID_POOL entries, keyed by id. May be undef or omitted, which
# is treated the same as an empty hashref.
+# floor: optional lower bound for the scan of the range, as raised
+# by id_floor() when REUSE_IDS=no. It does NOT apply to the
+# preferred id: the GID of an existing group is already in use
+# as a GID, so using it as UID too does not hand out an id that
+# the counter has not yet passed. If omitted, min is used.
# return values:
# -1 if no free uid is available
# otherwise the choosen uid
sub first_avail_uid {
- my ($min, $max, $pool_id, $preferred, $reserved_uid_pool) = @_;
+ my ($min, $max, $pool_id, $preferred, $reserved_uid_pool, $floor) = @_;
$reserved_uid_pool //= {};
+ $floor = $min if (!defined($floor) || $floor < $min);
if (defined ($pool_id)) {
return $pool_id if (!defined(getpwuid($pool_id)));
return -1;
@@ -246,9 +394,9 @@ sub first_avail_uid {
log_trace( "first_avail_uid: preferred id %d is free, using it", $preferred );
return $preferred;
}
- log_info( mtx("Selecting UID from range %d to %d ...\n"),$min,$max);
+ log_info( mtx("Selecting UID from range %d to %d ...\n"),$floor,$max);
- my $t = $min;
+ my $t = $floor;
while ($t <= $max) {
return $t if (!exists($reserved_uid_pool->{$t}) and !defined(getpwuid($t)));
$t++;
@@ -345,7 +493,7 @@ sub read_configfile {
my $conffh;
unless( open ($conffh, q{<}, $conf_file) ) {
- log_fatal( mtx("Can not open configuration file %s: `%s'\n"), $conf_file, $! );
+ log_fatal( mtx("Cannot open configuration file %s: `%s'\n"), $conf_file, $! );
exit( RET_CONFFILE );
}
while (<$conffh>) {
@@ -647,6 +795,8 @@ sub read_config {
uid_pool => "",
gid_pool => "",
reserve_uid_pool => "yes",
+ reuse_ids => "no",
+ id_counter_init => "first_free",
reserve_gid_pool => "yes",
loggerparms => "",
stdoutmsglevel => "warn",
=====================================
AdduserStatefile.pm
=====================================
@@ -22,6 +22,8 @@ use vars qw(@EXPORT);
'get_state_value',
'get_state_user_data',
'delete_state_user',
+ 'set_global_value',
+ 'get_global_value',
);
use strict;
@@ -30,6 +32,7 @@ use warnings;
our $STATE_DIR = '/var/lib/adduser';
our $STATE_FILE = "$STATE_DIR/state";
our $LOCK_FILE = "$STATE_DIR/state.lock";
+our $GLOBAL_RECORD = '@global';
# init_state_file()
#
@@ -67,21 +70,23 @@ sub init_state_file {
sub set_state_value {
my ($username, $key, $value) = @_;
+ die "Invalid user name" if ($username eq $GLOBAL_RECORD);
+
my $lock_fh = _acquire_lock();
- my %data = _read_state();
+ my ($data, $globals) = _read_state();
- $data{$username} ||= {};
+ $data->{$username} ||= {};
if (!defined $value || $value eq '') {
- delete $data{$username}{$key};
- if (keys %{$data{$username}} == 0) {
- delete $data{$username};
+ delete $data->{$username}{$key};
+ if (keys %{$data->{$username}} == 0) {
+ delete $data->{$username};
}
} else {
die "Invalid value" if $value =~ /[:\n]/;
- $data{$username}{$key} = $value;
+ $data->{$username}{$key} = $value;
}
- _write_state(\%data);
+ _write_state($data, $globals);
_release_lock($lock_fh);
}
@@ -105,15 +110,14 @@ sub get_state_value {
# Return undef/empty hash if state file doesn't exist yet
return undef unless -f $STATE_FILE;
- my %data = _read_state();
-
+ my ($data, $globals) = _read_state();
# Return undef/empty hash if user doesn't exist
- if (!exists $data{$username}) {
+ if (!exists $data->{$username}) {
return defined $key ? undef : {};
}
# Return specific key or all data
- return defined $key ? $data{$username}{$key} : $data{$username};
+ return defined $key ? $data->{$username}{$key} : $data->{$username};
}
# get_user_data($username)
@@ -149,12 +153,57 @@ sub delete_state_user {
# Acquire lock, read, modify, write, release lock
my $lock_fh = _acquire_lock();
- my %data = _read_state();
- delete $data{$username};
- _write_state(\%data);
+ my ($data, $globals) = _read_state();
+ delete $data->{$username};
+ _write_state($data, $globals);
+ _release_lock($lock_fh);
+}
+
+# set_global_value($key, $value)
+#
+# Set a key-value pair that does not belong to any user account.
+#
+# Parameters:
+# $key - The key name (cannot contain '=', ':', or newlines)
+# $value - The value to store (cannot contain ':' or newlines)
+# If empty or undefined, the key is deleted
+sub set_global_value {
+ my ($key, $value) = @_;
+
+ die "Invalid key" if (!defined($key) || $key =~ /[=:\n]/);
+
+ my $lock_fh = _acquire_lock();
+ my ($data, $globals) = _read_state();
+
+ if (!defined $value || $value eq '') {
+ delete $globals->{$key};
+ } else {
+ die "Invalid value" if $value =~ /[:\n]/;
+ $globals->{$key} = $value;
+ }
+
+ _write_state($data, $globals);
_release_lock($lock_fh);
}
+# get_global_value($key)
+#
+# Retrieve a value that does not belong to any user account.
+#
+# Parameters:
+# $key - The key name to retrieve
+#
+# Returns:
+# The value if found, undef otherwise
+sub get_global_value {
+ my ($key) = @_;
+
+ return undef unless -f $STATE_FILE;
+
+ my ($data, $globals) = _read_state();
+ return $globals->{$key};
+}
+
# _acquire_lock()
#
# Internal function to acquire an exclusive lock on the state file.
@@ -205,15 +254,15 @@ sub _release_lock {
# Empty lines and lines starting with '#' are ignored.
#
# Returns:
-# A hash where keys are usernames and values are hash references
-# containing the key-value pairs for that user
+# Two hash references: the first maps user names to their key-value
+# pairs, the second holds the values that belong to no user
#
# Dies if the file cannot be opened.
sub _read_state {
- my %data;
+ my (%data, %globals);
# Return empty hash if state file doesn't exist yet
- return %data unless -f $STATE_FILE;
+ return (\%data, \%globals) unless -f $STATE_FILE;
open(my $fh, '<', $STATE_FILE) or die "Cannot read $STATE_FILE: $!";
@@ -231,50 +280,62 @@ sub _read_state {
my @fields = split(/:/, $line);
next unless @fields >= 1;
- my $username = shift @fields;
- $data{$username} = {};
-
- # Parse each key=value pair
+ my $record = shift @fields;
+ my %pairs;
foreach my $pair (@fields) {
my ($key, $value) = split(/=/, $pair, 2);
- $data{$username}{$key} = $value if defined $key && defined $value;
+ $pairs{$key} = $value if defined $key && defined $value;
+ }
+
+ if ($record eq $GLOBAL_RECORD) {
+ %globals = (%globals, %pairs);
+ } else {
+ $data{$record} = \%pairs;
}
}
close($fh);
- return %data;
+ return (\%data, \%globals);
}
-# _write_state(\%data)
+# _write_state($data_ref, $globals_ref)
#
# Internal function to write the entire state file atomically.
# MUST be called while holding the lock via _acquire_lock().
# Uses a temporary file and rename() to ensure atomicity.
#
# Parameters:
-# $data_ref - A hash reference in the format returned by _read_state()
+# $data_ref - A hash reference mapping user names to their key-value pairs
+# $globals_ref - A hash reference with the values that belong to no user
#
# The output is sorted by username and by key within each username
# for consistent, diff-friendly output.
#
# Dies if the file cannot be written or renamed.
sub _write_state {
- my ($data_ref) = @_;
+ my ($data_ref, $globals_ref) = @_;
# Use a process-specific temporary file name
my $temp_file = "$STATE_FILE.tmp.$$";
open(my $fh, '>', $temp_file) or die "Cannot write to $temp_file: $!";
+ if (%$globals_ref) {
+ my @pairs;
+ foreach my $key (sort keys %$globals_ref) {
+ push @pairs, "$key=$globals_ref->{$key}";
+ }
+ print $fh "$GLOBAL_RECORD:", join(':', @pairs), "\n";
+ }
+
# Write each user's data, sorted for consistency
foreach my $username (sort keys %$data_ref) {
my @pairs;
# Build key=value pairs, sorted by key
foreach my $key (sort keys %{$data_ref->{$username}}) {
- my $value = $data_ref->{$username}{$key};
- push @pairs, "$key=$value";
+ push @pairs, "$key=$data_ref->{$username}{$key}";
}
# Write the line: username:key1=value1:key2=value2:...
=====================================
adduser
=====================================
@@ -350,6 +350,11 @@ if (@authorized_keys && $action ne "adduser") {
@authorized_keys = ();
}
+# an explicitly requested range overrides everything: the account gets the
+# first free id in that range and the counter is neither read nor updated
+my $range_forced = defined($new_firstuid) || defined($new_lastuid)
+ || defined($new_firstgid) || defined($new_lastgid);
+
# $new_firstuid = $new_firstuid || $config{"first_uid"} || 1000;
# $new_lastuid = $new_lastuid || $config{"last_uid"} || 59999;
# $new_firstgid = $new_firstgid || $config{"first_gid"} || 1000;
@@ -467,6 +472,10 @@ $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'handler';
if ($action eq "addsysgroup") {
acquire_lock();
+ my $counter_key;
+
+ # an id given by the admin does not take part in the reuse counter
+ my $gid_forced = defined($gid_option);
log_trace( "addsysuser %s, uid %s", $new_name, $new_uid );
# Check if requested group already exists and we can exit safely
@@ -496,6 +505,8 @@ if ($action eq "addsysgroup") {
if (!defined($gid_option)) {
$first_gid = $new_firstgid || $config{"first_system_gid"};
$last_gid = $new_lastgid || $config{"last_system_gid"};
+ $counter_key = (id_counter_keys(\%config, 1))[1] unless ($range_forced);
+ $first_gid = id_floor($first_gid, $last_gid, $counter_key, \%config);
$gid_option = &first_avail_gid($first_gid,
$last_gid,
$gid_pool{$new_name}{'id'},
@@ -515,6 +526,8 @@ if ($action eq "addsysgroup") {
if( $ga_ret == RET_INVALID_NAME_FROM_USERADD ) {
$returnvalue = RET_INVALID_NAME_FROM_USERADD;
}
+ record_id_used($gid_option, $counter_key, \%config)
+ unless ($gid_forced || $returnvalue != RET_OK);
release_lock(0);
exit( $returnvalue );
}
@@ -525,6 +538,9 @@ if ($action eq "addsysgroup") {
##############
if ($action eq "addgroup") {
acquire_lock();
+ my $counter_key;
+
+ my $gid_forced = defined($gid_option);
if (defined egetgrnam(encode($charset, $new_name))) {
log_fatal( mtx("The group `%s' already exists."), $new_name);
exit( RET_OBJECT_EXISTS );
@@ -536,6 +552,8 @@ if ($action eq "addgroup") {
if (!defined($gid_option)) {
$first_gid = $new_firstgid || $config{"first_gid"};
$last_gid = $new_lastgid || $config{"last_gid"};
+ $counter_key = (id_counter_keys(\%config, 0))[1] unless ($range_forced);
+ $first_gid = id_floor($first_gid, $last_gid, $counter_key, \%config);
log_debug( "Searching for gid with first_gid=%s, last_gid=%s, new_name=%s, gid_pool=%s",
$first_gid,
$last_gid,
@@ -561,6 +579,8 @@ if ($action eq "addgroup") {
if( $ga_ret == RET_INVALID_NAME_FROM_USERADD ) {
$returnvalue = RET_INVALID_NAME_FROM_USERADD;
}
+ record_id_used($gid_option, $counter_key, \%config)
+ unless ($gid_forced || $returnvalue != RET_OK);
release_lock(0);
exit( $returnvalue );
}
@@ -599,6 +619,10 @@ if ($action eq 'addusertogroup') {
################
if ($action eq "addsysuser") {
acquire_lock();
+ my $counter_key;
+ my $gid_counter_key;
+
+ my $uid_forced = defined($new_uid);
log_trace( "addsysuser %s, uid %s", $new_name, $new_uid );
my $ret = existing_user_status(\%config, $new_name, $new_uid);
@@ -637,6 +661,10 @@ if ($action eq "addsysuser") {
my $last_sys_gid = $new_lastgid || $config{"last_system_gid"};
my ($first_uidgid, $last_uidgid) = &range_intersection(
$first_sys_uid, $last_sys_uid, $first_sys_gid, $last_sys_gid);
+ ($counter_key, $gid_counter_key) = id_counter_keys(\%config, 1) unless ($range_forced);
+ ($first_uidgid, $last_uidgid) = id_floor_uidgid(
+ $first_sys_uid, $last_sys_uid, $first_sys_gid, $last_sys_gid,
+ $counter_key, $gid_counter_key, \%config);
# TODO: Check what happens when those ranges do not overlap
$new_uid = &first_avail_uid_gid( $first_uidgid,
$last_uidgid,
@@ -657,6 +685,8 @@ if ($action eq "addsysuser") {
elsif (!defined($new_uid) && !$make_group_also) {
my $first_sys_uid = $new_firstuid || $config{"first_system_uid"};
my $last_sys_uid = $new_lastuid || $config{"last_system_uid"};
+ $counter_key = (id_counter_keys(\%config, 1))[0] unless ($range_forced);
+ my $floor_sys_uid = id_floor($first_sys_uid, $last_sys_uid, $counter_key, \%config);
# if the primary group is already known by GID (--gid) or by
# name (--ingroup), and that GID happens to also be free as a
# UID, prefer it, so the user ends up with matching UID/GID
@@ -673,10 +703,11 @@ if ($action eq "addsysuser") {
$last_sys_uid,
$uid_pool{$new_name}{'id'},
$preferred_uid,
- \%reserved_uid_pool);
+ \%reserved_uid_pool,
+ $floor_sys_uid);
if ($new_uid == -1) {
log_warn( mtx("No UID is available in the range %d-%d (FIRST_SYS_UID - LAST_SYS_UID)."),
- $first_sys_uid,
+ $floor_sys_uid,
$last_sys_uid );
log_fatal( mtx("The user `%s' was not created."), $new_name);
exit( RET_NO_ID_IN_RANGE );
@@ -747,6 +778,11 @@ if ($action eq "addsysuser") {
$returnvalue = RET_INVALID_NAME_FROM_USERADD;
}
+ record_id_used($new_uid, $counter_key, \%config)
+ unless ($uid_forced || $returnvalue != RET_OK);
+ record_id_used($new_uid, $gid_counter_key, \%config)
+ unless ($uid_forced || $returnvalue != RET_OK);
+
release_lock(0);
if (defined($comment_tainted)) {
@@ -779,6 +815,11 @@ if ($action eq "addsysuser") {
#############
if ($action eq "adduser") {
acquire_lock();
+ my $counter_key;
+ my $gid_counter_key;
+
+ # an id given by the admin does not take part in the reuse counter
+ my $uid_forced = defined($new_uid);
$primary_gid=-1;
my @supplemental_groups=();
@@ -879,6 +920,7 @@ if ($action eq "adduser") {
$first_gid = $new_firstgid || $config{"first_gid"};
$last_gid = $new_lastgid || $config{"last_gid"};
#}
+
log_trace( "first_uid %s, last_uid %s, first_gid %s, last_gid %s", $first_uid, $last_uid, $first_gid, $last_gid );
log_info (gtx("Adding user `%s' ..."),$new_name);
@@ -889,15 +931,24 @@ if ($action eq "adduser") {
# even though it was not created as a usergroup. Falls back
# to the lowest free UID in range if the GID is not free as
# a UID (or is outside the UID range).
+ $counter_key = (id_counter_keys(\%config, 0))[0] unless ($range_forced);
+ my $floor_uid = id_floor($first_uid, $last_uid, $counter_key, \%config);
my $ingroup_gid = egetgrnam($ingroup_name);
$new_uid = &first_avail_uid( $first_uid,
$last_uid,
$uid_pool{$new_name}{'id'},
$ingroup_gid,
- \%reserved_uid_pool);
+ \%reserved_uid_pool,
+ $floor_uid);
} else {
my ($first_uidgid, $last_uidgid) = &range_intersection(
$first_uid, $last_uid, $first_gid, $last_gid);
+ ($counter_key, $gid_counter_key) = id_counter_keys(\%config, 0) unless ($range_forced);
+ # the gid is only consumed if the group is created here
+ undef($gid_counter_key) unless ($make_group_also);
+ ($first_uidgid, $last_uidgid) = id_floor_uidgid(
+ $first_uid, $last_uid, $first_gid, $last_gid,
+ $counter_key, $gid_counter_key, \%config);
# TODO: Check what happens when those ranges do not overlap
$new_uid = &first_avail_uid_gid( $first_uidgid,
$last_uidgid,
@@ -1093,6 +1144,10 @@ if ($action eq "adduser") {
systemcall('/usr/local/sbin/adduser.local', $new_name, $new_uid,
$primary_gid, $home_dir) if (-x "/usr/local/sbin/adduser.local");
+ record_id_used($new_uid, $counter_key, \%config)
+ unless ($uid_forced || $returnvalue != RET_OK);
+ record_id_used($new_uid, $gid_counter_key, \%config)
+ unless ($uid_forced || $returnvalue != RET_OK);
release_lock(0);
exit( $returnvalue );
=====================================
adduser.conf
=====================================
@@ -47,6 +47,28 @@
#FIRST_GID=1000
#LAST_GID=59999
+# Whether an id that has already been handed out may be handed out again
+# once the account is deleted. With REUSE_IDS=no, adduser keeps a counter
+# in /var/lib/adduser/state and never allocates below it, so a uid or gid
+# is used at most once on this system.
+# An explicit range on the command line (--firstuid, --lastuid, --firstgid,
+# --lastgid) overrides the counter: the first free id of that range is used
+# and the counter is neither read nor updated.
+# If the uid range and the gid range are not the same, uids and gids are
+# counted separately.
+# Default: REUSE_IDS=no
+#REUSE_IDS=no
+
+# Where the counter starts on a system that does not have one yet.
+# With first_free, the counter only starts once adduser hands out an id,
+# so ids below the highest one already in use remain available.
+# With highest, the counter starts above the highest id currently in use
+# in the range. That also protects the ids of accounts deleted before the
+# counter existed, at the price of never filling the gaps below it.
+# This setting has no effect once the counter exists.
+# Default: ID_COUNTER_INIT=first_free
+#ID_COUNTER_INIT=first_free
+
# Specify a file or a directory containing UID and GID pool.
#UID_POOL=/etc/adduser-pool.conf
#UID_POOL=/etc/adduser-pool.d
=====================================
debian/NEWS
=====================================
@@ -57,13 +57,13 @@ adduser (3.130) unstable; urgency=low
installations are probably using a directory service like LDAP and Active
Directory to manage their users and do not use adduser anyway. If you're
using one of these options and want them to stay, please write that to
- #1025623 and let us know. Some kind of help and committment, for example
+ #1025623 and let us know. Some kind of help and commitment, for example
verified autopkgtest scripts, would be appreciated and make it easier for
us to keep the feature around.
We are planning to deprecate and remove the QUOTAUSER configuration
option. If you're using this, please write that to #1026898 and let us
- know. Some kind of help and committment, for example verified autopkg
+ know. Some kind of help and commitment, for example verified autopkg
testscripts, would be appreciated and make it easier for us to keep
the feature around.
=====================================
debian/README
=====================================
@@ -1,4 +1,4 @@
-This document was last touched in Februar 2025.
+This document was last touched in February 2025.
adduser in Debian
=================
@@ -112,7 +112,7 @@ postinst when your package gets reinstalled.
Locking and unlocking system accounts should be handled by adduser.
Currently, it doesn't. See bug #1008082 for this discussion. The goal is
to enable the local admin to choose whether purging a package should
-remove a system account or just lock it. For othogonality, there should
+remove a system account or just lock it. For orthogonality, there should
also be a possibility to undo this operation within adduser. For a
regular user account, the local admin is better served with calling
usermod --lock and usermod --unlock to do this.
=====================================
debian/README.source
=====================================
@@ -35,7 +35,7 @@ debian/latest: the latest Debian packaging. This branch should always be
and/or unstable
debian/releasename: security, stable updates. branched off debian/latest
when needed from the appropriate debian/<number> tag.
-debian/unstable: only exists when unstable work was neeed while
+debian/unstable: only exists when unstable work was needed while
debian/latest holds an experimental branch. branched off
debian/latest from the latest debian/<number> tag that got
uploaded to unstable
@@ -62,7 +62,7 @@ The package has two distinct rather extensive test suites: One that can be
considered "upstream", in "testsuite", and an autopkgtest test suite in
debian/tests. All bug fixes and features should be accompanied by appropriate
test cases. In case of a bug fix, a test case should be written first and
-committed separatly, so that the test can be cherry-picked and proven to fail
+committed separately, so that the test can be cherry-picked and proven to fail
without the fix.
Autopkgtest needs a full perl to run, adduser is specified to run without full
=====================================
debian/TODO
=====================================
@@ -20,7 +20,7 @@ For adduser 3.x there is to do:
for removal in bookworm+2.
* The --force-badname command line is deprecated as of bookworm+1.
- Run-time warnings shold be added to notify users of the change;
+ Run-time warnings should be added to notify users of the change;
the feature is slated for removal in bookworm+2.
* get rid of --no-preserve-root, refuse removing the root account in any case
=====================================
debian/control
=====================================
@@ -2,19 +2,31 @@ Source: adduser
Section: admin
Priority: important
Maintainer: Debian Adduser Developers <adduser at packages.debian.org>
-Uploaders: Marc Haber <mh+debian-packages at zugschlus.de>
-Standards-Version: 4.7.2
-Build-Depends: debhelper-compat (= 13), po4a
-Build-Depends-Indep: gettext
+Uploaders:
+ Marc Haber <mh+debian-packages at zugschlus.de>,
+Standards-Version: 4.7.4
+Build-Depends:
+ debhelper-compat (= 13),
+ po4a,
+Build-Depends-Indep:
+ gettext,
Vcs-Browser: https://salsa.debian.org/debian/adduser
Vcs-Git: https://salsa.debian.org/debian/adduser.git
Package: adduser
Architecture: all
Multi-Arch: foreign
-Pre-Depends: ${misc:Pre-Depends}
-Depends: passwd (>= 1:4.19.0-4), ${misc:Depends}
-Suggests: liblocale-gettext-perl, perl, cron, quota, ecryptfs-utils (>= 67-1)
+Pre-Depends:
+ ${misc:Pre-Depends},
+Depends:
+ passwd (>= 1:4.19.0-4),
+ ${misc:Depends},
+Suggests:
+ cron,
+ ecryptfs-utils (>= 67-1),
+ liblocale-gettext-perl,
+ perl,
+ quota,
Description: add and remove users and groups
This package includes the 'adduser' and 'deluser' commands for creating
and removing users.
=====================================
debian/examples
=====================================
@@ -1,3 +1,3 @@
-examples/*
adduser.conf
deluser.conf
+examples/*
=====================================
debian/links
=====================================
@@ -8,16 +8,16 @@ ${MANDIR}/man8/adduser.8 ${MANDIR}/man8/addgroup.8
${MANDIR}/man8/deluser.8 ${MANDIR}/man8/delgroup.8
EOLINKS
-cd debian/adduser > /dev/null
+cd debian/adduser > /dev/null || exit
-for MPLANG in $(find ${MANDIR} -mindepth 1 -maxdepth 1 -type d -name 'man?' -prune -o -printf '%f\n'); do
- if [ -e "${MANDIR}/${MPLANG}/man8/adduser.local.8" ]; then
+for MPLANG in $(find "${MANDIR}" -mindepth 1 -maxdepth 1 -type d -name 'man?' -prune -o -printf '%f\n'); do
+ if [[ -e "${MANDIR}/${MPLANG}/man8/adduser.local.8" ]]; then
printf "%s/%s/man8/adduser.local.8 %s/%s/man8/deluser.local.8\\n" "${MANDIR}" "${MPLANG}" "${MANDIR}" "${MPLANG}"
fi
- if [ -e "${MANDIR}/${MPLANG}/man8/adduser.8" ]; then
+ if [[ -e "${MANDIR}/${MPLANG}/man8/adduser.8" ]]; then
printf "%s/%s/man8/adduser.8 %s/%s/man8/addgroup.8\\n" "${MANDIR}" "${MPLANG}" "${MANDIR}" "${MPLANG}"
fi
- if [ -e "${MANDIR}/${MPLANG}/man8/deluser.8" ]; then
+ if [[ -e "${MANDIR}/${MPLANG}/man8/deluser.8" ]]; then
printf "%s/%s/man8/deluser.8 %s/%s/man8/delgroup.8\\n" "${MANDIR}" "${MPLANG}" "${MANDIR}" "${MPLANG}"
fi
done
=====================================
debian/manpages
=====================================
@@ -9,19 +9,19 @@ doc/deluser.conf.5
EOMAN
for MPLANG in $(find doc/ -maxdepth 1 -type f -name '*.??.?' -printf '%f\n' | sed 's/.*\.\(..\)\../\1/' |sort -u); do
- if [ -e "doc/adduser.${MPLANG}.8" ]; then
+ if [[ -e "doc/adduser.${MPLANG}.8" ]]; then
printf "doc/adduser.%s.8\\n" "${MPLANG}"
fi
- if [ -e "doc/adduser.conf.${MPLANG}.5" ]; then
+ if [[ -e "doc/adduser.conf.${MPLANG}.5" ]]; then
printf "doc/adduser.conf.%s.5\\n" "${MPLANG}"
fi
- if [ -e "doc/adduser.local.${MPLANG}.8" ]; then
+ if [[ -e "doc/adduser.local.${MPLANG}.8" ]]; then
printf "doc/adduser.local.%s.8\\n" "${MPLANG}"
fi
- if [ -e "doc/deluser.${MPLANG}.8" ]; then
+ if [[ -e "doc/deluser.${MPLANG}.8" ]]; then
printf "doc/deluser.%s.8\\n" "${MPLANG}"
fi
- if [ -e "doc/deluser.conf.${MPLANG}.5" ]; then
+ if [[ -e "doc/deluser.conf.${MPLANG}.5" ]]; then
printf "doc/deluser.conf.%s.5\\n" "${MPLANG}"
fi
done
=====================================
debian/tests/control
=====================================
@@ -2,31 +2,70 @@
# after apt purge perl if you want to test operation without full perl
Test-Command: /usr/bin/prove -v debian/tests/f
-Depends: @, cron, perl, login
-Restrictions: needs-root
-Features: test-name=debian-tests-f
+Depends:
+ cron,
+ login,
+ perl,
+ @,
+Restrictions:
+ needs-root,
+Features:
+ test-name=package-test-suite,
Test-Command: /usr/bin/prove -p -v debian/tests/ecryptfs
-Depends: cron, ecryptfs-utils, kmod, perl
-Restrictions: allow-stderr isolation-machine needs-root
-Features: test-name=ecryptfs-with-pkg
+Depends:
+ cron,
+ ecryptfs-utils,
+ kmod,
+ perl,
+Restrictions:
+ allow-stderr,
+ isolation-machine,
+ needs-root,
+Features:
+ test-name=ecryptfs-with-pkg,
Test-Command: /usr/bin/prove -p -v debian/tests/ecryptfs-no-package
-Depends: cron, kmod, perl
-Restrictions: allow-stderr isolation-machine needs-root
-Features: test-name=ecryptfs-without-pkg
+Depends:
+ cron,
+ kmod,
+ perl,
+Restrictions:
+ allow-stderr,
+ isolation-machine,
+ needs-root,
+Features:
+ test-name=ecryptfs-without-pkg,
Test-Command: cd testsuite/ && ./runsuite.sh
-Depends: @, cron, perl, login
-Restrictions: allow-stderr breaks-testbed needs-root
-Features: test-name=upstream-test-suite-full
+Depends:
+ cron,
+ login,
+ perl,
+ @,
+Restrictions:
+ allow-stderr,
+ breaks-testbed,
+ needs-root,
+Features:
+ test-name=upstream-test-suite-full,
Test-Command: cd testsuite/ && ./runsuite.sh
-Depends: @, login
-Restrictions: allow-stderr breaks-testbed needs-root
-Features: test-name=upstream-test-suite-minimal
+Depends:
+ login,
+ @,
+Restrictions:
+ allow-stderr,
+ breaks-testbed,
+ needs-root,
+Features:
+ test-name=upstream-test-suite-minimal,
Test-Command: /usr/sbin/adduser --system austc3
-Depends: @, login
-Restrictions: needs-root
-Features: test-name=basic-system-user
+Depends:
+ login,
+ @,
+Restrictions:
+ needs-root,
+Features:
+ test-name=basic-system-user,
=====================================
debian/tests/f/cron_jobs.t
=====================================
@@ -2,7 +2,7 @@
# Ref: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1006899
-# this test is skipped if /usr/bin/crontab is not foudn
+# this test is skipped if /usr/bin/crontab is not found
use diagnostics;
use strict;
=====================================
debian/tests/f/firstlastuidgid.t
=====================================
@@ -27,6 +27,10 @@ my $prefix;
sub cleanup {
my $prefix=$_[0] || '';
+ # the id counter (REUSE_IDS=no) must not leak from one test group
+ # into the next one, each of which expects to start from its own
+ # configured first id.
+ reset_state_file();
foreach $userbase( @unames ) {
$user=$prefix.$userbase;
system("/usr/sbin/deluser @quiet --remove-home $user 2>/dev/null");
@@ -233,6 +237,15 @@ sub assert_usergroup_loop {
$uidcount++;
}
} else {
+ if ($user_index == 1 && !$via_cli) {
+ # With the range taken from the config file, the id
+ # counter (REUSE_IDS=no) decides where the scan for the
+ # second user starts. What is checked here is the range,
+ # the counter itself is tested in id_counter.t.
+ $uidcount = (getpwnam($user))[2];
+ cmp_ok($uidcount, '>=', $firstuid,
+ "uid of $user is inside the configured range");
+ }
assert_user_has_uid($user, $uidcount);
$uidcount++;
while (defined(getpwuid($uidcount))) {
@@ -553,7 +566,7 @@ assert_usergroup_loop({prefix => 'u3a', system => 0, firstuid => 6100, firstgid
assert_command_success("true u3a2: FIRST_UID=6100 FIRST_GID=6150");
assert_plain_usergroup_loop({prefix => 'u3a2', system => 0, firstuid => 6100, expected_uidgid => 6150, via_cli => 0});
-# test group U4A: ranges requested by config, overriden by command line
+# test group U4A: ranges requested by config, overridden by command line
assert_usergroup_loop({prefix => 'u4a', system => 0, firstuid => 6200, firstgid => 6250, fuid => 6940, fgid => 6950});
@@ -587,7 +600,7 @@ assert_usergroup_loop({prefix => 's3a', system => 1, firstuid => 730, firstgid =
assert_plain_usergroup_loop({prefix => 's3a2', system => 1, firstuid => 730, via_cli => 0});
-# test group S4A: ranges requested by config, overriden by command line
+# test group S4A: ranges requested by config, overridden by command line
assert_usergroup_loop({prefix => 's4a', system => 1, firstuid => 760, firstgid => 780, fuid => 890, fgid => 900});
@@ -615,7 +628,7 @@ apply_config_hash(\%confhash);
assert_command_success("true firstuid=2090 firstgid=2190 lastuid=2093 lastgid=2193");
assert_usergroup_loop_to_exhaustion({prefix => 'u3l', system => 0, firstuid => 2090, lastuid => 2093, firstgid => 2190, lastgid => 2193, fuid => 3750, fgid => 3761, via_cli => 0});
-# test group U4L: ranges requested by config, overriden by command line
+# test group U4L: ranges requested by config, overridden by command line
assert_usergroup_loop_to_exhaustion({prefix => 'u4l', system => 0, firstuid => 2290, lastuid => 2293, firstgid => 2390, lastgid => 2393, fuid => 3750, fgid => 3761});
@@ -638,7 +651,7 @@ apply_config_hash(\%confhash);
assert_command_success("true firstsysuid=410 firstsysgid=510 lastsysuid=413 lastsysgid=513");
assert_usergroup_loop_to_exhaustion({prefix => 's3l', system => 1, firstuid => 410, lastuid => 413, firstgid => 510, lastgid => 513, fuid => 710, fgid => 760, via_cli => 0});
-# test group S4L: ranges requested by config, overriden by command line
+# test group S4L: ranges requested by config, overridden by command line
assert_usergroup_loop_to_exhaustion({prefix => 's4l', system => 1, firstuid => 320, lastuid => 323, firstgid => 520, lastgid => 523, fuid => 720, fgid => 770});
=====================================
debian/tests/f/firstlastuidgid_orig.t deleted
=====================================
@@ -1,1020 +0,0 @@
-#! /usr/bin/perl -Idebian/tests/lib
-
-# check first/last uid/gid functionality
-
-use diagnostics;
-use strict;
-use warnings;
-
-use AdduserTestsCommon;
-use Test::More;
-
-my @quiet=('--stdoutmsglevel=error', '--stderrmsglevel=error');
-my $gidcount;
-my $uidcount;
-
-my @unames = ( 'oflugu01', 'oflugu02', 'oflugu03', 'oflugu04' );
-my $unamex = 'oflugu05';
-my @gnames = ( 'oflugg01', 'oflugg02', 'oflugg03', 'oflugg04' );
-my $gnamex = 'oflugg05';
-my $funame = 'ofixedu01';
-my $fgname = 'ofixedg01';
-my $user;
-my $userbase;
-my $fuid;
-my $group;
-my $groupbase;
-my $fgid;
-my $prefix;
-
-my $firstuid1;
-my $lastuid1;
-my $firstgid1;
-my $lastgid1;
-
-sub cleanup {
- my $prefix=$_[0] || '';
- foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- system("/usr/sbin/deluser @quiet --remove-home $user 2>/dev/null");
- assert_user_does_not_exist($user);
- }
- system("/usr/sbin/deluser @quiet --remove-home $prefix$unamex 2>/dev/null");
- assert_user_does_not_exist($prefix.$unamex);
- system("/usr/sbin/deluser @quiet --remove-home $prefix$funame 2>/dev/null");
- assert_user_does_not_exist($prefix.$funame);
- $uidcount=0;
- foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- system("/usr/sbin/delgroup @quiet $group 2>/dev/null");
- assert_group_does_not_exist($group);
- }
- system("/usr/sbin/delgroup @quiet $prefix$gnamex 2>/dev/null");
- assert_group_does_not_exist($prefix.$gnamex);
- system("/usr/sbin/delgroup @quiet $prefix$fgname 2>/dev/null");
- assert_user_does_not_exist($prefix.$fgname);
- $gidcount=0;
-}
-cleanup();
-
-# test group U1A: default config, no command line
-
-$prefix = 'u1a';
-$fuid = 3750;
-$fgid = 3761;
-my %confhash=();
-apply_config_hash(\%confhash);
-
-foreach $groupbase( @gnames ) {
- $group = $prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet, $group);
- assert_group_exists($group);
- if ($gidcount==0) {
- $gidcount=((getgrnam($group))[2]);
- }
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user = $prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- if ($uidcount==0) {
- $uidcount=((getpwnam($user))[2]);
- }
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='u1a2';
-foreach $userbase( @unames ) {
- $user = $prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- assert_group_exists($user);
- if ($uidcount==0) {
- $uidcount=((getpwnam($user))[2]);
- }
- if ($gidcount==0) {
- $gidcount=((getgrnam($user))[2]);
- }
- assert_primary_group_membership_exists($user, $user);
- assert_user_has_uid($user, $uidcount);
- assert_group_has_gid($user, $gidcount);
- $uidcount++;
- $gidcount++;
-}
-cleanup($prefix);
-
-# test group U2A: default config, uid/gid range requested on command line
-
-$prefix='u2a';
-$firstuid1=2000;
-$firstgid1=2100;
-$fuid = 3750;
-$fgid = 3761;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_group_does_not_exist($prefix.$fgname);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- # commented. this behavior has changed - the first user created
- # gets the same uid as the group, the following users are one off
- # the expectation. this test is correctly in the new test file,
- # hence commented here.
- # assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='u2a2';
-$firstuid1=2000;
-$fuid = 3750;
-$uidcount=$firstuid1;
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_group_exists($user);
- assert_primary_group_membership_exists($user, $user);
- assert_user_has_uid($user, $uidcount);
- assert_group_has_gid($user, $uidcount);
- $uidcount++;
-}
-cleanup($prefix);
-
-# test group U3A: uid range requested by config, no command line
-
-$prefix='u3a';
-$firstuid1=2000;
-$firstgid1=2100;
-$fuid = 3750;
-$fgid = 3761;
-%confhash=();
-$confhash{'FIRST_UID'}="$firstuid1";
-$confhash{'FIRST_GID'}="$firstgid1";
-apply_config_hash(\%confhash);
-
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet, $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- # commented. this behavior has changed - the first user created
- # gets the same uid as the group, the following users are one off
- # the expectation. this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='u3a2';
-$firstuid1=2000;
-$fuid = 3750;
-$uidcount=$firstuid1;
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- assert_group_exists($user);
- assert_primary_group_membership_exists($user, $user);
- # commented. this behavior has changed. new adduser tries to
- # honor both the uid and the gid range in this case.
- # this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- #assert_group_has_gid($user, $uidcount);
- $uidcount++;
-}
-cleanup($prefix);
-
-# test group U4A: ranges requested by config, overriden by command line
-
-$prefix='u4a';
-$firstuid1=2200;
-$firstgid1=2300;
-$fuid = 3750;
-$fgid = 3761;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- # commented. this behavior has changed - the first user created
- # gets the same uid as the group, the following users are one off
- # the expectation. this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='u4a2';
-$firstuid1=2000;
-$fuid = 3750;
-$uidcount=$firstuid1;
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_group_exists($user);
- assert_primary_group_membership_exists($user, $user);
- # commented. this behavior has changed. new adduser tries to
- # honor both the uid and the gid range in this case.
- # this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- #assert_group_has_gid($user, $uidcount);
- $uidcount++;
-}
-cleanup($prefix);
-
-%confhash=();
-apply_config_hash(\%confhash);
-
-# test group S1A: default config, no command line
-
-$prefix = 's1a';
-$fuid = 200;
-$fgid = 210;
-%confhash=();
-apply_config_hash(\%confhash);
-
-foreach $groupbase( @gnames ) {
- $group = $prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet, '--system', $group);
- assert_group_exists($group);
- if ($gidcount==0) {
- $gidcount=((getgrnam($group))[2]);
- }
- assert_group_has_gid($group, $gidcount);
- while (defined(getgrgid($gidcount))) {
- $gidcount++;
- }
-}
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user = $prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- if ($uidcount==0) {
- $uidcount=((getpwnam($user))[2]);
- }
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- # commented. this behavior has changed - the first user created
- # gets the same uid as the group, the following users are one off
- # the expectation. this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- while (defined(getpwuid($uidcount))) {
- $uidcount++;
- }
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='s1a2';
-foreach $userbase( @unames ) {
- $user = $prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- if ($uidcount==0) {
- $uidcount=((getpwnam($user))[2]);
- }
- assert_primary_group_membership_exists($user, 'nogroup');
- assert_user_has_uid($user, $uidcount);
- while (defined(getpwuid($uidcount))) {
- $uidcount++;
- }
-}
-cleanup($prefix);
-
-# test group S2A: default config, uid/gid range requested on command line
-
-$prefix='s2a';
-$firstuid1=220;
-$firstgid1=230;
-$fuid = 850;
-$fgid = 860;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_group_does_not_exist($prefix.$fgname);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- # commented. this behavior has changed - the first user created
- # gets the same uid as the group, the following users are one off
- # the expectation. this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='s2a2';
-$firstuid1=240;
-$fuid = 250;
-$uidcount=$firstuid1;
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, 'nogroup');
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-cleanup($prefix);
-
-# test group S3A: uid range requested by config, no command line
-
-$prefix='s3a';
-$firstuid1=260;
-$firstgid1=270;
-$fuid = 870;
-$fgid = 880;
-%confhash=();
-$confhash{'FIRST_SYSTEM_UID'}="$firstuid1";
-$confhash{'FIRST_SYSTEM_GID'}="$firstgid1";
-apply_config_hash(\%confhash);
-
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', '--system', @quiet, $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- # commented. this behavior has changed - the first user created
- # gets the same uid as the group, the following users are one off
- # the expectation. this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='s3a2';
-$firstuid1=260;
-$fuid = 870;
-$uidcount=$firstuid1;
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, 'nogroup');
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-cleanup($prefix);
-
-# test group S4A: ranges requested by config, overriden by command line
-
-$prefix='s4a';
-$firstuid1=290;
-$firstgid1=300;
-$fuid = 810;
-$fgid = 820;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- # commented. this behavior has changed - the first user created
- # gets the same uid as the group, the following users are one off
- # the expectation. this test is correctly in the new test file,
- # hence commented here.
- #assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-$prefix='s4a2';
-$firstuid1=310;
-$fuid = 830;
-$uidcount=$firstuid1;
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, 'nogroup');
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-cleanup($prefix);
-
-%confhash=();
-apply_config_hash(\%confhash);
-
-
-# tests with last_ options: we set a range and fill it, last creation must fail
-
-# test group U1L: not applicable
-# test group U2L: default config, uid/gid range requested on command line
-
-$prefix='u2l';
-$firstuid1=2090;
-$lastuid1=2093;
-$firstgid1=2190;
-$lastgid1=2193;
-$fuid = 3750;
-$fgid = 3761;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_failure_silent('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $prefix.$gnamex);
-assert_group_does_not_exist($prefix.$gnamex);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_failure_silent('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $prefix.$unamex);
-assert_user_does_not_exist($prefix.$unamex);
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-# test group U3L: uid range requested by config, no command line
-
-$prefix='u3l';
-$firstuid1=2090;
-$lastuid1=2093;
-$firstgid1=2190;
-$lastgid1=2193;
-$fuid = 3750;
-$fgid = 3761;
-%confhash=();
-$confhash{'FIRST_UID'}="$firstuid1";
-$confhash{'FIRST_GID'}="$firstgid1";
-$confhash{'LAST_UID'}="$lastuid1";
-$confhash{'LAST_GID'}="$lastgid1";
-apply_config_hash(\%confhash);
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_failure_silent('/usr/sbin/addgroup', @quiet,
- $prefix.$gnamex);
-assert_group_does_not_exist($prefix.$gnamex);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_failure_silent('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $prefix.$unamex);
-assert_user_does_not_exist($unamex);
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-# test group U4L: ranges requested by config, overriden by command line
-
-$prefix='u4l';
-$firstuid1=2290;
-$lastuid1=2293;
-$firstgid1=2390;
-$lastgid1=2393;
-$fuid = 3750;
-$fgid = 3761;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_failure_silent('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $prefix.$gnamex);
-assert_group_does_not_exist($prefix.$gnamex);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_failure_silent('/usr/sbin/adduser', @quiet,
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $prefix.$unamex);
-assert_user_does_not_exist($prefix.$unamex);
-assert_command_success('/usr/sbin/adduser', @quiet,
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-%confhash=();
-apply_config_hash(\%confhash);
-
-# test group S1L: not applicable
-# test group S2L: default config, uid/gid range requested on command line
-
-$prefix='s2l';
-$firstuid1=400;
-$lastuid1=403;
-$firstgid1=500;
-$lastgid1=503;
-$fuid = 700;
-$fgid = 750;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_failure_silent('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $prefix.$gnamex);
-assert_group_does_not_exist($prefix.$gnamex);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_failure_silent('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $prefix.$unamex);
-assert_user_does_not_exist($prefix.$unamex);
-assert_command_success_silent('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-# test group S3L: uid range requested by config, no command line
-
-$prefix='s3l';
-$firstuid1=410;
-$lastuid1=413;
-$firstgid1=510;
-$lastgid1=513;
-$fuid = 710;
-$fgid = 760;
-%confhash=();
-$confhash{'FIRST_SYSTEM_UID'}="$firstuid1";
-$confhash{'FIRST_SYSTEM_GID'}="$firstgid1";
-$confhash{'LAST_SYSTEM_UID'}="$lastuid1";
-$confhash{'LAST_SYSTEM_GID'}="$lastgid1";
-apply_config_hash(\%confhash);
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_failure_silent('/usr/sbin/addgroup', @quiet,
- '--system',
- $prefix.$gnamex);
-assert_group_does_not_exist($prefix.$gnamex);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_failure_silent('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- $prefix.$unamex);
-assert_user_does_not_exist($unamex);
-assert_command_success_silent('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-# test group S4L: ranges requested by config, overriden by command line
-
-$prefix='s4l';
-$firstuid1=320;
-$lastuid1=323;
-$firstgid1=520;
-$lastgid1=523;
-$fuid = 720;
-$fgid = 770;
-$gidcount=$firstgid1;
-$uidcount=$firstuid1;
-foreach $groupbase( @gnames ) {
- $group=$prefix.$groupbase;
- assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $group);
- assert_group_exists($group);
- assert_group_has_gid($group, $gidcount);
- $gidcount++;
-}
-assert_command_failure_silent('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- $prefix.$gnamex);
-assert_group_does_not_exist($prefix.$gnamex);
-assert_command_success('/usr/sbin/addgroup', @quiet,
- '--system',
- '--firstgid', $firstgid1, '--lastgid', $lastgid1,
- '--gid', $fgid,
- $prefix.$fgname);
-assert_group_exists($prefix.$fgname);
-assert_group_has_gid($prefix.$fgname, $fgid);
-
-foreach $userbase( @unames ) {
- $user=$prefix.$userbase;
- assert_command_success('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $user);
- assert_user_exists($user);
- assert_primary_group_membership_exists($user, $prefix.$gnames[0]);
- assert_user_has_uid($user, $uidcount);
- $uidcount++;
-}
-assert_command_failure_silent('/usr/sbin/adduser', @quiet,
- '--system',
- '--ingroup', $prefix.$gnames[0],
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- $prefix.$unamex);
-assert_user_does_not_exist($prefix.$unamex);
-assert_command_success_silent('/usr/sbin/adduser', @quiet,
- '--system',
- '--comment', '""', '--disabled-password', '--no-create-home',
- '--firstuid', $firstuid1, '--lastuid', $lastuid1,
- '--uid', $fuid,
- $prefix.$funame);
-assert_user_exists($prefix.$funame);
-assert_user_has_uid($prefix.$funame, $fuid);
-cleanup($prefix);
-
-%confhash=();
-apply_config_hash(\%confhash);
-cleanup();
-
-done_testing();
-
-# vim: tabstop=4 shiftwidth=4 expandtab
=====================================
debian/tests/f/id_counter.t
=====================================
@@ -0,0 +1,298 @@
+#! /usr/bin/perl -Idebian/tests/lib
+
+# tests for the id counter that keeps adduser from re-using ids
+# (REUSE_IDS and ID_COUNTER_INIT)
+
+use diagnostics;
+use strict;
+use warnings;
+
+use AdduserTestsCommon;
+use Test::More;
+
+use lib '/usr/share/perl5';
+use Debian::AdduserStatefile;
+
+my $adduser = '/usr/sbin/adduser';
+my $deluser = '/usr/sbin/deluser';
+my $addgroup = '/usr/sbin/addgroup';
+my $delgroup = '/usr/sbin/delgroup';
+
+my @users = qw(
+ ausridinit1 ausridbug1 ausridbug2 ausridreuse1 ausridreuse2
+ ausridsys1 ausridsys2 ausridsysafter ausridforced ausridfull
+ ausridhigh ausridhighnew ausridlost1 ausridlost2
+ ausridconc1 ausridconc2 ausridconc3 ausridconc4 ausridconc5
+ ausridconc1 ausridconc2 ausridconc3 ausridconc4 ausridconc5
+ ausridrange1 ausridrange2 ausriddisj1 ausriddisj2
+);
+my @groups = qw(ausridgroup1 ausriddisjg1 ausriddisjg2);
+
+END {
+ cleanup_user($_) foreach (@users);
+ foreach my $group (@groups) {
+ system($delgroup, $group) if (defined(getgrnam($group)));
+ }
+ done_testing();
+}
+
+# create a user without any interactive prompt, and return its uid
+sub add_user {
+ my ($name, @args) = @_;
+ assert_command_success($adduser,
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--comment', '""', '--disabled-password',
+ @args, $name);
+ assert_user_exists($name);
+ return scalar(getpwnam($name));
+}
+
+sub remove_user {
+ my ($name) = @_;
+ system($deluser, '--remove-home', $name);
+ assert_user_does_not_exist($name);
+}
+
+##############################################################
+# 1. on a system without a state file, the counter is created
+# with the id that has just been handed out
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+assert_no_state_file();
+
+my $uid = add_user('ausridinit1');
+assert_state_global('last_id', $uid);
+
+##############################################################
+# 2. an id that has been used once is not handed out again,
+# even after the account has been deleted
+# (the case Joerg Hoh described in 2006)
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+
+my $uid_first = add_user('ausridbug1');
+remove_user('ausridbug1');
+
+my $uid_second = add_user('ausridbug2');
+isnt($uid_second, $uid_first,
+ "the uid of a deleted account is not handed out again");
+cmp_ok($uid_second, '>', $uid_first,
+ "the new uid is above the counter");
+assert_state_global('last_id', $uid_second);
+
+##############################################################
+# 3. with REUSE_IDS set to yes, the previous behaviour is kept
+# and no counter is written at all
+##############################################################
+apply_config('REUSE_IDS', 'yes');
+reset_state_file();
+
+my $uid_reuse = add_user('ausridreuse1');
+remove_user('ausridreuse1');
+
+my $uid_again = add_user('ausridreuse2');
+is($uid_again, $uid_reuse,
+ "with REUSE_IDS=yes the freed uid is used again");
+assert_no_state_file();
+
+##############################################################
+# 4. system users have a counter of their own, and using it
+# does not affect the counter of the regular range
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+
+my $sys_first = add_user('ausridsys1', '--system');
+assert_state_global('last_sys_id', $sys_first);
+remove_user('ausridsys1');
+
+my $sys_second = add_user('ausridsys2', '--system');
+cmp_ok($sys_second, '>', $sys_first,
+ "the uid of a deleted system account is not handed out again");
+assert_state_global('last_sys_id', $sys_second);
+
+# the regular range is untouched by all of the above
+my $after_sys = add_user('ausridsysafter');
+cmp_ok($after_sys, '>=', 1000,
+ "the system counter does not push regular uids");
+assert_state_global('last_id', $after_sys);
+
+##############################################################
+# 5. an id given by the admin is none of adduser's business:
+# the counter is neither consulted nor updated
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+
+my $forced = add_user('ausridforced', '--uid', '4242');
+is($forced, 4242, "the requested uid has been used");
+assert_no_state_file();
+
+##############################################################
+# 6. addgroup consumes an id of the range as well, so it moves
+# the same counter: this is what keeps uids and gids aligned
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+
+assert_command_success($addgroup,
+ '--stdoutmsglevel=error', '--stderrmsglevel=error', 'ausridgroup1');
+my $gid = scalar(getgrnam('ausridgroup1'));
+assert_state_global('last_id', $gid);
+
+##############################################################
+# 7. when the counter has passed the end of the range, adduser
+# explains why and creates nothing
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+set_global_value('last_id', 59999);
+
+assert_command_result_silent(22, $adduser,
+ '--comment', '""', '--disabled-password', 'ausridfull');
+assert_user_does_not_exist('ausridfull');
+
+##############################################################
+# 8. with ID_COUNTER_INIT set to highest, the counter starts
+# above the highest id in use instead of at the first free one
+##############################################################
+apply_config('REUSE_IDS', 'no', 'ID_COUNTER_INIT', 'highest');
+reset_state_file();
+
+my $high_uid = 5000;
+$high_uid++ while (defined(getpwuid($high_uid)) || defined(getgrgid($high_uid)));
+
+my $high = add_user('ausridhigh', '--uid', $high_uid);
+is($high, $high_uid, "the requested uid has been used");
+assert_no_state_file();
+
+my $after_high = add_user('ausridhighnew');
+is($after_high, $high_uid + 1,
+ "the counter has been initialised above the highest id in use");
+assert_state_global('last_id', $high_uid + 1);
+
+##############################################################
+# 9. the guarantee only holds while the state file survives:
+# losing it degrades to the behaviour of a fresh system
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+
+my $before_loss = add_user('ausridlost1');
+assert_state_global('last_id', $before_loss);
+
+reset_state_file();
+assert_no_state_file();
+
+my $after_loss = add_user('ausridlost2');
+assert_state_global('last_id', $after_loss);
+isnt($after_loss, $before_loss,
+ "the id of the still existing account is not handed out again");
+
+##############################################################
+# 10. concurrent invocations must not hand out the same id.
+# Five processes at once, no timing assumptions: what is
+# checked is that all five ids differ and that the counter
+# ends up at the highest of them.
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+
+my @concurrent = qw(ausridconc1 ausridconc2 ausridconc3 ausridconc4 ausridconc5);
+my @pids;
+
+foreach my $name (@concurrent) {
+ my $pid = fork();
+ if (!defined($pid)) {
+ fail("fork failed: $!");
+ last;
+ }
+ if ($pid == 0) {
+ # the child replaces itself, so it never runs the test harness
+ open(STDOUT, '>', '/dev/null');
+ open(STDERR, '>', '/dev/null');
+ exec($adduser, '--comment', '""', '--disabled-password', $name);
+ exit(127);
+ }
+ push(@pids, $pid);
+}
+waitpid($_, 0) foreach (@pids);
+
+my %seen;
+my $highest = 0;
+foreach my $name (@concurrent) {
+ my $id = scalar(getpwnam($name));
+ if (!defined($id)) {
+ fail("concurrent user $name has been created");
+ next;
+ }
+ $seen{$id} = $name;
+ $highest = $id if ($id > $highest);
+}
+
+is(scalar(keys %seen), scalar(@concurrent),
+ "concurrent invocations handed out distinct uids");
+assert_state_global('last_id', $highest);
+
+##############################################################
+# 11. an explicitly requested range overrides the counter:
+# the account gets the first free id in that range, the
+# counter is neither read nor updated, and an id freed
+# inside that range is handed out again.
+##############################################################
+apply_config('REUSE_IDS', 'no');
+reset_state_file();
+
+my $ranged = add_user('ausridrange1', '--firstuid', '31000', '--lastuid', '31010');
+is($ranged, 31000, "an explicit range starts at its first free id");
+assert_no_state_file();
+
+cleanup_user('ausridrange1');
+my $ranged_again = add_user('ausridrange1', '--firstuid', '31000', '--lastuid', '31010');
+is($ranged_again, 31000, "an explicit range hands out a freed id again");
+assert_no_state_file();
+
+# the counter was never written, so the next regular user starts it on its
+# own id instead of continuing from the ranged one
+my $regular = add_user('ausridrange2');
+isnt($regular, 31000, "a regular user is not affected by the previous range");
+assert_state_global('last_id', $regular);
+
+##############################################################
+# 11. if the uid range and the gid range differ, each has its
+# own counter: creating groups must not move the uid counter,
+# in particular not above the end of the uid range
+##############################################################
+apply_config('REUSE_IDS', 'no',
+ 'FIRST_UID', '52000', 'LAST_UID', '52003',
+ 'FIRST_GID', '52100', 'LAST_GID', '52103');
+reset_state_file();
+
+foreach my $group (qw(ausriddisjg1 ausriddisjg2)) {
+ assert_command_success($addgroup,
+ '--stdoutmsglevel=error', '--stderrmsglevel=error', $group);
+}
+my $disj_gid = scalar(getgrnam('ausriddisjg2'));
+is($disj_gid, 52101, "groups are taken from the gid range");
+assert_state_global('last_gid', 52101);
+ok(!defined(get_global_value('last_id')),
+ "the shared counter has not been used");
+
+# the gid of the first group is not in the uid range, so the first
+# free uid of the uid range is used
+my $disj1 = add_user('ausriddisj1', '--no-create-home',
+ '--ingroup', 'ausriddisjg1');
+is($disj1, 52000, "uid comes from the uid range, not above it");
+assert_state_global('last_uid', 52000);
+
+my $disj2 = add_user('ausriddisj2', '--no-create-home',
+ '--ingroup', 'ausriddisjg1');
+is($disj2, 52001, "the uid counter continues in the uid range");
+assert_state_global('last_uid', 52001);
+assert_state_global('last_gid', 52101);
+
+# done_testing(); done in END
+
+# vim: tabstop=4 shiftwidth=4 expandtab
=====================================
debian/tests/f/ingroup_uid.t
=====================================
@@ -0,0 +1,56 @@
+#! /usr/bin/perl -Idebian/tests/lib
+
+# adduser --ingroup: if the GID of the primary group is also free as a
+# UID, the user gets that UID, even if the id counter (REUSE_IDS=no)
+# has already advanced beyond it because of groups created later.
+
+use diagnostics;
+use strict;
+use warnings;
+
+use AdduserTestsCommon;
+use Test::More;
+
+my $adduser = '/usr/sbin/adduser';
+my $addgroup = '/usr/sbin/addgroup';
+my $delgroup = '/usr/sbin/delgroup';
+
+my @groups = qw(aingrpuid1 aingrpuid2 aingrpuid3 aingrpuid4);
+my @users = qw(aingrpuser1);
+
+END {
+ cleanup_user($_) foreach (@users);
+ foreach my $group (@groups) {
+ system($delgroup, $group) if (defined(getgrnam($group)));
+ }
+ done_testing();
+}
+
+foreach my $reuse ('no', 'yes') {
+ apply_config('REUSE_IDS', $reuse);
+ reset_state_file();
+
+ foreach my $group (@groups) {
+ assert_command_success($addgroup,
+ '--stdoutmsglevel=error', '--stderrmsglevel=error', $group);
+ }
+
+ my $gid = scalar(getgrnam('aingrpuid2'));
+ ok(defined($gid), "group aingrpuid2 has gid $gid (REUSE_IDS=$reuse)");
+ ok(!defined(getpwuid($gid)), "uid $gid is free");
+
+ assert_command_success($adduser,
+ '--stdoutmsglevel=error', '--stderrmsglevel=error',
+ '--comment', '\"\"', '--disabled-password',
+ '--ingroup', 'aingrpuid2', $users[0]);
+ assert_user_exists($users[0]);
+ is(scalar(getpwnam($users[0])), $gid,
+ "uid equals gid of --ingroup group (REUSE_IDS=$reuse)");
+
+ cleanup_user($users[0]);
+ foreach my $group (@groups) {
+ system($delgroup, $group);
+ }
+}
+
+# vim: tabstop=4 shiftwidth=4 expandtab
=====================================
debian/tests/f/suidsgidpool.t
=====================================
@@ -204,6 +204,7 @@ $confhash{"FIRST_SYSTEM_UID"}="$firstuid";
$confhash{"FIRST_SYSTEM_GID"}="$firstgid";
$confhash{"RESERVE_UID_POOL"}="no";
$confhash{"RESERVE_GID_POOL"}="no";
+$confhash{"REUSE_IDS"}="yes";
apply_config_hash(\%confhash);
# test not reserved uid in pool
@@ -276,6 +277,7 @@ $confhash{"FIRST_SYSTEM_UID"}="$firstuid";
$confhash{"FIRST_SYSTEM_GID"}="$firstgid";
$confhash{"RESERVE_UID_POOL"}="no";
$confhash{"RESERVE_GID_POOL"}="no";
+$confhash{"REUSE_IDS"}="yes";
apply_config_hash(\%confhash);
# test not reserved uid in pool
=====================================
debian/tests/f/uidgidpool.t
=====================================
@@ -206,6 +206,7 @@ $confhash{"FIRST_UID"}="$firstuid";
$confhash{"FIRST_GID"}="$firstgid";
$confhash{"RESERVE_UID_POOL"}="no";
$confhash{"RESERVE_GID_POOL"}="no";
+$confhash{"REUSE_IDS"}="yes";
apply_config_hash(\%confhash);
# test not reserved uid in pool
@@ -281,6 +282,7 @@ $confhash{"FIRST_UID"}="$firstuid";
$confhash{"FIRST_GID"}="$firstgid";
$confhash{"RESERVE_UID_POOL"}="no";
$confhash{"RESERVE_GID_POOL"}="no";
+$confhash{"REUSE_IDS"}="yes";
apply_config_hash(\%confhash);
# test not reserved uid in pool
=====================================
debian/tests/f/valid_username.t
=====================================
@@ -166,7 +166,7 @@ test_name("\\}b", FAIL, FAIL|BAD, FAIL|ABAD, FAIL|FBAD, FAIL|ALL,
# windows conventions
test_name('machine$', PASS,
$pat{ieee}, PASS);
-# useradd 4.17.2 doesnt accept \ any more
+# useradd 4.17.2 doesn't accept \ any more
test_name('DOMAIN\user', FAIL, FAIL|BAD, FAIL|FBAD, FAIL|ABAD, FAIL|ALL,
$pat{min}, FAIL);
@@ -193,7 +193,7 @@ test_name("test/slash", FAIL,
$pat{min}, FAIL, FAIL|BAD, FAIL|ABAD, FAIL|FBAD, FAIL|ALL);
# some stranger choices
-# useradd 4.17.2 does not acccept *, > and % any more
+# useradd 4.17.2 does not accept *, > and % any more
test_name('*', FAIL|BAD, FAIL|ABAD, FAIL|FBAD, FAIL|ALL, $pat{min}, FAIL);
test_name('3>6', FAIL, FAIL|BAD, FAIL|ABAD, FAIL|FBAD, FAIL|ALL, $pat{min}, FAIL);
test_name('.com', FAIL, PASS|BAD, PASS|ABAD, PASS|FBAD, PASS|ALL, $pat{min}, PASS);
=====================================
debian/tests/lib/AdduserTestsCommon.pm
=====================================
@@ -7,10 +7,14 @@ use strict;
use warnings;
use Encode;
use I18N::Langinfo qw(langinfo CODESET);
-use File::Path qw(remove_tree);
+use File::Path qw(make_path remove_tree);
use Test::More;
our @EXPORT = qw(
+ reset_state_file
+ assert_no_state_file
+ assert_state_global
+ assert_state_user
egetgrnam
egetpwnam
in_range
@@ -104,10 +108,20 @@ BEGIN {
'etc/login.defs',
'etc/passwd',
'etc/shadow',
+ 'var/lib/adduser/state',
);
- mkdir('/var/cache/adduser/tests');
- system('/bin/tar', 'cf', '/var/cache/adduser/tests/state.tar', '--directory=/', @conffiles);
+ make_path('/var/lib/adduser');
+ if (! -e '/var/lib/adduser/state') {
+ open(my $fh, '>', '/var/lib/adduser/state')
+ or die "cannot create /var/lib/adduser/state: $!";
+ close($fh);
+ }
+
+ make_path('/var/cache/adduser/tests');
+ system('/bin/tar', 'cf', '/var/cache/adduser/tests/state.tar',
+ '--directory=/', @conffiles) == 0
+ or die "cannot create the test state snapshot";
}
}
@@ -142,6 +156,66 @@ our @skelfiles = (
"Masaüstü/ŞĞÇaŞ-tst",
);
+our $STATE_FILE = '/var/lib/adduser/state';
+our $STATE_GLOBAL = '@global';
+
+sub _read_state_file {
+ my %state;
+
+ open(my $fh, '<', $STATE_FILE) or return %state;
+ while (my $line = <$fh>) {
+ chomp $line;
+ next if ($line =~ /^\s*$/ || $line =~ /^\s*#/);
+ my ($record, @pairs) = split(/:/, $line);
+ next unless defined $record;
+ foreach my $pair (@pairs) {
+ my ($key, $value) = split(/=/, $pair, 2);
+ $state{$record}{$key} = $value if (defined $key && defined $value);
+ }
+ }
+ close($fh);
+
+ return %state;
+}
+
+sub _assert_state_record {
+ my ($record, $key, $expected, $desc) = @_;
+ my $name = "state file: $desc has $key=$expected";
+
+ if (! -e $STATE_FILE) {
+ fail($name);
+ diag("state file $STATE_FILE does not exist");
+ return;
+ }
+
+ my %state = _read_state_file();
+ if (!exists $state{$record}) {
+ fail($name);
+ diag("no record `$record' in $STATE_FILE");
+ return;
+ }
+
+ is($state{$record}{$key}, $expected, $name);
+}
+
+sub reset_state_file {
+ unlink($STATE_FILE);
+}
+
+sub assert_no_state_file {
+ ok(! -e $STATE_FILE, "state file does not exist");
+}
+
+sub assert_state_global {
+ my ($key, $expected) = @_;
+ _assert_state_record($STATE_GLOBAL, $key, $expected, "global record");
+}
+
+sub assert_state_user {
+ my ($user, $key, $expected) = @_;
+ _assert_state_record($user, $key, $expected, "user $user");
+}
+
sub egetgrnam {
my ($name) = @_;
$name = encode($charset, $name);
@@ -614,7 +688,7 @@ sub user_uid_exists {
}
sub assert_user_has_disabled_password {
- # this should be changed to check against the varios ways of
+ # this should be changed to check against the various ways of
# checking an account: !, * in shadow, and expiry. It should change
# to a two-argument variant that checks for certain kind of lock
my $user = shift;
=====================================
debian/tests/no-autopkgtest
=====================================
@@ -8,7 +8,7 @@ set -e
cd testsuite && ./runsuite.sh
cd ..
for t in debian/tests/f/*.t; do
- ./$t;
+ ./"$t";
done
echo "all tests run"
=====================================
doc/adduser.conf.5
=====================================
@@ -91,6 +91,20 @@ Defaults to \fI1000\fP - \fI59999\fP.
.B GID_POOL
See \fBUID_POOL\fP.
.TP
+.B ID_COUNTER_INIT
+Where the id counter starts on a system that does not have one yet.
+With \fIfirst_free\fP,
+the counter only comes into existence when \fBadduser\fR(8) hands out an id,
+so ids below the highest one already in use remain available.
+With \fIhighest\fP,
+the counter starts above the highest id currently in use in the range,
+which also protects the ids of accounts that were deleted
+before the counter existed,
+at the price of never filling the gaps below it.
+This option has no effect once the counter exists,
+or if \fBREUSE_IDS\fP is set to \fIyes\fP.
+Defaults to \fIfirst_free\fP.
+.TP
.B LAST_SYSTEM_GID
.TQ
.B LAST_GID
@@ -117,6 +131,22 @@ files are truly reserved.
See UID AND GID POOLS in the NOTES section.
Defaults to \fIyes\fR.
.TP
+.B REUSE_IDS
+Controls whether an id that has already been handed out by \fBadduser\fR(8)
+may be handed out again after the account has been deleted.
+With \fIno\fP,
+a counter is kept in \fI/var/lib/adduser/state\fP
+and no id below it is allocated again,
+so a uid or gid is used at most once on this system.
+An explicit range given on the command line
+(\fB\-\-firstuid\fP, \fB\-\-lastuid\fP, \fB\-\-firstgid\fP, \fB\-\-lastgid\fP)
+overrides the counter:
+the first free id of that range is used
+and the counter is neither read nor updated.
+Ids requested with \fB\-\-uid\fP or \fB\-\-gid\fP never take part in the counter.
+See \fBID_COUNTER_INIT\fP.
+Defaults to \fIno\fR.
+.TP
.B SKEL
The directory from which
skeletal user configuration files will be copied.
@@ -226,6 +256,8 @@ by accounts that are not in the pool.
.SH FILES
.I /etc/adduser.conf
+.br
+.I /var/lib/adduser/state
.SH SEE ALSO
.BR deluser.conf (5),
.BR addgroup (8),
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/13125f96bbf80fd69897609f2802432ebb3759d1...4d32a479ad14be1b6547c85478deaae3b5180dc7
--
View it on GitLab: https://salsa.debian.org/debian/adduser/-/compare/13125f96bbf80fd69897609f2802432ebb3759d1...4d32a479ad14be1b6547c85478deaae3b5180dc7
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-shadow-devel/attachments/20261126/8ba757a7/attachment-0001.htm>
More information about the Pkg-shadow-devel
mailing list