Line data Source code
1 :
2 : /* Python wrapper functions auto-generated by pidl */
3 : #define PY_SSIZE_T_CLEAN 1 /* We use Py_ssize_t for PyArg_ParseTupleAndKeywords */
4 : #include "lib/replace/system/python.h"
5 : #include "python/py3compat.h"
6 : #include "includes.h"
7 : #include "python/modules.h"
8 : #include <pytalloc.h>
9 : #include "librpc/rpc/pyrpc.h"
10 : #include "librpc/rpc/pyrpc_util.h"
11 : #include "bin/default/librpc/gen_ndr/ndr_server_id.h"
12 :
13 :
14 : /*
15 : * Suppress compiler warnings if the generated code does not call these
16 : * functions
17 : */
18 : #ifndef _MAYBE_UNUSED_
19 : #ifdef __has_attribute
20 : #if __has_attribute(unused)
21 : #define _MAYBE_UNUSED_ __attribute__ ((unused))
22 : #else
23 : #define _MAYBE_UNUSED_
24 : #endif
25 : #endif
26 : #endif
27 : /*
28 : * These functions are here to ensure they can be optimized out by
29 : * the compiler based on the constant input values
30 : */
31 :
32 0 : static inline unsigned long long ndr_sizeof2uintmax(size_t var_size)
33 : {
34 0 : switch (var_size) {
35 0 : case 8:
36 0 : return UINT64_MAX;
37 0 : case 4:
38 0 : return UINT32_MAX;
39 0 : case 2:
40 0 : return UINT16_MAX;
41 0 : case 1:
42 0 : return UINT8_MAX;
43 : }
44 :
45 0 : return 0;
46 : }
47 :
48 : static inline _MAYBE_UNUSED_ long long ndr_sizeof2intmax(size_t var_size)
49 : {
50 : switch (var_size) {
51 : case 8:
52 : return INT64_MAX;
53 : case 4:
54 : return INT32_MAX;
55 : case 2:
56 : return INT16_MAX;
57 : case 1:
58 : return INT8_MAX;
59 : }
60 :
61 : return 0;
62 : }
63 :
64 : static PyTypeObject server_id_Type;
65 :
66 : static PyTypeObject *BaseObject_Type;
67 :
68 8189 : static PyObject *py_server_id_get_pid(PyObject *obj, void *closure)
69 : {
70 8189 : struct server_id *object = pytalloc_get_ptr(obj);
71 0 : PyObject *py_pid;
72 8189 : py_pid = PyLong_FromUnsignedLongLong(object->pid);
73 8189 : return py_pid;
74 : }
75 :
76 0 : static int py_server_id_set_pid(PyObject *py_obj, PyObject *value, void *closure)
77 : {
78 0 : struct server_id *object = pytalloc_get_ptr(py_obj);
79 0 : if (value == NULL) {
80 0 : PyErr_Format(PyExc_AttributeError, "Cannot delete NDR object: object->pid");
81 0 : return -1;
82 : }
83 : {
84 0 : const unsigned long long uint_max = ndr_sizeof2uintmax(sizeof(object->pid));
85 0 : if (PyLong_Check(value)) {
86 0 : unsigned long long test_var;
87 0 : test_var = PyLong_AsUnsignedLongLong(value);
88 0 : if (PyErr_Occurred() != NULL) {
89 0 : return -1;
90 : }
91 0 : if (test_var > uint_max) {
92 0 : PyErr_Format(PyExc_OverflowError, "Expected type %s within range 0 - %llu, got %llu",
93 : PyLong_Type.tp_name, uint_max, test_var);
94 0 : return -1;
95 : }
96 0 : object->pid = test_var;
97 : } else {
98 0 : PyErr_Format(PyExc_TypeError, "Expected type %s",
99 : PyLong_Type.tp_name);
100 0 : return -1;
101 : }
102 : }
103 0 : return 0;
104 : }
105 :
106 0 : static PyObject *py_server_id_get_task_id(PyObject *obj, void *closure)
107 : {
108 0 : struct server_id *object = pytalloc_get_ptr(obj);
109 0 : PyObject *py_task_id;
110 0 : py_task_id = PyLong_FromUnsignedLongLong((uint32_t)(object->task_id));
111 0 : return py_task_id;
112 : }
113 :
114 0 : static int py_server_id_set_task_id(PyObject *py_obj, PyObject *value, void *closure)
115 : {
116 0 : struct server_id *object = pytalloc_get_ptr(py_obj);
117 0 : if (value == NULL) {
118 0 : PyErr_Format(PyExc_AttributeError, "Cannot delete NDR object: object->task_id");
119 0 : return -1;
120 : }
121 : {
122 0 : const unsigned long long uint_max = ndr_sizeof2uintmax(sizeof(object->task_id));
123 0 : if (PyLong_Check(value)) {
124 0 : unsigned long long test_var;
125 0 : test_var = PyLong_AsUnsignedLongLong(value);
126 0 : if (PyErr_Occurred() != NULL) {
127 0 : return -1;
128 : }
129 0 : if (test_var > uint_max) {
130 0 : PyErr_Format(PyExc_OverflowError, "Expected type %s within range 0 - %llu, got %llu",
131 : PyLong_Type.tp_name, uint_max, test_var);
132 0 : return -1;
133 : }
134 0 : object->task_id = test_var;
135 : } else {
136 0 : PyErr_Format(PyExc_TypeError, "Expected type %s",
137 : PyLong_Type.tp_name);
138 0 : return -1;
139 : }
140 : }
141 0 : return 0;
142 : }
143 :
144 0 : static PyObject *py_server_id_get_vnn(PyObject *obj, void *closure)
145 : {
146 0 : struct server_id *object = pytalloc_get_ptr(obj);
147 0 : PyObject *py_vnn;
148 0 : py_vnn = PyLong_FromUnsignedLongLong((uint32_t)(object->vnn));
149 0 : return py_vnn;
150 : }
151 :
152 2 : static int py_server_id_set_vnn(PyObject *py_obj, PyObject *value, void *closure)
153 : {
154 2 : struct server_id *object = pytalloc_get_ptr(py_obj);
155 2 : if (value == NULL) {
156 0 : PyErr_Format(PyExc_AttributeError, "Cannot delete NDR object: object->vnn");
157 0 : return -1;
158 : }
159 : {
160 2 : const unsigned long long uint_max = ndr_sizeof2uintmax(sizeof(object->vnn));
161 2 : if (PyLong_Check(value)) {
162 2 : unsigned long long test_var;
163 2 : test_var = PyLong_AsUnsignedLongLong(value);
164 2 : if (PyErr_Occurred() != NULL) {
165 0 : return -1;
166 : }
167 1 : if (test_var > uint_max) {
168 1 : PyErr_Format(PyExc_OverflowError, "Expected type %s within range 0 - %llu, got %llu",
169 : PyLong_Type.tp_name, uint_max, test_var);
170 1 : return -1;
171 : }
172 0 : object->vnn = test_var;
173 : } else {
174 0 : PyErr_Format(PyExc_TypeError, "Expected type %s",
175 : PyLong_Type.tp_name);
176 0 : return -1;
177 : }
178 : }
179 0 : return 0;
180 : }
181 :
182 2 : static PyObject *py_server_id_get_unique_id(PyObject *obj, void *closure)
183 : {
184 2 : struct server_id *object = pytalloc_get_ptr(obj);
185 2 : PyObject *py_unique_id;
186 2 : py_unique_id = PyLong_FromUnsignedLongLong(object->unique_id);
187 2 : return py_unique_id;
188 : }
189 :
190 3 : static int py_server_id_set_unique_id(PyObject *py_obj, PyObject *value, void *closure)
191 : {
192 3 : struct server_id *object = pytalloc_get_ptr(py_obj);
193 3 : if (value == NULL) {
194 0 : PyErr_Format(PyExc_AttributeError, "Cannot delete NDR object: object->unique_id");
195 0 : return -1;
196 : }
197 : {
198 3 : const unsigned long long uint_max = ndr_sizeof2uintmax(sizeof(object->unique_id));
199 3 : if (PyLong_Check(value)) {
200 3 : unsigned long long test_var;
201 3 : test_var = PyLong_AsUnsignedLongLong(value);
202 3 : if (PyErr_Occurred() != NULL) {
203 0 : return -1;
204 : }
205 2 : if (test_var > uint_max) {
206 0 : PyErr_Format(PyExc_OverflowError, "Expected type %s within range 0 - %llu, got %llu",
207 : PyLong_Type.tp_name, uint_max, test_var);
208 0 : return -1;
209 : }
210 2 : object->unique_id = test_var;
211 : } else {
212 0 : PyErr_Format(PyExc_TypeError, "Expected type %s",
213 : PyLong_Type.tp_name);
214 0 : return -1;
215 : }
216 : }
217 2 : return 0;
218 : }
219 :
220 : static PyGetSetDef py_server_id_getsetters[] = {
221 : {
222 : .name = discard_const_p(char, "pid"),
223 : .get = py_server_id_get_pid,
224 : .set = py_server_id_set_pid,
225 : .doc = discard_const_p(char, "PIDL-generated element of base type hyper")
226 : },
227 : {
228 : .name = discard_const_p(char, "task_id"),
229 : .get = py_server_id_get_task_id,
230 : .set = py_server_id_set_task_id,
231 : .doc = discard_const_p(char, "PIDL-generated element of base type uint32")
232 : },
233 : {
234 : .name = discard_const_p(char, "vnn"),
235 : .get = py_server_id_get_vnn,
236 : .set = py_server_id_set_vnn,
237 : .doc = discard_const_p(char, "PIDL-generated element of base type uint32")
238 : },
239 : {
240 : .name = discard_const_p(char, "unique_id"),
241 : .get = py_server_id_get_unique_id,
242 : .set = py_server_id_set_unique_id,
243 : .doc = discard_const_p(char, "PIDL-generated element of base type hyper")
244 : },
245 : { .name = NULL }
246 : };
247 :
248 5 : static PyObject *py_server_id_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
249 : {
250 5 : return pytalloc_new(struct server_id, type);
251 : }
252 :
253 0 : static PyObject *py_server_id_ndr_pack(PyObject *py_obj, PyObject *Py_UNUSED(ignored))
254 : {
255 0 : struct server_id *object = pytalloc_get_ptr(py_obj);
256 0 : PyObject *ret = NULL;
257 0 : DATA_BLOB blob;
258 0 : enum ndr_err_code err;
259 0 : TALLOC_CTX *tmp_ctx = talloc_new(pytalloc_get_mem_ctx(py_obj));
260 0 : if (tmp_ctx == NULL) {
261 0 : PyErr_SetNdrError(NDR_ERR_ALLOC);
262 0 : return NULL;
263 : }
264 0 : err = ndr_push_struct_blob(&blob, tmp_ctx, object, (ndr_push_flags_fn_t)ndr_push_server_id);
265 0 : if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
266 0 : TALLOC_FREE(tmp_ctx);
267 0 : PyErr_SetNdrError(err);
268 0 : return NULL;
269 : }
270 :
271 0 : ret = PyBytes_FromStringAndSize((char *)blob.data, blob.length);
272 0 : TALLOC_FREE(tmp_ctx);
273 0 : return ret;
274 : }
275 :
276 0 : static PyObject *py_server_id_ndr_unpack(PyObject *py_obj, PyObject *args, PyObject *kwargs)
277 : {
278 0 : struct server_id *object = pytalloc_get_ptr(py_obj);
279 0 : DATA_BLOB blob = {.data = NULL, .length = 0};
280 0 : Py_ssize_t blob_length = 0;
281 0 : enum ndr_err_code err;
282 0 : const char * const kwnames[] = { "data_blob", "allow_remaining", NULL };
283 0 : PyObject *allow_remaining_obj = NULL;
284 0 : bool allow_remaining = false;
285 :
286 0 : if (!PyArg_ParseTupleAndKeywords(args, kwargs, PYARG_BYTES_LEN "|O:__ndr_unpack__",
287 : discard_const_p(char *, kwnames),
288 : &blob.data, &blob_length,
289 : &allow_remaining_obj)) {
290 0 : return NULL;
291 : }
292 0 : blob.length = blob_length;
293 :
294 0 : if (allow_remaining_obj && PyObject_IsTrue(allow_remaining_obj)) {
295 0 : allow_remaining = true;
296 : }
297 :
298 0 : if (allow_remaining) {
299 0 : err = ndr_pull_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_server_id);
300 : } else {
301 0 : err = ndr_pull_struct_blob_all(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_server_id);
302 : }
303 0 : if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
304 0 : PyErr_SetNdrError(err);
305 0 : return NULL;
306 : }
307 :
308 0 : Py_RETURN_NONE;
309 : }
310 :
311 2 : static PyObject *py_server_id_ndr_print(PyObject *py_obj, PyObject *Py_UNUSED(ignored))
312 : {
313 2 : struct server_id *object = pytalloc_get_ptr(py_obj);
314 0 : PyObject *ret;
315 0 : char *retstr;
316 :
317 2 : retstr = ndr_print_struct_string(pytalloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_server_id, "server_id", object);
318 2 : ret = PyUnicode_FromString(retstr);
319 2 : talloc_free(retstr);
320 :
321 2 : return ret;
322 : }
323 :
324 : static PyMethodDef py_server_id_methods[] = {
325 : { "__ndr_pack__", (PyCFunction)py_server_id_ndr_pack, METH_NOARGS, "S.ndr_pack(object) -> blob\nNDR pack" },
326 : { "__ndr_unpack__", PY_DISCARD_FUNC_SIG(PyCFunction,py_server_id_ndr_unpack), METH_VARARGS|METH_KEYWORDS, "S.ndr_unpack(class, blob, allow_remaining=False) -> None\nNDR unpack" },
327 : { "__ndr_print__", (PyCFunction)py_server_id_ndr_print, METH_NOARGS, "S.ndr_print(object) -> None\nNDR print" },
328 : { NULL, NULL, 0, NULL }
329 : };
330 :
331 :
332 : static PyTypeObject server_id_Type = {
333 : PyVarObject_HEAD_INIT(NULL, 0)
334 : .tp_name = "server_id.server_id",
335 : .tp_getset = py_server_id_getsetters,
336 : .tp_methods = py_server_id_methods,
337 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
338 : .tp_new = py_server_id_new,
339 : };
340 :
341 : static PyMethodDef server_id_methods[] = {
342 : { NULL, NULL, 0, NULL }
343 : };
344 :
345 : static struct PyModuleDef moduledef = {
346 : PyModuleDef_HEAD_INIT,
347 : .m_name = "server_id",
348 : .m_doc = "server_id DCE/RPC",
349 : .m_size = -1,
350 : .m_methods = server_id_methods,
351 : };
352 33 : MODULE_INIT_FUNC(server_id)
353 : {
354 33 : PyObject *m = NULL;
355 33 : PyObject *dep_talloc = NULL;
356 :
357 33 : dep_talloc = PyImport_ImportModule("talloc");
358 33 : if (dep_talloc == NULL)
359 0 : goto out;
360 :
361 33 : BaseObject_Type = (PyTypeObject *)PyObject_GetAttrString(dep_talloc, "BaseObject");
362 33 : if (BaseObject_Type == NULL)
363 0 : goto out;
364 :
365 33 : server_id_Type.tp_base = BaseObject_Type;
366 33 : server_id_Type.tp_basicsize = pytalloc_BaseObject_size();
367 :
368 33 : if (PyType_Ready(&server_id_Type) < 0)
369 0 : goto out;
370 : #ifdef PY_SERVER_ID_PATCH
371 : PY_SERVER_ID_PATCH(&server_id_Type);
372 : #endif
373 :
374 33 : m = PyModule_Create(&moduledef);
375 33 : if (m == NULL)
376 0 : goto out;
377 :
378 33 : PyModule_AddObject(m, "NONCLUSTER_VNN", PyLong_FromUnsignedLongLong(0xFFFFFFFF));
379 33 : PyModule_AddObject(m, "SERVERID_UNIQUE_ID_NOT_TO_VERIFY", PyLong_FromUnsignedLongLong(0xFFFFFFFFFFFFFFFFULL));
380 28 : Py_INCREF((PyObject *)(void *)&server_id_Type);
381 33 : PyModule_AddObject(m, "server_id", (PyObject *)(void *)&server_id_Type);
382 : #ifdef PY_MOD_SERVER_ID_PATCH
383 : PY_MOD_SERVER_ID_PATCH(m);
384 : #endif
385 33 : out:
386 33 : Py_XDECREF(dep_talloc);
387 33 : return m;
388 :
389 : }
|