*/
#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 */
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 = 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(ctx, "%s/%s", path, file);
+ if (!tdbname) {
+ talloc_free(path);
+ return NULL;
+ }
+
+ talloc_free(path);
+ return tdbname;
}
ELOG_TDB *tdb_node = NULL;
char *eventlogdir;
TALLOC_CTX *ctx = talloc_tos();
+ bool ok;
/* check for invalid options */
/* make sure that the eventlog dir exists */
- eventlogdir = state_path( "eventlog" );
- if ( !directory_exist( eventlogdir ) )
- mkdir( eventlogdir, 0755 );
+ eventlogdir = state_path("eventlog");
+ if (eventlogdir == NULL) {
+ return NULL;
+ }
+ ok = directory_create_or_exist(eventlogdir, 0755);
+ TALLOC_FREE(eventlogdir);
+ if (!ok) {
+ return NULL;
+ }
/* get the path on disk */
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;
}
} else if ( 0 == strncmp( start, "STR", stop - start ) ) {
size_t tmp_len;
- int num_of_strings;
+ size_t num_of_strings;
/* skip past initial ":" */
stop++;
/* now skip any other leading whitespace */
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)) {
return NULL;
}
- r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, NULL, 0);
+ r->Length = r->Length2 = ndr_size_EVENTLOGRECORD(r, 0);
return r;
}
/* lock */
ret = tdb_lock_bystring_with_timeout(tdb, EVT_NEXT_RECORD, 1);
- if (ret == -1) {
+ if (ret != 0) {
return NT_STATUS_LOCK_NOT_GRANTED;
}
/* 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);
ebuf.dptr = blob.data;
ret = tdb_store(tdb, kbuf, ebuf, 0);
- if (ret == -1) {
+ if (ret != 0) {
tdb_unlock_bystring(tdb, EVT_NEXT_RECORD);
return NT_STATUS_EVENTLOG_FILE_CORRUPT;
}
ret = tdb_store_int32(tdb, EVT_NEXT_RECORD, r->record_number + 1);
- if (ret == -1) {
+ if (ret != 0) {
tdb_unlock_bystring(tdb, EVT_NEXT_RECORD);
return NT_STATUS_EVENTLOG_FILE_CORRUPT;
}
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);
+ bool ok = string_to_sid(&e->UserSid, sid_str);
+ if (!ok) {
+ return NT_STATUS_INVALID_SID;
+ }
}
}
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++;
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);