]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
23 months agoUse CALLOC() instead of its pattern
Alejandro Colomar [Mon, 31 Jul 2023 15:30:59 +0000 (17:30 +0200)] 
Use CALLOC() instead of its pattern

MALLOC() + memset() is simpler written as CALLOC().

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agoUse STRLCPY() instead of its pattern
Alejandro Colomar [Sat, 29 Jul 2023 16:22:12 +0000 (18:22 +0200)] 
Use STRLCPY() instead of its pattern

This makes it harder to make mistakes while editing the code.  Since the
sizeof's can be autocalculated, let the machine do that.  It also
reduces the cognitive load while reading the code.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agodefines.h: Remove definition of STRFCPY()
Alejandro Colomar [Sat, 29 Jul 2023 16:13:06 +0000 (18:13 +0200)] 
defines.h: Remove definition of STRFCPY()

It's not being used anymore.  We got rid of it in favor of better APIs.

Well, it's still being used in one place: a contrib/ patch, but I
explicitly want to break it, so that someone reviews it.  I don't want
to modify it, since it's not being tested, so it would be very risky for
me to touch it.  Instead, let it bitrot, and if someone cares, they'll
update it correctly.

BTW, the comment that said /* danger -side effects */ was wrong:
sizeof() doesn't evaluate the argument (unless it's a VLA), so there
wasn't really a double-evaluation issue.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agopasswd: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Sat, 29 Jul 2023 16:11:02 +0000 (18:11 +0200)] 
passwd: Replace STRFCPY() by STRLCPY()

The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agogpasswd: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Sat, 29 Jul 2023 16:04:30 +0000 (18:04 +0200)] 
gpasswd: Replace STRFCPY() by STRLCPY()

The variable is only being read as a string (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agologin: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Sat, 29 Jul 2023 15:56:46 +0000 (17:56 +0200)] 
login: Replace STRFCPY() by STRLCPY()

The variable is only being read as a string (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agosu: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Sat, 29 Jul 2023 15:35:40 +0000 (17:35 +0200)] 
su: Replace STRFCPY() by STRLCPY()

The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agosulogin: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Sat, 29 Jul 2023 15:28:23 +0000 (17:28 +0200)] 
sulogin: Replace STRFCPY() by STRLCPY()

The variable is only being read as a string (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agochsh: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Thu, 8 Jun 2023 18:46:09 +0000 (20:46 +0200)] 
chsh: Replace STRFCPY() by STRLCPY()

The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agochfn: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Thu, 8 Jun 2023 18:39:04 +0000 (20:39 +0200)] 
chfn: Replace STRFCPY() by STRLCPY()

The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agochage: Replace STRFCPY() by STRLCPY()
Alejandro Colomar [Thu, 8 Jun 2023 18:33:13 +0000 (20:33 +0200)] 
chage: Replace STRFCPY() by STRLCPY()

The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agostrlcpy.h: Add STRLCPY() macro
Alejandro Colomar [Sat, 29 Jul 2023 15:21:24 +0000 (17:21 +0200)] 
strlcpy.h: Add STRLCPY() macro

It wraps strlcpy(3bsd) so that it performs some steps that one might
forget, or might be prone to accidents:

-  It calculates the size of the destination buffer, and makes sure it's
   an array (otherwise, using sizeof(dst) would be very bad).

-  It calculates if there's truncation, returning an easy-to-use value.

BTW, this macro doesn't have any issues of double evaluation, because
sizeof() doesn't evaluate its argument (unless it's a VLA, but then
the static_assert(3) within SIZEOF_ARRAY() makes sure VLAs are not
allowed).

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agoUse ZUSTR2STP() instead of its pattern
Alejandro Colomar [Sun, 30 Jul 2023 16:48:36 +0000 (18:48 +0200)] 
Use ZUSTR2STP() instead of its pattern

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agozustr2stp.h: Add ZUSTR2STP() macro
Alejandro Colomar [Sun, 30 Jul 2023 16:45:47 +0000 (18:45 +0200)] 
zustr2stp.h: Add ZUSTR2STP() macro

It's a wrapper around zustr2stp() that calls SIZEOF_ARRAY() internally.
The function call is usually --in our code base, always-- called with an
array as the second argument.  For such an argument, one should call
SIZEOF_ARRAY().  To avoid mistakes, and simplify usage, let's add this
macro that does it internally.

BTW, this macro doesn't have any issues of double evaluation, because
sizeof() doesn't evaluate its argument (unless it's a VLA, but then
the static_assert(3) within SIZEOF_ARRAY() makes sure VLAs are not
allowed).

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agoCall zustr2stp() where appropriate
Alejandro Colomar [Sun, 30 Jul 2023 16:07:35 +0000 (18:07 +0200)] 
Call zustr2stp() where appropriate

These calls were intending to copy from a NUL-padded (possibly
non-NUL-terminated) character sequences contained in fixed-width arrays,
into a string, where extra padding is superfluous.  Use the appropriate
call, which removes the superfluous work.  That reduces the chance of
confusing maintainers about the intention of the code.

While at it, use the appropriate third parameter, which is the size of
the source buffer, and not the one of the destination buffer.  As a side
effect, this reduces the use of '-1', which itself reduces the chance of
off-by-one bugs.

Also, since using sizeof() on an array is dangerous, use SIZEOF_ARRAY().

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agozustr2stp.[ch]: Add zustr2stp()
Alejandro Colomar [Sun, 30 Jul 2023 15:39:59 +0000 (17:39 +0200)] 
zustr2stp.[ch]: Add zustr2stp()

There's no standard function that copies from a null-padded character
sequence into a string.

A few standard functions can be workarounded to do that:

-  strncat(3):  This function is designed to catenate from a null-padded
   character sequence into a string.  The catch is that there's no
   *cpy() equivalent of it --strncpy(3) is not at all related to
   strncat(3); don't be fooled by the confusing name--, so one would
   need to zero the first byte before the call to strncat(3).  It also
   has the inconvenient that it returns a useless value.

-  strncpy(3):  This function is designed to copy from a string to a
   null-padded character sequence; the opposite of what we want to do.
   If one passes the size of src instead of the size of dst, and then
   manually zeroes the last byte of the dst buffer, something similar
   to what we want happens.  However, this does more than what we want:
   it also padds with NUL the remaining bytes after the terminating NUL.
   That extra work can confuse maintainers to believe that it's
   necessary.  That is exactly what happens in logout.c.

src/logoutd.c-46- /*
src/logoutd.c-47-  * ut_user may not have the terminating NUL.
src/logoutd.c-48-  */
src/logoutd.c:49: strncpy (user, ut->ut_user, sizeof (ut->ut_user));
src/logoutd.c-50- user[sizeof (ut->ut_user)] = '\0';

   In that logout.c case --and in most invocations of strncpy(3), which
   is usually a wrong tool-- the extra work is not wanted, so it's
   preferrable to use the right tool, a function that does exactly
   what's needed and nothing more than that.  That tool is zustr2stp().

Read string_copying(7) for a more complete comparison of string copying
functions.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agolibmisc: Fix wrong #include
Alejandro Colomar [Sun, 30 Jul 2023 15:55:20 +0000 (17:55 +0200)] 
libmisc: Fix wrong #include

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agoUse MEMZERO() instead of its pattern
Alejandro Colomar [Sun, 30 Jul 2023 12:03:07 +0000 (14:03 +0200)] 
Use MEMZERO() instead of its pattern

This patch implicitly adds the safety of SIZEOF_ARRAY(), since the calls
were using sizeof() instead.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agomemzero.h: Add MEMZERO() macro
Alejandro Colomar [Sun, 30 Jul 2023 12:32:39 +0000 (14:32 +0200)] 
memzero.h: Add MEMZERO() macro

It calculates the size of the array safely, via SIZEOF_ARRAY(), instead of
sizeof(), which can be dangerous.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agosizeof.h: Add SIZEOF_ARRAY() macro
Alejandro Colomar [Sun, 30 Jul 2023 12:29:45 +0000 (14:29 +0200)] 
sizeof.h: Add SIZEOF_ARRAY() macro

This makes it safe to call sizeof() on an array.  Calling sizeof()
directly on an array is dangerous, because if the array changes to be a
pointer, the behavior will unexpectedly change.  It's the same problem
as with NITEMS().

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agosizeof.h: Make NITEMS() and derivative macros safe against pointers
Alejandro Colomar [Sun, 30 Jul 2023 12:26:27 +0000 (14:26 +0200)] 
sizeof.h: Make NITEMS() and derivative macros safe against pointers

By using must_be_array(), code that calls NITEMS() or STRLEN() with
non-arrays will not compile.

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agomust_be.h: Add must_be_array() macro
Alejandro Colomar [Fri, 4 Aug 2023 17:49:57 +0000 (19:49 +0200)] 
must_be.h: Add must_be_array() macro

This macro statically asserts that the argument is an array.

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agomust_be.h: Add must_be() macro
Alejandro Colomar [Sun, 30 Jul 2023 12:12:45 +0000 (14:12 +0200)] 
must_be.h: Add must_be() macro

It's like static_assert(3), but can be used in more places.  It's
necessary for writing a must_be_array() macro.

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agosizeof.h: Move sizeof()-related macros to their own header
Alejandro Colomar [Sun, 30 Jul 2023 12:05:10 +0000 (14:05 +0200)] 
sizeof.h: Move sizeof()-related macros to their own header

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agomemzero.h: Remove no-op assignment
Alejandro Colomar [Mon, 31 Jul 2023 11:20:19 +0000 (13:20 +0200)] 
memzero.h: Remove no-op assignment

memset(3) returns the input pointer.  The assignment was effectively a
no-op, and just confused the code.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agomemzero.[ch]: Define memzero() and strzero() as inline functions
Alejandro Colomar [Sun, 30 Jul 2023 11:30:47 +0000 (13:30 +0200)] 
memzero.[ch]: Define memzero() and strzero() as inline functions

There's no need to have these as macros, so use functions, which are a
lot safer: there's no need to worry about multiple evaluation of args,
and there's also more type safety.  Compiler warnings are also simpler,
as they don't dump all the nested macros.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agomemzero.h: Remove outdated comments
Alejandro Colomar [Sun, 30 Jul 2023 11:24:43 +0000 (13:24 +0200)] 
memzero.h: Remove outdated comments

These comments were wrong.  Remove them instead of fixing them, since
now that we have this small header file, it's much easier to follow the
preprocessor conditionals.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agomemzero.h: Move memzero() and strzero() to their own header
Alejandro Colomar [Sun, 30 Jul 2023 11:18:03 +0000 (13:18 +0200)] 
memzero.h: Move memzero() and strzero() to their own header

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agolib: Merge libmisc into libshadow
Alejandro Colomar [Mon, 28 Aug 2023 10:54:22 +0000 (12:54 +0200)] 
lib: Merge libmisc into libshadow

The separation was unnecessary, and caused build problems.  Let's go
wild and obliterate the library.  The files are moved to libshadow.

Scripted change:

$ find libmisc/ -type f \
| grep '\.[chy]$' \
| xargs mv -t lib;

Plus updating the Makefile and other references.  While at it, I've
sorted the sources lists.

Link: <https://github.com/shadow-maint/shadow/pull/792>
Reported-by: David Seifert <soap@gentoo.org>
Cc: Sam James <sam@gentoo.org>
Cc: Christian Bricart <christian@bricart.de>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Robert Förster <Dessa@gmake.de>
[ soap tested the Gentoo package ]
Tested-by: David Seifert <soap@gentoo.org>
Acked-by: David Seifert <soap@gentoo.org>
Acked-by: Serge Hallyn <serge@hallyn.com>
Acked-by: Iker Pedrosa <ipedrosa@redhat.com>
Acked-by: <lslebodn@fedoraproject.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agolib, libmisc: Move source files to lib (where their headers were)
Alejandro Colomar [Fri, 25 Aug 2023 09:29:00 +0000 (11:29 +0200)] 
lib, libmisc: Move source files to lib (where their headers were)

Scripted change:

$ find lib/ -type f \
| grep '\.h$' \
| sed 's,lib/,libmisc/,' \
| sed 's,\.h$,.c,' \
| xargs find 2>/dev/null \
| xargs mv -t lib/;

Plus updating the Makefiles.

Closes: <https://github.com/shadow-maint/shadow/issues/791>
Closes: <https://bugs.gentoo.org/912446>
Link: <https://github.com/shadow-maint/shadow/issues/763#issuecomment-1664383425>
Link: <https://github.com/shadow-maint/shadow/pull/776>
Link: <https://github.com/shadow-maint/shadow/commit/d0518cc250afeaceb772a7f50a900cfc9b3ab937>
Reported-by: Christian Bricart <christian@bricart.de>
Reported-by: Robert Marmorstein <robert@marmorstein.org>
Cc: Sam James <sam@gentoo.org>
[ jubalh tested the openSUSE package ]
Tested-by: Michael Vetter <jubalh@iodoru.org>
Acked-by: Michael Vetter <jubalh@iodoru.org>
[ Robert F. tested the Gentoo package ]
Tested-by: Robert Förster <Dessa@gmake.de>
Cc: David Seifert <soap@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agoAvoid usage of sprintf
Christian Göttsche [Thu, 26 Jan 2023 19:49:41 +0000 (20:49 +0100)] 
Avoid usage of sprintf

sprintf(3) does not take the destination buffer into account. Although
the destination in these case is large enough, sprintf(3) indicates a
code smell.

Use snprintf(3).

23 months agocommonio: check for path truncations
Christian Göttsche [Thu, 26 Jan 2023 19:58:24 +0000 (20:58 +0100)] 
commonio: check for path truncations

Bail out if the paths generated for the backup and replacement database
are truncated.

23 months agolib/btrfs: avoid NULL-dereference
Christian Göttsche [Thu, 26 Jan 2023 20:03:56 +0000 (21:03 +0100)] 
lib/btrfs: avoid NULL-dereference

    btrfs.c:42:13: warning: use of NULL 'cmd' where non-null expected [CWE-476] [-Wanalyzer-null-argument]

Reviewed-by: Alejandro Colomar <alx@kernel.org>
23 months agolib/commonio: drop dead store
Christian Göttsche [Thu, 26 Jan 2023 20:40:47 +0000 (21:40 +0100)] 
lib/commonio: drop dead store

    commonio.c:522:15: warning: Although the value stored to 'cp' is used in the enclosing expression, the value is never actually read from 'cp' [deadcode.DeadStores]

Reviewed-by: Alejandro Colomar <alx@kernel.org>
23 months agologin: use strlcpy to always NUL terminate
Christian Göttsche [Thu, 26 Jan 2023 19:24:09 +0000 (20:24 +0100)] 
login: use strlcpy to always NUL terminate

    login.c:728:25: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation]

Reviewed-by: Alejandro Colomar <alx@kernel.org>
23 months agolib: avoid dropping const qualifier during cast
Christian Göttsche [Tue, 28 Feb 2023 14:41:20 +0000 (15:41 +0100)] 
lib: avoid dropping const qualifier during cast

    subordinateio.c:360:20: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      360 |         range1 = (*(struct commonio_entry **) p1)->eptr;
          |                    ^
    subordinateio.c:364:20: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      364 |         range2 = (*(struct commonio_entry **) p2)->eptr;
          |                    ^

    groupio.c:215:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      215 |         if ((*(struct commonio_entry **) p1)->eptr == NULL) {
          |               ^
    groupio.c:218:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      218 |         if ((*(struct commonio_entry **) p2)->eptr == NULL) {
          |               ^
    groupio.c:222:34: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      222 |         u1 = ((struct group *) (*(struct commonio_entry **) p1)->eptr)->gr_gid;
          |                                  ^
    groupio.c:223:34: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      223 |         u2 = ((struct group *) (*(struct commonio_entry **) p2)->eptr)->gr_gid;
          |                                  ^

    pwio.c:187:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      187 |         if ((*(struct commonio_entry **) p1)->eptr == NULL)
          |               ^
    pwio.c:189:15: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      189 |         if ((*(struct commonio_entry **) p2)->eptr == NULL)
          |               ^
    pwio.c:192:35: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      192 |         u1 = ((struct passwd *) (*(struct commonio_entry **) p1)->eptr)->pw_uid;
          |                                   ^
    pwio.c:193:35: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      193 |         u2 = ((struct passwd *) (*(struct commonio_entry **) p2)->eptr)->pw_uid;
          |                                   ^

Reviewed-by: Alejandro Colomar <alx@kernel.org>
23 months agoDrop unnecessary cast to same type
Christian Göttsche [Thu, 26 Jan 2023 21:55:12 +0000 (22:55 +0100)] 
Drop unnecessary cast to same type

23 months agoDeclare usage and failure handler noreturn
Christian Göttsche [Thu, 26 Jan 2023 21:08:43 +0000 (22:08 +0100)] 
Declare usage and failure handler noreturn

Assist static analyzers in understanding final code paths.

23 months agolib/tcbfuncs: operate on file descriptor rather than path
Christian Göttsche [Tue, 28 Feb 2023 15:05:09 +0000 (16:05 +0100)] 
lib/tcbfuncs: operate on file descriptor rather than path

23 months agolibmisc/write_full.c: Improve write_full()
Alejandro Colomar [Fri, 4 Aug 2023 23:04:04 +0000 (01:04 +0200)] 
libmisc/write_full.c: Improve write_full()

Documentation:

-  Correct the comment documenting the function:

   write_full() doesn't write "up to" count bytes (which is write(2)'s
   behavior, and exactly what this function is designed to avoid), but
   rather exactly count bytes (on success).

-  While fixing the documentation, take the time to add a man-page-like
   comment as in other APIs.  Especially, since we'll have to document
   a few other changes from this patch, such as the modified return
   values.

-  Partial writes are still possible on error.  It's the caller's
   responsibility to handle that possibility.

API:

-  In write(2), it's useful to know how many bytes were transferred,
   since it can have short writes.  In this API, since it either writes
   it all or fails, that value is useless, and callers only want to know
   if it succeeded or not.  Thus, just return 0 or -1.

Implementation:

-  Use `== -1` instead of `< 0` to check for write(2) syscall errors.
   This is wisdom from Michael Kerrisk.  This convention is useful
   because it more explicitly tells maintainers that the only value
   which can lead to that path is -1.  Otherwise, a maintainer of the
   code might be confused to think that other negative values are
   possible.  Keep it simple.

-  The path under `if (res == 0)` was unreachable, since the loop
   condition `while (count > 0)` precludes that possibility.  Remove the
   dead code.

-  Use a temporary variable of type `const char *` to avoid a cast.

-  Rename `res`, which just holds the result from write(2), to `w`,
   which more clearly shows that it's just a very-short-lived variable
   (by it's one-letter name), and also relates itself more to write(2).
   I find it more readable.

-  Move the definition of `w` to the top of the function.  Now that the
   function is significantly shorter, the lifetime of the variable is
   clearer, and I find it more readable this way.

Use:

-  Also use `== -1` to check errors.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
23 months agoReplace __{BEGIN,END}_DECLS with #ifdef __cplusplus
Heiko Becker [Fri, 18 Aug 2023 16:23:56 +0000 (18:23 +0200)] 
Replace __{BEGIN,END}_DECLS with #ifdef __cplusplus

Fixes the build with musl libc.

23 months agorelease 4.14.0 4.14.0
Serge Hallyn [Wed, 16 Aug 2023 02:38:30 +0000 (21:38 -0500)] 
release 4.14.0

Signed-off-by: Serge Hallyn <serge@hallyn.com>
23 months agopre-release 4.14.0-rc5 4.14.0-rc5
Serge Hallyn [Mon, 14 Aug 2023 16:51:36 +0000 (11:51 -0500)] 
pre-release 4.14.0-rc5

Signed-off-by: Serge Hallyn <serge@hallyn.com>
23 months agoconfigure.ac: check for strlcpy
Serge Hallyn [Mon, 14 Aug 2023 13:27:30 +0000 (08:27 -0500)] 
configure.ac: check for strlcpy

Signed-off-by: Serge Hallyn <serge@hallyn.com>
23 months agoRemove intree website
Michael Vetter [Mon, 14 Aug 2023 06:57:40 +0000 (08:57 +0200)] 
Remove intree website

AFAIK these files were not used in a while.
On 2023-04-27 we also archived the GitHub pages based repo:
https://github.com/shadow-maint/shadow-www

In https://github.com/shadow-maint/shadow/commit/1654f42194ba7804c99d5ac96346a1a19fb793d7 we mention the regular repo URL as our home page.

Also see:
https://github.com/shadow-maint/shadow/issues/114

23 months ago4.14.0-rc4 pre-release 4.14.0-rc4
Serge Hallyn [Sun, 13 Aug 2023 04:17:52 +0000 (23:17 -0500)] 
4.14.0-rc4 pre-release

Signed-off-by: Serge Hallyn <serge@hallyn.com>
23 months agoReleases: add etc/shadow-maint to distfiles
Serge Hallyn [Fri, 11 Aug 2023 17:47:41 +0000 (12:47 -0500)] 
Releases: add etc/shadow-maint to distfiles

Closes #784

Signed-off-by: Serge Hallyn <serge@hallyn.com>
23 months ago4.14.0-rc3 4.14.0-rc3
Serge Hallyn [Thu, 10 Aug 2023 14:33:07 +0000 (09:33 -0500)] 
4.14.0-rc3

Signed-off-by: Serge Hallyn <serge@hallyn.com>
23 months agolibmisc: include freezero
Iker Pedrosa [Thu, 10 Aug 2023 07:46:38 +0000 (09:46 +0200)] 
libmisc: include freezero

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
23 months agolibmisc: add freezero source code
Iker Pedrosa [Thu, 10 Aug 2023 07:45:32 +0000 (09:45 +0200)] 
libmisc: add freezero source code

If shadow is built without libbsd support, then freezero() needs to be
provided from the project.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
23 months agolibmisc: add readpassphrase source code
Iker Pedrosa [Tue, 8 Aug 2023 14:01:41 +0000 (16:01 +0200)] 
libmisc: add readpassphrase source code

If shadow is built without libbsd support, then readpassphrase() needs
to be provided from the project.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
23 months agoconfigure: add `with-libbsd` option
Iker Pedrosa [Thu, 10 Aug 2023 07:15:04 +0000 (09:15 +0200)] 
configure: add `with-libbsd` option

It enables the build with libbsd support. By default it is enabled.

Resolves: https://github.com/shadow-maint/shadow/issues/779

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
23 months agoman: include `shadow-man.xsl` in tarball
Iker Pedrosa [Tue, 8 Aug 2023 10:52:21 +0000 (12:52 +0200)] 
man: include `shadow-man.xsl` in tarball

This will help generate man pages from tarball.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
23 months agoman: include `its.rules` in tarball
Iker Pedrosa [Tue, 8 Aug 2023 10:50:27 +0000 (12:50 +0200)] 
man: include `its.rules` in tarball

This will help generate the man pages from tarball.

Resolves: https://github.com/shadow-maint/shadow/issues/781

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
23 months agoautogen: enable lastlog build
Iker Pedrosa [Mon, 7 Aug 2023 08:12:04 +0000 (10:12 +0200)] 
autogen: enable lastlog build

Add "--enable-lastlog" to include lastlog man pages in tarball.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoAdd wrapper for write(2)
Christian Göttsche [Tue, 28 Feb 2023 15:35:05 +0000 (16:35 +0100)] 
Add wrapper for write(2)

write(2) may not write the complete given buffer.  Add a wrapper to
avoid short writes.

2 years agotag 4.14.0-rc2 4.14.0-rc2
Serge Hallyn [Fri, 4 Aug 2023 21:24:54 +0000 (16:24 -0500)] 
tag 4.14.0-rc2

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agoAdd new files to libmisc_la_SOURCES
Michael Vetter [Fri, 4 Aug 2023 12:26:50 +0000 (14:26 +0200)] 
Add new files to libmisc_la_SOURCES

Resolves https://github.com/shadow-maint/shadow/issues/763

2 years agoAdd a make dist CI test
Serge Hallyn [Fri, 4 Aug 2023 14:59:56 +0000 (09:59 -0500)] 
Add a make dist CI test

Add a CI test to check that make dist builds a usable tarball.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years ago4.14.0-rc1 4.14.0-rc1
Serge Hallyn [Mon, 31 Jul 2023 14:39:12 +0000 (09:39 -0500)] 
4.14.0-rc1

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agoremove xmalloc.c from POTFILES.in
Serge Hallyn [Thu, 3 Aug 2023 13:24:44 +0000 (08:24 -0500)] 
remove xmalloc.c from POTFILES.in

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agologoutd: add missing <utmp.h> include
Iker Pedrosa [Fri, 21 Jul 2023 06:35:17 +0000 (08:35 +0200)] 
logoutd: add missing <utmp.h> include

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoCI: compile old utmp interface in Fedora
Iker Pedrosa [Fri, 21 Jul 2023 06:26:51 +0000 (08:26 +0200)] 
CI: compile old utmp interface in Fedora

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agosrc: add SELINUX library
Iker Pedrosa [Wed, 19 Jul 2023 11:00:17 +0000 (13:00 +0200)] 
src: add SELINUX library

With the recent changes both login and su compilation fail because there
are some missing dependencies from SELINUX library. Thus, add LIBSELINUX
to su and login for those cases where the library is used.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agolibmisc: conditionally compile `utmp.c` and `logind.c`
Iker Pedrosa [Wed, 19 Jul 2023 10:41:06 +0000 (12:41 +0200)] 
libmisc: conditionally compile `utmp.c` and `logind.c`

Depending on the configuration option selected.

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agolib: replace `USER_NAME_MAX_LENGTH` macro
Iker Pedrosa [Wed, 19 Jul 2023 10:05:09 +0000 (12:05 +0200)] 
lib: replace `USER_NAME_MAX_LENGTH` macro

Replace it by `sysconf(_SC_LOGIN_NAME_MAX)`, which is the maximum
username length supported by the kernel.

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agolibmisc: call `active_sessions_count()`
Iker Pedrosa [Wed, 19 Jul 2023 10:02:31 +0000 (12:02 +0200)] 
libmisc: call `active_sessions_count()`

Replace the utmp dependent code with the call to
`active_sessions_count()`.

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agolibmisc: implement `active_sessions_count()`
Iker Pedrosa [Wed, 19 Jul 2023 09:02:55 +0000 (11:02 +0200)] 
libmisc: implement `active_sessions_count()`

Implement `active_sessions_count()` in `utmp.c` and `logind.c`.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoutmp: update `update_utmp()`
Iker Pedrosa [Wed, 19 Jul 2023 07:42:35 +0000 (09:42 +0200)] 
utmp: update `update_utmp()`

Remove `utmp` structure as an argument and include its logic inside the
function. This will help remove any reference to utmp from login.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoutmp: move `update_utmp`
Iker Pedrosa [Tue, 18 Jul 2023 14:48:02 +0000 (16:48 +0200)] 
utmp: move `update_utmp`

The functionality from this function is related to utmp. Restrict access
to `setutmp()` to the same file.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoutmp: move `failtmp()`
Iker Pedrosa [Tue, 18 Jul 2023 14:36:35 +0000 (16:36 +0200)] 
utmp: move `failtmp()`

The functionality from this function is related to btmp.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agolibmisc: implement `get_session_host()`
Iker Pedrosa [Tue, 18 Jul 2023 13:56:46 +0000 (15:56 +0200)] 
libmisc: implement `get_session_host()`

Implement `get_session_host()` in `utmp.c` and `logind.c`.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoconfigure: new option `enable-logind`
Iker Pedrosa [Tue, 18 Jul 2023 09:33:02 +0000 (11:33 +0200)] 
configure: new option `enable-logind`

Create new configuration option `enable-logind` to select which session
support functionality to build, logind or utmp. By default the option is
logind.

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoshadow userdel: add the adaptation to the busybox ps in 01-kill_user_procs.sh
xiongshenglan [Wed, 19 Jul 2023 07:13:06 +0000 (15:13 +0800)] 
shadow userdel: add the adaptation to the busybox ps in 01-kill_user_procs.sh

In some embedded systems, users only use the ps
provided by the busybox. But the ps provided by
the busybox does not support the -eo option by
default. As a result, an error is reported when
the userdel is used. So add a judgment on ps.
If there is no ps -eo, traverse the process directly.

The error information is as follows:
 # userdel xsl
ps: invalid option -- 'e'

Signed-off-by: xiongshenglan <xiongshenglan@huawei.com>
2 years agochsh: warn if root sets a shell not listed in /etc/shells
Michael Vetter [Wed, 26 Jul 2023 08:13:53 +0000 (10:13 +0200)] 
chsh: warn if root sets a shell not listed in /etc/shells

Print a warning even for the root user if the provided shell isn't
listed in /etc/shells, but continue to execute the action.
In case of non root user exit.

See https://github.com/shadow-maint/shadow/issues/535

2 years agodoc: mention ci workflow file to learn about deps
Michael Vetter [Wed, 26 Jul 2023 09:24:29 +0000 (11:24 +0200)] 
doc: mention ci workflow file to learn about deps

Fix https://github.com/shadow-maint/shadow/issues/38

2 years agoman/po/Makefile: add a comment to shadow-man-pages.pot
Serge Hallyn [Sat, 15 Jul 2023 12:50:34 +0000 (07:50 -0500)] 
man/po/Makefile: add a comment to shadow-man-pages.pot

Add a comment at the top of that file explaining how to
regenerate it.

We should add a README, but I don't have time to draft one
right now.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agonewgrp: fix potential string injection
Vegard Nossum [Fri, 21 Jul 2023 12:55:19 +0000 (14:55 +0200)] 
newgrp: fix potential string injection

Since newgrp is setuid-root, any write() system calls it does in order
to print error messages will be done as the root user.

Unprivileged users can get newgrp to print essentially arbitrary strings
to any open file in this way by passing those strings as argv[0] when
calling execve(). For example:

    $ setpid() { (exec -a $1$'\n:' newgrp '' 2>/proc/sys/kernel/ns_last_pid & wait) >/dev/null; }
    $ setpid 31000
    $ readlink /proc/self
    31001

This is not a vulnerability in newgrp; it is a bug in the Linux kernel.

However, this type of bug is not new [1] and it makes sense to try to
mitigate these types of bugs in userspace where possible.

[1]: https://lwn.net/Articles/476947/

Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
2 years agolastlog: fix alignment of Latest header
Todd Zullinger [Tue, 18 Jul 2023 03:16:00 +0000 (23:16 -0400)] 
lastlog: fix alignment of Latest header

b1282224 (Add maximum padding to fit IPv6-Addresses, 2020-05-24) pads
the From field header using `maxIPv6Addrlen - 3`.  This leaves the
Latest field header misaligned.  Subtract 4 (the length of "From").

2 years agoconfigure: fix lastlog check
Iker Pedrosa [Mon, 17 Jul 2023 13:04:19 +0000 (15:04 +0200)] 
configure: fix lastlog check

Fixes: 1bdcfa8d3710bf0a3f180b590017df096d346ade ("lastlog: stop building by
default")

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agosubuid.5: reference newusers(8) rather than newusers(1)
Alan D. Salewski [Sat, 15 Jul 2023 20:36:06 +0000 (16:36 -0400)] 
subuid.5: reference newusers(8) rather than newusers(1)

Resolves: https://github.com/shadow-maint/shadow/issues/752

Signed-off-by: Alan D. Salewski <ads@salewski.email>
2 years agoCI: build lastlog in Fedora
Iker Pedrosa [Thu, 13 Jul 2023 13:33:07 +0000 (15:33 +0200)] 
CI: build lastlog in Fedora

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoman: conditionally build lastlog documentation
Iker Pedrosa [Thu, 13 Jul 2023 13:30:22 +0000 (15:30 +0200)] 
man: conditionally build lastlog documentation

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agousermod: conditionally build lastlog functionality
Iker Pedrosa [Thu, 13 Jul 2023 13:25:03 +0000 (15:25 +0200)] 
usermod: conditionally build lastlog functionality

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agouseradd: conditionally build lastlog functionality
Iker Pedrosa [Thu, 13 Jul 2023 13:24:37 +0000 (15:24 +0200)] 
useradd: conditionally build lastlog functionality

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agologin: conditionally build lastlog functionality
Iker Pedrosa [Thu, 13 Jul 2023 10:59:33 +0000 (12:59 +0200)] 
login: conditionally build lastlog functionality

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agolastlog: stop building by default
Iker Pedrosa [Thu, 13 Jul 2023 10:54:04 +0000 (12:54 +0200)] 
lastlog: stop building by default

Created a new configuration option `--enable-lastlog` to conditionally
build the lastlog binary. By default the option is disabled.

Resolves: https://github.com/shadow-maint/shadow/issues/674

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoCI: update debian repos
Iker Pedrosa [Fri, 14 Jul 2023 09:39:33 +0000 (11:39 +0200)] 
CI: update debian repos

Latest debian version changed the location and format for the repos
file.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoFix yescrypt support
Bernd Kuhls [Sun, 9 Jul 2023 08:55:03 +0000 (10:55 +0200)] 
Fix yescrypt support

Fixes build error:
newusers.c: In function 'update_passwd':
newusers.c:433:21: error: 'sflg' undeclared (first use in this function); did you mean 'rflg'?

introduced by
https://github.com/shadow-maint/shadow/commit/5cd04d03f94622c12220d4a6352824af081b8531
which forgot to define sflg for these configure options:

--without-sha-crypt --without-bcrypt --with-yescrypt

2 years agochgpasswd: fix segfault in command-line options
Jeffrey Bencteux [Wed, 21 Jun 2023 13:12:43 +0000 (15:12 +0200)] 
chgpasswd: fix segfault in command-line options

Using the --sha-rounds option without first giving a crypt method via the --crypt-method option results in comparisons with a NULL pointer and thus make chgpasswd segfault:

$ chgpasswd -s 1
zsh: segmentation fault  chgpasswd -s 1

Current patch add a sanity check before these comparisons to ensure there is a defined encryption method.

2 years agogpasswd(1): Fix password leak
Alejandro Colomar [Sat, 10 Jun 2023 14:20:05 +0000 (16:20 +0200)] 
gpasswd(1): Fix password leak

How to trigger this password leak?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When gpasswd(1) asks for the new password, it asks twice (as is usual
for confirming the new password).  Each of those 2 password prompts
uses agetpass() to get the password.  If the second agetpass() fails,
the first password, which has been copied into the 'static' buffer
'pass' via STRFCPY(), wasn't being zeroed.

agetpass() is defined in <./libmisc/agetpass.c> (around line 91), and
can fail for any of the following reasons:

-  malloc(3) or readpassphrase(3) failure.

   These are going to be difficult to trigger.  Maybe getting the system
   to the limits of memory utilization at that exact point, so that the
   next malloc(3) gets ENOMEM, and possibly even the OOM is triggered.
   About readpassphrase(3), ENFILE and EINTR seem the only plausible
   ones, and EINTR probably requires privilege or being the same user;
   but I wouldn't discard ENFILE so easily, if a process starts opening
   files.

-  The password is longer than PASS_MAX.

   The is plausible with physical access.  However, at that point, a
   keylogger will be a much simpler attack.

And, the attacker must be able to know when the second password is being
introduced, which is not going to be easy.

How to read the password after the leak?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Provoking the leak yourself at the right point by entering a very long
password is easy, and inspecting the process stack at that point should
be doable.  Try to find some consistent patterns.

Then, search for those patterns in free memory, right after the victim
leaks their password.

Once you get the leak, a program should read all the free memory
searching for patterns that gpasswd(1) leaves nearby the leaked
password.

On 6/10/23 03:14, Seth Arnold wrote:
> An attacker process wouldn't be able to use malloc(3) for this task.
> There's a handful of tools available for userspace to allocate memory:
>
> -  brk / sbrk
> -  mmap MAP_ANONYMOUS
> -  mmap /dev/zero
> -  mmap some other file
> -  shm_open
> -  shmget
>
> Most of these return only pages of zeros to a process.  Using mmap of an
> existing file, you can get some of the contents of the file demand-loaded
> into the memory space on the first use.
>
> The MAP_UNINITIALIZED flag only works if the kernel was compiled with
> CONFIG_MMAP_ALLOW_UNINITIALIZED.  This is rare.
>
> malloc(3) doesn't zero memory, to our collective frustration, but all the
> garbage in the allocations is from previous allocations in the current
> process.  It isn't leftover from other processes.
>
> The avenues available for reading the memory:
> -  /dev/mem and /dev/kmem (requires root, not available with Secure Boot)
> -  /proc/pid/mem (requires ptrace privileges, mediated by YAMA)
> -  ptrace (requires ptrace privileges, mediated by YAMA)
> -  causing memory to be swapped to disk, and then inspecting the swap
>
> These all require a certain amount of privileges.

How to fix it?
~~~~~~~~~~~~~~

memzero(), which internally calls explicit_bzero(3), or whatever
alternative the system provides with a slightly different name, will
make sure that the buffer is zeroed in memory, and optimizations are not
allowed to impede this zeroing.

This is not really 100% effective, since compilers may place copies of
the string somewhere hidden in the stack.  Those copies won't get zeroed
by explicit_bzero(3).  However, that's arguably a compiler bug, since
compilers should make everything possible to avoid optimizing strings
that are later passed to explicit_bzero(3).  But we all know that
sometimes it's impossible to have perfect knowledge in the compiler, so
this is plausible.  Nevertheless, there's nothing we can do against such
issues, except minimizing the time such passwords are stored in plain
text.

Security concerns
~~~~~~~~~~~~~~~~~

We believe this isn't easy to exploit.  Nevertheless, and since the fix
is trivial, this fix should probably be applied soon, and backported to
all supported distributions, to prevent someone else having more
imagination than us to find a way.

Affected versions
~~~~~~~~~~~~~~~~~

All.  Bug introduced in shadow 19990709.  That's the second commit in
the git history.

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Reported-by: Alejandro Colomar <alx@kernel.org>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Seth Arnold <seth.arnold@canonical.com>
Cc: Christian Brauner <christian@brauner.io>
Cc: Balint Reczey <rbalint@debian.org>
Cc: Sam James <sam@gentoo.org>
Cc: David Runge <dvzrv@archlinux.org>
Cc: Andreas Jaeger <aj@suse.de>
Cc: <~hallyn/shadow@lists.sr.ht>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agosrc/useradd.c: create_mail(): Cosmetic
Alejandro Colomar [Wed, 7 Jun 2023 21:56:30 +0000 (23:56 +0200)] 
src/useradd.c: create_mail(): Cosmetic

-  Invert conditional to reduce indentation.
-  Reduce use of whitespace and newlines while unindenting.
-  Reorder variable declarations.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agosrc/useradd.c: create_home(): Cosmetic
Alejandro Colomar [Wed, 7 Jun 2023 21:56:29 +0000 (23:56 +0200)] 
src/useradd.c: create_home(): Cosmetic

-  Invert conditional to reduce indentation.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agosrc/useradd.c: create_home(): Cosmetic
Alejandro Colomar [Wed, 7 Jun 2023 21:56:28 +0000 (23:56 +0200)] 
src/useradd.c: create_home(): Cosmetic

-  Invert conditional to reduce indentation.
-  Rewrite while loop calling strtok(3) as a for loop.  This allows
   doing more simplification inside the loop (see next commit).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agosrc/useradd.c: create_home(): Cosmetic
Alejandro Colomar [Wed, 7 Jun 2023 21:56:27 +0000 (23:56 +0200)] 
src/useradd.c: create_home(): Cosmetic

-  Fix indentation.  It was very broken.
-  Move variable declaration to the top of the block in which it's used.
-  Reduce use of whitespace and newlines.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agosrc/useradd.c: close_group_files(): Cosmetic
Alejandro Colomar [Wed, 7 Jun 2023 21:56:26 +0000 (23:56 +0200)] 
src/useradd.c: close_group_files(): Cosmetic

-  Invert conditional, to reduce indentation.
-  Reduce use of whitespace and newlines while unindenting.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agosrc/useradd.c: check_uid_range(): Cosmetic
Alejandro Colomar [Wed, 7 Jun 2023 21:56:25 +0000 (23:56 +0200)] 
src/useradd.c: check_uid_range(): Cosmetic

-  Merge nested conditionals into a single if, to reduce indentation.
-  Indent (1 SP) nested preprocessor conditionals.
-  Reduce use of whitespace and newlines while unindenting.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agobuild: link passwd, chpasswd and chage against libdl
Jaroslav Jindrak [Fri, 5 May 2023 18:29:58 +0000 (20:29 +0200)] 
build: link passwd, chpasswd and chage against libdl

2 years agoconfigure: check whether fgetpwent_r is available before marking xprefix_getpwnam_r...
Jaroslav Jindrak [Thu, 4 May 2023 20:41:02 +0000 (22:41 +0200)] 
configure: check whether fgetpwent_r is available before marking xprefix_getpwnam_r as reentrant

2 years agopasswd: fall back to non-PAM code when prefix is used
Jaroslav Jindrak [Wed, 3 May 2023 20:38:28 +0000 (22:38 +0200)] 
passwd: fall back to non-PAM code when prefix is used

Prefix does not make sense when we use PAM, so when the option
is used behave as if --with-libpam=no was used to configure the
project.