summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-04-15 22:08:49 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-04-15 22:08:49 +0200
commit038987543043346cdcd8a4b8fe2970cd1350a7a7 (patch)
tree63df88d6cc354bd766a4b9b3f36d3e43bf67872b /source4/scripting/python
parentf01c377bc039b776ded213f455cdb79d682ae7b2 (diff)
parentb708a3d1e7f8d98bc6cedad8d405b1434d32a22e (diff)
downloadsamba-038987543043346cdcd8a4b8fe2970cd1350a7a7.tar.gz
samba-038987543043346cdcd8a4b8fe2970cd1350a7a7.tar.bz2
samba-038987543043346cdcd8a4b8fe2970cd1350a7a7.zip
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into registry
(This used to be commit 70ebb22c3df178a26c26c0a25c5722ff9ccdb0b4)
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/config.mk34
-rw-r--r--source4/scripting/python/misc.i5
-rw-r--r--source4/scripting/python/misc.py1
-rw-r--r--source4/scripting/python/misc_wrap.c45
-rw-r--r--source4/scripting/python/pytalloc.c4
-rw-r--r--source4/scripting/python/samba/getopt.py10
-rw-r--r--source4/scripting/python/samba/idmap.py7
-rw-r--r--source4/scripting/python/samba/provision.py7
-rw-r--r--source4/scripting/python/samba/samdb.py28
-rw-r--r--source4/scripting/python/samba/tests/__init__.py15
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/registry.py9
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/rpcecho.py7
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/sam.py7
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/unix.py9
-rw-r--r--source4/scripting/python/samba/tests/provision.py2
-rw-r--r--source4/scripting/python/samba/tests/samdb.py4
-rw-r--r--source4/scripting/python/uuidmodule.c4
17 files changed, 134 insertions, 64 deletions
diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk
index 09c77813ca..59f628fe18 100644
--- a/source4/scripting/python/config.mk
+++ b/source4/scripting/python/config.mk
@@ -1,49 +1,29 @@
[BINARY::smbpython]
PRIVATE_DEPENDENCIES = LIBPYTHON
-OBJ_FILES = smbpython.o
+
+smbpython_OBJ_FILES = scripting/python/smbpython.o
[SUBSYSTEM::LIBPYTHON]
PUBLIC_DEPENDENCIES = EXT_LIB_PYTHON
INIT_FUNCTION_SENTINEL = { NULL, NULL }
-OBJ_FILES = modules.o pytalloc.o
+
+LIBPYTHON_OBJ_FILES = $(addprefix scripting/python/, modules.o pytalloc.o)
[PYTHON::python_uuid]
PRIVATE_DEPENDENCIES = LIBNDR
-OBJ_FILES = uuidmodule.o
+
+python_uuid_OBJ_FILES = scripting/python/uuidmodule.o
[PYTHON::python_misc]
PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS
SWIG_FILE = misc.i
-# Swig extensions
-swig:: pythonmods
-
-.SUFFIXES: _wrap.c .i
-
-.i_wrap.c:
- [ "$(SWIG)" = "no" ] || $(SWIG) -O -Wall -I$(srcdir)/scripting/swig -python -keyword $<
-
-realdistclean::
- @echo "Removing SWIG output files"
- # FIXME: Remove _wrap.c files
-
-pythonmods:: $(PYTHON_DSOS) $(PYTHON_PYS)
+python_misc_OBJ_FILES = scripting/python/misc_wrap.o
PYDOCTOR_MODULES=bin/python/ldb.py bin/python/auth.py bin/python/credentials.py bin/python/registry.py bin/python/tdb.py bin/python/security.py bin/python/events.py bin/python/net.py
-pydoctor:: pythonmods
- LD_LIBRARY_PATH=bin/shared PYTHONPATH=bin/python pydoctor --project-name=Samba --make-html --docformat=restructuredtext --add-package scripting/python/samba/ $(addprefix --add-module , $(PYDOCTOR_MODULES))
-
-bin/python/%.py:
- mkdir -p $(@D)
- cp $< $@
-
installpython:: pythonmods
@$(SHELL) $(srcdir)/script/installpython.sh \
$(INSTALLPERMS) \
$(DESTDIR)$(PYTHONDIR) \
scripting/python bin/python
-
-clean::
- @echo "Removing python modules"
- @rm -rf bin/python/*
diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i
index e04e6a6906..6fa3bc93e3 100644
--- a/source4/scripting/python/misc.i
+++ b/source4/scripting/python/misc.i
@@ -78,3 +78,8 @@ bool dsdb_set_ntds_invocation_id(struct ldb_context *ldb, const char *guid)
return samdb_set_ntds_invocation_id(ldb, &invocation_id_in);
}
%}
+
+char *private_path(TALLOC_CTX* mem_ctx,
+ struct loadparm_context *lp_ctx,
+ const char *name);
+
diff --git a/source4/scripting/python/misc.py b/source4/scripting/python/misc.py
index 2fc7fe37e7..f1da4c687a 100644
--- a/source4/scripting/python/misc.py
+++ b/source4/scripting/python/misc.py
@@ -71,5 +71,6 @@ version = _misc.version
dsdb_set_global_schema = _misc.dsdb_set_global_schema
ldb_register_samba_handlers = _misc.ldb_register_samba_handlers
dsdb_set_ntds_invocation_id = _misc.dsdb_set_ntds_invocation_id
+private_path = _misc.private_path
diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c
index 579d1f379f..4944515d15 100644
--- a/source4/scripting/python/misc_wrap.c
+++ b/source4/scripting/python/misc_wrap.c
@@ -3153,6 +3153,50 @@ fail:
}
+SWIGINTERN PyObject *_wrap_private_path(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+ PyObject *resultobj = 0;
+ TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ;
+ struct loadparm_context *arg2 = (struct loadparm_context *) 0 ;
+ char *arg3 = (char *) 0 ;
+ char *result = 0 ;
+ void *argp2 = 0 ;
+ int res2 = 0 ;
+ int res3 ;
+ char *buf3 = 0 ;
+ int alloc3 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ char * kwnames[] = {
+ (char *) "lp_ctx",(char *) "name", NULL
+ };
+
+ arg2 = loadparm_init(NULL);
+ arg1 = NULL;
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:private_path",kwnames,&obj0,&obj1)) SWIG_fail;
+ if (obj0) {
+ res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_loadparm_context, 0 | 0 );
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "private_path" "', argument " "2"" of type '" "struct loadparm_context *""'");
+ }
+ arg2 = (struct loadparm_context *)(argp2);
+ }
+ if (obj1) {
+ res3 = SWIG_AsCharPtrAndSize(obj1, &buf3, NULL, &alloc3);
+ if (!SWIG_IsOK(res3)) {
+ SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "private_path" "', argument " "3"" of type '" "char const *""'");
+ }
+ arg3 = (char *)(buf3);
+ }
+ result = (char *)private_path(arg1,arg2,(char const *)arg3);
+ resultobj = SWIG_FromCharPtr((const char *)result);
+ if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
+ return resultobj;
+fail:
+ if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
+ 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},
@@ -3164,6 +3208,7 @@ static PyMethodDef SwigMethods[] = {
{ (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},
{ (char *)"dsdb_set_ntds_invocation_id", (PyCFunction) _wrap_dsdb_set_ntds_invocation_id, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"private_path", (PyCFunction) _wrap_private_path, METH_VARARGS | METH_KEYWORDS, NULL},
{ NULL, NULL, 0, NULL }
};
diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c
index d8d3efe69c..aa0ae9bf90 100644
--- a/source4/scripting/python/pytalloc.c
+++ b/source4/scripting/python/pytalloc.c
@@ -39,7 +39,7 @@ PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx,
PyObject *py_talloc_default_repr(PyObject *py_obj)
{
py_talloc_Object *obj = (py_talloc_Object *)py_obj;
+ PyTypeObject *type = (PyTypeObject*)PyObject_Type((PyObject *)obj);
- return PyString_FromFormat("<talloc: %s>",
- talloc_get_name(obj->talloc_ctx));
+ return PyString_FromFormat("<%s>", type->tp_name);
}
diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py
index 82cb004b62..7ec684a9d6 100644
--- a/source4/scripting/python/samba/getopt.py
+++ b/source4/scripting/python/samba/getopt.py
@@ -35,12 +35,14 @@ class SambaOptions(optparse.OptionGroup):
self._configfile = arg
def get_loadparm(self):
- import param
+ import os, param
lp = param.LoadParm()
- if self._configfile is None:
- lp.load_default()
- else:
+ if self._configfile is not None:
lp.load(self._configfile)
+ elif os.getenv("SMB_CONF_PATH") is not None:
+ lp.load(os.getenv("SMB_CONF_PATH"))
+ else:
+ lp.load_default()
return lp
class VersionOptions(optparse.OptionGroup):
diff --git a/source4/scripting/python/samba/idmap.py b/source4/scripting/python/samba/idmap.py
index 355565968a..16efcd0470 100644
--- a/source4/scripting/python/samba/idmap.py
+++ b/source4/scripting/python/samba/idmap.py
@@ -21,6 +21,7 @@
"""Convenience functions for using the idmap database."""
import samba
+import misc
import ldb
class IDmapDB(samba.Ldb):
@@ -37,11 +38,17 @@ class IDmapDB(samba.Ldb):
:param url: URL of the database.
"""
+ self.lp = lp
+
super(IDmapDB, self).__init__(session_info=session_info, credentials=credentials,
modules_dir=modules_dir, lp=lp)
if url:
self.connect(url)
+ else:
+ self.connect(lp.get("idmap database"))
+ def connect(self, url):
+ super(IDmapDB, self).connect(misc.private_path(self.lp, url))
def setup_name_mapping(self, sid, type, unixid):
"""Setup a mapping between a sam name and a unix name.
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index a8d188e7a3..0e8840646c 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -1166,6 +1166,7 @@ def provision_backend(setup_dir=None, message=None,
"NETBIOSNAME": names.netbiosname,
"DEFAULTSITE": DEFAULTSITE,
"CONFIGDN": names.configdn,
+ "SERVERDN": names.serverdn
})
setup_add_ldif(schemadb, setup_path("schema_samba4.ldif"),
@@ -1241,9 +1242,9 @@ refint_attributes""" + refint_attributes + "\n";
setup_file(setup_path("modules.conf"), paths.modulesconf,
{"REALM": names.realm})
- setup_db_config(setup_path, file, os.path.join(paths.ldapdir, "user"))
- setup_db_config(setup_path, file, os.path.join(paths.ldapdir, "config"))
- setup_db_config(setup_path, file, os.path.join(paths.ldapdir, "schema"))
+ setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "user")))
+ setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "config")))
+ setup_db_config(setup_path, os.path.join(paths.ldapdir, os.path.join("db", "schema")))
mapping = "schema-map-openldap-2.3"
backend_schema = "backend-schema.schema"
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index bc3eef7879..198d1e9f5c 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -25,20 +25,29 @@
import samba
import misc
import ldb
+from samba.idmap import IDmapDB
+import pwd
class SamDB(samba.Ldb):
"""The SAM database."""
+
def __init__(self, url=None, session_info=None, credentials=None,
modules_dir=None, lp=None):
"""Open the Sam Database.
:param url: URL of the database.
"""
+ self.lp = lp
super(SamDB, self).__init__(session_info=session_info, credentials=credentials,
modules_dir=modules_dir, lp=lp)
assert misc.dsdb_set_global_schema(self) == 0
if url:
self.connect(url)
+ else:
+ self.connect(lp.get("sam database"))
+
+ def connect(self, url):
+ super(SamDB, self).connect(misc.private_path(self.lp, url))
def add_foreign(self, domaindn, sid, desc):
"""Add a foreign security principle."""
@@ -101,10 +110,27 @@ userAccountControl: %u
# now the real work
self.add({"dn": user_dn,
"sAMAccountName": username,
- "unixName": unixname,
"sambaPassword": password,
"objectClass": "user"})
+ res = self.search(user_dn, scope=ldb.SCOPE_BASE,
+ expression="objectclass=*",
+ attrs=["objectSid"])
+ assert(len(res) == 1)
+ user_sid = self.schema_format_value("objectSid", res[0]["objectSid"][0])
+
+
+ try:
+ idmap = IDmapDB(lp=self.lp)
+
+ user = pwd.getpwnam(unixname)
+ # setup ID mapping for this UID
+
+ idmap.setup_name_mapping(user_sid, idmap.TYPE_UID, user[2])
+
+ except KeyError:
+ pass
+
# modify the userAccountControl to remove the disabled bit
self.enable_account(user_dn)
self.transaction_commit()
diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py
index c8673d3fae..e29b4a87d5 100644
--- a/source4/scripting/python/samba/tests/__init__.py
+++ b/source4/scripting/python/samba/tests/__init__.py
@@ -85,8 +85,13 @@ class LdbExtensionTests(TestCaseInTempDir):
os.unlink(path)
-def get_loadparm():
- import param
- lp = param.LoadParm()
- lp.load(os.getenv("SMB_CONF_PATH"))
- return lp
+cmdline_loadparm = None
+cmdline_credentials = None
+
+class RpcInterfaceTestCase(unittest.TestCase):
+ def get_loadparm(self):
+ assert cmdline_loadparm is not None
+ return cmdline_loadparm
+
+ def get_credentials(self):
+ return cmdline_credentials
diff --git a/source4/scripting/python/samba/tests/dcerpc/registry.py b/source4/scripting/python/samba/tests/dcerpc/registry.py
index 147acc5098..1afdc582a7 100644
--- a/source4/scripting/python/samba/tests/dcerpc/registry.py
+++ b/source4/scripting/python/samba/tests/dcerpc/registry.py
@@ -18,14 +18,13 @@
#
import winreg
-from param import LoadParm
import unittest
-from samba.tests import get_loadparm
+from samba.tests import RpcInterfaceTestCase
-class WinregTests(unittest.TestCase):
+class WinregTests(RpcInterfaceTestCase):
def setUp(self):
- lp_ctx = get_loadparm()
- self.conn = winreg.winreg("ncalrpc:", lp_ctx)
+ self.conn = winreg.winreg("ncalrpc:", self.get_loadparm(),
+ self.get_credentials())
def get_hklm(self):
return self.conn.OpenHKLM(None,
diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
index 484af9490c..6c43632d97 100644
--- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
+++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -19,12 +19,11 @@
import echo
import unittest
-from samba.tests import get_loadparm
+from samba.tests import RpcInterfaceTestCase
-class RpcEchoTests(unittest.TestCase):
+class RpcEchoTests(RpcInterfaceTestCase):
def setUp(self):
- lp_ctx = get_loadparm()
- self.conn = echo.rpcecho("ncalrpc:", lp_ctx)
+ self.conn = echo.rpcecho("ncalrpc:", self.get_loadparm())
def test_addone(self):
self.assertEquals(2, self.conn.AddOne(1))
diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py
index 96348f2f69..8ef12dad86 100644
--- a/source4/scripting/python/samba/tests/dcerpc/sam.py
+++ b/source4/scripting/python/samba/tests/dcerpc/sam.py
@@ -18,12 +18,11 @@
#
import samr
-import unittest
-from samba.tests import get_loadparm
+from samba.tests import RpcInterfaceTestCase
-class SamrTests(unittest.TestCase):
+class SamrTests(RpcInterfaceTestCase):
def setUp(self):
- self.conn = samr.samr("ncalrpc:", get_loadparm())
+ self.conn = samr.samr("ncalrpc:", self.get_loadparm())
def test_connect5(self):
(level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1())
diff --git a/source4/scripting/python/samba/tests/dcerpc/unix.py b/source4/scripting/python/samba/tests/dcerpc/unix.py
index b2577ec898..43978ac9dc 100644
--- a/source4/scripting/python/samba/tests/dcerpc/unix.py
+++ b/source4/scripting/python/samba/tests/dcerpc/unix.py
@@ -18,16 +18,17 @@
#
import unixinfo
-import unittest
-from samba.tests import get_loadparm
+from samba.tests import RpcInterfaceTestCase
-class UnixinfoTests(unittest.TestCase):
+class UnixinfoTests(RpcInterfaceTestCase):
def setUp(self):
- self.conn = unixinfo.unixinfo("ncalrpc:", get_loadparm())
+ self.conn = unixinfo.unixinfo("ncalrpc:", self.get_loadparm())
def test_getpwuid(self):
infos = self.conn.GetPWUid(range(512))
self.assertEquals(512, len(infos))
+ self.assertEquals("", infos[0].shell)
+ self.assertEquals("", infos[0].homedir)
def test_gidtosid(self):
self.conn.GidToSid(1000)
diff --git a/source4/scripting/python/samba/tests/provision.py b/source4/scripting/python/samba/tests/provision.py
index 514582cbe4..b9e0e16d3c 100644
--- a/source4/scripting/python/samba/tests/provision.py
+++ b/source4/scripting/python/samba/tests/provision.py
@@ -24,7 +24,7 @@ from ldb import Dn
import param
import unittest
-lp = samba.tests.get_loadparm()
+lp = samba.tests.cmdline_loadparm
setup_dir = "setup"
def setup_path(file):
diff --git a/source4/scripting/python/samba/tests/samdb.py b/source4/scripting/python/samba/tests/samdb.py
index 3745dba6fc..0e175bf936 100644
--- a/source4/scripting/python/samba/tests/samdb.py
+++ b/source4/scripting/python/samba/tests/samdb.py
@@ -21,7 +21,7 @@ from credentials import Credentials
import os
from samba.provision import setup_samdb
from samba.samdb import SamDB
-from samba.tests import get_loadparm, TestCaseInTempDir
+from samba.tests import cmdline_loadparm, TestCaseInTempDir
import security
from unittest import TestCase
import uuid
@@ -43,7 +43,7 @@ class SamDBTestCase(TestCaseInTempDir):
hostguid = uuid.random()
path = os.path.join(self.tempdir, "samdb.ldb")
self.samdb = setup_samdb(path, setup_path, system_session(), creds,
- get_loadparm(), schemadn, configdn,
+ cmdline_loadparm, schemadn, configdn,
self.domaindn, "example.com", "EXAMPLE.COM",
"FOO", lambda x: None, "foo", domaindn,
False, domainsid, "# no aci", domainguid,
diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c
index cd9a1cb4d5..18cfb6ce32 100644
--- a/source4/scripting/python/uuidmodule.c
+++ b/source4/scripting/python/uuidmodule.c
@@ -27,7 +27,7 @@ static PyObject *uuid_random(PyObject *self, PyObject *args)
PyObject *pyobj;
char *str;
- if (!PyArg_ParseTuple(args, (char *)""))
+ if (!PyArg_ParseTuple(args, ""))
return NULL;
guid = GUID_random();
@@ -52,7 +52,7 @@ static PyMethodDef methods[] = {
void inituuid(void)
{
- PyObject *mod = Py_InitModule3((char *)"uuid", methods, "UUID helper routines");
+ PyObject *mod = Py_InitModule3("uuid", methods, "UUID helper routines");
if (mod == NULL)
return;
}