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
93eb022
lib/shadow/group/sgetgrent.c: Move free(3) call outside of helper
alejandro-colomar Jun 10, 2025
7fe5662
lib/shadow/gshadow/sgetsgent.c: Don't exit from library code
alejandro-colomar Jun 10, 2025
2831c42
lib/, src/: Use more readable syntax for empty loops
alejandro-colomar Jun 10, 2025
35befcc
lib/: Deduplicate code
alejandro-colomar Jun 10, 2025
ceb4fa6
lib/list.c: comma_to_list(): Allow a trailing comma
alejandro-colomar Jun 10, 2025
3726f1a
lib/list.c: comma_to_list(): Use xastrsep2ls() instead of its pattern
alejandro-colomar Jun 10, 2025
dcc2f6f
lib/shadow/group/sgetgrent.c: Remove redundant code
alejandro-colomar Jun 10, 2025
f5b4551
lib/list.c: comma_to_list(): Use build_list() instead of its pattern
alejandro-colomar Jun 10, 2025
e2e8660
lib/: Rename build_list() => acsv2ls()
alejandro-colomar Jun 13, 2025
df8d071
lib/, src/: Move list.c prototypes to new file list.h
alejandro-colomar Sep 28, 2025
6eb89b1
lib/list.[ch]: csv2ls(): Add non-allocating version of acsv2ls()
alejandro-colomar Sep 28, 2025
52ab696
lib/, src/: Remove ISO_C_forbids_an_empty_translation_unit
alejandro-colomar Sep 29, 2025
2c1784c
lib/shadow/subid/: sgetsient(): Add function
alejandro-colomar Sep 29, 2025
3c4d20f
lib/shadow/: Remove redundant code
alejandro-colomar Sep 29, 2025
c0d5f11
lib/shadow/: Update comments
alejandro-colomar Sep 29, 2025
3229666
lib/shadow/: Reduce scope of conditional compilation block
alejandro-colomar Sep 29, 2025
b04bf73
lib/shadow/: Reduce scope of static variable
alejandro-colomar Sep 29, 2025
23cb3e5
lib/shadow/: Explicitly allocate space for lists
alejandro-colomar Sep 29, 2025
6366940
lib/shadow/: Rename local variable
alejandro-colomar Sep 29, 2025
c584518
lib/shadow/: Allocate and copy the string in separate steps
alejandro-colomar Sep 29, 2025
f16a0a8
lib/shadow/: Copy the string with strtcpy(), and malloc(3) the buffer
alejandro-colomar Sep 29, 2025
e924d4b
lib/shadow/: Use a single allocation
alejandro-colomar Sep 29, 2025
a70fe56
lib/shadow/: Rename local variable for consistency
alejandro-colomar Sep 29, 2025
cbb3b63
lib/shadow/: Use pointer to structure
alejandro-colomar Sep 29, 2025
9702ec6
lib/typetraits.h: is_aligned(): Add macro
alejandro-colomar Sep 29, 2025
246838b
lib/shadow/: Add re-entrant functions
alejandro-colomar Sep 28, 2025
ab0167b
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 @@ -65,7 +65,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 @@ -106,6 +106,7 @@ libshadow_la_SOURCES = \
isexpired.c \
limits.c \
list.c \
list.h \
lockpw.c \
loginprompt.c \
mail.c \
Expand Down Expand Up @@ -175,6 +176,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 @@ -77,6 +77,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 @@ -128,8 +128,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 @@ -330,7 +330,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 @@ -400,7 +401,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_T(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,20 +17,19 @@

#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.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 @@ -524,8 +523,4 @@ void setup_limits (const struct passwd *info)
}
}
}

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

64 changes: 43 additions & 21 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_T(i + 1, char *);

Expand Down Expand Up @@ -198,7 +202,6 @@ comma_to_list(const char *comma)
{
char *members;
char **array;
size_t n;

assert (NULL != comma);

Expand All @@ -208,26 +211,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_T(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;

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

return array;
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;
}
25 changes: 25 additions & 0 deletions lib/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 void free_list (char **);
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 */
8 changes: 0 additions & 8 deletions lib/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,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 void free_list (char **);
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 @@ -36,6 +36,4 @@ passwd_check(const char *user, const char *passwd)
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 @@ -204,7 +204,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_T(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_T(i + 1, char *);
/*@=mustfreeonly@*/
Expand Down Expand Up @@ -308,6 +310,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