- Add further functionality to check for invalid characters
- Remove keyword 'continue' for more indepth error reporting on each line - WARNS 6 Clean Submitted by: Liam J. Foy <liamfoy@dragonflybsd.org> MFC after: 1 week
This commit is contained in:
parent
bef2146e49
commit
41b27a91a9
@ -44,7 +44,8 @@ errors.
|
||||
Specifically, it checks that every non-blank, non-comment
|
||||
entry is composed of four colon-separated fields, that none of them
|
||||
contains whitespace, and that the third field (the group ID) is
|
||||
numeric.
|
||||
numeric. It will also check for invalid characters in the group names
|
||||
and group members.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /etc/group -compact
|
||||
.It Pa /etc/group
|
||||
@ -64,8 +65,6 @@ For each error found,
|
||||
.Nm
|
||||
will print an error message containing the name of the file being
|
||||
scanned and the line number on which the error was found.
|
||||
Otherwise no
|
||||
output is produced.
|
||||
.Sh SEE ALSO
|
||||
.Xr getgrent 3 ,
|
||||
.Xr group 5
|
||||
@ -79,6 +78,8 @@ The
|
||||
.Nm
|
||||
utility and this manual page were written by
|
||||
.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
|
||||
.Pp
|
||||
Further functionality was added by
|
||||
.An Liam J. Foy Aq liamfoy@dragonflybsd.org .
|
||||
.Sh BUGS
|
||||
Should check fields more thoroughly for allowed/disallowed
|
||||
characters, and the range of the group ID.
|
||||
Should check the range of the group ID.
|
||||
|
@ -50,7 +50,7 @@ main(int argc, char *argv[])
|
||||
size_t len;
|
||||
int n = 0, k, e = 0;
|
||||
char *line, *f[4], *p;
|
||||
const char *gfn;
|
||||
const char *cp, *gfn;
|
||||
FILE *gf;
|
||||
|
||||
/* check arguments */
|
||||
@ -104,30 +104,46 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
line[i++] = 0;
|
||||
}
|
||||
|
||||
for (cp = f[0] ; *cp ; cp++) {
|
||||
if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-') {
|
||||
warnx("%s: line %d: '%c' invalid character", gfn, n, *cp);
|
||||
e++;
|
||||
}
|
||||
}
|
||||
|
||||
for (cp = f[3] ; *cp ; cp++) {
|
||||
if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-' &&
|
||||
*cp != ',') {
|
||||
warnx("%s: line %d: '%c' invalid character", gfn, n, *cp);
|
||||
e++;
|
||||
}
|
||||
}
|
||||
|
||||
if (k < 4) {
|
||||
warnx("%s: line %d: missing field(s)", gfn, n);
|
||||
e++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check if fourth field ended with a colon */
|
||||
if (i < len) {
|
||||
warnx("%s: line %d: too many fields", gfn, n);
|
||||
e++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check that none of the fields contain whitespace */
|
||||
for (k = 0; k < 4; k++)
|
||||
if (strcspn(f[k], " \t") != strlen(f[k]))
|
||||
for (k = 0; k < 4; k++) {
|
||||
if (strcspn(f[k], " \t") != strlen(f[k])) {
|
||||
warnx("%s: line %d: field %d contains whitespace",
|
||||
gfn, n, k+1);
|
||||
e++;
|
||||
}
|
||||
}
|
||||
|
||||
/* check that the GID is numeric */
|
||||
if (strspn(f[2], "0123456789") != strlen(f[2])) {
|
||||
warnx("%s: line %d: GID is not numeric", gfn, n);
|
||||
e++;
|
||||
continue;
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -142,5 +158,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* done */
|
||||
fclose(gf);
|
||||
if (e == 0)
|
||||
printf("%s is fine\n", gfn);
|
||||
exit(e ? EX_DATAERR : EX_OK);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user