dsdb:audit_log: avoid printing "... remote host [Unknown] SID [(NULL SID)] ..."
[metze/samba/wip.git] / source4 / dsdb / samdb / ldb_modules / audit_log.c
index 5d6ebc1e16539cbb8c2dc48997f97a88a0526995..ef674950100883f2aa26ec027bd098d4dd2bb300 100644 (file)
@@ -778,7 +778,7 @@ static char *password_change_human_readable(
        struct ldb_context *ldb = NULL;
        const char *remote_host = NULL;
        const struct dom_sid *sid = NULL;
-       const char *user_sid = NULL;
+       struct dom_sid_buf user_sid;
        const char *timestamp = NULL;
        char *log_entry = NULL;
        const char *action = NULL;
@@ -790,7 +790,6 @@ static char *password_change_human_readable(
 
        remote_host = dsdb_audit_get_remote_host(ldb, ctx);
        sid = dsdb_audit_get_user_sid(module);
-       user_sid = dom_sid_string(ctx, sid);
        timestamp = audit_get_timestamp(ctx);
        action = get_password_action(request, reply);
        dn = dsdb_audit_get_primary_dn(request);
@@ -803,7 +802,7 @@ static char *password_change_human_readable(
                timestamp,
                ldb_strerror(reply->error),
                remote_host,
-               user_sid,
+               dom_sid_str_buf(sid, &user_sid),
                dn);
        TALLOC_FREE(ctx);
        return log_entry;
@@ -829,7 +828,7 @@ static char *log_attributes(
        enum ldb_request_type operation,
        const struct ldb_message *message)
 {
-       int i, j;
+       size_t i, j;
        for (i=0;i<message->num_elements;i++) {
                if (i > 0) {
                        buffer = talloc_asprintf_append_buffer(buffer, " ");
@@ -840,7 +839,7 @@ static char *log_attributes(
                                ldb,
                                LDB_DEBUG_ERROR,
                                "Error: Invalid element name (NULL) at "
-                               "position %d", i);
+                               "position %zu", i);
                        return NULL;
                }
 
@@ -874,7 +873,7 @@ static char *log_attributes(
                for (j=0;j<message->elements[i].num_values;j++) {
                        struct ldb_val v;
                        bool use_b64_encode = false;
-                       int length;
+                       size_t length;
                        if (j > 0) {
                                buffer = talloc_asprintf_append_buffer(
                                        buffer,
@@ -898,8 +897,8 @@ static char *log_attributes(
                                buffer = talloc_asprintf_append_buffer(
                                        buffer,
                                        "[%*.*s%s]",
-                                       length,
-                                       length,
+                                       (int)length,
+                                       (int)length,
                                        (char *)v.data,
                                        (v.length > MAX_LENGTH ? "..." : ""));
                        }
@@ -929,8 +928,9 @@ static char *operation_human_readable(
 {
        struct ldb_context *ldb = NULL;
        const char *remote_host = NULL;
+       const struct tsocket_address *remote = NULL;
        const struct dom_sid *sid = NULL;
-       const char *user_sid = NULL;
+       struct dom_sid_buf user_sid;
        const char *timestamp = NULL;
        const char *op_name = NULL;
        char *log_entry = NULL;
@@ -943,12 +943,12 @@ static char *operation_human_readable(
        ldb = ldb_module_get_ctx(module);
 
        remote_host = dsdb_audit_get_remote_host(ldb, ctx);
-       if (remote_host != NULL && dsdb_audit_is_system_session(module)) {
+       remote = dsdb_audit_get_remote_address(ldb);
+       if (remote != NULL && dsdb_audit_is_system_session(module)) {
                sid = dsdb_audit_get_actual_sid(ldb);
        } else {
                sid = dsdb_audit_get_user_sid(module);
        }
-       user_sid = dom_sid_string(ctx, sid);
        timestamp = audit_get_timestamp(ctx);
        op_name = dsdb_audit_get_operation_name(request);
        dn = dsdb_audit_get_primary_dn(request);
@@ -964,7 +964,7 @@ static char *operation_human_readable(
                timestamp,
                ldb_strerror(reply->error),
                remote_host,
-               user_sid,
+               dom_sid_str_buf(sid, &user_sid),
                dn);
        if (new_dn != NULL) {
                log_entry = talloc_asprintf_append_buffer(