2007-12-11 23:21:17 +03:00
/*
* Unix SMB / CIFS implementation .
* libnet smbconf registry Support
2008-01-03 02:44:47 +03:00
* Copyright ( C ) Michael Adam 2007 - 2008
2007-12-11 23:21:17 +03:00
* Copyright ( C ) Guenther Deschner 2007
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* 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 .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2007-12-29 23:59:28 +03:00
# include "libnet/libnet.h"
2007-12-11 23:21:17 +03:00
2007-12-23 05:47:16 +03:00
/**********************************************************************
*
* Helper functions ( mostly registry related )
* TODO : These should be eventually static .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-29 16:32:13 +03:00
/**
* add a string to a talloced array of strings .
*/
2008-01-03 15:31:23 +03:00
static WERROR libnet_conf_add_string_to_array ( TALLOC_CTX * mem_ctx ,
char * * * array ,
uint32_t count ,
const char * string )
2007-12-29 16:32:13 +03:00
{
char * * new_array = NULL ;
if ( ( array = = NULL ) | | ( string = = NULL ) ) {
return WERR_INVALID_PARAM ;
}
new_array = TALLOC_REALLOC_ARRAY ( mem_ctx , * array , char * , count + 1 ) ;
if ( new_array = = NULL ) {
return WERR_NOMEM ;
}
new_array [ count ] = talloc_strdup ( new_array , string ) ;
* array = new_array ;
return WERR_OK ;
}
2008-01-03 02:49:53 +03:00
/**
2008-01-03 13:33:17 +03:00
* Open a registry key specified by " path "
2007-12-11 23:21:17 +03:00
*/
2008-01-03 15:33:10 +03:00
static WERROR libnet_conf_reg_open_path ( TALLOC_CTX * mem_ctx ,
const char * path ,
uint32 desired_access ,
struct registry_key * * key )
2007-12-11 23:21:17 +03:00
{
WERROR werr = WERR_OK ;
NT_USER_TOKEN * token ;
2008-01-03 03:26:31 +03:00
TALLOC_CTX * tmp_ctx = NULL ;
2007-12-11 23:21:17 +03:00
2008-01-03 03:07:30 +03:00
if ( path = = NULL ) {
DEBUG ( 1 , ( " Error: NULL path string given \n " ) ) ;
werr = WERR_INVALID_PARAM ;
goto done ;
}
2008-01-03 03:26:31 +03:00
tmp_ctx = talloc_new ( mem_ctx ) ;
if ( tmp_ctx = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
token = registry_create_admin_token ( tmp_ctx ) ;
2008-01-03 03:07:30 +03:00
if ( token = = NULL ) {
2007-12-11 23:21:17 +03:00
DEBUG ( 1 , ( " Error creating admin token \n " ) ) ;
2008-01-03 02:52:55 +03:00
/* what is the appropriate error code here? */
werr = WERR_CAN_NOT_COMPLETE ;
2007-12-11 23:21:17 +03:00
goto done ;
}
2008-01-03 03:07:30 +03:00
werr = reg_open_path ( mem_ctx , path , desired_access , token , key ) ;
2007-12-11 23:21:17 +03:00
2007-12-26 02:53:19 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
DEBUG ( 1 , ( " Error opening registry path '%s': %s \n " ,
path , dos_errstr ( werr ) ) ) ;
}
2008-01-03 03:07:30 +03:00
done :
2008-01-03 03:26:31 +03:00
TALLOC_FREE ( tmp_ctx ) ;
2008-01-03 03:07:30 +03:00
return werr ;
}
/**
* Open a subkey of KEY_SMBCONF ( i . e a service )
*/
2008-01-03 15:36:25 +03:00
static WERROR libnet_conf_reg_open_service_key ( TALLOC_CTX * ctx ,
const char * servicename ,
uint32 desired_access ,
struct registry_key * * key )
2008-01-03 03:07:30 +03:00
{
WERROR werr = WERR_OK ;
char * path = NULL ;
if ( servicename = = NULL ) {
DEBUG ( 3 , ( " Error: NULL servicename given. \n " ) ) ;
werr = WERR_INVALID_PARAM ;
goto done ;
}
path = talloc_asprintf ( ctx , " %s \\ %s " , KEY_SMBCONF , servicename ) ;
2008-01-03 15:33:10 +03:00
werr = libnet_conf_reg_open_path ( ctx , path , desired_access , key ) ;
2008-01-03 03:07:30 +03:00
2007-12-11 23:21:17 +03:00
done :
TALLOC_FREE ( path ) ;
return werr ;
}
2007-12-26 03:03:28 +03:00
/*
* open the base key KEY_SMBCONF
*/
2008-01-03 15:38:55 +03:00
static WERROR libnet_conf_reg_open_base_key ( TALLOC_CTX * ctx ,
uint32 desired_access ,
struct registry_key * * key )
2007-12-26 03:03:28 +03:00
{
2008-01-03 15:33:10 +03:00
return libnet_conf_reg_open_path ( ctx , KEY_SMBCONF , desired_access , key ) ;
2007-12-26 03:03:28 +03:00
}
2008-01-03 15:40:40 +03:00
static bool libnet_conf_value_exists ( struct registry_key * key ,
const char * param )
2007-12-23 05:47:16 +03:00
{
2007-12-24 02:57:04 +03:00
bool ret = false ;
2007-12-23 05:47:16 +03:00
WERROR werr = WERR_OK ;
2007-12-24 02:56:24 +03:00
TALLOC_CTX * ctx = talloc_stackframe ( ) ;
2007-12-23 05:47:16 +03:00
struct registry_value * value = NULL ;
werr = reg_queryvalue ( ctx , key , param , & value ) ;
if ( W_ERROR_IS_OK ( werr ) ) {
2007-12-24 02:57:04 +03:00
ret = true ;
2007-12-23 05:47:16 +03:00
}
2007-12-24 02:56:24 +03:00
TALLOC_FREE ( ctx ) ;
2007-12-23 05:47:16 +03:00
return ret ;
}
2007-12-11 23:21:17 +03:00
/*
* create a subkey of KEY_SMBCONF
*/
2008-01-03 15:42:40 +03:00
static WERROR libnet_conf_reg_create_service_key ( TALLOC_CTX * ctx ,
const char * subkeyname ,
struct registry_key * * newkey )
2007-12-11 23:21:17 +03:00
{
WERROR werr = WERR_OK ;
struct registry_key * create_parent = NULL ;
TALLOC_CTX * create_ctx ;
enum winreg_CreateAction action = REG_ACTION_NONE ;
/* create a new talloc ctx for creation. it will hold
* the intermediate parent key ( SMBCONF ) for creation
* and will be destroyed when leaving this function . . . */
if ( ! ( create_ctx = talloc_new ( ctx ) ) ) {
werr = WERR_NOMEM ;
goto done ;
}
2008-01-03 15:38:55 +03:00
werr = libnet_conf_reg_open_base_key ( create_ctx , REG_KEY_WRITE ,
& create_parent ) ;
2007-12-11 23:21:17 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
werr = reg_createkey ( ctx , create_parent , subkeyname ,
REG_KEY_WRITE , newkey , & action ) ;
if ( W_ERROR_IS_OK ( werr ) & & ( action ! = REG_CREATED_NEW_KEY ) ) {
2007-12-31 00:27:45 +03:00
DEBUG ( 10 , ( " Key '%s' already exists. \n " , subkeyname ) ) ;
2007-12-11 23:21:17 +03:00
werr = WERR_ALREADY_EXISTS ;
}
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-31 00:27:45 +03:00
DEBUG ( 5 , ( " Error creating key %s: %s \n " ,
subkeyname , dos_errstr ( werr ) ) ) ;
2007-12-11 23:21:17 +03:00
}
done :
TALLOC_FREE ( create_ctx ) ;
return werr ;
}
2007-12-23 05:34:36 +03:00
/*
* add a value to a key .
*/
2008-01-03 15:43:34 +03:00
static WERROR libnet_conf_reg_set_value ( struct registry_key * key ,
const char * valname ,
const char * valstr )
2007-12-23 05:34:36 +03:00
{
struct registry_value val ;
WERROR werr = WERR_OK ;
char * subkeyname ;
const char * canon_valname ;
const char * canon_valstr ;
if ( ! lp_canonicalize_parameter_with_value ( valname , valstr ,
& canon_valname ,
& canon_valstr ) )
{
if ( canon_valname = = NULL ) {
2007-12-31 00:27:45 +03:00
DEBUG ( 5 , ( " invalid parameter '%s' given \n " ,
valname ) ) ;
2007-12-23 05:34:36 +03:00
} else {
2007-12-31 00:27:45 +03:00
DEBUG ( 5 , ( " invalid value '%s' given for "
" parameter '%s' \n " , valstr , valname ) ) ;
2007-12-23 05:34:36 +03:00
}
werr = WERR_INVALID_PARAM ;
goto done ;
}
ZERO_STRUCT ( val ) ;
val . type = REG_SZ ;
val . v . sz . str = CONST_DISCARD ( char * , canon_valstr ) ;
val . v . sz . len = strlen ( canon_valstr ) + 1 ;
if ( registry_smbconf_valname_forbidden ( canon_valname ) ) {
2007-12-31 00:27:45 +03:00
DEBUG ( 5 , ( " Parameter '%s' not allowed in registry. \n " ,
canon_valname ) ) ;
2007-12-23 05:34:36 +03:00
werr = WERR_INVALID_PARAM ;
goto done ;
}
subkeyname = strrchr_m ( key - > key - > name , ' \\ ' ) ;
if ( ( subkeyname = = NULL ) | | ( * ( subkeyname + 1 ) = = ' \0 ' ) ) {
2007-12-31 00:27:45 +03:00
DEBUG ( 5 , ( " Invalid registry key '%s' given as "
" smbconf section. \n " , key - > key - > name ) ) ;
2007-12-23 05:34:36 +03:00
werr = WERR_INVALID_PARAM ;
goto done ;
}
subkeyname + + ;
if ( ! strequal ( subkeyname , GLOBAL_NAME ) & &
lp_parameter_is_global ( valname ) )
{
2007-12-31 00:27:45 +03:00
DEBUG ( 5 , ( " Global paramter '%s' not allowed in "
2007-12-23 05:34:36 +03:00
" service definition ('%s'). \n " , canon_valname ,
2007-12-31 00:27:45 +03:00
subkeyname ) ) ;
2007-12-23 05:34:36 +03:00
werr = WERR_INVALID_PARAM ;
goto done ;
}
werr = reg_setvalue ( key , canon_valname , & val ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-31 00:27:45 +03:00
DEBUG ( 5 , ( " Error adding value '%s' to "
2007-12-23 05:34:36 +03:00
" key '%s': %s \n " ,
2007-12-31 00:27:45 +03:00
canon_valname , key - > key - > name , dos_errstr ( werr ) ) ) ;
2007-12-23 05:34:36 +03:00
}
done :
return werr ;
}
2007-12-29 04:18:44 +03:00
/**
* format a registry_value into a string .
*
* This is intended to be used for smbconf registry values ,
* which are ar stored as REG_SZ values , so the incomplete
* handling should be ok .
*/
2008-01-03 15:45:14 +03:00
static char * libnet_conf_format_registry_value ( TALLOC_CTX * mem_ctx ,
struct registry_value * value )
2007-12-29 02:05:23 +03:00
{
char * result = NULL ;
2007-12-29 04:16:38 +03:00
/* alternatively, create a new talloc context? */
if ( mem_ctx = = NULL ) {
return result ;
}
2007-12-29 02:05:23 +03:00
switch ( value - > type ) {
case REG_DWORD :
result = talloc_asprintf ( mem_ctx , " %d " , value - > v . dword ) ;
break ;
case REG_SZ :
case REG_EXPAND_SZ :
result = talloc_asprintf ( mem_ctx , " %s " , value - > v . sz . str ) ;
break ;
case REG_MULTI_SZ : {
uint32 j ;
for ( j = 0 ; j < value - > v . multi_sz . num_strings ; j + + ) {
result = talloc_asprintf ( mem_ctx , " \" %s \" " ,
value - > v . multi_sz . strings [ j ] ) ;
}
break ;
}
case REG_BINARY :
result = talloc_asprintf ( mem_ctx , " binary (%d bytes) " ,
( int ) value - > v . binary . length ) ;
break ;
default :
result = talloc_asprintf ( mem_ctx , " <unprintable> " ) ;
break ;
}
return result ;
}
2007-12-29 05:38:13 +03:00
/**
* Get the values of a key as a list of value names
* and a list of value strings ( ordered )
*/
2008-01-03 15:46:45 +03:00
static WERROR libnet_conf_reg_get_values ( TALLOC_CTX * mem_ctx ,
struct registry_key * key ,
uint32_t * num_values ,
char * * * value_names ,
char * * * value_strings )
2007-12-29 05:38:13 +03:00
{
2007-12-29 18:35:51 +03:00
TALLOC_CTX * tmp_ctx = NULL ;
2007-12-29 05:38:13 +03:00
WERROR werr = WERR_OK ;
uint32_t count ;
struct registry_value * valvalue = NULL ;
char * valname = NULL ;
char * * tmp_valnames = NULL ;
char * * tmp_valstrings = NULL ;
if ( ( num_values = = NULL ) | | ( value_names = = NULL ) | |
( value_strings = = NULL ) )
{
werr = WERR_INVALID_PARAM ;
goto done ;
}
tmp_ctx = talloc_new ( mem_ctx ) ;
if ( tmp_ctx = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
for ( count = 0 ;
W_ERROR_IS_OK ( werr = reg_enumvalue ( tmp_ctx , key , count , & valname ,
& valvalue ) ) ;
count + + )
{
2007-12-29 16:32:13 +03:00
char * valstring ;
2008-01-03 15:31:23 +03:00
werr = libnet_conf_add_string_to_array ( tmp_ctx ,
& tmp_valnames ,
count , valname ) ;
2007-12-29 16:32:13 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-01-03 15:45:14 +03:00
valstring = libnet_conf_format_registry_value ( tmp_ctx ,
valvalue ) ;
2008-01-03 15:31:23 +03:00
werr = libnet_conf_add_string_to_array ( tmp_ctx ,
& tmp_valstrings ,
count ,
valstring ) ;
2007-12-29 16:32:13 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-12-29 05:38:13 +03:00
goto done ;
}
}
if ( ! W_ERROR_EQUAL ( WERR_NO_MORE_ITEMS , werr ) ) {
goto done ;
}
werr = WERR_OK ;
2007-12-29 19:02:27 +03:00
* num_values = count ;
2007-12-29 05:38:13 +03:00
if ( count > 0 ) {
* value_names = talloc_move ( mem_ctx , & tmp_valnames ) ;
* value_strings = talloc_move ( mem_ctx , & tmp_valstrings ) ;
2007-12-29 19:06:49 +03:00
} else {
* value_names = NULL ;
* value_strings = NULL ;
2007-12-29 05:38:13 +03:00
}
done :
TALLOC_FREE ( tmp_ctx ) ;
return werr ;
}
2007-12-29 02:05:23 +03:00
2007-12-23 05:47:16 +03:00
/**********************************************************************
*
* The actual net conf api functions , that are exported .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-25 05:08:00 +03:00
/**
* Drop the whole configuration ( restarting empty ) .
*/
2008-01-03 15:48:56 +03:00
WERROR libnet_conf_drop ( void )
2007-12-25 04:55:07 +03:00
{
char * path , * p ;
WERROR werr = WERR_OK ;
struct registry_key * parent_key = NULL ;
struct registry_key * new_key = NULL ;
2007-12-25 05:05:06 +03:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-12-25 04:55:07 +03:00
enum winreg_CreateAction action ;
2007-12-25 05:05:06 +03:00
path = talloc_strdup ( mem_ctx , KEY_SMBCONF ) ;
2007-12-25 04:55:07 +03:00
if ( path = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
p = strrchr ( path , ' \\ ' ) ;
* p = ' \0 ' ;
2008-01-03 15:33:10 +03:00
werr = libnet_conf_reg_open_path ( mem_ctx , path , REG_KEY_WRITE ,
& parent_key ) ;
2007-12-25 04:55:07 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-25 05:05:06 +03:00
werr = reg_deletekey_recursive ( mem_ctx , parent_key , p + 1 ) ;
2007-12-25 04:55:07 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-25 05:05:06 +03:00
werr = reg_createkey ( mem_ctx , parent_key , p + 1 , REG_KEY_WRITE ,
2007-12-25 04:55:07 +03:00
& new_key , & action ) ;
done :
2007-12-25 05:05:06 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-12-25 04:55:07 +03:00
return werr ;
}
2007-12-30 00:08:11 +03:00
/**
* Get the whole configuration as lists of strings with counts :
*
* num_shares : number of shares
* share_names : list of length num_shares of share names
* num_params : list of length num_shares of parameter counts for each share
* param_names : list of lists of parameter names for each share
* param_values : list of lists of parameter values for each share
*/
2008-01-03 15:50:55 +03:00
WERROR libnet_conf_get_config ( TALLOC_CTX * mem_ctx , uint32_t * num_shares ,
char * * * share_names , uint32_t * * num_params ,
char * * * * param_names , char * * * * param_values )
2007-12-30 00:08:11 +03:00
{
WERROR werr = WERR_OK ;
TALLOC_CTX * tmp_ctx = NULL ;
uint32_t tmp_num_shares ;
char * * tmp_share_names ;
uint32_t * tmp_num_params ;
char * * * tmp_param_names ;
char * * * tmp_param_values ;
uint32_t count ;
if ( ( num_shares = = NULL ) | | ( share_names = = NULL ) | |
( num_params = = NULL ) | | ( param_names = = NULL ) | |
( param_values = = NULL ) )
{
werr = WERR_INVALID_PARAM ;
goto done ;
}
tmp_ctx = talloc_new ( mem_ctx ) ;
if ( tmp_ctx = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
2008-01-03 15:53:04 +03:00
werr = libnet_conf_get_share_names ( tmp_ctx , & tmp_num_shares ,
& tmp_share_names ) ;
2007-12-30 00:08:11 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
tmp_num_params = TALLOC_ARRAY ( tmp_ctx , uint32_t , tmp_num_shares ) ;
tmp_param_names = TALLOC_ARRAY ( tmp_ctx , char * * , tmp_num_shares ) ;
tmp_param_values = TALLOC_ARRAY ( tmp_ctx , char * * , tmp_num_shares ) ;
if ( ( tmp_num_params = = NULL ) | | ( tmp_param_names = = NULL ) | |
( tmp_param_values = = NULL ) )
{
werr = WERR_NOMEM ;
goto done ;
}
for ( count = 0 ; count < tmp_num_shares ; count + + ) {
2008-01-03 15:59:14 +03:00
werr = libnet_conf_get_share ( mem_ctx , tmp_share_names [ count ] ,
& tmp_num_params [ count ] ,
& tmp_param_names [ count ] ,
& tmp_param_values [ count ] ) ;
2007-12-30 00:08:11 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
}
werr = WERR_OK ;
* num_shares = tmp_num_shares ;
if ( tmp_num_shares > 0 ) {
* share_names = talloc_move ( mem_ctx , & tmp_share_names ) ;
* num_params = talloc_move ( mem_ctx , & tmp_num_params ) ;
* param_names = talloc_move ( mem_ctx , & tmp_param_names ) ;
* param_values = talloc_move ( mem_ctx , & tmp_param_values ) ;
} else {
* share_names = NULL ;
* num_params = NULL ;
* param_names = NULL ;
* param_values = NULL ;
}
done :
TALLOC_FREE ( tmp_ctx ) ;
return werr ;
}
2007-12-29 14:53:19 +03:00
/**
* get the list of share names defined in the configuration .
*/
2008-01-03 15:53:04 +03:00
WERROR libnet_conf_get_share_names ( TALLOC_CTX * mem_ctx , uint32_t * num_shares ,
char * * * share_names )
2007-12-29 14:52:09 +03:00
{
uint32_t count ;
2007-12-29 16:38:42 +03:00
uint32_t added_count = 0 ;
2007-12-29 18:35:51 +03:00
TALLOC_CTX * tmp_ctx = NULL ;
2007-12-29 14:52:09 +03:00
WERROR werr = WERR_OK ;
struct registry_key * key = NULL ;
char * subkey_name = NULL ;
char * * tmp_share_names = NULL ;
if ( ( num_shares = = NULL ) | | ( share_names = = NULL ) ) {
werr = WERR_INVALID_PARAM ;
goto done ;
}
tmp_ctx = talloc_new ( mem_ctx ) ;
if ( tmp_ctx = = NULL ) {
werr = WERR_NOMEM ;
goto done ;
}
2007-12-29 16:38:42 +03:00
/* make sure "global" is always listed first */
2008-01-03 15:54:31 +03:00
if ( libnet_conf_share_exists ( GLOBAL_NAME ) ) {
2008-01-03 15:31:23 +03:00
werr = libnet_conf_add_string_to_array ( tmp_ctx ,
& tmp_share_names ,
0 , GLOBAL_NAME ) ;
2007-12-29 16:38:42 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
added_count + + ;
}
2008-01-03 15:38:55 +03:00
werr = libnet_conf_reg_open_base_key ( tmp_ctx , SEC_RIGHTS_ENUM_SUBKEYS ,
& key ) ;
2007-12-29 14:52:09 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
for ( count = 0 ;
W_ERROR_IS_OK ( werr = reg_enumkey ( tmp_ctx , key , count ,
& subkey_name , NULL ) ) ;
count + + )
{
2007-12-29 16:38:42 +03:00
if ( strequal ( subkey_name , GLOBAL_NAME ) ) {
continue ;
}
2008-01-03 15:31:23 +03:00
werr = libnet_conf_add_string_to_array ( tmp_ctx ,
& tmp_share_names ,
added_count ,
subkey_name ) ;
2007-12-29 16:32:13 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-29 16:38:42 +03:00
added_count + + ;
2007-12-29 14:52:09 +03:00
}
if ( ! W_ERROR_EQUAL ( WERR_NO_MORE_ITEMS , werr ) ) {
goto done ;
}
werr = WERR_OK ;
2007-12-29 16:38:42 +03:00
* num_shares = added_count ;
if ( added_count > 0 ) {
2007-12-29 14:52:09 +03:00
* share_names = talloc_move ( mem_ctx , & tmp_share_names ) ;
2007-12-29 19:06:49 +03:00
} else {
* share_names = NULL ;
2007-12-29 14:52:09 +03:00
}
done :
TALLOC_FREE ( tmp_ctx ) ;
return werr ;
}
2007-12-31 03:14:44 +03:00
/**
* check if a share / service of a given name exists
*/
2008-01-03 15:54:31 +03:00
bool libnet_conf_share_exists ( const char * servicename )
2007-12-31 03:14:44 +03:00
{
bool ret = false ;
WERROR werr = WERR_OK ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
struct registry_key * key = NULL ;
2008-01-03 15:36:25 +03:00
werr = libnet_conf_reg_open_service_key ( mem_ctx , servicename ,
REG_KEY_READ , & key ) ;
2007-12-31 03:14:44 +03:00
if ( W_ERROR_IS_OK ( werr ) ) {
ret = true ;
}
TALLOC_FREE ( mem_ctx ) ;
return ret ;
}
2008-01-03 13:30:14 +03:00
/**
* Add a service if it does not already exist .
*/
2008-01-03 15:55:43 +03:00
WERROR libnet_conf_create_share ( const char * servicename )
2008-01-03 13:30:14 +03:00
{
WERROR werr ;
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
struct registry_key * key = NULL ;
2008-01-03 15:54:31 +03:00
if ( libnet_conf_share_exists ( servicename ) ) {
2008-01-03 13:30:14 +03:00
werr = WERR_ALREADY_EXISTS ;
goto done ;
}
2008-01-03 15:42:40 +03:00
werr = libnet_conf_reg_create_service_key ( mem_ctx , servicename , & key ) ;
2008-01-03 13:30:14 +03:00
done :
TALLOC_FREE ( mem_ctx ) ;
return werr ;
}
2007-12-29 05:38:13 +03:00
/**
* get a definition of a share ( service ) from configuration .
*/
2008-01-03 15:59:14 +03:00
WERROR libnet_conf_get_share ( TALLOC_CTX * mem_ctx , const char * servicename ,
uint32_t * num_params , char * * * param_names ,
char * * * param_values )
2007-12-29 05:38:13 +03:00
{
WERROR werr = WERR_OK ;
struct registry_key * key = NULL ;
2008-01-03 15:36:25 +03:00
werr = libnet_conf_reg_open_service_key ( mem_ctx , servicename ,
REG_KEY_READ , & key ) ;
2007-12-29 05:38:13 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-01-03 15:46:45 +03:00
werr = libnet_conf_reg_get_values ( mem_ctx , key , num_params ,
param_names , param_values ) ;
2007-12-29 05:38:13 +03:00
done :
TALLOC_FREE ( key ) ;
return werr ;
}
2007-12-25 04:24:39 +03:00
/**
* delete a service from configuration
2007-12-25 04:21:30 +03:00
*/
2008-01-03 16:01:50 +03:00
WERROR libnet_conf_delete_share ( const char * servicename )
2007-12-25 04:21:30 +03:00
{
WERROR werr = WERR_OK ;
struct registry_key * key = NULL ;
2007-12-25 04:31:41 +03:00
TALLOC_CTX * ctx = talloc_stackframe ( ) ;
2007-12-25 04:21:30 +03:00
2008-01-03 15:38:55 +03:00
werr = libnet_conf_reg_open_base_key ( ctx , REG_KEY_WRITE , & key ) ;
2007-12-25 04:21:30 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-25 04:31:41 +03:00
werr = reg_deletekey_recursive ( key , key , servicename ) ;
2007-12-25 04:21:30 +03:00
done :
2007-12-25 04:31:41 +03:00
TALLOC_FREE ( ctx ) ;
2007-12-25 04:21:30 +03:00
return werr ;
}
2007-12-29 04:26:33 +03:00
/**
* set a configuration parameter to the value provided .
*/
2007-12-25 05:29:05 +03:00
WERROR libnet_smbconf_setparm ( const char * service ,
2007-12-23 05:41:55 +03:00
const char * param ,
const char * valstr )
{
WERROR werr ;
struct registry_key * key = NULL ;
2007-12-25 05:29:05 +03:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-12-23 05:41:55 +03:00
2008-01-03 15:54:31 +03:00
if ( ! libnet_conf_share_exists ( service ) ) {
2008-01-03 13:30:14 +03:00
werr = WERR_NO_SUCH_SERVICE ;
goto done ;
2007-12-23 05:41:55 +03:00
}
2008-01-03 13:30:14 +03:00
2008-01-03 15:36:25 +03:00
werr = libnet_conf_reg_open_service_key ( mem_ctx , service , REG_KEY_WRITE ,
& key ) ;
2007-12-24 03:00:46 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-23 05:41:55 +03:00
2008-01-03 15:43:34 +03:00
werr = libnet_conf_reg_set_value ( key , param , valstr ) ;
2007-12-23 05:41:55 +03:00
2007-12-24 03:00:46 +03:00
done :
2007-12-25 05:29:05 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-12-23 05:41:55 +03:00
return werr ;
}
2007-12-29 04:26:33 +03:00
/**
* get the value of a configuration parameter as a string
*/
2007-12-23 17:07:20 +03:00
WERROR libnet_smbconf_getparm ( TALLOC_CTX * mem_ctx ,
const char * service ,
const char * param ,
2007-12-29 04:12:33 +03:00
char * * valstr )
2007-12-23 17:07:20 +03:00
{
2007-12-29 04:12:33 +03:00
WERROR werr = WERR_OK ;
2007-12-23 17:07:20 +03:00
struct registry_key * key = NULL ;
2007-12-29 03:17:39 +03:00
struct registry_value * value = NULL ;
2007-12-23 17:07:20 +03:00
2007-12-29 04:12:33 +03:00
if ( valstr = = NULL ) {
werr = WERR_INVALID_PARAM ;
goto done ;
}
2008-01-03 15:54:31 +03:00
if ( ! libnet_conf_share_exists ( service ) ) {
2007-12-24 02:47:43 +03:00
werr = WERR_NO_SUCH_SERVICE ;
goto done ;
2007-12-23 17:07:20 +03:00
}
2008-01-03 15:36:25 +03:00
werr = libnet_conf_reg_open_service_key ( mem_ctx , service , REG_KEY_READ ,
& key ) ;
2007-12-24 02:47:43 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-23 17:07:20 +03:00
2008-01-03 15:40:40 +03:00
if ( ! libnet_conf_value_exists ( key , param ) ) {
2007-12-24 02:47:43 +03:00
werr = WERR_INVALID_PARAM ;
goto done ;
2007-12-23 17:07:20 +03:00
}
2007-12-29 04:12:33 +03:00
werr = reg_queryvalue ( mem_ctx , key , param , & value ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2008-01-03 15:45:14 +03:00
* valstr = libnet_conf_format_registry_value ( mem_ctx , value ) ;
2007-12-29 04:12:33 +03:00
if ( * valstr = = NULL ) {
werr = WERR_NOMEM ;
}
2007-12-23 17:07:20 +03:00
2007-12-24 02:47:43 +03:00
done :
TALLOC_FREE ( key ) ;
2007-12-29 04:12:33 +03:00
TALLOC_FREE ( value ) ;
2007-12-23 17:07:20 +03:00
return werr ;
}
2007-12-29 04:26:33 +03:00
/**
* delete a parameter from configuration
*/
2007-12-25 05:34:04 +03:00
WERROR libnet_smbconf_delparm ( const char * service ,
2007-12-23 04:55:25 +03:00
const char * param )
{
struct registry_key * key = NULL ;
WERROR werr = WERR_OK ;
2007-12-25 05:34:04 +03:00
TALLOC_CTX * mem_ctx = talloc_stackframe ( ) ;
2007-12-23 04:55:25 +03:00
2008-01-03 15:54:31 +03:00
if ( ! libnet_conf_share_exists ( service ) ) {
2007-12-23 04:55:25 +03:00
return WERR_NO_SUCH_SERVICE ;
}
2008-01-03 15:36:25 +03:00
werr = libnet_conf_reg_open_service_key ( mem_ctx , service , REG_KEY_ALL ,
& key ) ;
2007-12-24 03:03:14 +03:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
goto done ;
}
2007-12-23 04:55:25 +03:00
2008-01-03 15:40:40 +03:00
if ( ! libnet_conf_value_exists ( key , param ) ) {
2007-12-24 03:03:14 +03:00
werr = WERR_INVALID_PARAM ;
goto done ;
2007-12-23 04:55:25 +03:00
}
werr = reg_deletevalue ( key , param ) ;
2007-12-24 03:03:14 +03:00
done :
2007-12-25 05:34:04 +03:00
TALLOC_FREE ( mem_ctx ) ;
2007-12-24 01:02:47 +03:00
return werr ;
2007-12-23 04:55:25 +03:00
}
2007-12-23 05:52:00 +03:00
/**********************************************************************
*
2007-12-25 05:16:25 +03:00
* Convenience functions that are also exported .
2007-12-23 05:52:00 +03:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-25 05:29:05 +03:00
WERROR libnet_smbconf_set_global_param ( const char * param ,
2007-12-23 05:52:00 +03:00
const char * val )
{
2007-12-25 05:29:05 +03:00
return libnet_smbconf_setparm ( GLOBAL_NAME , param , val ) ;
2007-12-23 05:52:00 +03:00
}