On 2025-03-04 13:41:28 +0100, Vincent Lefevre wrote:
> I recall the problematic code:
>
> my $ret = existing_user_status($new_name, $new_uid);
> if ($ret == (EXISTING_FOUND|EXISTING_SYSTEM)) {
> # a user with this name already exists; it's a problem when it's not
> a system user
> log_fatal( mtx("The user `%s' already exists, but is not a system
> user. Exiting."), $new_name );
> exit( RET_WRONG_OBJECT_PROPERTIES );
> }
I think that the test should just be
if (($ret & EXISTING_FOUND) && !($ret & EXISTING_SYSTEM)) {
But you could factorize the EXISTING_FOUND case as done for the
addsysgroup action:
my $ret = existing_user_status($new_name, $new_uid);
if ($ret == (EXISTING_FOUND|EXISTING_SYSTEM)) {
# a user with this name already exists; it's a problem when it's not a
system user
log_fatal( mtx("The user `%s' already exists, but is not a system user.
Exiting."), $new_name );
exit( RET_WRONG_OBJECT_PROPERTIES );
}
if ($ret & EXISTING_ID_MISMATCH) {
log_fatal( mtx("The user `%s' already exists with a different UID.
Exiting."), $new_name );
exit( RET_WRONG_OBJECT_PROPERTIES );
}
if ($ret & EXISTING_FOUND) {
log_fatal( mtx("The system user `%s' already exists. Exiting.\n"),
$new_name );
exit( RET_OK );
}
would be changed to
my $ret = existing_user_status($new_name, $new_uid);
if ($ret & EXISTING_FOUND) {
if (!($ret & EXISTING_SYSTEM)) {
# a user with this name already exists; it's a problem when it's
not a system user
log_fatal( mtx("The user `%s' already exists, but is not a system
user. Exiting."), $new_name );
exit( RET_WRONG_OBJECT_PROPERTIES );
}
if ($ret & EXISTING_ID_MISMATCH) {
log_fatal( mtx("The user `%s' already exists with a different UID.
Exiting."), $new_name );
exit( RET_WRONG_OBJECT_PROPERTIES );
}
log_fatal( mtx("The system user `%s' already exists. Exiting.\n"),
$new_name );
exit( RET_OK );
}
Not tested.
--
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)