Author: jerry
Date: 2005-06-03 05:32:46 +0000 (Fri, 03 Jun 2005)
New Revision: 7209

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7209

Log:
add initial frontend for RegRestoreKey(); now need to fill in the backend store 
key/value functions in reg_printing.c
Modified:
   trunk/source/include/doserr.h
   trunk/source/registry/reg_cachehook.c
   trunk/source/rpc_server/srv_reg_nt.c


Changeset:
Modified: trunk/source/include/doserr.h
===================================================================
--- trunk/source/include/doserr.h       2005-06-03 05:29:41 UTC (rev 7208)
+++ trunk/source/include/doserr.h       2005-06-03 05:32:46 UTC (rev 7209)
@@ -185,6 +185,9 @@
 #define WERR_INVALID_OWNER W_ERROR(1307)
 #define WERR_IO_PENDING W_ERROR(997)
 #define WERR_CAN_NOT_COMPLETE W_ERROR(1003)
+#define WERR_REG_CORRUPT W_ERROR(1015)
+#define WERR_REG_IO_FAILURE W_ERROR(1016)
+#define WERR_REG_FILE_INVALID W_ERROR(1017)
 #define WERR_NO_SUCH_SERVICE W_ERROR(1060)
 #define WERR_INVALID_SERVICE_CONTROL W_ERROR(1052)
 #define WERR_INVALID_SECURITY_DESCRIPTOR W_ERROR(1338)

Modified: trunk/source/registry/reg_cachehook.c
===================================================================
--- trunk/source/registry/reg_cachehook.c       2005-06-03 05:29:41 UTC (rev 
7208)
+++ trunk/source/registry/reg_cachehook.c       2005-06-03 05:32:46 UTC (rev 
7209)
@@ -67,7 +67,7 @@
  Initialize the cache tree
  *********************************************************************/
 
-REGISTRY_HOOK* reghook_cache_find( char *keyname )
+REGISTRY_HOOK* reghook_cache_find( const char *keyname )
 {
        char *key;
        int len;

Modified: trunk/source/rpc_server/srv_reg_nt.c
===================================================================
--- trunk/source/rpc_server/srv_reg_nt.c        2005-06-03 05:29:41 UTC (rev 
7208)
+++ trunk/source/rpc_server/srv_reg_nt.c        2005-06-03 05:32:46 UTC (rev 
7209)
@@ -763,17 +763,115 @@
 }
 
 /*******************************************************************
+ Note: topkeypaty is the *full* path that this *key will be 
+ loaded into (including the name of the key)
  ********************************************************************/
 
-static WERROR restore_registry_key ( REGISTRY_KEY *krecord, const char *fname )
+static WERROR reg_load_tree( REGF_FILE *regfile, const char *topkeypath,
+                             REGF_NK_REC *key )
 {
+       REGF_NK_REC *subkey;
+       REGISTRY_KEY registry_key;
+       REGVAL_CTR values;
+       REGSUBKEY_CTR subkeys;
+       int i;
+       pstring path;
+       WERROR result = WERR_OK;
+       
+       /* initialize the REGISTRY_KEY structure */
+       
+       if ( !(registry_key.hook = reghook_cache_find(topkeypath)) ) {
+               DEBUG(0,("reg_load_tree: Failed to assigned a REGISTRY_HOOK to 
[%s]\n",
+                       topkeypath ));
+               return WERR_BADFILE;
+       }
+       pstrcpy( registry_key.name, topkeypath );
+       
+       /* now start parsing the values and subkeys */
 
-       return WERR_OK;
+       ZERO_STRUCT( values );
+       ZERO_STRUCT( subkeys );
+
+       regsubkey_ctr_init( &subkeys );
+       regval_ctr_init( &values );
+       
+       /* copy values into the REGVAL_CTR */
+       
+       for ( i=0; i<key->num_values; i++ ) {
+               regval_ctr_addvalue( &values, key->values[i].valuename, 
key->values[i].type,
+                       key->values[i].data, (key->values[i].data_size & 
~VK_DATA_IN_OFFSET) );
+       }
+
+       /* copy subkeys into the REGSUBKEY_CTR */
+       
+       key->subkey_index = 0;
+       while ( (subkey = regfio_fetch_subkey( regfile, key )) ) {
+               regsubkey_ctr_addkey( &subkeys, subkey->keyname );
+       }
+       
+       /* write this key and values out */
+       
+       if ( !store_reg_values( &registry_key, &values ) 
+               || !store_reg_keys( &registry_key, &subkeys ) )
+       {
+               DEBUG(0,("reg_load_tree: Failed to load %s!\n", topkeypath));
+               result = WERR_REG_IO_FAILURE;
+       }
+       
+       regval_ctr_destroy( &values );
+       regsubkey_ctr_destroy( &subkeys );
+       
+       if ( !W_ERROR_IS_OK(result) )
+               return result;
+       
+       /* now continue to load each subkey registry tree */
+
+       key->subkey_index = 0;
+       while ( (subkey = regfio_fetch_subkey( regfile, key )) ) {
+               pstr_sprintf( path, "%s%s%s", topkeypath, "\\", subkey->keyname 
);
+               result = reg_load_tree( regfile, path, subkey );
+               if ( !W_ERROR_IS_OK(result) )
+                       break;
+       }
+
+       return result;
 }
 
 /*******************************************************************
  ********************************************************************/
 
+static WERROR restore_registry_key ( REGISTRY_KEY *krecord, const char *fname )
+{
+       REGF_FILE *regfile;
+       REGF_NK_REC *rootkey;
+       WERROR result;
+               
+       /* open the registry file....fail if the file already exists */
+       
+       if ( !(regfile = regfio_open( fname, (O_RDONLY), 0 )) ) {
+                DEBUG(0,("backup_registry_key: failed to open \"%s\" (%s)\n", 
+                       fname, strerror(errno) ));
+               return ( ntstatus_to_werror(map_nt_error_from_unix( errno )) );
+        }
+       
+       /* get the rootkey from the regf file and then load the tree
+          via recursive calls */
+          
+       if ( !(rootkey = regfio_rootkey( regfile )) )
+               return WERR_REG_FILE_INVALID;
+       
+       result = reg_load_tree( regfile, krecord->name, rootkey );
+               
+       /* cleanup */
+       
+       regfio_close( regfile );
+       
+       return result;
+}
+
+/*******************************************************************
+ ********************************************************************/
+
 WERROR _reg_restore_key(pipes_struct *p, REG_Q_RESTORE_KEY  *q_u, 
REG_R_RESTORE_KEY *r_u)
 {
        REGISTRY_KEY    *regkey = find_regkey_index_by_hnd( p, &q_u->pol );

Reply via email to