]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
13 months agosrc/useradd.c: tallylog_reset(): Use Basename() instead of its pattern
Alejandro Colomar [Sun, 12 May 2024 22:13:41 +0000 (00:13 +0200)] 
src/useradd.c: tallylog_reset(): Use Basename() instead of its pattern

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

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

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

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

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

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

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

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

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

See time(2):

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

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

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

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/shadow.c: my_sgetspent(): Clarify that we're assigning an empty string
Alejandro Colomar [Mon, 20 May 2024 14:22:56 +0000 (16:22 +0200)] 
lib/shadow.c: my_sgetspent(): Clarify that we're assigning an empty string

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, src/: Reduce scope of local variables
Alejandro Colomar [Mon, 13 May 2024 21:24:38 +0000 (23:24 +0200)] 
lib/, src/: Reduce scope of local variables

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/login.c: Remove dead code
Alejandro Colomar [Mon, 13 May 2024 12:31:01 +0000 (14:31 +0200)] 
src/login.c: Remove dead code

The functions that set these strings --do_rlogin() and login_prompt()--
make sure to terminate them with a NUL.

Fixes: 3704745289f5 ("* lib/defines.h: Define USER_NAME_MAX_LENGTH, based on utmp and [...]")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/logoutd.c: Remove unused variable
Alejandro Colomar [Mon, 13 May 2024 21:18:19 +0000 (23:18 +0200)] 
src/logoutd.c: Remove unused variable

wait(2) accepts NULL if the status won't be read.  Simplify.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/su.c: save_caller_context(): Remove unused parameter
Alejandro Colomar [Mon, 20 May 2024 15:51:27 +0000 (17:51 +0200)] 
src/su.c: save_caller_context(): Remove unused parameter

Fixes: e6c2e4393784 ("Hardcoding Prog to known value")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/strcpy/, lib/, src/, tests/: Move all copying APIs to a subdirectory
Alejandro Colomar [Thu, 27 Jun 2024 09:48:16 +0000 (11:48 +0200)] 
lib/string/strcpy/, lib/, src/, tests/: Move all copying APIs to a subdirectory

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory
Alejandro Colomar [Thu, 27 Jun 2024 09:29:56 +0000 (11:29 +0200)] 
lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory

And have a separate file for each pair of APIs.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/get_subid_owners.c: Use uid_t for holding UIDs (and GIDs)
Alejandro Colomar [Sat, 29 Jun 2024 17:35:14 +0000 (19:35 +0200)] 
src/get_subid_owners.c: Use uid_t for holding UIDs (and GIDs)

Suggested-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/usermod.c: Fix const correctness
Alejandro Colomar [Sun, 5 May 2024 22:25:41 +0000 (00:25 +0200)] 
src/usermod.c: Fix const correctness

Now that we use liba2i's const-generic macros, we can (and must) use a
'const char **' endp where the input string is 'const char *'.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
Alejandro Colomar [Tue, 9 Jan 2024 17:02:24 +0000 (18:02 +0100)] 
lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
Alejandro Colomar [Tue, 9 Jan 2024 16:46:21 +0000 (17:46 +0100)] 
lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"

Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/get_uid.c: get_uid(): Reimplement in terms of a2i()
Alejandro Colomar [Tue, 9 Jan 2024 16:40:51 +0000 (17:40 +0100)] 
lib/get_uid.c: get_uid(): Reimplement in terms of a2i()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/usermod.c: getulong_range(): Reimplement in terms of a2ul()
Alejandro Colomar [Tue, 9 Jan 2024 16:35:29 +0000 (17:35 +0100)] 
src/usermod.c: getulong_range(): Reimplement in terms of a2ul()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
Alejandro Colomar [Tue, 9 Jan 2024 16:05:43 +0000 (17:05 +0100)] 
lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a...
Alejandro Colomar [Tue, 9 Jan 2024 16:01:52 +0000 (17:01 +0100)] 
lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/: get_pid(): Move function to "atoi/getnum.h"
Alejandro Colomar [Tue, 9 Jan 2024 15:41:24 +0000 (16:41 +0100)] 
lib/: get_pid(): Move function to "atoi/getnum.h"

Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/get_pid.c: get_pid(): Reimplement in terms of a2i()
Alejandro Colomar [Tue, 9 Jan 2024 15:36:08 +0000 (16:36 +0100)] 
lib/get_pid.c: get_pid(): Reimplement in terms of a2i()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/: Don't open-code get_gid()
Alejandro Colomar [Tue, 9 Jan 2024 14:48:55 +0000 (15:48 +0100)] 
lib/: Don't open-code get_gid()

These functions were open-coding get_gid().  Use the actual function.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
Alejandro Colomar [Tue, 9 Jan 2024 14:34:28 +0000 (15:34 +0100)] 
lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"

Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/get_gid.c: get_gid(): Reimplement in terms of a2i()
Alejandro Colomar [Tue, 9 Jan 2024 14:11:25 +0000 (15:11 +0100)] 
lib/get_gid.c: get_gid(): Reimplement in terms of a2i()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agosrc/: Use str2[u]l() instead of atoi(3)
Alejandro Colomar [Sat, 6 Jan 2024 21:12:06 +0000 (22:12 +0100)] 
src/: Use str2[u]l() instead of atoi(3)

atoi(3) easily triggers Undefined Behavior.  Replace it by str2[u]l(),
which are safe from that, and add type safety too.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agotests/unit/test_typetraits.c: Add tests for typetraits.h macros
Alejandro Colomar [Sat, 29 Jun 2024 17:32:32 +0000 (19:32 +0200)] 
tests/unit/test_typetraits.c: Add tests for typetraits.h macros

Suggested-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/typetraits.h: Add macros that give information about a type
Alejandro Colomar [Fri, 1 Dec 2023 23:16:49 +0000 (00:16 +0100)] 
lib/typetraits.h: Add macros that give information about a type

In the case of is_unsigned() and is_signed(), the natural thing would be
to compare to 0:

#define is_unsigned(x)  (((typeof(x)) -1) > 0)
#define is_signed(x)    (((typeof(x)) -1) < 0)

However, that would trigger -Wtype-limits, so we compare against 1,
which silences that, and does the same job.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agotests/run_some: make sure unshared root user can descend build dir
Serge Hallyn [Fri, 28 Jun 2024 15:37:39 +0000 (10:37 -0500)] 
tests/run_some: make sure unshared root user can descend build dir

This was causing errors in my local testing in vms.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
13 months agoMakefile.am: Use 'dist-hook' to clean up <tests/unit/Makefile>
Alejandro Colomar [Fri, 28 Jun 2024 10:21:01 +0000 (12:21 +0200)] 
Makefile.am: Use 'dist-hook' to clean up <tests/unit/Makefile>

Closes: <https://github.com/shadow-maint/shadow/issues/1027>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Co-developed-by: Serge Hallyn <shallyn@cisco.com>
Signed-off-by: Serge Hallyn <shallyn@cisco.com>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agohave_range: open the subid db if needed
Serge Hallyn [Fri, 28 Jun 2024 06:30:40 +0000 (01:30 -0500)] 
have_range: open the subid db if needed

When we run for instance

  check_subid_range ubuntu u 100000 65536

when ubuntu user is defined and has that range, it returns no entries
because the subid db is not opened.  Open it in have_range if needed.

I haven't figured out why this ever worked.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
13 months agolibsubid test makefile: fix a typo
Serge Hallyn [Fri, 28 Jun 2024 04:10:22 +0000 (23:10 -0500)] 
libsubid test makefile: fix a typo

Fix a missing space after the -I path

Signed-off-by: Serge Hallyn <serge@hallyn.com>
13 months agotests/unit/test_xasprintf.c: Fix use of volatile pointer
Alejandro Colomar [Fri, 28 Jun 2024 11:57:35 +0000 (13:57 +0200)] 
tests/unit/test_xasprintf.c: Fix use of volatile pointer

volatile needs to be casted away behind a [[gnu::noipa]] function, to
make that invisible to the compiler.  Otherwise, the compiler can see
that it is being discarded, and is free to abuse Undefined Behavior.

Closes: <https://github.com/shadow-maint/shadow/issues/1028>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Tested-by: Chris Hofstaedtler <zeha@debian.org>
Reviewed-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agotests/unit/test_xasprintf.c: Cosmetic
Alejandro Colomar [Fri, 28 Jun 2024 11:51:36 +0000 (13:51 +0200)] 
tests/unit/test_xasprintf.c: Cosmetic

This is in preparation for the following commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agotests/: Support run_some from exported tarball
Serge Hallyn [Sat, 25 May 2024 13:40:11 +0000 (08:40 -0500)] 
tests/: Support run_some from exported tarball

common/config.sh currently tries to find the top directory by looking
for .git.  There are also many places under tests/ where we use
hard-coded ../../.. to find things like ${TOP_DIR}/lib.

We don't actually ship the tests with 'make dist'.  So we will
be exporting tests/ as a separate tarball.  In particular, I want
to then import this in the debian package.  However, there it will
be under shadow.git/debian/tests, not shadow.git/tests.

To support this, accept the environment variable BUILD_BASE_DIR,
which should point to shadow.git.

An alternative would be to move the tests to their own git
tree.  However, keeping tests in separate git tree tends to
lead to repos getting out of sync.  And we'd still need to accept
something like BUILD_BASE_DIR.

Note there are a lot of tests under run-all, which I'm not converting
as they currently are not being run in CI, so I'm more likely to
break something.

Changelog:
  2024 05 26: Incorporate feedback from alejandro-colomar

Link: <https://salsa.debian.org/debian/shadow/-/merge_requests/21>
Link: <https://salsa.debian.org/debian/shadow/-/merge_requests/22>
Cc: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agolib/csrand.c: Fix the lower part of the domain of csrand_uniform()
Alejandro Colomar [Wed, 19 Jun 2024 17:54:16 +0000 (19:54 +0200)] 
lib/csrand.c: Fix the lower part of the domain of csrand_uniform()

I accidentally broke this code during an un-optimization.  We need to
start from a random value of the width of the limit, that is, 32 bits.

Thanks to Jason for pointing to his similar code in the kernel, which
made me see my mistake.

Fixes: 2a61122b5e8f ("Unoptimize the higher part of the domain of csrand_uniform()")
Closes: <https://github.com/shadow-maint/shadow/issues/1015>
Reported-by: Michael Brunnbauer <https://github.com/michaelbrunnbauer>
Link: <https://git.zx2c4.com/linux-rng/tree/drivers/char/random.c#n535>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Link: <https://github.com/shadow-maint/shadow/pull/638>
Link: <https://github.com/shadow-maint/shadow/issues/634>
Link: <https://github.com/shadow-maint/shadow/pull/624>
Tested-by: Michael Brunnbauer <https://github.com/michaelbrunnbauer>
Reviewed-by: Michael Brunnbauer <https://github.com/michaelbrunnbauer>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
13 months agoconfigure.ac: release 4.16.0 4.16.0
Serge Hallyn [Tue, 18 Jun 2024 21:34:10 +0000 (16:34 -0500)] 
configure.ac: release 4.16.0

Signed-off-by: Serge Hallyn <serge@hallyn.com>
14 months agorelease 4.16.0-rc1 4.16.0-rc1
Serge Hallyn [Thu, 13 Jun 2024 23:09:08 +0000 (18:09 -0500)] 
release 4.16.0-rc1

Signed-off-by: Serge Hallyn <serge@hallyn.com>
14 months agoconfigure.ac: specify tar-pax to avoid 99 char filename limit
Serge Hallyn [Fri, 14 Jun 2024 00:56:48 +0000 (19:56 -0500)] 
configure.ac: specify tar-pax to avoid 99 char filename limit

Signed-off-by: Serge Hallyn <serge@hallyn.com>
14 months agoRemove support for rlogind in login(1), that is, remove the '-r' flag
Alejandro Colomar [Fri, 17 May 2024 23:57:40 +0000 (01:57 +0200)] 
Remove support for rlogind in login(1), that is, remove the '-r' flag

The "quick hack" finally disappeared.  Probably nobody noticed.  ;)
(See the changes in <configure.ac> for the context of this pun.)

Probably everybody uses SSH these days for remote login.  Let's remove
this insecure method.

Closes: <https://github.com/shadow-maint/shadow/issues/992>
Reviewed-by: dkwo <nicolopiazzalunga@gmail.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Sam James <sam@gentoo.org>
Cc: Benedikt Brinkmann <datacobra@thinkbot.de>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolibsubid: Fix code style issues
Daniel Bershatsky [Wed, 12 Jun 2024 19:25:11 +0000 (22:25 +0300)] 
libsubid: Fix code style issues

14 months agolibsubid: Fail on plugin loading if no subid_free provided
Daniel Bershatsky [Wed, 12 Jun 2024 17:07:23 +0000 (20:07 +0300)] 
libsubid: Fail on plugin loading if no subid_free provided

14 months agolibsubid: Apply minor fixes
Daniel Bershatsky [Wed, 12 Jun 2024 14:38:43 +0000 (17:38 +0300)] 
libsubid: Apply minor fixes

14 months agolibsubid: Add routine to free allocated memory
Daniel Bershatsky [Mon, 10 Jun 2024 22:12:45 +0000 (01:12 +0300)] 
libsubid: Add routine to free allocated memory

14 months agolibsubid: Dealocate memory on exit
Daniel Bershatsky [Wed, 12 Jun 2024 16:26:45 +0000 (19:26 +0300)] 
libsubid: Dealocate memory on exit

14 months agosrc/groupmod.c: delete gr_free_members(&grp) to avoid double free
lixinyun [Tue, 28 May 2024 22:53:02 +0000 (06:53 +0800)] 
src/groupmod.c: delete gr_free_members(&grp) to avoid double free

Groupmod -U may cause crashes because of double free. If without -a, the first free of (*ogrp).gr_mem is in gr_free_members(&grp), and then in gr_update without -n or gr_remove with -n.
Considering the minimal impact of modifications on existing code, delete gr_free_members(&grp) to avoid double free.Although this may seem reckless, the second free in two different positions will definitely be triggered, and the following two test cases can be used to illustrate the situation :

[root@localhost src]# ./useradd u1
[root@localhost src]# ./useradd u2
[root@localhost src]# ./useradd u3
[root@localhost src]# ./groupadd -U u1,u2,u3 g1
[root@localhost src]# ./groupmod -n g2 -U u1,u2 g1
Segmentation fault

This case would free (*ogrp).gr_mem in gr_free_members(&grp) due to assignment statements grp = *ogrp, then in if (nflg && (gr_remove (group_name) == 0)), which finally calls gr_free_members(grent) to free (*ogrp).gr_mem again.

[root@localhost src]# ./useradd u1
[root@localhost src]# ./useradd u2
[root@localhost src]# ./useradd u3
[root@localhost src]# ./groupadd -U u1,u2,u3 g1
[root@localhost src]# ./groupmod -U u1,u2 g1
Segmentation fault

The other case would free (*ogrp).gr_mem in gr_free_members(&grp) too, then in if (gr_update (&grp) == 0), which finally calls gr_free_members(grent) too to free (*ogrp).gr_mem again.

So the first free is unnecessary, maybe we can drop it.

Fixes: 342c934a3590 ("add -U option to groupadd and groupmod")
Closes: <https://github.com/shadow-maint/shadow/issues/1013>
Link: <https://github.com/shadow-maint/shadow/pull/1007>
Link: <https://github.com/shadow-maint/shadow/pull/271>
Link: <https://github.com/shadow-maint/shadow/issues/265>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: lixinyun <li.xinyun@h3c.com>
14 months agoman/lastlog: remove wrong use of keyword term
Serge Hallyn [Wed, 5 Jun 2024 13:02:27 +0000 (08:02 -0500)] 
man/lastlog: remove wrong use of keyword term

Per https://tdg.docbook.org/tdg/4.5/term, term is a word being
defined in a varlistentry.  The 'high uid' description is not a
varlistentry, so <term> and </term> show up in the processed
manpage.  See debian Bug#1072297.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
14 months agolib/cast.h: const_cast(): Reimplement with _Generic(3)
Alejandro Colomar [Wed, 15 May 2024 11:19:43 +0000 (13:19 +0200)] 
lib/cast.h: const_cast(): Reimplement with _Generic(3)

This makes it much simpler and portable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agoconfigure: move cmocka library detection
Iker Pedrosa [Mon, 27 May 2024 13:33:45 +0000 (15:33 +0200)] 
configure: move cmocka library detection

`PKG_CONFIG` variable needs to be set for `PKG_CHECK_MODULES` to
succeed, but this wasn't happening in Fedora because the first
appearance of `PKG_CHECK_MODULES` was conditionally skipped because this
distribution is compiled without `libbsd` support. Thus, moving the
cmocka library detection before libbsd fixes the problem.

Suggested-by: Lukas Slebodnik <lslebodn@fedoraproject.org>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
14 months agotests: add the tests/ subdirectory to dist tarball
Serge Hallyn [Tue, 28 May 2024 18:25:49 +0000 (13:25 -0500)] 
tests: add the tests/ subdirectory to dist tarball

This is a first step to helping distributions to use our tests in CI.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
14 months agolib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function
Alejandro Colomar [Tue, 9 Jan 2024 14:00:15 +0000 (15:00 +0100)] 
lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function

All call sites have been replaced by functions from "atoi/a2i.h" and
"atoi/str2i.h" recently.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
Alejandro Colomar [Tue, 9 Jan 2024 13:53:59 +0000 (14:53 +0100)] 
src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()

It is a simpler call, with more type safety.

A consequence of this change is that the program now accepts numbers in
bases 8 and 16.  That's not a problem here, I think.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
Alejandro Colomar [Tue, 9 Jan 2024 13:49:34 +0000 (14:49 +0100)] 
lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function

All call sites were replaced by a2i() recently.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 22:15:06 +0000 (23:15 +0100)] 
lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()

time_t isn't necessarily unsigned (in fact, it's likely to be signed.
Therefore, parse the number as the right type, via a2i(time_t, ...).

Still, reject negative numbers, just to be cautious.  It was done
before (strtoull_noneg()), so it shouldn't be a problem.  (However,
strtoull_noneg() was only introduced recently, and before that we called
strtoull(3), which silently accepted negative values.)

Remove the limitation of ULONG_MAX, which seems arbitrary.  It probably
was written in times where 'time_t' had the same length of 'long', and
this was thus a test that the value didn't overflow 'time_t'.  Such a
test is implicit in the a2i() call, so forget about it.

Unify the error messages into a single one that provides all the info
(except the value of 'fallback').

Link: <https://github.com/shadow-maint/shadow/commit/cb610d54b47ea2fc3da5a1b7c5a71274ada91371#r136407772>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Chris Lamb <lamby@debian.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agoSTABLE.md: 4.15.x is now stable
Tianyu Chen [Wed, 22 May 2024 12:23:04 +0000 (20:23 +0800)] 
STABLE.md: 4.15.x is now stable

14 months agosrc/login.c: main(): Use login_name_max_size()
Alejandro Colomar [Mon, 13 May 2024 23:13:18 +0000 (01:13 +0200)] 
src/login.c: main(): Use login_name_max_size()

Instead of raw sysconf(_SC_LOGIN_NAME_MAX) calls, which was being used
without error handling.

Fixes: 3b7cc053872c ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/chkname.[ch]: login_name_max_size(): Add function
Alejandro Colomar [Fri, 10 May 2024 23:34:05 +0000 (01:34 +0200)] 
lib/chkname.[ch]: login_name_max_size(): Add function

It encapsulates some logic that we may want to reuse elsewhere.

Link: <https://github.com/shadow-maint/shadow/pull/989>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/chkname.[ch]: Fix includes
Alejandro Colomar [Fri, 10 May 2024 23:41:52 +0000 (01:41 +0200)] 
lib/chkname.[ch]: Fix includes

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: update_gshadow(): Add helper function
Alejandro Colomar [Fri, 17 May 2024 00:29:46 +0000 (02:29 +0200)] 
src/usermod.c: update_gshadow(): Add helper function

Keep the while loop in the outer function, and move the iteration code
to this new helper.  This makes it a bit more readable.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: update_group(): Add helper function
Alejandro Colomar [Thu, 16 May 2024 12:12:09 +0000 (14:12 +0200)] 
src/usermod.c: update_group(): Add helper function

Keep the while loop in the outer function, and move the iteration code
to this new helper.  This makes it a bit more readable.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: update_gshadow_file(): Reduce scope of local variable
Alejandro Colomar [Fri, 17 May 2024 00:19:46 +0000 (02:19 +0200)] 
src/usermod.c: update_gshadow_file(): Reduce scope of local variable

After _every_ iteration, 'changed' is always 'false'.  We don't need to
have it outside of the loop.

See:

$ grepc update_gshadow_file . \
| grep -e changed -e goto -e continue -e break -e free_ngrp -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
bool               changed;
changed = false;
while ((sgrp = sgr_next ()) != NULL) {
if (!was_member && !was_admin && !is_member) {
continue;
}
if (was_admin && lflg) {
changed = true;
}
if (was_member) {
if ((!Gflg) || is_member) {
if (lflg) {
changed = true;
}
} else {
changed = true;
}
} else if (is_member) {
changed = true;
}
if (!changed)
goto free_nsgrp;
changed = false;
}
}

This was already true in the commit that introduced the code:

$ git show 45c6603cc:src/usermod.c \
| grepc update_gshadow \
| grep -e changed -e goto -e break -e continue -e '\<if\>' -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
int changed;
changed = 0;
while ((sgrp = sgr_next())) {
 * See if the user was a member of this group
 * See if the user was an administrator of this group
 * See if the user specified this group as one of their
if (!was_member && !was_admin && !is_member)
continue;
if (was_admin && lflg) {
changed = 1;
}
if (was_member && (!Gflg || is_member)) {
if (lflg) {
changed = 1;
}
} else if (was_member && Gflg && !is_member) {
changed = 1;
} else if (!was_member && Gflg && is_member) {
changed = 1;
}
if (!changed)
continue;
changed = 0;
}
}

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: update_group_file(): Reduce scope of local variable
Alejandro Colomar [Thu, 16 May 2024 12:02:54 +0000 (14:02 +0200)] 
src/usermod.c: update_group_file(): Reduce scope of local variable

After _every_ iteration, 'changed' is always 'false'.  We don't need to
have it outside of the loop.

See:

$ grepc update_group_file . \
| grep -e changed -e goto -e continue -e break -e free_ngrp -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
bool                changed;
changed = false;
while ((grp = gr_next ()) != NULL) {
if (!was_member && !is_member) {
continue;
}
if (was_member) {
if ((!Gflg) || is_member) {
if (lflg) {
changed = true;
}
} else {
changed = true;
}
} else if (is_member) {
changed = true;
}
if (!changed)
goto free_ngrp;
changed = false;
free_ngrp:
}
}

This was already true in the commit that introduced the code:

$ git show 45c6603cc:src/usermod.c \
| grepc update_group \
| grep -e changed -e goto -e break -e continue -e '\<if\>' -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
int changed;
changed = 0;
while ((grp = gr_next())) {
 * See if the user specified this group as one of their
if (!was_member && !is_member)
continue;
if (was_member && (!Gflg || is_member)) {
if (lflg) {
changed = 1;
}
} else if (was_member && Gflg && !is_member) {
changed = 1;
} else if (!was_member && Gflg && is_member) {
changed = 1;
}
if (!changed)
continue;
changed = 0;
}
}

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: update_gshadow_file(): Fix RESOURCE_LEAK (CWE-772)
Alejandro Colomar [Fri, 17 May 2024 00:15:15 +0000 (02:15 +0200)] 
src/usermod.c: update_gshadow_file(): Fix RESOURCE_LEAK (CWE-772)

Report:
> shadow-4.15.0/src/usermod.c:864:3: alloc_fn: Storage is returned from allocation function "__sgr_dup".
> shadow-4.15.0/src/usermod.c:864:3: var_assign: Assigning: "nsgrp" = storage returned from "__sgr_dup(sgrp)".
> shadow-4.15.0/src/usermod.c:964:1: leaked_storage: Variable "nsgrp" going out of scope leaks the storage it points to.
> 962|                   free (nsgrp);
> 963|           }
> 964|-> }
> 965|   #endif                                /* SHADOWGRP */
> 966|

Link: https://issues.redhat.com/browse/RHEL-35383
Reported-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: update_group_file(): Fix RESOURCE_LEAK (CWE-772)
Alejandro Colomar [Thu, 16 May 2024 11:54:06 +0000 (13:54 +0200)] 
src/usermod.c: update_group_file(): Fix RESOURCE_LEAK (CWE-772)

Report:
> shadow-4.15.0/src/usermod.c:734:3: alloc_fn: Storage is returned from allocation function "__gr_dup".
> shadow-4.15.0/src/usermod.c:734:3: var_assign: Assigning: "ngrp" = storage returned from "__gr_dup(grp)".
> shadow-4.15.0/src/usermod.c:815:1: leaked_storage: Variable "ngrp" going out of scope leaks the storage it points to.
> 813|                   gr_free(ngrp);
> 814|           }
> 815|-> }
> 816|
> 817|   #ifdef SHADOWGRP

Link: https://issues.redhat.com/browse/RHEL-35383
Reported-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: Rename update_gshadow() => update_gshadow_file()
Alejandro Colomar [Fri, 17 May 2024 00:11:22 +0000 (02:11 +0200)] 
src/usermod.c: Rename update_gshadow() => update_gshadow_file()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: Rename update_group() => update_group_file()
Alejandro Colomar [Thu, 16 May 2024 11:49:34 +0000 (13:49 +0200)] 
src/usermod.c: Rename update_group() => update_group_file()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/usermod.c: Reduce scope of local variables
Alejandro Colomar [Thu, 16 May 2024 11:52:15 +0000 (13:52 +0200)] 
src/usermod.c: Reduce scope of local variables

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/useradd.c: set_defaults(): Fix FILE* leak
Alejandro Colomar [Fri, 17 May 2024 11:52:07 +0000 (13:52 +0200)] 
src/useradd.c: set_defaults(): Fix FILE* leak

Report:
> shadow-4.15.0/src/useradd.c:575:2: alloc_fn: Storage is returned from allocation function "fdopen".
> shadow-4.15.0/src/useradd.c:575:2: var_assign: Assigning: "ofp" = storage returned from "fdopen(ofd, "w")".
> shadow-4.15.0/src/useradd.c:734:2: leaked_storage: Variable "ofp" going out of scope leaks the storage it points to.
> 732|           }
> 733|
> 734|->         return ret;
> 735|   }
> 736|

Link: <https://issues.redhat.com/browse/RHEL-35383>
Reported-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/useradd.c: Add fmkstemp() to fix file-descriptor leak
Alejandro Colomar [Fri, 17 May 2024 11:40:58 +0000 (13:40 +0200)] 
src/useradd.c: Add fmkstemp() to fix file-descriptor leak

This function creates a temporary file, and returns a FILE pointer to
it.  This avoids dealing with both a file descriptor and a FILE pointer,
and correctly deallocating the resources on error.

The code before this patch was leaking the file descriptor if fdopen(3)
failed.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/useradd.c: De-duplicate code
Alejandro Colomar [Fri, 17 May 2024 11:14:31 +0000 (13:14 +0200)] 
src/useradd.c: De-duplicate code

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/useradd.c: set_defaults(): Do not free(3) the result of asprintf(3) if it failed
Alejandro Colomar [Fri, 17 May 2024 11:10:46 +0000 (13:10 +0200)] 
src/useradd.c: set_defaults(): Do not free(3) the result of asprintf(3) if it failed

See asprintf(3):

RETURN VALUE
     When successful,  these  functions  return  the  number  of  bytes
     printed, just like sprintf(3).  If memory allocation wasn’t possi‐
     ble,  or  some other error occurs, these functions will return -1,
     and the contents of strp are undefined.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/useradd.c: set_defaults(): Rename goto label
Alejandro Colomar [Fri, 17 May 2024 12:28:50 +0000 (14:28 +0200)] 
src/useradd.c: set_defaults(): Rename goto label

This will help add other labels in the following commits.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agosrc/useradd.c: set_defaults(): Fix order of clean-ups
Alejandro Colomar [Fri, 17 May 2024 12:05:31 +0000 (14:05 +0200)] 
src/useradd.c: set_defaults(): Fix order of clean-ups

Resources should be freed in the inverse order of the allocation.
This refactor prepares for the following commits, which fix some leaks.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agoport: fix OVERRUN (CWE-119)
Iker Pedrosa [Wed, 15 May 2024 10:25:51 +0000 (12:25 +0200)] 
port: fix OVERRUN (CWE-119)

```
shadow-4.15.0/lib/port.c:154:2: alias: Assigning: "port.pt_names" = "ttys". "port.pt_names" now points to element 0 of "ttys" (which consists of 65 8-byte elements).
shadow-4.15.0/lib/port.c:155:2: cond_const: Checking "j < 64" implies that "j" is 64 on the false branch.
shadow-4.15.0/lib/port.c:175:2: overrun-local: Overrunning array of 65 8-byte elements at element index 65 (byte offset 527) by dereferencing pointer "port.pt_names + (j + 1)".
173|           *cp = '\0';
174|           cp++;
175|->         port.pt_names[j + 1] = NULL;
176|
177|           /*
```

Resolves: https://issues.redhat.com/browse/RHEL-35383

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/getrange.c: getrange(): Report an error when min>max
Alejandro Colomar [Sun, 7 Jan 2024 00:17:33 +0000 (01:17 +0100)] 
lib/getrange.c: getrange(): Report an error when min>max

Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/getrange.c: getrange(): Add missing cast
Alejandro Colomar [Sat, 6 Jan 2024 23:31:01 +0000 (00:31 +0100)] 
lib/getrange.c: getrange(): Add missing cast

isdigit(3) requires a cast if the argument is of type 'char'.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/getrange.c: getrange(): Add const to pointer
Alejandro Colomar [Mon, 15 Apr 2024 11:47:26 +0000 (13:47 +0200)] 
lib/getrange.c: getrange(): Add const to pointer

Now that we have const-generic macros, we can use a const pointer.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/getrange.c: getrange(): Use a2ul() instead of strtoul_noneg()
Alejandro Colomar [Sat, 6 Jan 2024 23:24:26 +0000 (00:24 +0100)] 
lib/getrange.c: getrange(): Use a2ul() instead of strtoul_noneg()

It simplifies the error checking.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
14 months agolib/atoi/a2i.[ch]: Add const-generic macros
Alejandro Colomar [Mon, 15 Apr 2024 11:20:55 +0000 (13:20 +0200)] 
lib/atoi/a2i.[ch]: Add const-generic macros

These overloaded macros allow passing either a const or a non-const
endp, and will call the appropriate function.  This kind of const
overloading has prior art in C23's string functions, such as memchr(3).

Martin suggested using an artificial function pointer in _Generic(3); it
allows switching on various types at the same time.

Also add a comment referring to liba2i's PDF manual for documentation.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf#subsubsection.7.26.5.2>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114731>
Link: <http://www.alejandro-colomar.es/share/dist/liba2i/git/HEAD/liba2i-HEAD.pdf>
Co-developed-by: Martin Uecker <muecker@gwdg.de>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/alloc.h: Reimplement [X]REALLOC[F]() macros with _Generic(3)
Alejandro Colomar [Thu, 9 May 2024 22:58:23 +0000 (00:58 +0200)] 
lib/alloc.h: Reimplement [X]REALLOC[F]() macros with _Generic(3)

Instead of GNU builtins and extensions, these macros can be implemented
with C11's _Generic(3), and the result is much simpler (and safer, since
it's now an error, not just a warning).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agoupdated Dutch translation
Frans Spiesschaert [Thu, 9 May 2024 10:36:26 +0000 (12:36 +0200)] 
updated Dutch translation

15 months agoman: update translations for username length
Iker Pedrosa [Tue, 7 May 2024 07:40:00 +0000 (09:40 +0200)] 
man: update translations for username length

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
15 months agoman: update username length
Iker Pedrosa [Tue, 7 May 2024 07:37:21 +0000 (09:37 +0200)] 
man: update username length

Fixes: 6a1f45d932c8 ("lib/chkname.c: Support unlimited user name lengths")
Related-To: https://github.com/shadow-maint/shadow/pull/986
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/, src/: Rename some local variables
Alejandro Colomar [Sun, 7 Jan 2024 00:37:04 +0000 (01:37 +0100)] 
lib/, src/: Rename some local variables

'endptr' is appropriate internally in strtol(3) because it's a pointer
to 'end', and 'end' itself is a pointer to one-after-the-last character
of the numeric string.  In other words,

endptr == &end

However, naming the pointer whose address we pass to strtol(3)'s
'endptr' feels wrong, and causes me trouble while parsing the code; I
need to double check the number of dereferences, because something feels
wrong in my head.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Use goto to deduplicate code
Alejandro Colomar [Sat, 6 Jan 2024 23:06:49 +0000 (00:06 +0100)] 
lib/getrange.c: getrange(): Use goto to deduplicate code

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Return early
Alejandro Colomar [Mon, 15 Apr 2024 09:57:49 +0000 (11:57 +0200)] 
lib/getrange.c: getrange(): Return early

It's doesn't make much sense to break from a switch() just to return.
Let's return early, to simplify.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Return early to reduce indentation
Alejandro Colomar [Mon, 15 Apr 2024 09:52:43 +0000 (11:52 +0200)] 
lib/getrange.c: getrange(): Return early to reduce indentation

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Don't else after return
Alejandro Colomar [Mon, 15 Apr 2024 09:47:21 +0000 (11:47 +0200)] 
lib/getrange.c: getrange(): Don't else after return

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Return early to remove an else
Alejandro Colomar [Mon, 15 Apr 2024 09:46:12 +0000 (11:46 +0200)] 
lib/getrange.c: getrange(): Return early to remove an else

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Remove temporary variable
Alejandro Colomar [Sat, 6 Jan 2024 22:48:33 +0000 (23:48 +0100)] 
lib/getrange.c: getrange(): Remove temporary variable

This means we set the pointees on error, which we didn't do before, but
since we return -1 on error and ignore (don't use) the pointees at call
site, that's fine.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Small refactor
Alejandro Colomar [Mon, 15 Apr 2024 09:32:39 +0000 (11:32 +0200)] 
lib/getrange.c: getrange(): Small refactor

All 3 non-error paths in the second part resulted in *has_min = true.
Set in once before the switch(), to simplify.

This means we set this variable on error, which we didn't do before,
but since we return -1 on error and ignore (don't use) the pointees at
call site, that's fine.

Also, move a couple of *has_max = true statements to before a comment,
in preparation for future commits.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agolib/getrange.c: getrange(): Small refactor
Alejandro Colomar [Mon, 15 Apr 2024 09:18:46 +0000 (11:18 +0200)] 
lib/getrange.c: getrange(): Small refactor

Set *has_{min,max} = false at the begining, so we only need to set them
to true later.

This means we set these variables on error, which we didn't do before,
but since we return -1 on error and ignore (don't use) the pointees at
call site, that's fine.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
15 months agoshare/containers: update build flags for fedora 40
Iker Pedrosa [Thu, 25 Apr 2024 07:12:39 +0000 (09:12 +0200)] 
share/containers: update build flags for fedora 40

libpam is enabled to provide `passwd` binary from this package, as there
are several password quality checks that are enabled through a PAM
module. Same reason to disable account-tools-setuid.

sssd is disabled because `files provider` has been removed in sssd, and
the underlying functionality in shadow isn't needed anymore.

libcrack dependency was disabled some time ago, but the upstream repo
wasn't updated. Doing it now.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
15 months agoshare/containers: sort configuration options
Iker Pedrosa [Mon, 29 Apr 2024 08:16:44 +0000 (10:16 +0200)] 
share/containers: sort configuration options

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
15 months agoshare/containers: fix indentation in fedora
Iker Pedrosa [Thu, 25 Apr 2024 07:09:39 +0000 (09:09 +0200)] 
share/containers: fix indentation in fedora

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
16 months agonewuidmap and newgidmap manpages: fix fd description
Serge Hallyn [Tue, 9 Apr 2024 22:12:46 +0000 (17:12 -0500)] 
newuidmap and newgidmap manpages: fix fd description

The manpages for newuidmap and newgidmap had a typo "[pid[" instead
of "[pid]".  They were also unclear about what the /proc/pid fd should
be.  Fix both.

Closes #977

Reported-by: igo95862@yandex.ru
Signed-off-by: Serge Hallyn <serge@hallyn.com>
16 months agolib/env.c: treat out of memory condition as error
Tobias Stoeckmann [Sun, 31 Mar 2024 10:14:04 +0000 (12:14 +0200)] 
lib/env.c: treat out of memory condition as error

If not enough memory is available for more environment variables, treat
it exactly like not enough memory for new environment variable content.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>