Avoid implicit brackets and re-indent.
This commit is contained in:
parent
9923513271
commit
8c4efbb8ce
@ -5,6 +5,7 @@
|
|||||||
check_flags(), check_perms(), open_files(), and close_files().
|
check_flags(), check_perms(), open_files(), and close_files().
|
||||||
* 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.
|
||||||
|
|
||||||
2007-12-29 Nicolas François <nicolas.francois@centraliens.net>
|
2007-12-29 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
@ -119,9 +119,11 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
|
|||||||
add_member:
|
add_member:
|
||||||
grent = *grp;
|
grent = *grp;
|
||||||
*ngid = grent.gr_gid;
|
*ngid = grent.gr_gid;
|
||||||
for (i = 0; grent.gr_mem[i] != (char *) 0; i++)
|
for (i = 0; grent.gr_mem[i] != (char *) 0; i++) {
|
||||||
if (strcmp (grent.gr_mem[i], name) == 0)
|
if (strcmp (grent.gr_mem[i], name) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
grent.gr_mem = (char **) xmalloc (sizeof (char *) * (i + 2));
|
grent.gr_mem = (char **) xmalloc (sizeof (char *) * (i + 2));
|
||||||
memcpy (grent.gr_mem, grp->gr_mem, sizeof (char *) * (i + 2));
|
memcpy (grent.gr_mem, grp->gr_mem, sizeof (char *) * (i + 2));
|
||||||
@ -140,26 +142,29 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
|
|||||||
if (gid[0] == '\0') {
|
if (gid[0] == '\0') {
|
||||||
i = 100;
|
i = 100;
|
||||||
for (pw_rewind (); (pwd = pw_next ());) {
|
for (pw_rewind (); (pwd = pw_next ());) {
|
||||||
if (pwd->pw_uid >= (unsigned int)i)
|
if (pwd->pw_uid >= (unsigned int)i) {
|
||||||
i = pwd->pw_uid + 1;
|
i = pwd->pw_uid + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (gr_rewind (); (grp = gr_next ());) {
|
for (gr_rewind (); (grp = gr_next ());) {
|
||||||
if (grp->gr_gid == (unsigned int)i) {
|
if (grp->gr_gid == (unsigned int)i) {
|
||||||
i = -1;
|
i = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (gid[0] >= '0' && gid[0] <= '9') {
|
} else if ((gid[0] >= '0') && (gid[0] <= '9')) {
|
||||||
/*
|
/*
|
||||||
* The GID is a number, which means either this is a brand
|
* The GID is a number, which means either this is a brand
|
||||||
* new group, or an existing group. For existing groups I
|
* new group, or an existing group. For existing groups I
|
||||||
* just add myself as a member, just like I did earlier.
|
* just add myself as a member, just like I did earlier.
|
||||||
*/
|
*/
|
||||||
i = atoi (gid);
|
i = atoi (gid);
|
||||||
for (gr_rewind (); (grp = gr_next ());)
|
for (gr_rewind (); (grp = gr_next ());) {
|
||||||
if (grp->gr_gid == (unsigned int)i)
|
if (grp->gr_gid == (unsigned int)i) {
|
||||||
goto add_member;
|
goto add_member;
|
||||||
} else
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
/*
|
/*
|
||||||
* The last alternative is that the GID is a name which is
|
* The last alternative is that the GID is a name which is
|
||||||
* not already the name of an existing group, and I need to
|
* not already the name of an existing group, and I need to
|
||||||
@ -167,23 +172,27 @@ static int add_group (const char *name, const char *gid, gid_t * ngid)
|
|||||||
* have.
|
* have.
|
||||||
*/
|
*/
|
||||||
i = -1;
|
i = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If I don't have a group ID by now, I'll go get the next one.
|
* If I don't have a group ID by now, I'll go get the next one.
|
||||||
*/
|
*/
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
for (i = 100, gr_rewind (); (grp = gr_next ());)
|
for (i = 100, gr_rewind (); (grp = gr_next ());) {
|
||||||
if (grp->gr_gid >= (unsigned int)i)
|
if (grp->gr_gid >= (unsigned int)i) {
|
||||||
i = grp->gr_gid + 1;
|
i = grp->gr_gid + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now I have all of the fields required to create the new group.
|
* Now I have all of the fields required to create the new group.
|
||||||
*/
|
*/
|
||||||
if (gid[0] && (gid[0] <= '0' || gid[0] >= '9'))
|
if (('\0' != gid[0]) && ((gid[0] <= '0') || (gid[0] >= '9'))) {
|
||||||
grent.gr_name = xstrdup (gid);
|
grent.gr_name = xstrdup (gid);
|
||||||
else
|
} else {
|
||||||
grent.gr_name = xstrdup (name);
|
grent.gr_name = xstrdup (name);
|
||||||
|
}
|
||||||
|
|
||||||
grent.gr_passwd = "x"; /* XXX warning: const */
|
grent.gr_passwd = "x"; /* XXX warning: const */
|
||||||
grent.gr_gid = i;
|
grent.gr_gid = i;
|
||||||
@ -208,18 +217,20 @@ static int add_user (const char *name, const char *uid, uid_t * nuid, gid_t gid)
|
|||||||
* The first guess for the UID is either the numerical UID that the
|
* The first guess for the UID is either the numerical UID that the
|
||||||
* caller provided, or the next available UID.
|
* caller provided, or the next available UID.
|
||||||
*/
|
*/
|
||||||
if (uid[0] >= '0' && uid[0] <= '9') {
|
if ((uid[0] >= '0') && (uid[0] <= '9')) {
|
||||||
i = atoi (uid);
|
i = atoi (uid);
|
||||||
} else if (uid[0] && (pwd = pw_locate (uid))) {
|
} else if (('\0' != uid[0]) && (pwd = pw_locate (uid))) {
|
||||||
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
|
||||||
* greater than all the group and user IDs */
|
* greater than all the group and user IDs */
|
||||||
i = gid;
|
i = gid;
|
||||||
for (pw_rewind (); (pwd = pw_next ());)
|
for (pw_rewind (); (pwd = pw_next ());) {
|
||||||
if (pwd->pw_uid >= i)
|
if (pwd->pw_uid >= i) {
|
||||||
i = pwd->pw_uid + 1;
|
i = pwd->pw_uid + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I don't want to fill in the entire password structure members
|
* I don't want to fill in the entire password structure members
|
||||||
@ -242,11 +253,12 @@ static void update_passwd (struct passwd *pwd, const char *passwd)
|
|||||||
{
|
{
|
||||||
void *crypt_arg = NULL;
|
void *crypt_arg = NULL;
|
||||||
if (crypt_method != NULL) {
|
if (crypt_method != NULL) {
|
||||||
if (sflg)
|
if (sflg) {
|
||||||
crypt_arg = &sha_rounds;
|
crypt_arg = &sha_rounds;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (crypt_method != NULL && 0 == strcmp(crypt_method, "NONE")) {
|
if ((crypt_method != NULL) && (0 == strcmp(crypt_method, "NONE"))) {
|
||||||
pwd->pw_passwd = (char *)passwd;
|
pwd->pw_passwd = (char *)passwd;
|
||||||
} else {
|
} else {
|
||||||
pwd->pw_passwd = pw_encrypt (passwd,
|
pwd->pw_passwd = pw_encrypt (passwd,
|
||||||
@ -264,9 +276,10 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
|
|||||||
struct spwd spent;
|
struct spwd spent;
|
||||||
void *crypt_arg = NULL;
|
void *crypt_arg = NULL;
|
||||||
if (crypt_method != NULL) {
|
if (crypt_method != NULL) {
|
||||||
if (sflg)
|
if (sflg) {
|
||||||
crypt_arg = &sha_rounds;
|
crypt_arg = &sha_rounds;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In the case of regular password files, this is real easy - pwd
|
* In the case of regular password files, this is real easy - pwd
|
||||||
@ -401,12 +414,12 @@ static void check_flags (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cflg) {
|
if (cflg) {
|
||||||
if ( 0 != strcmp (crypt_method, "DES")
|
if ( (0 != strcmp (crypt_method, "DES"))
|
||||||
&& 0 != strcmp (crypt_method, "MD5")
|
&& (0 != strcmp (crypt_method, "MD5"))
|
||||||
&& 0 != strcmp (crypt_method, "NONE")
|
&& (0 != strcmp (crypt_method, "NONE"))
|
||||||
#ifdef USE_SHA_CRYPT
|
#ifdef USE_SHA_CRYPT
|
||||||
&& 0 != strcmp (crypt_method, "SHA256")
|
&& (0 != strcmp (crypt_method, "SHA256"))
|
||||||
&& 0 != strcmp (crypt_method, "SHA512")
|
&& (0 != strcmp (crypt_method, "SHA512"))
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
@ -484,16 +497,18 @@ static void open_files (void)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: can't lock files, try again later\n"), Prog);
|
_("%s: can't lock files, try again later\n"), Prog);
|
||||||
(void) pw_unlock ();
|
(void) pw_unlock ();
|
||||||
if (is_shadow)
|
if (is_shadow) {
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
|
}
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
if (!pw_open (O_RDWR) || (is_shadow && !spw_open (O_RDWR))
|
if (!pw_open (O_RDWR) || (is_shadow && !spw_open (O_RDWR))
|
||||||
|| !gr_open (O_RDWR)) {
|
|| !gr_open (O_RDWR)) {
|
||||||
fprintf (stderr, _("%s: can't open files\n"), Prog);
|
fprintf (stderr, _("%s: can't open files\n"), Prog);
|
||||||
(void) pw_unlock ();
|
(void) pw_unlock ();
|
||||||
if (is_shadow)
|
if (is_shadow) {
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
|
}
|
||||||
(void) gr_unlock ();
|
(void) gr_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
@ -507,14 +522,16 @@ static void close_files (void)
|
|||||||
if (!pw_close () || (is_shadow && !spw_close ()) || !gr_close ()) {
|
if (!pw_close () || (is_shadow && !spw_close ()) || !gr_close ()) {
|
||||||
fprintf (stderr, _("%s: error updating files\n"), Prog);
|
fprintf (stderr, _("%s: error updating files\n"), Prog);
|
||||||
(void) gr_unlock ();
|
(void) gr_unlock ();
|
||||||
if (is_shadow)
|
if (is_shadow) {
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
|
}
|
||||||
(void) pw_unlock ();
|
(void) pw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
(void) gr_unlock ();
|
(void) gr_unlock ();
|
||||||
if (is_shadow)
|
if (is_shadow) {
|
||||||
(void) spw_unlock ();
|
(void) spw_unlock ();
|
||||||
|
}
|
||||||
(void) pw_unlock ();
|
(void) pw_unlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,11 +589,12 @@ 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, ':')))
|
if ((cp = strchr (cp, ':'))) {
|
||||||
*cp++ = '\0';
|
*cp++ = '\0';
|
||||||
else
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (nfields != 6) {
|
if (nfields != 6) {
|
||||||
fprintf (stderr, _("%s: line %d: invalid line\n"),
|
fprintf (stderr, _("%s: line %d: invalid line\n"),
|
||||||
Prog, line);
|
Prog, line);
|
||||||
@ -609,7 +627,8 @@ int main (int argc, char **argv)
|
|||||||
* available user ID is computed and used. After this there
|
* available user ID is computed and used. After this there
|
||||||
* will at least be a (struct passwd) for the user.
|
* will at least be a (struct passwd) for the user.
|
||||||
*/
|
*/
|
||||||
if (!pw && add_user (fields[0], fields[2], &uid, gid)) {
|
if ( (NULL == pw)
|
||||||
|
&& (add_user (fields[0], fields[2], &uid, gid) != 0)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: can't create UID\n"),
|
_("%s: line %d: can't create UID\n"),
|
||||||
Prog, line);
|
Prog, line);
|
||||||
@ -637,28 +656,32 @@ int main (int argc, char **argv)
|
|||||||
errors++;
|
errors++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fields[4][0])
|
if (fields[4][0]) {
|
||||||
newpw.pw_gecos = fields[4];
|
newpw.pw_gecos = fields[4];
|
||||||
|
}
|
||||||
|
|
||||||
if (fields[5][0])
|
if (fields[5][0]) {
|
||||||
newpw.pw_dir = fields[5];
|
newpw.pw_dir = fields[5];
|
||||||
|
}
|
||||||
|
|
||||||
if (fields[6][0])
|
if (fields[6][0]) {
|
||||||
newpw.pw_shell = fields[6];
|
newpw.pw_shell = fields[6];
|
||||||
|
}
|
||||||
|
|
||||||
if (newpw.pw_dir[0] && access (newpw.pw_dir, F_OK)) {
|
if (newpw.pw_dir[0] && access (newpw.pw_dir, F_OK)) {
|
||||||
if (mkdir (newpw.pw_dir,
|
if (mkdir (newpw.pw_dir,
|
||||||
0777 & ~getdef_num ("UMASK",
|
0777 & ~getdef_num ("UMASK",
|
||||||
GETDEF_DEFAULT_UMASK)))
|
GETDEF_DEFAULT_UMASK))) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: mkdir failed\n"), Prog,
|
_("%s: line %d: mkdir failed\n"), Prog,
|
||||||
line);
|
line);
|
||||||
else if (chown
|
} else if (chown
|
||||||
(newpw.pw_dir, newpw.pw_uid, newpw.pw_gid))
|
(newpw.pw_dir, newpw.pw_uid, newpw.pw_gid)) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: line %d: chown failed\n"), Prog,
|
_("%s: line %d: chown failed\n"), Prog,
|
||||||
line);
|
line);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the password entry with the new changes made.
|
* Update the password entry with the new changes made.
|
||||||
@ -683,8 +706,9 @@ int main (int argc, char **argv)
|
|||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("%s: error detected, changes ignored\n"), Prog);
|
_("%s: error detected, changes ignored\n"), Prog);
|
||||||
(void) gr_unlock ();
|
(void) gr_unlock ();
|
||||||
if (is_shadow)
|
if (is_shadow) {
|
||||||
spw_unlock ();
|
spw_unlock ();
|
||||||
|
}
|
||||||
(void) pw_unlock ();
|
(void) pw_unlock ();
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user