nss: Don't stop parsing on unexpected key

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>
This commit is contained in:
Michal Privoznik 2019-08-09 10:25:22 +02:00
parent 0848af78ae
commit 8be0ab638d
3 changed files with 4 additions and 3 deletions

View 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
}
]

View 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;

View 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))))