Compare commits

...

626 Commits

Author SHA1 Message Date
Serge Hallyn
e2512d5741 Release 4.17.0
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-12-25 16:32:40 -06:00
Pranav Lawate
881a506ce4 Added information in lastlog man page for new option '-a'
Signed-off-by: Pranav Lawate <pran.lawate@gmail.com>
2024-12-25 08:40:46 -06:00
Alejandro Colomar
8821d3ff2d lib/fs/readlink/: readlinknul(): Fix return type
Fixes: 419ce14b6f (2024-11-01, "lib/fs/readlink/: readlinknul(): Add function")
Cc: Serge Halyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-09 21:26:00 -06:00
Alejandro Colomar
b9d00b64a1 lib/fs/readlink/readlinknul.h: readlinknul(): Silence warning
Use a temporary variable to silence a sign-mismatch diagnostic.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-09 21:26:00 -06:00
Pranav Lawate
205c23bff2 Added option -a for listing active users only, optimized using if aflg,return
Signed-off-by: Pranav Lawate <pran.lawate@gmail.com>
2024-12-09 21:04:21 -06:00
Alejandro Colomar
c39305569b lib/, src/: Use !streq() instead of its pattern
Except for the added (and sorted) includes, the removal of redundant
parentheses, and a few non-string cases that I've left out of the
change, this patch can be approximated with the following semantic
patch:

	$ cat ~/tmp/spatch/strneq.sp
	@@
	expression s;
	@@

	- '\0' != *s
	+ !streq(s, "")

	@@
	expression s;
	@@

	- '\0' != s[0]
	+ !streq(s, "")

	@@
	expression s;
	@@

	- *s != '\0'
	+ !streq(s, "")

	@@
	expression s;
	@@

	- s[0] != '\0'
	+ !streq(s, "")

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --in-place --sp-file ~/tmp/spatch/strneq.sp;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-09 20:54:42 -06:00
Alejandro Colomar
7182d6402f lib/, src/: Use streq() instead of its pattern
Except for the added (and sorted) includes, the removal of redundant
parentheses, a few cases that have been refactored for readability, and
a couple of non-string cases that I've left out of the change, this
patch can be approximated with the following semantic patch:

	$ cat ~/tmp/spatch/streq.sp
	@@
	expression s;
	@@

	- '\0' == *s
	+ streq(s, "")

	@@
	expression s;
	@@

	- '\0' == s[0]
	+ streq(s, "")

	@@
	expression s;
	@@

	- *s == '\0'
	+ streq(s, "")

	@@
	expression s;
	@@

	- s[0] == '\0'
	+ streq(s, "")

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --in-place --sp-file ~/tmp/spatch/streq.sp;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-09 20:54:42 -06:00
Alejandro Colomar
8424d7c494 lib/sgetgrent.c: sgetgrent(): Fix use-after-free bug
We were reusing a leftover from parsing a previous line if
(i == NFIELDS-1).  A few lines below this check, we use read the element
in [3] (that is, [NFIELDS-1]), without having written it in this call.

Be stricter, and require that all NFIELDS fields are found.

Fixes: 45c6603cc8 (2007-10-07, "[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Closes: <https://github.com/shadow-maint/shadow/issues/1144>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-09 19:46:29 -06:00
Serge Hallyn
b75ea29821 Release 4.17.0-rc1
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-12-05 23:52:36 -06:00
Alejandro Colomar
2f74389334 lib/gshadow.c: build_list(): Transform while loop into for loop
And 'n' is now an iterator.  Rename it to 'i' as usual.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
512deecca5 lib/gshadow.c: build_list(): Allocate at once
Instead of reallocating 1 more meber per iteration, calculate the total
amount that we want by counting the number of commas (delimiters) in the
string, plus one for the last element, plus one for the terminating
NULL.

This might result in overallocation of one element if the string is an
empty string, or if there's a trailing comma; however, that's not an
issue.  We can afford overallocating one element in certain cases, and
we get in exchange a much simpler function.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
2f4b5f5d80 lib/gshadow.c: Remove redundant variables
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
5ba62265b3 lib/gshadow.c: build_list(): Remove second parameter
We've simplified the function so much in the previous commits, that now
$2 is rather useless.  It only sets the output parameter to the same
value that the function returns.  It's simpler if the caller just sets
it itself after the call.

This removes the only 3-star pointer in the entire project.  :)

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
c1d597acbb lib/gshadow.c: sgetsgent(): Be consistent using NULL
0 is a horrible null-pointer constant.  Don't use it.
Especially, when just a few lines above, in the same function,
we've used NULL for the same thing.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
64ab7221fb lib/gshadow.c: build_list(): Compact ++ into previous statement
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
3feff7ae5b lib/gshadow.c: build_list(): Minimize use of pointer parameters
Use instead automatic variables as much as possible.
This reduces the number of dereferences, enhancing readability.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
30bcd185c3 lib/gshadow.c: Remove dead code
Nothing is using that value outside of build_list().
Keep it as an local variable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
ecce8f098d lib/gshadow.c: Move zeroing to within build_list()
This makes build_list() less dependent on the context.
It starts from clean, whatever the state before the call was.
I was having a hard time understanding the reallocation,
until I saw that we were zeroing everything right before the call.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
712278add1 lib/gshadow.c: sgetsgent(): Remove superfluous condition
If n was 0, it doesn't hurt to set it again to 0;
and the list would be NULL, so it doesn't hurt free(3)ing it
and setting to NULL again either.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
de4715d978 lib/gshadow.c: build_list(): Remove dead assignment
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
f3464103fb lib/gshadow.c: build_list(): Improve variable and parameter names
It was hard to understand what each variable is.  Use a consistent
scheme, where a 'p' means a pointer, 'l' means list, and 'n' means
number of elements.  Those should be obvious from the name of the
function and the context, and will make it easier to read the code.
Also, the shorter names will allow focusing on the rest of the code.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
93887b4de6 lib/gshadow.c: build_list(): Remove unused variable
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
960947135c lib/gshadow.c: build_list(): Fix type of parameter
list ($2) is a pointer to a list of strings.  We were declaring it as an
array of pointers to strings, which was bogus.  It worked out of luck,
because array parameters are transformed into pointers by the compiler,
but it was incorrect.  Just look at how we're calling this function.

	$ grep build_list lib/gshadow.c
	build_list(char *s, char ***list, size_t *nlist)
		sgroup.sg_adm = build_list (fields[2], &admins, &nadmins);
		sgroup.sg_mem = build_list (fields[3], &members, &nmembers);
	$ grep '^static .*\<admins\>' lib/gshadow.c
	static /*@null@*//*@only@*/char **admins = NULL;
	$ grep '^static .*\<members\>' lib/gshadow.c
	static /*@null@*//*@only@*/char **members = NULL;

Fixes: 8e167d28af ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
c8c1059384 src/: Transform do-while into while
list cannot be NULL in the first iteration, so we don't need a do-while.

Just in case it's not obvious: we know it's not NULL in the first
iteration because right above, in line 772, we've already dereferenced
it.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 21:20:59 -06:00
Alejandro Colomar
90afe61003 lib/, src/: Use strsep(3) instead of strtok(3)
strsep(3) is stateless, and so is easier to reason about.

It also has a slight difference: strtok(3) jumps over empty fields,
while strsep(3) respects them as empty fields.  In most of the cases
where we were using strtok(3), it makes more sense to respect empty
fields, and this commit probably silently fixes a few bugs.

In other cases (most notably filesystem paths), contiguous delimiters
("//") should be collapsed, so strtok(3) still makes more sense there.
This commit doesn't replace such strtok(3) calls.

While at this, remove some useless variables used by these calls, and
reduce the scope of others.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-05 15:33:32 -06:00
Iker Pedrosa
bdb5e2b79f CI: update artifacts action
v3 of upload-artifact actions is being deprecated, so let's move to v4.

Link: https://github.com/actions/upload-artifact
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-12-05 14:31:23 +01:00
Dennis Baurichter
f220407144 groupadd, groupmod: Update gshadow file with -U
When running groupadd or groupmod with the -U|--user option, also update
the group shadow database if it is used.

Fixes: 342c934a (2020-08-09, "add -U option to groupadd and groupmod")
Closes: <https://github.com/shadow-maint/shadow/issues/1124>
2024-12-03 11:16:13 +01:00
Alejandro Colomar
9f129146ff lib/, src/: Use !streq() instead of its pattern
Except for the added (and sorted) includes, and the removal of redundant
parentheses, and one special case, this patch can be approximated with
the following semantic patch:

	$ cat ~/tmp/spatch/strneq.sp;
	@@
	expression a, b;
	@@

	- strcmp(a, b) != 0
	+ !streq(a, b)

	@@
	expression a, b;
	@@

	- 0 != strcmp(a, b)
	+ !streq(a, b)

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --sp-file ~/tmp/spatch/strneq.sp --in-place;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-01 22:23:19 -06:00
Alejandro Colomar
5581e74188 contrib/, lib/, src/: Use streq() instead of its pattern
Except for the added (and sorted) includes, and the removal of redundant
parentheses, this patch can be approximated with the following semantic
patch:

	$ cat ~/tmp/spatch/streq.sp;
	@@
	expression a, b;
	@@

	- strcmp(a, b) == 0
	+ streq(a, b)

	@@
	expression a, b;
	@@

	- 0 == strcmp(a, b)
	+ streq(a, b)

	@@
	expression a, b;
	@@

	- !strcmp(a, b)
	+ streq(a, b)

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --sp-file ~/tmp/spatch/streq.sp --in-place;
	$ git restore lib/string/strcmp/streq.h;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-01 22:23:19 -06:00
Alejandro Colomar
212ef97449 lib/gshadow_.h: __STDC__ is always 1
We require C11 since a long time ago.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-01 22:04:24 -06:00
Alejandro Colomar
1d6456542c lib/csrand.c: csrand(): Use read(2) instead of fread(2)
We don't need the heavy stdio for getting a few bytes from
</dev/urandom>.  Let's use the simpler POSIX API.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-01 21:43:25 -06:00
Alejandro Colomar
627b7364b5 src/login_nopam.c: resolve_hostname(): Use NI_MAXHOST instead of MAXHOSTNAMELEN with getnameinfo(3)
That's what the getnameinfo(3) manual page recommends.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-12-01 20:59:28 -06:00
Volker Theile
a65fccf199 Allow setting an empty homedir
With the PR 352 it is not possible anymore to run `usermod --home "" <USERNAME>`. This PR will fix that regression.

Related to: https://github.com/shadow-maint/shadow/pull/352

Signed-off-by: Volker Theile <votdev@gmx.de>
2024-11-27 09:51:06 -06:00
Alejandro Colomar
365279ea95 share/container-build.sh: Fix path
The instructions are written so that this script should be run from the
root of the repository.  Specify the path from the root of the repo.
Before this fix, the command needed to be run from within <share/>.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-25 16:23:43 +01:00
Iker Pedrosa
742a230e30 CI: avoid cancelling all jobs when one fails
If a job in a matrix fails we don't want to cancel all jobs, thus we
need to set `fail-fast: false` as a strategy property.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-11-23 01:04:19 +01:00
Tobias Stoeckmann
929e61d604 lib/idmapping.c: Fix get_map_ranges range check
The get_map_ranges function shall support the whole accepted range
as specified in user_namespaces(7), i.e. upper and lower from 0 to
UINT_MAX - 1 as well as range from 1 to UINT_MAX. The actual limit of
range depends on values of upper and lower and adding the range
to either upper or lower shall never overflow UINT_MAX.

Fixes: 7c43eb2c4e (2024-07-11, "lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call")
Fixes: ff2baed5db (2016-08-14, "idmapping: add more checks for overflow")
Fixes: 94da3dc5c8 (2016-08-14, "also check upper for wrap")
Fixes: 7f5a14817d (2016-07-31, "get_map_ranges: check for overflow")
Co-authored-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-13 18:17:03 +01:00
Alejandro Colomar
0b8c0c893c lib/, src/: Use NULL instead of 0 as a null pointer constant
GCC 15 will add -Wzero-as-null-pointer-constant for deprecating it,
and I'm working on a paper for deprecating it from ISO C too.
Let's remove any uses in our code base.

I've done this change by building GCC from master, adding
-Werror=zero-as-null-pointer-constant to ./autogen.sh, and fixing every
error that showed up.

Closes: <https://github.com/shadow-maint/shadow/issues/1120>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117059>
Link: <https://software.codidact.com/posts/292718/292759#answer-292759>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-13 09:44:54 -06:00
Alejandro Colomar
8296e62957 lib/shadow.c: my_sgetspent(): There can be only one!
We already have sgetspent(), with identical semantics, defined in
<lib/sgetspent.c>.

	$ diff -u <(grepc sgetspent .) <(grepc my_sgetspent .)
	--- /dev/fd/63	2024-11-11 11:56:55.444055921 +0100
	+++ /dev/fd/62	2024-11-11 11:56:55.444055921 +0100
	@@ -1,23 +1,19 @@
	-./lib/sgetspent.c:struct spwd *
	-sgetspent(const char *string)
	+./lib/shadow.c:static struct spwd *my_sgetspent (const char *string)
	 {
	-	static char spwbuf[PASSWD_ENTRY_MAX_LENGTH];
	-	static struct spwd spwd;
	-	char *fields[FIELDS];
	-	char *cp;
	-	int i;
	+	int                 i;
	+	char                *fields[FIELDS];
	+	char                *cp;
	+	static char         spwbuf[BUFSIZ];
	+	static char         empty[] = "";
	+	static struct spwd  spwd;

		/*
		 * Copy string to local buffer.  It has to be tokenized and we
		 * have to do that to our private copy.
		 */

	-	if (strlen (string) >= sizeof spwbuf) {
	-		fprintf (shadow_logfd,
	-		         "%s: Too long passwd entry encountered, file corruption?\n",
	-		         shadow_progname);
	-		return NULL;	/* fail if too long */
	-	}
	+	if (strlen (string) >= sizeof spwbuf)
	+		return 0;
		strcpy (spwbuf, string);
		stpsep(spwbuf, "\n");

	@@ -30,14 +26,16 @@
			fields[i] = strsep(&cp, ":");

		if (i == (FIELDS - 1))
	-		fields[i++] = "";
	+		fields[i++] = empty;

		if (cp != NULL || (i != FIELDS && i != OFIELDS))
	-		return NULL;
	+		return 0;

		/*
		 * Start populating the structure.  The fields are all in
	-	 * static storage, as is the structure we pass back.
	+	 * static storage, as is the structure we pass back.  If we
	+	 * ever see a name with '+' as the first character, we try
	+	 * to turn on NIS processing.
		 */

		spwd.sp_namp = fields[0];
	@@ -46,13 +44,13 @@
		/*
		 * Get the last changed date.  For all of the integer fields,
		 * we check for proper format.  It is an error to have an
	-	 * incorrectly formatted number.
	+	 * incorrectly formatted number, unless we are using NIS.
		 */

		if (fields[2][0] == '\0')
			spwd.sp_lstchg = -1;
		else if (a2sl(&spwd.sp_lstchg, fields[2], NULL, 0, 0, LONG_MAX) == -1)
	-		return NULL;
	+		return 0;

		/*
		 * Get the minimum period between password changes.
	@@ -61,7 +59,7 @@
		if (fields[3][0] == '\0')
			spwd.sp_min = -1;
		else if (a2sl(&spwd.sp_min, fields[3], NULL, 0, 0, LONG_MAX) == -1)
	-		return NULL;
	+		return 0;

		/*
		 * Get the maximum number of days a password is valid.
	@@ -70,7 +68,7 @@
		if (fields[4][0] == '\0')
			spwd.sp_max = -1;
		else if (a2sl(&spwd.sp_max, fields[4], NULL, 0, 0, LONG_MAX) == -1)
	-		return NULL;
	+		return 0;

		/*
		 * If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
	@@ -93,7 +91,7 @@
		if (fields[5][0] == '\0')
			spwd.sp_warn = -1;
		else if (a2sl(&spwd.sp_warn, fields[5], NULL, 0, 0, LONG_MAX) == -1)
	-		return NULL;
	+		return 0;

		/*
		 * Get the number of days of inactivity before an account is
	@@ -103,7 +101,7 @@
		if (fields[6][0] == '\0')
			spwd.sp_inact = -1;
		else if (a2sl(&spwd.sp_inact, fields[6], NULL, 0, 0, LONG_MAX) == -1)
	-		return NULL;
	+		return 0;

		/*
		 * Get the number of days after the epoch before the account is
	@@ -113,7 +111,7 @@
		if (fields[7][0] == '\0')
			spwd.sp_expire = -1;
		else if (a2sl(&spwd.sp_expire, fields[7], NULL, 0, 0, LONG_MAX) == -1)
	-		return NULL;
	+		return 0;

		/*
		 * This field is reserved for future use.  But it isn't supposed
	@@ -123,8 +121,7 @@
		if (fields[8][0] == '\0')
			spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
		else if (str2ul(&spwd.sp_flag, fields[8]) == -1)
	-		return NULL;
	+		return 0;

		return (&spwd);
	 }
	-./lib/prototypes.h:extern struct spwd *sgetspent (const char *string);

Closes: <https://github.com/shadow-maint/shadow/issues/1114>
Link: <https://www.youtube.com/watch?v=IpbvtSQvgWM>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-11 16:47:57 -06:00
Alejandro Colomar
19ce8b0abc src/login_nopam.c: Rely on the system's MAXHOSTNAMELEN
The reason for that code seems to be some ancient AIX version that
defined a value that was too small (32).  We don't support such systems.
In the link below, I found the following comment and code:

	 /*
	  * Some AIX versions advertise a too small MAXHOSTNAMELEN value (32).
	  * Result: long hostnames would be truncated, and connections would be
	  * dropped because of host name verification failures. Adrian van Bloois
	  * (A.vanBloois@info.nic.surfnet.nl) figured out what was the problem.
	  */

	#if (MAXHOSTNAMELEN < 64)
	#undef MAXHOSTNAMELEN
	#endif

	/* In case not defined in <sys/param.h>. */

	#ifndef MAXHOSTNAMELEN
	#define MAXHOSTNAMELEN  256             /* storage for host name */
	#endif

Today's systems seem to be much better regarding this macro.  Rely on
them.

Link: <https://sources.debian.org/src/tcp-wrappers/7.6.q-33/workarounds.c/?hl=36#L36>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-10 23:17:41 -06:00
Alejandro Colomar
9d8145acfc lib/gshadow.c: endsgent(): Invert logic to reduce indentation
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-10 23:11:43 -06:00
Alejandro Colomar
99a3ca17df lib/list.c: comma_to_list(): Use strchrcnt() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-10 23:07:19 -06:00
Alejandro Colomar
9efce1ac85 lib/string/strchr/: strchrcnt(): Add function
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-10 23:07:19 -06:00
Alejandro Colomar
67c42427a0 lib/string/strcmp/: streq(): Add function
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-10 23:07:19 -06:00
frostb1te
73e58adc6b src/gpasswd.c: is_valid_user_list(): Fix invalid free(3)
This fix addresses an issue in is_valid_user_list() where the free
operation was attempted on an address not allocated with malloc().  By
duplicating the pointer with xstrdup(users) into dup, and using dup as
the original pointer, we ensure that only the valid pointer is freed,
avoiding an invalid free operation.

This bug was introduced when changing some code that used strchrnul(3)
to use strsep(3) instead.  strsep(3) advances the pointer, unlike the
previous code.

This unconditionally leads to a bug:

-  Passing NULL to free(3), if the last field in the
   colon-separated-value list is non-empty.  This results in a memory
   leak.

-  Passing a pointer to the null byte ('\0') that terminates the string,
   if the last element of the colon-separated-value list is empty.  The
   most obvious reproducer of such a bogus free(3) call is:

       free(strdup("foo:") + 4);

   This results in Undefined Behavior, and could result in allocator
   data corruption.

Fixes: 16cb664865 (2024-07-01, "lib/, src/: Use strsep(3) instead of its pattern")
Suggested-by: <https://github.com/frostb1ten>
Reported-by: <https://github.com/frostb1ten>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Christian Brauner <christian@brauner.io>
2024-11-08 13:42:23 +01:00
Miroslav Cimerman
a0771fc01a man/shadow,man/gshadow: Fix grammar
Signed-off-by: Miroslav Cimerman <mc@doas.su>
2024-11-04 14:17:49 +01:00
Alejandro Colomar
86451e374b lib/fs/readlink/areadlink.h: areadlink(): Use PATH_MAX instead of a magic value
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-01 21:25:50 -05:00
Alejandro Colomar
ed569088cc lib/fs/readlink/areadlink.h: Cosmetic changes
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-01 21:25:50 -05:00
Alejandro Colomar
32f10c3dec lib/fs/readlink/, lib/: areadlink(): Move and rename function
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-01 21:25:50 -05:00
Alejandro Colomar
f8c7955bbb lib/: Use READLINKNUL() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-01 21:25:50 -05:00
Alejandro Colomar
5d5ab18890 lib/: Use readlinknul() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-01 21:25:50 -05:00
Alejandro Colomar
d78d1c2fd7 lib/fs/readlink/readlinknul.h: READLINKNUL(): Add macro
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-01 21:25:50 -05:00
Alejandro Colomar
419ce14b6f lib/fs/readlink/: readlinknul(): Add function
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-11-01 21:25:50 -05:00
Iker Pedrosa
c8c3731e05 CI: fix fedora build problems
The new fedora 41 has been released and some things have changed. Make
sure to install python and python3-dnf and specify the dnf version in
the roles.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-10-31 09:52:54 -05:00
Serge Hallyn
cd8a8da7de CI: fix handling of sources.list
Closes #1088

We can't be sure whether a github runner will have new- or old-
style sources.list, so check whether the new exists, else use
the old style.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-10-31 09:46:51 +01:00
Alejandro Colomar
6266a916c2 lib/loginprompt.c: login_prompt(): Use strtcpy() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-30 21:52:21 -05:00
Alejandro Colomar
3daf3f0cc4 lib/getdef.c: Remove dead code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-30 21:15:30 -05:00
Alejandro Colomar
0589cbc135 lib/fields.c: Remove dead code
A few lines above, we've removed the '\n' already.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-30 21:15:30 -05:00
sgakerru
feead2f639 src/useradd.c: get_groups(): Fix memory leak 2024-10-30 12:58:55 +01:00
Marcin Nowakowski
326889ca81 Fix coverity unbound buffer issues
During coverity scan, there are reported four issues
with unbounded source buffer for each usage of input arg
directly with syslog function.

Sample coverity test report for chsh.c file:

 1. string_size_argv: argv contains strings with unknown size.
 int main (int argc, char **argv)
[...]
 4. var_assign_var: Assigning: user = argv[optind]. Both are now tainted.
 user = argv[optind];
[...]
CID 5771784: (#1 of 1): Unbounded source buffer (STRING_SIZE)
15. string_size: Passing string user of unknown size to syslog.
 SYSLOG ((LOG_INFO, "changed user '%s' shell to '%s'", user, loginsh));

Similar issue is reported three times more:
File: chfn.c, function: main, variable: user
File: passwd.c, function: main, variable: name
File: newgrp.c, function: main, variable: group

This commit is the first approach to fix the reported issues.
The proposed changes add conditions, which verify
the user and group names arguments, including their lengths.
This will not silence the coverity reports, but the change causes
that they are irrelevant and could be ignored.
2024-10-22 15:31:19 +02:00
Alejandro Colomar
afc4b574b7 lib/alloc/realloc*.h: Always reallocate at least 1 byte
glibc's realloc(3) is broken.  It was originally good (I believe) until
at some point, when it was changed to conform to C89, which had a bogus
specification that required that it returns NULL.  C99 fixed the mistake
from C89, and so glibc's realloc(3) is non-conforming to
C99/C11/POSIX.1-2008.  C17 broke again the definition of realloc(3).

Link: <https://github.com/shadow-maint/shadow/pull/1095>
Link: <https://nabijaczleweli.xyz/content/blogn_t/017-malloc0.html>
Link: <https://inbox.sourceware.org/libc-alpha/5gclfbrxfd7446gtwd2x2gfuquy7ukjdbrndphyfmfszxlft76@wwjz7spd4vd7/T/#t>
Co-developed-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Acked-by: Paul Eggert <eggert@cs.ucla.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-22 10:53:06 +02:00
Alejandro Colomar
12aa29b576 lib/alloc/realloc*.h: Rename macro parameter
This is in preparation for the following commit, which will need this
shorter parameter name to avoid breaking long lines.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-22 10:53:06 +02:00
Alejandro Colomar
30ab822cf3 doc/contributions/introduction.md: Fix typo in link
Fixes: 981bb8f9d1 ("doc: add contributions introduction")
Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-17 17:09:26 +02:00
Iker Pedrosa
0d1faafd3c CI: install libltdl-dev
Required to manage an autoconf macro.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-10-15 10:43:24 +02:00
Iker Pedrosa
c8600f1359 CI: run command as non-root user
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-10-15 10:43:24 +02:00
Iker Pedrosa
339a596374 CI: run Install dependencies workflow
Run this workflow instead of replicating the script every time we need
to install the dependencies.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-10-15 10:43:24 +02:00
Iker Pedrosa
99c4f445c7 CI: update Ubuntu repositories configuration
Recently Ubuntu updated its repositories configuration file from
`/etc/apt/sources.list` to `/etc/apt/sources.list.d/ubuntu.source`.
Thus, we need to update its location to be able to install all the
package dependencies.

In addition, the CI script was trying to uncomment the lines starting
with `deb-src`, but there is none in the new configuration file format.
Replace `Types: deb` by `Types: deb deb-src` at the beginning of the
line instead.

This commit merges all dependency installation scripts into a single
workflow, which will be called from all sites that have to install
dependencies.

Link: https://linuxconfig.org/ubuntus-repository-configuration-ubuntu-sources-have-moved-to-etc-apt-sources-list-d-ubuntu-sources
Closes: https://github.com/shadow-maint/shadow/issues/1088
Reported-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-10-15 10:43:24 +02:00
Alejandro Colomar
4a15739408 src/suauth.c: check_su_auth(): Use pointers to simplify
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-13 20:40:02 -05:00
Alejandro Colomar
fb731369fd src/suauth.c: check_su_auth(): Use strspn(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-13 20:40:02 -05:00
Alejandro Colomar
276f3fde26 lib/gshadow.c: endsgent(): Remove dead assignment
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-13 20:40:02 -05:00
Alejandro Colomar
02d4af7f6f lib/port.c: portcmp(): Use strcmp(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-13 20:40:02 -05:00
Alejandro Colomar
f45adadd28 lib/, src/: Use stpspn() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-13 20:40:02 -05:00
Iker Pedrosa
9035932496 useradd: fix comparison sign for write_full() return
I forgot to change the comparison sign that checks the return value of
write_full()

Closes: https://github.com/shadow-maint/shadow/issues/1072
Fixes: 8903b94c86 ("useradd: fix write_full() return value")
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2313559

Reported-by: <https://github.com/brown-midas>
Suggested-by: <https://github.com/brown-midas>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-10-04 21:01:58 -05:00
kugarocks
6c9e80165b src/useradd.c: Add the missing equals sign
Fixes: a7b169be18 ("src/useradd.c: Use stpsep() to simplify")
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-10-04 20:59:23 -05:00
Alejandro Colomar
7a796897e5 src/check_subid_range.c: Remove dead code
I forgot to remove the setting of errno when I switched from
strtoul_noneg() to str2ul().  strtoul(3) needs errno for determining
success, but str2ul() does not.

Fixes: f3a1e1cf09 ("src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-03 10:38:56 +02:00
Tobias Stoeckmann
af66ffea33 man/subgid,man/subuid: Fix program list
The groupadd utility does not set information in subgid. Instead, list
all programs which actually can do so.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-10-02 13:03:38 +02:00
Tobias Stoeckmann
e7a970a189 man/passwd: Fix typo
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-10-02 13:03:38 +02:00
Alejandro Colomar
759d2373e4 src/useradd.c: Add fmkomstemp() to fix mode of </etc/default/useradd>
The mode of the file should be 644, but mkstemp(2) was transforming it
to 600.

To do this, we need a function that accepts a mode parameter.  While we
don't need a flags parameter, to avoid confusion with mkostemp(2), let's
add both a flags and a mode parameter.

Link: <https://github.com/shadow-maint/shadow/pull/1080>
Reported-by: kugarocks <kugacola@gmail.com>
Suggested-by: kugarocks <kugacola@gmail.com>
Tested-by: kugarocks <kugacola@gmail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-10-01 14:38:59 -05:00
Tobias Stoeckmann
e6a5484ced lib: Eliminate dead code
The tz function is only called if ENV_TZ starts with a slash.

If the specified file cannot be read, the code implies that ENV_TZ
would be returned if it does not start with a slash.

Since we know that it DOES start with a slash, the code can be
simplified to state that "TZ=CST6CDT" is returned as a default if
the specified file cannot be read.

Benefit of this change is that strcpy's use case here can be
easier verified.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-29 12:23:05 +02:00
Tobias Stoeckmann
dd6cddd481 lib/run_part: Adjust style
Remove some of these whitespaces.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-18 14:52:05 +02:00
Tobias Stoeckmann
76c97ed7ec lib/run_part: Unify error messages
At least if they can be assigned directly to a function call.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-18 14:52:05 +02:00
Tobias Stoeckmann
62bd261fbe lib: Fix typo
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-18 14:52:05 +02:00
Tobias Stoeckmann
6b4487e173 lib/run_part: Reduce visibility
The run_part function is only used in run_part.c itself, so no
need to expose it to other files.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-18 14:52:05 +02:00
Tobias Stoeckmann
db395130d1 lib/run_part: Unify logging
Use shadow_logfd for logging instead of fixed stderr to use
shadow's own logging infrastructure.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-18 14:52:05 +02:00
Tobias Stoeckmann
3ac50e1d02 lib/run_part: Use correct data types
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-18 14:52:05 +02:00
Tobias Stoeckmann
81078c57fb Fix typos
Typos in comments and configure output, i.e. no functional change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-09-13 22:27:08 +02:00
Iker Pedrosa
8903b94c86 useradd: fix write_full() return value
write_full() returns -1 on error and useradd was checking another value.

Closes: https://github.com/shadow-maint/shadow/issues/1072
Fixes: f45498a6c2 ("libmisc/write_full.c: Improve write_full()")

Reported-by: <https://github.com/brown-midas>
Suggested-by: <https://github.com/brown-midas>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-09-13 09:44:51 +02:00
Pino Toscano
b2b37863a6 lib/user_busy.c: Include <utmpx.h>
Since:
- utmpx APIs are used in non-Linux code blocks
- <utmpx.h> is already unconditionally included in Linux parts in other
  files
then unconditionally include it in this file as well.

Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
2024-09-12 11:43:39 +02:00
Alejandro Colomar
1f11a5ce5a src/: Recommend --badname only if it is useful
(Review with -w (--ignore-all-space).)

Closes: <https://github.com/shadow-maint/shadow/issues/1067>
Reported-by: Anselm Schüler <mail@anselmschueler.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-09-01 08:17:11 -05:00
Alejandro Colomar
0663c91f80 src/: Invert logic to improve readability
And remove the (now) redundant comments.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-09-01 08:17:11 -05:00
Alejandro Colomar
1c127bd173 lib/chkname.c: is_valid_{user,group}_name(): Set errno to distinguish the reasons
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-09-01 08:17:11 -05:00
Alejandro Colomar
56d52997c3 man/userdel.8.xml: Reword '-f'
The previous wording seemed to say that -f implied -r.  It doesn't; -f
only skips safety checks, so reword accordingly.

Closes: <https://github.com/shadow-maint/shadow/issues/1062>
Reported-by: Martin von Wittich <martin.von.wittich@iserv.eu>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-09-01 07:45:30 -05:00
Alejandro Colomar
f5806e0511 lib/: Chain free(strzero(s))
This reduces the repetition of the argument, which could be error-prone.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-30 21:44:07 -05:00
Alejandro Colomar
dab8de8a72 lib/string/memset/: memzero(), strzero(): Return the pointer
This allows chaining with free(3) on the same line.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-30 21:44:07 -05:00
Alejandro Colomar
87a5145719 lib/: Move memzero.[ch] under lib/string/memset/
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-30 21:44:07 -05:00
Alejandro Colomar
5c0b99c77e po/es.po: wsfix
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-22 22:51:57 -05:00
Alejandro Colomar
3dc840a56a lib/string/strftime.h: STRFTIME(): Tighten macro definition
strftime(3) is not a variadic function; there's exactly one argument
after the format string.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-22 22:51:57 -05:00
Alejandro Colomar
60da937c2f src/chage.c: print_day_as_date(): Handle errors from strfime(3)
Just like we do in day_to_str().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-22 22:51:57 -05:00
Alejandro Colomar
6a2e298a5b src/chage.c: print_day_as_date(): Simplify error handling
If localtime_r(3) fails, just print future, as we do in day_to_str().
It should only fail for unrealistic dates, if at all.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-22 22:51:57 -05:00
Alejandro Colomar
683b3caa62 lib/, src/: Use %F instead of %Y-%m-%d with strftime(3)
%F is specified by ISO C99.  It adds semantic meaning as printing an
ISO 8601 date.

Scripted change:

	$ cat ~/tmp/spatch/strftime_F.sp
	@@
	@@

	- "%Y-%m-%d"
	+ "%F"
	$ find contrib/ lib* src/ -type f \
	| xargs spatch --sp-file ~/tmp/spatch/strftime_F.sp --in-place

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-22 22:51:57 -05:00
Chris Hofstaedtler
04592e4cc7 Remove references to cppw, cpgr
cppw, cpgr were Debian-only tools, which I've dropped in a recent upload.

Upstream should have never had tests for them.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2024-08-12 10:08:45 +02:00
Carles Pina i Estany
e04e493234 Update Catalan translation 2024-08-11 23:22:04 +02:00
Alejandro Colomar
3f5b4b5626 lib/, src/: Use local time for human-readable dates
That is, use localtime_r(3) instead of gmtime_r(3).

Closes: <https://github.com/shadow-maint/shadow/issues/1057>
Reported-by: Gus Kenion <https://github.com/kenion>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Paul Eggert <eggert@cs.ucla.edu>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-08-01 10:12:44 +02:00
Eisuke Kawashima
f3f501c81c doc(login.defs): fix type of TTYPERM 2024-07-18 10:21:21 -05:00
Iker Pedrosa
fffa4d3e27 share/containers: remove unused dockerfiles
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
28ffa634d8 CI: use Ansible build in Github Action
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
4bc0c5b0b8 doc: update documentation to use Ansible build
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
f56e79a2b7 share/container-build.sh: update to use Ansible build
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
d8fb10f7b7 share/ansible: implement distribution selection
Distribution to run can be selected when running `ansible-playbook` by
appending `-e 'distribution=fedora'` to the command.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
80c4e70da0 share/ansible: convert alpine dockerfile to ansible
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
1d6f578f3e share/ansible: convert debian dockerfile to ansible
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
9a53a8aebd share/ansible: move fedora ci_run to its own file
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
36e8015e2b share/.gitignore: add build-out folder
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
df50348a28 share/ansible: create roles
Create `build_container` and `ci_run` roles and move the fedora target
to them.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Iker Pedrosa
9a0cd7a231 share/ansible: convert fedora dockerfile to ansible
Using a dockerfile to build, install and test the code can be
problematic as we can't capture the log files to check what failed in
case of failure. This PR converts the fedora dockerfile to Ansible, an
open source IT automation tool. The tool can be used on the developers
and the CI system to check whether a piece of code can be built,
installed and tested.

This is the first patch in a series, where I will convert the existing
PR workflows to use Ansible instead of dockerfiles.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-07-18 10:17:29 -05:00
Chris Hofstaedtler
dfbc0db895 Makefile.am: avoid warning: EXTRA_DIST multiply defined
automake complained about duplicate definitions of EXTRA_DIST:

autoreconf: running: automake --add-missing --copy --no-force
Makefile.am:19: warning: EXTRA_DIST multiply defined in condition TRUE ...
Makefile.am:3: ... 'EXTRA_DIST' previously defined here
autoreconf: Leaving directory '.'

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2024-07-18 09:21:57 -05:00
Chris Hofstaedtler
11e9627658 tests/libsubid/04_nss: fix setting basedir
Align on variable name BUILD_BASE_DIR for overriding the toplevel
directory. This is the same name as accepted by tests/common/config.sh.

Without this, the test libsubid/04_nss fails in Debian's autopkgtests.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2024-07-18 08:52:35 -05:00
Sebastian Gross
34f213211f man: groupmod: remove misleading -N option
The extra paragraph for --users mentions a -N option. groupmod has no -N
option.

Prevent confusion and remove its appearance.

Signed-off-by: Sebastian Gross <sgross@emlix.com>
2024-07-17 15:48:22 +02:00
Sebastian Gross
48b36a03e8 man: group(add|mod): clarify list format
The --users list option expect a string of comma separated values.
While this might be obvious to some others it is certainly not for others.

Remove this ambiguity.

Closes #848

Signed-off-by: Sebastian Gross <sgross@emlix.com>
2024-07-17 15:48:22 +02:00
Sebastian Gross
9176206a7c man: groupmod: fix misleading param
--append has no argument in groupmod.c but the man pages states GID as
parameter.

In order to avoid confusion remove it from man page.

Signed-off-by: Sebastian Gross <sgross@emlix.com>
2024-07-17 15:48:22 +02:00
Alejandro Colomar
8a93576ff9 lib/chkname.c: An object cannot expand further than the universe in which it resides
If you want a larger object, you'll have to wait at least until the
universe expands so much.

If an implementation doesn't recognize its own limitations, its a bug,
not a feature.

Closes: <https://github.com/shadow-maint/shadow/issues/1052>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-15 15:01:11 +02:00
Alejandro Colomar
63297e836d lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
745281f295 lib/atoi/, *: Split files 2024-07-11 22:42:58 -05:00
Alejandro Colomar
2dda45a390 src/usermod.c: Use id_t for parsing uid_t and gid_t
Use a static_assert(3) to make sure that id_t == uid_t == gid_t.

And use uintmax_t to print it, since on Linux they are unsigned types.

Link: <https://github.com/shadow-maint/shadow/pull/951>
Reviewed-by: Tycho Andersen <tycho@tycho.pizza>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
cfb8df4a91 src/usermod.c: Rename identifiers ralated to [ug]id's
It was unclear why this code is using ulong.  Since these only handle
uid's and gid's, rename the identifiers accordingly, after id_t.

Link: <https://github.com/shadow-maint/shadow/pull/951>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
b73c78581c lib/idmapping.c: get_map_ranges(): Don't exit() from a library function
Fixes: ff2baed5db ("idmapping: add more checks for overflow")
Link: <ff2baed5db (r136635300)>
Reported-by: Alejandro Colomar <alx@kernel.org>
Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
c46c6a6e5a lib/idmapping.c: get_map_ranges(): Simplify iterator variables
Merge two iterator variables into one, and reduce its scope.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
a184c2b555 lib/idmapping.c: get_map_ranges(): Remove dead code
This test is impossible.  The limits specified in a2ul() already cover
this.

Link: <ff2baed5db (r136635300)>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
7c43eb2c4e lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
Link: <ff2baed5db (r136635300)>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
57aa813c73 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call
Link: <ff2baed5db (r136635300)>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
5586f43d48 lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls
Link: <ff2baed5db (r136635300)>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
f89925c219 lib/idmapping.c: get_map_ranges(): Rename local variable
For a pointer iterator used often, a single-letter identifier is more
appropriate.  That reduces the length of lines considerably, avoiding
unnecessary line breaks.  And since we initialize it with

	m = mappings;

it's clear what it is.

Link: <ff2baed5db (r136635300)>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
c2ebd210e7 lib/limits.c: check_logins(): Report LOGIN_ERROR_LOGIN if str2ul() ERANGE
Fixes: 10396f9536 ("* libmisc/limits.c: Parse the limits, umask, nice, maxlogin, file limit with getlog() / getulong().")
Link: <882cf59459>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
568d26d7ed src/login_nopam.c: login_access(): Use stpsep() to simplify
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Alejandro Colomar
a7b169be18 src/useradd.c: Use stpsep() to simplify
This allows using plain strcmp(3) instead of MATCH().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Alejandro Colomar
d95b899bfc lib/nss.c: nss_init(): Use stpsep() instead of strtok_r(3)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Alejandro Colomar
8714ac0cd6 src/suauth.c: check_su_auth(): Use stpsep() to simplify
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Alejandro Colomar
64409c28b7 lib/string/strchr/stpcspn.[ch]: stpcspn(): Remove unused function
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Alejandro Colomar
a33d7430ed lib/attr.h: ATTR_STRING(): It only accepts one argument
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Alejandro Colomar
d91b22cc2f lib/, src/: Use stpsep() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Alejandro Colomar
39da15614e lib/string/strtok/stpsep.[ch]: stpsep(): Add function
This function is somewhat simpler to use than strsep(3) in some cases.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-08 20:25:01 -05:00
Chris Hofstaedtler
843c151f2c lib/find_new_[gu]id.c: include stdint.h for UINT16_MAX/UINT32_MAX
Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2024-07-08 01:19:49 +02:00
Alejandro Colomar
cee79c215a lib/port.c: getportent(): Use strsep(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
882db57f24 lib/port.c: getportent(): Align variables
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
b4b4ff633a lib/port.c: getttyuser(): Use pointer arithmetic to simplify
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
d9d0117e80 lib/port.c: getportent(): Use equivalent code to parse equally-formatted fields
The tty names field and the user names field have the same formatting:
a CSV terminated by a ':'.  Thus, we can --and should-- use the same
exact code for parsing both.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
a198054456 lib/port.c: getportent(): Make sure the aren't too many fields in the CSV
Otherwise, the line is invalidly formatted, and we ignore it.

Detailed explanation:

There are two conditions on which we break out of the loops that precede
these added checks:

-  j is too big (we've exhausted the space in the static arrays)

	$ grep -r -e PORT_TTY -e PORT_IDS lib/port.*
	lib/port.c:	static char *ttys[PORT_TTY + 1];	/* some pointers to tty names     */
	lib/port.c:	static char *users[PORT_IDS + 1];	/* some pointers to user ids     */
	lib/port.c:	for (cp = buf, j = 0; j < PORT_TTY; j++) {
	lib/port.c:			if ((',' == *cp) && (j < PORT_IDS)) {
	lib/port.h: * PORT_IDS - Allowable number of IDs per entry.
	lib/port.h: * PORT_TTY - Allowable number of TTYs per entry.
	lib/port.h:#define	PORT_IDS	64
	lib/port.h:#define	PORT_TTY	64

-  strpbrk(3) found a ':', which signals the end of the comma-sepatated
   list, and the start of the next colon-separated field.

If the first character in the remainder of the string is not a ':', it
means we've exhausted the array size, but the CSV list was longer, so
we'd be truncating it.  Consider the entire line invalid, and skip it.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
c3f97e251e lib/port.c: getportent(): Make sure there are at least 2 ':' in the line
Otherwise, the line is invalidly formatted, and we ignore it.

Closes: <https://github.com/shadow-maint/shadow/issues/1036>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
f1f82c2105 lib/port.c: getportent(): Remove obvious comments
And do some style changes on the corresponding code.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
e790993c5d lib/port.c: getportent(): Rename goto label
This label means we detected a bogus line, and want to skip it and jump
to the next one; rename it accordingly.  'again' seemed to say that it
was somehow looping on the same line.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
bf84b3a855 lib/port.c: getttyuser(): Use goto to break out of nested loops
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
a4b91048e9 lib/port.c: getttyuser(): Remove dead code
port.pt_names cannot be NULL; it always points to the static array ttys.

$ grep -rn pt_names
lib/port.c:157:	port.pt_names = ttys;
lib/port.c:159:		port.pt_names[j] = cp;
lib/port.c:172:	port.pt_names[j] = NULL;
lib/port.c:344:		for (i = 0; NULL != port->pt_names[i]; i++) {
lib/port.c:345:			if (portcmp (port->pt_names[i], tty) == 0) {
lib/port.c:350:		if (port->pt_names[i] == 0) {
lib/port.h:39: *	pt_names - pointer to array of device names in /dev/
lib/port.h:45:	char **pt_names;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-06 07:44:02 -05:00
Alejandro Colomar
53ea42e67f contrib/adduser.c: main(): Use strcpy/cat(3) instead of their pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
59e5eef38f contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
c6018240f8 lib/, src/: Use strrspn() instead of its pattern
This requires changing isspace(3) calls to an explicit accept string,
and I chose " \t\n" for it (as is done in other parts of this project),
which isn't exactly the same, but we probably don't want other
isspace(3) characters in those files, so it should work.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
7c9da42db0 lib/sssd.c: Style fixes
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
813c3ec6c5 src/login_nopam.c: login_access(): Simplify, calling strchr(3)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
9174697469 lib/getdef.c: def_load(): Use stp[c]spn() instead of their patterns
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
2fcf520184 lib/string/strchr/: stp[c]spn(), strrspn(), strnul(): Add macros and functions
Often, a pointer is more useful than a length when calling these.

Link: <https://docs.oracle.com/cd/E86824_01/html/E54769/strrspn-3gen.html>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
b38ee0c6d0 src/chage.c: Simplify, by calling a2sl() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
ab9f4da83f src/faillog.c: Simplify, by calling str2sh() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
0464c1abf1 src/usermod.c: Simplify, by calling a2sl() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
e341291f99 src/passwd.c: Simplify, by calling a2sl() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
b178fed180 src/useradd.c: Simplify, by calling a2sl() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
ebdeb8f22a src/: Use get_[ug]id() where appropriate
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
a11ae5cf29 lib/shadow.c: my_sgetspent(): Simplify error handling
Handle negative values as errors from a2sl(), and reuse its
error-handling code.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
7e754cc447 lib/shadow.c: my_sgetspent(): Remove dead code
spwd.sp_flag is an unsigned long, which can never be negative.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
e9cc053df7 lib/shadow.c: my_sgetspent(): Merge 'else {if}' into 'else if'
This reduces indentation.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
326bdfe70b lib/sgetspent.c: sgetspent(): Simplify, by calling a2sl() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
03521bccce lib/limits.c: setup_limits(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
3fd1d62e29 lib/limits.c: setup_limits(): Simplify, by calling str2si() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
312c3b1389 lib/limits.c: setup_limits(): Simplify, by calling a2si() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
169cbe1f56 lib/limits.c: set_umask(): Simplify, by calling str2i(mode_t, ) instead of str2ul()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
dba5600cef lib/limits.c: set_prio(): Simplify, by calling str2si() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
5f2055c395 lib/getdef.c: getdef_long(): Simplify, by calling a2sl() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
45d4472c92 lib/getdef.c: getdef_unum(): Fix wrong limit check
The limit, since it's an unsigned int, should have been UINT_MAX, not
INT_MAX.  By calling a2ui() we can fix that and simplify too.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
9415ce4a14 lib/getdef.c: getdef_num(): Simplify, by calling a2si() instead of str2sl()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 22:52:31 +02:00
Alejandro Colomar
866d911655 Remove groups(1)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 13:32:13 -05:00
Alejandro Colomar
c7981fdd00 Remove id(1)
Distributions use id(1) from GNU coreutils or BusyBox.  Drop ours.

Closes: <https://github.com/shadow-maint/shadow/issues/1005>
Suggested-by: dkwo <nicolopiazzalunga@gmail.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 13:32:13 -05:00
Alejandro Colomar
379e9c32f7 lib/idmapping.c: Use long constants in prctl(2), and remove 0s
The prctl(2) system-call wrapper is implemented as a variadic function.
This makes it important to pass arguments to it of the right type (and
more importantly of the right width), to avoid undefined behavior.

While at it, check errors with ==-1, not <0, which is more explicit.

Also, PR_SET_KEEPCAPS(2const) doesn't need all arguments, so it can be
called with just two of them; remove unnecessary 0s.

See-also: prctl(2), PR_SET_KEEPCAPS(2const)
Link: <https://lore.kernel.org/linux-man/ddbdyaiptesjalgfmztxideej67e3yaob7ucsmbf6qvriwxiif@dohhxrqgwhrf/T/#med306b5b003f9cc7cc2de69fcdd7ee2d056d0954>
Cc: Xi Ruoyao <xry111@xry111.site>
Cc: Lukas Slebodnik <lslebodn@fedoraproject.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-02 13:12:22 -05:00
Alejandro Colomar
060b0849a6 lib/attr.h: Use C23-style attributes
They're stricter.  The GNU attributes are too lazy, and can be misused
more easily.  Also, mixing both has its own problems.

Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108796>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
4eed3e84a1 lib/gshadow.c: Use XREALLOC() instead of silently continuing on ENOMEM
We should do better, and correctly handle errors, since this is library
code.  However, I'm lazy right now, so let's die hard, and let us
improve this later.

Link: <https://github.com/shadow-maint/shadow/pull/991#discussion_r1660308154>
Reported-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
53e1eb4045 src/: Remove dead code
FIRST_MEMBER_IS_ADMIN was never enabled.  And BTW, that code had been
broken for a long time, so probably nobody should manually enable it.

Link: <https://github.com/shadow-maint/shadow/pull/991#discussion_r1660308748>
Reported-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
ba3a51e90f lib/: Use [[gnu::alloc_size(...)]] on allocation functions
Suggested-by: Martin Uecker <uecker@tugraz.at>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
5111e5ed1b lib/: Use multi-line macro definitions
This reduces the complexity of those nested parentheses.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
3049bef9c3 lib/alloc/, lib/, src/, tests/: Organize the allocation APIs in a new subdirectory
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
883bf71fc8 lib/alloc.[ch]: xmalloc(): Remove unused function
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
29f4f03def lib/string/strdup/xstrdup.[ch], lib/, src/: Move xstrdup() to its own file
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
2cf73c99a6 lib/string/strcpy/zustr2stp.[ch], tests/: Remove ZUSTR2STP()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
85a2f36992 src/logoutd.c: Use STRNCAT() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
cb3e2fbdcf src/logoutd.c: Use STRNDUPA() instead of its pattern
STRNDUPA() is equivalent to automatic storage allocation (alloca(3))
+ ZUSTR2STP().

The benefits of this refactor are:

-  The allocation size is always correct, and needs no comments, since
   it's now automatically calculated by the macro.

-  STRNDUPA() is probably more familiar, since
   -  strndupa(3) is a libc function,
   -  STRNDUPA() is the obvious wrapper that
      calculates the size based on the input array.

-  We can remove ZUSTR2STP().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
ac591763fe src/newusers.c: Exit on ENOMEM, by calling xstrdup() instead of strdup(3)
The program was happily ignoring ENOMEM errors.

Fixes: 7f9e196903 ("* NEWS, src/newusers.c, src/Makefile.am: Added support for")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
103ffc5b1d lib/utmp.c: prepare_utmp(): Use xstrdup() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
3c09e40a1f lib/utmp.c: Use XSTRNDUP() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
2a0c0dd24b lib/string/strdup/: XSTRNDUP(), STRNDUPA(): Add macros
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
9a9faf86f0 lib/string/strcpy/strncat.[ch]: STRNCAT(): Add macro
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
d9923431eb src/: Use xasprintf() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
44ba094766 src/groupmems.c: Fix number of elements in allocation
We are setting `sgrent.sg_adm[1] = NULL;`, so we need 2 elements.

Fixes: 87b56b19fb ("* NEWS, src/groupmems.c, man/groupmems.8.xml: Added support for [...]")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
c287317075 lib/gshadow.c: build_list(): Fix REALLOC() nmemb calculation
Fixes: efbbcade43 ("Use safer allocation macros")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
056f1d03ee lib/gshadow.c: build_list(): Fix forever loop on ENOMEM
Before this patch, the function looped while (s != NULL && *s != '\0').
However, nothing was modifying that string if REALLOC() failed, so the
loop was forever.

Fixes: 8e167d28af ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
16cb664865 lib/, src/: Use strsep(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
8176e309ed src/useradd.c: tallylog_reset(): Use Basename() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
964df6ed6e lib/, src/: Use strchrnul(3) instead of its pattern
In the files where #include <string.h> is missing, add it, and sort the
includes.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
077f7b6ade lib/commonio.c: commonio_open(): MALLOC() and REALLOCF() already set ENOMEM
We don't need to set ENOMEM on failure of those functions.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
d611d1a947 lib/: Use REALLOCF() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
23663a1607 lib/, src/: Add missing include
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
bdf00dca44 lib/failure.c: failprint(): Remove dead code
This should have gone into the #else'd branch in 8451bed8b0, and
should have been removed in 3e602b58a2.

Fixes: 8451bed8b0 ("[svn-upgrade] Integrating new upstream version, shadow (4.0.13)")
Fixes: 3e602b58a2 ("Remove HAVE_STRFTIME ifdefs")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
bfb6aad7cb lib/, src/: Always pass NULL to time(2)
See time(2):

BUGS
     Error returns from this system  call  are  indistinguishable  from
     successful  reports  that  the  time  is  a few seconds before the
     Epoch, so the C library wrapper function never sets errno as a re‐
     sult of this call.

     The tloc argument is obsolescent and should always be NULL in  new
     code.  When tloc is NULL, the call cannot fail.

Fixes: 45c6603cc8 ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
761eb07016 lib/getdate.y: NULL doesn't need a cast
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
2cb3deec72 lib/shadow.c: my_sgetspent(): Clarify that we're assigning an empty string
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
5e11e89fd9 lib/, src/: Reduce scope of local variables
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
847a19e7a3 src/login.c: Remove dead code
The functions that set these strings --do_rlogin() and login_prompt()--
make sure to terminate them with a NUL.

Fixes: 3704745289 ("* lib/defines.h: Define USER_NAME_MAX_LENGTH, based on utmp and [...]")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
e5d40a1863 src/logoutd.c: Remove unused variable
wait(2) accepts NULL if the status won't be read.  Simplify.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
89402f5171 src/su.c: save_caller_context(): Remove unused parameter
Fixes: e6c2e43937 ("Hardcoding Prog to known value")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
40ab806066 lib/string/strcpy/, lib/, src/, tests/: Move all copying APIs to a subdirectory
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
22272347b6 lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory
And have a separate file for each pair of APIs.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
89e4be3957 src/get_subid_owners.c: Use uid_t for holding UIDs (and GIDs)
Suggested-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
1f7c00b8f7 src/usermod.c: Fix const correctness
Now that we use liba2i's const-generic macros, we can (and must) use a
'const char **' endp where the input string is 'const char *'.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
7f3ab84714 lib/limits.c: setrlimit_value(): Reimplement in terms of a2i()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
7f86f893ab lib/, po/, src/: get_uid(): Move function to "atoi/getnum.h"
Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
6093c93e81 lib/get_uid.c: get_uid(): Reimplement in terms of a2i()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
8ad2768472 src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
b198c1e782 lib/get_pid.c: get_pidfd_from_fd(): Don't open-code get_fd()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
a80715448b lib/atoi/getnum.[ch]: get_fd(): Add function for parsing a file descriptor from a string
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
1557fac0a5 lib/: get_pid(): Move function to "atoi/getnum.h"
Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
6fd56468c3 lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
509e3bcbf8 lib/: Don't open-code get_gid()
These functions were open-coding get_gid().  Use the actual function.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
f85a07f140 lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
74a2ed4537 lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
678c2a23ee src/: Use str2[u]l() instead of atoi(3)
atoi(3) easily triggers Undefined Behavior.  Replace it by str2[u]l(),
which are safe from that, and add type safety too.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
24695e6f38 tests/unit/test_typetraits.c: Add tests for typetraits.h macros
Suggested-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Alejandro Colomar
500ec3f8f3 lib/typetraits.h: Add macros that give information about a type
In the case of is_unsigned() and is_signed(), the natural thing would be
to compare to 0:

	#define is_unsigned(x)  (((typeof(x)) -1) > 0)
	#define is_signed(x)    (((typeof(x)) -1) < 0)

However, that would trigger -Wtype-limits, so we compare against 1,
which silences that, and does the same job.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Serge Hallyn
2457fc7c6b tests/run_some: make sure unshared root user can descend build dir
This was causing errors in my local testing in vms.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-28 14:45:25 -05:00
Alejandro Colomar
488bf4a519 Makefile.am: Use 'dist-hook' to clean up <tests/unit/Makefile>
Closes: <https://github.com/shadow-maint/shadow/issues/1027>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Co-developed-by: Serge Hallyn <shallyn@cisco.com>
Signed-off-by: Serge Hallyn <shallyn@cisco.com>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-28 09:37:27 -05:00
Serge Hallyn
75ea679799 have_range: open the subid db if needed
When we run for instance

  check_subid_range ubuntu u 100000 65536

when ubuntu user is defined and has that range, it returns no entries
because the subid db is not opened.  Open it in have_range if needed.

I haven't figured out why this ever worked.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-28 16:16:33 +02:00
Serge Hallyn
81b5b26925 libsubid test makefile: fix a typo
Fix a missing space after the -I path

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-28 16:16:33 +02:00
Alejandro Colomar
6e57238bf9 tests/unit/test_xasprintf.c: Fix use of volatile pointer
volatile needs to be casted away behind a [[gnu::noipa]] function, to
make that invisible to the compiler.  Otherwise, the compiler can see
that it is being discarded, and is free to abuse Undefined Behavior.

Closes: <https://github.com/shadow-maint/shadow/issues/1028>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Tested-by: Chris Hofstaedtler <zeha@debian.org>
Reviewed-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-28 08:57:01 -05:00
Alejandro Colomar
3307a8f4f0 tests/unit/test_xasprintf.c: Cosmetic
This is in preparation for the following commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-28 08:57:01 -05:00
Serge Hallyn
d55367bb16 tests/: Support run_some from exported tarball
common/config.sh currently tries to find the top directory by looking
for .git.  There are also many places under tests/ where we use
hard-coded ../../.. to find things like ${TOP_DIR}/lib.

We don't actually ship the tests with 'make dist'.  So we will
be exporting tests/ as a separate tarball.  In particular, I want
to then import this in the debian package.  However, there it will
be under shadow.git/debian/tests, not shadow.git/tests.

To support this, accept the environment variable BUILD_BASE_DIR,
which should point to shadow.git.

An alternative would be to move the tests to their own git
tree.  However, keeping tests in separate git tree tends to
lead to repos getting out of sync.  And we'd still need to accept
something like BUILD_BASE_DIR.

Note there are a lot of tests under run-all, which I'm not converting
as they currently are not being run in CI, so I'm more likely to
break something.

Changelog:
  2024 05 26: Incorporate feedback from alejandro-colomar

Link: <https://salsa.debian.org/debian/shadow/-/merge_requests/21>
Link: <https://salsa.debian.org/debian/shadow/-/merge_requests/22>
Cc: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-26 23:59:07 +02:00
Alejandro Colomar
47edcd3045 lib/csrand.c: Fix the lower part of the domain of csrand_uniform()
I accidentally broke this code during an un-optimization.  We need to
start from a random value of the width of the limit, that is, 32 bits.

Thanks to Jason for pointing to his similar code in the kernel, which
made me see my mistake.

Fixes: 2a61122b5e ("Unoptimize the higher part of the domain of csrand_uniform()")
Closes: <https://github.com/shadow-maint/shadow/issues/1015>
Reported-by: Michael Brunnbauer <https://github.com/michaelbrunnbauer>
Link: <https://git.zx2c4.com/linux-rng/tree/drivers/char/random.c#n535>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Link: <https://github.com/shadow-maint/shadow/pull/638>
Link: <https://github.com/shadow-maint/shadow/issues/634>
Link: <https://github.com/shadow-maint/shadow/pull/624>
Tested-by: Michael Brunnbauer <https://github.com/michaelbrunnbauer>
Reviewed-by: Michael Brunnbauer <https://github.com/michaelbrunnbauer>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-20 21:38:58 -05:00
Serge Hallyn
cde08e422d configure.ac: release 4.16.0
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-18 16:34:10 -05:00
Serge Hallyn
2df2c35bad release 4.16.0-rc1
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-13 21:24:10 -05:00
Serge Hallyn
9b7d786b6f configure.ac: specify tar-pax to avoid 99 char filename limit
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-13 21:24:10 -05:00
Alejandro Colomar
ca046af5d9 Remove support for rlogind in login(1), that is, remove the '-r' flag
The "quick hack" finally disappeared.  Probably nobody noticed.  ;)
(See the changes in <configure.ac> for the context of this pun.)

Probably everybody uses SSH these days for remote login.  Let's remove
this insecure method.

Closes: <https://github.com/shadow-maint/shadow/issues/992>
Reviewed-by: dkwo <nicolopiazzalunga@gmail.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Sam James <sam@gentoo.org>
Cc: Benedikt Brinkmann <datacobra@thinkbot.de>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-13 19:39:26 -05:00
Daniel Bershatsky
df59088641 libsubid: Fix code style issues 2024-06-12 21:45:31 +02:00
Daniel Bershatsky
b620b5d0d1 libsubid: Fail on plugin loading if no subid_free provided 2024-06-12 21:45:31 +02:00
Daniel Bershatsky
29dbcfbabd libsubid: Apply minor fixes 2024-06-12 21:45:31 +02:00
Daniel Bershatsky
0217516349 libsubid: Add routine to free allocated memory 2024-06-12 21:45:31 +02:00
Daniel Bershatsky
18f113cc46 libsubid: Dealocate memory on exit 2024-06-12 18:41:22 +02:00
lixinyun
10429edc14 src/groupmod.c: delete gr_free_members(&grp) to avoid double free
Groupmod -U may cause crashes because of double free. If without -a, the first free of (*ogrp).gr_mem is in gr_free_members(&grp), and then in gr_update without -n or gr_remove with -n.
Considering the minimal impact of modifications on existing code, delete gr_free_members(&grp) to avoid double free.Although this may seem reckless, the second free in two different positions will definitely be triggered, and the following two test cases can be used to illustrate the situation :

[root@localhost src]# ./useradd u1
[root@localhost src]# ./useradd u2
[root@localhost src]# ./useradd u3
[root@localhost src]# ./groupadd -U u1,u2,u3 g1
[root@localhost src]# ./groupmod -n g2 -U u1,u2 g1
Segmentation fault

This case would free (*ogrp).gr_mem in gr_free_members(&grp) due to assignment statements grp = *ogrp, then in if (nflg && (gr_remove (group_name) == 0)), which finally calls gr_free_members(grent) to free (*ogrp).gr_mem again.

[root@localhost src]# ./useradd u1
[root@localhost src]# ./useradd u2
[root@localhost src]# ./useradd u3
[root@localhost src]# ./groupadd -U u1,u2,u3 g1
[root@localhost src]# ./groupmod -U u1,u2 g1
Segmentation fault

The other case would free (*ogrp).gr_mem in gr_free_members(&grp) too, then in if (gr_update (&grp) == 0), which finally calls gr_free_members(grent) too to free (*ogrp).gr_mem again.

So the first free is unnecessary, maybe we can drop it.

Fixes: 342c934a35 ("add -U option to groupadd and groupmod")
Closes: <https://github.com/shadow-maint/shadow/issues/1013>
Link: <https://github.com/shadow-maint/shadow/pull/1007>
Link: <https://github.com/shadow-maint/shadow/pull/271>
Link: <https://github.com/shadow-maint/shadow/issues/265>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: lixinyun <li.xinyun@h3c.com>
2024-06-07 12:42:44 +02:00
Serge Hallyn
8acec35d1d man/lastlog: remove wrong use of keyword term
Per https://tdg.docbook.org/tdg/4.5/term, term is a word being
defined in a varlistentry.  The 'high uid' description is not a
varlistentry, so <term> and </term> show up in the processed
manpage.  See debian Bug#1072297.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-05 15:49:54 +02:00
Alejandro Colomar
69f74dbf8a lib/cast.h: const_cast(): Reimplement with _Generic(3)
This makes it much simpler and portable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-04 09:10:23 +02:00
Iker Pedrosa
4e2453fa9f configure: move cmocka library detection
`PKG_CONFIG` variable needs to be set for `PKG_CHECK_MODULES` to
succeed, but this wasn't happening in Fedora because the first
appearance of `PKG_CHECK_MODULES` was conditionally skipped because this
distribution is compiled without `libbsd` support. Thus, moving the
cmocka library detection before libbsd fixes the problem.

Suggested-by: Lukas Slebodnik <lslebodn@fedoraproject.org>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2024-05-28 19:19:58 -05:00
Serge Hallyn
d0fef040ed tests: add the tests/ subdirectory to dist tarball
This is a first step to helping distributions to use our tests in CI.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-05-28 19:18:39 -05:00
Alejandro Colomar
71e28359d1 lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function
All call sites have been replaced by functions from "atoi/a2i.h" and
"atoi/str2i.h" recently.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-27 16:32:09 +02:00
Alejandro Colomar
f3a1e1cf09 src/check_subid_range.c: Call str2ul() instead of strtoul_noneg()
It is a simpler call, with more type safety.

A consequence of this change is that the program now accepts numbers in
bases 8 and 16.  That's not a problem here, I think.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-27 16:32:09 +02:00
Alejandro Colomar
fb49de61b7 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
All call sites were replaced by a2i() recently.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-27 16:32:09 +02:00
Alejandro Colomar
895dfd77d2 lib/gettime.c: gettime(): Call a2i() instead of strtoull_noneg()
time_t isn't necessarily unsigned (in fact, it's likely to be signed.
Therefore, parse the number as the right type, via a2i(time_t, ...).

Still, reject negative numbers, just to be cautious.  It was done
before (strtoull_noneg()), so it shouldn't be a problem.  (However,
strtoull_noneg() was only introduced recently, and before that we called
strtoull(3), which silently accepted negative values.)

Remove the limitation of ULONG_MAX, which seems arbitrary.  It probably
was written in times where 'time_t' had the same length of 'long', and
this was thus a test that the value didn't overflow 'time_t'.  Such a
test is implicit in the a2i() call, so forget about it.

Unify the error messages into a single one that provides all the info
(except the value of 'fallback').

Link: <cb610d54b4 (r136407772)>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Chris Lamb <lamby@debian.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-27 16:32:09 +02:00
Tianyu Chen
9dddcd29f1 STABLE.md: 4.15.x is now stable 2024-05-22 15:10:03 +02:00
Alejandro Colomar
a6eb312f60 src/login.c: main(): Use login_name_max_size()
Instead of raw sysconf(_SC_LOGIN_NAME_MAX) calls, which was being used
without error handling.

Fixes: 3b7cc05387 ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-21 13:26:41 +02:00
Alejandro Colomar
99df9d746e lib/chkname.[ch]: login_name_max_size(): Add function
It encapsulates some logic that we may want to reuse elsewhere.

Link: <https://github.com/shadow-maint/shadow/pull/989>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-21 13:26:41 +02:00
Alejandro Colomar
27e467a61a lib/chkname.[ch]: Fix includes
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-21 13:26:41 +02:00
Alejandro Colomar
d8e6a8b99b src/usermod.c: update_gshadow(): Add helper function
Keep the while loop in the outer function, and move the iteration code
to this new helper.  This makes it a bit more readable.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
adf37cccd0 src/usermod.c: update_group(): Add helper function
Keep the while loop in the outer function, and move the iteration code
to this new helper.  This makes it a bit more readable.

Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
da77a82ecb src/usermod.c: update_gshadow_file(): Reduce scope of local variable
After _every_ iteration, 'changed' is always 'false'.  We don't need to
have it outside of the loop.

See:

$ grepc update_gshadow_file . \
| grep -e changed -e goto -e continue -e break -e free_ngrp -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
	bool               changed;
	changed = false;
	while ((sgrp = sgr_next ()) != NULL) {
		if (!was_member && !was_admin && !is_member) {
			continue;
		}
		if (was_admin && lflg) {
			changed = true;
		}
		if (was_member) {
			if ((!Gflg) || is_member) {
				if (lflg) {
					changed = true;
				}
			} else {
				changed = true;
			}
		} else if (is_member) {
			changed = true;
		}
		if (!changed)
			goto free_nsgrp;
		changed = false;
	}
}

This was already true in the commit that introduced the code:

$ git show 45c6603cc:src/usermod.c \
| grepc update_gshadow \
| grep -e changed -e goto -e break -e continue -e '\<if\>' -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
	int changed;
	changed = 0;
	while ((sgrp = sgr_next())) {
		 * See if the user was a member of this group
		 * See if the user was an administrator of this group
		 * See if the user specified this group as one of their
		if (!was_member && !was_admin && !is_member)
			continue;
		if (was_admin && lflg) {
			changed = 1;
		}
		if (was_member && (!Gflg || is_member)) {
			if (lflg) {
				changed = 1;
			}
		} else if (was_member && Gflg && !is_member) {
			changed = 1;
		} else if (!was_member && Gflg && is_member) {
			changed = 1;
		}
		if (!changed)
			continue;
		changed = 0;
	}
}

Fixes: 45c6603cc8 ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
68d42a8fbe src/usermod.c: update_group_file(): Reduce scope of local variable
After _every_ iteration, 'changed' is always 'false'.  We don't need to
have it outside of the loop.

See:

$ grepc update_group_file . \
| grep -e changed -e goto -e continue -e break -e free_ngrp -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
	bool                changed;
	changed = false;
	while ((grp = gr_next ()) != NULL) {
		if (!was_member && !is_member) {
			continue;
		}
		if (was_member) {
			if ((!Gflg) || is_member) {
				if (lflg) {
					changed = true;
				}
			} else {
				changed = true;
			}
		} else if (is_member) {
			changed = true;
		}
		if (!changed)
			goto free_ngrp;
		changed = false;
free_ngrp:
	}
}

This was already true in the commit that introduced the code:

$ git show 45c6603cc:src/usermod.c \
| grepc update_group \
| grep -e changed -e goto -e break -e continue -e '\<if\>' -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
	int changed;
	changed = 0;
	while ((grp = gr_next())) {
		 * See if the user specified this group as one of their
		if (!was_member && !is_member)
			continue;
		if (was_member && (!Gflg || is_member)) {
			if (lflg) {
				changed = 1;
			}
		} else if (was_member && Gflg && !is_member) {
			changed = 1;
		} else if (!was_member && Gflg && is_member) {
			changed = 1;
		}
		if (!changed)
			continue;
		changed = 0;
	}
}

Fixes: 45c6603cc8 ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
71a3238b79 src/usermod.c: update_gshadow_file(): Fix RESOURCE_LEAK (CWE-772)
Report:
> shadow-4.15.0/src/usermod.c:864:3: alloc_fn: Storage is returned from allocation function "__sgr_dup".
> shadow-4.15.0/src/usermod.c:864:3: var_assign: Assigning: "nsgrp" = storage returned from "__sgr_dup(sgrp)".
> shadow-4.15.0/src/usermod.c:964:1: leaked_storage: Variable "nsgrp" going out of scope leaks the storage it points to.
> 962|                   free (nsgrp);
> 963|           }
> 964|-> }
> 965|   #endif                                /* SHADOWGRP */
> 966|

Link: https://issues.redhat.com/browse/RHEL-35383
Reported-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
61964aa06b src/usermod.c: update_group_file(): Fix RESOURCE_LEAK (CWE-772)
Report:
> shadow-4.15.0/src/usermod.c:734:3: alloc_fn: Storage is returned from allocation function "__gr_dup".
> shadow-4.15.0/src/usermod.c:734:3: var_assign: Assigning: "ngrp" = storage returned from "__gr_dup(grp)".
> shadow-4.15.0/src/usermod.c:815:1: leaked_storage: Variable "ngrp" going out of scope leaks the storage it points to.
> 813|                   gr_free(ngrp);
> 814|           }
> 815|-> }
> 816|
> 817|   #ifdef SHADOWGRP

Link: https://issues.redhat.com/browse/RHEL-35383
Reported-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
81bc78ec5c src/usermod.c: Rename update_gshadow() => update_gshadow_file()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
b089a63ab3 src/usermod.c: Rename update_group() => update_group_file()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
151f14ad69 src/usermod.c: Reduce scope of local variables
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-20 09:37:01 +02:00
Alejandro Colomar
1ee066ae1e src/useradd.c: set_defaults(): Fix FILE* leak
Report:
> shadow-4.15.0/src/useradd.c:575:2: alloc_fn: Storage is returned from allocation function "fdopen".
> shadow-4.15.0/src/useradd.c:575:2: var_assign: Assigning: "ofp" = storage returned from "fdopen(ofd, "w")".
> shadow-4.15.0/src/useradd.c:734:2: leaked_storage: Variable "ofp" going out of scope leaks the storage it points to.
> 732|           }
> 733|
> 734|->         return ret;
> 735|   }
> 736|

Link: <https://issues.redhat.com/browse/RHEL-35383>
Reported-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-18 01:15:10 +02:00
Alejandro Colomar
e7d1508e07 src/useradd.c: Add fmkstemp() to fix file-descriptor leak
This function creates a temporary file, and returns a FILE pointer to
it.  This avoids dealing with both a file descriptor and a FILE pointer,
and correctly deallocating the resources on error.

The code before this patch was leaking the file descriptor if fdopen(3)
failed.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-18 01:15:10 +02:00
Alejandro Colomar
a74c4b6ae1 src/useradd.c: De-duplicate code
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-18 01:15:10 +02:00
Alejandro Colomar
701fe4cf1a src/useradd.c: set_defaults(): Do not free(3) the result of asprintf(3) if it failed
See asprintf(3):

RETURN VALUE
     When successful,  these  functions  return  the  number  of  bytes
     printed, just like sprintf(3).  If memory allocation wasn’t possi‐
     ble,  or  some other error occurs, these functions will return -1,
     and the contents of strp are undefined.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-18 01:15:10 +02:00
Alejandro Colomar
37ae8827a0 src/useradd.c: set_defaults(): Rename goto label
This will help add other labels in the following commits.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-18 01:15:10 +02:00
Alejandro Colomar
f8fc6371f6 src/useradd.c: set_defaults(): Fix order of clean-ups
Resources should be freed in the inverse order of the allocation.
This refactor prepares for the following commits, which fix some leaks.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-18 01:15:10 +02:00
Iker Pedrosa
4c16416ebc port: fix OVERRUN (CWE-119)
```
shadow-4.15.0/lib/port.c:154:2: alias: Assigning: "port.pt_names" = "ttys". "port.pt_names" now points to element 0 of "ttys" (which consists of 65 8-byte elements).
shadow-4.15.0/lib/port.c:155:2: cond_const: Checking "j < 64" implies that "j" is 64 on the false branch.
shadow-4.15.0/lib/port.c:175:2: overrun-local: Overrunning array of 65 8-byte elements at element index 65 (byte offset 527) by dereferencing pointer "port.pt_names + (j + 1)".
173|           *cp = '\0';
174|           cp++;
175|->         port.pt_names[j + 1] = NULL;
176|
177|           /*
```

Resolves: https://issues.redhat.com/browse/RHEL-35383

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-05-17 16:08:26 +02:00
Alejandro Colomar
0066743c49 lib/getrange.c: getrange(): Report an error when min>max
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-17 15:40:03 +02:00
Alejandro Colomar
29f135777e lib/getrange.c: getrange(): Add missing cast
isdigit(3) requires a cast if the argument is of type 'char'.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-17 15:40:03 +02:00
Alejandro Colomar
34f431f607 lib/getrange.c: getrange(): Add const to pointer
Now that we have const-generic macros, we can use a const pointer.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-17 15:40:03 +02:00
Alejandro Colomar
040ba6a853 lib/getrange.c: getrange(): Use a2ul() instead of strtoul_noneg()
It simplifies the error checking.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-17 15:40:03 +02:00
Alejandro Colomar
b0498564b2 lib/atoi/a2i.[ch]: Add const-generic macros
These overloaded macros allow passing either a const or a non-const
endp, and will call the appropriate function.  This kind of const
overloading has prior art in C23's string functions, such as memchr(3).

Martin suggested using an artificial function pointer in _Generic(3); it
allows switching on various types at the same time.

Also add a comment referring to liba2i's PDF manual for documentation.

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf#subsubsection.7.26.5.2>
Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114731>
Link: <http://www.alejandro-colomar.es/share/dist/liba2i/git/HEAD/liba2i-HEAD.pdf>
Co-developed-by: Martin Uecker <muecker@gwdg.de>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-17 15:40:03 +02:00
Alejandro Colomar
26c9dd3715 lib/alloc.h: Reimplement [X]REALLOC[F]() macros with _Generic(3)
Instead of GNU builtins and extensions, these macros can be implemented
with C11's _Generic(3), and the result is much simpler (and safer, since
it's now an error, not just a warning).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-15 12:08:00 +02:00
Frans Spiesschaert
18ecf3987e updated Dutch translation 2024-05-09 14:25:19 +02:00
Iker Pedrosa
9b3889696b man: update translations for username length
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-05-09 10:56:27 +02:00
Iker Pedrosa
03c31bef87 man: update username length
Fixes: 6a1f45d932 ("lib/chkname.c: Support unlimited user name lengths")
Related-To: https://github.com/shadow-maint/shadow/pull/986

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-05-09 10:56:27 +02:00
Alejandro Colomar
98aefe8772 lib/, src/: Rename some local variables
'endptr' is appropriate internally in strtol(3) because it's a pointer
to 'end', and 'end' itself is a pointer to one-after-the-last character
of the numeric string.  In other words,

	endptr == &end

However, naming the pointer whose address we pass to strtol(3)'s
'endptr' feels wrong, and causes me trouble while parsing the code; I
need to double check the number of dereferences, because something feels
wrong in my head.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
f40bd94856 lib/getrange.c: getrange(): Use goto to deduplicate code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
7af7361fd6 lib/getrange.c: getrange(): Return early
It's doesn't make much sense to break from a switch() just to return.
Let's return early, to simplify.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
bbb2735cc0 lib/getrange.c: getrange(): Return early to reduce indentation
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
d7ab811a36 lib/getrange.c: getrange(): Don't else after return
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
62a4daa2cd lib/getrange.c: getrange(): Return early to remove an else
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
8d8062c770 lib/getrange.c: getrange(): Remove temporary variable
This means we set the pointees on error, which we didn't do before, but
since we return -1 on error and ignore (don't use) the pointees at call
site, that's fine.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
38a0b0a610 lib/getrange.c: getrange(): Small refactor
All 3 non-error paths in the second part resulted in *has_min = true.
Set in once before the switch(), to simplify.

This means we set this variable on error, which we didn't do before,
but since we return -1 on error and ignore (don't use) the pointees at
call site, that's fine.

Also, move a couple of *has_max = true statements to before a comment,
in preparation for future commits.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Alejandro Colomar
6bf5d6d4f3 lib/getrange.c: getrange(): Small refactor
Set *has_{min,max} = false at the begining, so we only need to set them
to true later.

This means we set these variables on error, which we didn't do before,
but since we return -1 on error and ignore (don't use) the pointees at
call site, that's fine.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-04 17:22:57 -05:00
Iker Pedrosa
dbd3527c03 share/containers: update build flags for fedora 40
libpam is enabled to provide `passwd` binary from this package, as there
are several password quality checks that are enabled through a PAM
module. Same reason to disable account-tools-setuid.

sssd is disabled because `files provider` has been removed in sssd, and
the underlying functionality in shadow isn't needed anymore.

libcrack dependency was disabled some time ago, but the upstream repo
wasn't updated. Doing it now.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-05-02 10:45:03 +02:00
Iker Pedrosa
dbf3b1ad51 share/containers: sort configuration options
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-05-02 10:45:03 +02:00
Iker Pedrosa
b8f17f9c29 share/containers: fix indentation in fedora
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-05-02 10:45:03 +02:00
Serge Hallyn
2e01b9d7d2 newuidmap and newgidmap manpages: fix fd description
The manpages for newuidmap and newgidmap had a typo "[pid[" instead
of "[pid]".  They were also unclear about what the /proc/pid fd should
be.  Fix both.

Closes #977

Reported-by: igo95862@yandex.ru
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-04-10 09:18:40 +02:00
Tobias Stoeckmann
5f5b21fd5c lib/env.c: treat out of memory condition as error
If not enough memory is available for more environment variables, treat
it exactly like not enough memory for new environment variable content.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-04-04 20:12:03 +02:00
Alejandro Colomar
f7fe4c5978 lib/atoi/: a2*(), str2*(): Add variants for other types
And type-generic macros that wrap them: a2i(), str2i()

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-29 14:29:13 -05:00
Alejandro Colomar
f39ac101ff lib/, src/: str2*(): Rename functions and reorder parameters
This makes them compatible with liba2i's functions.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-29 14:29:13 -05:00
Alejandro Colomar
b085c3f612 lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-29 14:29:13 -05:00
Alejandro Colomar
27e236ca79 lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
And make them inline.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-29 14:29:13 -05:00
Serge Hallyn
dc12e87fe7 configure.ac: release 4.15.1
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-03-23 18:33:45 -05:00
Alejandro Colomar
4827da0a2f src/login.c: Use localtime_r(3) instead of localtime(3)
This silences a CodeQL warning.  We don't care about reentrancy, but
after this patch we don't need to break a long line, so that's a win.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-24 00:16:00 +01:00
Alejandro Colomar
0460dac019 lib/, src/: Use STRFTIME() instead of its pattern
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-24 00:16:00 +01:00
Alejandro Colomar
b3affb29cf lib/string/strftime.[ch]: STRFTIME(): Add macro
This macro makes sure that the first argument is an array, and
calculates its size.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-24 00:16:00 +01:00
Serge Hallyn
0b3d017276 man/Makefile.am: ship config.xml
Other man/*.xml's import it, so they need it shipped as well.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-03-23 16:39:07 -05:00
Serge Hallyn
e08db2de4c man/po/Makefile.in: avoid unnecessary changes to git indexed files
Keep pot creation date out of our po files when we compare them.
Otherwise, we always think they need to be updated.

We prepend a line '# To re-generate, ....' to the shadow-man-pages.pot
file.  Do that before we compare the new candidate, because right
now our comparison to see if we've made changes always thinks we have.

Put some of the tempfiles in a mktemp -d'd directory, which we remove when
all's done.  This keeps the working tree cleaner.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-03-23 16:39:07 -05:00
Serge Hallyn
55c107617e update translations
Update .po and .pot files to reflect some changes in print
statements.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-03-23 16:39:07 -05:00
Serge Hallyn
673ff74fd4 Makefile.am: clean some tempfiles
Add some temporary files to CLEANFILES

Put test-driver in .gitignore

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-03-23 16:39:07 -05:00
Serge Hallyn
ead55e9ba8 getdef: avoid spurious error messages about unknown configuration options
def_find can return NULL for unset, not just unknown, config options.  So
move the decision of whether to log an error message about an unknown config
option back into def_find, which knows the difference.  Only putdef_str()
will pass a char* srcfile to def_find, so only calls from putdef_str will
cause the message, which was the original intent of fa68441bc4.

closes #967

fixes: fa68441bc4 ("Improve the login.defs unknown item error message")
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-03-21 11:21:33 +05:30
Enrico Scholz
000619344d lib/copydir:copy_entry(): use temporary stat buffer
There are no guarantees that fstatat() does not clobber the stat
buffer on errors.

Use a temporary buffer so that the following code sees correct
attributes of the source entry.

Issue #973

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
2024-03-21 02:44:12 +01:00
Antoine Roux
51a0d94a08 Fix wrong french translation
32 characters were wrongly translated to 16 in french translation file
2024-03-20 09:58:51 +05:30
Eli Schwartz
e44a9e631d gitignore: add a few more generated files to be ignored
before this, the following untracked files showed up in `git status`:

	lib/atoi/.dirstamp
	lib/string/.dirstamp
	lib/time/.dirstamp
	man/da/login.defs.d
	man/da/messages.mo
	man/de/login.defs.d
	man/de/messages.mo
	man/fr/login.defs.d
	man/fr/messages.mo
	man/it/login.defs.d
	man/it/messages.mo
	man/pl/login.defs.d
	man/pl/messages.mo
	man/ru/login.defs.d
	man/ru/messages.mo
	man/sv/login.defs.d
	man/sv/messages.mo
	man/uk/login.defs.d
	man/uk/messages.mo
	man/zh_CN/login.defs.d
	man/zh_CN/messages.mo
	test-driver

Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2024-03-18 17:06:07 -05:00
Samanta Navarro
2b67dc7765 lib/pam_pass_non_interactive.c: use strzero/free
The combination of bzero and free could be optimized away.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2024-03-14 17:20:30 -05:00
Alejandro Colomar
fce1d88479 lib/list.c: is_on_list(): Call strsep(3) instead of open-coding it
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
46fd68c37e lib/list.c: is_on_list(): Move break condition to loop controlling expression
This change executes `i++` one more time before breaking, so we need to
update the `i+1` after the loop to just `i`.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
fb01e07e83 lib/list.c: is_on_list(): Move code out of loop
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
08ae38e394 lib/list.c: is_on_list(): Remove unnecessary use of temporary variable
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
34b113baba lib/sgetspent.c: sgetspent(): Explicitly use an empty string literal
cp can only be an empty string literal in that conditional.  Use a
string literal to be more explicit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
93151689c0 lib/sgetspent.c: sgetspent(): Use NULL instead of 0 to mean a null pointer constant
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
ae17e0291d lib/port.c: getportent(): Call strpbrk(3) instead of open-coding it
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
03677d9acf lib/: Call strsep(3) instead of open-coding it
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
5f8f19f267 lib/: Call strchrnul(3) instead of open-coding it
Performance tests made in 2007 are obsolete.  We should assume libc is
reasonably fast today (otherwise, report a bug to libc).

$ git blame -- lib/sgetgrent.c | grep strchr
45c6603cc (nekral-guest      2007-10-07 11:44:02 +0000  30)  *	WARNING: I profiled this once with and without strchr() calls
6f88bcf58 (nekral-guest      2008-05-26 08:31:14 +0000  97) 		cp = strchr (cp, ':');

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 17:11:36 -05:00
Alejandro Colomar
bed18501b1 lib/, src/: Call gmtime_r(3) instead of gmtime(3)
It's trivial to do the change, and it removes a CodeQL warning.
We don't need to be reentrant, but it doesn't hurt either.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:30:46 -05:00
Alejandro Colomar
8fcf6cccff lib/time/day_to_str.[ch]: day_to_str(): Accept a day instead of a date, and rename function
It was always being called with 'day * DAY', so do that internally and
simplify.  This grabs some code from print_day_as_date().

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:30:46 -05:00
Alejandro Colomar
8fee869e9a src/passwd.c: print_status(): Fix typo (bogus use of the comma operator)
Amazing that this triggered no warnings at all.

Fixes: 355ad6a9e0 ("Have a single definition of date_to_str()")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:30:46 -05:00
Alejandro Colomar
82e28ad534 src/: Use DAY_TO_STR() instead of its pattern
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:30:46 -05:00
Alejandro Colomar
19edb06fd2 lib/time/day_to_str.h: DAY_TO_STR(): Add macro
This macro ensures that the buffer is an array, and calculates the size.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:30:46 -05:00
Alejandro Colomar
be05c62bd7 lib/, src/, po/: date_to_str(): Move function to header, and make inline
BTW, there's no translatable string in there.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:30:46 -05:00
Alejandro Colomar
88760598f0 src/sulogin.c: Invert logic to reduce indentation
Also, it was checking for >=0 for success, but since that code is for
opening a different tty as stdin, that was bogus.  But since it's
guaranteed to be either 0 or -1, this commit doesn't add any code to
make sure it's 0 (i.e., we could say !=0 instead of ==-1).  That's more
appropriate for a different commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:16:15 -05:00
Alejandro Colomar
efd169e010 lib/, src/: Use int main(void) where appropriate
Remove /*ARGSUSED*/ comments.  Instead, use appropriate declarators for
main().  ISO C allows using int main(void) if the parameters are going
to be unused.

Also, do some cosmetic changes in the uses of argc and argv, to show
where they are used.

And use *argv[], instead of **argv.  Array notation is friendlier, IMO.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:16:15 -05:00
Alejandro Colomar
da440b536c lib/: Clean up after previous removal of dead code
Just cosmetic changes.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:12:51 -05:00
Alejandro Colomar
33825ab57d lib/, src/: Remove all code wrapped in defined(USE_NIS)
I don't find any way to enable USE_NIS, so it looks like it's all
dead code.  Bury it.

Closes: <https://github.com/shadow-maint/shadow/issues/909>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:12:51 -05:00
Alejandro Colomar
ae3d71fb94 src/passwd.c: Don't print the program name twice in a log entry
OPENLOG() already sets the program name as the prefix.

This resulted in entries like:

$ journalctl 2>/dev/null | grep passwd
Mar 03 01:09:47 debian passwd[140744]: passwd: can't view or modify password information for root

Fixes: 8e167d28af ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-14 16:01:32 -05:00
ed neville
4959cd10ae Noting copy_symlink behaviour
Mention that symlinks are modified when they prefix the skel directory.

Closes #933
2024-03-14 15:53:33 -05:00
Alejandro Colomar
a3cae72faa share/containers/, .github/workflows/: Don't make(1) twice
It was being done so that the second one prints errors without races.
However, the same thing can be achieved by passing -Orecurse to make(1).

And this makes the logs even more readable, since there's no racy output
at all.

Fixes: 97f79e3b27 ("CI: Make build logs more readable")
Link: <https://github.com/shadow-maint/shadow/pull/702>
Link: <https://github.com/nginx/unit/pull/1123>
Acked-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Andrew Clayton <a.clayton@nginx.com>
Cc: Konstantin Pavlov <thresh@nginx.com>
Cc: Dylan Arbour <https://github.com/arbourd>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-13 11:05:36 -05:00
Alejandro Colomar
26deef6945 lib/idmapping.c: get_map_ranges(): Merge two input checks into a simpler one
Previously, we were performing the following two checks:

-       if (ranges != ((argc + 2) / 3)) {
-       if ((ranges * 3) > argc) {

Let's draw a table of the possible input that would pass the first check:

argc:	0 1 2 3 4 5 6 7 8 9
rng:	0 1 1 1 2 2 2 3 3 3
a+2/3*3:0 3 3 3 6 6 6 9 9 9	<-- this is  roundup(argc, 3);
a+2/3:	0 1 1 1 2 2 2 3 3 3	<-- this is  roundup(argc, 3) / 3;
rng*3:	0 3 3 3 6 6 6 9 9 9

From those, let's extract those that would also pass the second check:

argc:	0     3     6     9
rng:	0     1     2     3
rng*3:	0     3     6     9

We can see that there's a simple check for this input:

+       if (ranges * 3 != argc) {

As a sanity check, let's draw a table of the acceptable input with that
check:

rng:	0     1     2     3
rng*3:	0     3     6     9
argc:	0     3     6     9

Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-13 10:55:00 -05:00
Skyler Ferrante
d2f2c1877a Adding checks for fd omission
Adding function check_fds to new file fd.c. The function check_fds
should be called in every setuid/setgid program.

Co-developed-by: Alejandro Colomar <alx@kernel.org>
2024-03-10 19:56:40 -05:00
Alejandro Colomar
b76fc2947f tests/unit/test_zustr2stp.c: Test ZUSTR2STP()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-10 19:55:39 -05:00
Alejandro Colomar
ffb3992467 lib/string/zustr2stp.[ch]: Remove zustr2stp(); keep ZUSTR2STP()
The function should never be used; it's always used via its wrapper
macro.  To simplify, and reduce chances of confusion: remove the
function, and implement the macro directly in terms of
stpcpy(mempcpy(strnlen())).

Update the documentation, and improve the example, which was rather
confusing.

Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-10 19:55:39 -05:00
Serge Hallyn
ba43b49a52 configure.ac: Release 4.15.0
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-03-08 16:04:59 -06:00
Alejandro Colomar
89c4da43cb src/vipw.c: Use string literals to initialize 'Prog'
This avoids using argv[0], which is controlled by the user,
and might inject arbitrary text in stderr and the logs.

Link: <https://github.com/shadow-maint/shadow/issues/959>
Link: <https://github.com/shadow-maint/shadow/pull/960>
Cc: "Skyler Ferrante (RIT Student)" <sjf5462@rit.edu>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Karel Zak <kzak@redhat.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Christian Brauner <christian@brauner.io>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-08 10:24:15 -06:00
Alejandro Colomar
0ab893a734 src/vipw.c: Reverse logic and variable name
Since we're checking for "vigr", it makes more sense to name the
variable accordingly.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-08 10:24:15 -06:00
Skyler Ferrante
e6c2e43937 Hardcoding Prog to known value
See #959. We now set Prog (program name) based on hardcoded value instead
of argv[0]. This is to help prevent escape sequence injection.
2024-03-07 22:23:04 +01:00
Alejandro Colomar
d13844408c share/containers/: trap(1) to see the cmocka logs
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-04 01:43:25 +01:00
Alejandro Colomar
e59a39663d share/containers/: Specify one argument per line
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-04 01:43:25 +01:00
Alejandro Colomar
a14936cf2e .github/workflows/runner.yml: trap(1) to see the testsuite log
Otherwise, 'cat testsuite.log' isn't run, since 'set -e' aborts the
script earlier.

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-04 01:43:25 +01:00
Serge Hallyn
959343fe79 configure.ac: release 4.15.0-rc3
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-02-29 19:51:37 -06:00
Alejandro Colomar
1af6b68cbe lib/utmp.c: Use the appropriate autotools macros for struct utmpx
Recently, we started using utmpx instead of utmp, and we updated
<./configure.ac> to do the checks for 'struct utmpx' instead of
'struct utmp'.  However, I forgot to update the preprocessor
conditionals accordingly.

Fixes: 64bcb54fa9 ("lib/, src/, configure.ac: Use utmpx instead of utmp")
Link: <https://github.com/shadow-maint/shadow/pull/954>
Cc: Firas Khalil Khana <firasuke@gmail.com>
Cc: "A. Wilfox" <https://github.com/awilfox>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-21 15:43:25 +01:00
Alejandro Colomar
2806b827d8 lib/utmp.c: Use defined() instead of #if[n]def
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-21 15:43:25 +01:00
Alejandro Colomar
7e94a2f484 lib/utmp.c: Remove #endif comments
Indentation makes it clear which is which.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-21 15:43:25 +01:00
Alejandro Colomar
e5815acf37 lib/utmp.c: Merge preprocessor conditionals
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-21 15:43:25 +01:00
Alejandro Colomar
f4ea04b728 lib/utmp.c: Indent nested preprocessor conditionals
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-21 15:43:25 +01:00
Alejandro Colomar
5ff6edf9f2 lib/utmp.c: Replace UT_LINESIZE by a NITEMS() calculation
A difference between 'struct utmp' and 'struct utmpx' is that
the former uses UT_LINESIZE for the size of its array members,
while the latter doesn't have a standard variable to get its
size.  Therefore, we need to get the number of elements in
the array with NITEMS().

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-20 18:53:53 +01:00
Alejandro Colomar
544709fad3 lib/sizeof.h: memberof(): Add macro
This macro is useful to get the size of a member of a structure
without having a variable of that type.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-20 18:53:53 +01:00
Alejandro Colomar
8d1f0bcf99 lib/utmp.c: get_session_host(): Reduce scope of variable
This silences a warning about an unused variable.

Tested-by: Firas Khalil Khana <firasuke@gmail.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-20 18:53:53 +01:00
Alejandro Colomar
64bcb54fa9 lib/, src/, configure.ac: Use utmpx instead of utmp
utmpx is specified by POSIX as an XSI extension.  That's more portable
than utmp, which is unavailable for example in musl libc.  The manual
page specifies that in Linux (but it probably means in glibc), utmp and
utmpx (and the functions that use them) are identical, so this commit
shouldn't affect glibc systems.

Assume utmpx is always present.

Also, if utmpx is present, POSIX guarantees that some members exist:

-  ut_user
-  ut_id
-  ut_line
-  ut_pid
-  ut_type
-  ut_tv

So, rely on them unconditionally.

Fixes: 170b76cdd1 ("Disable utmpx permanently")
Closes: <https://github.com/shadow-maint/shadow/issues/945>
Reported-by: Firas Khalil Khana <firasuke@gmail.com>
Reported-by: "A. Wilfox" <https://github.com/awilfox>
Tested-by: Firas Khalil Khana <firasuke@gmail.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-20 18:53:53 +01:00
Alejandro Colomar
4d139ca466 lib/getdate.y: get_date(): Fix calculation
Instead of adding 1, we should add the value the we stored previously in
the variable.

Fixes: 45c6603cc8 ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Closes: <https://github.com/shadow-maint/shadow/issues/939>
Link: <https://github.com/shadow-maint/shadow/pull/942>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Reported-by: Gus Kenion <https://github.com/kenion>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-16 19:58:43 -06:00
Tomas Halman
e15aa5a8a6 src/passwd.c: check password length upper limit
The passwd silently truncated the password length to PASS_MAX.
This patch introduces check that prints an error message
and exits the call.

Signed-off-by: Tomas Halman <tomas@halman.net>
2024-02-16 15:46:08 -06:00
Tomas Halman
dfb4d8fdf9 src/passwd.c: inconsistent password length limit
The passwd utility had hardcoded limit for password lenght set
to 200 characters. In the agetpass.c is used PASS_MAX for
this purpose.

This patch moves the PASS_MAX definition to common place
and uses it in both places.

Signed-off-by: Tomas Halman <tomas@halman.net>
2024-02-16 15:46:08 -06:00
Serge Hallyn
0259f84583 release 4.15.0-rc2
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-02-15 17:54:19 -06:00
NorwayFun
d72d99a810 Update Georgian translation 2024-02-14 15:20:14 -06:00
Alejandro Colomar
f22ca217cd lib/chkname.c: is_valid_user_name(): Avoid a cast
By using a temporary vairable, we can remove a cast.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:13:05 -06:00
Alejandro Colomar
ad307ee42a lib/chkname.c: is_valid_user_name(): Remove unnecessary check
If (maxsize == -1), then ((size_t)maxsize == SIZE_MAX).  And no size can
ever be >= SIZE_MAX, so it will never return false if sysconf(3) reports
an unlimited user-name size via returning -1.  Well, to be pedantic,
that disallows a user-name siz of precisely SIZE_MAX bytes when
sysconf(3) returns -1.  However, that's probably a good thing; such a
long user name might trigger Undefined Behavior somewhere else, so be
cautious and disallow it.  I hope nobody will be using the entire
address space for a user name.

The commit that introduced that check missed that this code had always
supported unlimited user-name sizes since it was introduced by Iker in
3b7cc05387 ("lib: replace `USER_NAME_MAX_LENGTH` macro"), and
6be85b0baf ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare
warning") even clarified this in the commit message.

So, while the code in 6a1f45d932 ("lib/chkname.c: Support unlimited
user name lengths") wasn't bad per se, the commit message was incorrect.
What that patch did was adding code for handling EINVAL (or any other
errors that a future kernel might add).

To be more pedantically correct, that commit also allowed (under certain
circumstances, user names of SIZE_MAX bytes, but those were originally
allowed (by accident), and only became disallowed in 403a2e3771
("lib/chkname.c: Take NUL byte into account").  But again, let's
disallow those, just to be cautious.

Link: <https://github.com/shadow-maint/shadow/pull/935>
Link: <https://github.com/shadow-maint/shadow/pull/935#discussion_r1477429492>
See-also: 6be85b0baf ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning")
Fixes: 6a1f45d932 ("lib/chkname.c: Support unlimited user name lengths")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:13:05 -06:00
Alejandro Colomar
15882a5f90 src/login.c: Fix off-by-one bugss
These functions expect a size, not a length.  Don't subtract 1 to the
size.

Link: <https://github.com/shadow-maint/shadow/pull/935>
Link: <https://github.com/shadow-maint/shadow/issues/920#issuecomment-1926002209>
Link: <https://github.com/shadow-maint/shadow/pull/757>
Link: <https://github.com/shadow-maint/shadow/issues/674>
See-also: 0656a90bfd0d ("src/login.c: Fix off-by-one buggs")
See-also: 403a2e3771 ("lib/chkname.c: Take NUL byte into account")
Fixes: 3b7cc05387 ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:13:05 -06:00
Alejandro Colomar
51cd6aec02 lib/: Don't say 'len' where 'size' is meant
Fixes: 45c6603cc8 ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Fixes: 3b7cc05387 ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Fixes: 6be85b0baf ("lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning")
See-also: 403a2e3771 ("lib/chkname.c: Take NUL byte into account")
See-also: 6a1f45d932 ("lib/chkname.c: Support unlimited user name lengths")
Fixes: 95ea61009d ("lib/chkname.c: Use precise comment")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:13:05 -06:00
Alejandro Colomar
6551709e96 src/login.c: Fix off-by-one buggs
Before 3b7cc05387 ("lib: replace `USER_NAME_MAX_LENGTH` macro"), this
code did use a length.  It used a utmp(5) fixed-width buffer, so the
length matches the buffer size (there was no terminating NUL byte).
However, sysconf(_SC_LOGIN_NAME_MAX) returns a buffer size that accounts
for the terminating null byte; see sysconf(3).  Thus, the commit that
introduced the call to sysconf(3), should have taken that detail into
account.

403a2e3771 ("lib/chkname.c: Take NUL byte into account"), by Tobias,
caught that bug in <lib/chkname.c>, but missed that the same commit that
introduced that bug, introduced the same bug in two other places.
This fixes all remaining calls to sysconf(_SC_LOGIN_NAME_MAX).

I still observe some suspicious code after this fix:

	if (do_rlogin(hostname, username, max_size - 1, term, sizeof(term)))

	...

	login_prompt(username, max_size - 1);

We're passing size-1 to functions that want a size.  But since the fix
to those will be different, let's do that in the following commits.

Link: <https://github.com/shadow-maint/shadow/pull/935>
Link: <https://github.com/shadow-maint/shadow/issues/920#issuecomment-1926002209>
Link: <https://github.com/shadow-maint/shadow/pull/757>
Link: <https://github.com/shadow-maint/shadow/issues/674>
See-also: 403a2e3771 ("lib/chkname.c: Take NUL byte into account")
Fixes: 3b7cc05387 ("lib: replace `USER_NAME_MAX_LENGTH` macro")
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:13:05 -06:00
Tycho Andersen
714b6a53d5 usermod: refuse invalid uidmaps during --add-sub{u,g}ids
It is slightly confusing to allow adding these only to later refuse them.

Here is a (lightly tested :) patch to also refuse them when adding.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2024-02-13 16:06:23 -06:00
Alejandro Colomar
1175932c0c lib/strtoday.c: strtoday(): Fix calculation
Days officially roll over at 00:00 UTC, not at 12:00 UTC.  I see no
reason to add that half day.

Also, remove the comment.  It's likely to get stale.

So, get_date() gets the number of seconds since the Epoch.  I wonder how
that thing works, but I'll assume it's something similar to getdate(3)
+ mktime(3).  After that, we need to convert seconds since Epoch to days
since Epoch.  That should be a simple division, AFAICS, since Epoch is
"1970‐01‐01 00:00:00 +0000 (UTC)".  See mktime(3).

Fixes: 45c6603cc8 ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Link: <https://github.com/shadow-maint/shadow/issues/939>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Tested-by: Gus Kenion <https://github.com/kenion>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:05:12 -06:00
Tobias Stoeckmann
674409e226 lib/: Saturate addition to avoid overflow
Very large values in /etc/shadow could lead to overflows.  Make sure
that these calculations are saturated at LONG_MAX.  Since entries are
based on days and not seconds since epoch, saturating won't hurt anyone.

Co-developed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:02:49 -06:00
Tobias Stoeckmann
20100e4b22 src/chage.c: Unify long overflow checks in print_day_as_date()
The conversion from day to seconds can be done in print_date
(renamed to print_day_as_date for clarification).  This has the nice
benefit that DAY multiplication and long to time_t conversion are done
at just one place.

Co-developed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 16:02:49 -06:00
Alejandro Colomar
7eb10e6298 etc/pam.d/Makefile.am: Fix typo
The commit we're fixing mentions that it wanted to move 'chpasswd', but
it removed 'ch_g_passwd' from 'pamd_acct_tools_files' and added
'chpasswd' to 'pamd_files'.  It seems it removed the wrong thing by
accident.

Fixes: 341d80c2c7 ("Makefile: move chpasswd and newusers to pamd target")
Link: <https://github.com/shadow-maint/shadow/pull/928#discussion_r1487687347>
Link: <https://github.com/shadow-maint/shadow/issues/926#issuecomment-1941324761>
Reported-by: Dominique Leuenberger <dleuenberger@suse.com>
Reported-by: Michael Vetter <jubalh@iodoru.org>
Cc: David Runge <dvzrv@archlinux.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Tested-by: Michael Vetter <jubalh@iodoru.org>
Reviewed-by: Michael Vetter <jubalh@iodoru.org>
Reviewed-by: loqs <https://github.com/loqs>
Co-developed-by: Dominique Leuenberger <dleuenberger@suse.com>
Signed-off-by: Dominique Leuenberger <dleuenberger@suse.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-13 18:45:04 +01:00
Alejandro Colomar
3e59e9613e AUTHORS.md: Format list
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-02-06 16:16:32 +01:00
Tobias Stoeckmann
95ea61009d lib/chkname.c: Use precise comment
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-02-04 17:03:12 -06:00
Tobias Stoeckmann
6a1f45d932 lib/chkname.c: Support unlimited user name lengths
If the system does not have a user name length limit, support it
accordingly. If the system has no _SC_LOGIN_NAME_MAX, use
LOGIN_NAME_MAX constant instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-02-04 17:03:12 -06:00
Tobias Stoeckmann
403a2e3771 lib/chkname.c: Take NUL byte into account
The _SC_LOGIN_NAME_MAX value includes space for the NUL byte. The length
of name must smaller than this value to be valid.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-02-04 17:03:12 -06:00
Serge Hallyn
37b02a5f88 release 4.15.0-rc1
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-02-01 17:12:09 -06:00
Samanta Navarro
cae6cea0e8 src/sulogin.c: Remove unused variable
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2024-02-01 14:37:00 +01:00
Samanta Navarro
f078412398 src/sulogin.c: Simplify password handling
The password returned by agetpass can be used directly without copying
it into a char array first.

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2024-02-01 14:37:00 +01:00
Samanta Navarro
cb42ee620e src/sulogin.c: Use a do-while loop
Clarify how this endless while(true) loop can be stopped by using a
boolean variable as condition and turn it into a do-while loop.

Suggested-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2024-02-01 14:37:00 +01:00
Alejandro Colomar
f98e43ee11 tests/unit/test_atoi_strtoi.c: Test strtou_noneg()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Alejandro Colomar
f2b240595b lib/atoi/strtou_noneg.[ch]: Add strtou_noneg()
It's like strtou_(), but rejects negative input, instead of silently
converting it to unsigned.

Link: <https://softwareengineering.stackexchange.com/a/449060/332848>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Alejandro Colomar
f632515581 tests/unit/Makefile.am: tfix
Fix typo.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Alejandro Colomar
40355150c4 tests/unit/test_atoi_strtoi.c: Test strtoi_()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Alejandro Colomar
34ff8edb63 lib/atoi/strtoi.[ch]: strtoi_(), strtou_(): Add functions
These functions are identical to strtoi(3bsd) and strtou(3bsd), except
for one important thing: if both ERANGE and ENOTSUP conditions happen,
the BSD functions report ENOTSUP, which is bogus; our strtoi_() and
strtou_() report ERANGE.

Link: <https://lists.sr.ht/~hallyn/shadow/%3CZZoQDms6Sv6e5SPE%40debian%3E>
Link: <https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57828>
Cc: Thorsten Glaser <tg@mirbsd.de>
Cc: christos <christos@netbsd.org>
Cc: roy <roy@netbsd.org>
Cc: Guillem Jover <guillem@hadrons.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Tomas Halman
49001ca846 src/passwd.c: implement reading password from pipe
New option --stdin/-t is available for root user. It is useful
for automation/setup and it makes shadow utils passwd more versatile.

Signed-off-by: Tomas Halman <tomas@halman.net>
2024-01-31 22:16:02 -06:00
Tomas Halman
3fff9d7621 lib/agetpass.[ch]: add function ro read from pipe
Add alternative function to agetpass for reading password
from stdin or pipe.

Signed-off-by: Tomas Halman <tomas@halman.net>
2024-01-31 22:16:02 -06:00
loqs
341d80c2c7 Makefile: move chpasswd and newusers to pamd target
Install pam configs for chpasswd and newusers when using ./configure --with-libpam --disable-account-tools-setuid.
Fixes https://github.com/shadow-maint/shadow/issues/810.

Tested-by: David Runge <dvzrv@archlinux.org>
2024-01-30 22:10:32 +01:00
Pablo Saavedra
cd9b4de327 lib/, src/: Make the use of MAYBE_UNUSED macro consistent
There is an inconsistent use of the MAYBE_UNUSED macro. Sometimes the
`int unused(x)` form is used form and others the `unused int x`. We'd
like to use the second form always.

Related-To: https://github.com/shadow-maint/shadow/issues/918

Suggested-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
2024-01-30 16:19:56 +01:00
Pablo Saavedra
5d5d212764 lib/, src/: Rename 'unused' macro as 'MAYBE_UNUSED'
Related-To: https://github.com/shadow-maint/shadow/issues/918

Suggested-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
2024-01-30 16:19:56 +01:00
Pablo Saavedra
da84d0ede7 Fix Build error 'parameter name omitted' in logind
Fixes #918 by adding the omitted parameter name in
active_sessions_count().

Signed-off-by: Pablo Saavedra <psaavedra@igalia.com>
2024-01-30 16:19:56 +01:00
Alejandro Colomar
1a377e318f src/sulogin.c: pw_entry(): Report errors by returning -1
Cc: Samanta Navarro <ferivoz@riseup.net>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-29 17:29:59 +01:00
Alejandro Colomar
6fb7fe11f2 src/passwd.c: Remove comments about flags that don't exist
Those flags have never existed, AFAICS.

Closes: <https://github.com/shadow-maint/shadow/issues/929>
Cc: Tomas Halman <tomas@halman.net>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-29 08:10:44 -06:00
Sam James
0f4e59fd00 Link correctly with libdl
This fixes build with glibc-2.33 (newer glibc merged libdl and libpthread
into libc):
```
libtool: link: x86_64-pc-linux-gnu-gcc -isystem /usr/include/bsd -DLIBBSD_OVERLAY -O2 -pipe -Wl,-O1 -o login login.o login_nopam.o  -Wl,--as-needed ../lib/.libs/libshadow.a -lcrypt -lsystemd -lpam -lpam_misc -lbsd
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: ../lib/.libs/libshadow.a(libshadow_la-nss.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /lib64/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
```

In Debian, the needed macro from libtool seems to be in libltdl-dev.

Signed-off-by: Sam James <sam@gentoo.org>
2024-01-26 10:05:40 +01:00
Alejandro Colomar
6fcc0f6756 autogen.sh: CFLAGS: Use -Wno-unknown-attributes; Clang doesn't know [[gnu::access()]]
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
d74ffd3c29 autogen.sh: CFLAGS: Add some -Werror=... flags that will be default soon
Clang 16 and GCC 14 have upgraded several warnings to errors by default.
Also, there are new warnings that will be requirements of ISO C23.  Add
all of those to our build.

Use Clang's -Wno-unknown-attribute-option, to ignore warnings that are
exclusive of GCC.  Sadly, GCC doesn't have such an option.

Link: <https://wiki.gentoo.org/wiki/Modern_C_porting#What_changed.3F>
Link: <https://github.com/shadow-maint/shadow/issues/922>
Suggested-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
d452d1b812 src/usermod.c: grp_update(): Remove scope of variable, and fix const correctness
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
5a5cd85bd2 src/useradd.c: get_defaults(): Use const temporary pointer to fix const correctness
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
3e0cdc87b7 src/su.c: Use const_cast() to silence -Wincompatible-pointer-types-discards-qualifiers
argv is passed to execve(3), which for historic reasons is non-const,
but doesn't modify the strings.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
e9fc8fc7ef lib/cast.h: const_cast(): Add macro for dropping 'const'
Uses of this macro indicate a code smell, but in some cases, libc
functions require breaking const correctness.  Use this macro to wrap
casts in such cases, so that we limit the danger of the cast.

It only permits discarding const.  Discarding any other qualifiers, or
doing other type changes should result in a compile-time error.

Link: <https://software.codidact.com/posts/286575/287345#answer-287345>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
4ef08548cc lib/must_be.h: is_same_type(): Add macro
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
9c5e433a3a lib/must_be.h: is_same_typeof(): Rename macro
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-26 09:40:10 +01:00
Alejandro Colomar
9340efbb0d src/su.c: do_check_perms(): Fix -Wincompatible-pointer-types bug
Fixes: ef95bb7ed1 ("src/su.c: Fix type of variable")
Closes: <https://github.com/shadow-maint/shadow/issues/915>
Reported-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-24 14:49:56 +01:00
Alejandro Colomar
0138819b2a tests/unit/test_atoi_strtou_noneg.c: Test strtou[l]l_noneg()
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-22 17:17:15 -06:00
Alejandro Colomar
f14670ee1a lib/, src/: Replace strtou[l]l(3) by strtou[l]l_noneg()
strtou[l]l(3) silently converts negative numbers into positive.  This
behavior is wrong: a negative value should be parsed as a negative
value, which would underflow unsigned (long) long, and so would return
the smallest possible value, 0, and set errno to ERANGE to report an
error.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-22 17:17:15 -06:00
Alejandro Colomar
4a2646f676 lib/atoi/strtou_noneg.[ch]: Add strtou[l]l_noneg()
These functions reject negative numbers, instead of silently converting
them into unsigned, which strtou[l]l(3) do.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-22 17:17:15 -06:00
Samanta Navarro
4d835c7ea4 src/sulogin.c: Free previously allocated memory
The sulogin program calls pw_entry in a loop while incorrect root
passwords are entered.

Free the previously allocated memory to avoid memory exhaustion.

Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2024-01-22 15:40:39 -06:00
Alejandro Colomar
08ae7af111 src/sulogin.c: Remove 'static' from local variable, but keep initialization
We don't need 'static', because it's in main(), which is only called
once.  However, we will need initialization as if it were 'static', so
use ={} to initialize it.  This will allow freeing the pointers before
they have been allocated.

Cc: Samanta Navarro <ferivoz@riseup.net>
Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-17 18:11:19 -06:00
Alejandro Colomar
4edda5d8ba src/sulogin.c: Remove 'static' from a temporary variable
There's no need to keep 'pass' in .bss:

$ grep -nC3 '\<pass\>' src/sulogin.c
58-/*ARGSUSED*/ int main (int argc, char **argv)
59-{
60-	int     err = 0;
61:	char    pass[BUFSIZ];
62-	char    **envp = environ;
63-	TERMIO  termio;
64-#ifndef USE_PAM
--
166-#endif
167-			exit (0);
168-		}
169:		STRTCPY(pass, cp);
170-		erase_pass (cp);
171-
172:		if (valid (pass, &pwent)) {	/* check encrypted passwords ... */
173-			break;	/* ... encrypted passwords matched */
174-		}
175-
176-		sleep (2);
177-		(void) puts (_("Login incorrect"));
178-	}
179:	MEMZERO(pass);
180-	(void) alarm (0);
181-	(void) signal (SIGALRM, SIG_DFL);
182-	environ = newenvp;	/* make new environment active */

Cc: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-17 18:11:19 -06:00
Alejandro Colomar
d2c28a402a src/sulogin.c: Align local variables
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-17 18:11:19 -06:00
Alejandro Colomar
1faf4d6469 src/sulogin.c: Make static variables local to main()
Those variables are only used in main().  Restrict their scope.
Keep them static (.bss), as changing that may be dangerous.

Suggested-by: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-17 18:11:19 -06:00
Alejandro Colomar
5214710432 src/sulogin.c: pw_entry(): Don't else after return
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-17 18:11:19 -06:00
Alejandro Colomar
8679878c8b lib/, src/, po/: pw_entry(): Move function to src/sulogin.c
That's the only file where it's called, and it's a delicate function.
Reduce the chances that other files call it.

Link: <https://github.com/shadow-maint/shadow/pull/908>
Suggested-by: Samanta Navarro <ferivoz@riseup.net>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-17 18:11:19 -06:00
Alejandro Colomar
2e56af1902 lib/, tests/: addsl(): Add addsl(), a variadic macro
Add a variadic macro addsl() that accepts an arbitrary number of
addends, instead of having specific versions like addsl2() or addsl3().

It is internally implemented by the addslN() function, which itself
calls addsl2().  addsl3() is now obsolete and thus removed.

Code should just call addsl().

Link: <https://github.com/shadow-maint/shadow/pull/882#discussion_r1437155212>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-16 16:58:18 +01:00
Alejandro Colomar
2e5fc4c90b lib/, tests/: addsl2(): Rename addsl() to addsl2()
This is for consistency with addsl3(), and in preparation for the
following commit, which will unify the interface into a single addsl()
macro.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-16 16:58:18 +01:00
Alejandro Colomar
1356b14a00 lib/defines.h: Don't wrap #undef in #ifdef
ISO C guarantees that #undef is a no-op if there is no such macro.

C11::6.10.3.5p2:
> A preprocessing directive of the form
>
>       # undef identifier new-line
>
> causes the specified identifier no longer to be defined as a macro
> name.  It is ignored if the specified identifier is not currently
> defined as a macro name.

Link: <http://port70.net/~nsz/c/c11/n1570.html#6.10.3.5p2>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:41:06 -06:00
Alejandro Colomar
effdb14786 lib/idmapping.c: write_mapping(): Fixx off-by-one bug
Link: <673c2a6f9a (r136830993)>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:37:09 -06:00
Alejandro Colomar
6bec1cf37c lib/: Use 'restrict' alongside [[gnu::access()]]
const + restrict imply read_only.

Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Alejandro Colomar
76e7de3fbb lib/: Use ATTR_ACCESS() instead of /*@out@*/
The compiler seems to ignore the attribute in a function pointer,
though.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Alejandro Colomar
561448443f lib/: get[u]long(): Use ATTR_ACCESS() instead of /*@out@*/
Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Alejandro Colomar
9ca6b71e76 lib/: Remove incorrect /*@out@*/ comment from functions that read the pointee
These functions (e.g., gr_free()), explicitly dereference the pointer
and read the pointee.

The /@out@/ comment, which is (almost) analogous to the
[[gnu::access(write_only, ...)]] attribute, means that the pointee can
be uninitialized, since it won't read it.  There's a difference between
/@out@/ and the GCC attribute: the attribute doesn't require that the
call writes to the pointee, while /@out@/ requires that the pointee be
fully initialized after the call, so it _must_ write to it.

A guess of why it was used is that these functions are similar to
free(3), which does not read the memory it frees, and so one would
assume that if it doesn't read, write_only (or equivalents) are good.
That's wrong in several ways:

-  free(3) does not read _nor_ write to the memory, so it would
   be slightly inappropriate to use write_only with it.  It wouldn't be
   "wrong", but [[gnu::access(none, ...)]] would be more appropriate.

-  Because /@out@/ requires that the call writes to the pointee, it
   would be wrong to use it in free(3), which doesn't write to the
   pointee.

-  Our functions are similar to free(3) conceptually, but they don't
   behave like free(3), since they do read the memory (pointee) (and
   also write to it), and thus they're actually read_write.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Alejandro Colomar
f1b9f8d829 lib/: Remove /*@out@*/ comments in return type
/*@out@*/ makes no sense in the return of a function, AFAICS.

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Alejandro Colomar
7c1576cfb6 lib/: fgetsx(): Use ATTR_ACCESS() instead of /*@out@*/
Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Alejandro Colomar
a070b84f2e lib/: run_command(): Use ATTR_ACCESS() instead of /*@out@*/
Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Alejandro Colomar
9ac5b2fc5a lib/attr.h: Add ATTR_ACCESS()
This will replace the existing comments like /*@out@*/

Link: <https://splint.org/manual/manual.html#undefined>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-15 13:14:28 -06:00
Samanta Navarro
a9e07c0feb lib/sgetgrent.c: fix null pointer dereference
If reallocation fails in function list, then reset the size to 0 again.
Without the reset, the next call assumes that `members` points to
a memory location with reserved space.

Also use size_t instead of int for size to prevent signed integer
overflows. The length of group lines is not limited.

Fixes 45c0003e53 (4.14 release series)

Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2024-01-15 13:06:35 -06:00
Alejandro Colomar
4c0c7c52f1 lib/: get_pid(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
18c428a6c9 lib/, src/: get_uid(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
470baeabbd lib/, src/: get_gid(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
ea253cb275 lib/, src/: getrange(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
c595ea7e87 lib/getrange.c: Reduce indentation
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
2a9b6d80e7 lib/, src/: getulong(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
2d581cb337 lib/, src/: getlong(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 16:54:55 -06:00
Alejandro Colomar
173231a8ff tests/unit/test_adds.c: Test addsl() and addsl3()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 15:45:08 -06:00
Alejandro Colomar
89e5a32966 lib/adds.[ch]: Add addsl() and addsl3()
These functions add 2 or 3 longs, saturating to LONG_{MIN,MAX} instead
of overflowing.

Cc: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 15:45:08 -06:00
Tobias Stoeckmann
1a383194ff src/: Fix long/time_t handling
Special care has to be taken for 32 bit systems with a 64 bit time_t,
since their long data type is still 32 bit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 15:41:12 -06:00
Tobias Stoeckmann
2d188a9987 src/passwd.c: Add overflow check
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 15:41:12 -06:00
Tobias Stoeckmann
3b5ba41d3e src/passwd.c: Switch to day precision
The size of time_t varies across systems, but since data type long is
more than enough to calculate with days (precision of shadow file),
use it instead.

Just in case a shadow file contains huge values, check for a possible
signed integer overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 15:41:12 -06:00
Tobias Stoeckmann
ecc3508877 lib/, src/: Remove SCALE definition
SCALE is always DAY (and has to be always DAY), so replace it with DAY
in source code and remove unneeded calculations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: <https://github.com/shadow-maint/shadow/pull/876>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 15:41:12 -06:00
Tobias Stoeckmann
11091949be man/: add BCRYPT and YESCRYPT information
The BCRYPT and YESCRYPT relevant items should be described in
manual pages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-12-27 10:48:48 -06:00
Tobias Stoeckmann
f89ba6822d man/: CONSOLE_GROUPS is only used without PAM
CONSOLE_GROUPS is only used if PAM is not in use, just like
CONSOLE itself.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-12-27 10:35:02 -06:00
Tobias Stoeckmann
97ddb0d80c man/: ENV_HZ is only used without PAM
Contrary to the comment in ENV_HZ.xml, ENV_HZ is not even used in
sulogin (anymore) if PAM support is enabled.

Skip paragraphs of sulogin if PAM support is enabled, since they would
be empty now.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-12-27 10:35:02 -06:00
Alejandro Colomar
0ee79295f6 lib/defines.h: Use 'time_t' for DAY
Special care has to be taken for 32 bit systems with a 64 bit time_t,
since their long data type is still 32 bit.

Since this macro expresses a number of seconds, and seconds are in units
of 'time_t' in C, the appropriate type for the multiplication is
'time_t'.

Reported-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-27 09:55:25 -06:00
Tobias Stoeckmann
ca6425e54e login.defs.5: Be specific that only -1 is allowed
Other negative values can have bad effects and won't be allowed
anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-12-27 09:54:06 -06:00
Tobias Stoeckmann
b80c55946a lib/getdef.c: Reject negative values in getdef_* except -1
The values are retrieved from login.defs files, which normally do not
contain negative values. In fact, negative value -1 is used in many
code places as "feature disabled", which is normally achieved by
simply commenting out the key from the file.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-12-27 09:54:06 -06:00
Tobias Stoeckmann
8b8793920e man/: Support compiling in build directory
Having a dedicated build directory breaks manual page creation.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-12-25 10:08:24 -06:00
Alejandro Colomar
ddbd3a36c1 tests/unit/test_sprintf.c: Test SNPRINTF()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-15 16:41:47 +01:00
Alejandro Colomar
cf9cc6963c lib/, src/: Use SNPRINTF() instead of its pattern
The variable declarations for the buffers have been aligned in this
commit, so that they appear in the diff, making it easier to review.

Some important but somewhat tangent changes included in this commit:

-  lib/nss.c: The size was being defined as 65, but then used as 64.
   That was a bug, although not an important one; we were just wasting
   one byte.  Fix that while we replace snprintf() by SNPRINTF(), which
   will get the size from sizeof(), and thus will use the real size.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-15 16:41:47 +01:00
Alejandro Colomar
8c6634d9bc lib/string/sprintf.[ch]: Add [v]snprintf_()
These functions are like [v]snprintf(3), but return -1 on truncation,
which makes it easier to test.  In fact, the API of swprintf(3), which
was invented later than snprintf(3), and is the wide-character version
of it, is identical to this snprintf_().

snprintf(3) is iseful in two cases:

-  We don't care if the output is truncated.  snprintf(3) is fine for
   those, and the return value can be ignored.  But snprintf_() is also
   fine for those.

-  Truncation is bad.  In that case, it's as bad as a hard error (-1)
   from snprintf, so merging both problems into the same error code
   makes it easier to handle errors.  Return the length if no truncation
   so that we can use it if necessary.

Not returning the whole length before truncation makes a better API,
which need not read the entire input, so it's less vulnerable to DoS
attacks when a malicious user controls the input.

Use these functions to implement SNPRINTF().

Cc: Samanta Navarro <ferivoz@riseup.net>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-15 16:41:47 +01:00
Alejandro Colomar
ce4c4d4ad5 lib/string/sprintf.h: Add SNPRINTF() macro
It wraps snprintf(3) so that it performs some steps that one might
forget, or might be prone to accidents:

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

-  It calculates if there's truncation or an error, returning -1 if so.

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

This macro is very similar to STRTCPY(), defined in
<lib/string/strtcpy.h>.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-15 16:41:47 +01:00
Christian Göttsche
9c39b13194 src/chfn,chpasswd,newusers: declare fatal_exit() NORETURN
Help static analyzers to understand fatal_exit() does never return.
2023-12-14 07:40:40 -06:00
Christian Göttsche
d2e7edcd00 lib: avoid format truncation
commonio.c: In function 'commonio_unlock':
    commonio.c:487:49: warning: '.lock' directive output may be truncated writing 5 bytes into a region of size between 1 and 1024 [-Wformat-truncation=]
      487 |                 snprintf (lock, sizeof lock, "%s.lock", db->filename);
          |                                                 ^~~~~
    commonio.c:487:17: note: 'snprintf' output between 6 and 1029 bytes into a destination of size 1024
      487 |                 snprintf (lock, sizeof lock, "%s.lock", db->filename);
          |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2023-12-14 07:40:40 -06:00
Christian Göttsche
ce3a4ac7a3 lib: avoid double close on error
log.c:90:24: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]
    failure.c:94:24: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]
    failure.c:193:32: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]
    utmp.c:103:24: warning: double 'close' of file descriptor 'fd' [CWE-1341] [-Wanalyzer-fd-double-close]
2023-12-14 07:40:40 -06:00
Christian Göttsche
cdb2490ab6 Update close(2) checking
Check for close(2) failure at more places closing a file descriptor
written to.

Also ignore failures with errno set to EINTR (see man:close(2) for
details).
2023-12-14 07:40:40 -06:00
Christian Göttsche
92b889b671 src/useradd: free string
useradd.c:2329:10: warning: Potential leak of memory pointed to by 'btrfs_check' [unix.Malloc]
2023-12-14 07:40:40 -06:00
Christian Göttsche
6178f5a3df lib/failure,utmp: update error messages
Include errno description.
2023-12-14 07:40:40 -06:00
Christian Göttsche
7f20bb88ad lib/utmp: merge file access
Avoid checking if the file exists before opening it.

Resolves a CodeQL report of Time-of-check time-of-use filesystem race
condition.
2023-12-14 07:40:40 -06:00
Christian Göttsche
0d7cb003b7 src/useradd: avoid usage of sprintf
sprintf(3) does not take the destination buffer into account. Although
the destination in these case is large enough, sprintf(3) indicates a
code smell.

Use the xasprintf() wrapper.
2023-12-14 07:40:40 -06:00
Christian Göttsche
95a8de2a0a src/usermod,groups: use checked malloc
usermod.c:2165:24: warning: dereference of possibly-NULL ‘user_groups’ [CWE-690] [-Wanalyzer-possible-null-dereference]
2023-12-14 07:40:40 -06:00
Alejandro Colomar
76bbce3564 lib/, src/: Align variable definitions
This is just a cosmetic patch in preparation for others.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-13 10:06:34 -06:00
Alejandro Colomar
ce0fc161b4 src/login.c: Group preprocessor conditionals
Group them at the end of the list of variable definitions, and use
'#if defined()' instead of '#if[n]def'.  Also indent nested ones.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-13 09:15:09 -06:00
Tobias Stoeckmann
ab260fcd1f lib/defines.h: Remove ITI_AGING
ITI_AGING is not set through any build environment. If it would be set,
then timings in /etc/shadow would not fit anymore.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-12-13 09:08:12 -06:00
Alejandro Colomar
ef95bb7ed1 src/su.c: Fix type of variable
su.c:678:26: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘const void *’ [-Wformat=]
su.c:681:44: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘const void *’ [-Wformat=]
su.c:683:46: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘const void *’ [-Wformat=]

Reported-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-13 09:06:59 -06:00
Alejandro Colomar
9858133cc6 lib/, src/: snprintf(3) already terminates strings with NUL
We don't need to terminate them manually after the call.  Remove all
that paranoid code, which in some cases was even wrong.  While at it,
let's do a few more things:

-  Use sizeof(buf) for the size of the buffer.  I found that a few cases
   were passing one less byte (probably because the last one was
   manually zeroed later).  This caused a double NUL.  snprintf(3) wants
   the size of the entire buffer to properly terminate it.  Passing the
   exact value hardcoded is brittle, so use sizeof().

-  Align and improve style of variable declarations.  This makes them
   appear in this diff, which will help review the patch.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-13 12:34:30 +01:00
Alejandro Colomar
93a5c47c2c lib/: Use ATTR_STRING() on stpecpy() and strtcpy()
These functions consume a source string.  Document that.  There's no way
to mark that they also produce a string in dst, though.  That will be up
to the static analyzer to guess.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 12:22:47 +01:00
Alejandro Colomar
a61cf0068b lib/attr.h: Add ATTR_STRING() attribute macro
It signals that a function parameter is a string _before_ the call.

Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 12:22:47 +01:00
Alejandro Colomar
1c464d9a2d lib/, src/: Fix error handling after strto[u]l[l](3)
-  Set errno = 0 before the call.  Otherwise, it may contain anything.
-  ERANGE is not the only possible errno value of these functions.  They
   can also set it to EINVAL.
-  Any errno value after these calls is bad; just compare against 0.
-  Don't check for the return value; just errno.  This function is
   guaranteed to not modify errno on success (POSIX).
-  Check endptr == str, which may or may not set EINVAL.

Suggested-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 12:21:55 +01:00
Alejandro Colomar
f6701d3efa lib/prefix_flag.c: Invert conditional to remove a branch
This simplifies the code, and is preparation for a following commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 12:21:55 +01:00
Alejandro Colomar
ad1e0e9f96 lib/string/strtcpy.h: Don't use a ternary op, to silence a -Wsign-compare warning
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
62772039b7 src/gpasswd.c: Simplify cpp conditional
Since failure() is [[noreturn]], we can invert the conditional so that
we don't need an else.  This silences a -Wunused-parameter warning.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
0c1ca49be3 src/gpasswd.c: Reduce scope of cpp conditional
This prepares for the next patch, which will invert the logic of the
conditional.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
9035f90510 src/gpasswd.c: Mark failure() as [[noreturn]]
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
ccc055d9d9 src/gpasswd.c: Move if out of cpp conditional
This simplifies the code a little bit, and prepares for the next
commits, which will clean up further.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
1fcf807949 src/login_nopam.c: Add missing 'const'
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
d2aa177c50 autogen.sh: CFLAGS: Add -Wno-expansion-to-defined
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
82484117b3 lib/obscure.c: Mark parameter as [[maybe_unused]]
It's only used in certain builds.  This is to silence a -Wunused-parameter warning.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
5ba6cd8545 lib/loginprompt.c: Remove dead code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
5e0c61cce3 lib/limits.c: Check for overflow without invoking UB
The multiplication was already invoking UB.  The test was flawed.
Use __builtin_mul_overflow() instead.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
9b798b584a lib/limits.c: Fix wrong error check
strtol(3) doesn't specify a return value if (value == endptr).
It is always an error, if (value==endptr).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
00e4e0c735 lib/copydir.c: Cosmetic
I was investigating a warning in this function, but the code was
inscrutable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
97e9d60133 lib/commonio.c: Use uintmax_t to print nlink_t
See uintmax_t(3type).

While at it, remove the useless cast to (void).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
6be85b0baf lib/chkname.c: Use tmp variable to avoid a -Wsign-compare warning
I used size_t because:

sysconf(3) can return -1 if the value is not supported, but then it can
only mean that there's no limit.  Having no limit is the same as having
a limit of SIZE_MAX (to which -1 is converted).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
028e3e2764 autogen.sh: CFLAGS: Add -Wextra
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-04 11:45:09 +01:00
Alejandro Colomar
fc8389331e lib/string/: Fortify source of strtcpy(), stpecpy(), and zustr2stp()
By writing the terminating null byte via stpcpy(3), we take advantage of
_FORTIFY_SOURCE for the last byte, which was unprotected before this
commit.

Reported-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 22:24:29 -06:00
Alejandro Colomar
72060a2b2b lib/env.c: Replace strncpy(3) call by stpcpy(mempcpy(), "")
We were using strncpy(3), which is designed to copy from a string into a
(null-padded) fixed-size character array.  However, we were doing the
opposite: copying from a known-size array (which was a prefix of a
string), into a string.  That's why we had to manually zero the buffer
afterwards.

Use instead mempcpy(3) to copy the non-null bytes, and then terminate
with a null byte with stpcpy(..., "").

Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 22:24:29 -06:00
Alejandro Colomar
dbb37b1b31 lib/string/: Move string-related files to string/ subdir
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 12:22:11 -06:00
Alejandro Colomar
d1ad64b40f configure.ac: AM_INIT_AUTOMAKE: Use [subdir-objects]
This will allow using subdirs.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 12:22:11 -06:00
Alejandro Colomar
4f16458b6c lib/, src/: Say 'long' instead of 'long int'
We were using 'long' in most places, so be consistent and use it
everywhere.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 09:58:19 -06:00
Alejandro Colomar
44b8f7b3ef lib/attr.h, lib/, src/: Move attributes to new header file
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 09:56:13 -06:00
Sergei Trofimovich
5abe0811b8 src: add missing declaration of getdef_bool
Upcoming `gcc-14` enabled a few warnings into errors, like
`-Wimplicit-function-declaration`. This caused `shadow` build to fail
as:

    pwunconv.c: In function 'main':
    pwunconv.c:132:13: error: implicit declaration of function 'getdef_bool' [-Wimplicit-function-declaration]
      132 |         if (getdef_bool("USE_TCB")) {
          |             ^~~~~~~~~~~

The change adds missing include headers.
2023-12-02 11:04:35 -06:00
Alejandro Colomar
0d2fa501ec lib/defines.h: Remove condition on __STRICT_ANSI__
We require C11 since a few releases ago.  It seems I missed this
reminder of ANSI C (C89) back then.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-28 17:00:46 +01:00
Alejandro Colomar
218235e9dd tests/unit/test_chkname.c: Test is_valid_user_name()
Suggested-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-28 16:57:54 +01:00
Tobias Stoeckmann
4b89ac41cb chsh: limit acceptable shells to absolute paths
If an entry in /etc/shells is not an absolute path (comments or
partial reads due to fgets), the line should not be considered as
a valid login shell.

In general all systems should have getusershells, but let's better
be safe than sorry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2023-11-27 09:16:08 +01:00
Alejandro Colomar
721b9096eb lib/: Use NITEMS() instead of SIZEOF_ARRAY() where number of elements is meant
For arrays of char, both NITEMS() and SIZEOF_ARRAY() return the same
value.  However, NITEMS() is more appropriate.  Think of wide-character
equivalents of the same code; with NITEMS(), they would continue to be
valid, while with SIZEOF_ARRAY(), they would be wrong.

In the implementation of ZUSTR2STP(), we want SIZEOF_ARRAY() within the
static assert, because we're just comparing the sizes of the source and
destination buffers, and we don't care if we compare sizes or numbers of
elements, and using sizes is just simpler.  But we want NITEMS() in the
zustr2stp() call, where we want to copy a specific number of characters.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 21:01:05 -06:00
Alejandro Colomar
a5cddf243a lib/chkname.c: Update regex for valid names
The maximum length of 32 wasn't being enforced in the code, and POSIX
doesn't specify that maximum length either, so it seems it was an
arbitrary limit of the past that doesn't exist any more.  Use a regex
that has no length limit.

Closes: <https://github.com/shadow-maint/shadow/issues/836>
Link: <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:56:33 -06:00
Alejandro Colomar
fe62fc48bf tests/unit/test_strncpy.c: Test STRNCPY()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
ce30dfe255 lib/: Use STRNCPY() instead of strncpy(3)
We've recently fixed several bugs in the calculation of the size in this
function call.  Use this wrapper to prevent similar mistakes in the
future.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
225530b7e1 lib/strncpy.h: Add STRNCPY() wrapper for strncpy(3)
This wrapper calculates the destination buffer's size, to avoid errors
in the size calculation.

A curious fact: this macro did exist in Version 7 Unix (with a slightly
different name).  I found it by chance, investigating the origins of
strncpy(3) and strncat(3) in V7, after Branden suggested me to do so,
related to recent discussions about string_copying(7).

	alx@debian:~/src/unix/unix/Research-V7$ grepc SCPYN .
	./usr/src/cmd/login.c:#define SCPYN(a, b)	strncpy(a, b, sizeof(a))

Our implementation is slightly better, because using nitems() we're
protected against passing a pointer instead of an array, and it's also
conceptually more appropriate: for wide characters, it would be

	#define WCSNCPY(dst, src)  wcsncpy(dst, src, NITEMS(dst))

Cc: "G. Branden Robinson" <branden@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
07ab1af55c lib/: Remove off-by-one bugs in calls to strncpy(3)
We're not even zeroing the last byte after this call.  This was a
completely gratuitous truncation of one byte, and the resulting
character array still wasn't guaranteed to be null terminated, because
strncpy(3) can't do that.

Just to clarify, none of these structures needed zeroing, as they are
treated as null-padded fixed-size character arrays.  Calling strncpy(3)
was actually the correct call, and the only problem was unnecessarily
truncating strings by one byte more than necessary.

Cc: Matthew House <mattlloydhouse@gmail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
81f0e6a30f lib/log.c: Replace strncpy(3) call by STRTCPY()
This call was too clever.  It relied on the last byte of ll_line
being 0 due to a previous memzero() and not writing to it later.
Write an explicit terminating null byte, by using STRTCPY().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
09957c6d27 lib/failure.c: Replace strncpy(3) call by STRTCPY()
This call was way too clever.  It relied on the last byte of fail_line
being 0 due to it being in a static structure and never writing to it.
Write an explicit terminating null byte, by using STRTCPY().

Cc: Matthew House <mattlloydhouse@gmail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
8a1a097afa lib/utmp.c: Replace strncpy(3) call by ZUSTR2STP()
We were copying from a (zero-padded) fixed-width character array to a
string, but strncpy(3) is meant to do the opposite thing.  ZUSTR2STP()
is designed to be used in this case (like strncat(3)).

Fixes: f40bdfa66a ("libmisc: implement `get_session_host()`")
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
751f8e055b tests/: Remove references to cracklib
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-25 21:24:38 -06:00
Alejandro Colomar
45f34ee8c1 Remove libcrack support
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-25 21:24:38 -06:00
Alejandro Colomar
43b4e5a6c4 Remove FascistHistory() and FascistHistoryPw() calls
These functions don't seem to exist anymore.  I can't find them in
Debian, nor in a web search.  They probably were functions from an
ancient implementation of cracklib that doesn't exist anymore.

$ git remote -v
origin	git@github.com:cracklib/cracklib.git (fetch)
origin	git@github.com:cracklib/cracklib.git (push)
$ grep -rni fascisthistory
$ git log --grep FascistHistory
$ git log -S FascistHistory

Closes: <https://codesearch.debian.net/search?q=FascistHistory&literal=1>
Cc: Mike Frysinger <vapier@gentoo.org>
Acked-by: Michael Vetter <jubalh@iodoru.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-25 21:24:38 -06:00
Alejandro Colomar
1c50a44db6 lib/date_to_str.c: strftime(3) leaves the buffer undefined on failure
strftime(3) makes no guarantees about the contents of the buffer if the
formatted string wouldn't fit in the buffer.  It simply returns 0, and
it's the programmer's responsibility to do the right thing after that.

Let's write the string "future" if there's an error, similar to what we
do with gmtime(3)'s errors.

Also, `buf[size - 1] = '\0';` didn't make sense.  If the copy fits,
strftime(3) guarantees to terminate with NUL.  If it doesn't, the entire
contents of buf are undefined, so adding a NUL at the end of the buffer
would be dangerous: the string could contain anything, such as
"gimme root access now".  Remove that, now that we set the string to
"future", as with gmtime(3) errors.  This setting to '\0' comes from the
times when we used strncpy(3) in the implementation, and should have
been removed when I changed it to use strlcpy(3); however, I didn't
check we didn't need it anymore.

Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-23 08:04:39 -06:00
Alejandro Colomar
bbf1d9a800 src/logoutd.c: Fix theoretical buffer overrun
ut_line doesn't hold a string.  It is a null-padded fixed-width array.
Luckily, I don't think there has ever existed a ut_line ("/dev/tty*")
that was 32 bytes long.  That would have resulted in a buffer overrun.
Anyway, do the right thing, which is copying into a temporary string.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:58:17 +01:00
Alejandro Colomar
2eceb4381c lib/date_to_str.c, configure.ac: Replace calls to strlcpy(3) by strtcpy(3)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
3c5a563654 lib/date_to_str.c: Add missing include <config.h>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
ff8e4ede1e lib/Makefile.am: Add missing source file
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
f9fb855889 src/, lib/, tests/: Rename files defining strtcpy()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
090c019ada src/, lib/, tests/: Rename STRLCPY() to STRTCPY()
It is a wrapper around STRTCPY(), so use a proper name.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
6adaa40135 lib/strlcpy.[ch]: Implement strtcpy(3) to replace strlcpy_()
There's been a very long and interesting discussion in linux-man@ and
libc-alpha@, where we've discussed all the string-copying functions,
their pros and cons, when should each be used and avoided, etc.

Paul Eggert pointed out an important problem of strlcpy(3): it is
vulnerable to DoS attacks if an attacker controls the length of the
source string.  And even if it doesn't control it, the function is dead
slow (because its API forces it to calculate strlen(src)).

We've agreed that the general solution for a truncating string-copying
function is to write a wrapper over strnlen(3)+memcpy(3), which is
limited to strnlen(src, sizeof(dst)).  This is not vulnerable to DoS,
and is very fast for all buffer sizes.  string_copying(7) has been
updated to reflect this, and provides a reference implementation for
this wrapper function.

This strtcpy(3) (t for truncation) wrapper happens to have the same API
that our strlcpy_() function had, so replace it with the better
implementation.  We don't need to update callers nor tests, since the
API is the same.

A future commit will rename STRLCPY() to STRTCPY(), and replace
remaining calls to strlcpy(3) by calls to this strtcpy(3).

Link: <https://lore.kernel.org/linux-man/ZU4SDh-Se5gjPny5@debian/T/#mfb5a3fdeb35487dec6f8d9e3d8548bd0d92c4975/>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
0f27931155 lib/strlcpy.[ch]: Fix return type
To return an error code, we need ssize_t.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
6879f46327 tests/unit/test_strlcpy.c: Test strlcpy_() and STRLCPY()
This test fails now, due to a bug: the return type of strlcpy_() is
size_t, but it should be ssize_t.  The next commit will pass the test,
by fixing the bug.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
dad103bdb9 README.md, STABLE.md: record the stable branch URL(s).
Acked-by: Serge Hallyn <serge@hallyn.com>
Acked-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-17 09:49:15 -06:00
Joakim Tjernlund
ee3a79c695 Define SUBUID_FILE/SUBGID_FILE
These where hard coded, make them definable like SHADOW_FILE

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
2023-11-13 12:40:48 +01:00
Iker Pedrosa
a9e642d444 CI: fix Fedora 39 build
libbsd is unwanted in Fedora and RHEL, and the recently released Fedora
39 doesn't contain this dependency in the base image.

shadow removed libbsd from its dependencies for Fedora 39, so let's
build without it to avoid compilation errors.

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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
2023-11-13 12:39:13 +01:00
Alejandro Colomar
5c86700fd7 lib/utmp.c: Don't check for NULL before free(3)
free(NULL) is valid; there's no need to check for NULL.  Simplify.

Fixes: 5178f8c5af ("utmp: call prepare_utmp() even if utent is NULL")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-29 21:12:02 -05:00
Serge Hallyn
b11129827a Add keys/ directory with public keys for maintainers
These can be used to verify releases.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-10-26 22:31:27 -05:00
Michael Vetter
01f6258df7 man: document --prefix option in chage, chpasswd and passwd
Support for `--prefix` was added in
https://github.com/shadow-maint/shadow/pull/714 and is available since
shadow 4.14.0.

Close https://github.com/shadow-maint/shadow/issues/822
2023-10-26 10:14:53 -05:00
Christian Göttsche
2fa907a522 libmisc/copydir: do not forget errors from directory copy
copydir.c:429:4: warning: Value stored to 'err' is never read [deadcode.DeadStores]

Also reduce indentation by bailing out early.

(cherry picked from commit d89f2fb06d1b81b56299f9d0bfe7a927a2282f19)
2023-10-21 21:37:38 -05:00
Serge Hallyn
fa68441bc4 Improve the login.defs unknown item error message
Closes #746

Only print the 'unknown item' message to syslog if we are
actually parsing a login.defs.  Prefix it with "shadow:" to make
it clear in syslog where it came from.

Also add the source filename to the console message.  I'm not
quite clear on the econf API, so not sure whether in that path we
will end up actually having the path, or printing ''.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-10-20 18:46:23 -05:00
Alejandro Colomar
d73f480ddc autogen.sh: Prepare CFLAGS before ./configure
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
b3652d8a32 lib/: Add missing #include <config.h>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
a6d795bac5 autogen.sh: CFLAGS: Add -Werror=implicit-function-declaration
This is not just a style issue.  This should be a hard error, and never
compile.  ISO C89 already had this feature as deprecated.  ISO C99
removed this deprecated feature, for good reasons.  If we compile
ignoring this warning, shadow is not going to behave well.

Cc: Sam James <sam@gentoo.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
d5e1c1e475 lib/, src/: Use xasprintf() instead of its pattern
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
ad3b31a59e lib/, src/: Use asprintf(3) instead of strlen(3)+malloc(3)+snprintf(3)
asprintf(3) is non-standard, but is provided by GNU, the BSDs, and musl.
That makes it portable enough for us to use.

This function is much simpler than the burdensome code for allocating
the right size.  Being simpler, it's thus safer.

I took the opportunity to fix the style to my preferred one in the
definitions of variables used in these calls, and also in the calls to
free(3) with these pointers.  That isn't gratuituous, but has a reason:
it makes those appear in the diff for this patch, which helps review it.
Oh, well, I had an excuse :)

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
c5e5fee606 lib/copydir.c: Use goto to reduce a conditional branch
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
2a558bd8cb tests/unit/test_xasprintf.c: Test x[v]asprintf()
Link: <https://github.com/shadow-maint/shadow/pull/816>
Suggested-by: Iker Pedrosa <ipedrosa@redhat.com>
Acked-by: Andreas Schneider <https://github.com/cryptomilk>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
83c8a2d3fa lib/sprintf.[ch]: Add x[v]asprintf()
As other x...() wrappers around functions that allocate, these wrappers
are like [v]asprintf(3), but exit on failure.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Alejandro Colomar
7c93e1cdce lib/copydir.c: Invert conditional to reduce nesting
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-10-20 21:05:33 +02:00
Dimitri John Ledkov
088fe2618f Fix badname option to be singular just like useradd.
Badnames still accepted, note that previously usage already stated
singular form, whilst manpage and real one was plural only.

Fixes: 45d6746219 ("src: correct "badname" option")

Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
2023-10-16 12:45:21 -05:00
Dimitri John Ledkov
2e45fff44b Fix mixed-whitespace
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
2023-10-16 12:45:21 -05:00
Iker Pedrosa
0d50e1e15f Remove TODO
Sad to remove this file, but things are going on and it doesn't seem to
be up to date.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
fe299017b1 Remove shadow.spec.in
The file isn't up to date with the latest development, the last change
was made 15 years ago, so I'm removing it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
a0546212c0 Remove .travis.yml
It isn't used anywhere so let's remove it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
c883786f4f doc: remove WISHLIST
Another file that I remove with sadness. We were unable to complete the
first item but we are working hard on it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
bc35dfe4ec doc: remove README.platforms
I remove this file with sadness, as it contains data from old times.
Unfortunately, this data is no longer relevant. The source code
management tool will keep it in memory.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
2cfa1743d3 doc: remove cracklib26.diff
Keeping a patch for a file no longer maintained is a bad idea, so I'm
removing it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
3a43d72e42 doc: remove console.c.spec.txt
I guess we are keeping this for historical purposes more than anything
else. If so, anybody can check the git history to recover the
specification.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
b91b3793a9 contrib: remove udbachk.tgz
Having source code in a compressed file doesn't seem like a good idea. I
checked several distributions and they don't distribute this binary, so
let's remove it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
d702e08097 contrib: remove shadow-anonftp.patch
The patch is never applied upstream. If I were to take a gamble, I would
even say that it throws an error when trying to patch.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
52d2198252 contrib: remove groupmems.shar
Not sure what this file is exactly, but there's already a groupmems.c
that should generate the binary responsible for managing  the members of
a user's primary group.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
fbcd8b536a contrib: remove atudel
AFAIK, it isn't included in any distribution and it isn't used
internally in the project, so let's remove it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Iker Pedrosa
13a7713384 CI: remove .builds folder
We stopped using the CI relying on this folder and moved to Github's, so
I'm removing these files.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-10-04 13:31:38 -05:00
Johannes Segitz
48aa12af31 useradd: Set proper SELinux labels for def_usrtemplate
Fixes: 74c17c716 ("Add support for skeleton files from /usr/etc/skel")

Signed-off-by: Johannes Segitz <jsegitz@suse.com>
2023-10-03 09:24:47 +02:00
Iker Pedrosa
4f49e3fd3e doc: add unit tests
Brief description of the unit testing framework and how to create test
cases with it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-09-29 09:24:01 +02:00
Iker Pedrosa
0fc697a4b1 CI: build and run unit tests
Run `make check` after the project is built in every runner.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-09-29 09:24:01 +02:00
Iker Pedrosa
015448b049 tests: happy path for active_sessions_count()
Simple test to check the recently implemented logind functionality. It
also contains the changes to the build infrastructure, and the
gitignore.

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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-09-29 09:24:01 +02:00
Iker Pedrosa
163c424999 configure: add cmocka for unit tests
Prepare the ground for unit tests.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-09-29 09:24:01 +02:00
Christian Göttsche
247a869ccd faillog: check for overflows
Check for arithmetic overflows when computing offsets to avoid file
corruptions for huge UIDs.

Refactor the file lookup into a separate function.
2023-09-29 09:20:43 +02:00
Iker Pedrosa
5178f8c5af utmp: call prepare_utmp() even if utent is NULL
update_utmp() should also return 0 when success.

Fixes: 1f368e1c18 ("utmp: update
`update_utmp()")
Resolves: https://github.com/shadow-maint/shadow/issues/805

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-09-15 12:57:16 -05:00
Vasil Velichkov
bef4da47be groupadd: Improve error message when opening group file fails.
Both gr_open and sgr_open are using commonio_open function and when
there is a failure this function sets errno accordingly.
2023-09-04 16:04:42 +02:00
Alejandro Colomar
c1fd94d7d5 lib/mempcpy.[ch]: Remove our definition of mempcpy(3)
It is provided by glibc, musl, and FreeBSD.

Reported-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-04 08:57:43 -05:00
Alejandro Colomar
9b0f8ddc30 lib/pwauth.c: Replace getpass(3) by agetpass()
Closes: <https://github.com/shadow-maint/shadow/issues/797>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-04 08:57:18 -05:00
Alejandro Colomar
7c45a6e8ba lib/agetpass.h: Move prototypes to dedicated header
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-04 08:57:18 -05:00
Alejandro Colomar
158866bfdc lib/pwauth.c: Simplify empty string
And do not set 'clear' to point to the empty string.  After this commit,
'clear' only stores the result of getpass(3).  This will be useful to
change the code to use agetpass().

$ grep '\<clear\>' lib/pwauth.c;
	char *clear = NULL;
		clear = getpass (prompt);
		input = (clear == NULL) ? "" : clear;
		clear = getpass (prompt);
		input = (clear == NULL) ? "" : clear;
	if (NULL != clear) {
		strzero (clear);

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-04 08:57:18 -05:00
Alejandro Colomar
adbdd086a2 lib/pwauth.c: Remove dead code
There are no users of 'clear_pass' and 'wipe_clear_pass'.

$ grep -rn '\<clear_pass\>'
lib/pwauth.c:35:/*@null@*/char *clear_pass = NULL;
lib/pwauth.c:199:	 * not wipe it (the caller should wipe clear_pass when it is
lib/pwauth.c:203:	clear_pass = clear;

$ grep -rn wipe_clear_pass
lib/pwauth.c:34:bool wipe_clear_pass = true;
lib/pwauth.c:198:	 * if the external variable wipe_clear_pass is zero, we will
lib/pwauth.c:204:	if (wipe_clear_pass && (NULL != clear) && ('\0' != *clear)) {
ChangeLog:3813:	* lib/pwauth.c: Use a boolean for wipe_clear_pass and use_skey.

Remove them.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-04 08:57:18 -05:00
Alejandro Colomar
2b393114c7 lib/pwauth.c: Remove dead code
If the string is "", then strzero() is a no-op.  We don't need to test
that.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-04 08:57:18 -05:00
Alejandro Colomar
8893c51480 autogen.sh: Support out-of-tree builds
This allows to do the following:

~/src/shadow/shadow/master$ mkdir .tmp/ && cd .tmp/
~/src/shadow/shadow/master/.tmp$ ../autogen.sh

Link: <https://github.com/shadow-maint/shadow/issues/795>
Reviewed-by: Sam James <sam@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-04 15:47:14 +02:00
Alejandro Colomar
9514a841bc zustr2stp.h: Assert some assumptions about the size
If the destination buffer is an array, we can check our assumptions.
This adds a readable way to explain that dsize must be strictly > ssize.
The reason is that the destination string is the source + '\0'.

If the destination is not an array, it's up to _FORTIFY_SOURCE or
-fanalyzer to catch newly introduced errors.  There's nothing we can do;
at least not portably.

Suggested-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
3bf8d68f10 strlcpy.[ch]: Add strlcpy_()
This function is like strlcpy(3), but returns -1 on truncation, which
makes it much easier to test.  strlcpy(3) is useful in two cases:

-  We don't care if the output is truncated.  strlcpy(3) is fine for
   those, and the return value can be ignored.

-  Truncation is bad.  In that case, we just want to signal truncation,
   and the length of the original string is quite useless.  Return the
   length iff no truncation so that we can use it if necessary.

This simplifies the definition of the STRLCPY() macro.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
e7a292ed4f Use bzero(3) instead of its pattern
It was blessed by POSIX.1-2001, and GCC says that it won't go away,
possibly ever.

memset(3) is dangerous, as the 2nd and 3rd arguments can be accidentally
swapped --who remembers what's the order of the 2nd and 3rd parameters
to memset(3) without checking the manual page or some code that uses
it?--.  Some recent compilers may be able to catch that via some
warnings, but those are not infalible.  And even if compiler warnings
could always catch that, the time lost in fixing or checking the docs is
lost for no clear gain.  Having a sane API that is unambiguous is the
Right Thing (tm); and that API is bzero(3).

If someone doesn't believe memset(3) is error-prone, please read the
book "Unix Network Programming", Volume 1, 3rd Edition by Stevens, et
al., Section 1.2.  See a stackoverflow reference in the link below[1].

bzero(3) had a bad fame in the bad old days, because some ancient
systems (I'm talking of many decades ago) shipped a broken version of
bzero(3).  We can assume that all systems in which current shadow utils
can be built, have a working version of bzero(3) --if not, please fix
your broken system; don't blame the programmer--.

One reason that some use today to avoid bzero(3) in favor of memset(3)
is that memset(3) is more often used; but that's a circular reasoning.
Even if bzero(3) wasn't supported by the system, it would need to be
invented.  It's the right API.

Another reason that some argue is that POSIX.1-2008 removed the
specification of bzero(3).  That's not a problem, because GCC will
probably support it forever, and even if it didn't, we can redefine it
like we do with memzero().  bzero(3) is just a one-liner wrapper around
memset(3).

Link: [1] <https://stackoverflow.com/a/17097978>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
624bacfbd8 Use CALLOC() instead of its pattern
MALLOC() + memset() is simpler written as CALLOC().

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
24367027d6 Use STRLCPY() instead of its pattern
This makes it harder to make mistakes while editing the code.  Since the
sizeof's can be autocalculated, let the machine do that.  It also
reduces the cognitive load while reading the code.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
370652ba05 defines.h: Remove definition of STRFCPY()
It's not being used anymore.  We got rid of it in favor of better APIs.

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

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

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
3029883888 passwd: Replace STRFCPY() by STRLCPY()
The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
7bfcf1724c gpasswd: Replace STRFCPY() by STRLCPY()
The variable is only being read as a string (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
fcc25a03cd login: Replace STRFCPY() by STRLCPY()
The variable is only being read as a string (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
6dacb154e5 su: Replace STRFCPY() by STRLCPY()
The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
3e0913f119 sulogin: Replace STRFCPY() by STRLCPY()
The variable is only being read as a string (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
2ffc1a76f5 chsh: Replace STRFCPY() by STRLCPY()
The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
8e33195c8e chfn: Replace STRFCPY() by STRLCPY()
The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
5579b40e35 chage: Replace STRFCPY() by STRLCPY()
The variables are only being read as strings (char *), so data after the
'\0' can't be leaked.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
33abc8bcd9 strlcpy.h: Add STRLCPY() macro
It wraps strlcpy(3bsd) so that it performs some steps that one might
forget, or might be prone to accidents:

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

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

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

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
b1b5c46668 Use ZUSTR2STP() instead of its pattern
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
983a844633 zustr2stp.h: Add ZUSTR2STP() macro
It's a wrapper around zustr2stp() that calls SIZEOF_ARRAY() internally.
The function call is usually --in our code base, always-- called with an
array as the second argument.  For such an argument, one should call
SIZEOF_ARRAY().  To avoid mistakes, and simplify usage, let's add this
macro that does it internally.

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

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
02b1471d5b Call zustr2stp() where appropriate
These calls were intending to copy from a NUL-padded (possibly
non-NUL-terminated) character sequences contained in fixed-width arrays,
into a string, where extra padding is superfluous.  Use the appropriate
call, which removes the superfluous work.  That reduces the chance of
confusing maintainers about the intention of the code.

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

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

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
6a576391d6 zustr2stp.[ch]: Add zustr2stp()
There's no standard function that copies from a null-padded character
sequence into a string.

A few standard functions can be workarounded to do that:

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

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

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

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

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

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
ec1cc096e8 libmisc: Fix wrong #include
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
f3ee47fe3f Use MEMZERO() instead of its pattern
This patch implicitly adds the safety of SIZEOF_ARRAY(), since the calls
were using sizeof() instead.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
64ab401239 memzero.h: Add MEMZERO() macro
It calculates the size of the array safely, via SIZEOF_ARRAY(), instead of
sizeof(), which can be dangerous.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
e299942189 sizeof.h: Add SIZEOF_ARRAY() macro
This makes it safe to call sizeof() on an array.  Calling sizeof()
directly on an array is dangerous, because if the array changes to be a
pointer, the behavior will unexpectedly change.  It's the same problem
as with NITEMS().

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
49ea7327d9 sizeof.h: Make NITEMS() and derivative macros safe against pointers
By using must_be_array(), code that calls NITEMS() or STRLEN() with
non-arrays will not compile.

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
c3a8d02b9f must_be.h: Add must_be_array() macro
This macro statically asserts that the argument is an array.

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
10f31a97e2 must_be.h: Add must_be() macro
It's like static_assert(3), but can be used in more places.  It's
necessary for writing a must_be_array() macro.

Link: <https://stackoverflow.com/a/57537491>
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
328958ca01 sizeof.h: Move sizeof()-related macros to their own header
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
246edc0481 memzero.h: Remove no-op assignment
memset(3) returns the input pointer.  The assignment was effectively a
no-op, and just confused the code.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
2daa6cc65d memzero.[ch]: Define memzero() and strzero() as inline functions
There's no need to have these as macros, so use functions, which are a
lot safer: there's no need to worry about multiple evaluation of args,
and there's also more type safety.  Compiler warnings are also simpler,
as they don't dump all the nested macros.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
fca2fd65c0 memzero.h: Remove outdated comments
These comments were wrong.  Remove them instead of fixing them, since
now that we have this small header file, it's much easier to follow the
preprocessor conditionals.

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
6b11077f09 memzero.h: Move memzero() and strzero() to their own header
Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-09-01 09:39:23 +02:00
Alejandro Colomar
093fb605f9 lib: Merge libmisc into libshadow
The separation was unnecessary, and caused build problems.  Let's go
wild and obliterate the library.  The files are moved to libshadow.

Scripted change:

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

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

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

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

Plus updating the Makefiles.

Closes: <https://github.com/shadow-maint/shadow/issues/791>
Closes: <https://bugs.gentoo.org/912446>
Link: <https://github.com/shadow-maint/shadow/issues/763#issuecomment-1664383425>
Link: <https://github.com/shadow-maint/shadow/pull/776>
Link: <d0518cc250>
Reported-by: Christian Bricart <christian@bricart.de>
Reported-by: Robert Marmorstein <robert@marmorstein.org>
Cc: Sam James <sam@gentoo.org>
[ jubalh tested the openSUSE package ]
Tested-by: Michael Vetter <jubalh@iodoru.org>
Acked-by: Michael Vetter <jubalh@iodoru.org>
[ Robert F. tested the Gentoo package ]
Tested-by: Robert Förster <Dessa@gmake.de>
Cc: David Seifert <soap@gentoo.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-08-30 17:22:38 +02:00
Christian Göttsche
f76c31f50e Avoid usage of sprintf
sprintf(3) does not take the destination buffer into account. Although
the destination in these case is large enough, sprintf(3) indicates a
code smell.

Use snprintf(3).
2023-08-21 16:04:09 -05:00
Christian Göttsche
e0d3ba6934 commonio: check for path truncations
Bail out if the paths generated for the backup and replacement database
are truncated.
2023-08-21 15:56:44 -05:00
Christian Göttsche
54ab542887 lib/btrfs: avoid NULL-dereference
btrfs.c:42:13: warning: use of NULL 'cmd' where non-null expected [CWE-476] [-Wanalyzer-null-argument]

Reviewed-by: Alejandro Colomar <alx@kernel.org>
2023-08-21 14:05:34 -05:00
Christian Göttsche
a08021eb0e lib/commonio: drop dead store
commonio.c:522:15: warning: Although the value stored to 'cp' is used in the enclosing expression, the value is never actually read from 'cp' [deadcode.DeadStores]

Reviewed-by: Alejandro Colomar <alx@kernel.org>
2023-08-21 14:05:27 -05:00
Christian Göttsche
931e7c0c2f login: use strlcpy to always NUL terminate
login.c:728:25: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation]

Reviewed-by: Alejandro Colomar <alx@kernel.org>
2023-08-21 14:05:18 -05:00
Christian Göttsche
15f4421f10 lib: avoid dropping const qualifier during cast
subordinateio.c:360:20: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      360 |         range1 = (*(struct commonio_entry **) p1)->eptr;
          |                    ^
    subordinateio.c:364:20: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual]
      364 |         range2 = (*(struct commonio_entry **) p2)->eptr;
          |                    ^

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

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

Reviewed-by: Alejandro Colomar <alx@kernel.org>
2023-08-21 13:54:27 -05:00
Christian Göttsche
856ffcfa5e Drop unnecessary cast to same type 2023-08-21 11:43:30 +02:00
Christian Göttsche
35edae5892 Declare usage and failure handler noreturn
Assist static analyzers in understanding final code paths.
2023-08-21 11:43:18 +02:00
Christian Göttsche
1aaa4ec5ba lib/tcbfuncs: operate on file descriptor rather than path 2023-08-21 11:29:17 +02:00
Alejandro Colomar
f45498a6c2 libmisc/write_full.c: Improve write_full()
Documentation:

-  Correct the comment documenting the function:

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

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

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

API:

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

Implementation:

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

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

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

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

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

Use:

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

Cc: Christian Göttsche <cgzones@googlemail.com>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-08-18 20:35:15 -05:00
Heiko Becker
890f911e17 Replace __{BEGIN,END}_DECLS with #ifdef __cplusplus
Fixes the build with musl libc.
2023-08-18 18:04:11 -05:00
Serge Hallyn
014536f5d5 release 4.14.0
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-15 21:38:30 -05:00
Serge Hallyn
ca0f828e7a pre-release 4.14.0-rc5
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-14 11:51:36 -05:00
Serge Hallyn
ebad5f840a configure.ac: check for strlcpy
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-14 09:08:35 -05:00
Michael Vetter
ae2a4507ed Remove intree website
AFAIK these files were not used in a while.
On 2023-04-27 we also archived the GitHub pages based repo:
https://github.com/shadow-maint/shadow-www

In 1654f42194 we mention the regular repo URL as our home page.

Also see:
https://github.com/shadow-maint/shadow/issues/114
2023-08-14 07:06:51 -05:00
Serge Hallyn
c1924dc5a1 4.14.0-rc4 pre-release
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-12 23:17:52 -05:00
Serge Hallyn
ee3e6112d3 Releases: add etc/shadow-maint to distfiles
Closes #784

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-12 23:16:56 -05:00
Serge Hallyn
2492fc00d4 4.14.0-rc3
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-10 09:33:07 -05:00
Iker Pedrosa
776bbd0ccb libmisc: include freezero
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-08-10 09:29:17 -05:00
Iker Pedrosa
0e0a310acf libmisc: add freezero source code
If shadow is built without libbsd support, then freezero() needs to be
provided from the project.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-08-10 09:29:17 -05:00
Iker Pedrosa
7d5eeb2135 libmisc: add readpassphrase source code
If shadow is built without libbsd support, then readpassphrase() needs
to be provided from the project.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-08-10 09:29:17 -05:00
Iker Pedrosa
c408c4ad3d configure: add with-libbsd option
It enables the build with libbsd support. By default it is enabled.

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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-08-10 09:29:17 -05:00
Iker Pedrosa
6ddd10482b man: include shadow-man.xsl in tarball
This will help generate man pages from tarball.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-08-09 21:33:21 -05:00
Iker Pedrosa
8e17459fa1 man: include its.rules in tarball
This will help generate the man pages from tarball.

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

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-08-09 21:33:21 -05:00
Iker Pedrosa
c89b326350 autogen: enable lastlog build
Add "--enable-lastlog" to include lastlog man pages in tarball.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2023-08-07 09:42:11 -05:00
Christian Göttsche
969549fdf0 Add wrapper for write(2)
write(2) may not write the complete given buffer.  Add a wrapper to
avoid short writes.
2023-08-04 17:15:42 -05:00
Serge Hallyn
d63f3a0c0a tag 4.14.0-rc2
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-04 16:24:54 -05:00
Michael Vetter
d0518cc250 Add new files to libmisc_la_SOURCES
Resolves https://github.com/shadow-maint/shadow/issues/763
2023-08-04 15:39:55 -05:00
Serge Hallyn
4107c49ecd Add a make dist CI test
Add a CI test to check that make dist builds a usable tarball.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-08-04 14:15:49 -05:00
870 changed files with 156812 additions and 105761 deletions

View File

@@ -1,34 +0,0 @@
image: alpine/latest
# apk add --update alpine-sdk
packages:
- cmd:setcap
- autoconf
- automake
- byacc
- expect
- gettext
- gettext-dev
- gettext-lang
- libbsd-dev
- libcap-dev
- libtool
- linux-pam-dev
- pkgconf
- sed
sources:
- https://github.com/shadow-maint/shadow
tasks:
- build: |
cd shadow
./autogen.sh --without-selinux --disable-man --disable-nls
grep ENABLE_ config.status
- tasks: |
cd shadow
cat /proc/self/uid_map
cat /proc/self/status
make
make DESTDIR=/tmp/shadow-inst install
sudo make install
#TODO - fix up the tests. Let's merge what's here now as it
#at least tests build.
#(cd tests; sudo ./run_some || { cat testsuite.log; false; })

View File

@@ -1,33 +0,0 @@
image: fedora/latest
packages:
- autoconf
- automake
- byacc
- expect
- findutils
- gettext
- gettext-devel
- git
- libbsd-devel
- libselinux-devel
- libsemanage-devel
- libtool
- libxslt
- pkgconf
sources:
- https://github.com/shadow-maint/shadow
tasks:
- build: |
cd shadow
./autogen.sh --with-selinux --enable-man
grep ENABLE_ config.status
- tasks: |
cd shadow
cat /proc/self/uid_map
cat /proc/self/status
make
make DESTDIR=/tmp/shadow-inst install
sudo make install
#TODO - fix up the tests. Let's merge what's here now as it
#at least tests build.
#(cd tests; sudo ./run_some || { cat testsuite.log; false; })

View File

@@ -1,28 +0,0 @@
image: ubuntu/focal
packages:
- automake
- autopoint
- xsltproc
- libbsd-dev
- libselinux1-dev
- gettext
- expect
- byacc
- libtool
- pkgconf
sources:
- https://github.com/shadow-maint/shadow
tasks:
- build: |
cd shadow
./autogen.sh --without-selinux --disable-man
grep ENABLE_ config.status
- tasks: |
cd shadow
cat /proc/self/uid_map
cat /proc/self/status
systemd-detect-virt
make
make DESTDIR=/tmp/shadow-inst install
sudo make install
(cd tests; sudo ./run_some || { cat testsuite.log; false; })

View File

@@ -1,28 +0,0 @@
image: ubuntu/22.04
packages:
- automake
- autopoint
- xsltproc
- libbsd-dev
- libselinux1-dev
- gettext
- expect
- byacc
- libtool
- pkgconf
sources:
- https://github.com/shadow-maint/shadow
tasks:
- build: |
cd shadow
./autogen.sh --without-selinux --enable-man
grep ENABLE_ config.status
- tasks: |
cat /proc/self/uid_map
cat /proc/self/status
systemd-detect-virt
cd shadow
make
make DESTDIR=/tmp/shadow-inst install
sudo make install
(cd tests; sudo ./run_some || { cat testsuite.log; false; })

View File

@@ -5,8 +5,21 @@ runs:
steps:
- shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y ubuntu-dev-tools libbsd-dev
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt-get update -y
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
echo "Found new-style sources.list.d"
cat /etc/apt/sources.list.d/ubuntu.sources
sudo sed -i 's/^Types: deb/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
else
echo "Found legacy sources.list"
cat /etc/apt/sources.list
sudo sed -i '/deb-src/d' /etc/apt/sources.list
sudo sed -i '/^deb /p;s/ /-src /' /etc/apt/sources.list
fi
export DEBIAN_PRIORITY=critical
export DEBIAN_FRONTEND=noninteractive
# let's try to work around upgrade breakage in a pkg we don't care about
sudo apt-mark hold grub-efi-amd64-bin grub-efi-amd64-signed
sudo apt-get update
sudo apt-get -y dist-upgrade
sudo apt-get -y install ubuntu-dev-tools automake autopoint xsltproc gettext expect byacc libtool libbsd-dev libltdl-dev pkgconf
sudo apt-get -y build-dep shadow

View File

@@ -25,18 +25,8 @@ jobs:
cat /proc/self/status
systemd-detect-virt
- name: Install dependencies
run: |
sudo cat /etc/apt/sources.list
sudo sed -i '/deb-src/d' /etc/apt/sources.list
sudo sed -i '/^deb /p;s/ /-src /' /etc/apt/sources.list
export DEBIAN_PRIORITY=critical
export DEBIAN_FRONTEND=noninteractive
# let's try to work around upgrade breakage in a pkg we don't care about
sudo apt-mark hold grub-efi-amd64-bin grub-efi-amd64-signed
sudo apt-get update
sudo apt-get -y dist-upgrade
sudo apt-get -y install ubuntu-dev-tools automake autopoint xsltproc gettext expect byacc libtool libbsd-dev pkgconf
sudo apt-get -y build-dep shadow
id: dependencies
uses: ./.github/actions/install-dependencies
- name: configure
run: |
autoreconf -v -f --install
@@ -49,12 +39,37 @@ jobs:
run: |
set -e
cd tests
trap 'cat testsuite.log' ERR
sudo ./run_some
cat testsuite.log
trap - ERR
# Make sure that 'make dist' makes a usable tarball with no missing files
dist-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install dependencies
id: dependencies
uses: ./.github/actions/install-dependencies
- name: Test make dist
run: |
./autogen.sh
make dist
f=shadow-*.tar.gz
tar -zxf $f
d=$(basename $f .tar.gz)
cd $d
./configure
make -j5
make check
container-build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [alpine, debian, fedora]
@@ -62,15 +77,25 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Ansible
run: |
sudo apt-get update
sudo apt-get -y install ansible
- name: Build container
run: |
docker buildx build -f ./share/containers/${{ matrix.os }}.dockerfile . --output build-out
pushd share/ansible/
ansible-playbook playbook.yml -i inventory.ini -e 'distribution=${{ matrix.os }}'
popd
- name: Store artifacts
uses: actions/upload-artifact@v3
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-build
path: |
./build-out/config.log
./build-out/config.h
./share/ansible/build-out/config.log
./share/ansible/build-out/config.h
./share/ansible/build-out/build.log
./share/ansible/build-out/test-suite.log
if-no-files-found: ignore

View File

@@ -32,10 +32,7 @@ jobs:
- name: Build shadow-utils
run: |
PROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
make -kj$PROCESSORS || true
- name: Check build errors
run: make
make -Orecurse -j$PROCESSORS
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

7
.gitignore vendored
View File

@@ -3,9 +3,11 @@ lib*.a
*.o
*.lo
*.la
*.mo
*.gmo
.deps
.libs
.dirstamp
*.patch
*.rej
@@ -14,6 +16,8 @@ lib*.a
Makefile
Makefile.in
test-driver
/ABOUT-NLS
/aclocal.m4
/autom4te.cache
@@ -34,6 +38,7 @@ Makefile.in
/m4
/missing
/stamp-h1
/test-driver
/ylwrap
/po/*.header
@@ -47,5 +52,5 @@ Makefile.in
/shadow.spec
/shadow-*.tar.*
/libmisc/getdate.c
/lib/getdate.c
/libsubid/subid.h

View File

@@ -1,52 +0,0 @@
dist: bionic
sudo: false
language: c
compiler:
- gcc
- clang
arch:
- amd64
- arm64
- ppc64le
- s390x
before_install:
- sudo apt-get update -qq
- sudo apt-get -y install -qq automake autopoint xsltproc libselinux1-dev gettext expect
- sudo apt-get -y install -qq byacc libtool
script:
- ./autogen.sh --without-selinux --disable-man
- grep ENABLE_ config.status
- make
env:
global:
- secure: "G47VYFrtzqalrVjixTqBG9Qsa8EZRcaqsh1k6fq5JgEyHmMQActpvTUDs9FXf1MEqiY5XX3VDVfBsZgKPHgmHsMzD1bX11xpnpGByB8g7gr8I3u2ZkCREqgi77a5l3LeBh+seWiambe/DYOgvPCNa6pCynLgR9advqtgKhpCruU="
addons:
coverity_scan:
project:
name: "shadow-maint/shadow"
description: "Upstream shadow utils tree"
notification_email: christian.brauner@ubuntu.com,serge@hallyn.com
build_command_prepend: "./autogen.sh --without-selinux --disable-man"
build_command: "make -kj4 || make"
branch_pattern: master
script:
- cat /proc/self/uid_map
- cat /proc/self/status
- systemd-detect-virt
- ./autogen.sh --without-selinux --disable-man
- grep ENABLE_ config.status
- make
- sudo make install
- (cd tests; sudo ./run_some; cat testsuite.log)
# vim:et:ts=2:sw=2

View File

@@ -9,6 +9,14 @@ a lot of mail...
* Serge E. Hallyn <serge@hallyn.com> (2014-now)
* Christian Brauner <christian@brauner.io> (2019-now)
* Iker Pedrosa <ipedrosa@redhat.com> (2022-now)
* Alejandro Colomar <alx@kernel.org> (2023-now) (4.14 stable)
To verify signatures on releases, use the following keys under keys/ :
* Serge Hallyn: keys/66D0387DB85D320F8408166DB175CFA98F192AF2.asc
* Christian Brauner: keys/4880B8C9BD0E5106FC070F4F7B3C391EFEA93624.asc
* Iker Pedrosa: keys/4E80EF49C7987B6DE2F81F5005079C6C3A653E57.asc
* Alejandro Colomar: keys/A9348594CE31283A826FBDD8D57633D441E25BB5.asc
# Authors and contributors
* Adam Rudnicki <adam@v-lo.krakow.pl>

View File

@@ -1,15 +1,27 @@
## Process this file with automake to produce Makefile.in
EXTRA_DIST = NEWS README TODO shadow.spec.in
SUBDIRS = libmisc lib
SUBDIRS = lib
if ENABLE_SUBIDS
SUBDIRS += libsubid
endif
SUBDIRS += src po contrib doc etc
SUBDIRS += src po contrib doc etc tests/unit
if ENABLE_REGENERATE_MAN
SUBDIRS += man
endif
CLEANFILES = man/8.out man/po/remove-potcdate.* man/*/login.defs.d man/*/*.mo
EXTRA_DIST = NEWS README tests/
dist-hook:
chmod -R u+w $(distdir)/tests
chmod u+w $(distdir)
mv $(distdir)/tests/unit $(distdir)/realunittest
mv $(distdir)/tests/tests $(distdir)/realtests
rm -rf $(distdir)/tests
mv $(distdir)/realtests $(distdir)/tests
rm -rf $(distdir)/tests/unit $(distdir)/tests/Makefile*
mv $(distdir)/realunittest $(distdir)/tests/unit

View File

@@ -17,6 +17,12 @@ are used for managing group accounts.
* [Issue tracker](https://github.com/shadow-maint/shadow/issues)
* [Releases](https://github.com/shadow-maint/shadow/releases)
## Code
The main development branch is at [https://github.com/shadow-maint/shadow.git](https://github.com/shadow-maint/shadow)
See [STABLE.md](https://github.com/shadow-maint/shadow/blob/master/STABLE.md) for a list of supported stable branches.
## Contacts
There are several ways to contact us:
* [the general discussion mailing list](

11
STABLE.md Normal file
View File

@@ -0,0 +1,11 @@
# Supported stable branches
The following stable branches are kindly maintained by trusted volunteers:
- 4.15.x
- git
- [main](https://www.alejandro-colomar.es/src/alx/shadow/stable/shadow.git/log/?h=4.15.x)
- [mirror](https://github.com/shadow-maint/shadow/tree/4.15.x)
- tarballs
- [main](https://www.alejandro-colomar.es/share/dist/shadow/4/4.15/)
- [mirror](https://github.com/shadow-maint/shadow/releases/)

127
TODO
View File

@@ -1,127 +0,0 @@
* Create a common usage function that'd take the array of
long options and an array of descriptions and output that so things would
be standardized across the utils.
Usage strings should be normalized and split first.
Investigate optparse.
/etc/default/useradd
* GROUP=1000 should accept a group name.
Check when RLOGIN is enabled if ruserok() exists
Move selinux_file_context out of libmisc/copydir.c
Review hardcoded root account?
review all call to strto
libmisc/cleanup_user.c
cleanup needed (cleanup_report_add_user* not used)
libxcrypt support
* http://wiki.linuxfromscratch.org/patches/browser/trunk/shadow/shadow-4.0.18.1-owl_blowfish-1.patch
implement getlong, getulong.
avoid atoi, atol, atoul, strtol, strtoul, ...
manpages: comment the RLOGIN parts
Replace build_list (in lib/gshadow.c) and list (in lib/sgetgrent.c) by
comma_to_list()
Revert the modified files if all files could not be changed.
* or warn and indicate which files were modified and which were not.
* check the order the files are modified.
report nscd_flush_cache failures?
call nscd from the programs or from lib (commonio?)
PAM: check if a non-interactive conversation function could be used to set
the password in chpasswd and newusers
WITH_SELINUX
- review all tools to check that the strategies are consistent
chage, chfn, chsh: same change needed as in passwd.
- probably need moving check_selinux_access to a separate file.
testsuite
- newgrp
- test with unknown user's GID
newusers
- add logging to SYSLOG & AUDIT
- use CREATE_HOME
- Add a -Z option (see useradd / usermod)
Document when/where option appeared, document whether an option is standard
or not.
Check all the expiry semantics
ALL:
- move base passwd/shadow/group/gshadow operation to module for allow write
different backend modules for db, NIS, LDAP and others. Default backend it
will be goot if will be chosen depending on /etc/nsswitch.conf and allow
override this by -r <repository> options (where the <repository> can be
file, db, nis nisplus, ldap .. like on /etc/nsswitch.conf in service column).
passwd have old piece of code with handling -r option and it will be good
finish this and propagate on other shadow tools for allow operate on other
user databases by well known tools.
- Protect against signals. Register do_cleanups in a signal handler.
- login.defs
- generate depending on configuration
- useradd:
- add handle create user mail spool in maildir format.
- Add support for -k in -D mode
- Add support for -K in -D mode
- Add option to create or not the mail spool (and set the default in -D
mode)
- Change -l to reset the entry if an entry was already there
- set the mask in mkdir?
- userdel:
- add backup option for the removal of user resources,
- user_busy: check that the user is not running any processes.
- missing "deleting group" FAILED
- home dir removed, but userdel may fail and may leave the user
=> warning needed
- usermod
- add an option equivalent to useradd's -l (only when uid is changed)
- the mode of new home directories should be set according to the
original mode. Does copy_tree does this?
- user renamed, order is not kept in /etc/group (see
47_usermod-l_no_shadow_file). This is a problem when the first user is
considered as the admin.
- see mail "user ID change" on April, 15
+ fix call to chown (combination of -m and -u/-g)
+ add tests
- passwd:
- check combination of options (e.g. -u/-l)
- when -u refuse to unlock because it would create an empty password, it
should not display "Password changed."
exit instead?
- newgrp: check the USE_PAM section.
- pwck
- Add check to move passwd passwords to shadow if there is a shadow
entry (with a password).
- Add check to move passwd passwords to shadow if there is a shadow
file.
- Support an alternative /etc/tcb directory as second parameter.
- add options -g / -G to specify alternative group / gshadow files
- su
- add a login.defs configuration parameter to add variables to keep in
the environment with "su -l" (TERM/TERMCOLOR/...)
- vipw
- set ACLs and XATTRs on the temporary file (and backups?)
- vipw + selinux -> use lib/selinux.c

View File

@@ -1,9 +1,21 @@
#! /bin/sh
autoreconf -v -f --install || exit 1
autoreconf -v -f --install "$(dirname "$0")" || exit 1
./configure \
CFLAGS="-O2 -Wall" \
CFLAGS="-O2"
CFLAGS="$CFLAGS -Wall"
CFLAGS="$CFLAGS -Wextra"
CFLAGS="$CFLAGS -Werror=implicit-function-declaration"
CFLAGS="$CFLAGS -Werror=implicit-int"
CFLAGS="$CFLAGS -Werror=incompatible-pointer-types"
CFLAGS="$CFLAGS -Werror=int-conversion"
CFLAGS="$CFLAGS -Wno-expansion-to-defined"
CFLAGS="$CFLAGS -Wno-unknown-attributes"
CFLAGS="$CFLAGS -Wno-unknown-warning-option"
"$(dirname "$0")"/configure \
CFLAGS="$CFLAGS" \
--enable-lastlog \
--enable-man \
--enable-maintainer-mode \
--enable-shared \

View File

@@ -1,12 +1,12 @@
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
m4_define([libsubid_abi_major], 4)
m4_define([libsubid_abi_major], 5)
m4_define([libsubid_abi_minor], 0)
m4_define([libsubid_abi_micro], 0)
m4_define([libsubid_abi], [libsubid_abi_major.libsubid_abi_minor.libsubid_abi_micro])
AC_INIT([shadow], [4.14.0-rc1], [pkg-shadow-devel@lists.alioth.debian.org], [],
AC_INIT([shadow], [4.17.0], [pkg-shadow-devel@lists.alioth.debian.org], [],
[https://github.com/shadow-maint/shadow])
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects tar-pax])
AC_CONFIG_MACRO_DIRS([m4])
AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([config.h])
@@ -32,6 +32,7 @@ AC_PROG_CC
AC_PROG_LN_S
AC_PROG_YACC
LT_INIT
LT_LIB_DLLOAD
dnl Checks for libraries.
@@ -47,8 +48,8 @@ AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])])
AC_CHECK_FUNCS(arc4random_buf futimes \
getentropy getrandom getspnam getusershell \
initgroups lckpwdf lutimes mempcpy \
setgroups updwtmp updwtmpx innetgr \
initgroups lckpwdf lutimes \
setgroups updwtmpx innetgr \
getspnam_r \
rpmatch \
memset_explicit explicit_bzero stpecpy stpeprintf)
@@ -56,17 +57,13 @@ AC_SYS_LARGEFILE
dnl Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_MEMBERS([struct utmp.ut_type,
struct utmp.ut_id,
struct utmp.ut_name,
struct utmp.ut_user,
struct utmp.ut_host,
struct utmp.ut_syslen,
struct utmp.ut_addr,
struct utmp.ut_addr_v6,
struct utmp.ut_time,
struct utmp.ut_xtime,
struct utmp.ut_tv],,,[[#include <utmp.h>]])
AC_CHECK_MEMBERS([struct utmpx.ut_name,
struct utmpx.ut_host,
struct utmpx.ut_syslen,
struct utmpx.ut_addr,
struct utmpx.ut_addr_v6,
struct utmpx.ut_time,
struct utmpx.ut_xtime],,,[[#include <utmpx.h>]])
dnl Checks for library functions.
AC_TYPE_GETGROUPS
@@ -162,13 +159,6 @@ fi])
AC_DEFINE_UNQUOTED(PASSWD_PROGRAM, "$shadow_cv_passwd_dir/passwd",
[Path to passwd program.])
dnl XXX - quick hack, should disappear before anyone notices :).
dnl XXX - I just read the above message :).
if test "$ac_cv_func_ruserok" = "yes"; then
AC_DEFINE(RLOGIN, 1, [Define if login should support the -r flag for rlogind.])
AC_DEFINE(RUSEROK, 0, [Define to the ruserok() "success" return value (0 or 1).])
fi
AC_ARG_ENABLE(shadowgrp,
[AS_HELP_STRING([--enable-shadowgrp], [enable shadow group support @<:@default=yes@:>@])],
[case "${enableval}" in
@@ -243,9 +233,6 @@ AC_ARG_WITH(skey,
AC_ARG_WITH(tcb,
[AS_HELP_STRING([--with-tcb], [use tcb support (incomplete) @<:@default=yes if found@:>@])],
[with_tcb=$withval], [with_tcb=maybe])
AC_ARG_WITH(libcrack,
[AS_HELP_STRING([--with-libcrack], [use libcrack @<:@default=no@:>@])],
[with_libcrack=$withval], [with_libcrack=no])
AC_ARG_WITH(sha-crypt,
[AS_HELP_STRING([--with-sha-crypt], [allow the SHA256 and SHA512 password encryption algorithms @<:@default=yes@:>@])],
[with_sha_crypt=$withval], [with_sha_crypt=yes])
@@ -267,6 +254,9 @@ AC_ARG_WITH(group-name-max-length,
AC_ARG_WITH(su,
[AS_HELP_STRING([--with-su], [build and install su program and man page @<:@default=yes@:>@])],
[with_su=$withval], [with_su=yes])
AC_ARG_WITH(libbsd,
[AS_HELP_STRING([--with-libbsd], [use libbsd support @<:@default=yes if found@:>@])],
[with_libbsd=$withval], [with_libbsd=yes])
if test "$with_group_name_max_length" = "no" ; then
with_group_name_max_length=0
@@ -277,6 +267,7 @@ AC_DEFINE_UNQUOTED(GROUP_NAME_MAX_LENGTH, $with_group_name_max_length, [max grou
AC_SUBST(GROUP_NAME_MAX_LENGTH)
GROUP_NAME_MAX_LENGTH="$with_group_name_max_length"
AM_CONDITIONAL(USE_SHA_CRYPT, test "x$with_sha_crypt" = "xyes")
if test "$with_sha_crypt" = "yes"; then
AC_DEFINE(USE_SHA_CRYPT, 1, [Define to allow the SHA256 and SHA512 password encryption algorithms])
@@ -313,6 +304,10 @@ dnl needed (Linux glibc, Irix), but still link it if needed (Solaris).
AC_SEARCH_LIBS(gethostbyname, nsl)
PKG_CHECK_MODULES([CMOCKA], [cmocka], [have_cmocka="yes"],
[AC_MSG_WARN([libcmocka not found, cmocka tests will not be built])])
AM_CONDITIONAL([HAVE_CMOCKA], [test x$have_cmocka = xyes])
AC_CHECK_LIB([econf],[econf_readDirs],[LIBECONF="-leconf"],[LIBECONF=""])
if test -n "$LIBECONF"; then
AC_DEFINE_UNQUOTED([VENDORDIR], ["$enable_vendordir"],
@@ -412,20 +407,27 @@ AC_SUBST(LIYESCRYPT)
AC_CHECK_LIB(crypt, crypt, [LIYESCRYPT=-lcrypt],
[AC_MSG_ERROR([crypt() not found])])
AC_SEARCH_LIBS([readpassphrase], [bsd], [], [
AC_MSG_ERROR([readpassphrase() is missing, either from libc or libbsd])
])
AS_IF([test "$ac_cv_search_readpassphrase" = "-lbsd"], [
PKG_CHECK_MODULES([LIBBSD], [libbsd-overlay])
])
dnl Make sure either the libc or libbsd provide the header.
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
AC_CHECK_HEADERS([readpassphrase.h])
AS_IF([test "$ac_cv_header_readpassphrase_h" != "yes"], [
AC_MSG_ERROR([readpassphrase.h is missing])
])
CFLAGS="$save_CFLAGS"
AC_SUBST(LIBBSD)
if test "$with_libbsd" != "no"; then
AC_SEARCH_LIBS([readpassphrase], [bsd], [], [
AC_MSG_ERROR([readpassphrase() is missing, either from libc or libbsd])
])
AS_IF([test "$ac_cv_search_readpassphrase" = "-lbsd"], [
PKG_CHECK_MODULES([LIBBSD], [libbsd-overlay])
])
dnl Make sure either the libc or libbsd provide the header.
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
AC_CHECK_HEADERS([readpassphrase.h])
AS_IF([test "$ac_cv_header_readpassphrase_h" != "yes"], [
AC_MSG_ERROR([readpassphrase.h is missing])
])
CFLAGS="$save_CFLAGS"
AC_DEFINE(WITH_LIBBSD, 1, [Build shadow with libbsd support])
else
AC_DEFINE(WITH_LIBBSD, 0, [Build shadow without libbsd support])
fi
AM_CONDITIONAL(WITH_LIBBSD, test x$with_libbsd = xyes)
AC_SUBST(LIBACL)
if test "$with_acl" != "no"; then
@@ -511,17 +513,6 @@ if test "$with_audit" != "no"; then
fi
fi
AC_SUBST(LIBCRACK)
if test "$with_libcrack" = "yes"; then
echo "checking cracklib flavour, don't be surprised by the results"
AC_CHECK_LIB(crack, FascistCheck,
[LIBCRACK=-lcrack AC_DEFINE(HAVE_LIBCRACK, 1, [Defined if you have libcrack.])])
AC_CHECK_LIB(crack, FascistHistory,
AC_DEFINE(HAVE_LIBCRACK_HIST, 1, [Defined if you have the ts&szs cracklib.]))
AC_CHECK_LIB(crack, FascistHistoryPw,
AC_DEFINE(HAVE_LIBCRACK_PW, 1, [Defined if it includes *Pw functions.]))
fi
if test "$with_btrfs" != "no"; then
AC_CHECK_HEADERS([sys/statfs.h linux/magic.h linux/btrfs_tree.h], \
[btrfs_headers="yes"], [btrfs_headers="no"])
@@ -698,7 +689,7 @@ AC_SUBST(LIBMD)
if test "$with_skey" = "yes"; then
AC_CHECK_LIB(md, MD5Init, [LIBMD=-lmd])
AC_CHECK_LIB(skey, skeychallenge, [LIBSKEY=-lskey],
[AC_MSG_ERROR([liskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2])])
[AC_MSG_ERROR([libskey missing. You can download S/Key source code from http://rsync1.it.gentoo.org/gentoo/distfiles/skey-1.1.5.tar.bz2])])
AC_DEFINE(SKEY, 1, [Define to support S/Key logins.])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
@@ -742,7 +733,6 @@ AC_CONFIG_FILES([
man/uk/Makefile
man/zh_CN/Makefile
man/zh_TW/Makefile
libmisc/Makefile
lib/Makefile
libsubid/Makefile
libsubid/subid.h
@@ -750,7 +740,8 @@ AC_CONFIG_FILES([
contrib/Makefile
etc/Makefile
etc/pam.d/Makefile
shadow.spec
etc/shadow-maint/Makefile
tests/unit/Makefile
])
AC_OUTPUT
@@ -758,7 +749,6 @@ echo
echo "shadow will be compiled with the following features:"
echo
echo " auditing support: $with_audit"
echo " CrackLib support: $with_libcrack"
echo " PAM support: $with_libpam"
if test "$with_libpam" = "yes"; then
echo " suid account management tools: $enable_acct_tools_setuid"

View File

@@ -1,6 +1,4 @@
# This is a dummy Makefile.am to get automake work flawlessly,
# and also cooperate to make a distribution for `make dist'
EXTRA_DIST = README adduser.c adduser.sh adduser2.sh \
atudel groupmems.shar shadow-anonftp.patch \
udbachk.tgz
EXTRA_DIST = README adduser.c adduser.sh adduser2.sh

View File

@@ -2,9 +2,6 @@ People keep sending various adduser programs and scripts... They are
all in this directory. I haven't tested them, use at your own risk.
Anyway, the best one I've seen so far is adduser-3.x from Debian.
atudel is a perl script to remove at jobs owned by the specified user
(atrm in at-2.9 for Linux can't do that).
udbachk.tgz is a passwd/group/shadow file integrity checker.
--marekm

View File

@@ -118,6 +118,9 @@
#include <sys/stat.h>
#include <syslog.h>
#include "string/strcmp/streq.h"
#define IMMEDIATE_CHANGE /* Expire newly created password, must be changed
* immediately upon next login */
#define HAVE_QUOTAS /* Obvious */
@@ -291,12 +294,10 @@ main (void)
printf ("Home Directory [%s/%s]: ", DEFAULT_HOME, usrname);
fflush (stdout);
safeget (dir, sizeof (dir));
if (!strlen (dir))
{ /* hit return */
sprintf (dir, "%s/%s", DEFAULT_HOME, usrname);
}
if (!strlen(dir)) /* hit return */
sprintf(dir, "%s/%s", DEFAULT_HOME, usrname);
else if (dir[strlen (dir) - 1] == '/')
sprintf (dir+strlen(dir), "%s", usrname);
strcat(dir, usrname);
}
else
{
@@ -308,7 +309,7 @@ main (void)
fflush (stdout);
safeget (shell, sizeof (shell));
if (!strlen (shell))
sprintf (shell, "%s", DEFAULT_SHELL);
strcpy(shell, DEFAULT_SHELL);
else
{
char *sh;
@@ -316,7 +317,7 @@ main (void)
#ifdef HAVE_GETUSERSHELL
setusershell ();
while ((sh = getusershell ()) != NULL)
if (!strcmp (shell, sh))
if (streq(shell, sh))
ok = 1;
endusershell ();
#endif
@@ -327,7 +328,7 @@ main (void)
else
{
printf ("Shell NOT in /etc/shells, DEFAULT used\n");
sprintf (shell, "%s", DEFAULT_SHELL);
strcpy(shell, DEFAULT_SHELL);
}
}
}
@@ -491,12 +492,12 @@ safeget (char *buf, int maxlen)
bad = (!isalnum (c) && (c != '_') && (c != ' '));
*(buf++) = c;
}
*buf = '\0';
stpcpy(buf, "");
if (bad)
{
printf ("\nString contained banned character. Please stick to alphanumerics.\n");
*bstart = '\0';
stpcpy(bstart, "");
}
}

View File

@@ -1,58 +0,0 @@
#!/usr/bin/perl
#
# SPDX-FileCopyrightText: 1996 Brian R. Gaeke
# SPDX-License-Identifier: BSD-4-Clause
#
# Additionally:
#
# This software is provided without support and without any obligation
# on the part of Brian R. Gaeke to assist in its use, correction,
# modification or enhancement.
#
#######################################################################
#
# this is atudel, version 2, by Brian R. Gaeke <brg@dgate.org>
#
require "getopts.pl";
&Getopts('v');
$username = shift(@ARGV);
&usage unless $username;
sub usage
{
print STDERR "atudel - remove all at jobs owned by a user\n";
print STDERR "usage: $0 [-v] username\n";
exit(1);
}
# odd. unless getpwnam($uname) doesn't seem to work for $uname eq "root" on
# my linux system. but this does.
die "user $username does not exist; stopping"
unless defined(getpwnam($username));
print "searching for at jobs owned by user $username ..." if $opt_v;
chdir "/var/spool/atjobs" ||
die "can't chdir to /var/spool/atjobs: $!\nstopping";
opendir(DIR,".") || die "can't opendir(/var/spool/atjobs): $!\nstopping";
@files = grep(!/^\./,grep(-f,readdir(DIR)));
closedir DIR;
foreach $x (@files)
{
$owner = (getpwuid((stat($x))[4]))[0];
push(@nuke_bait,$x) if $owner eq $username;
}
if (@nuke_bait)
{
print "removed jobIDs: @{nuke_bait}.\n" if $opt_v;
unlink @nuke_bait;
}
elsif ($opt_v)
{
print "\n";
}
exit 0;

View File

@@ -1,465 +0,0 @@
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2000-05-25 14:41 CDT by <gk4@gnu.austin.ibm.com>.
# Source directory was `/home/gk4/src/groupmem'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1960 -rw-r--r-- Makefile
# 6348 -rw-r--r-- groupmems.c
# 3372 -rw------- groupmems.8
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh10937; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= Makefile ==============
if test -f 'Makefile' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'Makefile' '(file already exists)'
else
$echo 'x -' extracting 'Makefile' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
/*
# SPDX-FileCopyrightText: 2000, International Business Machines, Inc.
# SPDX-FileCopyrightText: 2000, George Kraft IV, gk4@us.ibm.com
# SPDX-License-Identifier: BSD-3-Clause
#
X
all: groupmems
X
groupmems: groupmems.c
X cc -g -o groupmems groupmems.c -L. -lshadow
X
install: groupmems
X -/usr/sbin/groupadd groups
X install -o root -g groups -m 4770 groupmems /usr/bin
X
install.man: groupmems.8
X install -o root -g root -m 644 groupmems.8 /usr/man/man8
X
SHAR_EOF
(set 20 00 05 25 14 40 28 'Makefile'; eval "$shar_touch") &&
chmod 0644 'Makefile' ||
$echo 'restore of' 'Makefile' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'Makefile:' 'MD5 check failed'
b46cf7ef8d59149093c011ced3f3103c Makefile
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
test 1960 -eq "$shar_count" ||
$echo 'Makefile:' 'original size' '1960,' 'current size' "$shar_count!"
fi
fi
# ============= groupmems.c ==============
if test -f 'groupmems.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'groupmems.c' '(file already exists)'
else
$echo 'x -' extracting 'groupmems.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'groupmems.c' &&
/*
X * SPDX-FileCopyrightText: 2000, International Business Machines, Inc.
X * SPDX-FileCopyrightText: 2000, George Kraft IV, gk4@us.ibm.com
X * SPDX-License-Identifier: BSD-3-Clause
X */
/*
**
** Utility "groupmem" adds and deletes members from a user's group.
**
** Setup (as "root"):
**
** groupadd -r groups
** chmod 2770 groupmems
** chown root.groups groupmems
** groupmems -g groups -a gk4
**
** Usage (as "gk4"):
**
** groupmems -a olive
** groupmems -a jordan
** groupmems -a meghan
** groupmems -a morgan
** groupmems -a jake
** groupmems -l
** groupmems -d jake
** groupmems -l
*/
X
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "defines.h"
#include "groupio.h"
X
/* Exit Status Values */
X
#define EXIT_SUCCESS 0 /* success */
#define EXIT_USAGE 1 /* invalid command syntax */
#define EXIT_GROUP_FILE 2 /* group file access problems */
#define EXIT_NOT_ROOT 3 /* not superuser */
#define EXIT_NOT_EROOT 4 /* not effective superuser */
#define EXIT_NOT_PRIMARY 5 /* not primary owner of group */
#define EXIT_NOT_MEMBER 6 /* member of group does not exist */
#define EXIT_MEMBER_EXISTS 7 /* member of group already exists */
X
#define TRUE 1
#define FALSE 0
X
/* Globals */
X
extern int optind;
extern char *optarg;
static char *adduser = NULL;
static char *deluser = NULL;
static char *thisgroup = NULL;
static int purge = FALSE;
static int list = FALSE;
static int exclusive = 0;
X
static int isroot(void) {
X return getuid() ? FALSE : TRUE;
}
X
static int isgroup(void) {
X gid_t g = getgid();
X struct group *grp = getgrgid(g);
X
X return TRUE;
}
X
static char *whoami(void) {
X struct group *grp = getgrgid(getgid());
X struct passwd *usr = getpwuid(getuid());
X
X if (0 == strcmp(usr->pw_name, grp->gr_name)) {
X return (char *)strdup(usr->pw_name);
X } else {
X return NULL;
X }
}
X
static void
addtogroup(char *user, char **members) {
X int i;
X char **pmembers;
X
X for (i = 0; NULL != members[i]; i++ ) {
X if (0 == strcmp(user, members[i])) {
X fprintf(stderr, "Member already exists\n");
X exit(EXIT_MEMBER_EXISTS);
X }
X }
X
X if (0 == i) {
X pmembers = (char **)calloc(2, sizeof(char *));
X } else {
X pmembers = (char **)realloc(members, sizeof(char *)*(i+1));
X }
X
X *members = *pmembers;
X members[i] = user;
X members[i+1] = NULL;
}
X
static void
rmfromgroup(char *user, char **members) {
X int i;
X int found = FALSE;
X
X i = 0;
X while (!found && NULL != members[i]) {
X if (0 == strcmp(user, members[i])) {
X found = TRUE;
X } else {
X i++;
X }
X }
X
X while (found && NULL != members[i]) {
X members[i] = members[++i];
X }
X
X if (!found) {
X fprintf(stderr, "Member to remove could not be found\n");
X exit(EXIT_NOT_MEMBER);
X }
}
X
static void
nomembers(char **members) {
X int i;
X
X for (i = 0; NULL != members[i]; i++ ) {
X members[i] = NULL;
X }
}
X
static void
members(char **members) {
X int i;
X
X for (i = 0; NULL != members[i]; i++ ) {
X printf("%s ", members[i]);
X
X if (NULL == members[i+1]) {
X printf("\n");
X } else {
X printf(" ");
X }
X }
}
X
static void usage(void) {
X fprintf(stderr, "usage: groupmems -a username | -d username | -D | -l [-g groupname]\n");
X exit(EXIT_USAGE);
}
X
main(int argc, char **argv) {
X int arg, i;
X char *name;
X struct group *grp;
X
X while ((arg = getopt(argc, argv, "a:d:g:Dl")) != EOF) {
X switch (arg) {
X case 'a':
X adduser = strdup(optarg);
X ++exclusive;
X break;
X case 'd':
X deluser = strdup(optarg);
X ++exclusive;
X break;
X case 'g':
X thisgroup = strdup(optarg);
X break;
X case 'D':
X purge = TRUE;
X ++exclusive;
X break;
X case 'l':
X list = TRUE;
X ++exclusive;
X break;
X default:
X usage();
X }
X }
X
X if (exclusive > 1 || optind < argc) {
X usage();
X }
X
X if (!isroot() && NULL != thisgroup) {
X fprintf(stderr, "Only root can add members to different groups\n");
X exit(EXIT_NOT_ROOT);
X } else if (isroot() && NULL != thisgroup) {
X name = thisgroup;
X } else if (!isgroup()) {
X fprintf(stderr, "Group access is required\n");
X exit(EXIT_NOT_EROOT);
X } else if (NULL == (name = whoami())) {
X fprintf(stderr, "Not primary owner of current group\n");
X exit(EXIT_NOT_PRIMARY);
X }
X
X if (!gr_lock()) {
X fprintf(stderr, "Unable to lock group file\n");
X exit(EXIT_GROUP_FILE);
X }
X
X if (!gr_open(O_RDWR)) {
X fprintf(stderr, "Unable to open group file\n");
X exit(EXIT_GROUP_FILE);
X }
X
X grp = (struct group *)gr_locate(name);
X
X if (NULL != adduser) {
X addtogroup(adduser, grp->gr_mem);
X gr_update(grp);
X } else if (NULL != deluser) {
X rmfromgroup(deluser, grp->gr_mem);
X gr_update(grp);
X } else if (purge) {
X nomembers(grp->gr_mem);
X gr_update(grp);
X } else if (list) {
X members(grp->gr_mem);
X }
X
X if (!gr_close()) {
X fprintf(stderr, "Cannot close group file\n");
X exit(EXIT_GROUP_FILE);
X }
X
X gr_unlock();
X
X exit(EXIT_SUCCESS);
}
X
/* EOF */
SHAR_EOF
(set 20 00 05 25 14 36 38 'groupmems.c'; eval "$shar_touch") &&
chmod 0644 'groupmems.c' ||
$echo 'restore of' 'groupmems.c' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'groupmems.c:' 'MD5 check failed'
f0dd68f8d762d89d24d3ce1f4141f981 groupmems.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'groupmems.c'`"
test 6348 -eq "$shar_count" ||
$echo 'groupmems.c:' 'original size' '6348,' 'current size' "$shar_count!"
fi
fi
# ============= groupmems.8 ==============
if test -f 'groupmems.8' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'groupmems.8' '(file already exists)'
else
$echo 'x -' extracting 'groupmems.8' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'groupmems.8' &&
X.\"
X.\" SPDX-FileCopyrightText: 2000, International Business Machines, Inc.
X.\" SPDX-FileCopyrightText: 2000, George Kraft IV, gk4@us.ibm.com
X.\" SPDX-License-Identifier: BSD-3-Clause
X.\"
X.\" $Id$
X.\"
X.TH GROUPMEMS 8
X.SH NAME
groupmems \- Administer members of a user's primary group
X.SH SYNOPSIS
X.B groupmems
\fB-a\fI user_name \fR |
\fB-d\fI user_name \fR |
\fB-l\fR |
\fB-D\fR |
[\fB-g\fI group_name \fR]
X.SH DESCRIPTION
The \fBgroupmems\fR utility allows a user to administer their own
group membership list without the requirement of superuser privileges.
The \fBgroupmems\fR utility is for systems that configure its users to
be in their own name sake primary group (i.e., guest / guest).
X.P
Only the superuser, as administrator, can use \fBgroupmems\fR to alter
the memberships of other groups.
X.IP "\fB-a \fIuser_name\fR"
Add a new user to the group membership list.
X.IP "\fB-d \fIuser_name\fR"
Delete a user from the group membership list.
X.IP "\fB-l\fR"
List the group membership list.
X.IP "\fB-D\fR"
Delete all users from the group membership list.
X.IP "\fB-g \fIgroup_name\fR"
The superuser can specify which group membership list to modify.
X.SH SETUP
The \fBgroupmems\fR executable should be in mode \fB2770\fR as user \fBroot\fR
and in group \fBgroups\fR. The system administrator can add users to
group groups to allow or disallow them using the \fBgroupmems\fR utility
to manager their own group membership list.
X.P
X $ groupadd -r groups
X.br
X $ chmod 2770 groupmems
X.br
X $ chown root.groups groupmems
X.br
X $ groupmems -g groups -a gk4
X.SH FILES
/etc/group
X.br
/etc/gshadow
X.SH SEE ALSO
X.BR chfn (1),
X.BR chsh (1),
X.BR useradd (8),
X.BR userdel (8),
X.BR usermod (8),
X.BR passwd (1),
X.BR groupadd (8),
X.BR groupdel (8)
X.SH AUTHOR
George Kraft IV (gk4@us.ibm.com)
X.\" EOF
SHAR_EOF
(set 20 00 05 25 14 38 23 'groupmems.8'; eval "$shar_touch") &&
chmod 0600 'groupmems.8' ||
$echo 'restore of' 'groupmems.8' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'groupmems.8:' 'MD5 check failed'
181e6cd3a3c9d3df320197fa2cde2b4a groupmems.8
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'groupmems.8'`"
test 3372 -eq "$shar_count" ||
$echo 'groupmems.8:' 'original size' '3372,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh10937
exit 0

View File

@@ -1,147 +0,0 @@
Hello Marek,
I have created a diffile against the 980403 release that adds
functionality to newusers for automatic handling of users with only
anonymous ftp login (using the guestgroup feature in ftpaccess, which
means that the users home directory looks like '/home/user/./'). It also
adds a commandline argument to specify an initial directory structure
for such users, with a tarball normally containing the bin,lib,etc
directories used in the chrooted environment.
I am using it to automatically create chunks of users with only ftp
access for a webserver.
I have tried to follow your coding standards and I believe it is bug
free but.. well, who knows. :) It's not much code however.
I hope you find it useful. Do what you like with it, feel free to ask if
anything is unclear.
Best rgds,
Calle Karlsson
ckn@kash.se
diff -uNr shadow-980403.orig/src/newusers.c shadow-980403/src/newusers.c
--- shadow-980403.orig/src/newusers.c Fri Jan 30 00:22:43 1998
+++ shadow-980403/src/newusers.c Fri Apr 17 16:55:33 1998
@@ -76,11 +76,35 @@
static void
usage(void)
{
- fprintf(stderr, "Usage: %s [ input ]\n", Prog);
+ fprintf (stderr, "Usage: %s [-p prototype tarfile] [ input ]\n", Prog);
+ fprintf (stderr, "The prototype tarfile is only used for users\n");
+ fprintf (stderr, "marked as anonymous ftp users. It must be a full pathname.\n");
exit(1);
}
/*
+ * createuserdir - create a directory and chmod it
+ */
+
+static int
+createuserdir (char * dir, int uid, int gid, int line)
+{
+ if (mkdir (dir, 0777 & ~getdef_num("UMASK", 077))) {
+ fprintf (stderr, "%s: line %d: mkdir %s failed\n",
+ Prog, line, dir);
+ return -1;
+ }
+
+ if (chown (dir, uid, gid)) {
+ fprintf (stderr, "%s: line %d: chown %s failed\n",
+ Prog, line, dir);
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
* add_group - create a new group or add a user to an existing group
*/
@@ -328,6 +352,8 @@
main(int argc, char **argv)
{
char buf[BUFSIZ];
+ char anonproto[BUFSIZ];
+ int flag;
char *fields[8];
int nfields;
char *cp;
@@ -340,12 +366,23 @@
Prog = Basename(argv[0]);
- if (argc > 1 && argv[1][0] == '-')
- usage ();
+ * anonproto = '\0';
+
+ while ((flag = getopt (argc, argv, "p:h")) != EOF) {
+ switch (flag) {
+ case 'p':
+ STRFCPY(anonproto, optarg);
+ break;
+ case 'h':
+ default:
+ usage ();
+ break;
+ }
+ }
- if (argc == 2) {
- if (! freopen (argv[1], "r", stdin)) {
- snprintf(buf, sizeof buf, "%s: %s", Prog, argv[1]);
+ if (optind < argc) {
+ if (! freopen (argv[optind], "r", stdin)) {
+ snprintf(buf, sizeof buf, "%s: %s", Prog, argv[optind]);
perror (buf);
exit (1);
}
@@ -499,15 +536,36 @@
if (fields[6][0])
newpw.pw_shell = fields[6];
- if (newpw.pw_dir[0] && access(newpw.pw_dir, F_OK)) {
- if (mkdir (newpw.pw_dir,
- 0777 & ~getdef_num("UMASK", 077)))
- fprintf (stderr, "%s: line %d: mkdir failed\n",
- Prog, line);
- else if (chown (newpw.pw_dir,
- newpw.pw_uid, newpw.pw_gid))
- fprintf (stderr, "%s: line %d: chown failed\n",
- Prog, line);
+ if (newpw.pw_dir[0]) {
+ char * userdir = strdup (newpw.pw_dir);
+ char * anonpart;
+ int rc;
+
+ if ((anonpart = strstr (userdir, "/./"))) {
+ * anonpart = '\0';
+ anonpart += 2;
+ }
+
+ if (access(userdir, F_OK))
+ rc = createuserdir (userdir, newpw.pw_uid, newpw.pw_gid, line);
+ else
+ rc = 0;
+
+ if (rc == 0 && anonpart) {
+ if (* anonproto) {
+ char cmdbuf [BUFSIZ];
+ snprintf(cmdbuf, sizeof cmdbuf,
+ "cd %s; tar xf %s",
+ userdir, anonproto);
+ system (cmdbuf);
+ }
+ if (strlen (anonpart) > 1) {
+ strcat (userdir, anonpart);
+ if (access (userdir, F_OK))
+ createuserdir (userdir, newpw.pw_uid, newpw.pw_gid, line);
+ }
+ }
+ free (userdir);
}
/*

Binary file not shown.

View File

@@ -471,12 +471,12 @@
The Shadow Suite contains replacement programs for:
su, login, passwd, newgrp, chfn, chsh, and id
su, login, passwd, newgrp, chfn, chsh
The package also contains the new programs:
chage, newusers, dpasswd, gpasswd, useradd, userdel, usermod,
groupadd, groupdel, groupmod, groups, pwck, grpck, lastlog, pwconv,
groupadd, groupdel, groupmod, pwck, grpck, lastlog, pwconv,
and pwunconv
Additionally, the library: libshadow.a is included for writing and/or
@@ -586,8 +586,6 @@
· /usr/bin/chsh
· /usr/bin/id
The BETA package has a save target in the Makefile, but it's commented
out because different distributions place the programs in different
places.
@@ -637,8 +635,6 @@
· /usr/man/man1/chsh.1.gz
· /usr/man/man1/id.1.gz
· /usr/man/man1/login.1.gz
· /usr/man/man1/passwd.1.gz
@@ -1377,7 +1373,7 @@
users or changing the group password, the /etc/gshadow file will be
changed.
The programs groups, groupadd, groupmod, and groupdel are provided as
The programs groupadd, groupmod, and groupdel are provided as
part of the Shadow Suite to modify groups.
The format of the /etc/group file is as follows:

View File

@@ -1,5 +1,4 @@
# This is a dummy Makefile.am to get automake work flawlessly,
# and also cooperate to make a distribution for `make dist'
EXTRA_DIST = HOWTO README.limits \
README.platforms WISHLIST console.c.spec.txt cracklib26.diff
EXTRA_DIST = HOWTO README.limits

View File

@@ -1,33 +0,0 @@
# $Id$
#
# This is the current (still incomplete) list of platforms this
# package has been verified to work on. Additions (preferably
# in the format as described below) are welcome. Thanks!
#
# V: last version reported to work
# H: host type
# L: Linux libc version
# D: Linux distribution, or other OS name and version
# C: changes (if any)
# R: reported by
V: 980529
H: sparc-unknown-linux-gnu
L: glibc-2.0.7
D: Ultrapenguin-1.0.9
C: had to explicitly disable desrpc.
R: Bjorn Christianson <bjorn@cascade.psychology.mcmaster.ca>
V: 980724
H: i486-pc-linux-gnulibc1
L: libc-5.4.33
D: Debian-1.3.1.r6
C: none (use dpkg-buildpackage)
R: Marek Michalkiewicz <marekm@linux.org.pl>
V: current
H: i686-pc-linux-gnu
L: glibc-2.0.7.19981211
D: Debian-2.1
C: none (use dpkg-buildpackage)
R: Marek Michalkiewicz <marekm@linux.org.pl>

View File

@@ -1,38 +0,0 @@
$Id$
This is my wishlist for the shadow suite, in no particular order. Feel
free to do anything from this list and mail me the diffs :-).
Patches in diff -u format, against the latest version (sometimes in the
"beta" directory) are preferred and make my job easier. Please, no
MIME, base64, quoted-printable, or HTML. For very big patches, or if
your mailer can corrupt them, please use gzip and uuencode. Thanks!
New ideas to add to this list are welcome, too. --marekm
- fix all the bugs, of course
- implement "su only" accounts (no logins, only su from other account)
- rewrite getdef.c to be more general? (no hardcoded names)
- patch for rlogind/telnetd to create utmp entry and fill in ut_addr
- option to specify encrypted password in passwd (for yppasswdd, so it
doesn't need to know about shadow/non-shadow); should probably use a pipe
(less insecure than command line arguments)
- add support for changing NIS passwords
- add option to check passwords by piping them to external programs
- add functionality of the contrib/rpasswd.c wrapper to passwd
- option to generate pronounceable passwords (like on SCO), external program?
- poppassd (remote password change for eudora etc.)
- add support for passwd/shadow db files (glibc)
- vipw: check password files for errors after editing
- add "maximum time users allowed to stay logged in" limit option to logoutd
- handle quotes in /etc/environment like the shell does (but sshd doesn't...)
- better OPIE support (report number of logins left, etc.)
- new option for /etc/suauth: don't load user's environment (force "su -")
suggested by Ulisses Alonso Camaro
- find out why recent releases won't compile on Solaris
- newusers should be able to copy /etc/skel to the new home directory
(like useradd)
- add directories where other packages can add hooks for package-specific
per-user configuration, to be executed with run-parts. Some hooks should
be executed at package install time for existing users, likewise for
package removal and possibly modification. (Debian Bug#36019)

View File

@@ -1,36 +0,0 @@
$Id$
Specification for console.c source file --
input values --
tty -- character pointer to device name with leading "/dev/"
removed.
return values --
0 -- false
1 -- true
int console (char * tty)
if "CONSOLE" string value is not present in login.defs
return true
if the first character of "CONSOLE" string value is not "/"
treat the string as a ":" delimited list of device
names and search for the value of tty in that
tokenized list.
if a match is found
return true
return false
if the file named by "CONSOLE" cannot be opened
return true
scan the file looking for a match between the input line
and the value of tty
if a match is found
return true
return false

View File

@@ -62,9 +62,11 @@ You can either generate a single image by running the following command from
the root folder of the project (i.e. Alpine):
```
docker build -f share/containers/alpine.dockerfile . --output build-out/alpine
ansible-playbook share/ansible/playbook.yml -i share/ansible/inventory.ini -e 'distribution=alpine'
```
**Note**: you'll need to install ansible to run this automation.
Or generate all of the images with the `container-build.sh` script, as if you
were running some of the CI checks locally:

View File

@@ -72,6 +72,6 @@ understand the project's development model:
* [Build & install](build_install.md)
* [Coding style](coding_style.md)
* [Tests](tests.md)
* [Continuous Integration](CI.md)
* [Continuous Integration](ci.md)
* [Releases](releases.md)
* [License](license.md)

View File

@@ -1,6 +1,22 @@
# Tests
Currently, shadow only provides system tests.
Currently, shadow provides unit and system tests.
## Unit tests
Unit testing is provided by the [cmocka](https://cmocka.org/) framework. It's
recommended to read the
[basics](https://cmocka.org/talks/cmocka_unit_testing_and_mocking.pdf) and
[API](https://api.cmocka.org/) before writing any test case.
In addition, you can check [test_logind.c](../../tests/unit/test_logind.c) to
get a general idea on how to implement unit tests for shadow using cmocka.
You can execute unit tests by running:
```
make check
```
## System tests

View File

@@ -1,340 +0,0 @@
diff -ur orig/cracklib26_small/cracklib/fascist.c cracklib26_small/cracklib/fascist.c
--- orig/cracklib26_small/cracklib/fascist.c Mon Dec 15 02:56:55 1997
+++ cracklib26_small/cracklib/fascist.c Sat Apr 4 22:14:45 1998
@@ -12,6 +12,7 @@
#include <ctype.h>
#include <sys/types.h>
#include <pwd.h>
+#include <string.h>
#define ISSKIP(x) (isspace(x) || ispunct(x))
@@ -460,28 +461,27 @@
}
char *
-FascistGecos(password, uid)
+FascistGecosPw(password, pwd)
char *password;
- int uid;
+ struct passwd *pwd;
{
int i;
int j;
int wc;
char *ptr;
- struct passwd *pwp;
char gbuffer[STRINGSIZE];
char tbuffer[STRINGSIZE];
char *uwords[STRINGSIZE];
char longbuffer[STRINGSIZE * 2];
- if (!(pwp = getpwuid(uid)))
+ if (!pwd)
{
return ("you are not registered in the password file");
}
/* lets get really paranoid and assume a dangerously long gecos entry */
- strncpy(tbuffer, pwp->pw_name, STRINGSIZE);
+ strncpy(tbuffer, pwd->pw_name, STRINGSIZE);
tbuffer[STRINGSIZE-1] = '\0';
if (GTry(tbuffer, password))
{
@@ -490,12 +490,13 @@
/* it never used to be that you got passwd strings > 1024 chars, but now... */
- strncpy(tbuffer, pwp->pw_gecos, STRINGSIZE);
+ strncpy(tbuffer, pwd->pw_gecos, STRINGSIZE);
tbuffer[STRINGSIZE-1] = '\0';
strcpy(gbuffer, Lowercase(tbuffer));
wc = 0;
ptr = gbuffer;
+ uwords[0] = (char *) 0;
while (*ptr)
{
@@ -530,6 +531,8 @@
*(ptr++) = '\0';
}
}
+ if (!uwords[0])
+ return ((char *) 0); /* empty gecos */
#ifdef DEBUG
for (i = 0; uwords[i]; i++)
{
@@ -586,9 +589,10 @@
}
char *
-FascistLook(pwp, instring)
+FascistLookPw(pwp, instring, pwd)
PWDICT *pwp;
char *instring;
+ struct passwd *pwd;
{
int i;
char *ptr;
@@ -667,7 +671,7 @@
return ("it looks like a National Insurance number.");
}
- if (ptr = FascistGecos(password, getuid()))
+ if (ptr = FascistGecosPw(password, pwd ? pwd : getpwuid(getuid())))
{
return (ptr);
}
@@ -715,9 +719,10 @@
}
char *
-FascistCheck(password, path)
+FascistCheckPw(password, path, pwd)
char *password;
char *path;
+ struct passwd *pwd;
{
static char lastpath[STRINGSIZE];
static PWDICT *pwp;
@@ -750,5 +755,29 @@
strncpy(lastpath, path, STRINGSIZE);
}
- return (FascistLook(pwp, pwtrunced));
+ return (FascistLookPw(pwp, pwtrunced, pwd));
+}
+
+char *
+FascistGecos(password, uid)
+ char *password;
+ int uid;
+{
+ return (FascistGecosPw(password, getpwuid(uid)));
+}
+
+char *
+FascistLook(pwp, instring)
+ PWDICT *pwp;
+ char *instring;
+{
+ return (FascistLookPw(pwp, instring, (char *) 0));
+}
+
+char *
+FascistCheck(password, path)
+ char *password;
+ char *path;
+{
+ return (FascistCheckPw(password, path, (char *) 0));
}
diff -ur orig/cracklib26_small/cracklib/packer.h cracklib26_small/cracklib/packer.h
--- orig/cracklib26_small/cracklib/packer.h Mon Dec 15 00:09:30 1997
+++ cracklib26_small/cracklib/packer.h Sat Jan 10 22:13:46 1998
@@ -34,6 +34,7 @@
FILE *dfp;
FILE *wfp;
+ int canfree;
int32 flags;
#define PFOR_WRITE 0x0001
#define PFOR_FLUSH 0x0002
diff -ur orig/cracklib26_small/cracklib/packlib.c cracklib26_small/cracklib/packlib.c
--- orig/cracklib26_small/cracklib/packlib.c Fri Jul 9 22:22:58 1993
+++ cracklib26_small/cracklib/packlib.c Sat Jan 10 22:28:49 1998
@@ -16,7 +16,7 @@
char *mode;
{
int32 i;
- static PWDICT pdesc;
+ PWDICT *pdesc;
char iname[STRINGSIZE];
char dname[STRINGSIZE];
char wname[STRINGSIZE];
@@ -25,92 +25,94 @@
FILE *ifp;
FILE *wfp;
- if (pdesc.header.pih_magic == PIH_MAGIC)
- {
- fprintf(stderr, "%s: another dictionary already open\n", prefix);
+ if ((pdesc = (PWDICT *) malloc(sizeof(PWDICT))) == 0)
return ((PWDICT *) 0);
- }
- memset(&pdesc, '\0', sizeof(pdesc));
+ memset(pdesc, '\0', sizeof(*pdesc));
sprintf(iname, "%s.pwi", prefix);
sprintf(dname, "%s.pwd", prefix);
sprintf(wname, "%s.hwm", prefix);
- if (!(pdesc.dfp = fopen(dname, mode)))
+ if (!(pdesc->dfp = fopen(dname, mode)))
{
perror(dname);
+ free(pdesc);
return ((PWDICT *) 0);
}
- if (!(pdesc.ifp = fopen(iname, mode)))
+ if (!(pdesc->ifp = fopen(iname, mode)))
{
- fclose(pdesc.dfp);
+ fclose(pdesc->dfp);
perror(iname);
+ free(pdesc);
return ((PWDICT *) 0);
}
- if (pdesc.wfp = fopen(wname, mode))
+ if (pdesc->wfp = fopen(wname, mode))
{
- pdesc.flags |= PFOR_USEHWMS;
+ pdesc->flags |= PFOR_USEHWMS;
}
- ifp = pdesc.ifp;
- dfp = pdesc.dfp;
- wfp = pdesc.wfp;
+ ifp = pdesc->ifp;
+ dfp = pdesc->dfp;
+ wfp = pdesc->wfp;
if (mode[0] == 'w')
{
- pdesc.flags |= PFOR_WRITE;
- pdesc.header.pih_magic = PIH_MAGIC;
- pdesc.header.pih_blocklen = NUMWORDS;
- pdesc.header.pih_numwords = 0;
+ pdesc->flags |= PFOR_WRITE;
+ pdesc->header.pih_magic = PIH_MAGIC;
+ pdesc->header.pih_blocklen = NUMWORDS;
+ pdesc->header.pih_numwords = 0;
- fwrite((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp);
+ fwrite((char *) &pdesc->header, sizeof(pdesc->header), 1, ifp);
} else
{
- pdesc.flags &= ~PFOR_WRITE;
+ pdesc->flags &= ~PFOR_WRITE;
- if (!fread((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp))
+ if (!fread((char *) &pdesc->header, sizeof(pdesc->header), 1, ifp))
{
fprintf(stderr, "%s: error reading header\n", prefix);
- pdesc.header.pih_magic = 0;
+ pdesc->header.pih_magic = 0;
fclose(ifp);
fclose(dfp);
+ free(pdesc);
return ((PWDICT *) 0);
}
- if (pdesc.header.pih_magic != PIH_MAGIC)
+ if (pdesc->header.pih_magic != PIH_MAGIC)
{
fprintf(stderr, "%s: magic mismatch\n", prefix);
- pdesc.header.pih_magic = 0;
+ pdesc->header.pih_magic = 0;
fclose(ifp);
fclose(dfp);
+ free(pdesc);
return ((PWDICT *) 0);
}
- if (pdesc.header.pih_blocklen != NUMWORDS)
+ if (pdesc->header.pih_blocklen != NUMWORDS)
{
fprintf(stderr, "%s: size mismatch\n", prefix);
- pdesc.header.pih_magic = 0;
+ pdesc->header.pih_magic = 0;
fclose(ifp);
fclose(dfp);
+ free(pdesc);
return ((PWDICT *) 0);
}
- if (pdesc.flags & PFOR_USEHWMS)
+ if (pdesc->flags & PFOR_USEHWMS)
{
- if (fread(pdesc.hwms, 1, sizeof(pdesc.hwms), wfp) != sizeof(pdesc.hwms))
+ if (fread(pdesc->hwms, 1, sizeof(pdesc->hwms), wfp) != sizeof(pdesc->hwms))
{
- pdesc.flags &= ~PFOR_USEHWMS;
+ pdesc->flags &= ~PFOR_USEHWMS;
}
}
}
-
- return (&pdesc);
+ pdesc->canfree = 1;
+ return (pdesc);
}
int
@@ -159,8 +161,13 @@
fclose(pwp->ifp);
fclose(pwp->dfp);
+ if (pwp->wfp)
+ fclose(pwp->wfp);
- pwp->header.pih_magic = 0;
+ if (pwp->canfree)
+ free(pwp);
+ else
+ pwp->header.pih_magic = 0;
return (0);
}
@@ -307,6 +314,11 @@
register char *this;
int idx;
+/*
+ * comment in npasswd-2.0beta4 says this:
+ * This does not work under all circumstances, so don't bother
+ */
+#if 0
if (pwp->flags & PFOR_USEHWMS)
{
idx = string[0] & 0xff;
@@ -317,6 +329,10 @@
lwm = 0;
hwm = PW_WORDS(pwp) - 1;
}
+#else
+ lwm = 0;
+ hwm = PW_WORDS(pwp);
+#endif
#ifdef DEBUG
printf("---- %lu, %lu ----\n", lwm, hwm);
diff -ur orig/cracklib26_small/util/mkdict cracklib26_small/util/mkdict
--- orig/cracklib26_small/util/mkdict Fri Jul 9 22:23:03 1993
+++ cracklib26_small/util/mkdict Sat Apr 4 22:31:45 1998
@@ -14,9 +14,16 @@
SORT="sort"
###SORT="sort -T /tmp"
-cat $* |
+### Use zcat to read compressed (as well as uncompressed) dictionaries.
+### Compressed dictionaries can save quite a lot of disk space.
+
+CAT="gzip -cdf"
+###CAT="zcat"
+###CAT="cat"
+
+$CAT $* |
tr '[A-Z]' '[a-z]' |
- tr -cd '[\012a-z0-9]' |
+ tr -cd '\012[a-z][0-9]' |
$SORT |
uniq |
grep -v '^#' |

View File

@@ -1,15 +0,0 @@
<head>
<title>shadow - Welcome</title>
</head>
<body>
<h2> Welcome!</h2>
<p> This is the shadow tool suite home page. </p>
<p>
You can find releases <a href="https://github.com/shadow-maint/shadow/releases">here</a>.
</p>
<p>
Raise issues, request features, and report bugs <a href="https://github.com/shadow-maint/shadow/issues">here</a>.
</p>
</body>

View File

@@ -20,4 +20,4 @@ EXTRA_DIST = \
$(sysconf_DATA) \
$(default_DATA)
SUBDIRS = pam.d
SUBDIRS = pam.d shadow-maint

View File

@@ -227,11 +227,6 @@ PASS_WARN_AGE 7
#
SU_WHEEL_ONLY no
#
# If compiled with cracklib support, sets the path to the dictionaries
#
CRACKLIB_DICTPATH /var/cache/cracklib/cracklib_dict
#
# Min/max values for automatic uid selection in useradd(8)
#

View File

@@ -2,20 +2,20 @@
# and also cooperate to make a distribution for `make dist'
pamd_files = \
chpasswd \
chfn \
chsh \
groupmems \
login \
newusers \
passwd
pamd_acct_tools_files = \
chage \
chgpasswd \
chpasswd \
groupadd \
groupdel \
groupmod \
newusers \
useradd \
userdel \
usermod

View File

@@ -0,0 +1,5 @@
shadowmaint_files = \
groupdel-pre.d/01-kill_group_procs.sh \
userdel-pre.d/01-kill_user_procs.sh
EXTRA_DIST = $(shadowmaint_files)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGG8mOoBEADeiVXeiQGVydXf6J/VpVjh9L2Q8drC8esi0zrMGO07TExJ+A/u
h1wLDfArQWhkoKqoSpbEynYyXubuZ1VIDtV61Vjglm28uCVuWPBk1AoQLe6erENk
d/b6IFJ0+OwFqqN0/0erqzTMaAM7rhE+3t4Uuqi2D259UVZRRXkld4AMztkYVxK2
dPQOhddZSN+didG/pVDP3q5t9bLpOYd8DL3reIgoFsvfKbmbTFU+ymT1Pgdd+Fvr
g1Xs7lL8l8P0u9lrm7YSaJkk0mqUooE05oc/yeXWJKun8EqQRyMQmkL/nLzlFx8r
Kjlq1fMiOKDFYzDAGyac7XDGGIYeNPBrSxu5XVgRfywgoAZzEI4cR0ZvMpO7cG0q
+DWZ0mFvAxZ5kE3gNgTb2YM59PaS86Wu0E+4WAbu/60mcv/llRAd7JLcvQcJjK0R
/BgPIujfkAeU06TzqVKeb9+DJ5jlzRkthROO/K9RPJMwDANRfkmHZoSQXuAOWKP2
KC8uh7N/Xy0NKP7xnffXeI0494Xg4uCjRROw3H7ZZnAiyRYM+d0cYFRF4Q7n9hy6
Umwb6yrFxhP4gRCN+HbE2Q5Ot4OsaU9KrczmXGbjbm88o5UDmHTGAssdmEWG/IFP
s5tJi/TwhXVBLxQWCDfHKl3/LCb2X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WXbNUZkyyZvoA
s1YqOM+RFzyTCowFQR2qTDTJeE4k2suoDBukCTMJIFZkthdvMMY/Ss7ZHZwvtmFi
XVg3jNOy3tt9V9oZ0UBPw3qTeDKLh6HzgdyN1mPrEkdilIpPVnHi/iAiL1IrAjZN
xr11YOoWFyLpDfGUeEn9wK0T6Xj6HwytL2XliBremZLFWPQNxkHNHDGoKoAkytIF
MXg5P7Tx/Mcs/1b0WTxmghpc3kkNYIksIDV19RQ35xjnZ/6yYf2qA5dT80wY8mXG
debPR0jwOod+kzIAq0gmopFo25PJjiYSIU28XJciPSS7tgHirvsz+NRotABBBpIR
SmfXBunBhuwLkrImdzqjrrMpv2Ss9brlxqNYiSYJGdsoqt6MeyhzGQ==
=2CmL
-----END PGP PUBLIC KEY BLOCK-----

View File

@@ -5,58 +5,160 @@ DEFS =
noinst_LTLIBRARIES = libshadow.la
if USE_PAM
LIBCRYPT_PAM = $(LIBCRYPT)
else
LIBCRYPT_PAM =
endif
AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir) $(ECONF_CPPFLAGS)
libshadow_la_CPPFLAGS = $(ECONF_CPPFLAGS)
if HAVE_VENDORDIR
libshadow_la_CPPFLAGS += -DVENDORDIR=\"$(VENDORDIR)\"
endif
libshadow_la_CPPFLAGS += -I$(top_srcdir)
libshadow_la_CFLAGS = $(LIBBSD_CFLAGS)
libshadow_la_CFLAGS = $(LIBBSD_CFLAGS) $(LIBCRYPT_PAM) $(LIBSYSTEMD)
libshadow_la_LIBADD = $(LIBADD_DLOPEN)
libshadow_la_SOURCES = \
addgrps.c \
adds.c \
adds.h \
age.c \
agetpass.c \
agetpass.h \
alloc/calloc.c \
alloc/calloc.h \
alloc/malloc.c \
alloc/malloc.h \
alloc/realloc.c \
alloc/realloc.h \
alloc/reallocf.c \
alloc/reallocf.h \
alloc/x/xcalloc.c \
alloc/x/xcalloc.h \
alloc/x/xmalloc.c \
alloc/x/xmalloc.h \
alloc/x/xrealloc.c \
alloc/x/xrealloc.h \
atoi/a2i/a2i.c \
atoi/a2i/a2i.h \
atoi/a2i/a2s.c \
atoi/a2i/a2s.h \
atoi/a2i/a2s_c.c \
atoi/a2i/a2s_c.h \
atoi/a2i/a2s_nc.c \
atoi/a2i/a2s_nc.h \
atoi/a2i/a2u.c \
atoi/a2i/a2u.h \
atoi/a2i/a2u_c.c \
atoi/a2i/a2u_c.h \
atoi/a2i/a2u_nc.c \
atoi/a2i/a2u_nc.h \
atoi/getnum.c \
atoi/getnum.h \
atoi/str2i/str2i.c \
atoi/str2i/str2i.h \
atoi/str2i/str2s.c \
atoi/str2i/str2s.h \
atoi/str2i/str2u.c \
atoi/str2i/str2u.h \
atoi/strtoi/strtoi.c \
atoi/strtoi/strtoi.h \
atoi/strtoi/strtou.c \
atoi/strtoi/strtou.h \
atoi/strtoi/strtou_noneg.c \
atoi/strtoi/strtou_noneg.h \
attr.h \
audit_help.c \
basename.c \
bit.c \
bit.h \
cast.h \
chkname.c \
chkname.h \
chowndir.c \
chowntty.c \
cleanup.c \
cleanup_group.c \
cleanup_user.c \
commonio.c \
commonio.h \
console.c \
copydir.c \
csrand.c \
defines.h \
encrypt.c \
env.c \
exitcodes.h \
faillog.h \
failure.c \
failure.h \
fd.c \
fields.c \
find_new_gid.c \
find_new_uid.c \
find_new_sub_gids.c \
find_new_sub_uids.c \
fputsx.c \
fs/readlink/areadlink.c \
fs/readlink/areadlink.h \
fs/readlink/readlinknul.c \
fs/readlink/readlinknul.h \
get_pid.c \
getdate.h \
getdate.y \
getdef.c \
getdef.h \
get_gid.c \
getlong.c \
get_pid.c \
get_uid.c \
getulong.c \
getgr_nam_gid.c \
getrange.c \
gettime.c \
groupio.c \
groupmem.c \
groupio.h \
gshadow.c \
hushed.c \
idmapping.h \
idmapping.c \
isexpired.c \
limits.c \
list.c \
lockpw.c \
loginprompt.c \
mail.c \
motd.c \
must_be.h \
myname.c \
nss.c \
nscd.c \
nscd.h \
shadowlog.c \
shadowlog.h \
shadowlog_internal.h \
sssd.c \
sssd.h \
obscure.c \
pam_defs.h \
pam_pass.c \
pam_pass_non_interactive.c \
port.c \
port.h \
prefix_flag.c \
prototypes.h \
pwauth.c \
pwauth.h \
pwio.c \
pwio.h \
pwd_init.c \
pwd2spwd.c \
pwdcheck.c \
pwmem.c \
remove_tree.c \
root_flag.c \
run_part.h \
run_part.c \
subordinateio.h \
subordinateio.c \
salt.c \
selinux.c \
semanage.c \
setugid.c \
setupenv.c \
sgetgrent.c \
sgetpwent.c \
sgetspent.c \
@@ -65,13 +167,99 @@ libshadow_la_SOURCES = \
shadow.c \
shadowio.c \
shadowio.h \
shadowlog.c \
shadowlog.h \
shadowlog_internal.h \
shadowmem.c \
spawn.c
shell.c \
sizeof.h \
spawn.c \
sssd.c \
sssd.h \
string/memset/memzero.c \
string/memset/memzero.h \
string/sprintf/snprintf.c \
string/sprintf/snprintf.h \
string/sprintf/stpeprintf.c \
string/sprintf/stpeprintf.h \
string/sprintf/xasprintf.c \
string/sprintf/xasprintf.h \
string/strchr/strchrcnt.c \
string/strchr/strchrcnt.h \
string/strchr/stpspn.c \
string/strchr/stpspn.h \
string/strchr/strnul.c \
string/strchr/strnul.h \
string/strchr/strrspn.c \
string/strchr/strrspn.h \
string/strcmp/streq.c \
string/strcmp/streq.h \
string/strcpy/stpecpy.c \
string/strcpy/stpecpy.h \
string/strcpy/strncat.c \
string/strcpy/strncat.h \
string/strcpy/strncpy.c \
string/strcpy/strncpy.h \
string/strcpy/strtcpy.c \
string/strcpy/strtcpy.h \
string/strdup/strndupa.c \
string/strdup/strndupa.h \
string/strdup/xstrdup.c \
string/strdup/xstrdup.h \
string/strdup/xstrndup.c \
string/strdup/xstrndup.h \
string/strftime.c \
string/strftime.h \
string/strtok/stpsep.c \
string/strtok/stpsep.h \
strtoday.c \
sub.c \
subordinateio.h \
subordinateio.c \
sulog.c \
time/day_to_str.c \
time/day_to_str.h \
ttytype.c \
typetraits.h \
tz.c \
ulimit.c \
user_busy.c \
valid.c \
write_full.c \
xgetpwnam.c \
xprefix_getpwnam.c \
xgetpwuid.c \
xgetgrnam.c \
xgetgrgid.c \
xgetspnam.c \
yesno.c
if WITH_TCB
libshadow_la_SOURCES += tcbfuncs.c tcbfuncs.h
endif
if WITH_BTRFS
libshadow_la_SOURCES += btrfs.c
endif
if ENABLE_LASTLOG
libshadow_la_SOURCES += log.c
endif
if ENABLE_LOGIND
libshadow_la_SOURCES += logind.c
else
libshadow_la_SOURCES += utmp.c
endif
if !WITH_LIBBSD
libshadow_la_SOURCES += \
freezero.h \
freezero.c \
readpassphrase.h \
readpassphrase.c
endif
# These files are unneeded for some reason, listed in
# order of appearance:
#
@@ -79,4 +267,5 @@ endif
EXTRA_DIST = \
.indent.pro \
gshadow_.h
gshadow_.h \
xgetXXbyYY.c

View File

@@ -14,28 +14,30 @@
#include "prototypes.h"
#include "defines.h"
#include <stdio.h>
#include <grp.h>
#include <errno.h>
#include <grp.h>
#include <stdio.h>
#include <string.h>
#include "alloc.h"
#include "alloc/malloc.h"
#include "alloc/reallocf.h"
#include "shadowlog.h"
#ident "$Id$"
#define SEP ",:"
/*
* Add groups with names from LIST (separated by commas or colons)
* to the supplementary group set. Silently ignore groups which are
* already there. Warning: uses strtok().
* already there.
*/
int add_groups (const char *list)
int
add_groups(const char *list)
{
GETGROUPS_T *grouplist;
size_t i;
int ngroups;
bool added;
char *token;
char *g, *p;
char buf[1024];
int ret;
FILE *shadow_logfd = log_get_logfd();
@@ -70,13 +72,13 @@ int add_groups (const char *list)
}
added = false;
for (token = strtok (buf, SEP); NULL != token; token = strtok (NULL, SEP)) {
p = buf;
while (NULL != (g = strsep(&p, ",:"))) {
struct group *grp;
grp = getgrnam (token); /* local, no need for xgetgrnam */
grp = getgrnam(g); /* local, no need for xgetgrnam */
if (NULL == grp) {
fprintf (shadow_logfd, _("Warning: unknown group %s\n"),
token);
fprintf(shadow_logfd, _("Warning: unknown group %s\n"), g);
continue;
}

15
lib/adds.c Normal file
View File

@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "adds.h"
#include <stddef.h>
extern inline long addsl2(long a, long b);
extern inline long addslN(size_t n, long addend[n]);
extern inline int cmpl(const void *p1, const void *p2);

86
lib/adds.h Normal file
View File

@@ -0,0 +1,86 @@
// SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ADDS_H_
#define SHADOW_INCLUDE_LIB_ADDS_H_
#include <config.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include "sizeof.h"
#define addsl(a, b, ...) \
({ \
long addend_[] = {a, b, __VA_ARGS__}; \
\
addslN(NITEMS(addend_), addend_); \
})
inline long addsl2(long a, long b);
inline long addslN(size_t n, long addend[n]);
inline int cmpl(const void *p1, const void *p2);
inline long
addsl2(long a, long b)
{
if (a > 0 && b > LONG_MAX - a) {
errno = EOVERFLOW;
return LONG_MAX;
}
if (a < 0 && b < LONG_MIN - a) {
errno = EOVERFLOW;
return LONG_MIN;
}
return a + b;
}
inline long
addslN(size_t n, long addend[n])
{
int e;
if (n == 0) {
errno = EDOM;
return 0;
}
e = errno;
while (n > 1) {
qsort(addend, n, sizeof(addend[0]), cmpl);
errno = 0;
addend[0] = addsl2(addend[0], addend[--n]);
if (errno == EOVERFLOW)
return addend[0];
}
errno = e;
return addend[0];
}
inline int
cmpl(const void *p1, const void *p2)
{
const long *l1 = p1;
const long *l2 = p2;
if (*l1 < *l2)
return -1;
if (*l1 > *l2)
return +1;
return 0;
}
#endif // include guard

View File

@@ -13,12 +13,15 @@
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include "prototypes.h"
#include "defines.h"
#include "exitcodes.h"
#include <pwd.h>
#include <grp.h>
#include "adds.h"
#include "defines.h"
#include "exitcodes.h"
#include "prototypes.h"
#ident "$Id$"
#ifndef PASSWD_PROGRAM
@@ -139,7 +142,7 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp)
void agecheck (/*@null@*/const struct spwd *sp)
{
long now = time(NULL) / SCALE;
long now = time(NULL) / DAY;
long remain;
if (NULL == sp) {
@@ -162,9 +165,9 @@ void agecheck (/*@null@*/const struct spwd *sp)
return;
}
remain = sp->sp_lstchg + sp->sp_max - now;
remain = addsl(sp->sp_lstchg, sp->sp_max, -now);
if (remain <= sp->sp_warn) {
remain /= DAY / SCALE;
if (remain > 1) {
(void) printf (_("Your password will expire in %ld days.\n"),
remain);

View File

@@ -7,27 +7,27 @@
#include <config.h>
#include "agetpass.h"
#include <limits.h>
#include <readpassphrase.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ident "$Id$"
#include "alloc.h"
#include "prototypes.h"
#include "alloc/malloc.h"
#if !defined(PASS_MAX)
#define PASS_MAX BUFSIZ - 1
#endif
#if WITH_LIBBSD == 0
#include "freezero.h"
#endif /* WITH_LIBBSD */
/*
* SYNOPSIS
* [[gnu::malloc(erase_pass)]]
* char *agetpass(const char *prompt);
* char *agetpass_stdin();
*
* void erase_pass(char *pass);
*
@@ -60,6 +60,10 @@
* erased by calling erase_pass(), to avoid possibly leaking the
* password.
*
* agetpass_stdin()
* This function is the same as previous one (agetpass). Just the
* password is read from stdin and terminal is not required.
*
* erase_pass()
* This function first clears the password, by calling
* explicit_bzero(3) (or an equivalent call), and then frees the
@@ -88,8 +92,8 @@
*/
char *
agetpass(const char *prompt)
static char *
agetpass_internal(const char *prompt, int flags)
{
char *pass;
size_t len;
@@ -106,7 +110,7 @@ agetpass(const char *prompt)
if (pass == NULL)
return NULL;
if (readpassphrase(prompt, pass, PASS_MAX + 2, RPP_REQUIRE_TTY) == NULL)
if (readpassphrase(prompt, pass, PASS_MAX + 2, flags) == NULL)
goto fail;
len = strlen(pass);
@@ -122,6 +126,17 @@ fail:
return NULL;
}
char *
agetpass(const char *prompt)
{
return agetpass_internal(prompt, RPP_REQUIRE_TTY);
}
char *
agetpass_stdin()
{
return agetpass_internal(NULL, RPP_STDIN);
}
void
erase_pass(char *pass)

23
lib/agetpass.h Normal file
View File

@@ -0,0 +1,23 @@
/*
* SPDX-FileCopyrightText: 2022-2023, Alejandro Colomar <alx@kernel.org>
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SHADOW_INCLUDE_LIB_AGETPASS_H_
#define SHADOW_INCLUDE_LIB_AGETPASS_H_
#include <config.h>
#include "attr.h"
#include "defines.h"
void erase_pass(char *pass);
ATTR_MALLOC(erase_pass)
char *agetpass(const char *prompt);
char *agetpass_stdin();
#endif // include guard

View File

@@ -1,115 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023, Alejandro Colomar <alx@kernel.org>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
#define SHADOW_INCLUDE_LIB_MALLOC_H_
#include <config.h>
#include <assert.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "defines.h"
#define CALLOC(n, type) ((type *) calloc(n, sizeof(type)))
#define XCALLOC(n, type) ((type *) xcalloc(n, sizeof(type)))
#define MALLOC(n, type) ((type *) mallocarray(n, sizeof(type)))
#define XMALLOC(n, type) ((type *) xmallocarray(n, sizeof(type)))
#define REALLOC(ptr, n, type) \
({ \
__auto_type p_ = (ptr); \
\
static_assert(__builtin_types_compatible_p(typeof(p_), type *), ""); \
\
(type *) reallocarray(p_, n, sizeof(type)); \
})
#define REALLOCF(ptr, n, type) \
({ \
__auto_type p_ = (ptr); \
\
static_assert(__builtin_types_compatible_p(typeof(p_), type *), ""); \
\
(type *) reallocarrayf(p_, n, sizeof(type)); \
})
#define XREALLOC(ptr, n, type) \
({ \
__auto_type p_ = (ptr); \
\
static_assert(__builtin_types_compatible_p(typeof(p_), type *), ""); \
\
(type *) xreallocarray(p_, n, sizeof(type)); \
})
ATTR_MALLOC(free)
inline void *xmalloc(size_t size);
ATTR_MALLOC(free)
inline void *xmallocarray(size_t nmemb, size_t size);
ATTR_MALLOC(free)
inline void *mallocarray(size_t nmemb, size_t size);
ATTR_MALLOC(free)
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
ATTR_MALLOC(free)
inline char *xstrdup(const char *str);
ATTR_MALLOC(free)
void *xcalloc(size_t nmemb, size_t size);
ATTR_MALLOC(free)
void *xreallocarray(void *p, size_t nmemb, size_t size);
inline void *
xmalloc(size_t size)
{
return xmallocarray(1, size);
}
inline void *
xmallocarray(size_t nmemb, size_t size)
{
return xreallocarray(NULL, nmemb, size);
}
inline void *
mallocarray(size_t nmemb, size_t size)
{
return reallocarray(NULL, nmemb, size);
}
inline void *
reallocarrayf(void *p, size_t nmemb, size_t size)
{
void *q;
q = reallocarray(p, nmemb, size);
/* realloc(p, 0) is equivalent to free(p); avoid double free. */
if (q == NULL && nmemb != 0 && size != 0)
free(p);
return q;
}
inline char *
xstrdup(const char *str)
{
return strcpy(XMALLOC(strlen(str) + 1, char), str);
}
#endif // include guard

11
lib/alloc/calloc.c Normal file
View File

@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2008 , Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "alloc/calloc.h"

20
lib/alloc/calloc.h Normal file
View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
#define SHADOW_INCLUDE_LIB_ALLOC_CALLOC_H_
#include <config.h>
#include <stdlib.h>
#define CALLOC(n, type) \
( \
(type *) calloc(n, sizeof(type)) \
)
#endif // include guard

16
lib/alloc/malloc.c Normal file
View File

@@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2008 , Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "alloc/malloc.h"
#include <stddef.h>
extern inline void *mallocarray(size_t nmemb, size_t size);

34
lib/alloc/malloc.h Normal file
View File

@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
#define SHADOW_INCLUDE_LIB_ALLOC_MALLOC_H_
#include <config.h>
#include <stdlib.h>
#include "attr.h"
#define MALLOC(n, type) \
( \
(type *) mallocarray(n, sizeof(type)) \
)
ATTR_ALLOC_SIZE(1, 2)
ATTR_MALLOC(free)
inline void *mallocarray(size_t nmemb, size_t size);
inline void *
mallocarray(size_t nmemb, size_t size)
{
return reallocarray(NULL, nmemb, size);
}
#endif // include guard

11
lib/alloc/realloc.c Normal file
View File

@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2008 , Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "alloc/realloc.h"

20
lib/alloc/realloc.h Normal file
View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
#define SHADOW_INCLUDE_LIB_ALLOC_REALLOC_H_
#include <config.h>
#include <stdlib.h>
#define REALLOC(p, n, type) \
( \
_Generic(p, type *: (type *) reallocarray(p, (n) ?: 1, sizeof(type))) \
)
#endif // include guard

16
lib/alloc/reallocf.c Normal file
View File

@@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2008 , Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "alloc/reallocf.h"
#include <stddef.h>
extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);

41
lib/alloc/reallocf.h Normal file
View File

@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
#define SHADOW_INCLUDE_LIB_ALLOC_REALLOCF_H_
#include <config.h>
#include <stddef.h>
#include <stdlib.h>
#include "attr.h"
#define REALLOCF(p, n, type) \
( \
_Generic(p, type *: (type *) reallocarrayf(p, (n) ?: 1, sizeof(type)))\
)
ATTR_ALLOC_SIZE(2, 3)
ATTR_MALLOC(free)
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
inline void *
reallocarrayf(void *p, size_t nmemb, size_t size)
{
void *q;
q = reallocarray(p, nmemb ?: 1, size ?: 1);
if (q == NULL)
free(p);
return q;
}
#endif // include guard

36
lib/alloc/x/xcalloc.c Normal file
View File

@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2008 , Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "alloc/x/xcalloc.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "defines.h"
#include "shadowlog.h"
void *
xcalloc(size_t nmemb, size_t size)
{
void *p;
p = calloc(nmemb, size);
if (p == NULL)
goto x;
return p;
x:
fprintf(log_get_logfd(), _("%s: %s\n"),
log_get_progname(), strerror(errno));
exit(13);
}

28
lib/alloc/x/xcalloc.h Normal file
View File

@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
#define SHADOW_INCLUDE_LIB_ALLOC_X_XCALLOC_H_
#include <config.h>
#include <stddef.h>
#include <stdlib.h>
#include "attr.h"
#define XCALLOC(n, type) \
( \
(type *) xcalloc(n, sizeof(type)) \
)
ATTR_ALLOC_SIZE(1, 2)
ATTR_MALLOC(free)
void *xcalloc(size_t nmemb, size_t size);
#endif // include guard

16
lib/alloc/x/xmalloc.c Normal file
View File

@@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2008 , Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "alloc/x/xmalloc.h"
#include <stddef.h>
extern inline void *xmallocarray(size_t nmemb, size_t size);

35
lib/alloc/x/xmalloc.h Normal file
View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
#define SHADOW_INCLUDE_LIB_ALLOC_X_XMALLOC_H_
#include <config.h>
#include <stddef.h>
#include "alloc/x/xrealloc.h"
#include "attr.h"
#define XMALLOC(n, type) \
( \
(type *) xmallocarray(n, sizeof(type)) \
)
ATTR_ALLOC_SIZE(1, 2)
ATTR_MALLOC(free)
inline void *xmallocarray(size_t nmemb, size_t size);
inline void *
xmallocarray(size_t nmemb, size_t size)
{
return xreallocarray(NULL, nmemb, size);
}
#endif // include guard

35
lib/alloc/x/xrealloc.c Normal file
View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2008 , Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "alloc/x/xrealloc.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "alloc/reallocf.h"
#include "defines.h"
#include "shadowlog.h"
void *
xreallocarray(void *p, size_t nmemb, size_t size)
{
p = reallocarrayf(p, nmemb, size);
if (p == NULL)
goto x;
return p;
x:
fprintf(log_get_logfd(), _("%s: %s\n"),
log_get_progname(), strerror(errno));
exit(13);
}

31
lib/alloc/x/xrealloc.h Normal file
View File

@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_MALLOC_H_
#define SHADOW_INCLUDE_LIB_MALLOC_H_
#include <config.h>
#include <assert.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "attr.h"
#define XREALLOC(ptr, n, type) \
( \
_Generic(ptr, type *: (type *) xreallocarray(ptr, n, sizeof(type))) \
)
ATTR_ALLOC_SIZE(2, 3)
ATTR_MALLOC(free)
void *xreallocarray(void *p, size_t nmemb, size_t size);
#endif // include guard

7
lib/atoi/a2i/a2i.c Normal file
View File

@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/a2i/a2i.h"

62
lib/atoi/a2i/a2i.h Normal file
View File

@@ -0,0 +1,62 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2I_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2I_H_
#include <config.h>
#include "atoi/a2i/a2s_c.h"
#include "atoi/a2i/a2s_nc.h"
#include "atoi/a2i/a2u_c.h"
#include "atoi/a2i/a2u_nc.h"
/*
* See the manual of these macros in liba2i's documentation:
* <http://www.alejandro-colomar.es/share/dist/liba2i/git/HEAD/liba2i-HEAD.pdf>
*/
#define a2i(TYPE, n, s, ...) \
( \
_Generic((void (*)(TYPE, typeof(s))) 0, \
void (*)(short, const char *): a2sh_c, \
void (*)(short, const void *): a2sh_c, \
void (*)(short, char *): a2sh_nc, \
void (*)(short, void *): a2sh_nc, \
void (*)(int, const char *): a2si_c, \
void (*)(int, const void *): a2si_c, \
void (*)(int, char *): a2si_nc, \
void (*)(int, void *): a2si_nc, \
void (*)(long, const char *): a2sl_c, \
void (*)(long, const void *): a2sl_c, \
void (*)(long, char *): a2sl_nc, \
void (*)(long, void *): a2sl_nc, \
void (*)(long long, const char *): a2sll_c, \
void (*)(long long, const void *): a2sll_c, \
void (*)(long long, char *): a2sll_nc, \
void (*)(long long, void *): a2sll_nc, \
void (*)(unsigned short, const char *): a2uh_c, \
void (*)(unsigned short, const void *): a2uh_c, \
void (*)(unsigned short, char *): a2uh_nc, \
void (*)(unsigned short, void *): a2uh_nc, \
void (*)(unsigned int, const char *): a2ui_c, \
void (*)(unsigned int, const void *): a2ui_c, \
void (*)(unsigned int, char *): a2ui_nc, \
void (*)(unsigned int, void *): a2ui_nc, \
void (*)(unsigned long, const char *): a2ul_c, \
void (*)(unsigned long, const void *): a2ul_c, \
void (*)(unsigned long, char *): a2ul_nc, \
void (*)(unsigned long, void *): a2ul_nc, \
void (*)(unsigned long long, const char *): a2ull_c, \
void (*)(unsigned long long, const void *): a2ull_c, \
void (*)(unsigned long long, char *): a2ull_nc, \
void (*)(unsigned long long, void *): a2ull_nc \
)(n, s, __VA_ARGS__) \
)
#endif // include guard

7
lib/atoi/a2i/a2s.c Normal file
View File

@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/a2i/a2s.h"

56
lib/atoi/a2i/a2s.h Normal file
View File

@@ -0,0 +1,56 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_H_
#include <config.h>
#include "atoi/a2i/a2s_c.h"
#include "atoi/a2i/a2s_nc.h"
#define a2sh(n, s, ...) \
( \
_Generic(s, \
const char *: a2sh_c, \
const void *: a2sh_c, \
char *: a2sh_nc, \
void *: a2sh_nc \
)(n, s, __VA_ARGS__) \
)
#define a2si(n, s, ...) \
( \
_Generic(s, \
const char *: a2si_c, \
const void *: a2si_c, \
char *: a2si_nc, \
void *: a2si_nc \
)(n, s, __VA_ARGS__) \
)
#define a2sl(n, s, ...) \
( \
_Generic(s, \
const char *: a2sl_c, \
const void *: a2sl_c, \
char *: a2sl_nc, \
void *: a2sl_nc \
)(n, s, __VA_ARGS__) \
)
#define a2sll(n, s, ...) \
( \
_Generic(s, \
const char *: a2sll_c, \
const void *: a2sll_c, \
char *: a2sll_nc, \
void *: a2sll_nc \
)(n, s, __VA_ARGS__) \
)
#endif // include guard

17
lib/atoi/a2i/a2s_c.c Normal file
View File

@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/a2i/a2s_c.h"
extern inline int a2sh_c(short *restrict n, const char *s,
const char **restrict endp, int base, short min, short max);
extern inline int a2si_c(int *restrict n, const char *s,
const char **restrict endp, int base, int min, int max);
extern inline int a2sl_c(long *restrict n, const char *s,
const char **restrict endp, int base, long min, long max);
extern inline int a2sll_c(long long *restrict n, const char *s,
const char **restrict endp, int base, long long min, long long max);

64
lib/atoi/a2i/a2s_c.h Normal file
View File

@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_C_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_C_H_
#include <config.h>
#include <errno.h>
#include <inttypes.h>
#include "atoi/a2i/a2s_nc.h"
#include "attr.h"
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2sh_c(short *restrict n, const char *s,
const char **restrict endp, int base, short min, short max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2si_c(int *restrict n, const char *s,
const char **restrict endp, int base, int min, int max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2sl_c(long *restrict n, const char *s,
const char **restrict endp, int base, long min, long max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2sll_c(long long *restrict n, const char *s,
const char **restrict endp, int base, long long min, long long max);
inline int
a2sh_c(short *restrict n, const char *s,
const char **restrict endp, int base, short min, short max)
{
return a2sh_nc(n, (char *) s, (char **) endp, base, min, max);
}
inline int
a2si_c(int *restrict n, const char *s,
const char **restrict endp, int base, int min, int max)
{
return a2si_nc(n, (char *) s, (char **) endp, base, min, max);
}
inline int
a2sl_c(long *restrict n, const char *s,
const char **restrict endp, int base, long min, long max)
{
return a2sl_nc(n, (char *) s, (char **) endp, base, min, max);
}
inline int
a2sll_c(long long *restrict n, const char *s,
const char **restrict endp, int base, long long min, long long max)
{
return a2sll_nc(n, (char *) s, (char **) endp, base, min, max);
}
#endif // include guard

17
lib/atoi/a2i/a2s_nc.c Normal file
View File

@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/a2i/a2s_nc.h"
extern inline int a2sh_nc(short *restrict n, char *s,
char **restrict endp, int base, short min, short max);
extern inline int a2si_nc(int *restrict n, char *s,
char **restrict endp, int base, int min, int max);
extern inline int a2sl_nc(long *restrict n, char *s,
char **restrict endp, int base, long min, long max);
extern inline int a2sll_nc(long long *restrict n, char *s,
char **restrict endp, int base, long long min, long long max);

91
lib/atoi/a2i/a2s_nc.h Normal file
View File

@@ -0,0 +1,91 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_NC_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2S_NC_H_
#include <config.h>
#include <errno.h>
#include "atoi/strtoi/strtoi.h"
#include "attr.h"
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2sh_nc(short *restrict n, char *s,
char **restrict endp, int base, short min, short max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2si_nc(int *restrict n, char *s,
char **restrict endp, int base, int min, int max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2sl_nc(long *restrict n, char *s,
char **restrict endp, int base, long min, long max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2sll_nc(long long *restrict n, char *s,
char **restrict endp, int base, long long min, long long max);
inline int
a2sh_nc(short *restrict n, char *s,
char **restrict endp, int base, short min, short max)
{
int status;
*n = strtoi_(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
inline int
a2si_nc(int *restrict n, char *s,
char **restrict endp, int base, int min, int max)
{
int status;
*n = strtoi_(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
inline int
a2sl_nc(long *restrict n, char *s,
char **restrict endp, int base, long min, long max)
{
int status;
*n = strtoi_(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
inline int
a2sll_nc(long long *restrict n, char *s,
char **restrict endp, int base, long long min, long long max)
{
int status;
*n = strtoi_(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
#endif // include guard

7
lib/atoi/a2i/a2u.c Normal file
View File

@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/a2i/a2u.h"

56
lib/atoi/a2i/a2u.h Normal file
View File

@@ -0,0 +1,56 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_H_
#include <config.h>
#include "atoi/a2i/a2u_c.h"
#include "atoi/a2i/a2u_nc.h"
#define a2uh(n, s, ...) \
( \
_Generic(s, \
const char *: a2uh_c, \
const void *: a2uh_c, \
char *: a2uh_nc, \
void *: a2uh_nc \
)(n, s, __VA_ARGS__) \
)
#define a2ui(n, s, ...) \
( \
_Generic(s, \
const char *: a2ui_c, \
const void *: a2ui_c, \
char *: a2ui_nc, \
void *: a2ui_nc \
)(n, s, __VA_ARGS__) \
)
#define a2ul(n, s, ...) \
( \
_Generic(s, \
const char *: a2ul_c, \
const void *: a2ul_c, \
char *: a2ul_nc, \
void *: a2ul_nc \
)(n, s, __VA_ARGS__) \
)
#define a2ull(n, s, ...) \
( \
_Generic(s, \
const char *: a2ull_c, \
const void *: a2ull_c, \
char *: a2ull_nc, \
void *: a2ull_nc \
)(n, s, __VA_ARGS__) \
)
#endif // include guard

19
lib/atoi/a2i/a2u_c.c Normal file
View File

@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/a2i/a2u_c.h"
extern inline int a2uh_c(unsigned short *restrict n, const char *s,
const char **restrict endp, int base, unsigned short min,
unsigned short max);
extern inline int a2ui_c(unsigned int *restrict n, const char *s,
const char **restrict endp, int base, unsigned int min, unsigned int max);
extern inline int a2ul_c(unsigned long *restrict n, const char *s,
const char **restrict endp, int base, unsigned long min, unsigned long max);
extern inline int a2ull_c(unsigned long long *restrict n, const char *s,
const char **restrict endp, int base, unsigned long long min,
unsigned long long max);

65
lib/atoi/a2i/a2u_c.h Normal file
View File

@@ -0,0 +1,65 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_C_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_C_H_
#include <config.h>
#include "atoi/a2i/a2u_nc.h"
#include "attr.h"
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2uh_c(unsigned short *restrict n, const char *s,
const char **restrict endp, int base, unsigned short min,
unsigned short max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2ui_c(unsigned int *restrict n, const char *s,
const char **restrict endp, int base, unsigned int min, unsigned int max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2ul_c(unsigned long *restrict n, const char *s,
const char **restrict endp, int base, unsigned long min, unsigned long max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2ull_c(unsigned long long *restrict n, const char *s,
const char **restrict endp, int base, unsigned long long min,
unsigned long long max);
inline int
a2uh_c(unsigned short *restrict n, const char *s,
const char **restrict endp, int base, unsigned short min,
unsigned short max)
{
return a2uh_nc(n, (char *) s, (char **) endp, base, min, max);
}
inline int
a2ui_c(unsigned int *restrict n, const char *s,
const char **restrict endp, int base, unsigned int min, unsigned int max)
{
return a2ui_nc(n, (char *) s, (char **) endp, base, min, max);
}
inline int
a2ul_c(unsigned long *restrict n, const char *s,
const char **restrict endp, int base, unsigned long min, unsigned long max)
{
return a2ul_nc(n, (char *) s, (char **) endp, base, min, max);
}
inline int
a2ull_c(unsigned long long *restrict n, const char *s,
const char **restrict endp, int base, unsigned long long min,
unsigned long long max)
{
return a2ull_nc(n, (char *) s, (char **) endp, base, min, max);
}
#endif // include guard

18
lib/atoi/a2i/a2u_nc.c Normal file
View File

@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/a2i/a2u_nc.h"
extern inline int a2uh_nc(unsigned short *restrict n, char *s,
char **restrict endp, int base, unsigned short min, unsigned short max);
extern inline int a2ui_nc(unsigned int *restrict n, char *s,
char **restrict endp, int base, unsigned int min, unsigned int max);
extern inline int a2ul_nc(unsigned long *restrict n, char *s,
char **restrict endp, int base, unsigned long min, unsigned long max);
extern inline int a2ull_nc(unsigned long long *restrict n, char *s,
char **restrict endp, int base, unsigned long long min,
unsigned long long max);

94
lib/atoi/a2i/a2u_nc.h Normal file
View File

@@ -0,0 +1,94 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_NC_H_
#define SHADOW_INCLUDE_LIB_ATOI_A2I_A2U_NC_H_
#include <config.h>
#include <errno.h>
#include "atoi/strtoi/strtou_noneg.h"
#include "attr.h"
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2uh_nc(unsigned short *restrict n, char *s,
char **restrict endp, int base, unsigned short min, unsigned short max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2ui_nc(unsigned int *restrict n, char *s,
char **restrict endp, int base, unsigned int min, unsigned int max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2ul_nc(unsigned long *restrict n, char *s,
char **restrict endp, int base, unsigned long min, unsigned long max);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1) ATTR_ACCESS(write_only, 3)
inline int a2ull_nc(unsigned long long *restrict n, char *s,
char **restrict endp, int base, unsigned long long min,
unsigned long long max);
inline int
a2uh_nc(unsigned short *restrict n, char *s,
char **restrict endp, int base, unsigned short min,
unsigned short max)
{
int status;
*n = strtou_noneg(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
inline int
a2ui_nc(unsigned int *restrict n, char *s,
char **restrict endp, int base, unsigned int min, unsigned int max)
{
int status;
*n = strtou_noneg(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
inline int
a2ul_nc(unsigned long *restrict n, char *s,
char **restrict endp, int base, unsigned long min, unsigned long max)
{
int status;
*n = strtou_noneg(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
inline int
a2ull_nc(unsigned long long *restrict n, char *s,
char **restrict endp, int base, unsigned long long min,
unsigned long long max)
{
int status;
*n = strtou_noneg(s, endp, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
#endif // include guard

16
lib/atoi/getnum.c Normal file
View File

@@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include <sys/types.h>
#include "atoi/getnum.h"
extern inline int get_fd(const char *restrict fdstr, int *restrict fd);
extern inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);
extern inline int get_pid(const char *restrict pidstr, pid_t *restrict pid);
extern inline int get_uid(const char *restrict uidstr, uid_t *restrict uid);

60
lib/atoi/getnum.h Normal file
View File

@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_
#define SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_
#include <config.h>
#include <limits.h>
#include <stddef.h>
#include <sys/types.h>
#include "atoi/a2i/a2i.h"
#include "atoi/a2i/a2s.h"
#include "attr.h"
#include "typetraits.h"
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
inline int get_fd(const char *restrict fdstr, int *restrict fd);
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
inline int get_pid(const char *restrict pidstr, pid_t *restrict pid);
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
inline int get_uid(const char *restrict uidstr, uid_t *restrict uid);
inline int
get_fd(const char *restrict fdstr, int *restrict fd)
{
return a2si(fd, fdstr, NULL, 10, 0, INT_MAX);
}
inline int
get_gid(const char *restrict gidstr, gid_t *restrict gid)
{
return a2i(gid_t, gid, gidstr, NULL, 10, type_min(gid_t), type_max(gid_t));
}
inline int
get_pid(const char *restrict pidstr, pid_t *restrict pid)
{
return a2i(pid_t, pid, pidstr, NULL, 10, 1, type_max(pid_t));
}
inline int
get_uid(const char *restrict uidstr, uid_t *restrict uid)
{
return a2i(uid_t, uid, uidstr, NULL, 10, type_min(uid_t), type_max(uid_t));
}
#endif // include guard

8
lib/atoi/str2i/str2i.c Normal file
View File

@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/str2i/str2i.h"

31
lib/atoi/str2i/str2i.h Normal file
View File

@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2I_H_
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2I_H_
#include <config.h>
#include "atoi/str2i/str2s.h"
#include "atoi/str2i/str2u.h"
#define str2i(TYPE, ...) \
( \
_Generic((TYPE) 0, \
short: str2sh, \
int: str2si, \
long: str2sl, \
long long: str2sll, \
unsigned short: str2uh, \
unsigned int: str2ui, \
unsigned long: str2ul, \
unsigned long long: str2ull \
)(__VA_ARGS__) \
)
#endif // include guard

14
lib/atoi/str2i/str2s.c Normal file
View File

@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/str2i/str2s.h"
extern inline int str2sh(short *restrict n, const char *restrict s);
extern inline int str2si(int *restrict n, const char *restrict s);
extern inline int str2sl(long *restrict n, const char *restrict s);
extern inline int str2sll(long long *restrict n, const char *restrict s);

57
lib/atoi/str2i/str2s.h Normal file
View File

@@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2S_H_
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2S_H_
#include <config.h>
#include <limits.h>
#include <stddef.h>
#include "atoi/a2i/a2s.h"
#include "attr.h"
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2sh(short *restrict n, const char *restrict s);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2si(int *restrict n, const char *restrict s);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2sl(long *restrict n, const char *restrict s);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2sll(long long *restrict n, const char *restrict s);
inline int
str2sh(short *restrict n, const char *restrict s)
{
return a2sh(n, s, NULL, 0, SHRT_MIN, SHRT_MAX);
}
inline int
str2si(int *restrict n, const char *restrict s)
{
return a2si(n, s, NULL, 0, INT_MIN, INT_MAX);
}
inline int
str2sl(long *restrict n, const char *restrict s)
{
return a2sl(n, s, NULL, 0, LONG_MIN, LONG_MAX);
}
inline int
str2sll(long long *restrict n, const char *restrict s)
{
return a2sll(n, s, NULL, 0, LLONG_MIN, LLONG_MAX);
}
#endif // include guard

14
lib/atoi/str2i/str2u.c Normal file
View File

@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/str2i/str2u.h"
extern inline int str2uh(unsigned short *restrict n, const char *restrict s);
extern inline int str2ui(unsigned int *restrict n, const char *restrict s);
extern inline int str2ul(unsigned long *restrict n, const char *restrict s);
extern inline int str2ull(unsigned long long *restrict n, const char *restrict s);

57
lib/atoi/str2i/str2u.h Normal file
View File

@@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2U_H_
#define SHADOW_INCLUDE_LIB_ATOI_STR2I_STR2U_H_
#include <config.h>
#include <limits.h>
#include <stddef.h>
#include "atoi/a2i/a2u.h"
#include "attr.h"
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2uh(unsigned short *restrict n, const char *restrict s);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2ui(unsigned int *restrict n, const char *restrict s);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2ul(unsigned long *restrict n, const char *restrict s);
ATTR_STRING(2) ATTR_ACCESS(write_only, 1)
inline int str2ull(unsigned long long *restrict n, const char *restrict s);
inline int
str2uh(unsigned short *restrict n, const char *restrict s)
{
return a2uh(n, s, NULL, 0, 0, USHRT_MAX);
}
inline int
str2ui(unsigned int *restrict n, const char *restrict s)
{
return a2ui(n, s, NULL, 0, 0, UINT_MAX);
}
inline int
str2ul(unsigned long *restrict n, const char *restrict s)
{
return a2ul(n, s, NULL, 0, 0, ULONG_MAX);
}
inline int
str2ull(unsigned long long *restrict n, const char *restrict s)
{
return a2ull(n, s, NULL, 0, 0, ULLONG_MAX);
}
#endif // include guard

13
lib/atoi/strtoi/strtoi.c Normal file
View File

@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/strtoi/strtoi.h"
#include <stdint.h>
extern inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
intmax_t min, intmax_t max, int *restrict status);

64
lib/atoi/strtoi/strtoi.h Normal file
View File

@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOI_H_
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOI_H_
#include <config.h>
#include <errno.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/param.h>
#include "attr.h"
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
inline intmax_t strtoi_(const char *s, char **restrict endp, int base,
intmax_t min, intmax_t max, int *restrict status);
inline intmax_t
strtoi_(const char *s, char **restrict endp, int base,
intmax_t min, intmax_t max, int *restrict status)
{
int e, st;
char *end;
intmax_t n;
if (endp == NULL)
endp = &end;
if (status == NULL)
status = &st;
if (base != 0 && (base < 2 || base > 36)) {
*status = EINVAL;
return MAX(min, MIN(max, 0));
}
e = errno;
errno = 0;
n = strtoimax(s, endp, base);
if (*endp == s)
*status = ECANCELED;
else if (errno == ERANGE || n < min || n > max)
*status = ERANGE;
else if (**endp != '\0')
*status = ENOTSUP;
else
*status = 0;
errno = e;
return MAX(min, MIN(max, n));
}
#endif // include guard

13
lib/atoi/strtoi/strtou.c Normal file
View File

@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/strtoi/strtou.h"
#include <stdint.h>
extern inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
uintmax_t min, uintmax_t max, int *restrict status);

64
lib/atoi/strtoi/strtou.h Normal file
View File

@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_H_
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_H_
#include <config.h>
#include <errno.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/param.h>
#include "attr.h"
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
inline uintmax_t strtou_(const char *s, char **restrict endp, int base,
uintmax_t min, uintmax_t max, int *restrict status);
inline uintmax_t
strtou_(const char *s, char **restrict endp, int base,
uintmax_t min, uintmax_t max, int *restrict status)
{
int e, st;
char *end;
uintmax_t n;
if (endp == NULL)
endp = &end;
if (status == NULL)
status = &st;
if (base != 0 && (base < 2 || base > 36)) {
*status = EINVAL;
return MAX(min, 0);
}
e = errno;
errno = 0;
n = strtoumax(s, endp, base);
if (*endp == s)
*status = ECANCELED;
else if (errno == ERANGE || n < min || n > max)
*status = ERANGE;
else if (**endp != '\0')
*status = ENOTSUP;
else
*status = 0;
errno = e;
return MAX(min, MIN(max, n));
}
#endif // include guard

View File

@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#include <config.h>
#include "atoi/strtoi/strtou_noneg.h"
#include <stdint.h>
extern inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
int base, uintmax_t min, uintmax_t max, int *restrict status);

View File

@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
#define SHADOW_INCLUDE_LIB_ATOI_STRTOI_STRTOU_NONEG_H_
#include <config.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include "atoi/strtoi/strtoi.h"
#include "atoi/strtoi/strtou.h"
#include "attr.h"
ATTR_STRING(1) ATTR_ACCESS(write_only, 2) ATTR_ACCESS(write_only, 6)
inline uintmax_t strtou_noneg(const char *s, char **restrict endp,
int base, uintmax_t min, uintmax_t max, int *restrict status);
inline uintmax_t
strtou_noneg(const char *s, char **restrict endp, int base,
uintmax_t min, uintmax_t max, int *restrict status)
{
int st;
if (status == NULL)
status = &st;
if (strtoi_(s, endp, base, 0, 1, status) == 0 && *status == ERANGE)
return min;
return strtou_(s, endp, base, min, max, status);
}
#endif // include guard

35
lib/attr.h Normal file
View File

@@ -0,0 +1,35 @@
#ifndef SHADOW_INCLUDE_LIB_ATTR_H_
#define SHADOW_INCLUDE_LIB_ATTR_H_
#include "config.h"
#if defined(__GNUC__)
# define MAYBE_UNUSED [[gnu::unused]]
# define NORETURN [[gnu::__noreturn__]]
# define format_attr(type, fmt, va) [[gnu::format(type, fmt, va)]]
# define ATTR_ACCESS(...) [[gnu::access(__VA_ARGS__)]]
# define ATTR_ALLOC_SIZE(...) [[gnu::alloc_size(__VA_ARGS__)]]
#else
# define MAYBE_UNUSED
# define NORETURN
# define format_attr(type, fmt, va)
# define ATTR_ACCESS(...)
# define ATTR_ALLOC_SIZE(...)
#endif
#if (__GNUC__ >= 11) && !defined(__clang__)
# define ATTR_MALLOC(deallocator) [[gnu::malloc(deallocator)]]
#else
# define ATTR_MALLOC(deallocator)
#endif
#if (__GNUC__ >= 14)
# define ATTR_STRING(i) [[gnu::null_terminated_string_arg(i)]]
#else
# define ATTR_STRING(i)
#endif
#endif // include guard

View File

@@ -21,6 +21,8 @@
#include <libaudit.h>
#include <errno.h>
#include <stdio.h>
#include "attr.h"
#include "prototypes.h"
#include "shadowlog.h"
int audit_fd;
@@ -54,7 +56,7 @@ void audit_help_open (void)
* id - uid or gid that the operation is being performed on. This is used
* only when user is NULL.
*/
void audit_logger (int type, unused const char *pgname, const char *op,
void audit_logger (int type, MAYBE_UNUSED const char *pgname, const char *op,
const char *name, unsigned int id,
shadow_audit_result result)
{

View File

@@ -39,7 +39,7 @@ static int run_btrfs_subvolume_cmd(const char *subcmd, const char *arg1, const c
NULL
};
if (access(cmd, X_OK)) {
if (!cmd || access(cmd, X_OK)) {
return 1;
}

15
lib/cast.h Normal file
View File

@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHADOW_INCLUDE_LIB_CAST_H_
#define SHADOW_INCLUDE_LIB_CAST_H_
#include <config.h>
#define const_cast(T, p) _Generic(p, const T: (T) (p))
#endif // include guard

141
lib/chkname.c Normal file
View File

@@ -0,0 +1,141 @@
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
// SPDX-FileCopyrightText: 2001-2005, Tomasz Kłoczko
// SPDX-FileCopyrightText: 2005-2008, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause
/*
* is_valid_user_name(), is_valid_group_name() - check the new user/group
* name for validity;
* return values:
* true - OK
* false - bad name
* errors:
* EINVAL Invalid name characters or sequences
* EOVERFLOW Name longer than maximum size
*/
#include <config.h>
#ident "$Id$"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/param.h>
#include <unistd.h>
#include "defines.h"
#include "chkname.h"
#include "string/strcmp/streq.h"
int allow_bad_names = false;
size_t
login_name_max_size(void)
{
long conf;
errno = 0;
conf = sysconf(_SC_LOGIN_NAME_MAX);
if (conf == -1 && errno != 0)
return LOGIN_NAME_MAX;
return MIN(conf, PTRDIFF_MAX);
}
static bool
is_valid_name(const char *name)
{
if (allow_bad_names) {
return true;
}
/*
* User/group names must match BRE regex:
* [a-zA-Z0-9_.][a-zA-Z0-9_.-]*$\?
*
* as a non-POSIX, extension, allow "$" as the last char for
* sake of Samba 3.x "add machine script"
*
* Also do not allow fully numeric names or just "." or "..".
*/
int numeric;
if ('\0' == *name ||
('.' == *name && (('.' == name[1] && '\0' == name[2]) ||
'\0' == name[1])) ||
!((*name >= 'a' && *name <= 'z') ||
(*name >= 'A' && *name <= 'Z') ||
(*name >= '0' && *name <= '9') ||
*name == '_' ||
*name == '.'))
{
errno = EINVAL;
return false;
}
numeric = isdigit(*name);
while (!streq(++name, "")) {
if (!((*name >= 'a' && *name <= 'z') ||
(*name >= 'A' && *name <= 'Z') ||
(*name >= '0' && *name <= '9') ||
*name == '_' ||
*name == '.' ||
*name == '-' ||
(*name == '$' && name[1] == '\0')
))
{
errno = EINVAL;
return false;
}
numeric &= isdigit(*name);
}
if (numeric) {
errno = EINVAL;
return false;
}
return true;
}
bool
is_valid_user_name(const char *name)
{
if (strlen(name) >= login_name_max_size()) {
errno = EOVERFLOW;
return false;
}
return is_valid_name(name);
}
bool
is_valid_group_name(const char *name)
{
/*
* Arbitrary limit for group names.
* HP-UX 10 limits to 16 characters
*/
if ( (GROUP_NAME_MAX_LENGTH > 0)
&& (strlen (name) > GROUP_NAME_MAX_LENGTH))
{
errno = EOVERFLOW;
return false;
}
return is_valid_name (name);
}

View File

@@ -11,6 +11,7 @@
#ifndef _CHKNAME_H_
#define _CHKNAME_H_
/*
* is_valid_user_name(), is_valid_group_name() - check the new user/group
* name for validity;
@@ -19,8 +20,14 @@
* false - bad name
*/
#include "defines.h"
#include <config.h>
#include <stdbool.h>
#include <stddef.h>
extern size_t login_name_max_size(void);
extern bool is_valid_user_name (const char *name);
extern bool is_valid_group_name (const char *name);

View File

@@ -13,12 +13,15 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "prototypes.h"
#include "defines.h"
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "defines.h"
#include "prototypes.h"
#include "string/strcmp/streq.h"
static int chown_tree_at (int at_fd,
const char *path,
uid_t old_uid,
@@ -56,8 +59,8 @@ static int chown_tree_at (int at_fd,
/*
* Skip the "." and ".." entries
*/
if ( (strcmp (ent->d_name, ".") == 0)
|| (strcmp (ent->d_name, "..") == 0)) {
if ( streq(ent->d_name, ".")
|| streq(ent->d_name, "..")) {
continue;
}

Some files were not shown because too many files have changed in this diff Show More