]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
13 months agoshare/ansible: convert alpine dockerfile to ansible
Iker Pedrosa [Tue, 14 May 2024 15:35:48 +0000 (17:35 +0200)] 
share/ansible: convert alpine dockerfile to ansible

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
13 months agoshare/ansible: convert debian dockerfile to ansible
Iker Pedrosa [Tue, 14 May 2024 15:14:05 +0000 (17:14 +0200)] 
share/ansible: convert debian dockerfile to ansible

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
13 months agoshare/ansible: move fedora ci_run to its own file
Iker Pedrosa [Tue, 14 May 2024 15:11:39 +0000 (17:11 +0200)] 
share/ansible: move fedora ci_run to its own file

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
13 months agoshare/.gitignore: add build-out folder
Iker Pedrosa [Tue, 14 May 2024 10:52:39 +0000 (12:52 +0200)] 
share/.gitignore: add build-out folder

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
13 months agoshare/ansible: create roles
Iker Pedrosa [Tue, 14 May 2024 10:49:28 +0000 (12:49 +0200)] 
share/ansible: create roles

Create `build_container` and `ci_run` roles and move the fedora target
to them.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
13 months agoshare/ansible: convert fedora dockerfile to ansible
Iker Pedrosa [Thu, 2 May 2024 14:09:02 +0000 (16:09 +0200)] 
share/ansible: convert fedora dockerfile to ansible

Using a dockerfile to build, install and test the code can be
problematic as we can't capture the log files to check what failed in
case of failure. This PR converts the fedora dockerfile to Ansible, an
open source IT automation tool. The tool can be used on the developers
and the CI system to check whether a piece of code can be built,
installed and tested.

This is the first patch in a series, where I will convert the existing
PR workflows to use Ansible instead of dockerfiles.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
13 months agoMakefile.am: avoid warning: EXTRA_DIST multiply defined
Chris Hofstaedtler [Sun, 7 Jul 2024 11:36:55 +0000 (13:36 +0200)] 
Makefile.am: avoid warning: EXTRA_DIST multiply defined

automake complained about duplicate definitions of EXTRA_DIST:

autoreconf: running: automake --add-missing --copy --no-force
Makefile.am:19: warning: EXTRA_DIST multiply defined in condition TRUE ...
Makefile.am:3: ... 'EXTRA_DIST' previously defined here
autoreconf: Leaving directory '.'

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
13 months agotests/libsubid/04_nss: fix setting basedir
Chris Hofstaedtler [Sun, 7 Jul 2024 00:11:45 +0000 (02:11 +0200)] 
tests/libsubid/04_nss: fix setting basedir

Align on variable name BUILD_BASE_DIR for overriding the toplevel
directory. This is the same name as accepted by tests/common/config.sh.

Without this, the test libsubid/04_nss fails in Debian's autopkgtests.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
13 months agoman: groupmod: remove misleading -N option
Sebastian Gross [Wed, 17 Jul 2024 12:22:19 +0000 (14:22 +0200)] 
man: groupmod: remove misleading -N option

The extra paragraph for --users mentions a -N option. groupmod has no -N
option.

Prevent confusion and remove its appearance.

Signed-off-by: Sebastian Gross <sgross@emlix.com>
13 months agoman: group(add|mod): clarify list format
Sebastian Gross [Wed, 17 Jul 2024 12:18:18 +0000 (14:18 +0200)] 
man: group(add|mod): clarify list format

The --users list option expect a string of comma separated values.
While this might be obvious to some others it is certainly not for others.

Remove this ambiguity.

Closes #848

Signed-off-by: Sebastian Gross <sgross@emlix.com>
13 months agoman: groupmod: fix misleading param
Sebastian Gross [Wed, 17 Jul 2024 12:16:03 +0000 (14:16 +0200)] 
man: groupmod: fix misleading param

--append has no argument in groupmod.c but the man pages states GID as
parameter.

In order to avoid confusion remove it from man page.

Signed-off-by: Sebastian Gross <sgross@emlix.com>
13 months agolib/chkname.c: An object cannot expand further than the universe in which it resides
Alejandro Colomar [Sat, 13 Jul 2024 09:37:25 +0000 (11:37 +0200)] 
lib/chkname.c: An object cannot expand further than the universe in which it resides

If you want a larger object, you'll have to wait at least until the
universe expands so much.

If an implementation doesn't recognize its own limitations, its a bug,
not a feature.

Closes: <https://github.com/shadow-maint/shadow/issues/1052>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base
Alejandro Colomar [Sun, 30 Jun 2024 01:00:40 +0000 (03:00 +0200)] 
lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/atoi/, *: Split files
Alejandro Colomar [Sun, 30 Jun 2024 00:18:55 +0000 (02:18 +0200)] 
lib/atoi/, *: Split files

13 months agosrc/usermod.c: Use id_t for parsing uid_t and gid_t
Alejandro Colomar [Thu, 15 Feb 2024 14:50:45 +0000 (15:50 +0100)] 
src/usermod.c: Use id_t for parsing uid_t and gid_t

Use a static_assert(3) to make sure that id_t == uid_t == gid_t.

And use uintmax_t to print it, since on Linux they are unsigned types.

Link: <https://github.com/shadow-maint/shadow/pull/951>
Reviewed-by: Tycho Andersen <tycho@tycho.pizza>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/usermod.c: Rename identifiers ralated to [ug]id's
Alejandro Colomar [Thu, 15 Feb 2024 14:55:33 +0000 (15:55 +0100)] 
src/usermod.c: Rename identifiers ralated to [ug]id's

It was unclear why this code is using ulong.  Since these only handle
uid's and gid's, rename the identifiers accordingly, after id_t.

Link: <https://github.com/shadow-maint/shadow/pull/951>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: get_map_ranges(): Don't exit() from a library function
Alejandro Colomar [Tue, 16 Jan 2024 01:27:56 +0000 (02:27 +0100)] 
lib/idmapping.c: get_map_ranges(): Don't exit() from a library function

Fixes: ff2baed5dbf8 ("idmapping: add more checks for overflow")
Link: <https://github.com/shadow-maint/shadow/commit/ff2baed5dbf81e8967b805889f565fedb48600df#r136635300>
Reported-by: Alejandro Colomar <alx@kernel.org>
Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: get_map_ranges(): Simplify iterator variables
Alejandro Colomar [Thu, 11 Jan 2024 17:11:13 +0000 (18:11 +0100)] 
lib/idmapping.c: get_map_ranges(): Simplify iterator variables

Merge two iterator variables into one, and reduce its scope.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: get_map_ranges(): Remove dead code
Alejandro Colomar [Thu, 11 Jan 2024 11:19:24 +0000 (12:19 +0100)] 
lib/idmapping.c: get_map_ranges(): Remove dead code

This test is impossible.  The limits specified in a2ul() already cover
this.

Link: <https://github.com/shadow-maint/shadow/commit/ff2baed5dbf81e8967b805889f565fedb48600df#r136635300>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
Alejandro Colomar [Thu, 11 Jan 2024 11:17:36 +0000 (12:17 +0100)] 
lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call

Link: <https://github.com/shadow-maint/shadow/commit/ff2baed5dbf81e8967b805889f565fedb48600df#r136635300>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
Alejandro Colomar [Thu, 11 Jan 2024 11:15:11 +0000 (12:15 +0100)] 
lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call

Link: <https://github.com/shadow-maint/shadow/commit/ff2baed5dbf81e8967b805889f565fedb48600df#r136635300>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
Alejandro Colomar [Thu, 11 Jan 2024 11:07:58 +0000 (12:07 +0100)] 
lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls

Link: <https://github.com/shadow-maint/shadow/commit/ff2baed5dbf81e8967b805889f565fedb48600df#r136635300>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: get_map_ranges(): Rename local variable
Alejandro Colomar [Thu, 11 Jan 2024 11:04:23 +0000 (12:04 +0100)] 
lib/idmapping.c: get_map_ranges(): Rename local variable

For a pointer iterator used often, a single-letter identifier is more
appropriate.  That reduces the length of lines considerably, avoiding
unnecessary line breaks.  And since we initialize it with

m = mappings;

it's clear what it is.

Link: <https://github.com/shadow-maint/shadow/commit/ff2baed5dbf81e8967b805889f565fedb48600df#r136635300>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
Alejandro Colomar [Thu, 11 Jan 2024 10:47:50 +0000 (11:47 +0100)] 
lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE

Fixes: 10396f953613 ("* libmisc/limits.c: Parse the limits, umask, nice, maxlogin, file limit with getlog() / getulong().")
Link: <https://github.com/shadow-maint/shadow/pull/893/commits/882cf59459bc4501b0882a7f02d36c8ce28a30f2>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/login_nopam.c: login_access(): Use stpsep() to simplify
Alejandro Colomar [Thu, 4 Jul 2024 12:35:24 +0000 (14:35 +0200)] 
src/login_nopam.c: login_access(): Use stpsep() to simplify

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/useradd.c: Use stpsep() to simplify
Alejandro Colomar [Thu, 4 Jul 2024 12:26:09 +0000 (14:26 +0200)] 
src/useradd.c: Use stpsep() to simplify

This allows using plain strcmp(3) instead of MATCH().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/nss.c: nss_init(): Use stpsep() instead of strtok_r(3)
Alejandro Colomar [Thu, 4 Jul 2024 11:25:57 +0000 (13:25 +0200)] 
lib/nss.c: nss_init(): Use stpsep() instead of strtok_r(3)

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/suauth.c: check_su_auth(): Use stpsep() to simplify
Alejandro Colomar [Wed, 3 Jul 2024 21:41:16 +0000 (23:41 +0200)] 
src/suauth.c: check_su_auth(): Use stpsep() to simplify

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strchr/stpcspn.[ch]: stpcspn(): Remove unused function
Alejandro Colomar [Wed, 3 Jul 2024 00:18:37 +0000 (02:18 +0200)] 
lib/string/strchr/stpcspn.[ch]: stpcspn(): Remove unused function

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/attr.h: ATTR_STRING(): It only accepts one argument
Alejandro Colomar [Tue, 2 Jul 2024 23:59:19 +0000 (01:59 +0200)] 
lib/attr.h: ATTR_STRING(): It only accepts one argument

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, src/: Use stpsep() instead of its pattern
Alejandro Colomar [Tue, 2 Jul 2024 22:32:12 +0000 (00:32 +0200)] 
lib/, src/: Use stpsep() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strtok/stpsep.[ch]: stpsep(): Add function
Alejandro Colomar [Tue, 2 Jul 2024 17:31:38 +0000 (19:31 +0200)] 
lib/string/strtok/stpsep.[ch]: stpsep(): Add function

This function is somewhat simpler to use than strsep(3) in some cases.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/find_new_[gu]id.c: include stdint.h for UINT16_MAX/UINT32_MAX
Chris Hofstaedtler [Sun, 7 Jul 2024 11:31:41 +0000 (13:31 +0200)] 
lib/find_new_[gu]id.c: include stdint.h for UINT16_MAX/UINT32_MAX

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
13 months agolib/port.c: getportent(): Use strsep(3) instead of its pattern
Alejandro Colomar [Tue, 2 Jul 2024 16:57:44 +0000 (18:57 +0200)] 
lib/port.c: getportent(): Use strsep(3) instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getportent(): Align variables
Alejandro Colomar [Tue, 2 Jul 2024 16:37:57 +0000 (18:37 +0200)] 
lib/port.c: getportent(): Align variables

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getttyuser(): Use pointer arithmetic to simplify
Alejandro Colomar [Tue, 2 Jul 2024 14:16:29 +0000 (16:16 +0200)] 
lib/port.c: getttyuser(): Use pointer arithmetic to simplify

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getportent(): Use equivalent code to parse equally-formatted fields
Alejandro Colomar [Tue, 2 Jul 2024 13:05:21 +0000 (15:05 +0200)] 
lib/port.c: getportent(): Use equivalent code to parse equally-formatted fields

The tty names field and the user names field have the same formatting:
a CSV terminated by a ':'.  Thus, we can --and should-- use the same
exact code for parsing both.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getportent(): Make sure the aren't too many fields in the CSV
Alejandro Colomar [Tue, 2 Jul 2024 12:51:04 +0000 (14:51 +0200)] 
lib/port.c: getportent(): Make sure the aren't too many fields in the CSV

Otherwise, the line is invalidly formatted, and we ignore it.

Detailed explanation:

There are two conditions on which we break out of the loops that precede
these added checks:

-  j is too big (we've exhausted the space in the static arrays)

$ grep -r -e PORT_TTY -e PORT_IDS lib/port.*
lib/port.c: static char *ttys[PORT_TTY + 1]; /* some pointers to tty names     */
lib/port.c: static char *users[PORT_IDS + 1]; /* some pointers to user ids     */
lib/port.c: for (cp = buf, j = 0; j < PORT_TTY; j++) {
lib/port.c: if ((',' == *cp) && (j < PORT_IDS)) {
lib/port.h: * PORT_IDS - Allowable number of IDs per entry.
lib/port.h: * PORT_TTY - Allowable number of TTYs per entry.
lib/port.h:#define PORT_IDS 64
lib/port.h:#define PORT_TTY 64

-  strpbrk(3) found a ':', which signals the end of the comma-sepatated
   list, and the start of the next colon-separated field.

If the first character in the remainder of the string is not a ':', it
means we've exhausted the array size, but the CSV list was longer, so
we'd be truncating it.  Consider the entire line invalid, and skip it.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getportent(): Make sure there are at least 2 ':' in the line
Alejandro Colomar [Tue, 2 Jul 2024 12:43:26 +0000 (14:43 +0200)] 
lib/port.c: getportent(): Make sure there are at least 2 ':' in the line

Otherwise, the line is invalidly formatted, and we ignore it.

Closes: <https://github.com/shadow-maint/shadow/issues/1036>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getportent(): Remove obvious comments
Alejandro Colomar [Tue, 2 Jul 2024 12:26:19 +0000 (14:26 +0200)] 
lib/port.c: getportent(): Remove obvious comments

And do some style changes on the corresponding code.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getportent(): Rename goto label
Alejandro Colomar [Tue, 2 Jul 2024 12:23:19 +0000 (14:23 +0200)] 
lib/port.c: getportent(): Rename goto label

This label means we detected a bogus line, and want to skip it and jump
to the next one; rename it accordingly.  'again' seemed to say that it
was somehow looping on the same line.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getttyuser(): Use goto to break out of nested loops
Alejandro Colomar [Tue, 2 Jul 2024 13:49:48 +0000 (15:49 +0200)] 
lib/port.c: getttyuser(): Use goto to break out of nested loops

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/port.c: getttyuser(): Remove dead code
Alejandro Colomar [Tue, 2 Jul 2024 12:03:27 +0000 (14:03 +0200)] 
lib/port.c: getttyuser(): Remove dead code

port.pt_names cannot be NULL; it always points to the static array ttys.

$ grep -rn pt_names
lib/port.c:157: port.pt_names = ttys;
lib/port.c:159: port.pt_names[j] = cp;
lib/port.c:172: port.pt_names[j] = NULL;
lib/port.c:344: for (i = 0; NULL != port->pt_names[i]; i++) {
lib/port.c:345: if (portcmp (port->pt_names[i], tty) == 0) {
lib/port.c:350: if (port->pt_names[i] == 0) {
lib/port.h:39: * pt_names - pointer to array of device names in /dev/
lib/port.h:45: char **pt_names;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agocontrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern
Alejandro Colomar [Sun, 19 May 2024 00:05:16 +0000 (02:05 +0200)] 
contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agocontrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern
Alejandro Colomar [Sat, 18 May 2024 23:53:12 +0000 (01:53 +0200)] 
contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, src/: Use strrspn() instead of its pattern
Alejandro Colomar [Sat, 18 May 2024 19:38:24 +0000 (21:38 +0200)] 
lib/, src/: Use strrspn() instead of its pattern

This requires changing isspace(3) calls to an explicit accept string,
and I chose " \t\n" for it (as is done in other parts of this project),
which isn't exactly the same, but we probably don't want other
isspace(3) characters in those files, so it should work.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/sssd.c: Style fixes
Alejandro Colomar [Sat, 18 May 2024 21:45:46 +0000 (23:45 +0200)] 
lib/sssd.c: Style fixes

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/login_nopam.c: login_access(): Simplify, calling strchr(3)
Alejandro Colomar [Sat, 18 May 2024 20:03:08 +0000 (22:03 +0200)] 
src/login_nopam.c: login_access(): Simplify, calling strchr(3)

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns
Alejandro Colomar [Sat, 18 May 2024 23:00:21 +0000 (01:00 +0200)] 
lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strchr/: stp[c]spn(), strrspn(), strnul(): Add macros and functions
Alejandro Colomar [Sat, 18 May 2024 18:41:30 +0000 (20:41 +0200)] 
lib/string/strchr/: stp[c]spn(), strrspn(), strnul(): Add macros and functions

Often, a pointer is more useful than a length when calling these.

Link: <https://docs.oracle.com/cd/E86824_01/html/E54769/strrspn-3gen.html>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/chage.c: Simplify, by calling a2sl() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 20:44:05 +0000 (21:44 +0100)] 
src/chage.c: Simplify, by calling a2sl() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/faillog.c: Simplify, by calling str2sh() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 20:39:43 +0000 (21:39 +0100)] 
src/faillog.c: Simplify, by calling str2sh() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/usermod.c: Simplify, by calling a2sl() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 20:22:30 +0000 (21:22 +0100)] 
src/usermod.c: Simplify, by calling a2sl() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/passwd.c: Simplify, by calling a2sl() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 20:21:00 +0000 (21:21 +0100)] 
src/passwd.c: Simplify, by calling a2sl() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/useradd.c: Simplify, by calling a2sl() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 20:17:13 +0000 (21:17 +0100)] 
src/useradd.c: Simplify, by calling a2sl() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/: Use get_[ug]id() where appropriate
Alejandro Colomar [Tue, 9 Jan 2024 19:54:38 +0000 (20:54 +0100)] 
src/: Use get_[ug]id() where appropriate

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/shadow.c: my_sgetspent(): Simplify error handling
Alejandro Colomar [Tue, 9 Jan 2024 19:20:07 +0000 (20:20 +0100)] 
lib/shadow.c: my_sgetspent(): Simplify error handling

Handle negative values as errors from a2sl(), and reuse its
error-handling code.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/shadow.c: my_sgetspent(): Remove dead code
Alejandro Colomar [Tue, 9 Jan 2024 19:21:39 +0000 (20:21 +0100)] 
lib/shadow.c: my_sgetspent(): Remove dead code

spwd.sp_flag is an unsigned long, which can never be negative.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
Alejandro Colomar [Tue, 9 Jan 2024 19:09:58 +0000 (20:09 +0100)] 
lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'

This reduces indentation.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 19:04:43 +0000 (20:04 +0100)] 
lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
Alejandro Colomar [Tue, 9 Jan 2024 19:03:58 +0000 (20:03 +0100)] 
lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 19:03:33 +0000 (20:03 +0100)] 
lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 19:03:16 +0000 (20:03 +0100)] 
lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
Alejandro Colomar [Tue, 9 Jan 2024 19:02:38 +0000 (20:02 +0100)] 
lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 19:01:57 +0000 (20:01 +0100)] 
lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 19:01:09 +0000 (20:01 +0100)] 
lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/getdef.c: getdef_unum(): Fix wrong limit check
Alejandro Colomar [Tue, 9 Jan 2024 19:00:03 +0000 (20:00 +0100)] 
lib/getdef.c: getdef_unum(): Fix wrong limit check

The limit, since it's an unsigned int, should have been UINT_MAX, not
INT_MAX.  By calling a2ui() we can fix that and simplify too.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
Alejandro Colomar [Tue, 9 Jan 2024 18:58:02 +0000 (19:58 +0100)] 
lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agoRemove groups(1)
Alejandro Colomar [Sun, 30 Jun 2024 22:06:48 +0000 (00:06 +0200)] 
Remove groups(1)

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agoRemove id(1)
Alejandro Colomar [Wed, 29 May 2024 12:41:45 +0000 (14:41 +0200)] 
Remove id(1)

Distributions use id(1) from GNU coreutils or BusyBox.  Drop ours.

Closes: <https://github.com/shadow-maint/shadow/issues/1005>
Suggested-by: dkwo <nicolopiazzalunga@gmail.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/idmapping.c: Use long constants in prctl(2), and remove 0s
Alejandro Colomar [Fri, 31 May 2024 16:30:16 +0000 (18:30 +0200)] 
lib/idmapping.c: Use long constants in prctl(2), and remove 0s

The prctl(2) system-call wrapper is implemented as a variadic function.
This makes it important to pass arguments to it of the right type (and
more importantly of the right width), to avoid undefined behavior.

While at it, check errors with ==-1, not <0, which is more explicit.

Also, PR_SET_KEEPCAPS(2const) doesn't need all arguments, so it can be
called with just two of them; remove unnecessary 0s.

See-also: prctl(2), PR_SET_KEEPCAPS(2const)
Link: <https://lore.kernel.org/linux-man/ddbdyaiptesjalgfmztxideej67e3yaob7ucsmbf6qvriwxiif@dohhxrqgwhrf/T/#med306b5b003f9cc7cc2de69fcdd7ee2d056d0954>
Cc: Xi Ruoyao <xry111@xry111.site>
Cc: Lukas Slebodnik <lslebodn@fedoraproject.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/attr.h: Use C23-style attributes
Alejandro Colomar [Sun, 30 Jun 2024 22:24:40 +0000 (00:24 +0200)] 
lib/attr.h: Use C23-style attributes

They're stricter.  The GNU attributes are too lazy, and can be misused
more easily.  Also, mixing both has its own problems.

Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108796>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/gshadow.c: Use XREALLOC() instead of silently continuing on ENOMEM
Alejandro Colomar [Sun, 30 Jun 2024 21:55:56 +0000 (23:55 +0200)] 
lib/gshadow.c: Use XREALLOC() instead of silently continuing on ENOMEM

We should do better, and correctly handle errors, since this is library
code.  However, I'm lazy right now, so let's die hard, and let us
improve this later.

Link: <https://github.com/shadow-maint/shadow/pull/991#discussion_r1660308154>
Reported-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/: Remove dead code
Alejandro Colomar [Sun, 30 Jun 2024 21:50:31 +0000 (23:50 +0200)] 
src/: Remove dead code

FIRST_MEMBER_IS_ADMIN was never enabled.  And BTW, that code had been
broken for a long time, so probably nobody should manually enable it.

Link: <https://github.com/shadow-maint/shadow/pull/991#discussion_r1660308748>
Reported-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/: Use [[gnu::alloc_size(...)]] on allocation functions
Alejandro Colomar [Sat, 29 Jun 2024 16:43:47 +0000 (18:43 +0200)] 
lib/: Use [[gnu::alloc_size(...)]] on allocation functions

Suggested-by: Martin Uecker <uecker@tugraz.at>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/: Use multi-line macro definitions
Alejandro Colomar [Thu, 27 Jun 2024 15:19:36 +0000 (17:19 +0200)] 
lib/: Use multi-line macro definitions

This reduces the complexity of those nested parentheses.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/alloc/, lib/, src/, tests/: Organize the allocation APIs in a new subdirectory
Alejandro Colomar [Thu, 27 Jun 2024 14:42:54 +0000 (16:42 +0200)] 
lib/alloc/, lib/, src/, tests/: Organize the allocation APIs in a new subdirectory

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/alloc.[ch]: xmalloc(): Remove unused function
Alejandro Colomar [Thu, 27 Jun 2024 13:58:18 +0000 (15:58 +0200)] 
lib/alloc.[ch]: xmalloc(): Remove unused function

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strdup/xstrdup.[ch], lib/, src/: Move xstrdup() to its own file
Alejandro Colomar [Thu, 27 Jun 2024 12:16:16 +0000 (14:16 +0200)] 
lib/string/strdup/xstrdup.[ch], lib/, src/: Move xstrdup() to its own file

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strcpy/zustr2stp.[ch], tests/: Remove ZUSTR2STP()
Alejandro Colomar [Tue, 14 May 2024 16:41:21 +0000 (18:41 +0200)] 
lib/string/strcpy/zustr2stp.[ch], tests/: Remove ZUSTR2STP()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/logoutd.c: Use STRNCAT() instead of its pattern
Alejandro Colomar [Tue, 21 May 2024 11:58:12 +0000 (13:58 +0200)] 
src/logoutd.c: Use STRNCAT() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/logoutd.c: Use STRNDUPA() instead of its pattern
Alejandro Colomar [Tue, 14 May 2024 16:15:55 +0000 (18:15 +0200)] 
src/logoutd.c: Use STRNDUPA() instead of its pattern

STRNDUPA() is equivalent to automatic storage allocation (alloca(3))
+ ZUSTR2STP().

The benefits of this refactor are:

-  The allocation size is always correct, and needs no comments, since
   it's now automatically calculated by the macro.

-  STRNDUPA() is probably more familiar, since
   -  strndupa(3) is a libc function,
   -  STRNDUPA() is the obvious wrapper that
      calculates the size based on the input array.

-  We can remove ZUSTR2STP().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/newusers.c: Exit on ENOMEM, by calling xstrdup() instead of strdup(3)
Alejandro Colomar [Tue, 14 May 2024 19:37:53 +0000 (21:37 +0200)] 
src/newusers.c: Exit on ENOMEM, by calling xstrdup() instead of strdup(3)

The program was happily ignoring ENOMEM errors.

Fixes: 7f9e19690333 ("* NEWS, src/newusers.c, src/Makefile.am: Added support for")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/utmp.c: prepare_utmp(): Use xstrdup() instead of its pattern
Alejandro Colomar [Mon, 13 May 2024 13:48:53 +0000 (15:48 +0200)] 
lib/utmp.c: prepare_utmp(): Use xstrdup() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/utmp.c: Use XSTRNDUP() instead of its pattern
Alejandro Colomar [Mon, 13 May 2024 13:47:19 +0000 (15:47 +0200)] 
lib/utmp.c: Use XSTRNDUP() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strdup/: XSTRNDUP(), STRNDUPA(): Add macros
Alejandro Colomar [Mon, 13 May 2024 13:21:48 +0000 (15:21 +0200)] 
lib/string/strdup/: XSTRNDUP(), STRNDUPA(): Add macros

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strcpy/strncat.[ch]: STRNCAT(): Add macro
Alejandro Colomar [Tue, 21 May 2024 10:50:27 +0000 (12:50 +0200)] 
lib/string/strcpy/strncat.[ch]: STRNCAT(): Add macro

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/: Use xasprintf() instead of its pattern
Alejandro Colomar [Mon, 13 May 2024 12:37:14 +0000 (14:37 +0200)] 
src/: Use xasprintf() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/groupmems.c: Fix number of elements in allocation
Alejandro Colomar [Mon, 13 May 2024 12:46:47 +0000 (14:46 +0200)] 
src/groupmems.c: Fix number of elements in allocation

We are setting `sgrent.sg_adm[1] = NULL;`, so we need 2 elements.

Fixes: 87b56b19fb72 ("* NEWS, src/groupmems.c, man/groupmems.8.xml: Added support for [...]")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/gshadow.c: build_list(): Fix REALLOC() nmemb calculation
Alejandro Colomar [Mon, 13 May 2024 02:07:51 +0000 (04:07 +0200)] 
lib/gshadow.c: build_list(): Fix REALLOC() nmemb calculation

Fixes: efbbcade43ff ("Use safer allocation macros")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/gshadow.c: build_list(): Fix forever loop on ENOMEM
Alejandro Colomar [Sun, 12 May 2024 23:24:47 +0000 (01:24 +0200)] 
lib/gshadow.c: build_list(): Fix forever loop on ENOMEM

Before this patch, the function looped while (s != NULL && *s != '\0').
However, nothing was modifying that string if REALLOC() failed, so the
loop was forever.

Fixes: 8e167d28afd6 ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, src/: Use strsep(3) instead of its pattern
Alejandro Colomar [Sun, 12 May 2024 23:02:59 +0000 (01:02 +0200)] 
lib/, src/: Use strsep(3) instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/useradd.c: tallylog_reset(): Use Basename() instead of its pattern
Alejandro Colomar [Sun, 12 May 2024 22:13:41 +0000 (00:13 +0200)] 
src/useradd.c: tallylog_reset(): Use Basename() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, src/: Use strchrnul(3) instead of its pattern
Alejandro Colomar [Sun, 12 May 2024 21:44:35 +0000 (23:44 +0200)] 
lib/, src/: Use strchrnul(3) instead of its pattern

In the files where #include <string.h> is missing, add it, and sort the
includes.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/commonio.c: commonio_open(): MALLOC() and REALLOCF() already set ENOMEM
Alejandro Colomar [Sun, 12 May 2024 21:15:12 +0000 (23:15 +0200)] 
lib/commonio.c: commonio_open(): MALLOC() and REALLOCF() already set ENOMEM

We don't need to set ENOMEM on failure of those functions.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/: Use REALLOCF() instead of its pattern
Alejandro Colomar [Sun, 12 May 2024 23:18:48 +0000 (01:18 +0200)] 
lib/: Use REALLOCF() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, src/: Add missing include
Alejandro Colomar [Mon, 13 May 2024 14:37:56 +0000 (16:37 +0200)] 
lib/, src/: Add missing include

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/failure.c: failprint(): Remove dead code
Alejandro Colomar [Mon, 20 May 2024 15:34:30 +0000 (17:34 +0200)] 
lib/failure.c: failprint(): Remove dead code

This should have gone into the #else'd branch in 8451bed8b06d, and
should have been removed in 3e602b58a2aa.

Fixes: 8451bed8b06d ("[svn-upgrade] Integrating new upstream version, shadow (4.0.13)")
Fixes: 3e602b58a2aa ("Remove HAVE_STRFTIME ifdefs")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, src/: Always pass NULL to time(2)
Alejandro Colomar [Tue, 14 May 2024 17:58:36 +0000 (19:58 +0200)] 
lib/, src/: Always pass NULL to time(2)

See time(2):

BUGS
     Error returns from this system  call  are  indistinguishable  from
     successful  reports  that  the  time  is  a few seconds before the
     Epoch, so the C library wrapper function never sets errno as a re‐
     sult of this call.

     The tloc argument is obsolescent and should always be NULL in  new
     code.  When tloc is NULL, the call cannot fail.

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/getdate.y: NULL doesn't need a cast
Alejandro Colomar [Tue, 14 May 2024 17:49:39 +0000 (19:49 +0200)] 
lib/getdate.y: NULL doesn't need a cast

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