summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/config.mk6
-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/modules.c1
-rw-r--r--source4/scripting/python/pyrpc.h5
-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.py156
-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.py9
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/sam.py7
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/unix.py19
-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
19 files changed, 245 insertions, 92 deletions
diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk
index a0f5caad3b..15be4ca309 100644
--- a/source4/scripting/python/config.mk
+++ b/source4/scripting/python/config.mk
@@ -23,3 +23,9 @@ python_misc_OBJ_FILES = scripting/python/misc_wrap.o
_PY_FILES = $(shell find scripting/python -name "*.py")
$(foreach pyfile, $(_PY_FILES),$(eval $(call python_py_module_template,$(patsubst scripting/python/%,%,$(pyfile)),$(pyfile))))
+
+installpython:: pythonmods
+ @$(SHELL) $(srcdir)/script/installpython.sh \
+ $(INSTALLPERMS) \
+ $(DESTDIR)$(PYTHONDIR) \
+ scripting/python 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/modules.c b/source4/scripting/python/modules.c
index 08f3c1156c..cbff14c708 100644
--- a/source4/scripting/python/modules.c
+++ b/source4/scripting/python/modules.c
@@ -41,6 +41,7 @@ extern void initepmapper(void);
extern void initinitshutdown(void);
static void initdcerpc_misc(void) {}
extern void initmgmt(void);
+extern void initnet(void);
extern void initatsvc(void);
extern void initsamr(void);
static void initdcerpc_security(void) {}
diff --git a/source4/scripting/python/pyrpc.h b/source4/scripting/python/pyrpc.h
index f4d0f37c39..93d583c10a 100644
--- a/source4/scripting/python/pyrpc.h
+++ b/source4/scripting/python/pyrpc.h
@@ -17,6 +17,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef _PYRPC_H_
+#define _PYRPC_H_
+
#define PY_CHECK_TYPE(type, var, fail) \
if (!type ## _Check(var)) {\
PyErr_Format(PyExc_TypeError, "Expected type %s", type ## _Type.tp_name); \
@@ -32,3 +35,5 @@
#ifndef PyAPI_DATA
# define PyAPI_DATA(RTYPE) extern RTYPE
#endif
+
+#endif /* _PYRPC_H_ */
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 6917aa1a54..0e8840646c 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -87,6 +87,7 @@ class ProvisionNames:
self.domain = None
self.hostname = None
self.sitename = None
+ self.smbconf = None
class ProvisionResult:
def __init__(self):
@@ -262,10 +263,15 @@ def provision_paths_from_lp(lp, dnsdomain):
paths.netlogon = lp.get("path", "netlogon")
+ paths.smbconf = lp.configfile()
+
return paths
+
def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, serverrole=None,
- rootdn=None, domaindn=None, configdn=None, schemadn=None, sitename=None):
+ rootdn=None, domaindn=None, configdn=None, schemadn=None, serverdn=None,
+ sitename=None):
+ """Guess configuration settings to use."""
if hostname is None:
hostname = socket.gethostname().split(".")[0].lower()
@@ -287,7 +293,7 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, serverrole=
if lp.get("realm").upper() != realm:
raise Exception("realm '%s' in %s must match chosen realm '%s'" %
- (lp.get("realm"), smbconf, realm))
+ (lp.get("realm"), lp.configfile(), realm))
dnsdomain = dnsdomain.lower()
@@ -332,6 +338,7 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, serverrole=
names.netbiosname = netbiosname
names.hostname = hostname
names.sitename = sitename
+ names.serverdn = "CN=%s,CN=Servers,CN=%s,CN=Sites,%s" % (netbiosname, sitename, configdn)
return names
@@ -398,6 +405,7 @@ def load_or_make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrol
return lp
+
def setup_name_mappings(samdb, idmap, sid, domaindn, root_uid, nobody_uid,
users_gid, wheel_gid):
"""setup reasonable name mappings for sam names to unix names.
@@ -423,6 +431,7 @@ def setup_name_mappings(samdb, idmap, sid, domaindn, root_uid, nobody_uid,
idmap.setup_name_mapping(sid + "-500", idmap.TYPE_UID, root_uid)
idmap.setup_name_mapping(sid + "-513", idmap.TYPE_GID, users_gid)
+
def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
credentials, names,
serverrole, ldap_backend=None,
@@ -543,9 +552,7 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
samdb.load_ldif_file_add(setup_path("provision_init.ldif"))
message("Setting up sam.ldb rootDSE")
- setup_samdb_rootdse(samdb, setup_path, names.schemadn, names.domaindn, names.hostname,
- names.dnsdomain, names.realm, names.rootdn, names.configdn, names.netbiosname,
- names.sitename)
+ setup_samdb_rootdse(samdb, setup_path, names)
if erase:
message("Erasing data from partitions")
@@ -637,6 +644,7 @@ def setup_registry(path, setup_path, session_info, credentials, lp):
assert os.path.exists(provision_reg)
reg.diff_apply(provision_reg)
+
def setup_idmapdb(path, setup_path, session_info, credentials, lp):
"""Setup the idmap database.
@@ -656,25 +664,23 @@ def setup_idmapdb(path, setup_path, session_info, credentials, lp):
idmap_ldb.load_ldif_file_add(setup_path("idmap_init.ldif"))
return idmap_ldb
-def setup_samdb_rootdse(samdb, setup_path, schemadn, domaindn, hostname,
- dnsdomain, realm, rootdn, configdn, netbiosname,
- sitename):
+
+def setup_samdb_rootdse(samdb, setup_path, names):
"""Setup the SamDB rootdse.
:param samdb: Sam Database handle
:param setup_path: Obtain setup path
"""
setup_add_ldif(samdb, setup_path("provision_rootdse_add.ldif"), {
- "SCHEMADN": schemadn,
- "NETBIOSNAME": netbiosname,
- "DNSDOMAIN": dnsdomain,
- "DEFAULTSITE": sitename,
- "REALM": realm,
- "DNSNAME": "%s.%s" % (hostname, dnsdomain),
- "DOMAINDN": domaindn,
- "ROOTDN": rootdn,
- "CONFIGDN": configdn,
- "VERSION": samba.version(),
+ "SCHEMADN": names.schemadn,
+ "NETBIOSNAME": names.netbiosname,
+ "DNSDOMAIN": names.dnsdomain,
+ "REALM": names.realm,
+ "DNSNAME": "%s.%s" % (names.hostname, names.dnsdomain),
+ "DOMAINDN": names.domaindn,
+ "ROOTDN": names.rootdn,
+ "CONFIGDN": names.configdn,
+ "SERVERDN": names.serverdn,
})
@@ -687,6 +693,7 @@ def setup_self_join(samdb, names,
"CONFIGDN": names.configdn,
"SCHEMADN": names.schemadn,
"DOMAINDN": names.domaindn,
+ "SERVERDN": names.serverdn,
"INVOCATIONID": invocationid,
"NETBIOSNAME": names.netbiosname,
"DEFAULTSITE": names.sitename,
@@ -734,8 +741,6 @@ def setup_samdb(path, setup_path, session_info, credentials, lp,
return samdb
message("Pre-loading the Samba 4 and AD schema")
- samdb = SamDB(path, session_info=session_info,
- credentials=credentials, lp=lp)
samdb.set_domain_sid(domainsid)
if serverrole == "domain controller":
samdb.set_invocation_id(invocationid)
@@ -770,6 +775,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp,
"NETBIOSNAME": names.netbiosname,
"DEFAULTSITE": names.sitename,
"CONFIGDN": names.configdn,
+ "SERVERDN": names.serverdn,
"POLICYGUID": policyguid,
"DOMAINDN": names.domaindn,
"DOMAINGUID_MOD": domainguid_mod,
@@ -800,6 +806,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp,
"NETBIOSNAME": names.netbiosname,
"DEFAULTSITE": names.sitename,
"CONFIGDN": names.configdn,
+ "SERVERDN": names.serverdn
})
message("Setting up sam.ldb Samba4 schema")
@@ -818,6 +825,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp,
"DOMAIN": names.domain,
"SCHEMADN": names.schemadn,
"DOMAINDN": names.domaindn,
+ "SERVERDN": names.serverdn
})
message("Setting up display specifiers")
@@ -842,6 +850,7 @@ def setup_samdb(path, setup_path, session_info, credentials, lp,
"NETBIOSNAME": names.netbiosname,
"DEFAULTSITE": names.sitename,
"CONFIGDN": names.configdn,
+ "SERVERDN": names.serverdn
})
if fill == FILL_FULL:
@@ -879,7 +888,8 @@ FILL_DRS = "DRS"
def provision(setup_dir, message, session_info,
credentials, smbconf=None, targetdir=None, samdb_fill=FILL_FULL, realm=None,
- rootdn=None, domaindn=None, schemadn=None, configdn=None,
+ rootdn=None, domaindn=None, schemadn=None, configdn=None,
+ serverdn=None,
domain=None, hostname=None, hostip=None, hostip6=None,
domainsid=None, adminpass=None, krbtgtpass=None, domainguid=None,
policyguid=None, invocationid=None, machinepass=None,
@@ -932,7 +942,8 @@ def provision(setup_dir, message, session_info,
names = guess_names(lp=lp, hostname=hostname, domain=domain,
dnsdomain=realm, serverrole=serverrole, sitename=sitename,
- rootdn=rootdn, domaindn=domaindn, configdn=configdn, schemadn=schemadn)
+ rootdn=rootdn, domaindn=domaindn, configdn=configdn, schemadn=schemadn,
+ serverdn=serverdn)
paths = provision_paths_from_lp(lp, names.dnsdomain)
@@ -999,20 +1010,25 @@ def provision(setup_dir, message, session_info,
ldap_backend_type=ldap_backend_type)
if lp.get("server role") == "domain controller":
- policy_path = os.path.join(paths.sysvol, names.dnsdomain, "Policies",
- "{" + policyguid + "}")
- os.makedirs(policy_path, 0755)
- os.makedirs(os.path.join(policy_path, "Machine"), 0755)
- os.makedirs(os.path.join(policy_path, "User"), 0755)
- if not os.path.isdir(paths.netlogon):
+ if paths.netlogon is None:
+ message("Existing smb.conf does not have a [netlogon] share, but you are configuring a DC.")
+ message("Please either remove %s or see the template at %s" %
+ ( paths.smbconf, setup_path("provision.smb.conf.dc")))
+ assert(paths.netlogon is not None)
+
+ if paths.sysvol is None:
+ message("Existing smb.conf does not have a [sysvol] share, but you are configuring a DC.")
+ message("Please either remove %s or see the template at %s" %
+ (paths.smbconf, setup_path("provision.smb.conf.dc")))
+ assert(paths.sysvol is not None)
+
+ policy_path = os.path.join(paths.sysvol, names.dnsdomain, "Policies",
+ "{" + policyguid + "}")
+ os.makedirs(policy_path, 0755)
+ os.makedirs(os.path.join(policy_path, "Machine"), 0755)
+ os.makedirs(os.path.join(policy_path, "User"), 0755)
+ if not os.path.isdir(paths.netlogon):
os.makedirs(paths.netlogon, 0755)
- secrets_ldb = Ldb(paths.secrets, session_info=session_info,
- credentials=credentials, lp=lp)
- secretsdb_become_dc(secrets_ldb, setup_path, domain=domain, realm=names.realm,
- netbiosname=names.netbiosname, domainsid=domainsid,
- keytab_path=paths.keytab, samdb_url=paths.samdb,
- dns_keytab_path=paths.dns_keytab, dnspass=dnspass,
- machinepass=machinepass, dnsdomain=names.dnsdomain)
if samdb_fill == FILL_FULL:
setup_name_mappings(samdb, idmap, str(domainsid), names.domaindn,
@@ -1024,6 +1040,14 @@ def provision(setup_dir, message, session_info,
# Only make a zone file on the first DC, it should be replicated with DNS replication
if serverrole == "domain controller":
+ secrets_ldb = Ldb(paths.secrets, session_info=session_info,
+ credentials=credentials, lp=lp)
+ secretsdb_become_dc(secrets_ldb, setup_path, domain=domain, realm=names.realm,
+ netbiosname=names.netbiosname, domainsid=domainsid,
+ keytab_path=paths.keytab, samdb_url=paths.samdb,
+ dns_keytab_path=paths.dns_keytab, dnspass=dnspass,
+ machinepass=machinepass, dnsdomain=names.dnsdomain)
+
samdb = SamDB(paths.samdb, session_info=session_info,
credentials=credentials, lp=lp)
@@ -1046,8 +1070,8 @@ def provision(setup_dir, message, session_info,
message("Please install the phpLDAPadmin configuration located at %s into /etc/phpldapadmin/config.php" % paths.phpldapadminconfig)
- message("Once the above files are installed, your server will be ready to use")
- message("Server Type: %s" % serverrole)
+ message("Once the above files are installed, your Samba4 server will be ready to use")
+ message("Server Role: %s" % serverrole)
message("Hostname: %s" % names.hostname)
message("NetBIOS Domain: %s" % names.domain)
message("DNS Domain: %s" % names.dnsdomain)
@@ -1061,27 +1085,33 @@ def provision(setup_dir, message, session_info,
result.samdb = samdb
return result
+
def provision_become_dc(setup_dir=None,
smbconf=None, targetdir=None, realm=None,
rootdn=None, domaindn=None, schemadn=None, configdn=None,
+ serverdn=None,
domain=None, hostname=None, domainsid=None,
adminpass=None, krbtgtpass=None, domainguid=None,
policyguid=None, invocationid=None, machinepass=None,
dnspass=None, root=None, nobody=None, nogroup=None, users=None,
wheel=None, backup=None, aci=None, serverrole=None,
- ldap_backend=None, ldap_backend_type=None, sitename=DEFAULTSITE):
+ ldap_backend=None, ldap_backend_type=None, sitename=None):
def message(text):
"""print a message if quiet is not set."""
print text
- provision(setup_dir, message, system_session(), None,
+ return provision(setup_dir, message, system_session(), None,
smbconf=smbconf, targetdir=targetdir, samdb_fill=FILL_DRS, realm=realm,
- rootdn=rootdn, domaindn=domaindn, schemadn=schemadn, configdn=configdn,
+ rootdn=rootdn, domaindn=domaindn, schemadn=schemadn, configdn=configdn, serverdn=serverdn,
domain=domain, hostname=hostname, hostip="127.0.0.1", domainsid=domainsid, machinepass=machinepass, serverrole="domain controller", sitename=sitename);
-def setup_db_config(setup_path, file, dbdir):
+def setup_db_config(setup_path, dbdir):
+ """Setup a Berkeley database.
+
+ :param setup_path: Setup path function.
+ :param dbdir: Database directory."""
if not os.path.isdir(os.path.join(dbdir, "bdb-logs")):
os.makedirs(os.path.join(dbdir, "bdb-logs"), 0700);
if not os.path.isdir(os.path.join(dbdir, "tmp")):
@@ -1096,7 +1126,7 @@ def provision_backend(setup_dir=None, message=None,
smbconf=None, targetdir=None, realm=None,
rootdn=None, domaindn=None, schemadn=None, configdn=None,
domain=None, hostname=None, adminpass=None, root=None, serverrole=None,
- ldap_backend_type=None):
+ ldap_backend_type=None, ldap_backend_port=None):
def setup_path(file):
return os.path.join(setup_dir, file)
@@ -1136,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"),
@@ -1144,7 +1175,12 @@ def provision_backend(setup_dir=None, message=None,
{"SCHEMADN": names.schemadn})
if ldap_backend_type == "fedora-ds":
- setup_file(setup_path("fedora-ds.inf"), paths.fedoradsinf,
+ if ldap_backend_port is not None:
+ serverport = "ServerPort=%d" % ldap_backend_port
+ else:
+ serverport = ""
+
+ setup_file(setup_path("fedorads.inf"), paths.fedoradsinf,
{"ROOT": root,
"HOSTNAME": hostname,
"DNSDOMAIN": names.dnsdomain,
@@ -1152,19 +1188,18 @@ def provision_backend(setup_dir=None, message=None,
"DOMAINDN": names.domaindn,
"LDAPMANAGERDN": names.ldapmanagerdn,
"LDAPMANAGERPASS": adminpass,
- "SERVERPORT": ""})
+ "SERVERPORT": serverport})
- setup_file(setup_path("fedora-partitions.ldif"), paths.fedoradspartitions,
+ setup_file(setup_path("fedorads-partitions.ldif"), paths.fedoradspartitions,
{"CONFIGDN": names.configdn,
"SCHEMADN": names.schemadn,
})
- setup_file(setup_path("fedora-partitions.ldif"), paths.fedoradspartitions,
- {"CONFIGDN": names.configdn,
- "SCHEMADN": names.schemadn,
- })
mapping = "schema-map-fedora-ds-1.0"
backend_schema = "99_ad.ldif"
+
+ slapdcommand="Initailise Fedora DS with: setup-ds.pl --file=%s" % paths.fedoradsinf
+
elif ldap_backend_type == "openldap":
attrs = ["linkID", "lDAPDisplayName"]
res = schemadb.search(expression="(&(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1)))(objectclass=attributeSchema))", base=names.schemadn, scope=SCOPE_SUBTREE, attrs=attrs);
@@ -1207,22 +1242,33 @@ 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, "db", "user"))
- setup_db_config(setup_path, file, os.path.join(paths.ldapdir, "db", "config"))
- setup_db_config(setup_path, file, os.path.join(paths.ldapdir, "db", "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"
-
ldapi_uri = "ldapi://" + urllib.quote(os.path.join(paths.private_dir, "ldap", "ldapi"), safe="")
- message("Start slapd with: slapd -f " + paths.ldapdir + "/slapd.conf -h " + ldapi_uri)
-
+ if ldap_backend_port is not None:
+ server_port_string = " -h ldap://0.0.0.0:%d" % ldap_backend_port
+ else:
+ server_port_string = ""
+ slapdcommand="Start slapd with: slapd -f " + paths.ldapdir + "/slapd.conf -h " + ldapi_uri + server_port_string
schema_command = "bin/ad2oLschema --option=convert:target=" + ldap_backend_type + " -I " + setup_path(mapping) + " -H tdb://" + schemadb_path + " -O " + os.path.join(paths.ldapdir, backend_schema);
os.system(schema_command)
+ message("Your %s Backend for Samba4 is now configured, and is ready to be started" % ( ldap_backend_type) )
+ message("Server Role: %s" % serverrole)
+ message("Hostname: %s" % names.hostname)
+ message("DNS Domain: %s" % names.dnsdomain)
+ message("Base DN: %s" % names.domaindn)
+ message("LDAP admin DN: %s" % names.ldapmanagerdn)
+ message("LDAP admin password: %s" % adminpass)
+ message(slapdcommand)
+
def create_phpldapadmin_config(path, setup_path, ldapi_uri):
"""Create a PHP LDAP admin configuration file.
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 8c1a8bec71..6c43632d97 100644
--- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
+++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -19,18 +19,17 @@
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))
def test_echodata(self):
- self.assertEquals([1,2,3], self.conn.EchoData(3, [1, 2, 3]))
+ self.assertEquals([1,2,3], self.conn.EchoData([1, 2, 3]))
def test_call(self):
self.assertEquals(u"foobar", self.conn.TestCall(u"foobar"))
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 99c84c08da..78a987cedd 100644
--- a/source4/scripting/python/samba/tests/dcerpc/unix.py
+++ b/source4/scripting/python/samba/tests/dcerpc/unix.py
@@ -18,13 +18,20 @@
#
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):
- (count, infos) = self.conn.GetPWUid(1, [0])
- self.assertEquals(1, len(infos))
+ infos = self.conn.GetPWUid(range(512))
+ self.assertEquals(512, len(infos))
+ self.assertEquals("/bin/false", infos[0].shell)
+ self.assertTrue(isinstance(infos[0].homedir, unicode))
+
+ def test_gidtosid(self):
+ self.conn.GidToSid(1000)
+
+ def test_uidtosid(self):
+ self.conn.UidToSid(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;
}