WHATSNEW: Add release notes for Samba 4.0.26.
[samba.git] / source / 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
35 typedef struct registry_context reg;
36 typedef struct hive_key hive_key;
37 %}
38 %include "../../libcli/util/errors.i"
39
40 /* FIXME: This should be in another file */
41 %typemap(default,noblock=1) struct auth_session_info * {
42     $1 = NULL; 
43 }
44
45 %import "stdint.i"
46 %import "../../lib/talloc/talloc.i"
47 %import "../../auth/credentials/credentials.i"
48 %import "../../param/param.i"
49 %import "../events/events.i"
50
51 /* Utility functions */
52
53 const char *reg_get_predef_name(uint32_t hkey);
54 const char *str_regtype(int type);
55
56 /* Registry contexts */
57 %typemap(in,noblock=1,numinputs=0) struct registry_context ** (struct registry_context *tmp) {
58     $1 = &tmp; 
59 }
60
61 %typemap(argout,noblock=1) struct registry_context ** {
62     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_registry_context, 0);
63 }
64
65 %rename(Registry) reg_open_local;
66 WERROR reg_open_local(TALLOC_CTX *parent_ctx, struct registry_context **ctx);
67
68 %typemap(in,noblock=1) const char ** {
69   /* Check if is a list */
70   if (PyList_Check($input)) {
71     int size = PyList_Size($input);
72     int i = 0;
73     $1 = (char **) malloc((size+1)*sizeof(const char *));
74     for (i = 0; i < size; i++) {
75       PyObject *o = PyList_GetItem($input,i);
76       if (PyString_Check(o))
77     $1[i] = PyString_AsString(PyList_GetItem($input,i));
78       else {
79     PyErr_SetString(PyExc_TypeError,"list must contain strings");
80     free($1);
81     return NULL;
82       }
83     }
84     $1[i] = 0;
85   } else {
86     PyErr_SetString(PyExc_TypeError,"not a list");
87     return NULL;
88   }
89 }
90
91 %typemap(freearg,noblock=1) const char ** {
92   free((char **) $1);
93 }
94
95 %talloctype(reg);
96
97 typedef struct registry_context {
98     %extend {
99
100     %feature("docstring") get_predefined_key_by_name "S.get_predefined_key_by_name(name) -> key\n"
101                                                      "Find a predefined key by name";
102     WERROR get_predefined_key_by_name(const char *name, 
103                                       struct registry_key **key);
104
105     %feature("docstring") key_del_abs "S.key_del_abs(name) -> None\n"
106                                       "Delete a key by absolute path.";
107     WERROR key_del_abs(const char *path);
108     %feature("docstring") get_predefined_key "S.get_predefined_key(hkey_id) -> key\n"
109                                       "Find a predefined key by id";
110     WERROR get_predefined_key(uint32_t hkey_id, struct registry_key **key);
111     %feature("docstring") diff_apply "S.diff_apply(filename) -> None\n"
112                                       "Apply the diff from the specified file";
113
114     WERROR diff_apply(const char *filename);
115     WERROR generate_diff(struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks,
116                          void *callback_data);
117
118     WERROR mount_hive(struct hive_key *key, uint32_t hkey_id,
119                       const char **elements=NULL);
120
121     struct registry_key *import_hive_key(struct hive_key *hive, uint32_t predef_key, const char **elements);
122     %feature("docstring") mount_hive "S.mount_hive(key, predef_name) -> None\n"
123                                       "Mount the specified key at the specified path.";
124     WERROR mount_hive(struct hive_key *key, const char *predef_name)
125     {
126         int i;
127         for (i = 0; reg_predefined_keys[i].name; i++) {
128             if (!strcasecmp(reg_predefined_keys[i].name, predef_name))
129                 return reg_mount_hive($self, key, 
130                                       reg_predefined_keys[i].handle, NULL);
131         }
132         return WERR_INVALID_NAME;
133     }
134
135     }
136 } reg;
137
138 /* Hives */
139 %typemap(in,noblock=1,numinputs=0) struct hive_key ** (struct hive_key *tmp) {
140     $1 = &tmp; 
141 }
142
143 %typemap(argout,noblock=1) struct hive_key ** {
144     Py_XDECREF($result);
145     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_hive_key, 0);
146 }
147
148 %feature("docstring") reg_open_hive "S.__init__(location, session_info=None, credentials=None, loadparm_context=None)";
149 %rename(hive_key) reg_open_hive;
150 WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
151                      struct auth_session_info *session_info,
152                      struct cli_credentials *credentials,
153                      struct event_context *ev_ctx,
154                      struct loadparm_context *lp_ctx,
155                      struct hive_key **root);
156
157 %feature("docstring") reg_open_ldb_file "open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key";
158 %rename(open_ldb) reg_open_ldb_file;
159 WERROR reg_open_ldb_file(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 **k);
165
166 %feature("docstring") reg_create_directory "create_dir(location) -> key";
167 %rename(create_dir) reg_create_directory;
168 WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
169                 const char *location, struct hive_key **key);
170
171 %feature("docstring") reg_open_directory "open_dir(location) -> key";
172 %rename(open_dir) reg_open_directory;
173 WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
174              const char *location, struct hive_key **key);
175
176 %talloctype(hive_key);
177
178 typedef struct hive_key {
179     %extend {
180         %feature("docstring") del "S.del(name) -> None\n"
181                                   "Delete a subkey";
182         WERROR del(const char *name);
183         %feature("docstring") flush "S.flush() -> None\n"
184                                   "Flush this key to disk";
185         WERROR flush(void);
186         %feature("docstring") del_value "S.del_value(name) -> None\n"
187                                   "Delete a value";
188         WERROR del_value(const char *name);
189         %feature("docstring") set_value "S.set_value(name, type, data) -> None\n"
190                                   "Set a value";
191         WERROR set_value(const char *name, uint32_t type, const DATA_BLOB data);
192     }
193 } hive_key;
194
195 %rename(open_samba) reg_open_samba;
196
197 %feature("docstring") reg_open_samba "open_samba() -> reg";
198 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
199                       struct registry_context **ctx,
200                       struct event_context *ev_ctx,
201                       struct loadparm_context *lp_ctx,
202                       struct auth_session_info *session_info,
203                       struct cli_credentials *credentials);
204
205 /* Constants */
206 %constant uint32_t HKEY_CLASSES_ROOT = HKEY_CLASSES_ROOT;
207 %constant uint32_t HKEY_CURRENT_USER = HKEY_CURRENT_USER;
208 %constant uint32_t HKEY_LOCAL_MACHINE = HKEY_LOCAL_MACHINE;
209 %constant uint32_t HKEY_USERS = HKEY_USERS;
210 %constant uint32_t HKEY_PERFORMANCE_DATA = HKEY_PERFORMANCE_DATA;
211 %constant uint32_t HKEY_CURRENT_CONFIG = HKEY_CURRENT_CONFIG;
212 %constant uint32_t HKEY_DYN_DATA = HKEY_DYN_DATA;
213 %constant uint32_t HKEY_PERFORMANCE_TEXT = HKEY_PERFORMANCE_TEXT;
214 %constant uint32_t HKEY_PERFORMANCE_NLSTEXT = HKEY_PERFORMANCE_NLSTEXT;