* lib/sgetspent.c: Add brackets and parenthesis.
* lib/sgetspent.c: Avoid assignments in comparisons. * lib/sgetspent.c: Avoid implicit conversion of pointers / chars to booleans. * lib/sgetspent.c: Avoid multi-statements lines.
This commit is contained in:
parent
004fb5f9c2
commit
9e31065b5e
@ -1,3 +1,11 @@
|
|||||||
|
2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* lib/sgetspent.c: Add brackets and parenthesis.
|
||||||
|
* lib/sgetspent.c: Avoid assignments in comparisons.
|
||||||
|
* lib/sgetspent.c: Avoid implicit conversion of pointers / chars
|
||||||
|
to booleans.
|
||||||
|
* lib/sgetspent.c: Avoid multi-statements lines.
|
||||||
|
|
||||||
2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
|
2008-05-26 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* lib/sgetpwent.c: Avoid implicit conversion of pointers / chars to
|
* lib/sgetpwent.c: Avoid implicit conversion of pointers / chars to
|
||||||
|
@ -56,32 +56,41 @@ struct spwd *sgetspent (const char *string)
|
|||||||
* have to do that to our private copy.
|
* have to do that to our private copy.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (strlen (string) >= sizeof spwbuf)
|
if (strlen (string) >= sizeof spwbuf) {
|
||||||
return 0; /* fail if too long */
|
return 0; /* fail if too long */
|
||||||
|
}
|
||||||
strcpy (spwbuf, string);
|
strcpy (spwbuf, string);
|
||||||
|
|
||||||
if ((cp = strrchr (spwbuf, '\n')))
|
cp = strrchr (spwbuf, '\n');
|
||||||
|
if (NULL != cp) {
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tokenize the string into colon separated fields. Allow up to
|
* Tokenize the string into colon separated fields. Allow up to
|
||||||
* FIELDS different fields.
|
* FIELDS different fields.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
|
for (cp = spwbuf, i = 0; ('\0' != *cp) && (i < FIELDS); i++) {
|
||||||
fields[i] = cp;
|
fields[i] = cp;
|
||||||
while (*cp && *cp != ':')
|
while (('\0' != *cp) && (':' != *cp)) {
|
||||||
cp++;
|
cp++;
|
||||||
|
}
|
||||||
|
|
||||||
if (*cp)
|
if ('\0' != *cp) {
|
||||||
*cp++ = '\0';
|
*cp = '\0';
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == (FIELDS - 1))
|
if (i == (FIELDS - 1)) {
|
||||||
fields[i++] = cp;
|
fields[i++] = cp;
|
||||||
|
}
|
||||||
|
|
||||||
if ((cp && *cp) || (i != FIELDS && i != OFIELDS))
|
if ( ((NULL != cp) && ('\0' != *cp)) ||
|
||||||
|
((i != FIELDS) && (i != OFIELDS)) ) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start populating the structure. The fields are all in
|
* Start populating the structure. The fields are all in
|
||||||
@ -97,28 +106,37 @@ struct spwd *sgetspent (const char *string)
|
|||||||
* incorrectly formatted number.
|
* incorrectly formatted number.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spwd.sp_lstchg = strtol (fields[2], &cpp, 10)) == 0 && *cpp) {
|
spwd.sp_lstchg = strtol (fields[2], &cpp, 10);
|
||||||
|
/* FIXME: (0 == spwd.sp_lstchg) does not look correct */
|
||||||
|
if ((0 == spwd.sp_lstchg) && ('\0' != *cpp)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (fields[2][0] == '\0')
|
} else if (fields[2][0] == '\0') {
|
||||||
spwd.sp_lstchg = -1;
|
spwd.sp_lstchg = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the minimum period between password changes.
|
* Get the minimum period between password changes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spwd.sp_min = strtol (fields[3], &cpp, 10)) == 0 && *cpp) {
|
spwd.sp_min = strtol (fields[3], &cpp, 10);
|
||||||
|
/* FIXME: (0 == spwd.sp_min) does not look correct */
|
||||||
|
if ((0 == spwd.sp_min) && ('\0' != *cpp)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (fields[3][0] == '\0')
|
} else if (fields[3][0] == '\0') {
|
||||||
spwd.sp_min = -1;
|
spwd.sp_min = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the maximum number of days a password is valid.
|
* Get the maximum number of days a password is valid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spwd.sp_max = strtol (fields[4], &cpp, 10)) == 0 && *cpp) {
|
spwd.sp_max = strtol (fields[4], &cpp, 10);
|
||||||
|
/* FIXME: (0 == spwd.sp_max) does not look correct */
|
||||||
|
if ((0 == spwd.sp_max) && ('\0' != *cpp)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (fields[4][0] == '\0')
|
} else if (fields[4][0] == '\0') {
|
||||||
spwd.sp_max = -1;
|
spwd.sp_max = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
|
* If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
|
||||||
@ -126,8 +144,10 @@ struct spwd *sgetspent (const char *string)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (i == OFIELDS) {
|
if (i == OFIELDS) {
|
||||||
spwd.sp_warn = spwd.sp_inact = spwd.sp_expire =
|
spwd.sp_warn = -1;
|
||||||
spwd.sp_flag = -1;
|
spwd.sp_inact = -1;
|
||||||
|
spwd.sp_expire = -1;
|
||||||
|
spwd.sp_flag = -1;
|
||||||
|
|
||||||
return &spwd;
|
return &spwd;
|
||||||
}
|
}
|
||||||
@ -136,40 +156,53 @@ struct spwd *sgetspent (const char *string)
|
|||||||
* Get the number of days of password expiry warning.
|
* Get the number of days of password expiry warning.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spwd.sp_warn = strtol (fields[5], &cpp, 10)) == 0 && *cpp) {
|
spwd.sp_warn = strtol (fields[5], &cpp, 10);
|
||||||
|
/* FIXME: (0 == spwd.sp_warn) does not look correct */
|
||||||
|
if ((0 == spwd.sp_warn) && ('\0' != *cpp)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (fields[5][0] == '\0')
|
} else if (fields[5][0] == '\0') {
|
||||||
spwd.sp_warn = -1;
|
spwd.sp_warn = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the number of days of inactivity before an account is
|
* Get the number of days of inactivity before an account is
|
||||||
* disabled.
|
* disabled.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spwd.sp_inact = strtol (fields[6], &cpp, 10)) == 0 && *cpp) {
|
spwd.sp_inact = strtol (fields[6], &cpp, 10);
|
||||||
|
/* FIXME: (0 == spwd.sp_inact) does not look correct */
|
||||||
|
if ((0 == spwd.sp_inact) && ('\0' != *cpp)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (fields[6][0] == '\0')
|
} else if (fields[6][0] == '\0') {
|
||||||
spwd.sp_inact = -1;
|
spwd.sp_inact = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the number of days after the epoch before the account is
|
* Get the number of days after the epoch before the account is
|
||||||
* set to expire.
|
* set to expire.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spwd.sp_expire = strtol (fields[7], &cpp, 10)) == 0 && *cpp) {
|
spwd.sp_expire = strtol (fields[7], &cpp, 10);
|
||||||
|
/* FIXME: (0 == spwd.sp_expire) does not look correct */
|
||||||
|
if ((0 == spwd.sp_expire) && ('\0' != *cpp)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (fields[7][0] == '\0')
|
} else if (fields[7][0] == '\0') {
|
||||||
spwd.sp_expire = -1;
|
spwd.sp_expire = -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This field is reserved for future use. But it isn't supposed
|
* This field is reserved for future use. But it isn't supposed
|
||||||
* to have anything other than a valid integer in it.
|
* to have anything other than a valid integer in it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((spwd.sp_flag = strtol (fields[8], &cpp, 10)) == 0 && *cpp) {
|
spwd.sp_flag = strtol (fields[8], &cpp, 10);
|
||||||
|
/* FIXME: (0 == spwd.sp_flag) does not look correct */
|
||||||
|
if ((0 == spwd.sp_flag) && ('\0' != *cpp)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (fields[8][0] == '\0')
|
} else if (fields[8][0] == '\0') {
|
||||||
spwd.sp_flag = -1;
|
spwd.sp_flag = -1;
|
||||||
|
}
|
||||||
|
|
||||||
return (&spwd);
|
return (&spwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user