Unverified Commit 6ef567d1 authored by Ph. Gesang's avatar Ph. Gesang 💾
Browse files

lib/audit_logging: add JSON object accessors

This adds a wrappers for libjansson routines to handle a greater
variety of data types:

        - json_has_key(),
        - json_assert_is_object(),

        - json_add_uint32(),
        - json_add_uint64(),
        - json_add_timespec(),
        - json_add_ntstatus(),
        - json_add_base64(),

        - json_get_int(),
        - json_get_string(),
        - json_get_sid(),
        - json_get_uint64_t(),
        - json_get_uint32_t(),
        - json_get_array_element(),
        - json_array_length(),
        - json_get_timespec(),
        - json_get_ntstatus(),
        - json_get_guid(), and
        - json_get_base64().

Also add helpers ``json_from_{string,FILEp}()`` for decoding JSON
from strings and file handles, respectively. The inputs may be
either JSON objects or arrays. Add a new constructor
``json_new_null()`` to make it more obvious that incoming JSON
values may be of any type.
Signed-off-by: Ph. Gesang's avatarPhilipp Gesang <philipp.gesang@intra2net.com>
parent 450f67ba
This diff is collapsed.
......@@ -22,6 +22,7 @@
#include "lib/messaging/irpc.h"
#include "lib/tsocket/tsocket.h"
#include "lib/util/attr.h"
#include "lib/util/data_blob.h"
_WARN_UNUSED_RESULT_ char *audit_get_timestamp(TALLOC_CTX *frame);
void audit_log_human_text(const char *prefix,
......@@ -52,13 +53,24 @@ void audit_message_send(struct imessaging_context *msg_ctx,
struct json_object *message);
_WARN_UNUSED_RESULT_ struct json_object json_new_object(void);
_WARN_UNUSED_RESULT_ struct json_object json_new_array(void);
_WARN_UNUSED_RESULT_ struct json_object json_new_null(void);
void json_free(struct json_object *object);
void json_assert_is_array(struct json_object *array);
void json_assert_is_object(struct json_object *object);
_WARN_UNUSED_RESULT_ bool json_is_invalid(const struct json_object *object);
_WARN_UNUSED_RESULT_ int json_add_int(struct json_object *object,
const char *name,
const int value);
_WARN_UNUSED_RESULT_ int json_add_uint64(struct json_object *object,
const char *name,
const uint64_t value);
_WARN_UNUSED_RESULT_ int json_add_uint32(struct json_object *object,
const char *name,
const uint32_t value);
_WARN_UNUSED_RESULT_ int json_add_timespec(struct json_object *object,
const char *name,
const struct timespec *ts);
_WARN_UNUSED_RESULT_ int json_add_bool(struct json_object *object,
const char *name,
const bool value);
......@@ -86,12 +98,55 @@ _WARN_UNUSED_RESULT_ int json_add_sid(struct json_object *object,
_WARN_UNUSED_RESULT_ int json_add_guid(struct json_object *object,
const char *name,
const struct GUID *guid);
_WARN_UNUSED_RESULT_ int json_add_base64(struct json_object *object,
const char *name,
const DATA_BLOB src);
_WARN_UNUSED_RESULT_ int json_get_int(const struct json_object *object,
const char *name, int *value);
_WARN_UNUSED_RESULT_ int json_get_uint64(const struct json_object *object,
const char *name, uint64_t *value);
_WARN_UNUSED_RESULT_ int json_get_uint32(const struct json_object *object,
const char *name, uint32_t *value);
_WARN_UNUSED_RESULT_ int json_get_timespec(const struct json_object *object,
const char *name,
struct timespec *ts);
_WARN_UNUSED_RESULT_ int json_get_string(TALLOC_CTX *ctx,
const struct json_object *object,
const char *name,
const char **value);
_WARN_UNUSED_RESULT_ int json_get_sid(const struct json_object *object,
const char *name,
struct dom_sid *sid);
_WARN_UNUSED_RESULT_ int json_get_guid(const struct json_object *object,
const char *name,
struct GUID *guid);
_WARN_UNUSED_RESULT_ int json_get_base64(TALLOC_CTX *ctx,
const struct json_object *object,
const char *name,
DATA_BLOB *dst);
_WARN_UNUSED_RESULT_ int json_add_ntstatus(struct json_object *object,
const char *name,
const NTSTATUS nt_code);
_WARN_UNUSED_RESULT_ int json_get_ntstatus(const struct json_object *object,
const char *name, NTSTATUS *nt_code);
_WARN_UNUSED_RESULT_ bool json_has_key(const struct json_object *object,
const char *name);
_WARN_UNUSED_RESULT_ struct json_object json_get_array(
struct json_object *object, const char *name);
_WARN_UNUSED_RESULT_ int json_array_length(const struct json_object *array,
size_t *len);
_WARN_UNUSED_RESULT_ int json_get_array_element(const struct json_object *array,
const size_t index,
struct json_object *element);
_WARN_UNUSED_RESULT_ struct json_object json_get_object(
struct json_object *object, const char *name);
_WARN_UNUSED_RESULT_ char *json_to_string(TALLOC_CTX *mem_ctx,
const struct json_object *object);
_WARN_UNUSED_RESULT_ int json_from_FILEp(struct json_object *dst, FILE *jsfh);
_WARN_UNUSED_RESULT_ int json_from_string(struct json_object *dst,
const char *jsdata);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment