2007-09-14 02:41:04 +04:00
/*
2002-08-30 15:03:44 +04:00
* Unix SMB / CIFS implementation .
2005-05-23 20:25:31 +04:00
* Virtual Windows Registry Layer
* Copyright ( C ) Gerald Carter 2002 - 2005
2002-08-30 15:03:44 +04:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
* the Free Software Foundation ; either version 3 of the License , or
2002-08-30 15:03:44 +04:00
* ( at your option ) any later version .
2007-09-14 02:41:04 +04:00
*
2002-08-30 15:03:44 +04:00
* 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 .
2007-09-14 02:41:04 +04:00
*
2002-08-30 15:03:44 +04:00
* You should have received a copy of the GNU General Public License
2007-07-10 09:23:25 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2002-08-30 15:03:44 +04:00
*/
/* Implementation of registry frontend view functions. */
# include "includes.h"
2009-10-02 02:17:06 +04:00
# include "registry.h"
2002-08-30 15:03:44 +04:00
# undef DBGC_CLASS
2007-09-29 03:05:52 +04:00
# define DBGC_CLASS DBGC_REGISTRY
2002-08-30 15:03:44 +04:00
2009-02-25 02:33:24 +03:00
struct regsubkey_ctr {
2009-02-25 11:53:16 +03:00
uint32_t num_subkeys ;
2009-02-25 02:33:24 +03:00
char * * subkeys ;
2009-02-25 11:53:16 +03:00
struct db_context * subkeys_hash ;
2009-02-25 02:33:24 +03:00
int seqnum ;
} ;
2005-08-29 18:55:40 +04:00
/**********************************************************************
2002-08-30 15:03:44 +04:00
2009-03-23 20:14:17 +03:00
Note that the struct regsubkey_ctr and struct regval_ctr objects * must * be
2009-02-25 00:41:40 +03:00
talloc ( ) ' d since the methods use the object pointer as the talloc
context for internal private data .
2002-08-30 15:03:44 +04:00
2009-02-25 00:43:47 +03:00
There is no longer a regval_ctr_intit ( ) and regval_ctr_destroy ( )
2007-09-14 02:41:04 +04:00
pair of functions . Simply TALLOC_ZERO_P ( ) and TALLOC_FREE ( ) the
2005-08-29 18:55:40 +04:00
object .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-08-30 15:03:44 +04:00
2009-02-25 00:43:47 +03:00
WERROR regsubkey_ctr_init ( TALLOC_CTX * mem_ctx , struct regsubkey_ctr * * ctr )
{
if ( ctr = = NULL ) {
return WERR_INVALID_PARAM ;
}
* ctr = talloc_zero ( mem_ctx , struct regsubkey_ctr ) ;
if ( * ctr = = NULL ) {
return WERR_NOMEM ;
}
2009-02-25 11:53:16 +03:00
( * ctr ) - > subkeys_hash = db_open_rbt ( * ctr ) ;
if ( ( * ctr ) - > subkeys_hash = = NULL ) {
talloc_free ( * ctr ) ;
return WERR_NOMEM ;
}
2009-02-25 00:43:47 +03:00
return WERR_OK ;
}
2009-07-15 14:47:12 +04:00
/**
* re - initialize the list of subkeys ( to the emtpy list )
* in an already allocated regsubkey_ctr
*/
WERROR regsubkey_ctr_reinit ( struct regsubkey_ctr * ctr )
{
if ( ctr = = NULL ) {
return WERR_INVALID_PARAM ;
}
talloc_free ( ctr - > subkeys_hash ) ;
ctr - > subkeys_hash = db_open_rbt ( ctr ) ;
W_ERROR_HAVE_NO_MEMORY ( ctr - > subkeys_hash ) ;
TALLOC_FREE ( ctr - > subkeys ) ;
ctr - > num_subkeys = 0 ;
ctr - > seqnum = 0 ;
return WERR_OK ;
}
2009-02-25 01:10:35 +03:00
WERROR regsubkey_ctr_set_seqnum ( struct regsubkey_ctr * ctr , int seqnum )
{
if ( ctr = = NULL ) {
return WERR_INVALID_PARAM ;
}
ctr - > seqnum = seqnum ;
return WERR_OK ;
}
2009-02-25 01:15:55 +03:00
int regsubkey_ctr_get_seqnum ( struct regsubkey_ctr * ctr )
{
if ( ctr = = NULL ) {
return - 1 ;
}
return ctr - > seqnum ;
}
2009-02-25 11:53:16 +03:00
static WERROR regsubkey_ctr_hash_keyname ( struct regsubkey_ctr * ctr ,
const char * keyname ,
uint32 idx )
{
WERROR werr ;
2009-07-08 18:16:18 +04:00
werr = ntstatus_to_werror ( dbwrap_store_bystring_upper ( ctr - > subkeys_hash ,
2009-02-25 11:53:16 +03:00
keyname ,
make_tdb_data ( ( uint8 * ) & idx ,
sizeof ( idx ) ) ,
TDB_REPLACE ) ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
DEBUG ( 1 , ( " error hashing new key '%s' in container: %s \n " ,
keyname , win_errstr ( werr ) ) ) ;
}
return werr ;
}
static WERROR regsubkey_ctr_unhash_keyname ( struct regsubkey_ctr * ctr ,
const char * keyname )
{
WERROR werr ;
2009-07-08 18:16:18 +04:00
werr = ntstatus_to_werror ( dbwrap_delete_bystring_upper ( ctr - > subkeys_hash ,
2009-02-25 11:53:16 +03:00
keyname ) ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
DEBUG ( 1 , ( " error unhashing key '%s' in container: %s \n " ,
keyname , win_errstr ( werr ) ) ) ;
}
return werr ;
}
static WERROR regsubkey_ctr_index_for_keyname ( struct regsubkey_ctr * ctr ,
const char * keyname ,
uint32 * idx )
{
TDB_DATA data ;
if ( ( ctr = = NULL ) | | ( keyname = = NULL ) ) {
return WERR_INVALID_PARAM ;
}
2009-07-08 18:16:18 +04:00
data = dbwrap_fetch_bystring_upper ( ctr - > subkeys_hash , ctr , keyname ) ;
2009-02-25 11:53:16 +03:00
if ( data . dptr = = NULL ) {
return WERR_NOT_FOUND ;
}
if ( data . dsize ! = sizeof ( * idx ) ) {
talloc_free ( data . dptr ) ;
return WERR_INVALID_DATATYPE ;
}
if ( idx ! = NULL ) {
* idx = * ( uint32 * ) data . dptr ;
}
talloc_free ( data . dptr ) ;
return WERR_OK ;
}
2002-08-30 15:03:44 +04:00
/***********************************************************************
Add a new key to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 17:19:18 +03:00
WERROR regsubkey_ctr_addkey ( struct regsubkey_ctr * ctr , const char * keyname )
2002-08-30 15:03:44 +04:00
{
2006-11-18 20:46:32 +03:00
char * * newkeys ;
2009-02-25 11:53:16 +03:00
WERROR werr ;
2006-11-18 20:46:32 +03:00
if ( ! keyname ) {
return WERR_OK ;
}
2002-08-30 15:03:44 +04:00
2005-05-23 20:25:31 +04:00
/* make sure the keyname is not already there */
2006-11-18 20:46:32 +03:00
if ( regsubkey_ctr_key_exists ( ctr , keyname ) ) {
return WERR_OK ;
2006-03-30 02:45:52 +04:00
}
2006-11-18 20:46:32 +03:00
if ( ! ( newkeys = TALLOC_REALLOC_ARRAY ( ctr , ctr - > subkeys , char * ,
ctr - > num_subkeys + 1 ) ) ) {
return WERR_NOMEM ;
2002-08-30 15:03:44 +04:00
}
2005-05-23 20:25:31 +04:00
2006-11-18 20:46:32 +03:00
ctr - > subkeys = newkeys ;
if ( ! ( ctr - > subkeys [ ctr - > num_subkeys ] = talloc_strdup ( ctr - > subkeys ,
keyname ) ) ) {
/*
* Don ' t shrink the new array again , this wastes a pointer
*/
return WERR_NOMEM ;
}
2009-02-25 11:53:16 +03:00
werr = regsubkey_ctr_hash_keyname ( ctr , keyname , ctr - > num_subkeys ) ;
W_ERROR_NOT_OK_RETURN ( werr ) ;
2005-05-23 20:25:31 +04:00
ctr - > num_subkeys + + ;
2006-11-18 20:46:32 +03:00
return WERR_OK ;
2002-08-30 15:03:44 +04:00
}
2007-09-14 02:41:04 +04:00
2005-06-17 22:57:37 +04:00
/***********************************************************************
2006-12-01 22:55:29 +03:00
Delete a key from the array
2005-06-17 22:57:37 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-25 11:53:16 +03:00
WERROR regsubkey_ctr_delkey ( struct regsubkey_ctr * ctr , const char * keyname )
2005-06-17 22:57:37 +04:00
{
2009-02-25 11:53:16 +03:00
WERROR werr ;
uint32 idx , j ;
2005-06-17 22:57:37 +04:00
2009-02-25 11:53:16 +03:00
if ( keyname = = NULL ) {
return WERR_INVALID_PARAM ;
}
2005-06-17 22:57:37 +04:00
/* make sure the keyname is actually already there */
2009-02-25 11:53:16 +03:00
werr = regsubkey_ctr_index_for_keyname ( ctr , keyname , & idx ) ;
W_ERROR_NOT_OK_RETURN ( werr ) ;
2007-09-14 02:41:04 +04:00
2009-02-25 11:53:16 +03:00
werr = regsubkey_ctr_unhash_keyname ( ctr , keyname ) ;
W_ERROR_NOT_OK_RETURN ( werr ) ;
2005-06-17 22:57:37 +04:00
/* update if we have any keys left */
ctr - > num_subkeys - - ;
2009-02-25 11:53:16 +03:00
if ( idx < ctr - > num_subkeys ) {
memmove ( & ctr - > subkeys [ idx ] , & ctr - > subkeys [ idx + 1 ] ,
sizeof ( char * ) * ( ctr - > num_subkeys - idx ) ) ;
/* we have to re-hash rest of the array... :-( */
for ( j = idx ; j < ctr - > num_subkeys ; j + + ) {
werr = regsubkey_ctr_hash_keyname ( ctr , ctr - > subkeys [ j ] , j ) ;
W_ERROR_NOT_OK_RETURN ( werr ) ;
}
}
2007-09-14 02:41:04 +04:00
2009-02-25 11:53:16 +03:00
return WERR_OK ;
2005-06-17 22:57:37 +04:00
}
/***********************************************************************
Check for the existance of a key
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 17:19:18 +03:00
bool regsubkey_ctr_key_exists ( struct regsubkey_ctr * ctr , const char * keyname )
2005-06-17 22:57:37 +04:00
{
2009-02-25 11:53:16 +03:00
WERROR werr ;
2007-09-14 02:41:04 +04:00
2006-08-28 09:35:27 +04:00
if ( ! ctr - > subkeys ) {
return False ;
}
2009-02-25 11:53:16 +03:00
werr = regsubkey_ctr_index_for_keyname ( ctr , keyname , NULL ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return false ;
2005-06-17 22:57:37 +04:00
}
2007-09-14 02:41:04 +04:00
2009-02-25 11:53:16 +03:00
return true ;
2005-06-17 22:57:37 +04:00
}
2002-08-30 15:03:44 +04:00
/***********************************************************************
How many keys does the container hold ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 17:19:18 +03:00
int regsubkey_ctr_numkeys ( struct regsubkey_ctr * ctr )
2002-08-30 15:03:44 +04:00
{
return ctr - > num_subkeys ;
}
/***********************************************************************
Retreive a specific key string
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-25 11:53:16 +03:00
char * regsubkey_ctr_specific_key ( struct regsubkey_ctr * ctr , uint32_t key_index )
2002-08-30 15:03:44 +04:00
{
if ( ! ( key_index < ctr - > num_subkeys ) )
return NULL ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
return ctr - > subkeys [ key_index ] ;
}
/*
2009-03-23 20:14:17 +03:00
* Utility functions for struct regval_ctr
2002-08-30 15:03:44 +04:00
*/
/***********************************************************************
How many keys does the container hold ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 20:14:17 +03:00
int regval_ctr_numvals ( struct regval_ctr * ctr )
2002-08-30 15:03:44 +04:00
{
return ctr - > num_values ;
}
/***********************************************************************
2009-03-24 00:27:59 +03:00
allocate memory for and duplicate a struct regval_blob .
2002-08-30 15:03:44 +04:00
This is malloc ' d memory so the caller should free it when done
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
struct regval_blob * dup_registry_value ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
2009-03-24 00:27:59 +03:00
struct regval_blob * copy = NULL ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
if ( ! val )
return NULL ;
2007-09-14 02:41:04 +04:00
2009-03-24 00:27:59 +03:00
if ( ! ( copy = SMB_MALLOC_P ( struct regval_blob ) ) ) {
2002-08-30 15:03:44 +04:00
DEBUG ( 0 , ( " dup_registry_value: malloc() failed! \n " ) ) ;
return NULL ;
}
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
/* copy all the non-pointer initial data */
2007-09-14 02:41:04 +04:00
2009-03-24 00:27:59 +03:00
memcpy ( copy , val , sizeof ( struct regval_blob ) ) ;
2007-09-14 02:41:04 +04:00
2005-08-05 04:58:31 +04:00
copy - > size = 0 ;
copy - > data_p = NULL ;
2007-09-14 02:41:04 +04:00
if ( val - > data_p & & val - > size )
2002-08-30 15:03:44 +04:00
{
2006-07-31 07:53:39 +04:00
if ( ! ( copy - > data_p = ( uint8 * ) memdup ( val - > data_p ,
val - > size ) ) ) {
2007-09-14 02:41:04 +04:00
DEBUG ( 0 , ( " dup_registry_value: memdup() failed for [%d] "
" bytes! \n " , val - > size ) ) ;
2002-08-30 15:03:44 +04:00
SAFE_FREE ( copy ) ;
2006-08-28 06:29:36 +04:00
return NULL ;
2002-08-30 15:03:44 +04:00
}
2005-08-05 04:58:31 +04:00
copy - > size = val - > size ;
2002-08-30 15:03:44 +04:00
}
2007-09-14 02:41:04 +04:00
return copy ;
2002-08-30 15:03:44 +04:00
}
/**********************************************************************
2009-03-24 00:27:59 +03:00
free the memory allocated to a struct regval_blob
2002-08-30 15:03:44 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-09-14 02:41:04 +04:00
2009-03-24 00:27:59 +03:00
void free_registry_value ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
if ( ! val )
return ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
SAFE_FREE ( val - > data_p ) ;
SAFE_FREE ( val ) ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
return ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
uint8 * regval_data_p ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
return val - > data_p ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
uint32 regval_size ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
return val - > size ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
char * regval_name ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
return val - > valuename ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
uint32 regval_type ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
return val - > type ;
}
/***********************************************************************
Retreive a pointer to a specific value . Caller shoud dup the structure
2005-09-30 21:13:37 +04:00
since this memory will go away when the ctr is free ( ) ' d
2002-08-30 15:03:44 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
struct regval_blob * regval_ctr_specific_value ( struct regval_ctr * ctr ,
uint32 idx )
2002-08-30 15:03:44 +04:00
{
if ( ! ( idx < ctr - > num_values ) )
return NULL ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
return ctr - > values [ idx ] ;
}
2005-06-25 21:31:40 +04:00
/***********************************************************************
Check for the existance of a value
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 20:14:17 +03:00
bool regval_ctr_key_exists ( struct regval_ctr * ctr , const char * value )
2005-06-25 21:31:40 +04:00
{
int i ;
2007-09-14 02:41:04 +04:00
2005-06-25 21:31:40 +04:00
for ( i = 0 ; i < ctr - > num_values ; i + + ) {
if ( strequal ( ctr - > values [ i ] - > valuename , value ) )
return True ;
}
2007-09-14 02:41:04 +04:00
2005-06-25 21:31:40 +04:00
return False ;
}
2007-09-07 18:41:49 +04:00
/***********************************************************************
2009-03-24 00:27:59 +03:00
* compose a struct regval_blob from input data
2007-09-07 18:41:49 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
struct regval_blob * regval_compose ( TALLOC_CTX * ctx , const char * name ,
uint16 type ,
2010-05-24 17:00:29 +04:00
const uint8 * data_p , size_t size )
2007-09-07 18:41:49 +04:00
{
2009-03-24 00:27:59 +03:00
struct regval_blob * regval = TALLOC_P ( ctx , struct regval_blob ) ;
2007-09-07 18:41:49 +04:00
if ( regval = = NULL ) {
return NULL ;
}
fstrcpy ( regval - > valuename , name ) ;
regval - > type = type ;
if ( size ) {
regval - > data_p = ( uint8 * ) TALLOC_MEMDUP ( regval , data_p , size ) ;
if ( ! regval - > data_p ) {
TALLOC_FREE ( regval ) ;
return NULL ;
}
} else {
regval - > data_p = NULL ;
}
regval - > size = size ;
return regval ;
}
2002-08-30 15:03:44 +04:00
/***********************************************************************
Add a new registry value to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 20:14:17 +03:00
int regval_ctr_addvalue ( struct regval_ctr * ctr , const char * name , uint16 type ,
2010-05-24 17:15:33 +04:00
const uint8 * data_p , size_t size )
2002-08-30 15:03:44 +04:00
{
2005-05-23 20:25:31 +04:00
if ( ! name )
return ctr - > num_values ;
2005-06-25 21:31:40 +04:00
/* Delete the current value (if it exists) and add the new one */
regval_ctr_delvalue ( ctr , name ) ;
2005-05-23 20:25:31 +04:00
/* allocate a slot in the array of pointers */
2007-09-14 02:41:04 +04:00
2006-03-30 02:51:23 +04:00
if ( ctr - > num_values = = 0 ) {
2009-03-24 00:27:59 +03:00
ctr - > values = TALLOC_P ( ctr , struct regval_blob * ) ;
2006-03-30 02:51:23 +04:00
} else {
2007-09-14 02:41:04 +04:00
ctr - > values = TALLOC_REALLOC_ARRAY ( ctr , ctr - > values ,
2009-03-24 00:27:59 +03:00
struct regval_blob * ,
2007-09-14 02:41:04 +04:00
ctr - > num_values + 1 ) ;
2006-03-30 02:51:23 +04:00
}
if ( ! ctr - > values ) {
ctr - > num_values = 0 ;
return 0 ;
2005-05-23 20:25:31 +04:00
}
2002-08-30 15:03:44 +04:00
2005-05-23 20:25:31 +04:00
/* allocate a new value and store the pointer in the arrya */
2007-09-14 02:41:04 +04:00
2007-09-07 18:54:30 +04:00
ctr - > values [ ctr - > num_values ] = regval_compose ( ctr , name , type , data_p ,
size ) ;
if ( ctr - > values [ ctr - > num_values ] = = NULL ) {
2006-03-30 02:51:23 +04:00
ctr - > num_values = 0 ;
return 0 ;
}
2005-05-23 20:25:31 +04:00
ctr - > num_values + + ;
2002-08-30 15:03:44 +04:00
return ctr - > num_values ;
}
2009-09-24 13:30:45 +04:00
/***********************************************************************
Add a new registry SZ value to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int regval_ctr_addvalue_sz ( struct regval_ctr * ctr , const char * name , const char * data )
{
DATA_BLOB blob ;
2010-05-10 02:42:06 +04:00
if ( ! push_reg_sz ( ctr , & blob , data ) ) {
2009-09-24 13:30:45 +04:00
return - 1 ;
}
return regval_ctr_addvalue ( ctr , name , REG_SZ ,
2010-05-24 17:15:33 +04:00
( const uint8 * ) blob . data ,
2009-09-24 13:30:45 +04:00
blob . length ) ;
}
2009-09-30 17:21:37 +04:00
/***********************************************************************
Add a new registry MULTI_SZ value to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int regval_ctr_addvalue_multi_sz ( struct regval_ctr * ctr , const char * name , const char * * data )
{
DATA_BLOB blob ;
2010-05-10 02:42:06 +04:00
if ( ! push_reg_multi_sz ( ctr , & blob , data ) ) {
2009-09-30 17:21:37 +04:00
return - 1 ;
}
return regval_ctr_addvalue ( ctr , name , REG_MULTI_SZ ,
2010-05-24 17:15:33 +04:00
( const uint8 * ) blob . data ,
2009-09-30 17:21:37 +04:00
blob . length ) ;
}
2002-08-30 15:03:44 +04:00
/***********************************************************************
Add a new registry value to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
int regval_ctr_copyvalue ( struct regval_ctr * ctr , struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
2006-03-30 02:51:23 +04:00
if ( val ) {
2007-09-14 02:36:10 +04:00
regval_ctr_addvalue ( ctr , val - > valuename , val - > type ,
2010-05-24 17:15:33 +04:00
( uint8 * ) val - > data_p , val - > size ) ;
2002-08-30 15:03:44 +04:00
}
return ctr - > num_values ;
}
/***********************************************************************
Delete a single value from the registry container .
No need to free memory since it is talloc ' d .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 20:14:17 +03:00
int regval_ctr_delvalue ( struct regval_ctr * ctr , const char * name )
2002-08-30 15:03:44 +04:00
{
int i ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
for ( i = 0 ; i < ctr - > num_values ; i + + ) {
2005-06-25 21:31:40 +04:00
if ( strequal ( ctr - > values [ i ] - > valuename , name ) )
2002-08-30 15:03:44 +04:00
break ;
}
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
/* just return if we don't find it */
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
if ( i = = ctr - > num_values )
return ctr - > num_values ;
2007-09-14 02:41:04 +04:00
2005-06-29 20:35:32 +04:00
/* If 'i' was not the last element, just shift everything down one */
2002-08-30 15:03:44 +04:00
ctr - > num_values - - ;
2005-06-29 20:35:32 +04:00
if ( i < ctr - > num_values )
2007-09-14 02:41:04 +04:00
memmove ( & ctr - > values [ i ] , & ctr - > values [ i + 1 ] ,
2009-03-24 00:27:59 +03:00
sizeof ( struct regval_blob * ) * ( ctr - > num_values - i ) ) ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
return ctr - > num_values ;
}
/***********************************************************************
2005-06-17 22:57:37 +04:00
Retrieve single value from the registry container .
2002-08-30 15:03:44 +04:00
No need to free memory since it is talloc ' d .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
struct regval_blob * regval_ctr_getvalue ( struct regval_ctr * ctr ,
const char * name )
2002-08-30 15:03:44 +04:00
{
int i ;
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
/* search for the value */
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
for ( i = 0 ; i < ctr - > num_values ; i + + ) {
if ( strequal ( ctr - > values [ i ] - > valuename , name ) )
return ctr - > values [ i ] ;
}
2007-09-14 02:41:04 +04:00
2002-08-30 15:03:44 +04:00
return NULL ;
}
2005-09-30 21:13:37 +04:00
/***********************************************************************
return the data_p as a uint32
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-24 00:27:59 +03:00
uint32 regval_dword ( struct regval_blob * val )
2005-09-30 21:13:37 +04:00
{
uint32 data ;
2007-09-14 02:41:04 +04:00
2005-09-30 21:13:37 +04:00
data = IVAL ( regval_data_p ( val ) , 0 ) ;
2007-09-14 02:41:04 +04:00
2005-09-30 21:13:37 +04:00
return data ;
}
/***********************************************************************
return the data_p as a character string
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-09-30 22:00:52 +04:00
const char * regval_sz ( struct regval_blob * val )
2005-09-30 21:13:37 +04:00
{
2009-09-30 22:00:52 +04:00
const char * data = NULL ;
DATA_BLOB blob = data_blob_const ( regval_data_p ( val ) , regval_size ( val ) ) ;
2010-05-10 02:42:06 +04:00
pull_reg_sz ( talloc_tos ( ) , & blob , & data ) ;
2005-09-30 21:13:37 +04:00
2007-11-27 04:24:56 +03:00
return data ;
2005-09-30 21:13:37 +04:00
}