1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

r26520: More Python updates.

(This used to be commit a8b1fe15ac853082961132ede061fe1556ae29f7)
This commit is contained in:
Jelmer Vernooij 2007-12-18 02:21:14 +01:00 committed by Stefan Metzmacher
parent cad1e11959
commit 63f53094ef
9 changed files with 205 additions and 26 deletions

View File

@ -104,6 +104,18 @@ typedef struct registry_context {
WERROR mount_hive(struct hive_key *hive_key, uint32_t hkey_id,
const char **elements=NULL);
WERROR mount_hive(struct hive_key *hive_key, const char *predef_name)
{
int i;
for (i = 0; reg_predefined_keys[i].name; i++) {
if (!strcasecmp(reg_predefined_keys[i].name, predef_name))
return reg_mount_hive($self, hive_key,
reg_predefined_keys[i].handle, NULL);
}
return WERR_INVALID_NAME;
}
}
} reg;

View File

@ -2831,6 +2831,15 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
SWIGINTERN WERROR reg_apply_patchfile(reg *self,char const *filename){
return reg_diff_apply(filename, self);
}
SWIGINTERN WERROR reg_mount_hive__SWIG_1(reg *self,struct hive_key *hive_key,char const *predef_name){
int i;
for (i = 0; reg_predefined_keys[i].name; i++) {
if (!strcasecmp(reg_predefined_keys[i].name, predef_name))
return reg_mount_hive(self, hive_key,
reg_predefined_keys[i].handle, NULL);
}
return WERR_INVALID_NAME;
}
#define SWIG_From_long PyInt_FromLong
@ -3112,7 +3121,7 @@ fail:
}
SWIGINTERN PyObject *_wrap_reg_mount_hive(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
SWIGINTERN PyObject *_wrap_reg_mount_hive__SWIG_0(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
reg *arg1 = (reg *) 0 ;
struct hive_key *arg2 = (struct hive_key *) 0 ;
@ -3125,41 +3134,34 @@ SWIGINTERN PyObject *_wrap_reg_mount_hive(PyObject *SWIGUNUSEDPARM(self), PyObje
int res2 = 0 ;
unsigned int val3 ;
int ecode3 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
char * kwnames[] = {
(char *) "self",(char *) "hive_key",(char *) "hkey_id",(char *) "elements", NULL
};
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:reg_mount_hive",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_registry_context, 0 | 0 );
if ((nobjs < 3) || (nobjs > 4)) SWIG_fail;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_registry_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "reg_mount_hive" "', argument " "1"" of type '" "reg *""'");
}
arg1 = (reg *)(argp1);
res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_hive_key, 0 | 0 );
res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_hive_key, 0 | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "reg_mount_hive" "', argument " "2"" of type '" "struct hive_key *""'");
}
arg2 = (struct hive_key *)(argp2);
ecode3 = SWIG_AsVal_unsigned_SS_int(obj2, &val3);
ecode3 = SWIG_AsVal_unsigned_SS_int(swig_obj[2], &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "reg_mount_hive" "', argument " "3"" of type '" "uint32_t""'");
}
arg3 = (uint32_t)(val3);
if (obj3) {
if (swig_obj[3]) {
{
/* Check if is a list */
if (PyList_Check(obj3)) {
int size = PyList_Size(obj3);
if (PyList_Check(swig_obj[3])) {
int size = PyList_Size(swig_obj[3]);
int i = 0;
arg4 = (char **) malloc((size+1)*sizeof(const char *));
for (i = 0; i < size; i++) {
PyObject *o = PyList_GetItem(obj3,i);
PyObject *o = PyList_GetItem(swig_obj[3],i);
if (PyString_Check(o))
arg4[i] = PyString_AsString(PyList_GetItem(obj3,i));
arg4[i] = PyString_AsString(PyList_GetItem(swig_obj[3],i));
else {
PyErr_SetString(PyExc_TypeError,"list must contain strings");
free(arg4);
@ -3194,6 +3196,82 @@ fail:
}
SWIGINTERN PyObject *_wrap_reg_mount_hive__SWIG_1(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
reg *arg1 = (reg *) 0 ;
struct hive_key *arg2 = (struct hive_key *) 0 ;
char *arg3 = (char *) 0 ;
WERROR result;
void *argp1 = 0 ;
int res1 = 0 ;
void *argp2 = 0 ;
int res2 = 0 ;
int res3 ;
char *buf3 = 0 ;
int alloc3 = 0 ;
if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_registry_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "reg_mount_hive" "', argument " "1"" of type '" "reg *""'");
}
arg1 = (reg *)(argp1);
res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_hive_key, 0 | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "reg_mount_hive" "', argument " "2"" of type '" "struct hive_key *""'");
}
arg2 = (struct hive_key *)(argp2);
res3 = SWIG_AsCharPtrAndSize(swig_obj[2], &buf3, NULL, &alloc3);
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "reg_mount_hive" "', argument " "3"" of type '" "char const *""'");
}
arg3 = (char *)(buf3);
result = reg_mount_hive__SWIG_1(arg1,arg2,(char const *)arg3);
{
if (!W_ERROR_IS_OK(result)) {
PyObject *obj = Py_BuildValue("(i,s)", (&result)->v, win_errstr(result));
PyErr_SetObject(PyExc_RuntimeError, obj);
} else if (resultobj == NULL) {
resultobj = Py_None;
}
}
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
return resultobj;
fail:
if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
return NULL;
}
SWIGINTERN PyObject *_wrap_reg_mount_hive(PyObject *self, PyObject *args) {
int argc;
PyObject *argv[5];
if (!(argc = SWIG_Python_UnpackTuple(args,"reg_mount_hive",0,4,argv))) SWIG_fail;
--argc;
if ((argc >= 3) && (argc <= 4)) {
int _v = 0;
{
{
int res = SWIG_AsVal_unsigned_SS_int(argv[2], NULL);
_v = SWIG_CheckState(res);
}
}
if (!_v) goto check_1;
return _wrap_reg_mount_hive__SWIG_0(self, argc, argv);
}
check_1:
if (argc == 3) {
return _wrap_reg_mount_hive__SWIG_1(self, argc, argv);
}
fail:
SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'reg_mount_hive'.\n Possible C/C++ prototypes are:\n"" mount_hive(reg *,struct hive_key *,uint32_t,char const **)\n"" mount_hive(reg *,struct hive_key *,char const *)\n");
return NULL;
}
SWIGINTERN PyObject *_wrap_new_reg(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
reg *result = 0 ;
@ -3462,7 +3540,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"reg_get_predefined_key_by_name", (PyCFunction) _wrap_reg_get_predefined_key_by_name, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"reg_get_predefined_key", (PyCFunction) _wrap_reg_get_predefined_key, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"reg_apply_patchfile", (PyCFunction) _wrap_reg_apply_patchfile, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"reg_mount_hive", (PyCFunction) _wrap_reg_mount_hive, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"reg_mount_hive", _wrap_reg_mount_hive, METH_VARARGS, NULL},
{ (char *)"new_reg", (PyCFunction)_wrap_new_reg, METH_NOARGS, NULL},
{ (char *)"delete_reg", (PyCFunction)_wrap_delete_reg, METH_O, NULL},
{ (char *)"reg_swigregister", reg_swigregister, METH_VARARGS, NULL},

View File

@ -23,6 +23,7 @@
#include "ldb.h"
#include "param/param.h"
#include "dsdb/samdb/samdb.h"
#include "lib/ldb-samba/ldif_handlers.h"
%}
%import "stdint.i"
@ -62,3 +63,5 @@ WERROR dsdb_attach_schema_from_ldif_file(struct ldb_context *ldb, const char *pf
%rename(version) samba_version_string;
const char *samba_version_string(void);
int dsdb_set_global_schema(struct ldb_context *ldb);
int ldb_register_samba_handlers(struct ldb_context *ldb);

View File

@ -68,5 +68,7 @@ ldb_set_loadparm = _misc.ldb_set_loadparm
samdb_set_domain_sid = _misc.samdb_set_domain_sid
dsdb_attach_schema_from_ldif_file = _misc.dsdb_attach_schema_from_ldif_file
version = _misc.version
dsdb_set_global_schema = _misc.dsdb_set_global_schema
ldb_register_samba_handlers = _misc.ldb_register_samba_handlers

View File

@ -2531,6 +2531,7 @@ static swig_module_info swig_module = {swig_types, 27, 0, 0, 0, 0};
#include "ldb.h"
#include "param/param.h"
#include "dsdb/samdb/samdb.h"
#include "lib/ldb-samba/ldif_handlers.h"
SWIGINTERN int
@ -2782,6 +2783,16 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
#define SWIG_From_long PyInt_FromLong
SWIGINTERNINLINE PyObject *
SWIG_From_int (int value)
{
return SWIG_From_long (value);
}
#ifdef __cplusplus
extern "C" {
#endif
@ -3051,6 +3062,66 @@ fail:
}
SWIGINTERN PyObject *_wrap_dsdb_set_global_schema(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
struct ldb_context *arg1 = (struct ldb_context *) 0 ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
char * kwnames[] = {
(char *) "ldb", NULL
};
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:dsdb_set_global_schema",kwnames,&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "dsdb_set_global_schema" "', argument " "1"" of type '" "struct ldb_context *""'");
}
arg1 = (struct ldb_context *)(argp1);
{
if (arg1 == NULL)
SWIG_exception(SWIG_ValueError,
"ldb context must be non-NULL");
}
result = (int)dsdb_set_global_schema(arg1);
resultobj = SWIG_From_int((int)(result));
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_ldb_register_samba_handlers(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
struct ldb_context *arg1 = (struct ldb_context *) 0 ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
char * kwnames[] = {
(char *) "ldb", NULL
};
if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:ldb_register_samba_handlers",kwnames,&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_register_samba_handlers" "', argument " "1"" of type '" "struct ldb_context *""'");
}
arg1 = (struct ldb_context *)(argp1);
{
if (arg1 == NULL)
SWIG_exception(SWIG_ValueError,
"ldb context must be non-NULL");
}
result = (int)ldb_register_samba_handlers(arg1);
resultobj = SWIG_From_int((int)(result));
return resultobj;
fail:
return NULL;
}
static PyMethodDef SwigMethods[] = {
{ (char *)"random_password", (PyCFunction) _wrap_random_password, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"ldb_set_credentials", (PyCFunction) _wrap_ldb_set_credentials, METH_VARARGS | METH_KEYWORDS, NULL},
@ -3059,6 +3130,8 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"samdb_set_domain_sid", (PyCFunction) _wrap_samdb_set_domain_sid, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"dsdb_attach_schema_from_ldif_file", (PyCFunction) _wrap_dsdb_attach_schema_from_ldif_file, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"version", (PyCFunction)_wrap_version, METH_NOARGS, NULL},
{ (char *)"dsdb_set_global_schema", (PyCFunction) _wrap_dsdb_set_global_schema, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"ldb_register_samba_handlers", (PyCFunction) _wrap_ldb_register_samba_handlers, METH_VARARGS | METH_KEYWORDS, NULL},
{ NULL, NULL, 0, NULL }
};

View File

@ -78,6 +78,10 @@ class Ldb(ldb.Ldb):
if url:
self.connect(url)
def msg(l,text):
print text
#self.set_debug(msg)
set_credentials = misc.ldb_set_credentials
set_session_info = misc.ldb_set_session_info
set_loadparm = misc.ldb_set_loadparm

View File

@ -306,7 +306,7 @@ def setup_name_mappings(subobj, ldb):
["objectSid"])
assert len(res) == 1
assert "objectSid" in res[0]
sid = list(res[0]["objectSid"])[0]
sid = str(list(res[0]["objectSid"])[0])
# add some foreign sids if they are not present already
ldb.add_foreign(subobj.domaindn, "S-1-5-7", "Anonymous")
@ -419,12 +419,12 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
message("Setting up registry")
reg = registry.Registry()
hive = registry.Hive(paths.hklm, session_info=session_info,
credentials=credentials, lp_ctx=lp)
reg.mount_hive(hive, registry.HKEY_LOCAL_MACHINE, [])
#hive = registry.Hive(paths.hklm, session_info=session_info,
# credentials=credentials, lp_ctx=lp)
#reg.mount_hive(hive, "HKEY_LOCAL_MACHINE")
provision_reg = os.path.join(setup_dir, "provision.reg")
assert os.path.exists(provision_reg)
reg.apply_patchfile(provision_reg)
#reg.apply_patchfile(provision_reg)
message("Setting up templates into %s" % paths.templates)
setup_ldb(setup_dir, "provision_templates.ldif", session_info,
@ -434,7 +434,8 @@ def provision(lp, setup_dir, subobj, message, blank, paths, session_info,
setup_ldb(setup_dir, "provision_partitions.ldif", session_info,
credentials, subobj, lp, paths.samdb)
samdb = open_ldb(session_info, credentials, lp, paths.samdb)
samdb = SamDB(paths.samdb, session_info=session_info,
credentials=credentials, lp=lp)
samdb.transaction_start()
try:
message("Setting up sam.ldb attributes")

View File

@ -22,8 +22,14 @@
import samba
import misc
import ldb
class SamDB(samba.Ldb):
def __init__(self, *args, **kwargs):
super(SamDB, self).__init__(*args, **kwargs)
misc.dsdb_set_global_schema(self)
misc.ldb_register_samba_handlers(self)
def add_foreign(self, domaindn, sid, desc):
"""Add a foreign security principle."""
add = """
@ -39,7 +45,7 @@ description: %s
def setup_name_mapping(self, domaindn, sid, unixname):
"""Setup a mapping between a sam name and a unix name."""
res = self.search(Dn(ldb, domaindn), SCOPE_SUBTREE,
res = self.search(ldb.Dn(self, domaindn), ldb.SCOPE_SUBTREE,
"objectSid=%s" % sid, ["dn"])
assert len(res) == 1, "Failed to find record for objectSid %s" % sid

View File

@ -99,7 +99,7 @@ opts = parser.parse_args()[0]
def message(text):
"""print a message if quiet is not set."""
if opts.quiet:
if not opts.quiet:
print text
hostname = opts.host_name