Changeset 745 for trunk/server/source4/lib/registry/pyregistry.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/lib/registry/pyregistry.c
r414 r745 3 3 Samba utility functions 4 4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008 5 Copyright (C) Wilco Baan Hofman <wilco@baanhofman.nl> 2010 5 6 6 7 This program is free software; you can redistribute it and/or modify … … 18 19 */ 19 20 21 #include <Python.h> 20 22 #include "includes.h" 21 #include <tevent.h>22 #include <Python.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() */26 #include <pytalloc.h>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" 29 29 30 #ifndef Py_RETURN_NONE 31 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None 32 #endif 33 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; 37 33 38 34 /*#define PyRegistryKey_AsRegistryKey(obj) py_talloc_get_type(obj, struct registry_key)*/ … … 96 92 return NULL; 97 93 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); 100 96 … … 164 160 .tp_new = registry_new, 165 161 .tp_basicsize = sizeof(py_talloc_Object), 166 .tp_dealloc = py_talloc_dealloc,167 162 .tp_flags = Py_TPFLAGS_DEFAULT, 168 163 }; … … 177 172 return NULL; 178 173 179 result = hive_key_del( key, name);174 result = hive_key_del(NULL, key, name); 180 175 181 176 PyErr_WERROR_IS_ERR_RAISE(result); … … 204 199 return NULL; 205 200 206 result = hive_key_del_value( key, name);201 result = hive_key_del_value(NULL, key, name); 207 202 208 203 PyErr_WERROR_IS_ERR_RAISE(result); … … 225 220 result = hive_key_set_value(key, name, type, value); 226 221 else 227 result = hive_key_del_value( key, name);222 result = hive_key_del_value(NULL, key, name); 228 223 229 224 PyErr_WERROR_IS_ERR_RAISE(result); … … 244 239 }; 245 240 246 static PyObject *hive_open(PyTypeObject *type, PyObject *args, PyObject *kwargs) 247 { 248 /* reg_open_hive */ 241 static PyObject *hive_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { 249 242 Py_RETURN_NONE; 243 } 244 245 static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwargs) 246 { 247 const char *kwnames[] = { "location", "lp_ctx", "session_info", "credentials", NULL }; 248 WERROR result; 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; 253 char *location; 254 struct hive_key *hive_key; 255 TALLOC_CTX *mem_ctx; 256 257 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", 258 discard_const_p(char *, kwnames), 259 &location, 260 &py_lp_ctx, &py_session_info, 261 &py_credentials)) 262 return NULL; 263 264 mem_ctx = talloc_new(NULL); 265 if (mem_ctx == NULL) { 266 PyErr_NoMemory(); 267 return NULL; 268 } 269 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); 274 return NULL; 275 } 276 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); 281 return NULL; 282 } 283 session_info = NULL; 284 285 result = reg_open_hive(NULL, location, session_info, credentials, 286 tevent_context_init(NULL), 287 lp_ctx, &hive_key); 288 talloc_free(mem_ctx); 289 PyErr_WERROR_IS_ERR_RAISE(result); 290 291 return py_talloc_steal(&PyHiveKey, hive_key); 250 292 } 251 293 … … 253 295 .tp_name = "HiveKey", 254 296 .tp_methods = hive_key_methods, 255 .tp_new = hive_ open,297 .tp_new = hive_new, 256 298 .tp_basicsize = sizeof(py_talloc_Object), 257 .tp_dealloc = py_talloc_dealloc,258 299 .tp_flags = Py_TPFLAGS_DEFAULT, 259 300 }; … … 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, 266 306 }; … … 271 311 struct registry_context *reg_ctx; 272 312 WERROR result; 273 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)) 279 return NULL; 280 281 lp_ctx = lp_from_py_object(py_lp_ctx); 282 if (lp_ctx == NULL) { 316 struct cli_credentials *credentials; 317 TALLOC_CTX *mem_ctx; 318 319 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", 320 discard_const_p(char *, kwnames), 321 &py_lp_ctx, &py_session_info, 322 &py_credentials)) 323 return NULL; 324 325 mem_ctx = talloc_new(NULL); 326 if (mem_ctx == NULL) { 327 PyErr_NoMemory(); 328 return NULL; 329 } 330 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"); 284 return NULL; 285 } 334 talloc_free(mem_ctx); 335 return NULL; 336 } 286 337 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); 290 342 return NULL; 291 343 } … … 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); 299 352 return NULL; 300 353 } 301 354 302 355 return py_talloc_steal(&PyRegistry, reg_ctx); 303 356 } … … 339 392 WERROR result; 340 393 char *location; 341 342 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; 398 TALLOC_CTX *mem_ctx; 345 399 346 400 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", 347 discard_const_p(char *, kwnames), 348 &location, 349 &py_session_info, &py_credentials, 350 &py_lp_ctx)) 351 return NULL; 352 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)) 404 return NULL; 405 406 mem_ctx = talloc_new(NULL); 407 if (mem_ctx == NULL) { 408 PyErr_NoMemory(); 409 return NULL; 410 } 411 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"); 356 return NULL; 357 } 415 talloc_free(mem_ctx); 416 return NULL; 417 } 358 418 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); 362 423 return NULL; 363 424 } … … 366 427 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); 370 432 … … 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" }, … … 409 472 { 410 473 PyObject *m; 474 PyTypeObject *talloc_type = PyTalloc_GetObjectType(); 475 476 if (talloc_type == NULL) 477 return; 478 479 PyHiveKey.tp_base = talloc_type; 480 PyRegistry.tp_base = talloc_type; 481 PyRegistryKey.tp_base = talloc_type; 411 482 412 483 if (PyType_Ready(&PyHiveKey) < 0)
Note:
See TracChangeset
for help on using the changeset viewer.