[libvirt] [PATCH 1/3] nss: Don't stop parsing on unexpected key

Michal Privoznik posted 3 patches 6 years, 6 months ago
[libvirt] [PATCH 1/3] nss: Don't stop parsing on unexpected key
Posted by Michal Privoznik 6 years, 6 months ago
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>
---
 tests/nssdata/virbr1.status    | 1 +
 tools/nss/libvirt_nss_leases.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/nssdata/virbr1.status b/tests/nssdata/virbr1.status
index 4951d4513e..f73c478be0 100644
--- a/tests/nssdata/virbr1.status
+++ b/tests/nssdata/virbr1.status
@@ -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
     }
 ]
diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c
index 86881641a9..577b5a2fd1 100644
--- a/tools/nss/libvirt_nss_leases.c
+++ b/tools/nss/libvirt_nss_leases.c
@@ -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;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] nss: Don't stop parsing on unexpected key
Posted by Daniel P. Berrangé 6 years, 6 months ago
On Fri, Aug 09, 2019 at 10:49:09AM +0200, Michal Privoznik wrote:
> 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>
> ---
>  tests/nssdata/virbr1.status    | 1 +
>  tools/nss/libvirt_nss_leases.c | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list