*/
#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 *file;
char *tdbname;
- path = talloc_strdup(ctx, state_path("eventlog"));
+ path = state_path("eventlog");
if (!path) {
return NULL;
}
return NULL;
}
- tdbname = talloc_asprintf(path, "%s/%s", state_path("eventlog"), file);
+ 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 */
/* lock */
ret = tdb_lock_bystring_with_timeout(tdb, EVT_NEXT_RECORD, 1);
- if (ret == -1) {
+ if (ret != 0) {
return NT_STATUS_LOCK_NOT_GRANTED;
}
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;
}
NT_STATUS_HAVE_NO_MEMORY(e->Computername);
if (t->sid_length > 0) {
- const char *sid_str = NULL;
+ char *sid_str = NULL;
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) {
- string_to_sid(&e->UserSid, sid_str);
+ bool ok = string_to_sid(&e->UserSid, sid_str);
+ if (!ok) {
+ return NT_STATUS_INVALID_SID;
+ }
}
+ TALLOC_FREE(sid_str);
}
e->Strings = talloc_array(mem_ctx, const char *, t->num_of_strings);