1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

Move the implementation of _winreg_RestoreKey to reg_api.c

This removes the internals of reg_api from srv_winreg_nt.c entirely,
only reg_api is used there, now. This enlarges the dependencies of
reg_api somewhat now since it adds regfio. But this can be separated
out later. The current goal is to achieve a complete use of reg_api.

Michael
This commit is contained in:
Michael Adam 2008-02-15 15:31:31 +01:00
parent bf6340d00d
commit 2222acbac9
3 changed files with 132 additions and 127 deletions

View File

@ -459,7 +459,8 @@ REGISTRY_OBJ = registry/reg_init_full.o registry/reg_cachehook.o \
registry/reg_dispatcher.o \
$(REGISTRY_BACKENDS) \
$(UTIL_REG_API_OBJ) \
$(REG_INIT_SMBCONF_OBJ)
$(REG_INIT_SMBCONF_OBJ) \
$(REGFIO_OBJ)
# objects to be used when not all of the registry code should be
# loaded but only the portion needed by reg_api, typically for
@ -474,7 +475,8 @@ REG_API_OBJ = registry/reg_api.o \
\
lib/util_nttoken.o \
$(UTIL_REG_API_OBJ) \
$(REG_INIT_SMBCONF_OBJ)
$(REG_INIT_SMBCONF_OBJ) \
$(REGFIO_OBJ)
RPC_LSA_OBJ = rpc_server/srv_lsa.o rpc_server/srv_lsa_nt.o librpc/gen_ndr/srv_lsa.o
@ -489,8 +491,7 @@ RPC_SAMR_OBJ = rpc_server/srv_samr_nt.o \
RPC_INITSHUTDOWN_OBJ = librpc/gen_ndr/srv_initshutdown.o rpc_server/srv_initshutdown_nt.o
RPC_REG_OBJ = rpc_server/srv_winreg_nt.o \
librpc/gen_ndr/srv_winreg.o \
$(REGFIO_OBJ)
librpc/gen_ndr/srv_winreg.o
RPC_DSSETUP_OBJ = rpc_server/srv_dssetup_nt.o librpc/gen_ndr/srv_dssetup.o
@ -810,7 +811,7 @@ NET_OBJ = $(NET_OBJ1) $(PARAM_WITHOUT_REG_OBJ) $(SECRETS_OBJ) $(LIBSMB_OBJ) \
$(LIBMSRPC_OBJ) $(LIBMSRPC_GEN_OBJ) \
$(LIBADS_OBJ) $(LIBADS_SERVER_OBJ) $(POPT_LIB_OBJ) \
$(SMBLDAP_OBJ) $(DCUTIL_OBJ) $(SERVER_MUTEX_OBJ) \
$(AFS_OBJ) $(AFS_SETTOKEN_OBJ) $(REGFIO_OBJ) $(READLINE_OBJ) \
$(AFS_OBJ) $(AFS_SETTOKEN_OBJ) $(READLINE_OBJ) \
$(LDB_OBJ) $(LIBGPO_OBJ) @BUILD_INIPARSER@ $(DISPLAY_SEC_OBJ) \
$(REG_API_OBJ) $(DISPLAY_DSDCINFO_OBJ) @LIBNETAPI_STATIC@ $(LIBNET_OBJ) \
$(WBCOMMON_OBJ) @LIBWBCLIENT_STATIC@

View File

@ -43,7 +43,7 @@
* 0x10 winreg_QueryInfoKey reg_queryinfokey
* 0x11 winreg_QueryValue reg_queryvalue
* 0x12 winreg_ReplaceKey
* 0x13 winreg_RestoreKey
* 0x13 winreg_RestoreKey reg_restorekey
* 0x14 winreg_SaveKey reg_savekey
* 0x15 winreg_SetKeySecurity reg_setkeysecurity
* 0x16 winreg_SetValue reg_setvalue
@ -697,6 +697,130 @@ WERROR reg_getversion(uint32_t *version)
return WERR_OK;
}
/*******************************************************************
Note: topkeypat is the *full* path that this *key will be
loaded into (including the name of the key)
********************************************************************/
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;
char *path = NULL;
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;
}
registry_key.name = talloc_strdup( regfile->mem_ctx, topkeypath );
if ( !registry_key.name ) {
DEBUG(0,("reg_load_tree: Talloc failed for reg_key.name!\n"));
return WERR_NOMEM;
}
/* now start parsing the values and subkeys */
if ( !(subkeys = TALLOC_ZERO_P( regfile->mem_ctx, REGSUBKEY_CTR )) )
return WERR_NOMEM;
if ( !(values = TALLOC_ZERO_P( subkeys, REGVAL_CTR )) )
return WERR_NOMEM;
/* 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,
(char*)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;
}
TALLOC_FREE( 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 )) ) {
path = talloc_asprintf(regfile->mem_ctx,
"%s\\%s",
topkeypath,
subkey->keyname);
if (!path) {
return WERR_NOMEM;
}
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,("restore_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 )) ) {
regfio_close( regfile );
return WERR_REG_FILE_INVALID;
}
result = reg_load_tree( regfile, krecord->name, rootkey );
/* cleanup */
regfio_close( regfile );
return result;
}
WERROR reg_restorekey(struct registry_key *key, const char *fname)
{
return restore_registry_key(key->key, fname);
}
/********************************************************************
********************************************************************/

View File

@ -21,7 +21,6 @@
/* Implementation of registry functions. */
#include "includes.h"
#include "regfio.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
@ -651,125 +650,6 @@ static int validate_reg_filename(TALLOC_CTX *ctx, char **pp_fname )
return (snum < num_services) ? snum : -1;
}
/*******************************************************************
Note: topkeypat is the *full* path that this *key will be
loaded into (including the name of the key)
********************************************************************/
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;
char *path = NULL;
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;
}
registry_key.name = talloc_strdup( regfile->mem_ctx, topkeypath );
if ( !registry_key.name ) {
DEBUG(0,("reg_load_tree: Talloc failed for reg_key.name!\n"));
return WERR_NOMEM;
}
/* now start parsing the values and subkeys */
if ( !(subkeys = TALLOC_ZERO_P( regfile->mem_ctx, REGSUBKEY_CTR )) )
return WERR_NOMEM;
if ( !(values = TALLOC_ZERO_P( subkeys, REGVAL_CTR )) )
return WERR_NOMEM;
/* 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,
(char*)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;
}
TALLOC_FREE( 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 )) ) {
path = talloc_asprintf(regfile->mem_ctx,
"%s\\%s",
topkeypath,
subkey->keyname);
if (!path) {
return WERR_NOMEM;
}
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,("restore_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 )) ) {
regfio_close( regfile );
return WERR_REG_FILE_INVALID;
}
result = reg_load_tree( regfile, krecord->name, rootkey );
/* cleanup */
regfio_close( regfile );
return result;
}
/*******************************************************************
********************************************************************/
@ -804,7 +684,7 @@ WERROR _winreg_RestoreKey(pipes_struct *p, struct winreg_RestoreKey *r)
DEBUG(2,("_winreg_RestoreKey: Restoring [%s] from %s in share %s\n",
regkey->key->name, fname, lp_servicename(snum) ));
return restore_registry_key( regkey->key, fname );
return reg_restorekey(regkey, fname);
}
WERROR _winreg_SaveKey(pipes_struct *p, struct winreg_SaveKey *r)