2004-04-04 16:24:08 +00:00
/*
Unix SMB / CIFS implementation .
simple registry frontend
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-03 00:17:12 +00:00
# include "dynconfig.h"
2005-09-04 14:47:19 +00:00
# include "lib/registry/registry.h"
2004-11-02 02:57:18 +00:00
# include "lib/cmdline/popt_common.h"
2004-04-04 16:24:08 +00:00
2004-09-22 12:32:31 +00:00
static void print_tree ( int l , struct registry_key * p , int fullpath , int novals )
2004-04-04 16:24:08 +00:00
{
2004-09-22 12:32:31 +00:00
struct registry_key * subkey ;
struct registry_value * value ;
2005-09-03 23:23:14 +00:00
struct security_descriptor * sec_desc ;
2004-04-09 00:02:20 +00:00
WERROR error ;
int i ;
2004-09-22 12:32:31 +00:00
TALLOC_CTX * mem_ctx ;
2004-04-04 16:24:08 +00:00
for ( i = 0 ; i < l ; i + + ) putchar ( ' ' ) ;
2004-09-22 12:32:31 +00:00
/* Hive name */
2004-10-11 13:57:30 +00:00
if ( p - > hive - > root = = p ) {
2004-12-10 20:07:04 +00:00
if ( p - > hive - > root - > name ) printf ( " %s \n " , p - > hive - > root - > name ) ; else printf ( " <No Name> \n " ) ;
2004-10-11 13:57:30 +00:00
} else {
if ( ! p - > name ) printf ( " <No Name> \n " ) ;
if ( fullpath ) printf ( " %s \n " , p - > path ) ;
else printf ( " %s \n " , p - > name ) ;
}
2004-04-04 16:24:08 +00:00
2004-09-22 12:32:31 +00:00
mem_ctx = talloc_init ( " print_tree " ) ;
for ( i = 0 ; W_ERROR_IS_OK ( error = reg_key_get_subkey_by_index ( mem_ctx , p , i , & subkey ) ) ; i + + ) {
2004-04-04 16:24:08 +00:00
print_tree ( l + 1 , subkey , fullpath , novals ) ;
}
2005-01-27 07:08:20 +00:00
talloc_free ( mem_ctx ) ;
2004-04-04 16:24:08 +00:00
2004-04-09 00:02:20 +00:00
if ( ! W_ERROR_EQUAL ( error , WERR_NO_MORE_ITEMS ) ) {
2004-09-22 12:32:31 +00:00
DEBUG ( 0 , ( " Error occured while fetching subkeys for '%s': %s \n " , p - > path , win_errstr ( error ) ) ) ;
2004-04-09 00:02:20 +00:00
}
2004-04-04 16:24:08 +00:00
if ( ! novals ) {
2004-09-22 12:32:31 +00:00
mem_ctx = talloc_init ( " print_tree " ) ;
for ( i = 0 ; W_ERROR_IS_OK ( error = reg_key_get_value_by_index ( mem_ctx , p , i , & value ) ) ; i + + ) {
2004-04-04 16:24:08 +00:00
int j ;
char * desc ;
for ( j = 0 ; j < l + 1 ; j + + ) putchar ( ' ' ) ;
2004-09-22 12:32:31 +00:00
desc = reg_val_description ( mem_ctx , value ) ;
2004-04-04 16:24:08 +00:00
printf ( " %s \n " , desc ) ;
}
2005-01-27 07:08:20 +00:00
talloc_free ( mem_ctx ) ;
2004-04-09 00:02:20 +00:00
if ( ! W_ERROR_EQUAL ( error , WERR_NO_MORE_ITEMS ) ) {
2004-09-22 12:32:31 +00:00
DEBUG ( 0 , ( " Error occured while fetching values for '%s': %s \n " , p - > path , win_errstr ( error ) ) ) ;
2004-04-09 00:02:20 +00:00
}
2004-04-04 16:24:08 +00:00
}
2005-09-03 23:23:14 +00:00
mem_ctx = talloc_init ( " sec_desc " ) ;
if ( NT_STATUS_IS_ERR ( reg_get_sec_desc ( mem_ctx , p , & sec_desc ) ) ) {
DEBUG ( 0 , ( " Error getting security descriptor \n " ) ) ;
}
talloc_free ( mem_ctx ) ;
2004-04-04 16:24:08 +00:00
}
2005-09-03 23:23:14 +00:00
int main ( int argc , char * * argv )
2004-04-04 16:24:08 +00:00
{
2004-05-22 18:49:25 +00:00
int opt , i ;
2004-12-10 20:07:04 +00:00
const char * backend = NULL ;
const char * remote = NULL ;
2004-04-04 16:24:08 +00:00
poptContext pc ;
2004-12-10 20:07:04 +00:00
struct registry_context * h = NULL ;
struct registry_key * root = NULL ;
2004-04-09 00:02:20 +00:00
WERROR error ;
2004-04-04 16:24:08 +00:00
int fullpath = 0 , no_values = 0 ;
struct poptOption long_options [ ] = {
POPT_AUTOHELP
{ " backend " , ' b ' , POPT_ARG_STRING , & backend , 0 , " backend to use " , NULL } ,
{ " fullpath " , ' f ' , POPT_ARG_NONE , & fullpath , 0 , " show full paths " , NULL } ,
2004-12-10 20:07:04 +00:00
{ " remote " , ' R ' , POPT_ARG_STRING , & remote , 0 , " connect to specified remote server " , NULL } ,
2004-04-04 16:24:08 +00:00
{ " no-values " , ' V ' , POPT_ARG_NONE , & no_values , 0 , " don't show values " , NULL } ,
2005-06-13 08:12:39 +00:00
POPT_COMMON_SAMBA
POPT_COMMON_CREDENTIALS
2004-04-04 16:24:08 +00:00
POPT_TABLEEND
} ;
2004-11-06 23:23:15 +00:00
regtree_init_subsystems ;
2004-09-22 12:32:31 +00:00
2004-04-04 16:24:08 +00:00
pc = poptGetContext ( argv [ 0 ] , argc , ( const char * * ) argv , long_options , 0 ) ;
while ( ( opt = poptGetNextOpt ( pc ) ) ! = - 1 ) {
}
2004-12-10 20:07:04 +00:00
if ( remote ) {
2005-06-16 11:36:09 +00:00
error = reg_open_remote ( & h , cmdline_credentials , remote , NULL ) ;
2004-12-10 20:07:04 +00:00
} else if ( backend ) {
error = reg_open_hive ( NULL , backend , poptGetArg ( pc ) , NULL , & root ) ;
} else {
error = reg_open_local ( & h ) ;
}
2004-04-09 00:02:20 +00:00
if ( ! W_ERROR_IS_OK ( error ) ) {
2004-04-11 15:34:18 +00:00
fprintf ( stderr , " Unable to open '%s' with backend '%s':%s \n " , poptGetArg ( pc ) , backend , win_errstr ( error ) ) ;
2004-04-04 16:24:08 +00:00
return 1 ;
}
poptFreeContext ( pc ) ;
2004-05-22 18:49:25 +00:00
error = WERR_OK ;
2004-04-04 16:24:08 +00:00
2004-12-10 20:07:04 +00:00
if ( ! h ) {
print_tree ( 0 , root , fullpath , no_values ) ;
} else {
2004-12-11 17:12:16 +00:00
for ( i = HKEY_CLASSES_ROOT ; i < HKEY_PERFORMANCE_NLSTEXT ; i + + ) {
2004-12-11 20:06:40 +00:00
error = reg_get_predefined_key ( h , i , & root ) ;
2004-12-10 20:07:04 +00:00
if ( ! W_ERROR_IS_OK ( error ) ) {
2004-12-11 20:06:40 +00:00
fprintf ( stderr , " Skipping %s \n " , reg_get_predef_name ( i ) ) ;
2004-12-10 20:07:04 +00:00
continue ;
}
print_tree ( 0 , root , fullpath , no_values ) ;
}
}
2004-04-04 16:24:08 +00:00
return 0 ;
}