mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 09:57:41 +00:00
Store mulitple command digests of the same type as an array.
Otherwise, we end up with duplicated keys in the object. GitHub issue #370
This commit is contained in:
parent
78699a8f7a
commit
c429220693
@ -31,6 +31,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <sudoers.h>
|
#include <sudoers.h>
|
||||||
|
#include <sudo_digest.h>
|
||||||
#include <sudo_json.h>
|
#include <sudo_json.h>
|
||||||
#include <cvtsudoers.h>
|
#include <cvtsudoers.h>
|
||||||
#include <gram.h>
|
#include <gram.h>
|
||||||
@ -67,6 +68,7 @@ print_command_json(struct json_container *jsonc, const char *name, bool negated)
|
|||||||
struct command_digest *digest;
|
struct command_digest *digest;
|
||||||
struct json_value value;
|
struct json_value value;
|
||||||
char *cmnd = c->cmnd;
|
char *cmnd = c->cmnd;
|
||||||
|
unsigned int digest_type;
|
||||||
const char *digest_name;
|
const char *digest_name;
|
||||||
debug_decl(print_command_json, SUDOERS_DEBUG_UTIL);
|
debug_decl(print_command_json, SUDOERS_DEBUG_UTIL);
|
||||||
|
|
||||||
@ -89,13 +91,36 @@ print_command_json(struct json_container *jsonc, const char *name, bool negated)
|
|||||||
if (!sudo_json_add_value(jsonc, "command", &value))
|
if (!sudo_json_add_value(jsonc, "command", &value))
|
||||||
debug_return_bool(false);
|
debug_return_bool(false);
|
||||||
|
|
||||||
/* Optional digest list. */
|
/* Optional digest list, ordered by digest type. */
|
||||||
TAILQ_FOREACH(digest, &c->digests, entries) {
|
for (digest_type = 0; digest_type < SUDO_DIGEST_INVALID; digest_type++) {
|
||||||
digest_name = digest_type_to_name(digest->digest_type);
|
unsigned int ndigests = 0;
|
||||||
value.type = JSON_STRING;
|
|
||||||
value.u.string = digest->digest_str;
|
TAILQ_FOREACH(digest, &c->digests, entries) {
|
||||||
if (!sudo_json_add_value(jsonc, digest_name, &value))
|
if (digest->digest_type == digest_type)
|
||||||
debug_return_bool(false);
|
ndigests++;
|
||||||
|
}
|
||||||
|
if (ndigests == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
digest_name = digest_type_to_name(digest_type);
|
||||||
|
if (ndigests > 1) {
|
||||||
|
if (!sudo_json_open_array(jsonc, digest_name))
|
||||||
|
debug_return_bool(false);
|
||||||
|
/* Only use digest_name for the array key, not value. */
|
||||||
|
digest_name = NULL;
|
||||||
|
}
|
||||||
|
TAILQ_FOREACH(digest, &c->digests, entries) {
|
||||||
|
if (digest->digest_type != digest_type)
|
||||||
|
continue;
|
||||||
|
value.type = JSON_STRING;
|
||||||
|
value.u.string = digest->digest_str;
|
||||||
|
if (!sudo_json_add_value(jsonc, digest_name, &value))
|
||||||
|
debug_return_bool(false);
|
||||||
|
}
|
||||||
|
if (ndigests > 1) {
|
||||||
|
if (!sudo_json_close_array(jsonc))
|
||||||
|
debug_return_bool(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Command may be negated. */
|
/* Command may be negated. */
|
||||||
|
@ -3,15 +3,19 @@
|
|||||||
"LS": [
|
"LS": [
|
||||||
{
|
{
|
||||||
"command": "/bin/ls",
|
"command": "/bin/ls",
|
||||||
"sha224": "d06a2617c98d377c250edd470fd5e576327748d82915d6e33b5f8db1",
|
"sha224": [
|
||||||
"sha224": "d7910e1967342b4605cb73a550944044c631cd3514001900966962ac"
|
"d06a2617c98d377c250edd470fd5e576327748d82915d6e33b5f8db1",
|
||||||
|
"d7910e1967342b4605cb73a550944044c631cd3514001900966962ac"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"SH": [
|
"SH": [
|
||||||
{
|
{
|
||||||
"command": "/bin/sh",
|
"command": "/bin/sh",
|
||||||
"sha256": "hOtoe/iK6SlGg7w4BfZBBdSsXjUmTJ5+ts51yjh7vkM=",
|
"sha256": [
|
||||||
"sha256": "1IXHRCxXgSnIEnb+xBz4PAfWaPdXIBWKFF0QCwxJ5G4="
|
"hOtoe/iK6SlGg7w4BfZBBdSsXjUmTJ5+ts51yjh7vkM=",
|
||||||
|
"1IXHRCxXgSnIEnb+xBz4PAfWaPdXIBWKFF0QCwxJ5G4="
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -51,8 +55,8 @@
|
|||||||
"Commands": [
|
"Commands": [
|
||||||
{
|
{
|
||||||
"command": "ALL",
|
"command": "ALL",
|
||||||
"sha384": "knMlCLkJ71K6uRrKo5C1CAvZ5kq+mRpjKDD/RofGosFjiGcYhiYYZORVyiRHgBnu",
|
"sha256": "1IXHRCxXgSnIEnb+xBz4PAfWaPdXIBWKFF0QCwxJ5G4=",
|
||||||
"sha256": "1IXHRCxXgSnIEnb+xBz4PAfWaPdXIBWKFF0QCwxJ5G4="
|
"sha384": "knMlCLkJ71K6uRrKo5C1CAvZ5kq+mRpjKDD/RofGosFjiGcYhiYYZORVyiRHgBnu"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user