diff options
Diffstat (limited to 'source4/scripting')
-rw-r--r-- | source4/scripting/ejs/smbcalls_param.c | 8 | ||||
-rw-r--r-- | source4/scripting/python/misc_wrap.c | 25 | ||||
-rw-r--r-- | source4/scripting/python/samba/__init__.py | 56 | ||||
-rw-r--r-- | source4/scripting/python/samba/provision.py | 30 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/__init__.py | 2 |
5 files changed, 64 insertions, 57 deletions
diff --git a/source4/scripting/ejs/smbcalls_param.c b/source4/scripting/ejs/smbcalls_param.c index 830c45d978..5fbb0bb017 100644 --- a/source4/scripting/ejs/smbcalls_param.c +++ b/source4/scripting/ejs/smbcalls_param.c @@ -45,7 +45,7 @@ static int ejs_param_get(MprVarHandle eid, int argc, char **argv) if (argc == 2) { ret = param_get_string(ctx, argv[0], argv[1]); } else { - ret = param_get_string(ctx, NULL, argv[0]); + ret = param_get_string(ctx, argv[0], NULL); } if (ret) { @@ -78,7 +78,7 @@ static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv) if (argc == 2) { ret = param_get_string_list(ctx, argv[0], argv[1], NULL); } else { - ret = param_get_string_list(ctx, NULL, argv[0], NULL); + ret = param_get_string_list(ctx, argv[0], NULL, NULL); } if (ret != NULL) { @@ -123,9 +123,9 @@ static int ejs_param_set(MprVarHandle eid, int argc, struct MprVar **argv) list = mprToList(mprMemCtx(), value); if (list) { - ret = param_set_string_list(ctx, section, paramname, list); + ret = param_set_string_list(ctx, paramname, list, section); } else { - ret = param_set_string(ctx, section, paramname, mprToString(value)); + ret = param_set_string(ctx, paramname, mprToString(value), section); } mpr_Return(eid, mprCreateBoolVar(ret)); diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c index f5e23d0407..25b6389f6a 100644 --- a/source4/scripting/python/misc_wrap.c +++ b/source4/scripting/python/misc_wrap.c @@ -2474,16 +2474,17 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) #define SWIGTYPE_p_loadparm_service swig_types[12] #define SWIGTYPE_p_long_long swig_types[13] #define SWIGTYPE_p_param_context swig_types[14] -#define SWIGTYPE_p_param_section swig_types[15] -#define SWIGTYPE_p_short swig_types[16] -#define SWIGTYPE_p_signed_char swig_types[17] -#define SWIGTYPE_p_unsigned_char swig_types[18] -#define SWIGTYPE_p_unsigned_int swig_types[19] -#define SWIGTYPE_p_unsigned_long swig_types[20] -#define SWIGTYPE_p_unsigned_long_long swig_types[21] -#define SWIGTYPE_p_unsigned_short swig_types[22] -static swig_type_info *swig_types[24]; -static swig_module_info swig_module = {swig_types, 23, 0, 0, 0, 0}; +#define SWIGTYPE_p_param_opt swig_types[15] +#define SWIGTYPE_p_param_section swig_types[16] +#define SWIGTYPE_p_short swig_types[17] +#define SWIGTYPE_p_signed_char swig_types[18] +#define SWIGTYPE_p_unsigned_char swig_types[19] +#define SWIGTYPE_p_unsigned_int swig_types[20] +#define SWIGTYPE_p_unsigned_long swig_types[21] +#define SWIGTYPE_p_unsigned_long_long swig_types[22] +#define SWIGTYPE_p_unsigned_short swig_types[23] +static swig_type_info *swig_types[25]; +static swig_module_info swig_module = {swig_types, 24, 0, 0, 0, 0}; #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) @@ -2896,6 +2897,7 @@ static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "stru static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *|param_opt *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0}; @@ -2921,6 +2923,7 @@ static swig_type_info *swig_type_initial[] = { &_swigt__p_loadparm_service, &_swigt__p_long_long, &_swigt__p_param_context, + &_swigt__p_param_opt, &_swigt__p_param_section, &_swigt__p_short, &_swigt__p_signed_char, @@ -2946,6 +2949,7 @@ static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_con static swig_cast_info _swigc__p_loadparm_service[] = { {&_swigt__p_loadparm_service, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_param_context[] = { {&_swigt__p_param_context, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_param_opt[] = { {&_swigt__p_param_opt, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_param_section[] = { {&_swigt__p_param_section, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}}; static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}}; @@ -2971,6 +2975,7 @@ static swig_cast_info *swig_cast_initial[] = { _swigc__p_loadparm_service, _swigc__p_long_long, _swigc__p_param_context, + _swigc__p_param_opt, _swigc__p_param_section, _swigc__p_short, _swigc__p_signed_char, diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 56adce4473..511dcd905a 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -33,11 +33,9 @@ if _in_source_tree(): default_ldb_modules_dir = "%s/bin/modules/ldb" % srcdir -import misc import ldb -ldb.Ldb.set_credentials = misc.ldb_set_credentials -ldb.Ldb.set_session_info = misc.ldb_set_session_info -ldb.Ldb.set_loadparm = misc.ldb_set_loadparm +import credentials +import misc class Ldb(ldb.Ldb): """Simple Samba-specific LDB subclass that takes care @@ -47,38 +45,42 @@ class Ldb(ldb.Ldb): not necessarily the Sam database. For Sam-specific helper functions see samdb.py. """ - def __init__(url, session_info=None, credentials=None, modules_dir=None, - lp=None): + def __init__(self, url=None, session_info=None, credentials=None, + modules_dir=None, lp=None): """Open a Samba Ldb file. - :param url: LDB Url to open + :param url: Optional LDB URL to open :param session_info: Optional session information :param credentials: Optional credentials, defaults to anonymous. - :param modules_dir: Modules directory, automatically set if not specified. + :param modules_dir: Modules directory, if not the default. :param lp: Loadparm object, optional. This is different from a regular Ldb file in that the Samba-specific modules-dir is used by default and that credentials and session_info can be passed through (required by some modules). """ - super(self, Ldb).__init__() - import ldb - ret = ldb.Ldb() - if modules_dir is None: - modules_dir = default_ldb_modules_dir + super(Ldb, self).__init__() + if modules_dir is not None: - ret.set_modules_dir(modules_dir) - def samba_debug(level,text): - print "%d %s" % (level, text) + self.set_modules_dir(modules_dir) + elif default_ldb_modules_dir is not None: + self.set_modules_dir(default_ldb_modules_dir) + if credentials is not None: - ldb.set_credentials(credentials) + self.set_credentials(self, credentials) + if session_info is not None: - ldb.set_session_info(session_info) + self.set_session_info(self, session_info) + if lp is not None: - ldb.set_loadparm(lp) - #ret.set_debug(samba_debug) - ret.connect(url) - return ret + self.set_loadparm(self, lp) + + if url: + self.connect(url) + + set_credentials = misc.ldb_set_credentials + set_session_info = misc.ldb_set_session_info + set_loadparm = misc.ldb_set_loadparm def searchone(self, basedn, expression, attribute): """Search for one attribute as a string.""" @@ -93,19 +95,19 @@ class Ldb(ldb.Ldb): for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES", "@OPTIONS", "@PARTITION", "@KLUDGEACL"]: try: - self.delete(Dn(self, attr)) - except LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): + self.delete(ldb.Dn(self, attr)) + except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _): # Ignore missing dn errors pass - basedn = Dn(self, "") + basedn = ldb.Dn(self, "") # and the rest - for msg in self.search(basedn, SCOPE_SUBTREE, + for msg in self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"]): self.delete(msg.dn) - res = self.search(basedn, SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"]) + res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"]) assert len(res) == 0 diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 60dcf06c83..5332a9f9ff 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -16,6 +16,7 @@ import param import registry from samba import Ldb, substitute_var, valid_netbios_name from samba.samdb import SamDB +import security from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \ LDB_ERR_NO_SUCH_OBJECT, timestring @@ -69,7 +70,7 @@ class ProvisionSettings(object): "DOMAINDN_LDB": self.domaindn_ldb, "DOMAINDN_MOD": "pdc_fsmo,password_hash", "DOMAINDN_MOD2": ",objectguid", - "DOMAINSID": self.domainsid, + "DOMAINSID": str(self.domainsid), "MODULES_LIST": ",".join(self.modules_list), "CONFIGDN_MOD": "naming_fsmo", "CONFIGDN_MOD2": ",objectguid", @@ -115,13 +116,13 @@ class ProvisionSettings(object): if not valid_netbios_name(self.netbiosname): raise InvalidNetbiosName(self.netbiosname) - if lp.get("workgroup").upper() != self.domain.upper(): + if lp.get_string("workgroup").upper() != self.domain.upper(): raise Error("workgroup '%s' in smb.conf must match chosen domain '%s'\n", - lp.get("workgroup"), self.domain) + lp.get_string("workgroup"), self.domain) - if lp.get("realm").upper() != self.realm.upper(): + if lp.get_string("realm").upper() != self.realm.upper(): raise Error("realm '%s' in smb.conf must match chosen realm '%s'\n" % - (lp.get("realm"), self.realm)) + (lp.get_string("realm"), self.realm)) class ProvisionPaths: @@ -147,9 +148,9 @@ class ProvisionPaths: def install_ok(lp, session_info, credentials): """Check whether the current install seems ok.""" - if lp.get("realm") == "": + if lp.get_string("realm") == "": return False - ldb = Ldb(lp.get("sam database"), session_info=session_info, + ldb = Ldb(lp.get_string("sam database"), session_info=session_info, credentials=credentials) if len(ldb.search("(cn=Administrator)")) != 1: return False @@ -166,7 +167,6 @@ def findnss(nssfn, *names): raise Exception("Unable to find user/group for %s" % arguments[1]) - def hostip(): """return first host IP.""" return gethostbyname(hostname()) @@ -230,7 +230,7 @@ def setup_ldb(setup_dir, ldif, session_info, credentials, subobj, dbname, ldb.transaction_start() try: if erase: - ldb_erase(ldb); + ldb.erase(); setup_add_ldif(setup_dir, ldif, subobj, ldb) except: ldb.transaction_cancel() @@ -271,10 +271,10 @@ def provision_default_paths(lp, subobj): :param subobj: Object """ paths = ProvisionPaths() - private_dir = lp.get("private dir") + private_dir = lp.get_string("private dir") paths.shareconf = os.path.join(private_dir, "share.ldb") - paths.samdb = lp.get("sam database") or os.path.join(private_dir, "samdb.ldb") - paths.secrets = lp.get("secrets database") or os.path.join(private_dir, "secrets.ldb") + paths.samdb = lp.get_string("sam database") or os.path.join(private_dir, "samdb.ldb") + paths.secrets = lp.get_string("secrets database") or os.path.join(private_dir, "secrets.ldb") paths.templates = os.path.join(private_dir, "templates.ldb") paths.keytab = os.path.join(private_dir, "secrets.keytab") paths.dns = os.path.join(private_dir, subobj.dnsdomain + ".zone") @@ -572,8 +572,8 @@ def provision_ldapbase(setup_dir, subobj, message, paths): def provision_guess(lp): """guess reasonably default options for provisioning.""" - subobj = ProvisionSettings(realm=lp.get("realm").upper(), - domain=lp.get("workgroup"), + subobj = ProvisionSettings(realm=lp.get_string("realm").upper(), + domain=lp.get_string("workgroup"), hostname=hostname(), hostip=hostip()) @@ -581,7 +581,7 @@ def provision_guess(lp): assert subobj.domain is not None assert subobj.hostname is not None - subobj.domainsid = sid.random() + subobj.domainsid = security.random_sid() subobj.invocationid = uuid.random() subobj.policyguid = uuid.random() subobj.krbtgtpass = misc.random_password(12) diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py index d374f8bafa..d3930e217a 100644 --- a/source4/scripting/python/samba/tests/__init__.py +++ b/source4/scripting/python/samba/tests/__init__.py @@ -27,7 +27,7 @@ class LdbTestCase(unittest.TestCase): self.filename = os.tempnam() self.ldb = samba.Ldb(self.filename) - def load_modules(self, modules=[]): + def set_modules(self, modules=[]): m = ldb.Message() m.dn = ldb.Dn(self.ldb, "@MODULES") m["@LIST"] = ",".join(modules) |