Skip to content

Commit

Permalink
lib/gshadow_.h: Fix compatibility with libc's struct sgrp
Browse files Browse the repository at this point in the history
The name of the first field was different.  Rename for compatiblity with
libc.

	$ diff -wU10 \
		<(grepc sgrp . | sed_rm_ccomments) \
		<(grepc sgrp /usr/include/ | sed_rm_ccomments);
	--- /dev/fd/63	2024-11-06 14:49:03.287204461 +0100
	+++ /dev/fd/62	2024-11-06 14:49:03.287204461 +0100
	@@ -1,6 +1,7 @@
	-./lib/gshadow_.h:struct sgrp {
	-	char *sg_name;
	+/usr/include/gshadow.h:struct sgrp
	+  {
	+    char *sg_namp;
		char *sg_passwd;
		char **sg_adm;
		char **sg_mem;
	 };

This originates from a typo in this project, which was later copied by
glibc, and so the typo was set in stone.  The typo was eventually fixed
in shadow, but glibc had already set the name in stone, so we should
just learn to live with it.

	$ grep -rn -C3 sg_name ChangeLog
	1607-
	1608-2011-07-30  Nicolas François  <nicolas.francois@centraliens.net>
	1609-
	1610:	* src/chgpasswd.c: Fix typo sp -> sg. sg_namp -> sg_name
	1611-	* src/chgpasswd.c: Always update the group file when SHADOWGRP is
	1612-	not enabled.
	1613-

This is a scripted change:

	$ find lib* src -type f \
	| xargs sed -i 's/\<sg_name\>/sg_namp/g';

Signed-off-by: Alejandro Colomar <alx@kernel.org>
  • Loading branch information
alejandro-colomar committed Nov 6, 2024
1 parent e0f15b7 commit d8090da
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 59 deletions.
8 changes: 4 additions & 4 deletions lib/gshadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void endsgent (void)
if (NULL != cp || i != FIELDS)
return 0;

sgroup.sg_name = fields[0];
sgroup.sg_namp = fields[0];
sgroup.sg_passwd = fields[1];
if (0 != nadmins) {
nadmins = 0;
Expand Down Expand Up @@ -202,7 +202,7 @@ void endsgent (void)
setsgent ();

while ((sgrp = getsgent ()) != NULL) {
if (strcmp (name, sgrp->sg_name) == 0) {
if (strcmp (name, sgrp->sg_namp) == 0) {
break;
}
}
Expand All @@ -228,7 +228,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 @@ -245,7 +245,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
2 changes: 1 addition & 1 deletion lib/gshadow_.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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 Down
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 @@ -555,7 +555,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 @@ -593,7 +593,7 @@ int main (int argc, char **argv)
if (sgr_update (&newsg) == 0) {
fprintf (stderr,
_("%s: line %d: failed to prepare the new %s entry '%s'\n"),
Prog, line, sgr_dbname (), newsg.sg_name);
Prog, line, sgr_dbname (), newsg.sg_namp);
errors++;
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/gpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,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 @@ -771,13 +771,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 @@ -148,7 +148,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 @@ -224,7 +224,7 @@ static void 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 @@ -127,7 +127,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 @@ -153,7 +153,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 @@ -202,7 +202,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 @@ -229,7 +229,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 @@ -268,7 +268,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 @@ -298,7 +298,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 @@ -176,7 +176,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 @@ -235,7 +235,7 @@ static void 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 @@ -300,7 +300,7 @@ static void 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
14 changes: 7 additions & 7 deletions src/grpck.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static void check_grp_file (int *errors, bool *changed)
struct group gr;
static char *empty = NULL;

sg.sg_name = grp->gr_name;
sg.sg_namp = grp->gr_name;
sg.sg_passwd = grp->gr_passwd;
sg.sg_adm = &empty;
sg.sg_mem = grp->gr_mem;
Expand All @@ -622,7 +622,7 @@ static void check_grp_file (int *errors, bool *changed)
if (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);
fail_exit (E_CANT_UPDATE);
}
/* remove password from /etc/group */
Expand Down Expand Up @@ -737,7 +737,7 @@ static void check_sgr_file (int *errors, bool *changed)
continue;
}

if (strcmp (sgr->sg_name, ent->sg_name) != 0) {
if (strcmp (sgr->sg_namp, ent->sg_namp) != 0) {
continue;
}

Expand All @@ -760,7 +760,7 @@ static void check_sgr_file (int *errors, bool *changed)
/*
* Make sure this entry exists in the /etc/group file.
*/
grp = gr_locate (sgr->sg_name);
grp = gr_locate (sgr->sg_namp);
if (grp == NULL) {
printf (_("no matching group file entry in %s\n"),
grp_file);
Expand All @@ -774,15 +774,15 @@ static void check_sgr_file (int *errors, bool *changed)
* Verify that the all members defined in /etc/gshadow are also
* present in /etc/group.
*/
compare_members_lists (sgr->sg_name,
compare_members_lists (sgr->sg_namp,
sgr->sg_mem, grp->gr_mem,
sgr_file, grp_file);
}

/*
* Make sure each administrator exists
*/
if (check_members (sgr->sg_name, sgr->sg_adm,
if (check_members (sgr->sg_namp, sgr->sg_adm,
_("shadow group %s: no administrative user %s\n"),
_("delete administrative member '%s'? "),
"delete admin '%s' from shadow group '%s'",
Expand All @@ -795,7 +795,7 @@ static void check_sgr_file (int *errors, bool *changed)
/*
* Make sure each member exists
*/
if (check_members (sgr->sg_name, sgr->sg_mem,
if (check_members (sgr->sg_namp, sgr->sg_mem,
_("shadow group %s: no user %s\n"),
_("delete member '%s'? "),
"delete member '%s' from shadow group '%s'",
Expand Down
10 changes: 5 additions & 5 deletions src/grpconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ int main (int argc, char **argv)
*/
(void) sgr_rewind ();
while ((sg = sgr_next ()) != NULL) {
if (gr_locate (sg->sg_name) != NULL) {
if (gr_locate (sg->sg_namp) != NULL) {
continue;
}

if (sgr_remove (sg->sg_name) == 0) {
if (sgr_remove (sg->sg_namp) == 0) {
/*
* This shouldn't happen (the entry exists) but...
*/
fprintf (stderr,
_("%s: cannot remove entry '%s' from %s\n"),
Prog, sg->sg_name, sgr_dbname ());
Prog, sg->sg_namp, sgr_dbname ());
fail_exit (3);
}
(void) sgr_rewind ();
Expand All @@ -201,7 +201,7 @@ int main (int argc, char **argv)

/* add new shadow group entry */
bzero(&sgent, sizeof sgent);
sgent.sg_name = gr->gr_name;
sgent.sg_namp = gr->gr_name;
sgent.sg_passwd = gr->gr_passwd;
sgent.sg_adm = &empty;
}
Expand All @@ -216,7 +216,7 @@ int main (int argc, char **argv)
if (sgr_update (&sgent) == 0) {
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), sgent.sg_name);
Prog, sgr_dbname (), sgent.sg_namp);
fail_exit (3);
}
/* remove password from /etc/group */
Expand Down
2 changes: 1 addition & 1 deletion src/newusers.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid)
if (is_shadow_grp) {
struct sgrp sgrent;
char *admins[1];
sgrent.sg_name = grent.gr_name;
sgrent.sg_namp = grent.gr_name;
sgrent.sg_passwd = "*"; /* XXX warning: const */
grent.gr_passwd = "x"; /* XXX warning: const */
admins[0] = NULL;
Expand Down
Loading

0 comments on commit d8090da

Please sign in to comment.