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 \
#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
*/
/*@observer@*//*@null@*/struct sgrp *getsgent (void);
/*@observer@*//*@null@*/struct sgrp *getsgnam (const char *);
-/*@observer@*//*@null@*/struct sgrp *sgetsgent (const char *);
#define GSHADOW "/etc/gshadow"
#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"
#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"
}
}
stpsep(buf, "\n");
- return (sgetsgent (buf));
+ return sgetsgent(buf);
}
#endif
--- /dev/null
+// 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
--- /dev/null
+// 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