summaryrefslogtreecommitdiff
path: root/source3/autoconf/librpc/gen_ndr/py_unixinfo.c
blob: c9018aaa885dedf9de2302bd8171026d733c3d8c (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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407

/* 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 "autoconf/librpc/gen_ndr/ndr_unixinfo.h"
#include "autoconf/librpc/gen_ndr/ndr_unixinfo_c.h"

#include "librpc/gen_ndr/security.h"
staticforward PyTypeObject unixinfo_GetPWUidInfo_Type;
staticforward PyTypeObject unixinfo_InterfaceType;

void initunixinfo(void);static PyTypeObject *dom_sid_Type;
static PyTypeObject *Object_Type;
static PyTypeObject *ClientConnection_Type;

static PyObject *py_unixinfo_GetPWUidInfo_get_status(PyObject *obj, void *closure)
{
	struct unixinfo_GetPWUidInfo *object = (struct unixinfo_GetPWUidInfo *)pytalloc_get_ptr(obj);
	PyObject *py_status;
	py_status = PyErr_FromNTSTATUS(object->status);
	return py_status;
}

static int py_unixinfo_GetPWUidInfo_set_status(PyObject *py_obj, PyObject *value, void *closure)
{
	struct unixinfo_GetPWUidInfo *object = (struct unixinfo_GetPWUidInfo *)pytalloc_get_ptr(py_obj);
	object->status = NT_STATUS(PyInt_AsLong(value));
	return 0;
}

static PyObject *py_unixinfo_GetPWUidInfo_get_homedir(PyObject *obj, void *closure)
{
	struct unixinfo_GetPWUidInfo *object = (struct unixinfo_GetPWUidInfo *)pytalloc_get_ptr(obj);
	PyObject *py_homedir;
	if (object->homedir == NULL) {
		py_homedir = Py_None;
		Py_INCREF(py_homedir);
	} else {
		py_homedir = PyUnicode_Decode(object->homedir, strlen(object->homedir), "utf-8", "ignore");
	}
	return py_homedir;
}

static int py_unixinfo_GetPWUidInfo_set_homedir(PyObject *py_obj, PyObject *value, void *closure)
{
	struct unixinfo_GetPWUidInfo *object = (struct unixinfo_GetPWUidInfo *)pytalloc_get_ptr(py_obj);
	if (PyUnicode_Check(value)) {
		object->homedir = PyString_AS_STRING(PyUnicode_AsEncodedString(value, "utf-8", "ignore"));
	} else if (PyString_Check(value)) {
		object->homedir = PyString_AS_STRING(value);
	} else {
		PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(value)->tp_name);
		return -1;
	}
	return 0;
}

static PyObject *py_unixinfo_GetPWUidInfo_get_shell(PyObject *obj, void *closure)
{
	struct unixinfo_GetPWUidInfo *object = (struct unixinfo_GetPWUidInfo *)pytalloc_get_ptr(obj);
	PyObject *py_shell;
	if (object->shell == NULL) {
		py_shell = Py_None;
		Py_INCREF(py_shell);
	} else {
		py_shell = PyUnicode_Decode(object->shell, strlen(object->shell), "utf-8", "ignore");
	}
	return py_shell;
}

static int py_unixinfo_GetPWUidInfo_set_shell(PyObject *py_obj, PyObject *value, void *closure)
{
	struct unixinfo_GetPWUidInfo *object = (struct unixinfo_GetPWUidInfo *)pytalloc_get_ptr(py_obj);
	if (PyUnicode_Check(value)) {
		object->shell = PyString_AS_STRING(PyUnicode_AsEncodedString(value, "utf-8", "ignore"));
	} else if (PyString_Check(value)) {
		object->shell = PyString_AS_STRING(value);
	} else {
		PyErr_Format(PyExc_TypeError, "Expected string or unicode object, got %s", Py_TYPE(value)->tp_name);
		return -1;
	}
	return 0;
}

static PyGetSetDef py_unixinfo_GetPWUidInfo_getsetters[] = {
	{ discard_const_p(char, "status"), py_unixinfo_GetPWUidInfo_get_status, py_unixinfo_GetPWUidInfo_set_status },
	{ discard_const_p(char, "homedir"), py_unixinfo_GetPWUidInfo_get_homedir, py_unixinfo_GetPWUidInfo_set_homedir },
	{ discard_const_p(char, "shell"), py_unixinfo_GetPWUidInfo_get_shell, py_unixinfo_GetPWUidInfo_set_shell },
	{ NULL }
};

static PyObject *py_unixinfo_GetPWUidInfo_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	return pytalloc_new(struct unixinfo_GetPWUidInfo, type);
}


static PyTypeObject unixinfo_GetPWUidInfo_Type = {
	PyObject_HEAD_INIT(NULL) 0,
	.tp_name = "unixinfo.GetPWUidInfo",
	.tp_getset = py_unixinfo_GetPWUidInfo_getsetters,
	.tp_methods = NULL,
	.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
	.tp_basicsize = sizeof(pytalloc_Object),
	.tp_new = py_unixinfo_GetPWUidInfo_new,
};


static bool pack_py_unixinfo_SidToUid_args_in(PyObject *args, PyObject *kwargs, struct unixinfo_SidToUid *r)
{
	PyObject *py_sid;
	const char *kwnames[] = {
		"sid", NULL
	};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:unixinfo_SidToUid", discard_const_p(char *, kwnames), &py_sid)) {
		return false;
	}

	PY_CHECK_TYPE(dom_sid_Type, py_sid, return false;);
	if (talloc_reference(r, pytalloc_get_mem_ctx(py_sid)) == NULL) {
		PyErr_NoMemory();
		return false;
	}
	r->in.sid = *(struct dom_sid *)pytalloc_get_ptr(py_sid);
	return true;
}

static PyObject *unpack_py_unixinfo_SidToUid_args_out(struct unixinfo_SidToUid *r)
{
	PyObject *result;
	PyObject *py_uid;
	py_uid = PyLong_FromLongLong(*r->out.uid);
	result = py_uid;
	if (NT_STATUS_IS_ERR(r->out.result)) {
		PyErr_SetNTSTATUS(r->out.result);
		return NULL;
	}

	return result;
}

static bool pack_py_unixinfo_UidToSid_args_in(PyObject *args, PyObject *kwargs, struct unixinfo_UidToSid *r)
{
	PyObject *py_uid;
	const char *kwnames[] = {
		"uid", NULL
	};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:unixinfo_UidToSid", discard_const_p(char *, kwnames), &py_uid)) {
		return false;
	}

	if (PyLong_Check(py_uid)) {
		r->in.uid = PyLong_AsLongLong(py_uid);
	} else if (PyInt_Check(py_uid)) {
		r->in.uid = PyInt_AsLong(py_uid);
	} else {
		PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
		  PyInt_Type.tp_name, PyLong_Type.tp_name);
		return false;
	}
	return true;
}

static PyObject *unpack_py_unixinfo_UidToSid_args_out(struct unixinfo_UidToSid *r)
{
	PyObject *result;
	PyObject *py_sid;
	py_sid = pytalloc_reference_ex(dom_sid_Type, r->out.sid, r->out.sid);
	result = py_sid;
	if (NT_STATUS_IS_ERR(r->out.result)) {
		PyErr_SetNTSTATUS(r->out.result);
		return NULL;
	}

	return result;
}

static bool pack_py_unixinfo_SidToGid_args_in(PyObject *args, PyObject *kwargs, struct unixinfo_SidToGid *r)
{
	PyObject *py_sid;
	const char *kwnames[] = {
		"sid", NULL
	};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:unixinfo_SidToGid", discard_const_p(char *, kwnames), &py_sid)) {
		return false;
	}

	PY_CHECK_TYPE(dom_sid_Type, py_sid, return false;);
	if (talloc_reference(r, pytalloc_get_mem_ctx(py_sid)) == NULL) {
		PyErr_NoMemory();
		return false;
	}
	r->in.sid = *(struct dom_sid *)pytalloc_get_ptr(py_sid);
	return true;
}

static PyObject *unpack_py_unixinfo_SidToGid_args_out(struct unixinfo_SidToGid *r)
{
	PyObject *result;
	PyObject *py_gid;
	py_gid = PyLong_FromLongLong(*r->out.gid);
	result = py_gid;
	if (NT_STATUS_IS_ERR(r->out.result)) {
		PyErr_SetNTSTATUS(r->out.result);
		return NULL;
	}

	return result;
}

static bool pack_py_unixinfo_GidToSid_args_in(PyObject *args, PyObject *kwargs, struct unixinfo_GidToSid *r)
{
	PyObject *py_gid;
	const char *kwnames[] = {
		"gid", NULL
	};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:unixinfo_GidToSid", discard_const_p(char *, kwnames), &py_gid)) {
		return false;
	}

	if (PyLong_Check(py_gid)) {
		r->in.gid = PyLong_AsLongLong(py_gid);
	} else if (PyInt_Check(py_gid)) {
		r->in.gid = PyInt_AsLong(py_gid);
	} else {
		PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
		  PyInt_Type.tp_name, PyLong_Type.tp_name);
		return false;
	}
	return true;
}

static PyObject *unpack_py_unixinfo_GidToSid_args_out(struct unixinfo_GidToSid *r)
{
	PyObject *result;
	PyObject *py_sid;
	py_sid = pytalloc_reference_ex(dom_sid_Type, r->out.sid, r->out.sid);
	result = py_sid;
	if (NT_STATUS_IS_ERR(r->out.result)) {
		PyErr_SetNTSTATUS(r->out.result);
		return NULL;
	}

	return result;
}

static bool pack_py_unixinfo_GetPWUid_args_in(PyObject *args, PyObject *kwargs, struct unixinfo_GetPWUid *r)
{
	PyObject *py_uids;
	const char *kwnames[] = {
		"uids", NULL
	};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:unixinfo_GetPWUid", discard_const_p(char *, kwnames), &py_uids)) {
		return false;
	}

	PY_CHECK_TYPE(&PyList_Type, py_uids, return false;);
	r->in.count = talloc_ptrtype(r, r->in.count);
	*r->in.count = PyList_GET_SIZE(py_uids);
	PY_CHECK_TYPE(&PyList_Type, py_uids, return false;);
	{
		int uids_cntr_0;
		r->in.uids = talloc_array_ptrtype(r, r->in.uids, PyList_GET_SIZE(py_uids));
		if (!r->in.uids) { return false;; }
		talloc_set_name_const(r->in.uids, "ARRAY: r->in.uids");
		for (uids_cntr_0 = 0; uids_cntr_0 < PyList_GET_SIZE(py_uids); uids_cntr_0++) {
			if (PyLong_Check(PyList_GET_ITEM(py_uids, uids_cntr_0))) {
				r->in.uids[uids_cntr_0] = PyLong_AsLongLong(PyList_GET_ITEM(py_uids, uids_cntr_0));
			} else if (PyInt_Check(PyList_GET_ITEM(py_uids, uids_cntr_0))) {
				r->in.uids[uids_cntr_0] = PyInt_AsLong(PyList_GET_ITEM(py_uids, uids_cntr_0));
			} else {
				PyErr_Format(PyExc_TypeError, "Expected type %s or %s",\
				  PyInt_Type.tp_name, PyLong_Type.tp_name);
				return false;
			}
		}
	}
	return true;
}

static PyObject *unpack_py_unixinfo_GetPWUid_args_out(struct unixinfo_GetPWUid *r)
{
	PyObject *result;
	PyObject *py_infos;
	py_infos = PyList_New(*r->out.count);
	if (py_infos == NULL) {
		return NULL;
	}
	{
		int infos_cntr_0;
		for (infos_cntr_0 = 0; infos_cntr_0 < *r->out.count; infos_cntr_0++) {
			PyObject *py_infos_0;
			py_infos_0 = pytalloc_reference_ex(&unixinfo_GetPWUidInfo_Type, r->out.infos, &r->out.infos[infos_cntr_0]);
			PyList_SetItem(py_infos, infos_cntr_0, py_infos_0);
		}
	}
	result = py_infos;
	if (NT_STATUS_IS_ERR(r->out.result)) {
		PyErr_SetNTSTATUS(r->out.result);
		return NULL;
	}

	return result;
}

const struct PyNdrRpcMethodDef py_ndr_unixinfo_methods[] = {
	{ "SidToUid", "S.SidToUid(sid) -> uid", (py_dcerpc_call_fn)dcerpc_unixinfo_SidToUid_r, (py_data_pack_fn)pack_py_unixinfo_SidToUid_args_in, (py_data_unpack_fn)unpack_py_unixinfo_SidToUid_args_out, 0, &ndr_table_unixinfo },
	{ "UidToSid", "S.UidToSid(uid) -> sid", (py_dcerpc_call_fn)dcerpc_unixinfo_UidToSid_r, (py_data_pack_fn)pack_py_unixinfo_UidToSid_args_in, (py_data_unpack_fn)unpack_py_unixinfo_UidToSid_args_out, 1, &ndr_table_unixinfo },
	{ "SidToGid", "S.SidToGid(sid) -> gid", (py_dcerpc_call_fn)dcerpc_unixinfo_SidToGid_r, (py_data_pack_fn)pack_py_unixinfo_SidToGid_args_in, (py_data_unpack_fn)unpack_py_unixinfo_SidToGid_args_out, 2, &ndr_table_unixinfo },
	{ "GidToSid", "S.GidToSid(gid) -> sid", (py_dcerpc_call_fn)dcerpc_unixinfo_GidToSid_r, (py_data_pack_fn)pack_py_unixinfo_GidToSid_args_in, (py_data_unpack_fn)unpack_py_unixinfo_GidToSid_args_out, 3, &ndr_table_unixinfo },
	{ "GetPWUid", "S.GetPWUid(uids) -> infos", (py_dcerpc_call_fn)dcerpc_unixinfo_GetPWUid_r, (py_data_pack_fn)pack_py_unixinfo_GetPWUid_args_in, (py_data_unpack_fn)unpack_py_unixinfo_GetPWUid_args_out, 4, &ndr_table_unixinfo },
	{ NULL }
};

static PyObject *interface_unixinfo_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	return py_dcerpc_interface_init_helper(type, args, kwargs, &ndr_table_unixinfo);
}

#define PY_DOC_UNIXINFO "Unixinfo specific stuff"
static PyTypeObject unixinfo_InterfaceType = {
	PyObject_HEAD_INIT(NULL) 0,
	.tp_name = "unixinfo.unixinfo",
	.tp_basicsize = sizeof(dcerpc_InterfaceObject),
	.tp_doc = "unixinfo(binding, lp_ctx=None, credentials=None) -> connection\n"
"\n"
"binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\n"
"lp_ctx should be a path to a smb.conf file or a param.LoadParm object\n"
"credentials should be a credentials.Credentials object.\n\n"PY_DOC_UNIXINFO,
	.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
	.tp_new = interface_unixinfo_new,
};

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

void initunixinfo(void)
{
	PyObject *m;
	PyObject *dep_samba_dcerpc_security;
	PyObject *dep_talloc;
	PyObject *dep_samba_dcerpc_base;

	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;

	dep_samba_dcerpc_base = PyImport_ImportModule("samba.dcerpc.base");
	if (dep_samba_dcerpc_base == 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;

	ClientConnection_Type = (PyTypeObject *)PyObject_GetAttrString(dep_samba_dcerpc_base, "ClientConnection");
	if (ClientConnection_Type == NULL)
		return;

	unixinfo_GetPWUidInfo_Type.tp_base = Object_Type;

	unixinfo_InterfaceType.tp_base = ClientConnection_Type;

	if (PyType_Ready(&unixinfo_GetPWUidInfo_Type) < 0)
		return;
	if (PyType_Ready(&unixinfo_InterfaceType) < 0)
		return;
	if (!PyInterface_AddNdrRpcMethods(&unixinfo_InterfaceType, py_ndr_unixinfo_methods))
		return;

#ifdef PY_GETPWUIDINFO_PATCH
	PY_GETPWUIDINFO_PATCH(&unixinfo_GetPWUidInfo_Type);
#endif
#ifdef PY_UNIXINFO_PATCH
	PY_UNIXINFO_PATCH(&unixinfo_InterfaceType);
#endif

	m = Py_InitModule3("unixinfo", unixinfo_methods, "unixinfo DCE/RPC");
	if (m == NULL)
		return;

	Py_INCREF((PyObject *)(void *)&unixinfo_GetPWUidInfo_Type);
	PyModule_AddObject(m, "GetPWUidInfo", (PyObject *)(void *)&unixinfo_GetPWUidInfo_Type);
	Py_INCREF((PyObject *)(void *)&unixinfo_InterfaceType);
	PyModule_AddObject(m, "unixinfo", (PyObject *)(void *)&unixinfo_InterfaceType);
#ifdef PY_MOD_UNIXINFO_PATCH
	PY_MOD_UNIXINFO_PATCH(m);
#endif

}