eventlog: Fix CID 242105 Unchecked return value
[metze/samba/wip.git] / source3 / lib / eventlog / eventlog.c
index 67583b8666c03eae15add015d5b6f29b01836866..cc4573c869ceb4edc80ce94ee8ba2fc9e045b622 100644 (file)
@@ -73,7 +73,7 @@ char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
        char *file;
        char *tdbname;
 
-       path = talloc_strdup(ctx, state_path("eventlog"));
+       path = state_path("eventlog");
        if (!path) {
                return NULL;
        }
@@ -84,12 +84,13 @@ char *elog_tdbname(TALLOC_CTX *ctx, const char *name )
                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;
 }
 
@@ -203,7 +204,7 @@ static bool make_way_for_eventlogs( TDB_CONTEXT * the_tdb, int32_t needed,
                /* read a record, add the amt to nbytes */
                key.dsize = sizeof(int32_t);
                key.dptr = (unsigned char *)&i;
-               ret = tdb_fetch_compat( the_tdb, key );
+               ret = tdb_fetch( the_tdb, key );
                if ( ret.dsize == 0 ) {
                        DEBUG( 8,
                               ( "Can't find a record for the key, record [%d]\n",
@@ -340,6 +341,7 @@ ELOG_TDB *elog_open_tdb( const char *logname, bool force_clear, bool read_only )
        ELOG_TDB *tdb_node = NULL;
        char *eventlogdir;
        TALLOC_CTX *ctx = talloc_tos();
+       bool ok;
 
        /* check for invalid options */
 
@@ -371,9 +373,15 @@ ELOG_TDB *elog_open_tdb( const char *logname, bool force_clear, bool read_only )
 
        /* 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 */
 
@@ -578,7 +586,7 @@ bool parse_logentry( TALLOC_CTX *mem_ctx, char *line, struct eventlog_Record_tdb
                }
        } 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 */
@@ -679,7 +687,7 @@ struct eventlog_Record_tdb *evlog_pull_record_tdb(TALLOC_CTX *mem_ctx,
        key.dptr = (unsigned char *)&srecno;
        key.dsize = sizeof(int32_t);
 
-       data = tdb_fetch_compat(tdb, key);
+       data = tdb_fetch(tdb, key);
        if (data.dsize == 0) {
                DEBUG(8,("evlog_pull_record_tdb: "
                        "Can't find a record for the key, record %d\n",
@@ -958,7 +966,10 @@ NTSTATUS evlog_tdb_entry_to_evt_entry(TALLOC_CTX *mem_ctx,
                        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;
+                       }
                }
        }