Split check_members() out of check_grp_file() and check_sgr_file().

This commit is contained in:
nekral-guest 2008-01-01 13:50:06 +00:00
parent 612820cb9a
commit 3d82d5e452
2 changed files with 81 additions and 99 deletions

View File

@ -5,6 +5,8 @@
sort_mode, use_system_grp_file, and use_system_sgr_file. sort_mode, use_system_grp_file, and use_system_sgr_file.
* src/grpck.c: Split check_grp_file() and check_sgr_file() out of * src/grpck.c: Split check_grp_file() and check_sgr_file() out of
main(). main().
* src/grpck.c: Split check_members() out of check_grp_file() and
check_sgr_file().
2007-12-31 Nicolas François <nicolas.francois@centraliens.net> 2007-12-31 Nicolas François <nicolas.francois@centraliens.net>

View File

@ -260,11 +260,67 @@ static void close_files (int changed)
(void) gr_unlock (); (void) gr_unlock ();
} }
static int check_members (const char *groupname,
char **members,
const char *fmt_info,
const char *fmt_prompt,
const char *fmt_syslog,
int *errors)
{
int i;
int members_changed = 0;
/*
* Make sure each member exists
*/
for (i = 0; members[i]; i++) {
/* local, no need for xgetpwnam */
if (getpwnam (members[i]))
continue;
/*
* Can't find this user. Remove them
* from the list.
*/
*errors += 1;
printf (fmt_info, groupname, members[i]);
printf (fmt_prompt, members[i]);
if (!yes_or_no (read_only))
continue;
SYSLOG ((LOG_INFO, fmt_syslog, members[i], groupname));
members_changed = 1;
delete_member (members, members[i]);
}
return members_changed;
}
static void compare_members_lists (const char *groupname,
char **members,
char **other_members,
const char *file,
const char *other_file)
{
char **pmem, **other_pmem;
for (pmem = members; *pmem; pmem++) {
for (other_pmem = other_members; *other_pmem; other_pmem++) {
if (strcmp (*pmem, *other_pmem) == 0)
break;
}
if (*other_pmem == NULL) {
printf
("'%s' is a member of the '%s' group in %s but not in %s\n",
*pmem, groupname, file, other_file);
}
}
}
static void check_grp_file (int *errors, int *changed) static void check_grp_file (int *errors, int *changed)
{ {
struct commonio_entry *gre, *tgre; struct commonio_entry *gre, *tgre;
struct group *grp; struct group *grp;
int i;
#ifdef SHADOWGRP #ifdef SHADOWGRP
struct sgrp *sgr; struct sgrp *sgr;
#endif #endif
@ -375,29 +431,12 @@ static void check_grp_file (int *errors, int *changed)
&& *(grp->gr_mem[0]) == '\0') && *(grp->gr_mem[0]) == '\0')
grp->gr_mem[0] = (char *) 0; grp->gr_mem[0] = (char *) 0;
/* if (check_members (grp->gr_name, grp->gr_mem,
* Make sure each member exists _("group %s: no user %s\n"),
*/ _("delete member '%s'? "),
for (i = 0; grp->gr_mem[i]; i++) { "delete member `%s' from group `%s'",
/* local, no need for xgetpwnam */ errors) == 1) {
if (getpwnam (grp->gr_mem[i]))
continue;
/*
* Can't find this user. Remove them
* from the list.
*/
*errors += 1;
printf (_("group %s: no user %s\n"),
grp->gr_name, grp->gr_mem[i]);
printf (_("delete member '%s'? "), grp->gr_mem[i]);
if (!yes_or_no (read_only))
continue;
SYSLOG ((LOG_INFO, "delete member '%s' group '%s'",
grp->gr_mem[i], grp->gr_name));
*changed = 1; *changed = 1;
delete_member (grp->gr_mem, grp->gr_mem[i]);
gre->changed = 1; gre->changed = 1;
__gr_set_changed (); __gr_set_changed ();
} }
@ -450,26 +489,12 @@ static void check_grp_file (int *errors, int *changed)
} }
} else { } else {
/** /**
* Verify that the all members defined in /etc/group are also * Verify that all the members defined in /etc/group are also
* present in /etc/gshadow. * present in /etc/gshadow.
*/ */
char **pgrp_mem, **psgr_mem; compare_members_lists (grp->gr_name,
grp->gr_mem, sgr->sg_mem,
for (pgrp_mem = grp->gr_mem; *pgrp_mem; grp_file, sgr_file);
pgrp_mem++) {
for (psgr_mem = sgr->sg_mem; *psgr_mem;
psgr_mem++) {
if (strcmp
(*pgrp_mem, *psgr_mem) == 0)
break;
}
if (*psgr_mem == NULL) {
printf
("'%s' is a member of the '%s' group in %s but not in %s\n",
*pgrp_mem, sgr->sg_name,
grp_file, sgr_file);
}
}
} }
} }
#endif #endif
@ -483,7 +508,6 @@ static void check_sgr_file (int *errors, int *changed)
struct group *grp; struct group *grp;
struct commonio_entry *sge, *tsge; struct commonio_entry *sge, *tsge;
struct sgrp *sgr; struct sgrp *sgr;
int i;
/* /*
* Loop through the entire shadow group file. * Loop through the entire shadow group file.
@ -584,49 +608,20 @@ static void check_sgr_file (int *errors, int *changed)
* Verify that the all members defined in /etc/gshadow are also * Verify that the all members defined in /etc/gshadow are also
* present in /etc/group. * present in /etc/group.
*/ */
char **pgrp_mem, **psgr_mem; compare_members_lists (sgr->sg_name,
sgr->sg_mem, grp->gr_mem,
for (psgr_mem = sgr->sg_mem; *psgr_mem; psgr_mem++) { sgr_file, grp_file);
for (pgrp_mem = grp->gr_mem; *pgrp_mem;
pgrp_mem++) {
if (strcmp (*pgrp_mem, *psgr_mem) == 0)
break;
}
if (*pgrp_mem == NULL) {
printf
("'%s' is a member of the '%s' group in %s but not in %s\n",
*psgr_mem, sgr->sg_name, sgr_file,
grp_file);
}
}
} }
/* /*
* Make sure each administrator exists * Make sure each administrator exists
*/ */
for (i = 0; sgr->sg_adm[i]; i++) { if (check_members (sgr->sg_name, sgr->sg_adm,
/* local, no need for xgetpwnam */ _("shadow group %s: no administrative user %s\n"),
if (getpwnam (sgr->sg_adm[i])) _("delete administrative member '%s'? "),
continue; "delete admin `%s' from shadow group `%s'",
/* errors) == 1) {
* Can't find this user. Remove them
* from the list.
*/
*errors += 1;
printf (_
("shadow group %s: no administrative user %s\n"),
sgr->sg_name, sgr->sg_adm[i]);
printf (_("delete administrative member '%s'? "),
sgr->sg_adm[i]);
if (!yes_or_no (read_only))
continue;
SYSLOG ((LOG_INFO,
"delete admin `%s' from shadow group `%s'",
sgr->sg_adm[i], sgr->sg_name));
*changed = 1; *changed = 1;
delete_member (sgr->sg_adm, sgr->sg_adm[i]);
sge->changed = 1; sge->changed = 1;
__sgr_set_changed (); __sgr_set_changed ();
} }
@ -634,27 +629,12 @@ static void check_sgr_file (int *errors, int *changed)
/* /*
* Make sure each member exists * Make sure each member exists
*/ */
for (i = 0; sgr->sg_mem[i]; i++) { if (check_members (sgr->sg_name, sgr->sg_mem,
/* local, no need for xgetpwnam */ _("shadow group %s: no user %s\n"),
if (getpwnam (sgr->sg_mem[i])) _("delete member '%s'? "),
continue; "delete member `%s' from shadow group `%s'",
errors) == 1) {
/*
* Can't find this user. Remove them from the list.
*/
*errors += 1;
printf (_("shadow group %s: no user %s\n"),
sgr->sg_name, sgr->sg_mem[i]);
printf (_("delete member '%s'? "), sgr->sg_mem[i]);
if (!yes_or_no (read_only))
continue;
SYSLOG ((LOG_INFO,
"delete member `%s' from shadow group `%s'",
sgr->sg_mem[i], sgr->sg_name));
*changed = 1; *changed = 1;
delete_member (sgr->sg_mem, sgr->sg_mem[i]);
sge->changed = 1; sge->changed = 1;
__sgr_set_changed (); __sgr_set_changed ();
} }