r20020: Arglll... eventlogadm links against reg_db but not the rest of the registry
authorVolker Lendecke <vlendec@samba.org>
Sun, 3 Dec 2006 17:34:11 +0000 (17:34 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:16:21 +0000 (12:16 -0500)
stuff. Revert the last change.

This needs better fixing.

Volker
(This used to be commit ad1e00430bf5c4130023d30e9c8266ecdc640d2b)

source3/registry/reg_db.c
source3/registry/reg_frontend.c
source3/rpc_server/srv_srvsvc_nt.c

index e0838a2b71bbbdc2c3398d31e16f66f5b971cd75..345193716e1825459215ed4f9a6ed229e5a38185 100644 (file)
@@ -41,10 +41,6 @@ static int tdb_refcount;
    the reg_printing backend onto the last component of the path (see 
    KEY_PRINTING_2K in include/rpc_reg.h)   --jerry */
 
-static const char *builtin_registry_hives[] = {
-       "HKLM", "HKU", "HKCR", "HKPD", "HKPT", NULL
-};
-
 static const char *builtin_registry_paths[] = {
        KEY_PRINTING_2K,
        KEY_PRINTING_PORTS,
@@ -59,6 +55,10 @@ static const char *builtin_registry_paths[] = {
        "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\DefaultUserConfiguration",
        "HKLM\\SYSTEM\\CurrentControlSet\\Services\\TcpIp\\Parameters",
        "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Netlogon\\Parameters",
+       "HKU",
+       "HKCR",
+       "HKPD",
+       "HKPT",
         NULL };
 
 struct builtin_regkey_value {
@@ -91,98 +91,105 @@ static struct builtin_regkey_value builtin_registry_values[] = {
  
 static BOOL init_registry_data( void )
 {
+       pstring path, base, remaining;
+       fstring keyname, subkeyname;
+       REGSUBKEY_CTR *subkeys;
+       REGVAL_CTR *values;
        int i;
-
-       for (i=0; builtin_registry_hives[i] != NULL; i++) {
-               REGSUBKEY_CTR *subkeys;
-
-               if (!(subkeys = TALLOC_ZERO_P(NULL, REGSUBKEY_CTR))) {
-                       DEBUG(0, ("talloc failed\n"));
-                       return False;
-               }
-               regdb_fetch_keys(builtin_registry_hives[i], subkeys);
-               if (!regdb_store_keys(builtin_registry_hives[i], subkeys)) {
-                       TALLOC_FREE(subkeys);
-                       return False;
-               }
-               TALLOC_FREE(subkeys);
-       }
+       const char *p, *p2;
+       UNISTR2 data;
        
        /* loop over all of the predefined paths and add each component */
        
        for ( i=0; builtin_registry_paths[i] != NULL; i++ ) {
-               WERROR err;
-               struct registry_key *key;
-
-               DEBUG(10,("init_registry_data: Adding [%s]\n",
-                         builtin_registry_paths[i]));
-
-               err = reg_create_path(NULL, builtin_registry_paths[i],
-                                     REG_KEY_READ, get_root_nt_token(),
-                                     NULL, &key);
-               if (!W_ERROR_IS_OK(err)) {
-                       DEBUG(6, ("reg_create_path failed for %s: %s\n",
-                                 builtin_registry_paths[i],
-                                 dos_errstr(err)));
-                       return False;
+
+               DEBUG(6,("init_registry_data: Adding [%s]\n", builtin_registry_paths[i]));
+
+               pstrcpy( path, builtin_registry_paths[i] );
+               pstrcpy( base, "" );
+               p = path;
+               
+               while ( next_token(&p, keyname, "\\", sizeof(keyname)) ) {
+               
+                       /* build up the registry path from the components */
+                       
+                       if ( *base )
+                               pstrcat( base, "\\" );
+                       pstrcat( base, keyname );
+                       
+                       /* get the immediate subkeyname (if we have one ) */
+                       
+                       *subkeyname = '\0';
+                       if ( *p ) {
+                               pstrcpy( remaining, p );
+                               p2 = remaining;
+                               
+                               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 
+                          subkeys already present */
+                       
+                       if ( !(subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR )) ) {
+                               DEBUG(0,("talloc() failure!\n"));
+                               return False;
+                       }
+
+                       regdb_fetch_keys( base, subkeys );
+                       if ( *subkeyname ) 
+                               regsubkey_ctr_addkey( subkeys, subkeyname );
+                       if ( !regdb_store_keys( base, subkeys ))
+                               return False;
+                       
+                       TALLOC_FREE( subkeys );
                }
-               TALLOC_FREE(key);
        }
 
        /* loop over all of the predefined values and add each component */
        
        for ( i=0; builtin_registry_values[i].path != NULL; i++ ) {
-               WERROR err;
-               struct registry_key *key;
-               struct registry_value *pval;
-
-               err = reg_open_path(NULL, builtin_registry_values[i].path,
-                                   REG_KEY_WRITE, get_root_nt_token(), &key);
-               if (!W_ERROR_IS_OK(err)) {
-                       DEBUG(10, ("Could not open key %s: %s\n",
-                                  builtin_registry_values[i].path,
-                                  dos_errstr(err)));
+               if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
+                       DEBUG(0,("talloc() failure!\n"));
                        return False;
                }
 
-               if (W_ERROR_IS_OK(reg_queryvalue(
-                                         key, key,
-                                         builtin_registry_values[i].valuename,
-                                         &pval))) {
-                       /* preserve existing values across restarts.  Only add
-                        * new ones */
-                       TALLOC_FREE(key);
-                       continue;
-               }
+               regdb_fetch_values( builtin_registry_values[i].path, values );
 
-               err = WERR_OK;
-
-               switch( builtin_registry_values[i].type ) {
-               case REG_DWORD:
-                       err = reg_set_dword(
-                               key, builtin_registry_values[i].valuename,
-                               builtin_registry_values[i].data.dw_value);
-                       break;
-               case REG_SZ:
-                       err = reg_set_sz(
-                               key, builtin_registry_values[i].valuename,
-                               builtin_registry_values[i].data.string);
-                       break;
-               default:
-                       DEBUG(0,("init_registry_data: invalid value type in "
-                                "builtin_registry_values [%d]\n",
-                                builtin_registry_values[i].type));
-               }
+               /* preserve existing values across restarts.  Only add new ones */
 
-               if (!W_ERROR_IS_OK(err)) {
-                       DEBUG(0, ("setting regvalue %s[%s] failed: %s\n",
-                                 builtin_registry_values[i].path,
-                                 builtin_registry_values[i].valuename,
-                                 dos_errstr(err)));
-                       return False;
+               if ( !regval_ctr_key_exists( values, builtin_registry_values[i].valuename ) ) 
+               {
+                       switch( builtin_registry_values[i].type ) {
+                       case REG_DWORD:
+                               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, 
+                                                    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(key);
+               
+               TALLOC_FREE( values );
        }
        
        return True;
index 1f6b2856534142bcbe316e2074af39a4aae83b50..3bb88eaf474ef1ae24299dfbe8009565dcad53a6 100644 (file)
@@ -93,16 +93,15 @@ BOOL init_registry( void )
        int i;
        
        
-       /* build the cache tree of registry hooks */
-       
-       reghook_cache_init();
-       
        if ( !regdb_init() ) {
-               DEBUG(0,("init_registry: failed to initialize the registry "
-                        "tdb!\n"));
+               DEBUG(0,("init_registry: failed to initialize the registry tdb!\n"));
                return False;
        }
 
+       /* build the cache tree of registry hooks */
+       
+       reghook_cache_init();
+       
        for ( i=0; reg_hooks[i].keyname; i++ ) {
                if ( !reghook_cache_add(&reg_hooks[i]) )
                        return False;
@@ -643,24 +642,3 @@ WERROR reg_delete_path(const struct nt_user_token *token,
        TALLOC_FREE(hive);
        return err;
 }
-
-WERROR reg_set_dword(struct registry_key *key, const char *valuename,
-                    uint32 value)
-{
-       struct registry_value val;
-       ZERO_STRUCT(val);
-       val.type = REG_DWORD;
-       val.v.dword = value;
-       return reg_setvalue(key, valuename, &val);
-}
-
-WERROR reg_set_sz(struct registry_key *key, const char *valuename,
-                 const char *value)
-{
-       struct registry_value val;
-       ZERO_STRUCT(val);
-       val.type = REG_SZ;
-       val.v.sz.str = CONST_DISCARD(char *, value);
-       val.v.sz.len = strlen(value)+1;
-       return reg_setvalue(key, valuename, &val);
-}
index 1b86fa349f22640d86cd244332177a806571ce20..abfa794518c00504d5b5d6a32f1abf394bf54f39 100644 (file)
@@ -1375,10 +1375,18 @@ char *valid_share_pathname(char *dos_pathname)
 static void setval_helper(struct registry_key *key, const char *name,
                          const char *value, WERROR *err)
 {
+       struct registry_value val;
+
        if (!W_ERROR_IS_OK(*err)) {
                return;
        }
-       *err = reg_set_sz(key, name, value);
+
+       ZERO_STRUCT(val);
+       val.type = REG_SZ;
+       val.v.sz.str = CONST_DISCARD(char *, value);
+       val.v.sz.len = strlen(value)+1;
+
+       *err = reg_setvalue(key, name, &val);
 }
 
 static WERROR add_share(const char *share_name, const char *path,