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