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
2010-05-25 12:53:17 +04:00
* Copyright ( C ) Michael Adam 2007 - 2010
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"
2010-05-25 03:00:37 +04:00
# include "reg_objects.h"
2011-05-05 13:25:29 +04:00
# include "util_tdb.h"
2011-07-07 19:42:08 +04:00
# include "dbwrap/dbwrap.h"
2011-08-16 18:20:14 +04:00
# include "dbwrap/dbwrap_rbt.h"
2011-02-26 02:28:15 +03:00
# include "../libcli/registry/util_reg.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
2010-05-24 02:05:26 +04:00
/* low level structure to contain registry values */
struct regval_blob {
fstring valuename ;
2010-07-01 13:22:20 +04:00
uint32_t type ;
2010-05-24 02:05:26 +04:00
/* this should be encapsulated in an RPC_DATA_BLOB */
2010-05-25 12:32:51 +04:00
uint32_t size ; /* in bytes */
uint8_t * data_p ;
2010-05-24 02:05:26 +04:00
} ;
/* container for registry values */
struct regval_ctr {
2010-05-25 12:32:51 +04:00
uint32_t num_values ;
2010-05-24 02:05:26 +04:00
struct regval_blob * * values ;
int seqnum ;
} ;
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 ( )
2011-06-07 05:44:43 +04:00
pair of functions . Simply talloc_zero ( ) 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 ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2009-02-25 00:43:47 +03:00
}
* ctr = talloc_zero ( mem_ctx , struct regsubkey_ctr ) ;
if ( * ctr = = NULL ) {
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2009-02-25 00:43:47 +03:00
}
2009-02-25 11:53:16 +03:00
( * ctr ) - > subkeys_hash = db_open_rbt ( * ctr ) ;
if ( ( * ctr ) - > subkeys_hash = = NULL ) {
talloc_free ( * ctr ) ;
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2009-02-25 11:53:16 +03:00
}
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 ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2009-07-15 14:47:12 +04:00
}
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 ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2009-02-25 01:10:35 +03:00
}
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 ,
2010-05-25 12:32:51 +04:00
uint32_t idx )
2009-02-25 11:53:16 +03:00
{
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 ,
2010-05-25 12:32:51 +04:00
make_tdb_data ( ( uint8_t * ) & idx ,
2009-02-25 11:53:16 +03:00
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 ,
2010-05-25 12:32:51 +04:00
uint32_t * idx )
2009-02-25 11:53:16 +03:00
{
TDB_DATA data ;
2011-08-24 15:08:13 +04:00
NTSTATUS status ;
2009-02-25 11:53:16 +03:00
if ( ( ctr = = NULL ) | | ( keyname = = NULL ) ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2009-02-25 11:53:16 +03:00
}
2011-08-24 15:08:13 +04:00
status = dbwrap_fetch_bystring_upper ( ctr - > subkeys_hash , ctr , keyname ,
& data ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-02-25 11:53:16 +03:00
return WERR_NOT_FOUND ;
}
if ( data . dsize ! = sizeof ( * idx ) ) {
talloc_free ( data . dptr ) ;
return WERR_INVALID_DATATYPE ;
}
if ( idx ! = NULL ) {
2015-01-21 13:44:58 +03:00
memcpy ( idx , data . dptr , sizeof ( * idx ) ) ;
2009-02-25 11:53:16 +03:00
}
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
}
2011-06-07 05:10:15 +04:00
if ( ! ( newkeys = talloc_realloc ( ctr , ctr - > subkeys , char * ,
2006-11-18 20:46:32 +03:00
ctr - > num_subkeys + 1 ) ) ) {
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
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
*/
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2006-11-18 20:46:32 +03:00
}
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 ;
2010-05-25 12:32:51 +04:00
uint32_t idx , j ;
2005-06-17 22:57:37 +04:00
2009-02-25 11:53:16 +03:00
if ( keyname = = NULL ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2009-02-25 11:53:16 +03:00
}
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
}
/***********************************************************************
2017-02-17 22:56:18 +03:00
Check for the existence of a key
2005-06-17 22:57:37 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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 ;
}
/***********************************************************************
2015-07-27 00:02:57 +03:00
Retrieve a specific key string
2002-08-30 15:03:44 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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
*/
2010-05-24 00:47:53 +04:00
/**
* allocate a regval_ctr structure .
*/
WERROR regval_ctr_init ( TALLOC_CTX * mem_ctx , struct regval_ctr * * ctr )
{
if ( ctr = = NULL ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2010-05-24 00:47:53 +04:00
}
* ctr = talloc_zero ( mem_ctx , struct regval_ctr ) ;
if ( * ctr = = NULL ) {
2015-12-03 17:24:14 +03:00
return WERR_NOT_ENOUGH_MEMORY ;
2010-05-24 00:47:53 +04:00
}
return WERR_OK ;
}
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 ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-05-25 12:32:51 +04:00
uint8_t * regval_data_p ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
return val - > data_p ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-05-25 12:32:51 +04:00
uint32_t 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 ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-05-25 12:32:51 +04:00
uint32_t regval_type ( struct regval_blob * val )
2002-08-30 15:03:44 +04:00
{
return val - > type ;
}
/***********************************************************************
2015-07-27 00:02:57 +03:00
Retrieve 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 ,
2010-05-25 12:32:51 +04:00
uint32_t 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
/***********************************************************************
2017-02-17 22:56:18 +03:00
Check for the existence of a value
2005-06-25 21:31:40 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-03-30 16:33:39 +04:00
bool regval_ctr_value_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
2012-03-30 16:39:50 +04:00
/**
* Get a value by its name
*/
struct regval_blob * regval_ctr_value_byname ( struct regval_ctr * ctr ,
const char * value )
{
int i ;
for ( i = 0 ; i < ctr - > num_values ; i + + ) {
if ( strequal ( ctr - > values [ i ] - > valuename , value ) ) {
return ctr - > values [ i ] ;
}
}
return NULL ;
}
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 ,
2010-07-01 13:22:20 +04:00
uint32_t type ,
2010-05-25 12:32:51 +04:00
const uint8_t * data_p , size_t size )
2007-09-07 18:41:49 +04:00
{
2011-06-07 05:38:41 +04:00
struct regval_blob * regval = talloc ( 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 ) {
2011-06-07 06:13:26 +04:00
regval - > data_p = ( uint8_t * ) talloc_memdup ( regval , data_p , size ) ;
2007-09-07 18:41:49 +04:00
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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-01 13:22:20 +04:00
int regval_ctr_addvalue ( struct regval_ctr * ctr , const char * name , uint32_t type ,
2010-05-25 12:32:51 +04:00
const uint8_t * 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 ) {
2011-06-07 05:38:41 +04:00
ctr - > values = talloc ( ctr , struct regval_blob * ) ;
2006-03-30 02:51:23 +04:00
} else {
2011-06-07 05:10:15 +04:00
ctr - > values = talloc_realloc ( 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-25 12:32:51 +04:00
( const uint8_t * ) 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-25 12:32:51 +04:00
( const uint8_t * ) 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-25 12:32:51 +04:00
( uint8_t * ) 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 ;
}
2010-05-24 00:53:44 +04:00
int regval_ctr_get_seqnum ( struct regval_ctr * ctr )
{
if ( ctr = = NULL ) {
return - 1 ;
}
return ctr - > seqnum ;
}
2010-05-24 00:55:12 +04:00
WERROR regval_ctr_set_seqnum ( struct regval_ctr * ctr , int seqnum )
{
if ( ctr = = NULL ) {
2015-12-03 17:24:24 +03:00
return WERR_INVALID_PARAMETER ;
2010-05-24 00:55:12 +04:00
}
ctr - > seqnum = seqnum ;
return WERR_OK ;
}