2007-06-14 11:29:35 +00:00
/*
* Unix SMB / CIFS implementation .
* Registry helper routines
* Copyright ( C ) Michael Adam 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
2007-07-09 19:25:36 +00:00
* Software Foundation ; either version 3 of the License , or ( at your option )
2007-06-14 11:29:35 +00:00
* 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
2007-07-10 05:23:25 +00:00
* this program ; if not , see < http : //www.gnu.org/licenses/>.
2007-06-14 11:29:35 +00:00
*/
# include "includes.h"
2007-09-28 23:05:52 +00:00
# undef DBGC_CLASS
# define DBGC_CLASS DBGC_REGISTRY
2009-03-23 23:14:45 +01:00
extern struct registry_ops smbconf_reg_ops ;
2007-06-14 11:29:35 +00:00
/*
* create a fake token just with enough rights to
2008-01-09 00:25:27 +01:00
* locally access the registry :
*
* - builtin administrators sid
* - disk operators privilege
2007-06-14 11:29:35 +00:00
*/
2008-01-09 01:17:13 +01:00
NTSTATUS registry_create_admin_token ( TALLOC_CTX * mem_ctx ,
NT_USER_TOKEN * * ptoken )
2007-06-14 11:29:35 +00:00
{
2008-01-09 00:11:31 +01:00
NTSTATUS status ;
2007-06-14 11:29:35 +00:00
NT_USER_TOKEN * token = NULL ;
2008-01-09 01:17:13 +01:00
if ( ptoken = = NULL ) {
return NT_STATUS_INVALID_PARAMETER ;
}
2008-01-09 00:11:31 +01:00
token = TALLOC_ZERO_P ( mem_ctx , NT_USER_TOKEN ) ;
if ( token = = NULL ) {
2007-06-14 11:29:35 +00:00
DEBUG ( 1 , ( " talloc failed \n " ) ) ;
2008-01-09 01:17:13 +01:00
status = NT_STATUS_NO_MEMORY ;
2007-06-14 11:29:35 +00:00
goto done ;
}
token - > privileges = se_disk_operators ;
2008-01-09 00:11:31 +01:00
status = add_sid_to_array ( token , & global_sid_Builtin_Administrators ,
& token - > user_sids , & token - > num_sids ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-06-14 11:29:35 +00:00
DEBUG ( 1 , ( " Error adding builtin administrators sid "
" to fake token. \n " ) ) ;
goto done ;
}
2008-01-09 01:17:13 +01:00
* ptoken = token ;
2007-06-14 11:29:35 +00:00
done :
2008-01-09 01:17:13 +01:00
return status ;
2007-06-14 11:29:35 +00:00
}
/*
* init the smbconf portion of the registry .
* for use in places where not the whole registry is needed ,
* e . g . utils / net_conf . c and loadparm . c
*/
2008-04-13 15:25:47 +02:00
WERROR registry_init_smbconf ( const char * keyname )
2007-06-14 11:29:35 +00:00
{
2008-04-13 12:41:34 +02:00
WERROR werr ;
2007-06-14 11:29:35 +00:00
2008-02-15 13:57:31 +01:00
DEBUG ( 10 , ( " registry_init_smbconf called \n " ) ) ;
2007-06-14 11:29:35 +00:00
2008-04-13 12:10:07 +02:00
if ( keyname = = NULL ) {
DEBUG ( 10 , ( " registry_init_smbconf: defaulting to key '%s' \n " ,
KEY_SMBCONF ) ) ;
keyname = KEY_SMBCONF ;
}
2008-04-13 15:21:31 +02:00
werr = registry_init_common ( ) ;
2008-04-13 12:41:34 +02:00
if ( ! W_ERROR_IS_OK ( werr ) ) {
2007-06-14 11:29:35 +00:00
goto done ;
}
2008-04-13 13:38:44 +02:00
werr = init_registry_key ( keyname ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
DEBUG ( 1 , ( " Failed to initialize registry key '%s': %s \n " ,
2008-11-01 17:19:26 +01:00
keyname , win_errstr ( werr ) ) ) ;
2008-03-20 14:08:29 +01:00
goto done ;
}
2008-04-13 13:38:44 +02:00
2008-04-13 14:55:49 +02:00
werr = reghook_cache_add ( keyname , & smbconf_reg_ops ) ;
if ( ! W_ERROR_IS_OK ( werr ) ) {
DEBUG ( 1 , ( " Failed to add smbconf reghooks to reghook cache: "
2008-11-01 17:19:26 +01:00
" %s \n " , win_errstr ( werr ) ) ) ;
2007-06-14 11:29:35 +00:00
goto done ;
}
done :
2008-03-22 01:54:18 +01:00
regdb_close ( ) ;
2008-04-13 15:25:47 +02:00
return werr ;
2007-06-14 11:29:35 +00:00
}