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