From: Alejandro Colomar Date: Sun, 10 Nov 2024 14:27:43 +0000 (+0100) Subject: lib/shadow/, lib/: putsgent(): Move to separate file X-Git-Tag: 4.19.0-rc1~145 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27097d59d1620b93dd3a7106a8c0c2e750709202;p=thirdparty%2Fshadow.git lib/shadow/, lib/: putsgent(): Move to separate file Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 6c68cfa1e..0d1d81ed5 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 2bde38695..4d692a28e 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 2b38cb338..21fa21061 100644 --- a/lib/gshadow_.h +++ b/lib/gshadow_.h @@ -36,7 +36,6 @@ struct sgrp { /*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE *); void setsgent (void); void endsgent (void); -int putsgent (const struct sgrp *, FILE *); #define GSHADOW "/etc/gshadow" diff --git a/lib/sgroupio.c b/lib/sgroupio.c index c31ef835e..b6127252b 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 000000000..4ddd5f3f2 --- /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 000000000..ad6fe3933 --- /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