2007-11-27 04:24:56 +03:00
/*
2002-07-19 03:00:24 +04:00
* Unix SMB / CIFS implementation .
2005-05-23 20:25:31 +04:00
* Virtual Windows Registry Layer
* Copyright ( C ) Gerald Carter 2002 - 2005
2010-05-26 13:27:28 +04:00
* Copyright ( c ) Andreas Schneider < asn @ samba . org > 2010
2002-07-19 03:00:24 +04:00
*
* 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
2007-07-09 23:25:36 +04:00
* the Free Software Foundation ; either version 3 of the License , or
2002-07-19 03:00:24 +04:00
* ( at your option ) any later version .
2007-11-27 04:24:56 +03:00
*
2002-07-19 03:00:24 +04:00
* 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 .
2007-11-27 04:24:56 +03:00
*
2002-07-19 03:00:24 +04:00
* You should have received a copy of the GNU General Public License
2007-07-10 09:23:25 +04:00
* along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2002-07-19 03:00:24 +04:00
*/
/* Implementation of registry virtual views for printing information */
# include "includes.h"
2009-10-02 02:17:06 +04:00
# include "registry.h"
2010-05-25 02:04:13 +04:00
# include "reg_util_internal.h"
2002-07-19 03:00:24 +04:00
# undef DBGC_CLASS
2007-09-29 03:05:52 +04:00
# define DBGC_CLASS DBGC_REGISTRY
2002-07-19 03:00:24 +04:00
2012-04-20 16:07:30 +04:00
extern struct registry_ops regdb_ops ;
2010-05-26 13:27:28 +04:00
/* registry paths used in the print_registry[] */
2010-06-28 15:15:06 +04:00
# define KEY_CONTROL_PRINTERS "HKLM\\SYSTEM\\CURRENTCONTROLSET\\CONTROL\\PRINT\\PRINTERS"
# define KEY_WINNT_PRINTERS "HKLM\\SOFTWARE\\MICROSOFT\\WINDOWS NT\\CURRENTVERSION\\PRINT\\PRINTERS"
2005-06-30 07:29:48 +04:00
/* callback table for various registry paths below the ones we service in this module */
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
struct reg_dyn_tree {
/* full key path in normalized form */
const char * path ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
/* callbscks for fetch/store operations */
2009-02-24 17:19:18 +03:00
int ( * fetch_subkeys ) ( const char * path , struct regsubkey_ctr * subkeys ) ;
bool ( * store_subkeys ) ( const char * path , struct regsubkey_ctr * subkeys ) ;
2009-03-23 20:14:17 +03:00
int ( * fetch_values ) ( const char * path , struct regval_ctr * values ) ;
bool ( * store_values ) ( const char * path , struct regval_ctr * values ) ;
2005-06-30 06:59:29 +04:00
} ;
2005-07-01 23:15:07 +04:00
/*********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * " HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRINT/PRINTERS "
* * " HKLM/SOFTWARE/MICROSOFT/WINDOWS NT/CURRENTVERSION/PRINT/PRINTERS "
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2005-06-30 23:43:53 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-05-26 13:27:28 +04:00
static char * create_printer_registry_path ( TALLOC_CTX * mem_ctx , const char * key ) {
char * path ;
char * subkey = NULL ;
2007-11-27 04:24:56 +03:00
2010-05-26 13:27:28 +04:00
path = talloc_strdup ( mem_ctx , key ) ;
if ( path = = NULL ) {
2007-11-27 04:24:56 +03:00
return NULL ;
}
2010-05-26 13:27:28 +04:00
path = normalize_reg_path ( mem_ctx , path ) ;
if ( path = = NULL ) {
2007-11-27 04:24:56 +03:00
return NULL ;
}
2005-07-02 02:24:00 +04:00
2010-05-26 13:27:28 +04:00
if ( strncmp ( path , KEY_CONTROL_PRINTERS , strlen ( KEY_CONTROL_PRINTERS ) ) = = 0 ) {
subkey = reg_remaining_path ( mem_ctx , key + strlen ( KEY_CONTROL_PRINTERS ) ) ;
if ( subkey = = NULL ) {
return NULL ;
}
return talloc_asprintf ( mem_ctx , " %s \\ %s " , KEY_WINNT_PRINTERS , subkey ) ;
2007-11-27 04:24:56 +03:00
}
2010-05-26 13:27:28 +04:00
return NULL ;
2005-07-02 02:24:00 +04:00
}
/*********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-27 04:24:56 +03:00
2009-02-24 17:19:18 +03:00
static int key_printers_fetch_keys ( const char * key , struct regsubkey_ctr * subkeys )
2002-07-19 22:49:44 +04:00
{
2010-05-26 13:27:28 +04:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
2005-07-02 02:24:00 +04:00
char * printers_key ;
2005-07-01 23:15:07 +04:00
2010-05-26 13:27:28 +04:00
printers_key = create_printer_registry_path ( ctx , key ) ;
if ( printers_key = = NULL ) {
/* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
2012-04-20 16:07:30 +04:00
return regdb_ops . fetch_subkeys ( KEY_WINNT_PRINTERS , subkeys ) ;
2005-07-11 22:27:22 +04:00
}
2012-04-20 16:07:30 +04:00
return regdb_ops . fetch_subkeys ( printers_key , subkeys ) ;
2005-07-02 05:23:21 +04:00
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 17:19:18 +03:00
static bool key_printers_store_keys ( const char * key , struct regsubkey_ctr * subkeys )
2005-06-30 23:43:53 +04:00
{
2010-05-26 13:27:28 +04:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
2005-07-02 02:24:00 +04:00
char * printers_key ;
2009-03-17 17:22:22 +03:00
2010-05-26 13:27:28 +04:00
printers_key = create_printer_registry_path ( ctx , key ) ;
if ( printers_key = = NULL ) {
/* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
2012-04-20 16:07:30 +04:00
return regdb_ops . store_subkeys ( KEY_WINNT_PRINTERS , subkeys ) ;
2005-07-01 23:15:07 +04:00
}
2002-07-24 12:58:03 +04:00
2012-04-20 16:07:30 +04:00
return regdb_ops . store_subkeys ( printers_key , subkeys ) ;
2005-07-01 23:15:07 +04:00
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 20:14:17 +03:00
static int key_printers_fetch_values ( const char * key , struct regval_ctr * values )
2005-07-01 23:15:07 +04:00
{
2010-05-26 13:27:28 +04:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
2005-07-02 02:24:00 +04:00
char * printers_key ;
2010-02-07 13:05:07 +03:00
2010-05-26 13:27:28 +04:00
printers_key = create_printer_registry_path ( ctx , key ) ;
if ( printers_key = = NULL ) {
2005-07-11 20:55:10 +04:00
/* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
2012-04-20 16:07:30 +04:00
return regdb_ops . fetch_values ( KEY_WINNT_PRINTERS , values ) ;
2005-06-30 21:46:06 +04:00
}
2007-11-27 04:24:56 +03:00
2012-04-20 16:07:30 +04:00
return regdb_ops . fetch_values ( printers_key , values ) ;
2005-06-30 21:46:06 +04:00
}
2005-07-01 23:15:07 +04:00
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-06-30 06:59:29 +04:00
2010-05-26 13:27:28 +04:00
static bool key_printers_store_values ( const char * key , struct regval_ctr * values )
2005-06-30 06:59:29 +04:00
{
2007-11-27 04:24:56 +03:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
2010-05-26 13:27:28 +04:00
char * printers_key ;
2007-11-27 04:24:56 +03:00
2010-05-26 13:27:28 +04:00
printers_key = create_printer_registry_path ( ctx , key ) ;
if ( printers_key = = NULL ) {
/* normalize on the 'HKLM\SOFTWARE\....\Print\Printers' key */
2012-04-20 16:07:30 +04:00
return regdb_ops . store_values ( KEY_WINNT_PRINTERS , values ) ;
2007-11-27 04:24:56 +03:00
}
2012-04-20 16:07:30 +04:00
return regdb_ops . store_values ( printers_key , values ) ;
2005-06-30 06:59:29 +04:00
}
/**********************************************************************
2005-07-01 23:15:07 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * Structure to hold dispatch table of ops for various printer keys .
2007-11-27 04:24:56 +03:00
* * Make sure to always store deeper keys along the same path first so
2005-07-01 23:15:07 +04:00
* * we ge a more specific match .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2005-06-30 06:59:29 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct reg_dyn_tree print_registry [ ] = {
2007-11-27 04:24:56 +03:00
{ KEY_CONTROL_PRINTERS ,
2005-07-02 05:23:21 +04:00
& key_printers_fetch_keys ,
& key_printers_store_keys ,
& key_printers_fetch_values ,
& key_printers_store_values } ,
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
{ NULL , NULL , NULL , NULL , NULL }
} ;
/**********************************************************************
2005-07-01 23:15:07 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * Main reg_printing interface functions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2005-06-30 06:59:29 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-07-01 23:15:07 +04:00
/***********************************************************************
Lookup a key in the print_registry table , returning its index .
- 1 on failure
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-27 04:24:56 +03:00
static int match_registry_path ( const char * key )
2005-06-30 06:59:29 +04:00
{
int i ;
2007-11-27 04:24:56 +03:00
char * path = NULL ;
TALLOC_CTX * ctx = talloc_tos ( ) ;
2005-06-30 06:59:29 +04:00
if ( ! key )
return - 1 ;
2007-11-27 04:24:56 +03:00
path = talloc_strdup ( ctx , key ) ;
if ( ! path ) {
return - 1 ;
}
path = normalize_reg_path ( ctx , path ) ;
if ( ! path ) {
return - 1 ;
}
2005-06-30 06:59:29 +04:00
for ( i = 0 ; print_registry [ i ] . path ; i + + ) {
2007-11-27 04:24:56 +03:00
if ( strncmp ( path , print_registry [ i ] . path , strlen ( print_registry [ i ] . path ) ) = = 0 )
2005-06-30 06:59:29 +04:00
return i ;
}
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
return - 1 ;
}
2005-07-01 23:15:07 +04:00
/***********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 17:19:18 +03:00
static int regprint_fetch_reg_keys ( const char * key , struct regsubkey_ctr * subkeys )
2005-06-30 06:59:29 +04:00
{
int i = match_registry_path ( key ) ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
if ( i = = - 1 )
return - 1 ;
2007-11-27 04:24:56 +03:00
2005-06-30 21:46:06 +04:00
if ( ! print_registry [ i ] . fetch_subkeys )
return - 1 ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
return print_registry [ i ] . fetch_subkeys ( key , subkeys ) ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-24 17:19:18 +03:00
static bool regprint_store_reg_keys ( const char * key , struct regsubkey_ctr * subkeys )
2005-06-30 06:59:29 +04:00
{
int i = match_registry_path ( key ) ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
if ( i = = - 1 )
return False ;
2007-11-27 04:24:56 +03:00
2005-06-30 21:46:06 +04:00
if ( ! print_registry [ i ] . store_subkeys )
return False ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
return print_registry [ i ] . store_subkeys ( key , subkeys ) ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 20:14:17 +03:00
static int regprint_fetch_reg_values ( const char * key , struct regval_ctr * values )
2005-06-30 06:59:29 +04:00
{
int i = match_registry_path ( key ) ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
if ( i = = - 1 )
return - 1 ;
2007-11-27 04:24:56 +03:00
/* return 0 values by default since we know the key had
2005-06-30 21:46:06 +04:00
to exist because the client opened a handle */
2007-11-27 04:24:56 +03:00
2005-06-30 21:46:06 +04:00
if ( ! print_registry [ i ] . fetch_values )
return 0 ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
return print_registry [ i ] . fetch_values ( key , values ) ;
}
/**********************************************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-03-23 20:14:17 +03:00
static bool regprint_store_reg_values ( const char * key , struct regval_ctr * values )
2005-06-30 06:59:29 +04:00
{
int i = match_registry_path ( key ) ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
if ( i = = - 1 )
return False ;
2007-11-27 04:24:56 +03:00
2005-06-30 21:46:06 +04:00
if ( ! print_registry [ i ] . store_values )
return False ;
2007-11-27 04:24:56 +03:00
2005-06-30 06:59:29 +04:00
return print_registry [ i ] . store_values ( key , values ) ;
}
2007-11-27 04:24:56 +03:00
/*
2002-07-19 03:00:24 +04:00
* Table of function pointers for accessing printing data
*/
2007-11-27 04:24:56 +03:00
2009-03-24 01:14:45 +03:00
struct registry_ops printing_ops = {
2008-01-20 01:06:12 +03:00
. fetch_subkeys = regprint_fetch_reg_keys ,
. fetch_values = regprint_fetch_reg_values ,
. store_subkeys = regprint_store_reg_keys ,
. store_values = regprint_store_reg_values ,
2002-07-19 03:00:24 +04:00
} ;