s3-talloc Change TALLOC_ZERO_P() to talloc_zero()
[nivanova/samba-autobuild/.git] / source3 / lib / eventlog / eventlog.c
index 11cb28a1203c58dd50ad4fec31af456432cc48f3..556938fe1d07f6edb1835737d14adbbb8c67dd19 100644 (file)
  */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "lib/eventlog/eventlog.h"
+#include "../libcli/security/security.h"
+#include "util_tdb.h"
 
 /* maintain a list of open eventlog tdbs with reference counts */
 
@@ -65,14 +69,28 @@ TDB_CONTEXT *elog_init_tdb( char *tdbfilename )
 
 char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
 {
-       char *path = talloc_asprintf(ctx, "%s/%s.tdb",
-                       state_path("eventlog"),
-                       name);
+       char *path;
+       char *file;
+       char *tdbname;
+
+       path = talloc_strdup(ctx, state_path("eventlog"));
        if (!path) {
                return NULL;
        }
-       strlower_m(path);
-       return path;
+
+       file = talloc_asprintf_strlower_m(path, "%s.tdb", name);
+       if (!file) {
+               talloc_free(path);
+               return NULL;
+       }
+
+       tdbname = talloc_asprintf(path, "%s/%s", state_path("eventlog"), file);
+       if (!tdbname) {
+               talloc_free(path);
+               return NULL;
+       }
+
+       return tdbname;
 }
 
 
@@ -398,7 +416,7 @@ ELOG_TDB *elog_open_tdb( const char *logname, bool force_clear, bool read_only )
                        return ptr;
                }
 
-               if ( !(tdb_node = TALLOC_ZERO_P( NULL, ELOG_TDB)) ) {
+               if ( !(tdb_node = talloc_zero( NULL, ELOG_TDB)) ) {
                        DEBUG(0,("elog_open_tdb: talloc() failure!\n"));
                        tdb_close( tdb );
                        return NULL;
@@ -676,7 +694,7 @@ struct eventlog_Record_tdb *evlog_pull_record_tdb(TALLOC_CTX *mem_ctx,
 
        blob = data_blob_const(data.dptr, data.dsize);
 
-       ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, r,
+       ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, r,
                           (ndr_pull_flags_fn_t)ndr_pull_eventlog_Record_tdb);
 
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
@@ -726,7 +744,7 @@ struct EVENTLOGRECORD *evlog_pull_record(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, NULL, 0);
+       r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, 0);
 
        return r;
 }
@@ -770,7 +788,7 @@ NTSTATUS evlog_push_record_tdb(TALLOC_CTX *mem_ctx,
        /* read */
        r->record_number = tdb_fetch_int32(tdb, EVT_NEXT_RECORD);
 
-       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, r,
+       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, r,
                      (ndr_push_flags_fn_t)ndr_push_eventlog_Record_tdb);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                tdb_unlock_bystring(tdb, EVT_NEXT_RECORD);
@@ -936,11 +954,11 @@ NTSTATUS evlog_tdb_entry_to_evt_entry(TALLOC_CTX *mem_ctx,
                size_t len;
                if (!convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX,
                                           t->sid.data, t->sid.length,
-                                          (void **)&sid_str, &len, false)) {
+                                          (void *)&sid_str, &len)) {
                        return NT_STATUS_INVALID_SID;
                }
                if (len > 0) {
-                       e->UserSid = *string_sid_talloc(mem_ctx, sid_str);
+                       string_to_sid(&e->UserSid, sid_str);
                }
        }
 
@@ -992,7 +1010,7 @@ NTSTATUS evlog_convert_tdb_to_evt(TALLOC_CTX *mem_ctx,
                        goto done;
                }
 
-               endoffset += ndr_size_EVENTLOGRECORD(&e, NULL, 0);
+               endoffset += ndr_size_EVENTLOGRECORD(&e, 0);
 
                ADD_TO_ARRAY(mem_ctx, struct EVENTLOGRECORD, e, &evt.records, &num_records);
                count++;
@@ -1019,7 +1037,7 @@ NTSTATUS evlog_convert_tdb_to_evt(TALLOC_CTX *mem_ctx,
                NDR_PRINT_DEBUG(EVENTLOGEOF, &evt.eof);
        }
 
-       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, &evt,
+       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &evt,
                   (ndr_push_flags_fn_t)ndr_push_EVENTLOG_EVT_FILE);
        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                status = ndr_map_error2ntstatus(ndr_err);