]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
6 months agolib/search/cmp/, lib/, tests/: CMP(), cmp_*(): Add macro and functions
Alejandro Colomar [Thu, 14 Nov 2024 14:07:25 +0000 (15:07 +0100)] 
lib/search/cmp/, lib/, tests/: CMP(), cmp_*(): Add macro and functions

These macros are for use with bsearch(3),lfind(3),qsort(3).

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/, src/: Simplify allocation of buffer
Alejandro Colomar [Thu, 14 Nov 2024 13:39:23 +0000 (14:39 +0100)] 
lib/, src/: Simplify allocation of buffer

getgroups(0, NULL) returns the number of groups, so that we can allocate
at once.  This might fail if there's a race and the number of users
grows while we're allocating, but if that happens, failing is probably a
good thing to do.

There was some comment saying it doesn't work on some systems, but
according to gnulib, that's only NeXTstep 3.2, which we don't support.

Link: <https://www.gnu.org/software/gnulib/manual/html_node/getgroups.html>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/, src/: Un-spageticize code
Alejandro Colomar [Thu, 14 Nov 2024 12:52:31 +0000 (13:52 +0100)] 
lib/, src/: Un-spageticize code

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/, src/: Reduce scope of variables
Alejandro Colomar [Thu, 14 Nov 2024 12:47:12 +0000 (13:47 +0100)] 
lib/, src/: Reduce scope of variables

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/gshadow_.h: Fix compatibility with libc's struct sgrp
Alejandro Colomar [Wed, 6 Nov 2024 13:51:06 +0000 (14:51 +0100)] 
lib/gshadow_.h: Fix compatibility with libc's struct sgrp

The name of the first field was different.  Rename for compatiblity with
libc.

$ diff -wU10 \
<(grepc sgrp . | sed_rm_ccomments) \
<(grepc sgrp /usr/include/ | sed_rm_ccomments);
--- /dev/fd/63 2024-11-06 14:49:03.287204461 +0100
+++ /dev/fd/62 2024-11-06 14:49:03.287204461 +0100
@@ -1,6 +1,7 @@
-./lib/gshadow_.h:struct sgrp {
- char *sg_name;
+/usr/include/gshadow.h:struct sgrp
+  {
+    char *sg_namp;
char *sg_passwd;
char **sg_adm;
char **sg_mem;
 };

This originates from a typo in this project, which was later copied by
glibc, and so the typo was set in stone.  The typo was eventually fixed
in shadow, but glibc had already set the name in stone, so we should
just learn to live with it.

$ grep -rn -C3 sg_name ChangeLog
1607-
1608-2011-07-30  Nicolas François  <nicolas.francois@centraliens.net>
1609-
1610: * src/chgpasswd.c: Fix typo sp -> sg. sg_namp -> sg_name
1611- * src/chgpasswd.c: Always update the group file when SHADOWGRP is
1612- not enabled.
1613-

This is a scripted change:

$ find lib* src -type f \
| xargs sed -i 's/\<sg_name\>/sg_namp/g';

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agoconfigure.ac, lib/gshadow.c: Presume working shadow group support in libc
Alejandro Colomar [Wed, 6 Nov 2024 12:07:29 +0000 (13:07 +0100)] 
configure.ac, lib/gshadow.c: Presume working shadow group support in libc

This check was testing a specific bug in a prehistoric libc version.
Red Hat 3 is long dead, and it doesn't make sense to test for that
specific bug.

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/: Include <gshadow.h> if it's available
Alejandro Colomar [Wed, 6 Nov 2024 13:19:12 +0000 (14:19 +0100)] 
lib/: Include <gshadow.h> if it's available

The existing code was assuming that libc's <shadow.h> includes
<gshadow.h>.  That's not true.

alx@debian:~$ find /usr/include/shadow.h
/usr/include/shadow.h
alx@debian:~$ find /usr/include/gshadow.h
/usr/include/gshadow.h
alx@debian:~$ grep include.*gshadow /usr/include/shadow.h
alx@debian:~$

As a result, we were unconditionally including our own "gshadow_.h".

Fix that incorrect assumption, and do the following instead:

-  Include unconditionally our own "gshadow_.h".
-  Make our "gshadow_.h" include <gshadow.h> if it exists,
   and only provide the declarations otherwise.

While at it, fix the include guard to be consistent with the project.

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agoconfigure.ac, lib/: Assume initgroups(3) exists
Alejandro Colomar [Sat, 16 Nov 2024 13:02:08 +0000 (14:02 +0100)] 
configure.ac, lib/: Assume initgroups(3) exists

It's available in every system I checked: glibc,musl,{Free,Net,Open}BSD.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agoconfigure.ac, lib/, src/: Assume setgroups(2) exists
Alejandro Colomar [Sat, 16 Nov 2024 12:23:54 +0000 (13:23 +0100)] 
configure.ac, lib/, src/: Assume setgroups(2) exists

It's available in every system I checked: glibc,musl,{Free,Net,Open}BSD.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agolib/, src/: Turn error counters into flags
Tobias Stoeckmann [Mon, 20 Jan 2025 18:39:12 +0000 (19:39 +0100)] 
lib/, src/: Turn error counters into flags

If we are not interested in the amount of errors but only if errors
exist, use a flag instead of a counter. This eliminates the chance of
signed integer overflows and better reflects the meaning of variable.

Keeping variable name and basically copied from src/faillog.c.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agodoc: fix typo
Michael Vetter [Tue, 21 Jan 2025 14:38:47 +0000 (15:38 +0100)] 
doc: fix typo

6 months agosrc/gpasswd: Use correct preprocessor definition
Tobias Stoeckmann [Sun, 19 Jan 2025 20:28:25 +0000 (21:28 +0100)] 
src/gpasswd: Use correct preprocessor definition

Use PASS_MAX + 1 instead of BUFSIZ to clarify where this size comes
from. Technically, PASS_MAX is BUFSIZ - 1 so this is a no-op change.

Just make sure that the size of pass stays in sync with agetpass.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agosrc/gpasswd: Clear password in more cases
Tobias Stoeckmann [Sun, 19 Jan 2025 20:27:50 +0000 (21:27 +0100)] 
src/gpasswd: Clear password in more cases

If encryption of password fails, clear the memory before exiting.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agolib/encrypt.c: Do not exit in error case
Tobias Stoeckmann [Sun, 19 Jan 2025 20:23:54 +0000 (21:23 +0100)] 
lib/encrypt.c: Do not exit in error case

If crypt fails, pw_encrypt calls exit. This has the consequence that the
plaintext password is not cleared.

A valid password can fail if the underlying library does not support it.
One such example is SHA512, for which the password must not be longer
than 256 characters on musl. A password longer than this with glibc
works, so it is actually possible that a user, running passwd, tries to
enter the old password but the musl-based passwd binary simply exits.
Let passwd clear the password before exiting.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agoci: add openSUSE Tumbleweed
Michael Vetter [Mon, 20 Jan 2025 10:13:54 +0000 (11:13 +0100)] 
ci: add openSUSE Tumbleweed

Add an ansible task for openSUSE which will use the
configure options used by the official openSUSE package.

Signed-off-by: Michael Vetter <jubalh@iodoru.org>
6 months agoman/useradd.8.xml: wfix
Markus Hiereth [Wed, 8 Jan 2025 21:43:45 +0000 (22:43 +0100)] 
man/useradd.8.xml: wfix

Closes: Debian Bug <https://bugs.debian.org/1005253>
Cc: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/login_nopam.c: list_match(): Use iteration instead of recursion
Tobias Stoeckmann [Thu, 16 Jan 2025 20:09:54 +0000 (21:09 +0100)] 
src/login_nopam.c: list_match(): Use iteration instead of recursion

The recursive nature of list_match() triggered regression during
refactoring.  In Linux-PAM, the same code exists which could lead to
stack overflow because <access.conf> could be arbitrarily long.

Use an iterative approach for easier refactoring, to support long
lines in the future and to stay in sync with Linux-PAM.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/login_nopam.c: list_match(): Remove local variable
Alejandro Colomar [Sat, 18 Jan 2025 18:30:12 +0000 (19:30 +0100)] 
src/login_nopam.c: list_match(): Remove local variable

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/login_nopam.c: list_match(): Move code around
Alejandro Colomar [Thu, 16 Jan 2025 21:30:56 +0000 (22:30 +0100)] 
src/login_nopam.c: list_match(): Move code around

This is just a no-op refactor in preparation for the following commits.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/login_nopam.c: list_match(): '(match)' is always true here
Alejandro Colomar [Thu, 16 Jan 2025 23:14:54 +0000 (00:14 +0100)] 
src/login_nopam.c: list_match(): '(match)' is always true here

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/login_nopam.c: list_match(): Add superfluous else
Alejandro Colomar [Thu, 16 Jan 2025 21:25:31 +0000 (22:25 +0100)] 
src/login_nopam.c: list_match(): Add superfluous else

This is just a no-op refactor in preparation for the following commits.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agosrc/login_nopam.c: list_match(): Refactor conditional
Alejandro Colomar [Sat, 18 Jan 2025 19:16:24 +0000 (20:16 +0100)] 
src/login_nopam.c: list_match(): Refactor conditional

This is just a no-op refactor in preparation for the following commits.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
6 months agoman/passwd.1.xml: -P disables PAM support
Tobias Stoeckmann [Tue, 14 Jan 2025 20:57:09 +0000 (21:57 +0100)] 
man/passwd.1.xml: -P disables PAM support

If passwd is called with -P, then PAM handling is disabled
(src/passwd.c line 749). The manual page claims that host files would
be used, which is not true.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agochage: Drop PAM support
Tobias Stoeckmann [Tue, 14 Jan 2025 16:42:21 +0000 (17:42 +0100)] 
chage: Drop PAM support

The PAM support was only enabled with configure option
--enable-account-tools-setuid. The other account tools would use PAM
then to verify that the user is granted elevated permissions for
actions which normally only root can do.

In chage, however, any non-root user who does not specify the -l
command line option is denied access in check_perms. The check for
being root or not is done with getuid, so non-root users cannot
change user account's aging information in any possible way since
more than 18 years by now.

It's safe to say that nobody misses this non-existing feature. Biggest
benefit is to get chage out of the ACCT_TOOLS_SETUID group of tools.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agosrc/newusers.c: Turn nusers into size_t
Tobias Stoeckmann [Sun, 12 Jan 2025 18:21:09 +0000 (19:21 +0100)] 
src/newusers.c: Turn nusers into size_t

The nusers variable could, in theory, overflow and trigger an out of
boundary access if a huge amount of entries is added. Realistically,
this is not possible with current systems because way too much data
would be involved.

But let's better be safe than sorry and use correct data types.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agosrc/: Make line number overflows less likely
Tobias Stoeckmann [Sun, 12 Jan 2025 18:19:39 +0000 (19:19 +0100)] 
src/: Make line number overflows less likely

Huge files could trigger signed integer overflows if enough lines are
within the file. Use intmax_t which is at least 64 bit to move this
event far into the future.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agoman/: Install suauth.5 only if feature exists
Tobias Stoeckmann [Sun, 12 Jan 2025 17:45:13 +0000 (18:45 +0100)] 
man/: Install suauth.5 only if feature exists

Support for /etc/suauth only exists if su is installed without
PAM support. If su is not installed (--without-su) or if PAM
support is enabled (default), do not install suauth.5 manual
page.

The SU_ACCESS preprocessor definition is used to decide if
feature exists or not. See links for more details.

Link: https://github.com/shadow-maint/shadow/blob/65723c3c4704fde4cc8c94299123d3eeca81aadf/src/su.c#L558-L581
Link: https://github.com/shadow-maint/shadow/blob/65723c3c4704fde4cc8c94299123d3eeca81aadf/configure.ac#L628-L654
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 months agoadd and use a login.defs.test with CREATE_HOME set
Serge Hallyn [Sat, 11 Jan 2025 21:35:01 +0000 (15:35 -0600)] 
add and use a login.defs.test with CREATE_HOME set

I suspect this is not a big deal, and most distributions just ship their own
version verbatim like debian/login.defs. But if there is a distro - or even a
person - using this as is from upstream, then we dont' want to break them. So
let's undo this and use an etc/login.defs.test for the testing if needed.

Changelog: 01/13: move etc/login.defs.test to tests/system/etc/login.defs per
                  suggestion.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
6 months agoRevert "etc/login.defs: enable CREATE_HOME"
Serge Hallyn [Sat, 11 Jan 2025 21:22:59 +0000 (15:22 -0600)] 
Revert "etc/login.defs: enable CREATE_HOME"

This reverts commit dcb6b0f4152c1507a137640fea42401a91f22e2c.

Reported-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
6 months agoCI: run system tests
Iker Pedrosa [Thu, 21 Nov 2024 15:19:18 +0000 (16:19 +0100)] 
CI: run system tests

Run the newly created system tests in CI and collect artifacts.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agoetc/login.defs: enable CREATE_HOME
Iker Pedrosa [Fri, 22 Nov 2024 09:28:48 +0000 (10:28 +0100)] 
etc/login.defs: enable CREATE_HOME

In order to have consistent behaviour among all distributions, the same
configuration needs to be shared. That is why we are going to use the
`etc/login.defs` file and enable CREATE_HOME so that the home dir is
created automatically. This is not the default configuration used in all
distributions, but it is the most common one.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: basic group deletion
Iker Pedrosa [Wed, 20 Nov 2024 09:41:10 +0000 (10:41 +0100)] 
tests: basic group deletion

This is the transformation to Python of the test located in
`tests/grouptools/groupdel/01_groupdel_delete_group/groupdel.test`,
which checks that `groupdel` is able to delete a group.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: change GID of a group
Iker Pedrosa [Wed, 20 Nov 2024 09:13:33 +0000 (10:13 +0100)] 
tests: change GID of a group

This is the transformation to Python of the test located in
`tests/grouptools/groupmod/01_groupmod_change_gid/groupmod.test`, which
checks that `groupmod` is able to change the GID of a group.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: basic group creation
Iker Pedrosa [Tue, 19 Nov 2024 15:18:45 +0000 (16:18 +0100)] 
tests: basic group creation

This is the transformation to Python of the test located in
`tests/grouptools/groupadd/02_groupadd_add_group_GID_MIN/groupadd.test`,
which checks that `groupadd` is able to create a new group.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: delete user and homedir
Iker Pedrosa [Tue, 19 Nov 2024 09:19:09 +0000 (10:19 +0100)] 
tests: delete user and homedir

This is the transformation to Python of the test located in
`tests/usertools/01/18_userdel_remove_homedir.test`, which checks that
`userdel` is able to delete a user and its homedir. The test checks that
the user, the group and the home folder don't exist.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: rename user
Iker Pedrosa [Wed, 13 Nov 2024 15:24:55 +0000 (16:24 +0100)] 
tests: rename user

This is the transformation to Python of the test located in
`tests/usertools/01/10_usermod_rename_user.test`, which checks that
`usermod` is able to rename a user. The test checks that the new user,
the group and home folder exists.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: recreate deleted user
Iker Pedrosa [Wed, 20 Nov 2024 13:58:54 +0000 (14:58 +0100)] 
tests: recreate deleted user

This is the transformation to Python of the test located in
`tests/usertools/01/02_useradd_recreate_deleted_user.test`, which checks
that `useradd` is able to create again a removed user.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: basic user creation
Iker Pedrosa [Fri, 8 Nov 2024 11:15:52 +0000 (12:15 +0100)] 
tests: basic user creation

This is the transformation to Python of the test located in
`tests/usertools/01/01_useradd_add_user.test`, which checks that
`useradd` is able to create a new user and its corresponding group and
home folder.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agotests: basic configuration
Iker Pedrosa [Fri, 8 Nov 2024 12:46:51 +0000 (13:46 +0100)] 
tests: basic configuration

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agoTests: implement system test framework
Iker Pedrosa [Mon, 7 Oct 2024 13:44:17 +0000 (15:44 +0200)] 
Tests: implement system test framework

As discussed at length, this is the implementation of the new system
tests framework for shadow. This is a proof of concept that contains the
key elements to be able to run basic user (i.e. useradd, usermod) and
group (i.e. usermod) tests. If you like the framework the rest of the
functionality will be added in the future.

Some useful facts:
* It is implemented in python
* It is based on pytest and pytest-mh
* It works on all the distributions that are part of our CI
* It can be run in the cloud (VM or container) as well as on-premises
* After the execution of each test the environment is cleaned up
* Logs and other artifacts for failed tests are collected
* It has a rich API that can be extended and extended to cover new
  functionalities

Closes: https://github.com/shadow-maint/shadow/issues/835
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
6 months agoRelease 4.17.2 4.17.2
Alejandro Colomar [Fri, 10 Jan 2025 13:57:55 +0000 (14:57 +0100)] 
Release 4.17.2

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 months agoman/, po/: Update Romanian translation
Remus-Gabriel Chelu [Wed, 8 Jan 2025 21:51:56 +0000 (22:51 +0100)] 
man/, po/: Update Romanian translation

Add translation of manual pages, and update the translation of strings.

Bug-Debian: https://bugs.debian.org/1080487
[alx: fix typo: po => ro]
Reviewed-by: Alejandro Colomar <alx@kernel.org>
7 months agolib/: Set O_CLOEXEC for static FILE handles
Tobias Stoeckmann [Mon, 6 Jan 2025 16:24:13 +0000 (17:24 +0100)] 
lib/: Set O_CLOEXEC for static FILE handles

With glibc we can use "e" in mode argument to set O_CLOEXEC on
opened files. The /etc/shadow and /etc/gshadow file handles should
be protected to make sure that they are never passed to child
processes by accident.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
7 months agolib/: Use _exit in case of execv errors
Tobias Stoeckmann [Mon, 6 Jan 2025 16:18:43 +0000 (17:18 +0100)] 
lib/: Use _exit in case of execv errors

Calling exit might trigger cleanup functions registered through
atexit. Since some programs use this mechanism, be extra cautious to
never release passwd/group locks too early.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
7 months agoUpdate French translation
bubu [Wed, 8 Jan 2025 21:56:35 +0000 (22:56 +0100)] 
Update French translation

Bug-Debian: https://bugs.debian.org/1076260

7 months agoman: Add Portuguese translation
Américo Monteiro [Wed, 8 Jan 2025 21:59:50 +0000 (22:59 +0100)] 
man: Add Portuguese translation

Bug-Debian: https://bugs.debian.org/968304

7 months agologin: Fix no-pam authorization regression
Tobias Stoeckmann [Wed, 8 Jan 2025 16:04:07 +0000 (17:04 +0100)] 
login: Fix no-pam authorization regression

The list_match function handles EXCEPT entries through recursive
calls. It calls itself with NULL, which was then passed to strtok so
parsing continued at current position.

Replacing strtok with strsep, this means that EXCEPT entries never
match, because strsep(NULL, ...) always returns NULL, i.e. the
code treats everything after EXCEPT as non-existing.

Fix this by passing current list pointer to recursive call.

Fixes: 90afe61003ef (2024-07-04; "lib/, src/: Use strsep(3) instead of strtok(3)")
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
7 months agolib/attr.h: use C23 attributes only with gcc >= 10
Alexander Kanavin [Tue, 7 Jan 2025 16:03:32 +0000 (17:03 +0100)] 
lib/attr.h: use C23 attributes only with gcc >= 10

These are not available on earlier versions and builds break there.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
7 months agoman/: Update link to Wikipedia to use HTTPS
Scott Martin [Tue, 31 Dec 2024 13:21:04 +0000 (13:21 +0000)] 
man/: Update link to Wikipedia to use HTTPS

The link to Wikipedia's article "Password strength" was added here in
2008 and Wikipedia went HTTPS-only 7 years later.

Link: <https://diff.wikimedia.org/2015/06/12/securing-wikimedia-sites-with-https/>

7 months agolib/chkname.c: login_name_max_size(): Put limits for LOGIN_NAME_MAX and sysconf(_SC_L...
Alejandro Colomar [Sat, 4 Jan 2025 12:10:48 +0000 (13:10 +0100)] 
lib/chkname.c: login_name_max_size(): Put limits for LOGIN_NAME_MAX and sysconf(_SC_LOGIN_NAME_MAX)

GNU Hurd doesn't define LOGIN_NAME_MAX.  GNU Hurd recommends having no
system limits.  When a program needs a limit, because it needs to
validate user input, it is recommended that each program defines its own
limit macros.  The rationale is that this avoids hard-coded limits in
ABIs, which cannot be modified ever.

However, that doesn't mean that programs should have no limits at all.
We use this limit for validating user input, and so we shouldn't allow
anything just because the system doesn't want to set a limit.

So, when sysconf(2) returns -1, either due to an error or due to a claim
for no limits, we must fall back to the LOGIN_NAME_MAX value.  And if
the system doesn't define that value, we must define it ourselves (we're
more or less free to choose any value, so let's pick the one that glibc
provides nowadays).

Fixes: 6a1f45d932c8 (2024-02-04; "lib/chkname.c: Support unlimited user name lengths")
Closes: <https://github.com/shadow-maint/shadow/issues/1166>
Cc: Chris Hofstaedtler <zeha@debian.org>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 months agosrc/login_nopam.c: Fix compiler warnings
Tobias Stoeckmann [Mon, 6 Jan 2025 16:15:51 +0000 (17:15 +0100)] 
src/login_nopam.c: Fix compiler warnings

The function user_match actually modifies the string passed as its
first argument, so use char * instead of const char *.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
7 months agoRelease 4.17.1 4.17.1
Serge Hallyn [Tue, 31 Dec 2024 19:06:01 +0000 (13:06 -0600)] 
Release 4.17.1

Signed-off-by: Serge Hallyn <serge@hallyn.com>
7 months agosu: Fix su - regression
Tobias Stoeckmann [Mon, 30 Dec 2024 14:12:32 +0000 (15:12 +0100)] 
su: Fix su - regression

Launch a login shell again if requested through "su -" or "su -l".

Fixes: d9923431eb38 ("src/: Use xasprintf() instead of its pattern")
Closes: <https://github.com/shadow-maint/shadow/issues/1160>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
7 months agoRelease 4.17.0 4.17.0
Serge Hallyn [Wed, 25 Dec 2024 14:47:03 +0000 (08:47 -0600)] 
Release 4.17.0

Signed-off-by: Serge Hallyn <serge@hallyn.com>
7 months agoAdded information in lastlog man page for new option '-a'
Pranav Lawate [Thu, 12 Dec 2024 05:50:36 +0000 (11:20 +0530)] 
Added information in lastlog man page for new option '-a'

Signed-off-by: Pranav Lawate <pran.lawate@gmail.com>
8 months agolib/fs/readlink/: readlinknul(): Fix return type
Alejandro Colomar [Mon, 2 Dec 2024 10:05:05 +0000 (11:05 +0100)] 
lib/fs/readlink/: readlinknul(): Fix return type

Fixes: 419ce14b6f72 (2024-11-01, "lib/fs/readlink/: readlinknul(): Add function")
Cc: Serge Halyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/fs/readlink/readlinknul.h: readlinknul(): Silence warning
Alejandro Colomar [Sat, 2 Nov 2024 11:28:44 +0000 (12:28 +0100)] 
lib/fs/readlink/readlinknul.h: readlinknul(): Silence warning

Use a temporary variable to silence a sign-mismatch diagnostic.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agoAdded option -a for listing active users only, optimized using if aflg,return
Pranav Lawate [Tue, 29 Oct 2024 09:57:51 +0000 (15:27 +0530)] 
Added option -a for listing active users only, optimized using if aflg,return

Signed-off-by: Pranav Lawate <pran.lawate@gmail.com>
8 months agolib/, src/: Use !streq() instead of its pattern
Alejandro Colomar [Fri, 6 Dec 2024 00:59:23 +0000 (01:59 +0100)] 
lib/, src/: Use !streq() instead of its pattern

Except for the added (and sorted) includes, the removal of redundant
parentheses, and a few non-string cases that I've left out of the
change, this patch can be approximated with the following semantic
patch:

$ cat ~/tmp/spatch/strneq.sp
@@
expression s;
@@

- '\0' != *s
+ !streq(s, "")

@@
expression s;
@@

- '\0' != s[0]
+ !streq(s, "")

@@
expression s;
@@

- *s != '\0'
+ !streq(s, "")

@@
expression s;
@@

- s[0] != '\0'
+ !streq(s, "")

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

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/, src/: Use streq() instead of its pattern
Alejandro Colomar [Mon, 2 Dec 2024 12:16:56 +0000 (13:16 +0100)] 
lib/, src/: Use streq() instead of its pattern

Except for the added (and sorted) includes, the removal of redundant
parentheses, a few cases that have been refactored for readability, and
a couple of non-string cases that I've left out of the change, this
patch can be approximated with the following semantic patch:

$ cat ~/tmp/spatch/streq.sp
@@
expression s;
@@

- '\0' == *s
+ streq(s, "")

@@
expression s;
@@

- '\0' == s[0]
+ streq(s, "")

@@
expression s;
@@

- *s == '\0'
+ streq(s, "")

@@
expression s;
@@

- s[0] == '\0'
+ streq(s, "")

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

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/sgetgrent.c: sgetgrent(): Fix use-after-free bug
Alejandro Colomar [Fri, 6 Dec 2024 23:07:27 +0000 (00:07 +0100)] 
lib/sgetgrent.c: sgetgrent(): Fix use-after-free bug

We were reusing a leftover from parsing a previous line if
(i == NFIELDS-1).  A few lines below this check, we use read the element
in [3] (that is, [NFIELDS-1]), without having written it in this call.

Be stricter, and require that all NFIELDS fields are found.

Fixes: 45c6603cc86c (2007-10-07, "[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Closes: <https://github.com/shadow-maint/shadow/issues/1144>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agoRelease 4.17.0-rc1
Serge Hallyn [Fri, 6 Dec 2024 05:39:32 +0000 (23:39 -0600)] 
Release 4.17.0-rc1

Signed-off-by: Serge Hallyn <serge@hallyn.com>
8 months agolib/gshadow.c: build_list(): Transform while loop into for loop
Alejandro Colomar [Wed, 6 Nov 2024 00:22:42 +0000 (01:22 +0100)] 
lib/gshadow.c: build_list(): Transform while loop into for loop

And 'n' is now an iterator.  Rename it to 'i' as usual.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Allocate at once
Alejandro Colomar [Wed, 6 Nov 2024 00:20:17 +0000 (01:20 +0100)] 
lib/gshadow.c: build_list(): Allocate at once

Instead of reallocating 1 more meber per iteration, calculate the total
amount that we want by counting the number of commas (delimiters) in the
string, plus one for the last element, plus one for the terminating
NULL.

This might result in overallocation of one element if the string is an
empty string, or if there's a trailing comma; however, that's not an
issue.  We can afford overallocating one element in certain cases, and
we get in exchange a much simpler function.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: Remove redundant variables
Alejandro Colomar [Tue, 5 Nov 2024 14:30:41 +0000 (15:30 +0100)] 
lib/gshadow.c: Remove redundant variables

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Remove second parameter
Alejandro Colomar [Tue, 5 Nov 2024 14:13:35 +0000 (15:13 +0100)] 
lib/gshadow.c: build_list(): Remove second parameter

We've simplified the function so much in the previous commits, that now
$2 is rather useless.  It only sets the output parameter to the same
value that the function returns.  It's simpler if the caller just sets
it itself after the call.

This removes the only 3-star pointer in the entire project.  :)

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: sgetsgent(): Be consistent using NULL
Alejandro Colomar [Tue, 5 Nov 2024 13:10:23 +0000 (14:10 +0100)] 
lib/gshadow.c: sgetsgent(): Be consistent using NULL

0 is a horrible null-pointer constant.  Don't use it.
Especially, when just a few lines above, in the same function,
we've used NULL for the same thing.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Compact ++ into previous statement
Alejandro Colomar [Mon, 4 Nov 2024 20:59:27 +0000 (21:59 +0100)] 
lib/gshadow.c: build_list(): Compact ++ into previous statement

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Minimize use of pointer parameters
Alejandro Colomar [Mon, 4 Nov 2024 20:57:06 +0000 (21:57 +0100)] 
lib/gshadow.c: build_list(): Minimize use of pointer parameters

Use instead automatic variables as much as possible.
This reduces the number of dereferences, enhancing readability.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: Remove dead code
Alejandro Colomar [Mon, 4 Nov 2024 21:09:46 +0000 (22:09 +0100)] 
lib/gshadow.c: Remove dead code

Nothing is using that value outside of build_list().
Keep it as an local variable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: Move zeroing to within build_list()
Alejandro Colomar [Tue, 5 Nov 2024 13:56:14 +0000 (14:56 +0100)] 
lib/gshadow.c: Move zeroing to within build_list()

This makes build_list() less dependent on the context.
It starts from clean, whatever the state before the call was.
I was having a hard time understanding the reallocation,
until I saw that we were zeroing everything right before the call.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: sgetsgent(): Remove superfluous condition
Alejandro Colomar [Mon, 4 Nov 2024 20:47:42 +0000 (21:47 +0100)] 
lib/gshadow.c: sgetsgent(): Remove superfluous condition

If n was 0, it doesn't hurt to set it again to 0;
and the list would be NULL, so it doesn't hurt free(3)ing it
and setting to NULL again either.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Remove dead assignment
Alejandro Colomar [Tue, 5 Nov 2024 13:50:35 +0000 (14:50 +0100)] 
lib/gshadow.c: build_list(): Remove dead assignment

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Improve variable and parameter names
Alejandro Colomar [Mon, 4 Nov 2024 16:48:39 +0000 (17:48 +0100)] 
lib/gshadow.c: build_list(): Improve variable and parameter names

It was hard to understand what each variable is.  Use a consistent
scheme, where a 'p' means a pointer, 'l' means list, and 'n' means
number of elements.  Those should be obvious from the name of the
function and the context, and will make it easier to read the code.
Also, the shorter names will allow focusing on the rest of the code.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Remove unused variable
Alejandro Colomar [Mon, 4 Nov 2024 16:33:19 +0000 (17:33 +0100)] 
lib/gshadow.c: build_list(): Remove unused variable

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: build_list(): Fix type of parameter
Alejandro Colomar [Mon, 4 Nov 2024 16:16:33 +0000 (17:16 +0100)] 
lib/gshadow.c: build_list(): Fix type of parameter

list ($2) is a pointer to a list of strings.  We were declaring it as an
array of pointers to strings, which was bogus.  It worked out of luck,
because array parameters are transformed into pointers by the compiler,
but it was incorrect.  Just look at how we're calling this function.

$ grep build_list lib/gshadow.c
build_list(char *s, char ***list, size_t *nlist)
sgroup.sg_adm = build_list (fields[2], &admins, &nadmins);
sgroup.sg_mem = build_list (fields[3], &members, &nmembers);
$ grep '^static .*\<admins\>' lib/gshadow.c
static /*@null@*//*@only@*/char **admins = NULL;
$ grep '^static .*\<members\>' lib/gshadow.c
static /*@null@*//*@only@*/char **members = NULL;

Fixes: 8e167d28afd6 ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agosrc/: Transform do-while into while
Alejandro Colomar [Mon, 4 Nov 2024 15:37:48 +0000 (16:37 +0100)] 
src/: Transform do-while into while

list cannot be NULL in the first iteration, so we don't need a do-while.

Just in case it's not obvious: we know it's not NULL in the first
iteration because right above, in line 772, we've already dereferenced
it.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/, src/: Use strsep(3) instead of strtok(3)
Alejandro Colomar [Thu, 4 Jul 2024 11:21:12 +0000 (13:21 +0200)] 
lib/, src/: Use strsep(3) instead of strtok(3)

strsep(3) is stateless, and so is easier to reason about.

It also has a slight difference: strtok(3) jumps over empty fields,
while strsep(3) respects them as empty fields.  In most of the cases
where we were using strtok(3), it makes more sense to respect empty
fields, and this commit probably silently fixes a few bugs.

In other cases (most notably filesystem paths), contiguous delimiters
("//") should be collapsed, so strtok(3) still makes more sense there.
This commit doesn't replace such strtok(3) calls.

While at this, remove some useless variables used by these calls, and
reduce the scope of others.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agoCI: update artifacts action
Iker Pedrosa [Thu, 5 Dec 2024 11:39:33 +0000 (12:39 +0100)] 
CI: update artifacts action

v3 of upload-artifact actions is being deprecated, so let's move to v4.

Link: https://github.com/actions/upload-artifact
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
8 months agogroupadd, groupmod: Update gshadow file with -U
Dennis Baurichter [Sun, 17 Nov 2024 02:27:40 +0000 (03:27 +0100)] 
groupadd, groupmod: Update gshadow file with -U

When running groupadd or groupmod with the -U|--user option, also update
the group shadow database if it is used.

Fixes: 342c934a (2020-08-09, "add -U option to groupadd and groupmod")
Closes: <https://github.com/shadow-maint/shadow/issues/1124>
8 months agolib/, src/: Use !streq() instead of its pattern
Alejandro Colomar [Sun, 24 Nov 2024 17:40:48 +0000 (18:40 +0100)] 
lib/, src/: Use !streq() instead of its pattern

Except for the added (and sorted) includes, and the removal of redundant
parentheses, and one special case, this patch can be approximated with
the following semantic patch:

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

- strcmp(a, b) != 0
+ !streq(a, b)

@@
expression a, b;
@@

- 0 != strcmp(a, b)
+ !streq(a, b)

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

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agocontrib/, lib/, src/: Use streq() instead of its pattern
Alejandro Colomar [Sun, 17 Nov 2024 02:17:41 +0000 (03:17 +0100)] 
contrib/, lib/, src/: Use streq() instead of its pattern

Except for the added (and sorted) includes, and the removal of redundant
parentheses, this patch can be approximated with the following semantic
patch:

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

- strcmp(a, b) == 0
+ streq(a, b)

@@
expression a, b;
@@

- 0 == strcmp(a, b)
+ streq(a, b)

@@
expression a, b;
@@

- !strcmp(a, b)
+ streq(a, b)

$ find contrib/ lib* src/ -type f \
| xargs spatch --sp-file ~/tmp/spatch/streq.sp --in-place;
$ git restore lib/string/strcmp/streq.h;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow_.h: __STDC__ is always 1
Alejandro Colomar [Mon, 4 Nov 2024 23:37:03 +0000 (00:37 +0100)] 
lib/gshadow_.h: __STDC__ is always 1

We require C11 since a long time ago.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/csrand.c: csrand(): Use read(2) instead of fread(2)
Alejandro Colomar [Tue, 12 Nov 2024 14:19:19 +0000 (15:19 +0100)] 
lib/csrand.c: csrand(): Use read(2) instead of fread(2)

We don't need the heavy stdio for getting a few bytes from
</dev/urandom>.  Let's use the simpler POSIX API.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agosrc/login_nopam.c: resolve_hostname(): Use NI_MAXHOST instead of MAXHOSTNAMELEN with...
Alejandro Colomar [Tue, 22 Oct 2024 22:49:50 +0000 (00:49 +0200)] 
src/login_nopam.c: resolve_hostname(): Use NI_MAXHOST instead of MAXHOSTNAMELEN with getnameinfo(3)

That's what the getnameinfo(3) manual page recommends.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agoAllow setting an empty homedir
Volker Theile [Tue, 26 Nov 2024 08:26:14 +0000 (09:26 +0100)] 
Allow setting an empty homedir

With the PR 352 it is not possible anymore to run `usermod --home "" <USERNAME>`. This PR will fix that regression.

Related to: https://github.com/shadow-maint/shadow/pull/352

Signed-off-by: Volker Theile <votdev@gmx.de>
8 months agoshare/container-build.sh: Fix path
Alejandro Colomar [Mon, 25 Nov 2024 14:22:10 +0000 (15:22 +0100)] 
share/container-build.sh: Fix path

The instructions are written so that this script should be run from the
root of the repository.  Specify the path from the root of the repo.
Before this fix, the command needed to be run from within <share/>.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agoCI: avoid cancelling all jobs when one fails
Iker Pedrosa [Fri, 22 Nov 2024 11:49:41 +0000 (12:49 +0100)] 
CI: avoid cancelling all jobs when one fails

If a job in a matrix fails we don't want to cancel all jobs, thus we
need to set `fail-fast: false` as a strategy property.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
8 months agolib/idmapping.c: Fix get_map_ranges range check
Tobias Stoeckmann [Mon, 11 Nov 2024 19:28:52 +0000 (20:28 +0100)] 
lib/idmapping.c: Fix get_map_ranges range check

The get_map_ranges function shall support the whole accepted range
as specified in user_namespaces(7), i.e. upper and lower from 0 to
UINT_MAX - 1 as well as range from 1 to UINT_MAX. The actual limit of
range depends on values of upper and lower and adding the range
to either upper or lower shall never overflow UINT_MAX.

Fixes: 7c43eb2c4ea6 (2024-07-11, "lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call")
Fixes: ff2baed5dbf8 (2016-08-14, "idmapping: add more checks for overflow")
Fixes: 94da3dc5c853 (2016-08-14, "also check upper for wrap")
Fixes: 7f5a14817d30 (2016-07-31, "get_map_ranges: check for overflow")
Co-authored-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/, src/: Use NULL instead of 0 as a null pointer constant
Alejandro Colomar [Wed, 13 Nov 2024 12:23:35 +0000 (13:23 +0100)] 
lib/, src/: Use NULL instead of 0 as a null pointer constant

GCC 15 will add -Wzero-as-null-pointer-constant for deprecating it,
and I'm working on a paper for deprecating it from ISO C too.
Let's remove any uses in our code base.

I've done this change by building GCC from master, adding
-Werror=zero-as-null-pointer-constant to ./autogen.sh, and fixing every
error that showed up.

Closes: <https://github.com/shadow-maint/shadow/issues/1120>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>
Link: <https://software.codidact.com/posts/292718/292759#answer-292759>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/shadow.c: my_sgetspent(): There can be only one!
Alejandro Colomar [Mon, 11 Nov 2024 10:58:30 +0000 (11:58 +0100)] 
lib/shadow.c: my_sgetspent(): There can be only one!

We already have sgetspent(), with identical semantics, defined in
<lib/sgetspent.c>.

$ diff -u <(grepc sgetspent .) <(grepc my_sgetspent .)
--- /dev/fd/63 2024-11-11 11:56:55.444055921 +0100
+++ /dev/fd/62 2024-11-11 11:56:55.444055921 +0100
@@ -1,23 +1,19 @@
-./lib/sgetspent.c:struct spwd *
-sgetspent(const char *string)
+./lib/shadow.c:static struct spwd *my_sgetspent (const char *string)
 {
- static char spwbuf[PASSWD_ENTRY_MAX_LENGTH];
- static struct spwd spwd;
- char *fields[FIELDS];
- char *cp;
- int i;
+ int                 i;
+ char                *fields[FIELDS];
+ char                *cp;
+ static char         spwbuf[BUFSIZ];
+ static char         empty[] = "";
+ static struct spwd  spwd;

/*
 * Copy string to local buffer.  It has to be tokenized and we
 * have to do that to our private copy.
 */

- if (strlen (string) >= sizeof spwbuf) {
- fprintf (shadow_logfd,
-          "%s: Too long passwd entry encountered, file corruption?\n",
-          shadow_progname);
- return NULL; /* fail if too long */
- }
+ if (strlen (string) >= sizeof spwbuf)
+ return 0;
strcpy (spwbuf, string);
stpsep(spwbuf, "\n");

@@ -30,14 +26,16 @@
fields[i] = strsep(&cp, ":");

if (i == (FIELDS - 1))
- fields[i++] = "";
+ fields[i++] = empty;

if (cp != NULL || (i != FIELDS && i != OFIELDS))
- return NULL;
+ return 0;

/*
 * Start populating the structure.  The fields are all in
-  * static storage, as is the structure we pass back.
+  * static storage, as is the structure we pass back.  If we
+  * ever see a name with '+' as the first character, we try
+  * to turn on NIS processing.
 */

spwd.sp_namp = fields[0];
@@ -46,13 +44,13 @@
/*
 * Get the last changed date.  For all of the integer fields,
 * we check for proper format.  It is an error to have an
-  * incorrectly formatted number.
+  * incorrectly formatted number, unless we are using NIS.
 */

if (fields[2][0] == '\0')
spwd.sp_lstchg = -1;
else if (a2sl(&spwd.sp_lstchg, fields[2], NULL, 0, 0, LONG_MAX) == -1)
- return NULL;
+ return 0;

/*
 * Get the minimum period between password changes.
@@ -61,7 +59,7 @@
if (fields[3][0] == '\0')
spwd.sp_min = -1;
else if (a2sl(&spwd.sp_min, fields[3], NULL, 0, 0, LONG_MAX) == -1)
- return NULL;
+ return 0;

/*
 * Get the maximum number of days a password is valid.
@@ -70,7 +68,7 @@
if (fields[4][0] == '\0')
spwd.sp_max = -1;
else if (a2sl(&spwd.sp_max, fields[4], NULL, 0, 0, LONG_MAX) == -1)
- return NULL;
+ return 0;

/*
 * If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
@@ -93,7 +91,7 @@
if (fields[5][0] == '\0')
spwd.sp_warn = -1;
else if (a2sl(&spwd.sp_warn, fields[5], NULL, 0, 0, LONG_MAX) == -1)
- return NULL;
+ return 0;

/*
 * Get the number of days of inactivity before an account is
@@ -103,7 +101,7 @@
if (fields[6][0] == '\0')
spwd.sp_inact = -1;
else if (a2sl(&spwd.sp_inact, fields[6], NULL, 0, 0, LONG_MAX) == -1)
- return NULL;
+ return 0;

/*
 * Get the number of days after the epoch before the account is
@@ -113,7 +111,7 @@
if (fields[7][0] == '\0')
spwd.sp_expire = -1;
else if (a2sl(&spwd.sp_expire, fields[7], NULL, 0, 0, LONG_MAX) == -1)
- return NULL;
+ return 0;

/*
 * This field is reserved for future use.  But it isn't supposed
@@ -123,8 +121,7 @@
if (fields[8][0] == '\0')
spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
else if (str2ul(&spwd.sp_flag, fields[8]) == -1)
- return NULL;
+ return 0;

return (&spwd);
 }
-./lib/prototypes.h:extern struct spwd *sgetspent (const char *string);

Closes: <https://github.com/shadow-maint/shadow/issues/1114>
Link: <https://www.youtube.com/watch?v=IpbvtSQvgWM>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agosrc/login_nopam.c: Rely on the system's MAXHOSTNAMELEN
Alejandro Colomar [Tue, 22 Oct 2024 22:14:12 +0000 (00:14 +0200)] 
src/login_nopam.c: Rely on the system's MAXHOSTNAMELEN

The reason for that code seems to be some ancient AIX version that
defined a value that was too small (32).  We don't support such systems.
In the link below, I found the following comment and code:

 /*
  * Some AIX versions advertise a too small MAXHOSTNAMELEN value (32).
  * Result: long hostnames would be truncated, and connections would be
  * dropped because of host name verification failures. Adrian van Bloois
  * (A.vanBloois@info.nic.surfnet.nl) figured out what was the problem.
  */

#if (MAXHOSTNAMELEN < 64)
#undef MAXHOSTNAMELEN
#endif

/* In case not defined in <sys/param.h>. */

#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN  256             /* storage for host name */
#endif

Today's systems seem to be much better regarding this macro.  Rely on
them.

Link: <https://sources.debian.org/src/tcp-wrappers/7.6.q-33/workarounds.c/?hl=36#L36>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/gshadow.c: endsgent(): Invert logic to reduce indentation
Alejandro Colomar [Sun, 21 Jul 2024 16:18:08 +0000 (18:18 +0200)] 
lib/gshadow.c: endsgent(): Invert logic to reduce indentation

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/list.c: comma_to_list(): Use strchrcnt() instead of its pattern
Alejandro Colomar [Thu, 4 Jul 2024 13:42:17 +0000 (15:42 +0200)] 
lib/list.c: comma_to_list(): Use strchrcnt() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/string/strchr/: strchrcnt(): Add function
Alejandro Colomar [Thu, 4 Jul 2024 13:30:58 +0000 (15:30 +0200)] 
lib/string/strchr/: strchrcnt(): Add function

Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 months agolib/string/strcmp/: streq(): Add function
Alejandro Colomar [Tue, 15 Oct 2024 11:21:17 +0000 (13:21 +0200)] 
lib/string/strcmp/: streq(): Add function

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 months agosrc/gpasswd.c: is_valid_user_list(): Fix invalid free(3)
frostb1te [Fri, 8 Nov 2024 11:00:24 +0000 (05:00 -0600)] 
src/gpasswd.c: is_valid_user_list(): Fix invalid free(3)

This fix addresses an issue in is_valid_user_list() where the free
operation was attempted on an address not allocated with malloc().  By
duplicating the pointer with xstrdup(users) into dup, and using dup as
the original pointer, we ensure that only the valid pointer is freed,
avoiding an invalid free operation.

This bug was introduced when changing some code that used strchrnul(3)
to use strsep(3) instead.  strsep(3) advances the pointer, unlike the
previous code.

This unconditionally leads to a bug:

-  Passing NULL to free(3), if the last field in the
   colon-separated-value list is non-empty.  This results in a memory
   leak.

-  Passing a pointer to the null byte ('\0') that terminates the string,
   if the last element of the colon-separated-value list is empty.  The
   most obvious reproducer of such a bogus free(3) call is:

       free(strdup("foo:") + 4);

   This results in Undefined Behavior, and could result in allocator
   data corruption.

Fixes: 16cb66486554 (2024-07-01, "lib/, src/: Use strsep(3) instead of its pattern")
Suggested-by: <https://github.com/frostb1ten>
Reported-by: <https://github.com/frostb1ten>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Christian Brauner <christian@brauner.io>
9 months agoman/shadow,man/gshadow: Fix grammar
Miroslav Cimerman [Mon, 4 Nov 2024 09:06:56 +0000 (10:06 +0100)] 
man/shadow,man/gshadow: Fix grammar

Signed-off-by: Miroslav Cimerman <mc@doas.su>
9 months agolib/fs/readlink/areadlink.h: areadlink(): Use PATH_MAX instead of a magic value
Alejandro Colomar [Tue, 22 Oct 2024 10:15:48 +0000 (12:15 +0200)] 
lib/fs/readlink/areadlink.h: areadlink(): Use PATH_MAX instead of a magic value

Signed-off-by: Alejandro Colomar <alx@kernel.org>
9 months agolib/fs/readlink/areadlink.h: Cosmetic changes
Alejandro Colomar [Mon, 14 Oct 2024 11:53:31 +0000 (13:53 +0200)] 
lib/fs/readlink/areadlink.h: Cosmetic changes

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