The branch, v3-2-test has been updated via 331c0d6216e1a1607a49ed7eb4078e10138ec16a (commit) from 3088bc76f1ceffecaa5aea039be79973c9876f0c (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test - Log ----------------------------------------------------------------- commit 331c0d6216e1a1607a49ed7eb4078e10138ec16a Author: Jeremy Allison <[EMAIL PROTECTED]> Date: Mon Nov 26 17:24:56 2007 -0800 Remove pstrings from nsswitch/ and registry/ Jeremy. ----------------------------------------------------------------------- Summary of changes: source/nsswitch/wb_common.c | 41 ++-- source/registry/reg_cachehook.c | 26 ++- source/registry/reg_db.c | 443 ++++++++++++++++++++++---------------- source/registry/reg_dynamic.c | 43 +++-- source/registry/reg_eventlog.c | 151 ++++++++------ source/registry/reg_objects.c | 10 +- source/registry/reg_perfcount.c | 50 +++-- source/registry/reg_printing.c | 393 ++++++++++++++++++---------------- source/registry/reg_util.c | 138 +++++++------ 9 files changed, 723 insertions(+), 572 deletions(-) Changeset truncated at 500 lines: diff --git a/source/nsswitch/wb_common.c b/source/nsswitch/wb_common.c index 2ae85dc..49a2935 100644 --- a/source/nsswitch/wb_common.c +++ b/source/nsswitch/wb_common.c @@ -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; } diff --git a/source/registry/reg_cachehook.c b/source/registry/reg_cachehook.c index 739faca..289d4e5 100644 --- a/source/registry/reg_cachehook.c +++ b/source/registry/reg_cachehook.c @@ -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 ); } diff --git a/source/registry/reg_db.c b/source/registry/reg_db.c index 4947b2a..7c4ea18 100644 --- a/source/registry/reg_db.c +++ b/source/registry/reg_db.c @@ -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 ) -- Samba Shared Repository