From 6ea78090c5694d5a98d96b43f49b62f751f37955 Mon Sep 17 00:00:00 2001 From: green Date: Fri, 3 Sep 1999 18:18:46 +0000 Subject: Make the "uid" and "gid" code better. Now it can detect invalid user names/numbers. Reviewed by: chris --- sbin/ipfw/ipfw.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'sbin/ipfw/ipfw.c') diff --git a/sbin/ipfw/ipfw.c b/sbin/ipfw/ipfw.c index d297119..5a160dc 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; } -- cgit v1.1