]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
3 months agosrc/vipw.c: Reverse logic and variable name
Alejandro Colomar [Thu, 7 Mar 2024 22:34:31 +0000 (23:34 +0100)] 
src/vipw.c: Reverse logic and variable name

Since we're checking for "vigr", it makes more sense to name the
variable accordingly.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agoHardcoding Prog to known value
Skyler Ferrante [Sun, 3 Mar 2024 05:54:05 +0000 (00:54 -0500)] 
Hardcoding Prog to known value

See #959. We now set Prog (program name) based on hardcoded value instead
of argv[0]. This is to help prevent escape sequence injection.

3 months agoshare/containers/: trap(1) to see the cmocka logs
Alejandro Colomar [Wed, 28 Feb 2024 11:10:17 +0000 (12:10 +0100)] 
share/containers/: trap(1) to see the cmocka logs

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agoshare/containers/: Specify one argument per line
Alejandro Colomar [Wed, 28 Feb 2024 11:07:22 +0000 (12:07 +0100)] 
share/containers/: Specify one argument per line

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months ago.github/workflows/runner.yml: trap(1) to see the testsuite log
Alejandro Colomar [Wed, 21 Feb 2024 14:14:45 +0000 (15:14 +0100)] 
.github/workflows/runner.yml: trap(1) to see the testsuite log

Otherwise, 'cat testsuite.log' isn't run, since 'set -e' aborts the
script earlier.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agoconfigure.ac: release 4.15.0-rc3 4.15.0-rc3
Serge Hallyn [Fri, 1 Mar 2024 01:51:37 +0000 (19:51 -0600)] 
configure.ac: release 4.15.0-rc3

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 months agolib/utmp.c: Use the appropriate autotools macros for struct utmpx
Alejandro Colomar [Tue, 20 Feb 2024 18:15:41 +0000 (19:15 +0100)] 
lib/utmp.c: Use the appropriate autotools macros for struct utmpx

Recently, we started using utmpx instead of utmp, and we updated
<./configure.ac> to do the checks for 'struct utmpx' instead of
'struct utmp'.  However, I forgot to update the preprocessor
conditionals accordingly.

Fixes: 64bcb54fa962 ("lib/, src/, configure.ac: Use utmpx instead of utmp")
Link: <https://github.com/shadow-maint/shadow/pull/954>
Cc: Firas Khalil Khana <firasuke@gmail.com>
Cc: "A. Wilfox" <https://github.com/awilfox>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/utmp.c: Use defined() instead of #if[n]def
Alejandro Colomar [Tue, 20 Feb 2024 18:13:03 +0000 (19:13 +0100)] 
lib/utmp.c: Use defined() instead of #if[n]def

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/utmp.c: Remove #endif comments
Alejandro Colomar [Tue, 20 Feb 2024 18:25:37 +0000 (19:25 +0100)] 
lib/utmp.c: Remove #endif comments

Indentation makes it clear which is which.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/utmp.c: Merge preprocessor conditionals
Alejandro Colomar [Tue, 20 Feb 2024 18:09:36 +0000 (19:09 +0100)] 
lib/utmp.c: Merge preprocessor conditionals

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/utmp.c: Indent nested preprocessor conditionals
Alejandro Colomar [Tue, 20 Feb 2024 18:06:49 +0000 (19:06 +0100)] 
lib/utmp.c: Indent nested preprocessor conditionals

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/utmp.c: Replace UT_LINESIZE by a NITEMS() calculation
Alejandro Colomar [Sun, 18 Feb 2024 17:36:04 +0000 (18:36 +0100)] 
lib/utmp.c: Replace UT_LINESIZE by a NITEMS() calculation

A difference between 'struct utmp' and 'struct utmpx' is that
the former uses UT_LINESIZE for the size of its array members,
while the latter doesn't have a standard variable to get its
size.  Therefore, we need to get the number of elements in
the array with NITEMS().

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/sizeof.h: memberof(): Add macro
Alejandro Colomar [Sun, 18 Feb 2024 17:32:31 +0000 (18:32 +0100)] 
lib/sizeof.h: memberof(): Add macro

This macro is useful to get the size of a member of a structure
without having a variable of that type.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/utmp.c: get_session_host(): Reduce scope of variable
Alejandro Colomar [Sun, 18 Feb 2024 01:39:57 +0000 (02:39 +0100)] 
lib/utmp.c: get_session_host(): Reduce scope of variable

This silences a warning about an unused variable.

Tested-by: Firas Khalil Khana <firasuke@gmail.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/, src/, configure.ac: Use utmpx instead of utmp
Alejandro Colomar [Sat, 17 Feb 2024 14:15:38 +0000 (15:15 +0100)] 
lib/, src/, configure.ac: Use utmpx instead of utmp

utmpx is specified by POSIX as an XSI extension.  That's more portable
than utmp, which is unavailable for example in musl libc.  The manual
page specifies that in Linux (but it probably means in glibc), utmp and
utmpx (and the functions that use them) are identical, so this commit
shouldn't affect glibc systems.

Assume utmpx is always present.

Also, if utmpx is present, POSIX guarantees that some members exist:

-  ut_user
-  ut_id
-  ut_line
-  ut_pid
-  ut_type
-  ut_tv

So, rely on them unconditionally.

Fixes: 170b76cdd1a9 ("Disable utmpx permanently")
Closes: <https://github.com/shadow-maint/shadow/issues/945>
Reported-by: Firas Khalil Khana <firasuke@gmail.com>
Reported-by: "A. Wilfox" <https://github.com/awilfox>
Tested-by: Firas Khalil Khana <firasuke@gmail.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/getdate.y: get_date(): Fix calculation
Alejandro Colomar [Thu, 15 Feb 2024 11:59:23 +0000 (12:59 +0100)] 
lib/getdate.y: get_date(): Fix calculation

Instead of adding 1, we should add the value the we stored previously in
the variable.

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Closes: <https://github.com/shadow-maint/shadow/issues/939>
Link: <https://github.com/shadow-maint/shadow/pull/942>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Reported-by: Gus Kenion <https://github.com/kenion>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agosrc/passwd.c: check password length upper limit
Tomas Halman [Fri, 16 Feb 2024 08:52:39 +0000 (09:52 +0100)] 
src/passwd.c: check password length upper limit

The passwd silently truncated the password length to PASS_MAX.
This patch introduces check that prints an error message
and exits the call.

Signed-off-by: Tomas Halman <tomas@halman.net>
3 months agosrc/passwd.c: inconsistent password length limit
Tomas Halman [Fri, 16 Feb 2024 08:33:02 +0000 (09:33 +0100)] 
src/passwd.c: inconsistent password length limit

The passwd utility had hardcoded limit for password lenght set
to 200 characters. In the agetpass.c is used PASS_MAX for
this purpose.

This patch moves the PASS_MAX definition to common place
and uses it in both places.

Signed-off-by: Tomas Halman <tomas@halman.net>
3 months agorelease 4.15.0-rc2 4.15.0-rc2
Serge Hallyn [Thu, 15 Feb 2024 23:54:19 +0000 (17:54 -0600)] 
release 4.15.0-rc2

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 months agoUpdate Georgian translation
NorwayFun [Thu, 8 Feb 2024 05:15:03 +0000 (06:15 +0100)] 
Update Georgian translation

3 months agolib/chkname.c: is_valid_user_name(): Avoid a cast
Alejandro Colomar [Mon, 5 Feb 2024 11:40:51 +0000 (12:40 +0100)] 
lib/chkname.c: is_valid_user_name(): Avoid a cast

By using a temporary vairable, we can remove a cast.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/chkname.c: is_valid_user_name(): Remove unnecessary check
Alejandro Colomar [Mon, 5 Feb 2024 13:14:01 +0000 (14:14 +0100)] 
lib/chkname.c: is_valid_user_name(): Remove unnecessary check

If (maxsize == -1), then ((size_t)maxsize == SIZE_MAX).  And no size can
ever be >= SIZE_MAX, so it will never return false if sysconf(3) reports
an unlimited user-name size via returning -1.  Well, to be pedantic,
that disallows a user-name siz of precisely SIZE_MAX bytes when
sysconf(3) returns -1.  However, that's probably a good thing; such a
long user name might trigger Undefined Behavior somewhere else, so be
cautious and disallow it.  I hope nobody will be using the entire
address space for a user name.

The commit that introduced that check missed that this code had always
supported unlimited user-name sizes since it was introduced by Iker in
3b7cc053872c ("lib: replace `USER_NAME_MAX_LENGTH` macro"), and
6be85b0bafb5 ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare
warning") even clarified this in the commit message.

So, while the code in 6a1f45d932c8 ("lib/chkname.c: Support unlimited
user name lengths") wasn't bad per se, the commit message was incorrect.
What that patch did was adding code for handling EINVAL (or any other
errors that a future kernel might add).

To be more pedantically correct, that commit also allowed (under certain
circumstances, user names of SIZE_MAX bytes, but those were originally
allowed (by accident), and only became disallowed in 403a2e3771be
("lib/chkname.c: Take NUL byte into account").  But again, let's
disallow those, just to be cautious.

Link: <https://github.com/shadow-maint/shadow/pull/935>
Link: <https://github.com/shadow-maint/shadow/pull/935#discussion_r1477429492>
See-also: 6be85b0bafb5 ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning")
Fixes: 6a1f45d932c8 ("lib/chkname.c: Support unlimited user name lengths")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agosrc/login.c: Fix off-by-one bugss
Alejandro Colomar [Mon, 5 Feb 2024 12:54:25 +0000 (13:54 +0100)] 
src/login.c: Fix off-by-one bugss

These functions expect a size, not a length.  Don't subtract 1 to the
size.

Link: <https://github.com/shadow-maint/shadow/pull/935>
Link: <https://github.com/shadow-maint/shadow/issues/920#issuecomment-1926002209>
Link: <https://github.com/shadow-maint/shadow/pull/757>
Link: <https://github.com/shadow-maint/shadow/issues/674>
See-also: 0656a90bfd0d ("src/login.c: Fix off-by-one buggs")
See-also: 403a2e3771be ("lib/chkname.c: Take NUL byte into account")
Fixes: 3b7cc053872c ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/: Don't say 'len' where 'size' is meant
Alejandro Colomar [Mon, 5 Feb 2024 12:44:52 +0000 (13:44 +0100)] 
lib/: Don't say 'len' where 'size' is meant

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Fixes: 3b7cc053872c ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Fixes: 6be85b0bafb5 ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning")
See-also: 403a2e3771be ("lib/chkname.c: Take NUL byte into account")
See-also: 6a1f45d932c8 ("lib/chkname.c: Support unlimited user name lengths")
Fixes: 95ea61009da8 ("lib/chkname.c: Use precise comment")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agosrc/login.c: Fix off-by-one buggs
Alejandro Colomar [Mon, 5 Feb 2024 12:14:13 +0000 (13:14 +0100)] 
src/login.c: Fix off-by-one buggs

Before 3b7cc053872c ("lib: replace `USER_NAME_MAX_LENGTH` macro"), this
code did use a length.  It used a utmp(5) fixed-width buffer, so the
length matches the buffer size (there was no terminating NUL byte).
However, sysconf(_SC_LOGIN_NAME_MAX) returns a buffer size that accounts
for the terminating null byte; see sysconf(3).  Thus, the commit that
introduced the call to sysconf(3), should have taken that detail into
account.

403a2e3771be ("lib/chkname.c: Take NUL byte into account"), by Tobias,
caught that bug in <lib/chkname.c>, but missed that the same commit that
introduced that bug, introduced the same bug in two other places.
This fixes all remaining calls to sysconf(_SC_LOGIN_NAME_MAX).

I still observe some suspicious code after this fix:

if (do_rlogin(hostname, username, max_size - 1, term, sizeof(term)))

...

login_prompt(username, max_size - 1);

We're passing size-1 to functions that want a size.  But since the fix
to those will be different, let's do that in the following commits.

Link: <https://github.com/shadow-maint/shadow/pull/935>
Link: <https://github.com/shadow-maint/shadow/issues/920#issuecomment-1926002209>
Link: <https://github.com/shadow-maint/shadow/pull/757>
Link: <https://github.com/shadow-maint/shadow/issues/674>
See-also: 403a2e3771be ("lib/chkname.c: Take NUL byte into account")
Fixes: 3b7cc053872c ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agousermod: refuse invalid uidmaps during --add-sub{u,g}ids
Tycho Andersen [Tue, 13 Feb 2024 21:30:12 +0000 (14:30 -0700)] 
usermod: refuse invalid uidmaps during --add-sub{u,g}ids

It is slightly confusing to allow adding these only to later refuse them.

Here is a (lightly tested :) patch to also refuse them when adding.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
3 months agolib/strtoday.c: strtoday(): Fix calculation
Alejandro Colomar [Thu, 8 Feb 2024 11:53:24 +0000 (12:53 +0100)] 
lib/strtoday.c: strtoday(): Fix calculation

Days officially roll over at 00:00 UTC, not at 12:00 UTC.  I see no
reason to add that half day.

Also, remove the comment.  It's likely to get stale.

So, get_date() gets the number of seconds since the Epoch.  I wonder how
that thing works, but I'll assume it's something similar to getdate(3)
+ mktime(3).  After that, we need to convert seconds since Epoch to days
since Epoch.  That should be a simple division, AFAICS, since Epoch is
"1970‐01‐01 00:00:00 +0000 (UTC)".  See mktime(3).

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Link: <https://github.com/shadow-maint/shadow/issues/939>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Tested-by: Gus Kenion <https://github.com/kenion>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agolib/: Saturate addition to avoid overflow
Tobias Stoeckmann [Mon, 18 Dec 2023 19:45:44 +0000 (20:45 +0100)] 
lib/: Saturate addition to avoid overflow

Very large values in /etc/shadow could lead to overflows.  Make sure
that these calculations are saturated at LONG_MAX.  Since entries are
based on days and not seconds since epoch, saturating won't hurt anyone.

Co-developed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agosrc/chage.c: Unify long overflow checks in print_day_as_date()
Tobias Stoeckmann [Thu, 14 Dec 2023 11:33:35 +0000 (12:33 +0100)] 
src/chage.c: Unify long overflow checks in print_day_as_date()

The conversion from day to seconds can be done in print_date
(renamed to print_day_as_date for clarification).  This has the nice
benefit that DAY multiplication and long to time_t conversion are done
at just one place.

Co-developed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
3 months agoetc/pam.d/Makefile.am: Fix typo
Alejandro Colomar [Tue, 13 Feb 2024 12:17:44 +0000 (13:17 +0100)] 
etc/pam.d/Makefile.am: Fix typo

The commit we're fixing mentions that it wanted to move 'chpasswd', but
it removed 'ch_g_passwd' from 'pamd_acct_tools_files' and added
'chpasswd' to 'pamd_files'.  It seems it removed the wrong thing by
accident.

Fixes: 341d80c2c751 ("Makefile: move chpasswd and newusers to pamd target")
Link: <https://github.com/shadow-maint/shadow/pull/928#discussion_r1487687347>
Link: <https://github.com/shadow-maint/shadow/issues/926#issuecomment-1941324761>
Reported-by: Dominique Leuenberger <dleuenberger@suse.com>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Cc: David Runge <dvzrv@archlinux.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Tested-by: Michael Vetter <jubalh@iodoru.org>
Reviewed-by: Michael Vetter <jubalh@iodoru.org>
Reviewed-by: loqs <https://github.com/loqs>
Co-developed-by: Dominique Leuenberger <dleuenberger@suse.com>
Signed-off-by: Dominique Leuenberger <dleuenberger@suse.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agoAUTHORS.md: Format list
Alejandro Colomar [Tue, 6 Feb 2024 09:44:36 +0000 (10:44 +0100)] 
AUTHORS.md: Format list

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/chkname.c: Use precise comment
Tobias Stoeckmann [Sat, 3 Feb 2024 00:12:16 +0000 (01:12 +0100)] 
lib/chkname.c: Use precise comment

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 months agolib/chkname.c: Support unlimited user name lengths
Tobias Stoeckmann [Sat, 3 Feb 2024 00:10:22 +0000 (01:10 +0100)] 
lib/chkname.c: Support unlimited user name lengths

If the system does not have a user name length limit, support it
accordingly. If the system has no _SC_LOGIN_NAME_MAX, use
LOGIN_NAME_MAX constant instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 months agolib/chkname.c: Take NUL byte into account
Tobias Stoeckmann [Sat, 3 Feb 2024 00:07:58 +0000 (01:07 +0100)] 
lib/chkname.c: Take NUL byte into account

The _SC_LOGIN_NAME_MAX value includes space for the NUL byte. The length
of name must smaller than this value to be valid.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 months agorelease 4.15.0-rc1 4.15.0-rc1
Serge Hallyn [Thu, 1 Feb 2024 23:02:48 +0000 (17:02 -0600)] 
release 4.15.0-rc1

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 months agosrc/sulogin.c: Remove unused variable
Samanta Navarro [Fri, 19 Jan 2024 11:55:24 +0000 (11:55 +0000)] 
src/sulogin.c: Remove unused variable

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 months agosrc/sulogin.c: Simplify password handling
Samanta Navarro [Fri, 19 Jan 2024 11:54:14 +0000 (11:54 +0000)] 
src/sulogin.c: Simplify password handling

The password returned by agetpass can be used directly without copying
it into a char array first.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 months agosrc/sulogin.c: Use a do-while loop
Samanta Navarro [Fri, 19 Jan 2024 11:53:53 +0000 (11:53 +0000)] 
src/sulogin.c: Use a do-while loop

Clarify how this endless while(true) loop can be stopped by using a
boolean variable as condition and turn it into a do-while loop.

Suggested-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 months agotests/unit/test_atoi_strtoi.c: Test strtou_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 19:35:29 +0000 (20:35 +0100)] 
tests/unit/test_atoi_strtoi.c: Test strtou_noneg()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/atoi/strtou_noneg.[ch]: Add strtou_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 18:46:20 +0000 (19:46 +0100)] 
lib/atoi/strtou_noneg.[ch]: Add strtou_noneg()

It's like strtou_(), but rejects negative input, instead of silently
converting it to unsigned.

Link: <https://softwareengineering.stackexchange.com/a/449060/332848>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agotests/unit/Makefile.am: tfix
Alejandro Colomar [Sun, 7 Jan 2024 01:35:00 +0000 (02:35 +0100)] 
tests/unit/Makefile.am: tfix

Fix typo.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agotests/unit/test_atoi_strtoi.c: Test strtoi_()
Alejandro Colomar [Sat, 6 Jan 2024 18:06:27 +0000 (19:06 +0100)] 
tests/unit/test_atoi_strtoi.c: Test strtoi_()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/atoi/strtoi.[ch]: strtoi_(), strtou_(): Add functions
Alejandro Colomar [Fri, 1 Dec 2023 21:34:31 +0000 (22:34 +0100)] 
lib/atoi/strtoi.[ch]: strtoi_(), strtou_(): Add functions

These functions are identical to strtoi(3bsd) and strtou(3bsd), except
for one important thing: if both ERANGE and ENOTSUP conditions happen,
the BSD functions report ENOTSUP, which is bogus; our strtoi_() and
strtou_() report ERANGE.

Link: <https://lists.sr.ht/~hallyn/shadow/%3CZZoQDms6Sv6e5SPE%40debian%3E>
Link: <https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57828>
Cc: Thorsten Glaser <tg@mirbsd.de>
Cc: christos <christos@netbsd.org>
Cc: roy <roy@netbsd.org>
Cc: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/passwd.c: implement reading password from pipe
Tomas Halman [Thu, 25 Jan 2024 10:00:09 +0000 (11:00 +0100)] 
src/passwd.c: implement reading password from pipe

New option --stdin/-t is available for root user. It is useful
for automation/setup and it makes shadow utils passwd more versatile.

Signed-off-by: Tomas Halman <tomas@halman.net>
4 months agolib/agetpass.[ch]: add function ro read from pipe
Tomas Halman [Thu, 25 Jan 2024 09:56:10 +0000 (10:56 +0100)] 
lib/agetpass.[ch]: add function ro read from pipe

Add alternative function to agetpass for reading password
from stdin or pipe.

Signed-off-by: Tomas Halman <tomas@halman.net>
4 months agoMakefile: move chpasswd and newusers to pamd target
loqs [Fri, 26 Jan 2024 12:41:09 +0000 (12:41 +0000)] 
Makefile: move chpasswd and newusers to pamd target

Install pam configs for chpasswd and newusers when using ./configure --with-libpam --disable-account-tools-setuid.
Fixes https://github.com/shadow-maint/shadow/issues/810.

Tested-by: David Runge <dvzrv@archlinux.org>
4 months agolib/, src/: Make the use of MAYBE_UNUSED macro consistent
Pablo Saavedra [Tue, 23 Jan 2024 07:33:37 +0000 (08:33 +0100)] 
lib/, src/: Make the use of MAYBE_UNUSED macro consistent

There is an inconsistent use of the MAYBE_UNUSED macro. Sometimes the
`int unused(x)` form is used form and others the `unused int x`. We'd
like to use the second form always.

Related-To: https://github.com/shadow-maint/shadow/issues/918
Suggested-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
4 months agolib/, src/: Rename 'unused' macro as 'MAYBE_UNUSED'
Pablo Saavedra [Mon, 22 Jan 2024 09:00:54 +0000 (10:00 +0100)] 
lib/, src/: Rename 'unused' macro as 'MAYBE_UNUSED'

Related-To: https://github.com/shadow-maint/shadow/issues/918
Suggested-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
4 months agoFix Build error 'parameter name omitted' in logind
Pablo Saavedra [Mon, 22 Jan 2024 13:46:15 +0000 (14:46 +0100)] 
Fix Build error 'parameter name omitted' in logind

Fixes #918 by adding the omitted parameter name in
active_sessions_count().

Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
4 months agosrc/sulogin.c: pw_entry(): Report errors by returning -1
Alejandro Colomar [Mon, 29 Jan 2024 15:28:02 +0000 (16:28 +0100)] 
src/sulogin.c: pw_entry(): Report errors by returning -1

Cc: Samanta Navarro <ferivoz@riseup.net>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/passwd.c: Remove comments about flags that don't exist
Alejandro Colomar [Mon, 29 Jan 2024 11:59:14 +0000 (12:59 +0100)] 
src/passwd.c: Remove comments about flags that don't exist

Those flags have never existed, AFAICS.

Closes: <https://github.com/shadow-maint/shadow/issues/929>
Cc: Tomas Halman <tomas@halman.net>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agoLink correctly with libdl
Sam James [Sun, 21 Jan 2024 14:58:33 +0000 (14:58 +0000)] 
Link correctly with libdl

This fixes build with glibc-2.33 (newer glibc merged libdl and libpthread
into libc):
```
libtool: link: x86_64-pc-linux-gnu-gcc -isystem /usr/include/bsd -DLIBBSD_OVERLAY -O2 -pipe -Wl,-O1 -o login login.o login_nopam.o  -Wl,--as-needed ../lib/.libs/libshadow.a -lcrypt -lsystemd -lpam -lpam_misc -lbsd
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: ../lib/.libs/libshadow.a(libshadow_la-nss.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /lib64/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
```

In Debian, the needed macro from libtool seems to be in libltdl-dev.

Signed-off-by: Sam James <sam@gentoo.org>
4 months agoautogen.sh: CFLAGS: Use -Wno-unknown-attributes; Clang doesn't know [[gnu::access()]]
Alejandro Colomar [Mon, 22 Jan 2024 23:10:14 +0000 (00:10 +0100)] 
autogen.sh: CFLAGS: Use -Wno-unknown-attributes; Clang doesn't know [[gnu::access()]]

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agoautogen.sh: CFLAGS: Add some -Werror=... flags that will be default soon
Alejandro Colomar [Mon, 22 Jan 2024 21:25:34 +0000 (22:25 +0100)] 
autogen.sh: CFLAGS: Add some -Werror=... flags that will be default soon

Clang 16 and GCC 14 have upgraded several warnings to errors by default.
Also, there are new warnings that will be requirements of ISO C23.  Add
all of those to our build.

Use Clang's -Wno-unknown-attribute-option, to ignore warnings that are
exclusive of GCC.  Sadly, GCC doesn't have such an option.

Link: <https://wiki.gentoo.org/wiki/Modern_C_porting#What_changed.3F>
Link: <https://github.com/shadow-maint/shadow/issues/922>
Suggested-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/usermod.c: grp_update(): Remove scope of variable, and fix const correctness
Alejandro Colomar [Mon, 22 Jan 2024 22:52:09 +0000 (23:52 +0100)] 
src/usermod.c: grp_update(): Remove scope of variable, and fix const correctness

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/useradd.c: get_defaults(): Use const temporary pointer to fix const correctness
Alejandro Colomar [Mon, 22 Jan 2024 22:49:19 +0000 (23:49 +0100)] 
src/useradd.c: get_defaults(): Use const temporary pointer to fix const correctness

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/su.c: Use const_cast() to silence -Wincompatible-pointer-types-discards-qualifiers
Alejandro Colomar [Mon, 22 Jan 2024 21:52:59 +0000 (22:52 +0100)] 
src/su.c: Use const_cast() to silence -Wincompatible-pointer-types-discards-qualifiers

argv is passed to execve(3), which for historic reasons is non-const,
but doesn't modify the strings.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/cast.h: const_cast(): Add macro for dropping 'const'
Alejandro Colomar [Sun, 7 Jan 2024 00:00:45 +0000 (01:00 +0100)] 
lib/cast.h: const_cast(): Add macro for dropping 'const'

Uses of this macro indicate a code smell, but in some cases, libc
functions require breaking const correctness.  Use this macro to wrap
casts in such cases, so that we limit the danger of the cast.

It only permits discarding const.  Discarding any other qualifiers, or
doing other type changes should result in a compile-time error.

Link: <https://software.codidact.com/posts/286575/287345#answer-287345>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/must_be.h: is_same_type(): Add macro
Alejandro Colomar [Mon, 22 Jan 2024 21:43:40 +0000 (22:43 +0100)] 
lib/must_be.h: is_same_type(): Add macro

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/must_be.h: is_same_typeof(): Rename macro
Alejandro Colomar [Mon, 22 Jan 2024 21:42:46 +0000 (22:42 +0100)] 
lib/must_be.h: is_same_typeof(): Rename macro

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/su.c: do_check_perms(): Fix -Wincompatible-pointer-types bug
Alejandro Colomar [Sun, 21 Jan 2024 12:48:21 +0000 (13:48 +0100)] 
src/su.c: do_check_perms(): Fix -Wincompatible-pointer-types bug

Fixes: ef95bb7ed139 ("src/su.c: Fix type of variable")
Closes: <https://github.com/shadow-maint/shadow/issues/915>
Reported-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agotests/unit/test_atoi_strtou_noneg.c: Test strtou[l]l_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 17:00:19 +0000 (18:00 +0100)] 
tests/unit/test_atoi_strtou_noneg.c: Test strtou[l]l_noneg()

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/, src/: Replace strtou[l]l(3) by strtou[l]l_noneg()
Alejandro Colomar [Mon, 11 Dec 2023 00:06:05 +0000 (01:06 +0100)] 
lib/, src/: Replace strtou[l]l(3) by strtou[l]l_noneg()

strtou[l]l(3) silently converts negative numbers into positive.  This
behavior is wrong: a negative value should be parsed as a negative
value, which would underflow unsigned (long) long, and so would return
the smallest possible value, 0, and set errno to ERANGE to report an
error.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/atoi/strtou_noneg.[ch]: Add strtou[l]l_noneg()
Alejandro Colomar [Sun, 10 Dec 2023 23:51:05 +0000 (00:51 +0100)] 
lib/atoi/strtou_noneg.[ch]: Add strtou[l]l_noneg()

These functions reject negative numbers, instead of silently converting
them into unsigned, which strtou[l]l(3) do.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/sulogin.c: Free previously allocated memory
Samanta Navarro [Thu, 18 Jan 2024 11:53:41 +0000 (11:53 +0000)] 
src/sulogin.c: Free previously allocated memory

The sulogin program calls pw_entry in a loop while incorrect root
passwords are entered.

Free the previously allocated memory to avoid memory exhaustion.

Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 months agosrc/sulogin.c: Remove 'static' from local variable, but keep initialization
Alejandro Colomar [Wed, 17 Jan 2024 16:08:50 +0000 (17:08 +0100)] 
src/sulogin.c: Remove 'static' from local variable, but keep initialization

We don't need 'static', because it's in main(), which is only called
once.  However, we will need initialization as if it were 'static', so
use ={} to initialize it.  This will allow freeing the pointers before
they have been allocated.

Cc: Samanta Navarro <ferivoz@riseup.net>
Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/sulogin.c: Remove 'static' from a temporary variable
Alejandro Colomar [Wed, 17 Jan 2024 16:02:27 +0000 (17:02 +0100)] 
src/sulogin.c: Remove 'static' from a temporary variable

There's no need to keep 'pass' in .bss:

$ grep -nC3 '\<pass\>' src/sulogin.c
58-/*ARGSUSED*/ int main (int argc, char **argv)
59-{
60- int     err = 0;
61: char    pass[BUFSIZ];
62- char    **envp = environ;
63- TERMIO  termio;
64-#ifndef USE_PAM
--
166-#endif
167- exit (0);
168- }
169: STRTCPY(pass, cp);
170- erase_pass (cp);
171-
172: if (valid (pass, &pwent)) { /* check encrypted passwords ... */
173- break; /* ... encrypted passwords matched */
174- }
175-
176- sleep (2);
177- (void) puts (_("Login incorrect"));
178- }
179: MEMZERO(pass);
180- (void) alarm (0);
181- (void) signal (SIGALRM, SIG_DFL);
182- environ = newenvp; /* make new environment active */

Cc: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/sulogin.c: Align local variables
Alejandro Colomar [Wed, 17 Jan 2024 16:00:48 +0000 (17:00 +0100)] 
src/sulogin.c: Align local variables

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/sulogin.c: Make static variables local to main()
Alejandro Colomar [Wed, 17 Jan 2024 15:57:02 +0000 (16:57 +0100)] 
src/sulogin.c: Make static variables local to main()

Those variables are only used in main().  Restrict their scope.
Keep them static (.bss), as changing that may be dangerous.

Suggested-by: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agosrc/sulogin.c: pw_entry(): Don't else after return
Alejandro Colomar [Wed, 17 Jan 2024 15:52:12 +0000 (16:52 +0100)] 
src/sulogin.c: pw_entry(): Don't else after return

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/, src/, po/: pw_entry(): Move function to src/sulogin.c
Alejandro Colomar [Wed, 17 Jan 2024 15:48:53 +0000 (16:48 +0100)] 
lib/, src/, po/: pw_entry(): Move function to src/sulogin.c

That's the only file where it's called, and it's a delicate function.
Reduce the chances that other files call it.

Link: <https://github.com/shadow-maint/shadow/pull/908>
Suggested-by: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/, tests/: addsl(): Add addsl(), a variadic macro
Alejandro Colomar [Sat, 6 Jan 2024 01:17:38 +0000 (02:17 +0100)] 
lib/, tests/: addsl(): Add addsl(), a variadic macro

Add a variadic macro addsl() that accepts an arbitrary number of
addends, instead of having specific versions like addsl2() or addsl3().

It is internally implemented by the addslN() function, which itself
calls addsl2().  addsl3() is now obsolete and thus removed.

Code should just call addsl().

Link: <https://github.com/shadow-maint/shadow/pull/882#discussion_r1437155212>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/, tests/: addsl2(): Rename addsl() to addsl2()
Alejandro Colomar [Sat, 6 Jan 2024 01:25:21 +0000 (02:25 +0100)] 
lib/, tests/: addsl2(): Rename addsl() to addsl2()

This is for consistency with addsl3(), and in preparation for the
following commit, which will unify the interface into a single addsl()
macro.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/defines.h: Don't wrap #undef in #ifdef
Alejandro Colomar [Fri, 12 Jan 2024 00:58:28 +0000 (01:58 +0100)] 
lib/defines.h: Don't wrap #undef in #ifdef

ISO C guarantees that #undef is a no-op if there is no such macro.

C11::6.10.3.5p2:
> A preprocessing directive of the form
>
>       # undef identifier new-line
>
> causes the specified identifier no longer to be defined as a macro
> name.  It is ignored if the specified identifier is not currently
> defined as a macro name.

Link: <http://port70.net/~nsz/c/c11/n1570.html#6.10.3.5p2>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/idmapping.c: write_mapping(): Fixx off-by-one bug
Alejandro Colomar [Thu, 11 Jan 2024 18:12:24 +0000 (19:12 +0100)] 
lib/idmapping.c: write_mapping(): Fixx off-by-one bug

Link: <https://github.com/shadow-maint/shadow/commit/673c2a6f9aa6c69588f4c1be08589b8d3475a520#r136830993>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/: Use 'restrict' alongside [[gnu::access()]]
Alejandro Colomar [Sat, 6 Jan 2024 12:41:16 +0000 (13:41 +0100)] 
lib/: Use 'restrict' alongside [[gnu::access()]]

const + restrict imply read_only.

Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/: Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 13:21:24 +0000 (14:21 +0100)] 
lib/: Use ATTR_ACCESS() instead of /*@out@*/

The compiler seems to ignore the attribute in a function pointer,
though.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/: get[u]long(): Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 13:16:31 +0000 (14:16 +0100)] 
lib/: get[u]long(): Use ATTR_ACCESS() instead of /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/: Remove incorrect /*@out@*/ comment from functions that read the pointee
Alejandro Colomar [Mon, 11 Dec 2023 13:01:38 +0000 (14:01 +0100)] 
lib/: Remove incorrect /*@out@*/ comment from functions that read the pointee

These functions (e.g., gr_free()), explicitly dereference the pointer
and read the pointee.

The /@out@/ comment, which is (almost) analogous to the
[[gnu::access(write_only, ...)]] attribute, means that the pointee can
be uninitialized, since it won't read it.  There's a difference between
/@out@/ and the GCC attribute: the attribute doesn't require that the
call writes to the pointee, while /@out@/ requires that the pointee be
fully initialized after the call, so it _must_ write to it.

A guess of why it was used is that these functions are similar to
free(3), which does not read the memory it frees, and so one would
assume that if it doesn't read, write_only (or equivalents) are good.
That's wrong in several ways:

-  free(3) does not read _nor_ write to the memory, so it would
   be slightly inappropriate to use write_only with it.  It wouldn't be
   "wrong", but [[gnu::access(none, ...)]] would be more appropriate.

-  Because /@out@/ requires that the call writes to the pointee, it
   would be wrong to use it in free(3), which doesn't write to the
   pointee.

-  Our functions are similar to free(3) conceptually, but they don't
   behave like free(3), since they do read the memory (pointee) (and
   also write to it), and thus they're actually read_write.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/: Remove /*@out@*/ comments in return type
Alejandro Colomar [Mon, 11 Dec 2023 12:48:35 +0000 (13:48 +0100)] 
lib/: Remove /*@out@*/ comments in return type

/*@out@*/ makes no sense in the return of a function, AFAICS.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/: fgetsx(): Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 13:10:38 +0000 (14:10 +0100)] 
lib/: fgetsx(): Use ATTR_ACCESS() instead of /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/: run_command(): Use ATTR_ACCESS() instead of /*@out@*/
Alejandro Colomar [Mon, 11 Dec 2023 12:36:53 +0000 (13:36 +0100)] 
lib/: run_command(): Use ATTR_ACCESS() instead of /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/attr.h: Add ATTR_ACCESS()
Alejandro Colomar [Mon, 11 Dec 2023 12:32:12 +0000 (13:32 +0100)] 
lib/attr.h: Add ATTR_ACCESS()

This will replace the existing comments like /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
4 months agolib/sgetgrent.c: fix null pointer dereference
Samanta Navarro [Fri, 12 Jan 2024 11:49:27 +0000 (11:49 +0000)] 
lib/sgetgrent.c: fix null pointer dereference

If reallocation fails in function list, then reset the size to 0 again.
Without the reset, the next call assumes that `members` points to
a memory location with reserved space.

Also use size_t instead of int for size to prevent signed integer
overflows. The length of group lines is not limited.

Fixes 45c0003e53ab671c63dcd530fd9f3245d3b29e76 (4.14 release series)

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
5 months agolib/: get_pid(): Use the usual -1 as an error code
Alejandro Colomar [Sat, 2 Dec 2023 00:21:01 +0000 (01:21 +0100)] 
lib/: get_pid(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: get_uid(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 23:27:04 +0000 (00:27 +0100)] 
lib/, src/: get_uid(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: get_gid(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 23:23:06 +0000 (00:23 +0100)] 
lib/, src/: get_gid(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: getrange(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 22:10:06 +0000 (23:10 +0100)] 
lib/, src/: getrange(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/getrange.c: Reduce indentation
Alejandro Colomar [Sat, 30 Dec 2023 13:08:13 +0000 (14:08 +0100)] 
lib/getrange.c: Reduce indentation

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: getulong(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 19:33:20 +0000 (20:33 +0100)] 
lib/, src/: getulong(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: getlong(): Use the usual -1 as an error code
Alejandro Colomar [Fri, 1 Dec 2023 19:23:48 +0000 (20:23 +0100)] 
lib/, src/: getlong(): Use the usual -1 as an error code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agotests/unit/test_adds.c: Test addsl() and addsl3()
Alejandro Colomar [Wed, 20 Dec 2023 21:09:36 +0000 (22:09 +0100)] 
tests/unit/test_adds.c: Test addsl() and addsl3()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/adds.[ch]: Add addsl() and addsl3()
Alejandro Colomar [Wed, 20 Dec 2023 20:43:03 +0000 (21:43 +0100)] 
lib/adds.[ch]: Add addsl() and addsl3()

These functions add 2 or 3 longs, saturating to LONG_{MIN,MAX} instead
of overflowing.

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/: Fix long/time_t handling
Tobias Stoeckmann [Thu, 14 Dec 2023 11:11:28 +0000 (12:11 +0100)] 
src/: Fix long/time_t handling

Special care has to be taken for 32 bit systems with a 64 bit time_t,
since their long data type is still 32 bit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/passwd.c: Add overflow check
Tobias Stoeckmann [Wed, 20 Dec 2023 19:48:54 +0000 (20:48 +0100)] 
src/passwd.c: Add overflow check

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agosrc/passwd.c: Switch to day precision
Tobias Stoeckmann [Thu, 14 Dec 2023 10:54:00 +0000 (11:54 +0100)] 
src/passwd.c: Switch to day precision

The size of time_t varies across systems, but since data type long is
more than enough to calculate with days (precision of shadow file),
use it instead.

Just in case a shadow file contains huge values, check for a possible
signed integer overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agolib/, src/: Remove SCALE definition
Tobias Stoeckmann [Wed, 13 Dec 2023 20:25:51 +0000 (20:25 +0000)] 
lib/, src/: Remove SCALE definition

SCALE is always DAY (and has to be always DAY), so replace it with DAY
in source code and remove unneeded calculations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 months agoman/: add BCRYPT and YESCRYPT information
Tobias Stoeckmann [Tue, 19 Dec 2023 16:39:54 +0000 (17:39 +0100)] 
man/: add BCRYPT and YESCRYPT information

The BCRYPT and YESCRYPT relevant items should be described in
manual pages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 months agoman/: CONSOLE_GROUPS is only used without PAM
Tobias Stoeckmann [Wed, 20 Dec 2023 17:55:09 +0000 (18:55 +0100)] 
man/: CONSOLE_GROUPS is only used without PAM

CONSOLE_GROUPS is only used if PAM is not in use, just like
CONSOLE itself.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 months agoman/: ENV_HZ is only used without PAM
Tobias Stoeckmann [Wed, 20 Dec 2023 11:27:24 +0000 (12:27 +0100)] 
man/: ENV_HZ is only used without PAM

Contrary to the comment in ENV_HZ.xml, ENV_HZ is not even used in
sulogin (anymore) if PAM support is enabled.

Skip paragraphs of sulogin if PAM support is enabled, since they would
be empty now.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>