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