]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/shadow/, lib/: putsgent(): Move to separate file
authorAlejandro Colomar <alx@kernel.org>
Sun, 10 Nov 2024 14:27:43 +0000 (15:27 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 7 Oct 2025 09:03:09 +0000 (11:03 +0200)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/gshadow.c
lib/gshadow_.h
lib/sgroupio.c
lib/shadow/gshadow/putsgent.c [new file with mode: 0644]
lib/shadow/gshadow/putsgent.h [new file with mode: 0644]

index 6c68cfa1eb56be64ace1533f84777dd2d5b8948c..0d1d81ed51776a9ad514e4ff70e085ef919d0074 100644 (file)
@@ -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 \
index 2bde386954d7c676dcf527a84b3dff93da9a40ef..4d692a28ec2746a0bfa4b940c67f067074cb5087 100644 (file)
@@ -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
index 2b38cb338e7724c2d86c4ccff9f805e1a705e408..21fa210612c8fef5b1748552f095374f0af0b61b 100644 (file)
@@ -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"
 
index c31ef835e38891ac4e059cc14808b0244a5fc011..b6127252bac80ad98626b81d11f9759ee053b492 100644 (file)
@@ -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 (file)
index 0000000..4ddd5f3
--- /dev/null
@@ -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 <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include "config.h"
+
+#include "shadow/gshadow/putsgent.h"
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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(<gshadow.h>)
+// 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 (file)
index 0000000..ad6fe39
--- /dev/null
@@ -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 <alx@kernel.org>
+// 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 <stdio.h>
+
+#include "gshadow_.h"
+
+
+#if __has_include(<gshadow.h>)
+# include <gshadow.h>
+#else
+int putsgent(const struct sgrp *sgrp, FILE *fp);
+#endif
+
+
+#endif  // include guard