Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : Samba utility functions
4 : Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
5 :
6 : This program is free software; you can redistribute it and/or modify
7 : it under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3 of the License, or
9 : (at your option) any later version.
10 :
11 : This program is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : GNU General Public License for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with this program. If not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #include "lib/replace/system/python.h"
21 : #include "python/py3compat.h"
22 : #include "includes.h"
23 : #include "python/modules.h"
24 : #include <structmember.h>
25 : #include "librpc/rpc/pyrpc.h"
26 : #include "lib/events/events.h"
27 : #include "param/pyparam.h"
28 : #include "librpc/rpc/dcerpc.h"
29 : #include "librpc/rpc/pyrpc_util.h"
30 : #include "auth/credentials/pycredentials.h"
31 : #include "auth/gensec/gensec.h"
32 :
33 : void initbase(void);
34 :
35 : static PyTypeObject dcerpc_InterfaceType;
36 :
37 : static PyTypeObject *BaseObject_Type;
38 :
39 : static PyTypeObject *ndr_syntax_id_Type;
40 :
41 6 : static bool PyString_AsGUID(PyObject *object, struct GUID *uuid)
42 : {
43 0 : NTSTATUS status;
44 6 : status = GUID_from_string(PyUnicode_AsUTF8(object), uuid);
45 6 : if (NT_STATUS_IS_ERR(status)) {
46 0 : PyErr_SetNTSTATUS(status);
47 0 : return false;
48 : }
49 6 : return true;
50 : }
51 :
52 6 : static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *syntax_id)
53 : {
54 6 : ZERO_STRUCTP(syntax_id);
55 :
56 6 : if (PyUnicode_Check(object)) {
57 0 : return PyString_AsGUID(object, &syntax_id->uuid);
58 : }
59 :
60 6 : if (PyTuple_Check(object)) {
61 6 : PyObject *item = NULL;
62 6 : if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) {
63 0 : PyErr_SetString(PyExc_ValueError, "Syntax ID tuple has invalid size");
64 0 : return false;
65 : }
66 :
67 6 : item = PyTuple_GetItem(object, 0);
68 6 : if (!PyUnicode_Check(item)) {
69 0 : PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple");
70 0 : return false;
71 : }
72 :
73 6 : if (!PyString_AsGUID(item, &syntax_id->uuid)) {
74 0 : return false;
75 : }
76 :
77 6 : item = PyTuple_GetItem(object, 1);
78 6 : if (!PyLong_Check(item)) {
79 0 : PyErr_SetString(PyExc_ValueError, "Expected version as second element in tuple");
80 0 : return false;
81 : }
82 :
83 6 : syntax_id->if_version = PyLong_AsLong(item);
84 6 : return true;
85 : }
86 :
87 0 : PyErr_SetString(PyExc_TypeError, "Expected UUID or syntax id tuple");
88 0 : return false;
89 : }
90 :
91 1 : static PyObject *py_iface_server_name(PyObject *obj, void *closure)
92 : {
93 0 : const char *server_name;
94 1 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
95 :
96 1 : server_name = dcerpc_server_name(iface->pipe);
97 1 : if (server_name == NULL)
98 1 : Py_RETURN_NONE;
99 :
100 0 : return PyUnicode_FromString(server_name);
101 : }
102 :
103 1 : static PyObject *py_ndr_syntax_id(struct ndr_syntax_id *syntax_id)
104 : {
105 0 : PyObject *ret;
106 0 : struct GUID_txt_buf buf;
107 :
108 1 : ret = Py_BuildValue(
109 : "(s,i)",
110 1 : GUID_buf_string(&syntax_id->uuid, &buf),
111 : syntax_id->if_version);
112 :
113 1 : return ret;
114 : }
115 :
116 1 : static PyObject *py_iface_abstract_syntax(PyObject *obj, void *closure)
117 : {
118 1 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
119 :
120 1 : return py_ndr_syntax_id(&iface->pipe->syntax);
121 : }
122 :
123 0 : static PyObject *py_iface_transfer_syntax(PyObject *obj, void *closure)
124 : {
125 0 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
126 :
127 0 : return py_ndr_syntax_id(&iface->pipe->transfer_syntax);
128 : }
129 :
130 29 : static PyObject *py_iface_session_key(PyObject *obj, void *closure)
131 : {
132 29 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
133 0 : DATA_BLOB session_key;
134 :
135 29 : NTSTATUS status = dcerpc_fetch_session_key(iface->pipe, &session_key);
136 29 : PyErr_NTSTATUS_IS_ERR_RAISE(status);
137 :
138 29 : return PyBytes_FromStringAndSize((const char *)session_key.data, session_key.length);
139 : }
140 :
141 0 : static PyObject *py_iface_user_session_key(PyObject *obj, void *closure)
142 : {
143 0 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
144 0 : TALLOC_CTX *mem_ctx;
145 0 : NTSTATUS status;
146 0 : struct gensec_security *security = NULL;
147 0 : DATA_BLOB session_key = data_blob_null;
148 0 : static PyObject *session_key_obj = NULL;
149 :
150 0 : if (iface->pipe == NULL) {
151 0 : PyErr_SetNTSTATUS(NT_STATUS_NO_USER_SESSION_KEY);
152 0 : return NULL;
153 : }
154 :
155 0 : if (iface->pipe->conn == NULL) {
156 0 : PyErr_SetNTSTATUS(NT_STATUS_NO_USER_SESSION_KEY);
157 0 : return NULL;
158 : }
159 :
160 0 : if (iface->pipe->conn->security_state.generic_state == NULL) {
161 0 : PyErr_SetNTSTATUS(NT_STATUS_NO_USER_SESSION_KEY);
162 0 : return NULL;
163 : }
164 :
165 0 : security = iface->pipe->conn->security_state.generic_state;
166 :
167 0 : mem_ctx = talloc_new(NULL);
168 :
169 0 : status = gensec_session_key(security, mem_ctx, &session_key);
170 0 : if (!NT_STATUS_IS_OK(status)) {
171 0 : talloc_free(mem_ctx);
172 0 : PyErr_SetNTSTATUS(status);
173 0 : return NULL;
174 : }
175 :
176 0 : session_key_obj = PyBytes_FromStringAndSize((const char *)session_key.data,
177 0 : session_key.length);
178 0 : talloc_free(mem_ctx);
179 0 : return session_key_obj;
180 : }
181 :
182 0 : static PyObject *py_iface_get_timeout(PyObject *obj, void *closure)
183 : {
184 0 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
185 0 : uint32_t timeout;
186 :
187 0 : timeout = dcerpc_binding_handle_set_timeout(iface->binding_handle, 0);
188 0 : dcerpc_binding_handle_set_timeout(iface->binding_handle, timeout);
189 :
190 0 : return PyLong_FromUnsignedLong(timeout);
191 : }
192 :
193 951 : static int py_iface_set_timeout(PyObject *obj, PyObject *value, void *closure)
194 : {
195 951 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
196 0 : uint32_t timeout;
197 :
198 951 : timeout = PyLong_AsUnsignedLong(value);
199 951 : if (PyErr_Occurred() != NULL) {
200 0 : return -1;
201 : }
202 :
203 951 : dcerpc_binding_handle_set_timeout(iface->binding_handle, timeout);
204 951 : return 0;
205 : }
206 :
207 : static PyGetSetDef dcerpc_interface_getsetters[] = {
208 : {
209 : .name = discard_const_p(char, "server_name"),
210 : .get = py_iface_server_name,
211 : .doc = discard_const_p(char, "name of the server, if connected over SMB"),
212 : },
213 : {
214 : .name = discard_const_p(char, "abstract_syntax"),
215 : .get = py_iface_abstract_syntax,
216 : .doc = discard_const_p(char, "syntax id of the abstract syntax"),
217 : },
218 : {
219 : .name = discard_const_p(char, "transfer_syntax"),
220 : .get = py_iface_transfer_syntax,
221 : .doc = discard_const_p(char, "syntax id of the transfer syntax"),
222 : },
223 : {
224 : .name = discard_const_p(char, "session_key"),
225 : .get = py_iface_session_key,
226 : .doc = discard_const_p(char, "session key (as used for blob encryption on LSA and SAMR)"),
227 : },
228 : {
229 : .name = discard_const_p(char, "user_session_key"),
230 : .get = py_iface_user_session_key,
231 : .doc = discard_const_p(char, "user_session key (as used for blob encryption on DRSUAPI)"),
232 : },
233 : {
234 : .name = discard_const_p(char, "request_timeout"),
235 : .get = py_iface_get_timeout,
236 : .set = py_iface_set_timeout,
237 : .doc = discard_const_p(char, "request timeout, in seconds"),
238 : },
239 : { .name = NULL }
240 : };
241 :
242 7 : static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwargs)
243 : {
244 7 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;
245 0 : int opnum;
246 0 : DATA_BLOB data_in, data_out;
247 0 : NTSTATUS status;
248 0 : char *in_data;
249 0 : Py_ssize_t in_length;
250 0 : PyObject *ret;
251 7 : PyObject *object = NULL;
252 0 : struct GUID object_guid;
253 7 : TALLOC_CTX *mem_ctx = talloc_new(NULL);
254 7 : uint32_t out_flags = 0;
255 7 : const char *kwnames[] = { "opnum", "data", "object", NULL };
256 :
257 7 : if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#|O:request",
258 : discard_const_p(char *, kwnames), &opnum, &in_data, &in_length, &object)) {
259 0 : talloc_free(mem_ctx);
260 0 : return NULL;
261 : }
262 :
263 7 : data_in.data = (uint8_t *)talloc_memdup(mem_ctx, in_data, in_length);
264 7 : data_in.length = in_length;
265 :
266 7 : ZERO_STRUCT(data_out);
267 :
268 7 : if (object != NULL && !PyString_AsGUID(object, &object_guid)) {
269 0 : talloc_free(mem_ctx);
270 0 : return NULL;
271 : }
272 :
273 7 : status = dcerpc_binding_handle_raw_call(iface->binding_handle,
274 7 : object?&object_guid:NULL,
275 : opnum,
276 : 0, /* in_flags */
277 7 : data_in.data,
278 : data_in.length,
279 : mem_ctx,
280 : &data_out.data,
281 : &data_out.length,
282 : &out_flags);
283 7 : if (!NT_STATUS_IS_OK(status)) {
284 0 : PyErr_SetDCERPCStatus(iface->pipe, status);
285 0 : talloc_free(mem_ctx);
286 0 : return NULL;
287 : }
288 :
289 7 : ret = PyBytes_FromStringAndSize((char *)data_out.data, data_out.length);
290 :
291 7 : talloc_free(mem_ctx);
292 7 : return ret;
293 : }
294 :
295 8 : static PyObject *py_iface_transport_encrypted(PyObject *self)
296 : {
297 8 : dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;
298 :
299 8 : if (dcerpc_transport_encrypted(iface->pipe)) {
300 4 : Py_RETURN_TRUE;
301 : }
302 :
303 4 : Py_RETURN_FALSE;
304 : }
305 :
306 : static PyMethodDef dcerpc_interface_methods[] = {
307 : { "request", PY_DISCARD_FUNC_SIG(PyCFunction, py_iface_request),
308 : METH_VARARGS|METH_KEYWORDS,
309 : "S.request(opnum, data, object=None) -> data\n"
310 : "Make a raw request" },
311 : { "transport_encrypted", PY_DISCARD_FUNC_SIG(PyCFunction, py_iface_transport_encrypted),
312 : METH_NOARGS,
313 : "Check if the DCE transport is encrypted" },
314 : { NULL, NULL, 0, NULL },
315 : };
316 :
317 4555 : static void dcerpc_interface_dealloc(PyObject* self)
318 : {
319 4555 : dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self;
320 :
321 4559 : struct tevent_context *ev_save = talloc_reparent(
322 4555 : interface->mem_ctx, NULL, interface->ev);
323 4555 : SMB_ASSERT(ev_save != NULL);
324 :
325 4555 : interface->binding_handle = NULL;
326 4555 : interface->pipe = NULL;
327 :
328 : /*
329 : * Free everything *except* the event context, which must go
330 : * away last
331 : */
332 4555 : TALLOC_FREE(interface->mem_ctx);
333 :
334 : /*
335 : * Now wish a fond goodbye to the event context itself
336 : */
337 4555 : talloc_unlink(NULL, ev_save);
338 4555 : self->ob_type->tp_free(self);
339 4555 : }
340 :
341 6 : static PyObject *dcerpc_interface_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
342 : {
343 0 : PyObject *ret;
344 6 : const char *binding_string = NULL;
345 6 : PyObject *py_lp_ctx = Py_None;
346 6 : PyObject *py_credentials = Py_None;
347 6 : PyObject *syntax = Py_None;
348 6 : PyObject *py_basis = Py_None;
349 6 : const char *kwnames[] = {
350 : "binding", "syntax", "lp_ctx", "credentials", "basis_connection", NULL
351 : };
352 0 : static struct ndr_interface_table dummy_table;
353 0 : static struct ndr_interface_string_array dummy_endpoints;
354 6 : PyObject *args2 = Py_None;
355 6 : PyObject *kwargs2 = Py_None;
356 :
357 6 : if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OOO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials, &py_basis)) {
358 0 : return NULL;
359 : }
360 :
361 6 : if (strncmp(binding_string, "irpc:", 5) == 0) {
362 0 : PyErr_SetString(PyExc_ValueError, "irpc: transport not supported");
363 0 : return NULL;
364 : }
365 :
366 : /*
367 : * Fill a dummy interface table struct. TODO: In the future, we should
368 : * rather just allow connecting without requiring an interface table.
369 : *
370 : * We just fill the syntax during the connect, but keep the memory valid
371 : * the whole time.
372 : */
373 6 : if (!ndr_syntax_from_py_object(syntax, &dummy_table.syntax_id)) {
374 0 : return NULL;
375 : }
376 :
377 : /*
378 : * Initialise the endpoints list in dummy_table if required
379 : */
380 6 : if (dummy_table.endpoints == NULL) {
381 1 : dummy_table.endpoints = &dummy_endpoints;
382 : }
383 :
384 6 : args2 = Py_BuildValue("(s)", binding_string);
385 6 : if (args2 == NULL) {
386 0 : return NULL;
387 : }
388 :
389 6 : kwargs2 = Py_BuildValue("{s:O,s:O,s:O}",
390 : "lp_ctx", py_lp_ctx,
391 : "credentials", py_credentials,
392 : "basis_connection", py_basis);
393 6 : if (kwargs2 == NULL) {
394 0 : Py_DECREF(args2);
395 0 : return NULL;
396 : }
397 :
398 6 : ret = py_dcerpc_interface_init_helper(type, args2, kwargs2, &dummy_table);
399 6 : ZERO_STRUCT(dummy_table.syntax_id);
400 6 : Py_DECREF(args2);
401 6 : Py_DECREF(kwargs2);
402 6 : return ret;
403 : }
404 :
405 : static PyTypeObject dcerpc_InterfaceType = {
406 : PyVarObject_HEAD_INIT(NULL, 0)
407 : .tp_name = "dcerpc.ClientConnection",
408 : .tp_basicsize = sizeof(dcerpc_InterfaceObject),
409 : .tp_dealloc = dcerpc_interface_dealloc,
410 : .tp_getset = dcerpc_interface_getsetters,
411 : .tp_methods = dcerpc_interface_methods,
412 : .tp_doc = "ClientConnection(binding, syntax, lp_ctx=None, credentials=None) -> connection\n"
413 : "\n"
414 : "binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\n"
415 : "syntax should be a tuple with a GUID and version number of an interface\n"
416 : "lp_ctx should be a path to a smb.conf file or a param.LoadParm object\n"
417 : "credentials should be a credentials.Credentials object.\n\n",
418 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
419 : .tp_new = dcerpc_interface_new,
420 : };
421 :
422 600 : static PyObject *py_transfer_syntax_ndr_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
423 : {
424 600 : return py_dcerpc_syntax_init_helper(type, args, kwargs, &ndr_transfer_syntax_ndr);
425 : }
426 :
427 : static PyTypeObject py_transfer_syntax_ndr_SyntaxType = {
428 : PyVarObject_HEAD_INIT(NULL, 0)
429 : .tp_name = "base.transfer_syntax_ndr",
430 : .tp_doc = "transfer_syntax_ndr()\n",
431 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
432 : .tp_new = py_transfer_syntax_ndr_new,
433 : };
434 :
435 30 : static PyObject *py_transfer_syntax_ndr64_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
436 : {
437 30 : return py_dcerpc_syntax_init_helper(type, args, kwargs, &ndr_transfer_syntax_ndr64);
438 : }
439 :
440 : static PyTypeObject py_transfer_syntax_ndr64_SyntaxType = {
441 : PyVarObject_HEAD_INIT(NULL, 0)
442 : .tp_name = "base.transfer_syntax_ndr64",
443 : .tp_doc = "transfer_syntax_ndr64()\n",
444 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
445 : .tp_new = py_transfer_syntax_ndr64_new,
446 : };
447 :
448 36 : static PyObject *py_bind_time_features_syntax_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
449 : {
450 36 : const char *kwnames[] = {
451 : "features", NULL
452 : };
453 36 : unsigned long long features = 0;
454 0 : struct ndr_syntax_id syntax;
455 36 : PyObject *args2 = Py_None;
456 36 : PyObject *kwargs2 = Py_None;
457 :
458 36 : if (!PyArg_ParseTupleAndKeywords(args, kwargs, "K:features", discard_const_p(char *, kwnames), &features)) {
459 0 : return NULL;
460 : }
461 :
462 36 : args2 = Py_BuildValue("()");
463 36 : if (args2 == NULL) {
464 0 : return NULL;
465 : }
466 :
467 36 : kwargs2 = Py_BuildValue("{}");
468 36 : if (kwargs2 == NULL) {
469 0 : Py_DECREF(args2);
470 0 : return NULL;
471 : }
472 :
473 36 : syntax = dcerpc_construct_bind_time_features(features);
474 :
475 36 : return py_dcerpc_syntax_init_helper(type, args2, kwargs2, &syntax);
476 : }
477 :
478 : static PyTypeObject py_bind_time_features_syntax_SyntaxType = {
479 : PyVarObject_HEAD_INIT(NULL, 0)
480 : .tp_name = "base.bind_time_features_syntax",
481 : .tp_doc = "bind_time_features_syntax(features)\n",
482 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
483 : .tp_new = py_bind_time_features_syntax_new,
484 : };
485 :
486 : struct py_dcerpc_ndr_pointer {
487 : PyObject *value;
488 : };
489 :
490 336 : static void py_dcerpc_ndr_pointer_dealloc(PyObject* self)
491 : {
492 0 : struct py_dcerpc_ndr_pointer *obj =
493 336 : pytalloc_get_type(self, struct py_dcerpc_ndr_pointer);
494 :
495 336 : Py_CLEAR(obj->value);
496 :
497 336 : self->ob_type->tp_free(self);
498 336 : }
499 :
500 324 : static PyObject *py_dcerpc_ndr_pointer_get_value(PyObject *self, void *closure)
501 : {
502 0 : struct py_dcerpc_ndr_pointer *obj =
503 324 : pytalloc_get_type(self, struct py_dcerpc_ndr_pointer);
504 :
505 324 : Py_INCREF(obj->value);
506 324 : return obj->value;
507 : }
508 :
509 0 : static int py_dcerpc_ndr_pointer_set_value(PyObject *self, PyObject *value, void *closure)
510 : {
511 0 : struct py_dcerpc_ndr_pointer *obj =
512 0 : pytalloc_get_type(self, struct py_dcerpc_ndr_pointer);
513 :
514 0 : Py_CLEAR(obj->value);
515 0 : obj->value = value;
516 0 : Py_INCREF(obj->value);
517 0 : return 0;
518 : }
519 :
520 : static PyGetSetDef py_dcerpc_ndr_pointer_getsetters[] = {
521 : {
522 : .name = discard_const_p(char, "value"),
523 : .get = py_dcerpc_ndr_pointer_get_value,
524 : .set = py_dcerpc_ndr_pointer_set_value,
525 : .doc = discard_const_p(char, "the value store by the pointer"),
526 : },
527 : {
528 : .name = NULL,
529 : },
530 : };
531 :
532 336 : static PyObject *py_dcerpc_ndr_pointer_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
533 : {
534 336 : PyObject *ret = NULL;
535 336 : struct py_dcerpc_ndr_pointer *obj = NULL;
536 336 : const char *kwnames[] = { "value", NULL };
537 336 : PyObject *value = NULL;
538 0 : bool ok;
539 :
540 336 : ok = PyArg_ParseTupleAndKeywords(args, kwargs, "O:value",
541 : discard_const_p(char *, kwnames),
542 : &value);
543 336 : if (!ok) {
544 0 : return NULL;
545 : }
546 :
547 336 : ret = pytalloc_new(struct py_dcerpc_ndr_pointer, type);
548 336 : if (ret == NULL) {
549 0 : return NULL;
550 : }
551 :
552 336 : obj = pytalloc_get_type(ret, struct py_dcerpc_ndr_pointer);
553 336 : *obj = (struct py_dcerpc_ndr_pointer) {
554 : .value = value,
555 : };
556 :
557 336 : Py_INCREF(obj->value);
558 336 : return ret;
559 : }
560 :
561 : static PyTypeObject py_dcerpc_ndr_pointer_type = {
562 : PyVarObject_HEAD_INIT(NULL, 0)
563 : .tp_name = "base.ndr_pointer",
564 : .tp_dealloc = py_dcerpc_ndr_pointer_dealloc,
565 : .tp_getset = py_dcerpc_ndr_pointer_getsetters,
566 : .tp_doc = "ndr_pointer(value)\n",
567 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
568 : .tp_new = py_dcerpc_ndr_pointer_new,
569 : };
570 :
571 : static struct PyModuleDef moduledef = {
572 : PyModuleDef_HEAD_INIT,
573 : .m_name = "base",
574 : .m_doc = "DCE/RPC protocol implementation",
575 : .m_size = -1,
576 : };
577 :
578 7670 : MODULE_INIT_FUNC(base)
579 : {
580 194 : PyObject *m;
581 194 : PyObject *dep_talloc;
582 194 : PyObject *dep_samba_dcerpc_misc;
583 :
584 7670 : dep_talloc = PyImport_ImportModule("talloc");
585 7670 : if (dep_talloc == NULL)
586 0 : return NULL;
587 :
588 7670 : BaseObject_Type = (PyTypeObject *)PyObject_GetAttrString(dep_talloc, "BaseObject");
589 7670 : if (BaseObject_Type == NULL) {
590 0 : Py_CLEAR(dep_talloc);
591 0 : return NULL;
592 : }
593 :
594 7670 : Py_CLEAR(dep_talloc);
595 7670 : dep_samba_dcerpc_misc = PyImport_ImportModule("samba.dcerpc.misc");
596 7670 : if (dep_samba_dcerpc_misc == NULL) {
597 0 : return NULL;
598 : }
599 :
600 7670 : ndr_syntax_id_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_misc, "ndr_syntax_id");
601 7670 : Py_CLEAR(dep_samba_dcerpc_misc);
602 7670 : if (ndr_syntax_id_Type == NULL) {
603 0 : return NULL;
604 : }
605 :
606 7670 : py_transfer_syntax_ndr_SyntaxType.tp_base = ndr_syntax_id_Type;
607 7670 : py_transfer_syntax_ndr_SyntaxType.tp_basicsize = pytalloc_BaseObject_size();
608 7670 : py_transfer_syntax_ndr64_SyntaxType.tp_base = ndr_syntax_id_Type;
609 7670 : py_transfer_syntax_ndr64_SyntaxType.tp_basicsize = pytalloc_BaseObject_size();
610 7670 : py_bind_time_features_syntax_SyntaxType.tp_base = ndr_syntax_id_Type;
611 7670 : py_bind_time_features_syntax_SyntaxType.tp_basicsize = pytalloc_BaseObject_size();
612 :
613 7670 : py_dcerpc_ndr_pointer_type.tp_base = BaseObject_Type;
614 7670 : py_dcerpc_ndr_pointer_type.tp_basicsize = pytalloc_BaseObject_size();
615 :
616 7670 : if (PyType_Ready(&dcerpc_InterfaceType) < 0) {
617 0 : return NULL;
618 : }
619 :
620 7670 : if (PyType_Ready(&py_transfer_syntax_ndr_SyntaxType) < 0) {
621 0 : return NULL;
622 : }
623 7670 : if (PyType_Ready(&py_transfer_syntax_ndr64_SyntaxType) < 0) {
624 0 : return NULL;
625 : }
626 7670 : if (PyType_Ready(&py_bind_time_features_syntax_SyntaxType) < 0) {
627 0 : return NULL;
628 : }
629 :
630 7670 : if (PyType_Ready(&py_dcerpc_ndr_pointer_type) < 0) {
631 0 : return NULL;
632 : }
633 :
634 7670 : m = PyModule_Create(&moduledef);
635 7670 : if (m == NULL) {
636 0 : return NULL;
637 : }
638 :
639 6422 : Py_INCREF((PyObject *)&dcerpc_InterfaceType);
640 7670 : PyModule_AddObject(m, "ClientConnection", (PyObject *)&dcerpc_InterfaceType);
641 :
642 6422 : Py_INCREF((PyObject *)(void *)&py_transfer_syntax_ndr_SyntaxType);
643 7670 : PyModule_AddObject(m, "transfer_syntax_ndr", (PyObject *)(void *)&py_transfer_syntax_ndr_SyntaxType);
644 6422 : Py_INCREF((PyObject *)(void *)&py_transfer_syntax_ndr64_SyntaxType);
645 7670 : PyModule_AddObject(m, "transfer_syntax_ndr64", (PyObject *)(void *)&py_transfer_syntax_ndr64_SyntaxType);
646 6422 : Py_INCREF((PyObject *)(void *)&py_bind_time_features_syntax_SyntaxType);
647 7670 : PyModule_AddObject(m, "bind_time_features_syntax", (PyObject *)(void *)&py_bind_time_features_syntax_SyntaxType);
648 6422 : Py_INCREF((PyObject *)(void *)&py_dcerpc_ndr_pointer_type);
649 7670 : PyModule_AddObject(m, "ndr_pointer", (PyObject *)(void *)&py_dcerpc_ndr_pointer_type);
650 7670 : return m;
651 : }
|