]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
5 weeks agoconfigure.ac: release 4.15.1 4.15.x 4.15.1
Serge Hallyn [Sat, 23 Mar 2024 23:33:45 +0000 (18:33 -0500)] 
configure.ac: release 4.15.1

Signed-off-by: Serge Hallyn <serge@hallyn.com>
5 weeks agosrc/login.c: Use localtime_r(3) instead of localtime(3)
Alejandro Colomar [Mon, 29 Jan 2024 22:35:43 +0000 (23:35 +0100)] 
src/login.c: Use localtime_r(3) instead of localtime(3)

This silences a CodeQL warning.  We don't care about reentrancy, but
after this patch we don't need to break a long line, so that's a win.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 weeks agolib/, src/: Use STRFTIME() instead of its pattern
Alejandro Colomar [Mon, 29 Jan 2024 12:50:33 +0000 (13:50 +0100)] 
lib/, src/: Use STRFTIME() instead of its pattern

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 weeks agolib/string/strftime.[ch]: STRFTIME(): Add macro
Alejandro Colomar [Mon, 29 Jan 2024 12:43:07 +0000 (13:43 +0100)] 
lib/string/strftime.[ch]: STRFTIME(): Add macro

This macro makes sure that the first argument is an array, and
calculates its size.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
5 weeks agoman/Makefile.am: ship config.xml
Serge Hallyn [Fri, 15 Mar 2024 23:50:04 +0000 (18:50 -0500)] 
man/Makefile.am: ship config.xml

Other man/*.xml's import it, so they need it shipped as well.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
5 weeks agoman/po/Makefile.in: avoid unnecessary changes to git indexed files
Serge Hallyn [Thu, 14 Mar 2024 23:53:49 +0000 (18:53 -0500)] 
man/po/Makefile.in: avoid unnecessary changes to git indexed files

Keep pot creation date out of our po files when we compare them.
Otherwise, we always think they need to be updated.

We prepend a line '# To re-generate, ....' to the shadow-man-pages.pot
file.  Do that before we compare the new candidate, because right
now our comparison to see if we've made changes always thinks we have.

Put some of the tempfiles in a mktemp -d'd directory, which we remove when
all's done.  This keeps the working tree cleaner.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
5 weeks agoupdate translations
Serge Hallyn [Thu, 14 Mar 2024 23:34:16 +0000 (18:34 -0500)] 
update translations

Update .po and .pot files to reflect some changes in print
statements.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
5 weeks agoMakefile.am: clean some tempfiles
Serge Hallyn [Wed, 13 Mar 2024 20:32:26 +0000 (15:32 -0500)] 
Makefile.am: clean some tempfiles

Add some temporary files to CLEANFILES

Put test-driver in .gitignore

Signed-off-by: Serge Hallyn <serge@hallyn.com>
6 weeks agogetdef: avoid spurious error messages about unknown configuration options
Serge Hallyn [Wed, 20 Mar 2024 22:39:46 +0000 (17:39 -0500)] 
getdef: avoid spurious error messages about unknown configuration options

def_find can return NULL for unset, not just unknown, config options.  So
move the decision of whether to log an error message about an unknown config
option back into def_find, which knows the difference.  Only putdef_str()
will pass a char* srcfile to def_find, so only calls from putdef_str will
cause the message, which was the original intent of fa68441bc4be8.

closes #967

fixes: fa68441bc4be8 ("Improve the login.defs unknown item error message")
Signed-off-by: Serge Hallyn <serge@hallyn.com>
6 weeks agolib/copydir:copy_entry(): use temporary stat buffer
Enrico Scholz [Mon, 18 Mar 2024 11:14:21 +0000 (12:14 +0100)] 
lib/copydir:copy_entry(): use temporary stat buffer

There are no guarantees that fstatat() does not clobber the stat
buffer on errors.

Use a temporary buffer so that the following code sees correct
attributes of the source entry.

Issue #973

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
6 weeks agoFix wrong french translation
Antoine Roux [Tue, 19 Mar 2024 15:49:45 +0000 (16:49 +0100)] 
Fix wrong french translation

32 characters were wrongly translated to 16 in french translation file

6 weeks agogitignore: add a few more generated files to be ignored
Eli Schwartz [Sun, 17 Mar 2024 22:40:21 +0000 (18:40 -0400)] 
gitignore: add a few more generated files to be ignored

before this, the following untracked files showed up in `git status`:

lib/atoi/.dirstamp
lib/string/.dirstamp
lib/time/.dirstamp
man/da/login.defs.d
man/da/messages.mo
man/de/login.defs.d
man/de/messages.mo
man/fr/login.defs.d
man/fr/messages.mo
man/it/login.defs.d
man/it/messages.mo
man/pl/login.defs.d
man/pl/messages.mo
man/ru/login.defs.d
man/ru/messages.mo
man/sv/login.defs.d
man/sv/messages.mo
man/uk/login.defs.d
man/uk/messages.mo
man/zh_CN/login.defs.d
man/zh_CN/messages.mo
test-driver

Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/pam_pass_non_interactive.c: use strzero/free
Samanta Navarro [Tue, 23 Jan 2024 12:04:05 +0000 (12:04 +0000)] 
lib/pam_pass_non_interactive.c: use strzero/free

The combination of bzero and free could be optimized away.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
7 weeks agolib/list.c: is_on_list(): Call strsep(3) instead of open-coding it
Alejandro Colomar [Mon, 15 Jan 2024 18:07:28 +0000 (19:07 +0100)] 
lib/list.c: is_on_list(): Call strsep(3) instead of open-coding it

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/list.c: is_on_list(): Move break condition to loop controlling expression
Alejandro Colomar [Wed, 17 Jan 2024 01:50:42 +0000 (02:50 +0100)] 
lib/list.c: is_on_list(): Move break condition to loop controlling expression

This change executes `i++` one more time before breaking, so we need to
update the `i+1` after the loop to just `i`.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/list.c: is_on_list(): Move code out of loop
Alejandro Colomar [Wed, 17 Jan 2024 01:46:21 +0000 (02:46 +0100)] 
lib/list.c: is_on_list(): Move code out of loop

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/list.c: is_on_list(): Remove unnecessary use of temporary variable
Alejandro Colomar [Mon, 15 Jan 2024 18:03:07 +0000 (19:03 +0100)] 
lib/list.c: is_on_list(): Remove unnecessary use of temporary variable

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/sgetspent.c: sgetspent(): Explicitly use an empty string literal
Alejandro Colomar [Mon, 15 Jan 2024 17:23:17 +0000 (18:23 +0100)] 
lib/sgetspent.c: sgetspent(): Explicitly use an empty string literal

cp can only be an empty string literal in that conditional.  Use a
string literal to be more explicit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/sgetspent.c: sgetspent(): Use NULL instead of 0 to mean a null pointer constant
Alejandro Colomar [Mon, 15 Jan 2024 17:18:24 +0000 (18:18 +0100)] 
lib/sgetspent.c: sgetspent(): Use NULL instead of 0 to mean a null pointer constant

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/port.c: getportent(): Call strpbrk(3) instead of open-coding it
Alejandro Colomar [Mon, 15 Jan 2024 16:18:33 +0000 (17:18 +0100)] 
lib/port.c: getportent(): Call strpbrk(3) instead of open-coding it

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/: Call strsep(3) instead of open-coding it
Alejandro Colomar [Mon, 15 Jan 2024 15:28:11 +0000 (16:28 +0100)] 
lib/: Call strsep(3) instead of open-coding it

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/: Call strchrnul(3) instead of open-coding it
Alejandro Colomar [Mon, 15 Jan 2024 15:20:03 +0000 (16:20 +0100)] 
lib/: Call strchrnul(3) instead of open-coding it

Performance tests made in 2007 are obsolete.  We should assume libc is
reasonably fast today (otherwise, report a bug to libc).

$ git blame -- lib/sgetgrent.c | grep strchr
45c6603cc (nekral-guest      2007-10-07 11:44:02 +0000  30)  * WARNING: I profiled this once with and without strchr() calls
6f88bcf58 (nekral-guest      2008-05-26 08:31:14 +0000  97)  cp = strchr (cp, ':');

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/, src/: Call gmtime_r(3) instead of gmtime(3)
Alejandro Colomar [Mon, 29 Jan 2024 14:53:34 +0000 (15:53 +0100)] 
lib/, src/: Call gmtime_r(3) instead of gmtime(3)

It's trivial to do the change, and it removes a CodeQL warning.
We don't need to be reentrant, but it doesn't hurt either.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/time/day_to_str.[ch]: day_to_str(): Accept a day instead of a date, and rename...
Alejandro Colomar [Mon, 29 Jan 2024 14:34:20 +0000 (15:34 +0100)] 
lib/time/day_to_str.[ch]: day_to_str(): Accept a day instead of a date, and rename function

It was always being called with 'day * DAY', so do that internally and
simplify.  This grabs some code from print_day_as_date().

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agosrc/passwd.c: print_status(): Fix typo (bogus use of the comma operator)
Alejandro Colomar [Mon, 29 Jan 2024 14:20:22 +0000 (15:20 +0100)] 
src/passwd.c: print_status(): Fix typo (bogus use of the comma operator)

Amazing that this triggered no warnings at all.

Fixes: 355ad6a9e089 ("Have a single definition of date_to_str()")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agosrc/: Use DAY_TO_STR() instead of its pattern
Alejandro Colomar [Mon, 29 Jan 2024 14:19:44 +0000 (15:19 +0100)] 
src/: Use DAY_TO_STR() instead of its pattern

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/time/day_to_str.h: DAY_TO_STR(): Add macro
Alejandro Colomar [Mon, 29 Jan 2024 14:14:29 +0000 (15:14 +0100)] 
lib/time/day_to_str.h: DAY_TO_STR(): Add macro

This macro ensures that the buffer is an array, and calculates the size.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/, src/, po/: date_to_str(): Move function to header, and make inline
Alejandro Colomar [Mon, 29 Jan 2024 14:11:04 +0000 (15:11 +0100)] 
lib/, src/, po/: date_to_str(): Move function to header, and make inline

BTW, there's no translatable string in there.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agosrc/sulogin.c: Invert logic to reduce indentation
Alejandro Colomar [Thu, 18 Jan 2024 10:15:17 +0000 (11:15 +0100)] 
src/sulogin.c: Invert logic to reduce indentation

Also, it was checking for >=0 for success, but since that code is for
opening a different tty as stdin, that was bogus.  But since it's
guaranteed to be either 0 or -1, this commit doesn't add any code to
make sure it's 0 (i.e., we could say !=0 instead of ==-1).  That's more
appropriate for a different commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/, src/: Use int main(void) where appropriate
Alejandro Colomar [Thu, 18 Jan 2024 00:30:23 +0000 (01:30 +0100)] 
lib/, src/: Use int main(void) where appropriate

Remove /*ARGSUSED*/ comments.  Instead, use appropriate declarators for
main().  ISO C allows using int main(void) if the parameters are going
to be unused.

Also, do some cosmetic changes in the uses of argc and argv, to show
where they are used.

And use *argv[], instead of **argv.  Array notation is friendlier, IMO.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/: Clean up after previous removal of dead code
Alejandro Colomar [Wed, 17 Jan 2024 13:31:05 +0000 (14:31 +0100)] 
lib/: Clean up after previous removal of dead code

Just cosmetic changes.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/, src/: Remove all code wrapped in defined(USE_NIS)
Alejandro Colomar [Wed, 17 Jan 2024 13:16:27 +0000 (14:16 +0100)] 
lib/, src/: Remove all code wrapped in defined(USE_NIS)

I don't find any way to enable USE_NIS, so it looks like it's all
dead code.  Bury it.

Closes: <https://github.com/shadow-maint/shadow/issues/909>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agosrc/passwd.c: Don't print the program name twice in a log entry
Alejandro Colomar [Thu, 7 Mar 2024 23:33:19 +0000 (00:33 +0100)] 
src/passwd.c: Don't print the program name twice in a log entry

OPENLOG() already sets the program name as the prefix.

This resulted in entries like:

$ journalctl 2>/dev/null | grep passwd
Mar 03 01:09:47 debian passwd[140744]: passwd: can't view or modify password information for root

Fixes: 8e167d28afd6 ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agoNoting copy_symlink behaviour
ed neville [Thu, 14 Mar 2024 19:38:15 +0000 (19:38 +0000)] 
Noting copy_symlink behaviour

Mention that symlinks are modified when they prefix the skel directory.

Closes #933

7 weeks agoshare/containers/, .github/workflows/: Don't make(1) twice
Alejandro Colomar [Tue, 13 Feb 2024 15:54:33 +0000 (16:54 +0100)] 
share/containers/, .github/workflows/: Don't make(1) twice

It was being done so that the second one prints errors without races.
However, the same thing can be achieved by passing -Orecurse to make(1).

And this makes the logs even more readable, since there's no racy output
at all.

Fixes: 97f79e3b2715 ("CI: Make build logs more readable")
Link: <https://github.com/shadow-maint/shadow/pull/702>
Link: <https://github.com/nginx/unit/pull/1123>
Acked-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Andrew Clayton <a.clayton@nginx.com>
Cc: Konstantin Pavlov <thresh@nginx.com>
Cc: Dylan Arbour <https://github.com/arbourd>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/idmapping.c: get_map_ranges(): Merge two input checks into a simpler one
Alejandro Colomar [Thu, 11 Jan 2024 17:28:07 +0000 (18:28 +0100)] 
lib/idmapping.c: get_map_ranges(): Merge two input checks into a simpler one

Previously, we were performing the following two checks:

-       if (ranges != ((argc + 2) / 3)) {
-       if ((ranges * 3) > argc) {

Let's draw a table of the possible input that would pass the first check:

argc: 0 1 2 3 4 5 6 7 8 9
rng: 0 1 1 1 2 2 2 3 3 3
a+2/3*3:0 3 3 3 6 6 6 9 9 9 <-- this is  roundup(argc, 3);
a+2/3: 0 1 1 1 2 2 2 3 3 3 <-- this is  roundup(argc, 3) / 3;
rng*3: 0 3 3 3 6 6 6 9 9 9

From those, let's extract those that would also pass the second check:

argc: 0     3     6     9
rng: 0     1     2     3
rng*3: 0     3     6     9

We can see that there's a simple check for this input:

+       if (ranges * 3 != argc) {

As a sanity check, let's draw a table of the acceptable input with that
check:

rng: 0     1     2     3
rng*3: 0     3     6     9
argc: 0     3     6     9

Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agoAdding checks for fd omission
Skyler Ferrante [Fri, 8 Mar 2024 17:53:21 +0000 (12:53 -0500)] 
Adding checks for fd omission

Adding function check_fds to new file fd.c. The function check_fds
should be called in every setuid/setgid program.

Co-developed-by: Alejandro Colomar <alx@kernel.org>
7 weeks agotests/unit/test_zustr2stp.c: Test ZUSTR2STP()
Alejandro Colomar [Mon, 29 Jan 2024 23:22:33 +0000 (00:22 +0100)] 
tests/unit/test_zustr2stp.c: Test ZUSTR2STP()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
7 weeks agolib/string/zustr2stp.[ch]: Remove zustr2stp(); keep ZUSTR2STP()
Alejandro Colomar [Sun, 3 Dec 2023 20:43:07 +0000 (21:43 +0100)] 
lib/string/zustr2stp.[ch]: Remove zustr2stp(); keep ZUSTR2STP()

The function should never be used; it's always used via its wrapper
macro.  To simplify, and reduce chances of confusion: remove the
function, and implement the macro directly in terms of
stpcpy(mempcpy(strnlen())).

Update the documentation, and improve the example, which was rather
confusing.

Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 weeks agoconfigure.ac: Release 4.15.0 4.15.0
Serge Hallyn [Fri, 8 Mar 2024 22:04:59 +0000 (16:04 -0600)] 
configure.ac: Release 4.15.0

Signed-off-by: Serge Hallyn <serge@hallyn.com>
8 weeks agosrc/vipw.c: Use string literals to initialize 'Prog'
Alejandro Colomar [Thu, 7 Mar 2024 22:38:48 +0000 (23:38 +0100)] 
src/vipw.c: Use string literals to initialize 'Prog'

This avoids using argv[0], which is controlled by the user,
and might inject arbitrary text in stderr and the logs.

Link: <https://github.com/shadow-maint/shadow/issues/959>
Link: <https://github.com/shadow-maint/shadow/pull/960>
Cc: "Skyler Ferrante (RIT Student)" <sjf5462@rit.edu>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Karel Zak <kzak@redhat.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Christian Brauner <christian@brauner.io>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
8 weeks 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>
8 weeks 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.

2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 months agoUpdate Georgian translation
NorwayFun [Thu, 8 Feb 2024 05:15:03 +0000 (06:15 +0100)] 
Update Georgian translation

2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
2 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>
3 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>