diff --git a/lib/Makefile.am b/lib/Makefile.am index 6c68cfa1eb..31e9c0ee32 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 \ @@ -167,13 +166,34 @@ libshadow_la_SOURCES = \ semanage.c \ setugid.c \ setupenv.c \ - sgetgrent.c \ - sgetpwent.c \ - sgetspent.c \ sgroupio.c \ - sgroupio.h\ + sgroupio.h \ + shadow/group/sgetgrent.c \ + shadow/group/sgetgrent.h \ shadow/grp/agetgroups.c \ shadow/grp/agetgroups.h \ + shadow/gshadow/endsgent.c \ + 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 \ + shadow/gshadow/gshadow.h \ + shadow/gshadow/putsgent.c \ + 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 \ + shadow/passwd/sgetpwent.c \ + shadow/passwd/sgetpwent.h \ + shadow/shadow/sgetspent.c \ + shadow/shadow/sgetspent.h \ shadowio.c \ shadowio.h \ shadowlog.c \ @@ -308,5 +328,4 @@ endif EXTRA_DIST = \ .indent.pro \ - gshadow_.h \ xgetXXbyYY.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/defines.h b/lib/defines.h index 8673a09f4f..0374f0f03c 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -51,9 +51,6 @@ #include #include -#if defined(SHADOWGRP) -#include "gshadow_.h" -#endif #include @@ -160,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 @@ -172,12 +165,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/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/gshadow.c b/lib/gshadow.c deleted file mode 100644 index 2bde386954..0000000000 --- a/lib/gshadow.c +++ /dev/null @@ -1,253 +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 "alloc/malloc.h" -#include "alloc/realloc.h" -#include "defines.h" -#include "prototypes.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 = {}; - - -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; -} - -void setsgent (void) -{ - if (NULL != shadow) { - rewind (shadow); - } else { - shadow = fopen (SGROUP_FILE, "re"); - } -} - -void endsgent (void) -{ - if (NULL != shadow) { - (void) fclose (shadow); - } - - shadow = NULL; -} - -/*@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; -} - -/* - * 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 - */ - -/*@observer@*//*@null@*/struct sgrp *getsgent (void) -{ - if (NULL == shadow) { - setsgent (); - } - return (fgetsgent (shadow)); -} - -/* - * 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; -} - -/* - * 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 deleted file mode 100644 index 2b38cb338e..0000000000 --- a/lib/gshadow_.h +++ /dev/null @@ -1,45 +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 - -/* - * 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 /* for FILE */ - -/*@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 *); -void setsgent (void); -void endsgent (void); -int putsgent (const struct sgrp *, FILE *); - -#define GSHADOW "/etc/gshadow" - - -#endif // !__has_include() -#endif // include guard diff --git a/lib/prefix_flag.c b/lib/prefix_flag.c index f69aa10606..dd5972cc72 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,11 +118,11 @@ 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 - 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/prototypes.h b/lib/prototypes.h index 4063ae1644..b5e18e52be 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) @@ -395,17 +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); - -/* 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/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/sgroupio.c b/lib/sgroupio.c index c31ef835e3..5c10965798 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,10 @@ #include "fields.h" #include "getdef.h" #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" @@ -205,7 +209,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/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/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/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/lib/shadow/gshadow/fgetsgent.c b/lib/shadow/gshadow/fgetsgent.c new file mode 100644 index 0000000000..57e45fb5e1 --- /dev/null +++ b/lib/shadow/gshadow/fgetsgent.c @@ -0,0 +1,78 @@ +// 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/sgetsgent.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 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 new file mode 100644 index 0000000000..86fb9ad49d --- /dev/null +++ b/lib/shadow/gshadow/getsgnam.c @@ -0,0 +1,41 @@ +// 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/getsgent.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/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..42f74823bc --- /dev/null +++ b/lib/shadow/gshadow/gshadow.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_GSHADOW_H_ +#define SHADOW_INCLUDE_LIB_SHADOW_GSHADOW_GSHADOW_H_ + + +#include "config.h" + +#include +#include + + +#ifndef _PATH_GSHADOW +# define _PATH_GSHADOW "/etc/gshadow" +#endif + + +extern FILE *gshadow; + + +#endif // include guard diff --git a/lib/shadow/gshadow/putsgent.c b/lib/shadow/gshadow/putsgent.c new file mode 100644 index 0000000000..cd8dc024b4 --- /dev/null +++ b/lib/shadow/gshadow/putsgent.c @@ -0,0 +1,99 @@ +// 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" +#include "shadow/gshadow/sgrp.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..22ed38ea73 --- /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 "shadow/gshadow/sgrp.h" + + +#if __has_include() +# include +#else +int putsgent(const struct sgrp *sgrp, FILE *fp); +#endif + + +#endif // include guard 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 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 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/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/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..bf71817519 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -10,6 +10,7 @@ #include "config.h" +#include #include #include @@ -18,6 +19,7 @@ #include "fields.h" #include "getdef.h" #include "prototypes.h" +#include "shadow/shadow/sgetspent.h" #include "shadowio.h" #ifdef WITH_TCB @@ -81,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 diff --git a/po/POTFILES.in b/po/POTFILES.in index a925b2350b..376dec4e18 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 @@ -57,10 +56,9 @@ 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/shadow/passwd/sgetpwent.c lib/shadowio.c lib/shadowmem.c lib/shell.c 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 4f31986bb5..8721d4afba 100644 --- a/src/grpck.c +++ b/src/grpck.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,8 @@ #include "groupio.h" #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" @@ -31,6 +34,7 @@ #include "sgroupio.h" #endif + /* * Exit codes */ @@ -52,7 +56,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/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 f9b24d8127..4a822f7ed5 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,8 @@ #ifdef SHADOWGRP #include "groupio.h" #include "sgroupio.h" +#include "shadow/gshadow/gshadow.h" +#include "shadow/gshadow/sgrp.h" #include "shadowlog.h" @@ -201,11 +202,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); } 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..51b1dcc060 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -27,6 +27,9 @@ #include "search/l/lfind.h" #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" #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 8295165a52..17288d07b3 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -60,6 +60,8 @@ #ifdef WITH_TCB #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"