From 7972c23d6c278938eb6079c88a47853fc5d053d5 Mon Sep 17 00:00:00 2001 From: roberto Date: Thu, 26 May 2005 10:57:03 +0000 Subject: - 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 MFC after: 1 week --- usr.sbin/chkgrp/chkgrp.8 | 11 ++++++----- usr.sbin/chkgrp/chkgrp.c | 30 ++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) (limited to 'usr.sbin/chkgrp') diff --git a/usr.sbin/chkgrp/chkgrp.8 b/usr.sbin/chkgrp/chkgrp.8 index 942f7d0..ce9497c 100644 --- a/usr.sbin/chkgrp/chkgrp.8 +++ b/usr.sbin/chkgrp/chkgrp.8 @@ -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. diff --git a/usr.sbin/chkgrp/chkgrp.c b/usr.sbin/chkgrp/chkgrp.c index f448dae..9116bc5 100644 --- a/usr.sbin/chkgrp/chkgrp.c +++ b/usr.sbin/chkgrp/chkgrp.c @@ -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); } -- cgit v1.1