* Start by seeing if the named group already exists. This will be
* very easy to deal with if it does.
*/
- if ((grp = gr_locate (gid))) {
+ grp = gr_locate (gid);
+ if (NULL != grp) {
add_member:
grent = *grp;
*ngid = grent.gr_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;
uid_t i;
*/
if ((uid[0] >= '0') && (uid[0] <= '9')) {
i = atoi (uid);
- } else if (('\0' != uid[0]) && (pwd = pw_locate (uid))) {
- i = pwd->pw_uid;
} else {
- /* Start with gid, either the specified GID, or an ID
- * greater than all the group and user IDs */
- i = gid;
- for (pw_rewind (); (pwd = pw_next ());) {
- if (pwd->pw_uid >= i) {
- i = pwd->pw_uid + 1;
+ if ('\0' != uid[0]) {
+ pwd = pw_locate (uid);
+ }
+
+ if (NULL != pwd) {
+ i = pwd->pw_uid;
+ } else {
+ /* Start with gid, either the specified GID, or an ID
+ * greater than all the group and user IDs */
+ i = gid;
+ for (pw_rewind (); (pwd = pw_next ());) {
+ if (pwd->pw_uid >= i) {
+ i = pwd->pw_uid + 1;
+ }
}
}
}
* Do the first and easiest shadow file case. The user already
* 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_pwdp = pw_encrypt (passwd,
crypt_make_salt (crypt_method,
*/
while (fgets (buf, sizeof buf, stdin) != (char *) 0) {
line++;
- if ((cp = strrchr (buf, '\n'))) {
+ cp = strrchr (buf, '\n');
+ if (NULL != cp) {
*cp = '\0';
} else {
fprintf (stderr, _("%s: line %d: line too long\n"),
*/
for (cp = buf, nfields = 0; nfields < 7; nfields++) {
fields[nfields] = cp;
- if ((cp = strchr (cp, ':'))) {
+ cp = strchr (cp, ':');
+ if (NULL != cp) {
*cp++ = '\0';
} else {
break;
* new group, if that group ID exists, a whole new group ID
* will be made up.
*/
- if (!(pw = pw_locate (fields[0])) &&
- add_group (fields[0], fields[3], &gid)) {
+ pw = pw_locate (fields[0]);
+ if ( (NULL == pw)
+ && (add_group (fields[0], fields[3], &gid) != 0)) {
fprintf (stderr,
_("%s: line %d: can't create GID\n"),
Prog, line);
* The password, gecos field, directory, and shell fields
* all come next.
*/
- if (!(pw = pw_locate (fields[0]))) {
+ pw = pw_locate (fields[0]);
+ if (NULL == pw) {
fprintf (stderr,
_("%s: line %d: cannot find user %s\n"),
Prog, line, fields[0]);