int commonio_close (struct commonio_db *db)
{
- int errors = 0;
+ bool errors = false;
char buf[1024];
struct stat sb;
#ifdef WITH_SELINUX
if (set_selinux_file_context (db->filename, S_IFREG) != 0) {
- errors++;
+ errors = true;
}
#endif
if (create_backup (buf, db->fp) != 0) {
- errors++;
+ errors = true;
}
if (fclose (db->fp) != 0) {
- errors++;
+ errors = true;
}
db->fp = NULL;
#ifdef WITH_SELINUX
if (reset_selinux_file_context () != 0) {
- errors++;
+ errors = true;
}
#endif
- if (errors != 0)
+ if (errors)
goto fail;
} else {
/*
#ifdef WITH_SELINUX
if (set_selinux_file_context (db->filename, S_IFREG) != 0) {
- errors++;
+ errors = true;
}
#endif
}
if (write_all (db) != 0) {
- errors++;
+ errors = true;
}
if (fflush (db->fp) != 0) {
- errors++;
+ errors = true;
}
if (fsync (fileno (db->fp)) != 0) {
- errors++;
+ errors = true;
}
if (fclose (db->fp) != 0) {
- errors++;
+ errors = true;
}
db->fp = NULL;
- if (errors != 0) {
+ if (errors) {
unlink (buf);
goto fail;
}
nscd_need_reload = true;
goto success;
fail:
- errors++;
+ errors = true;
success:
free_linked_list (db);
- return errors == 0;
+ return !errors;
}
static /*@dependent@*/ /*@null@*/struct commonio_entry *next_entry_by_name (
const struct group *gr;
struct group newgr;
- int errors = 0;
+ bool errors = false;
intmax_t line = 0;
log_set_progname(Prog);
if (stpsep(buf, "\n") == NULL) {
fprintf (stderr, _("%s: line %jd: line too long\n"),
Prog, line);
- errors++;
+ errors = true;
continue;
}
fprintf (stderr,
_("%s: line %jd: missing new password\n"),
Prog, line);
- errors++;
+ errors = true;
continue;
}
newpwd = cp;
fprintf (stderr,
_("%s: line %jd: group '%s' does not exist\n"), Prog,
line, name);
- errors++;
+ errors = true;
continue;
}
#ifdef SHADOWGRP
fprintf (stderr,
_("%s: line %jd: failed to prepare the new %s entry '%s'\n"),
Prog, line, sgr_dbname (), newsg.sg_name);
- errors++;
+ errors = true;
continue;
}
}
fprintf (stderr,
_("%s: line %jd: failed to prepare the new %s entry '%s'\n"),
Prog, line, gr_dbname (), newgr.gr_name);
- errors++;
+ errors = true;
continue;
}
}
* changes to be written out all at once, and then unlocked
* afterwards.
*/
- if (0 != errors) {
+ if (errors) {
fprintf (stderr,
_("%s: error detected, changes ignored\n"), Prog);
fail_exit (1);
bool use_pam = true;
#endif /* USE_PAM */
- int errors = 0;
+ bool errors = false;
intmax_t line = 0;
log_set_progname(Prog);
fprintf (stderr,
_("%s: line %jd: line too long\n"),
Prog, line);
- errors++;
+ errors = true;
continue;
}
}
fprintf (stderr,
_("%s: line %jd: missing new password\n"),
Prog, line);
- errors++;
+ errors = true;
continue;
}
newpwd = cp;
fprintf (stderr,
_("%s: (line %jd, user %s) password not changed\n"),
Prog, line, name);
- errors++;
+ errors = true;
}
} else
#endif /* USE_PAM */
fprintf (stderr,
_("%s: line %jd: user '%s' does not exist\n"), Prog,
line, name);
- errors++;
+ errors = true;
continue;
}
if (is_shadow_pwd) {
fprintf (stderr,
_("%s: line %jd: failed to prepare the new %s entry '%s'\n"),
Prog, line, spw_dbname (), newsp.sp_namp);
- errors++;
+ errors = true;
continue;
}
}
fprintf (stderr,
_("%s: line %jd: failed to prepare the new %s entry '%s'\n"),
Prog, line, pw_dbname (), newpw.pw_name);
- errors++;
+ errors = true;
continue;
}
}
* With PAM, it is not possible to delay the update of the
* password database.
*/
- if (0 != errors) {
+ if (errors) {
#ifdef USE_PAM
if (!use_pam)
#endif /* USE_PAM */
const char *fmt_info,
const char *fmt_prompt,
const char *fmt_syslog,
- int *errors);
-static void check_grp_file (int *errors, bool *changed);
+ bool *errors);
+static void check_grp_file (bool *errors, bool *changed);
#ifdef SHADOWGRP
static void compare_members_lists (const char *groupname,
char **members,
char **other_members,
const char *file,
const char *other_file);
-static void check_sgr_file (int *errors, bool *changed);
+static void check_sgr_file (bool *errors, bool *changed);
#endif
/*
/*
* check_members - check that every members of a group exist
*
- * If an error is detected, *errors is incremented.
+ * If an error is detected, *errors is set to true.
*
* The user will be prompted for the removal of the non-existent
* user.
const char *fmt_info,
const char *fmt_prompt,
const char *fmt_syslog,
- int *errors)
+ bool *errors)
{
int i;
int members_changed = 0;
* Can't find this user. Remove them
* from the list.
*/
- *errors += 1;
+ *errors = true;
printf (fmt_info, groupname, members[i]);
printf (fmt_prompt, members[i]);
/*
* check_grp_file - check the content of the group file
*/
-static void check_grp_file (int *errors, bool *changed)
+static void check_grp_file (bool *errors, bool *changed)
{
struct commonio_entry *gre, *tgre;
struct group *grp;
*/
(void) puts (_("invalid group file entry"));
printf (_("delete line '%s'? "), gre->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
*/
(void) puts (_("duplicate group entry"));
printf (_("delete line '%s'? "), gre->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
* Check for invalid group names. --marekm
*/
if (!is_valid_group_name (grp->gr_name)) {
- *errors += 1;
+ *errors = true;
printf (_("invalid group name '%s'\n"), grp->gr_name);
}
*/
if (grp->gr_gid == (gid_t)-1) {
printf (_("invalid group ID '%lu'\n"), (long unsigned int)grp->gr_gid);
- *errors += 1;
+ *errors = true;
}
/*
sgr_file);
printf (_("add group '%s' in %s? "),
grp->gr_name, sgr_file);
- *errors += 1;
+ *errors = true;
if (yes_or_no (read_only)) {
struct sgrp sg;
struct group gr;
if (!streq(grp->gr_passwd, SHADOW_PASSWD_STRING)) {
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;
+ *errors = true;
}
}
}
/*
* check_sgr_file - check the content of the shadowed group file (gshadow)
*/
-static void check_sgr_file (int *errors, bool *changed)
+static void check_sgr_file (bool *errors, bool *changed)
{
const struct group *grp;
struct commonio_entry *sge, *tsge;
*/
(void) puts (_("invalid shadow group file entry"));
printf (_("delete line '%s'? "), sge->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
*/
(void) puts (_("duplicate shadow group entry"));
printf (_("delete line '%s'? "), sge->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
printf (_("no matching group file entry in %s\n"),
grp_file);
printf (_("delete line '%s'? "), sge->line);
- *errors += 1;
+ *errors = true;
if (yes_or_no (read_only)) {
goto delete_sg;
}
*/
int main (int argc, char **argv)
{
- int errors = 0;
+ bool errors = false;
bool changed = false;
log_set_progname(Prog);
/*
* Tell the user what we did and exit.
*/
- if (0 != errors) {
+ if (errors) {
if (changed) {
printf (_("%s: the files have been updated\n"), Prog);
} else {
}
}
- return ((0 != errors) ? E_BAD_ENTRY : E_OKAY);
+ return (errors ? E_BAD_ENTRY : E_OKAY);
}
static void process_flags (int argc, char **argv);
static void open_files (void);
static void close_files (bool changed);
-static void check_pw_file (int *errors, bool *changed);
-static void check_spw_file (int *errors, bool *changed);
+static void check_pw_file (bool *errors, bool *changed);
+static void check_spw_file (bool *errors, bool *changed);
extern int allow_bad_names;
/*
* check_pw_file - check the content of the passwd file
*/
-static void check_pw_file (int *errors, bool *changed)
+static void check_pw_file (bool *errors, bool *changed)
{
struct commonio_entry *pfe, *tpfe;
struct passwd *pwd;
*/
puts (_("invalid password file entry"));
printf (_("delete line '%s'? "), pfe->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
*/
puts (_("duplicate password entry"));
printf (_("delete line '%s'? "), pfe->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
printf(_("invalid user name '%s'\n"),
pwd->pw_name);
}
- *errors += 1;
+ *errors = true;
}
/*
*/
if (pwd->pw_uid == (uid_t)-1) {
printf (_("invalid user ID '%lu'\n"), (long unsigned int)pwd->pw_uid);
- *errors += 1;
+ *errors = true;
}
/*
printf (_("user '%s': no group %lu\n"),
pwd->pw_name, (unsigned long) pwd->pw_gid);
- *errors += 1;
+ *errors = true;
}
/*
if (NULL == nonexistent || !streq(pwd->pw_dir, nonexistent)) {
printf (_("user '%s': directory '%s' does not exist\n"),
pwd->pw_name, pwd->pw_dir);
- *errors += 1;
+ *errors = true;
}
}
}
*/
printf (_("user '%s': program '%s' does not exist\n"),
pwd->pw_name, pwd->pw_shell);
- *errors += 1;
+ *errors = true;
}
/*
pwd->pw_name);
printf (_("create tcb directory for %s?"),
pwd->pw_name);
- *errors += 1;
+ *errors = true;
if (yes_or_no (read_only)) {
if (shadowtcb_create (pwd->pw_name, pwd->pw_uid) == SHADOWTCB_FAILURE) {
- *errors += 1;
+ *errors = true;
printf (_("failed to create tcb directory for %s\n"), pwd->pw_name);
continue;
}
}
}
if (spw_lock () == 0) {
- *errors += 1;
+ *errors = true;
fprintf (stderr,
_("%s: cannot lock %s.\n"),
Prog, spw_dbname ());
fprintf (stderr,
_("%s: cannot open %s\n"),
Prog, spw_dbname ());
- *errors += 1;
+ *errors = true;
if (spw_unlock () == 0) {
fprintf (stderr,
_("%s: failed to unlock %s\n"),
spw_dbname ());
printf (_("add user '%s' in %s? "),
pwd->pw_name, spw_dbname ());
- *errors += 1;
+ *errors = true;
if (yes_or_no (read_only)) {
struct spwd sp;
struct passwd pw;
&& !streq(pwd->pw_passwd, SHADOW_PASSWD_STRING)) {
printf (_("user %s has an entry in %s, but its password field in %s is not set to 'x'\n"),
pwd->pw_name, spw_dbname (), pw_dbname ());
- *errors += 1;
+ *errors = true;
}
}
}
/*
* check_spw_file - check the content of the shadowed password file (shadow)
*/
-static void check_spw_file (int *errors, bool *changed)
+static void check_spw_file (bool *errors, bool *changed)
{
struct commonio_entry *spe, *tspe;
struct spwd *spw;
*/
puts (_("invalid shadow password file entry"));
printf (_("delete line '%s'? "), spe->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
*/
puts (_("duplicate shadow password entry"));
printf (_("delete line '%s'? "), spe->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
printf (_("no matching password file entry in %s\n"),
pw_dbname ());
printf (_("delete line '%s'? "), spe->line);
- *errors += 1;
+ *errors = true;
/*
* prompt the user to delete the entry or not
&& (spw->sp_lstchg > t / DAY)) {
printf (_("user %s: last password change in the future\n"),
spw->sp_namp);
- *errors += 1;
+ *errors = true;
}
}
}
*/
int main (int argc, char **argv)
{
- int errors = 0;
+ bool errors = false;
bool changed = false;
log_set_progname(Prog);
/*
* Tell the user what we did and exit.
*/
- if (0 != errors) {
+ if (errors) {
printf (changed ?
_("%s: the files have been updated\n") :
_("%s: no changes\n"), Prog);
}
closelog ();
- return ((0 != errors) ? E_BADENTRY : E_OKAY);
+ return (errors ? E_BADENTRY : E_OKAY);
}
static int get_groups (char *list)
{
struct group *grp;
- int errors = 0;
+ bool errors = false;
int ngroups = 0;
/*
fprintf (stderr,
_("%s: group '%s' does not exist\n"),
Prog, g);
- errors++;
+ errors = true;
}
/*
/*
* Any errors in finding group names are fatal
*/
- if (0 != errors) {
+ if (errors) {
return -1;
}
static bool path_prefix (const char *, const char *);
#endif /* EXTRA_CHECK_HOME_DIR */
static int is_owner (uid_t, const char *);
-static int remove_mailbox (void);
+static bool remove_mailbox (void);
#ifdef WITH_TCB
static int remove_tcbdir (const char *user_name, uid_t user_id);
#endif /* WITH_TCB */
return (st.st_uid == uid) ? 1 : 0;
}
-static int remove_mailbox (void)
+static bool remove_mailbox (void)
{
- int i, errors = 0;
+ int i;
+ bool errors = false;
char *mailfile;
const char *maildir;
"deleting mail file",
user_name, user_id, SHADOW_AUDIT_FAILURE);
#endif /* WITH_AUDIT */
- errors = 1;
+ errors = true;
/* continue */
}
#ifdef WITH_AUDIT
"deleting mail file",
user_name, user_id, SHADOW_AUDIT_FAILURE);
#endif /* WITH_AUDIT */
- errors = 1;
+ errors = true;
/* continue */
}
#ifdef WITH_AUDIT
*/
int main (int argc, char **argv)
{
- int errors = 0; /* Error in the removal of the home directory */
+ bool errors = false; /* Error in the removal of the home directory */
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
update_groups ();
if (rflg) {
- errors += remove_mailbox ();
+ if (remove_mailbox ()) {
+ errors = true;
+ }
}
if (rflg) {
int home_owned = is_owner (user_id, user_home);
_("%s: %s not owned by %s, not removing\n"),
Prog, user_home, user_name);
rflg = 0;
- errors++;
+ errors = true;
/* continue */
}
}
_("%s: not removing directory %s (would remove home of user %s)\n"),
Prog, user_home, pwd->pw_name);
rflg = false;
- errors++;
+ errors = true;
/* continue */
break;
}
#ifdef WITH_BTRFS
int is_subvolume = btrfs_is_subvolume (user_home);
if (is_subvolume < 0) {
- errors++;
+ errors = true;
/* continue */
}
else if (is_subvolume > 0) {
fprintf (stderr,
_("%s: error removing subvolume %s\n"),
Prog, user_home);
- errors++;
+ errors = true;
/* continue */
}
}
fprintf (stderr,
_("%s: error removing directory %s\n"),
Prog, user_home);
- errors++;
+ errors = true;
/* continue */
}
#ifdef WITH_AUDIT
#endif /* WITH_AUDIT */
}
#ifdef WITH_AUDIT
- if (0 != errors) {
+ if (errors) {
audit_logger (AUDIT_DEL_USER, Prog,
"deleting home directory",
user_name, AUDIT_NO_ID,
}
#ifdef WITH_TCB
- errors += remove_tcbdir (user_name, user_id);
+ if (remove_tcbdir (user_name, user_id)) {
+ errors = true;
+ }
#endif /* WITH_TCB */
nscd_flush_cache ("passwd");
nscd_flush_cache ("group");
sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP);
- return ((0 != errors) ? E_HOMEDIR : E_SUCCESS);
+ return (errors ? E_HOMEDIR : E_SUCCESS);
}
static int get_groups (char *list)
{
struct group *grp;
- int errors = 0;
+ bool errors = false;
int ngroups = 0;
/*
if (NULL == grp) {
fprintf (stderr, _("%s: group '%s' does not exist\n"),
Prog, g);
- errors++;
+ errors = true;
}
/*
/*
* Any errors in finding group names are fatal
*/
- if (0 != errors) {
+ if (errors) {
return -1;
}