4531327d948a0e4f827fbc323e64b81df5c84e8a
[tprouty/samba.git] / source / registry / reg_shares.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  Virtual Windows Registry Layer
4  *  Copyright (C) Gerald Carter                     2005
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 /* Implementation of registry virtual views for printing information */
22
23 #include "includes.h"
24
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_SRV
27
28 /**********************************************************************
29  It is safe to assume that every registry path passed into on of 
30  the exported functions here begins with KEY_PRINTING else
31  these functions would have never been called.  This is a small utility
32  function to strip the beginning of the path and make a copy that the 
33  caller can modify.  Note that the caller is responsible for releasing
34  the memory allocated here.
35  **********************************************************************/
36
37 static char* trim_reg_path( char *path )
38 {
39         char *p;
40         uint16 key_len = strlen(KEY_SHARES);
41         
42         /* 
43          * sanity check...this really should never be True.
44          * It is only here to prevent us from accessing outside
45          * the path buffer in the extreme case.
46          */
47         
48         if ( strlen(path) < key_len ) {
49                 DEBUG(0,("trim_reg_path: Registry path too short! [%s]\n", path));
50                 return NULL;
51         }
52         
53         
54         p = path + strlen( KEY_SHARES );
55         
56         if ( *p == '\\' )
57                 p++;
58         
59         if ( *p )
60                 return SMB_STRDUP(p);
61         else
62                 return NULL;
63 }
64
65 /**********************************************************************
66  Enumerate registry subkey names given a registry path.  
67  Caller is responsible for freeing memory to **subkeys
68  *********************************************************************/
69  
70 static int shares_subkey_info( char *key, REGSUBKEY_CTR *subkey_ctr )
71 {
72         char            *path;
73         BOOL            top_level = False;
74         int             num_subkeys = 0;
75         
76         DEBUG(10,("printing_subkey_info: key=>[%s]\n", key));
77         
78         path = trim_reg_path( key );
79         
80         /* check to see if we are dealing with the top level key */
81         
82         if ( !path )
83                 top_level = True;
84                 
85         if ( top_level ) {
86                 num_subkeys = 1;
87                 regsubkey_ctr_addkey( subkey_ctr, "Security" );
88         }
89 #if 0
90         else
91                 num_subkeys = handle_share_subpath( path, subkey_ctr, NULL );
92 #endif
93         
94         SAFE_FREE( path );
95         
96         return num_subkeys;
97 }
98
99 /**********************************************************************
100  Enumerate registry values given a registry path.  
101  Caller is responsible for freeing memory 
102  *********************************************************************/
103
104 static int shares_value_info( char *key, REGVAL_CTR *val )
105 {
106         char            *path;
107         BOOL            top_level = False;
108         int             num_values = 0;
109         
110         DEBUG(10,("printing_value_info: key=>[%s]\n", key));
111         
112         path = trim_reg_path( key );
113         
114         /* check to see if we are dealing with the top level key */
115         
116         if ( !path )
117                 top_level = True;
118         
119         /* fill in values from the getprinterdata_printer_server() */
120         if ( top_level )
121                 num_values = 0;
122 #if 0
123         else
124                 num_values = handle_printing_subpath( path, NULL, val );
125 #endif
126                 
127         
128         return num_values;
129 }
130
131 /**********************************************************************
132  Stub function which always returns failure since we don't want
133  people storing printing information directly via regostry calls
134  (for now at least)
135  *********************************************************************/
136
137 static BOOL shares_store_subkey( char *key, REGSUBKEY_CTR *subkeys )
138 {
139         return False;
140 }
141
142 /**********************************************************************
143  Stub function which always returns failure since we don't want
144  people storing printing information directly via regostry calls
145  (for now at least)
146  *********************************************************************/
147
148 static BOOL shares_store_value( char *key, REGVAL_CTR *val )
149 {
150         return False;
151 }
152
153 /* 
154  * Table of function pointers for accessing printing data
155  */
156  
157 REGISTRY_OPS shares_reg_ops = {
158         shares_subkey_info,
159         shares_value_info,
160         shares_store_subkey,
161         shares_store_value,
162         NULL
163 };
164
165