git add -f bin/default/librpc/gen_ndr/*.{c,h,ndr,pidl} bin/default/source*/librpc...
[metze/samba/wip.git] / bin / default / librpc / gen_ndr / py_witness.c
1
2 /* Python wrapper functions auto-generated by pidl */
3 #include <Python.h>
4 #include "includes.h"
5 #include <pytalloc.h>
6 #include "librpc/rpc/pyrpc.h"
7 #include "librpc/rpc/pyrpc_util.h"
8 #include "bin/default/librpc/gen_ndr/ndr_witness.h"
9 #include "bin/default/librpc/gen_ndr/ndr_witness_c.h"
10
11 #include "librpc/gen_ndr/misc.h"
12 staticforward PyTypeObject witness_interfaceInfo_Type;
13 staticforward PyTypeObject witness_interfaceList_Type;
14 staticforward PyTypeObject witness_notifyResponse_Type;
15 staticforward PyTypeObject witness_InterfaceType;
16
17 void initwitness(void);static PyTypeObject *Object_Type;
18 static PyTypeObject *policy_handle_Type;
19 static PyTypeObject *ClientConnection_Type;
20 static PyTypeObject *ndr_syntax_id_Type;
21
22 static PyObject *py_witness_interfaceInfo_get_group_name(PyObject *obj, void *closure)
23 {
24         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(obj);
25         PyObject *py_group_name;
26         if (object->group_name == NULL) {
27                 py_group_name = Py_None;
28                 Py_INCREF(py_group_name);
29         } else {
30                 py_group_name = PyUnicode_Decode(object->group_name, strlen(object->group_name), "utf-8", "ignore");
31         }
32         return py_group_name;
33 }
34
35 static int py_witness_interfaceInfo_set_group_name(PyObject *py_obj, PyObject *value, void *closure)
36 {
37         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(py_obj);
38         if (PyUnicode_Check(value)) {
39                 object->group_name = PyString_AS_STRING(PyUnicode_AsEncodedString(value, "utf-8", "ignore"));
40         } else if (PyString_Check(value)) {
41                 object->group_name = PyString_AS_STRING(value);
42         } else {
43                 PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(value)->tp_name);
44                 return -1;
45         }
46         return 0;
47 }
48
49 static PyObject *py_witness_interfaceInfo_get_version(PyObject *obj, void *closure)
50 {
51         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(obj);
52         PyObject *py_version;
53         py_version = PyInt_FromLong(object->version);
54         return py_version;
55 }
56
57 static int py_witness_interfaceInfo_set_version(PyObject *py_obj, PyObject *value, void *closure)
58 {
59         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(py_obj);
60         if (PyLong_Check(value)) {
61                 object->version = PyLong_AsLongLong(value);
62         } else if (PyInt_Check(value)) {
63                 object->version = PyInt_AsLong(value);
64         } else {
65                 PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
66                   PyInt_Type.tp_name, PyLong_Type.tp_name);
67                 return -1;
68         }
69         return 0;
70 }
71
72 static PyObject *py_witness_interfaceInfo_get_state(PyObject *obj, void *closure)
73 {
74         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(obj);
75         PyObject *py_state;
76         py_state = PyInt_FromLong(object->state);
77         return py_state;
78 }
79
80 static int py_witness_interfaceInfo_set_state(PyObject *py_obj, PyObject *value, void *closure)
81 {
82         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(py_obj);
83         if (PyLong_Check(value)) {
84                 object->state = PyLong_AsLongLong(value);
85         } else if (PyInt_Check(value)) {
86                 object->state = PyInt_AsLong(value);
87         } else {
88                 PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
89                   PyInt_Type.tp_name, PyLong_Type.tp_name);
90                 return -1;
91         }
92         return 0;
93 }
94
95 static PyObject *py_witness_interfaceInfo_get_ipv4(PyObject *obj, void *closure)
96 {
97         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(obj);
98         PyObject *py_ipv4;
99         py_ipv4 = PyString_FromStringOrNULL(object->ipv4);
100         return py_ipv4;
101 }
102
103 static int py_witness_interfaceInfo_set_ipv4(PyObject *py_obj, PyObject *value, void *closure)
104 {
105         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(py_obj);
106         object->ipv4 = PyString_AS_STRING(value);
107         return 0;
108 }
109
110 static PyObject *py_witness_interfaceInfo_get_ipv6(PyObject *obj, void *closure)
111 {
112         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(obj);
113         PyObject *py_ipv6;
114         py_ipv6 = PyString_FromStringOrNULL(object->ipv6);
115         return py_ipv6;
116 }
117
118 static int py_witness_interfaceInfo_set_ipv6(PyObject *py_obj, PyObject *value, void *closure)
119 {
120         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(py_obj);
121         object->ipv6 = PyString_AsString(value);
122         return 0;
123 }
124
125 static PyObject *py_witness_interfaceInfo_get_flags(PyObject *obj, void *closure)
126 {
127         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(obj);
128         PyObject *py_flags;
129         py_flags = PyInt_FromLong(object->flags);
130         return py_flags;
131 }
132
133 static int py_witness_interfaceInfo_set_flags(PyObject *py_obj, PyObject *value, void *closure)
134 {
135         struct witness_interfaceInfo *object = (struct witness_interfaceInfo *)pytalloc_get_ptr(py_obj);
136         if (PyLong_Check(value)) {
137                 object->flags = PyLong_AsLongLong(value);
138         } else if (PyInt_Check(value)) {
139                 object->flags = PyInt_AsLong(value);
140         } else {
141                 PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
142                   PyInt_Type.tp_name, PyLong_Type.tp_name);
143                 return -1;
144         }
145         return 0;
146 }
147
148 static PyGetSetDef py_witness_interfaceInfo_getsetters[] = {
149         { discard_const_p(char, "group_name"), py_witness_interfaceInfo_get_group_name, py_witness_interfaceInfo_set_group_name },
150         { discard_const_p(char, "version"), py_witness_interfaceInfo_get_version, py_witness_interfaceInfo_set_version },
151         { discard_const_p(char, "state"), py_witness_interfaceInfo_get_state, py_witness_interfaceInfo_set_state },
152         { discard_const_p(char, "ipv4"), py_witness_interfaceInfo_get_ipv4, py_witness_interfaceInfo_set_ipv4 },
153         { discard_const_p(char, "ipv6"), py_witness_interfaceInfo_get_ipv6, py_witness_interfaceInfo_set_ipv6 },
154         { discard_const_p(char, "flags"), py_witness_interfaceInfo_get_flags, py_witness_interfaceInfo_set_flags },
155         { NULL }
156 };
157
158 static PyObject *py_witness_interfaceInfo_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
159 {
160         return pytalloc_new(struct witness_interfaceInfo, type);
161 }
162
163
164 static PyTypeObject witness_interfaceInfo_Type = {
165         PyObject_HEAD_INIT(NULL) 0,
166         .tp_name = "witness.interfaceInfo",
167         .tp_getset = py_witness_interfaceInfo_getsetters,
168         .tp_methods = NULL,
169         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
170         .tp_basicsize = sizeof(pytalloc_Object),
171         .tp_new = py_witness_interfaceInfo_new,
172 };
173
174
175 static PyObject *py_witness_interfaceList_get_num_interfaces(PyObject *obj, void *closure)
176 {
177         struct witness_interfaceList *object = (struct witness_interfaceList *)pytalloc_get_ptr(obj);
178         PyObject *py_num_interfaces;
179         py_num_interfaces = PyInt_FromLong(object->num_interfaces);
180         return py_num_interfaces;
181 }
182
183 static int py_witness_interfaceList_set_num_interfaces(PyObject *py_obj, PyObject *value, void *closure)
184 {
185         struct witness_interfaceList *object = (struct witness_interfaceList *)pytalloc_get_ptr(py_obj);
186         PY_CHECK_TYPE(&PyInt_Type, value, return -1;);
187         object->num_interfaces = PyInt_AsLong(value);
188         return 0;
189 }
190
191 static PyObject *py_witness_interfaceList_get_interfaces(PyObject *obj, void *closure)
192 {
193         struct witness_interfaceList *object = (struct witness_interfaceList *)pytalloc_get_ptr(obj);
194         PyObject *py_interfaces;
195         if (object->interfaces == NULL) {
196                 py_interfaces = Py_None;
197                 Py_INCREF(py_interfaces);
198         } else {
199                 py_interfaces = PyList_New(object->num_interfaces);
200                 if (py_interfaces == NULL) {
201                         return NULL;
202                 }
203                 {
204                         int interfaces_cntr_1;
205                         for (interfaces_cntr_1 = 0; interfaces_cntr_1 < object->num_interfaces; interfaces_cntr_1++) {
206                                 PyObject *py_interfaces_1;
207                                 py_interfaces_1 = pytalloc_reference_ex(&witness_interfaceInfo_Type, object->interfaces, &object->interfaces[interfaces_cntr_1]);
208                                 PyList_SetItem(py_interfaces, interfaces_cntr_1, py_interfaces_1);
209                         }
210                 }
211         }
212         return py_interfaces;
213 }
214
215 static int py_witness_interfaceList_set_interfaces(PyObject *py_obj, PyObject *value, void *closure)
216 {
217         struct witness_interfaceList *object = (struct witness_interfaceList *)pytalloc_get_ptr(py_obj);
218         talloc_unlink(pytalloc_get_mem_ctx(py_obj), object->interfaces);
219         if (value == Py_None) {
220                 object->interfaces = NULL;
221         } else {
222                 object->interfaces = NULL;
223                 PY_CHECK_TYPE(&PyList_Type, value, return -1;);
224                 {
225                         int interfaces_cntr_1;
226                         object->interfaces = talloc_array_ptrtype(pytalloc_get_mem_ctx(py_obj), object->interfaces, PyList_GET_SIZE(value));
227                         if (!object->interfaces) { return -1;; }
228                         talloc_set_name_const(object->interfaces, "ARRAY: object->interfaces");
229                         for (interfaces_cntr_1 = 0; interfaces_cntr_1 < PyList_GET_SIZE(value); interfaces_cntr_1++) {
230                                 PY_CHECK_TYPE(&witness_interfaceInfo_Type, PyList_GET_ITEM(value, interfaces_cntr_1), return -1;);
231                                 if (talloc_reference(object->interfaces, pytalloc_get_mem_ctx(PyList_GET_ITEM(value, interfaces_cntr_1))) == NULL) {
232                                         PyErr_NoMemory();
233                                         return -1;
234                                 }
235                                 object->interfaces[interfaces_cntr_1] = *(struct witness_interfaceInfo *)pytalloc_get_ptr(PyList_GET_ITEM(value, interfaces_cntr_1));
236                         }
237                 }
238         }
239         return 0;
240 }
241
242 static PyGetSetDef py_witness_interfaceList_getsetters[] = {
243         { discard_const_p(char, "num_interfaces"), py_witness_interfaceList_get_num_interfaces, py_witness_interfaceList_set_num_interfaces },
244         { discard_const_p(char, "interfaces"), py_witness_interfaceList_get_interfaces, py_witness_interfaceList_set_interfaces },
245         { NULL }
246 };
247
248 static PyObject *py_witness_interfaceList_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
249 {
250         return pytalloc_new(struct witness_interfaceList, type);
251 }
252
253
254 static PyTypeObject witness_interfaceList_Type = {
255         PyObject_HEAD_INIT(NULL) 0,
256         .tp_name = "witness.interfaceList",
257         .tp_getset = py_witness_interfaceList_getsetters,
258         .tp_methods = NULL,
259         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
260         .tp_basicsize = sizeof(pytalloc_Object),
261         .tp_new = py_witness_interfaceList_new,
262 };
263
264
265 static PyObject *py_witness_notifyResponse_get_message_type(PyObject *obj, void *closure)
266 {
267         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(obj);
268         PyObject *py_message_type;
269         py_message_type = PyInt_FromLong(object->message_type);
270         return py_message_type;
271 }
272
273 static int py_witness_notifyResponse_set_message_type(PyObject *py_obj, PyObject *value, void *closure)
274 {
275         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(py_obj);
276         if (PyLong_Check(value)) {
277                 object->message_type = PyLong_AsLongLong(value);
278         } else if (PyInt_Check(value)) {
279                 object->message_type = PyInt_AsLong(value);
280         } else {
281                 PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
282                   PyInt_Type.tp_name, PyLong_Type.tp_name);
283                 return -1;
284         }
285         return 0;
286 }
287
288 static PyObject *py_witness_notifyResponse_get_length(PyObject *obj, void *closure)
289 {
290         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(obj);
291         PyObject *py_length;
292         py_length = PyInt_FromLong(object->length);
293         return py_length;
294 }
295
296 static int py_witness_notifyResponse_set_length(PyObject *py_obj, PyObject *value, void *closure)
297 {
298         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(py_obj);
299         PY_CHECK_TYPE(&PyInt_Type, value, return -1;);
300         object->length = PyInt_AsLong(value);
301         return 0;
302 }
303
304 static PyObject *py_witness_notifyResponse_get_num_messages(PyObject *obj, void *closure)
305 {
306         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(obj);
307         PyObject *py_num_messages;
308         py_num_messages = PyInt_FromLong(object->num_messages);
309         return py_num_messages;
310 }
311
312 static int py_witness_notifyResponse_set_num_messages(PyObject *py_obj, PyObject *value, void *closure)
313 {
314         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(py_obj);
315         PY_CHECK_TYPE(&PyInt_Type, value, return -1;);
316         object->num_messages = PyInt_AsLong(value);
317         return 0;
318 }
319
320 static PyObject *py_witness_notifyResponse_get_message_buffer(PyObject *obj, void *closure)
321 {
322         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(obj);
323         PyObject *py_message_buffer;
324         if (object->message_buffer == NULL) {
325                 py_message_buffer = Py_None;
326                 Py_INCREF(py_message_buffer);
327         } else {
328                 py_message_buffer = PyList_New(object->length);
329                 if (py_message_buffer == NULL) {
330                         return NULL;
331                 }
332                 {
333                         int message_buffer_cntr_1;
334                         for (message_buffer_cntr_1 = 0; message_buffer_cntr_1 < object->length; message_buffer_cntr_1++) {
335                                 PyObject *py_message_buffer_1;
336                                 py_message_buffer_1 = PyInt_FromLong(object->message_buffer[message_buffer_cntr_1]);
337                                 PyList_SetItem(py_message_buffer, message_buffer_cntr_1, py_message_buffer_1);
338                         }
339                 }
340         }
341         return py_message_buffer;
342 }
343
344 static int py_witness_notifyResponse_set_message_buffer(PyObject *py_obj, PyObject *value, void *closure)
345 {
346         struct witness_notifyResponse *object = (struct witness_notifyResponse *)pytalloc_get_ptr(py_obj);
347         talloc_unlink(pytalloc_get_mem_ctx(py_obj), object->message_buffer);
348         if (value == Py_None) {
349                 object->message_buffer = NULL;
350         } else {
351                 object->message_buffer = NULL;
352                 PY_CHECK_TYPE(&PyList_Type, value, return -1;);
353                 {
354                         int message_buffer_cntr_1;
355                         object->message_buffer = talloc_array_ptrtype(pytalloc_get_mem_ctx(py_obj), object->message_buffer, PyList_GET_SIZE(value));
356                         if (!object->message_buffer) { return -1;; }
357                         talloc_set_name_const(object->message_buffer, "ARRAY: object->message_buffer");
358                         for (message_buffer_cntr_1 = 0; message_buffer_cntr_1 < PyList_GET_SIZE(value); message_buffer_cntr_1++) {
359                                 PY_CHECK_TYPE(&PyInt_Type, PyList_GET_ITEM(value, message_buffer_cntr_1), return -1;);
360                                 object->message_buffer[message_buffer_cntr_1] = PyInt_AsLong(PyList_GET_ITEM(value, message_buffer_cntr_1));
361                         }
362                 }
363         }
364         return 0;
365 }
366
367 static PyGetSetDef py_witness_notifyResponse_getsetters[] = {
368         { discard_const_p(char, "message_type"), py_witness_notifyResponse_get_message_type, py_witness_notifyResponse_set_message_type },
369         { discard_const_p(char, "length"), py_witness_notifyResponse_get_length, py_witness_notifyResponse_set_length },
370         { discard_const_p(char, "num_messages"), py_witness_notifyResponse_get_num_messages, py_witness_notifyResponse_set_num_messages },
371         { discard_const_p(char, "message_buffer"), py_witness_notifyResponse_get_message_buffer, py_witness_notifyResponse_set_message_buffer },
372         { NULL }
373 };
374
375 static PyObject *py_witness_notifyResponse_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
376 {
377         return pytalloc_new(struct witness_notifyResponse, type);
378 }
379
380
381 static PyTypeObject witness_notifyResponse_Type = {
382         PyObject_HEAD_INIT(NULL) 0,
383         .tp_name = "witness.notifyResponse",
384         .tp_getset = py_witness_notifyResponse_getsetters,
385         .tp_methods = NULL,
386         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
387         .tp_basicsize = sizeof(pytalloc_Object),
388         .tp_new = py_witness_notifyResponse_new,
389 };
390
391
392 static bool pack_py_witness_GetInterfaceList_args_in(PyObject *args, PyObject *kwargs, struct witness_GetInterfaceList *r)
393 {
394         const char *kwnames[] = {
395                 NULL
396         };
397
398         if (!PyArg_ParseTupleAndKeywords(args, kwargs, ":witness_GetInterfaceList", discard_const_p(char *, kwnames))) {
399                 return false;
400         }
401
402         return true;
403 }
404
405 static PyObject *unpack_py_witness_GetInterfaceList_args_out(struct witness_GetInterfaceList *r)
406 {
407         PyObject *result;
408         PyObject *py_interface_list;
409         if (*r->out.interface_list == NULL) {
410                 py_interface_list = Py_None;
411                 Py_INCREF(py_interface_list);
412         } else {
413                 py_interface_list = pytalloc_reference_ex(&witness_interfaceList_Type, *r->out.interface_list, *r->out.interface_list);
414         }
415         result = py_interface_list;
416         if (!W_ERROR_IS_OK(r->out.result)) {
417                 PyErr_SetWERROR(r->out.result);
418                 return NULL;
419         }
420
421         return result;
422 }
423
424 static bool pack_py_witness_Register_args_in(PyObject *args, PyObject *kwargs, struct witness_Register *r)
425 {
426         PyObject *py_version;
427         PyObject *py_net_name;
428         PyObject *py_ip_address;
429         PyObject *py_client_computer_name;
430         const char *kwnames[] = {
431                 "version", "net_name", "ip_address", "client_computer_name", NULL
432         };
433
434         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOO:witness_Register", discard_const_p(char *, kwnames), &py_version, &py_net_name, &py_ip_address, &py_client_computer_name)) {
435                 return false;
436         }
437
438         if (PyLong_Check(py_version)) {
439                 r->in.version = PyLong_AsLongLong(py_version);
440         } else if (PyInt_Check(py_version)) {
441                 r->in.version = PyInt_AsLong(py_version);
442         } else {
443                 PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
444                   PyInt_Type.tp_name, PyLong_Type.tp_name);
445                 return false;
446         }
447         if (py_net_name == Py_None) {
448                 r->in.net_name = NULL;
449         } else {
450                 r->in.net_name = NULL;
451                 if (PyUnicode_Check(py_net_name)) {
452                         r->in.net_name = PyString_AS_STRING(PyUnicode_AsEncodedString(py_net_name, "utf-8", "ignore"));
453                 } else if (PyString_Check(py_net_name)) {
454                         r->in.net_name = PyString_AS_STRING(py_net_name);
455                 } else {
456                         PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_net_name)->tp_name);
457                         return false;
458                 }
459         }
460         if (py_ip_address == Py_None) {
461                 r->in.ip_address = NULL;
462         } else {
463                 r->in.ip_address = NULL;
464                 if (PyUnicode_Check(py_ip_address)) {
465                         r->in.ip_address = PyString_AS_STRING(PyUnicode_AsEncodedString(py_ip_address, "utf-8", "ignore"));
466                 } else if (PyString_Check(py_ip_address)) {
467                         r->in.ip_address = PyString_AS_STRING(py_ip_address);
468                 } else {
469                         PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_ip_address)->tp_name);
470                         return false;
471                 }
472         }
473         if (py_client_computer_name == Py_None) {
474                 r->in.client_computer_name = NULL;
475         } else {
476                 r->in.client_computer_name = NULL;
477                 if (PyUnicode_Check(py_client_computer_name)) {
478                         r->in.client_computer_name = PyString_AS_STRING(PyUnicode_AsEncodedString(py_client_computer_name, "utf-8", "ignore"));
479                 } else if (PyString_Check(py_client_computer_name)) {
480                         r->in.client_computer_name = PyString_AS_STRING(py_client_computer_name);
481                 } else {
482                         PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_client_computer_name)->tp_name);
483                         return false;
484                 }
485         }
486         return true;
487 }
488
489 static PyObject *unpack_py_witness_Register_args_out(struct witness_Register *r)
490 {
491         PyObject *result;
492         PyObject *py_context_handle;
493         py_context_handle = pytalloc_reference_ex(policy_handle_Type, r->out.context_handle, r->out.context_handle);
494         result = py_context_handle;
495         if (!W_ERROR_IS_OK(r->out.result)) {
496                 PyErr_SetWERROR(r->out.result);
497                 return NULL;
498         }
499
500         return result;
501 }
502
503 static bool pack_py_witness_UnRegister_args_in(PyObject *args, PyObject *kwargs, struct witness_UnRegister *r)
504 {
505         PyObject *py_context_handle;
506         const char *kwnames[] = {
507                 "context_handle", NULL
508         };
509
510         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:witness_UnRegister", discard_const_p(char *, kwnames), &py_context_handle)) {
511                 return false;
512         }
513
514         PY_CHECK_TYPE(policy_handle_Type, py_context_handle, return false;);
515         if (talloc_reference(r, pytalloc_get_mem_ctx(py_context_handle)) == NULL) {
516                 PyErr_NoMemory();
517                 return false;
518         }
519         r->in.context_handle = *(struct policy_handle *)pytalloc_get_ptr(py_context_handle);
520         return true;
521 }
522
523 static PyObject *unpack_py_witness_UnRegister_args_out(struct witness_UnRegister *r)
524 {
525         PyObject *result;
526         result = Py_None;
527         Py_INCREF(result);
528         if (!W_ERROR_IS_OK(r->out.result)) {
529                 PyErr_SetWERROR(r->out.result);
530                 return NULL;
531         }
532
533         return result;
534 }
535
536 static bool pack_py_witness_AsyncNotify_args_in(PyObject *args, PyObject *kwargs, struct witness_AsyncNotify *r)
537 {
538         PyObject *py_context_handle;
539         const char *kwnames[] = {
540                 "context_handle", NULL
541         };
542
543         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:witness_AsyncNotify", discard_const_p(char *, kwnames), &py_context_handle)) {
544                 return false;
545         }
546
547         PY_CHECK_TYPE(policy_handle_Type, py_context_handle, return false;);
548         if (talloc_reference(r, pytalloc_get_mem_ctx(py_context_handle)) == NULL) {
549                 PyErr_NoMemory();
550                 return false;
551         }
552         r->in.context_handle = *(struct policy_handle *)pytalloc_get_ptr(py_context_handle);
553         return true;
554 }
555
556 static PyObject *unpack_py_witness_AsyncNotify_args_out(struct witness_AsyncNotify *r)
557 {
558         PyObject *result;
559         PyObject *py_response;
560         if (*r->out.response == NULL) {
561                 py_response = Py_None;
562                 Py_INCREF(py_response);
563         } else {
564                 py_response = pytalloc_reference_ex(&witness_notifyResponse_Type, *r->out.response, *r->out.response);
565         }
566         result = py_response;
567         if (!W_ERROR_IS_OK(r->out.result)) {
568                 PyErr_SetWERROR(r->out.result);
569                 return NULL;
570         }
571
572         return result;
573 }
574
575 static bool pack_py_witness_RegisterEx_args_in(PyObject *args, PyObject *kwargs, struct witness_RegisterEx *r)
576 {
577         PyObject *py_version;
578         PyObject *py_net_name;
579         PyObject *py_share_name;
580         PyObject *py_ip_address;
581         PyObject *py_client_computer_name;
582         PyObject *py_flags;
583         PyObject *py_timeout;
584         const char *kwnames[] = {
585                 "version", "net_name", "share_name", "ip_address", "client_computer_name", "flags", "timeout", NULL
586         };
587
588         if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOOOOO:witness_RegisterEx", discard_const_p(char *, kwnames), &py_version, &py_net_name, &py_share_name, &py_ip_address, &py_client_computer_name, &py_flags, &py_timeout)) {
589                 return false;
590         }
591
592         if (PyLong_Check(py_version)) {
593                 r->in.version = PyLong_AsLongLong(py_version);
594         } else if (PyInt_Check(py_version)) {
595                 r->in.version = PyInt_AsLong(py_version);
596         } else {
597                 PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
598                   PyInt_Type.tp_name, PyLong_Type.tp_name);
599                 return false;
600         }
601         if (py_net_name == Py_None) {
602                 r->in.net_name = NULL;
603         } else {
604                 r->in.net_name = NULL;
605                 if (PyUnicode_Check(py_net_name)) {
606                         r->in.net_name = PyString_AS_STRING(PyUnicode_AsEncodedString(py_net_name, "utf-8", "ignore"));
607                 } else if (PyString_Check(py_net_name)) {
608                         r->in.net_name = PyString_AS_STRING(py_net_name);
609                 } else {
610                         PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_net_name)->tp_name);
611                         return false;
612                 }
613         }
614         if (py_share_name == Py_None) {
615                 r->in.share_name = NULL;
616         } else {
617                 r->in.share_name = NULL;
618                 if (PyUnicode_Check(py_share_name)) {
619                         r->in.share_name = PyString_AS_STRING(PyUnicode_AsEncodedString(py_share_name, "utf-8", "ignore"));
620                 } else if (PyString_Check(py_share_name)) {
621                         r->in.share_name = PyString_AS_STRING(py_share_name);
622                 } else {
623                         PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_share_name)->tp_name);
624                         return false;
625                 }
626         }
627         if (py_ip_address == Py_None) {
628                 r->in.ip_address = NULL;
629         } else {
630                 r->in.ip_address = NULL;
631                 if (PyUnicode_Check(py_ip_address)) {
632                         r->in.ip_address = PyString_AS_STRING(PyUnicode_AsEncodedString(py_ip_address, "utf-8", "ignore"));
633                 } else if (PyString_Check(py_ip_address)) {
634                         r->in.ip_address = PyString_AS_STRING(py_ip_address);
635                 } else {
636                         PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_ip_address)->tp_name);
637                         return false;
638                 }
639         }
640         if (py_client_computer_name == Py_None) {
641                 r->in.client_computer_name = NULL;
642         } else {
643                 r->in.client_computer_name = NULL;
644                 if (PyUnicode_Check(py_client_computer_name)) {
645                         r->in.client_computer_name = PyString_AS_STRING(PyUnicode_AsEncodedString(py_client_computer_name, "utf-8", "ignore"));
646                 } else if (PyString_Check(py_client_computer_name)) {
647                         r->in.client_computer_name = PyString_AS_STRING(py_client_computer_name);
648                 } else {
649                         PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(py_client_computer_name)->tp_name);
650                         return false;
651                 }
652         }
653         if (PyLong_Check(py_flags)) {
654                 r->in.flags = PyLong_AsLongLong(py_flags);
655         } else if (PyInt_Check(py_flags)) {
656                 r->in.flags = PyInt_AsLong(py_flags);
657         } else {
658                 PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
659                   PyInt_Type.tp_name, PyLong_Type.tp_name);
660                 return false;
661         }
662         PY_CHECK_TYPE(&PyInt_Type, py_timeout, return false;);
663         r->in.timeout = PyInt_AsLong(py_timeout);
664         return true;
665 }
666
667 static PyObject *unpack_py_witness_RegisterEx_args_out(struct witness_RegisterEx *r)
668 {
669         PyObject *result;
670         PyObject *py_context_handle;
671         py_context_handle = pytalloc_reference_ex(policy_handle_Type, r->out.context_handle, r->out.context_handle);
672         result = py_context_handle;
673         if (!W_ERROR_IS_OK(r->out.result)) {
674                 PyErr_SetWERROR(r->out.result);
675                 return NULL;
676         }
677
678         return result;
679 }
680
681 const struct PyNdrRpcMethodDef py_ndr_witness_methods[] = {
682         { "GetInterfaceList", "S.GetInterfaceList() -> interface_list", (py_dcerpc_call_fn)dcerpc_witness_GetInterfaceList_r, (py_data_pack_fn)pack_py_witness_GetInterfaceList_args_in, (py_data_unpack_fn)unpack_py_witness_GetInterfaceList_args_out, 0, &ndr_table_witness },
683         { "Register", "S.Register(version, net_name, ip_address, client_computer_name) -> context_handle", (py_dcerpc_call_fn)dcerpc_witness_Register_r, (py_data_pack_fn)pack_py_witness_Register_args_in, (py_data_unpack_fn)unpack_py_witness_Register_args_out, 1, &ndr_table_witness },
684         { "UnRegister", "S.UnRegister(context_handle) -> None", (py_dcerpc_call_fn)dcerpc_witness_UnRegister_r, (py_data_pack_fn)pack_py_witness_UnRegister_args_in, (py_data_unpack_fn)unpack_py_witness_UnRegister_args_out, 2, &ndr_table_witness },
685         { "AsyncNotify", "S.AsyncNotify(context_handle) -> response", (py_dcerpc_call_fn)dcerpc_witness_AsyncNotify_r, (py_data_pack_fn)pack_py_witness_AsyncNotify_args_in, (py_data_unpack_fn)unpack_py_witness_AsyncNotify_args_out, 3, &ndr_table_witness },
686         { "RegisterEx", "S.RegisterEx(version, net_name, share_name, ip_address, client_computer_name, flags, timeout) -> context_handle", (py_dcerpc_call_fn)dcerpc_witness_RegisterEx_r, (py_data_pack_fn)pack_py_witness_RegisterEx_args_in, (py_data_unpack_fn)unpack_py_witness_RegisterEx_args_out, 4, &ndr_table_witness },
687         { NULL }
688 };
689
690 static PyObject *interface_witness_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
691 {
692         return py_dcerpc_interface_init_helper(type, args, kwargs, &ndr_table_witness);
693 }
694
695 #define PY_DOC_WITNESS "SMB Witness Service"
696 static PyTypeObject witness_InterfaceType = {
697         PyObject_HEAD_INIT(NULL) 0,
698         .tp_name = "witness.witness",
699         .tp_basicsize = sizeof(dcerpc_InterfaceObject),
700         .tp_doc = "witness(binding, lp_ctx=None, credentials=None) -> connection\n"
701 "\n"
702 "binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\n"
703 "lp_ctx should be a path to a smb.conf file or a param.LoadParm object\n"
704 "credentials should be a credentials.Credentials object.\n\n"PY_DOC_WITNESS,
705         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
706         .tp_new = interface_witness_new,
707 };
708
709 static PyObject *syntax_witness_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
710 {
711         return py_dcerpc_syntax_init_helper(type, args, kwargs, &ndr_table_witness.syntax_id);
712 }
713
714 #define PY_DOC_WITNESS_SYNTAX "SMB Witness Service"
715 static PyTypeObject witness_SyntaxType = {
716         PyObject_HEAD_INIT(NULL) 0,
717         .tp_name = "witness.witness",
718         .tp_basicsize = sizeof(pytalloc_Object),
719         .tp_doc = "abstract_syntax()\n"PY_DOC_WITNESS_SYNTAX,
720         .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
721         .tp_new = syntax_witness_new,
722 };
723
724 static PyMethodDef witness_methods[] = {
725         { NULL, NULL, 0, NULL }
726 };
727
728 void initwitness(void)
729 {
730         PyObject *m;
731         PyObject *dep_samba_dcerpc_misc;
732         PyObject *dep_talloc;
733         PyObject *dep_samba_dcerpc_base;
734
735         dep_samba_dcerpc_misc = PyImport_ImportModule("samba.dcerpc.misc");
736         if (dep_samba_dcerpc_misc == NULL)
737                 return;
738
739         dep_talloc = PyImport_ImportModule("talloc");
740         if (dep_talloc == NULL)
741                 return;
742
743         dep_samba_dcerpc_base = PyImport_ImportModule("samba.dcerpc.base");
744         if (dep_samba_dcerpc_base == NULL)
745                 return;
746
747         Object_Type = (PyTypeObject *)PyObject_GetAttrString(dep_talloc, "Object");
748         if (Object_Type == NULL)
749                 return;
750
751         policy_handle_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_misc, "policy_handle");
752         if (policy_handle_Type == NULL)
753                 return;
754
755         ClientConnection_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_base, "ClientConnection");
756         if (ClientConnection_Type == NULL)
757                 return;
758
759         ndr_syntax_id_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_misc, "ndr_syntax_id");
760         if (ndr_syntax_id_Type == NULL)
761                 return;
762
763         witness_interfaceInfo_Type.tp_base = Object_Type;
764
765         witness_interfaceList_Type.tp_base = Object_Type;
766
767         witness_notifyResponse_Type.tp_base = Object_Type;
768
769         witness_InterfaceType.tp_base = ClientConnection_Type;
770
771         witness_SyntaxType.tp_base = ndr_syntax_id_Type;
772
773         if (PyType_Ready(&witness_interfaceInfo_Type) < 0)
774                 return;
775         if (PyType_Ready(&witness_interfaceList_Type) < 0)
776                 return;
777         if (PyType_Ready(&witness_notifyResponse_Type) < 0)
778                 return;
779         if (PyType_Ready(&witness_InterfaceType) < 0)
780                 return;
781         if (PyType_Ready(&witness_SyntaxType) < 0)
782                 return;
783         if (!PyInterface_AddNdrRpcMethods(&witness_InterfaceType, py_ndr_witness_methods))
784                 return;
785
786 #ifdef PY_INTERFACEINFO_PATCH
787         PY_INTERFACEINFO_PATCH(&witness_interfaceInfo_Type);
788 #endif
789 #ifdef PY_INTERFACELIST_PATCH
790         PY_INTERFACELIST_PATCH(&witness_interfaceList_Type);
791 #endif
792 #ifdef PY_NOTIFYRESPONSE_PATCH
793         PY_NOTIFYRESPONSE_PATCH(&witness_notifyResponse_Type);
794 #endif
795 #ifdef PY_WITNESS_PATCH
796         PY_WITNESS_PATCH(&witness_InterfaceType);
797 #endif
798 #ifdef PY_ABSTRACT_SYNTAX_PATCH
799         PY_ABSTRACT_SYNTAX_PATCH(&witness_SyntaxType);
800 #endif
801
802         m = Py_InitModule3("witness", witness_methods, "witness DCE/RPC");
803         if (m == NULL)
804                 return;
805
806         PyModule_AddObject(m, "WITNESS_V1", PyInt_FromLong(WITNESS_V1));
807         PyModule_AddObject(m, "WITNESS_V2", PyInt_FromLong(WITNESS_V2));
808         PyModule_AddObject(m, "WITNESS_STATE_UNKNOWN", PyInt_FromLong(WITNESS_STATE_UNKNOWN));
809         PyModule_AddObject(m, "WITNESS_STATE_AVAILABLE", PyInt_FromLong(WITNESS_STATE_AVAILABLE));
810         PyModule_AddObject(m, "WITNESS_STATE_UNAVAILABLE", PyInt_FromLong(WITNESS_STATE_UNAVAILABLE));
811         PyModule_AddObject(m, "WITNESS_INFO_IPv4_VALID", PyInt_FromLong(WITNESS_INFO_IPv4_VALID));
812         PyModule_AddObject(m, "WITNESS_INFO_IPv6_VALID", PyInt_FromLong(WITNESS_INFO_IPv6_VALID));
813         PyModule_AddObject(m, "WITNESS_INFO_WITNESS_IF", PyInt_FromLong(WITNESS_INFO_WITNESS_IF));
814         PyModule_AddObject(m, "WITNESS_NOTIFY_RESOURCE_CHANGE", PyInt_FromLong(WITNESS_NOTIFY_RESOURCE_CHANGE));
815         PyModule_AddObject(m, "WITNESS_NOTIFY_CLIENT_MOVE", PyInt_FromLong(WITNESS_NOTIFY_CLIENT_MOVE));
816         PyModule_AddObject(m, "WITNESS_NOTIFY_SHARE_MOVE", PyInt_FromLong(WITNESS_NOTIFY_SHARE_MOVE));
817         PyModule_AddObject(m, "WITNESS_NOTIFY_IP_CHANGE", PyInt_FromLong(WITNESS_NOTIFY_IP_CHANGE));
818         PyModule_AddObject(m, "WITNESS_REGISTER_NONE", PyInt_FromLong(WITNESS_REGISTER_NONE));
819         PyModule_AddObject(m, "WITNESS_REGISTER_IP_NOTIFICATION", PyInt_FromLong(WITNESS_REGISTER_IP_NOTIFICATION));
820         Py_INCREF((PyObject *)(void *)&witness_interfaceInfo_Type);
821         PyModule_AddObject(m, "interfaceInfo", (PyObject *)(void *)&witness_interfaceInfo_Type);
822         Py_INCREF((PyObject *)(void *)&witness_interfaceList_Type);
823         PyModule_AddObject(m, "interfaceList", (PyObject *)(void *)&witness_interfaceList_Type);
824         Py_INCREF((PyObject *)(void *)&witness_notifyResponse_Type);
825         PyModule_AddObject(m, "notifyResponse", (PyObject *)(void *)&witness_notifyResponse_Type);
826         Py_INCREF((PyObject *)(void *)&witness_InterfaceType);
827         PyModule_AddObject(m, "witness", (PyObject *)(void *)&witness_InterfaceType);
828         Py_INCREF((PyObject *)(void *)&witness_SyntaxType);
829         PyModule_AddObject(m, "abstract_syntax", (PyObject *)(void *)&witness_SyntaxType);
830 #ifdef PY_MOD_WITNESS_PATCH
831         PY_MOD_WITNESS_PATCH(m);
832 #endif
833
834 }