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