diff options
author | Ollivier Robert <roberto@FreeBSD.org> | 2005-05-26 10:57:03 +0000 |
---|---|---|
committer | Ollivier Robert <roberto@FreeBSD.org> | 2005-05-26 10:57:03 +0000 |
commit | 41b27a91a9feaa94873d0ee4ce24c2f1b39e1dd6 (patch) | |
tree | 20598d149b0c36d18e9a4c955135652d778ae9ce /usr.sbin/chkgrp/chkgrp.c | |
parent | bef2146e493b6148334123c319a890a8f0abcfca (diff) |
- 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
Notes
Notes:
svn path=/head/; revision=146641
Diffstat (limited to 'usr.sbin/chkgrp/chkgrp.c')
-rw-r--r-- | usr.sbin/chkgrp/chkgrp.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/usr.sbin/chkgrp/chkgrp.c b/usr.sbin/chkgrp/chkgrp.c index f448dae500d6..9116bc5f8867 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); } |