dc17eb06b1345ad6515134ce4de03b2c5fcbda45
[jelmer/samba4-debian.git] / source / 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 #define HKEY_CLASSES_ROOT                0x80000000
27 #define HKEY_CURRENT_USER                0x80000001
28 #define HKEY_LOCAL_MACHINE               0x80000002
29 #define HKEY_USERS                               0x80000003
30 #define HKEY_PERFORMANCE_DATA    0x80000004
31 #define HKEY_CURRENT_CONFIG              0x80000005
32 #define HKEY_DYN_DATA                    0x80000006
33 #define HKEY_PERFORMANCE_TEXT    0x80000050
34 #define HKEY_PERFORMANCE_NLSTEXT 0x80000060
35
36 #define REG_DELETE                                                                 -1
37
38 #if 0
39 /* FIXME */
40 typedef struct ace_struct_s {
41   uint8_t type, flags;
42   uint_t perms;   /* Perhaps a better def is in order */
43   DOM_SID *trustee;
44 } ACE;
45 #endif
46
47 /*
48  * The general idea here is that every backend provides a 'hive'. Combining
49  * various hives gives you a complete registry like windows has
50  */
51
52 #define REGISTRY_INTERFACE_VERSION 1
53
54 /* structure to store the registry handles */
55 struct registry_key {
56   char *name;         /* Name of the key                    */
57   const char *path;               /* Full path to the key */
58   char *class_name; /* Name of key class */
59   NTTIME last_mod; /* Time last modified                 */
60   struct registry_hive *hive;
61   void *backend_data;
62 };
63
64 struct registry_value {
65   char *name;
66   unsigned int data_type;
67   DATA_BLOB data;
68 };
69
70 /* FIXME */
71 typedef void (*key_notification_function) (void);
72 typedef void (*value_notification_function) (void);
73
74 /* 
75  * Container for function pointers to enumeration routines
76  * for virtual registry view 
77  *
78  * Backends can provide :
79  *  - just one hive (example: nt4, w95)
80  *  - several hives (example: rpc).
81  * 
82  * Backends should always do case-insensitive compares 
83  * (everything is case-insensitive but case-preserving, 
84  * just like the FS)
85  */ 
86
87 struct hive_operations {
88         const char *name;
89
90         /* Implement this one */
91         WERROR (*open_hive) (struct registry_hive *, struct registry_key **);
92
93         /* Or this one */
94         WERROR (*open_key) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_key **);
95
96         WERROR (*num_subkeys) (struct registry_key *, uint32_t *count);
97         WERROR (*num_values) (struct registry_key *, uint32_t *count);
98         WERROR (*get_subkey_by_index) (TALLOC_CTX *, struct registry_key *, int idx, struct registry_key **);
99
100         /* Can not contain more then one level */
101         WERROR (*get_subkey_by_name) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_key **);
102         WERROR (*get_value_by_index) (TALLOC_CTX *, struct registry_key *, int idx, struct registry_value **);
103
104         /* Can not contain more then one level */
105         WERROR (*get_value_by_name) (TALLOC_CTX *, struct registry_key *, const char *name, struct registry_value **);
106
107         /* Security control */
108         WERROR (*key_get_sec_desc) (TALLOC_CTX *, struct registry_key *, struct security_descriptor **);
109         WERROR (*key_set_sec_desc) (struct registry_key *, struct security_descriptor *);
110
111         /* Notification */
112         WERROR (*request_key_change_notify) (struct registry_key *, key_notification_function);
113         WERROR (*request_value_change_notify) (struct registry_value *, value_notification_function);
114
115         /* Key management */
116         WERROR (*add_key)(TALLOC_CTX *, struct registry_key *, const char *name, uint32_t access_mask, struct security_descriptor *, struct registry_key **);
117         WERROR (*del_key)(struct registry_key *, const char *name);
118         WERROR (*flush_key) (struct registry_key *);
119
120         /* Value management */
121         WERROR (*set_value)(struct registry_key *, const char *name, uint32_t type, DATA_BLOB data); 
122         WERROR (*del_value)(struct registry_key *, const char *valname);
123 };
124
125 struct registry_hive {
126         const struct hive_operations *functions;
127         struct registry_key *root;
128         void *backend_data;
129         const char *location;
130 };
131
132 /* Handle to a full registry
133  * contains zero or more hives */
134 struct registry_context {
135     void *backend_data;
136         WERROR (*get_predefined_key) (struct registry_context *, uint32_t hkey, struct registry_key **);
137 };
138
139 struct reg_init_function_entry {
140         const struct hive_operations *hive_functions;
141         struct reg_init_function_entry *prev, *next;
142 };
143
144 #endif /* _REGISTRY_H */