mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-04 12:52:15 +00:00
- 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
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=146641
@ -44,7 +44,8 @@ errors.
|
|||||||
Specifically, it checks that every non-blank, non-comment
|
Specifically, it checks that every non-blank, non-comment
|
||||||
entry is composed of four colon-separated fields, that none of them
|
entry is composed of four colon-separated fields, that none of them
|
||||||
contains whitespace, and that the third field (the group ID) is
|
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
|
.Sh FILES
|
||||||
.Bl -tag -width /etc/group -compact
|
.Bl -tag -width /etc/group -compact
|
||||||
.It Pa /etc/group
|
.It Pa /etc/group
|
||||||
@ -64,8 +65,6 @@ For each error found,
|
|||||||
.Nm
|
.Nm
|
||||||
will print an error message containing the name of the file being
|
will print an error message containing the name of the file being
|
||||||
scanned and the line number on which the error was found.
|
scanned and the line number on which the error was found.
|
||||||
Otherwise no
|
|
||||||
output is produced.
|
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr getgrent 3 ,
|
.Xr getgrent 3 ,
|
||||||
.Xr group 5
|
.Xr group 5
|
||||||
@ -79,6 +78,8 @@ The
|
|||||||
.Nm
|
.Nm
|
||||||
utility and this manual page were written by
|
utility and this manual page were written by
|
||||||
.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
|
.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
|
.Sh BUGS
|
||||||
Should check fields more thoroughly for allowed/disallowed
|
Should check the range of the group ID.
|
||||||
characters, and the range of the group ID.
|
|
||||||
|
@ -50,7 +50,7 @@ main(int argc, char *argv[])
|
|||||||
size_t len;
|
size_t len;
|
||||||
int n = 0, k, e = 0;
|
int n = 0, k, e = 0;
|
||||||
char *line, *f[4], *p;
|
char *line, *f[4], *p;
|
||||||
const char *gfn;
|
const char *cp, *gfn;
|
||||||
FILE *gf;
|
FILE *gf;
|
||||||
|
|
||||||
/* check arguments */
|
/* check arguments */
|
||||||
@ -104,30 +104,46 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
line[i++] = 0;
|
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) {
|
if (k < 4) {
|
||||||
warnx("%s: line %d: missing field(s)", gfn, n);
|
warnx("%s: line %d: missing field(s)", gfn, n);
|
||||||
e++;
|
e++;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if fourth field ended with a colon */
|
/* check if fourth field ended with a colon */
|
||||||
if (i < len) {
|
if (i < len) {
|
||||||
warnx("%s: line %d: too many fields", gfn, n);
|
warnx("%s: line %d: too many fields", gfn, n);
|
||||||
e++;
|
e++;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check that none of the fields contain whitespace */
|
/* check that none of the fields contain whitespace */
|
||||||
for (k = 0; k < 4; k++)
|
for (k = 0; k < 4; k++) {
|
||||||
if (strcspn(f[k], " \t") != strlen(f[k]))
|
if (strcspn(f[k], " \t") != strlen(f[k])) {
|
||||||
warnx("%s: line %d: field %d contains whitespace",
|
warnx("%s: line %d: field %d contains whitespace",
|
||||||
gfn, n, k+1);
|
gfn, n, k+1);
|
||||||
|
e++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* check that the GID is numeric */
|
/* check that the GID is numeric */
|
||||||
if (strspn(f[2], "0123456789") != strlen(f[2])) {
|
if (strspn(f[2], "0123456789") != strlen(f[2])) {
|
||||||
warnx("%s: line %d: GID is not numeric", gfn, n);
|
warnx("%s: line %d: GID is not numeric", gfn, n);
|
||||||
e++;
|
e++;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -142,5 +158,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* done */
|
/* done */
|
||||||
fclose(gf);
|
fclose(gf);
|
||||||
|
if (e == 0)
|
||||||
|
printf("%s is fine\n", gfn);
|
||||||
exit(e ? EX_DATAERR : EX_OK);
|
exit(e ? EX_DATAERR : EX_OK);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user