]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nss: Don't stop parsing on unexpected key
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Aug 2019 08:25:22 +0000 (10:25 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Aug 2019 10:17:19 +0000 (12:17 +0200)
Due to latest rewrite of NSS module, we are doing yajl parsing
ourselves. This means, we had to introduce couple of callback
that yajl calls. According to its documentation, a callback can
cancel parsing if it returns a zero value. Well, we do just that
in the string callback (findLeasesParserString()). If the JSON
file we are parsing contains a key that we are not interested in,
zero is returned meaning stop all parsing. This is not correct,
because the JSON file can contain some other keys which are not
harmful for our address translation (e.g. 'client-id').

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tests/nssdata/virbr1.status
tools/nss/libvirt_nss_leases.c
tools/nss/libvirt_nss_macs.c

index 4951d4513ef9a220bddd99f3b317cf38cb18677f..f73c478be0015c639c9871467c6275aa3daacb1b 100644 (file)
@@ -20,6 +20,7 @@
     {
         "ip-address": "192.168.122.3",
         "mac-address": "52:54:00:aa:bb:cc",
+        "client-id": "01:52:54:00:aa:bb:cc",
         "expiry-time": 2000000000
     }
 ]
index 86881641a9293df477855c808c206607bed12f04..577b5a2fd12e817cb4314015c4b8ba04cacb267f 100644 (file)
@@ -201,7 +201,7 @@ findLeasesParserString(void *ctx,
             if (!(parser->entry.hostname = strndup((char *)stringVal, stringLen)))
                 return 0;
         } else {
-            return 0;
+            return 1;
         }
     } else {
         return 0;
index 26ba4bf5158f2aca9de1c916eaf802109e31af56..ef14ef0a24217a5f367cde37e1e31f12811d1a0b 100644 (file)
@@ -68,7 +68,7 @@ findMACsParserString(void *ctx,
 
     if (parser->state == FIND_MACS_STATE_ENTRY) {
         if (strcmp(parser->key, "domain"))
-            return 0;
+            return 1;
 
         free(parser->entry.name);
         if (!(parser->entry.name = strndup((char *)stringVal, stringLen)))
@@ -76,7 +76,7 @@ findMACsParserString(void *ctx,
     } else if (parser->state == FIND_MACS_STATE_ENTRY_MACS) {
         char **macs;
         if (strcmp(parser->key, "macs"))
-            return 0;
+            return 1;
 
         if (!(macs = realloc(parser->entry.macs,
                              sizeof(char *) * (parser->entry.nmacs + 1))))