Remove pstrings from nsswitch/ and registry/
[kai/samba.git] / source3 / registry / reg_eventlog.c
index a9369b9ddfee736bc5d532635a5204ff2f736af0..be47d131407533b517d3a6b3eff35de6cd59bd71 100644 (file)
  for an eventlog, add in the default values
 *********************************************************************/
 
-bool eventlog_init_keys( void )
+bool eventlog_init_keys(void)
 {
        /* Find all of the eventlogs, add keys for each of them */
-       const char **elogs = lp_eventlog_list(  );
-       pstring evtlogpath;
-       pstring evtfilepath;
+       const char **elogs = lp_eventlog_list();
+       char *evtlogpath = NULL;
+       char *evtfilepath = NULL;
        REGSUBKEY_CTR *subkeys;
        REGVAL_CTR *values;
        uint32 uiMaxSize;
        uint32 uiRetention;
        uint32 uiCategoryCount;
        UNISTR2 data;
+       TALLOC_CTX *ctx = talloc_tos();
 
-       while ( elogs && *elogs ) {
-               if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
+       while (elogs && *elogs) {
+               if (!(subkeys = TALLOC_ZERO_P(ctx, REGSUBKEY_CTR ) ) ) {
                        DEBUG( 0, ( "talloc() failure!\n" ) );
                        return False;
                }
-               regdb_fetch_keys( KEY_EVENTLOG, subkeys );
+               regdb_fetch_keys(KEY_EVENTLOG, subkeys);
                regsubkey_ctr_addkey( subkeys, *elogs );
                if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) ) {
                        TALLOC_FREE(subkeys);
                        return False;
                }
-               TALLOC_FREE( subkeys );
+               TALLOC_FREE(subkeys);
 
                /* add in the key of form KEY_EVENTLOG/Application */
                DEBUG( 5,
                       ( "Adding key of [%s] to path of [%s]\n", *elogs,
                         KEY_EVENTLOG ) );
 
-               slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s",
-                         KEY_EVENTLOG, *elogs );
+               evtlogpath = talloc_asprintf(ctx, "%s\\%s",
+                         KEY_EVENTLOG, *elogs);
+               if (!evtlogpath) {
+                       return false;
+               }
                /* add in the key of form KEY_EVENTLOG/Application/Application */
                DEBUG( 5,
                       ( "Adding key of [%s] to path of [%s]\n", *elogs,
                         evtlogpath ) );
-               if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
+               if (!(subkeys = TALLOC_ZERO_P(ctx, REGSUBKEY_CTR))) {
                        DEBUG( 0, ( "talloc() failure!\n" ) );
                        return False;
                }
@@ -80,7 +84,7 @@ bool eventlog_init_keys( void )
                TALLOC_FREE( subkeys );
 
                /* now add the values to the KEY_EVENTLOG/Application form key */
-               if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
+               if (!(values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
                        DEBUG( 0, ( "talloc() failure!\n" ) );
                        return False;
                }
@@ -90,7 +94,7 @@ bool eventlog_init_keys( void )
                regdb_fetch_values( evtlogpath, values );
 
 
-               if ( !regval_ctr_key_exists( values, "MaxSize" ) ) {
+               if (!regval_ctr_key_exists(values, "MaxSize")) {
 
                        /* assume we have none, add them all */
 
@@ -100,48 +104,57 @@ bool eventlog_init_keys( void )
                        uiMaxSize = 0x00080000;
                        uiRetention = 0x93A80;
 
-                       regval_ctr_addvalue( values, "MaxSize", REG_DWORD,
-                                            ( char * ) &uiMaxSize,
-                                            sizeof( uint32 ) );
+                       regval_ctr_addvalue(values, "MaxSize", REG_DWORD,
+                                            (char *)&uiMaxSize,
+                                            sizeof(uint32));
 
-                       regval_ctr_addvalue( values, "Retention", REG_DWORD,
-                                            ( char * ) &uiRetention,
-                                            sizeof( uint32 ) );
-                       init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
+                       regval_ctr_addvalue(values, "Retention", REG_DWORD,
+                                            (char *)&uiRetention,
+                                            sizeof(uint32));
+                       init_unistr2(&data, *elogs, UNI_STR_TERMINATE);
 
-                       regval_ctr_addvalue( values, "PrimaryModule", REG_SZ,
-                                            ( char * ) data.buffer,
+                       regval_ctr_addvalue(values, "PrimaryModule", REG_SZ,
+                                            (char *)data.buffer,
                                             data.uni_str_len *
-                                            sizeof( uint16 ) );
-                       init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
+                                            sizeof(uint16));
+                       init_unistr2(&data, *elogs, UNI_STR_TERMINATE);
 
-                       regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
-                                            ( char * ) data.buffer,
+                       regval_ctr_addvalue(values, "Sources", REG_MULTI_SZ,
+                                            (char *)data.buffer,
                                             data.uni_str_len *
-                                            sizeof( uint16 ) );
+                                            sizeof(uint16));
 
-                       pstr_sprintf( evtfilepath, "%%SystemRoot%%\\system32\\config\\%s.tdb", *elogs );
-                       init_unistr2( &data, evtfilepath, UNI_STR_TERMINATE );
-                       regval_ctr_addvalue( values, "File", REG_EXPAND_SZ, ( char * ) data.buffer,
-                                            data.uni_str_len * sizeof( uint16 ) );
-                       regdb_store_values( evtlogpath, values );
+                       evtfilepath = talloc_asprintf(ctx,
+                                       "%%SystemRoot%%\\system32\\config\\%s.tdb",
+                                       *elogs);
+                       if (!evtfilepath) {
+                               TALLOC_FREE(values);
+                       }
+                       init_unistr2(&data, evtfilepath, UNI_STR_TERMINATE);
+                       regval_ctr_addvalue(values, "File", REG_EXPAND_SZ, (char *)data.buffer,
+                                            data.uni_str_len * sizeof(uint16));
+                       regdb_store_values(evtlogpath, values);
 
                }
 
-               TALLOC_FREE( values );
+               TALLOC_FREE(values);
 
                /* now do the values under KEY_EVENTLOG/Application/Application */
-               slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s",
-                         KEY_EVENTLOG, *elogs, *elogs );
-               if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
+               TALLOC_FREE(evtlogpath);
+               evtlogpath = talloc_asprintf("%s\\%s\\%s",
+                         KEY_EVENTLOG, *elogs, *elogs);
+               if (!evtlogpath) {
+                       return false;
+               }
+               if (!(values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
                        DEBUG( 0, ( "talloc() failure!\n" ) );
                        return False;
                }
                DEBUG( 5,
                       ( "Storing values to eventlog path of [%s]\n",
-                        evtlogpath ) );
-               regdb_fetch_values( evtlogpath, values );
-               if ( !regval_ctr_key_exists( values, "CategoryCount" ) ) {
+                        evtlogpath));
+               regdb_fetch_values(evtlogpath, values);
+               if (!regval_ctr_key_exists( values, "CategoryCount")) {
 
                        /* hard code some initial values */
 
@@ -161,17 +174,16 @@ bool eventlog_init_keys( void )
                                             sizeof( uint16 ) );
                        regdb_store_values( evtlogpath, values );
                }
-               TALLOC_FREE( values );
+               TALLOC_FREE(values);
                elogs++;
        }
 
-       return True;
-
+       return true;
 }
 
 /*********************************************************************
- for an eventlog, add in a source name. If the eventlog doesn't 
- exist (not in the list) do nothing.   If a source for the log 
+ for an eventlog, add in a source name. If the eventlog doesn't
+ exist (not in the list) do nothing.   If a source for the log
  already exists, change the information (remove, replace)
 *********************************************************************/
 
@@ -184,7 +196,7 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
 
        const char **elogs = lp_eventlog_list(  );
        char **wrklist, **wp;
-       pstring evtlogpath;
+       char *evtlogpath = NULL;
        REGSUBKEY_CTR *subkeys;
        REGVAL_CTR *values;
        REGISTRY_VALUE *rval;
@@ -194,6 +206,7 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
        bool already_in;
        int i;
        int numsources;
+       TALLOC_CTX *ctx = talloc_tos();
 
        if (!elogs) {
                return False;
@@ -208,7 +221,7 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
                DEBUG( 0,
                       ( "Eventlog [%s] not found in list of valid event logs\n",
                         eventlog ) );
-               return False;   /* invalid named passed in */
+               return false;   /* invalid named passed in */
        }
 
        /* have to assume that the evenlog key itself exists at this point */
@@ -216,12 +229,16 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
 
        /* todo add to Sources */
 
-       if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
-               DEBUG( 0, ( "talloc() failure!\n" ) );
-               return False;
+       if (!( values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
+               DEBUG( 0, ( "talloc() failure!\n" ));
+               return false;
        }
 
-       pstr_sprintf( evtlogpath, "%s\\%s", KEY_EVENTLOG, eventlog );
+       evtlogpath = talloc_asprintf("%s\\%s", KEY_EVENTLOG, eventlog);
+       if (!evtlogpath) {
+               TALLOC_FREE(values);
+               return false;
+       }
 
        regdb_fetch_values( evtlogpath, values );
 
@@ -275,7 +292,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( NULL, char *, numsources + 2 );
+               wp = TALLOC_ARRAY(ctx, char *, numsources + 2 );
 
                if ( !wp ) {
                        DEBUG( 0, ( "talloc() failed \n" ) );
@@ -289,20 +306,25 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
                regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
                                     ( char * ) msz_wp, mbytes );
                regdb_store_values( evtlogpath, values );
-               TALLOC_FREE( msz_wp );
+               TALLOC_FREE(msz_wp);
        } else {
                DEBUG( 3,
                       ( "Source name [%s] found in existing list of sources\n",
                         sourcename ) );
        }
-       TALLOC_FREE( values );
-       TALLOC_FREE( wrklist ); /*  */
+       TALLOC_FREE(values);
+       TALLOC_FREE(wrklist);   /*  */
 
-       if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
+       if ( !( subkeys = TALLOC_ZERO_P(ctx, REGSUBKEY_CTR ) ) ) {
                DEBUG( 0, ( "talloc() failure!\n" ) );
                return False;
        }
-       pstr_sprintf( evtlogpath, "%s\\%s", KEY_EVENTLOG, eventlog );
+       TALLOC_FREE(evtlogpath);
+       evtlogpath = talloc_asprintf("%s\\%s", KEY_EVENTLOG, eventlog );
+       if (!evtlogpath) {
+               TALLOC_FREE(subkeys);
+               return false;
+       }
 
        regdb_fetch_keys( evtlogpath, subkeys );
 
@@ -314,23 +336,28 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
                if ( !regdb_store_keys( evtlogpath, subkeys ) )
                        return False;
        }
-       TALLOC_FREE( subkeys );
+       TALLOC_FREE(subkeys);
 
        /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
 
        /* now allocate room for the source's subkeys */
 
-       if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
+       if ( !( subkeys = TALLOC_ZERO_P(ctx, REGSUBKEY_CTR ) ) ) {
                DEBUG( 0, ( "talloc() failure!\n" ) );
                return False;
        }
-       slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s",
-                 KEY_EVENTLOG, eventlog, sourcename );
+       TALLOC_FREE(evtlogpath);
+       evtlogpath = talloc_asprintf("%s\\%s\\%s",
+                 KEY_EVENTLOG, eventlog, sourcename);
+       if (!evtlogpath) {
+               TALLOC_FREE(subkeys);
+               return false;
+       }
 
        regdb_fetch_keys( evtlogpath, subkeys );
 
        /* now add the values to the KEY_EVENTLOG/Application form key */
-       if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
+       if ( !( values = TALLOC_ZERO_P(ctx, REGVAL_CTR ) ) ) {
                DEBUG( 0, ( "talloc() failure!\n" ) );
                return False;
        }
@@ -347,7 +374,7 @@ bool eventlog_add_source( const char *eventlog, const char *sourcename,
                             data.uni_str_len * sizeof( uint16 ) );
        regdb_store_values( evtlogpath, values );
 
-       TALLOC_FREE( values );
+       TALLOC_FREE(values);
 
        return True;
 }