From 291514e341ba5fad829f93b2348c1bf7831e4a22 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 15:27:43 +0100 Subject: [PATCH 01/15] lib/shadow/, 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 6c68cfa1eb..0d1d81ed51 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -171,9 +171,11 @@ libshadow_la_SOURCES = \ sgetpwent.c \ sgetspent.c \ sgroupio.c \ - sgroupio.h\ + sgroupio.h \ 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 2bde386954..4d692a28ec 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -173,81 +173,6 @@ sgetsgent(const char *s) } 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 2b38cb338e..21fa210612 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 c31ef835e3..b6127252ba 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -22,6 +22,7 @@ #include "fields.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 0000000000..4ddd5f3f2f --- /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 "config.h" + +#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 0000000000..ad6fe39337 --- /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 "config.h" + +#include + +#include "gshadow_.h" + + +#if __has_include() +# include +#else +int putsgent(const struct sgrp *sgrp, FILE *fp); +#endif + + +#endif // include guard From 426570e89c834ffc166be0ab624d7c81a341fb68 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 16:22:12 +0100 Subject: [PATCH 02/15] lib/shadow/, 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 | 20 ++++++++++++++++++++ 4 files changed, 48 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 0d1d81ed51..fdbdc968d4 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -174,6 +174,8 @@ libshadow_la_SOURCES = \ sgroupio.h \ 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 4d692a28ec..4c5ac41917 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -22,13 +22,13 @@ #include "alloc/realloc.h" #include "defines.h" #include "prototypes.h" +#include "shadow/gshadow/gshadow.h" #include "string/strcmp/streq.h" #include "string/strtok/stpsep.h" #include "string/strtok/strsep2arr.h" #include "string/strtok/xastrsep2ls.h" -static /*@null@*/FILE *shadow; static struct sgrp sgroup = {}; @@ -48,20 +48,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 * @@ -150,10 +150,10 @@ sgetsgent(const char *s) /*@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 0000000000..1fa0fe5f09 --- /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 "config.h" + +#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 0000000000..b2a1ef9f55 --- /dev/null +++ b/lib/shadow/gshadow/gshadow.h @@ -0,0 +1,20 @@ +// 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 "config.h" + +#include + + +extern FILE *gshadow; + + +#endif // include guard From 9fe9529dc8b9dc114a656ca060c03ce8ba010e4d Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 16:48:15 +0100 Subject: [PATCH 03/15] lib/shadow/, 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 fdbdc968d4..74f16b376a 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -174,6 +174,8 @@ libshadow_la_SOURCES = \ sgroupio.h \ 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 cbaea09ebc..bdb789e30d 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 4c5ac41917..b88bba0353 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -55,15 +55,6 @@ void setsgent (void) } } -void endsgent (void) -{ - if (NULL != gshadow) { - fclose(gshadow); - } - - gshadow = NULL; -} - /*@observer@*//*@null@*/struct sgrp * sgetsgent(const char *s) { diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 21fa210612..618e04369a 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 0000000000..5cfb2d4d2d --- /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 "config.h" + +#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 0000000000..b1cde28c09 --- /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 "config.h" + + +#if __has_include() +# include +#else +void endsgent(void); +#endif + + +#endif // include guard diff --git a/src/login.c b/src/login.c index ff6b98e07c..7b567aae8c 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 0d9cb33959..91cede727b 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 8295165a52..47c254750f 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 d93a0612fc7aa8269b08668e9d02c0dede050542 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 17:36:44 +0100 Subject: [PATCH 04/15] lib/shadow/, lib/, src/: Use _PATH_GSHADOW from This macro is provided by glibc (but not musl) as _PATH_GSHADOW in . Let's use that macro, and define it only if libc doesn't provide it. Signed-off-by: Alejandro Colomar --- lib/defines.h | 6 ------ lib/gshadow.c | 2 +- lib/prefix_flag.c | 5 ++++- lib/sgroupio.c | 5 +++-- lib/shadow/gshadow/gshadow.h | 6 ++++++ src/grpck.c | 5 ++++- src/grpunconv.c | 10 +++++----- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/defines.h b/lib/defines.h index 8673a09f4f..e478552eb1 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -172,12 +172,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 b88bba0353..eb2ea5dffb 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -51,7 +51,7 @@ void setsgent (void) if (NULL != gshadow) { rewind(gshadow); } else { - gshadow = fopen(SGROUP_FILE, "re"); + gshadow = fopen(_PATH_GSHADOW, "re"); } } diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index f69aa10606..cb807c6ac4 100644 --- a/lib/prefix_flag.c +++ b/lib/prefix_flag.c @@ -9,7 +9,9 @@ #ident "$Id$" +#include #include + #include #include "atoi/getnum.h" @@ -27,6 +29,7 @@ #include "subordinateio.h" #endif /* ENABLE_SUBIDS */ #include "getdef.h" +#include "shadow/gshadow/gshadow.h" #include "shadowlog.h" #include "string/sprintf/xaprintf.h" #include "string/strcmp/streq.h" @@ -115,7 +118,7 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** gr_setdbname(group_db_file); #ifdef SHADOWGRP - sgroup_db_file = xaprintf("%s/%s", prefix, SGROUP_FILE); + sgroup_db_file = xaprintf("%s/%s", prefix, _PATH_GSHADOW); sgr_setdbname(sgroup_db_file); #endif diff --git a/lib/sgroupio.c b/lib/sgroupio.c index b6127252ba..7c363b083e 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -12,7 +12,7 @@ #ifdef SHADOWGRP -#ident "$Id$" +#include #include "alloc/calloc.h" #include "alloc/malloc.h" @@ -22,6 +22,7 @@ #include "fields.h" #include "getdef.h" #include "sgroupio.h" +#include "shadow/gshadow/gshadow.h" #include "shadow/gshadow/putsgent.h" #include "string/memset/memzero.h" @@ -206,7 +207,7 @@ static struct commonio_ops gshadow_ops = { }; static struct commonio_db gshadow_db = { - SGROUP_FILE, /* filename */ + _PATH_GSHADOW, /* filename */ &gshadow_ops, /* ops */ NULL, /* fp */ #ifdef WITH_SELINUX diff --git a/lib/shadow/gshadow/gshadow.h b/lib/shadow/gshadow/gshadow.h index b2a1ef9f55..42f74823bc 100644 --- a/lib/shadow/gshadow/gshadow.h +++ b/lib/shadow/gshadow/gshadow.h @@ -11,9 +11,15 @@ #include "config.h" +#include #include +#ifndef _PATH_GSHADOW +# define _PATH_GSHADOW "/etc/gshadow" +#endif + + extern FILE *gshadow; diff --git a/src/grpck.c b/src/grpck.c index 4f31986bb5..bff18aa125 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,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" @@ -31,6 +33,7 @@ #include "sgroupio.h" #endif + /* * Exit codes */ @@ -52,7 +55,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 = _PATH_GSHADOW; 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 f9b24d8127..1f1b45b0c1 100644 --- a/src/grpunconv.c +++ b/src/grpunconv.c @@ -14,8 +14,7 @@ #include "config.h" -#ident "$Id$" - +#include #include #include #include @@ -36,6 +35,7 @@ #ifdef SHADOWGRP #include "groupio.h" #include "sgroupio.h" +#include "shadow/gshadow/gshadow.h" #include "shadowlog.h" @@ -201,11 +201,11 @@ int main (int argc, char **argv) fail_exit (3); } - if (unlink (SGROUP_FILE) != 0) { + if (unlink(_PATH_GSHADOW) != 0) { fprintf (stderr, _("%s: cannot delete %s\n"), - Prog, SGROUP_FILE); - SYSLOG ((LOG_ERR, "cannot delete %s", SGROUP_FILE)); + Prog, _PATH_GSHADOW); + SYSLOG((LOG_ERR, "cannot delete %s", _PATH_GSHADOW)); fail_exit (3); } From dc2b56f769659b6c3e7a60b6be1b6c6ef164a423 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 17:44:23 +0100 Subject: [PATCH 05/15] lib/shadow/, 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 | 31 +++++++++++++++++++++++++++++++ lib/shadow/gshadow/setsgent.h | 22 ++++++++++++++++++++++ 5 files changed, 56 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 74f16b376a..61025b8876 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -180,6 +180,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 eb2ea5dffb..b80a82fe25 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/strcmp/streq.h" #include "string/strtok/stpsep.h" #include "string/strtok/strsep2arr.h" @@ -46,15 +47,6 @@ build_list(char *s) return l; } -void setsgent (void) -{ - if (NULL != gshadow) { - rewind(gshadow); - } else { - gshadow = fopen(_PATH_GSHADOW, "re"); - } -} - /*@observer@*//*@null@*/struct sgrp * sgetsgent(const char *s) { diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 618e04369a..66f7a90612 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 0000000000..73be77907a --- /dev/null +++ b/lib/shadow/gshadow/setsgent.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 "config.h" + +#include "shadow/gshadow/setsgent.h" + +#include +#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(_PATH_GSHADOW, "re"); + } +} +#endif diff --git a/lib/shadow/gshadow/setsgent.h b/lib/shadow/gshadow/setsgent.h new file mode 100644 index 0000000000..2c4435e79d --- /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 "config.h" + + +#if __has_include() +# include +#else +void setsgent(void); +#endif + + +#endif // include guard From 14e0357b8f242ece4e268105a14be9fb5ab75b33 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:07:59 +0100 Subject: [PATCH 06/15] lib/shadow/, 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 | 27 +++++++++++++++++++++++++++ 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, 69 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 61025b8876..5138d5b525 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -182,6 +182,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 b80a82fe25..072f4d475a 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/strcmp/streq.h" #include "string/strtok/stpsep.h" #include "string/strtok/strsep2arr.h" diff --git a/lib/gshadow_.h b/lib/gshadow_.h index 66f7a90612..63223e962f 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 4063ae1644..d8a88e372b 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 7c363b083e..f191d7d06a 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -24,6 +24,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 3474a985bc..d37526f5ea 100644 --- a/lib/sgroupio.h +++ b/lib/sgroupio.h @@ -12,6 +12,12 @@ #ifndef _SGROUPIO_H #define _SGROUPIO_H + +#include "config.h" + +#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 4ddd5f3f2f..cd8dc024b4 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 ad6fe39337..22ed38ea73 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 0000000000..5c0d186bc3 --- /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 "config.h" + +#include "shadow/gshadow/sgrp.h" diff --git a/lib/shadow/gshadow/sgrp.h b/lib/shadow/gshadow/sgrp.h new file mode 100644 index 0000000000..ae63f2e56b --- /dev/null +++ b/lib/shadow/gshadow/sgrp.h @@ -0,0 +1,27 @@ +// 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_ + + +#include "config.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 6f0e2753ce..c0017e3380 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 e6d0cf472e..a64c270178 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 4cb90719c2..8210388bd3 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 fb1e4b30d4..68a186730e 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 5b42135ba3..20c063058a 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 bff18aa125..8721d4afba 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -24,6 +24,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 9b198a4c49..64b2157d22 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 1f1b45b0c1..4a822f7ed5 100644 --- a/src/grpunconv.c +++ b/src/grpunconv.c @@ -36,6 +36,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 91cede727b..e154aba7a8 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 cce72f6c62..a4c374da1c 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 5b6a9d2737..586333a355 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -64,6 +64,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 5b1a8a8663..3e5b5b5825 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/aprintf.h" #include "string/sprintf/xaprintf.h" diff --git a/src/usermod.c b/src/usermod.c index 47c254750f..17288d07b3 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 8f8e82f66680db6d46ac42933312deec86a3ca1f Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:18:19 +0100 Subject: [PATCH 07/15] lib/shadow/, 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 5138d5b525..c6a2ce02fc 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -176,6 +176,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 072f4d475a..8f638f7f35 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -22,6 +22,7 @@ #include "alloc/realloc.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" @@ -77,57 +78,6 @@ sgetsgent(const char *s) 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 63223e962f..007652b08f 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 0000000000..9424ab9406 --- /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 "config.h" + +#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 0000000000..e40fbbd9a6 --- /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 "config.h" + +#include + +#include "shadow/gshadow/sgrp.h" + + +#if __has_include() +# include +#else +struct sgrp *fgetsgent(FILE *stream); +#endif + + +#endif // include guard From 26d6363fc04963f8bcb2926b2d4cda18ce6a9b92 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:44:05 +0100 Subject: [PATCH 08/15] lib/shadow/, lib/: sgetsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 2 + lib/gshadow.c | 51 ----------------------- lib/gshadow_.h | 1 - lib/sgroupio.c | 1 + lib/shadow/gshadow/fgetsgent.c | 3 +- lib/shadow/gshadow/sgetsgent.c | 75 ++++++++++++++++++++++++++++++++++ lib/shadow/gshadow/sgetsgent.h | 24 +++++++++++ 7 files changed, 104 insertions(+), 53 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 c6a2ce02fc..dee5e095ab 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -184,6 +184,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 8f638f7f35..c6e1ff3ac0 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -18,8 +18,6 @@ #include #include -#include "alloc/malloc.h" -#include "alloc/realloc.h" #include "defines.h" #include "prototypes.h" #include "shadow/gshadow/fgetsgent.h" @@ -27,57 +25,8 @@ #include "shadow/gshadow/setsgent.h" #include "shadow/gshadow/sgrp.h" #include "string/strcmp/streq.h" -#include "string/strtok/stpsep.h" -#include "string/strtok/strsep2arr.h" -#include "string/strtok/xastrsep2ls.h" -static struct sgrp sgroup = {}; - - -static /*@null@*/char ** -build_list(char *s) -{ - char **l; - size_t n; - - l = xastrsep2ls(s, ",", &n); - - if (streq(l[n-1], "")) - l[n-1] = NULL; - - return l; -} - -/*@observer@*//*@null@*/struct sgrp * -sgetsgent(const char *s) -{ - static char *dup = NULL; - - char *fields[4]; - - free(dup); - dup = strdup(s); - if (dup == NULL) - return NULL; - - stpsep(dup, "\n"); - - if (STRSEP2ARR(dup, ":", fields) == -1) - 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 007652b08f..ac58136108 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 f191d7d06a..5c10965798 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -24,6 +24,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 9424ab9406..57e45fb5e1 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 0000000000..c15bb58314 --- /dev/null +++ b/lib/shadow/gshadow/sgetsgent.c @@ -0,0 +1,75 @@ +// 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-2025, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include "config.h" + +#include "shadow/gshadow/sgetsgent.h" + +#include +#include +#include + +#include "shadow/gshadow/sgrp.h" +#include "string/strcmp/streq.h" +#include "string/strtok/stpsep.h" +#include "string/strtok/strsep2arr.h" +#include "string/strtok/xastrsep2ls.h" + + +#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 *s) +{ + static char *dup = NULL; + + char *fields[4]; + + free(dup); + dup = strdup(s); + if (dup == NULL) + return NULL; + + stpsep(dup, "\n"); + + if (STRSEP2ARR(dup, ":", fields) == -1) + 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 n; + + l = xastrsep2ls(s, ",", &n); + + if (streq(l[n-1], "")) + l[n-1] = NULL; + + return l; +} +#endif diff --git a/lib/shadow/gshadow/sgetsgent.h b/lib/shadow/gshadow/sgetsgent.h new file mode 100644 index 0000000000..65fda800df --- /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 "config.h" + +#include "shadow/gshadow/sgrp.h" + + +#if __has_include() +# include +#else +struct sgrp *sgetsgent(const char *); +#endif + + +#endif // include guard From 4129326722708696026264ef79b452be24e3261a Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 18:52:57 +0100 Subject: [PATCH 09/15] lib/shadow/, 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 dee5e095ab..300162b582 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -178,6 +178,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 c6e1ff3ac0..b16ca4764d 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -38,24 +38,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 (NULL != (sgrp = getsgent())) { - 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 ac58136108..ed7f6a9f30 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 0000000000..d78a57564f --- /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 "config.h" + +#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 (NULL != (sgrp = getsgent ())) { + 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 0000000000..f4acc3c413 --- /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 "config.h" + +#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 e154aba7a8..51b1dcc060 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 dc9af0556237e5549e53d46ec4d29602ce61f404 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 19:04:06 +0100 Subject: [PATCH 10/15] lib/shadow/, lib/: getsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- lib/Makefile.am | 3 ++- lib/gshadow.c | 43 ----------------------------------- 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(+), 49 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 300162b582..10b7d176c0 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -119,7 +119,6 @@ libshadow_la_SOURCES = \ groupio.c \ groupmem.c \ groupio.h \ - gshadow.c \ hushed.c \ idmapping.h \ idmapping.c \ @@ -178,6 +177,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 b16ca4764d..0000000000 --- a/lib/gshadow.c +++ /dev/null @@ -1,43 +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 "config.h" - -#if defined(SHADOWGRP) && !__has_include() - -#ident "$Id$" - -#include -#include -#include -#include - -#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/strcmp/streq.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 ed7f6a9f30..f2015dcde0 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 0000000000..0e4c55977d --- /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 "config.h" + +#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 0000000000..6107daaa81 --- /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 "config.h" + +#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 d78a57564f..86fb9ad49d 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 a925b2350b..614415c23d 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 7448d8bb8663731e1d427424415e9bec3979df4d Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:00:19 +0100 Subject: [PATCH 11/15] 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 10b7d176c0..d5ec99a078 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -325,5 +325,4 @@ endif EXTRA_DIST = \ .indent.pro \ - gshadow_.h \ xgetXXbyYY.c diff --git a/lib/defines.h b/lib/defines.h index e478552eb1..219724c9f3 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 f2015dcde0..0000000000 --- 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 f0a38019710d21ba832447c8726c6895d12a10f0 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:14:28 +0100 Subject: [PATCH 12/15] lib/shadow/, 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 | 18 +++++++++--------- lib/shadow/group/sgetgrent.h | 17 +++++++++++++++++ po/POTFILES.in | 2 +- 6 files changed, 30 insertions(+), 14 deletions(-) rename lib/{ => shadow/group}/sgetgrent.c (78%) create mode 100644 lib/shadow/group/sgetgrent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index d5ec99a078..25c915b507 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -166,11 +166,12 @@ libshadow_la_SOURCES = \ semanage.c \ setugid.c \ setupenv.c \ - sgetgrent.c \ sgetpwent.c \ sgetspent.c \ sgroupio.c \ sgroupio.h \ + 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 ac1a5d637f..0af395a957 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -23,6 +23,7 @@ #include "getdef.h" #include "groupio.h" #include "prototypes.h" +#include "shadow/group/sgetgrent.h" #include "string/sprintf/aprintf.h" #include "string/strcmp/streq.h" diff --git a/lib/prototypes.h b/lib/prototypes.h index d8a88e372b..2d20395edc 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -397,9 +397,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 78% rename from lib/sgetgrent.c rename to lib/shadow/group/sgetgrent.c index f2f3f838b0..744a8f5cbc 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 "config.h" -#ident "$Id$" +#include "shadow/group/sgetgrent.h" #include #include @@ -56,6 +55,7 @@ list(char *s) } +// from-string get group entry struct group * sgetgrent(const char *s) { diff --git a/lib/shadow/group/sgetgrent.h b/lib/shadow/group/sgetgrent.h new file mode 100644 index 0000000000..fcf0166055 --- /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 "config.h" + +#include + + +struct group *sgetgrent(const char *s); + + +#endif // include guard diff --git a/po/POTFILES.in b/po/POTFILES.in index 614415c23d..af5cfa5dfd 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -56,10 +56,10 @@ 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/group/sgetgrent.c lib/shadowio.c lib/shadowmem.c lib/shell.c From b6d5ce1affa429ec7ca32b6bd483f92491d70b1a Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 10 Nov 2024 23:31:23 +0100 Subject: [PATCH 13/15] lib/shadow/, 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 (81%) create mode 100644 lib/shadow/passwd/sgetpwent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 25c915b507..25f0846651 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 \ @@ -192,6 +191,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 2d20395edc..92a2f759fb 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -397,9 +397,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 0674d71860..463f8378c8 100644 --- a/lib/pwio.c +++ b/lib/pwio.c @@ -18,6 +18,8 @@ #include "fields.h" #include "prototypes.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 81% rename from lib/sgetpwent.c rename to lib/shadow/passwd/sgetpwent.c index 2e5bbbd1c7..ddea1384b0 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 "config.h" -#ident "$Id$" +#include "shadow/passwd/sgetpwent.h" #include #include @@ -38,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 *s) { @@ -85,4 +85,3 @@ sgetpwent(const char *s) return &pwent; } - diff --git a/lib/shadow/passwd/sgetpwent.h b/lib/shadow/passwd/sgetpwent.h new file mode 100644 index 0000000000..7b82a5ce83 --- /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 "config.h" + +#include + + +struct passwd *sgetpwent(const char *s); + + +#endif // include guard diff --git a/po/POTFILES.in b/po/POTFILES.in index af5cfa5dfd..1da1ae19bd 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -56,10 +56,10 @@ lib/selinux.c lib/semanage.c lib/setugid.c lib/setupenv.c -lib/sgetpwent.c lib/sgetspent.c lib/sgroupio.c lib/shadow/group/sgetgrent.c +lib/shadow/passwd/sgetpwent.c lib/shadowio.c lib/shadowmem.c lib/shell.c From 29da890590aff62a65661b8698ae6ae349f89827 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 24 Feb 2025 23:06:39 +0100 Subject: [PATCH 14/15] lib/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 | 20 +++++++++----------- lib/shadow/shadow/sgetspent.h | 19 +++++++++++++++++++ lib/shadowio.c | 1 + po/POTFILES.in | 1 - 6 files changed, 31 insertions(+), 18 deletions(-) rename lib/{ => shadow/shadow}/sgetspent.c (89%) create mode 100644 lib/shadow/shadow/sgetspent.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 25f0846651..31e9c0ee32 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/group/sgetgrent.c \ @@ -193,6 +192,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 92a2f759fb..b5e18e52be 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -397,11 +397,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 89% rename from lib/sgetspent.c rename to lib/shadow/shadow/sgetspent.c index 762e6c9582..5026ef99db 100644 --- a/lib/sgetspent.c +++ b/lib/shadow/shadow/sgetspent.c @@ -1,18 +1,16 @@ -/* - * 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 "config.h" -/* Newer versions of Linux libc already have shadow support. */ -#ifndef HAVE_SGETSPENT +#include "shadow/shadow/sgetspent.h" -#ident "$Id$" +#ifndef HAVE_SGETSPENT #include #include diff --git a/lib/shadow/shadow/sgetspent.h b/lib/shadow/shadow/sgetspent.h new file mode 100644 index 0000000000..4f88d08a6b --- /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 "config.h" + +#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 dbbaac2c95..9fe5d097f1 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -18,6 +18,7 @@ #include "fields.h" #include "getdef.h" #include "prototypes.h" +#include "shadow/shadow/sgetspent.h" #include "shadowio.h" #ifdef WITH_TCB diff --git a/po/POTFILES.in b/po/POTFILES.in index 1da1ae19bd..376dec4e18 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/group/sgetgrent.c lib/shadow/passwd/sgetpwent.c From 8a20518a03be65098764d9f3833121b67116a3ee Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 28 Sep 2025 10:40:09 +0200 Subject: [PATCH 15/15] lib/: Use libc _FILE_SHADOW from Signed-off-by: Alejandro Colomar --- lib/defines.h | 4 ---- lib/prefix_flag.c | 2 +- lib/shadowio.c | 3 ++- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/defines.h b/lib/defines.h index 219724c9f3..0374f0f03c 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -157,10 +157,6 @@ #define GROUP_FILE "/etc/group" #endif -#ifndef SHADOW_FILE -#define SHADOW_FILE "/etc/shadow" -#endif - #ifndef SUBUID_FILE #define SUBUID_FILE "/etc/subuid" #endif diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index cb807c6ac4..dd5972cc72 100644 --- a/lib/prefix_flag.c +++ b/lib/prefix_flag.c @@ -122,7 +122,7 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char ** sgr_setdbname(sgroup_db_file); #endif - spw_db_file = xaprintf("%s/%s", prefix, SHADOW_FILE); + spw_db_file = xaprintf("%s/%s", prefix, _PATH_SHADOW); spw_setdbname(spw_db_file); #ifdef ENABLE_SUBIDS diff --git a/lib/shadowio.c b/lib/shadowio.c index 9fe5d097f1..bf71817519 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -10,6 +10,7 @@ #include "config.h" +#include #include #include @@ -82,7 +83,7 @@ static struct commonio_ops shadow_ops = { }; static struct commonio_db shadow_db = { - SHADOW_FILE, /* filename */ + _PATH_SHADOW, /* filename */ &shadow_ops, /* ops */ NULL, /* fp */ #ifdef WITH_SELINUX