Avoid assignments in comparisons.
This commit is contained in:
parent
8c4efbb8ce
commit
b040f047fd
@ -6,6 +6,7 @@
|
|||||||
* src/newusers.c: Before pam_end(), the return value of the previous
|
* src/newusers.c: Before pam_end(), the return value of the previous
|
||||||
pam API was already checked. No need to validate it again.
|
pam API was already checked. No need to validate it again.
|
||||||
* src/newusers.c: Avoid implicit brackets.
|
* src/newusers.c: Avoid implicit brackets.
|
||||||
|
* src/newusers.c: Avoid assignments in comparisons.
|
||||||
|
|
||||||
2007-12-29 Nicolas François <nicolas.francois@centraliens.net>
|
2007-12-29 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
@ -115,7 +115,8 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
|
|||||||
* Start by seeing if the named group already exists. This will be
|
* Start by seeing if the named group already exists. This will be
|
||||||
* very easy to deal with if it does.
|
* very easy to deal with if it does.
|
||||||
*/
|
*/
|
||||||
if ((grp = gr_locate (gid))) {
|
grp = gr_locate (gid);
|
||||||
|
if (NULL != grp) {
|
||||||
add_member:
|
add_member:
|
||||||
grent = *grp;
|
grent = *grp;
|
||||||
*ngid = grent.gr_gid;
|
*ngid = grent.gr_gid;
|
||||||
@ -209,7 +210,7 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
|
|||||||
*/
|
*/
|
||||||
static int add_user (const char *name, const char *uid, uid_t * nuid, gid_t gid)
|
static int add_user (const char *name, const char *uid, uid_t * nuid, gid_t gid)
|
||||||
{
|
{
|
||||||
const struct passwd *pwd;
|
const struct passwd *pwd = NULL;
|
||||||
struct passwd pwent;
|
struct passwd pwent;
|
||||||
uid_t i;
|
uid_t i;
|
||||||
|
|
||||||
@ -219,7 +220,12 @@ static int add_user (const char *name, const char *uid, uid_t * nuid, gid_t gid)
|
|||||||
*/
|
*/
|
||||||
if ((uid[0] >= '0') && (uid[0] <= '9')) {
|
if ((uid[0] >= '0') && (uid[0] <= '9')) {
|
||||||
i = atoi (uid);
|
i = atoi (uid);
|
||||||
} else if (('\0' != uid[0]) && (pwd = pw_locate (uid))) {
|
} else {
|
||||||
|
if ('\0' != uid[0]) {
|
||||||
|
pwd = pw_locate (uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL != pwd) {
|
||||||
i = pwd->pw_uid;
|
i = pwd->pw_uid;
|
||||||
} else {
|
} else {
|
||||||
/* Start with gid, either the specified GID, or an ID
|
/* Start with gid, either the specified GID, or an ID
|
||||||
@ -231,6 +237,7 @@ static int add_user (const char *name, const char *uid, uid_t * nuid, gid_t gid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I don't want to fill in the entire password structure members
|
* I don't want to fill in the entire password structure members
|
||||||
@ -295,7 +302,8 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
|
|||||||
* Do the first and easiest shadow file case. The user already
|
* Do the first and easiest shadow file case. The user already
|
||||||
* exists in the shadow password file.
|
* exists in the shadow password file.
|
||||||
*/
|
*/
|
||||||
if ((sp = spw_locate (pwd->pw_name))) {
|
sp = spw_locate (pwd->pw_name);
|
||||||
|
if (NULL != sp) {
|
||||||
spent = *sp;
|
spent = *sp;
|
||||||
spent.sp_pwdp = pw_encrypt (passwd,
|
spent.sp_pwdp = pw_encrypt (passwd,
|
||||||
crypt_make_salt (crypt_method,
|
crypt_make_salt (crypt_method,
|
||||||
@ -573,7 +581,8 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
while (fgets (buf, sizeof buf, stdin) != (char *) 0) {
|
while (fgets (buf, sizeof buf, stdin) != (char *) 0) {
|
||||||
line++;
|
line++;
|
||||||
if ((cp = strrchr (buf, '\n'))) {
|
cp = strrchr (buf, '\n');
|
||||||
|
if (NULL != cp) {
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
} else {
|
} else {
|
||||||
fprintf (stderr, _("%s: line %d: line too long\n"),
|
fprintf (stderr, _("%s: line %d: line too long\n"),
|
||||||
@ -589,7 +598,8 @@ int main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
for (cp = buf, nfields = 0; nfields < 7; nfields++) {
|
for (cp = buf, nfields = 0; nfields < 7; nfields++) {
|
||||||
fields[nfields] = cp;
|
fields[nfields] = cp;
|
||||||
if ((cp = strchr (cp, ':'))) {
|
cp = strchr (cp, ':');
|
||||||
|
if (NULL != cp) {
|
||||||
*cp++ = '\0';
|
*cp++ = '\0';
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -611,8 +621,9 @@ int main (int argc, char **argv)
|
|||||||
* new group, if that group ID exists, a whole new group ID
|
* new group, if that group ID exists, a whole new group ID
|
||||||
* will be made up.
|
* will be made up.
|
||||||
*/
|
*/
|
||||||
if (!(pw = pw_locate (fields[0])) &&
|
pw = pw_locate (fields[0]);
|
||||||
add_group (fields[0], fields[3], &gid)) {
|
if ( (NULL == pw)
|
||||||
|
&& (add_group (fields[0], fields[3], &gid) != 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: can't create GID\n"),
|
_("%s: line %d: can't create GID\n"),
|
||||||
Prog, line);
|
Prog, line);
|
||||||
@ -640,7 +651,8 @@ int main (int argc, char **argv)
|
|||||||
* The password, gecos field, directory, and shell fields
|
* The password, gecos field, directory, and shell fields
|
||||||
* all come next.
|
* all come next.
|
||||||
*/
|
*/
|
||||||
if (!(pw = pw_locate (fields[0]))) {
|
pw = pw_locate (fields[0]);
|
||||||
|
if (NULL == pw) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: cannot find user %s\n"),
|
_("%s: line %d: cannot find user %s\n"),
|
||||||
Prog, line, fields[0]);
|
Prog, line, fields[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user