]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
2 years agoAssume <unistd.h> exists
Alejandro Colomar [Fri, 2 Dec 2022 20:39:15 +0000 (21:39 +0100)] 
Assume <unistd.h> exists

It is required by POSIX.1-2001.

Cc: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoRemove unused check for <fcntl.h>
Alejandro Colomar [Fri, 2 Dec 2022 20:37:50 +0000 (21:37 +0100)] 
Remove unused check for <fcntl.h>

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume strstr(3) exists
Alejandro Colomar [Mon, 5 Dec 2022 12:54:37 +0000 (13:54 +0100)] 
Assume strstr(3) exists

ISO C99 requires strstr(3).

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume snprintf(3) exists
Alejandro Colomar [Mon, 5 Dec 2022 12:53:08 +0000 (13:53 +0100)] 
Assume snprintf(3) exists

ISO C99 requires snprintf(3).

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume rename(2) exists
Alejandro Colomar [Mon, 5 Dec 2022 12:52:04 +0000 (13:52 +0100)] 
Assume rename(2) exists

ISO C99 requires rename(2).

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume NULL exists
Alejandro Colomar [Fri, 2 Dec 2022 16:25:07 +0000 (17:25 +0100)] 
Assume NULL exists

ISO C99 requires NULL.

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume strerror(3) exists
Alejandro Colomar [Fri, 2 Dec 2022 16:23:03 +0000 (17:23 +0100)] 
Assume strerror(3) exists

ISO C99 requires strerror(3).

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume fputs(3) exists
Alejandro Colomar [Fri, 2 Dec 2022 16:22:25 +0000 (17:22 +0100)] 
Assume fputs(3) exists

ISO C99 requires fputs(3).

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume <locale.h> exists
Alejandro Colomar [Fri, 2 Dec 2022 16:06:47 +0000 (17:06 +0100)] 
Assume <locale.h> exists

ISO C99 requires <locale.h>.

Other files in the project already include <locale.h> unconditionally,
so it's reasonable to assume that it is always available.

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoRemove unused check for <limits.h>
Alejandro Colomar [Fri, 2 Dec 2022 16:04:03 +0000 (17:04 +0100)] 
Remove unused check for <limits.h>

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume <errno.h> exists
Alejandro Colomar [Fri, 2 Dec 2022 15:58:12 +0000 (16:58 +0100)] 
Assume <errno.h> exists

ISO C99 requires <errno.h>.

Many files in the project already include <errno.h> unconditionally,
so it's reasonable to assume that it is always available.

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAssume <stdbool.h> exists
Alejandro Colomar [Fri, 2 Dec 2022 15:51:05 +0000 (16:51 +0100)] 
Assume <stdbool.h> exists

ISO C99 requires <stdbool.h>.

Many files in the project already include <stdbool.h> unconditionally,
so it's reasonable to assume that it is always available.

Link: <https://github.com/shadow-maint/shadow/pull/600>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoAdd '62_usermod_remove_supplementary_groups' test case to test runner scripts (run_some)
James Addison [Fri, 18 Nov 2022 22:14:43 +0000 (22:14 +0000)] 
Add '62_usermod_remove_supplementary_groups' test case to test runner scripts (run_some)

2 years agoAdd '62_usermod_remove_supplementary_groups' test case to test runner scripts (run_al...
James Addison [Thu, 17 Nov 2022 12:58:13 +0000 (12:58 +0000)] 
Add '62_usermod_remove_supplementary_groups' test case to test runner scripts (run_all, run_all.coverage)

2 years agoAdd regression test for 'usermod -rG' -- it should not add users to groups they did...
James Addison [Thu, 17 Nov 2022 12:47:31 +0000 (12:47 +0000)] 
Add regression test for 'usermod -rG' -- it should not add users to groups they did not previously belong to

2 years agoPreparation / clarity: rename existing usermod test from 'remove_supplemental_groups...
James Addison [Thu, 17 Nov 2022 11:35:52 +0000 (11:35 +0000)] 
Preparation / clarity: rename existing usermod test from 'remove_supplemental_groups' to 'clear_supplemental_groups'

2 years agoagetpass: Hook into build-system
Guillem Jover [Mon, 21 Nov 2022 13:00:13 +0000 (14:00 +0100)] 
agetpass: Hook into build-system

Signed-off-by: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoHide [[gnu::malloc(deallocator)]] in a macro
Alejandro Colomar [Wed, 28 Sep 2022 21:09:19 +0000 (23:09 +0200)] 
Hide [[gnu::malloc(deallocator)]] in a macro

Clang doesn't implement this attribute and reports an error.  Work
around it by hiding it in a macro that will be empty in clang.

Reported-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoReplace the deprecated getpass(3) by our agetpass()
Alejandro Colomar [Tue, 27 Sep 2022 19:21:35 +0000 (21:21 +0200)] 
Replace the deprecated getpass(3) by our agetpass()

getpass(3) is broken in all implementations; in some, more than
others, but somewhat broken in all of them.  Check the immediate
previous commit, which added the functions, for more details.
Check also the Linux man-pages commit that marked it as
deprecated, for more details:
7ca189099d73bde954eed2d7fc21732bcc8ddc6b.

Link: <https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit?id=7ca189099d73bde954eed2d7fc21732bcc8ddc6b>
Reported-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agolibmisc: agetpass(), erase_pass(): Add functions for getting passwords safely
Alex Colomar [Mon, 26 Sep 2022 20:22:24 +0000 (22:22 +0200)] 
libmisc: agetpass(), erase_pass(): Add functions for getting passwords safely

There are several issues with getpass(3).

Many implementations of it share the same issues that the infamous
gets(3).  In glibc it's not so terrible, since it's a wrapper
around getline(3).  But it still has an important bug:

If the password is long enough, getline(3) will realloc(3) memory,
and prefixes of the password will be laying around in some
deallocated memory.

See the getpass(3) manual page for more details, and especially
the commit that marked it as deprecated, which links to a long
discussion in the linux-man@ mailing list.

So, readpassphrase(3bsd) is preferrable, which is provided by
libbsd on GNU systems.  However, using readpassphrase(3) directly
is a bit verbose, so we can write our own wrapper with a simpler
interface similar to that of getpass(3).

One of the benefits of writing our own interface around
readpassphrase(3) is that we can hide there any checks that should
be done always and which would be error-prone to repeat every
time.  For example, check that there was no truncation in the
password.

Also, use malloc(3) to get the buffer, instead of using a global
buffer.  We're not using a multithreaded program (and it wouldn't
make sense to do so), but it's nice to know that the visibility of
our passwords is as limited as possible.

erase_pass() is a clean-up function that handles all clean-up
correctly, including zeroing the entire buffer, and then
free(3)ing the memory.  By using [[gnu::malloc(erase_pass)]], we
make sure that we don't leak the buffers in any case, since the
compiler will be able to enforce clean up.

Link: <https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit?id=7ca189099d73bde954eed2d7fc21732bcc8ddc6b>
Reported-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoDon't 'else' after a 'noreturn' call
Alex Colomar [Tue, 27 Sep 2022 22:03:46 +0000 (00:03 +0200)] 
Don't 'else' after a 'noreturn' call

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoCI: add libbsd and pkg-config dependencies
Iker Pedrosa [Tue, 22 Nov 2022 13:35:06 +0000 (14:35 +0100)] 
CI: add libbsd and pkg-config dependencies

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoFix HAVE_SHADOWGRP configure check
Florian Weimer [Mon, 21 Nov 2022 10:52:45 +0000 (11:52 +0100)] 
Fix HAVE_SHADOWGRP configure check

The missing #include <gshadow.h> causes the configure check to fail
spuriously, resulting in HAVE_SHADOWGRP not being defined even
on systems that actually have sgetsgent (such as current glibc).

2 years agoAllow supplementary groups to be added via config file
Andy Zaugg [Tue, 18 Oct 2022 23:30:14 +0000 (16:30 -0700)] 
Allow supplementary groups to be added via config file

Allow supplementary groups to be set via the /etc/default/useradd config
file. Allowing an administrator to set additonal groups via the GROUPS
configurable and control the default behaviour of useradd.

2 years agouseradd: check if subid range exists for user
Iker Pedrosa [Mon, 24 Oct 2022 08:46:36 +0000 (10:46 +0200)] 
useradd: check if subid range exists for user

Check if a user already has a subid range before assigning one.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2012929

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoRelease 4.13 4.13
Serge Hallyn [Tue, 8 Nov 2022 16:29:30 +0000 (10:29 -0600)] 
Release 4.13

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agoupdate changelog
Serge Hallyn [Tue, 8 Nov 2022 16:28:10 +0000 (10:28 -0600)] 
update changelog

2 years agoDon't warn when failed to open /etc/nsswitch.conf
Serge Hallyn [Mon, 7 Nov 2022 15:54:50 +0000 (09:54 -0600)] 
Don't warn when failed to open /etc/nsswitch.conf

Maybe we should have a debug mode where it's still printed, but
we don't, so let's be quieter.

Closes #557

2 years agouseradd: Fix buffer overflow when using a prefix
David Michael [Sun, 23 Oct 2022 22:51:33 +0000 (18:51 -0400)] 
useradd: Fix buffer overflow when using a prefix

The buffer length did not count the string's trailing null byte.

Signed-off-by: David Michael <fedora.dm0@gmail.com>
2 years agoadduser-old.c: Remove program 495/head
Alejandro Colomar [Fri, 7 Oct 2022 23:58:07 +0000 (01:58 +0200)] 
adduser-old.c: Remove program

This program has 10 calls to gets(3) according to grep(1).  That
makes it a very unsafe program which should not be used at all.
Let's kill the program already.

See what gets(3) has to say:

SYNOPSIS
       #include <stdio.h>

       [[deprecated]] char *gets(char *s);

DESCRIPTION
       Never use this function.

       ...

BUGS
       Never use gets().  Because it is impossible to tell with‐
       out knowing the  data  in  advance  how  many  characters
       gets()  will  read,  and  because gets() will continue to
       store characters past the end of the buffer,  it  is  ex‐
       tremely dangerous to use.  It has been used to break com‐
       puter security.  Use fgets() instead.

       For more information, see CWE‐242 (aka "Use of Inherently
       Dangerous Function") at http://cwe.mitre.org/data/defini‐
       tions/242.html

Acked-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoRaise limit for passwd and shadow entry length
Iker Pedrosa [Fri, 7 Oct 2022 10:36:59 +0000 (12:36 +0200)] 
Raise limit for passwd and shadow entry length

Moreover, include checks to prevent writing entries longer than the
length limit.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1422497

Signed-off-by: Tomáš Mráz <tm@t8m.info>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agolastlog: check for localtime() return value
Iker Pedrosa [Thu, 6 Oct 2022 08:05:44 +0000 (10:05 +0200)] 
lastlog: check for localtime() return value

Signed-off-by: Tomáš Mráz <tm@t8m.info>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agoman: add missing space in useradd.8.xml
Iker Pedrosa [Fri, 7 Oct 2022 10:17:41 +0000 (12:17 +0200)] 
man: add missing space in useradd.8.xml

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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agofix `usermod -rG x y` while user `y` is not in group `x` will cause user `y` add...
xyz [Sat, 27 Aug 2022 02:23:13 +0000 (19:23 -0700)] 
fix `usermod -rG x y` while user `y` is not in group `x` will cause user `y` add into group `x`

2 years agolibmisc: minimum id check for system accounts
Iker Pedrosa [Thu, 6 Oct 2022 09:21:18 +0000 (11:21 +0200)] 
libmisc: minimum id check for system accounts

The minimum id allocation for system accounts shouldn't be 0 as this is
reserved for root.

Signed-off-by: Tomáš Mráz <tm@t8m.info>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agousermod: report error if homedir does not exist
Iker Pedrosa [Wed, 5 Oct 2022 13:20:43 +0000 (15:20 +0200)] 
usermod: report error if homedir does not exist

Report error if usermod asked for moving homedir and it does not exist.

Signed-off-by: Tomáš Mráz <tm@t8m.info>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2 years agochage: Fix regression in print_date
Xiami [Wed, 5 Oct 2022 10:11:28 +0000 (18:11 +0800)] 
chage: Fix regression in print_date

Introduced by c6c8130db4319613a91dd07bbb845f6c33c5f79f

After removing snprintf, the format string should get unescaped once.

Fixes #564

Reporter and patch author: DerMouse (github.com/DerMouse)

2 years agoUse libc MAX() and MIN()
Alejandro Colomar [Wed, 28 Sep 2022 21:19:37 +0000 (23:19 +0200)] 
Use libc MAX() and MIN()

glibc, musl, FreeBSD, and OpenBSD define the MAX() and MIN()
macros in <sys/param.h> with the same definition that we use.
Let's not redefine it here and use the system one, as it's
effectively the same as we define (modulo whitespace).

See:

shadow (previously):

alx@asus5775:~/src/shadow/shadow$ grepc -ktm MAX
./lib/defines.h:318:#define MAX(x,y) (((x) > (y)) ? (x) : (y))

glibc:

alx@asus5775:~/src/gnu/glibc$ grepc -ktm -x 'sys/param.h$' MAX
./misc/sys/param.h:103:#define MAX(a,b) (((a)>(b))?(a):(b))

musl:

alx@asus5775:~/src/musl/musl$ grepc -ktm -x 'sys/param.h$' MAX
./include/sys/param.h:19:#define MAX(a,b) (((a)>(b))?(a):(b))

OpenBSD:

alx@asus5775:~/src/bsd/openbsd/src$ grepc -ktm -x 'sys/param.h$' MAX
./sys/sys/param.h:193:#define MAX(a,b) (((a)>(b))?(a):(b))

FreeBSD:

alx@asus5775:~/src/bsd/freebsd/freebsd-src$ grepc -ktm -x 'sys/param.h$' MAX
./sys/sys/param.h:333:#define MAX(a,b) (((a)>(b))?(a):(b))

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoDon't test for NULL before calling free(3)
Alex Colomar [Wed, 28 Sep 2022 20:03:52 +0000 (22:03 +0200)] 
Don't test for NULL before calling free(3)

free(3) accepts NULL, since the oldest ISO C.  I guess the
paranoid code was taking care of prehistoric implementations of
free(3).  I've never known of an implementation that doesn't
conform to this, so let's simplify this.

Remove xfree(3), which was effectively an equivalent of free(3).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2 years agoupdated Dutch translation
Frans Spiesschaert [Tue, 27 Sep 2022 15:11:02 +0000 (17:11 +0200)] 
updated Dutch translation

2 years agolib: use memzero where applicable
Christian Göttsche [Sat, 17 Sep 2022 16:03:46 +0000 (18:03 +0200)] 
lib: use memzero where applicable

Use memzero when operating in a buffer of known size to clear all bytes
and avoid leaking the size of the stored data.

2 years agolib: use strzero where applicable
Christian Göttsche [Sat, 17 Sep 2022 15:56:49 +0000 (17:56 +0200)] 
lib: use strzero where applicable

Replace `memzero (s, strlen(s))` with just the internal wrapper
`strzero (s)` where the underlying allocated size is not known.

2 years agolib/commonio: make lock failures more detailed
Luca BRUNO [Mon, 29 Aug 2022 12:35:07 +0000 (12:35 +0000)] 
lib/commonio: make lock failures more detailed

This tweaks the database locking logic so that failures in the
link-checking paths are more detailed.
The rationale for this is that I've experienced a non-deterministic
bug which seems to be coming from this logic, and I'd like to get
more details about the actual failing condition.

2 years agocopy_tree: carefully treat permissions
Samanta Navarro [Sat, 10 Sep 2022 11:58:15 +0000 (11:58 +0000)] 
copy_tree: carefully treat permissions

The setuid, setgid, and sticky bits are not copied during copy_tree.

Also start with very restrictive permissions before setting ownerships.

This prevents situations in which users in a group with less permissions
than others could win a race in opening the file before permissions are
removed again.

Proof of concept:

$ echo $HOME
/home/uwu
$ install -o uwu -g fandom -m 604 /dev/null /home/uwu/owo
$ ls -l /home/uwu/owo
-rw----r-- 1 uwu fandom 0 Sep  4 00:00 /home/uwu/owo

If /tmp is on another filesystem, then "usermod -md /tmp/uwu uwu" leads
to this temporary situation:

$ ls -l /tmp/uwu/owo
-rw----r-- 1 root root  0 Sep  4 00:00 /tmp/uwu/owo

This means that between openat and chownat_if_needed a user of group
fandom could open /tmp/uwu/owo and read the content when it is finally
written into the file.

2 years agoci(lint): add shell linter - Differential ShellCheck
Jan Macku [Mon, 12 Sep 2022 08:15:43 +0000 (10:15 +0200)] 
ci(lint): add shell linter - Differential ShellCheck

It performs differential ShellCheck scans and report results directly in pull request.

documentation: https://github.com/redhat-plumbers-in-action/differential-shellcheck

Signed-off-by: Jan Macku <jamacku@redhat.com>
2 years agocopy_tree: do not block on fifos
Samanta Navarro [Sun, 4 Sep 2022 11:58:03 +0000 (11:58 +0000)] 
copy_tree: do not block on fifos

Fixes regression introduced in faeab50e710131816b261de66141524898c2c487.

If a directory contains fifos, then openat blocks until the other side
of the fifo is connected as well.

This means that users can prevent "usermod -m" from completing if their
home directories contain at least one fifo.

2 years agocopy_tree: use fchmodat instead of chmod
Samanta Navarro [Sun, 4 Sep 2022 11:54:19 +0000 (11:54 +0000)] 
copy_tree: use fchmodat instead of chmod

Fixes regression introduced in faeab50e710131816b261de66141524898c2c487
for setups configured without acl support.

2 years agouseradd: check MLS enablement before setting serange Resolves: https://github.com...
genBTC [Tue, 23 Aug 2022 14:25:51 +0000 (10:25 -0400)] 
useradd: check MLS enablement before setting serange Resolves: https://github.com/shadow-maint/shadow/issues/552

2 years agoshadow: use relaxed usernames
Alexander Kanavin [Tue, 16 Aug 2022 11:46:22 +0000 (13:46 +0200)] 
shadow: use relaxed usernames

The groupadd from shadow does not allow upper case group names, the
same is true for the upstream shadow. But distributions like
Debian/Ubuntu/CentOS has their own way to cope with this problem,
this patch is picked up from Fedora [1] to relax the usernames
restrictions to allow the upper case group names, and the relaxation is
POSIX compliant because POSIX indicate that usernames are composed of
characters from the portable filename character set [A-Za-z0-9._-].

[1] https://src.fedoraproject.org/rpms/shadow-utils/blob/rawhide/f/shadow-4.8-goodname.patch

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
2 years agopo: Georgian translation
NorwayFun [Mon, 22 Aug 2022 00:38:43 +0000 (02:38 +0200)] 
po: Georgian translation

po: Georgian translation

2 years agopo: Georgian translation
NorwayFun [Mon, 22 Aug 2022 00:37:21 +0000 (02:37 +0200)] 
po: Georgian translation

po: Georgian translation

2 years agouseradd: Do not reset non-existent data in {last,fail}log
David Kalnischkies [Wed, 24 Aug 2022 11:21:01 +0000 (13:21 +0200)] 
useradd: Do not reset non-existent data in {last,fail}log

useradd does not create the files if they don't exist, but if they exist
it will reset user data even if the data did not exist before creating
a hole and an explicitly zero'd data point resulting (especially for
high UIDs) in a lot of zeros ending up in containers and tarballs.

2 years agoRevert "Drop unused function subid_init()"
Serge Hallyn [Sun, 21 Aug 2022 18:14:37 +0000 (13:14 -0500)] 
Revert "Drop unused function subid_init()"

As rbalint points out, this was an exported fn.  It also is
the only way for a libsubid user to do what it does, so let's
not drop it.

This reverts commit 477c8e6f42df1e17e45584e74988eb46a11e6caa.

2 years agouseradd.8.xml: fix default group id from 100 to 1000 according to bbf4b79
Tim Biermann [Fri, 19 Aug 2022 20:31:01 +0000 (22:31 +0200)] 
useradd.8.xml: fix default group id from 100 to 1000 according to bbf4b79

2 years agoRelease 4.12.2 with CVE fix 4.12.2
Serge Hallyn [Thu, 18 Aug 2022 21:54:21 +0000 (16:54 -0500)] 
Release 4.12.2 with CVE fix

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agoAvoid races in copy_tree()
Christian Göttsche [Fri, 5 Aug 2022 15:57:32 +0000 (17:57 +0200)] 
Avoid races in copy_tree()

Use *at() functions to pin the directory operating in to avoid being
redirected by unprivileged users replacing parts of paths by symlinks to
privileged files.

Introduce a path_info struct with the full path and dirfd and name
information for *at() functions, since the full path is needed for link
resolution, SELinux label lookup and ACL attributes.

2 years agoAddress minor compiler warnings
Christian Göttsche [Fri, 5 Aug 2022 15:57:29 +0000 (17:57 +0200)] 
Address minor compiler warnings

    copydir.c:666:44: warning: unsigned conversion from 'int' to '__mode_t' {aka 'unsigned int'} changes value from '-4096' to '4294963200' [-Wsign-conversion]
      666 |         if (   (mknod (dst, statp->st_mode & ~07777, statp->st_rdev) != 0)
          |                                            ^

    copydir.c:116:1: warning: missing initializer for field 'quote' of 'struct error_context' [-Wmissing-field-initializers]
      116 | };
          | ^
    In file included from copydir.c:27:
    /usr/include/attr/error_context.h:30:23: note: 'quote' declared here
       30 |         const char *(*quote) (struct error_context *, const char *);
          |                       ^~~~~

2 years agoMore robust file content copy in copy_tree()
Christian Göttsche [Fri, 5 Aug 2022 15:57:27 +0000 (17:57 +0200)] 
More robust file content copy in copy_tree()

Bail out on read(2) failure, continue on EINTR, support short writes and
increase chunk size.

2 years agoFail if regular file pre-exists in copy_tree()
Christian Göttsche [Fri, 5 Aug 2022 15:57:26 +0000 (17:57 +0200)] 
Fail if regular file pre-exists in copy_tree()

Similar to the default behavior of mkdir(2), symlink(2), link(2) and
mknod(2).

2 years agoRequire symlink support
Christian Göttsche [Fri, 5 Aug 2022 15:57:24 +0000 (17:57 +0200)] 
Require symlink support

Require lstat(2), lchown(2), S_IFLNK and S_ISLNK from POSIX.1-2001.

Already unconditionally used in lib/tcbfuncs.c and lib/run_part.c.

2 years agoAvoid races in remove_tree()
Christian Göttsche [Fri, 5 Aug 2022 15:57:22 +0000 (17:57 +0200)] 
Avoid races in remove_tree()

Use *at() functions to pin the directory operating in to avoid being
redirected by unprivileged users replacing parts of paths by symlinks to
privileged files.

2 years agoAvoid races in chown_tree()
Christian Göttsche [Fri, 5 Aug 2022 15:57:19 +0000 (17:57 +0200)] 
Avoid races in chown_tree()

Use *at() functions to pin the directory operating in to avoid being
redirected by unprivileged users replacing parts of paths by symlinks to
privileged files.

2 years agoRelease 4.12 4.12.1
Serge Hallyn [Mon, 15 Aug 2022 17:16:41 +0000 (12:16 -0500)] 
Release 4.12

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agouk has no limits.5 translation
Serge Hallyn [Fri, 12 Aug 2022 18:11:56 +0000 (13:11 -0500)] 
uk has no limits.5 translation

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agoAdd uk to list of man subdirs
Serge Hallyn [Fri, 12 Aug 2022 17:29:50 +0000 (12:29 -0500)] 
Add uk to list of man subdirs

Closes #547

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agoRelease 4.12 4.12
Serge Hallyn [Thu, 11 Aug 2022 16:04:18 +0000 (11:04 -0500)] 
Release 4.12

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2 years agoUpdate changelog
Serge Hallyn [Mon, 8 Aug 2022 23:56:41 +0000 (18:56 -0500)] 
Update changelog

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agolibmisc/root_flag: add tips for --root flag only support abspath
Celeste Liu [Wed, 27 Jul 2022 15:06:36 +0000 (23:06 +0800)] 
libmisc/root_flag: add tips for --root flag only support abspath

- Add tips in error message.
- Add tips in man.
- Add zh_CN and zh_TW for tips.

Signed-off-by: Celeste Liu <coelacanthus@outlook.com>
3 years agoUse function format attribute where applicable
Christian Göttsche [Fri, 5 Aug 2022 15:40:42 +0000 (17:40 +0200)] 
Use function format attribute where applicable

Allow the compiler to verify the format string against the supplied
arguments.

    chage.c:239:51: warning: format not a string literal, format string not checked [-Wformat-nonliteral]
      239 |                 (void) strftime (buf, sizeof buf, format, tp);
          |                                                   ^~~~~~

3 years agoDrop unused function subid_init()
Christian Göttsche [Fri, 5 Aug 2022 15:40:39 +0000 (17:40 +0200)] 
Drop unused function subid_init()

3 years agoDrop obsolete prototype for log_dolog()
Christian Göttsche [Fri, 5 Aug 2022 15:40:37 +0000 (17:40 +0200)] 
Drop obsolete prototype for log_dolog()

log_dolog() is neither implemented nor used.

3 years agoDrop superfluous const from return type
Christian Göttsche [Fri, 5 Aug 2022 15:40:36 +0000 (17:40 +0200)] 
Drop superfluous const from return type

    salt.c:102:22: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
      102 | static /*@observer@*/const unsigned long SHA_get_salt_rounds (/*@null@*/int *prefered_rounds);
          |                      ^~~~~
    salt.c:110:22: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
      110 | static /*@observer@*/const unsigned long YESCRYPT_get_salt_cost (/*@null@*/int *prefered_cost);
          |                      ^~~~~

    subordinateio.c:160:8: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
      160 | static const bool range_exists(struct commonio_db *db, const char *owner)
          |        ^~~~~

3 years agoAdd include for uid_t
Christian Göttsche [Fri, 5 Aug 2022 15:40:34 +0000 (17:40 +0200)] 
Add include for uid_t

Allow IDEs to parse the header file on its own.

3 years agoDrop unnecessary prototype
Christian Göttsche [Fri, 5 Aug 2022 15:40:33 +0000 (17:40 +0200)] 
Drop unnecessary prototype

The function is defined directly after.

3 years agoDeclare read-only data const
Christian Göttsche [Fri, 5 Aug 2022 15:40:31 +0000 (17:40 +0200)] 
Declare read-only data const

3 years agoDrop register keyword
Christian Göttsche [Fri, 5 Aug 2022 15:40:29 +0000 (17:40 +0200)] 
Drop register keyword

Compilers are free to ignore the indented hint and modern optimizations
should create good code by themself.

(As such it is for example deprecated in C++17.)

3 years agoReturn void pointer from xmalloc
Christian Göttsche [Fri, 5 Aug 2022 15:40:28 +0000 (17:40 +0200)] 
Return void pointer from xmalloc

xmalloc is a wrapper around malloc(3), which bails out on OOM failures.
As such it returns raw memory and is used to allocated all kind of
types.

3 years agoDeclare read-only parameters const
Christian Göttsche [Fri, 5 Aug 2022 15:40:26 +0000 (17:40 +0200)] 
Declare read-only parameters const

Signal callers arguments are not going to be modified and allow passing
const pointers.

3 years agopo: update translations
Christian Göttsche [Fri, 5 Aug 2022 15:40:24 +0000 (17:40 +0200)] 
po: update translations

Add language identifiers and fix line break.

3 years agoconfigure.ac: bump gettext version
Christian Göttsche [Fri, 5 Aug 2022 15:40:21 +0000 (17:40 +0200)] 
configure.ac: bump gettext version

Version 1.19.1 was released in June 2014.

    configure.ac:697: warning: AM_PROG_MKDIR_P: this macro is deprecated, and will soon be removed.
    configure.ac:697: You should use the Autoconf-provided 'AC_PROG_MKDIR_P' macro instead,
    configure.ac:697: and use '$(MKDIR_P)' instead of '$(mkdir_p)'in your Makefile.am files.
    ./lib/autoconf/general.m4:2434: AC_DIAGNOSE is expanded from...
    aclocal.m4:780: AM_PROG_MKDIR_P is expanded from...
    m4/po.m4:23: AM_PO_SUBDIRS is expanded from...
    m4/gettext.m4:57: AM_GNU_GETTEXT is expanded from...
    configure.ac:697: the top level
    configure.ac:697: warning: The macro `AC_TRY_LINK' is obsolete.
    configure.ac:697: You should run autoupdate.
    ./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
    lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
    lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
    ./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
    ./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from...
    m4/gettext.m4:365: gt_INTL_MACOSX is expanded from...
    m4/gettext.m4:57: AM_GNU_GETTEXT is expanded from...
    configure.ac:697: the top level
    configure.ac:697: warning: The macro `AC_TRY_LINK' is obsolete.
    configure.ac:697: You should run autoupdate.
    ./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
    lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
    lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
    ./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
    ./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from...
    m4/gettext.m4:57: AM_GNU_GETTEXT is expanded from...
    configure.ac:697: the top level
    configure.ac:697: warning: The macro `AC_TRY_LINK' is obsolete.
    configure.ac:697: You should run autoupdate.
    ./lib/autoconf/general.m4:2920: AC_TRY_LINK is expanded from...
    lib/m4sugar/m4sh.m4:692: _AS_IF_ELSE is expanded from...
    lib/m4sugar/m4sh.m4:699: AS_IF is expanded from...
    ./lib/autoconf/general.m4:2249: AC_CACHE_VAL is expanded from...
    ./lib/autoconf/general.m4:2270: AC_CACHE_CHECK is expanded from...
    m4/iconv.m4:20: AM_ICONV_LINK is expanded from...
    m4/gettext.m4:57: AM_GNU_GETTEXT is expanded from...
    configure.ac:697: the top level

3 years agoconfigure.ac: replace deprecated aliases
Christian Göttsche [Fri, 5 Aug 2022 15:40:12 +0000 (17:40 +0200)] 
configure.ac: replace deprecated aliases

See https://www.gnu.org/software/libtool/manual/html_node/LT_005fINIT.html

    configure.ac:25: warning: The macro `AM_ENABLE_STATIC' is obsolete.
    configure.ac:25: You should run autoupdate.
    m4/ltoptions.m4:259: AM_ENABLE_STATIC is expanded from...
    configure.ac:25: the top level
    configure.ac:26: warning: The macro `AM_ENABLE_SHARED' is obsolete.
    configure.ac:26: You should run autoupdate.
    m4/ltoptions.m4:205: AM_ENABLE_SHARED is expanded from...
    configure.ac:26: the top level

3 years agoFix E_NAME_IN_USE documentation.
Jeremy Whiting [Wed, 27 Jul 2022 18:02:12 +0000 (12:02 -0600)] 
Fix E_NAME_IN_USE documentation.

Since code gives this error if username or group name is already
used the documentation should reflect that.

3 years agoFix CI by testing Ubuntu 22.04 instead of 21.10.
Jeremy Whiting [Sat, 6 Aug 2022 15:48:53 +0000 (09:48 -0600)] 
Fix CI by testing Ubuntu 22.04 instead of 21.10.

Since Ubuntu 21.10 has gone out of support it no longer works for
testing with CI. Instead use 22.04 which is still supported.

3 years agotests: add a case for testing -F option of useradd
Masatake YAMATO [Wed, 20 Jul 2022 08:40:11 +0000 (17:40 +0900)] 
tests: add a case for testing -F option of useradd

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agouseradd: add -F option for updating /etc/sub[ig]id for system accounts
Masatake YAMATO [Wed, 20 Jul 2022 02:17:16 +0000 (11:17 +0900)] 
useradd: add -F option for updating /etc/sub[ig]id for system accounts

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agouseradd: make the option specstr passed to getopt_long extensible
Masatake YAMATO [Wed, 20 Jul 2022 01:43:02 +0000 (10:43 +0900)] 
useradd: make the option specstr passed to getopt_long extensible

It was hard to extend the option specification string passed to
getopt_long as the third argument.

The origian code had a branch with WITH_SELINUX ifdef condition. If
one wants to add one more option char with another ifdef condition
like ENABLE_SUBIDS to the spec, the one must enumerate the specs for
all combinations of the conditions:

*  WITH_SELINUX &&  ENABLE_SUBIDS
*  WITH_SELINUX && !ENABLE_SUBIDS
* !WITH_SELINUX &&  ENABLE_SUBIDS
* !WITH_SELINUX && !ENABLE_SUBIDS

With this change, you can append an option char to the spec.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agosubordinateio: also compare the owner ID
Iker Pedrosa [Wed, 13 Jul 2022 07:55:14 +0000 (09:55 +0200)] 
subordinateio: also compare the owner ID

IDs already populate /etc/subuid and /etc/subgid files so it's necessary
not only to check for the owner name but also for the owner ID of a
given range.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2093311

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 years agoman (useradd): add a note about -r option and /etc/subuid and subgid
Masatake YAMATO [Wed, 13 Jul 2022 16:58:33 +0000 (01:58 +0900)] 
man (useradd): add a note about -r option and /etc/subuid and subgid

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
3 years agoFix typo
Alexander Zhang [Wed, 6 Jul 2022 21:41:09 +0000 (14:41 -0700)] 
Fix typo

3 years agofix Changelog typo
Serge Hallyn [Tue, 5 Jul 2022 13:49:15 +0000 (08:49 -0500)] 
fix Changelog typo

Spotted by cgzones.

3 years agoUpdate changelog
Serge Hallyn [Mon, 4 Jul 2022 19:30:09 +0000 (14:30 -0500)] 
Update changelog

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agolibmisc: use /dev/urandom as a generic fallback for read_random_bytes()
Xi Ruoyao [Mon, 13 Jun 2022 08:44:14 +0000 (16:44 +0800)] 
libmisc: use /dev/urandom as a generic fallback for read_random_bytes()

On systems with Linux kernel < 3.17, getentropy() and getrandom() may
exist but return ENOSYS.  Use /dev/urandom as a fallback to avoid a hard
requirement on Linux kernel version.

Fixes #512.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
3 years agoCI: update actions version
Iker Pedrosa [Wed, 1 Jun 2022 11:22:22 +0000 (13:22 +0200)] 
CI: update actions version

CodeQL Action v1 is being deprecated and v2 needs to be used instead.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 years agoCI: enable CodeQL analyzer
Iker Pedrosa [Mon, 9 May 2022 14:06:38 +0000 (16:06 +0200)] 
CI: enable CodeQL analyzer

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 years agoCI: create Github workflow to install dependencies
Iker Pedrosa [Mon, 9 May 2022 14:17:57 +0000 (16:17 +0200)] 
CI: create Github workflow to install dependencies

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 years agoComplete Ukrainian translation
Yuri Chornoivan [Sat, 21 May 2022 17:49:25 +0000 (20:49 +0300)] 
Complete Ukrainian translation

3 years agoUpdate Ukrainian translation
Yuri Chornoivan [Fri, 20 May 2022 18:46:54 +0000 (21:46 +0300)] 
Update Ukrainian translation

3 years agoAdd Ukrainian translation for man pages
Yuri Chornoivan [Thu, 19 May 2022 19:01:55 +0000 (22:01 +0300)] 
Add Ukrainian translation for man pages

3 years agoInitialize local variables
Iker Pedrosa [Mon, 16 May 2022 15:24:58 +0000 (17:24 +0200)] 
Initialize local variables

CWE-457 by CodeQL.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 years agoAdd header guards
Iker Pedrosa [Tue, 10 May 2022 13:26:15 +0000 (15:26 +0200)] 
Add header guards

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>