2007-09-13 22:41:04 +00:00
/*
2002-08-30 11:03:44 +00:00
* Unix SMB / CIFS implementation .
2005-05-23 16:25:31 +00:00
* Virtual Windows Registry Layer
* Copyright ( C ) Gerald Carter 2002 - 2005
2010-05-25 10:53:17 +02:00
* Copyright ( C ) Michael Adam 2007 - 2010
2002-08-30 11:03:44 +00: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 19:25:36 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2002-08-30 11:03:44 +00:00
* ( at your option ) any later version .
2007-09-13 22:41:04 +00:00
*
2002-08-30 11:03:44 +00: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-13 22:41:04 +00:00
*
2002-08-30 11:03:44 +00:00
* You should have received a copy of the GNU General Public License
2007-07-10 05:23:25 +00:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2002-08-30 11:03:44 +00:00
*/
/* Implementation of registry frontend view functions. */
# include "includes.h"
2009-10-02 00:17:06 +02:00
# include "registry.h"
2010-05-25 01:00:37 +02:00
# include "reg_objects.h"
2011-05-05 11:25:29 +02:00
# include "util_tdb.h"
2011-07-07 17:42:08 +02:00
# include "dbwrap/dbwrap.h"
2011-08-16 16:20:14 +02:00
# include "dbwrap/dbwrap_rbt.h"
2011-02-26 00:28:15 +01:00
# include "../libcli/registry/util_reg.h"
2002-08-30 11:03:44 +00:00
# undef DBGC_CLASS
2007-09-28 23:05:52 +00:00
# define DBGC_CLASS DBGC_REGISTRY
2002-08-30 11:03:44 +00:00
2010-05-24 00:05:26 +02:00
/* low level structure to contain registry values */
struct regval_blob {
fstring valuename ;
2010-07-01 11:22:20 +02:00
uint32_t type ;
2010-05-24 00:05:26 +02:00
/* this should be encapsulated in an RPC_DATA_BLOB */
2010-05-25 10:32:51 +02:00
uint32_t size ; /* in bytes */
uint8_t * data_p ;
2010-05-24 00:05:26 +02:00
} ;
/* container for registry values */
struct regval_ctr {
2010-05-25 10:32:51 +02:00
uint32_t num_values ;
2010-05-24 00:05:26 +02:00
struct regval_blob * * values ;
int seqnum ;
} ;
2009-02-25 00:33:24 +01:00
struct regsubkey_ctr {
2009-02-25 09:53:16 +01:00
uint32_t num_subkeys ;
2009-02-25 00:33:24 +01:00
char * * subkeys ;
2009-02-25 09:53:16 +01:00
struct db_context * subkeys_hash ;
2009-02-25 00:33:24 +01:00
int seqnum ;
} ;
2005-08-29 14:55:40 +00:00
/**********************************************************************
2002-08-30 11:03:44 +00:00
2009-03-23 18:14:17 +01:00
Note that the struct regsubkey_ctr and struct regval_ctr objects * must * be
2009-02-24 22:41:40 +01:00
talloc ( ) ' d since the methods use the object pointer as the talloc
context for internal private data .
2002-08-30 11:03:44 +00:00
2009-02-24 22:43:47 +01:00
There is no longer a regval_ctr_intit ( ) and regval_ctr_destroy ( )
2011-06-07 11:44:43 +10:00
pair of functions . Simply talloc_zero ( ) and TALLOC_FREE ( ) the
2005-08-29 14:55:40 +00:00
object .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2002-08-30 11:03:44 +00:00
2009-02-24 22:43:47 +01:00
WERROR regsubkey_ctr_init ( TALLOC_CTX * mem_ctx , struct regsubkey_ctr * * ctr )
{
if ( ctr = = NULL ) {
2015-12-03 15:24:24 +01:00
return WERR_INVALID_PARAMETER ;
2009-02-24 22:43:47 +01:00
}
* ctr = talloc_zero ( mem_ctx , struct regsubkey_ctr ) ;
if ( * ctr = = NULL ) {
2015-12-03 15:24:14 +01:00
return WERR_NOT_ENOUGH_MEMORY ;
2009-02-24 22:43:47 +01:00
}
2009-02-25 09:53:16 +01:00
( * ctr ) - > subkeys_hash = db_open_rbt ( * ctr ) ;
if ( ( * ctr ) - > subkeys_hash = = NULL ) {
talloc_free ( * ctr ) ;
2015-12-03 15:24:14 +01:00
return WERR_NOT_ENOUGH_MEMORY ;
2009-02-25 09:53:16 +01:00
}
2009-02-24 22:43:47 +01:00
return WERR_OK ;
}
2009-07-15 12:47:12 +02: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 15:24:24 +01:00
return WERR_INVALID_PARAMETER ;
2009-07-15 12:47:12 +02: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-24 23:10:35 +01:00
WERROR regsubkey_ctr_set_seqnum ( struct regsubkey_ctr * ctr , int seqnum )
{
if ( ctr = = NULL ) {
2015-12-03 15:24:24 +01:00
return WERR_INVALID_PARAMETER ;
2009-02-24 23:10:35 +01:00
}
ctr - > seqnum = seqnum ;
return WERR_OK ;
}
2009-02-24 23:15:55 +01:00
int regsubkey_ctr_get_seqnum ( struct regsubkey_ctr * ctr )
{
if ( ctr = = NULL ) {
return - 1 ;
}
return ctr - > seqnum ;
}
2009-02-25 09:53:16 +01:00
static WERROR regsubkey_ctr_hash_keyname ( struct regsubkey_ctr * ctr ,
const char * keyname ,
2010-05-25 10:32:51 +02:00
uint32_t idx )
2009-02-25 09:53:16 +01:00
{
WERROR werr ;
2009-07-08 16:16:18 +02:00
werr = ntstatus_to_werror ( dbwrap_store_bystring_upper ( ctr - > subkeys_hash ,
2009-02-25 09:53:16 +01:00
keyname ,
2010-05-25 10:32:51 +02:00
make_tdb_data ( ( uint8_t * ) & idx ,
2009-02-25 09:53:16 +01: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 16:16:18 +02:00
werr = ntstatus_to_werror ( dbwrap_delete_bystring_upper ( ctr - > subkeys_hash ,
2009-02-25 09:53:16 +01: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 10:32:51 +02:00
uint32_t * idx )
2009-02-25 09:53:16 +01:00
{
TDB_DATA data ;
2011-08-24 13:08:13 +02:00
NTSTATUS status ;
2009-02-25 09:53:16 +01:00
if ( ( ctr = = NULL ) | | ( keyname = = NULL ) ) {
2015-12-03 15:24:24 +01:00
return WERR_INVALID_PARAMETER ;
2009-02-25 09:53:16 +01:00
}
2011-08-24 13:08:13 +02:00
status = dbwrap_fetch_bystring_upper ( ctr - > subkeys_hash , ctr , keyname ,
& data ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-02-25 09:53:16 +01:00
return WERR_NOT_FOUND ;
}
if ( data . dsize ! = sizeof ( * idx ) ) {
talloc_free ( data . dptr ) ;
return WERR_INVALID_DATATYPE ;
}
if ( idx ! = NULL ) {
2015-01-21 11:44:58 +01:00
memcpy ( idx , data . dptr , sizeof ( * idx ) ) ;
2009-02-25 09:53:16 +01:00
}
talloc_free ( data . dptr ) ;
return WERR_OK ;
}
2002-08-30 11:03:44 +00:00
/***********************************************************************
Add a new key to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 15:19:18 +01:00
WERROR regsubkey_ctr_addkey ( struct regsubkey_ctr * ctr , const char * keyname )
2002-08-30 11:03:44 +00:00
{
2006-11-18 17:46:32 +00:00
char * * newkeys ;
2009-02-25 09:53:16 +01:00
WERROR werr ;
2006-11-18 17:46:32 +00:00
if ( ! keyname ) {
return WERR_OK ;
}
2002-08-30 11:03:44 +00:00
2005-05-23 16:25:31 +00:00
/* make sure the keyname is not already there */
2006-11-18 17:46:32 +00:00
if ( regsubkey_ctr_key_exists ( ctr , keyname ) ) {
return WERR_OK ;
2006-03-29 22:45:52 +00:00
}
2011-06-07 11:10:15 +10:00
if ( ! ( newkeys = talloc_realloc ( ctr , ctr - > subkeys , char * ,
2006-11-18 17:46:32 +00:00
ctr - > num_subkeys + 1 ) ) ) {
2015-12-03 15:24:14 +01:00
return WERR_NOT_ENOUGH_MEMORY ;
2002-08-30 11:03:44 +00:00
}
2005-05-23 16:25:31 +00:00
2006-11-18 17:46:32 +00: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 15:24:14 +01:00
return WERR_NOT_ENOUGH_MEMORY ;
2006-11-18 17:46:32 +00:00
}
2009-02-25 09:53:16 +01:00
werr = regsubkey_ctr_hash_keyname ( ctr , keyname , ctr - > num_subkeys ) ;
W_ERROR_NOT_OK_RETURN ( werr ) ;
2005-05-23 16:25:31 +00:00
ctr - > num_subkeys + + ;
2006-11-18 17:46:32 +00:00
return WERR_OK ;
2002-08-30 11:03:44 +00:00
}
2007-09-13 22:41:04 +00:00
2005-06-17 18:57:37 +00:00
/***********************************************************************
2006-12-01 19:55:29 +00:00
Delete a key from the array
2005-06-17 18:57:37 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-25 09:53:16 +01:00
WERROR regsubkey_ctr_delkey ( struct regsubkey_ctr * ctr , const char * keyname )
2005-06-17 18:57:37 +00:00
{
2009-02-25 09:53:16 +01:00
WERROR werr ;
2010-05-25 10:32:51 +02:00
uint32_t idx , j ;
2005-06-17 18:57:37 +00:00
2009-02-25 09:53:16 +01:00
if ( keyname = = NULL ) {
2015-12-03 15:24:24 +01:00
return WERR_INVALID_PARAMETER ;
2009-02-25 09:53:16 +01:00
}
2005-06-17 18:57:37 +00:00
/* make sure the keyname is actually already there */
2009-02-25 09:53:16 +01:00
werr = regsubkey_ctr_index_for_keyname ( ctr , keyname , & idx ) ;
W_ERROR_NOT_OK_RETURN ( werr ) ;
2007-09-13 22:41:04 +00:00
2009-02-25 09:53:16 +01:00
werr = regsubkey_ctr_unhash_keyname ( ctr , keyname ) ;
W_ERROR_NOT_OK_RETURN ( werr ) ;
2005-06-17 18:57:37 +00:00
/* update if we have any keys left */
ctr - > num_subkeys - - ;
2009-02-25 09:53:16 +01: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-13 22:41:04 +00:00
2009-02-25 09:53:16 +01:00
return WERR_OK ;
2005-06-17 18:57:37 +00:00
}
/***********************************************************************
2017-02-18 08:56:18 +13:00
Check for the existence of a key
2005-06-17 18:57:37 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 15:19:18 +01:00
bool regsubkey_ctr_key_exists ( struct regsubkey_ctr * ctr , const char * keyname )
2005-06-17 18:57:37 +00:00
{
2009-02-25 09:53:16 +01:00
WERROR werr ;
2007-09-13 22:41:04 +00:00
2006-08-28 05:35:27 +00:00
if ( ! ctr - > subkeys ) {
return False ;
}
2009-02-25 09:53:16 +01:00
werr = regsubkey_ctr_index_for_keyname ( ctr , keyname , NULL ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
return false ;
2005-06-17 18:57:37 +00:00
}
2007-09-13 22:41:04 +00:00
2009-02-25 09:53:16 +01:00
return true ;
2005-06-17 18:57:37 +00:00
}
2002-08-30 11:03:44 +00:00
/***********************************************************************
How many keys does the container hold ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 15:19:18 +01:00
int regsubkey_ctr_numkeys ( struct regsubkey_ctr * ctr )
2002-08-30 11:03:44 +00:00
{
return ctr - > num_subkeys ;
}
/***********************************************************************
2015-07-26 23:02:57 +02:00
Retrieve a specific key string
2002-08-30 11:03:44 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-25 09:53:16 +01:00
char * regsubkey_ctr_specific_key ( struct regsubkey_ctr * ctr , uint32_t key_index )
2002-08-30 11:03:44 +00:00
{
if ( ! ( key_index < ctr - > num_subkeys ) )
return NULL ;
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
return ctr - > subkeys [ key_index ] ;
}
/*
2009-03-23 18:14:17 +01:00
* Utility functions for struct regval_ctr
2002-08-30 11:03:44 +00:00
*/
2010-05-23 22:47:53 +02:00
/**
* allocate a regval_ctr structure .
*/
WERROR regval_ctr_init ( TALLOC_CTX * mem_ctx , struct regval_ctr * * ctr )
{
if ( ctr = = NULL ) {
2015-12-03 15:24:24 +01:00
return WERR_INVALID_PARAMETER ;
2010-05-23 22:47:53 +02:00
}
* ctr = talloc_zero ( mem_ctx , struct regval_ctr ) ;
if ( * ctr = = NULL ) {
2015-12-03 15:24:14 +01:00
return WERR_NOT_ENOUGH_MEMORY ;
2010-05-23 22:47:53 +02:00
}
return WERR_OK ;
}
2002-08-30 11:03:44 +00:00
/***********************************************************************
How many keys does the container hold ?
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 18:14:17 +01:00
int regval_ctr_numvals ( struct regval_ctr * ctr )
2002-08-30 11:03:44 +00:00
{
return ctr - > num_values ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-05-25 10:32:51 +02:00
uint8_t * regval_data_p ( struct regval_blob * val )
2002-08-30 11:03:44 +00:00
{
return val - > data_p ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-05-25 10:32:51 +02:00
uint32_t regval_size ( struct regval_blob * val )
2002-08-30 11:03:44 +00:00
{
return val - > size ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 22:27:59 +01:00
char * regval_name ( struct regval_blob * val )
2002-08-30 11:03:44 +00:00
{
return val - > valuename ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-05-25 10:32:51 +02:00
uint32_t regval_type ( struct regval_blob * val )
2002-08-30 11:03:44 +00:00
{
return val - > type ;
}
/***********************************************************************
2015-07-26 23:02:57 +02:00
Retrieve a pointer to a specific value . Caller shoud dup the structure
2005-09-30 17:13:37 +00:00
since this memory will go away when the ctr is free ( ) ' d
2002-08-30 11:03:44 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 22:27:59 +01:00
struct regval_blob * regval_ctr_specific_value ( struct regval_ctr * ctr ,
2010-05-25 10:32:51 +02:00
uint32_t idx )
2002-08-30 11:03:44 +00:00
{
if ( ! ( idx < ctr - > num_values ) )
return NULL ;
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
return ctr - > values [ idx ] ;
}
2005-06-25 17:31:40 +00:00
/***********************************************************************
2017-02-18 08:56:18 +13:00
Check for the existence of a value
2005-06-25 17:31:40 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-03-30 14:33:39 +02:00
bool regval_ctr_value_exists ( struct regval_ctr * ctr , const char * value )
2005-06-25 17:31:40 +00:00
{
int i ;
2007-09-13 22:41:04 +00:00
2005-06-25 17:31:40 +00:00
for ( i = 0 ; i < ctr - > num_values ; i + + ) {
if ( strequal ( ctr - > values [ i ] - > valuename , value ) )
return True ;
}
2007-09-13 22:41:04 +00:00
2005-06-25 17:31:40 +00:00
return False ;
}
2007-09-07 14:41:49 +00:00
2012-03-30 14:39:50 +02: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 14:41:49 +00:00
/***********************************************************************
2009-03-23 22:27:59 +01:00
* compose a struct regval_blob from input data
2007-09-07 14:41:49 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 22:27:59 +01:00
struct regval_blob * regval_compose ( TALLOC_CTX * ctx , const char * name ,
2010-07-01 11:22:20 +02:00
uint32_t type ,
2010-05-25 10:32:51 +02:00
const uint8_t * data_p , size_t size )
2007-09-07 14:41:49 +00:00
{
2011-06-07 11:38:41 +10:00
struct regval_blob * regval = talloc ( ctx , struct regval_blob ) ;
2007-09-07 14:41:49 +00:00
if ( regval = = NULL ) {
return NULL ;
}
fstrcpy ( regval - > valuename , name ) ;
regval - > type = type ;
if ( size ) {
2011-06-07 12:13:26 +10:00
regval - > data_p = ( uint8_t * ) talloc_memdup ( regval , data_p , size ) ;
2007-09-07 14:41:49 +00:00
if ( ! regval - > data_p ) {
TALLOC_FREE ( regval ) ;
return NULL ;
}
} else {
regval - > data_p = NULL ;
}
regval - > size = size ;
return regval ;
}
2002-08-30 11:03:44 +00:00
/***********************************************************************
Add a new registry value to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-07-01 11:22:20 +02:00
int regval_ctr_addvalue ( struct regval_ctr * ctr , const char * name , uint32_t type ,
2010-05-25 10:32:51 +02:00
const uint8_t * data_p , size_t size )
2002-08-30 11:03:44 +00:00
{
2005-05-23 16:25:31 +00:00
if ( ! name )
return ctr - > num_values ;
2005-06-25 17:31:40 +00:00
/* Delete the current value (if it exists) and add the new one */
regval_ctr_delvalue ( ctr , name ) ;
2005-05-23 16:25:31 +00:00
/* allocate a slot in the array of pointers */
2007-09-13 22:41:04 +00:00
2006-03-29 22:51:23 +00:00
if ( ctr - > num_values = = 0 ) {
2011-06-07 11:38:41 +10:00
ctr - > values = talloc ( ctr , struct regval_blob * ) ;
2006-03-29 22:51:23 +00:00
} else {
2011-06-07 11:10:15 +10:00
ctr - > values = talloc_realloc ( ctr , ctr - > values ,
2009-03-23 22:27:59 +01:00
struct regval_blob * ,
2007-09-13 22:41:04 +00:00
ctr - > num_values + 1 ) ;
2006-03-29 22:51:23 +00:00
}
if ( ! ctr - > values ) {
ctr - > num_values = 0 ;
return 0 ;
2005-05-23 16:25:31 +00:00
}
2002-08-30 11:03:44 +00:00
2018-10-02 12:00:30 +02:00
/* allocate a new value and store the pointer in the array */
2007-09-13 22:41:04 +00:00
2007-09-07 14:54:30 +00:00
ctr - > values [ ctr - > num_values ] = regval_compose ( ctr , name , type , data_p ,
size ) ;
if ( ctr - > values [ ctr - > num_values ] = = NULL ) {
2006-03-29 22:51:23 +00:00
ctr - > num_values = 0 ;
return 0 ;
}
2005-05-23 16:25:31 +00:00
ctr - > num_values + + ;
2002-08-30 11:03:44 +00:00
return ctr - > num_values ;
}
2009-09-24 11:30:45 +02: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 00:42:06 +02:00
if ( ! push_reg_sz ( ctr , & blob , data ) ) {
2009-09-24 11:30:45 +02:00
return - 1 ;
}
return regval_ctr_addvalue ( ctr , name , REG_SZ ,
2010-05-25 10:32:51 +02:00
( const uint8_t * ) blob . data ,
2009-09-24 11:30:45 +02:00
blob . length ) ;
}
2009-09-30 15:21:37 +02: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 00:42:06 +02:00
if ( ! push_reg_multi_sz ( ctr , & blob , data ) ) {
2009-09-30 15:21:37 +02:00
return - 1 ;
}
return regval_ctr_addvalue ( ctr , name , REG_MULTI_SZ ,
2010-05-25 10:32:51 +02:00
( const uint8_t * ) blob . data ,
2009-09-30 15:21:37 +02:00
blob . length ) ;
}
2002-08-30 11:03:44 +00:00
/***********************************************************************
Add a new registry value to the array
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 22:27:59 +01:00
int regval_ctr_copyvalue ( struct regval_ctr * ctr , struct regval_blob * val )
2002-08-30 11:03:44 +00:00
{
2006-03-29 22:51:23 +00:00
if ( val ) {
2007-09-13 22:36:10 +00:00
regval_ctr_addvalue ( ctr , val - > valuename , val - > type ,
2010-05-25 10:32:51 +02:00
( uint8_t * ) val - > data_p , val - > size ) ;
2002-08-30 11:03:44 +00: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 18:14:17 +01:00
int regval_ctr_delvalue ( struct regval_ctr * ctr , const char * name )
2002-08-30 11:03:44 +00:00
{
int i ;
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
for ( i = 0 ; i < ctr - > num_values ; i + + ) {
2005-06-25 17:31:40 +00:00
if ( strequal ( ctr - > values [ i ] - > valuename , name ) )
2002-08-30 11:03:44 +00:00
break ;
}
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
/* just return if we don't find it */
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
if ( i = = ctr - > num_values )
return ctr - > num_values ;
2007-09-13 22:41:04 +00:00
2005-06-29 16:35:32 +00:00
/* If 'i' was not the last element, just shift everything down one */
2002-08-30 11:03:44 +00:00
ctr - > num_values - - ;
2005-06-29 16:35:32 +00:00
if ( i < ctr - > num_values )
2007-09-13 22:41:04 +00:00
memmove ( & ctr - > values [ i ] , & ctr - > values [ i + 1 ] ,
2009-03-23 22:27:59 +01:00
sizeof ( struct regval_blob * ) * ( ctr - > num_values - i ) ) ;
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
return ctr - > num_values ;
}
/***********************************************************************
2005-06-17 18:57:37 +00:00
Retrieve single value from the registry container .
2002-08-30 11:03:44 +00:00
No need to free memory since it is talloc ' d .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 22:27:59 +01:00
struct regval_blob * regval_ctr_getvalue ( struct regval_ctr * ctr ,
const char * name )
2002-08-30 11:03:44 +00:00
{
int i ;
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
/* search for the value */
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
for ( i = 0 ; i < ctr - > num_values ; i + + ) {
if ( strequal ( ctr - > values [ i ] - > valuename , name ) )
return ctr - > values [ i ] ;
}
2007-09-13 22:41:04 +00:00
2002-08-30 11:03:44 +00:00
return NULL ;
}
2010-05-23 22:53:44 +02:00
int regval_ctr_get_seqnum ( struct regval_ctr * ctr )
{
if ( ctr = = NULL ) {
return - 1 ;
}
return ctr - > seqnum ;
}
2010-05-23 22:55:12 +02:00
WERROR regval_ctr_set_seqnum ( struct regval_ctr * ctr , int seqnum )
{
if ( ctr = = NULL ) {
2015-12-03 15:24:24 +01:00
return WERR_INVALID_PARAMETER ;
2010-05-23 22:55:12 +02:00
}
ctr - > seqnum = seqnum ;
return WERR_OK ;
}