]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/shadow/, lib/: sgetsgent(): Move to separate file
authorAlejandro Colomar <alx@kernel.org>
Sun, 10 Nov 2024 17:44:05 +0000 (18:44 +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/fgetsgent.c
lib/shadow/gshadow/sgetsgent.c [new file with mode: 0644]
lib/shadow/gshadow/sgetsgent.h [new file with mode: 0644]

index c6a2ce02fc369438d63855981ec5a2e5dadec739..dee5e095ab9a2f68291191c0a875e06f0bf03f11 100644 (file)
@@ -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 \
index 8f638f7f35c3a31fb9ea19bae556d2ee0da2c372..c6e1ff3ac0f724e9b342fb7ed32352e487f60731 100644 (file)
@@ -18,8 +18,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "alloc/malloc.h"
-#include "alloc/realloc.h"
 #include "defines.h"
 #include "prototypes.h"
 #include "shadow/gshadow/fgetsgent.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"
-#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
  */
index 007652b08f81339a2f9214daa74b8a6c02c87507..ac58136108f0ec362109475eb2a5c2baf89c3b57 100644 (file)
@@ -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"
 
index f191d7d06a50809ee2512dbfc7686e572f4e1ede..5c109657983034ab0e5ee0060bc6a80308e2b427 100644 (file)
@@ -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"
 
index 9424ab9406964ab4f4c90f81b4178c2f7ee4bf17..57e45fb5e189dd01f69736515921b9f8a51aac9c 100644 (file)
@@ -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 (file)
index 0000000..c15bb58
--- /dev/null
@@ -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 <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include "config.h"
+
+#include "shadow/gshadow/sgetsgent.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.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"
+
+
+#if defined(SHADOWGRP) && !__has_include(<gshadow.h>)
+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 (file)
index 0000000..65fda80
--- /dev/null
@@ -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 <alx@kernel.org>
+// 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(<gshadow.h>)
+# include <gshadow.h>
+#else
+struct sgrp *sgetsgent(const char *);
+#endif
+
+
+#endif  // include guard