Remove pstrings from nsswitch/ and registry/
authorJeremy Allison <jra@samba.org>
Tue, 27 Nov 2007 01:24:56 +0000 (17:24 -0800)
committerJeremy Allison <jra@samba.org>
Tue, 27 Nov 2007 01:24:56 +0000 (17:24 -0800)
Jeremy.
(This used to be commit 331c0d6216e1a1607a49ed7eb4078e10138ec16a)

source3/nsswitch/wb_common.c
source3/registry/reg_cachehook.c
source3/registry/reg_db.c
source3/registry/reg_dynamic.c
source3/registry/reg_eventlog.c
source3/registry/reg_objects.c
source3/registry/reg_perfcount.c
source3/registry/reg_printing.c
source3/registry/reg_util.c

index 2ae85dcb1ebb68ebdb0c6434645b101ac6c2e40c..49a2935bffb47600020acb4951ce11db4c0efd7c 100644 (file)
@@ -168,54 +168,51 @@ static int winbind_named_pipe_sock(const char *dir)
 {
        struct sockaddr_un sunaddr;
        struct stat st;
-       pstring path;
+       char *path = NULL;
        int fd;
        int wait_time;
        int slept;
-       
+
        /* Check permissions on unix socket directory */
-       
+
        if (lstat(dir, &st) == -1) {
                return -1;
        }
-       
-       if (!S_ISDIR(st.st_mode) || 
+
+       if (!S_ISDIR(st.st_mode) ||
            (st.st_uid != 0 && st.st_uid != geteuid())) {
                return -1;
        }
-       
+
        /* Connect to socket */
-       
-       strncpy(path, dir, sizeof(path) - 1);
-       path[sizeof(path) - 1] = '\0';
-       
-       strncat(path, "/", sizeof(path) - 1 - strlen(path));
-       path[sizeof(path) - 1] = '\0';
-       
-       strncat(path, WINBINDD_SOCKET_NAME, sizeof(path) - 1 - strlen(path));
-       path[sizeof(path) - 1] = '\0';
-       
+
+       if (asprintf(&path, "%s/%s", dir, WINBINDD_SOCKET_NAME) < 0) {
+               return -1;
+       }
+
        ZERO_STRUCT(sunaddr);
        sunaddr.sun_family = AF_UNIX;
        strncpy(sunaddr.sun_path, path, sizeof(sunaddr.sun_path) - 1);
-       
+
        /* If socket file doesn't exist, don't bother trying to connect
           with retry.  This is an attempt to make the system usable when
           the winbindd daemon is not running. */
 
        if (lstat(path, &st) == -1) {
+               SAFE_FREE(path);
                return -1;
        }
-       
+
+       SAFE_FREE(path);
        /* Check permissions on unix socket file */
-       
-       if (!S_ISSOCK(st.st_mode) || 
+
+       if (!S_ISSOCK(st.st_mode) ||
            (st.st_uid != 0 && st.st_uid != geteuid())) {
                return -1;
        }
-       
+
        /* Connect to socket */
-       
+
        if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
                return -1;
        }
index 739facac99a9b822e8e157caaf4a2e1f944c8e82..289d4e50cec788bfbc7d758d328ea31c73459808 100644 (file)
@@ -47,18 +47,24 @@ bool reghook_cache_init( void )
 
 bool reghook_cache_add( REGISTRY_HOOK *hook )
 {
-       pstring key;
-       
-       if ( !hook )
-               return False;
-               
-       pstrcpy( key, "\\");
-       pstrcat( key, hook->keyname );  
-       
-       pstring_sub( key, "\\", "/" );
+       TALLOC_CTX *ctx = talloc_tos();
+       char *key = NULL;
+
+       if (!hook) {
+               return false;
+       }
+
+       key = talloc_asprintf(ctx, "//%s", hook->keyname);
+       if (!key) {
+               return false;
+       }
+       key = talloc_string_sub(ctx, key, "\\", "/");
+       if (!key) {
+               return false;
+       }
 
        DEBUG(10,("reghook_cache_add: Adding key [%s]\n", key));
-               
+
        return pathtree_add( cache_tree, key, hook );
 }
 
index 4947b2ad5238baa17ea30c966d36cbc6a5c4848b..7c4ea18b1e60ec81e607207e7146781c126f338a 100644 (file)
@@ -82,10 +82,13 @@ static struct builtin_regkey_value builtin_registry_values[] = {
 /***********************************************************************
  Open the registry data in the tdb
  ***********************************************************************/
+
 static bool init_registry_data( void )
 {
-       pstring path, base, remaining;
+       char *path = NULL;
+       char *base = NULL;
+       char *remaining = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
        fstring keyname, subkeyname;
        REGSUBKEY_CTR *subkeys;
        REGVAL_CTR *values;
@@ -104,109 +107,126 @@ static bool init_registry_data( void )
        if ( tdb_transaction_start( tdb_reg->tdb ) == -1 ) {
                DEBUG(0, ("init_registry_data: tdb_transaction_start "
                          "failed\n"));
-               return False;
+               return false;
        }
-       
+
        /* loop over all of the predefined paths and add each component */
-       
+
        for ( i=0; builtin_registry_paths[i] != NULL; i++ ) {
 
                DEBUG(6,("init_registry_data: Adding [%s]\n", builtin_registry_paths[i]));
 
-               pstrcpy( path, builtin_registry_paths[i] );
-               pstrcpy( base, "" );
+               TALLOC_FREE(path);
+               path = talloc_strdup(ctx, builtin_registry_paths[i]);
+               TALLOC_FREE(base);
+               base = talloc_strdup(ctx, "");
+               if (!path || !base) {
+                       goto fail;
+               }
                p = path;
-               
-               while ( next_token(&p, keyname, "\\", sizeof(keyname)) ) {
-               
+
+               while (next_token(&p, keyname, "\\", sizeof(keyname))) {
+
                        /* build up the registry path from the components */
-                       
-                       if ( *base )
-                               pstrcat( base, "\\" );
-                       pstrcat( base, keyname );
-                       
+
+                       if (*base) {
+                               base = talloc_asprintf(ctx, "%s\\", base);
+                               if (!base) {
+                                       goto fail;
+                               }
+                       }
+                       base = talloc_asprintf_append(base, "%s", keyname);
+                       if (!base) {
+                               goto fail;
+                       }
+
                        /* get the immediate subkeyname (if we have one ) */
-                       
+
                        *subkeyname = '\0';
-                       if ( *p ) {
-                               pstrcpy( remaining, p );
+                       if (*p) {
+                               TALLOC_FREE(remaining);
+                               remaining = talloc_strdup(ctx, p);
+                               if (!remaining) {
+                                       goto fail;
+                               }
                                p2 = remaining;
-                               
-                               if ( !next_token(&p2, subkeyname, "\\", sizeof(subkeyname)) )
+
+                               if (!next_token(&p2, subkeyname, "\\",
+                                                       sizeof(subkeyname))) {
                                        fstrcpy( subkeyname, p2 );
+                               }
                        }
 
                        DEBUG(10,("init_registry_data: Storing key [%s] with subkey [%s]\n",
                                base, *subkeyname ? subkeyname : "NULL"));
-                       
+
                        /* we don't really care if the lookup succeeds or not since
-                          we are about to update the record.  We just want any 
+                          we are about to update the record.  We just want any
                           subkeys already present */
-                       
-                       if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
+
+                       if ( !(subkeys = TALLOC_ZERO_P(ctx, REGSUBKEY_CTR )) ) {
                                DEBUG(0,("talloc() failure!\n"));
                                goto fail;
                        }
 
-                       regdb_fetch_keys( base, subkeys );
-                       if ( *subkeyname ) 
-                               regsubkey_ctr_addkey( subkeys, subkeyname );
-                       if ( !regdb_store_keys( base, subkeys ))
+                       regdb_fetch_keys(base, subkeys);
+                       if (*subkeyname) {
+                               regsubkey_ctr_addkey( subkeys, subkeyname);
+                       }
+                       if (!regdb_store_keys( base, subkeys)) {
                                goto fail;
-                       
-                       TALLOC_FREE( subkeys );
+                       }
+
+                       TALLOC_FREE(subkeys);
                }
        }
 
        /* loop over all of the predefined values and add each component */
-       
-       for ( i=0; builtin_registry_values[i].path != NULL; i++ ) {
-               if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
-                       DEBUG(0,("talloc() failure!\n"));
+
+       for (i=0; builtin_registry_values[i].path != NULL; i++) {
+               if (!(values = TALLOC_ZERO_P(ctx, REGVAL_CTR))) {
                        goto fail;
                }
 
-               regdb_fetch_values( builtin_registry_values[i].path, values );
+               regdb_fetch_values( builtin_registry_values[i].path, values);
 
                /* preserve existing values across restarts.  Only add new ones */
 
-               if ( !regval_ctr_key_exists( values, builtin_registry_values[i].valuename ) ) 
-               {
-                       switch( builtin_registry_values[i].type ) {
+               if (!regval_ctr_key_exists(values, builtin_registry_values[i].valuename)) {
+                       switch(builtin_registry_values[i].type) {
                        case REG_DWORD:
-                               regval_ctr_addvalue( values, 
+                               regval_ctr_addvalue( values,
                                                     builtin_registry_values[i].valuename,
                                                     REG_DWORD,
                                                     (char*)&builtin_registry_values[i].data.dw_value,
                                                     sizeof(uint32) );
                                break;
-                               
+
                        case REG_SZ:
                                init_unistr2( &data, builtin_registry_values[i].data.string, UNI_STR_TERMINATE);
-                               regval_ctr_addvalue( values, 
+                               regval_ctr_addvalue( values,
                                                     builtin_registry_values[i].valuename,
                                                     REG_SZ,
                                                     (char*)data.buffer,
                                                     data.uni_str_len*sizeof(uint16) );
                                break;
-                       
+
                        default:
                                DEBUG(0,("init_registry_data: invalid value type in builtin_registry_values [%d]\n",
                                        builtin_registry_values[i].type));
                        }
                        regdb_store_values( builtin_registry_values[i].path, values );
                }
-               
                TALLOC_FREE( values );
        }
-       
+
        if (tdb_transaction_commit( tdb_reg->tdb ) == -1) {
                DEBUG(0, ("init_registry_data: Could not commit "
                          "transaction\n"));
-               return False;
+               return false;
        }
 
-       return True;
+       return true;
 
  fail:
 
@@ -215,7 +235,7 @@ static bool init_registry_data( void )
                          "failed\n");
        }
 
-       return False;
+       return false;
 }
 
 /***********************************************************************
@@ -326,37 +346,42 @@ int regdb_get_seqnum(void)
  fmt is the same format as tdb_pack except this function only supports
  fstrings
  ***********************************************************************/
-static bool regdb_store_keys_internal( const char *key, REGSUBKEY_CTR *ctr )
+
+static bool regdb_store_keys_internal(const char *key, REGSUBKEY_CTR *ctr)
 {
        TDB_DATA dbuf;
-       uint8 *buffer;
+       uint8 *buffer = NULL;
        int i = 0;
        uint32 len, buflen;
        bool ret = True;
-       uint32 num_subkeys = regsubkey_ctr_numkeys( ctr );
-       pstring keyname;
-       
-       if ( !key )
-               return False;
+       uint32 num_subkeys = regsubkey_ctr_numkeys(ctr);
+       char *keyname = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
 
-       pstrcpy( keyname, key );
-       normalize_reg_path( keyname );
+       if (!key) {
+               return false;
+       }
+
+       keyname = talloc_strdup(ctx, key);
+       if (!keyname) {
+               return false;
+       }
+       keyname = normalize_reg_path(ctx, keyname);
 
        /* allocate some initial memory */
-               
-       if (!(buffer = (uint8 *)SMB_MALLOC(sizeof(pstring)))) {
+
+       if (!(buffer = (uint8 *)SMB_MALLOC(1024))) {
                return False;
        }
-       buflen = sizeof(pstring);
+       buflen = 1024;
        len = 0;
-       
+
        /* store the number of subkeys */
-       
+
        len += tdb_pack(buffer+len, buflen-len, "d", num_subkeys );
-       
+
        /* pack all the strings */
-       
+
        for (i=0; i<num_subkeys; i++) {
                len += tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) );
                if ( len > buflen ) {
@@ -367,13 +392,13 @@ static bool regdb_store_keys_internal( const char *key, REGSUBKEY_CTR *ctr )
                                goto done;
                        }
                        buflen = len*2;
-                                       
+
                        len = tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) );
-               }               
+               }
        }
-       
+
        /* finally write out the data */
-       
+
        dbuf.dptr = buffer;
        dbuf.dsize = len;
        if ( tdb_store_bystring( tdb_reg->tdb, keyname, dbuf, TDB_REPLACE ) == -1) {
@@ -381,35 +406,35 @@ static bool regdb_store_keys_internal( const char *key, REGSUBKEY_CTR *ctr )
                goto done;
        }
 
-done:          
+done:
        SAFE_FREE( buffer );
-       
        return ret;
 }
 
 /***********************************************************************
- Store the new subkey record and create any child key records that 
+ Store the new subkey record and create any child key records that
  do not currently exist
  ***********************************************************************/
 
-bool regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr )
+bool regdb_store_keys(const char *key, REGSUBKEY_CTR *ctr)
 {
        int num_subkeys, i;
-       pstring path;
+       char *path = NULL;
        REGSUBKEY_CTR *subkeys = NULL, *old_subkeys = NULL;
-       char *oldkeyname;
-       
+       char *oldkeyname = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
+
        /*
         * fetch a list of the old subkeys so we can determine if anything has
         * changed
         */
 
-       if ( !(old_subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {
+       if (!(old_subkeys = TALLOC_ZERO_P(ctr, REGSUBKEY_CTR))) {
                DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
-               goto fail;
+               return false;
        }
 
-       regdb_fetch_keys( key, old_subkeys );
+       regdb_fetch_keys(key, old_subkeys);
 
        if (ctr->num_subkeys == old_subkeys->num_subkeys) {
 
@@ -425,13 +450,13 @@ bool regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr )
                         * transaction
                         */
                        TALLOC_FREE(old_subkeys);
-                       return True;
+                       return true;
                }
        }
 
-       if ( tdb_transaction_start( tdb_reg->tdb ) == -1 ) {
+       if (tdb_transaction_start( tdb_reg->tdb ) == -1) {
                DEBUG(0, ("regdb_store_keys: tdb_transaction_start failed\n"));
-               return False;
+               return false;
        }
 
        /*
@@ -440,28 +465,28 @@ bool regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr )
 
        TALLOC_FREE(old_subkeys);
 
-       if ( !(old_subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {
+       if (!(old_subkeys = TALLOC_ZERO_P(ctr, REGSUBKEY_CTR))) {
                DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
                goto fail;
        }
 
-       regdb_fetch_keys( key, old_subkeys );
-       
+       regdb_fetch_keys(key, old_subkeys);
+
        /* store the subkey list for the parent */
-       
-       if ( !regdb_store_keys_internal( key, ctr ) ) {
+
+       if (!regdb_store_keys_internal(key, ctr) ) {
                DEBUG(0,("regdb_store_keys: Failed to store new subkey list "
-                        "for parent [%s]\n", key ));
+                        "for parent [%s]\n", key));
                goto fail;
        }
-       
+
        /* now delete removed keys */
-       
-       num_subkeys = regsubkey_ctr_numkeys( old_subkeys );
-       for ( i=0; i<num_subkeys; i++ ) {
-               oldkeyname = regsubkey_ctr_specific_key( old_subkeys, i );
 
-               if ( regsubkey_ctr_key_exists( ctr, oldkeyname ) ) {
+       num_subkeys = regsubkey_ctr_numkeys(old_subkeys);
+       for (i=0; i<num_subkeys; i++) {
+               oldkeyname = regsubkey_ctr_specific_key(old_subkeys, i);
+
+               if (regsubkey_ctr_key_exists(ctr, oldkeyname)) {
                        /*
                         * It's still around, don't delete
                         */
@@ -469,153 +494,182 @@ bool regdb_store_keys( const char *key, REGSUBKEY_CTR *ctr )
                        continue;
                }
 
-               pstr_sprintf( path, "%s/%s", key, oldkeyname );
-               normalize_reg_path( path );
-               if (tdb_delete_bystring( tdb_reg->tdb, path ) == -1) {
+               path = talloc_asprintf(ctx, "%s/%s", key, oldkeyname);
+               if (!path) {
+                       goto fail;
+               }
+               path = normalize_reg_path(ctx, path);
+               if (!path) {
+                       goto fail;
+               }
+               if (tdb_delete_bystring(tdb_reg->tdb, path) == -1) {
                        DEBUG(1, ("Deleting %s failed\n", path));
                        goto fail;
                }
-               
-               pstr_sprintf( path, "%s/%s/%s", REG_VALUE_PREFIX, key,
-                             oldkeyname );
-               normalize_reg_path( path );
+
+               TALLOC_FREE(path);
+               path = talloc_asprintf(ctx, "%s/%s/%s",
+                               REG_VALUE_PREFIX,
+                               key,
+                               oldkeyname );
+               if (!path) {
+                       goto fail;
+               }
+               path = normalize_reg_path(ctx, path);
+               if (!path) {
+                       goto fail;
+               }
 
                /*
                 * Ignore errors here, we might have no values around
                 */
                tdb_delete_bystring( tdb_reg->tdb, path );
+               TALLOC_FREE(path);
        }
 
-       TALLOC_FREE( old_subkeys );
-       
+       TALLOC_FREE(old_subkeys);
+
        /* now create records for any subkeys that don't already exist */
-       
-       num_subkeys = regsubkey_ctr_numkeys( ctr );
-       for ( i=0; i<num_subkeys; i++ ) {
-               pstr_sprintf( path, "%s/%s", key,
-                             regsubkey_ctr_specific_key( ctr, i ) );
 
-               if ( !(subkeys = TALLOC_ZERO_P( ctr, REGSUBKEY_CTR )) ) {
+       num_subkeys = regsubkey_ctr_numkeys(ctr);
+       for (i=0; i<num_subkeys; i++) {
+               path = talloc_asprintf(ctx, "%s/%s",
+                                       key,
+                                       regsubkey_ctr_specific_key(ctr, i));
+               if (!path) {
+                       goto fail;
+               }
+               if (!(subkeys = TALLOC_ZERO_P(ctr, REGSUBKEY_CTR)) ) {
                        DEBUG(0,("regdb_store_keys: talloc() failure!\n"));
                        goto fail;
                }
 
-               if ( regdb_fetch_keys( path, subkeys ) == -1 ) {
+               if (regdb_fetch_keys( path, subkeys ) == -1) {
                        /* create a record with 0 subkeys */
-                       if ( !regdb_store_keys_internal( path, subkeys ) ) {
+                       if (!regdb_store_keys_internal(path, subkeys)) {
                                DEBUG(0,("regdb_store_keys: Failed to store "
-                                        "new record for key [%s]\n", path ));
+                                        "new record for key [%s]\n", path));
                                goto fail;
                        }
                }
 
-               TALLOC_FREE( subkeys );
+               TALLOC_FREE(subkeys);
+               TALLOC_FREE(path);
        }
 
        if (tdb_transaction_commit( tdb_reg->tdb ) == -1) {
                DEBUG(0, ("regdb_store_keys: Could not commit transaction\n"));
-               return False;
+               return false;
        }
 
-       return True;
+       return true;
 
  fail:
-       TALLOC_FREE( old_subkeys );
-       TALLOC_FREE( subkeys );
+       TALLOC_FREE(old_subkeys);
+       TALLOC_FREE(subkeys);
 
-       if (tdb_transaction_cancel( tdb_reg->tdb ) == -1) {
+       if (tdb_transaction_cancel(tdb_reg->tdb) == -1) {
                smb_panic("regdb_store_keys: tdb_transaction_cancel failed\n");
        }
 
-       return False;
+       return false;
 }
 
 
 /***********************************************************************
- Retrieve an array of strings containing subkeys.  Memory should be 
- released by the caller.  
+ Retrieve an array of strings containing subkeys.  Memory should be
+ released by the caller.
  ***********************************************************************/
 
-int regdb_fetch_keys( const char* key, REGSUBKEY_CTR *ctr )
+int regdb_fetch_keys(const char *key, REGSUBKEY_CTR *ctr)
 {
-       pstring path;
+       char *path = NULL;
        uint32 num_items;
        TDB_DATA dbuf;
        uint8 *buf;
        uint32 buflen, len;
        int i;
        fstring subkeyname;
+       TALLOC_CTX *ctx = talloc_tos();
 
        DEBUG(11,("regdb_fetch_keys: Enter key => [%s]\n", key ? key : "NULL"));
-       
-       pstrcpy( path, key );
-       
+
+       path = talloc_strdup(ctx, key);
+       if (!path) {
+               return -1;
+       }
+
        /* convert to key format */
-       pstring_sub( path, "\\", "/" ); 
-       strupper_m( path );
-       
-       dbuf = tdb_fetch_bystring( tdb_reg->tdb, path );
-       
+       path = talloc_string_sub(ctx, path, "\\", "/");
+       if (!path) {
+               return -1;
+       }
+       strupper_m(path);
+
+       dbuf = tdb_fetch_bystring(tdb_reg->tdb, path);
+
+       TALLOC_FREE(path);
+
        buf = dbuf.dptr;
        buflen = dbuf.dsize;
-       
+
        if ( !buf ) {
                DEBUG(5,("regdb_fetch_keys: tdb lookup failed to locate key [%s]\n", key));
                return -1;
        }
-       
+
        len = tdb_unpack( buf, buflen, "d", &num_items);
-       
+
        for (i=0; i<num_items; i++) {
-               len += tdb_unpack( buf+len, buflen-len, "f", subkeyname );
-               regsubkey_ctr_addkey( ctr, subkeyname );
+               len += tdb_unpack(buf+len, buflen-len, "f", subkeyname);
+               regsubkey_ctr_addkey(ctr, subkeyname);
        }
 
-       SAFE_FREE( dbuf.dptr );
-       
+       SAFE_FREE(dbuf.dptr);
+
        DEBUG(11,("regdb_fetch_keys: Exit [%d] items\n", num_items));
-       
+
        return num_items;
 }
 
 /****************************************************************************
  Unpack a list of registry values frem the TDB
  ***************************************************************************/
+
 static int regdb_unpack_values(REGVAL_CTR *values, uint8 *buf, int buflen)
 {
        int             len = 0;
        uint32          type;
-       pstring         valuename;
+       fstring valuename;
        uint32          size;
        uint8           *data_p;
        uint32          num_values = 0;
        int             i;
-       
-       
-       
+
        /* loop and unpack the rest of the registry values */
-       
+
        len += tdb_unpack(buf+len, buflen-len, "d", &num_values);
-       
+
        for ( i=0; i<num_values; i++ ) {
                /* unpack the next regval */
-               
+
                type = REG_NONE;
                size = 0;
                data_p = NULL;
+               valuename[0] = '\0';
                len += tdb_unpack(buf+len, buflen-len, "fdB",
                                  valuename,
                                  &type,
                                  &size,
                                  &data_p);
-                               
+
                /* add the new value. Paranoid protective code -- make sure data_p is valid */
 
-               if ( size && data_p ) {
-                       regval_ctr_addvalue( values, valuename, type, (const char *)data_p, size );
-                       SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */
+               if (*valuename && size && data_p) {
+                       regval_ctr_addvalue(values, valuename, type,
+                                       (const char *)data_p, size);
                }
+               SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */
 
                DEBUG(8,("specific: [%s], len: %d\n", valuename, size));
        }
@@ -626,7 +680,7 @@ static int regdb_unpack_values(REGVAL_CTR *values, uint8 *buf, int buflen)
 /****************************************************************************
  Pack all values in all printer keys
  ***************************************************************************/
+
 static int regdb_pack_values(REGVAL_CTR *values, uint8 *buf, int buflen)
 {
        int             len = 0;
@@ -640,12 +694,12 @@ static int regdb_pack_values(REGVAL_CTR *values, uint8 *buf, int buflen)
        num_values = regval_ctr_numvals( values );
 
        /* pack the number of values first */
-       
+
        len += tdb_pack( buf+len, buflen-len, "d", num_values );
-       
+
        /* loop over all values */
-               
-       for ( i=0; i<num_values; i++ ) {                        
+
+       for ( i=0; i<num_values; i++ ) {
                val = regval_ctr_specific_value( values, i );
                len += tdb_pack(buf+len, buflen-len, "fdB",
                                regval_name(val),
@@ -658,60 +712,75 @@ static int regdb_pack_values(REGVAL_CTR *values, uint8 *buf, int buflen)
 }
 
 /***********************************************************************
- Retrieve an array of strings containing subkeys.  Memory should be 
+ Retrieve an array of strings containing subkeys.  Memory should be
  released by the caller.
  ***********************************************************************/
 
 int regdb_fetch_values( const char* key, REGVAL_CTR *values )
 {
        TDB_DATA data;
-       pstring keystr;
+       char *keystr = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
 
        DEBUG(10,("regdb_fetch_values: Looking for value of key [%s] \n", key));
-       
-       pstr_sprintf( keystr, "%s/%s", REG_VALUE_PREFIX, key );
-       normalize_reg_path( keystr );
-       
-       data = tdb_fetch_bystring( tdb_reg->tdb, keystr );
-       
-       if ( !data.dptr ) {
+
+       keystr = talloc_asprintf(ctx, "%s/%s", REG_VALUE_PREFIX, key);
+       if (!keystr) {
+               return 0;
+       }
+       keystr = normalize_reg_path(ctx, keystr);
+       if (!keystr) {
+               return 0;
+       }
+
+       data = tdb_fetch_bystring(tdb_reg->tdb, keystr);
+
+       if (!data.dptr) {
                /* all keys have zero values by default */
                return 0;
        }
-       
-       regdb_unpack_values( values, data.dptr, data.dsize );
-       
-       SAFE_FREE( data.dptr );
-       
+
+       regdb_unpack_values(values, data.dptr, data.dsize);
+
+       SAFE_FREE(data.dptr);
        return regval_ctr_numvals(values);
 }
 
 bool regdb_store_values( const char *key, REGVAL_CTR *values )
 {
        TDB_DATA old_data, data;
-       pstring keystr;
+       char *keystr = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
        int len, ret;
-       
+
        DEBUG(10,("regdb_store_values: Looking for value of key [%s] \n", key));
-       
-       ZERO_STRUCT( data );
-       
-       len = regdb_pack_values( values, data.dptr, data.dsize );
-       if ( len <= 0 ) {
+
+       ZERO_STRUCT(data);
+
+       len = regdb_pack_values(values, data.dptr, data.dsize);
+       if (len <= 0) {
                DEBUG(0,("regdb_store_values: unable to pack values. len <= 0\n"));
-               return False;
+               return false;
        }
-       
+
        data.dptr = SMB_MALLOC_ARRAY( uint8, len );
        data.dsize = len;
-       
-       len = regdb_pack_values( values, data.dptr, data.dsize );
-       
+
+       len = regdb_pack_values(values, data.dptr, data.dsize);
+
        SMB_ASSERT( len == data.dsize );
-       
-       pstr_sprintf( keystr, "%s/%s", REG_VALUE_PREFIX, key );
-       normalize_reg_path( keystr );
-       
+
+       keystr = talloc_asprintf(ctx, "%s/%s", REG_VALUE_PREFIX, key );
+       if (!keystr) {
+               SAFE_FREE(data.dptr);
+               return false;
+       }
+       keystr = normalize_reg_path(ctx, keystr);
+       if (!keystr) {
+               SAFE_FREE(data.dptr);
+               return false;
+       }
+
        old_data = tdb_fetch_bystring(tdb_reg->tdb, keystr);
 
        if ((old_data.dptr != NULL)
@@ -723,10 +792,10 @@ bool regdb_store_values( const char *key, REGVAL_CTR *values )
        }
 
        ret = tdb_trans_store_bystring(tdb_reg->tdb, keystr, data, TDB_REPLACE);
-       
+
        SAFE_FREE( old_data.dptr );
        SAFE_FREE( data.dptr );
-       
+
        return ret != -1 ;
 }
 
index e589dff2c85a9d1c366997354545b1be5062f06d..e70bd178f9370ab8a961170241e2ab7425a5e181 100644 (file)
@@ -216,16 +216,23 @@ static struct reg_dyn_values dynamic_values[] = {
 int fetch_dynamic_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
 {
        int i;
-       pstring path;
-       
-       pstrcpy( path, key->name );
-       normalize_reg_path( path );
-       
+       char *path = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
+
+       path = talloc_strdup(ctx, key->name);
+       if (!path) {
+               return -1;
+       }
+       path = normalize_reg_path(ctx, path);
+       if (!path) {
+               return -1;
+       }
+
        for ( i=0; dynamic_values[i].path; i++ ) {
                if ( strcmp( path, dynamic_values[i].path ) == 0 )
                        return dynamic_values[i].fetch_values( val );
        }
-       
+
        return -1;
 }
 
@@ -235,17 +242,23 @@ int fetch_dynamic_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
 bool check_dynamic_reg_values( REGISTRY_KEY *key )
 {
        int i;
-       pstring path;
-       
-       pstrcpy( path, key->name );
-       normalize_reg_path( path );
-       
+       char *path = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
+
+       path = talloc_strdup(ctx, key->name);
+       if (!path) {
+               return false;
+       }
+       path = normalize_reg_path(ctx, path);
+       if (!path) {
+               return false;
+       }
+
        for ( i=0; dynamic_values[i].path; i++ ) {
                /* can't write to dynamic keys */
                if ( strcmp( path, dynamic_values[i].path ) == 0 )
-                       return True;
+                       return true;
        }
-       
-       return False;
-}
 
+       return false;
+}
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;
 }
index fa531af10cba8f5e0c709bd79f0f91b3e61510f5..47122ccad2a20739e0c1483403eed89300b7e099 100644 (file)
@@ -421,11 +421,11 @@ uint32 regval_dword( REGISTRY_VALUE *val )
  return the data_p as a character string
  **********************************************************************/
 
-char* regval_sz( REGISTRY_VALUE *val )
+char *regval_sz(REGISTRY_VALUE *val)
 {
-       pstring data;
+       char *data = NULL;
 
-       rpcstr_pull(data, regval_data_p(val), sizeof(data), regval_size(val),0);
-
-       return talloc_strdup(talloc_tos(), data);
+       rpcstr_pull_talloc(talloc_tos(), &data,
+                       regval_data_p(val), regval_size(val),0);
+       return data;
 }
index 1fd9b36a5140bac46782e6ef43b807496cac143a..519e0e74880ade1b7e8ba8f9f54fb1370be9f544 100644 (file)
@@ -35,19 +35,23 @@ PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind);
 /*********************************************************************
 *********************************************************************/
 
-static char* counters_directory( const char *dbname )
+static char *counters_directory(const char *dbname)
 {
-       pstring fname;
-       fstring path;
-       
-       if ( !dbname )
+       char *path = NULL;
+       char *ret = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
+
+       if (!dbname)
                return NULL;
-       
-       fstr_sprintf( path, "%s/%s", PERFCOUNTDIR, dbname );
-       
-       pstrcpy( fname, state_path( path ) );
-       
-       return talloc_strdup(talloc_tos(), fname);
+
+       path = talloc_asprintf(ctx, "%s/%s", PERFCOUNTDIR, dbname);
+       if (!path) {
+               return NULL;
+       }
+
+       ret = talloc_strdup(ctx, state_path(path));
+       TALLOC_FREE(path);
+       return ret;
 }
 
 /*********************************************************************
@@ -667,7 +671,7 @@ bool _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst,
 {
        TDB_DATA key, data;
        char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
-       wpstring name;
+       smb_ucs2_t *name = NULL;
        int pad;
 
        /* First grab the instance data from the data file */
@@ -707,9 +711,13 @@ bool _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst,
        else
        {
                memset(buf, 0, PERFCOUNT_MAX_LEN);
-               memcpy(buf, data.dptr, data.dsize);
-               rpcstr_push((void *)name, buf, sizeof(name), STR_TERMINATE);
-               inst->NameLength = (strlen_w(name) * 2) + 2;
+               memcpy(buf, data.dptr, MIN(PERFCOUNT_MAX_LEN-1,data.dsize));
+               buf[PERFCOUNT_MAX_LEN-1] = '\0';
+               inst->NameLength = rpcstr_push_talloc(ps->mem_ctx, &name, buf);
+               if (inst->NameLength == (size_t)-1 || !name) {
+                       SAFE_FREE(data.dptr);
+                       return False;
+               }
                inst->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
                                                  inst->data,
                                                  uint8,
@@ -891,11 +899,15 @@ static bool _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block,
 static bool _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block,
                                           prs_struct *ps, TDB_CONTEXT *names)
 {
-       wpstring temp;
+       smb_ucs2_t *temp = NULL;
        time_t tm;
-       memset(temp, 0, sizeof(temp));
-       rpcstr_push((void *)temp, "PERF", sizeof(temp), STR_TERMINATE);
+
+       if (rpcstr_push_talloc(ps->mem_ctx, &temp, "PERF")==(size_t)-1) {
+               return false;
+       }
+       if (!temp) {
+               return false;
+       }
        memcpy(block->Signature, temp, strlen_w(temp) *2);
 
        if(ps->bigendian_data == RPC_BIG_ENDIAN)
index 47582c51f7def8d4e8ed361dc3f6bdc4cd4ae986..8c1de763bd142f45763f9c1a4541f05ff0bd74a4 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  *  Unix SMB/CIFS implementation.
  *  Virtual Windows Registry Layer
  *  Copyright (C) Gerald Carter                     2002-2005
@@ -7,12 +7,12 @@
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #define KEY_PORTS              "HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PORTS"
 
 /* callback table for various registry paths below the ones we service in this module */
-       
+
 struct reg_dyn_tree {
        /* full key path in normalized form */
        const char *path;
-       
+
        /* callbscks for fetch/store operations */
        int ( *fetch_subkeys) ( const char *path, REGSUBKEY_CTR *subkeys );
        bool (*store_subkeys) ( const char *path, REGSUBKEY_CTR *subkeys );
@@ -55,18 +55,19 @@ struct reg_dyn_tree {
  *********************************************************************/
 
 /***********************************************************************
- simple function to prune a pathname down to the basename of a file 
+ simple function to prune a pathname down to the basename of a file
  **********************************************************************/
-static char* dos_basename ( char *path )
+
+static const char *dos_basename(const char *path)
 {
-       char *p;
-       
-       if ( !(p = strrchr( path, '\\' )) )
+       const char *p;
+
+       if (!(p = strrchr( path, '\\'))) {
                p = path;
-       else
+       } else {
                p++;
-               
+       }
+
        return p;
 }
 
@@ -76,15 +77,16 @@ static char* dos_basename ( char *path )
  *********************************************************************
  *********************************************************************/
 
-static int key_forms_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
+static int key_forms_fetch_keys(const char *key, REGSUBKEY_CTR *subkeys)
 {
-       char *p = reg_remaining_path( key + strlen(KEY_FORMS) );
-       
+       char *p = reg_remaining_path(talloc_tos(), key + strlen(KEY_FORMS));
+
        /* no keys below Forms */
-       
-       if ( p )
+
+       if (p) {
                return -1;
-               
+       }
+
        return 0;
 }
 
@@ -97,19 +99,19 @@ static int key_forms_fetch_values( const char *key, REGVAL_CTR *values )
        int             i, num_values, form_index = 1;
        nt_forms_struct *forms_list = NULL;
        nt_forms_struct *form;
-               
+
        DEBUG(10,("print_values_forms: key=>[%s]\n", key ? key : "NULL" ));
-       
+
        num_values = get_ntforms( &forms_list );
-               
+
        DEBUG(10,("hive_forms_fetch_values: [%d] user defined forms returned\n",
                num_values));
 
        /* handle user defined forms */
-                               
+
        for ( i=0; i<num_values; i++ ) {
                form = &forms_list[i];
-                       
+
                data[0] = form->width;
                data[1] = form->length;
                data[2] = form->left;
@@ -118,23 +120,23 @@ static int key_forms_fetch_values( const char *key, REGVAL_CTR *values )
                data[5] = form->bottom;
                data[6] = form_index++;
                data[7] = form->flag;
-                       
+
                regval_ctr_addvalue( values, form->name, REG_BINARY, (char*)data, sizeof(data) );       
        }
-               
+
        SAFE_FREE( forms_list );
        forms_list = NULL;
-               
+
        /* handle built-on forms */
-               
+
        num_values = get_builtin_ntforms( &forms_list );
-               
+
        DEBUG(10,("print_subpath_values_forms: [%d] built-in forms returned\n",
                num_values));
-                       
+
        for ( i=0; i<num_values; i++ ) {
                form = &forms_list[i];
-                       
+
                data[0] = form->width;
                data[1] = form->length;
                data[2] = form->left;
@@ -143,13 +145,13 @@ static int key_forms_fetch_values( const char *key, REGVAL_CTR *values )
                data[5] = form->bottom;
                data[6] = form_index++;
                data[7] = form->flag;
-                                       
-               regval_ctr_addvalue( values, form->name, REG_BINARY, (char*)data, sizeof(data) );
+
+               regval_ctr_addvalue(values, form->name, REG_BINARY, (char*)data, sizeof(data) );
        }
-               
-       SAFE_FREE( forms_list );
-       
-       return regval_ctr_numvals( values );
+
+       SAFE_FREE(forms_list);
+
+       return regval_ctr_numvals(values);
 }
 
 /*********************************************************************
@@ -160,34 +162,43 @@ static int key_forms_fetch_values( const char *key, REGVAL_CTR *values )
  *********************************************************************/
 
 /*********************************************************************
- strip off prefix for printers key.  DOes return a pointer to static 
+ strip off prefix for printers key.  DOes return a pointer to static
  memory.
  *********************************************************************/
 
-static char* strip_printers_prefix( const char *key )
+static char *strip_printers_prefix(const char *key)
 {
-       char *subkeypath;
-       pstring path;
-       
-       pstrcpy( path, key );
-       normalize_reg_path( path );
+       char *subkeypath = NULL;
+       char *path = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
+
+       path = talloc_strdup(ctx, key);
+       if (!path) {
+               return NULL;
+       }
+       path = normalize_reg_path(ctx, path);
+       if (!path) {
+               return NULL;
+       }
 
        /* normalizing the path does not change length, just key delimiters and case */
 
-       if ( strncmp( path, KEY_WINNT_PRINTERS, strlen(KEY_WINNT_PRINTERS) ) == 0 )
-               subkeypath = reg_remaining_path( key + strlen(KEY_WINNT_PRINTERS) );
-       else
-               subkeypath = reg_remaining_path( key + strlen(KEY_CONTROL_PRINTERS) );
-               
+       if (strncmp(path, KEY_WINNT_PRINTERS, strlen(KEY_WINNT_PRINTERS)) == 0) {
+               subkeypath = reg_remaining_path(ctx, key + strlen(KEY_WINNT_PRINTERS));
+       } else {
+               subkeypath = reg_remaining_path(ctx, key + strlen(KEY_CONTROL_PRINTERS));
+       }
+
+       TALLOC_FREE(path);
        return subkeypath;
 }
 
 /*********************************************************************
  *********************************************************************/
+
 static int key_printers_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
 {
-       int n_services = lp_numservices();      
+       int n_services = lp_numservices();
        int snum;
        fstring sname;
        int i;
@@ -196,14 +207,14 @@ static int key_printers_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
        char *printername, *printerdatakey;
        NT_PRINTER_INFO_LEVEL *printer = NULL;
        fstring *subkey_names = NULL;
-       
+
        DEBUG(10,("key_printers_fetch_keys: key=>[%s]\n", key ? key : "NULL" ));
-       
-       printers_key = strip_printers_prefix( key );    
-       
+
+       printers_key = strip_printers_prefix( key );
+
        if ( !printers_key ) {
                /* enumerate all printers */
-               
+
                for (snum=0; snum<n_services; snum++) {
                        if ( !(lp_snum_ok(snum) && lp_print_ok(snum) ) )
                                continue;
@@ -212,18 +223,18 @@ static int key_printers_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
 
                        if ( strequal( lp_servicename(snum), PRINTERS_NAME ) )
                                continue;
-                               
+
                        fstrcpy( sname, lp_servicename(snum) );
-                               
+
                        regsubkey_ctr_addkey( subkeys, sname );
                }
-               
+
                num_subkeys = regsubkey_ctr_numkeys( subkeys );
                goto done;
        }
 
        /* get information for a specific printer */
-       
+
        if (!reg_split_path( printers_key, &printername, &printerdatakey )) {
                return -1;
        }
@@ -742,58 +753,61 @@ static int key_driver_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
        fstring *drivers = NULL;
        int i, env_index, num_drivers;
        char *keystr, *base, *subkeypath;
-       pstring key2;
+       char *key2 = NULL;
        int num_subkeys = -1;
        int version;
+       TALLOC_CTX *ctx = talloc_tos();
 
        DEBUG(10,("key_driver_fetch_keys key=>[%s]\n", key ? key : "NULL" ));
-       
-       keystr = reg_remaining_path( key + strlen(KEY_ENVIRONMENTS) );  
-       
+
+       keystr = reg_remaining_path(ctx, key + strlen(KEY_ENVIRONMENTS) );
+
        /* list all possible architectures */
-       
+
        if ( !keystr ) {
-               for ( num_subkeys=0; environments[num_subkeys]; num_subkeys++ ) 
+               for ( num_subkeys=0; environments[num_subkeys]; num_subkeys++ )
                        regsubkey_ctr_addkey( subkeys,  environments[num_subkeys] );
 
                return num_subkeys;
        }
-       
+
        /* we are dealing with a subkey of "Environments */
-       
-       pstrcpy( key2, keystr );
+       key2 = talloc_strdup(ctx, keystr);
+       if (!key2) {
+               return -1;
+       }
        keystr = key2;
-       if (!reg_split_path( keystr, &base, &subkeypath )) {
+       if (!reg_split_path(keystr, &base, &subkeypath )) {
                return -1;
        }
-       
+
        /* sanity check */
-       
+
        for ( env_index=0; environments[env_index]; env_index++ ) {
                if ( strequal( environments[env_index], base ) )
                        break;
        }
        if ( !environments[env_index] )
                return -1;
-       
+
        /* ...\Print\Environements\...\ */
-       
+
        if ( !subkeypath ) {
                regsubkey_ctr_addkey( subkeys, "Drivers" );
                regsubkey_ctr_addkey( subkeys, "Print Processors" );
-                               
+
                return 2;
        }
-       
+
        /* more of the key path to process */
-       
+
        keystr = subkeypath;
        if (!reg_split_path( keystr, &base, &subkeypath )) {
                return -1;
        }
-               
+
        /* ...\Print\Environements\...\Drivers\ */
-       
+
        if ( !subkeypath ) {
                if ( strequal(base, "Drivers") ) {
                        switch ( env_index ) {
@@ -803,21 +817,21 @@ static int key_driver_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
                                default: /* Windows NT based systems */
                                        regsubkey_ctr_addkey( subkeys, "Version-2" );
                                        regsubkey_ctr_addkey( subkeys, "Version-3" );
-                                       break;                  
+                                       break;
                        }
-               
+
                        return regsubkey_ctr_numkeys( subkeys );
                } else if ( strequal(base, "Print Processors") ) {
                        if ( env_index == 1 || env_index == 5 || env_index == 6 )
-                               regsubkey_ctr_addkey( subkeys, "winprint" );
-                               
+
+
                        return regsubkey_ctr_numkeys( subkeys );
                } else
                        return -1;      /* bad path */
        }
-       
+
        /* we finally get to enumerate the drivers */
-       
+
        /* only one possible subkey below PrintProc key */
 
        if ( strequal(base, "Print Processors") ) {
@@ -835,7 +849,7 @@ static int key_driver_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
 
                return strequal( base, "winprint" ) ? 0 : -1;
        }
-       
+
        /* only dealing with drivers from here on out */
 
        keystr = subkeypath;
@@ -844,7 +858,7 @@ static int key_driver_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
        }
 
        version = atoi(&base[strlen(base)-1]);
-                       
+
        switch (env_index) {
        case 0:
                if ( version != 0 )
@@ -856,20 +870,20 @@ static int key_driver_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
                break;
        }
 
-       
+
        if ( !subkeypath ) {
                num_drivers = get_ntdrivers( &drivers, environments[env_index], version );
                for ( i=0; i<num_drivers; i++ )
                        regsubkey_ctr_addkey( subkeys, drivers[i] );
-                       
-               return regsubkey_ctr_numkeys( subkeys );        
-       }       
-       
+
+               return regsubkey_ctr_numkeys( subkeys );
+       }
+
        /* if anything else left, just say if has no subkeys */
-       
-       DEBUG(1,("key_driver_fetch_keys unhandled key [%s] (subkey == %s\n", 
+
+       DEBUG(1,("key_driver_fetch_keys unhandled key [%s] (subkey == %s\n",
                key, subkeypath ));
-       
+
        return 0;
 }
 
@@ -882,61 +896,61 @@ static void fill_in_driver_values( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3, REGVAL
        char *buffer = NULL;
        int buffer_size = 0;
        int i, length;
-       char *filename;
+       const char *filename;
        UNISTR2 data;
-       
+
        filename = dos_basename( info3->driverpath );
        init_unistr2( &data, filename, UNI_STR_TERMINATE);
-       regval_ctr_addvalue( values, "Driver", REG_SZ, (char*)data.buffer, 
+       regval_ctr_addvalue( values, "Driver", REG_SZ, (char*)data.buffer,
                data.uni_str_len*sizeof(uint16) );
-       
+
        filename = dos_basename( info3->configfile );
        init_unistr2( &data, filename, UNI_STR_TERMINATE);
        regval_ctr_addvalue( values, "Configuration File", REG_SZ, (char*)data.buffer, 
                data.uni_str_len*sizeof(uint16) );
-       
+
        filename = dos_basename( info3->datafile );
        init_unistr2( &data, filename, UNI_STR_TERMINATE);
-       regval_ctr_addvalue( values, "Data File", REG_SZ, (char*)data.buffer, 
+       regval_ctr_addvalue( values, "Data File", REG_SZ, (char*)data.buffer,
                data.uni_str_len*sizeof(uint16) );
-       
+
        filename = dos_basename( info3->helpfile );
        init_unistr2( &data, filename, UNI_STR_TERMINATE);
-       regval_ctr_addvalue( values, "Help File", REG_SZ, (char*)data.buffer, 
+       regval_ctr_addvalue( values, "Help File", REG_SZ, (char*)data.buffer,
                data.uni_str_len*sizeof(uint16) );
-       
+
        init_unistr2( &data, info3->defaultdatatype, UNI_STR_TERMINATE);
-       regval_ctr_addvalue( values, "Data Type", REG_SZ, (char*)data.buffer, 
+       regval_ctr_addvalue( values, "Data Type", REG_SZ, (char*)data.buffer,
                data.uni_str_len*sizeof(uint16) );
-       
+
        regval_ctr_addvalue( values, "Version", REG_DWORD, (char*)&info3->cversion, 
                sizeof(info3->cversion) );
-       
+
        if ( info3->dependentfiles ) {
-               /* place the list of dependent files in a single 
+               /* place the list of dependent files in a single
                   character buffer, separating each file name by
                   a NULL */
-                  
+
                for ( i=0; strcmp(info3->dependentfiles[i], ""); i++ ) {
                        /* strip the path to only the file's base name */
-               
+
                        filename = dos_basename( info3->dependentfiles[i] );
-                       
+
                        length = strlen(filename);
-               
+
                        buffer = (char *)SMB_REALLOC( buffer, buffer_size + (length + 1)*sizeof(uint16) );
                        if ( !buffer ) {
                                break;
                        }
-                       
+
                        init_unistr2( &data, filename, UNI_STR_TERMINATE);
                        memcpy( buffer+buffer_size, (char*)data.buffer, data.uni_str_len*sizeof(uint16) );
-               
+
                        buffer_size += (length + 1)*sizeof(uint16);
                }
-               
+
                /* terminated by double NULL.  Add the final one here */
-               
+
                buffer = (char *)SMB_REALLOC( buffer, buffer_size + 2 );
                if ( !buffer ) {
                        buffer_size = 0;
@@ -945,11 +959,11 @@ static void fill_in_driver_values( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3, REGVAL
                        buffer[buffer_size++] = '\0';
                }
        }
-       
+
        regval_ctr_addvalue( values, "Dependent Files",    REG_MULTI_SZ, buffer, buffer_size );
-               
+
        SAFE_FREE( buffer );
-       
+
        return;
 }
 
@@ -968,12 +982,12 @@ static int driver_arch_fetch_values( char *key, REGVAL_CTR *values )
        if (!reg_split_path( key, &base, &subkeypath )) {
                return -1;
        }
-       
+
        /* no values in 'Environments\Drivers\Windows NT x86' */
-       
-       if ( !subkeypath ) 
+
+       if ( !subkeypath )
                return 0;
-               
+
        /* We have the Architecture string and some subkey name:
           Currently we only support
           * Drivers
@@ -982,7 +996,7 @@ static int driver_arch_fetch_values( char *key, REGVAL_CTR *values )
           */
 
        fstrcpy( arch_environment, base );
-       
+
        keystr = subkeypath;
        if (!reg_split_path( keystr, &base, &subkeypath )) {
                return -1;
@@ -992,16 +1006,16 @@ static int driver_arch_fetch_values( char *key, REGVAL_CTR *values )
                return 0;
 
        /* only Drivers key can be left */
-               
+
        if ( !strequal(base, "Drivers") )
                return -1;
-                       
+
        if ( !subkeypath )
                return 0;
-       
+
        /* We know that we have Architechure\Drivers with some subkey name
           The subkey name has to be Version-XX */
-       
+
        keystr = subkeypath;
        if (!reg_split_path( keystr, &base, &subkeypath )) {
                return -1;
@@ -1009,34 +1023,34 @@ static int driver_arch_fetch_values( char *key, REGVAL_CTR *values )
 
        if ( !subkeypath )
                return 0;
-               
+
        version = atoi(&base[strlen(base)-1]);
 
        /* BEGIN PRINTER DRIVER NAME BLOCK */
-       
+
        keystr = subkeypath;
        if (!reg_split_path( keystr, &base, &subkeypath )) {
                return -1;
        }
-       
+
        /* don't go any deeper for now */
-       
+
        fstrcpy( driver, base );
-       
+
        w_result = get_a_printer_driver( &driver_ctr, 3, driver, arch_environment, version );
 
        if ( !W_ERROR_IS_OK(w_result) )
                return -1;
-               
-       fill_in_driver_values( driver_ctr.info_3, values ); 
-       
+
+       fill_in_driver_values( driver_ctr.info_3, values );
+
        free_a_printer_driver( driver_ctr, 3 );
 
        /* END PRINTER DRIVER NAME BLOCK */
 
-                                               
+
        DEBUG(8,("key_driver_fetch_values: Exit\n"));
-       
+
        return regval_ctr_numvals( values );
 }
 
@@ -1045,20 +1059,24 @@ static int driver_arch_fetch_values( char *key, REGVAL_CTR *values )
 
 static int key_driver_fetch_values( const char *key, REGVAL_CTR *values )
 {
-       char *keystr;
-       pstring subkey;
-       
+       char *keystr = NULL;
+       char *subkey = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
+
        DEBUG(8,("key_driver_fetch_values: Enter key => [%s]\n", key ? key : "NULL"));
 
        /* no values in the Environments key */
-       
-       if ( !(keystr = reg_remaining_path( key + strlen(KEY_ENVIRONMENTS) )) )
+
+       if (!(keystr = reg_remaining_path(ctx, key + strlen(KEY_ENVIRONMENTS))))
                return 0;
-       
-       pstrcpy( subkey, keystr);
-       
+
+       subkey = talloc_strdup(ctx, keystr);
+       if (!subkey) {
+               return 0;
+       }
+
        /* pass off to handle subkeys */
-       
+
        return driver_arch_fetch_values( subkey, values );
 }
 
@@ -1069,11 +1087,11 @@ static int key_driver_fetch_values( const char *key, REGVAL_CTR *values )
  *********************************************************************/
 
 static int key_print_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
-{      
+{
        int key_len = strlen(key);
-       
+
        /* no keys below 'Print' handled here */
-       
+
        if ( (key_len != strlen(KEY_CONTROL_PRINT)) && (key_len != strlen(KEY_WINNT_PRINT)) )
                return -1;
 
@@ -1081,14 +1099,14 @@ static int key_print_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
        regsubkey_ctr_addkey( subkeys, "Monitors" );
        regsubkey_ctr_addkey( subkeys, "Forms" );
        regsubkey_ctr_addkey( subkeys, "Printers" );
-       
+
        return regsubkey_ctr_numkeys( subkeys );
 }
 
 /**********************************************************************
  *********************************************************************
  ** Structure to hold dispatch table of ops for various printer keys.
- ** Make sure to always store deeper keys along the same path first so 
+ ** Make sure to always store deeper keys along the same path first so
  ** we ge a more specific match.
  *********************************************************************
  *********************************************************************/
@@ -1096,16 +1114,16 @@ static int key_print_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys )
 static struct reg_dyn_tree print_registry[] = {
 /* just pass the monitor onto the registry tdb */
 { KEY_MONITORS,
-       &regdb_fetch_keys, 
+       &regdb_fetch_keys,
        &regdb_store_keys,
        &regdb_fetch_values,
        &regdb_store_values },
-{ KEY_FORMS, 
-       &key_forms_fetch_keys, 
-       NULL, 
+{ KEY_FORMS,
+       &key_forms_fetch_keys,
+       NULL,
        &key_forms_fetch_values,
        NULL },
-{ KEY_CONTROL_PRINTERS, 
+{ KEY_CONTROL_PRINTERS,
        &key_printers_fetch_keys,
        &key_printers_store_keys,
        &key_printers_fetch_values,
@@ -1126,11 +1144,11 @@ static struct reg_dyn_tree print_registry[] = {
        &key_printers_fetch_values,
        &key_printers_store_values },
 { KEY_PORTS,
-       &regdb_fetch_keys, 
+       &regdb_fetch_keys,
        &regdb_store_keys,
        &regdb_fetch_values,
        &regdb_store_values },
-       
+
 { NULL, NULL, NULL, NULL, NULL }
 };
 
@@ -1146,22 +1164,29 @@ static struct reg_dyn_tree print_registry[] = {
  -1 on failure
  **********************************************************************/
 
-static int match_registry_path( const char *key )
+static int match_registry_path(const char *key)
 {
        int i;
-       pstring path;
-       
+       char *path = NULL;
+       TALLOC_CTX *ctx = talloc_tos();
+
        if ( !key )
                return -1;
 
-       pstrcpy( path, key );
-       normalize_reg_path( path );
-       
+       path = talloc_strdup(ctx, key);
+       if (!path) {
+               return -1;
+       }
+       path = normalize_reg_path(ctx, path);
+       if (!path) {
+               return -1;
+       }
+
        for ( i=0; print_registry[i].path; i++ ) {
-               if ( strncmp( path, print_registry[i].path, strlen(print_registry[i].path) ) == 0 )
+               if (strncmp( path, print_registry[i].path, strlen(print_registry[i].path) ) == 0 )
                        return i;
        }
-       
+
        return -1;
 }
 
@@ -1171,13 +1196,13 @@ static int match_registry_path( const char *key )
 static int regprint_fetch_reg_keys( const char *key, REGSUBKEY_CTR *subkeys )
 {
        int i = match_registry_path( key );
-       
+
        if ( i == -1 )
                return -1;
-               
+
        if ( !print_registry[i].fetch_subkeys )
                return -1;
-               
+
        return print_registry[i].fetch_subkeys( key, subkeys );
 }
 
@@ -1187,13 +1212,13 @@ static int regprint_fetch_reg_keys( const char *key, REGSUBKEY_CTR *subkeys )
 static bool regprint_store_reg_keys( const char *key, REGSUBKEY_CTR *subkeys )
 {
        int i = match_registry_path( key );
-       
+
        if ( i == -1 )
                return False;
-       
+
        if ( !print_registry[i].store_subkeys )
                return False;
-               
+
        return print_registry[i].store_subkeys( key, subkeys );
 }
 
@@ -1203,16 +1228,16 @@ static bool regprint_store_reg_keys( const char *key, REGSUBKEY_CTR *subkeys )
 static int regprint_fetch_reg_values( const char *key, REGVAL_CTR *values )
 {
        int i = match_registry_path( key );
-       
+
        if ( i == -1 )
                return -1;
-       
-       /* return 0 values by default since we know the key had 
+
+       /* return 0 values by default since we know the key had
           to exist because the client opened a handle */
-          
+
        if ( !print_registry[i].fetch_values )
                return 0;
-               
+
        return print_registry[i].fetch_values( key, values );
 }
 
@@ -1222,20 +1247,20 @@ static int regprint_fetch_reg_values( const char *key, REGVAL_CTR *values )
 static bool regprint_store_reg_values( const char *key, REGVAL_CTR *values )
 {
        int i = match_registry_path( key );
-       
+
        if ( i == -1 )
                return False;
-       
+
        if ( !print_registry[i].store_values )
                return False;
-               
+
        return print_registry[i].store_values( key, values );
 }
 
-/* 
+/*
  * Table of function pointers for accessing printing data
  */
+
 REGISTRY_OPS printing_ops = {
        regprint_fetch_reg_keys,
        regprint_fetch_reg_values,
@@ -1243,5 +1268,3 @@ REGISTRY_OPS printing_ops = {
        regprint_store_reg_values,
        NULL, NULL, NULL
 };
-
-
index 7eb3c2a3a5aaa9fe88a9fba7791c05dcd7eefd2f..cd0982d09a741b516736d8db4c521b5b2f9959a3 100644 (file)
@@ -7,12 +7,12 @@
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
  Utility function for splitting the base path of a registry path off
  by setting base and new_path to the apprapriate offsets withing the
  path.
+
  WARNING!!  Does modify the original string!
  ***********************************************************************/
 
-bool reg_split_path( char *path, char **base, char **new_path )
+bool reg_split_path(char *path, char **base, char **new_path)
 {
        char *p;
-       
+
        *new_path = *base = NULL;
-       
-       if ( !path)
-               return False;
-       
+
+       if (!path) {
+               return false;
+       }
        *base = path;
-       
-       p = strchr( path, '\\' );
-       
+
+       p = strchr(path, '\\');
+
        if ( p ) {
                *p = '\0';
                *new_path = p+1;
        }
-       
-       return True;
-}
 
+       return true;
+}
 
 /***********************************************************************
  Utility function for splitting the base path of a registry path off
  by setting base and new_path to the appropriate offsets withing the
  path.
+
  WARNING!!  Does modify the original string!
  ***********************************************************************/
 
-bool reg_split_key( char *path, char **base, char **key )
+bool reg_split_key(char *path, char **base, char **key)
 {
        char *p;
-       
+
        *key = *base = NULL;
-       
-       if ( !path)
-               return False;
-       
+
+       if (!path) {
+               return false;
+       }
+
        *base = path;
-       
-       p = strrchr( path, '\\' );
-       
-       if ( p ) {
+
+       p = strrchr(path, '\\');
+
+       if (p) {
                *p = '\0';
                *key = p+1;
        }
-       
-       return True;
-}
 
+       return true;
+}
 
 /**********************************************************************
- The full path to the registry key is used as database after the 
+ The full path to the registry key is used as database after the
  \'s are converted to /'s.  Key string is also normalized to UPPER
- case. 
+ case.
 **********************************************************************/
 
-void normalize_reg_path( pstring keyname )
+char *normalize_reg_path(TALLOC_CTX *ctx, const char *keyname )
 {
-       pstring_sub( keyname, "\\", "/" );
-       strupper_m( keyname  );
+       char *nkeyname = talloc_string_sub(ctx, keyname, "\\", "/");
+       if (!nkeyname) {
+               return NULL;
+       }
+       strupper_m(nkeyname);
+       return nkeyname;
 }
 
 /**********************************************************************
  move to next non-delimter character
 *********************************************************************/
 
-char* reg_remaining_path( const char *key )
+char *reg_remaining_path(TALLOC_CTX *ctx, const char *key)
 {
-       pstring new_path;
-       char *p;
-       
-       if ( !key || !*key )
+       char *new_path = NULL;
+       char *p = NULL;
+
+       if (!key || !*key) {
                return NULL;
+       }
 
-       pstrcpy( new_path, key );
+       new_path = talloc_strdup(ctx, key);
+       if (!new_path) {
+               return NULL;
+       }
        /* normalize_reg_path( new_path ); */
-       
-       if ( !(p = strchr( new_path, '\\' )) ) 
-       {
-               if ( !(p = strchr( new_path, '/' )) )
+       if (!(p = strchr(new_path, '\\')) ) {
+               if (!(p = strchr( new_path, '/'))) {
                        p = new_path;
-               else 
+               } else {
                        p++;
-       }
-       else
+               }
+       } else {
                p++;
-               
-       return talloc_strdup(talloc_tos(), p);
+       }
+
+       return p;
 }
 
 /**********************************************************************
@@ -135,14 +141,14 @@ int regval_convert_multi_sz( uint16 *multi_string, size_t byte_len, char ***valu
        fstring buffer;
        uint16 *wp;
        size_t multi_len = byte_len / 2;
-       
+
        if ( !multi_string || !values )
                return 0;
 
        *values = NULL;
 
        /* just count the NULLs */
-       
+
        for ( i=0; (i<multi_len-1) && !(multi_string[i]==0x0 && multi_string[i+1]==0x0); i++ ) {
                /* peek ahead */
                if ( multi_string[i+1] == 0x0 )
@@ -151,29 +157,29 @@ int regval_convert_multi_sz( uint16 *multi_string, size_t byte_len, char ***valu
 
        if ( num_strings == 0 )
                return 0;
-       
+
        if ( !(sz = TALLOC_ARRAY( NULL, char*, num_strings+1 )) ) {
                DEBUG(0,("reg_convert_multi_sz: talloc() failed!\n"));
                return -1;
        }
 
        wp = multi_string;
-       
+
        for ( i=0; i<num_strings; i++ ) {
                rpcstr_pull( buffer, wp, sizeof(buffer), -1, STR_TERMINATE );
                sz[i] = talloc_strdup( sz, buffer );
-               
+
                /* skip to the next string NULL and then one more */
                while ( *wp )
                        wp++;
                wp++;
        }
-       
+
        /* tag the array off with an empty string */
        sz[i] = '\0';
-       
+
        *values = sz;
-       
+
        return num_strings;
 }
 
@@ -190,22 +196,22 @@ size_t regval_build_multi_sz( char **values, uint16 **buffer )
 
        if ( !values || !buffer )
                return 0;
-       
+
        /* go ahead and alloc some space */
-       
+
        if ( !(buf = TALLOC_ARRAY( NULL, uint16, 2 )) ) {
                DEBUG(0,("regval_build_multi_sz: talloc() failed!\n"));
                return 0;
        }
-       
+
        for ( i=0; values[i]; i++ ) {
                ZERO_STRUCT( sz );
                /* DEBUG(0,("regval_build_multi_sz: building [%s]\n",values[i])); */
                init_unistr2( &sz, values[i], UNI_STR_TERMINATE );
-               
+
                /* Alloc some more memory.  Always add one one to account for the 
                   double NULL termination */
-                  
+
                b = TALLOC_REALLOC_ARRAY( NULL, buf, uint16, buf_size+sz.uni_str_len+1 );
                if ( !b ) {
                        DEBUG(0,("regval_build_multi_sz: talloc() reallocation error!\n"));
@@ -214,15 +220,15 @@ size_t regval_build_multi_sz( char **values, uint16 **buffer )
                }
                buf = b;
 
-               /* copy the unistring2 buffer and increment the size */ 
+               /* copy the unistring2 buffer and increment the size */
                /* dump_data(1,sz.buffer,sz.uni_str_len*2); */
                memcpy( buf+buf_size, sz.buffer, sz.uni_str_len*2 );
                buf_size += sz.uni_str_len;
-               
+
                /* cleanup rather than leaving memory hanging around */
                TALLOC_FREE( sz.buffer );
        }
-       
+
        buf[buf_size++] = 0x0;
 
        *buffer = buf;
@@ -230,5 +236,3 @@ size_t regval_build_multi_sz( char **values, uint16 **buffer )
        /* return number of bytes */
        return buf_size*2;
 }
-
-