From: Alejandro Colomar Date: Sun, 10 Nov 2024 17:18:19 +0000 (+0100) Subject: lib/shadow/, lib/: fgetsgent(): Move to separate file X-Git-Tag: 4.19.0-rc1~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3aeee0878c37d217a8556f28cf8d2ad50255293;p=thirdparty%2Fshadow.git lib/shadow/, lib/: fgetsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 5138d5b52..c6a2ce02f 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 072f4d475..8f638f7f3 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 63223e962..007652b08 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -16,15 +16,12 @@ #include -#include /* for FILE */ - #include "shadow/gshadow/sgrp.h" /*@observer@*//*@null@*/struct sgrp *getsgent (void); /*@observer@*//*@null@*/struct sgrp *getsgnam (const char *); /*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *); -/*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE *); #define GSHADOW "/etc/gshadow" diff --git a/lib/shadow/gshadow/fgetsgent.c b/lib/shadow/gshadow/fgetsgent.c new file mode 100644 index 000000000..9424ab940 --- /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 000000000..e40fbbd9a --- /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