]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
4 years agoInstall subid.h 330/head
Serge Hallyn [Tue, 4 May 2021 14:21:11 +0000 (09:21 -0500)] 
Install subid.h

Now subid.h gets installed under /usr/include/shadow/subid.h

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #321 from hallyn/2021-04-08/nss
Serge Hallyn [Sat, 17 Apr 2021 02:03:37 +0000 (21:03 -0500)] 
Merge pull request #321 from hallyn/2021-04-08/nss

Subids: support nsswitch

4 years agotests: fix su failures under travis 321/head
Serge Hallyn [Tue, 13 Apr 2021 03:37:23 +0000 (22:37 -0500)] 
tests: fix su failures under travis

HOME has to start as /root since we are testing
that su didn't change it.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agosu/03: export shell = sh
Serge Hallyn [Mon, 12 Apr 2021 03:14:27 +0000 (22:14 -0500)] 
su/03: export shell = sh

Otherwise our su -p uses bash if that is what root was
configured to use, and then fails to read /root/ for
.bash_profile.  This caused an unexpected error message
in /tmp/err, failing the test.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agotest: su -p doesn't set home
Serge Hallyn [Mon, 12 Apr 2021 02:39:31 +0000 (21:39 -0500)] 
test: su -p doesn't set home

with out also doing '-'

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoclean up libsubid headers
Serge Hallyn [Thu, 15 Apr 2021 14:52:29 +0000 (09:52 -0500)] 
clean up libsubid headers

Move libsubid/api.h into libsubid/subid.h, and document the api in subid.h

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agosubids: support nsswitch
Serge Hallyn [Sun, 31 Jan 2021 23:38:20 +0000 (17:38 -0600)] 
subids: support nsswitch

Closes #154

When starting any operation to do with subuid delegation, check
nsswitch for a module to use.  If none is specified, then use
the traditional /etc/subuid and /etc/subgid files.

Currently only one module is supported, and there is no fallback
to the files on errors.  Several possibilities could be considered:

1. in case of connection error, fall back to files
2. in case of unknown user, also fall back to files

etc...

When non-files nss module is used, functions to edit the range
are not supported.  It may make sense to support it, but it also
may make sense to require another tool to be used.

libsubordinateio also uses the nss_ helpers.  This is how for instance
lxc could easily be converted to supporting nsswitch.

Add a set of test cases, including a dummy libsubid_zzz module.  This
hardcodes values such that:

'ubuntu' gets 200000 - 300000
'user1' gets 100000 - 165536
'error' emulates an nss module error
'unknown' emulates a user unknown to the nss module
'conn' emulates a connection error ot the nss module

Changes to libsubid:

Change the list_owner_ranges api: return a count instead of making the array
null terminated.

This is a breaking change, so bump the libsubid abi major number.

Rename free_subuid_range and free_subgid_range to ungrant_subuid_range,
because otherwise it's confusing with free_subid_ranges which frees
    memory.

Run libsubid tests in jenkins

Switch argument order in find_subid_owners

Move the db locking into subordinateio.c

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agotry again to fix libmisc sharing problem
Serge Hallyn [Mon, 1 Feb 2021 04:44:09 +0000 (22:44 -0600)] 
try again to fix libmisc sharing problem

Issue #297 reported seeing

*** Warning: Linking the shared library libsubid.la against the
*** static library ../libmisc/libmisc.a is not portable!

which commit b5fb1b38eea2fb0489ed088c82daf6700e72363e was supposed
to fix.  But a few commits later it's back.  So try to fix it
in the way the bug reporter suggested.  This broke builds some
other ways, namely a few missing library specifications, so add
those.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #314 from sevan/patch-1
Serge Hallyn [Tue, 30 Mar 2021 15:21:17 +0000 (10:21 -0500)] 
Merge pull request #314 from sevan/patch-1

passwd(5): Note the use of an ampersand in the comment field

4 years agoman: include lastlog file caveat (#313)
Iker Pedrosa [Mon, 29 Mar 2021 03:26:28 +0000 (05:26 +0200)] 
man: include lastlog file caveat (#313)

man/lastlog.8.xml: add another point to the caveats section regarding
the handling of the lastlog file by external tools.

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

4 years agologin & su: Treat an empty passwd field as invalid (#315)
Haelwenn Monnier [Mon, 29 Mar 2021 03:16:03 +0000 (05:16 +0200)] 
login & su: Treat an empty passwd field as invalid (#315)

* login & su: Treat an empty passwd field as invalid

Otherwise it's treated like the “require no password” clause while it probably
should be treated like a normal su that can't validate anyway.

A similar change should be done for USE_PAM.

* su & login: Introduce PREVENT_NO_AUTH

4 years agoMerge pull request #303 from breard-r/yescrypt
Serge Hallyn [Mon, 29 Mar 2021 03:13:56 +0000 (22:13 -0500)] 
Merge pull request #303 from breard-r/yescrypt

Add yescrypt support

4 years agoNote the use of an ampersand in the comment field 314/head
Sevan Janiyan [Fri, 12 Mar 2021 23:56:38 +0000 (23:56 +0000)] 
Note the use of an ampersand in the comment field

4 years agoMerge pull request #308 from martijndegouw/relaxgidcheck
Serge Hallyn [Tue, 2 Mar 2021 18:42:25 +0000 (12:42 -0600)] 
Merge pull request #308 from martijndegouw/relaxgidcheck

newuidmap,newgidmap: Relax gid checking to allow running under alternative group ID

4 years agoMerge pull request #310 from ikerexxe/upstream_man_clarifications
Serge Hallyn [Mon, 1 Mar 2021 16:02:44 +0000 (10:02 -0600)] 
Merge pull request #310 from ikerexxe/upstream_man_clarifications

Man clarifications

4 years agoMerge pull request #311 from ikerexxe/upstream_userdel_clarification
Serge Hallyn [Mon, 1 Mar 2021 15:59:14 +0000 (09:59 -0600)] 
Merge pull request #311 from ikerexxe/upstream_userdel_clarification

userdel: clarify "-f" usage

4 years agouserdel: clarify "-f" usage 311/head
ikerexxe [Tue, 23 Feb 2021 11:21:42 +0000 (12:21 +0100)] 
userdel: clarify "-f" usage

src/userdel.c: clarify the examples for "-f" option

4 years agoman: usermod clarification 310/head
ikerexxe [Tue, 2 Feb 2021 10:27:17 +0000 (11:27 +0100)] 
man: usermod clarification

man/usermod.8.xml: specify what happens when the current home directory
doesn't exist if using -d and -m options. Moreover, specify what happens
when the group ownership is changed and the uid's don't match in -u and
-g options.

4 years agoman: useradd clarification
ikerexxe [Tue, 2 Feb 2021 10:25:03 +0000 (11:25 +0100)] 
man: useradd clarification

man/useradd.8.xml: specify the SELinux requirements for -m option.

4 years agoman: shadow clarification
ikerexxe [Tue, 2 Feb 2021 10:21:12 +0000 (11:21 +0100)] 
man: shadow clarification

man/shadow.5.xml: indicate the exact time and timezone for the dates.
Moreover, clarify that when the password expires the user won't be able
to login.

4 years agoman: groupadd and groupmod clarification
ikerexxe [Tue, 2 Feb 2021 10:19:58 +0000 (11:19 +0100)] 
man: groupadd and groupmod clarification

man/groupadd.8.xml: clarify the exit values meaning.
man/groupmod.8.xml: clarify the E_GID_IN_USE value meaning.

4 years agoMerge pull request #307 from glysbaysb/usermod-shell-path
Serge Hallyn [Mon, 8 Feb 2021 16:03:11 +0000 (10:03 -0600)] 
Merge pull request #307 from glysbaysb/usermod-shell-path

usermod: check if shell is know

4 years agoAdd tests for group checking in newuidmap/newgidmap 308/head
Martijn de Gouw [Mon, 8 Feb 2021 12:20:04 +0000 (13:20 +0100)] 
Add tests for group checking in newuidmap/newgidmap

4 years agonewuidmap,newgidmap: Relax gid checking to allow running under alternative group ID
Martijn de Gouw [Thu, 7 Jan 2021 11:15:25 +0000 (12:15 +0100)] 
newuidmap,newgidmap: Relax gid checking to allow running under alternative group ID

Signed-off-by: Martijn de Gouw <martijn.de.gouw@prodrive-technologies.com>
4 years agousermod expects a path 307/head
Geert Ijewski [Sun, 7 Feb 2021 18:30:05 +0000 (19:30 +0100)] 
usermod expects a path

Closes #307

4 years agousermod: check if shell exists & is executable
Geert Ijewski [Sun, 7 Feb 2021 18:26:55 +0000 (19:26 +0100)] 
usermod: check if shell exists & is executable

4 years agoman: chage clarification
ikerexxe [Tue, 2 Feb 2021 09:24:32 +0000 (10:24 +0100)] 
man: chage clarification

man/chage.1.xml: Indicate that -d option with a value of 0 forces the
user to change his password. Besides, set an example on how to use -E
option. Finally, add a general note to clarify that chage only takes
charge of local users and another note to indicate that it doesn't check
inconsistencies between shadow and passwd files.

4 years agoAdd yescrypt support 303/head
Rodolphe Bréard [Sun, 27 Dec 2020 20:09:25 +0000 (21:09 +0100)] 
Add yescrypt support

4 years agoMerge pull request #306 from hallyn/2021-01-01/nosubids
Serge Hallyn [Fri, 1 Jan 2021 19:10:53 +0000 (13:10 -0600)] 
Merge pull request #306 from hallyn/2021-01-01/nosubids

useradd: don't try to create 0 subuids

4 years agouseradd: don't try to create 0 subuids 306/head
Serge Hallyn [Fri, 1 Jan 2021 19:10:12 +0000 (13:10 -0600)] 
useradd: don't try to create 0 subuids

Closes #289

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #305 from hallyn/2021-01-01/static-dynamic
Serge Hallyn [Fri, 1 Jan 2021 19:05:33 +0000 (13:05 -0600)] 
Merge pull request #305 from hallyn/2021-01-01/static-dynamic

libsubid: move libmisc.a to last LIBADD entry

4 years agolibsubid: move libmisc.a to last LIBADD entry 305/head
Serge Hallyn [Fri, 1 Jan 2021 19:01:54 +0000 (13:01 -0600)] 
libsubid: move libmisc.a to last LIBADD entry

Closes #297

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #302 from whzhe51/br_master
Serge Hallyn [Sun, 27 Dec 2020 06:37:46 +0000 (00:37 -0600)] 
Merge pull request #302 from whzhe51/br_master

useradd.c:fix memleaks of grp

4 years agoMerge pull request #301 from whzhe51/br_whzhe
Serge Hallyn [Sun, 27 Dec 2020 06:31:30 +0000 (00:31 -0600)] 
Merge pull request #301 from whzhe51/br_whzhe

useradd.c:fix memleak in get_groups

4 years agoMerge pull request #299 from lnussel/master
Serge Hallyn [Sun, 27 Dec 2020 06:26:47 +0000 (00:26 -0600)] 
Merge pull request #299 from lnussel/master

useradd: use built-in settings by default

4 years agoMerge pull request #296 from ikerexxe/log_exit_code
Serge Hallyn [Sun, 27 Dec 2020 06:18:12 +0000 (00:18 -0600)] 
Merge pull request #296 from ikerexxe/log_exit_code

useradd: log exit code when failing

4 years agoMerge pull request #295 from ikerexxe/newusers_clarification
Serge Hallyn [Sun, 27 Dec 2020 06:16:18 +0000 (00:16 -0600)] 
Merge pull request #295 from ikerexxe/newusers_clarification

newusers: doesn't create parent home directories

4 years agouseradd.c:fix memleak in get_groups 301/head
whzhe [Thu, 17 Dec 2020 08:27:15 +0000 (03:27 -0500)] 
useradd.c:fix memleak in get_groups

Signed-off-by: whzhe <wanghongzhe@huawei.com>
4 years agouseradd.c:fix memleaks of grp 302/head
whzhe51 [Sat, 19 Dec 2020 09:29:06 +0000 (04:29 -0500)] 
useradd.c:fix memleaks of grp
Signed-off-by: whzhe51 <wanghongzhe@huawei.com>
4 years agouseradd: use built-in settings by default 299/head
Ludwig Nussel [Thu, 3 Dec 2020 17:05:59 +0000 (18:05 +0100)] 
useradd: use built-in settings by default

Avoids installing inconsistent settings. The correct ones would be
written as soon as an admin uses useradd -D to modify the defaults.

4 years agouseradd: log exit code when failing 296/head
ikerexxe [Tue, 17 Nov 2020 15:58:40 +0000 (16:58 +0100)] 
useradd: log exit code when failing

src/useradd.c: log exit code when failing

4 years agonewusers: doesn't create parent home directories 295/head
ikerexxe [Tue, 17 Nov 2020 15:46:10 +0000 (16:46 +0100)] 
newusers: doesn't create parent home directories

man/newusers.8.xml: clarify that newusers doesn't create parent
directories of the new user's home directory.

4 years agoMerge pull request #293 from ikerexxe/sync_file_write
Serge Hallyn [Sun, 8 Nov 2020 22:36:36 +0000 (16:36 -0600)] 
Merge pull request #293 from ikerexxe/sync_file_write

commonio: force lock file sync

4 years agoMerge pull request #291 from ikerexxe/covscan_issues
Serge Hallyn [Sun, 8 Nov 2020 22:33:55 +0000 (16:33 -0600)] 
Merge pull request #291 from ikerexxe/covscan_issues

Two covscan issues

4 years agoMerge pull request #290 from jamincollins/master
Serge Hallyn [Sun, 8 Nov 2020 22:29:29 +0000 (16:29 -0600)] 
Merge pull request #290 from jamincollins/master

add parsing support for advertised force long opt

4 years agocommonio: force lock file sync 293/head
ikerexxe [Mon, 2 Nov 2020 16:08:55 +0000 (17:08 +0100)] 
commonio: force lock file sync

lib/commonio.c: after writing to the lock file, force a file sync to
the storage system.

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

4 years agoupdate groupdel man page for the --force option 290/head
Jamin W. Collins [Mon, 2 Nov 2020 00:24:49 +0000 (17:24 -0700)] 
update groupdel man page for the --force option

Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>
4 years agouseradd: free grp to avoid leak 291/head
ikerexxe [Tue, 27 Oct 2020 10:35:53 +0000 (11:35 +0100)] 
useradd: free grp to avoid leak

covscan issue:
Error: RESOURCE_LEAK (CWE-772): [#def39] [important]
src/useradd.c:728: alloc_fn: Storage is returned from allocation function "get_local_group".
src/useradd.c:728: var_assign: Assigning: "grp" = storage returned from "get_local_group(list)".
src/useradd.c:728: overwrite_var: Overwriting "grp" in "grp = get_local_group(list)" leaks the storage that "grp" points to.
726|     * GID values, otherwise the string is looked up as is.
727|     */
728|->  grp = get_local_group (list);
729|
730|    /*

4 years agonewgrp: delete dead code
ikerexxe [Tue, 27 Oct 2020 10:33:46 +0000 (11:33 +0100)] 
newgrp: delete dead code

covscan issue:
Error: CLANG_WARNING: [#def31]
src/newgrp.c:448:2: warning: Value stored to 'gid' is never read [deadcode.DeadStores]
gid = getgid ();

4 years agoadd parsing support for advertised force long opt
Jamin W. Collins [Sat, 17 Oct 2020 16:18:30 +0000 (09:18 -0700)] 
add parsing support for advertised force long opt

Existing help output advertises --force as a long opt.

  -f, --force                   delete group even if it is the primary group of a user

But errors when the long opt is used.

groupdel: unrecognized option '--force'

Signed-off-by: Jamin W. Collins <jamin.collins@gmail.com>
4 years agoMerge pull request #288 from whzhe51/br_whzhe
Serge Hallyn [Fri, 16 Oct 2020 14:59:34 +0000 (09:59 -0500)] 
Merge pull request #288 from whzhe51/br_whzhe

xfree: move xfree() function to xmalloc.c

4 years agoxfree: move xfree() function to xmalloc.c 288/head
w00475903 [Tue, 13 Oct 2020 01:29:37 +0000 (21:29 -0400)] 
xfree: move xfree() function to xmalloc.c

Signed-off-by: whzhe <wanghongzhe@huawei.com>
4 years agoMerge pull request #286 from karelzak/defs
Serge Hallyn [Mon, 12 Oct 2020 13:40:50 +0000 (08:40 -0500)] 
Merge pull request #286 from karelzak/defs

getdefs: add foreign (non-shadow-utils) items

4 years agoMerge pull request #285 from masmullin2000/master
Serge Hallyn [Mon, 12 Oct 2020 13:36:33 +0000 (08:36 -0500)] 
Merge pull request #285 from masmullin2000/master

Fix the undefined xfree issue

4 years agogetdefs: add foreign (non-shadow-utils) items 286/head
Karel Zak [Thu, 8 Oct 2020 10:17:30 +0000 (12:17 +0200)] 
getdefs: add foreign (non-shadow-utils) items

The login.defs is shared between more upstream projects (util-linux,
etc.). We need to improve compatibility between the projects do not
report valid, but foreign items.

Addresses: https://github.com/shadow-maint/shadow/issues/276
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoUse {} to kep more in line with code style 285/head
Michael Mullin [Sat, 3 Oct 2020 18:23:06 +0000 (14:23 -0400)] 
Use {} to kep more in line with code style

4 years agoFix the undefined xfree issue
Michael Mullin [Sat, 3 Oct 2020 18:19:46 +0000 (14:19 -0400)] 
Fix the undefined xfree issue

4 years agoMerge pull request #282 from ikerexxe/sssd_cache_error
Serge Hallyn [Sat, 3 Oct 2020 00:38:35 +0000 (19:38 -0500)] 
Merge pull request #282 from ikerexxe/sssd_cache_error

lib/sssd: redirect warning message to file

4 years agoMerge pull request #277 from whzhe51/br_whzhe
Serge Hallyn [Sat, 3 Oct 2020 00:37:20 +0000 (19:37 -0500)] 
Merge pull request #277 from whzhe51/br_whzhe

gpasswd.c: fix memory leak in sg_adm

4 years agolib/sssd: redirect warning message to file 282/head
ikerexxe [Fri, 2 Oct 2020 14:09:42 +0000 (16:09 +0200)] 
lib/sssd: redirect warning message to file

Instead of printing warning in stderr print it to file. This way the
user is not spammed with unnecessary messages when updating packages.

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

4 years agoMerge pull request #281 from towerpark/fix-newxidmap-man
Serge Hallyn [Thu, 1 Oct 2020 18:26:11 +0000 (13:26 -0500)] 
Merge pull request #281 from towerpark/fix-newxidmap-man

Fix the inaccurate description about ID range in man new{u,g}idmap

4 years agoFix the inaccurate description about the ID range to be verified against /etc/sub... 281/head
towerpark [Sat, 26 Sep 2020 12:01:01 +0000 (21:01 +0900)] 
Fix the inaccurate description about the ID range to be verified against /etc/sub{u,g}id.

4 years agogpasswd.c: fix memory leak in sg_adm 277/head
w00475903 [Wed, 16 Sep 2020 08:15:06 +0000 (04:15 -0400)] 
gpasswd.c: fix memory leak in sg_adm

Signed-off-by: whzhe <wanghongzhe@huawei.com>
4 years agoMerge pull request #279 from juergenhoetzel/fix-de-translation
Serge Hallyn [Fri, 25 Sep 2020 02:59:58 +0000 (21:59 -0500)] 
Merge pull request #279 from juergenhoetzel/fix-de-translation

Fix incorrect translation (de)

4 years agoMerge pull request #278 from edneville/104_su_waitpid
Serge Hallyn [Fri, 25 Sep 2020 02:58:35 +0000 (21:58 -0500)] 
Merge pull request #278 from edneville/104_su_waitpid

loop until waitpid returns pid_child or error

4 years agoFix incorrect translation (de) 279/head
Juergen Hoetzel [Tue, 22 Sep 2020 14:00:00 +0000 (16:00 +0200)] 
Fix incorrect translation (de)

4 years agoloop until waitpid returns pid_child or error 278/head
ed neville [Sun, 20 Sep 2020 22:02:58 +0000 (23:02 +0100)] 
loop until waitpid returns pid_child or error

closes #104

Signed-off-by: ed neville <ed@s5h.net>
4 years agoRevert "su.c: replace getopt with ad-hoc flag processing"
Serge Hallyn [Fri, 28 Aug 2020 20:16:11 +0000 (15:16 -0500)] 
Revert "su.c: replace getopt with ad-hoc flag processing"

This reverts commit dc732e77347461d18dd6132c429630a4c0f8ca97.

4 years agoRevert "su.c: s/doshell/do_interactive_shell/"
Serge Hallyn [Fri, 28 Aug 2020 20:16:04 +0000 (15:16 -0500)] 
Revert "su.c: s/doshell/do_interactive_shell/"

This reverts commit 6f38f43fdd745fa28b9e100f08bdf8b59b474280.

4 years agoRevert "su.c: implement --exec"
Serge Hallyn [Fri, 28 Aug 2020 20:15:56 +0000 (15:15 -0500)] 
Revert "su.c: implement --exec"

This reverts commit 4047d1fe8edbe5ae952fef17fc09a4105d0de14b.

4 years agoRevert "Update su tests"
Serge Hallyn [Fri, 28 Aug 2020 20:15:47 +0000 (15:15 -0500)] 
Revert "Update su tests"

This reverts commit cf8101aaae51464cbe7e8bf3fe9c03d10c82a8ac.

4 years agoMerge pull request #275 from hallyn/2020-08-27/test-su
Christian Brauner [Fri, 28 Aug 2020 10:13:49 +0000 (12:13 +0200)] 
Merge pull request #275 from hallyn/2020-08-27/test-su

Add tests on top of #254

4 years agoUpdate su tests 275/head
Serge Hallyn [Fri, 28 Aug 2020 04:09:13 +0000 (23:09 -0500)] 
Update su tests

Some of these tests seem wrong.  The assume that

    su -- -c command

should work, whereas -- should mean pass all remaining arguments
along to the command.

Add some new tests based on examples in Issue 253

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
4 years agosu.c: implement --exec
Vito Caputo [Sun, 10 May 2020 01:01:22 +0000 (18:01 -0700)] 
su.c: implement --exec

It's now possible to run commands as other users without shell
interpolation by using "--exec":

Read /etc/shadow as root without specifying user:
```
su --exec /bin/cat -- /etc/shadow
```

Or specify user:
```
su --exec /bin/cat root -- /etc/shadow
```

4 years agosu.c: s/doshell/do_interactive_shell/
Vito Caputo [Sun, 10 May 2020 00:43:14 +0000 (17:43 -0700)] 
su.c: s/doshell/do_interactive_shell/

Mechanical rename distinguishing this variable from intended changes
supporting executing commands without using an interpretive shell
(i.e. no '/bin/sh -c').

4 years agosu.c: replace getopt with ad-hoc flag processing
Vito Caputo [Sat, 9 May 2020 23:06:27 +0000 (16:06 -0700)] 
su.c: replace getopt with ad-hoc flag processing

In preparation for supporting --exec I was testing the robustness
of "--" handling and it became apparent that things are currently
a bit broken in `su`.

Since "--" is currently of limited utility, as the subsequent
words are simply passed to the shell after "-c","command_string",
it seems to have gone unnoticed for ages.

However, with --exec, it's expected that "--" would be an almost
required separator with every such usage, considering the
following flags must be passed verbatim to execve() and will
likely begin with hyphens looking indistinguishable from any
other flags in lieu of shell interpolation to worry about.

For some practical context of the existing situation, this
invocation doesn't work today:
```
  $ su --command ls -- flags for shell
  No passwd entry for user 'flags'
  $
```

This should just run ls as root with "flags","for","shell"
forwarded to the shell after "-c","ls".

The "--" should block "flags" from being treated as the user.
That particular issue isn't a getopt one per-se, it's arguably
just a bug in su.c's implementation.

It *seemed* like an easy fix for this would be to add a check if
argv[optind-1] were "--" before treating argv[optind] as USER.

But testing that fix revealed getopt was rearranging things when
encountering "--", the "--" would always separate the handled
opts from the unhandled ones.  USER would become shifted to
*after* "--" even when it occurred before it!

If we change the command to specify the user, it works as-is:
```
  $ su --command ls root -- flags for shell
  Password:
  testfile
  $

```

But what's rather surprising is how that works; the argv winds up:

"su","--command","ls","--","root","flags","for","shell"

with optind pointing at "root".

That arrangement of argv is indistinguishable from omitting the
user and having "root","flags","for","shell" as the stuff after
"--".

This makes it non-trivial to fix the bug of omitting user
treating the first word after "--" as the user, which one could
argue is a potentially serious security bug if you omit the user,
expect the command to run as root, and the first word after "--"
is a valid user, and what follows that something valid and
potentially destructive not only running in unintended form but
as whatever user happened to be the first word after "--".

So, it seems like something important to fix, and getopt seems to
be getting in the way of fixing it properly without being more
trouble than replacing getopt.

In disbelief of what I was seeing getopt doing with argv here, I
took a glance at the getopt source and found the following:

```
      /* The special ARGV-element '--' means premature end of options.
 Skip it like a null option,
 then exchange with previous non-options as if it were an option,
 then skip everything else like a non-option.  */

      if (d->optind != argc && !strcmp (argv[d->optind], "--"))
```

I basically never use getopt personally because ages ago it
annoyed me with its terrible API for what little it brought to
the table, and this brings it to a whole new level of awful.

4 years agoMerge pull request #267 from stoeckmann/chage
Serge Hallyn [Thu, 13 Aug 2020 05:34:19 +0000 (00:34 -0500)] 
Merge pull request #267 from stoeckmann/chage

chage: Prevent signed integer overflows.

4 years agoMerge pull request #273 from edneville/trailing_n_in_help_typo
Serge Hallyn [Thu, 13 Aug 2020 05:11:24 +0000 (00:11 -0500)] 
Merge pull request #273 from edneville/trailing_n_in_help_typo

Removing trailing n typo

4 years agoRemoving trailing n typo 273/head
ed neville [Wed, 12 Aug 2020 16:53:28 +0000 (17:53 +0100)] 
Removing trailing n typo

Signed-off-by: ed neville <ed@s5h.net>
4 years agoMerge pull request #263 from edneville/261_grpck_questionable_warning
Serge Hallyn [Tue, 11 Aug 2020 18:58:22 +0000 (13:58 -0500)] 
Merge pull request #263 from edneville/261_grpck_questionable_warning

Option to suppress group/gshadow inconsistencies

4 years agoOption to suppress group/gshadow inconsistencies 263/head
ed neville [Sat, 13 Jun 2020 08:02:32 +0000 (09:02 +0100)] 
Option to suppress group/gshadow inconsistencies

'gshadow' man page suggests that "You should use the same list of users
as in /etc/group", but not must.

Closes #261

4 years agoMerge pull request #270 from darktemplarbasealt/fix_resource_leak
Serge Hallyn [Tue, 11 Aug 2020 01:34:50 +0000 (20:34 -0500)] 
Merge pull request #270 from darktemplarbasealt/fix_resource_leak

Fix potential resource leak in set_selinux_file_context function

4 years agoMerge pull request #268 from stoeckmann/chfn
Serge Hallyn [Mon, 10 Aug 2020 18:45:15 +0000 (13:45 -0500)] 
Merge pull request #268 from stoeckmann/chfn

chfn: Prevent buffer overflow.

4 years agoMerge pull request #272 from ikerexxe/useradd_covscan
Christian Brauner [Mon, 10 Aug 2020 10:34:52 +0000 (12:34 +0200)] 
Merge pull request #272 from ikerexxe/useradd_covscan

useradd: check return value from chmod and log it

4 years agouseradd: check return value from chmod and log it 272/head
ikerexxe [Mon, 10 Aug 2020 09:44:00 +0000 (11:44 +0200)] 
useradd: check return value from chmod and log it

covscan was complaining abot calling chmod and ignoring the return
value:
Error: CHECKED_RETURN (CWE-252):
shadow-4.6/src/useradd.c:2084: check_return: Calling
"chmod(prefix_user_home, mode)" without checking return value. This
library function may fail and return an error code.
2082|    mode_t mode = getdef_num ("HOME_MODE",
2083|                              0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
2084|->  chmod (prefix_user_home, mode);
2085|    home_added = true;
2086|   #ifdef WITH_AUDIT

4 years agoMerge pull request #271 from hallyn/2020-08-08/groupmembers
Christian Brauner [Mon, 10 Aug 2020 08:22:45 +0000 (10:22 +0200)] 
Merge pull request #271 from hallyn/2020-08-08/groupmembers

add -U option to groupadd and groupmod

4 years agoadd -U option to groupadd and groupmod 271/head
Serge Hallyn [Sun, 9 Aug 2020 21:44:30 +0000 (16:44 -0500)] 
add -U option to groupadd and groupmod

Add a -U option which adds new usernames as members.  For groupmod,
also add -a (append), without which existing members are removed.

Closes #265

4 years agoFix potential resource leak in set_selinux_file_context function 270/head
Aleksei Nikiforov [Tue, 4 Aug 2020 07:24:46 +0000 (10:24 +0300)] 
Fix potential resource leak in set_selinux_file_context function

4 years agouseradd: suggest --badnames when given a bad name
Serge Hallyn [Sat, 1 Aug 2020 02:29:21 +0000 (21:29 -0500)] 
useradd: suggest --badnames when given a bad name

Closes #266

4 years agochfn: Prevent buffer overflow. 268/head
Tobias Stoeckmann [Sun, 12 Jul 2020 17:01:52 +0000 (19:01 +0200)] 
chfn: Prevent buffer overflow.

This is a stability fix, not a security fix, because the affected -o
option can only be used by root and it takes a modified passwd file.

If a gecos field for a user has BUFSIZ characters without commas and an
equals sign (i.e. a huge slop/extra field) and chfn is called with -o,
then a buffer overflow occurs.

It is not possible to trigger this with shadow tools. Therefore, the
passwd file must be modified manually.

I have fixed this unlikely case the easiest and cleanest way possible.
Since chfn bails out if more than 80 characters excluding commas are
supposed to be written into gecos field, we can stop processing early on
if -o argument is too long.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 years agochage: Prevent signed integer overflows. 267/head
Tobias Stoeckmann [Sun, 12 Jul 2020 15:56:38 +0000 (17:56 +0200)] 
chage: Prevent signed integer overflows.

This is merely a stability fix, not a security fix.

As the root user, it is possible to set time values which later on
result in signed integer overflows.

For this to work, an sgetspent implementation must be used which
supports long values (glibc on amd64 only parses 32 bit, not 64).
Either use musl or simply call configure with following environment
variable:

$ ac_cv_func_sgetspent=no ./configure

Also it is recommended to compile with -fsanitize=undefined or
-ftrapv to see these issues easily.

Examples to trigger issues when calling "chage -l user":

$ chage -d 9223372036854775807 user

$ chage -d 106751991167300 user
$ chage -M 9999 user

$ chage -d 90000000000000 user
$ chage -I 90000000000000 user
$ chage -M 9999 user

$ chage -E 9223372036854775807 user

While at it, I fixed casting issues which could lead to signed integer
overflows on systems which still have a 32 bit time_t.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 years agolibsubid: fix a prototype in api.h
Serge Hallyn [Sat, 20 Jun 2020 03:09:20 +0000 (22:09 -0500)] 
libsubid: fix a prototype in api.h

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
5 years agoMerge pull request #234 from edneville/79_userdel
Serge Hallyn [Wed, 10 Jun 2020 05:31:10 +0000 (00:31 -0500)] 
Merge pull request #234 from edneville/79_userdel

Adding run-parts for userdel

5 years agoAdding run-parts style for pre and post useradd/del 234/head
ed [Thu, 12 Mar 2020 21:14:57 +0000 (21:14 +0000)] 
Adding run-parts style for pre and post useradd/del

Signed-off-by: ed neville <ed@s5h.net>
5 years agoMerge pull request #250 from hallyn/libsubid
Serge Hallyn [Mon, 8 Jun 2020 05:10:16 +0000 (00:10 -0500)] 
Merge pull request #250 from hallyn/libsubid

[strawman] Implement libsubid

5 years agoCreate a new libsubid 250/head
Serge Hallyn [Sat, 18 Apr 2020 23:03:54 +0000 (18:03 -0500)] 
Create a new libsubid

Closes #154

Currently this has three functions: one which returns the
list of subuid ranges for a user, one returning the subgids,
and one which frees the ranges lists.

I might be mistaken about what -disable-man means;  some of
the code suggests it means just don't re-generate them, but
not totally ignore them.  But that doesn't seem to really work,
so let's just ignore man/ when -disable-man.

Remove --disable-shared.  I'm not sure why it was there, but it stems
from long, long ago, and I suspect it comes from some ancient
toolchain bug.

Create a tests/run_some, a shorter version of run_all.  I'll
slowly add tests to this as I verify they work, then I can
work on fixing the once which don't.

Also, don't touch man/ if not -enable-man.

Changelog:
Apr 22: change the subid list api as recomended by Dan Walsh.
Apr 23: implement get_subid_owner
Apr 24: implement range add/release
Apr 25: finish tests and rebase
May 10: make @owner const

Signed-off-by: Serge Hallyn <serge@hallyn.com>
5 years agoconfigure: define abi versions
Serge Hallyn [Sat, 18 Apr 2020 19:57:56 +0000 (14:57 -0500)] 
configure: define abi versions

Signed-off-by: Serge Hallyn <serge@hallyn.com>
5 years agodrop svn complications from test runner
Serge Hallyn [Fri, 24 Apr 2020 21:41:34 +0000 (16:41 -0500)] 
drop svn complications from test runner

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
5 years agotests: use git to determine top_dir
Serge Hallyn [Sun, 19 Apr 2020 04:32:59 +0000 (23:32 -0500)] 
tests: use git to determine top_dir

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
5 years agotrivial: drop useless version-info from libshadow_la_LDFLAGS
Serge Hallyn [Sun, 19 Apr 2020 00:17:51 +0000 (19:17 -0500)] 
trivial: drop useless version-info from libshadow_la_LDFLAGS

Signed-off-by: Serge Hallyn <serge@hallyn.com>