summaryrefslogtreecommitdiff
path: root/source3/librpc/gen_ndr/py_idmap.c
blob: e0f0ce22f62686f105e74f0df5904b4b25d780c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340

/* Python wrapper functions auto-generated by pidl */
#include <Python.h>
#include "includes.h"
#include <pytalloc.h>
#include "librpc/rpc/pyrpc.h"
#include "librpc/rpc/pyrpc_util.h"
#include "librpc/gen_ndr/ndr_idmap.h"
#include "librpc/gen_ndr/ndr_idmap_c.h"

#include "librpc/gen_ndr/security.h"
staticforward PyTypeObject unixid_Type;
staticforward PyTypeObject id_map_Type;

void initidmap(void);static PyTypeObject *dom_sid_Type;
static PyTypeObject *Object_Type;

static PyObject *py_unixid_get_id(PyObject *obj, void *closure)
{
	struct unixid *object = (struct unixid *)py_talloc_get_ptr(obj);
	PyObject *py_id;
	py_id = PyInt_FromLong(object->id);
	return py_id;
}

static int py_unixid_set_id(PyObject *py_obj, PyObject *value, void *closure)
{
	struct unixid *object = (struct unixid *)py_talloc_get_ptr(py_obj);
	PY_CHECK_TYPE(&PyInt_Type, value, return -1;);
	object->id = PyInt_AsLong(value);
	return 0;
}

static PyObject *py_unixid_get_type(PyObject *obj, void *closure)
{
	struct unixid *object = (struct unixid *)py_talloc_get_ptr(obj);
	PyObject *py_type;
	py_type = PyInt_FromLong(object->type);
	return py_type;
}

static int py_unixid_set_type(PyObject *py_obj, PyObject *value, void *closure)
{
	struct unixid *object = (struct unixid *)py_talloc_get_ptr(py_obj);
	if (PyLong_Check(value)) {
		object->type = PyLong_AsLongLong(value);
	} else if (PyInt_Check(value)) {
		object->type = PyInt_AsLong(value);
	} else {
		PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
		  PyInt_Type.tp_name, PyLong_Type.tp_name);
		return -1;
	}
	return 0;
}

static PyGetSetDef py_unixid_getsetters[] = {
	{ discard_const_p(char, "id"), py_unixid_get_id, py_unixid_set_id },
	{ discard_const_p(char, "type"), py_unixid_get_type, py_unixid_set_type },
	{ NULL }
};

static PyObject *py_unixid_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	return py_talloc_new(struct unixid, type);
}

static PyObject *py_unixid_ndr_pack(PyObject *py_obj)
{
	struct unixid *object = (struct unixid *)py_talloc_get_ptr(py_obj);
	DATA_BLOB blob;
	enum ndr_err_code err;
	err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_push_flags_fn_t)ndr_push_unixid);
	if (err != NDR_ERR_SUCCESS) {
		PyErr_SetNdrError(err);
		return NULL;
	}

	return PyString_FromStringAndSize((char *)blob.data, blob.length);
}

static PyObject *py_unixid_ndr_unpack(PyObject *py_obj, PyObject *args)
{
	struct unixid *object = (struct unixid *)py_talloc_get_ptr(py_obj);
	DATA_BLOB blob;
	enum ndr_err_code err;
	if (!PyArg_ParseTuple(args, "s#:__ndr_unpack__", &blob.data, &blob.length))
		return NULL;

	err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_unixid);
	if (err != NDR_ERR_SUCCESS) {
		PyErr_SetNdrError(err);
		return NULL;
	}

	Py_RETURN_NONE;
}

static PyObject *py_unixid_ndr_print(PyObject *py_obj)
{
	struct unixid *object = (struct unixid *)py_talloc_get_ptr(py_obj);
	PyObject *ret;
	char *retstr;

	retstr = ndr_print_struct_string(py_talloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_unixid, "unixid", object);
	ret = PyString_FromString(retstr);
	talloc_free(retstr);

	return ret;
}

static PyMethodDef py_unixid_methods[] = {
	{ "__ndr_pack__", (PyCFunction)py_unixid_ndr_pack, METH_NOARGS, "S.ndr_pack(object) -> blob\nNDR pack" },
	{ "__ndr_unpack__", (PyCFunction)py_unixid_ndr_unpack, METH_VARARGS, "S.ndr_unpack(class, blob) -> None\nNDR unpack" },
	{ "__ndr_print__", (PyCFunction)py_unixid_ndr_print, METH_VARARGS, "S.ndr_print(object) -> None\nNDR print" },
	{ NULL, NULL, 0, NULL }
};


static PyTypeObject unixid_Type = {
	PyObject_HEAD_INIT(NULL) 0,
	.tp_name = "idmap.unixid",
	.tp_getset = py_unixid_getsetters,
	.tp_methods = py_unixid_methods,
	.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
	.tp_basicsize = sizeof(py_talloc_Object),
	.tp_new = py_unixid_new,
};


static PyObject *py_id_map_get_sid(PyObject *obj, void *closure)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(obj);
	PyObject *py_sid;
	if (object->sid == NULL) {
		py_sid = Py_None;
		Py_INCREF(py_sid);
	} else {
		py_sid = py_talloc_reference_ex(dom_sid_Type, object->sid, object->sid);
	}
	return py_sid;
}

static int py_id_map_set_sid(PyObject *py_obj, PyObject *value, void *closure)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(py_obj);
	talloc_unlink(py_talloc_get_mem_ctx(py_obj), object->sid);
	if (value == Py_None) {
		object->sid = NULL;
	} else {
		object->sid = NULL;
		PY_CHECK_TYPE(dom_sid_Type, value, return -1;);
		if (talloc_reference(py_talloc_get_mem_ctx(py_obj), py_talloc_get_mem_ctx(value)) == NULL) {
			PyErr_NoMemory();
			return -1;
		}
		object->sid = (struct dom_sid *)py_talloc_get_ptr(value);
	}
	return 0;
}

static PyObject *py_id_map_get_xid(PyObject *obj, void *closure)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(obj);
	PyObject *py_xid;
	py_xid = py_talloc_reference_ex(&unixid_Type, py_talloc_get_mem_ctx(obj), &object->xid);
	return py_xid;
}

static int py_id_map_set_xid(PyObject *py_obj, PyObject *value, void *closure)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(py_obj);
	PY_CHECK_TYPE(&unixid_Type, value, return -1;);
	if (talloc_reference(py_talloc_get_mem_ctx(py_obj), py_talloc_get_mem_ctx(value)) == NULL) {
		PyErr_NoMemory();
		return -1;
	}
	object->xid = *(struct unixid *)py_talloc_get_ptr(value);
	return 0;
}

static PyObject *py_id_map_get_status(PyObject *obj, void *closure)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(obj);
	PyObject *py_status;
	py_status = PyInt_FromLong(object->status);
	return py_status;
}

static int py_id_map_set_status(PyObject *py_obj, PyObject *value, void *closure)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(py_obj);
	if (PyLong_Check(value)) {
		object->status = PyLong_AsLongLong(value);
	} else if (PyInt_Check(value)) {
		object->status = PyInt_AsLong(value);
	} else {
		PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
		  PyInt_Type.tp_name, PyLong_Type.tp_name);
		return -1;
	}
	return 0;
}

static PyGetSetDef py_id_map_getsetters[] = {
	{ discard_const_p(char, "sid"), py_id_map_get_sid, py_id_map_set_sid },
	{ discard_const_p(char, "xid"), py_id_map_get_xid, py_id_map_set_xid },
	{ discard_const_p(char, "status"), py_id_map_get_status, py_id_map_set_status },
	{ NULL }
};

static PyObject *py_id_map_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	return py_talloc_new(struct id_map, type);
}

static PyObject *py_id_map_ndr_pack(PyObject *py_obj)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(py_obj);
	DATA_BLOB blob;
	enum ndr_err_code err;
	err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_push_flags_fn_t)ndr_push_id_map);
	if (err != NDR_ERR_SUCCESS) {
		PyErr_SetNdrError(err);
		return NULL;
	}

	return PyString_FromStringAndSize((char *)blob.data, blob.length);
}

static PyObject *py_id_map_ndr_unpack(PyObject *py_obj, PyObject *args)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(py_obj);
	DATA_BLOB blob;
	enum ndr_err_code err;
	if (!PyArg_ParseTuple(args, "s#:__ndr_unpack__", &blob.data, &blob.length))
		return NULL;

	err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_id_map);
	if (err != NDR_ERR_SUCCESS) {
		PyErr_SetNdrError(err);
		return NULL;
	}

	Py_RETURN_NONE;
}

static PyObject *py_id_map_ndr_print(PyObject *py_obj)
{
	struct id_map *object = (struct id_map *)py_talloc_get_ptr(py_obj);
	PyObject *ret;
	char *retstr;

	retstr = ndr_print_struct_string(py_talloc_get_mem_ctx(py_obj), (ndr_print_fn_t)ndr_print_id_map, "id_map", object);
	ret = PyString_FromString(retstr);
	talloc_free(retstr);

	return ret;
}

static PyMethodDef py_id_map_methods[] = {
	{ "__ndr_pack__", (PyCFunction)py_id_map_ndr_pack, METH_NOARGS, "S.ndr_pack(object) -> blob\nNDR pack" },
	{ "__ndr_unpack__", (PyCFunction)py_id_map_ndr_unpack, METH_VARARGS, "S.ndr_unpack(class, blob) -> None\nNDR unpack" },
	{ "__ndr_print__", (PyCFunction)py_id_map_ndr_print, METH_VARARGS, "S.ndr_print(object) -> None\nNDR print" },
	{ NULL, NULL, 0, NULL }
};


static PyTypeObject id_map_Type = {
	PyObject_HEAD_INIT(NULL) 0,
	.tp_name = "idmap.id_map",
	.tp_getset = py_id_map_getsetters,
	.tp_methods = py_id_map_methods,
	.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
	.tp_basicsize = sizeof(py_talloc_Object),
	.tp_new = py_id_map_new,
};

static PyMethodDef idmap_methods[] = {
	{ NULL, NULL, 0, NULL }
};

void initidmap(void)
{
	PyObject *m;
	PyObject *dep_samba_dcerpc_security;
	PyObject *dep_talloc;

	dep_samba_dcerpc_security = PyImport_ImportModule("samba.dcerpc.security");
	if (dep_samba_dcerpc_security == NULL)
		return;

	dep_talloc = PyImport_ImportModule("talloc");
	if (dep_talloc == NULL)
		return;

	dom_sid_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_security, "dom_sid");
	if (dom_sid_Type == NULL)
		return;

	Object_Type = (PyTypeObject *)PyObject_GetAttrString(dep_talloc, "Object");
	if (Object_Type == NULL)
		return;

	unixid_Type.tp_base = Object_Type;

	id_map_Type.tp_base = Object_Type;

	if (PyType_Ready(&unixid_Type) < 0)
		return;
	if (PyType_Ready(&id_map_Type) < 0)
		return;
#ifdef PY_UNIXID_PATCH
	PY_UNIXID_PATCH(&unixid_Type);
#endif
#ifdef PY_ID_MAP_PATCH
	PY_ID_MAP_PATCH(&id_map_Type);
#endif

	m = Py_InitModule3("idmap", idmap_methods, "idmap DCE/RPC");
	if (m == NULL)
		return;

	PyModule_AddObject(m, "ID_TYPE_BOTH", PyInt_FromLong(ID_TYPE_BOTH));
	PyModule_AddObject(m, "ID_MAPPED", PyInt_FromLong(ID_MAPPED));
	PyModule_AddObject(m, "ID_TYPE_UID", PyInt_FromLong(ID_TYPE_UID));
	PyModule_AddObject(m, "ID_EXPIRED", PyInt_FromLong(ID_EXPIRED));
	PyModule_AddObject(m, "ID_UNMAPPED", PyInt_FromLong(ID_UNMAPPED));
	PyModule_AddObject(m, "ID_TYPE_NOT_SPECIFIED", PyInt_FromLong(ID_TYPE_NOT_SPECIFIED));
	PyModule_AddObject(m, "ID_TYPE_GID", PyInt_FromLong(ID_TYPE_GID));
	PyModule_AddObject(m, "ID_UNKNOWN", PyInt_FromLong(ID_UNKNOWN));
	Py_INCREF((PyObject *)(void *)&unixid_Type);
	PyModule_AddObject(m, "unixid", (PyObject *)(void *)&unixid_Type);
	Py_INCREF((PyObject *)(void *)&id_map_Type);
	PyModule_AddObject(m, "id_map", (PyObject *)(void *)&id_map_Type);
#ifdef PY_MOD_IDMAP_PATCH
	PY_MOD_IDMAP_PATCH(m);
#endif

}