* src/useradd.c: Use a bool when possible instead of int integers.

* src/useradd.c: Avoid implicit conversion of pointers / integers
	/ chars to booleans.
	* src/useradd.c: Add brackets and parenthesis.
	* src/useradd.c: Avoid assignments in comparisons.
	* src/useradd.c: Ignore the return value of fclose() for read-only
	files.
	* src/useradd.c: Ignore the return value of fflush() before
	closing the files.
	* src/useradd.c: Avoid multi-statements lines.
	* src/useradd.c: Ignore return value of setlocale(),
	bindtextdomain(), and textdomain().
	* src/useradd.c: Ignore the return value of pam_end() before
	exiting.
This commit is contained in:
nekral-guest 2008-06-09 22:08:08 +00:00
parent fdb577e0a0
commit 63f0e5e2c0
2 changed files with 201 additions and 154 deletions

View File

@ -1,3 +1,20 @@
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* src/useradd.c: Use a bool when possible instead of int integers.
* src/useradd.c: Avoid implicit conversion of pointers / integers
/ chars to booleans.
* src/useradd.c: Add brackets and parenthesis.
* src/useradd.c: Avoid assignments in comparisons.
* src/useradd.c: Ignore the return value of fclose() for read-only
files.
* src/useradd.c: Ignore the return value of fflush() before
closing the files.
* src/useradd.c: Avoid multi-statements lines.
* src/useradd.c: Ignore return value of setlocale(),
bindtextdomain(), and textdomain().
* src/useradd.c: Ignore the return value of pam_end() before
exiting.
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* src/vipw.c: Use a bool when possible instead of int integers.

View File

@ -106,41 +106,41 @@ static const char *user_shell = "";
static const char *create_mail_spool = "";
static long user_expire = -1;
static int is_shadow_pwd;
static bool is_shadow_pwd;
#ifdef SHADOWGRP
static int is_shadow_grp;
static int gshadow_locked = 0;
static bool is_shadow_grp;
static bool gshadow_locked = false;
#endif
static int passwd_locked = 0;
static int group_locked = 0;
static int shadow_locked = 0;
static bool passwd_locked = false;
static bool group_locked = false;
static bool shadow_locked = false;
static char **user_groups; /* NULL-terminated list */
static long sys_ngroups;
static int do_grp_update = 0; /* group files need to be updated */
static bool do_grp_update = false; /* group files need to be updated */
static char *Prog;
static int
bflg = 0, /* new default root of home directory */
cflg = 0, /* comment (GECOS) field for new account */
dflg = 0, /* home directory for new account */
Dflg = 0, /* set/show new user default values */
eflg = 0, /* days since 1970-01-01 when account is locked */
fflg = 0, /* days until account with expired password is locked */
gflg = 0, /* primary group ID for new account */
Gflg = 0, /* secondary group set for new account */
kflg = 0, /* specify a directory to fill new user directory */
lflg = 0, /* do not add user to lastlog database file */
mflg = 0, /* create user's home directory if it doesn't exist */
Nflg = 0, /* do not create a group having the same name as the user, but add the user to def_group (or the group specified with -g) */
oflg = 0, /* permit non-unique user ID to be specified with -u */
rflg = 0, /* create a system account */
sflg = 0, /* shell program for new account */
uflg = 0, /* specify user ID for new account */
Uflg = 0; /* create a group having the same name as the user */
static bool
bflg = false, /* new default root of home directory */
cflg = false, /* comment (GECOS) field for new account */
dflg = false, /* home directory for new account */
Dflg = false, /* set/show new user default values */
eflg = false, /* days since 1970-01-01 when account is locked */
fflg = false, /* days until account with expired password is locked */
gflg = false, /* primary group ID for new account */
Gflg = false, /* secondary group set for new account */
kflg = false, /* specify a directory to fill new user directory */
lflg = false, /* do not add user to lastlog database file */
mflg = false, /* create user's home directory if it doesn't exist */
Nflg = false, /* do not create a group having the same name as the user, but add the user to def_group (or the group specified with -g) */
oflg = false, /* permit non-unique user ID to be specified with -u */
rflg = false, /* create a system account */
sflg = false, /* shell program for new account */
uflg = false, /* specify user ID for new account */
Uflg = false; /* create a group having the same name as the user */
static int home_added;
static bool home_added = false;
/*
* exit status values
@ -237,7 +237,7 @@ static long get_number (const char *numstr)
char *errptr;
val = strtol (numstr, &errptr, 10);
if (*errptr || errno == ERANGE) {
if (('\0' != *errptr) || (ERANGE == errno)) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
numstr);
exit (E_BAD_ARG);
@ -251,7 +251,7 @@ static uid_t get_uid (const char *uidstr)
char *errptr;
val = strtol (uidstr, &errptr, 10);
if (*errptr || errno == ERANGE || val < 0) {
if (('\0' != *errptr) || (ERANGE == errno) || (val < 0)) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"), Prog,
uidstr);
@ -279,19 +279,25 @@ static void get_defaults (void)
* Open the defaults file for reading.
*/
if (!(fp = fopen (def_file, "r")))
fp = fopen (def_file, "r");
if (NULL == fp) {
return;
}
/*
* Read the file a line at a time. Only the lines that have relevant
* values are used, everything else can be ignored.
*/
while (fgets (buf, sizeof buf, fp)) {
if ((cp = strrchr (buf, '\n')))
while (fgets (buf, sizeof buf, fp) == buf) {
cp = strrchr (buf, '\n');
if (NULL != cp) {
*cp = '\0';
}
if (!(cp = strchr (buf, '=')))
cp = strchr (buf, '=');
if (NULL == cp) {
continue;
}
cp++;
@ -305,7 +311,8 @@ static void get_defaults (void)
if (*cp != '\0' && *ep == '\0') { /* valid number */
def_group = val;
/* local, no need for xgetgrgid */
if ((grp = getgrgid (def_group))) {
grp = getgrgid (def_group);
if (NULL != grp) {
def_gname = xstrdup (grp->gr_name);
} else {
fprintf (stderr,
@ -313,7 +320,7 @@ static void get_defaults (void)
Prog, cp);
}
/* local, no need for xgetgrnam */
} else if ((grp = getgrnam (cp))) {
} else if ((grp = getgrnam (cp)) != NULL) {
def_group = grp->gr_gid;
def_gname = xstrdup (cp);
} else {
@ -342,11 +349,12 @@ static void get_defaults (void)
else if (MATCH (buf, INACT)) {
long val = strtol (cp, &ep, 10);
if (*cp || errno == ERANGE)
if (('\0' != *cp) || (ERANGE == errno)) {
def_inactive = val;
else
} else {
def_inactive = -1;
}
}
/*
* Default account expiration date
@ -359,8 +367,9 @@ static void get_defaults (void)
* Default Skeleton information
*/
else if (MATCH (buf, SKEL)) {
if (*cp == '\0')
if ('\0' == *cp) {
cp = SKEL_DIR; /* XXX warning: const */
}
def_template = xstrdup (cp);
}
@ -369,8 +378,9 @@ static void get_defaults (void)
* Create by default user mail spool or not ?
*/
else if (MATCH (buf, CREATE_MAIL_SPOOL)) {
if (*cp == '\0')
if (*cp == '\0') {
cp = CREATE_MAIL_SPOOL; /* XXX warning: const */
}
def_create_mail_spool = xstrdup (cp);
}
@ -409,24 +419,26 @@ static int set_defaults (void)
static char new_file[] = NEW_USER_FILE;
char *cp;
int ofd;
int out_group = 0;
int out_home = 0;
int out_inactive = 0;
int out_expire = 0;
int out_shell = 0;
int out_skel = 0;
int out_create_mail_spool = 0;
bool out_group = false;
bool out_home = false;
bool out_inactive = false;
bool out_expire = false;
bool out_shell = false;
bool out_skel = false;
bool out_create_mail_spool = false;
/*
* Create a temporary file to copy the new output to.
*/
if ((ofd = mkstemp (new_file)) == -1) {
ofd = mkstemp (new_file);
if (-1 == ofd) {
fprintf (stderr,
_("%s: cannot create new defaults file\n"), Prog);
return -1;
}
if (!(ofp = fdopen (ofd, "w"))) {
ofp = fdopen (ofd, "w");
if (NULL == ofp) {
fprintf (stderr, _("%s: cannot open new defaults file\n"),
Prog);
return -1;
@ -437,42 +449,45 @@ static int set_defaults (void)
* temporary file, using any new values. Each line is checked
* to insure that it is not output more than once.
*/
if (!(ifp = fopen (def_file, "r"))) {
ifp = fopen (def_file, "r");
if (NULL == ifp) {
fprintf (ofp, "# useradd defaults file\n");
goto skip;
}
while (fgets (buf, sizeof buf, ifp)) {
if ((cp = strrchr (buf, '\n')))
while (fgets (buf, sizeof buf, ifp) == buf) {
cp = strrchr (buf, '\n');
if (NULL != cp) {
*cp = '\0';
}
if (!out_group && MATCH (buf, DGROUP)) {
fprintf (ofp, DGROUP "%u\n", (unsigned int) def_group);
out_group++;
out_group = true;
} else if (!out_home && MATCH (buf, HOME)) {
fprintf (ofp, HOME "%s\n", def_home);
out_home++;
out_home = true;
} else if (!out_inactive && MATCH (buf, INACT)) {
fprintf (ofp, INACT "%ld\n", def_inactive);
out_inactive++;
out_inactive = true;
} else if (!out_expire && MATCH (buf, EXPIRE)) {
fprintf (ofp, EXPIRE "%s\n", def_expire);
out_expire++;
out_expire = true;
} else if (!out_shell && MATCH (buf, SHELL)) {
fprintf (ofp, SHELL "%s\n", def_shell);
out_shell++;
out_shell = true;
} else if (!out_skel && MATCH (buf, SKEL)) {
fprintf (ofp, SKEL "%s\n", def_template);
out_skel++;
out_skel = true;
} else if (!out_create_mail_spool
&& MATCH (buf, CREATE_MAIL_SPOOL)) {
fprintf (ofp, CREATE_MAIL_SPOOL "%s\n",
def_create_mail_spool);
out_create_mail_spool++;
out_create_mail_spool = true;
} else
fprintf (ofp, "%s\n", buf);
}
fclose (ifp);
(void) fclose (ifp);
skip:
/*
@ -500,8 +515,8 @@ static int set_defaults (void)
* Flush and close the file. Check for errors to make certain
* the new file is intact.
*/
fflush (ofp);
if (ferror (ofp) || fclose (ofp)) {
(void) fflush (ofp);
if ((ferror (ofp) != 0) || (fclose (ofp) != 0)) {
unlink (new_file);
return -1;
}
@ -510,7 +525,7 @@ static int set_defaults (void)
* Rename the current default file to its backup name.
*/
snprintf (buf, sizeof buf, "%s-", def_file);
if (rename (def_file, buf) && errno != ENOENT) {
if ((rename (def_file, buf) != 0) && (ENOENT != errno)) {
snprintf (buf, sizeof buf, _("%s: rename: %s"), Prog, def_file);
perror (buf);
unlink (new_file);
@ -520,7 +535,7 @@ static int set_defaults (void)
/*
* Rename the new default file to its correct name.
*/
if (rename (new_file, def_file)) {
if (rename (new_file, def_file) != 0) {
snprintf (buf, sizeof buf, _("%s: rename: %s"), Prog, new_file);
perror (buf);
return -1;
@ -552,8 +567,9 @@ static int get_groups (char *list)
int errors = 0;
int ngroups = 0;
if (!*list)
if ('\0' == *list) {
return 0;
}
/*
* So long as there is some data to be converted, strip off
@ -564,8 +580,10 @@ static int get_groups (char *list)
/*
* Strip off a single name from the list
*/
if ((cp = strchr (list, ',')))
cp = strchr (list, ',');
if (NULL != cp) {
*cp++ = '\0';
}
/*
* Names starting with digits are treated as numerical
@ -577,7 +595,7 @@ static int get_groups (char *list)
* There must be a match, either by GID value or by
* string name.
*/
if (!grp) {
if (NULL == grp) {
fprintf (stderr, _("%s: unknown group %s\n"),
Prog, list);
errors++;
@ -588,8 +606,9 @@ static int get_groups (char *list)
* If the group doesn't exist, don't dump core...
* Instead, try the next one. --marekm
*/
if (!grp)
if (NULL == grp) {
continue;
}
#ifdef USE_NIS
/*
@ -616,15 +635,16 @@ static int get_groups (char *list)
* Add the group name to the user's list of groups.
*/
user_groups[ngroups++] = xstrdup (grp->gr_name);
} while (list);
} while (NULL != list);
user_groups[ngroups] = (char *) 0;
/*
* Any errors in finding group names are fatal
*/
if (errors)
if (0 != errors) {
return -1;
}
return 0;
}
@ -767,7 +787,7 @@ static void grp_update (void)
* from the old entry, and we need it later.
*/
ngrp = __gr_dup (grp);
if (!ngrp) {
if (NULL == ngrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update the group database.\n"),
Prog);
@ -779,7 +799,7 @@ static void grp_update (void)
* update the group entry to reflect the change.
*/
ngrp->gr_mem = add_list (ngrp->gr_mem, user_name);
if (!gr_update (ngrp)) {
if (gr_update (ngrp) == 0) {
fprintf (stderr,
_("%s: error adding new group entry\n"), Prog);
fail_exit (E_GRP_UPDATE);
@ -801,13 +821,13 @@ static void grp_update (void)
* that the user is a member of. The administrative list isn't
* modified.
*/
for (sgr_rewind (), sgrp = sgr_next (); sgrp; sgrp = sgr_next ()) {
for (sgr_rewind (), sgrp = sgr_next (); NULL != sgrp; sgrp = sgr_next ()) {
/*
* See if the user specified this group as one of their
* concurrent groups.
*/
if (!gr_locate (sgrp->sg_name))
if (gr_locate (sgrp->sg_name) == NULL)
continue;
if (!is_on_list (user_groups, sgrp->sg_name))
@ -818,7 +838,7 @@ static void grp_update (void)
* from the old entry, and we need it later.
*/
nsgrp = __sgr_dup (sgrp);
if (!nsgrp) {
if (NULL == nsgrp) {
fprintf (stderr,
_("%s: Out of memory. Cannot update the shadow group database.\n"),
Prog);
@ -830,7 +850,7 @@ static void grp_update (void)
* update the group entry to reflect the change.
*/
nsgrp->sg_mem = add_list (nsgrp->sg_mem, user_name);
if (!sgr_update (nsgrp)) {
if (sgr_update (nsgrp) == 0) {
fprintf (stderr,
_("%s: error adding new group entry\n"), Prog);
fail_exit (E_GRP_UPDATE);
@ -855,7 +875,7 @@ static void grp_update (void)
static void process_flags (int argc, char **argv)
{
const struct group *grp;
int anyflag = 0;
bool anyflag = false;
char *cp;
{
@ -899,7 +919,7 @@ static void process_flags (int argc, char **argv)
exit (E_BAD_ARG);
}
def_home = optarg;
bflg++;
bflg = true;
break;
case 'c':
if (!VALID (optarg)) {
@ -910,7 +930,7 @@ static void process_flags (int argc, char **argv)
exit (E_BAD_ARG);
}
user_comment = optarg;
cflg++;
cflg = true;
break;
case 'd':
if (!VALID (optarg)
@ -922,15 +942,15 @@ static void process_flags (int argc, char **argv)
exit (E_BAD_ARG);
}
user_home = optarg;
dflg++;
dflg = true;
break;
case 'D':
if (anyflag)
usage ();
Dflg++;
Dflg = true;
break;
case 'e':
if (*optarg) {
if ('\0' != *optarg) {
user_expire = strtoday (optarg);
if (user_expire == -1) {
fprintf (stderr,
@ -945,7 +965,7 @@ static void process_flags (int argc, char **argv)
/*
* -e "" is allowed - it's a no-op without /etc/shadow
*/
if (*optarg && !is_shadow_pwd) {
if (('\0' != *optarg) && !is_shadow_pwd) {
fprintf (stderr,
_
("%s: shadow passwords required for -e\n"),
@ -954,25 +974,25 @@ static void process_flags (int argc, char **argv)
}
if (Dflg)
def_expire = optarg;
eflg++;
eflg = true;
break;
case 'f':
def_inactive = get_number (optarg);
/*
* -f -1 is allowed - it's a no-op without /etc/shadow
*/
if (def_inactive != -1 && !is_shadow_pwd) {
if ((-1 != def_inactive) && !is_shadow_pwd) {
fprintf (stderr,
_
("%s: shadow passwords required for -f\n"),
Prog);
exit (E_USAGE);
}
fflg++;
fflg = true;
break;
case 'g':
grp = getgr_nam_gid (optarg);
if (!grp) {
if (NULL == grp) {
fprintf (stderr,
_
("%s: unknown group %s\n"),
@ -985,21 +1005,23 @@ static void process_flags (int argc, char **argv)
} else {
user_gid = grp->gr_gid;
}
gflg++;
gflg = true;
break;
case 'G':
if (get_groups (optarg))
if (get_groups (optarg) != 0) {
exit (E_NOTFOUND);
if (user_groups[0])
do_grp_update++;
Gflg++;
}
if (NULL != user_groups[0]) {
do_grp_update = true;
}
Gflg = true;
break;
case 'h':
usage ();
break;
case 'k':
def_template = optarg;
kflg++;
kflg = true;
break;
case 'K':
/*
@ -1008,7 +1030,7 @@ static void process_flags (int argc, char **argv)
* note: -K UID_MIN=10,UID_MAX=499 doesn't work yet
*/
cp = strchr (optarg, '=');
if (!cp) {
if (NULL == cp) {
fprintf (stderr,
_
("%s: -K requires KEY=VALUE\n"),
@ -1016,21 +1038,22 @@ static void process_flags (int argc, char **argv)
exit (E_BAD_ARG);
}
/* terminate name, point to value */
*cp++ = '\0';
*cp = '\0';
cp++;
if (putdef_str (optarg, cp) < 0)
exit (E_BAD_ARG);
break;
case 'l':
lflg++;
lflg = true;
break;
case 'm':
mflg++;
mflg = true;
break;
case 'N':
Nflg++;
Nflg = true;
break;
case 'o':
oflg++;
oflg = true;
break;
case 'p': /* set encrypted password */
if (!VALID (optarg)) {
@ -1043,13 +1066,13 @@ static void process_flags (int argc, char **argv)
user_pass = optarg;
break;
case 'r':
rflg++;
rflg = true;
break;
case 's':
if (!VALID (optarg)
|| (optarg[0]
&& (optarg[0] != '/'
&& optarg[0] != '*'))) {
|| ( ('\0' != optarg[0])
&& ('/' != optarg[0])
&& ('*' != optarg[0]))) {
fprintf (stderr,
_
("%s: invalid shell '%s'\n"),
@ -1058,19 +1081,19 @@ static void process_flags (int argc, char **argv)
}
user_shell = optarg;
def_shell = optarg;
sflg++;
sflg = true;
break;
case 'u':
user_id = get_uid (optarg);
uflg++;
uflg = true;
break;
case 'U':
Uflg++;
Uflg = true;
break;
default:
usage ();
}
anyflag++;
anyflag = true;
}
}
@ -1167,23 +1190,23 @@ static void process_flags (int argc, char **argv)
*/
static void close_files (void)
{
if (!pw_close ()) {
if (pw_close () == 0) {
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
fail_exit (E_PW_UPDATE);
}
if (is_shadow_pwd && !spw_close ()) {
if (is_shadow_pwd && (spw_close () == 0)) {
fprintf (stderr,
_("%s: cannot rewrite shadow password file\n"), Prog);
fail_exit (E_PW_UPDATE);
}
if (do_grp_update) {
if (!gr_close ()) {
if (gr_close () == 0) {
fprintf (stderr,
_("%s: cannot rewrite group file\n"), Prog);
fail_exit (E_GRP_UPDATE);
}
#ifdef SHADOWGRP
if (is_shadow_grp && !sgr_close ()) {
if (is_shadow_grp && (sgr_close () == 0)) {
fprintf (stderr,
_
("%s: cannot rewrite shadow group file\n"),
@ -1194,16 +1217,16 @@ static void close_files (void)
}
if (is_shadow_pwd) {
spw_unlock ();
shadow_locked--;
shadow_locked = false;
}
pw_unlock ();
passwd_locked--;
passwd_locked = false;
gr_unlock ();
group_locked--;
group_locked = false;
#ifdef SHADOWGRP
if (is_shadow_grp) {
sgr_unlock ();
gshadow_locked--;
gshadow_locked = false;
}
#endif
}
@ -1215,7 +1238,7 @@ static void close_files (void)
*/
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,
@ -1223,8 +1246,8 @@ static void open_files (void)
#endif
exit (E_PW_UPDATE);
}
passwd_locked++;
if (!pw_open (O_RDWR)) {
passwd_locked = true;
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,
@ -1233,7 +1256,7 @@ static void open_files (void)
fail_exit (E_PW_UPDATE);
}
if (is_shadow_pwd) {
if (!spw_lock ()) {
if (spw_lock () == 0) {
fprintf (stderr,
_("%s: cannot lock shadow password file\n"),
Prog);
@ -1244,8 +1267,8 @@ static void open_files (void)
#endif
fail_exit (E_PW_UPDATE);
}
shadow_locked++;
if (!spw_open (O_RDWR)) {
shadow_locked = true;
if (spw_open (O_RDWR) == 0) {
fprintf (stderr,
_("%s: cannot open shadow password file\n"),
Prog);
@ -1261,25 +1284,25 @@ static void open_files (void)
/*
* Lock and open the group file.
*/
if (!gr_lock ()) {
if (gr_lock () == 0) {
fprintf (stderr, _("%s: error locking group file\n"), Prog);
fail_exit (E_GRP_UPDATE);
}
group_locked++;
if (!gr_open (O_RDWR)) {
group_locked = true;
if (gr_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: error opening group file\n"), Prog);
fail_exit (E_GRP_UPDATE);
}
#ifdef SHADOWGRP
if (is_shadow_grp) {
if (!sgr_lock ()) {
if (sgr_lock () == 0) {
fprintf (stderr,
_("%s: error locking shadow group file\n"),
Prog);
fail_exit (E_GRP_UPDATE);
}
gshadow_locked++;
if (!sgr_open (O_RDWR)) {
gshadow_locked = true;
if (sgr_open (O_RDWR) == 0) {
fprintf (stderr,
_("%s: error opening shadow group file\n"),
Prog);
@ -1351,7 +1374,7 @@ static void grp_add (void)
/*
* Write out the new group file entry.
*/
if (!gr_update (&grp)) {
if (gr_update (&grp) == 0) {
fprintf (stderr, _("%s: error adding new group entry\n"), Prog);
fail_exit (E_GRP_UPDATE);
}
@ -1359,13 +1382,13 @@ static void grp_add (void)
/*
* Write out the new shadow group entries as well.
*/
if (is_shadow_grp && !sgr_update (&sgrp)) {
if (is_shadow_grp && (sgr_update (&sgrp) == 0)) {
fprintf (stderr, _("%s: error adding new group entry\n"), Prog);
fail_exit (E_GRP_UPDATE);
}
#endif /* SHADOWGRP */
SYSLOG ((LOG_INFO, "new group: name=%s, GID=%u", user_name, user_gid));
do_grp_update++;
do_grp_update = true;
}
static void faillog_reset (uid_t uid)
@ -1438,7 +1461,7 @@ static void usr_update (void)
/*
* Put the new (struct passwd) in the table.
*/
if (!pw_update (&pwent)) {
if (pw_update (&pwent) == 0) {
fprintf (stderr,
_("%s: error adding new password entry\n"), Prog);
fail_exit (E_PW_UPDATE);
@ -1447,7 +1470,7 @@ static void usr_update (void)
/*
* Put the new (struct spwd) in the table.
*/
if (is_shadow_pwd && !spw_update (&spent)) {
if (is_shadow_pwd && (spw_update (&spent) == 0)) {
fprintf (stderr,
_
("%s: error adding new shadow password entry\n"),
@ -1466,9 +1489,10 @@ static void usr_update (void)
/*
* Do any group file updates for this user.
*/
if (do_grp_update)
if (do_grp_update) {
grp_update ();
}
}
/*
* create_home - create the user's home directory
@ -1479,9 +1503,9 @@ static void usr_update (void)
*/
static void create_home (void)
{
if (access (user_home, F_OK)) {
if (access (user_home, F_OK) != 0) {
/* XXX - create missing parent directories. --marekm */
if (mkdir (user_home, 0)) {
if (mkdir (user_home, 0) != 0) {
fprintf (stderr,
_
("%s: cannot create directory %s\n"),
@ -1496,7 +1520,7 @@ static void create_home (void)
chown (user_home, user_id, user_gid);
chmod (user_home,
0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
home_added++;
home_added = true;
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"adding home directory", user_name, user_id, 1);
@ -1533,7 +1557,7 @@ static void create_mail (void)
}
gr = getgrnam ("mail"); /* local, no need for xgetgrnam */
if (!gr) {
if (NULL == gr) {
fputs (_("Group 'mail' not found. Creating the user mailbox file with 0600 mode.\n"),
stderr);
gid = user_gid;
@ -1543,8 +1567,10 @@ static void create_mail (void)
mode = 0660;
}
if (fchown (fd, user_id, gid) || fchmod (fd, mode))
if ( (fchown (fd, user_id, gid) != 0)
|| (fchmod (fd, mode) != 0)) {
perror (_("Setting mailbox file permissions"));
}
close (fd);
}
@ -1569,9 +1595,9 @@ int main (int argc, char **argv)
*/
Prog = Basename (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
(void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
OPENLOG ("useradd");
@ -1602,27 +1628,27 @@ int main (int argc, char **argv)
retval = PAM_USER_UNKNOWN;
}
if (retval == PAM_SUCCESS) {
if (PAM_SUCCESS == retval) {
retval = pam_start ("useradd", pampw->pw_name,
&conv, &pamh);
}
}
if (retval == PAM_SUCCESS) {
if (PAM_SUCCESS == retval) {
retval = pam_authenticate (pamh, 0);
if (retval != PAM_SUCCESS) {
pam_end (pamh, retval);
if (PAM_SUCCESS != retval) {
(void) pam_end (pamh, retval);
}
}
if (retval == PAM_SUCCESS) {
if (PAM_SUCCESS == retval) {
retval = pam_acct_mgmt (pamh, 0);
if (retval != PAM_SUCCESS) {
pam_end (pamh, retval);
if (PAM_SUCCESS != retval) {
(void) pam_end (pamh, retval);
}
}
if (retval != PAM_SUCCESS) {
if (PAM_SUCCESS != retval) {
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
fail_exit (1);
}
@ -1633,8 +1659,9 @@ int main (int argc, char **argv)
* a new user.
*/
if (Dflg) {
if (gflg || bflg || fflg || eflg || sflg)
exit (set_defaults ()? 1 : 0);
if (gflg || bflg || fflg || eflg || sflg) {
exit ((set_defaults () != 0) ? 1 : 0);
}
show_defaults ();
exit (E_SUCCESS);
@ -1643,7 +1670,7 @@ int main (int argc, char **argv)
/*
* Start with a quick check to see if the user exists.
*/
if (getpwnam (user_name)) { /* local, no need for xgetpwnam */
if (getpwnam (user_name) != NULL) { /* local, no need for xgetpwnam */
fprintf (stderr, _("%s: user %s exists\n"), Prog, user_name);
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding user",
@ -1659,7 +1686,8 @@ int main (int argc, char **argv)
* --bero
*/
if (Uflg) {
if (getgrnam (user_name)) { /* local, no need for xgetgrnam */
/* local, no need for xgetgrnam */
if (getgrnam (user_name) != NULL) {
fprintf (stderr,
_
("%s: group %s exists - if you want to add this user to that group, use -g.\n"),
@ -1728,7 +1756,7 @@ int main (int argc, char **argv)
"Not copying any file from skel directory into it.\n"),
Prog);
} else if (getdef_str ("CREATE_HOME")) {
} else if (getdef_str ("CREATE_HOME") != NULL) {
/*
* RedHat added the CREATE_HOME option in login.defs in their
* version of shadow-utils (which makes -m the default, with
@ -1755,9 +1783,11 @@ int main (int argc, char **argv)
nscd_flush_cache ("group");
#ifdef USE_PAM
if (retval == PAM_SUCCESS)
pam_end (pamh, PAM_SUCCESS);
if (PAM_SUCCESS == retval) {
(void) pam_end (pamh, PAM_SUCCESS);
}
#endif /* USE_PAM */
return E_SUCCESS;
}