17
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
22
#include "includes.h"
23
23
#include "libcli/util/pyerrors.h"
24
24
#include "lib/registry/registry.h"
25
#include "scripting/python/modules.h" /* for py_iconv_convenience() */
25
#include "lib/talloc/pytalloc.h"
26
#include "lib/events/events.h"
27
27
#include "auth/credentials/pycredentials.h"
28
28
#include "param/pyparam.h"
30
#ifndef Py_RETURN_NONE
31
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
34
PyAPI_DATA(PyTypeObject) PyRegistryKey;
35
PyAPI_DATA(PyTypeObject) PyRegistry;
36
PyAPI_DATA(PyTypeObject) PyHiveKey;
30
extern PyTypeObject PyRegistryKey;
31
extern PyTypeObject PyRegistry;
32
extern PyTypeObject PyHiveKey;
38
34
/*#define PyRegistryKey_AsRegistryKey(obj) py_talloc_get_type(obj, struct registry_key)*/
39
35
#define PyRegistry_AsRegistryContext(obj) ((struct registry_context *)py_talloc_get_ptr(obj))
95
91
if (!PyArg_ParseTuple(args, "s", &filename))
98
result = reg_diff_apply(ctx, py_iconv_convenience(NULL), filename);
94
result = reg_diff_apply(ctx, filename);
99
95
PyErr_WERROR_IS_ERR_RAISE(result);
224
219
if (value.data != NULL)
225
220
result = hive_key_set_value(key, name, type, value);
227
result = hive_key_del_value(key, name);
222
result = hive_key_del_value(NULL, key, name);
229
224
PyErr_WERROR_IS_ERR_RAISE(result);
246
static PyObject *hive_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
241
static PyObject *hive_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) {
245
static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwargs)
247
const char *kwnames[] = { "location", "lp_ctx", "session_info", "credentials", NULL };
249
struct loadparm_context *lp_ctx;
250
PyObject *py_lp_ctx, *py_session_info, *py_credentials;
251
struct auth_session_info *session_info;
252
struct cli_credentials *credentials;
254
struct hive_key *hive_key;
257
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO",
258
discard_const_p(char *, kwnames),
260
&py_lp_ctx, &py_session_info,
264
mem_ctx = talloc_new(NULL);
265
if (mem_ctx == NULL) {
270
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
271
if (lp_ctx == NULL) {
272
PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
273
talloc_free(mem_ctx);
277
credentials = cli_credentials_from_py_object(py_credentials);
278
if (credentials == NULL) {
279
PyErr_SetString(PyExc_TypeError, "Expected credentials");
280
talloc_free(mem_ctx);
285
result = reg_open_hive(NULL, location, session_info, credentials,
286
tevent_context_init(NULL),
288
talloc_free(mem_ctx);
289
PyErr_WERROR_IS_ERR_RAISE(result);
291
return py_talloc_steal(&PyHiveKey, hive_key);
252
294
PyTypeObject PyHiveKey = {
253
295
.tp_name = "HiveKey",
254
296
.tp_methods = hive_key_methods,
256
298
.tp_basicsize = sizeof(py_talloc_Object),
257
.tp_dealloc = py_talloc_dealloc,
258
299
.tp_flags = Py_TPFLAGS_DEFAULT,
261
302
PyTypeObject PyRegistryKey = {
262
303
.tp_name = "RegistryKey",
263
304
.tp_basicsize = sizeof(py_talloc_Object),
264
.tp_dealloc = py_talloc_dealloc,
265
305
.tp_flags = Py_TPFLAGS_DEFAULT,
270
310
const char *kwnames[] = { "lp_ctx", "session_info", NULL };
271
311
struct registry_context *reg_ctx;
273
struct loadparm_context *lp_ctx;
313
struct loadparm_context *lp_ctx;
274
314
PyObject *py_lp_ctx, *py_session_info, *py_credentials;
275
315
struct auth_session_info *session_info;
276
struct cli_credentials *credentials;
277
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", discard_const_p(char *, kwnames),
278
&py_lp_ctx, &py_session_info, &py_credentials))
281
lp_ctx = lp_from_py_object(py_lp_ctx);
282
if (lp_ctx == NULL) {
316
struct cli_credentials *credentials;
319
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO",
320
discard_const_p(char *, kwnames),
321
&py_lp_ctx, &py_session_info,
325
mem_ctx = talloc_new(NULL);
326
if (mem_ctx == NULL) {
331
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
332
if (lp_ctx == NULL) {
283
333
PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
334
talloc_free(mem_ctx);
287
338
credentials = cli_credentials_from_py_object(py_credentials);
288
339
if (credentials == NULL) {
289
340
PyErr_SetString(PyExc_TypeError, "Expected credentials");
341
talloc_free(mem_ctx);
295
347
result = reg_open_samba(NULL, ®_ctx, NULL,
296
348
lp_ctx, session_info, credentials);
349
talloc_free(mem_ctx);
297
350
if (!W_ERROR_IS_OK(result)) {
298
351
PyErr_SetWERROR(result);
302
355
return py_talloc_steal(&PyRegistry, reg_ctx);
338
391
PyObject *py_session_info = Py_None, *py_credentials = Py_None, *py_lp_ctx = Py_None;
341
struct loadparm_context *lp_ctx;
342
struct cli_credentials *credentials;
394
struct loadparm_context *lp_ctx;
395
struct cli_credentials *credentials;
343
396
struct hive_key *key;
344
397
struct auth_session_info *session_info;
346
400
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO",
347
discard_const_p(char *, kwnames),
349
&py_session_info, &py_credentials,
353
lp_ctx = lp_from_py_object(py_lp_ctx);
354
if (lp_ctx == NULL) {
401
discard_const_p(char *, kwnames),
402
&location, &py_session_info,
403
&py_credentials, &py_lp_ctx))
406
mem_ctx = talloc_new(NULL);
407
if (mem_ctx == NULL) {
412
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
413
if (lp_ctx == NULL) {
355
414
PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
415
talloc_free(mem_ctx);
359
419
credentials = cli_credentials_from_py_object(py_credentials);
360
420
if (credentials == NULL) {
361
421
PyErr_SetString(PyExc_TypeError, "Expected credentials");
422
talloc_free(mem_ctx);
365
426
session_info = NULL; /* FIXME */
367
428
result = reg_open_ldb_file(NULL, location, session_info, credentials,
368
tevent_context_init(NULL), lp_ctx, &key);
429
s4_event_context_init(NULL), lp_ctx, &key);
430
talloc_free(mem_ctx);
369
431
PyErr_WERROR_IS_ERR_RAISE(result);
371
433
return py_talloc_steal(&PyHiveKey, key);
400
462
{ "open_directory", py_open_directory, METH_VARARGS, "open_dir(location) -> key" },
401
463
{ "create_directory", py_create_directory, METH_VARARGS, "create_dir(location) -> key" },
402
464
{ "open_ldb", (PyCFunction)py_open_ldb_file, METH_VARARGS|METH_KEYWORDS, "open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key" },
465
{ "open_hive", (PyCFunction)py_open_hive, METH_VARARGS|METH_KEYWORDS, "open_hive(location, session_info=None, credentials=None, loadparm_context=None) -> key" },
403
466
{ "str_regtype", py_str_regtype, METH_VARARGS, "str_regtype(int) -> str" },
404
467
{ "get_predef_name", py_get_predef_name, METH_VARARGS, "get_predef_name(hkey) -> str" },