r5499: Commit forgotten change what tridge immediately pointed out
[samba.git] / source4 / include / registry.h
1 /* 
2    Unix SMB/CIFS implementation.
3    Registry interface
4    Copyright (C) Gerald Carter                        2002.
5    Copyright (C) Jelmer Vernooij                                          2003-2004.
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef _REGISTRY_H /* _REGISTRY_H */
23 #define _REGISTRY_H 
24
25 /* Handles for the predefined keys */
26 enum reg_predefined_key {
27         HKEY_CLASSES_ROOT               = 0x80000000,
28         HKEY_CURRENT_USER               = 0x80000001,
29         HKEY_LOCAL_MACHINE              = 0x80000002,
30         HKEY_USERS                              = 0x80000003,
31         HKEY_PERFORMANCE_DATA   = 0x80000004,
32         HKEY_CURRENT_CONFIG             = 0x80000005,
33         HKEY_DYN_DATA                   = 0x80000006,
34         HKEY_PERFORMANCE_TEXT   = 0x80000050,
35         HKEY_PERFORMANCE_NLSTEXT= 0x80000060
36 };
37
38 /* Registry data types */
39
40 #define REG_DELETE                                                                 -1
41 #define REG_NONE                                                                        0
42 #define REG_SZ                                                                          1
43 #define REG_EXPAND_SZ                                                           2
44 #define REG_BINARY                                                                      3
45 #define REG_DWORD_LE                                                            4 
46 #define REG_DWORD                                                REG_DWORD_LE
47 #define REG_DWORD_BE                                                            5 
48 #define REG_LINK                                                                        6
49 #define REG_MULTI_SZ                                                            7
50 #define REG_RESOURCE_LIST                                                       8
51 #define REG_FULL_RESOURCE_DESCRIPTOR                            9
52 #define REG_RESOURCE_REQUIREMENTS_LIST                          10
53 #define REG_QWORD_LE                                                            11
54 #define REG_QWORD                                                REQ_QWORD_LE
55
56 #if 0
57 /* FIXME */
58 typedef struct ace_struct_s {
59   uint8_t type, flags;
60   uint_t perms;   /* Perhaps a better def is in order */
61   DOM_SID *trustee;
62 } ACE;
63 #endif
64
65 /*
66  * The general idea here is that every backend provides a 'hive'. Combining
67  * various hives gives you a complete registry like windows has
68  */
69
70 #define REGISTRY_INTERFACE_VERSION 1
71
72 /* structure to store the registry handles */
73 struct registry_key {
74   char *name;         /* Name of the key                    */
75   const char *path;               /* Full path to the key */
76   char *class_name; /* Name of key class */
77   NTTIME last_mod; /* Time last modified                 */
78   struct registry_hive *hive;
79   void *backend_data;
80 };
81
82 struct registry_value {
83   char *name;
84   unsigned int data_type;
85   int data_len;
86   void *data_blk;    /* Might want a separate block */
87 };
88
89 /* FIXME */
90 typedef void (*key_notification_function) (void);
91 typedef void (*value_notification_function) (void);
92
93 /* 
94  * Container for function pointers to enumeration routines
95  * for virtual registry view 
96  *
97  * Backends can provide :
98  *  - just one hive (example: nt4, w95)
99  *  - several hives (example: rpc).
100  * 
101  * Backends should always do case-insensitive compares 
102  * (everything is case-insensitive but case-preserving, 
103  * just like the FS)
104  */ 
105
106 struct hive_operations {
107         const char *name;
108
109         /* Implement this one */
110         WERROR (*open_hive) (struct registry_hive *, struct registry_key **);
111
112         /* Or this one */
113         WERROR (*open_key) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_key **);
114
115         /* Either implement these */
116         WERROR (*num_subkeys) (struct registry_key *, int *count);
117         WERROR (*num_values) (struct registry_key *, int *count);
118         WERROR (*get_subkey_by_index) (TALLOC_CTX *, struct registry_key *, int idx, struct registry_key **);
119
120         /* Can not contain more then one level */
121         WERROR (*get_subkey_by_name) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_key **);
122         WERROR (*get_value_by_index) (TALLOC_CTX *, struct registry_key *, int idx, struct registry_value **);
123
124         /* Can not contain more then one level */
125         WERROR (*get_value_by_name) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_value **);
126
127         /* Security control */
128         WERROR (*key_get_sec_desc) (TALLOC_CTX *, struct registry_key *, struct security_descriptor **);
129         WERROR (*key_set_sec_desc) (struct registry_key *, struct security_descriptor *);
130
131         /* Notification */
132         WERROR (*request_key_change_notify) (struct registry_key *, key_notification_function);
133         WERROR (*request_value_change_notify) (struct registry_value *, value_notification_function);
134
135         /* Key management */
136         WERROR (*add_key)(TALLOC_CTX *, struct registry_key *, const char *name, uint32_t access_mask, struct security_descriptor *, struct registry_key **);
137         WERROR (*del_key)(struct registry_key *, const char *name);
138         WERROR (*flush_key) (struct registry_key *);
139
140         /* Value management */
141         WERROR (*set_value)(struct registry_key *, const char *name, uint32_t type, void *data, int len); 
142         WERROR (*del_value)(struct registry_key *, const char *valname);
143 };
144
145 struct registry_hive {
146         const struct hive_operations *functions;
147         struct registry_key *root;
148         void *backend_data;
149         const char *location;
150 };
151
152 /* Handle to a full registry
153  * contains zero or more hives */
154 struct registry_context {
155     void *backend_data;
156         WERROR (*get_predefined_key) (struct registry_context *, uint32_t hkey, struct registry_key **);
157 };
158
159 struct reg_init_function_entry {
160         /* Function to create a member of the pdb_methods list */
161         const struct hive_operations *hive_functions;
162         struct reg_init_function_entry *prev, *next;
163 };
164
165 /* Used internally */
166 #define SMB_REG_ASSERT(a) { if(!(a)) { DEBUG(0,("%s failed! (%s:%d)", #a, __FILE__, __LINE__)); }}
167
168 #endif /* _REGISTRY_H */