]> git.ipfire.org Git - thirdparty/shadow.git/log
thirdparty/shadow.git
3 years agoimplement passwd --status (mostly) rust
Serge Hallyn [Fri, 17 Dec 2021 21:10:09 +0000 (15:10 -0600)] 
implement passwd --status (mostly)

Still need to do date printing.

'sudo passwd -S' and 'sudo passwd -S someuser' work.

Note passwd has to be setuid root to be able to open shadow
file in order to print most of that info as non-root.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoimplement environment sanitization
Serge Hallyn [Fri, 17 Dec 2021 17:05:34 +0000 (11:05 -0600)] 
implement environment sanitization

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoadd shadow entry struct
Serge Hallyn [Mon, 23 Aug 2021 01:30:37 +0000 (20:30 -0500)] 
add shadow entry struct

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoadd tests
Serge Hallyn [Sun, 22 Aug 2021 22:13:59 +0000 (17:13 -0500)] 
add tests

Create a container in which to run tests.

Run the 'usage' test since that's all that will work so far.

Also remove two defines from src/bin/passwd.rs which were
breaking build.

ubuntu-dev-tools is probably overkill in the container.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoinitial rust
Tycho Andersen [Fri, 30 Jul 2021 16:52:52 +0000 (10:52 -0600)] 
initial rust

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
3 years agoMerge pull request #392 from hallyn/2021-07-25/useradd-defaults
Christian Brauner [Mon, 26 Jul 2021 08:20:56 +0000 (10:20 +0200)] 
Merge pull request #392 from hallyn/2021-07-25/useradd-defaults

useradd: create /etc/default saving defaults.

3 years agouseradd: create /etc/default saving defaults. 392/head
Serge Hallyn [Sun, 25 Jul 2021 21:19:56 +0000 (16:19 -0500)] 
useradd: create /etc/default saving defaults.

Since bbf4b79, we stopped shipping /etc/default/useradd, and therefore
install of shadow does not auto-create /etc/default.  So when useradd
tries to save a new default, it needs to create the directory.

Closes #390.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoMerge pull request #391 from hallyn/2021-07-25/static
Serge Hallyn [Sun, 25 Jul 2021 19:01:11 +0000 (14:01 -0500)] 
Merge pull request #391 from hallyn/2021-07-25/static

Respect --enable-static=no in libsubid

3 years agoRespect --enable-static=no in libsubid 391/head
Serge Hallyn [Sun, 25 Jul 2021 17:18:02 +0000 (17:18 +0000)] 
Respect --enable-static=no in libsubid

libsubid's Makefile.am was always setting enable-shared in its LDFLAGS.
Do that only if not building static.

Closes #387

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
3 years agoMerge pull request #388 from hallyn/2021-07-23/outoftreebuild
Serge Hallyn [Fri, 23 Jul 2021 23:11:51 +0000 (18:11 -0500)] 
Merge pull request #388 from hallyn/2021-07-23/outoftreebuild

Fix out of tree builds with respect to libsubid includes

3 years agoFix out of tree builds with respect to libsubid includes 388/head
Serge Hallyn [Fri, 23 Jul 2021 22:51:13 +0000 (17:51 -0500)] 
Fix out of tree builds with respect to libsubid includes

There's a better way to do this, and I hope to clean that up,
but this fixes out of tree builds for me right now.

Closes #386

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoMerge pull request #385 from xry111/ftbfs-fix
Serge Hallyn [Fri, 23 Jul 2021 09:53:34 +0000 (04:53 -0500)] 
Merge pull request #385 from xry111/ftbfs-fix

libsubid: link to PAM libraries

3 years agolibsubid: link to PAM libraries 385/head
Xi Ruoyao [Fri, 23 Jul 2021 06:38:08 +0000 (14:38 +0800)] 
libsubid: link to PAM libraries

libsubid.so links to libmisc.a, which contains several routines referring to
PAM functions.

3 years agoconfigure.ac: get ready to release 4.9 4.9 v4.9
Serge Hallyn [Thu, 22 Jul 2021 21:50:51 +0000 (16:50 -0500)] 
configure.ac: get ready to release 4.9

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoupdate Changelog
Serge Hallyn [Thu, 22 Jul 2021 21:49:26 +0000 (16:49 -0500)] 
update Changelog

Signed-off-by: Serge Hallyn <serge@hallyn.com>
3 years agoMerge pull request #378 from besser82/topic/besser82/update_po
Serge Hallyn [Wed, 14 Jul 2021 14:35:31 +0000 (09:35 -0500)] 
Merge pull request #378 from besser82/topic/besser82/update_po

Update translation files.

3 years agoMerge pull request #383 from ikerexxe/wrong_free
Serge Hallyn [Wed, 14 Jul 2021 12:25:55 +0000 (07:25 -0500)] 
Merge pull request #383 from ikerexxe/wrong_free

libmisc: don't free members variable

3 years agoMerge pull request #382 from StevenYGui/master
Serge Hallyn [Wed, 14 Jul 2021 12:20:24 +0000 (07:20 -0500)] 
Merge pull request #382 from StevenYGui/master

fread returns element count, not element size

3 years agolibmisc: don't free members variable 383/head
Iker Pedrosa [Wed, 14 Jul 2021 09:59:38 +0000 (11:59 +0200)] 
libmisc: don't free members variable

In 9eb191edc4a625bb68e827b18638f5b5816cb30c I included a free() that
frees the members variable, which in turn causes the comma_to_list()
function to return an array of empty elements. The array variable holds
a list of pointers that point to offsets of the members variable. When
the function succeeds freeing members variable causes the elements of
the array variable to point to an empty string.

This is causing several regressions in our internal testing environment.
So, I'm reverting the change.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 years agofread returns element count, not element size 381/head 382/head
steven Y Gui [Wed, 14 Jul 2021 08:17:48 +0000 (16:17 +0800)] 
fread returns element count, not element size

3 years agopo/de.po: Update German translations. 378/head
Björn Esser [Sun, 4 Jul 2021 10:26:36 +0000 (12:26 +0200)] 
po/de.po: Update German translations.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agopo: Update translation files from updated template.
Björn Esser [Sun, 4 Jul 2021 10:23:51 +0000 (12:23 +0200)] 
po: Update translation files from updated template.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agopo: Update pot file.
Björn Esser [Wed, 16 Jun 2021 15:58:46 +0000 (17:58 +0200)] 
po: Update pot file.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agoMerge pull request #357 from besser82/topic/besser82/xcrypt_gensalt
Serge Hallyn [Mon, 5 Jul 2021 03:23:56 +0000 (22:23 -0500)] 
Merge pull request #357 from besser82/topic/besser82/xcrypt_gensalt

Use crypt_gensalt(), if available in libcrypt.

3 years agolibmisc/salt.c: Use crypt_gensalt(), if available in libcrypt. 357/head
Björn Esser [Tue, 15 Jun 2021 12:23:42 +0000 (14:23 +0200)] 
libmisc/salt.c: Use crypt_gensalt(), if available in libcrypt.

Most Linux distributions, including Fedora and RHEL 8, are shipping
with libxcrypt >= 4.0.

Since that version of libxcrypt the provided family of crypt_gensalt()
functions are able to use automatic entropy drawn from secure system
ressources, like arc4random(), getentropy() or getrandom().

Anyways, the settings generated by crypt_gensalt() are always
guaranteed to works with the crypt() function.

Using crypt_gensalt() is also needed to make proper use of newer
hashing methods, like yescrypt, provided by libxcrypt.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agolib/defines.h: Include <crypt.h> if present on the system.
Björn Esser [Thu, 24 Jun 2021 10:39:27 +0000 (12:39 +0200)] 
lib/defines.h: Include <crypt.h> if present on the system.

The functions crypt(3), crypt_gensalt(3), and their
feature test macros may be defined in there.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agolibmisc/salt.c: Use secure system ressources to obtain random bytes. 380/head
Björn Esser [Sun, 4 Jul 2021 10:10:11 +0000 (12:10 +0200)] 
libmisc/salt.c: Use secure system ressources to obtain random bytes.

In a previous commit we introduced /dev/urandom as a source to obtain
random bytes from.  This may not be available on all systems, or when
operating inside of a chroot.

Almost all systems provide functions to obtain random bytes from
secure system ressources.  Thus we should prefer to use these, and
fall back to /dev/urandom, if there is no such function present, as
a last resort.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agoMerge pull request #359 from ikerexxe/rest_resource_leak
Serge Hallyn [Thu, 24 Jun 2021 18:14:15 +0000 (13:14 -0500)] 
Merge pull request #359 from ikerexxe/rest_resource_leak

Fix covscan RESOURCE_LEAK

3 years agoFix covscan RESOURCE_LEAK 359/head
Iker Pedrosa [Mon, 14 Jun 2021 10:39:48 +0000 (12:39 +0200)] 
Fix covscan RESOURCE_LEAK

Error: RESOURCE_LEAK (CWE-772): [#def1]
shadow-4.8.1/lib/commonio.c:320: alloc_fn: Storage is returned from allocation function "fopen_set_perms".
shadow-4.8.1/lib/commonio.c:320: var_assign: Assigning: "bkfp" = storage returned from "fopen_set_perms(backup, "w", &sb)".
shadow-4.8.1/lib/commonio.c:329: noescape: Resource "bkfp" is not freed or pointed-to in "putc".
shadow-4.8.1/lib/commonio.c:334: noescape: Resource "bkfp" is not freed or pointed-to in "fflush".
shadow-4.8.1/lib/commonio.c:339: noescape: Resource "bkfp" is not freed or pointed-to in "fileno".
shadow-4.8.1/lib/commonio.c:342: leaked_storage: Variable "bkfp" going out of scope leaks the storage it points to.
  340|        || (fclose (bkfp) != 0)) {
  341|    /* FIXME: unlink the backup file? */
  342|->  return -1;
  343|    }
  344|

Error: RESOURCE_LEAK (CWE-772): [#def2]
shadow-4.8.1/libmisc/addgrps.c:69: alloc_fn: Storage is returned from allocation function "malloc".
shadow-4.8.1/libmisc/addgrps.c:69: var_assign: Assigning: "grouplist" = storage returned from "malloc(i * 4UL)".
shadow-4.8.1/libmisc/addgrps.c:73: noescape: Resource "grouplist" is not freed or pointed-to in "getgroups". [Note: The source code implementation of the function has been overridden by a builtin model.]
shadow-4.8.1/libmisc/addgrps.c:126: leaked_storage: Variable "grouplist" going out of scope leaks the storage it points to.
  124|    }
  125|
  126|->  return 0;
  127|   }
  128|   #else /* HAVE_SETGROUPS && !USE_PAM */

Error: RESOURCE_LEAK (CWE-772): [#def3]
shadow-4.8.1/libmisc/chowntty.c:62: alloc_fn: Storage is returned from allocation function "getgr_nam_gid".
shadow-4.8.1/libmisc/chowntty.c:62: var_assign: Assigning: "grent" = storage returned from "getgr_nam_gid(getdef_str("TTYGROUP"))".
shadow-4.8.1/libmisc/chowntty.c:98: leaked_storage: Variable "grent" going out of scope leaks the storage it points to.
   96|     */
   97|   #endif
   98|-> }
   99|

Error: RESOURCE_LEAK (CWE-772): [#def4]
shadow-4.8.1/libmisc/copydir.c:742: 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/libmisc/copydir.c:742: var_assign: Assigning: "ifd" = handle returned from "open(src, 0)".
shadow-4.8.1/libmisc/copydir.c:748: leaked_handle: Handle variable "ifd" going out of scope leaks the handle.
  746|   #ifdef WITH_SELINUX
  747|    if (set_selinux_file_context (dst, NULL) != 0) {
  748|->  return -1;
  749|    }
  750|   #endif /* WITH_SELINUX */

Error: RESOURCE_LEAK (CWE-772): [#def5]
shadow-4.8.1/libmisc/copydir.c:751: 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/libmisc/copydir.c:751: var_assign: Assigning: "ofd" = handle returned from "open(dst, 577, statp->st_mode & 0xfffU)".
shadow-4.8.1/libmisc/copydir.c:752: noescape: Resource "ofd" is not freed or pointed-to in "fchown_if_needed".
shadow-4.8.1/libmisc/copydir.c:775: leaked_handle: Handle variable "ofd" going out of scope leaks the handle.
  773|       ) {
  774|    (void) close (ifd);
  775|->  return -1;
  776|    }
  777|

Error: RESOURCE_LEAK (CWE-772): [#def7]
shadow-4.8.1/libmisc/idmapping.c:188: alloc_fn: Storage is returned from allocation function "xmalloc".
shadow-4.8.1/libmisc/idmapping.c:188: var_assign: Assigning: "buf" = storage returned from "xmalloc(bufsize)".
shadow-4.8.1/libmisc/idmapping.c:188: var_assign: Assigning: "pos" = "buf".
shadow-4.8.1/libmisc/idmapping.c:213: noescape: Resource "buf" is not freed or pointed-to in "write".
shadow-4.8.1/libmisc/idmapping.c:219: leaked_storage: Variable "pos" going out of scope leaks the storage it points to.
shadow-4.8.1/libmisc/idmapping.c:219: leaked_storage: Variable "buf" going out of scope leaks the storage it points to.
  217|    }
  218|    close(fd);
  219|-> }

Error: RESOURCE_LEAK (CWE-772): [#def8]
shadow-4.8.1/libmisc/list.c:211: alloc_fn: Storage is returned from allocation function "xstrdup".
shadow-4.8.1/libmisc/list.c:211: var_assign: Assigning: "members" = storage returned from "xstrdup(comma)".
shadow-4.8.1/libmisc/list.c:217: var_assign: Assigning: "cp" = "members".
shadow-4.8.1/libmisc/list.c:218: noescape: Resource "cp" is not freed or pointed-to in "strchr".
shadow-4.8.1/libmisc/list.c:244: leaked_storage: Variable "cp" going out of scope leaks the storage it points to.
shadow-4.8.1/libmisc/list.c:244: leaked_storage: Variable "members" going out of scope leaks the storage it points to.
  242|    if ('\0' == *members) {
  243|    *array = (char *) 0;
  244|->  return array;
  245|    }
  246|

Error: RESOURCE_LEAK (CWE-772): [#def11]
shadow-4.8.1/libmisc/myname.c:61: alloc_fn: Storage is returned from allocation function "xgetpwnam".
shadow-4.8.1/libmisc/myname.c:61: var_assign: Assigning: "pw" = storage returned from "xgetpwnam(cp)".
shadow-4.8.1/libmisc/myname.c:67: leaked_storage: Variable "pw" going out of scope leaks the storage it points to.
   65|    }
   66|
   67|->  return xgetpwuid (ruid);
   68|   }
   69|

Error: RESOURCE_LEAK (CWE-772): [#def12]
shadow-4.8.1/libmisc/user_busy.c:260: alloc_fn: Storage is returned from allocation function "opendir".
shadow-4.8.1/libmisc/user_busy.c:260: var_assign: Assigning: "task_dir" = storage returned from "opendir(task_path)".
shadow-4.8.1/libmisc/user_busy.c:262: noescape: Resource "task_dir" is not freed or pointed-to in "readdir".
shadow-4.8.1/libmisc/user_busy.c:278: leaked_storage: Variable "task_dir" going out of scope leaks the storage it points to.
  276|             _("%s: user %s is currently used by process %d\n"),
  277|             Prog, name, pid);
  278|->  return 1;
  279|    }
  280|    }

Error: RESOURCE_LEAK (CWE-772): [#def20]
shadow-4.8.1/src/newgrp.c:162: alloc_fn: Storage is returned from allocation function "xgetspnam".
shadow-4.8.1/src/newgrp.c:162: var_assign: Assigning: "spwd" = storage returned from "xgetspnam(pwd->pw_name)".
shadow-4.8.1/src/newgrp.c:234: leaked_storage: Variable "spwd" going out of scope leaks the storage it points to.
  232|    }
  233|
  234|->  return;
  235|
  236|   failure:

Error: RESOURCE_LEAK (CWE-772): [#def21]
shadow-4.8.1/src/passwd.c:530: alloc_fn: Storage is returned from allocation function "xstrdup".
shadow-4.8.1/src/passwd.c:530: var_assign: Assigning: "cp" = storage returned from "xstrdup(crypt_passwd)".
shadow-4.8.1/src/passwd.c:551: noescape: Resource "cp" is not freed or pointed-to in "strlen".
shadow-4.8.1/src/passwd.c:554: noescape: Resource "cp" is not freed or pointed-to in "strcat". [Note: The source code implementation of the function has been overridden by a builtin model.]
shadow-4.8.1/src/passwd.c:555: overwrite_var: Overwriting "cp" in "cp = newpw" leaks the storage that "cp" points to.
  553|    strcpy (newpw, "!");
  554|    strcat (newpw, cp);
  555|->  cp = newpw;
  556|    }
  557|    return cp;

3 years agoMerge pull request #377 from besser82/topic/besser82/salt_c_random
Serge Hallyn [Wed, 23 Jun 2021 19:54:25 +0000 (14:54 -0500)] 
Merge pull request #377 from besser82/topic/besser82/salt_c_random

libmisc/salt.c: Obtain random bytes from /dev/urandom.

3 years agolibmisc/salt.c: Obtain random bytes from /dev/urandom. 377/head
Björn Esser [Wed, 23 Jun 2021 14:06:47 +0000 (16:06 +0200)] 
libmisc/salt.c: Obtain random bytes from /dev/urandom.

Using the random() function to obtain pseudo-random bytes
for generating salt strings is considered to be dangerous.
See CWE-327.

We really should use a more reliable source for obtaining
pseudo-random bytes like /dev/urandom.

Fixes #376.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agolibmisc/salt.c: Add comments how the minmum buffer length is computed.
Björn Esser [Mon, 14 Jun 2021 21:28:28 +0000 (23:28 +0200)] 
libmisc/salt.c: Add comments how the minmum buffer length is computed.

In the previous commit we refactored the functions converting the
rounds number into a string for use with the crypt() function, to
not require any static buffer anymore.

Add some clarifying comments about how the minimum required buffer
length is computed inside of these functions.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agoMerge pull request #361 from besser82/topic/besser82/simplyfy_libmisc_salt
Serge Hallyn [Wed, 23 Jun 2021 14:18:05 +0000 (09:18 -0500)] 
Merge pull request #361 from besser82/topic/besser82/simplyfy_libmisc_salt

Sanitize code in libmisc/salt.c

3 years agoMerge pull request #362 from ikerexxe/buffer_size
Serge Hallyn [Wed, 23 Jun 2021 01:55:31 +0000 (20:55 -0500)] 
Merge pull request #362 from ikerexxe/buffer_size

Fix covscan BUFFER_SIZE

3 years agolibmisc/salt.c: Sanitize code. 361/head
Björn Esser [Mon, 14 Jun 2021 21:28:28 +0000 (23:28 +0200)] 
libmisc/salt.c: Sanitize code.

* Move all pre-processor defines to the top of the file.
* Unify the gensalt() function to be useable for all supported
  hash methods.
* Drop the gensalt_{b,yes}crypt() functions in favor of the
  previous change.
* Refactor the functions converting the rounds number into
  a string for use with the crypt() function, to not require
  any static buffer anymore.
* Clarify the comment about how crypt_make_salt() chooses the used
  hash method from the settings in the login.defs file.
* Use memset() to fill static buffers with zero before using them.
* Use a fixed amount of 16 random base64-chars for the
  sha{256,512}crypt hash methods, which is effectively still less
  than the recommendation from NIST (>= 128 bits), but the maximum
  those methods can effectively use (approx. 90 bits).
* Rename ROUNDS_{MIN,MAX} to SHA_ROUNDS_{MIN,MAX}.
* Bugfixes in the logic of setting rounds in BCRYPT_salt_rounds().
* Likewise for YESCRYPT_salt_cost().
* Fix formatting and white-space errors.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 years agoMerge pull request #360 from besser82/topic/besser82/bcrypt_prefix
Serge Hallyn [Tue, 22 Jun 2021 19:46:41 +0000 (14:46 -0500)] 
Merge pull request #360 from besser82/topic/besser82/bcrypt_prefix

bcrypt should use $2b$ as prefix for setting.

3 years agolibmisc/salt.c: bcrypt should use $2b$ as prefix for setting. 360/head
Björn Esser [Sat, 12 Jun 2021 11:54:14 +0000 (13:54 +0200)] 
libmisc/salt.c: bcrypt should use $2b$ as prefix for setting.

This prefix is the recommended one for new bcrypt hashes
for a long time.

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
3 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>
3 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

3 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

3 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

3 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.

3 years agoFix covscan BUFFER_SIZE 362/head
Iker Pedrosa [Wed, 16 Jun 2021 07:50:53 +0000 (09:50 +0200)] 
Fix covscan BUFFER_SIZE

Error: BUFFER_SIZE (CWE-170): [#def6]
shadow-4.8.1/libmisc/failure.c:101: buffer_size_warning: Calling "strncpy" with a maximum size argument of 12 bytes on destination array "fl->fail_line" of size 12 bytes might leave the destination string unterminated.
   99|    }
  100|
  101|->  strncpy (fl->fail_line, tty, sizeof fl->fail_line);
  102|    (void) time (&fl->fail_time);
  103|

Error: BUFFER_SIZE (CWE-170): [#def9]
shadow-4.8.1/libmisc/log.c:103: buffer_size_warning: Calling "strncpy" with a maximum size argument of 32 bytes on destination array "newlog.ll_line" of size 32 bytes might leave the destination string unterminated.
  101|    (void) time (&ll_time);
  102|    newlog.ll_time = ll_time;
  103|->  strncpy (newlog.ll_line, line, sizeof newlog.ll_line);
  104|   #if HAVE_LL_HOST
  105|    strncpy (newlog.ll_host, host, sizeof newlog.ll_host);

Error: BUFFER_SIZE (CWE-170): [#def10]
shadow-4.8.1/libmisc/log.c:105: buffer_size_warning: Calling "strncpy" with a maximum size argument of 256 bytes on destination array "newlog.ll_host" of size 256 bytes might leave the destination string unterminated.
  103|    strncpy (newlog.ll_line, line, sizeof newlog.ll_line);
  104|   #if HAVE_LL_HOST
  105|->  strncpy (newlog.ll_host, host, sizeof newlog.ll_host);
  106|   #endif
  107|    if (   (lseek (fd, offset, SEEK_SET) != offset)

Error: BUFFER_SIZE (CWE-170): [#def13]
shadow-4.8.1/libmisc/utmp.c:260: buffer_size_warning: Calling "strncpy" with a maximum size argument of 32 bytes on destination array "utent->ut_line" of size 32 bytes might leave the destination string unterminated.
  258|   #endif /* HAVE_STRUCT_UTMP_UT_TYPE */
  259|    utent->ut_pid = getpid ();
  260|->  strncpy (utent->ut_line, line,      sizeof (utent->ut_line));
  261|   #ifdef HAVE_STRUCT_UTMP_UT_ID
  262|    if (NULL != ut) {

Error: BUFFER_SIZE (CWE-170): [#def14]
shadow-4.8.1/libmisc/utmp.c:266: buffer_size_warning: Calling "strncpy" with a maximum size argument of 4 bytes on destination array "utent->ut_id" of size 4 bytes might leave the destination string unterminated.
  264|    } else {
  265|    /* XXX - assumes /dev/tty?? */
  266|->  strncpy (utent->ut_id, line + 3, sizeof (utent->ut_id));
  267|    }
  268|   #endif /* HAVE_STRUCT_UTMP_UT_ID */

Error: BUFFER_SIZE (CWE-170): [#def15]
shadow-4.8.1/libmisc/utmp.c:273: buffer_size_warning: Calling "strncpy" with a maximum size argument of 32 bytes on destination array "utent->ut_user" of size 32 bytes might leave the destination string unterminated.
  271|   #endif /* HAVE_STRUCT_UTMP_UT_NAME */
  272|   #ifdef HAVE_STRUCT_UTMP_UT_USER
  273|->  strncpy (utent->ut_user, name,      sizeof (utent->ut_user));
  274|   #endif /* HAVE_STRUCT_UTMP_UT_USER */
  275|    if (NULL != hostname) {

Error: BUFFER_SIZE (CWE-170): [#def16]
shadow-4.8.1/libmisc/utmp.c:278: buffer_size_warning: Calling "strncpy" with a maximum size argument of 256 bytes on destination array "utent->ut_host" of size 256 bytes might leave the destination string unterminated.
  276|    struct addrinfo *info = NULL;
  277|   #ifdef HAVE_STRUCT_UTMP_UT_HOST
  278|->  strncpy (utent->ut_host, hostname, sizeof (utent->ut_host));
  279|   #endif /* HAVE_STRUCT_UTMP_UT_HOST */
  280|   #ifdef HAVE_STRUCT_UTMP_UT_SYSLEN

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
3 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|

3 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.

3 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

3 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

3 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

3 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

3 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>
3 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

3 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>
3 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

3 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

3 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

3 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

3 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)

3 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

3 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>
3 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.

3 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>
3 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

3 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>
3 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

3 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>
3 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>
3 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

3 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