From c3332329aa79227c546e85e5c38fa027b2aba334 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 15:27:43 +0100 Subject: [PATCH 01/14] lib/shadow/gshadow/, lib/: putsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 4 +- lib/gshadow.c | 75 --------------------------- lib/gshadow_.h | 1 - lib/sgroupio.c | 1 + lib/shadow/gshadow/putsgent.c | 98 +++++++++++++++++++++++++++++++++++ lib/shadow/gshadow/putsgent.h | 26 ++++++++++ 6 files changed, 128 insertions(+), 77 deletions(-) create mode 100644 lib/shadow/gshadow/putsgent.c create mode 100644 lib/shadow/gshadow/putsgent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 307e70469..99de31076 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -171,10 +171,12 @@ libshadow_la_SOURCES = \ sgetpwent.c \ sgetspent.c \ sgroupio.c \ - sgroupio.h\ + sgroupio.h \ shadow.c \ shadow/grp/agetgroups.c \ shadow/grp/agetgroups.h \ + shadow/gshadow/putsgent.c \ + shadow/gshadow/putsgent.h \ shadowio.c \ shadowio.h \ shadowlog.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c index 2725e09eb..ebad86008 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -198,81 +198,6 @@ sgetsgent(const char *string) } return sgrp; } - -/* - * putsgent - output shadow group entry in text form - * - * putsgent() converts the contents of a (struct sgrp) to text and - * writes the result to the given stream. This is the logical - * opposite of fgetsgent. - */ - -int putsgent (const struct sgrp *sgrp, FILE * fp) -{ - char *buf, *cp; - int i; - size_t size; - - if ((NULL == fp) || (NULL == sgrp)) { - return -1; - } - - /* calculate the required buffer size */ - size = strlen (sgrp->sg_namp) + strlen (sgrp->sg_passwd) + 10; - for (i = 0; (NULL != sgrp->sg_adm) && (NULL != sgrp->sg_adm[i]); i++) { - size += strlen (sgrp->sg_adm[i]) + 1; - } - for (i = 0; (NULL != sgrp->sg_mem) && (NULL != sgrp->sg_mem[i]); i++) { - size += strlen (sgrp->sg_mem[i]) + 1; - } - - buf = MALLOC(size, char); - if (NULL == buf) { - return -1; - } - cp = buf; - - /* - * Copy the group name and passwd. - */ - cp = stpcpy(stpcpy(cp, sgrp->sg_namp), ":"); - cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":"); - - /* - * Copy the administrators, separating each from the other - * with a ",". - */ - for (i = 0; NULL != sgrp->sg_adm[i]; i++) { - if (i > 0) - cp = stpcpy(cp, ","); - - cp = stpcpy(cp, sgrp->sg_adm[i]); - } - cp = stpcpy(cp, ":"); - - /* - * Now do likewise with the group members. - */ - for (i = 0; NULL != sgrp->sg_mem[i]; i++) { - if (i > 0) - cp = stpcpy(cp, ","); - - cp = stpcpy(cp, sgrp->sg_mem[i]); - } - stpcpy(cp, "\n"); - - /* - * Output using the function which understands the line - * continuation conventions. - */ - if (fputsx (buf, fp) == EOF) { - free (buf); - return -1; - } - - free (buf); - return 0; -} #else extern int ISO_C_forbids_an_empty_translation_unit; #endif // !SHADOWGRP diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 2b38cb338..21fa21061 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -36,7 +36,6 @@ struct sgrp { /*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE *); void setsgent (void); void endsgent (void); -int putsgent (const struct sgrp *, FILE *); #define GSHADOW "/etc/gshadow" diff --git a/lib/sgroupio.c b/lib/sgroupio.c index 980576124..ae0fe1439 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -21,6 +21,7 @@ #include "commonio.h" #include "getdef.h" #include "sgroupio.h" +#include "shadow/gshadow/putsgent.h" #include "string/memset/memzero.h" diff --git a/lib/shadow/gshadow/putsgent.c b/lib/shadow/gshadow/putsgent.c new file mode 100644 index 000000000..51d6552cf --- /dev/null +++ b/lib/shadow/gshadow/putsgent.c @@ -0,0 +1,98 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/putsgent.h" + +#include +#include +#include +#include + +#include "alloc/malloc.h" +#include "prototypes.h" + + +/* + * putsgent - output shadow group entry in text form + * + * putsgent() converts the contents of a (struct sgrp) to text and + * writes the result to the given stream. This is the logical + * opposite of fgetsgent. + */ +#if defined(SHADOWGRP) && !__has_include() +// put shadow group entry +int +putsgent(const struct sgrp *sgrp, FILE *fp) +{ + char *buf, *cp; + int i; + size_t size; + + if ((NULL == fp) || (NULL == sgrp)) { + return -1; + } + + /* calculate the required buffer size */ + size = strlen (sgrp->sg_namp) + strlen (sgrp->sg_passwd) + 10; + for (i = 0; (NULL != sgrp->sg_adm) && (NULL != sgrp->sg_adm[i]); i++) { + size += strlen (sgrp->sg_adm[i]) + 1; + } + for (i = 0; (NULL != sgrp->sg_mem) && (NULL != sgrp->sg_mem[i]); i++) { + size += strlen (sgrp->sg_mem[i]) + 1; + } + + buf = MALLOC(size, char); + if (NULL == buf) { + return -1; + } + cp = buf; + + /* + * Copy the group name and passwd. + */ + cp = stpcpy(stpcpy(cp, sgrp->sg_namp), ":"); + cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":"); + + /* + * Copy the administrators, separating each from the other + * with a ",". + */ + for (i = 0; NULL != sgrp->sg_adm[i]; i++) { + if (i > 0) + cp = stpcpy(cp, ","); + + cp = stpcpy(cp, sgrp->sg_adm[i]); + } + cp = stpcpy(cp, ":"); + + /* + * Now do likewise with the group members. + */ + for (i = 0; NULL != sgrp->sg_mem[i]; i++) { + if (i > 0) + cp = stpcpy(cp, ","); + + cp = stpcpy(cp, sgrp->sg_mem[i]); + } + stpcpy(cp, "\n"); + + /* + * Output using the function which understands the line + * continuation conventions. + */ + if (fputsx (buf, fp) == EOF) { + free (buf); + return -1; + } + + free (buf); + return 0; +} +#endif diff --git a/lib/shadow/gshadow/putsgent.h b/lib/shadow/gshadow/putsgent.h new file mode 100644 index 000000000..348ebab81 --- /dev/null +++ b/lib/shadow/gshadow/putsgent.h @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_PUTSGENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_PUTSGENT_H_ + + +#include + +#include + +#include "gshadow_.h" + + +#if __has_include() +# include +#else +int putsgent(const struct sgrp *sgrp, FILE *fp); +#endif + + +#endif // include guard From c9a10a880a50910ec62b3855c573b65782e2959f Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 16:22:12 +0100 Subject: [PATCH 02/14] lib/shadow/gshadow/, lib/: gshadow: Move to separate file and rename Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 ++ lib/gshadow.c | 18 +++++++++--------- lib/shadow/gshadow/gshadow.c | 17 +++++++++++++++++ lib/shadow/gshadow/gshadow.h | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 lib/shadow/gshadow/gshadow.c create mode 100644 lib/shadow/gshadow/gshadow.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 99de31076..b12edf092 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -175,6 +175,8 @@ libshadow_la_SOURCES = \ shadow.c \ shadow/grp/agetgroups.c \ shadow/grp/agetgroups.h \ + shadow/gshadow/gshadow.c \ + shadow/gshadow/gshadow.h \ shadow/gshadow/putsgent.c \ shadow/gshadow/putsgent.h \ shadowio.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c index ebad86008..e85bdba8f 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -22,12 +22,12 @@ #include "alloc/x/xmalloc.h" #include "defines.h" #include "prototypes.h" +#include "shadow/gshadow/gshadow.h" #include "string/strchr/strchrcnt.h" #include "string/strcmp/streq.h" #include "string/strtok/stpsep.h" -static /*@null@*/FILE *shadow; static struct sgrp sgroup = {}; #define FIELDS 4 @@ -51,20 +51,20 @@ build_list(char *s) void setsgent (void) { - if (NULL != shadow) { - rewind (shadow); + if (NULL != gshadow) { + rewind(gshadow); } else { - shadow = fopen (SGROUP_FILE, "re"); + gshadow = fopen(SGROUP_FILE, "re"); } } void endsgent (void) { - if (NULL != shadow) { - (void) fclose (shadow); + if (NULL != gshadow) { + fclose(gshadow); } - shadow = NULL; + gshadow = NULL; } /*@observer@*//*@null@*/struct sgrp * @@ -175,10 +175,10 @@ sgetsgent(const char *string) /*@observer@*//*@null@*/struct sgrp *getsgent (void) { - if (NULL == shadow) { + if (NULL == gshadow) { setsgent (); } - return (fgetsgent (shadow)); + return fgetsgent(gshadow); } /* diff --git a/lib/shadow/gshadow/gshadow.c b/lib/shadow/gshadow/gshadow.c new file mode 100644 index 000000000..ea81486a9 --- /dev/null +++ b/lib/shadow/gshadow/gshadow.c @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/gshadow.h" + +#include +#include + + +FILE *gshadow = NULL; diff --git a/lib/shadow/gshadow/gshadow.h b/lib/shadow/gshadow/gshadow.h new file mode 100644 index 000000000..3962492f6 --- /dev/null +++ b/lib/shadow/gshadow/gshadow.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_GSHADOW_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_GSHADOW_H_ + + +#include + +#include + +#include "shadow/gshadow/gshadow.h" + + +extern FILE *gshadow; + + +#endif // include guard From 1811620d38ec38379baa2f449e17f126a34eb58d Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 16:48:15 +0100 Subject: [PATCH 03/14] lib/shadow/gshadow/, lib/, src/: endsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 ++ lib/age.c | 1 + lib/gshadow.c | 9 --------- lib/gshadow_.h | 1 - lib/shadow/gshadow/endsgent.c | 30 ++++++++++++++++++++++++++++++ lib/shadow/gshadow/endsgent.h | 22 ++++++++++++++++++++++ src/login.c | 1 + src/newgrp.c | 1 + src/usermod.c | 1 + 9 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 lib/shadow/gshadow/endsgent.c create mode 100644 lib/shadow/gshadow/endsgent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index b12edf092..3c9286849 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -175,6 +175,8 @@ libshadow_la_SOURCES = \ shadow.c \ shadow/grp/agetgroups.c \ shadow/grp/agetgroups.h \ + shadow/gshadow/endsgent.c \ + shadow/gshadow/endsgent.h \ shadow/gshadow/gshadow.c \ shadow/gshadow/gshadow.h \ shadow/gshadow/putsgent.c \ diff --git a/lib/age.c b/lib/age.c index ff2aebe2b..b7ad6bcf7 100644 --- a/lib/age.c +++ b/lib/age.c @@ -20,6 +20,7 @@ #include "defines.h" #include "exitcodes.h" #include "prototypes.h" +#include "shadow/gshadow/endsgent.h" #ident "$Id$" diff --git a/lib/gshadow.c b/lib/gshadow.c index e85bdba8f..731ea0f45 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -58,15 +58,6 @@ void setsgent (void) } } -void endsgent (void) -{ - if (NULL != gshadow) { - fclose(gshadow); - } - - gshadow = NULL; -} - /*@observer@*//*@null@*/struct sgrp * sgetsgent(const char *string) { diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 21fa21061..618e04369 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -35,7 +35,6 @@ struct sgrp { /*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *); /*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE *); void setsgent (void); -void endsgent (void); #define GSHADOW "/etc/gshadow" diff --git a/lib/shadow/gshadow/endsgent.c b/lib/shadow/gshadow/endsgent.c new file mode 100644 index 000000000..284f3b2f2 --- /dev/null +++ b/lib/shadow/gshadow/endsgent.c @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/endsgent.h" + +#include +#include + +#include "shadow/gshadow/gshadow.h" + + +#if defined(SHADOWGRP) && !__has_include() +// end-working-with shadow group entries +void +endsgent(void) +{ + if (NULL != gshadow) { + fclose(gshadow); + } + + gshadow = NULL; +} +#endif diff --git a/lib/shadow/gshadow/endsgent.h b/lib/shadow/gshadow/endsgent.h new file mode 100644 index 000000000..056b4a70a --- /dev/null +++ b/lib/shadow/gshadow/endsgent.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_ENDSGENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_ENDSGENT_H_ + + +#include + + +#if __has_include() +# include +#else +void endsgent(void); +#endif + + +#endif // include guard diff --git a/src/login.c b/src/login.c index 2866b1523..322398dc3 100644 --- a/src/login.c +++ b/src/login.c @@ -37,6 +37,7 @@ #include "getdef.h" #include "prototypes.h" #include "pwauth.h" +#include "shadow/gshadow/endsgent.h" #include "shadowlog.h" #include "string/memset/memzero.h" #include "string/sprintf/snprintf.h" diff --git a/src/newgrp.c b/src/newgrp.c index 905ac2f4c..5426704dc 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -27,6 +27,7 @@ #include "search/l/lfind.h" #include "search/l/lsearch.h" #include "shadow/grp/agetgroups.h" +#include "shadow/gshadow/endsgent.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" diff --git a/src/usermod.c b/src/usermod.c index 22113daaa..36212a252 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -60,6 +60,7 @@ #ifdef WITH_TCB #include "tcbfuncs.h" #endif +#include "shadow/gshadow/endsgent.h" #include "shadowlog.h" #include "sssd.h" #include "string/memset/memzero.h" From 42b2c2c9f09be948a870b562909198ef89e6c60f Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 17:36:44 +0100 Subject: [PATCH 04/14] lib/shadow/gshadow/gshadow.h, lib/, src/: GSHADOW_FILE: Move definition and rename it Rename it for consistency with the file name itself, and with the FILE* variable that holds the handle to the open file. Also, we don't need to wrap it in conditionals. Just define it unconditionally, and let it be unused if we don't need it. Signed-off-by: Alejandro Colomar --- lib/defines.h | 6 ------ lib/gshadow.c | 2 +- lib/prefix_flag.c | 3 ++- lib/sgroupio.c | 3 ++- lib/shadow/gshadow/gshadow.h | 3 +++ src/grpck.c | 4 +++- src/grpunconv.c | 7 ++++--- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/defines.h b/lib/defines.h index 89300c93c..db74f72ef 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -164,12 +164,6 @@ #define SUBGID_FILE "/etc/subgid" #endif -#ifdef SHADOWGRP -#ifndef SGROUP_FILE -#define SGROUP_FILE "/etc/gshadow" -#endif -#endif - /* * string to use for the pw_passwd field in /etc/passwd when using * shadow passwords - most systems use "x" but there are a few diff --git a/lib/gshadow.c b/lib/gshadow.c index 731ea0f45..19b3528fe 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -54,7 +54,7 @@ void setsgent (void) if (NULL != gshadow) { rewind(gshadow); } else { - gshadow = fopen(SGROUP_FILE, "re"); + gshadow = fopen(GSHADOW_FILE, "re"); } } diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index c09b8d082..38491986d 100644 --- a/lib/prefix_flag.c +++ b/lib/prefix_flag.c @@ -27,6 +27,7 @@ #include "subordinateio.h" #endif /* ENABLE_SUBIDS */ #include "getdef.h" +#include "shadow/gshadow/gshadow.h" #include "shadowlog.h" #include "string/sprintf/xasprintf.h" #include "string/strcmp/streq.h" @@ -116,7 +117,7 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** gr_setdbname(group_db_file); #ifdef SHADOWGRP - xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE); + xasprintf(&sgroup_db_file, "%s/%s", prefix, GSHADOW_FILE); sgr_setdbname(sgroup_db_file); #endif diff --git a/lib/sgroupio.c b/lib/sgroupio.c index ae0fe1439..51eac1b7f 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -21,6 +21,7 @@ #include "commonio.h" #include "getdef.h" #include "sgroupio.h" +#include "shadow/gshadow/gshadow.h" #include "shadow/gshadow/putsgent.h" #include "string/memset/memzero.h" @@ -205,7 +206,7 @@ static struct commonio_ops gshadow_ops = { }; static struct commonio_db gshadow_db = { - SGROUP_FILE, /* filename */ + GSHADOW_FILE, /* filename */ &gshadow_ops, /* ops */ NULL, /* fp */ #ifdef WITH_SELINUX diff --git a/lib/shadow/gshadow/gshadow.h b/lib/shadow/gshadow/gshadow.h index 3962492f6..3786f6ddb 100644 --- a/lib/shadow/gshadow/gshadow.h +++ b/lib/shadow/gshadow/gshadow.h @@ -16,6 +16,9 @@ #include "shadow/gshadow/gshadow.h" +#define GSHADOW_FILE "/etc/gshadow" + + extern FILE *gshadow; diff --git a/src/grpck.c b/src/grpck.c index d3f2baee6..342431dfb 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -22,6 +22,7 @@ #include "groupio.h" #include "nscd.h" #include "prototypes.h" +#include "shadow/gshadow/gshadow.h" #include "shadowlog.h" #include "sssd.h" #include "string/strcmp/streq.h" @@ -30,6 +31,7 @@ #include "sgroupio.h" #endif + /* * Exit codes */ @@ -51,7 +53,7 @@ static const char *grp_file = GROUP_FILE; static bool use_system_grp_file = true; #ifdef SHADOWGRP -static const char *sgr_file = SGROUP_FILE; +static const char *sgr_file = GSHADOW_FILE; static bool use_system_sgr_file = true; static bool is_shadow = false; static bool sgr_locked = false; diff --git a/src/grpunconv.c b/src/grpunconv.c index ea65a329f..e54b2a96e 100644 --- a/src/grpunconv.c +++ b/src/grpunconv.c @@ -36,6 +36,7 @@ #ifdef SHADOWGRP #include "groupio.h" #include "sgroupio.h" +#include "shadow/gshadow/gshadow.h" #include "shadowlog.h" @@ -201,11 +202,11 @@ int main (int argc, char **argv) fail_exit (3); } - if (unlink (SGROUP_FILE) != 0) { + if (unlink(GSHADOW_FILE) != 0) { fprintf (stderr, _("%s: cannot delete %s\n"), - Prog, SGROUP_FILE); - SYSLOG ((LOG_ERR, "cannot delete %s", SGROUP_FILE)); + Prog, GSHADOW_FILE); + SYSLOG((LOG_ERR, "cannot delete %s", GSHADOW_FILE)); fail_exit (3); } From 9f4bd4d3a9ea8347b7a287e9958362c89eefacde Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 17:44:23 +0100 Subject: [PATCH 05/14] lib/shadow/gshadow/, lib/: setsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 ++ lib/gshadow.c | 10 +--------- lib/gshadow_.h | 1 - lib/shadow/gshadow/setsgent.c | 30 ++++++++++++++++++++++++++++++ lib/shadow/gshadow/setsgent.h | 22 ++++++++++++++++++++++ 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 lib/shadow/gshadow/setsgent.c create mode 100644 lib/shadow/gshadow/setsgent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 3c9286849..38e38292e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -181,6 +181,8 @@ libshadow_la_SOURCES = \ shadow/gshadow/gshadow.h \ shadow/gshadow/putsgent.c \ shadow/gshadow/putsgent.h \ + shadow/gshadow/setsgent.c \ + shadow/gshadow/setsgent.h \ shadowio.c \ shadowio.h \ shadowlog.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c index 19b3528fe..f4f428f45 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -23,6 +23,7 @@ #include "defines.h" #include "prototypes.h" #include "shadow/gshadow/gshadow.h" +#include "shadow/gshadow/setsgent.h" #include "string/strchr/strchrcnt.h" #include "string/strcmp/streq.h" #include "string/strtok/stpsep.h" @@ -49,15 +50,6 @@ build_list(char *s) return l; } -void setsgent (void) -{ - if (NULL != gshadow) { - rewind(gshadow); - } else { - gshadow = fopen(GSHADOW_FILE, "re"); - } -} - /*@observer@*//*@null@*/struct sgrp * sgetsgent(const char *string) { diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 618e04369..66f7a9061 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -34,7 +34,6 @@ struct sgrp { /*@observer@*//*@null@*/struct sgrp *getsgnam (const char *); /*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *); /*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE *); -void setsgent (void); #define GSHADOW "/etc/gshadow" diff --git a/lib/shadow/gshadow/setsgent.c b/lib/shadow/gshadow/setsgent.c new file mode 100644 index 000000000..a58edf9df --- /dev/null +++ b/lib/shadow/gshadow/setsgent.c @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/setsgent.h" + +#include +#include + +#include "shadow/gshadow/gshadow.h" + + +#if defined(SHADOWGRP) && !__has_include() +// set-resources-for-working-with shadow group entries +void +setsgent(void) +{ + if (NULL != gshadow) { + rewind(gshadow); + } else { + gshadow = fopen(GSHADOW_FILE, "re"); + } +} +#endif diff --git a/lib/shadow/gshadow/setsgent.h b/lib/shadow/gshadow/setsgent.h new file mode 100644 index 000000000..8382f70b2 --- /dev/null +++ b/lib/shadow/gshadow/setsgent.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_SETSGENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_SETSGENT_H_ + + +#include + + +#if __has_include() +# include +#else +void setsgent(void); +#endif + + +#endif // include guard From fce2744ec1098694194c52a0b36ff720634680b1 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:07:59 +0100 Subject: [PATCH 06/14] lib/shadow/gshadow/, lib/, src/: struct sgrp: Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 ++ lib/gshadow.c | 1 + lib/gshadow_.h | 17 ++++------------- lib/prototypes.h | 2 ++ lib/sgroupio.c | 1 + lib/sgroupio.h | 6 ++++++ lib/shadow/gshadow/putsgent.c | 1 + lib/shadow/gshadow/putsgent.h | 2 +- lib/shadow/gshadow/sgrp.c | 11 +++++++++++ lib/shadow/gshadow/sgrp.h | 24 ++++++++++++++++++++++++ src/chgpasswd.c | 1 + src/gpasswd.c | 1 + src/groupadd.c | 1 + src/groupmems.c | 1 + src/groupmod.c | 1 + src/grpck.c | 1 + src/grpconv.c | 1 + src/grpunconv.c | 1 + src/newgrp.c | 1 + src/newusers.c | 1 + src/useradd.c | 1 + src/userdel.c | 1 + src/usermod.c | 1 + 23 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 lib/shadow/gshadow/sgrp.c create mode 100644 lib/shadow/gshadow/sgrp.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 38e38292e..dacead6ca 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -183,6 +183,8 @@ libshadow_la_SOURCES = \ shadow/gshadow/putsgent.h \ shadow/gshadow/setsgent.c \ shadow/gshadow/setsgent.h \ + shadow/gshadow/sgrp.c \ + shadow/gshadow/sgrp.h \ shadowio.c \ shadowio.h \ shadowlog.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c index f4f428f45..2b9e5d26a 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -24,6 +24,7 @@ #include "prototypes.h" #include "shadow/gshadow/gshadow.h" #include "shadow/gshadow/setsgent.h" +#include "shadow/gshadow/sgrp.h" #include "string/strchr/strchrcnt.h" #include "string/strcmp/streq.h" #include "string/strtok/stpsep.h" diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 66f7a9061..63223e962 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -13,23 +13,14 @@ # include #else -/* - * Shadow group security file structure - */ -struct sgrp { - char *sg_namp; /* group name */ - char *sg_passwd; /* group password */ - char **sg_adm; /* group administrator list */ - char **sg_mem; /* group membership list */ -}; - -/* - * Shadow group security file functions. - */ +#include #include /* for FILE */ +#include "shadow/gshadow/sgrp.h" + + /*@observer@*//*@null@*/struct sgrp *getsgent (void); /*@observer@*//*@null@*/struct sgrp *getsgnam (const char *); /*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *); diff --git a/lib/prototypes.h b/lib/prototypes.h index 003fef049..1f3af234e 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -34,6 +34,8 @@ #include "attr.h" #include "defines.h" #include "commonio.h" +#include "shadow/gshadow/sgrp.h" + /* addgrps.c */ #if !defined(USE_PAM) diff --git a/lib/sgroupio.c b/lib/sgroupio.c index 51eac1b7f..4d85dcbd1 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -23,6 +23,7 @@ #include "sgroupio.h" #include "shadow/gshadow/gshadow.h" #include "shadow/gshadow/putsgent.h" +#include "shadow/gshadow/sgrp.h" #include "string/memset/memzero.h" diff --git a/lib/sgroupio.h b/lib/sgroupio.h index 3474a985b..e0ae944d5 100644 --- a/lib/sgroupio.h +++ b/lib/sgroupio.h @@ -12,6 +12,12 @@ #ifndef _SGROUPIO_H #define _SGROUPIO_H + +#include + +#include "shadow/gshadow/sgrp.h" + + extern int sgr_close (void); extern bool sgr_file_present (void); extern /*@observer@*/ /*@null@*/const struct sgrp *sgr_locate (const char *name); diff --git a/lib/shadow/gshadow/putsgent.c b/lib/shadow/gshadow/putsgent.c index 51d6552cf..f526cb006 100644 --- a/lib/shadow/gshadow/putsgent.c +++ b/lib/shadow/gshadow/putsgent.c @@ -17,6 +17,7 @@ #include "alloc/malloc.h" #include "prototypes.h" +#include "shadow/gshadow/sgrp.h" /* diff --git a/lib/shadow/gshadow/putsgent.h b/lib/shadow/gshadow/putsgent.h index 348ebab81..38c669919 100644 --- a/lib/shadow/gshadow/putsgent.h +++ b/lib/shadow/gshadow/putsgent.h @@ -13,7 +13,7 @@ #include -#include "gshadow_.h" +#include "shadow/gshadow/sgrp.h" #if __has_include() diff --git a/lib/shadow/gshadow/sgrp.c b/lib/shadow/gshadow/sgrp.c new file mode 100644 index 000000000..d34513243 --- /dev/null +++ b/lib/shadow/gshadow/sgrp.c @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/sgrp.h" diff --git a/lib/shadow/gshadow/sgrp.h b/lib/shadow/gshadow/sgrp.h new file mode 100644 index 000000000..7f7353131 --- /dev/null +++ b/lib/shadow/gshadow/sgrp.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_SGRP_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_SGRP_H_ + + +#if __has_include() +# include +#else +struct sgrp { + char *sg_namp; /* group name */ + char *sg_passwd; /* group password */ + char **sg_adm; /* group administrator list */ + char **sg_mem; /* group membership list */ +}; +#endif + + +#endif // include guard diff --git a/src/chgpasswd.c b/src/chgpasswd.c index c5f302844..46c0f4cbb 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -34,6 +34,7 @@ #endif /*@-exitarg@*/ #include "exitcodes.h" +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/strcmp/streq.h" #include "string/strtok/stpsep.h" diff --git a/src/gpasswd.c b/src/gpasswd.c index 460bd14c2..fe590c8ad 100644 --- a/src/gpasswd.c +++ b/src/gpasswd.c @@ -32,6 +32,7 @@ #ifdef SHADOWGRP #include "sgroupio.h" #endif +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" #include "string/memset/memzero.h" diff --git a/src/groupadd.c b/src/groupadd.c index a0d5adeb5..faa93f7cd 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -37,6 +37,7 @@ #ifdef SHADOWGRP #include "sgroupio.h" #endif +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/memset/memzero.h" #include "string/strtok/stpsep.h" diff --git a/src/groupmems.c b/src/groupmems.c index d37b237f2..084c937be 100644 --- a/src/groupmems.c +++ b/src/groupmems.c @@ -26,6 +26,7 @@ #ifdef SHADOWGRP #include "sgroupio.h" #endif +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/strcmp/streq.h" #include "string/strdup/xstrdup.h" diff --git a/src/groupmod.c b/src/groupmod.c index cce6fd49c..e9f7b86f6 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -38,6 +38,7 @@ #ifdef SHADOWGRP #include "sgroupio.h" #endif +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" #include "string/sprintf/stpeprintf.h" diff --git a/src/grpck.c b/src/grpck.c index 342431dfb..ec8a0266e 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -23,6 +23,7 @@ #include "nscd.h" #include "prototypes.h" #include "shadow/gshadow/gshadow.h" +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" #include "string/strcmp/streq.h" diff --git a/src/grpconv.c b/src/grpconv.c index 1b31cb85a..022defb37 100644 --- a/src/grpconv.c +++ b/src/grpconv.c @@ -36,6 +36,7 @@ #ifdef SHADOWGRP #include "groupio.h" #include "sgroupio.h" +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" diff --git a/src/grpunconv.c b/src/grpunconv.c index e54b2a96e..4a9e821f4 100644 --- a/src/grpunconv.c +++ b/src/grpunconv.c @@ -37,6 +37,7 @@ #include "groupio.h" #include "sgroupio.h" #include "shadow/gshadow/gshadow.h" +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" diff --git a/src/newgrp.c b/src/newgrp.c index 5426704dc..6d8115d29 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -28,6 +28,7 @@ #include "search/l/lsearch.h" #include "shadow/grp/agetgroups.h" #include "shadow/gshadow/endsgent.h" +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" diff --git a/src/newusers.c b/src/newusers.c index e3685efe9..cd10595fd 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -52,6 +52,7 @@ #ifdef ENABLE_SUBIDS #include "subordinateio.h" #endif /* ENABLE_SUBIDS */ +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" #include "string/sprintf/snprintf.h" diff --git a/src/useradd.c b/src/useradd.c index 6e744b042..78a93edf3 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -62,6 +62,7 @@ #ifdef WITH_TCB #include "tcbfuncs.h" #endif +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" #include "string/memset/memzero.h" diff --git a/src/userdel.c b/src/userdel.c index c034afbc1..3982ff082 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -50,6 +50,7 @@ #ifdef ENABLE_SUBIDS #include "subordinateio.h" #endif /* ENABLE_SUBIDS */ +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/sprintf/xasprintf.h" #include "string/strcmp/streq.h" diff --git a/src/usermod.c b/src/usermod.c index 36212a252..984ca1b60 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -61,6 +61,7 @@ #include "tcbfuncs.h" #endif #include "shadow/gshadow/endsgent.h" +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "sssd.h" #include "string/memset/memzero.h" From 352b4f78257839e812b5ed67b1aef9ba629d525c Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:18:19 +0100 Subject: [PATCH 07/14] lib/shadow/gshadow/, lib/: fgetsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 + lib/gshadow.c | 52 +---------------------- lib/gshadow_.h | 3 -- lib/shadow/gshadow/fgetsgent.c | 77 ++++++++++++++++++++++++++++++++++ lib/shadow/gshadow/fgetsgent.h | 26 ++++++++++++ 5 files changed, 106 insertions(+), 54 deletions(-) create mode 100644 lib/shadow/gshadow/fgetsgent.c create mode 100644 lib/shadow/gshadow/fgetsgent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index dacead6ca..4c059b74c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -177,6 +177,8 @@ libshadow_la_SOURCES = \ shadow/grp/agetgroups.h \ shadow/gshadow/endsgent.c \ shadow/gshadow/endsgent.h \ + shadow/gshadow/fgetsgent.c \ + shadow/gshadow/fgetsgent.h \ shadow/gshadow/gshadow.c \ shadow/gshadow/gshadow.h \ shadow/gshadow/putsgent.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c index 2b9e5d26a..475628296 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -22,6 +22,7 @@ #include "alloc/x/xmalloc.h" #include "defines.h" #include "prototypes.h" +#include "shadow/gshadow/fgetsgent.h" #include "shadow/gshadow/gshadow.h" #include "shadow/gshadow/setsgent.h" #include "shadow/gshadow/sgrp.h" @@ -102,57 +103,6 @@ sgetsgent(const char *string) return &sgroup; } -/* - * fgetsgent - convert next line in stream to (struct sgrp) - * - * fgetsgent() reads the next line from the provided stream and - * converts it to a (struct sgrp). NULL is returned on EOF. - */ - -/*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE * fp) -{ - static size_t buflen = 0; - static char *buf = NULL; - - char *cp; - - if (0 == buflen) { - buf = MALLOC(BUFSIZ, char); - if (NULL == buf) { - return NULL; - } - buflen = BUFSIZ; - } - - if (NULL == fp) { - return NULL; - } - - if (fgetsx(buf, buflen, fp) == NULL) - return NULL; - - while ( (strrchr(buf, '\n') == NULL) - && (feof (fp) == 0)) { - size_t len; - - cp = REALLOC(buf, buflen * 2, char); - if (NULL == cp) { - return NULL; - } - buf = cp; - buflen *= 2; - - len = strlen (buf); - if (fgetsx (&buf[len], - (int) (buflen - len), - fp) != &buf[len]) { - return NULL; - } - } - stpsep(buf, "\n"); - return (sgetsgent (buf)); -} - /* * getsgent - get a single shadow group entry */ diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 63223e962..007652b08 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -16,15 +16,12 @@ #include -#include /* for FILE */ - #include "shadow/gshadow/sgrp.h" /*@observer@*//*@null@*/struct sgrp *getsgent (void); /*@observer@*//*@null@*/struct sgrp *getsgnam (const char *); /*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *); -/*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE *); #define GSHADOW "/etc/gshadow" diff --git a/lib/shadow/gshadow/fgetsgent.c b/lib/shadow/gshadow/fgetsgent.c new file mode 100644 index 000000000..136ed291d --- /dev/null +++ b/lib/shadow/gshadow/fgetsgent.c @@ -0,0 +1,77 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/fgetsgent.h" + +#include +#include +#include + +#include "alloc/malloc.h" +#include "alloc/realloc.h" +#include "defines.h" +#include "prototypes.h" +#include "shadow/gshadow/sgrp.h" +#include "string/strtok/stpsep.h" + + +/* + * fgetsgent - convert next line in stream to (struct sgrp) + * + * fgetsgent() reads the next line from the provided stream and + * converts it to a (struct sgrp). NULL is returned on EOF. + */ +#if defined(SHADOWGRP) && !__has_include() +// from-FILE get-next shadow group entry +struct sgrp * +fgetsgent(FILE *fp) +{ + static size_t buflen = 0; + static char *buf = NULL; + + char *cp; + + if (0 == buflen) { + buf = MALLOC(BUFSIZ, char); + if (NULL == buf) { + return NULL; + } + buflen = BUFSIZ; + } + + if (NULL == fp) { + return NULL; + } + + if (fgetsx(buf, buflen, fp) == NULL) + return NULL; + + while ( (strrchr(buf, '\n') == NULL) + && (feof (fp) == 0)) { + size_t len; + + cp = REALLOC(buf, buflen * 2, char); + if (NULL == cp) { + return NULL; + } + buf = cp; + buflen *= 2; + + len = strlen (buf); + if (fgetsx (&buf[len], + (int) (buflen - len), + fp) != &buf[len]) { + return NULL; + } + } + stpsep(buf, "\n"); + return (sgetsgent (buf)); +} +#endif diff --git a/lib/shadow/gshadow/fgetsgent.h b/lib/shadow/gshadow/fgetsgent.h new file mode 100644 index 000000000..bb74dbc0d --- /dev/null +++ b/lib/shadow/gshadow/fgetsgent.h @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_FGETSGENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_FGETSGENT_H_ + + +#include + +#include + +#include "shadow/gshadow/sgrp.h" + + +#if __has_include() +# include +#else +struct sgrp *fgetsgent(FILE *stream); +#endif + + +#endif // include guard From 948bdcaa4616d0db805e0bd65a5b03a6d068948a Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:44:05 +0100 Subject: [PATCH 08/14] lib/shadow/gshadow/, lib/: sgetsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 + lib/gshadow.c | 72 ----------------------- lib/gshadow_.h | 1 - lib/sgroupio.c | 1 + lib/shadow/gshadow/fgetsgent.c | 3 +- lib/shadow/gshadow/sgetsgent.c | 101 +++++++++++++++++++++++++++++++++ lib/shadow/gshadow/sgetsgent.h | 24 ++++++++ 7 files changed, 130 insertions(+), 74 deletions(-) create mode 100644 lib/shadow/gshadow/sgetsgent.c create mode 100644 lib/shadow/gshadow/sgetsgent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 4c059b74c..18f92d7c6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -185,6 +185,8 @@ libshadow_la_SOURCES = \ shadow/gshadow/putsgent.h \ shadow/gshadow/setsgent.c \ shadow/gshadow/setsgent.h \ + shadow/gshadow/sgetsgent.c \ + shadow/gshadow/sgetsgent.h \ shadow/gshadow/sgrp.c \ shadow/gshadow/sgrp.h \ shadowio.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c index 475628296..12b076e62 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -31,78 +31,6 @@ #include "string/strtok/stpsep.h" -static struct sgrp sgroup = {}; - -#define FIELDS 4 - - -static /*@null@*/char ** -build_list(char *s) -{ - char **l; - size_t i; - - l = XMALLOC(strchrcnt(s, ',') + 2, char *); - - for (i = 0; s != NULL && !streq(s, ""); i++) - l[i] = strsep(&s, ","); - - l[i] = NULL; - - return l; -} - -/*@observer@*//*@null@*/struct sgrp * -sgetsgent(const char *string) -{ - static char *sgrbuf = NULL; - static size_t sgrbuflen = 0; - - char *fields[FIELDS]; - char *cp; - int i; - size_t len = strlen (string) + 1; - - if (len > sgrbuflen) { - char *buf = REALLOC(sgrbuf, len, char); - if (NULL == buf) - return NULL; - - sgrbuf = buf; - sgrbuflen = len; - } - - strcpy (sgrbuf, string); - stpsep(sgrbuf, "\n"); - - /* - * There should be exactly 4 colon separated fields. Find - * all 4 of them and save the starting addresses in fields[]. - */ - - for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++) - fields[i] = strsep(&cp, ":"); - - /* - * If there was an extra field somehow, or perhaps not enough, - * the line is invalid. - */ - - if (NULL != cp || i != FIELDS) - return NULL; - - sgroup.sg_namp = fields[0]; - sgroup.sg_passwd = fields[1]; - - free(sgroup.sg_adm); - free(sgroup.sg_mem); - - sgroup.sg_adm = build_list(fields[2]); - sgroup.sg_mem = build_list(fields[3]); - - return &sgroup; -} - /* * getsgent - get a single shadow group entry */ diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 007652b08..ac5813610 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -21,7 +21,6 @@ /*@observer@*//*@null@*/struct sgrp *getsgent (void); /*@observer@*//*@null@*/struct sgrp *getsgnam (const char *); -/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *); #define GSHADOW "/etc/gshadow" diff --git a/lib/sgroupio.c b/lib/sgroupio.c index 4d85dcbd1..c6c26dbe5 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -23,6 +23,7 @@ #include "sgroupio.h" #include "shadow/gshadow/gshadow.h" #include "shadow/gshadow/putsgent.h" +#include "shadow/gshadow/sgetsgent.h" #include "shadow/gshadow/sgrp.h" #include "string/memset/memzero.h" diff --git a/lib/shadow/gshadow/fgetsgent.c b/lib/shadow/gshadow/fgetsgent.c index 136ed291d..f2bae13f3 100644 --- a/lib/shadow/gshadow/fgetsgent.c +++ b/lib/shadow/gshadow/fgetsgent.c @@ -18,6 +18,7 @@ #include "alloc/realloc.h" #include "defines.h" #include "prototypes.h" +#include "shadow/gshadow/sgetsgent.h" #include "shadow/gshadow/sgrp.h" #include "string/strtok/stpsep.h" @@ -72,6 +73,6 @@ fgetsgent(FILE *fp) } } stpsep(buf, "\n"); - return (sgetsgent (buf)); + return sgetsgent(buf); } #endif diff --git a/lib/shadow/gshadow/sgetsgent.c b/lib/shadow/gshadow/sgetsgent.c new file mode 100644 index 000000000..07d2fe6e3 --- /dev/null +++ b/lib/shadow/gshadow/sgetsgent.c @@ -0,0 +1,101 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/sgetsgent.h" + +#include +#include + +#include "alloc/realloc.h" +#include "alloc/x/xmalloc.h" +#include "shadow/gshadow/sgrp.h" +#include "string/strchr/strchrcnt.h" +#include "string/strtok/stpsep.h" + + +#define FIELDS 4 + + +#if defined(SHADOWGRP) && !__has_include() +static struct sgrp sgroup = {}; + + +static char **build_list(char *s); + + +// from-string get shadow group entry +struct sgrp * +sgetsgent(const char *string) +{ + static char *sgrbuf = NULL; + static size_t sgrbuflen = 0; + + char *fields[FIELDS]; + char *cp; + int i; + size_t len = strlen (string) + 1; + + if (len > sgrbuflen) { + char *buf = REALLOC(sgrbuf, len, char); + if (NULL == buf) + return NULL; + + sgrbuf = buf; + sgrbuflen = len; + } + + strcpy (sgrbuf, string); + stpsep(sgrbuf, "\n"); + + /* + * There should be exactly 4 colon separated fields. Find + * all 4 of them and save the starting addresses in fields[]. + */ + + for (cp = sgrbuf, i = 0; (i < FIELDS) && (NULL != cp); i++) + fields[i] = strsep(&cp, ":"); + + /* + * If there was an extra field somehow, or perhaps not enough, + * the line is invalid. + */ + + if (NULL != cp || i != FIELDS) + return NULL; + + sgroup.sg_namp = fields[0]; + sgroup.sg_passwd = fields[1]; + + free(sgroup.sg_adm); + free(sgroup.sg_mem); + + sgroup.sg_adm = build_list(fields[2]); + sgroup.sg_mem = build_list(fields[3]); + + return &sgroup; +} + + +static char ** +build_list(char *s) +{ + char **l; + size_t i; + + l = XMALLOC(strchrcnt(s, ',') + 2, char *); + + for (i = 0; s != NULL && !streq(s, ""); i++) + l[i] = strsep(&s, ","); + + l[i] = NULL; + + return l; +} +#endif diff --git a/lib/shadow/gshadow/sgetsgent.h b/lib/shadow/gshadow/sgetsgent.h new file mode 100644 index 000000000..de7d45b16 --- /dev/null +++ b/lib/shadow/gshadow/sgetsgent.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_SGETSGENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_SGETSGENT_H_ + + +#include + +#include "shadow/gshadow/sgrp.h" + + +#if __has_include() +# include +#else +struct sgrp *sgetsgent(const char *); +#endif + + +#endif // include guard From 79e9d3df5df7118852a4191fd1af59bc3c835a71 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:52:57 +0100 Subject: [PATCH 09/14] lib/shadow/gshadow/, lib/, src/: getsgnam(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 ++ lib/gshadow.c | 18 ---------------- lib/gshadow_.h | 1 - lib/shadow/gshadow/getsgnam.c | 40 +++++++++++++++++++++++++++++++++++ lib/shadow/gshadow/getsgnam.h | 24 +++++++++++++++++++++ src/newgrp.c | 1 + 6 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 lib/shadow/gshadow/getsgnam.c create mode 100644 lib/shadow/gshadow/getsgnam.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 18f92d7c6..80c8a27da 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -179,6 +179,8 @@ libshadow_la_SOURCES = \ shadow/gshadow/endsgent.h \ shadow/gshadow/fgetsgent.c \ shadow/gshadow/fgetsgent.h \ + shadow/gshadow/getsgnam.c \ + shadow/gshadow/getsgnam.h \ shadow/gshadow/gshadow.c \ shadow/gshadow/gshadow.h \ shadow/gshadow/putsgent.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c index 12b076e62..33c6cff6f 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -42,24 +42,6 @@ } return fgetsgent(gshadow); } - -/* - * getsgnam - get a shadow group entry by name - */ - -/*@observer@*//*@null@*/struct sgrp *getsgnam (const char *name) -{ - struct sgrp *sgrp; - - setsgent (); - - while ((sgrp = getsgent ()) != NULL) { - if (streq(name, sgrp->sg_namp)) { - break; - } - } - return sgrp; -} #else extern int ISO_C_forbids_an_empty_translation_unit; #endif // !SHADOWGRP diff --git a/lib/gshadow_.h b/lib/gshadow_.h index ac5813610..ed7f6a9f3 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -20,7 +20,6 @@ /*@observer@*//*@null@*/struct sgrp *getsgent (void); -/*@observer@*//*@null@*/struct sgrp *getsgnam (const char *); #define GSHADOW "/etc/gshadow" diff --git a/lib/shadow/gshadow/getsgnam.c b/lib/shadow/gshadow/getsgnam.c new file mode 100644 index 000000000..aeffef740 --- /dev/null +++ b/lib/shadow/gshadow/getsgnam.c @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/getsgnam.h" + +#include +#include + +#include "defines.h" +#include "shadow/gshadow/setsgent.h" +#include "shadow/gshadow/sgrp.h" + + +/* + * getsgnam - get a shadow group entry by name + */ +#if defined(SHADOWGRP) && !__has_include() +// get shadow group entry-by-name +struct sgrp * +getsgnam(const char *name) +{ + struct sgrp *sgrp; + + setsgent (); + + while ((sgrp = getsgent ()) != NULL) { + if (strcmp (name, sgrp->sg_namp) == 0) { + break; + } + } + return sgrp; +} +#endif diff --git a/lib/shadow/gshadow/getsgnam.h b/lib/shadow/gshadow/getsgnam.h new file mode 100644 index 000000000..a0ba166ed --- /dev/null +++ b/lib/shadow/gshadow/getsgnam.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_GETSGNAM_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_GETSGNAM_H_ + + +#include + +#include "shadow/gshadow/sgrp.h" + + +#if __has_include() +# include +#else +struct sgrp *getsgnam(const char *); +#endif + + +#endif // include guard diff --git a/src/newgrp.c b/src/newgrp.c index 6d8115d29..4ecd1c752 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -28,6 +28,7 @@ #include "search/l/lsearch.h" #include "shadow/grp/agetgroups.h" #include "shadow/gshadow/endsgent.h" +#include "shadow/gshadow/getsgnam.h" #include "shadow/gshadow/sgrp.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" From 2194718656db851e3fd00cce6c0f598c24b822ae Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 19:04:06 +0100 Subject: [PATCH 10/14] lib/shadow/gshadow/, lib/: getsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 3 ++- lib/gshadow.c | 47 ----------------------------------- lib/gshadow_.h | 4 --- lib/shadow/gshadow/getsgent.c | 31 +++++++++++++++++++++++ lib/shadow/gshadow/getsgent.h | 24 ++++++++++++++++++ lib/shadow/gshadow/getsgnam.c | 1 + po/POTFILES.in | 1 - 7 files changed, 58 insertions(+), 53 deletions(-) delete mode 100644 lib/gshadow.c create mode 100644 lib/shadow/gshadow/getsgent.c create mode 100644 lib/shadow/gshadow/getsgent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 80c8a27da..b78d0be6c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -118,7 +118,6 @@ libshadow_la_SOURCES = \ groupio.c \ groupmem.c \ groupio.h \ - gshadow.c \ hushed.c \ idmapping.h \ idmapping.c \ @@ -179,6 +178,8 @@ libshadow_la_SOURCES = \ shadow/gshadow/endsgent.h \ shadow/gshadow/fgetsgent.c \ shadow/gshadow/fgetsgent.h \ + shadow/gshadow/getsgent.c \ + shadow/gshadow/getsgent.h \ shadow/gshadow/getsgnam.c \ shadow/gshadow/getsgnam.h \ shadow/gshadow/gshadow.c \ diff --git a/lib/gshadow.c b/lib/gshadow.c deleted file mode 100644 index 33c6cff6f..000000000 --- a/lib/gshadow.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 - 2009, Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include - -#if defined(SHADOWGRP) && !__has_include() - -#ident "$Id$" - -#include -#include -#include - -#include "alloc/malloc.h" -#include "alloc/realloc.h" -#include "alloc/x/xmalloc.h" -#include "defines.h" -#include "prototypes.h" -#include "shadow/gshadow/fgetsgent.h" -#include "shadow/gshadow/gshadow.h" -#include "shadow/gshadow/setsgent.h" -#include "shadow/gshadow/sgrp.h" -#include "string/strchr/strchrcnt.h" -#include "string/strcmp/streq.h" -#include "string/strtok/stpsep.h" - - -/* - * getsgent - get a single shadow group entry - */ - -/*@observer@*//*@null@*/struct sgrp *getsgent (void) -{ - if (NULL == gshadow) { - setsgent (); - } - return fgetsgent(gshadow); -} -#else -extern int ISO_C_forbids_an_empty_translation_unit; -#endif // !SHADOWGRP diff --git a/lib/gshadow_.h b/lib/gshadow_.h index ed7f6a9f3..f2015dcde 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -16,10 +16,6 @@ #include -#include "shadow/gshadow/sgrp.h" - - -/*@observer@*//*@null@*/struct sgrp *getsgent (void); #define GSHADOW "/etc/gshadow" diff --git a/lib/shadow/gshadow/getsgent.c b/lib/shadow/gshadow/getsgent.c new file mode 100644 index 000000000..40838333f --- /dev/null +++ b/lib/shadow/gshadow/getsgent.c @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008-2009, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "shadow/gshadow/getsgent.h" + +#include + +#include "shadow/gshadow/fgetsgent.h" +#include "shadow/gshadow/gshadow.h" +#include "shadow/gshadow/setsgent.h" +#include "shadow/gshadow/sgrp.h" + + +#if defined(SHADOWGRP) && !__has_include() +// get-next shadow group entry +struct sgrp * +getsgent(void) +{ + if (NULL == gshadow) { + setsgent (); + } + return fgetsgent(gshadow); +} +#endif diff --git a/lib/shadow/gshadow/getsgent.h b/lib/shadow/gshadow/getsgent.h new file mode 100644 index 000000000..b8efde1b0 --- /dev/null +++ b/lib/shadow/gshadow/getsgent.h @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_GETSGENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_GETSGENT_H_ + + +#include + +#include "shadow/gshadow/sgrp.h" + + +#if __has_include() +# include +#else +struct sgrp *getsgent(void); +#endif + + +#endif // include guard diff --git a/lib/shadow/gshadow/getsgnam.c b/lib/shadow/gshadow/getsgnam.c index aeffef740..65f88955f 100644 --- a/lib/shadow/gshadow/getsgnam.c +++ b/lib/shadow/gshadow/getsgnam.c @@ -14,6 +14,7 @@ #include #include "defines.h" +#include "shadow/gshadow/getsgent.h" #include "shadow/gshadow/setsgent.h" #include "shadow/gshadow/sgrp.h" diff --git a/po/POTFILES.in b/po/POTFILES.in index 3aff87b2d..57fd75c35 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,7 +27,6 @@ lib/getgr_nam_gid.c lib/getrange.c lib/groupio.c lib/groupmem.c -lib/gshadow.c lib/hushed.c lib/idmapping.c lib/isexpired.c From b5acda59ae17302e77610d4f05a4f493359e3659 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:00:19 +0100 Subject: [PATCH 11/14] lib/: GSHADOW: Remove unused macro And with it, the file that defines it, which does nothing else. Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 1 - lib/defines.h | 3 --- lib/gshadow_.h | 24 ------------------------ 3 files changed, 28 deletions(-) delete mode 100644 lib/gshadow_.h diff --git a/lib/Makefile.am b/lib/Makefile.am index b78d0be6c..431049557 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -306,5 +306,4 @@ endif EXTRA_DIST = \ .indent.pro \ - gshadow_.h \ xgetXXbyYY.c diff --git a/lib/defines.h b/lib/defines.h index db74f72ef..887f28824 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -51,9 +51,6 @@ #include #include -#if defined(SHADOWGRP) -#include "gshadow_.h" -#endif #include diff --git a/lib/gshadow_.h b/lib/gshadow_.h deleted file mode 100644 index f2015dcde..000000000 --- a/lib/gshadow_.h +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-FileCopyrightText: 1988-1994, Julianne Frances Haugh -// SPDX-FileCopyrightText: 1996-1997, Marek Michałkiewicz -// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko -// SPDX-FileCopyrightText: 2024, Alejandro Colomar -// SPDX-License-Identifier: BSD-3-Clause - - -#ifndef SHADOW_INCLUDE_LIB_GSHADOW__H_ -#define SHADOW_INCLUDE_LIB_GSHADOW__H_ - - -#if __has_include() -# include -#else - - -#include - - -#define GSHADOW "/etc/gshadow" - - -#endif // !__has_include() -#endif // include guard From 7cebadf735f7a9d806d4edd3a3c5ef60fc1f2be5 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:14:28 +0100 Subject: [PATCH 12/14] lib/, po/: sgetgrent(): Move to under lib/shadow/group/ Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 3 ++- lib/groupio.c | 1 + lib/prototypes.h | 3 --- lib/{ => shadow/group}/sgetgrent.c | 23 ++++++++++++----------- lib/shadow/group/sgetgrent.h | 17 +++++++++++++++++ po/POTFILES.in | 2 +- 6 files changed, 33 insertions(+), 16 deletions(-) rename lib/{ => shadow/group}/sgetgrent.c (82%) create mode 100644 lib/shadow/group/sgetgrent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 431049557..590ce6ab3 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -166,12 +166,13 @@ libshadow_la_SOURCES = \ semanage.c \ setugid.c \ setupenv.c \ - sgetgrent.c \ sgetpwent.c \ sgetspent.c \ sgroupio.c \ sgroupio.h \ shadow.c \ + shadow/group/sgetgrent.c \ + shadow/group/sgetgrent.h \ shadow/grp/agetgroups.c \ shadow/grp/agetgroups.h \ shadow/gshadow/endsgent.c \ diff --git a/lib/groupio.c b/lib/groupio.c index 516e3ccd2..66afe9a07 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -22,6 +22,7 @@ #include "getdef.h" #include "groupio.h" #include "prototypes.h" +#include "shadow/group/sgetgrent.h" #include "string/strcmp/streq.h" diff --git a/lib/prototypes.h b/lib/prototypes.h index 1f3af234e..de1160bee 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -401,9 +401,6 @@ extern void setup (struct passwd *); /* setupenv.c */ extern void setup_env (struct passwd *); -/* sgetgrent.c */ -extern struct group *sgetgrent (const char *buf); - /* sgetpwent.c */ extern struct passwd *sgetpwent (const char *buf); diff --git a/lib/sgetgrent.c b/lib/shadow/group/sgetgrent.c similarity index 82% rename from lib/sgetgrent.c rename to lib/shadow/group/sgetgrent.c index eeeed4b6f..693494c48 100644 --- a/lib/sgetgrent.c +++ b/lib/shadow/group/sgetgrent.c @@ -1,15 +1,14 @@ -/* - * SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 , Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + #include -#ident "$Id$" +#include "shadow/group/sgetgrent.h" #include #include @@ -27,6 +26,7 @@ #define NFIELDS 4 + /* * list - turn a comma-separated string into an array of (char *)'s * @@ -64,7 +64,9 @@ list(char *s) } -struct group *sgetgrent (const char *buf) +// from-string get group entry +struct group * +sgetgrent(const char *buf) { static char *grpbuf = NULL; static size_t size = 0; @@ -105,4 +107,3 @@ struct group *sgetgrent (const char *buf) return &grent; } - diff --git a/lib/shadow/group/sgetgrent.h b/lib/shadow/group/sgetgrent.h new file mode 100644 index 000000000..460e3c7cd --- /dev/null +++ b/lib/shadow/group/sgetgrent.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_GROUP_SGETGRENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GROUP_SGETGRENT_H_ + + +#include + +#include + + +struct group *sgetgrent(const char *s); + + +#endif // include guard diff --git a/po/POTFILES.in b/po/POTFILES.in index 57fd75c35..0a780d699 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -56,11 +56,11 @@ lib/selinux.c lib/semanage.c lib/setugid.c lib/setupenv.c -lib/sgetgrent.c lib/sgetpwent.c lib/sgetspent.c lib/sgroupio.c lib/shadow.c +lib/shadow/group/sgetgrent.c lib/shadowio.c lib/shadowmem.c lib/shell.c From fa284dd01e4c2c9606b0a9993f16d38fb2652ead Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:31:23 +0100 Subject: [PATCH 13/14] lib/, po/: sgetpwent(): Move to under lib/shadow/passwd/ Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 3 ++- lib/prototypes.h | 3 --- lib/pwio.c | 2 ++ lib/{ => shadow/passwd}/sgetpwent.c | 20 ++++++++++---------- lib/shadow/passwd/sgetpwent.h | 17 +++++++++++++++++ po/POTFILES.in | 2 +- 6 files changed, 32 insertions(+), 15 deletions(-) rename lib/{ => shadow/passwd}/sgetpwent.c (85%) create mode 100644 lib/shadow/passwd/sgetpwent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 590ce6ab3..c4c1ef0c8 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -166,7 +166,6 @@ libshadow_la_SOURCES = \ semanage.c \ setugid.c \ setupenv.c \ - sgetpwent.c \ sgetspent.c \ sgroupio.c \ sgroupio.h \ @@ -193,6 +192,8 @@ libshadow_la_SOURCES = \ shadow/gshadow/sgetsgent.h \ shadow/gshadow/sgrp.c \ shadow/gshadow/sgrp.h \ + shadow/passwd/sgetpwent.c \ + shadow/passwd/sgetpwent.h \ shadowio.c \ shadowio.h \ shadowlog.c \ diff --git a/lib/prototypes.h b/lib/prototypes.h index de1160bee..7d9c58a60 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -401,9 +401,6 @@ extern void setup (struct passwd *); /* setupenv.c */ extern void setup_env (struct passwd *); -/* sgetpwent.c */ -extern struct passwd *sgetpwent (const char *buf); - /* sgetspent.c */ #ifndef HAVE_SGETSPENT extern struct spwd *sgetspent (const char *string); diff --git a/lib/pwio.c b/lib/pwio.c index 3497c7545..59de8fcb9 100644 --- a/lib/pwio.c +++ b/lib/pwio.c @@ -18,6 +18,8 @@ #include #include "commonio.h" #include "pwio.h" +#include "shadow/passwd/sgetpwent.h" + static /*@null@*/ /*@only@*/void *passwd_dup (const void *ent) { diff --git a/lib/sgetpwent.c b/lib/shadow/passwd/sgetpwent.c similarity index 85% rename from lib/sgetpwent.c rename to lib/shadow/passwd/sgetpwent.c index b13d5bc54..9c1b18aec 100644 --- a/lib/sgetpwent.c +++ b/lib/shadow/passwd/sgetpwent.c @@ -1,15 +1,14 @@ -/* - * SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2008 , Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1989-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2008, Nicolas François +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + #include -#ident "$Id$" +#include "shadow/passwd/sgetpwent.h" #include #include @@ -25,6 +24,7 @@ #define NFIELDS 7 + /* * sgetpwent - convert a string to a (struct passwd) * @@ -37,6 +37,7 @@ * performance reasons. I am going to come up with some conditional * compilation glarp to improve on this in the future. */ +// from-string get pasword entry struct passwd * sgetpwent(const char *buf) { @@ -105,4 +106,3 @@ sgetpwent(const char *buf) return &pwent; } - diff --git a/lib/shadow/passwd/sgetpwent.h b/lib/shadow/passwd/sgetpwent.h new file mode 100644 index 000000000..ef432c73f --- /dev/null +++ b/lib/shadow/passwd/sgetpwent.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_PASSWD_SGETPWENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_PASSWD_SGETPWENT_H_ + + +#include + +#include + + +struct passwd *sgetpwent(const char *s); + + +#endif // include guard diff --git a/po/POTFILES.in b/po/POTFILES.in index 0a780d699..c2f9a4fb9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -56,11 +56,11 @@ lib/selinux.c lib/semanage.c lib/setugid.c lib/setupenv.c -lib/sgetpwent.c lib/sgetspent.c lib/sgroupio.c lib/shadow.c lib/shadow/group/sgetgrent.c +lib/shadow/passwd/sgetpwent.c lib/shadowio.c lib/shadowmem.c lib/shell.c From 3813478cc4a7a175865b14149674e96971a4628b Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 24 Feb 2025 23:06:39 +0100 Subject: [PATCH 14/14] lib/shadow/shadow/, lib/, po/: sgetspent(): Move to under lib/shadow/shadow/ Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 3 ++- lib/prototypes.h | 5 ----- lib/{ => shadow/shadow}/sgetspent.c | 18 +++++++----------- lib/shadow/shadow/sgetspent.h | 19 +++++++++++++++++++ lib/shadowio.c | 6 ++++-- po/POTFILES.in | 1 - 6 files changed, 32 insertions(+), 20 deletions(-) rename lib/{ => shadow/shadow}/sgetspent.c (90%) create mode 100644 lib/shadow/shadow/sgetspent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index c4c1ef0c8..66f45b2ae 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -166,7 +166,6 @@ libshadow_la_SOURCES = \ semanage.c \ setugid.c \ setupenv.c \ - sgetspent.c \ sgroupio.c \ sgroupio.h \ shadow.c \ @@ -194,6 +193,8 @@ libshadow_la_SOURCES = \ shadow/gshadow/sgrp.h \ shadow/passwd/sgetpwent.c \ shadow/passwd/sgetpwent.h \ + shadow/shadow/sgetspent.c \ + shadow/shadow/sgetspent.h \ shadowio.c \ shadowio.h \ shadowlog.c \ diff --git a/lib/prototypes.h b/lib/prototypes.h index 7d9c58a60..04205fc60 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -401,11 +401,6 @@ extern void setup (struct passwd *); /* setupenv.c */ extern void setup_env (struct passwd *); -/* sgetspent.c */ -#ifndef HAVE_SGETSPENT -extern struct spwd *sgetspent (const char *string); -#endif - /* sgroupio.c */ extern void __sgr_del_entry (const struct commonio_entry *ent); extern /*@null@*/ /*@only@*/struct sgrp *__sgr_dup (const struct sgrp *sgent); diff --git a/lib/sgetspent.c b/lib/shadow/shadow/sgetspent.c similarity index 90% rename from lib/sgetspent.c rename to lib/shadow/shadow/sgetspent.c index f34853ec6..b54052d51 100644 --- a/lib/sgetspent.c +++ b/lib/shadow/shadow/sgetspent.c @@ -1,19 +1,15 @@ -/* - * SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh - * SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz - * SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko - * SPDX-FileCopyrightText: 2009 , Nicolas François - * - * SPDX-License-Identifier: BSD-3-Clause - */ +// SPDX-FileCopyrightText: 1989-1994, Julianne Frances Haugh +// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz +// SPDX-FileCopyrightText: 2003-2005, Tomasz Kłoczko +// SPDX-FileCopyrightText: 2009, Nicolas François +// SPDX-FileCopyrightText: 2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + #include -/* Newer versions of Linux libc already have shadow support. */ #ifndef HAVE_SGETSPENT -#ident "$Id$" - #include #include #include diff --git a/lib/shadow/shadow/sgetspent.h b/lib/shadow/shadow/sgetspent.h new file mode 100644 index 000000000..f4d119235 --- /dev/null +++ b/lib/shadow/shadow/sgetspent.h @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_SHADOW_SHADOW_SGETSPENT_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_SHADOW_SGETSPENT_H_ + + +#include + +#include + + +#if !defined(HAVE_SGETSPENT) +struct spwd *sgetspent(const char *s); +#endif + + +#endif // include guard diff --git a/lib/shadowio.c b/lib/shadowio.c index d2c3b4730..3fe3dcad3 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -12,12 +12,14 @@ #ident "$Id$" -#include "prototypes.h" -#include "defines.h" #include #include + #include "commonio.h" +#include "defines.h" #include "getdef.h" +#include "prototypes.h" +#include "shadow/shadow/sgetspent.h" #include "shadowio.h" #ifdef WITH_TCB #include diff --git a/po/POTFILES.in b/po/POTFILES.in index c2f9a4fb9..d1422eb40 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -56,7 +56,6 @@ lib/selinux.c lib/semanage.c lib/setugid.c lib/setupenv.c -lib/sgetspent.c lib/sgroupio.c lib/shadow.c lib/shadow/group/sgetgrent.c