]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
meta: accept uid/gid in numerical
authorPablo Neira Ayuso <pablo@netfilter.org>
Sat, 20 Apr 2013 10:06:19 +0000 (12:06 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sat, 20 Apr 2013 10:07:34 +0000 (12:07 +0200)
You can use the user/group name or alternatively the uid/gid.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/meta.c

index d1fb791ca6eb7d9641fda34f1e3e8266e817ec20..54d4d64ef149e57857fa9a33161d81c29aeebc2d 100644 (file)
@@ -219,8 +219,12 @@ static struct error_record *uid_type_parse(const struct expr *sym,
        struct passwd *pw;
 
        pw = getpwnam(sym->identifier);
-       if (pw == NULL)
-               return error(&sym->location, "User does not exist");
+       if (pw == NULL) {
+               /* Try harder, lookup based on UID */
+               pw = getpwuid(atol(sym->identifier));
+               if (pw == NULL)
+                       return error(&sym->location, "User does not exist");
+       }
 
        *res = constant_expr_alloc(&sym->location, sym->dtype,
                                   BYTEORDER_HOST_ENDIAN,
@@ -260,8 +264,12 @@ static struct error_record *gid_type_parse(const struct expr *sym,
        struct group *gr;
 
        gr = getgrnam(sym->identifier);
-       if (gr == NULL)
-               return error(&sym->location, "Group does not exist");
+       if (gr == NULL) {
+               /* Try harder, lookup based on GID */
+               gr = getgrgid(atol(sym->identifier));
+               if (gr == NULL)
+                       return error(&sym->location, "Group does not exist");
+       }
 
        *res = constant_expr_alloc(&sym->location, sym->dtype,
                                   BYTEORDER_HOST_ENDIAN,