aboutsummaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorBrian Feldman <green@FreeBSD.org>1999-09-03 18:18:46 +0000
committerBrian Feldman <green@FreeBSD.org>1999-09-03 18:18:46 +0000
commit1efcedf596030f6be528bbe65999fa821bb2c04c (patch)
treef1dd33e7b78efd36b1a060607429054b530f1aae /sbin
parent77b3485b11cbb20746eb4d9e9d4275cd68b0bbb7 (diff)
downloadsrc-1efcedf596030f6be528bbe65999fa821bb2c04c.tar.gz
src-1efcedf596030f6be528bbe65999fa821bb2c04c.zip
Make the "uid" and "gid" code better. Now it can detect invalid user
names/numbers. Reviewed by: chris
Notes
Notes: svn path=/head/; revision=50851
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ipfw/ipfw.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/sbin/ipfw/ipfw.c b/sbin/ipfw/ipfw.c
index d297119f7bf8..5a160dcd5951 100644
--- a/sbin/ipfw/ipfw.c
+++ b/sbin/ipfw/ipfw.c
@@ -1273,27 +1273,43 @@ add(ac,av)
while (ac) {
if (!strncmp(*av,"uid",strlen(*av))) {
struct passwd *pwd;
+ char *end;
+ uid_t uid;
rule.fw_flg |= IP_FW_F_UID;
ac--; av++;
if (!ac)
show_usage("``uid'' requires argument");
- rule.fw_uid = (pwd = getpwnam(*av)) ? pwd->pw_uid
- : strtoul(*av, NULL, 0);
+ uid = strtoul(*av, &end, 0);
+ if (*end == '\0')
+ pwd = getpwuid(uid);
+ else
+ pwd = getpwnam(*av);
+ if (pwd == NULL)
+ show_usage("uid \"%s\" is nonexistant", *av);
+ rule.fw_uid = pwd->pw_uid;
ac--; av++;
continue;
}
if (!strncmp(*av,"gid",strlen(*av))) {
struct group *grp;
+ char *end;
+ gid_t gid;
rule.fw_flg |= IP_FW_F_GID;
ac--; av++;
if (!ac)
show_usage("``gid'' requires argument");
- rule.fw_gid = (grp = getgrnam(*av)) ? (gid_t)grp->gr_gid
- : strtoul(*av, NULL, 0);
+ gid = strtoul(*av, &end, 0);
+ if (*end == '\0')
+ grp = getgrgid(gid);
+ else
+ grp = getgrnam(*av);
+ if (grp == NULL)
+ show_usage("gid \"%s\" is nonexistant", *av);
+ rule.fw_gid = grp->gr_gid;
ac--; av++;
continue;
}