static rc_t vdi_report_repository( const KRepository * repo, const char * prefix, int idx, bool full ) { KRepCategory cat = KRepositoryCategory( repo ); KRepSubCategory subcat = KRepositorySubCategory( repo ); rc_t rc = KOutMsg( " repo.%s #%d:\n", prefix, idx ); if ( rc == 0 ) rc = KOutMsg( " - category : %s.%s\n", KRepCategory_to_str( cat ), KRepSubCategory_to_str( subcat ) ); if ( rc == 0 ) rc = vdi_report_repo_str( repo, "name", KRepositoryName ); if ( rc == 0 ) rc = KOutMsg( " - disabled : %s\n", yes_or_no( KRepositoryDisabled( repo ) ) ); if ( full ) { if ( rc == 0 ) rc = vdi_report_repo_str( repo, "displayname", KRepositoryDisplayName ); if ( rc == 0 ) rc = vdi_report_repo_str( repo, "root", KRepositoryRoot ); if ( rc == 0 ) rc = vdi_report_repo_str( repo, "resolver", KRepositoryResolver ); if ( rc == 0 ) rc = KOutMsg( " - cached : %s\n", yes_or_no( KRepositoryCacheEnabled( repo ) ) ); if ( rc == 0 ) rc = vdi_report_repo_str( repo, "ticket", KRepositoryDownloadTicket ); if ( rc == 0 ) rc = vdi_report_repo_str( repo, "key", KRepositoryEncryptionKey ); if ( rc == 0 ) rc = vdi_report_repo_str( repo, "keyfile", KRepositoryEncryptionKeyFile ); if ( rc == 0 ) rc = vdi_report_repo_str( repo, "desc", KRepositoryDescription ); if ( rc == 0 ) { uint32_t prj_id; rc_t rc1 = KRepositoryProjectId( repo, &prj_id ); if ( rc1 == 0 ) rc = KOutMsg( " - prj-id : %d\n", prj_id ); } } if ( rc == 0 ) rc = KOutMsg( "\n" ); return rc; }
/* * check_members - check that every members of a group exist * * If an error is detected, *errors is incremented. * * The user will be prompted for the removal of the non-existent * user. * * If any changes are performed, the return value will be 1, * otherwise check_members() returns 0. * * fmt_info, fmt_prompt, and fmt_syslog are used for logging. * * fmt_info must contain two string flags (%s): for the group's * name and the missing member. * * fmt_prompt must contain one string flags (%s): the missing * member. * * fmt_syslog must contain two string flags (%s): for the * group's name and the missing member. */ 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; NULL != members[i]; i++) { /* local, no need for xgetpwnam */ if (getpwnam (members[i]) != NULL) { 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]); /* Rewind in case of removal */ i--; } return members_changed; }
static rc_t vdi_report_repo_vector( const KRepositoryMgr * repomgr, const KRepCategory cat, int32_t select, bool full ) { rc_t rc = 0; catfunc f = vdi_get_catfunc( cat ); if ( f != NULL ) { KRepositoryVector v; rc = f( repomgr, &v ); if ( rc == 0 ) { const char * prefix = KRepCategory_to_prefix( cat ); uint32_t idx, len = VectorLength( &v ); bool disabled = KRepositoryMgrCategoryDisabled( repomgr, cat ); rc = KOutMsg( "repo.%s --> disabled: %s, %d subrepositories )\n", prefix, yes_or_no( disabled ), len ); for ( idx = 0; rc == 0 && idx < len; ++idx ) { if ( select == idx || !full ) rc = vdi_report_repository( VectorGet( &v, idx ), prefix, idx, full ); } KRepositoryVectorWhack( &v ); } } return rc; }
Sint32 vbutton::do_call(Sint32 whatfunc, Sint32 arg) { switch (whatfunc) { case BEGINMENU: return beginmenu(arg); case CREATE_TEAM_MENU: return create_team_menu(arg); case SET_PLAYER_MODE: return set_player_mode(arg); case QUIT_MENU: quit(arg); return 1; case CREATE_VIEW_MENU: return create_view_menu(arg); case CREATE_EDIT_MENU: return create_edit_menu(arg); case CREATE_BUY_MENU: return create_buy_menu(arg); case CREATE_LOAD_MENU: return create_load_menu(arg); case CREATE_SAVE_MENU: return create_save_menu(arg); case GO_MENU: return go_menu(arg); case RETURN_MENU: return arg; case CYCLE_TEAM_GUY: return cycle_team_guy(arg); case DECREASE_STAT: return decrease_stat(arg); case INCREASE_STAT: return increase_stat(arg); case EDIT_GUY: return edit_guy(arg); case CYCLE_GUY: return cycle_guy(arg); case ADD_GUY: return add_guy(arg); case DO_SAVE: return do_save(arg); case DO_LOAD: return do_load(arg); case NAME_GUY: // name some guy return name_guy(arg); case CREATE_DETAIL_MENU: return create_detail_menu(NULL); case DO_SET_SCEN_LEVEL: return do_set_scen_level(arg); case SET_DIFFICULTY: return set_difficulty(); case CHANGE_TEAM: return change_teamnum(arg); case CHANGE_HIRE_TEAM: return change_hire_teamnum(arg); case ALLIED_MODE: return change_allied(); case YES_OR_NO: return yes_or_no(arg); default: return 4; } }
/* * check_spw_file - check the content of the shadowed password file (shadow) */ static void check_spw_file (int *errors, bool *changed) { struct commonio_entry *spe, *tspe; struct spwd *spw; /* * Loop through the entire shadow password file. */ for (spe = __spw_get_head (); NULL != spe; spe = spe->next) { /* * Do not treat lines which were missing in shadow * and were added earlier. */ if (NULL == spe->line) { continue; } /* * If this is a NIS line, skip it. You can't "know" what NIS * is going to do without directly asking NIS ... */ if (('+' == spe->line[0]) || ('-' == spe->line[0])) { continue; } /* * Start with the entries that are completely corrupt. They * have no (struct spwd) entry because they couldn't be * parsed properly. */ if (NULL == spe->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ puts (_("invalid shadow password file entry")); printf (_("delete line '%s'? "), spe->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (!yes_or_no (read_only)) { continue; } /* * All shadow file deletions wind up here. This code * removes the current entry from the linked list. * When done, it skips back to the top of the loop * to try out the next list element. */ delete_spw: SYSLOG ((LOG_INFO, "delete shadow line '%s'", spe->line)); *changed = true; __spw_del_entry (spe); continue; } /* * Shadow password structure is good, start using it. */ spw = spe->eptr; /* * Make sure this entry has a unique name. */ for (tspe = __spw_get_head (); NULL != tspe; tspe = tspe->next) { const struct spwd *ent = tspe->eptr; /* * Don't check this entry */ if (tspe == spe) { continue; } /* * Don't check invalid entries. */ if (NULL == ent) { continue; } if (strcmp (spw->sp_namp, ent->sp_namp) != 0) { continue; } /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ puts (_("duplicate shadow password entry")); printf (_("delete line '%s'? "), spe->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (yes_or_no (read_only)) { goto delete_spw; } } /* * Make sure this entry exists in the /etc/passwd * file. */ if (pw_locate (spw->sp_namp) == NULL) { /* * Tell the user this entry has no matching * /etc/passwd entry and ask them to delete it. */ printf (_("no matching password file entry in %s\n"), pwd_file); printf (_("delete line '%s'? "), spe->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (yes_or_no (read_only)) { goto delete_spw; } } /* * Warn if last password change in the future. --marekm */ if ( !quiet && (spw->sp_lstchg > (long) time ((time_t *) 0) / SCALE)) { printf (_("user %s: last password change in the future\n"), spw->sp_namp); *errors += 1; } } }
/* * check_pw_file - check the content of the passwd file */ static void check_pw_file (int *errors, bool *changed) { struct commonio_entry *pfe, *tpfe; struct passwd *pwd; struct spwd *spw; /* * Loop through the entire password file. */ for (pfe = __pw_get_head (); NULL != pfe; pfe = pfe->next) { /* * If this is a NIS line, skip it. You can't "know" what NIS * is going to do without directly asking NIS ... */ if (('+' == pfe->line[0]) || ('-' == pfe->line[0])) { continue; } /* * Start with the entries that are completely corrupt. They * have no (struct passwd) entry because they couldn't be * parsed properly. */ if (NULL == pfe->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ puts (_("invalid password file entry")); printf (_("delete line '%s'? "), pfe->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (!yes_or_no (read_only)) { continue; } /* * All password file deletions wind up here. This * code removes the current entry from the linked * list. When done, it skips back to the top of the * loop to try out the next list element. */ delete_pw: SYSLOG ((LOG_INFO, "delete passwd line '%s'", pfe->line)); *changed = true; __pw_del_entry (pfe); continue; } /* * Password structure is good, start using it. */ pwd = pfe->eptr; /* * Make sure this entry has a unique name. */ for (tpfe = __pw_get_head (); NULL != tpfe; tpfe = tpfe->next) { const struct passwd *ent = tpfe->eptr; /* * Don't check this entry */ if (tpfe == pfe) { continue; } /* * Don't check invalid entries. */ if (NULL == ent) { continue; } if (strcmp (pwd->pw_name, ent->pw_name) != 0) { continue; } /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ puts (_("duplicate password entry")); printf (_("delete line '%s'? "), pfe->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (yes_or_no (read_only)) { goto delete_pw; } } /* * Check for invalid usernames. --marekm */ if (!is_valid_user_name (pwd->pw_name)) { printf (_("invalid user name '%s'\n"), pwd->pw_name); *errors += 1; } /* * Check for invalid user ID. */ if (pwd->pw_uid == (uid_t)-1) { printf (_("invalid user ID '%lu'\n"), (long unsigned int)pwd->pw_uid); *errors += 1; } /* * Make sure the primary group exists */ /* local, no need for xgetgrgid */ if (!quiet && (NULL == getgrgid (pwd->pw_gid))) { /* * No primary group, just give a warning */ printf (_("user '%s': no group %lu\n"), pwd->pw_name, (unsigned long) pwd->pw_gid); *errors += 1; } /* * Make sure the home directory exists */ if (!quiet && (access (pwd->pw_dir, F_OK) != 0)) { /* * Home directory doesn't exist, give a warning */ printf (_("user '%s': directory '%s' does not exist\n"), pwd->pw_name, pwd->pw_dir); *errors += 1; } /* * Make sure the login shell is executable */ if ( !quiet && ('\0' != pwd->pw_shell[0]) && (access (pwd->pw_shell, F_OK) != 0)) { /* * Login shell doesn't exist, give a warning */ printf (_("user '%s': program '%s' does not exist\n"), pwd->pw_name, pwd->pw_shell); *errors += 1; } /* * Make sure this entry exists in the /etc/shadow file. */ if (is_shadow) { spw = (struct spwd *) spw_locate (pwd->pw_name); if (NULL == spw) { printf (_("no matching password file entry in %s\n"), spw_file); printf (_("add user '%s' in %s? "), pwd->pw_name, spw_file); *errors += 1; if (yes_or_no (read_only)) { struct spwd sp; struct passwd pw; sp.sp_namp = pwd->pw_name; sp.sp_pwdp = pwd->pw_passwd; sp.sp_min = getdef_num ("PASS_MIN_DAYS", -1); sp.sp_max = getdef_num ("PASS_MAX_DAYS", -1); sp.sp_warn = getdef_num ("PASS_WARN_AGE", -1); sp.sp_inact = -1; sp.sp_expire = -1; sp.sp_flag = SHADOW_SP_FLAG_UNSET; sp.sp_lstchg = (long) time ((time_t *) 0) / SCALE; if (0 == sp.sp_lstchg) { /* Better disable aging than * requiring a password change */ sp.sp_lstchg = -1; } *changed = true; if (spw_update (&sp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, spw_dbname (), sp.sp_namp); exit (E_CANTUPDATE); } /* remove password from /etc/passwd */ pw = *pwd; pw.pw_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ if (pw_update (&pw) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, pw_dbname (), pw.pw_name); exit (E_CANTUPDATE); } } } else { /* The passwd entry has a shadow counterpart. * Make sure no passwords are in passwd. */ if (strcmp (pwd->pw_passwd, SHADOW_PASSWD_STRING) != 0) { printf (_("user %s has an entry in %s, but its password field in %s is not set to 'x'\n"), pwd->pw_name, spw_file, pwd_file); *errors += 1; } } } } }
/* * check_sgr_file - check the content of the shadowed group file (gshadow) */ static void check_sgr_file (int *errors, bool *changed) { struct group *grp; struct commonio_entry *sge, *tsge; struct sgrp *sgr; /* * Loop through the entire shadow group file. */ for (sge = __sgr_get_head (); NULL != sge; sge = sge->next) { /* * Start with the entries that are completely corrupt. They * have no (struct sgrp) entry because they couldn't be * parsed properly. */ if (NULL == sge->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ (void) puts (_("invalid shadow group file entry")); printf (_("delete line '%s'? "), sge->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (!yes_or_no (read_only)) { continue; } /* * All shadow group file deletions wind up here. * This code removes the current entry from the * linked list. When done, it skips back to the top * of the loop to try out the next list element. */ delete_sg: SYSLOG ((LOG_INFO, "delete shadow line '%s'", sge->line)); *changed = true; __sgr_del_entry (sge); continue; } /* * Shadow group structure is good, start using it. */ sgr = sge->eptr; /* * Make sure this entry has a unique name. */ for (tsge = __sgr_get_head (); NULL != tsge; tsge = tsge->next) { const struct sgrp *ent = tsge->eptr; /* * Don't check this entry */ if (tsge == sge) { continue; } /* * Don't check invalid entries. */ if (NULL == ent) { continue; } if (strcmp (sgr->sg_name, ent->sg_name) != 0) { continue; } /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ (void) puts (_("duplicate shadow group entry")); printf (_("delete line '%s'? "), sge->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (yes_or_no (read_only)) { goto delete_sg; } } /* * Make sure this entry exists in the /etc/group file. */ grp = (struct group *) gr_locate (sgr->sg_name); if (grp == NULL) { printf (_("no matching group file entry in %s\n"), grp_file); printf (_("delete line '%s'? "), sge->line); *errors += 1; if (yes_or_no (read_only)) { goto delete_sg; } } else { /** * Verify that the all members defined in /etc/gshadow are also * present in /etc/group. */ compare_members_lists (sgr->sg_name, sgr->sg_mem, grp->gr_mem, sgr_file, grp_file); } /* * Make sure each administrator exists */ if (check_members (sgr->sg_name, sgr->sg_adm, _("shadow group %s: no administrative user %s\n"), _("delete administrative member '%s'? "), "delete admin '%s' from shadow group '%s'", errors) == 1) { *changed = true; sge->changed = true; __sgr_set_changed (); } /* * Make sure each member exists */ if (check_members (sgr->sg_name, sgr->sg_mem, _("shadow group %s: no user %s\n"), _("delete member '%s'? "), "delete member '%s' from shadow group '%s'", errors) == 1) { *changed = true; sge->changed = true; __sgr_set_changed (); } } }
/* * check_grp_file - check the content of the group file */ static void check_grp_file (int *errors, bool *changed) { struct commonio_entry *gre, *tgre; struct group *grp; #ifdef SHADOWGRP struct sgrp *sgr; #endif /* * Loop through the entire group file. */ for (gre = __gr_get_head (); NULL != gre; gre = gre->next) { /* * Skip all NIS entries. */ if ((gre->line[0] == '+') || (gre->line[0] == '-')) { continue; } /* * Start with the entries that are completely corrupt. They * have no (struct group) entry because they couldn't be * parsed properly. */ if (NULL == gre->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ (void) puts (_("invalid group file entry")); printf (_("delete line '%s'? "), gre->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (!yes_or_no (read_only)) { continue; } /* * All group file deletions wind up here. This code * removes the current entry from the linked list. * When done, it skips back to the top of the loop * to try out the next list element. */ delete_gr: SYSLOG ((LOG_INFO, "delete group line '%s'", gre->line)); *changed = true; __gr_del_entry (gre); continue; } /* * Group structure is good, start using it. */ grp = gre->eptr; /* * Make sure this entry has a unique name. */ for (tgre = __gr_get_head (); NULL != tgre; tgre = tgre->next) { const struct group *ent = tgre->eptr; /* * Don't check this entry */ if (tgre == gre) { continue; } /* * Don't check invalid entries. */ if (NULL == ent) { continue; } if (strcmp (grp->gr_name, ent->gr_name) != 0) { continue; } /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ (void) puts (_("duplicate group entry")); printf (_("delete line '%s'? "), gre->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (yes_or_no (read_only)) { goto delete_gr; } } /* * Check for invalid group names. --marekm */ if (!is_valid_group_name (grp->gr_name)) { *errors += 1; printf (_("invalid group name '%s'\n"), grp->gr_name); } /* * Check for invalid group ID. */ if (grp->gr_gid == (gid_t)-1) { printf (_("invalid group ID '%lu'\n"), (long unsigned int)grp->gr_gid); *errors += 1; } /* * Workaround for a NYS libc 5.3.12 bug on RedHat 4.2 - * groups with no members are returned as groups with one * member "", causing grpck to fail. --marekm */ if ( (NULL != grp->gr_mem[0]) && (NULL == grp->gr_mem[1]) && ('\0' == grp->gr_mem[0][0])) { grp->gr_mem[0] = NULL; } if (check_members (grp->gr_name, grp->gr_mem, _("group %s: no user %s\n"), _("delete member '%s'? "), "delete member '%s' from group '%s'", errors) == 1) { *changed = true; gre->changed = true; __gr_set_changed (); } #ifdef SHADOWGRP /* * Make sure this entry exists in the /etc/gshadow file. */ if (is_shadow) { sgr = (struct sgrp *) sgr_locate (grp->gr_name); if (sgr == NULL) { printf (_("no matching group file entry in %s\n"), sgr_file); printf (_("add group '%s' in %s? "), grp->gr_name, sgr_file); *errors += 1; if (yes_or_no (read_only)) { struct sgrp sg; struct group gr; static char *empty = NULL; sg.sg_name = grp->gr_name; sg.sg_passwd = grp->gr_passwd; sg.sg_adm = ∅ sg.sg_mem = grp->gr_mem; SYSLOG ((LOG_INFO, "add group '%s' to '%s'", grp->gr_name, sgr_file)); *changed = true; if (sgr_update (&sg) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sg.sg_name); fail_exit (E_CANT_UPDATE); } /* remove password from /etc/group */ gr = *grp; gr.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ if (gr_update (&gr) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), gr.gr_name); fail_exit (E_CANT_UPDATE); } } } else { /** * Verify that all the members defined in /etc/group are also * present in /etc/gshadow. */ compare_members_lists (grp->gr_name, grp->gr_mem, sgr->sg_mem, grp_file, sgr_file); /* The group entry has a gshadow counterpart. * Make sure no passwords are in group. */ if (strcmp (grp->gr_passwd, SHADOW_PASSWD_STRING) != 0) { printf (_("group %s has an entry in %s, but its password field in %s is not set to 'x'\n"), grp->gr_name, sgr_file, grp_file); *errors += 1; } } } #endif } }
Sint32 vbutton::do_call(Sint32 whatfunc, Sint32 arg) { switch (whatfunc) { case BEGINMENU: return beginmenu(arg); case CREATE_TEAM_MENU: return create_team_menu(arg); case SET_PLAYER_MODE: return set_player_mode(arg); case QUIT_MENU: quit(arg); return 1; case CREATE_VIEW_MENU: return create_view_menu(arg); case CREATE_TRAIN_MENU: return create_train_menu(arg); case CREATE_HIRE_MENU: return create_hire_menu(arg); case CREATE_LOAD_MENU: return create_load_menu(arg); case CREATE_SAVE_MENU: return create_save_menu(arg); case GO_MENU: return go_menu(arg); case RETURN_MENU: return arg; case CYCLE_TEAM_GUY: return cycle_team_guy(arg); case DECREASE_STAT: return decrease_stat(arg); case INCREASE_STAT: return increase_stat(arg); case EDIT_GUY: return edit_guy(arg); case CYCLE_GUY: return cycle_guy(arg); case ADD_GUY: return add_guy(arg); case DO_SAVE: return do_save(arg); case DO_LOAD: return do_load(arg); case NAME_GUY: // name some guy return name_guy(arg); case CREATE_DETAIL_MENU: return create_detail_menu(NULL); case DO_SET_SCEN_LEVEL: return do_set_scen_level(arg); case DO_PICK_CAMPAIGN: return do_pick_campaign(arg); case SET_DIFFICULTY: return set_difficulty(); case CHANGE_TEAM: return change_teamnum(arg); case CHANGE_HIRE_TEAM: return change_hire_teamnum(arg); case ALLIED_MODE: return change_allied(); case DO_LEVEL_EDIT: return level_editor(); case YES_OR_NO: return yes_or_no(arg); case MAIN_OPTIONS: return main_options(); case TOGGLE_SOUND: toggle_effect("sound", "sound"); return REDRAW; case TOGGLE_RENDERING_ENGINE: toggle_rendering_engine(); return REDRAW; case TOGGLE_FULLSCREEN: toggle_effect("graphics", "fullscreen"); myscreen->set_fullscreen(cfg.is_on("graphics", "fullscreen")); return REDRAW; case OVERSCAN_ADJUST: return overscan_adjust(arg); case TOGGLE_MINI_HP_BAR: toggle_effect("effects", "mini_hp_bar"); return REDRAW; case TOGGLE_HIT_FLASH: toggle_effect("effects", "hit_flash"); return REDRAW; case TOGGLE_HIT_RECOIL: toggle_effect("effects", "hit_recoil"); return REDRAW; case TOGGLE_ATTACK_LUNGE: toggle_effect("effects", "attack_lunge"); return REDRAW; case TOGGLE_HIT_ANIM: toggle_effect("effects", "hit_anim"); return REDRAW; case TOGGLE_DAMAGE_NUMBERS: toggle_effect("effects", "damage_numbers"); return REDRAW; case TOGGLE_HEAL_NUMBERS: toggle_effect("effects", "heal_numbers"); return REDRAW; case TOGGLE_GORE: toggle_effect("effects", "gore"); return REDRAW; case RESTORE_DEFAULT_SETTINGS: restore_default_settings(); cfg.load_settings(); return REDRAW; default: return OK; } }
/* * grpck - verify group file integrity */ int main (int argc, char **argv) { int arg; int errors = 0; int deleted = 0; int i; struct commonio_entry *gre, *tgre; struct group *grp; int sort_mode = 0; #ifdef SHADOWGRP struct commonio_entry *sge, *tsge; struct sgrp *sgr; int is_shadow = 0; #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 */ while ((arg = getopt (argc, argv, "qrs")) != EOF) { switch (arg) { case 'q': /* quiet - ignored for now */ break; case 'r': read_only = 1; break; case 's': sort_mode = 1; break; default: usage (); } } if (sort_mode && read_only) { fprintf (stderr, _("%s: -s and -r are incompatibile\n"), Prog); exit (E_USAGE); } /* * Make certain we have the right number of arguments */ #ifdef SHADOWGRP if (optind != argc && optind + 1 != argc && optind + 2 != argc) #else if (optind != argc && optind + 1 != argc) #endif usage (); /* * If there are two left over filenames, use those as the group and * group password filenames. */ if (optind != argc) { grp_file = argv[optind]; gr_name (grp_file); } #ifdef SHADOWGRP if (optind + 2 == argc) { sgr_file = argv[optind + 1]; sgr_name (sgr_file); is_shadow = 1; } else if (optind == argc) is_shadow = sgr_file_present (); #endif /* * Lock the files if we aren't in "read-only" mode */ if (!read_only) { if (!gr_lock ()) { fprintf (stderr, _("%s: cannot lock file %s\n"), Prog, grp_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot lock %s", grp_file)); closelog (); exit (E_CANT_LOCK); } #ifdef SHADOWGRP if (is_shadow && !sgr_lock ()) { fprintf (stderr, _("%s: cannot lock file %s\n"), Prog, sgr_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot lock %s", sgr_file)); closelog (); exit (E_CANT_LOCK); } #endif } /* * Open the files. Use O_RDONLY if we are in read_only mode, * O_RDWR otherwise. */ if (!gr_open (read_only ? O_RDONLY : O_RDWR)) { fprintf (stderr, _("%s: cannot open file %s\n"), Prog, grp_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot open %s", grp_file)); closelog (); exit (E_CANT_OPEN); } #ifdef SHADOWGRP if (is_shadow && !sgr_open (read_only ? O_RDONLY : O_RDWR)) { fprintf (stderr, _("%s: cannot open file %s\n"), Prog, sgr_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot open %s", sgr_file)); closelog (); exit (E_CANT_OPEN); } #endif if (sort_mode) { gr_sort (); #ifdef SHADOWGRP if (is_shadow) sgr_sort (); #endif goto write_and_bye; } /* * Loop through the entire group file. */ for (gre = __gr_get_head (); gre; gre = gre->next) { /* * Skip all NIS entries. */ if (gre->line[0] == '+' || gre->line[0] == '-') continue; /* * Start with the entries that are completely corrupt. They * have no (struct group) entry because they couldn't be * parsed properly. */ if (!gre->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ printf (_("invalid group file entry\n")); printf (_("delete line `%s'? "), gre->line); errors++; /* * prompt the user to delete the entry or not */ if (!yes_or_no ()) continue; /* * All group file deletions wind up here. This code * removes the current entry from the linked list. * When done, it skips back to the top of the loop * to try out the next list element. */ delete_gr: SYSLOG ((LOG_INFO, "delete group line `%s'", gre->line)); deleted++; __gr_del_entry (gre); continue; } /* * Group structure is good, start using it. */ grp = gre->eptr; /* * Make sure this entry has a unique name. */ for (tgre = __gr_get_head (); tgre; tgre = tgre->next) { const struct group *ent = tgre->eptr; /* * Don't check this entry */ if (tgre == gre) continue; /* * Don't check invalid entries. */ if (!ent) continue; if (strcmp (grp->gr_name, ent->gr_name) != 0) continue; /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ printf (_("duplicate group entry\n")); printf (_("delete line `%s'? "), gre->line); errors++; /* * prompt the user to delete the entry or not */ if (yes_or_no ()) goto delete_gr; } /* * Check for invalid group names. --marekm */ if (!check_group_name (grp->gr_name)) { errors++; printf (_("invalid group name `%s'\n"), grp->gr_name); } /* * Workaround for a NYS libc 5.3.12 bug on RedHat 4.2 - * groups with no members are returned as groups with one * member "", causing grpck to fail. --marekm */ if (grp->gr_mem[0] && !grp->gr_mem[1] && *(grp->gr_mem[0]) == '\0') grp->gr_mem[0] = (char *) 0; /* * Make sure each member exists */ for (i = 0; grp->gr_mem[i]; i++) { if (getpwnam (grp->gr_mem[i])) continue; /* * Can't find this user. Remove them * from the list. */ errors++; 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 ()) continue; SYSLOG ((LOG_INFO, "delete member `%s' group `%s'", grp->gr_mem[i], grp->gr_name)); deleted++; delete_member (grp->gr_mem, grp->gr_mem[i]); gre->changed = 1; __gr_set_changed (); } } #ifdef SHADOWGRP if (!is_shadow) goto shadow_done; /* * Loop through the entire shadow group file. */ for (sge = __sgr_get_head (); sge; sge = sge->next) { /* * Start with the entries that are completely corrupt. They * have no (struct sgrp) entry because they couldn't be * parsed properly. */ if (!sge->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ printf (_("invalid shadow group file entry\n")); printf (_("delete line `%s'? "), sge->line); errors++; /* * prompt the user to delete the entry or not */ if (!yes_or_no ()) continue; /* * All shadow group file deletions wind up here. * This code removes the current entry from the * linked list. When done, it skips back to the top * of the loop to try out the next list element. */ delete_sg: SYSLOG ((LOG_INFO, "delete shadow line `%s'", sge->line)); deleted++; __sgr_del_entry (sge); continue; } /* * Shadow group structure is good, start using it. */ sgr = sge->eptr; /* * Make sure this entry has a unique name. */ for (tsge = __sgr_get_head (); tsge; tsge = tsge->next) { const struct sgrp *ent = tsge->eptr; /* * Don't check this entry */ if (tsge == sge) continue; /* * Don't check invalid entries. */ if (!ent) continue; if (strcmp (sgr->sg_name, ent->sg_name) != 0) continue; /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ printf (_("duplicate shadow group entry\n")); printf (_("delete line `%s'? "), sge->line); errors++; /* * prompt the user to delete the entry or not */ if (yes_or_no ()) goto delete_sg; } /* * Make sure this entry exists in the /etc/group file. */ if (!gr_locate (sgr->sg_name)) { printf (_("no matching group file entry\n")); printf (_("delete line `%s'? "), sge->line); errors++; if (yes_or_no ()) goto delete_sg; } /* * Make sure each administrator exists */ for (i = 0; sgr->sg_adm[i]; i++) { if (getpwnam (sgr->sg_adm[i])) continue; /* * Can't find this user. Remove them * from the list. */ errors++; 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 ()) continue; SYSLOG ((LOG_INFO, "delete admin `%s' from shadow group `%s'", sgr->sg_adm[i], sgr->sg_name)); deleted++; delete_member (sgr->sg_adm, sgr->sg_adm[i]); sge->changed = 1; __sgr_set_changed (); } /* * Make sure each member exists */ for (i = 0; sgr->sg_mem[i]; i++) { if (getpwnam (sgr->sg_mem[i])) continue; /* * Can't find this user. Remove them from the list. */ errors++; 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 ()) continue; SYSLOG ((LOG_INFO, "delete member `%s' from shadow group `%s'", sgr->sg_mem[i], sgr->sg_name)); deleted++; delete_member (sgr->sg_mem, sgr->sg_mem[i]); sge->changed = 1; __sgr_set_changed (); } } shadow_done: #endif /* SHADOWGRP */ /* * All done. If there were no deletions we can just abandon any * changes to the files. */ if (deleted) { write_and_bye: if (!gr_close ()) { fprintf (stderr, _("%s: cannot update file %s\n"), Prog, grp_file); exit (E_CANT_UPDATE); } #ifdef SHADOWGRP if (is_shadow && !sgr_close ()) { fprintf (stderr, _("%s: cannot update file %s\n"), Prog, sgr_file); exit (E_CANT_UPDATE); } #endif } /* * Don't be anti-social - unlock the files when you're done. */ #ifdef SHADOWGRP if (is_shadow) sgr_unlock (); #endif (void) gr_unlock (); nscd_flush_cache ("group"); /* * Tell the user what we did and exit. */ if (errors) printf (deleted ? _("%s: the files have been updated\n") : _("%s: no changes\n"), Prog); exit (errors ? E_BAD_ENTRY : E_OKAY); }