cbd5fe87937b856b80b0f89f1ffb2bc0c14827fe
[kai/samba.git] / source4 / lib / registry / registry.i
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 %define DOCSTRING
20 "Access to various registry formats and the Samba registry."
21 %enddef
22
23 %module(docstring=DOCSTRING) registry
24
25 %{
26 /* Include headers */
27 #include <stdint.h>
28 #include <stdbool.h>
29
30 #include "includes.h"
31 #include "registry.h"
32 #include "param/param.h"
33 #include "events/events.h"
34 #include "scripting/python/modules.h"
35
36 typedef struct registry_context reg;
37 typedef struct hive_key hive_key;
38 %}
39 %include "../../libcli/util/errors.i"
40
41 /* FIXME: This should be in another file */
42 %typemap(default,noblock=1) struct auth_session_info * {
43     $1 = NULL; 
44 }
45
46 %import "stdint.i"
47 %import "../../../lib/talloc/talloc.i"
48 %import "../../auth/credentials/credentials.i"
49 %import "../../param/param.i"
50 %import "../events/events.i"
51
52 /* Utility functions */
53
54 const char *reg_get_predef_name(uint32_t hkey);
55 const char *str_regtype(int type);
56
57 /* Registry contexts */
58 %typemap(in,noblock=1,numinputs=0) struct registry_context ** (struct registry_context *tmp) {
59     $1 = &tmp; 
60 }
61
62 %typemap(argout,noblock=1) struct registry_context ** {
63     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_registry_context, 0);
64 }
65
66 %typemap(in,noblock=1,numinputs=0) struct smb_iconv_convenience *ic {
67     $1 = py_iconv_convenience(NULL);
68 }
69
70 %typemap(freearg,noblock=1) struct smb_iconv_convenience *ic {
71     talloc_free($1);
72 }
73
74 %rename(Registry) reg_open_local;
75 WERROR reg_open_local(TALLOC_CTX *parent_ctx, struct registry_context **ctx);
76
77 %typemap(in,noblock=1) const char ** {
78   /* Check if is a list */
79   if (PyList_Check($input)) {
80     int size = PyList_Size($input);
81     int i = 0;
82     $1 = (char **) malloc((size+1)*sizeof(const char *));
83     for (i = 0; i < size; i++) {
84       PyObject *o = PyList_GetItem($input,i);
85       if (PyString_Check(o))
86     $1[i] = PyString_AsString(PyList_GetItem($input,i));
87       else {
88     PyErr_SetString(PyExc_TypeError,"list must contain strings");
89     free($1);
90     return NULL;
91       }
92     }
93     $1[i] = 0;
94   } else {
95     PyErr_SetString(PyExc_TypeError,"not a list");
96     return NULL;
97   }
98 }
99
100 %typemap(freearg,noblock=1) const char ** {
101   free((char **) $1);
102 }
103
104 %talloctype(reg);
105
106 typedef struct registry_context {
107     %extend {
108
109     %feature("docstring") get_predefined_key_by_name "S.get_predefined_key_by_name(name) -> key\n"
110                                                      "Find a predefined key by name";
111     WERROR get_predefined_key_by_name(const char *name, 
112                                       struct registry_key **key);
113
114     %feature("docstring") key_del_abs "S.key_del_abs(name) -> None\n"
115                                       "Delete a key by absolute path.";
116     WERROR key_del_abs(const char *path);
117     %feature("docstring") get_predefined_key "S.get_predefined_key(hkey_id) -> key\n"
118                                       "Find a predefined key by id";
119     WERROR get_predefined_key(uint32_t hkey_id, struct registry_key **key);
120     %feature("docstring") diff_apply "S.diff_apply(filename) -> None\n"
121                                       "Apply the diff from the specified file";
122
123     WERROR diff_apply(struct smb_iconv_convenience *ic, const char *filename);
124     WERROR generate_diff(struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks,
125                          void *callback_data);
126
127     WERROR mount_hive(struct hive_key *key, uint32_t hkey_id,
128                       const char **elements=NULL);
129
130     struct registry_key *import_hive_key(struct hive_key *hive, uint32_t predef_key, const char **elements);
131     %feature("docstring") mount_hive "S.mount_hive(key, predef_name) -> None\n"
132                                       "Mount the specified key at the specified path.";
133     WERROR mount_hive(struct hive_key *key, const char *predef_name)
134     {
135         int i;
136         for (i = 0; reg_predefined_keys[i].name; i++) {
137             if (!strcasecmp(reg_predefined_keys[i].name, predef_name))
138                 return reg_mount_hive($self, key, 
139                                       reg_predefined_keys[i].handle, NULL);
140         }
141         return WERR_INVALID_NAME;
142     }
143
144     }
145 } reg;
146
147 /* Hives */
148 %typemap(in,noblock=1,numinputs=0) struct hive_key ** (struct hive_key *tmp) {
149     $1 = &tmp; 
150 }
151
152 %typemap(argout,noblock=1) struct hive_key ** {
153     Py_XDECREF($result);
154     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_hive_key, 0);
155 }
156
157 %feature("docstring") reg_open_hive "S.__init__(location, session_info=None, credentials=None, loadparm_context=None)";
158 %rename(hive_key) reg_open_hive;
159 WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
160                      struct auth_session_info *session_info,
161                      struct cli_credentials *credentials,
162                      struct event_context *ev_ctx,
163                      struct loadparm_context *lp_ctx,
164                      struct hive_key **root);
165
166 %feature("docstring") reg_open_ldb_file "open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key";
167 %rename(open_ldb) reg_open_ldb_file;
168 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
169              struct auth_session_info *session_info,
170              struct cli_credentials *credentials,
171              struct event_context *ev_ctx,
172              struct loadparm_context *lp_ctx,
173              struct hive_key **k);
174
175 %feature("docstring") reg_create_directory "create_dir(location) -> key";
176 %rename(create_dir) reg_create_directory;
177 WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
178                 const char *location, struct hive_key **key);
179
180 %feature("docstring") reg_open_directory "open_dir(location) -> key";
181 %rename(open_dir) reg_open_directory;
182 WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
183              const char *location, struct hive_key **key);
184
185 %talloctype(hive_key);
186
187 typedef struct hive_key {
188     %extend {
189         %feature("docstring") del "S.del(name) -> None\n"
190                                   "Delete a subkey";
191         WERROR del(const char *name);
192         %feature("docstring") flush "S.flush() -> None\n"
193                                   "Flush this key to disk";
194         WERROR flush(void);
195         %feature("docstring") del_value "S.del_value(name) -> None\n"
196                                   "Delete a value";
197         WERROR del_value(const char *name);
198         %feature("docstring") set_value "S.set_value(name, type, data) -> None\n"
199                                   "Set a value";
200         WERROR set_value(const char *name, uint32_t type, const DATA_BLOB data);
201     }
202 } hive_key;
203
204 %rename(open_samba) reg_open_samba;
205
206 %feature("docstring") reg_open_samba "open_samba() -> reg";
207 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
208                       struct registry_context **ctx,
209                       struct event_context *ev_ctx,
210                       struct loadparm_context *lp_ctx,
211                       struct auth_session_info *session_info,
212                       struct cli_credentials *credentials);
213
214 /* Constants */
215 %constant uint32_t HKEY_CLASSES_ROOT = HKEY_CLASSES_ROOT;
216 %constant uint32_t HKEY_CURRENT_USER = HKEY_CURRENT_USER;
217 %constant uint32_t HKEY_LOCAL_MACHINE = HKEY_LOCAL_MACHINE;
218 %constant uint32_t HKEY_USERS = HKEY_USERS;
219 %constant uint32_t HKEY_PERFORMANCE_DATA = HKEY_PERFORMANCE_DATA;
220 %constant uint32_t HKEY_CURRENT_CONFIG = HKEY_CURRENT_CONFIG;
221 %constant uint32_t HKEY_DYN_DATA = HKEY_DYN_DATA;
222 %constant uint32_t HKEY_PERFORMANCE_TEXT = HKEY_PERFORMANCE_TEXT;
223 %constant uint32_t HKEY_PERFORMANCE_NLSTEXT = HKEY_PERFORMANCE_NLSTEXT;