152b22ee9167891da02882b590c62c3e138757cc
[kai/samba-autobuild/.git] / lib / audit_logging / audit_logging.h
1 /*
2    common routines for audit logging
3
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <talloc.h>
21 #include "lib/messaging/irpc.h"
22 #include "lib/tsocket/tsocket.h"
23
24 char* audit_get_timestamp(TALLOC_CTX *frame);
25 void audit_log_human_text(const char *prefix,
26                           const char *message,
27                           int debug_class,
28                           int debug_level);
29
30 #ifdef HAVE_JANSSON
31 #include <jansson.h>
32 /*
33  * Wrapper for jannson JSON object
34  *
35  */
36 struct json_object {
37         json_t *root;
38         bool error;
39 };
40
41 void audit_log_json(const char *prefix,
42                     struct json_object *message,
43                     int debug_class,
44                     int debug_level);
45 void audit_message_send(struct imessaging_context *msg_ctx,
46                         const char *server_name,
47                         uint32_t message_type,
48                         struct json_object *message);
49 struct json_object json_new_object(void);
50 struct json_object json_new_array(void);
51 void json_free(struct json_object *object);
52 void json_assert_is_array(struct json_object *array);
53 bool json_is_invalid(struct json_object *object);
54
55 void json_add_int(
56         struct json_object *object,
57         const char* name,
58         const int value);
59 void json_add_bool(
60         struct json_object *object,
61         const char* name,
62         const bool value);
63 void json_add_string(
64         struct json_object *object,
65         const char* name,
66         const char* value);
67 void json_add_object(
68         struct json_object *object,
69         const char* name,
70         struct json_object *value);
71 void json_add_stringn(
72         struct json_object *object,
73         const char *name,
74         const char *value,
75         const size_t len);
76 void json_add_version(
77         struct json_object *object,
78         int major,
79         int minor);
80 void json_add_timestamp(struct json_object *object);
81 void json_add_address(
82         struct json_object *object,
83         const char *name,
84         const struct tsocket_address *address);
85 void json_add_sid(
86         struct json_object *object,
87         const char *name,
88         const struct dom_sid *sid);
89 void json_add_guid(
90         struct json_object *object,
91         const char *name,
92         const struct GUID *guid);
93
94 struct json_object json_get_array(struct json_object *object,
95                                   const char* name);
96 struct json_object json_get_object(struct json_object *object,
97                                    const char* name);
98 char *json_to_string(TALLOC_CTX *mem_ctx, struct json_object *object);
99 #endif