Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3ed5c07
lib/shadow/group/sgetgrent.c: Move free(3) call outside of helper
alejandro-colomar Jun 10, 2025
a5f67fa
lib/shadow/gshadow/sgetsgent.c: Don't exit from library code
alejandro-colomar Jun 10, 2025
b148e9e
lib/, src/: Use more readable syntax for empty loops
alejandro-colomar Jun 10, 2025
35f0cf9
lib/: Deduplicate code
alejandro-colomar Jun 10, 2025
aecafd2
lib/list.c: comma_to_list(): Allow a trailing comma
alejandro-colomar Jun 10, 2025
dbaa72c
lib/list.c: comma_to_list(): Use xastrsep2ls() instead of its pattern
alejandro-colomar Jun 10, 2025
904bbf6
lib/shadow/group/sgetgrent.c: Remove redundant code
alejandro-colomar Jun 10, 2025
0e6a184
lib/list.c: comma_to_list(): Use build_list() instead of its pattern
alejandro-colomar Jun 10, 2025
4e16128
lib/: Rename build_list() => acsv2ls()
alejandro-colomar Jun 13, 2025
df842fb
lib/, src/: Move list.c prototypes to new file list.h
alejandro-colomar Sep 28, 2025
d619abb
lib/list.[ch]: csv2ls(): Add non-allocating version of acsv2ls()
alejandro-colomar Sep 28, 2025
f4c4f48
lib/, src/: Remove ISO_C_forbids_an_empty_translation_unit
alejandro-colomar Sep 29, 2025
8bcc6b6
lib/shadow/subid/: sgetsient(): Add function
alejandro-colomar Sep 29, 2025
cb5ebf8
lib/shadow/: Remove redundant code
alejandro-colomar Sep 29, 2025
e42d964
lib/shadow/: Update comments
alejandro-colomar Sep 29, 2025
9ea1c88
lib/shadow/: Reduce scope of conditional compilation block
alejandro-colomar Sep 29, 2025
744e05c
lib/shadow/: Reduce scope of static variable
alejandro-colomar Sep 29, 2025
605cd02
lib/shadow/: Explicitly allocate space for lists
alejandro-colomar Sep 29, 2025
dbc3b05
lib/shadow/: Rename local variable
alejandro-colomar Sep 29, 2025
71b98cc
lib/shadow/: Allocate and copy the string in separate steps
alejandro-colomar Sep 29, 2025
a54ec59
lib/shadow/: Copy the string with strtcpy(), and malloc(3) the buffer
alejandro-colomar Sep 29, 2025
7a9ebac
lib/shadow/: Use a single allocation
alejandro-colomar Sep 29, 2025
e93187d
lib/shadow/: Rename local variable for consistency
alejandro-colomar Sep 29, 2025
26ac72e
lib/shadow/: Use pointer to structure
alejandro-colomar Sep 29, 2025
1dbd8a0
lib/typetraits.h: is_aligned(): Add macro
alejandro-colomar Sep 29, 2025
ef47663
lib/shadow/: Add re-entrant functions
alejandro-colomar Sep 28, 2025
c46eacc
Revert "lib/shadow/: Use pointer to structure"
alejandro-colomar Sep 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ AC_CHECK_MEMBERS([struct utmpx.ut_name,
dnl Checks for library functions.
AC_FUNC_UTIME_NULL
AC_REPLACE_FUNCS([putgrent putpwent putspent])
AC_REPLACE_FUNCS([sgetgrent sgetpwent sgetspent])
AC_REPLACE_FUNCS([sgetgrent sgetpwent sgetspent sgetspent_r])

AC_CHECK_FUNC([setpgrp])
AC_CHECK_FUNC([secure_getenv],
Expand Down
3 changes: 3 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ libshadow_la_SOURCES = \
isexpired.c \
limits.c \
list.c \
list.h \
lockpw.c \
loginprompt.c \
mail.c \
Expand Down Expand Up @@ -190,6 +191,8 @@ libshadow_la_SOURCES = \
shadow/passwd/sgetpwent.h \
shadow/shadow/sgetspent.c \
shadow/shadow/sgetspent.h \
shadow/subid/sgetsient.c \
shadow/subid/sgetsient.h \
shadowio.c \
shadowio.h \
shadowlog.c \
Expand Down
2 changes: 0 additions & 2 deletions lib/addgrps.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,4 @@ add_groups(const char *list)
free(gids);
return -1;
}
#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !USE_PAM */
3 changes: 2 additions & 1 deletion lib/age.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ int expire (const struct passwd *pw, /*@null@*/const struct spwd *sp)
exit (EXIT_FAILURE);
}

while (((child = wait (&status)) != pid) && (child != (pid_t)-1));
while (((child = wait (&status)) != pid) && (child != (pid_t)-1))
continue;

if ((child == pid) && (0 == status)) {
return 1;
Expand Down
4 changes: 0 additions & 4 deletions lib/audit_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,4 @@ void audit_logger_message (const char *message, shadow_audit_result result)
result);
}
}

#else /* WITH_AUDIT */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* WITH_AUDIT */

3 changes: 2 additions & 1 deletion lib/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void add_cleanup (/*@notnull@*/cleanup_function pcf, /*@null@*/void *arg)
}

/* Add the cleanup_function at the end of the stack */
for (i=0; NULL != cleanup_functions[i]; i++);
for (i=0; NULL != cleanup_functions[i]; i++)
continue;
cleanup_functions[i] = pcf;
cleanup_function_args[i] = arg;
}
Expand Down
3 changes: 0 additions & 3 deletions lib/find_new_sub_gids.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,4 @@ int find_new_sub_gids (gid_t *range_start, unsigned long *range_count)
*range_count = count;
return 0;
}
#else /* !ENABLE_SUBIDS */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !ENABLE_SUBIDS */

3 changes: 0 additions & 3 deletions lib/find_new_sub_uids.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,4 @@ int find_new_sub_uids (uid_t *range_start, unsigned long *range_count)
*range_count = count;
return 0;
}
#else /* !ENABLE_SUBIDS */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !ENABLE_SUBIDS */

6 changes: 4 additions & 2 deletions lib/groupio.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ static /*@null@*/struct commonio_entry *merge_group_entries (
return NULL;

/* Concatenate the 2 list of members */
for (i=0; NULL != gptr1->gr_mem[i]; i++);
for (i=0; NULL != gptr1->gr_mem[i]; i++)
continue;
members += i;
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
char **pmember = gptr1->gr_mem;
Expand Down Expand Up @@ -402,7 +403,8 @@ static int split_groups (unsigned int max_members)
if (NULL == gptr) {
continue;
}
for (members = 0; NULL != gptr->gr_mem[members]; members++);
for (members = 0; NULL != gptr->gr_mem[members]; members++)
continue;
if (members <= max_members) {
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/groupmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
return NULL;
}

for (i = 0; grent->gr_mem[i]; i++);
for (i = 0; grent->gr_mem[i]; i++)
continue;

/*@-mustfreeonly@*/
gr->gr_mem = MALLOC(i + 1, char *);
Expand Down
21 changes: 8 additions & 13 deletions lib/limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@

#ifndef USE_PAM

#ident "$Id$"

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <ctype.h>
#include "prototypes.h"
#include "defines.h"
#include <pwd.h>
#include "getdef.h"
#include "shadowlog.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/resource.h>

#include "atoi/a2i/a2i.h"
#include "atoi/a2i/a2s.h"
#include "atoi/str2i.h"
#include "defines.h"
#include "list.h"
#include "getdef.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/memset/memzero.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
Expand Down Expand Up @@ -526,8 +525,4 @@ void setup_limits (const struct passwd *info)
}
}
}

#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !USE_PAM */

63 changes: 43 additions & 20 deletions lib/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@

#include "config.h"

#ident "$Id$"
#include "list.h"

#include <stddef.h>
#include <stdlib.h>
#include <sys/types.h>

#include <assert.h>

#include "alloc/malloc.h"
#include "prototypes.h"
#include "defines.h"
#include "string/strchr/strchrcnt.h"
#include "string/strcmp/streq.h"
#include "string/strdup/strdup.h"
#include "string/strtok/astrsep2ls.h"
#include "string/strtok/strsep2ls.h"


Expand Down Expand Up @@ -142,7 +145,8 @@ dup_list(char *const *list)

assert (NULL != list);

for (i = 0; NULL != list[i]; i++);
for (i = 0; NULL != list[i]; i++)
continue;

tmp = XMALLOC(i + 1, char *);

Expand Down Expand Up @@ -197,26 +201,45 @@ comma_to_list(const char *comma)

members = xstrdup (comma);

/*
* Allocate the array we're going to store the pointers into.
* n: number of delimiters + last element + NULL
*/
array = acsv2ls(members);
if (array == NULL)
exit(EXIT_FAILURE);

n = strchrcnt(members, ',') + 2;
array = XMALLOC(n, char *);
if (array[0] == NULL)
free(members);

/*
* Empty list is special - 0 members, not 1 empty member. --marekm
*/
return array;
}

if (streq(members, "")) {
*array = NULL;
free (members);
return array;
}

strsep2ls(members, ",", n, array);
char **
acsv2ls(char *s)
{
char **l;
size_t n;

return array;
l = astrsep2ls(s, ",", &n);
if (l == NULL)
return NULL;

if (streq(l[n-1], ""))
l[n-1] = NULL;

return l;
}


int
csv2ls(char *s, size_t n, char *ls[restrict n])
{
ssize_t i;

i = strsep2ls(s, ",", n, ls);
if (i == -1)
return -1;

if (streq(ls[i-1], ""))
ls[i-1] = NULL;

return 0;
}
24 changes: 24 additions & 0 deletions lib/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_LIST_H_
#define SHADOW_INCLUDE_LIB_LIST_H_


#include "config.h"

#include <stdbool.h>
#include <stddef.h>


extern /*@only@*/char **add_list (/*@returned@*/ /*@only@*/char **, const char *);
extern /*@only@*/char **del_list (/*@returned@*/ /*@only@*/char **, const char *);
extern /*@only@*/char **dup_list (char *const *);
extern bool is_on_list (char *const *list, const char *member);
extern /*@only@*/char **comma_to_list (const char *);
extern char **acsv2ls(char *s);
extern int csv2ls(char *s, size_t n, char *ls[restrict n]);


#endif // include guard
2 changes: 0 additions & 2 deletions lib/lockpw.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,4 @@ int ulckpwdf (void)

return (pw_unlock (true) && spw_unlock (true))? 0 : -1;
}
#else
extern int ISO_C_forbids_an_empty_translation_unit;
#endif
3 changes: 0 additions & 3 deletions lib/nscd.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,4 @@ int nscd_flush_cache (const char *service)

return 0;
}
#else /* USE_NSCD */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* USE_NSCD */

2 changes: 0 additions & 2 deletions lib/pam_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,4 @@ void do_pam_passwd (const char *user, bool silent, bool change_expired)
fputs (_("passwd: password updated successfully\n"), shadow_logfd);
(void) pam_end (pamh, PAM_SUCCESS);
}
#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !USE_PAM */
2 changes: 0 additions & 2 deletions lib/pam_pass_non_interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,4 @@ int do_pam_passwd_non_interactive (const char *pam_service,

return ((PAM_SUCCESS == ret) ? 0 : 1);
}
#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !USE_PAM */
7 changes: 0 additions & 7 deletions lib/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,6 @@ void audit_logger_with_group(int type, const char *op, const char *name,
extern void setup_limits (const struct passwd *);
#endif

/* list.c */
extern /*@only@*/char **add_list (/*@returned@*/ /*@only@*/char **, const char *);
extern /*@only@*/char **del_list (/*@returned@*/ /*@only@*/char **, const char *);
extern /*@only@*/char **dup_list (char *const *);
extern bool is_on_list (char *const *list, const char *member);
extern /*@only@*/char **comma_to_list (const char *);

#ifdef ENABLE_LASTLOG
/* log.c */
extern void dolastlog (
Expand Down
2 changes: 0 additions & 2 deletions lib/pwauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,4 @@ pw_auth(const char *cipher, const char *user)

return retval;
}
#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !USE_PAM */
2 changes: 0 additions & 2 deletions lib/pwdcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ void passwd_check (const char *user, const char *passwd, MAYBE_UNUSED const char
exit (EXIT_FAILURE);
}
}
#else /* USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* USE_PAM */
3 changes: 0 additions & 3 deletions lib/selinux.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,4 @@ int check_selinux_permit (const char *perm_name)
freecon (user_context_raw);
return r;
}

#else /* !WITH_SELINUX */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !WITH_SELINUX */
2 changes: 0 additions & 2 deletions lib/semanage.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,4 @@ int del_seuser (const char *login_name)
semanage_handle_destroy (handle);
return ret;
}
#else /* !WITH_SELINUX */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* !WITH_SELINUX */
8 changes: 4 additions & 4 deletions lib/sgroupio.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
return NULL;
}

for (i = 0; NULL != sgent->sg_adm[i]; i++);
for (i = 0; NULL != sgent->sg_adm[i]; i++)
continue;
/*@-mustfreeonly@*/
sg->sg_adm = MALLOC(i + 1, char *);
/*@=mustfreeonly@*/
Expand All @@ -81,7 +82,8 @@
}
sg->sg_adm[i] = NULL;

for (i = 0; NULL != sgent->sg_mem[i]; i++);
for (i = 0; NULL != sgent->sg_mem[i]; i++)
continue;
/*@-mustfreeonly@*/
sg->sg_mem = MALLOC(i + 1, char *);
/*@=mustfreeonly@*/
Expand Down Expand Up @@ -310,6 +312,4 @@ int sgr_sort ()
{
return commonio_sort_wrt (&gshadow_db, __gr_get_db ());
}
#else
extern int ISO_C_forbids_an_empty_translation_unit;
#endif
Loading
Loading