2004-04-04 16:24:08 +00:00
/*
Unix SMB / CIFS implementation .
Registry interface
Copyright ( C ) Jelmer Vernooij 2004.
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2004-11-02 10:13:26 +00:00
# include "registry.h"
2004-04-04 16:24:08 +00:00
# include <gconf/gconf-client.h>
2004-04-08 22:39:47 +00:00
static WERROR gerror_to_werror ( GError * error )
{
if ( error = = NULL ) return WERR_OK ;
/* FIXME */
return WERR_FOOBAR ;
}
2004-12-10 20:07:04 +00:00
static WERROR reg_open_gconf_hive ( struct registry_hive * h , struct registry_key * * k )
2004-04-04 16:24:08 +00:00
{
2004-09-22 12:32:31 +00:00
g_type_init ( ) ;
2004-04-04 16:24:08 +00:00
h - > backend_data = ( void * ) gconf_client_get_default ( ) ;
2004-04-08 22:39:47 +00:00
if ( ! h - > backend_data ) return WERR_FOOBAR ;
2004-09-22 12:32:31 +00:00
2004-12-10 20:07:04 +00:00
* k = talloc_p ( h , struct registry_key ) ;
( * k ) - > name = talloc_strdup ( * k , " " ) ;
( * k ) - > path = talloc_strdup ( * k , " " ) ;
( * k ) - > backend_data = talloc_strdup ( * k , " / " ) ;
2004-04-08 22:39:47 +00:00
return WERR_OK ;
2004-04-04 16:24:08 +00:00
}
2004-12-10 22:28:49 +00:00
static WERROR gconf_open_key ( TALLOC_CTX * mem_ctx , struct registry_key * h , const char * name , struct registry_key * * key )
2004-04-04 16:24:08 +00:00
{
2004-09-22 12:32:31 +00:00
struct registry_key * ret ;
2004-05-23 14:18:08 +00:00
char * fullpath ;
2004-12-10 22:28:49 +00:00
fullpath = talloc_asprintf ( mem_ctx , " %s%s%s " ,
( char * ) h - > backend_data ,
strlen ( ( char * ) h - > backend_data ) = = 1 ? " " : " / " ,
reg_path_win2unix ( talloc_strdup ( mem_ctx , name ) ) ) ;
2004-04-04 16:24:08 +00:00
/* Check if key exists */
2004-12-10 22:28:49 +00:00
if ( ! gconf_client_dir_exists ( ( GConfClient * ) h - > hive - > backend_data , fullpath , NULL ) ) {
2004-04-08 22:39:47 +00:00
return WERR_DEST_NOT_FOUND ;
2004-04-04 16:24:08 +00:00
}
2004-09-22 12:32:31 +00:00
ret = talloc_p ( mem_ctx , struct registry_key ) ;
2004-10-29 01:10:40 +00:00
ret - > backend_data = fullpath ;
2004-04-04 16:24:08 +00:00
2004-04-08 22:39:47 +00:00
* key = ret ;
return WERR_OK ;
2004-04-04 16:24:08 +00:00
}
2004-09-22 12:32:31 +00:00
static WERROR gconf_get_value_by_id ( TALLOC_CTX * mem_ctx , struct registry_key * p , int idx , struct registry_value * * val )
2004-04-04 16:24:08 +00:00
{
GSList * entries ;
GSList * cur ;
2004-09-22 12:32:31 +00:00
GConfEntry * entry ;
GConfValue * value ;
struct registry_value * newval ;
2004-04-05 10:28:59 +00:00
char * fullpath = p - > backend_data ;
2004-09-22 12:32:31 +00:00
int i ;
cur = entries = gconf_client_all_entries ( ( GConfClient * ) p - > hive - > backend_data , fullpath , NULL ) ;
for ( i = 0 ; i < idx & & cur ; i + + ) cur = cur - > next ;
if ( ! cur ) return WERR_NO_MORE_ITEMS ;
entry = cur - > data ;
value = gconf_entry_get_value ( entry ) ;
newval = talloc_p ( mem_ctx , struct registry_value ) ;
newval - > name = talloc_strdup ( mem_ctx , strrchr ( gconf_entry_get_key ( entry ) , ' / ' ) + 1 ) ;
if ( value ) {
switch ( value - > type ) {
case GCONF_VALUE_INVALID :
newval - > data_type = REG_NONE ;
break ;
case GCONF_VALUE_STRING :
newval - > data_type = REG_SZ ;
newval - > data_blk = talloc_strdup ( mem_ctx , gconf_value_get_string ( value ) ) ;
newval - > data_len = strlen ( newval - > data_blk ) ;
break ;
case GCONF_VALUE_INT :
newval - > data_type = REG_DWORD ;
newval - > data_blk = talloc_p ( mem_ctx , long ) ;
* ( ( long * ) newval - > data_blk ) = gconf_value_get_int ( value ) ;
newval - > data_len = sizeof ( long ) ;
break ;
case GCONF_VALUE_FLOAT :
newval - > data_blk = talloc_p ( mem_ctx , double ) ;
newval - > data_type = REG_BINARY ;
* ( ( double * ) newval - > data_blk ) = gconf_value_get_float ( value ) ;
newval - > data_len = sizeof ( double ) ;
break ;
case GCONF_VALUE_BOOL :
newval - > data_blk = talloc_p ( mem_ctx , BOOL ) ;
newval - > data_type = REG_BINARY ;
* ( ( BOOL * ) newval - > data_blk ) = gconf_value_get_bool ( value ) ;
newval - > data_len = sizeof ( BOOL ) ;
break ;
default :
newval - > data_type = REG_NONE ;
DEBUG ( 0 , ( " Not implemented.. \n " ) ) ;
break ;
}
} else newval - > data_type = REG_NONE ;
2004-04-04 16:24:08 +00:00
g_slist_free ( entries ) ;
2004-09-22 12:32:31 +00:00
* val = newval ;
2004-04-08 22:39:47 +00:00
return WERR_OK ;
2004-04-04 16:24:08 +00:00
}
2004-09-22 12:32:31 +00:00
static WERROR gconf_get_subkey_by_id ( TALLOC_CTX * mem_ctx , struct registry_key * p , int idx , struct registry_key * * sub )
2004-04-04 16:24:08 +00:00
{
GSList * dirs ;
GSList * cur ;
2004-09-22 12:32:31 +00:00
int i ;
2004-04-05 10:28:59 +00:00
char * fullpath = p - > backend_data ;
2004-09-22 12:32:31 +00:00
cur = dirs = gconf_client_all_dirs ( ( GConfClient * ) p - > hive - > backend_data , fullpath , NULL ) ;
for ( i = 0 ; i < idx & & cur ; i + + ) cur = cur - > next ;
if ( ! cur ) return WERR_NO_MORE_ITEMS ;
* sub = talloc_p ( mem_ctx , struct registry_key ) ;
( * sub ) - > name = talloc_strdup ( mem_ctx , strrchr ( ( char * ) cur - > data , ' / ' ) + 1 ) ;
( * sub ) - > backend_data = talloc_strdup ( mem_ctx , cur - > data ) ;
2004-04-04 16:24:08 +00:00
g_slist_free ( dirs ) ;
2004-04-08 22:39:47 +00:00
return WERR_OK ;
2004-04-04 16:24:08 +00:00
}
2004-09-22 12:32:31 +00:00
static WERROR gconf_set_value ( struct registry_key * key , const char * valname , int type , void * data , int len )
2004-04-04 16:24:08 +00:00
{
GError * error = NULL ;
char * valpath ;
2004-09-22 12:32:31 +00:00
asprintf ( & valpath , " %s/%s " , key - > path , valname ) ;
2004-04-04 16:24:08 +00:00
switch ( type ) {
case REG_SZ :
case REG_EXPAND_SZ :
2004-09-22 12:32:31 +00:00
gconf_client_set_string ( ( GConfClient * ) key - > hive - > backend_data , valpath , data , & error ) ;
SAFE_FREE ( valpath ) ;
2004-04-08 22:39:47 +00:00
return gerror_to_werror ( error ) ;
2004-04-04 16:24:08 +00:00
case REG_DWORD :
2004-09-22 12:32:31 +00:00
gconf_client_set_int ( ( GConfClient * ) key - > hive - > backend_data , valpath ,
2004-04-04 16:24:08 +00:00
* ( ( int * ) data ) , & error ) ;
2004-09-22 12:32:31 +00:00
SAFE_FREE ( valpath ) ;
2004-04-08 22:39:47 +00:00
return gerror_to_werror ( error ) ;
2004-04-04 16:24:08 +00:00
default :
DEBUG ( 0 , ( " Unsupported type: %d \n " , type ) ) ;
2004-09-22 12:32:31 +00:00
SAFE_FREE ( valpath ) ;
2004-04-08 22:39:47 +00:00
return WERR_NOT_SUPPORTED ;
2004-04-04 16:24:08 +00:00
}
2004-04-08 22:39:47 +00:00
return WERR_NOT_SUPPORTED ;
2004-04-04 16:24:08 +00:00
}
2004-12-10 20:07:04 +00:00
static struct hive_operations reg_backend_gconf = {
2004-04-04 16:24:08 +00:00
. name = " gconf " ,
2004-09-22 12:32:31 +00:00
. open_hive = reg_open_gconf_hive ,
2004-04-04 16:24:08 +00:00
. open_key = gconf_open_key ,
2004-09-22 12:32:31 +00:00
. get_subkey_by_index = gconf_get_subkey_by_id ,
. get_value_by_index = gconf_get_value_by_id ,
. set_value = gconf_set_value ,
2004-04-04 16:24:08 +00:00
/* Note:
* since GConf uses schemas for what keys and values are allowed , there
* is no way of ' emulating ' add_key and del_key here .
*/
} ;
2004-05-13 10:20:53 +00:00
NTSTATUS registry_gconf_init ( void )
2004-04-04 16:24:08 +00:00
{
2004-11-14 22:23:23 +00:00
return registry_register ( & reg_backend_gconf ) ;
2004-04-04 16:24:08 +00:00
}