Split check_grp_file() and check_sgr_file() out of main().
This commit is contained in:
parent
f6f6eeda8e
commit
612820cb9a
@ -3,6 +3,8 @@
|
|||||||
* src/grpck.c: Split process_flags(), open_files(), and
|
* src/grpck.c: Split process_flags(), open_files(), and
|
||||||
close_files() out of main(). New global variables is_shadow,
|
close_files() out of main(). New global variables is_shadow,
|
||||||
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
|
||||||
|
main().
|
||||||
|
|
||||||
2007-12-31 Nicolas François <nicolas.francois@centraliens.net>
|
2007-12-31 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
125
src/grpck.c
125
src/grpck.c
@ -260,47 +260,15 @@ static void close_files (int changed)
|
|||||||
(void) gr_unlock ();
|
(void) gr_unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void check_grp_file (int *errors, int *changed)
|
||||||
* grpck - verify group file integrity
|
|
||||||
*/
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
int errors = 0;
|
|
||||||
int changed = 0;
|
|
||||||
int i;
|
|
||||||
struct commonio_entry *gre, *tgre;
|
struct commonio_entry *gre, *tgre;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
|
int i;
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
struct commonio_entry *sge, *tsge;
|
|
||||||
struct sgrp *sgr;
|
struct sgrp *sgr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Get my name so that I can use it to report errors.
|
|
||||||
*/
|
|
||||||
Prog = Basename (argv[0]);
|
|
||||||
|
|
||||||
setlocale (LC_ALL, "");
|
|
||||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
||||||
textdomain (PACKAGE);
|
|
||||||
|
|
||||||
OPENLOG ("grpck");
|
|
||||||
|
|
||||||
/* Parse the command line arguments */
|
|
||||||
process_flags (argc, argv);
|
|
||||||
|
|
||||||
open_files ();
|
|
||||||
|
|
||||||
if (sort_mode) {
|
|
||||||
gr_sort ();
|
|
||||||
#ifdef SHADOWGRP
|
|
||||||
if (is_shadow)
|
|
||||||
sgr_sort ();
|
|
||||||
#endif
|
|
||||||
goto write_and_bye;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loop through the entire group file.
|
* Loop through the entire group file.
|
||||||
*/
|
*/
|
||||||
@ -325,7 +293,7 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
printf (_("invalid group file entry\n"));
|
printf (_("invalid group file entry\n"));
|
||||||
printf (_("delete line '%s'? "), gre->line);
|
printf (_("delete line '%s'? "), gre->line);
|
||||||
errors++;
|
*errors += 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
@ -342,7 +310,7 @@ int main (int argc, char **argv)
|
|||||||
delete_gr:
|
delete_gr:
|
||||||
SYSLOG ((LOG_INFO, "delete group line `%s'",
|
SYSLOG ((LOG_INFO, "delete group line `%s'",
|
||||||
gre->line));
|
gre->line));
|
||||||
changed++;
|
*changed = 1;
|
||||||
|
|
||||||
__gr_del_entry (gre);
|
__gr_del_entry (gre);
|
||||||
continue;
|
continue;
|
||||||
@ -381,7 +349,7 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
printf (_("duplicate group entry\n"));
|
printf (_("duplicate group entry\n"));
|
||||||
printf (_("delete line '%s'? "), gre->line);
|
printf (_("delete line '%s'? "), gre->line);
|
||||||
errors++;
|
*errors += 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
@ -394,7 +362,7 @@ int main (int argc, char **argv)
|
|||||||
* Check for invalid group names. --marekm
|
* Check for invalid group names. --marekm
|
||||||
*/
|
*/
|
||||||
if (!check_group_name (grp->gr_name)) {
|
if (!check_group_name (grp->gr_name)) {
|
||||||
errors++;
|
*errors += 1;
|
||||||
printf (_("invalid group name '%s'\n"), grp->gr_name);
|
printf (_("invalid group name '%s'\n"), grp->gr_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +386,7 @@ int main (int argc, char **argv)
|
|||||||
* Can't find this user. Remove them
|
* Can't find this user. Remove them
|
||||||
* from the list.
|
* from the list.
|
||||||
*/
|
*/
|
||||||
errors++;
|
*errors += 1;
|
||||||
printf (_("group %s: no user %s\n"),
|
printf (_("group %s: no user %s\n"),
|
||||||
grp->gr_name, grp->gr_mem[i]);
|
grp->gr_name, grp->gr_mem[i]);
|
||||||
printf (_("delete member '%s'? "), grp->gr_mem[i]);
|
printf (_("delete member '%s'? "), grp->gr_mem[i]);
|
||||||
@ -428,7 +396,7 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
SYSLOG ((LOG_INFO, "delete member '%s' group '%s'",
|
SYSLOG ((LOG_INFO, "delete member '%s' group '%s'",
|
||||||
grp->gr_mem[i], grp->gr_name));
|
grp->gr_mem[i], grp->gr_name));
|
||||||
changed++;
|
*changed = 1;
|
||||||
delete_member (grp->gr_mem, grp->gr_mem[i]);
|
delete_member (grp->gr_mem, grp->gr_mem[i]);
|
||||||
gre->changed = 1;
|
gre->changed = 1;
|
||||||
__gr_set_changed ();
|
__gr_set_changed ();
|
||||||
@ -447,7 +415,7 @@ int main (int argc, char **argv)
|
|||||||
sgr_file);
|
sgr_file);
|
||||||
printf (_("add group '%s' in %s ?"),
|
printf (_("add group '%s' in %s ?"),
|
||||||
grp->gr_name, sgr_file);
|
grp->gr_name, sgr_file);
|
||||||
errors++;
|
*errors += 1;
|
||||||
if (yes_or_no (read_only)) {
|
if (yes_or_no (read_only)) {
|
||||||
struct sgrp sg;
|
struct sgrp sg;
|
||||||
struct group gr;
|
struct group gr;
|
||||||
@ -460,7 +428,7 @@ int main (int argc, char **argv)
|
|||||||
SYSLOG ((LOG_INFO,
|
SYSLOG ((LOG_INFO,
|
||||||
"add group `%s' to `%s'",
|
"add group `%s' to `%s'",
|
||||||
grp->gr_name, sgr_file));
|
grp->gr_name, sgr_file));
|
||||||
changed++;
|
*changed = 1;
|
||||||
|
|
||||||
if (!sgr_update (&sg)) {
|
if (!sgr_update (&sg)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
@ -507,10 +475,15 @@ int main (int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SHADOWGRP
|
#ifdef SHADOWGRP
|
||||||
if (!is_shadow)
|
static void check_sgr_file (int *errors, int *changed)
|
||||||
goto shadow_done;
|
{
|
||||||
|
struct group *grp;
|
||||||
|
struct commonio_entry *sge, *tsge;
|
||||||
|
struct sgrp *sgr;
|
||||||
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loop through the entire shadow group file.
|
* Loop through the entire shadow group file.
|
||||||
@ -530,7 +503,7 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
printf (_("invalid shadow group file entry\n"));
|
printf (_("invalid shadow group file entry\n"));
|
||||||
printf (_("delete line '%s'? "), sge->line);
|
printf (_("delete line '%s'? "), sge->line);
|
||||||
errors++;
|
*errors += 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
@ -547,7 +520,7 @@ int main (int argc, char **argv)
|
|||||||
delete_sg:
|
delete_sg:
|
||||||
SYSLOG ((LOG_INFO, "delete shadow line `%s'",
|
SYSLOG ((LOG_INFO, "delete shadow line `%s'",
|
||||||
sge->line));
|
sge->line));
|
||||||
changed++;
|
*changed = 1;
|
||||||
|
|
||||||
__sgr_del_entry (sge);
|
__sgr_del_entry (sge);
|
||||||
continue;
|
continue;
|
||||||
@ -586,7 +559,7 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
printf (_("duplicate shadow group entry\n"));
|
printf (_("duplicate shadow group entry\n"));
|
||||||
printf (_("delete line '%s'? "), sge->line);
|
printf (_("delete line '%s'? "), sge->line);
|
||||||
errors++;
|
*errors += 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prompt the user to delete the entry or not
|
* prompt the user to delete the entry or not
|
||||||
@ -603,7 +576,7 @@ int main (int argc, char **argv)
|
|||||||
printf (_("no matching group file entry in %s\n"),
|
printf (_("no matching group file entry in %s\n"),
|
||||||
grp_file);
|
grp_file);
|
||||||
printf (_("delete line '%s'? "), sge->line);
|
printf (_("delete line '%s'? "), sge->line);
|
||||||
errors++;
|
*errors += 1;
|
||||||
if (yes_or_no (read_only))
|
if (yes_or_no (read_only))
|
||||||
goto delete_sg;
|
goto delete_sg;
|
||||||
} else {
|
} else {
|
||||||
@ -639,7 +612,7 @@ int main (int argc, char **argv)
|
|||||||
* Can't find this user. Remove them
|
* Can't find this user. Remove them
|
||||||
* from the list.
|
* from the list.
|
||||||
*/
|
*/
|
||||||
errors++;
|
*errors += 1;
|
||||||
printf (_
|
printf (_
|
||||||
("shadow group %s: no administrative user %s\n"),
|
("shadow group %s: no administrative user %s\n"),
|
||||||
sgr->sg_name, sgr->sg_adm[i]);
|
sgr->sg_name, sgr->sg_adm[i]);
|
||||||
@ -652,7 +625,7 @@ int main (int argc, char **argv)
|
|||||||
SYSLOG ((LOG_INFO,
|
SYSLOG ((LOG_INFO,
|
||||||
"delete admin `%s' from shadow group `%s'",
|
"delete admin `%s' from shadow group `%s'",
|
||||||
sgr->sg_adm[i], sgr->sg_name));
|
sgr->sg_adm[i], sgr->sg_name));
|
||||||
changed++;
|
*changed = 1;
|
||||||
delete_member (sgr->sg_adm, sgr->sg_adm[i]);
|
delete_member (sgr->sg_adm, sgr->sg_adm[i]);
|
||||||
sge->changed = 1;
|
sge->changed = 1;
|
||||||
__sgr_set_changed ();
|
__sgr_set_changed ();
|
||||||
@ -669,7 +642,7 @@ int main (int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Can't find this user. Remove them from the list.
|
* Can't find this user. Remove them from the list.
|
||||||
*/
|
*/
|
||||||
errors++;
|
*errors += 1;
|
||||||
printf (_("shadow group %s: no user %s\n"),
|
printf (_("shadow group %s: no user %s\n"),
|
||||||
sgr->sg_name, sgr->sg_mem[i]);
|
sgr->sg_name, sgr->sg_mem[i]);
|
||||||
printf (_("delete member '%s'? "), sgr->sg_mem[i]);
|
printf (_("delete member '%s'? "), sgr->sg_mem[i]);
|
||||||
@ -680,17 +653,55 @@ int main (int argc, char **argv)
|
|||||||
SYSLOG ((LOG_INFO,
|
SYSLOG ((LOG_INFO,
|
||||||
"delete member `%s' from shadow group `%s'",
|
"delete member `%s' from shadow group `%s'",
|
||||||
sgr->sg_mem[i], sgr->sg_name));
|
sgr->sg_mem[i], sgr->sg_name));
|
||||||
changed++;
|
*changed = 1;
|
||||||
delete_member (sgr->sg_mem, sgr->sg_mem[i]);
|
delete_member (sgr->sg_mem, sgr->sg_mem[i]);
|
||||||
sge->changed = 1;
|
sge->changed = 1;
|
||||||
__sgr_set_changed ();
|
__sgr_set_changed ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
shadow_done:
|
|
||||||
#endif /* SHADOWGRP */
|
#endif /* SHADOWGRP */
|
||||||
|
|
||||||
write_and_bye:
|
/*
|
||||||
|
* grpck - verify group file integrity
|
||||||
|
*/
|
||||||
|
int main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int errors = 0;
|
||||||
|
int changed = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get my name so that I can use it to report errors.
|
||||||
|
*/
|
||||||
|
Prog = Basename (argv[0]);
|
||||||
|
|
||||||
|
setlocale (LC_ALL, "");
|
||||||
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||||
|
textdomain (PACKAGE);
|
||||||
|
|
||||||
|
OPENLOG ("grpck");
|
||||||
|
|
||||||
|
/* Parse the command line arguments */
|
||||||
|
process_flags (argc, argv);
|
||||||
|
|
||||||
|
open_files ();
|
||||||
|
|
||||||
|
if (sort_mode) {
|
||||||
|
gr_sort ();
|
||||||
|
#ifdef SHADOWGRP
|
||||||
|
if (is_shadow)
|
||||||
|
sgr_sort ();
|
||||||
|
changed = 1;
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
check_grp_file (&errors, &changed);
|
||||||
|
#ifdef SHADOWGRP
|
||||||
|
if (is_shadow) {
|
||||||
|
check_sgr_file (&errors, &changed);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* Commit the change in the database if needed */
|
/* Commit the change in the database if needed */
|
||||||
close_files (changed);
|
close_files (changed);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user