]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
16 hours ago(pre-)Release 4.19.0-rc1 2025-12-07/4.19.0-rc1 master 1411/head 4.19.0-rc1
Serge Hallyn [Sun, 7 Dec 2025 16:08:19 +0000 (10:08 -0600)] 
(pre-)Release 4.19.0-rc1

First pre-release of 'herve', 4.19.0

Signed-off-by: Serge Hallyn <serge@hallyn.com>
27 hours agolib/tcbfuncs.c: rmdir_leading(): Create string just once
Alejandro Colomar [Sat, 16 Nov 2024 21:20:16 +0000 (22:20 +0100)] 
lib/tcbfuncs.c: rmdir_leading(): Create string just once

Signed-off-by: Alejandro Colomar <alx@kernel.org>
27 hours agolib/tcbfuncs.c: rmdir_leading(): Constify input
Alejandro Colomar [Sat, 16 Nov 2024 17:16:40 +0000 (18:16 +0100)] 
lib/tcbfuncs.c: rmdir_leading(): Constify input

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/search/: lsearch_T(): Don't return anything
Alejandro Colomar [Mon, 17 Nov 2025 19:50:31 +0000 (20:50 +0100)] 
lib/search/: lsearch_T(): Don't return anything

We don't use this value.  This silences a diagnostic about the unused
return value.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Rename XCALLOC() => xcalloc_T()
Alejandro Colomar [Sat, 15 Nov 2025 21:12:22 +0000 (22:12 +0100)] 
lib/: Rename XCALLOC() => xcalloc_T()

The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Rename CALLOC() => calloc_T()
Alejandro Colomar [Sat, 15 Nov 2025 21:08:15 +0000 (22:08 +0100)] 
lib/: Rename CALLOC() => calloc_T()

The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Rename XMALLOC() => xmalloc_T()
Alejandro Colomar [Sat, 15 Nov 2025 21:02:33 +0000 (22:02 +0100)] 
lib/: Rename XMALLOC() => xmalloc_T()

The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Rename MALLOC() => malloc_T()
Alejandro Colomar [Sat, 15 Nov 2025 21:01:20 +0000 (22:01 +0100)] 
lib/: Rename MALLOC() => malloc_T()

The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Rename XREALLOC() => xrealloc_T()
Alejandro Colomar [Sat, 15 Nov 2025 20:58:10 +0000 (21:58 +0100)] 
lib/: Rename XREALLOC() => xrealloc_T()

The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Rename REALLOC() => realloc_T()
Alejandro Colomar [Sat, 15 Nov 2025 20:56:34 +0000 (21:56 +0100)] 
lib/: Rename REALLOC() => realloc_T()

The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/, src/: Rename REALLOCF() => reallocf_T()
Alejandro Colomar [Sat, 15 Nov 2025 20:47:56 +0000 (21:47 +0100)] 
lib/, src/: Rename REALLOCF() => reallocf_T()

The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/alloc/: REALLOC[F](): Move _Generic(3) to separate line
Alejandro Colomar [Fri, 14 Nov 2025 00:50:11 +0000 (01:50 +0100)] 
lib/alloc/: REALLOC[F](): Move _Generic(3) to separate line

This should be more readable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Use compound literals to avoid casts
Alejandro Colomar [Fri, 14 Nov 2025 01:29:16 +0000 (02:29 +0100)] 
lib/: Use compound literals to avoid casts

Casts are unsafe.

Compound literals also have the ability of converting values, but they
don't have the unwanted effects on safety --casts disable most useful
diagnostics--.

Compound literals are lvalues, which means their address can be taken,
and they can also be assigned to.  To avoid this, we force lvalue
conversion through a statement expression.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/alloc/: reallocarray[f]_(): Add helper macros to handle n?:1
Alejandro Colomar [Sat, 15 Nov 2025 20:33:21 +0000 (21:33 +0100)] 
lib/alloc/: reallocarray[f]_(): Add helper macros to handle n?:1

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/gshadow.c: fgetsgent(): Don't use static variables
Alejandro Colomar [Mon, 22 Jul 2024 17:34:21 +0000 (19:34 +0200)] 
lib/gshadow.c: fgetsgent(): Don't use static variables

BTW, getline(3) says we are responsible for free(3)ing the buffer on
error.

Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Use getline(3) instead of its pattern
Alejandro Colomar [Mon, 22 Jul 2024 11:46:32 +0000 (13:46 +0200)] 
lib/: Use getline(3) instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/, po/: Remove fgetsx() and fputsx()
Alejandro Colomar [Sun, 21 Jul 2024 16:40:25 +0000 (18:40 +0200)] 
lib/, po/: Remove fgetsx() and fputsx()

It seems they never worked correctly.  Let's keep it simple and remove
support for escaped newlines.

Closes: <https://github.com/shadow-maint/shadow/issues/1055>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agotests/system/tests/test_newgrp.py: change to new group
Iker Pedrosa [Thu, 21 Aug 2025 10:57:16 +0000 (12:57 +0200)] 
tests/system/tests/test_newgrp.py: change to new group

Change to a new group using `newgrp`.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agotests/system/framework/roles/shadow.py: implement binding for `newgrp`
Iker Pedrosa [Thu, 21 Aug 2025 10:55:20 +0000 (12:55 +0200)] 
tests/system/framework/roles/shadow.py: implement binding for `newgrp`

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agoshare/ansible/: Make sure `expect` is found in Alpine
Iker Pedrosa [Thu, 21 Aug 2025 13:37:41 +0000 (15:37 +0200)] 
share/ansible/: Make sure `expect` is found in Alpine

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agoshare/ansible/: install `expect` package
Iker Pedrosa [Thu, 21 Aug 2025 10:54:21 +0000 (12:54 +0200)] 
share/ansible/: install `expect` package

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agotests/system/tests/test_groupmems.py: add user to group as root user
Iker Pedrosa [Tue, 19 Aug 2025 09:26:18 +0000 (11:26 +0200)] 
tests/system/tests/test_groupmems.py: add user to group as root user

This is the transformation to Python of the test located in
`tests/grouptools/groupmems/01_groupmems_root_add_user/groupmems.test`,
which checks that `groupmems` is able to add a user to a group running
as the root user.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agotests/system/framework/roles/shadow.py: implement binding for `groupmems`
Iker Pedrosa [Tue, 19 Aug 2025 09:23:16 +0000 (11:23 +0200)] 
tests/system/framework/roles/shadow.py: implement binding for `groupmems`

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agoshare/ansible/: create the groupmems PAM service file
Iker Pedrosa [Tue, 19 Aug 2025 09:47:42 +0000 (11:47 +0200)] 
share/ansible/: create the groupmems PAM service file

Temporary workaround to create the groupmems PAM service file. Fedora
will soon provide this service file and we'll be able to remove the
workaround.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agotests/system/tests/test_newusers.py: create multiple users using file input
Iker Pedrosa [Fri, 8 Aug 2025 15:08:20 +0000 (17:08 +0200)] 
tests/system/tests/test_newusers.py: create multiple users using file input

This is the transformation to Python of the test located in
`tests/newusers/20_multiple_users/newusers.test`, which checks that
`newusers` is able to create new users from file.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agotests/system/tests/test_newusers.py: create multiple users from stdin
Iker Pedrosa [Fri, 8 Aug 2025 15:05:42 +0000 (17:05 +0200)] 
tests/system/tests/test_newusers.py: create multiple users from stdin

This is the transformation to Python of the test located in
`tests/newusers/35_read_from_stdin/newusers.test`, which checks that
`newusers` is able to create new users from stdin.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agotests/system/framework/roles/shadow.py: implement binding for `newusers`
Iker Pedrosa [Fri, 8 Aug 2025 14:22:16 +0000 (16:22 +0200)] 
tests/system/framework/roles/shadow.py: implement binding for `newusers`

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agoshare/ansible/: create the newusers PAM service file
Iker Pedrosa [Fri, 8 Aug 2025 14:20:59 +0000 (16:20 +0200)] 
share/ansible/: create the newusers PAM service file

Temporary workaround to create the newusers PAM service file. Fedora
will soon provide this service file and we'll be able to remove the
workaround.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 days agolib/search/: Use (void)0 within _Generic(3) to avoid -Wunused-value diagnostics
Alejandro Colomar [Fri, 5 Dec 2025 15:06:15 +0000 (16:06 +0100)] 
lib/search/: Use (void)0 within _Generic(3) to avoid -Wunused-value diagnostics

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/sssd.h: sssd_flush_cache(): Define as static inline function
Alejandro Colomar [Fri, 21 Feb 2025 07:41:37 +0000 (08:41 +0100)] 
lib/sssd.h: sssd_flush_cache(): Define as static inline function

Being a macro, the unused return value triggers a diagnostic.
This probably needs further investigation, but we have the issue linked
below for that.

Link: <https://github.com/shadow-maint/shadow/issues/1221>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agoautogen.sh: CFLAGS: Promose some -Wunused-* to an error
Alejandro Colomar [Sat, 29 Nov 2025 23:24:13 +0000 (00:24 +0100)] 
autogen.sh: CFLAGS: Promose some -Wunused-* to an error

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled...
Alejandro Colomar [Fri, 21 Feb 2025 07:47:29 +0000 (08:47 +0100)] 
lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
Alejandro Colomar [Fri, 21 Feb 2025 07:05:42 +0000 (08:05 +0100)] 
lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/logind.c: Unname unused function parameter
Alejandro Colomar [Fri, 21 Feb 2025 05:46:53 +0000 (06:46 +0100)] 
lib/logind.c: Unname unused function parameter

[Serge: preference to keep the names as a comment, but ok]
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/, src/ tests/: Unname unused parameters in callbacks
Alejandro Colomar [Fri, 21 Feb 2025 05:25:15 +0000 (06:25 +0100)] 
lib/, src/ tests/: Unname unused parameters in callbacks

[Serge: preference to keep the names as a comment, but ok]
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agosrc/: Unname unused parameter of main()
Alejandro Colomar [Thu, 20 Feb 2025 16:44:02 +0000 (17:44 +0100)] 
src/: Unname unused parameter of main()

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agonewusers: allow not passing a password
Antonio Terceiro [Sun, 24 Aug 2025 13:59:07 +0000 (10:59 -0300)] 
newusers: allow not passing a password

A possible use case for this is wanting to add subuid/subgid entries for
an existing user. This change makes it possible to pass `username::::::`
to newusers; the empty password will be ignored an everything else will
be done. Currently this fails miserably, as PAM errors out on a empty
password.

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
2 days agolib/{alloc,search}/: Use typeas() to add support for arbitrary types
Alejandro Colomar [Sat, 15 Nov 2025 19:42:21 +0000 (20:42 +0100)] 
lib/{alloc,search}/: Use typeas() to add support for arbitrary types

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/sizeof.h: typeas(): Add macro
Alejandro Colomar [Sat, 15 Nov 2025 19:21:25 +0000 (20:21 +0100)] 
lib/sizeof.h: typeas(): Add macro

This macro is like typeof(), but requires that the input is a type name.

This macro is useful because it parenthesizes the type name, which
allows one to create pointers to arbitrary types.  The following code
works for simple types:

T  x;
T  *p;

For example, that would work fine for 'int':

int  x;
int  *p;

However, that wouldn't work for types such as 'int[3]':

int[3]  x;
int[3]  *p;

But if we do instead

typeas(T)  x;
typeas(T)  *p;

now we can use 'int[3]' just fine:

typeof((int[3]){})  x;
typeof((int[3]){})  *p;

To understand this, we create a compound literal of type int[3], with
default values (zero, zero, zero), then get it's type, which is
obviously int[3].  And then we use that to declare a variable x of that
type, and a pointer p, which has type 'int(*)[3]'.

This would also work with something simpler.  One could use typeof(T)
directly:

typeof(T)  x;
typeof(T)  *p;

However, typeof() doesn't require that the input is a type; it accepts
arbitrary input.  The following is valid C:

typeof(42)  x;

For our macro MALLOC(), where we want the second argument to be a type
name, we want to require that the argument is a type name.  For that, we
need to use typeas().

Reported-by: Alejandro Colomar <alx@kernel.org>
Suggested-by: Thiago Adams <thiago.adams@gmail.com>
Suggested-by: Martin Uecker <uecker@tugraz.at>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/search/: Split APIs
Alejandro Colomar [Sat, 15 Nov 2025 20:42:56 +0000 (21:42 +0100)] 
lib/search/: Split APIs

Have xxx_T() macros that only add type safety to the function they wrap.

Have XXX() macros that do more magic; in this case, they deduce the
comparison function that is appropriate for the type.

This will allow using the xxx_T() macros in more complex cases, where
the function can't be deduced just from the type.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/search/: Simplify CMP()
Alejandro Colomar [Sat, 15 Nov 2025 19:47:43 +0000 (20:47 +0100)] 
lib/search/: Simplify CMP()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/search/, lib/, src/: Add a type parameter to the type-safe macros
Alejandro Colomar [Fri, 14 Nov 2025 00:20:41 +0000 (01:20 +0100)] 
lib/search/, lib/, src/: Add a type parameter to the type-safe macros

This simplifies the implementation, allowing us to use _Generic(3) to
replace _Static_assert(3), is_same_type(), and local variables.

Local variables in macros can cause issues when nesting such macros.

This also makes the code more readable, by having the type explicitly
stated at call site.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agolib/: Use a consistent name for macro arguments representing a type name
Alejandro Colomar [Sat, 15 Nov 2025 19:55:25 +0000 (20:55 +0100)] 
lib/: Use a consistent name for macro arguments representing a type name

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agosrc/: Fix uninitialized flags, and use const appropriately
Alejandro Colomar [Fri, 5 Dec 2025 13:11:56 +0000 (14:11 +0100)] 
src/: Fix uninitialized flags, and use const appropriately

In all these functions, we were setting the flags to 'true' in
process_flags() if the appropriate command-line flag was specified.
However, they were never being defined to 'false', which should be the
default value.  Initialize these flags to false.

Fixes: c0c9485d9a5a (2025-10-07; "src/useradd.c: chroot or prefix SELinux file context")
Link: <https://github.com/shadow-maint/shadow/pull/1396>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 days agoUpdate po and potfiles
Serge Hallyn [Fri, 5 Dec 2025 05:00:56 +0000 (23:00 -0600)] 
Update po and potfiles

I just did a 'make dist', then committed the updates to the po and
shadow.pot files.

Closes #1359

Signed-off-by: Serge Hallyn <serge@hallyn.com>
CC: Chris Hofstaedtler <zeha@debian.org>
2 days agouseradd: fix uninitialized flags causing aarch64 failure
Iker Pedrosa [Tue, 25 Nov 2025 08:52:03 +0000 (09:52 +0100)] 
useradd: fix uninitialized flags causing aarch64 failure

Initialize option_flags structure to prevent garbage memory values in
`flags.chroot` and `flags.prefix` fields. Uninitialized memory caused
architecture-specific failures where process_selinux evaluation
differed between x86_64 and aarch64, leading to `pw_close()` failures
when SELinux contexts weren't properly managed.

Fixes: c0c9485d (2025-04-25; "src/useradd.c: chroot or prefix SELinux file context")
Link: <https://bodhi.fedoraproject.org/updates/FEDORA-2025-3d835cfb15>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 days agoautogen.sh: CFLAGS: Promote -Wdiscarded-qualifiers to an error
Alejandro Colomar [Thu, 20 Feb 2025 16:16:13 +0000 (17:16 +0100)] 
autogen.sh: CFLAGS: Promote -Wdiscarded-qualifiers to an error

Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 days agolib/string/strspn/: Add missing const
Alejandro Colomar [Wed, 19 Feb 2025 17:52:45 +0000 (18:52 +0100)] 
lib/string/strspn/: Add missing const

Closes: <https://github.com/shadow-maint/shadow/issues/1218>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 days agosrc/usermod.c: $user_newhome: Remove all trailing '/'s
Alejandro Colomar [Mon, 13 Oct 2025 13:36:32 +0000 (15:36 +0200)] 
src/usermod.c: $user_newhome: Remove all trailing '/'s

FTR: I'm not entirely sure if an empty string can arrive here.  It might
be that the streq() check is dead code, but I'm not sure, so I put it.
It also makes the code more robust.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 days agoconfigure.ac, Makefile.am: Propagate ./configure flags to 'distcheck'
Alejandro Colomar [Sat, 2 Aug 2025 10:35:41 +0000 (12:35 +0200)] 
configure.ac, Makefile.am: Propagate ./configure flags to 'distcheck'

'make distcheck' runs ./configure (among other things).  That command
should inherit the flags passed on the command line, as they are the
flags necessary to build in the current system.

This also allows testing different configurations in the same system.
Until now, we only tested the default automagic configuration.  With
this change, one can test the same default automagic configuration, by
not passing any flags to ./configure, or they can test more specific
configurations, by passing flags.

This allows removing the hardcoded AM_DISTCHECK_CONFIGURE_FLAGS in the
"Makefile.am".

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agolib/: Use simple assignment instead of memcpy(3)
Alejandro Colomar [Wed, 16 Jul 2025 22:55:23 +0000 (00:55 +0200)] 
lib/: Use simple assignment instead of memcpy(3)

memcpy(3) is overkill, and much more dangerous than simple assignment.
Simple assignment adds type safety, and removes any possibility of
buffer overflow due to accidentally specifying a wrong size.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agolib/subordinateio.c: append_range(): Use reallocf(3)-like calling conventions
Alejandro Colomar [Sun, 24 Aug 2025 07:48:23 +0000 (09:48 +0200)] 
lib/subordinateio.c: append_range(): Use reallocf(3)-like calling conventions

By returning the new pointer, we can simplify the implementation,
and we avoid a return-by-parameter.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agolib/subordinateio.c: Use REALLOCF() instead of its pattern
Alejandro Colomar [Sun, 24 Aug 2025 07:44:40 +0000 (09:44 +0200)] 
lib/subordinateio.c: Use REALLOCF() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agotests/unit/: Unname unused parameters in callbacks
Alejandro Colomar [Fri, 21 Feb 2025 05:25:15 +0000 (06:25 +0100)] 
tests/unit/: Unname unused parameters in callbacks

This silences diagnostics about unused parameters.

Tested-by: Silvan Mosberger <github@infinisil.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agotests/unit/test_xaprintf.c: Use assert_string_equal()
Alejandro Colomar [Tue, 4 Nov 2025 12:39:26 +0000 (13:39 +0100)] 
tests/unit/test_xaprintf.c: Use assert_string_equal()

This produces more useful test results.

With assert_true(streq(...)), we only see the line of code that
triggered the failure, while assert_string_equal() shows the contents
of the strings.  See the following example:

alx@devuan:~/tmp$ cat cmocka.c
#include <string.h>

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>

#define streq(a,b)  (!strcmp(a,b))

static void a(void **)
{
const char *s = "foo";

assert_true(streq(s, "bar"));
}

static void b(void **)
{
const char *s = "foo";

assert_string_equal(s, "bar");
}

int
main(void)
{

const struct CMUnitTest tests[] = {
cmocka_unit_test(a),
cmocka_unit_test(b),
};

return cmocka_run_group_tests(tests, NULL, NULL);
}
alx@devuan:~/tmp$ gcc cmocka.c -lcmocka
alx@devuan:~/tmp$ ./a.out
[==========] tests: Running 2 test(s).
[ RUN      ] a
[  ERROR   ] --- streq(s, "bar")
[   LINE   ] --- cmocka.c:15: error: Failure!
[  FAILED  ] a
[ RUN      ] b
[  ERROR   ] --- "foo" != "bar"
[   LINE   ] --- cmocka.c:22: error: Failure!
[  FAILED  ] b
[==========] tests: 2 test(s) run.
[  PASSED  ] 0 test(s).
[  FAILED  ] tests: 2 test(s), listed below:
[  FAILED  ] a
[  FAILED  ] b

 2 FAILED TEST(S)

Tested-by: Silvan Mosberger <github@infinisil.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agolib/, src/: Consistently use NULL with fgets(3)
Alejandro Colomar [Sun, 21 Jul 2024 16:21:02 +0000 (18:21 +0200)] 
lib/, src/: Consistently use NULL with fgets(3)

fgets(3) returns either NULL or the input pointer.  Checking for NULL is
more explicit, and simpler.

<stddef.h> is the header that provides NULL; add it where appropriate.

The meat of this patch can be approximated with the following semantic
patch:

$ cat ~/tmp/spatch/fgets_null.sp
@@
expression a, b, c;
@@

- fgets(a, b, c) == a
+ fgets(a, b, c) != NULL

@@
expression a, b, c;
@@

- fgetsx(a, b, c) == a
+ fgetsx(a, b, c) != NULL

@@
expression a, b, c, p;
@@

- p->cio_fgets(a, b, c) == a
+ p->cio_fgets(a, b, c) != NULL

@@
expression a, b, c;
@@

- fgets(a, b, c) != a
+ fgets(a, b, c) == NULL

@@
expression a, b, c;
@@

- fgetsx(a, b, c) != a
+ fgetsx(a, b, c) == NULL

@@
expression a, b, c, p;
@@

- p->cio_fgets(a, b, c) != a
+ p->cio_fgets(a, b, c) == NUL

Applied as

$ find contrib/ lib* src/ -type f \
| xargs spatch --sp-file ~/tmp/spatch/fgets_null.sp --in-place;

The differences between the actual patch and the approximation via the
semantic patch from above are includes, whitespace, braces, and a case
where there was an implicit pointer-to-bool comparison which I made
explicit.  When reviewing, it'll be useful to use git-diff(1) with '-w'
and '--color-words=.'.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agolib/, src/: Remove useless casts in fgets(3)
Alejandro Colomar [Sun, 21 Jul 2024 16:40:25 +0000 (18:40 +0200)] 
lib/, src/: Remove useless casts in fgets(3)

This patch can be replicated with the following semantic patch:

$ cat fgets_cast.sp
@@
expression a, b, c;
@@

- fgets(a, (int) (b), c)
+ fgets(a, b, c)

@@
expression a, b, c;
@@

- fgets(a, (int) b, c)
+ fgets(a, b, c)

@@
expression a, b, c;
@@

- fgetsx(a, (int) (b), c)
+ fgetsx(a, b, c)

@@
expression a, b, c;
@@

- fgetsx(a, (int) b, c)
+ fgetsx(a, b, c)

@@
expression a, b, c, p;
@@

- p->cio_fgets(a, (int) (b), c)
+ p->cio_fgets(a, b, c)

@@
expression a, b, c, p;
@@

- p->cio_fgets(a, (int) b, c)
+ p->cio_fgets(a, b, c)

which is applied as:

$ find lib* src/ -type f \
| xargs spatch --sp-file ~/tmp/spatch/fgets_cast.sp --in-place;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 days agolib/, src/: Consistently use sizeof() as if it were a function
Alejandro Colomar [Tue, 23 Jul 2024 20:42:54 +0000 (22:42 +0200)] 
lib/, src/: Consistently use sizeof() as if it were a function

sizeof(foo)

-  No spaces.
Not:  sizeof (foo)
-  Parentheses.
Not:  sizeof foo
-  No parentheses wrapping sizeof itself
Not:  (sizeof foo)

This patch can be approximated with the following semantic patch:

$ cat ~/tmp/spatch/sizeof.sp
@@
identifier a, b;
@@

- sizeof a->b
+ sizeof(a->b)

@@
identifier a, b;
@@

- sizeof a.b
+ sizeof(a.b)

@@
identifier x;
@@

- sizeof x
+ sizeof(x)

@@
identifier x;
@@

- sizeof *x
+ sizeof(*x)

@@
identifier x;
@@

- (sizeof(x))
+ sizeof(x)

@@
identifier x;
@@

- (sizeof(*x))
+ sizeof(*x)

Applied as

$ find contrib/ lib* src/ -type f \
| xargs spatch --sp-file ~/tmp/spatch/sizeof.sp --in-place;

The differences between the actual patch and the approximation via the
semantic patch from above are whitespace only.  When reviewing, it'll
be useful to diff with '-w'.

Link: <https://lkml.org/lkml/2012/7/11/103>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agodoc/contributions/coding_style.md: Python code
Iker Pedrosa [Tue, 26 Aug 2025 11:00:52 +0000 (13:00 +0200)] 
doc/contributions/coding_style.md: Python code

Document coding style for Python code used in system tests.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
10 days agodoc/contributions/ci.md: document system tests
Iker Pedrosa [Tue, 26 Aug 2025 11:00:11 +0000 (13:00 +0200)] 
doc/contributions/ci.md: document system tests

Extend the system tests section.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
10 days agodoc/contributions/build_install.md: container troubleshooting
Iker Pedrosa [Tue, 26 Aug 2025 10:35:06 +0000 (12:35 +0200)] 
doc/contributions/build_install.md: container troubleshooting

Extend the container section to document the container troubleshooting.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
10 days agodoc/contributions/tests.md: add Python system tests
Iker Pedrosa [Tue, 26 Aug 2025 08:48:15 +0000 (10:48 +0200)] 
doc/contributions/tests.md: add Python system tests

Document the new Python system tests:
- Benefits
- Contribution guidance
- How to setup the testing environment
- Test configuration and execution
- Advanced testing features
- Development patterns
- Debugging information
- Troubleshooting & FAQs

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
10 days agolib/string/: strerrno(): Use statement expression to perform lvalue conversion
Alejandro Colomar [Tue, 25 Nov 2025 21:51:28 +0000 (22:51 +0100)] 
lib/string/: strerrno(): Use statement expression to perform lvalue conversion

Compound literals are lvalues.  This means it's possible to take their
address.  That is, it would be possible (albeit nonsensical) to do

&strerrno();

It is also possible to assign to them (albeit also nonsensical):

strerrno() = NULL;

The statement expression performs lvalue conversion, which turns the
lvalue into an "rvalue", as expected, and disallows all those issues.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/string/README: Document *_a() macros
Alejandro Colomar [Fri, 31 Oct 2025 10:07:32 +0000 (11:07 +0100)] 
lib/string/README: Document *_a() macros

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRNEQ/strneq_a/
Alejandro Colomar [Fri, 31 Oct 2025 10:05:37 +0000 (11:05 +0100)] 
*/: s/STRNEQ/strneq_a/

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/DAY_TO_STR/day_to_str_a/
Alejandro Colomar [Fri, 31 Oct 2025 10:01:53 +0000 (11:01 +0100)] 
*/: s/DAY_TO_STR/day_to_str_a/

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRSEP2ARR/strsep2arr_a/
Alejandro Colomar [Tue, 14 Oct 2025 11:16:31 +0000 (13:16 +0200)] 
*/: s/STRSEP2ARR/strsep2arr_a/

This name better reflects that it handles arrays, and doesn't shout.

This case is slightly different, as this macro does a little bit more
than just enforcing arrays.  It changes the return value too.  However,
that is related-enough to the handling of arrays that I'm inclined to
accept it as a minor inconsistency.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRSEP2LS/strsep2ls_a/
Alejandro Colomar [Tue, 14 Oct 2025 11:05:59 +0000 (13:05 +0200)] 
*/: s/STRSEP2LS/strsep2ls_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRFTIME/strftime_a/
Alejandro Colomar [Tue, 14 Oct 2025 11:03:24 +0000 (13:03 +0200)] 
*/: s/STRFTIME/strftime_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/MEMZERO/memzero_a/
Alejandro Colomar [Tue, 14 Oct 2025 11:01:54 +0000 (13:01 +0200)] 
*/: s/MEMZERO/memzero_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRTCPY/strtcpy_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:58:00 +0000 (12:58 +0200)] 
*/: s/STRTCPY/strtcpy_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRNCPY/strncpy_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:54:04 +0000 (12:54 +0200)] 
*/: s/STRNCPY/strncpy_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRNCAT/strncat_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:50:42 +0000 (12:50 +0200)] 
*/: s/STRNCAT/strncat_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/SNPRINTF/stprintf_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:49:08 +0000 (12:49 +0200)] 
*/: s/SNPRINTF/stprintf_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRNDUP/strndup_a/ s/XSTRNDUP/xstrndup_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:40:46 +0000 (12:40 +0200)] 
*/: s/STRNDUP/strndup_a/ s/XSTRNDUP/xstrndup_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/STRNDUPA/strndupa_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:37:25 +0000 (12:37 +0200)] 
*/: s/STRNDUPA/strndupa_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/SIZEOF_ARRAY/sizeof_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:35:31 +0000 (12:35 +0200)] 
*/: s/SIZEOF_ARRAY/sizeof_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days ago*/: s/READLINKNUL/readlinknul_a/
Alejandro Colomar [Tue, 14 Oct 2025 10:32:35 +0000 (12:32 +0200)] 
*/: s/READLINKNUL/readlinknul_a/

This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agosrc/: usage(): Use [[noreturn]]
Alejandro Colomar [Thu, 7 Aug 2025 12:39:28 +0000 (14:39 +0200)] 
src/: usage(): Use [[noreturn]]

This silences false-positive diagnostics in Clang.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/attr.h: ATTR_STRING(): Use it also with Clang
Alejandro Colomar [Thu, 7 Aug 2025 12:35:01 +0000 (14:35 +0200)] 
lib/attr.h: ATTR_STRING(): Use it also with Clang

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/attr.h: ATTR_ALLOC_SIZE(): Use it also with Clang
Alejandro Colomar [Thu, 7 Aug 2025 12:34:14 +0000 (14:34 +0200)] 
lib/attr.h: ATTR_ALLOC_SIZE(): Use it also with Clang

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/attr.h: ATTR_ACCESS(): Use it also with Clang
Alejandro Colomar [Thu, 7 Aug 2025 12:33:40 +0000 (14:33 +0200)] 
lib/attr.h: ATTR_ACCESS(): Use it also with Clang

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/attr.h: format_attr(): Use it also with Clang
Alejandro Colomar [Thu, 7 Aug 2025 12:32:11 +0000 (14:32 +0200)] 
lib/attr.h: format_attr(): Use it also with Clang

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/attr.h: NORETURN: Implement with [[noreturn]]
Alejandro Colomar [Thu, 7 Aug 2025 12:29:43 +0000 (14:29 +0200)] 
lib/attr.h: NORETURN: Implement with [[noreturn]]

This is a C23 standard attribute with the same semantics.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/attr.h: MAYBE_UNUSED: Implement with [[maybe_unused]]
Alejandro Colomar [Thu, 7 Aug 2025 12:28:22 +0000 (14:28 +0200)] 
lib/attr.h: MAYBE_UNUSED: Implement with [[maybe_unused]]

This is a C23 standard attribute with the same semantics.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/atoi/, */: Move all str2i() macros together with a2i()
Alejandro Colomar [Fri, 17 Oct 2025 00:02:56 +0000 (02:02 +0200)] 
lib/atoi/, */: Move all str2i() macros together with a2i()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/atoi/, */: Move all a2i() macros to the same file
Alejandro Colomar [Thu, 16 Oct 2025 23:48:58 +0000 (01:48 +0200)] 
lib/atoi/, */: Move all a2i() macros to the same file

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/atoi/: a2i(): Re-implement with a statement expression
Alejandro Colomar [Thu, 16 Oct 2025 23:36:03 +0000 (01:36 +0200)] 
lib/atoi/: a2i(): Re-implement with a statement expression

Synopsis
int a2i(typename T, T *restrict n, QChar *s,
        QChar **_Nullable restrict endp, int base,
        T min, T max);

Description
This macro converts the initial portion of the string pointed to
by 's' to an integer of base 'base', ensure that the number is
in the range [min, max], and store it in *n.

It is similar to NetBSD's strtoi(3) and strtou(3), which
themselves are similar to strtol(3) and strtoul(3).

Arguments
T
The integer type used for the number.
n
A pointer to an integer.  The parsed number will be
stored there.
s
See strtol(3).
endp
See strtol(3).  A difference with strtol(3) is that this
macro is const-correct.  If 's' has type 'const char *',
then 'endp' must have type 'const char **', whereas if
's' has type 'char *', 'endp' must have type 'char **'.
base
See strtol(3).
min
max
See strtoi(3) and strtou(3).

An important difference with NetBSD's strtou(3) is that
a2i() (with an unsigned type T) doesn't intepret any
negative numbers as if they were large positive numbers.
a2i() respects the limits [min, max] as one would
intuitively expect.

Return value
On success, 0 is returned.
On error, -1 is returned and errno is set to indicate the error.

Errors
See strtoi(3) and strtou(3).

Examples
if (a2i(pid_t, &pid, s, &s, 10, 1, _Maxof(pid_t)) == -1)
goto err;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
10 days agolib/typetraits.h: QChar_of(): Add macro
Alejandro Colomar [Sun, 19 Oct 2025 08:10:37 +0000 (10:10 +0200)] 
lib/typetraits.h: QChar_of(): Add macro

This macro is useful to implement QChar versions of functions.
See ISO C23 for a description of what QChar is.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
11 days agouseradd: tests for supplements groups
sgakerru [Tue, 11 Nov 2025 20:22:41 +0000 (00:22 +0400)] 
useradd: tests for supplements groups

For regular and system user cases

11 days agouseradd: fix test `69_useradd_default_GROUPS_name`
sgakerru [Tue, 11 Nov 2025 20:22:06 +0000 (00:22 +0400)] 
useradd: fix test `69_useradd_default_GROUPS_name`

Missing files have been added for the test to work: `gshadow`, `passwd`, `shadow`.
Without them, the foo user was created with a different UID and thus the test failed.

And other minor improvements, such as removing extra spaces and adding empty lines.

11 days agosrc/useradd.c: Do not automatically add supplements groups for system users
sgakerru [Tue, 11 Nov 2025 15:52:11 +0000 (19:52 +0400)] 
src/useradd.c: Do not automatically add supplements groups for system users

11 days agosrc/useradd.c: Use free_list() to free user groups list
sgakerru [Tue, 17 Dec 2024 15:18:38 +0000 (19:18 +0400)] 
src/useradd.c: Use free_list() to free user groups list

11 days agolib/list.c: free_list(): Add function
sgakerru [Tue, 17 Dec 2024 15:10:13 +0000 (19:10 +0400)] 
lib/list.c: free_list(): Add function

2 weeks agogroupadd: clarify -U option help text
akshay [Mon, 17 Nov 2025 16:04:53 +0000 (21:34 +0530)] 
groupadd: clarify -U option help text
Align wording with groupmod to reduce ambiguity in -U option description.

4 weeks agotests/unit/test_exit_if_null.c: Test through XMALLOC() instead of xaprintf()
Alejandro Colomar [Tue, 4 Nov 2025 12:37:26 +0000 (13:37 +0100)] 
tests/unit/test_exit_if_null.c: Test through XMALLOC() instead of xaprintf()

Both are indirect tests for exit_if_null(), but through XMALLOC() we
can test it more robustly, as we don't need to wrap vasprintf(3) to
make it fail.  It's trivial to make MALLOC(3) fail: pass a huge size.

The tests with xaprintf() were failing on Nix.  I suspect the compiler
was inlining aggressively, and as a result, the interposition of
vasprintf(3) in cmocka wasn't actually working.  The approach with
XMALLOC() seems to work on Nix, as we don't need to interpose malloc(3).
We still need to interpose exit(3), but for some reason that works fine.

Closes: <https://github.com/shadow-maint/shadow/issues/1382>
Reported-by: Silvan Mosberger <github@infinisil.com>
Tested-by: Silvan Mosberger <github@infinisil.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 weeks agotests/unit/: Use more generic strings and names for testing exit_if_null()
Alejandro Colomar [Tue, 4 Nov 2025 12:46:01 +0000 (13:46 +0100)] 
tests/unit/: Use more generic strings and names for testing exit_if_null()

This test is actually for exit_if_null(), not xaprintf().  Rename the
test file and functions, and make strings more generic.

Tested-by: Silvan Mosberger <github@infinisil.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 weeks agolib/, src/: Remove unused parameter $2 of audit_logger()
Alejandro Colomar [Fri, 21 Feb 2025 05:37:24 +0000 (06:37 +0100)] 
lib/, src/: Remove unused parameter $2 of audit_logger()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 weeks agolib/defines.h: LOG_NOWAIT: Remove unused macro
Alejandro Colomar [Mon, 6 Oct 2025 08:57:34 +0000 (10:57 +0200)] 
lib/defines.h: LOG_NOWAIT: Remove unused macro

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 weeks agolib/defines.h: NGROUPS_MAX: Remove unused macro
Alejandro Colomar [Mon, 6 Oct 2025 08:53:19 +0000 (10:53 +0200)] 
lib/defines.h: NGROUPS_MAX: Remove unused macro

BTW, it's already defined in <limits.h>, so even if we used it,
we shouldn't define it here.

Signed-off-by: Alejandro Colomar <alx@kernel.org>