r166: Fix enumerating values in nt4 backend
[kai/samba.git] / source4 / lib / registry / common / registry.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Registry interface
4    This file contains the _internal_ structs for the registry 
5    subsystem. Backends and the subsystem itself are the only
6    files that need to include this file.
7    Copyright (C) Gerald Carter                        2002.
8    Copyright (C) Jelmer Vernooij                                          2003-2004.
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #ifndef _REGISTRY_REGISTRY_H /* _REGISTRY_REGISTRY_H */
26 #define _REGISTRY_REGISTRY_H 
27
28 #define REGISTRY_INTERFACE_VERSION 1
29
30 /* structure to store the registry handles */
31 struct reg_key_s {
32   char *name;         /* Name of the key                    */
33   char *path;             /* Full path to the key */
34   smb_ucs2_t *class_name; /* Name of key class */
35   NTTIME last_mod; /* Time last modified                 */
36   SEC_DESC *security;
37   REG_HANDLE *handle;
38   void *backend_data;
39   REG_VAL **cache_values; 
40   int cache_values_count;
41   REG_KEY **cache_subkeys; 
42   int cache_subkeys_count;
43   TALLOC_CTX *mem_ctx;
44   int ref;
45 };
46
47 struct reg_val_s {
48   char *name;
49   int has_name;
50   int data_type;
51   int data_len;
52   void *data_blk;    /* Might want a separate block */
53   REG_HANDLE *handle;
54   REG_KEY *parent;
55   void *backend_data;
56   TALLOC_CTX *mem_ctx;
57   int ref;
58 };
59
60 /* FIXME */
61 typedef void (*key_notification_function) ();
62 typedef void (*value_notification_function) ();
63
64
65 /* 
66  * Container for function pointers to enumeration routines
67  * for virtual registry view 
68  */ 
69  
70 struct registry_ops {
71         const char *name;
72         WERROR (*open_registry) (REG_HANDLE *, const char *location, const char *credentials);
73         WERROR (*sync_key)(REG_KEY *, const char *location);
74         WERROR (*close_registry) (REG_HANDLE *);
75
76         /* Either implement these */
77         WERROR (*open_root_key) (REG_HANDLE *, REG_KEY **);
78         WERROR (*num_subkeys) (REG_KEY *, int *count);
79         WERROR (*num_values) (REG_KEY *, int *count);
80         WERROR (*get_subkey_by_index) (REG_KEY *, int idx, REG_KEY **);
81         WERROR (*get_subkey_by_name) (REG_KEY *, const char *name, REG_KEY **);
82         WERROR (*get_value_by_index) (REG_KEY *, int idx, REG_VAL **);
83         WERROR (*get_value_by_name) (REG_KEY *, const char *name, REG_VAL **);
84
85         /* Or these */
86         WERROR (*open_key) (REG_HANDLE *, const char *name, REG_KEY **);
87         WERROR (*fetch_subkeys) (REG_KEY *, int *count, REG_KEY ***);
88         WERROR (*fetch_values) (REG_KEY *, int *count, REG_VAL ***);
89
90         /* Security control */
91         WERROR (*key_get_sec_desc) (REG_KEY *, SEC_DESC **);
92         WERROR (*key_set_sec_desc) (REG_KEY *, SEC_DESC *);
93
94         /* Notification */
95         WERROR (*request_key_change_notify) (REG_KEY *, key_notification_function);
96         WERROR (*request_value_change_notify) (REG_VAL *, value_notification_function);
97
98         /* Key management */
99         WERROR (*add_key)(REG_KEY *, const char *name, uint32 access_mask, SEC_DESC *, REG_KEY **);
100         WERROR (*del_key)(REG_KEY *);
101
102         /* Value management */
103         WERROR (*add_value)(REG_KEY *, const char *name, int type, void *data, int len);
104         WERROR (*del_value)(REG_VAL *);
105         
106         /* If update is not available, value will first be deleted and then added 
107          * again */
108         WERROR (*update_value)(REG_VAL *, int type, void *data, int len); 
109
110         void (*free_key_backend_data) (REG_KEY *);
111         void (*free_val_backend_data) (REG_VAL *);
112 };
113
114 typedef struct reg_sub_tree_s {
115         char *path;
116         REG_HANDLE *handle;
117         struct reg_sub_tree_s *prev, *next;
118 } REG_SUBTREE;
119
120 struct reg_handle_s {
121         struct registry_ops *functions;
122         REG_SUBTREE *subtrees;
123         char *location;
124         char *credentials;
125         void *backend_data;
126         TALLOC_CTX *mem_ctx;
127 };
128
129 struct reg_init_function_entry {
130         /* Function to create a member of the pdb_methods list */
131         struct registry_ops *functions;
132         struct reg_init_function_entry *prev, *next;
133 };
134
135 /* Used internally */
136 #define SMB_REG_ASSERT(a) { if(!(a)) { DEBUG(0,("%s failed! (%s:%d)", #a, __FILE__, __LINE__)); }}
137
138 #endif /* _REGISTRY_H */