Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure.ac, lib/, src/: Presume working shadow group support in libc #1111

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,6 @@ AC_CHECK_FUNC(secure_getenv, [AC_DEFINE(HAS_SECURE_GETENV,
1,
[Defined to 1 if you have the declaration of 'secure_getenv'])])

if test "$ac_cv_header_shadow_h" = "yes"; then
AC_CACHE_CHECK(for working shadow group support,
ac_cv_libc_shadowgrp,
AC_RUN_IFELSE([AC_LANG_SOURCE([
#include <shadow.h>
#ifdef HAVE_GSHADOW_H
#include <gshadow.h>
#endif
int
main()
{
struct sgrp *sg = sgetsgent("test:x::");
/* NYS libc on Red Hat 3.0.3 has broken shadow group support */
return !sg || !sg->sg_adm || !sg->sg_mem;
}]
)],
[ac_cv_libc_shadowgrp=yes],
[ac_cv_libc_shadowgrp=no],
[ac_cv_libc_shadowgrp=no]
)
)

if test "$ac_cv_libc_shadowgrp" = "yes"; then
AC_DEFINE(HAVE_SHADOWGRP, 1, [Have working shadow group support in libc])
fi
fi

AC_CACHE_CHECK([location of shared mail directory], shadow_cv_maildir,
[for shadow_cv_maildir in /var/mail /var/spool/mail /usr/spool/mail /usr/mail none; do
if test -d $shadow_cv_maildir; then
Expand Down
7 changes: 1 addition & 6 deletions lib/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,8 @@

#include <dirent.h>

/*
* Possible cases:
* - /usr/include/shadow.h exists and includes the shadow group stuff.
* - /usr/include/shadow.h exists, but we use our own gshadow.h.
*/
#include <shadow.h>
#if defined(SHADOWGRP) && !defined(GSHADOW)
#if defined(SHADOWGRP)
#include "gshadow_.h"
#endif

Expand Down
13 changes: 6 additions & 7 deletions lib/gshadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#include <config.h>

/* Newer versions of Linux libc already have shadow support. */
#if defined(SHADOWGRP) && !defined(HAVE_SHADOWGRP) /*{ */
#if defined(SHADOWGRP) && !defined(HAVE_GSHADOW_H)

#ident "$Id$"

Expand Down Expand Up @@ -107,7 +106,7 @@ sgetsgent(const char *string)
if (NULL != cp || i != FIELDS)
return NULL;

sgroup.sg_name = fields[0];
sgroup.sg_namp = fields[0];
sgroup.sg_passwd = fields[1];

free(sgroup.sg_adm);
Expand Down Expand Up @@ -193,7 +192,7 @@ sgetsgent(const char *string)
setsgent ();

while ((sgrp = getsgent ()) != NULL) {
if (streq(name, sgrp->sg_name)) {
if (streq(name, sgrp->sg_namp)) {
break;
}
}
Expand All @@ -219,7 +218,7 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
}

/* calculate the required buffer size */
size = strlen (sgrp->sg_name) + strlen (sgrp->sg_passwd) + 10;
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;
}
Expand All @@ -236,7 +235,7 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
/*
* Copy the group name and passwd.
*/
cp = stpcpy(stpcpy(cp, sgrp->sg_name), ":");
cp = stpcpy(stpcpy(cp, sgrp->sg_namp), ":");
cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":");

/*
Expand Down Expand Up @@ -276,4 +275,4 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
}
#else
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /*} SHADOWGRP */
#endif // !SHADOWGRP
31 changes: 17 additions & 14 deletions lib/gshadow_.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
* SPDX-FileCopyrightText: 1988 - 1994, Julianne Frances Haugh
* SPDX-FileCopyrightText: 1996 - 1997, Marek Michałkiewicz
* SPDX-FileCopyrightText: 2003 - 2005, Tomasz Kłoczko
*
* SPDX-License-Identifier: BSD-3-Clause
*/
// 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 <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause

/*
* $Id$
*/

#ifndef _H_GSHADOW
#define _H_GSHADOW
#ifndef SHADOW_INCLUDE_LIB_GSHADOW__H_
#define SHADOW_INCLUDE_LIB_GSHADOW__H_


#if defined(HAVE_GSHADOW_H)
# include <gshadow.h>
#else

/*
* Shadow group security file structure
*/

struct sgrp {
char *sg_name; /* group name */
char *sg_namp; /* group name */
char *sg_passwd; /* group password */
char **sg_adm; /* group administrator list */
char **sg_mem; /* group membership list */
Expand All @@ -39,4 +39,7 @@ void endsgent (void);
int putsgent (const struct sgrp *, FILE *);

#define GSHADOW "/etc/gshadow"
#endif /* ifndef _H_GSHADOW */


#endif // !HAVE_GSHADOW_H
#endif // include guard
20 changes: 10 additions & 10 deletions lib/sgroupio.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
/* Do the same as the other _dup function, even if we know the
* structure. */
/*@-mustfreeonly@*/
sg->sg_name = strdup (sgent->sg_name);
sg->sg_namp = strdup (sgent->sg_namp);
/*@=mustfreeonly@*/
if (NULL == sg->sg_name) {
if (NULL == sg->sg_namp) {
free (sg);
return NULL;
}
/*@-mustfreeonly@*/
sg->sg_passwd = strdup (sgent->sg_passwd);
/*@=mustfreeonly@*/
if (NULL == sg->sg_passwd) {
free (sg->sg_name);
free (sg->sg_namp);
free (sg);
return NULL;
}
Expand All @@ -57,7 +57,7 @@
/*@=mustfreeonly@*/
if (NULL == sg->sg_adm) {
free (sg->sg_passwd);
free (sg->sg_name);
free (sg->sg_namp);
free (sg);
return NULL;
}
Expand All @@ -69,7 +69,7 @@
}
free (sg->sg_adm);
free (sg->sg_passwd);
free (sg->sg_name);
free (sg->sg_namp);
free (sg);
return NULL;
}
Expand All @@ -86,7 +86,7 @@
}
free (sg->sg_adm);
free (sg->sg_passwd);
free (sg->sg_name);
free (sg->sg_namp);
free (sg);
return NULL;
}
Expand All @@ -102,7 +102,7 @@
}
free (sg->sg_adm);
free (sg->sg_passwd);
free (sg->sg_name);
free (sg->sg_namp);
free (sg);
return NULL;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ void
sgr_free(/*@only@*/struct sgrp *sgent)
{
size_t i;
free (sgent->sg_name);
free (sgent->sg_namp);
if (NULL != sgent->sg_passwd)
free(strzero(sgent->sg_passwd));

Expand All @@ -150,7 +150,7 @@ static const char *gshadow_getname (const void *ent)
{
const struct sgrp *gr = ent;

return gr->sg_name;
return gr->sg_namp;
}

static void *gshadow_parse (const char *line)
Expand All @@ -163,7 +163,7 @@ static int gshadow_put (const void *ent, FILE * file)
const struct sgrp *sg = ent;

if ( (NULL == sg)
|| (valid_field (sg->sg_name, ":\n") == -1)
|| (valid_field (sg->sg_namp, ":\n") == -1)
|| (valid_field (sg->sg_passwd, ":\n") == -1)) {
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/chgpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ int main (int argc, char **argv)
* group, but there are no entries in
* gshadow, create one.
*/
newsg.sg_name = name;
newsg.sg_namp = name;
/* newsg.sg_passwd = NULL; will be set later */
newsg.sg_adm = &empty;
newsg.sg_mem = dup_list (gr->gr_mem);
Expand Down Expand Up @@ -595,7 +595,7 @@ int main (int argc, char **argv)
if (sgr_update (&newsg) == 0) {
fprintf (stderr,
_("%s: line %jd: failed to prepare the new %s entry '%s'\n"),
Prog, line, sgr_dbname (), newsg.sg_name);
Prog, line, sgr_dbname (), newsg.sg_namp);
errors = true;
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/gpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ static void update_group (struct group *gr)
if (is_shadowgrp && (sgr_update (sg) == 0)) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), sg->sg_name);
Prog, sgr_dbname (), sg->sg_namp);
exit (1);
}
#endif /* SHADOWGRP */
Expand Down Expand Up @@ -774,13 +774,13 @@ static void get_group (struct group *gr)
tmpsg = sgr_locate (group);
if (NULL != tmpsg) {
*sg = *tmpsg;
sg->sg_name = xstrdup (tmpsg->sg_name);
sg->sg_namp = xstrdup (tmpsg->sg_namp);
sg->sg_passwd = xstrdup (tmpsg->sg_passwd);

sg->sg_mem = dup_list (tmpsg->sg_mem);
sg->sg_adm = dup_list (tmpsg->sg_adm);
} else {
sg->sg_name = xstrdup (group);
sg->sg_namp = xstrdup (group);
sg->sg_passwd = gr->gr_passwd;
gr->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */

Expand Down
4 changes: 2 additions & 2 deletions src/groupadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void new_grent (struct group *grent)
static void new_sgent (struct sgrp *sgent)
{
memzero (sgent, sizeof *sgent);
sgent->sg_name = group_name;
sgent->sg_namp = group_name;
if (pflg) {
sgent->sg_passwd = group_passwd;
} else {
Expand Down Expand Up @@ -231,7 +231,7 @@ grp_update(void)
if (is_shadow_grp && (sgr_update (&sgrp) == 0)) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), sgrp.sg_name);
Prog, sgr_dbname (), sgrp.sg_namp);
exit (E_GRP_UPDATE);
}
#endif /* SHADOWGRP */
Expand Down
12 changes: 6 additions & 6 deletions src/groupmems.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void add_user (const char *user,
if (NULL == sg) {
/* Create a shadow group based on this group */
static struct sgrp sgrent;
sgrent.sg_name = xstrdup (newgrp->gr_name);
sgrent.sg_namp = xstrdup (newgrp->gr_name);
sgrent.sg_mem = dup_list (newgrp->gr_mem);
sgrent.sg_adm = XMALLOC(1, char *);
sgrent.sg_adm[0] = NULL;
Expand All @@ -154,7 +154,7 @@ static void add_user (const char *user,
if (sgr_update (newsg) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), newsg->sg_name);
Prog, sgr_dbname (), newsg->sg_namp);
fail_exit (13);
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ static void remove_user (const char *user,
if (NULL == sg) {
/* Create a shadow group based on this group */
static struct sgrp sgrent;
sgrent.sg_name = xstrdup (newgrp->gr_name);
sgrent.sg_namp = xstrdup (newgrp->gr_name);
sgrent.sg_mem = dup_list (newgrp->gr_mem);
sgrent.sg_adm = XMALLOC(1, char *);
sgrent.sg_adm[0] = NULL;
Expand All @@ -230,7 +230,7 @@ static void remove_user (const char *user,
if (sgr_update (newsg) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), newsg->sg_name);
Prog, sgr_dbname (), newsg->sg_namp);
fail_exit (13);
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ static void purge_members (const struct group *grp)
if (NULL == sg) {
/* Create a shadow group based on this group */
static struct sgrp sgrent;
sgrent.sg_name = xstrdup (newgrp->gr_name);
sgrent.sg_namp = xstrdup (newgrp->gr_name);
sgrent.sg_mem = XMALLOC(1, char *);
sgrent.sg_mem[0] = NULL;
sgrent.sg_adm = XMALLOC(1, char *);
Expand Down Expand Up @@ -299,7 +299,7 @@ static void purge_members (const struct group *grp)
if (sgr_update (newsg) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), newsg->sg_name);
Prog, sgr_dbname (), newsg->sg_namp);
fail_exit (13);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/groupmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static void new_grent (struct group *grent)
static void new_sgent (struct sgrp *sgent)
{
if (nflg) {
sgent->sg_name = xstrdup (group_newname);
sgent->sg_namp = xstrdup (group_newname);
}

/* Always update the shadowed password if there is a shadow entry
Expand Down Expand Up @@ -238,7 +238,7 @@ grp_update(void)
* gshadow entry when a new password is requested.
*/
bzero(&sgrp, sizeof sgrp);
sgrp.sg_name = xstrdup (grp.gr_name);
sgrp.sg_namp = xstrdup (grp.gr_name);
sgrp.sg_passwd = xstrdup (grp.gr_passwd);
sgrp.sg_adm = &empty;
sgrp.sg_mem = dup_list (grp.gr_mem);
Expand Down Expand Up @@ -318,7 +318,7 @@ grp_update(void)
if (sgr_update (&sgrp) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), sgrp.sg_name);
Prog, sgr_dbname (), sgrp.sg_namp);
exit (E_GRP_UPDATE);
}
if (nflg && (sgr_remove (group_name) == 0)) {
Expand Down
Loading
Loading