6f46e081c24cf30db22a9ad2b827d5f1d008efdd
[ab/samba.git/.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 %module registry
20
21 %{
22 /* Include headers */
23 #include <stdint.h>
24 #include <stdbool.h>
25
26 #include "includes.h"
27 #include "registry.h"
28 #include "param/param.h"
29
30 typedef struct registry_context reg;
31 typedef struct hive_key hive_key;
32 %}
33
34 /* FIXME: This should be in another file */
35 %typemap(default,noblock=1) struct auth_session_info * {
36     $1 = NULL; 
37 }
38
39 %import "stdint.i"
40 %import "../../lib/talloc/talloc.i"
41 %import "../../auth/credentials/credentials.i"
42 %import "../../libcli/util/errors.i"
43 %import "../../param/param.i"
44
45 /* Utility functions */
46
47 const char *reg_get_predef_name(uint32_t hkey);
48 const char *str_regtype(int type);
49
50 /* Registry contexts */
51 %typemap(in,noblock=1,numinputs=0) struct registry_context ** (struct registry_context *tmp) {
52     $1 = &tmp; 
53 }
54
55 %typemap(argout,noblock=1) struct registry_context ** {
56     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_registry_context, 0);
57 }
58
59 %rename(Registry) reg_open_local;
60 WERROR reg_open_local(TALLOC_CTX *parent_ctx, struct registry_context **ctx,
61                       struct auth_session_info *session_info,
62                       struct cli_credentials *credentials);
63
64 %typemap(in,noblock=1) const char ** {
65   /* Check if is a list */
66   if (PyList_Check($input)) {
67     int size = PyList_Size($input);
68     int i = 0;
69     $1 = (char **) malloc((size+1)*sizeof(const char *));
70     for (i = 0; i < size; i++) {
71       PyObject *o = PyList_GetItem($input,i);
72       if (PyString_Check(o))
73     $1[i] = PyString_AsString(PyList_GetItem($input,i));
74       else {
75     PyErr_SetString(PyExc_TypeError,"list must contain strings");
76     free($1);
77     return NULL;
78       }
79     }
80     $1[i] = 0;
81   } else {
82     PyErr_SetString(PyExc_TypeError,"not a list");
83     return NULL;
84   }
85 }
86
87 %typemap(freearg,noblock=1) const char ** {
88   free((char **) $1);
89 }
90
91 %talloctype(reg);
92
93 typedef struct registry_context {
94     %extend {
95
96     WERROR get_predefined_key_by_name(const char *name, 
97                                       struct registry_key **key);
98
99     WERROR key_del_abs(const char *path);
100     WERROR get_predefined_key(uint32_t hkey_id, struct registry_key **key);
101     WERROR diff_apply(const char *filename);
102     WERROR generate_diff(struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks,
103                          void *callback_data);
104
105     WERROR mount_hive(struct hive_key *hive_key, uint32_t hkey_id,
106                       const char **elements=NULL);
107
108     struct registry_key *import_hive_key(struct hive_key *hive, uint32_t predef_key, const char **elements);
109     WERROR mount_hive(struct hive_key *hive_key, const char *predef_name)
110     {
111         int i;
112         for (i = 0; reg_predefined_keys[i].name; i++) {
113             if (!strcasecmp(reg_predefined_keys[i].name, predef_name))
114                 return reg_mount_hive($self, hive_key, 
115                                       reg_predefined_keys[i].handle, NULL);
116         }
117         return WERR_INVALID_NAME;
118     }
119
120     }
121 } reg;
122
123 /* Hives */
124 %typemap(in,noblock=1,numinputs=0) struct hive_key ** (struct hive_key *tmp) {
125     $1 = &tmp; 
126 }
127
128 %typemap(argout,noblock=1) struct hive_key ** {
129     Py_XDECREF($result);
130     $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_hive_key, 0);
131 }
132
133 %rename(hive_key) reg_open_hive;
134 WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
135                      struct auth_session_info *session_info,
136                      struct cli_credentials *credentials,
137                      struct loadparm_context *lp_ctx,
138                      struct hive_key **root);
139
140 %rename(open_ldb) reg_open_ldb_file;
141 WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location,
142              struct auth_session_info *session_info,
143              struct cli_credentials *credentials,
144              struct loadparm_context *lp_ctx,
145              struct hive_key **k);
146
147 %rename(create_dir) reg_create_directory;
148 WERROR reg_create_directory(TALLOC_CTX *parent_ctx,
149                 const char *location, struct hive_key **key);
150
151 %rename(open_dir) reg_open_directory;
152 WERROR reg_open_directory(TALLOC_CTX *parent_ctx,
153              const char *location, struct hive_key **key);
154
155 %talloctype(hive_key);
156
157 typedef struct hive_key {
158     %extend {
159         WERROR del(const char *name);
160         WERROR flush(void);
161         WERROR del_value(const char *name);
162         WERROR set_value(const char *name, uint32_t type, const DATA_BLOB data);
163     }
164 } hive_key;
165
166 %rename(open_samba) reg_open_samba;
167
168 WERROR reg_open_samba(TALLOC_CTX *mem_ctx,
169                       struct registry_context **ctx,
170                       struct loadparm_context *lp_ctx,
171                       struct auth_session_info *session_info,
172                       struct cli_credentials *credentials);
173
174 /* Constants */
175 %constant uint32_t HKEY_CLASSES_ROOT = HKEY_CLASSES_ROOT;
176 %constant uint32_t HKEY_CURRENT_USER = HKEY_CURRENT_USER;
177 %constant uint32_t HKEY_LOCAL_MACHINE = HKEY_LOCAL_MACHINE;
178 %constant uint32_t HKEY_USERS = HKEY_USERS;
179 %constant uint32_t HKEY_PERFORMANCE_DATA = HKEY_PERFORMANCE_DATA;
180 %constant uint32_t HKEY_CURRENT_CONFIG = HKEY_CURRENT_CONFIG;
181 %constant uint32_t HKEY_DYN_DATA = HKEY_DYN_DATA;
182 %constant uint32_t HKEY_PERFORMANCE_TEXT = HKEY_PERFORMANCE_TEXT;
183 %constant uint32_t HKEY_PERFORMANCE_NLSTEXT = HKEY_PERFORMANCE_NLSTEXT;