[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Fri Jun 1 09:11:03 UTC 2018


The branch, master has been updated
       via  d161aa3 ldb: Fix memory leak on module context
       via  0f5f8f1 lib/audit_logging: Remove #ifdef HAVE_JANSSON from audit_logging_test binary
       via  48ad90d lib/audit_logging: Make function prototypes look like the rest of Samba
       via  77e66b8 lib audit_logging: re-factor and add functions.
      from  7a0d82b s4-torture: add test for lease break after file unlink

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d161aa3522576545d269208426bb0014ee2ab35f
Author: Lukas Slebodnik <lslebodn at fedoraproject.org>
Date:   Sat Oct 21 15:09:01 2017 +0200

    ldb: Fix memory leak on module context
    
    Introduced in e8cdacc509016d9273d63faf334d9f827585c3eb
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13459
    
    Signed-off-by: Lukas Slebodnik <lslebodn at fedoraproject.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Fri Jun  1 11:10:24 CEST 2018 on sn-devel-144

commit 0f5f8f1312ee8c52d0a21f5435d92cc8543ef934
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Jun 1 06:42:24 2018 +1200

    lib/audit_logging: Remove #ifdef HAVE_JANSSON from audit_logging_test binary
    
    Instead, we either build or do not build the entire binary.
    
    This is much more likely to raise an error in make test if the build system
    changes.  The concern is that HAVE_JANSSON can go away and the tests just vanish.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>

commit 48ad90d93be8d863ce4c1be7cab6f1d60ed61257
Author: Andrew Bartlett <abartlet at samba.org>
Date:   Fri Jun 1 08:56:53 2018 +1200

    lib/audit_logging: Make function prototypes look like the rest of Samba
    
    The previous style is needed sometimes to avoid an 80-col limit, but
    is not how most of Samba looks.
    
    Signed-off-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Gary Lockyer <gary at catalyst.net.nz>

commit 77e66b86db606ff135c8c76a95c5576feec0fa51
Author: Gary Lockyer <gary at catalyst.net.nz>
Date:   Thu May 17 08:03:00 2018 +1200

    lib audit_logging: re-factor and add functions.
    
    Re-factor the common calls to json_dumps DEBUGC and audit_message_send
    into a separate function.
    Add functions to retrieve json object and json array elements
    
    Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 auth/auth_log.c                              |  22 +---
 lib/audit_logging/audit_logging.c            | 152 ++++++++++++++++++++++-----
 lib/audit_logging/audit_logging.h            |  92 ++++++++--------
 lib/audit_logging/tests/audit_logging_test.c | 141 ++++++++++++++++++++++++-
 lib/audit_logging/wscript_build              |  27 ++---
 lib/ldb/ldb_tdb/ldb_index.c                  |   4 +-
 6 files changed, 330 insertions(+), 108 deletions(-)


Changeset truncated at 500 lines:

diff --git a/auth/auth_log.c b/auth/auth_log.c
index 87daf2f..369a5c9 100644
--- a/auth/auth_log.c
+++ b/auth/auth_log.c
@@ -82,31 +82,13 @@ static void log_json(struct imessaging_context *msg_ctx,
 		     int debug_class,
 		     int debug_level)
 {
-	char* json = NULL;
-
-	if (object->error) {
-		return;
-	}
-
-	json = json_dumps(object->root, 0);
-	if (json == NULL) {
-		DBG_ERR("Unable to convert JSON object to string\n");
-		object->error = true;
-		return;
-	}
-
-	DEBUGC(debug_class, debug_level, ("JSON %s: %s\n", type, json));
+	audit_log_json(type, object, debug_class, debug_level);
 	if (msg_ctx && lp_ctx && lpcfg_auth_event_notification(lp_ctx)) {
 		audit_message_send(msg_ctx,
 				   AUTH_EVENT_NAME,
 				   MSG_AUTH_LOG,
-				   json);
-	}
-
-	if (json) {
-		free(json);
+				   object);
 	}
-
 }
 
 /*
diff --git a/lib/audit_logging/audit_logging.c b/lib/audit_logging/audit_logging.c
index 5c16806..13ff345 100644
--- a/lib/audit_logging/audit_logging.c
+++ b/lib/audit_logging/audit_logging.c
@@ -102,9 +102,45 @@ char* audit_get_timestamp(TALLOC_CTX *frame)
 	return ts;
 }
 
-#ifdef HAVE_JANSSON
+/*
+ * @brief write an audit message to the audit logs.
+ *
+ * Write a human readable text audit message to the samba logs.
+ *
+ * @param prefix Text to be printed at the start of the log line
+ * @param message The content of the log line.
+ * @param debub_class The debug class to log the message with.
+ * @param debug_level The debug level to log the message with.
+ */
+void audit_log_human_text(const char* prefix,
+			  const char* message,
+			  int debug_class,
+			  int debug_level)
+{
+	DEBUGC(debug_class, debug_level, ("%s %s\n", prefix, message));
+}
 
-#include "system/time.h"
+#ifdef HAVE_JANSSON
+/*
+ * @brief write a json object to the samba audit logs.
+ *
+ * Write the json object to the audit logs as a formatted string
+ *
+ * @param prefix Text to be printed at the start of the log line
+ * @param message The content of the log line.
+ * @param debub_class The debug class to log the message with.
+ * @param debug_level The debug level to log the message with.
+ */
+void audit_log_json(const char* prefix,
+		    struct json_object* message,
+		    int debug_class,
+		    int debug_level)
+{
+	TALLOC_CTX *ctx = talloc_new(NULL);
+	char *s = json_to_string(ctx, message);
+	DEBUGC(debug_class, debug_level, ("JSON %s: %s\n", prefix, s));
+	TALLOC_FREE(ctx);
+}
 
 /*
  * @brief get a connection to the messaging event server.
@@ -192,14 +228,18 @@ void audit_message_send(
 	struct imessaging_context *msg_ctx,
 	const char *server_name,
 	uint32_t message_type,
-	const char *message)
+	struct json_object *message)
 {
 	struct server_id event_server;
 	NTSTATUS status;
-	DATA_BLOB message_blob = data_blob_string_const(message);
+
+	const char *message_string = NULL;
+	DATA_BLOB message_blob = data_blob_null;
+	TALLOC_CTX *ctx = talloc_new(NULL);
 
 	if (msg_ctx == NULL) {
 		DBG_DEBUG("No messaging context\n");
+		TALLOC_FREE(ctx);
 		return;
 	}
 
@@ -213,9 +253,12 @@ void audit_message_send(
 		DBG_ERR("get_event_server for %s returned (%s)\n",
 			server_name,
 			nt_errstr(status));
+		TALLOC_FREE(ctx);
 		return;
 	}
 
+	message_string = json_to_string(ctx, message);
+	message_blob = data_blob_string_const(message_string);
 	status = imessaging_send(
 		msg_ctx,
 		event_server,
@@ -232,6 +275,7 @@ void audit_message_send(
 			DBG_ERR("get_event_server for %s returned (%s)\n",
 				server_name,
 				nt_errstr(status));
+			TALLOC_FREE(ctx);
 			return;
 		}
 		imessaging_send(
@@ -240,6 +284,7 @@ void audit_message_send(
 			message_type,
 			&message_blob);
 	}
+	TALLOC_FREE(ctx);
 }
 
 /*
@@ -450,8 +495,8 @@ void json_assert_is_array(struct json_object *array) {
  *
  */
 void json_add_object(struct json_object *object,
-		const char* name,
-		struct json_object *value)
+		     const char* name,
+		     struct json_object *value)
 {
 	int rc = 0;
 	json_t *jv = NULL;
@@ -497,11 +542,10 @@ void json_add_object(struct json_object *object,
  * @param len the maximum number of characters to be copied.
  *
  */
-void json_add_stringn(
-	struct json_object *object,
-	const char *name,
-	const char *value,
-	const size_t len)
+void json_add_stringn(struct json_object *object,
+		      const char *name,
+		      const char *value,
+		      const size_t len)
 {
 
 	int rc = 0;
@@ -622,10 +666,9 @@ void json_add_timestamp(struct json_object *object)
  * @param address the tsocket_address.
  *
  */
-void json_add_address(
-	struct json_object *object,
-	const char *name,
-	const struct tsocket_address *address)
+void json_add_address(struct json_object *object,
+		      const char *name,
+		      const struct tsocket_address *address)
 {
 
 	if (object->error) {
@@ -661,10 +704,9 @@ void json_add_address(
  * @param sid the sid
  *
  */
-void json_add_sid(
-	struct json_object *object,
-	const char *name,
-	const struct dom_sid *sid)
+void json_add_sid(struct json_object *object,
+		  const char *name,
+		  const struct dom_sid *sid)
 {
 
 	if (object->error) {
@@ -699,10 +741,9 @@ void json_add_sid(
  *
  *
  */
-void json_add_guid(
-	struct json_object *object,
-	const char *name,
-	const struct GUID *guid)
+void json_add_guid(struct json_object *object,
+		   const char *name,
+		   const struct GUID *guid)
 {
 
 
@@ -739,7 +780,8 @@ void json_add_guid(
  * @return A string representation of the object or NULL if the object
  *         is invalid.
  */
-char *json_to_string(TALLOC_CTX *mem_ctx, struct json_object *object)
+char *json_to_string(TALLOC_CTX *mem_ctx,
+		     struct json_object *object)
 {
 	char *json = NULL;
 	char *json_string = NULL;
@@ -768,4 +810,66 @@ char *json_to_string(TALLOC_CTX *mem_ctx, struct json_object *object)
 
 	return json_string;
 }
+
+/*
+ * @brief get a json array named "name" from the json object.
+ *
+ * Get the array attribute named name, creating it if it does not exist.
+ *
+ * @param object the json object.
+ * @param name the name of the array attribute
+ *
+ * @return The array object, will be created if it did not exist.
+ */
+struct json_object json_get_array(struct json_object *object,
+				  const char* name)
+{
+
+	struct json_object array = json_new_array();
+	json_t *a = NULL;
+
+	if (object->error) {
+		array.error = true;
+		return array;
+	}
+
+	a = json_object_get(object->root, name);
+	if (a == NULL) {
+		return array;
+	}
+	json_array_extend(array.root, a);
+
+	return array;
+}
+
+/*
+ * @brief get a json object named "name" from the json object.
+ *
+ * Get the object attribute named name, creating it if it does not exist.
+ *
+ * @param object the json object.
+ * @param name the name of the object attribute
+ *
+ * @return The object, will be created if it did not exist.
+ */
+struct json_object json_get_object(struct json_object *object,
+				   const char* name)
+{
+
+	struct json_object o = json_new_object();
+	json_t *v = NULL;
+
+	if (object->error) {
+		o.error = true;
+		return o;
+	}
+
+	v = json_object_get(object->root, name);
+	if (v == NULL) {
+		return o;
+	}
+	json_object_update(o.root, v);
+
+	return o;
+}
 #endif
diff --git a/lib/audit_logging/audit_logging.h b/lib/audit_logging/audit_logging.h
index 763f3ed..4af743a 100644
--- a/lib/audit_logging/audit_logging.h
+++ b/lib/audit_logging/audit_logging.h
@@ -21,14 +21,12 @@
 #include "lib/messaging/irpc.h"
 #include "lib/tsocket/tsocket.h"
 
-char* audit_get_timestamp(
-	TALLOC_CTX *frame);
+char* audit_get_timestamp(TALLOC_CTX *frame);
+void audit_log_human_text(const char *prefix,
+			  const char *message,
+			  int debug_class,
+			  int debug_level);
 
-void audit_message_send(
-	struct imessaging_context *msg_ctx,
-	const char *server_name,
-	uint32_t message_type,
-	const char *message);
 #ifdef HAVE_JANSSON
 #include <jansson.h>
 /*
@@ -40,50 +38,54 @@ struct json_object {
 	bool error;
 };
 
+void audit_log_json(const char *prefix,
+		    struct json_object *message,
+		    int debug_class,
+		    int debug_level);
+void audit_message_send(struct imessaging_context *msg_ctx,
+			const char *server_name,
+			uint32_t message_type,
+			struct json_object *message);
 struct json_object json_new_object(void);
 struct json_object json_new_array(void);
 void json_free(struct json_object *object);
 void json_assert_is_array(struct json_object *array);
 bool json_is_invalid(struct json_object *object);
 
-void json_add_int(
-	struct json_object *object,
-	const char* name,
-	const int value);
-void json_add_bool(
-	struct json_object *object,
-	const char* name,
-	const bool value);
-void json_add_string(
-	struct json_object *object,
-	const char* name,
-	const char* value);
-void json_add_object(
-	struct json_object *object,
-	const char* name,
-	struct json_object *value);
-void json_add_stringn(
-	struct json_object *object,
-	const char *name,
-	const char *value,
-	const size_t len);
-void json_add_version(
-	struct json_object *object,
-	int major,
-	int minor);
+void json_add_int(struct json_object *object,
+		  const char* name,
+		  const int value);
+void json_add_bool(struct json_object *object,
+		   const char* name,
+		   const bool value);
+void json_add_string(struct json_object *object,
+		     const char* name,
+		     const char* value);
+void json_add_object(struct json_object *object,
+		     const char* name,
+		     struct json_object *value);
+void json_add_stringn(struct json_object *object,
+		      const char *name,
+		      const char *value,
+		      const size_t len);
+void json_add_version(struct json_object *object,
+		      int major,
+		      int minor);
 void json_add_timestamp(struct json_object *object);
-void json_add_address(
-	struct json_object *object,
-	const char *name,
-	const struct tsocket_address *address);
-void json_add_sid(
-	struct json_object *object,
-	const char *name,
-	const struct dom_sid *sid);
-void json_add_guid(
-	struct json_object *object,
-	const char *name,
-	const struct GUID *guid);
+void json_add_address(struct json_object *object,
+		      const char *name,
+		      const struct tsocket_address *address);
+void json_add_sid(struct json_object *object,
+		  const char *name,
+		  const struct dom_sid *sid);
+void json_add_guid(struct json_object *object,
+		   const char *name,
+		   const struct GUID *guid);
 
-char *json_to_string(TALLOC_CTX *mem_ctx, struct json_object *object);
+struct json_object json_get_array(struct json_object *object,
+				  const char* name);
+struct json_object json_get_object(struct json_object *object,
+				   const char* name);
+char *json_to_string(TALLOC_CTX *mem_ctx,
+		     struct json_object *object);
 #endif
diff --git a/lib/audit_logging/tests/audit_logging_test.c b/lib/audit_logging/tests/audit_logging_test.c
index 8385e9c..6be71f3 100644
--- a/lib/audit_logging/tests/audit_logging_test.c
+++ b/lib/audit_logging/tests/audit_logging_test.c
@@ -59,7 +59,6 @@
 
 #include "lib/audit_logging/audit_logging.h"
 
-#ifdef HAVE_JANSSON
 static void test_json_add_int(void **state)
 {
 	struct json_object object;
@@ -490,7 +489,141 @@ static void test_json_to_string(void **state)
 	json_free(&object);
 	TALLOC_FREE(ctx);
 }
-#endif
+
+static void test_json_get_array(void **state)
+{
+	struct json_object object;
+	struct json_object array;
+	struct json_object stored_array = json_new_array();
+	json_t *value = NULL;
+	json_t *o = NULL;
+	struct json_object o1;
+	struct json_object o2;
+
+	object = json_new_object();
+
+	array = json_get_array(&object, "not-there");
+	assert_false(array.error);
+	assert_non_null(array.root);
+	assert_true(json_is_array(array.root));
+	json_free(&array);
+
+	o1 = json_new_object();
+	json_add_string(&o1, "value", "value-one");
+	json_add_object(&stored_array, NULL, &o1);
+	json_add_object(&object, "stored_array", &stored_array);
+
+	array = json_get_array(&object, "stored_array");
+	assert_false(array.error);
+	assert_non_null(array.root);
+	assert_true(json_is_array(array.root));
+
+	assert_int_equal(1, json_array_size(array.root));
+
+	o = json_array_get(array.root, 0);
+	assert_non_null(o);
+	assert_true(json_is_object(o));
+
+	value = json_object_get(o, "value");
+	assert_non_null(value);
+	assert_true(json_is_string(value));
+
+	assert_string_equal("value-one", json_string_value(value));
+	json_free(&array);
+
+	/*
+	 * Now update the array and add it back to the object
+	 */
+	array = json_get_array(&object, "stored_array");
+	assert_true(json_is_array(array.root));
+	o2 = json_new_object();
+	json_add_string(&o2, "value", "value-two");
+	assert_false(o2.error);
+	json_add_object(&array, NULL, &o2);
+	assert_true(json_is_array(array.root));
+	json_add_object(&object, "stored_array", &array);
+	assert_true(json_is_array(array.root));
+
+	array = json_get_array(&object, "stored_array");
+	assert_non_null(array.root);
+	assert_true(json_is_array(array.root));
+	assert_false(array.error);
+	assert_true(json_is_array(array.root));
+
+	assert_int_equal(2, json_array_size(array.root));
+
+	o = json_array_get(array.root, 0);
+	assert_non_null(o);
+	assert_true(json_is_object(o));
+
+	assert_non_null(value);
+	assert_true(json_is_string(value));
+
+	assert_string_equal("value-one", json_string_value(value));
+
+	o = json_array_get(array.root, 1);
+	assert_non_null(o);
+	assert_true(json_is_object(o));
+
+	value = json_object_get(o, "value");
+	assert_non_null(value);
+	assert_true(json_is_string(value));
+


-- 
Samba Shared Repository



More information about the samba-cvs mailing list