From 5882c687000331bae9db0b3b48ddb322af8f0e21 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 15:27:43 +0100 Subject: [PATCH 01/13] 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 | 97 +++++++++++++++++++++++++++++++++++ lib/shadow/gshadow/putsgent.h | 26 ++++++++++ 6 files changed, 127 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 dc67df9e8..f05dd4e09 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..b607534e3 --- /dev/null +++ b/lib/shadow/gshadow/putsgent.c @@ -0,0 +1,97 @@ +// 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() +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 0c2830e3c90380fcd7dfa250d7b9c626c023fb29 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 16:22:12 +0100 Subject: [PATCH 02/13] 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 f05dd4e09..3ac2e845b 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 c243ddd952f4f32c16ba64c2fcc8bdf4f28bac43 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 16:48:15 +0100 Subject: [PATCH 03/13] 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 | 29 +++++++++++++++++++++++++++++ lib/shadow/gshadow/endsgent.h | 22 ++++++++++++++++++++++ src/login.c | 1 + src/newgrp.c | 1 + src/usermod.c | 1 + 9 files changed, 57 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 3ac2e845b..8dff8f46d 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..59a5160a7 --- /dev/null +++ b/lib/shadow/gshadow/endsgent.c @@ -0,0 +1,29 @@ +// 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() +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 6e05277f6..2fd5753b9 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 7ea1a7244..7c2441442 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 02fc437b25eb5fb52ec8ac6b6ebe9ca4770eff04 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 17:36:44 +0100 Subject: [PATCH 04/13] 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 8aa6887127c2544a603f3934d14d4f86da9c70e4 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 17:44:23 +0100 Subject: [PATCH 05/13] 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 | 29 +++++++++++++++++++++++++++++ lib/shadow/gshadow/setsgent.h | 22 ++++++++++++++++++++++ 5 files changed, 54 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 8dff8f46d..e9c58de89 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..19028e957 --- /dev/null +++ b/lib/shadow/gshadow/setsgent.c @@ -0,0 +1,29 @@ +// 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() +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 2aa3f65d950f6e980428258692d469ba0d494482 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:07:59 +0100 Subject: [PATCH 06/13] 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 e9c58de89..40ba082a6 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 79bd0fdd6..a785cc698 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 b607534e3..69ac0bfc9 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 13abbdab7..d65d5d0b4 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 ab30960e3..12f925014 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 5164c4c3f..c0bc0861a 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 2fd5753b9..bd3ed6a39 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 562ba44fc..6289995e1 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 a267ae1d0..edc9bb8a3 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 7c2441442..1aa3a67d1 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 66b0763daed94adfa3ab01fbe641c78509af12e4 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:18:19 +0100 Subject: [PATCH 07/13] 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 | 76 ++++++++++++++++++++++++++++++++++ lib/shadow/gshadow/fgetsgent.h | 26 ++++++++++++ 5 files changed, 105 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 40ba082a6..d81da2f28 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..65902758f --- /dev/null +++ b/lib/shadow/gshadow/fgetsgent.c @@ -0,0 +1,76 @@ +// 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() +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 51c7ad870a448ae1f33fd7362c69c77d4085671a Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:44:05 +0100 Subject: [PATCH 08/13] 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 | 100 +++++++++++++++++++++++++++++++++ lib/shadow/gshadow/sgetsgent.h | 24 ++++++++ 7 files changed, 129 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 d81da2f28..66b174341 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 65902758f..4c05a7456 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" @@ -71,6 +72,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..5c08d91c6 --- /dev/null +++ b/lib/shadow/gshadow/sgetsgent.c @@ -0,0 +1,100 @@ +// 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); + + +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 b3a67122594adf985a193b247b4fd33f5794dcfc Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:52:57 +0100 Subject: [PATCH 09/13] 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 | 39 +++++++++++++++++++++++++++++++++++ lib/shadow/gshadow/getsgnam.h | 24 +++++++++++++++++++++ src/newgrp.c | 1 + 6 files changed, 66 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 66b174341..45754616c 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..7817e7659 --- /dev/null +++ b/lib/shadow/gshadow/getsgnam.c @@ -0,0 +1,39 @@ +// 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() +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 bd3ed6a39..0a982df32 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 c3ea18815974d08def561ffa83b42e3f5fa8b552 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 19:04:06 +0100 Subject: [PATCH 10/13] 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 | 33 ++++++++++++++++++++++++ lib/shadow/gshadow/getsgent.h | 24 ++++++++++++++++++ lib/shadow/gshadow/getsgnam.c | 1 + po/POTFILES.in | 1 - 7 files changed, 60 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 45754616c..b389652d7 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..03bf3dc8a --- /dev/null +++ b/lib/shadow/gshadow/getsgent.c @@ -0,0 +1,33 @@ +// 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() +/* + * getsgent - get a single 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 7817e7659..d762cd4d3 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 2b373a559c9e934125f19290ecf8e570860fe11d Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:00:19 +0100 Subject: [PATCH 11/13] 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 b389652d7..445ac1aee 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -296,5 +296,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 ca661d7e992ded143aae1417a747263d1d6e07db Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:14:28 +0100 Subject: [PATCH 12/13] 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 | 22 +++++++++++----------- lib/shadow/group/sgetgrent.h | 17 +++++++++++++++++ po/POTFILES.in | 2 +- 6 files changed, 32 insertions(+), 16 deletions(-) rename lib/{ => shadow/group}/sgetgrent.c (83%) create mode 100644 lib/shadow/group/sgetgrent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 445ac1aee..ebcd47ab9 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 a785cc698..60f259e31 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -398,9 +398,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 83% rename from lib/sgetgrent.c rename to lib/shadow/group/sgetgrent.c index eeeed4b6f..7432b3be2 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,8 @@ list(char *s) } -struct group *sgetgrent (const char *buf) +struct group * +sgetgrent(const char *buf) { static char *grpbuf = NULL; static size_t size = 0; @@ -105,4 +106,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 e729312987b8804aefdb004a122d9869b7fbd640 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:31:23 +0100 Subject: [PATCH 13/13] 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 | 19 +++++++++---------- lib/shadow/passwd/sgetpwent.h | 17 +++++++++++++++++ po/POTFILES.in | 2 +- 6 files changed, 31 insertions(+), 15 deletions(-) rename lib/{ => shadow/passwd}/sgetpwent.c (86%) create mode 100644 lib/shadow/passwd/sgetpwent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index ebcd47ab9..b925a038b 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 60f259e31..76ec3a3ed 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -398,9 +398,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 86% rename from lib/sgetpwent.c rename to lib/shadow/passwd/sgetpwent.c index b13d5bc54..38e9d5277 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) * @@ -105,4 +105,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