2004-04-04 20:24:08 +04:00
/*
Unix SMB / CIFS implementation .
endpoint server for the winreg pipe
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:42:47 +03:00
# include "rpc_server/dcerpc_server.h"
2004-11-02 09:52:59 +03:00
# include "registry.h"
2004-11-01 13:30:34 +03:00
# include "librpc/gen_ndr/ndr_winreg.h"
2004-05-04 10:11:47 +04:00
# include "rpc_server/common/common.h"
2004-04-04 20:24:08 +04:00
2004-10-29 02:38:27 +04:00
enum handle_types { HTYPE_REGVAL , HTYPE_REGKEY } ;
2004-12-10 23:07:04 +03:00
static NTSTATUS dcerpc_winreg_bind ( struct dcesrv_call_state * dce_call , const struct dcesrv_interface * iface )
2004-04-06 00:44:33 +04:00
{
2004-12-10 23:07:04 +03:00
struct registry_context * ctx ;
reg_open_local ( & ctx ) ;
dce_call - > conn - > private = ctx ;
return NT_STATUS_OK ;
2004-04-06 00:44:33 +04:00
}
2004-12-10 23:07:04 +03:00
# define DCESRV_INTERFACE_WINREG_BIND dcerpc_winreg_bind
static WERROR winreg_openhive ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx , uint32_t hkey , struct policy_handle * * outh )
2004-04-06 00:44:33 +04:00
{
2004-12-10 23:07:04 +03:00
struct registry_context * ctx = dce_call - > conn - > private ;
2004-10-29 02:38:27 +04:00
struct dcesrv_handle * h ;
2004-04-09 02:39:47 +04:00
WERROR error ;
2004-09-27 20:37:41 +04:00
2004-12-10 23:07:04 +03:00
h = dcesrv_handle_new ( dce_call - > conn , HTYPE_REGKEY ) ;
2004-09-27 20:37:41 +04:00
2004-12-11 23:06:40 +03:00
error = reg_get_predefined_key ( ctx , hkey , ( struct registry_key * * ) & h - > data ) ;
2004-12-10 23:07:04 +03:00
if ( ! W_ERROR_IS_OK ( error ) ) {
return error ;
2004-10-29 02:38:27 +04:00
}
* outh = & h - > wire_handle ;
2004-12-10 23:07:04 +03:00
return error ;
2004-10-29 02:38:27 +04:00
}
2004-04-06 00:44:33 +04:00
2004-05-04 10:07:52 +04:00
# define func_winreg_OpenHive(k,n) static WERROR winreg_Open ## k (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct winreg_Open ## k *r) \
2004-04-09 02:39:47 +04:00
{ \
2004-10-29 02:38:27 +04:00
return winreg_openhive ( dce_call , mem_ctx , n , & r - > out . handle ) ; \
2004-04-09 02:39:47 +04:00
}
2004-12-10 23:07:04 +03:00
func_winreg_OpenHive ( HKCR , HKEY_CLASSES_ROOT )
func_winreg_OpenHive ( HKCU , HKEY_CURRENT_USER )
func_winreg_OpenHive ( HKLM , HKEY_LOCAL_MACHINE )
func_winreg_OpenHive ( HKPD , HKEY_PERFORMANCE_DATA )
func_winreg_OpenHive ( HKU , HKEY_USERS )
func_winreg_OpenHive ( HKCC , HKEY_CURRENT_CONFIG )
func_winreg_OpenHive ( HKDD , HKEY_DYN_DATA )
2004-12-11 20:12:16 +03:00
func_winreg_OpenHive ( HKPT , HKEY_PERFORMANCE_TEXT )
func_winreg_OpenHive ( HKPN , HKEY_PERFORMANCE_NLSTEXT )
2004-04-04 20:24:08 +04:00
/*
2004-04-09 02:39:47 +04:00
winreg_CloseKey
2004-04-04 20:24:08 +04:00
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_CloseKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-09 02:39:47 +04:00
struct winreg_CloseKey * r )
2004-04-04 20:24:08 +04:00
{
2004-10-29 02:38:27 +04:00
struct dcesrv_handle * h ;
2004-05-04 10:07:52 +04:00
2004-10-29 02:38:27 +04:00
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
2004-05-04 10:07:52 +04:00
DCESRV_CHECK_HANDLE ( h ) ;
2004-04-06 00:44:33 +04:00
2004-04-09 02:39:47 +04:00
dcesrv_handle_destroy ( dce_call - > conn , h ) ;
2004-04-06 00:44:33 +04:00
2004-05-04 10:07:52 +04:00
return WERR_OK ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_CreateKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_CreateKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_CreateKey * r )
{
2004-10-29 02:38:27 +04:00
struct dcesrv_handle * h , * newh ;
2004-04-09 02:39:47 +04:00
WERROR error ;
2004-05-04 10:07:52 +04:00
2004-10-29 02:38:27 +04:00
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
2004-05-04 10:07:52 +04:00
DCESRV_CHECK_HANDLE ( h ) ;
2004-10-29 02:38:27 +04:00
newh = dcesrv_handle_new ( dce_call - > conn , HTYPE_REGKEY ) ;
error = reg_key_add_name ( newh , ( struct registry_key * ) h - > data , r - > in . key . name ,
r - > in . access_mask ,
r - > in . sec_desc ? r - > in . sec_desc - > sd : NULL ,
( struct registry_key * * ) & newh - > data ) ;
2004-04-09 02:39:47 +04:00
if ( W_ERROR_IS_OK ( error ) ) {
2004-10-29 02:38:27 +04:00
r - > out . handle = & newh - > wire_handle ;
} else {
dcesrv_handle_destroy ( dce_call - > conn , newh ) ;
2004-04-09 02:39:47 +04:00
}
2004-05-04 10:07:52 +04:00
return error ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_DeleteKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_DeleteKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_DeleteKey * r )
{
2004-10-29 02:38:27 +04:00
struct dcesrv_handle * h ;
struct registry_key * key ;
2004-05-04 10:07:52 +04:00
WERROR result ;
2004-10-29 02:38:27 +04:00
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
2004-05-04 10:07:52 +04:00
DCESRV_CHECK_HANDLE ( h ) ;
2004-04-09 02:39:47 +04:00
2004-10-29 02:38:27 +04:00
result = reg_open_key ( mem_ctx , ( struct registry_key * ) h - > data , r - > in . key . name , & key ) ;
2004-05-04 10:07:52 +04:00
if ( W_ERROR_IS_OK ( result ) ) {
return reg_key_del ( key ) ;
2004-04-09 02:39:47 +04:00
}
2004-05-04 10:07:52 +04:00
return result ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_DeleteValue
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_DeleteValue ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_DeleteValue * r )
{
2004-10-29 02:38:27 +04:00
struct dcesrv_handle * h ;
2004-12-13 03:45:29 +03:00
struct registry_key * key ;
2004-10-29 02:38:27 +04:00
2004-12-13 03:45:29 +03:00
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
2004-10-29 02:38:27 +04:00
DCESRV_CHECK_HANDLE ( h ) ;
2004-12-13 03:45:29 +03:00
key = h - > data ;
2004-10-29 02:38:27 +04:00
2004-12-13 03:45:29 +03:00
return reg_del_value ( key , r - > in . value . name ) ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_EnumKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_EnumKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_EnumKey * r )
{
2004-10-29 02:38:27 +04:00
struct dcesrv_handle * h ;
2004-09-22 16:33:39 +04:00
struct registry_key * key ;
2004-05-04 10:07:52 +04:00
2004-10-29 02:38:27 +04:00
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
2004-05-04 10:07:52 +04:00
DCESRV_CHECK_HANDLE ( h ) ;
2004-04-09 02:39:47 +04:00
2004-10-29 03:06:12 +04:00
r - > out . result = reg_key_get_subkey_by_index ( mem_ctx , ( struct registry_key * ) h - > data , r - > in . enum_index , & key ) ;
if ( W_ERROR_IS_OK ( r - > out . result ) ) {
r - > out . key_name_len = strlen ( key - > name ) ;
r - > out . out_name = talloc_zero_p ( mem_ctx , struct winreg_EnumKeyNameResponse ) ;
r - > out . out_name - > name = key - > name ;
r - > out . class = talloc_zero_p ( mem_ctx , struct winreg_String ) ;
r - > out . last_changed_time = talloc_zero_p ( mem_ctx , struct winreg_Time ) ;
}
2004-04-09 02:39:47 +04:00
2004-10-29 05:10:40 +04:00
return r - > out . result ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_EnumValue
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_EnumValue ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-12-09 15:50:50 +03:00
struct winreg_EnumValue * r )
2004-04-04 20:24:08 +04:00
{
2004-10-29 17:38:37 +04:00
struct dcesrv_handle * h ;
struct registry_key * key ;
struct registry_value * value ;
WERROR result ;
2004-10-29 02:38:27 +04:00
2004-10-29 17:38:37 +04:00
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
DCESRV_CHECK_HANDLE ( h ) ;
key = h - > data ;
result = reg_key_get_value_by_index ( mem_ctx , key , r - > in . enum_index , & value ) ;
if ( ! W_ERROR_IS_OK ( result ) ) {
return result ;
}
2004-12-09 15:54:01 +03:00
r - > out . type = talloc_p ( mem_ctx , uint32_t ) ;
* r - > out . type = value - > data_type ;
2004-10-29 17:38:37 +04:00
r - > out . name_out . name = value - > name ;
2004-12-09 15:50:50 +03:00
r - > out . value = value - > data_blk ;
r - > out . size = talloc_p ( mem_ctx , uint32_t ) ;
r - > out . length = r - > out . size ;
* r - > out . size = value - > data_len ;
2004-10-29 17:38:37 +04:00
return WERR_OK ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_FlushKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_FlushKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_FlushKey * r )
{
2004-10-29 15:44:59 +04:00
struct dcesrv_handle * h ;
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
DCESRV_CHECK_HANDLE ( h ) ;
return reg_key_flush ( h - > data ) ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_GetKeySecurity
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_GetKeySecurity ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_GetKeySecurity * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_LoadKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_LoadKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_LoadKey * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_NotifyChangeKeyValue
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_NotifyChangeKeyValue ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_NotifyChangeKeyValue * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_OpenKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_OpenKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_OpenKey * r )
{
2004-10-29 02:38:27 +04:00
struct dcesrv_handle * h , * newh ;
2004-05-04 10:07:52 +04:00
WERROR result ;
2004-10-29 02:38:27 +04:00
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
2004-05-04 10:07:52 +04:00
DCESRV_CHECK_HANDLE ( h ) ;
2004-04-09 02:39:47 +04:00
2004-10-29 02:38:27 +04:00
newh = dcesrv_handle_new ( dce_call - > conn , HTYPE_REGKEY ) ;
2004-04-09 02:39:47 +04:00
2004-10-29 02:38:27 +04:00
result = reg_open_key ( newh , ( struct registry_key * ) h - > data ,
r - > in . keyname . name , ( struct registry_key * * ) & newh - > data ) ;
2004-04-09 02:39:47 +04:00
2004-05-04 10:07:52 +04:00
if ( W_ERROR_IS_OK ( result ) ) {
2004-10-29 02:38:27 +04:00
r - > out . handle = & newh - > wire_handle ;
} else {
dcesrv_handle_destroy ( dce_call - > conn , newh ) ;
2004-04-09 02:39:47 +04:00
}
2004-04-06 00:44:33 +04:00
2004-05-04 10:07:52 +04:00
return result ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_QueryInfoKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_QueryInfoKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_QueryInfoKey * r )
{
2004-10-29 17:38:37 +04:00
struct dcesrv_handle * h ;
struct registry_key * k ;
WERROR ret ;
h = dcesrv_handle_fetch ( dce_call - > conn , r - > in . handle , HTYPE_REGKEY ) ;
DCESRV_CHECK_HANDLE ( h ) ;
k = h - > data ;
ret = reg_key_num_subkeys ( k , & r - > out . num_subkeys ) ;
if ( ! W_ERROR_IS_OK ( ret ) ) {
return ret ;
}
ret = reg_key_num_values ( k , & r - > out . num_values ) ;
if ( ! W_ERROR_IS_OK ( ret ) ) {
return ret ;
}
ret = reg_key_subkeysizes ( k , & r - > out . max_subkeysize , & r - > out . max_subkeylen ) ;
if ( ! W_ERROR_IS_OK ( ret ) ) {
return ret ;
}
ret = reg_key_valuesizes ( k , & r - > out . max_valnamelen , & r - > out . max_valbufsize ) ;
if ( ! W_ERROR_IS_OK ( ret ) ) {
return ret ;
}
r - > out . secdescsize = 0 ; /* FIXME */
ZERO_STRUCT ( r - > out . last_changed_time ) ; /* FIXME */ if ( ! W_ERROR_IS_OK ( ret ) ) {
return ret ;
}
return WERR_OK ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_QueryValue
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_QueryValue ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_QueryValue * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_ReplaceKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_ReplaceKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_ReplaceKey * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_RestoreKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_RestoreKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_RestoreKey * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_SaveKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_SaveKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_SaveKey * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_SetKeySecurity
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_SetKeySecurity ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_SetKeySecurity * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_SetValue
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_SetValue ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_SetValue * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_UnLoadKey
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_UnLoadKey ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_UnLoadKey * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_InitiateSystemShutdown
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_InitiateSystemShutdown ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_InitiateSystemShutdown * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_AbortSystemShutdown
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_AbortSystemShutdown ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_AbortSystemShutdown * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_GetVersion
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_GetVersion ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_GetVersion * r )
{
2004-10-29 17:38:37 +04:00
r - > out . version = 5 ;
return WERR_OK ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_QueryMultipleValues
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_QueryMultipleValues ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_QueryMultipleValues * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_InitiateSystemShutdownEx
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_InitiateSystemShutdownEx ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_InitiateSystemShutdownEx * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_SaveKeyEx
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_SaveKeyEx ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_SaveKeyEx * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/*
winreg_QueryMultipleValues2
*/
2004-05-04 10:07:52 +04:00
static WERROR winreg_QueryMultipleValues2 ( struct dcesrv_call_state * dce_call , TALLOC_CTX * mem_ctx ,
2004-04-04 20:24:08 +04:00
struct winreg_QueryMultipleValues2 * r )
{
2004-05-04 10:07:52 +04:00
return WERR_NOT_SUPPORTED ;
2004-04-04 20:24:08 +04:00
}
/* include the generated boilerplate */
# include "librpc/gen_ndr/ndr_winreg_s.c"