static char *user_home;
static char *Prog;
-static int fflg = 0, rflg = 0;
+static bool fflg = false;
+static bool rflg = false;
-static int is_shadow_pwd;
+static bool is_shadow_pwd;
#ifdef SHADOWGRP
-static int is_shadow_grp;
+static bool is_shadow_grp;
#endif
/* local function prototypes */
static void user_cancel (const char *);
#ifdef EXTRA_CHECK_HOME_DIR
-static int path_prefix (const char *, const char *);
+static bool path_prefix (const char *, const char *);
#endif
static int is_owner (uid_t, const char *);
static void remove_mailbox (void);
struct passwd *pwd;
#ifdef SHADOWGRP
- int deleted_user_group = 0;
+ bool deleted_user_group = false;
const struct sgrp *sgrp;
struct sgrp *nsgrp;
#endif /* SHADOWGRP */
* Scan through the entire group file looking for the groups that
* the user is a member of.
*/
- for (gr_rewind (), grp = gr_next (); grp; grp = gr_next ()) {
+ for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) {
/*
* See if the user specified this group as one of their
* update the group entry to reflect the change.
*/
ngrp = __gr_dup (grp);
- if (!ngrp) {
+ if (NULL == ngrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update the group database.\n"),
Prog);
exit (13); /* XXX */
}
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
- if (!gr_update (ngrp)) {
+ if (gr_update (ngrp) == 0) {
fprintf (stderr,
_("%s: error updating group entry\n"), Prog);
exit (E_GRP_UPDATE);
* user name, with no members, we delete it.
*/
grp = xgetgrnam (user_name);
- if (grp && getdef_bool ("USERGROUPS_ENAB")
- && (grp->gr_mem[0] == NULL)) {
+ if ( (NULL != grp)
+ && getdef_bool ("USERGROUPS_ENAB")
+ && (NULL == grp->gr_mem[0])) {
pwd = NULL;
if (!fflg) {
* used as a primary group.
*/
setpwent ();
- while ((pwd = getpwent ())) {
- if (strcmp (pwd->pw_name, user_name) == 0)
+ while ((pwd = getpwent ()) != NULL) {
+ if (strcmp (pwd->pw_name, user_name) == 0) {
continue;
+ }
if (pwd->pw_gid == grp->gr_gid) {
fprintf (stderr,
_
endpwent ();
}
- if (pwd == NULL) {
+ if (NULL == pwd) {
/*
* We can remove this group, it is not the primary
* group of any remaining user.
gr_remove (grp->gr_name);
#ifdef SHADOWGRP
- deleted_user_group = 1;
+ deleted_user_group = true;
#endif
#ifdef WITH_AUDIT
}
}
#ifdef SHADOWGRP
- if (!is_shadow_grp)
+ if (!is_shadow_grp) {
return;
+ }
/*
* Scan through the entire shadow group file looking for the groups
* that the user is a member of. Both the administrative list and
* the ordinary membership list is checked.
*/
- for (sgr_rewind (), sgrp = sgr_next (); sgrp; sgrp = sgr_next ()) {
- int was_member, was_admin;
+ for (sgr_rewind (), sgrp = sgr_next ();
+ NULL != sgrp;
+ sgrp = sgr_next ()) {
+ bool was_member, was_admin;
/*
* See if the user specified this group as one of their
was_member = is_on_list (sgrp->sg_mem, user_name);
was_admin = is_on_list (sgrp->sg_adm, user_name);
- if (!was_member && !was_admin)
+ if (!was_member && !was_admin) {
continue;
+ }
nsgrp = __sgr_dup (sgrp);
- if (!nsgrp) {
+ if (NULL == nsgrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update the shadow group database.\n"),
Prog);
exit (13); /* XXX */
}
- if (was_member)
+ if (was_member) {
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
+ }
- if (was_admin)
+ if (was_admin) {
nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name);
+ }
- if (!sgr_update (nsgrp)) {
+ if (sgr_update (nsgrp) == 0) {
fprintf (stderr,
_("%s: error updating shadow group entry\n"), Prog);
exit (E_GRP_UPDATE);
*/
static void close_files (void)
{
- if (!pw_close ())
+ if (pw_close () == 0)
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
- if (is_shadow_pwd && !spw_close ())
+ if (is_shadow_pwd && (spw_close () == 0))
fprintf (stderr,
_("%s: cannot rewrite shadow password file\n"), Prog);
- if (!gr_close ())
+ if (gr_close () == 0)
fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog);
- (void) gr_unlock ();
+ gr_unlock ();
#ifdef SHADOWGRP
- if (is_shadow_grp && !sgr_close ())
+ if (is_shadow_grp && (sgr_close () == 0))
fprintf (stderr,
_("%s: cannot rewrite shadow group file\n"), Prog);
- if (is_shadow_grp)
- (void) sgr_unlock ();
+ if (is_shadow_grp) {
+ sgr_unlock ();
+ }
#endif
- if (is_shadow_pwd)
- (void) spw_unlock ();
- (void) pw_unlock ();
+ if (is_shadow_pwd) {
+ spw_unlock ();
+ }
+ pw_unlock ();
}
/*
*/
static void fail_exit (int code)
{
- (void) pw_unlock ();
- (void) gr_unlock ();
- if (is_shadow_pwd)
+ pw_unlock ();
+ gr_unlock ();
+ if (is_shadow_pwd) {
spw_unlock ();
+ }
#ifdef SHADOWGRP
- if (is_shadow_grp)
+ if (is_shadow_grp) {
sgr_unlock ();
+ }
#endif
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting user", user_name,
static void open_files (void)
{
- if (!pw_lock ()) {
+ if (pw_lock () == 0) {
fprintf (stderr, _("%s: unable to lock password file\n"), Prog);
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
#endif
exit (E_PW_UPDATE);
}
- if (!pw_open (O_RDWR)) {
+ if (pw_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
#endif
fail_exit (E_PW_UPDATE);
}
- if (is_shadow_pwd && !spw_lock ()) {
+ if (is_shadow_pwd && (spw_lock () == 0)) {
fprintf (stderr,
_("%s: cannot lock shadow password file\n"), Prog);
#ifdef WITH_AUDIT
#endif
fail_exit (E_PW_UPDATE);
}
- if (is_shadow_pwd && !spw_open (O_RDWR)) {
+ if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) {
fprintf (stderr,
_("%s: cannot open shadow password file\n"), Prog);
#ifdef WITH_AUDIT
#endif
fail_exit (E_PW_UPDATE);
}
- if (!gr_lock ()) {
+ if (gr_lock () == 0) {
fprintf (stderr, _("%s: unable to lock group file\n"), Prog);
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking group file",
#endif
fail_exit (E_GRP_UPDATE);
}
- if (!gr_open (O_RDWR)) {
+ if (gr_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open group file\n"), Prog);
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening group file",
fail_exit (E_GRP_UPDATE);
}
#ifdef SHADOWGRP
- if (is_shadow_grp && !sgr_lock ()) {
+ if (is_shadow_grp && (sgr_lock () == 0)) {
fprintf (stderr,
_("%s: unable to lock shadow group file\n"), Prog);
#ifdef WITH_AUDIT
#endif
fail_exit (E_GRP_UPDATE);
}
- if (is_shadow_grp && !sgr_open (O_RDWR)) {
+ if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) {
fprintf (stderr, _("%s: cannot open shadow group file\n"),
Prog);
#ifdef WITH_AUDIT
*/
static void update_user (void)
{
- if (!pw_remove (user_name)) {
+ if (pw_remove (user_name) == 0) {
fprintf (stderr,
_("%s: error deleting password entry\n"), Prog);
fail_exit (E_PW_UPDATE);
}
- if (is_shadow_pwd && !spw_remove (user_name)) {
+ if (is_shadow_pwd && (spw_remove (user_name) == 0)) {
fprintf (stderr,
_("%s: error deleting shadow password entry\n"), Prog);
fail_exit (E_PW_UPDATE);
struct utmpx *utent;
setutxent ();
- while ((utent = getutxent ())) {
+ while ((utent = getutxent ()) != NULL) {
#else
struct utmp *utent;
setutent ();
- while ((utent = getutent ())) {
+ while ((utent = getutent ()) != NULL) {
#endif
if (utent->ut_type != USER_PROCESS)
continue;
- if (strncmp (utent->ut_user, name, sizeof utent->ut_user))
+ if (strncmp (utent->ut_user, name, sizeof utent->ut_user) != 0) {
continue;
+ }
fprintf (stderr,
_("%s: user %s is currently logged in\n"), Prog, name);
if (!fflg) {
int pid, wpid;
int status;
- if (!(cmd = getdef_str ("USERDEL_CMD")))
+ cmd = getdef_str ("USERDEL_CMD");
+ if (NUll == cmd) {
return;
+ }
pid = fork ();
if (pid == 0) {
execl (cmd, cmd, user, (char *) 0);
}
do {
wpid = wait (&status);
- } while (wpid != pid && wpid != -1);
+ } while ((wpid != pid) && (-1 != wpid));
}
#ifdef EXTRA_CHECK_HOME_DIR
-static int path_prefix (const char *s1, const char *s2)
+static bool path_prefix (const char *s1, const char *s2)
{
- return (strncmp (s2, s1, strlen (s1)) == 0 &&
- (s2[strlen (s1)] == '\0' || s2[strlen (s1)] == '/'));
+ return ( (strncmp (s2, s1, strlen (s1)) == 0)
+ && ( ('\0' == s2[strlen (s1)])
+ || ('/' == s2[strlen (s1)])));
}
#endif
{
struct stat st;
- if (stat (path, &st))
+ if (stat (path, &st) != 0) {
return -1;
+ }
return (st.st_uid == uid);
}
maildir = getdef_str ("MAIL_DIR");
#ifdef MAIL_SPOOL_DIR
- if (!maildir && !getdef_str ("MAIL_FILE"))
+ if ((NULL == maildir) && (getdef_str ("MAIL_FILE") == NULL)) {
maildir = MAIL_SPOOL_DIR;
+ }
#endif
- if (!maildir)
+ if (NULL == maildir) {
return;
+ }
snprintf (mailfile, sizeof mailfile, "%s/%s", maildir, user_name);
if (fflg) {
unlink (mailfile); /* always remove, ignore errors */
return;
} else if (i == -1)
return; /* mailbox doesn't exist */
- if (unlink (mailfile)) {
+ if (unlink (mailfile) != 0) {
fprintf (stderr, _("%s: warning: can't remove "), Prog);
perror (mailfile);
}
* Get my name so that I can use it to report errors.
*/
Prog = Basename (argv[0]);
- setlocale (LC_ALL, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
+ (void) setlocale (LC_ALL, "");
+ (void) bindtextdomain (PACKAGE, LOCALEDIR);
+ (void) textdomain (PACKAGE);
{
/*
{"remove", no_argument, NULL, 'r'},
{NULL, 0, NULL, '\0'}
};
- while ((c =
- getopt_long (argc, argv, "fhr",
- long_options, NULL)) != -1) {
+ while ((c = getopt_long (argc, argv, "fhr",
+ long_options, NULL)) != -1) {
switch (c) {
case 'f': /* force remove even if not owned by user */
- fflg++;
+ fflg = true;
break;
case 'r': /* remove home dir and mailbox */
- rflg++;
+ rflg = true;
break;
default:
usage ();
}
}
- if (optind + 1 != argc)
+ if ((optind + 1) != argc) {
usage ();
+ }
OPENLOG ("userdel");
if (retval == PAM_SUCCESS) {
retval = pam_authenticate (pamh, 0);
- if (retval != PAM_SUCCESS)
- pam_end (pamh, retval);
+ if (retval != PAM_SUCCESS) {
+ (void) pam_end (pamh, retval);
+ }
}
if (retval == PAM_SUCCESS) {
retval = pam_acct_mgmt (pamh, 0);
- if (retval != PAM_SUCCESS)
- pam_end (pamh, retval);
+ if (retval != PAM_SUCCESS) {
+ (void) pam_end (pamh, retval);
+ }
}
if (retval != PAM_SUCCESS) {
user_name = argv[argc - 1];
{
struct passwd *pwd;
- /* local, no need for xgetpwnam */
- if (!(pwd = getpwnam (user_name))) {
+ pwd = getpwnam (user_name); /* local, no need for xgetpwnam */
+ if (NULL == pwd) {
fprintf (stderr, _("%s: user %s does not exist\n"),
Prog, user_name);
#ifdef WITH_AUDIT
fprintf (stderr,
_("%s: user %s is a NIS user\n"), Prog, user_name);
- if (!yp_get_default_domain (&nis_domain)
+ if ( !yp_get_default_domain (&nis_domain)
&& !yp_master (nis_domain, "passwd.byname", &nis_master)) {
fprintf (stderr,
_("%s: %s is the NIS master\n"),
update_user ();
update_groups ();
- if (rflg)
+ if (rflg) {
remove_mailbox ();
- if (rflg && !fflg && !is_owner (user_id, user_home)) {
+ }
+ if (rflg && !fflg && (is_owner (user_id, user_home) == 0)) {
fprintf (stderr,
_("%s: %s not owned by %s, not removing\n"),
Prog, user_home, user_name);
*/
setpwent ();
while ((pwd = getpwent ())) {
- if (strcmp (pwd->pw_name, user_name) == 0)
+ if (strcmp (pwd->pw_name, user_name) == 0) {
continue;
+ }
if (path_prefix (user_home, pwd->pw_dir)) {
fprintf (stderr,
_
("%s: not removing directory %s (would remove home of user %s)\n"),
Prog, user_home, pwd->pw_name);
- rflg = 0;
+ rflg = false;
errors++;
break;
}
nscd_flush_cache ("group");
#ifdef USE_PAM
- if (retval == PAM_SUCCESS)
- pam_end (pamh, PAM_SUCCESS);
+ if (retval == PAM_SUCCESS) {
+ (void) pam_end (pamh, PAM_SUCCESS);
+ }
#endif /* USE_PAM */
#ifdef WITH_AUDIT
- if (errors)
+ if (0 != errors) {
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"deleting home directory", user_name, -1, 0);
+ }
#endif
- exit (errors ? E_HOMEDIR : E_SUCCESS);
+ exit ((0 != errors) ? E_HOMEDIR : E_SUCCESS);
/* NOT REACHED */
}
+