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