Skip to content
Draft

ls #1272

Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ libshadow_la_SOURCES = \
isexpired.c \
limits.c \
list.c \
list.h \
lockpw.c \
loginprompt.c \
mail.c \
Expand Down
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
3 changes: 2 additions & 1 deletion lib/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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
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
17 changes: 8 additions & 9 deletions lib/limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@

#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 "io/fgets/fgets.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
50 changes: 28 additions & 22 deletions lib/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

#include "config.h"

#include "list.h"

#include <stddef.h>
#include <stdlib.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/strsep2ls.h"
#include "string/strtok/astrsep2ls.h"

#undef NDEBUG
#include <assert.h>
Expand Down Expand Up @@ -141,7 +144,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 @@ -197,7 +201,6 @@ comma_to_list(const char *comma)
{
char *members;
char **array;
size_t n;

assert (NULL != comma);

Expand All @@ -207,26 +210,29 @@ 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;
}
23 changes: 23 additions & 0 deletions lib/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_LIST_H_
#define SHADOW_INCLUDE_LIB_LIST_H_


#include "config.h"

#include <stdbool.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);


#endif // include guard
8 changes: 0 additions & 8 deletions lib/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,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
6 changes: 4 additions & 2 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
47 changes: 7 additions & 40 deletions lib/shadow/group/sgetgrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,17 @@

#include "alloc/malloc.h"
#include "atoi/getnum.h"
#include "defines.h"
#include "prototypes.h"
#include "string/strcmp/streq.h"
#include "list.h"
#include "string/strtok/stpsep.h"
#include "string/strtok/strsep2arr.h"
#include "string/strtok/astrsep2ls.h"


/*
* list - turn a comma-separated string into an array of (char *)'s
*
* list() converts the comma-separated list of member names into
* an array of character pointers.
*
* FINALLY added dynamic allocation. Still need to fix sgetsgent().
* --marekm
*/
static char **
list(char *s)
{
static char **members = NULL;

size_t n;

free(members);

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

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

return members;
}


// from-string get group entry
struct group *
sgetgrent(const char *s)
{
static char *dup = NULL;
static struct group grent;
static struct group grent = {};

char *fields[4];

Expand All @@ -74,15 +42,14 @@ sgetgrent(const char *s)
if (strsep2arr_a(dup, ":", fields) == -1)
return NULL;

if (streq(fields[2], ""))
return NULL;

grent.gr_name = fields[0];
grent.gr_passwd = fields[1];
if (get_gid(fields[2], &grent.gr_gid) == -1) {
if (get_gid(fields[2], &grent.gr_gid) == -1)
return NULL;
}
grent.gr_mem = list(fields[3]);

free(grent.gr_mem);

grent.gr_mem = acsv2ls(fields[3]);
if (NULL == grent.gr_mem) {
return NULL; /* out of memory */
}
Expand Down
27 changes: 6 additions & 21 deletions lib/shadow/gshadow/sgetsgent.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <stdlib.h>
#include <string.h>

#include "list.h"
#include "shadow/gshadow/sgrp.h"
#include "string/strcmp/streq.h"
#include "string/strtok/astrsep2ls.h"
#include "string/strtok/stpsep.h"
#include "string/strtok/strsep2arr.h"

Expand All @@ -25,9 +25,6 @@
static struct sgrp sgroup = {};


static char **build_list(char *s);


// from-string get shadow group entry
struct sgrp *
sgetsgent(const char *s)
Expand All @@ -52,24 +49,12 @@ sgetsgent(const char *s)
free(sgroup.sg_adm);
free(sgroup.sg_mem);

sgroup.sg_adm = build_list(fields[2]);
sgroup.sg_mem = build_list(fields[3]);

return &sgroup;
}

sgroup.sg_adm = acsv2ls(fields[2]);
sgroup.sg_mem = acsv2ls(fields[3]);

static char **
build_list(char *s)
{
char **l;
size_t n;

l = xastrsep2ls(s, ",", &n);

if (streq(l[n-1], ""))
l[n-1] = NULL;
if (sgroup.sg_adm == NULL || sgroup.sg_mem == NULL)
return NULL;

return l;
return &sgroup;
}
#endif
1 change: 1 addition & 0 deletions src/chgpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "defines.h"
#include "groupio.h"
#include "io/fprintf.h"
#include "list.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
Expand Down
1 change: 1 addition & 0 deletions src/gpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "exitcodes.h"
#include "groupio.h"
#include "io/fprintf.h"
#include "list.h"
#include "nscd.h"
#include "prototypes.h"
#ifdef SHADOWGRP
Expand Down
1 change: 1 addition & 0 deletions src/groupadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "groupio.h"
#include "io/fprintf.h"
#include "io/syslog.h"
#include "list.h"
#include "nscd.h"
#include "sssd.h"
#include "prototypes.h"
Expand Down
3 changes: 2 additions & 1 deletion src/groupdel.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ static void group_busy (gid_t gid)

prefix_setpwent ();

while ( ((pwd = prefix_getpwent ()) != NULL) && (pwd->pw_gid != gid) );
while ( ((pwd = prefix_getpwent ()) != NULL) && (pwd->pw_gid != gid) )
continue;

prefix_endpwent ();

Expand Down
1 change: 1 addition & 0 deletions src/groupmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "defines.h"
#include "groupio.h"
#include "io/fprintf.h"
#include "list.h"
#include "nscd.h"
#include "prototypes.h"
#include "pwio.h"
Expand Down
Loading
Loading