Skip to content

Commit

Permalink
lib/, libsubid/, po/, src/: get_gid(): Move function to "atoi/getnum.h"
Browse files Browse the repository at this point in the history
Implement it as an inline function, and add restrict and ATTR_STRING()
and ATTR_ACCESS() as appropriate.

Reviewed-by: "Serge E. Hallyn" <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Jun 29, 2024
1 parent 74a2ed4 commit f85a07f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ libshadow_la_SOURCES = \
alloc.h \
atoi/a2i.c \
atoi/a2i.h \
atoi/getnum.c \
atoi/getnum.h \
atoi/str2i.c \
atoi/str2i.h \
atoi/strtoi.c \
Expand Down Expand Up @@ -71,7 +73,6 @@ libshadow_la_SOURCES = \
find_new_sub_gids.c \
find_new_sub_uids.c \
fputsx.c \
get_gid.c \
get_pid.c \
get_uid.c \
getdate.h \
Expand Down
13 changes: 13 additions & 0 deletions lib/atoi/getnum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2009, Nicolas François
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#include <config.h>

#include <sys/types.h>

#include "atoi/getnum.h"


extern inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);
20 changes: 15 additions & 5 deletions lib/get_gid.c → lib/atoi/getnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
// SPDX-License-Identifier: BSD-3-Clause


#include <config.h>
#ifndef SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_
#define SHADOW_INCLUDE_LIB_ATOI_GETNUM_H_


#ident "$Id$"
#include <config.h>

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

#include "prototypes.h"
#include "atoi/a2i.h"
#include "attr.h"
#include "typetraits.h"


int
get_gid(const char *gidstr, gid_t *gid)
ATTR_STRING(1) ATTR_ACCESS(write_only, 2)
inline int get_gid(const char *restrict gidstr, gid_t *restrict gid);


inline int
get_gid(const char *restrict gidstr, gid_t *restrict gid)
{
return a2i(gid_t, gid, gidstr, NULL, 10, type_min(gid_t), type_max(gid_t));
}


#endif // include guard
4 changes: 0 additions & 4 deletions lib/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ extern int find_new_sub_gids (gid_t *range_start, unsigned long *range_count);
extern int find_new_sub_uids (uid_t *range_start, unsigned long *range_count);
#endif /* ENABLE_SUBIDS */


/* get_gid.c */
extern int get_gid (const char *gidstr, gid_t *gid);

/* getgr_nam_gid.c */
extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname);

Expand Down
2 changes: 2 additions & 0 deletions lib/sgetgrent.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include <string.h>

#include "alloc.h"
#include "atoi/getnum.h"
#include "defines.h"
#include "prototypes.h"


#define NFIELDS 4

/*
Expand Down
2 changes: 2 additions & 0 deletions lib/sgetpwent.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include <pwd.h>
#include <string.h>

#include "atoi/getnum.h"
#include "defines.h"
#include "prototypes.h"
#include "shadowlog_internal.h"


#define NFIELDS 7

/*
Expand Down
2 changes: 2 additions & 0 deletions libsubid/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
#include <string.h>
#include <pwd.h>
#include <stdbool.h>

#include "subordinateio.h"
#include "idmapping.h"
#include "subid.h"
#include "shadowlog.h"


bool subid_init(const char *progname, FILE * logfd)
{
FILE *shadow_logfd;
Expand Down
1 change: 0 additions & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ lib/find_new_sub_gids.c
lib/find_new_sub_uids.c
lib/find_new_uid.c
lib/fputsx.c
lib/get_gid.c
lib/get_uid.c
lib/getdef.c
lib/getgr_nam_gid.c
Expand Down
3 changes: 3 additions & 0 deletions src/groupadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <pwd.h>
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */

#include "atoi/getnum.h"
#include "chkname.h"
#include "defines.h"
#include "getdef.h"
Expand All @@ -37,6 +39,7 @@
#include "shadowlog.h"
#include "run_part.h"


/*
* exit status values
*/
Expand Down
3 changes: 3 additions & 0 deletions src/groupmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif /* ACCT_TOOLS_SETUID */

#include "alloc.h"
#include "atoi/getnum.h"
#include "chkname.h"
#include "defines.h"
#include "groupio.h"
Expand All @@ -40,6 +41,8 @@
#include "shadowlog.h"
#include "string/stpecpy.h"
#include "string/stpeprintf.h"


/*
* exit status values
*/
Expand Down
1 change: 1 addition & 0 deletions src/newusers.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <string.h>

#include "alloc.h"
#include "atoi/getnum.h"
#include "atoi/str2i.h"
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
Expand Down

0 comments on commit f85a07f

Please sign in to comment.