]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
4 years agolibmisc/salt.c: Use int pointer for YESCRYPT_salt_cost(). 358/head
Björn Esser [Sat, 12 Jun 2021 17:05:07 +0000 (19:05 +0200)] 
libmisc/salt.c: Use int pointer for YESCRYPT_salt_cost().

The corresponding functions for the other hash methods all take
a pointer to an integer value as the only paramater, so this
particular function should do so as well.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
4 years agoMerge pull request #354 from ikerexxe/useradd_resource_leak
Serge Hallyn [Tue, 22 Jun 2021 14:22:09 +0000 (09:22 -0500)] 
Merge pull request #354 from ikerexxe/useradd_resource_leak

useradd.c: fix covscan RESOURCE_LEAK

4 years agoMerge pull request #353 from ikerexxe/man_subid
Serge Hallyn [Tue, 22 Jun 2021 14:20:11 +0000 (09:20 -0500)] 
Merge pull request #353 from ikerexxe/man_subid

man: improve subid documentation

4 years agoMerge pull request #356 from tzccinct/pass-min-days-doc
Serge Hallyn [Tue, 22 Jun 2021 13:51:08 +0000 (08:51 -0500)] 
Merge pull request #356 from tzccinct/pass-min-days-doc

man: use the consistent value 0 to disable PASS_MIN_DAYS restriction

4 years agoman: definition and configuration of subid 353/head
Iker Pedrosa [Fri, 11 Jun 2021 13:25:42 +0000 (15:25 +0200)] 
man: definition and configuration of subid

Define the subid functionality and explain the way to configure its
delegation.

4 years agouseradd.c: fix covscan RESOURCE_LEAK 354/head
Iker Pedrosa [Thu, 10 Jun 2021 11:05:03 +0000 (13:05 +0200)] 
useradd.c: fix covscan RESOURCE_LEAK

Error: RESOURCE_LEAK (CWE-772): [#def28]
shadow-4.8.1/src/useradd.c:1905: open_fn: Returning handle opened by "open". [Note: The source code implementation of the function has been overridden by a user model.]
shadow-4.8.1/src/useradd.c:1905: var_assign: Assigning: "fd" = handle returned from "open("/var/log/faillog", 2)".
shadow-4.8.1/src/useradd.c:1906: noescape: Resource "fd" is not freed or pointed-to in "lseek".
shadow-4.8.1/src/useradd.c:1917: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
 1915|    /* continue */
 1916|    }
 1917|-> }
 1918|
 1919|   static void lastlog_reset (uid_t uid)

Error: RESOURCE_LEAK (CWE-772): [#def29]
shadow-4.8.1/src/useradd.c:1938: open_fn: Returning handle opened by "open". [Note: The source code implementation of the function has been overridden by a user model.]
shadow-4.8.1/src/useradd.c:1938: var_assign: Assigning: "fd" = handle returned from "open("/var/log/lastlog", 2)".
shadow-4.8.1/src/useradd.c:1939: noescape: Resource "fd" is not freed or pointed-to in "lseek".
shadow-4.8.1/src/useradd.c:1950: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
 1948|    /* continue */
 1949|    }
 1950|-> }
 1951|
 1952|   static void tallylog_reset (const char *user_name)

Error: RESOURCE_LEAK (CWE-772): [#def30]
shadow-4.8.1/src/useradd.c:2109: alloc_fn: Storage is returned from allocation function "strdup".
shadow-4.8.1/src/useradd.c:2109: var_assign: Assigning: "bhome" = storage returned from "strdup(prefix_user_home)".
shadow-4.8.1/src/useradd.c:2131: noescape: Resource "bhome" is not freed or pointed-to in "strtok".
shadow-4.8.1/src/useradd.c:2207: leaked_storage: Variable "bhome" going out of scope leaks the storage it points to.
 2205|    }
 2206|   #endif
 2207|->  }
 2208|   }
 2209|

4 years agoman: clarify subid delegation behaviour
Iker Pedrosa [Mon, 7 Jun 2021 09:50:56 +0000 (11:50 +0200)] 
man: clarify subid delegation behaviour

Following the discussion https://github.com/shadow-maint/shadow/pull/345
I have changed the documentation to clarify the behaviour of subid
delegation when any subid source except files is configured.

4 years agoman: use the consistent value 0 to disable PASS_MIN_DAYS restriction 356/head
tzccinct [Sat, 12 Jun 2021 03:55:57 +0000 (12:55 +0900)] 
man: use the consistent value 0 to disable PASS_MIN_DAYS restriction

4 years agoMerge pull request #355 from ikerexxe/usermod_resource_leak
Serge Hallyn [Fri, 11 Jun 2021 18:57:38 +0000 (13:57 -0500)] 
Merge pull request #355 from ikerexxe/usermod_resource_leak

usermod.c: fix covscan RESOURCE_LEAK

4 years agousermod.c: fix covscan RESOURCE_LEAK 355/head
Iker Pedrosa [Fri, 11 Jun 2021 09:50:49 +0000 (11:50 +0200)] 
usermod.c: fix covscan RESOURCE_LEAK

Error: RESOURCE_LEAK (CWE-772): [#def31]
shadow-4.8.1/src/usermod.c:813: alloc_fn: Storage is returned from allocation function "__gr_dup".
shadow-4.8.1/src/usermod.c:813: var_assign: Assigning: "ngrp" = storage returned from "__gr_dup(grp)".
shadow-4.8.1/src/usermod.c:892: leaked_storage: Variable "ngrp" going out of scope leaks the storage it points to.
  890|    }
  891|    }
  892|-> }
  893|
  894|   #ifdef SHADOWGRP

Error: RESOURCE_LEAK (CWE-772): [#def32]
shadow-4.8.1/src/usermod.c:933: alloc_fn: Storage is returned from allocation function "__sgr_dup".
shadow-4.8.1/src/usermod.c:933: var_assign: Assigning: "nsgrp" = storage returned from "__sgr_dup(sgrp)".
shadow-4.8.1/src/usermod.c:1031: leaked_storage: Variable "nsgrp" going out of scope leaks the storage it points to.
 1029|    }
 1030|    }
 1031|-> }
 1032|   #endif /* SHADOWGRP */
 1033|

Error: RESOURCE_LEAK (CWE-772): [#def34]
shadow-4.8.1/src/usermod.c:1161: alloc_fn: Storage is returned from allocation function "getgr_nam_gid".
shadow-4.8.1/src/usermod.c:1161: var_assign: Assigning: "grp" = storage returned from "getgr_nam_gid(optarg)".
shadow-4.8.1/src/usermod.c:1495: leaked_storage: Variable "grp" going out of scope leaks the storage it points to.
 1493|    }
 1494|   #endif /* ENABLE_SUBIDS */
 1495|-> }
 1496|
 1497|   /*

Error: RESOURCE_LEAK (CWE-772): [#def35]
shadow-4.8.1/src/usermod.c:1991: open_fn: Returning handle opened by "open". [Note: The source code implementation of the function has been overridden by a user model.]
shadow-4.8.1/src/usermod.c:1991: var_assign: Assigning: "fd" = handle returned from "open("/var/log/lastlog", 2)".
shadow-4.8.1/src/usermod.c:2000: noescape: Resource "fd" is not freed or pointed-to in "lseek".
shadow-4.8.1/src/usermod.c:2000: noescape: Resource "fd" is not freed or pointed-to in "read". [Note: The source code implementation of the function has been overridden by a builtin model.]
shadow-4.8.1/src/usermod.c:2003: noescape: Resource "fd" is not freed or pointed-to in "lseek".
shadow-4.8.1/src/usermod.c:2032: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
 2030|    }
 2031|    }
 2032|-> }
 2033|
 2034|   /*

Error: RESOURCE_LEAK (CWE-772): [#def36]
shadow-4.8.1/src/usermod.c:2052: open_fn: Returning handle opened by "open". [Note: The source code implementation of the function has been overridden by a user model.]
shadow-4.8.1/src/usermod.c:2052: var_assign: Assigning: "fd" = handle returned from "open("/var/log/faillog", 2)".
shadow-4.8.1/src/usermod.c:2061: noescape: Resource "fd" is not freed or pointed-to in "lseek".
shadow-4.8.1/src/usermod.c:2061: noescape: Resource "fd" is not freed or pointed-to in "read". [Note: The source code implementation of the function has been overridden by a builtin model.]
shadow-4.8.1/src/usermod.c:2064: noescape: Resource "fd" is not freed or pointed-to in "lseek".
shadow-4.8.1/src/usermod.c:2092: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
 2090|    }
 2091|    }
 2092|-> }
 2093|
 2094|   #ifndef NO_MOVE_MAILBOX

4 years agoMerge pull request #352 from hallyn/2021-06-01/relpath
Serge Hallyn [Fri, 4 Jun 2021 02:31:17 +0000 (21:31 -0500)] 
Merge pull request #352 from hallyn/2021-06-01/relpath

usermod, newusers, prefix: enforce absolute paths for homedir

4 years agousermod, newusers, prefix: enforce absolute paths for homedir 352/head
Serge Hallyn [Wed, 2 Jun 2021 03:11:37 +0000 (22:11 -0500)] 
usermod, newusers, prefix: enforce absolute paths for homedir

useradd already was enforcing this, but these were not.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #348 from hallyn/2021-05-28/notextern
Serge Hallyn [Tue, 1 Jun 2021 15:12:46 +0000 (10:12 -0500)] 
Merge pull request #348 from hallyn/2021-05-28/notextern

libsubid/api.c: make shadow_logfd not extern

4 years agolibsubid/api.c: make shadow_logfd not extern 348/head
Serge Hallyn [Sat, 29 May 2021 03:02:16 +0000 (22:02 -0500)] 
libsubid/api.c: make shadow_logfd not extern

Closes #346

Also #include stdio.h

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #327 from squat/bugfix_relative_prefix_path
Serge Hallyn [Sat, 29 May 2021 19:16:46 +0000 (14:16 -0500)] 
Merge pull request #327 from squat/bugfix_relative_prefix_path

fix: create relative home path correctly

4 years agoMerge pull request #345 from ikerexxe/subid_single_source
Christian Brauner [Tue, 25 May 2021 12:20:17 +0000 (14:20 +0200)] 
Merge pull request #345 from ikerexxe/subid_single_source

man: clarify subid delegation

4 years agoman: clarify subid delegation 345/head
Iker Pedrosa [Mon, 24 May 2021 10:14:43 +0000 (12:14 +0200)] 
man: clarify subid delegation

Clarify that the subid delegation can only come from one source.
Moreover, add an example of what might happen if the subid source is NSS
and useradd is executed.

Related: https://github.com/shadow-maint/shadow/issues/331

4 years agoMerge pull request #344 from hallyn/2021-05-23/hasanyrange
Serge Hallyn [Sun, 23 May 2021 14:26:54 +0000 (09:26 -0500)] 
Merge pull request #344 from hallyn/2021-05-23/hasanyrange

fix newusers when nss provides subids

4 years agofix newusers when nss provides subids 344/head
Serge Hallyn [Mon, 17 May 2021 02:59:14 +0000 (21:59 -0500)] 
fix newusers when nss provides subids

Closes #331

1. drop 'has_any_range' nss method as it is not useful

2. do not try to create a subid range in newusers when using nss for
   subids, since that's not possible.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
(cherry picked from commit 88a434adbdcf4a8640793fd58bcd2ba77598349d)

4 years agoMerge pull request #343 from hallyn/2021-05-23/quiet
Serge Hallyn [Sun, 23 May 2021 13:03:58 +0000 (08:03 -0500)] 
Merge pull request #343 from hallyn/2021-05-23/quiet

libsubid_init: don't print messages on error

4 years agolibsubid_init: don't print messages on error 343/head
Serge Hallyn [Sun, 23 May 2021 13:03:10 +0000 (08:03 -0500)] 
libsubid_init: don't print messages on error

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #340 from hallyn/2021-05-16/subidrange
Serge Hallyn [Sat, 22 May 2021 23:16:43 +0000 (18:16 -0500)] 
Merge pull request #340 from hallyn/2021-05-16/subidrange

Don't return owner in list_owner_ranges API call.

4 years agonss/libsubid: simplify the ranges variable for list_owner_ranges 340/head
Serge Hallyn [Sat, 22 May 2021 17:16:50 +0000 (12:16 -0500)] 
nss/libsubid: simplify the ranges variable for list_owner_ranges

Following alexey-tikhonov's suggestion.

Since we've dropped the 'owner' field in the data returned for
get_subid_ranges, we can just return a single allocated array of
simple structs.  This means we can return a ** instead of ***, and
we can get rid of the subid_free_ranges() helper, since the caller
can just free() the returned data.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #342 from hallyn/2021-05-22/subuidzero
Serge Hallyn [Sat, 22 May 2021 16:43:23 +0000 (11:43 -0500)] 
Merge pull request #342 from hallyn/2021-05-22/subuidzero

Fix useradd with SUB_UID_COUNT=0

4 years agoFix useradd with SUB_UID_COUNT=0 342/head
Serge Hallyn [Sat, 22 May 2021 16:42:02 +0000 (11:42 -0500)] 
Fix useradd with SUB_UID_COUNT=0

Closes #298

Fix useradd when SUB_UID_COUNT=0 in login.defs.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #341 from hallyn/2021-05-17/fail
Serge Hallyn [Mon, 17 May 2021 13:49:31 +0000 (08:49 -0500)] 
Merge pull request #341 from hallyn/2021-05-17/fail

libsubid_init: return false if out of memory

4 years agolibsubid_init: return false if out of memory 341/head
Serge Hallyn [Mon, 17 May 2021 13:48:03 +0000 (08:48 -0500)] 
libsubid_init: return false if out of memory

The rest of the run isn't likely to get much better, is it?

Thanks to Alexey for pointing this out.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
Cc: Alexey Tikhonov <atikhono@redhat.com>
4 years agoDon't return owner in list_owner_ranges API call.
Serge Hallyn [Mon, 17 May 2021 02:47:05 +0000 (21:47 -0500)] 
Don't return owner in list_owner_ranges API call.

Closes: 339
struct subordinate_range is pretty closely tied to the existing
subid code and /etc/subuid format, so it includes an owner.  Dropping
that or even renaming it is more painful than I'd first thought.
So introduce a 'struct subid_range' which is only the start and
count, leaving 'struct subordinate_range' as the owner, start and
count.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #335 from hallyn/2021-05-08/stderr
Serge Hallyn [Mon, 17 May 2021 02:44:22 +0000 (21:44 -0500)] 
Merge pull request #335 from hallyn/2021-05-08/stderr

[WIP] libsubid: don't print error messages on stderr by default

4 years agolibsubid: don't print error messages on stderr by default 335/head
Serge Hallyn [Sat, 8 May 2021 22:42:14 +0000 (17:42 -0500)] 
libsubid: don't print error messages on stderr by default

Closes #325

Add a new subid_init() function which can be used to specify the
stream on which error messages should be printed.  (If you want to
get fancy you can redirect that to memory :)  If subid_init() is
not called, use stderr.  If NULL is passed, then /dev/null will
be used.

This patch also fixes up the 'Prog', which previously had to be
defined by any program linking against libsubid.  Now, by default
in libsubid it will show (subid).  Once subid_init() is called,
it will use the first variable passed to subid_init().

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #333 from ikerexxe/hmac_crypto_algo
Serge Hallyn [Sat, 8 May 2021 21:35:05 +0000 (16:35 -0500)] 
Merge pull request #333 from ikerexxe/hmac_crypto_algo

login.defs: include HMAC_CRYPTO_ALGO key

4 years agoMerge pull request #323 from cgzones/selinux
Serge Hallyn [Fri, 7 May 2021 13:32:01 +0000 (08:32 -0500)] 
Merge pull request #323 from cgzones/selinux

SELinux modernizations

4 years agoMerge pull request #334 from brauner/2021-05-06.cap_setfcap
Serge Hallyn [Thu, 6 May 2021 19:45:50 +0000 (14:45 -0500)] 
Merge pull request #334 from brauner/2021-05-06.cap_setfcap

libmisc: retain CAP_SETFCAP when mapping uid 0

4 years agolibmisc: retain setfcap when mapping uid 0 334/head
Christian Brauner [Thu, 6 May 2021 16:59:28 +0000 (18:59 +0200)] 
libmisc: retain setfcap when mapping uid 0

When uid 0 maps host uid 0 into the child userns newer kernels require
CAP_SETFCAP be retained as this allows the caller to create fscaps that
are valid in the ancestor userns. This was a security issue (in very
rare circumstances). So whenever host uid 0 is mapped, retain
CAP_SETFCAP if the caller had it.
Userspace won't need to set CAP_SETFCAP on newuidmap as this is really
only a scenario that real root should be doing which always has
CAP_SETFCAP. And if they don't then they are in a locked-down userns.
(LXC sometimes maps host uid 0 during chown operations in a helper
 userns but will not rely on newuidmap for that. But we don't want to
 risk regressing callers that want to rely on this behavior.)

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
4 years agologin.defs: include HMAC_CRYPTO_ALGO key 333/head
Iker Pedrosa [Thu, 6 May 2021 15:23:33 +0000 (17:23 +0200)] 
login.defs: include HMAC_CRYPTO_ALGO key

Include the new HMAC_CRYPTO_ALGO key that is needed by pam_timestamp to
select the algorithm that is going to be used to calculate the message
authentication code.

pam_timestamp is currently using an embedded algorithm to calculate the
HMAC message, but the idea is to improve this behaviour by relying on
openssl's implementation. On top of that, the ability to change the
algorithm with a simple configuration change allows to simplify the
process of removing unsecure algorithms.

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

4 years agoselinux: only open selabel database once 323/head
Christian Göttsche [Tue, 13 Apr 2021 12:13:11 +0000 (14:13 +0200)] 
selinux: only open selabel database once

Once opened, keep the selabel database open for further lookups.
Register an exit handler to close the database.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
4 years agoset_selinux_file_context(): prepare context for actual file type
Christian Göttsche [Fri, 9 Apr 2021 16:21:00 +0000 (18:21 +0200)] 
set_selinux_file_context(): prepare context for actual file type

Search the SELinux selabel database for the file type to be created.
Not specifying the file mode can cause an incorrect file context to be
returned.

Also prepare contexts in commonio_close() for the generic database
filename, not with the backup suffix appended, to ensure the desired
file context after the final rename.

Closes: #322
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
4 years agoselinux.c: use modern selabel interface instead of deprecated matchpathcon
Christian Göttsche [Fri, 9 Apr 2021 16:20:55 +0000 (18:20 +0200)] 
selinux.c: use modern selabel interface instead of deprecated matchpathcon

matchpathcon(3) is deprecated in favor of selabel_lookup(3).

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
4 years agoselinux.c:reset_selinux_file_context(): do not fail in permissive mode
Christian Göttsche [Fri, 9 Apr 2021 16:20:53 +0000 (18:20 +0200)] 
selinux.c:reset_selinux_file_context(): do not fail in permissive mode

Return 0 on setfscreatecon(3) failure, like set_selinux_file_context().

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
4 years agoselinux.c: do not use deprecated typedef and skip context translation
Christian Göttsche [Fri, 9 Apr 2021 16:20:51 +0000 (18:20 +0200)] 
selinux.c: do not use deprecated typedef and skip context translation

These retrieved contexts are just passed to libselinux functions and not
printed or otherwise made available to the outside, so a context
translation to human readable MCS/MLS labels is not needed.
(see man:setrans.conf(5))

The typedef security_context_t is deprecated, see
https://github.com/SELinuxProject/selinux/commit/9eb9c9327563014ad6a807814e7975424642d5b9

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
4 years agovipw[selinux]: do not use deprecated typedef and skip context translation
Christian Göttsche [Fri, 9 Apr 2021 16:20:49 +0000 (18:20 +0200)] 
vipw[selinux]: do not use deprecated typedef and skip context translation

This retrieved context is just passed to libselinux functions and not
printed or otherwise made available to the outside, so a context
translation to human readable MCS/MLS labels is not needed.
(see man:setrans.conf(5))

The typedef security_context_t is deprecated, see
https://github.com/SELinuxProject/selinux/commit/9eb9c9327563014ad6a807814e7975424642d5b9

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
4 years agostruct commonio_db[selinux]: do not use deprecated type security_context_t
Christian Göttsche [Fri, 9 Apr 2021 16:20:41 +0000 (18:20 +0200)] 
struct commonio_db[selinux]: do not use deprecated type security_context_t

The typedef security_context_t is deprecated, see
https://github.com/SELinuxProject/selinux/commit/9eb9c9327563014ad6a807814e7975424642d5b9

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
4 years agoMerge pull request #332 from hallyn/2021-05-04/manpage
Serge Hallyn [Tue, 4 May 2021 19:40:28 +0000 (14:40 -0500)] 
Merge pull request #332 from hallyn/2021-05-04/manpage

manpages: mention NSS in new[ug]idmap manpages

4 years agomanpages: mention NSS in new[ug]idmap manpages 332/head
Serge Hallyn [Tue, 4 May 2021 19:39:26 +0000 (14:39 -0500)] 
manpages: mention NSS in new[ug]idmap manpages

Closes #328

Signed-off-by: Serge Hallyn <serge@hallyn.com>
4 years agoMerge pull request #330 from hallyn/2021-05-04/subidhinclude
Serge Hallyn [Tue, 4 May 2021 14:22:48 +0000 (09:22 -0500)] 
Merge pull request #330 from hallyn/2021-05-04/subidhinclude

Install subid.h

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 agofix: create relative home path correctly 327/head
Lucas Servén Marín [Thu, 29 Apr 2021 12:09:31 +0000 (14:09 +0200)] 
fix: create relative home path correctly

Currently, supplying a relative path via the --prefix flag to the
useradd command triggers a bug in the creation of home directories. The
code seems to unintentionally prepend a leading "/" to all paths,
quietly transforming a relative prefixed home path into an absolute
path. This can be seen in the following strace logs from running
"useradd --create-home --prefix tmp/root squat":

```
access("tmp/root//home/squat", F_OK)    = -1 ENOENT (No such file or directory)
access("/mp", F_OK)                     = 0
access("/mp/root", F_OK)                = 0
access("/mp/root/home", F_OK)           = 0
access("/mp/root/home/squat", F_OK)     = -1 ENOENT (No such file or directory)
mkdir("/mp/root/home/squat", 000)       = 0
chown("/mp/root/home/squat", 0, 0)      = 0
chmod("/mp/root/home/squat", 0755)      = 0
chown("tmp/root//home/squat", 1000, 1000) = -1 ENOENT (No such file or directory)
chmod("tmp/root//home/squat", 0700)     = -1 ENOENT (No such file or directory)
```

Note that the relative path is correctly probed in the beginning and it
is only during the recursive creation that the path is turned into an
absolute path. This invocation results in the creation of a "/mp"
hierarchy in the root of the filesystem.

Similar problems occur when using `--prefix ./tmp/root`.

This commit fixes the handling of relative paths by not assuming that
the given path is anchored with a "/".

Signed-off-by: Lucas Servén Marín <lserven@gmail.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