1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE chapter PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
3 <chapter id="registry">
6 <pubdate>24 September 2003</pubdate>
9 <title>The registry subsystem</title>
11 <sect1><title>Planned backends</title>
14 The new registry subsystem will work with several different backends:
18 <listitem><para>NT4 (NT4 registry files)</para></listitem>
19 <listitem><para>TDB (Samba TDB files)</para></listitem>
20 <listitem><para>RPC (Remote Registry over RPC, reg pipe)</para></listitem>
21 <listitem><para>wine (Wine Registry Files)</para></listitem>
22 <listitem><para>gconf (The GNOME configuration backend)</para></listitem>
27 <sect1><title>Data structures</title>
30 The following structure describes a registry key:
34 typedef struct reg_key_s {
35 char *name; /* Name of the key */
36 smb_ucs2_t *class_name; /* Name of key class */
37 int type; /* One of REG_ROOT_KEY or REG_SUB_KEY */
38 NTTIME last_mod; /* Time last modified */
39 struct reg_key_s *owner;
40 struct key_list_s *sub_keys; /* NULL indicates keys not available in memory, function should be called */
41 struct val_list_s *values; /* NULL indicates values not available in memory, function should be called */
43 REG_HANDLE *handle; /* Pointer to REG_HANDLE this key belongs to */
44 void *backend_data; /* Pointer used by the backend */
48 <para>The following structure describes a registry value:</para>
51 typedef struct val_key_s {
52 char *name; /* NULL if name not available */
55 void *data_blk; /* Might want a separate block */
56 REG_HANDLE *handle; /* Pointer to REG_HANDLE this key belongs to */
61 <para>The following structures are used for lists of subkeys or values:</para>
64 /* container for registry subkey names */
65 typedef struct key_list_s {
71 /* container for registry values */
72 typedef struct val_list_s {
80 And this structure is used for an instance of a registry (a registry file that's opened, a remote registry pipe we're connected to, etc).
84 typedef struct reg_handle_s {
85 REGISTRY_OPS *functions;
86 REG_KEY *root; /* NULL if not available */
94 <title>External interface</title>
97 REG_HANDLE *reg_open(char *backend, char *location, BOOL try_full_load);
98 REG_KEY *reg_open_key(REG_KEY *parent, char *name);
99 REG_VAL *reg_key_get_val(REG_KEY *key, char *name);
100 REG_VAL_LIST *reg_key_get_vals(REG_KEY *key);
101 REG_KEY_LIST *reg_key_get_subkeys(REG_KEY *key);
102 BOOL reg_key_del(REG_KEY *key);
103 BOOL reg_val_del(REG_VAL *val);
104 BOOL reg_key_add(REG_KEY *parent, REG_KEY *key);
105 BOOL reg_val_add(REG_KEY *parent, REG_VAL *val):
106 BOOL reg_val_update(REG_VAL *val);
107 BOOL reg_key_update(REG_KEY *key);
108 void reg_free_key(REG_KEY *key);
109 void reg_free_val(REG_VAL *val);
110 void reg_free(REG_HANDLE *h);
111 void reg_free_key_list(REG_KEY_LIST *list):
112 void reg_free_val_list(REG_VAL_LIST *list):
118 <title>Utility functions</title>
120 <para>The following helper functions are available:</para>
123 void reg_key_list_init( REG_KEY_LIST *ctr );
124 int reg_key_list_addkey( REG_KEY_LIST *ctr, const char *keyname );
125 int reg_key_list_numkeys( REG_KEY_LIST *ctr );
126 char* reg_key_list_specific_key( REG_KEY_LIST *ctr, uint32 key_index );
127 void reg_key_list_destroy( REG_KEY_LIST *ctr );
128 void reg_val_list_init( REG_VAL_LIST *ctr );
129 int reg_val_list_numvals( REG_VAL_LIST *ctr );
130 void free_registry_value( REG_VAL *val );
131 uint8* regval_data_p( REG_VAL *val );
132 int regval_size( REG_VAL *val );
133 char* regval_name( REG_VAL *val );
134 uint32 regval_type( REG_VAL *val );
135 TALLOC_CTX* reg_val_list_getctx( REG_VAL_LIST *val );
136 int reg_val_list_addvalue( REG_VAL_LIST *ctr, const char *name, uint16 type,
137 const char *data_p, size_t size );
138 int reg_val_list_copyvalue( REG_VAL_LIST *ctr, REG_VAL *val );
139 int reg_val_list_delvalue( REG_VAL_LIST *ctr, const char *name );
140 void reg_val_list_destroy( REG_VAL_LIST *ctr );
146 <title>Writing backends</title>
148 <para>There are basically two ways of reading data from the registry: loading
149 it all into memory and then working in this copy in memory, or
150 re-reading/re-opening it every time necessary.</para>
152 <para>This interface aims to support both types. </para>
154 <para>A registry backend should provide the following functions:</para>
158 REG_HANDLE *(*open_registry) (const char *location, BOOL try_complete_load);
159 REG_KEY *(*open_root_key) (REG_HANDLE *);
160 REG_KEY *(*open_key_rel) (REG_KEY *parent, const char *name);
161 /* if open_key_abs is set to NULL, a default implementation will be provided. */
162 REG_KEY *(*open_key_abs) (REG_HANDLE *, const char *name);
163 REG_KEY_LIST *(*get_subkeys) (REG_KEY *);
164 REG_VAL_LIST *(*get_values) (REG_KEY *);
165 BOOL (*add_key)(REG_KEY *, REG_KEY *);
166 BOOL (*update_key)(REG_KEY *);
167 BOOL (*del_key)(REG_KEY *);
168 BOOL (*add_value)(REG_KEY *, REG_VAL *);
169 BOOL (*update_value)(REG_VAL *);
170 BOOL (*del_value)(REG_VAL *);
171 REG_VAL *(*get_value) (REG_KEY *, const char *name);
172 /* It is not guaranteed that no data has been stored before save()
173 * has been called. This function is only useful for backends that
174 * store the data in memory and then write out the whole registry at once */
175 BOOL (*save)(REG_HANDLE *, const char *location);
176 BOOL (*close_registry) (REG_HANDLE *);
177 void (*free_key)(REG_KEY *);
178 void (*free_value)(REG_VAL *);
182 <para>open_root_key() is optional. It's only called if the
183 <parameter>root</parameter> field of the REG_HANDLE struct is NULL.</para>
185 <para>open_key_abs() is optional. If it's NULL, the frontend will
186 provide a replacement, using open_key_rel().</para>
188 <para>get_values() and get_value() are optional. They're only called if
189 the <parameter>values</parameter> field of the REG_KEY struct is NULL.</para>
191 <para>get_subkeys() and get_key() are optional. THey're only called
192 if the <parameter>subkeys</parameter> field of the REG_KEY struct is NULL.</para>
196 <sect1><title>Memory allocation</title>
198 <para>Okay, so who's responsible for what parts of the memory? </para>
200 <para>The memory is basically maintained by the backends. When the user
201 is finished using a particular structure, it should call the related free
202 function for the structure it's freeing.</para>
204 <para>The backend should then decide what to do with the structure. It may
205 choose to free it, or, if it's maintaining single copies of everything in
206 memory, may choose to ignore the free and free it when the registry is closed.