s3:registry: move reg_objects.h to registry/ and use it only where needed
[kai/samba.git] / source3 / registry / reg_eventlog.c
index 4d395eddb10539df059673ba4056f425f74247e0..6bedf4635ebdc536a2db80cae9693f56b1b5ed4a 100644 (file)
  */
 
 #include "includes.h"
+#include "registry.h"
+#include "reg_backend_db.h"
+#include "reg_eventlog.h"
+#include "reg_objects.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_REGISTRY
@@ -87,7 +91,9 @@ bool eventlog_init_keys(void)
                TALLOC_FREE( subkeys );
 
                /* now add the values to the KEY_EVENTLOG/Application form key */
-               if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
+
+               werr = regval_ctr_init(ctx, &values);
+               if (!W_ERROR_IS_OK(werr)) {
                        DEBUG( 0, ( "talloc() failure!\n" ) );
                        return False;
                }
@@ -108,18 +114,18 @@ bool eventlog_init_keys(void)
                        uiRetention = 0x93A80;
 
                        regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
-                                            (char *)&uiMaxSize,
+                                            (uint8 *)&uiMaxSize,
                                             sizeof(uint32));
 
                        regval_ctr_addvalue(values, "Retention", REG_DWORD,
-                                            (char *)&uiRetention,
+                                            (uint8 *)&uiRetention,
                                             sizeof(uint32));
 
                        regval_ctr_addvalue_sz(values, "PrimaryModule", *elogs);
                        push_reg_sz(talloc_tos(), &data, *elogs);
 
                        regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
-                                            (char *)data.data,
+                                            data.data,
                                             data.length);
 
                        evtfilepath = talloc_asprintf(ctx,
@@ -129,7 +135,7 @@ bool eventlog_init_keys(void)
                                TALLOC_FREE(values);
                        }
                        push_reg_sz(talloc_tos(), &data, evtfilepath);
-                       regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, (char *)data.data,
+                       regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, data.data,
                                             data.length);
                        regdb_store_values(evtlogpath, values);
 
@@ -144,7 +150,9 @@ bool eventlog_init_keys(void)
                if (!evtlogpath) {
                        return false;
                }
-               if (!(values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
+
+               werr = regval_ctr_init(ctx, &values);
+               if (!W_ERROR_IS_OK(werr)) {
                        DEBUG( 0, ( "talloc() failure!\n" ) );
                        return False;
                }
@@ -159,14 +167,14 @@ bool eventlog_init_keys(void)
                        uiCategoryCount = 0x00000007;
                        regval_ctr_addvalue( values, "CategoryCount",
                                             REG_DWORD,
-                                            ( char * ) &uiCategoryCount,
+                                            (uint8 *) &uiCategoryCount,
                                             sizeof( uint32 ) );
                        push_reg_sz(talloc_tos(), &data,
                                      "%SystemRoot%\\system32\\eventlog.dll");
 
                        regval_ctr_addvalue( values, "CategoryMessageFile",
                                             REG_EXPAND_SZ,
-                                            ( char * ) data.data,
+                                            data.data,
                                             data.length);
                        regdb_store_values( evtlogpath, values );
                }
@@ -191,18 +199,18 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
           need to add KEY of source to KEY_EVENTLOG/<eventlog>/<source> */
 
        const char **elogs = lp_eventlog_list(  );
-       char **wrklist, **wp;
+       const char **wrklist, **wp;
        char *evtlogpath = NULL;
        struct regsubkey_ctr *subkeys;
        struct regval_ctr *values;
        struct regval_blob *rval;
-       uint16 *msz_wp;
-       int mbytes, ii;
+       int ii = 0;
        bool already_in;
        int i;
-       int numsources;
+       int numsources = 0;
        TALLOC_CTX *ctx = talloc_tos();
        WERROR werr;
+       DATA_BLOB blob;
 
        if (!elogs) {
                return False;
@@ -225,7 +233,8 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
 
        /* todo add to Sources */
 
-       if (!( values = TALLOC_ZERO_P(ctx, struct regval_ctr))) {
+       werr = regval_ctr_init(ctx, &values);
+       if(!W_ERROR_IS_OK(werr)) {
                DEBUG( 0, ( "talloc() failure!\n" ));
                return false;
        }
@@ -246,7 +255,7 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
        /* perhaps this adding a new string to a multi_sz should be a fn? */
        /* check to see if it's there already */
 
-       if ( rval->type != REG_MULTI_SZ ) {
+       if ( regval_type(rval) != REG_MULTI_SZ ) {
                DEBUG( 0,
                       ( "Wrong type for Sources, should be REG_MULTI_SZ\n" ) );
                return False;
@@ -255,16 +264,22 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
 
        already_in = False;
        wrklist = NULL;
-       dump_data( 1, rval->data_p, rval->size );
-       if ( ( numsources =
-              regval_convert_multi_sz( ( uint16 * ) rval->data_p, rval->size,
-                                       &wrklist ) ) > 0 ) {
+       dump_data(1, regval_data_p(rval), regval_size(rval));
+
+       blob = data_blob_const(regval_data_p(rval), regval_size(rval));
+       if (!pull_reg_multi_sz(talloc_tos(), &blob, &wrklist)) {
+               return false;
+       }
 
-               ii = numsources;
+       for (ii=0; wrklist[ii]; ii++) {
+               numsources++;
+       }
+
+       if (numsources > 0) {
                /* see if it's in there already */
                wp = wrklist;
 
-               while ( ii && wp && *wp ) {
+               while (wp && *wp ) {
                        if ( strequal( *wp, sourcename ) ) {
                                DEBUG( 5,
                                       ( "Source name [%s] already in list for [%s] \n",
@@ -273,13 +288,8 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
                                break;
                        }
                        wp++;
-                       ii--;
                }
        } else {
-               if ( numsources < 0 ) {
-                       DEBUG( 3, ( "problem in getting the sources\n" ) );
-                       return False;
-               }
                DEBUG( 3,
                       ( "Nothing in the sources list, this might be a problem\n" ) );
        }
@@ -288,7 +298,7 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
 
        if ( !already_in ) {
                /* make a new list with an additional entry; copy values, add another */
-               wp = TALLOC_ARRAY(ctx, char *, numsources + 2 );
+               wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 );
 
                if ( !wp ) {
                        DEBUG( 0, ( "talloc() failed \n" ) );
@@ -297,12 +307,14 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
                memcpy( wp, wrklist, sizeof( char * ) * numsources );
                *( wp + numsources ) = ( char * ) sourcename;
                *( wp + numsources + 1 ) = NULL;
-               mbytes = regval_build_multi_sz( wp, &msz_wp );
-               dump_data( 1, ( uint8 * ) msz_wp, mbytes );
+               if (!push_reg_multi_sz(ctx, &blob, wp)) {
+                       return false;
+               }
+               dump_data( 1, blob.data, blob.length);
                regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
-                                    ( char * ) msz_wp, mbytes );
+                                    blob.data, blob.length);
                regdb_store_values( evtlogpath, values );
-               TALLOC_FREE(msz_wp);
+               data_blob_free(&blob);
        } else {
                DEBUG( 3,
                       ( "Source name [%s] found in existing list of sources\n",
@@ -355,7 +367,8 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
        regdb_fetch_keys( evtlogpath, subkeys );
 
        /* now add the values to the KEY_EVENTLOG/Application form key */
-       if ( !( values = TALLOC_ZERO_P(ctx, struct regval_ctr ) ) ) {
+       werr = regval_ctr_init(ctx, &values);
+       if (!W_ERROR_IS_OK(werr)) {
                DEBUG( 0, ( "talloc() failure!\n" ) );
                return False;
        }