From 14e443b868f56db0b29c3221c175f1a2cd2a8d1d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 Apr 2008 16:13:42 +0200 Subject: Improve PEP8 (Python code style) compliancy a bit. (This used to be commit c7d388a6e2153234fe67daf1af094fc346e1da61) --- source4/scripting/python/samba/provision.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 6917aa1a54..9151f29603 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -264,8 +264,10 @@ def provision_paths_from_lp(lp, dnsdomain): 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): + +def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, + serverrole=None, rootdn=None, domaindn=None, configdn=None, + schemadn=None, sitename=None): if hostname is None: hostname = socket.gethostname().split(".")[0].lower() @@ -336,7 +338,8 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, serverrole= return names -def load_or_make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, targetdir): +def load_or_make_smbconf(smbconf, setup_path, hostname, domain, realm, + serverrole, targetdir): if targetdir is not None: if not os.path.exists(targetdir): os.mkdir(targetdir) @@ -423,6 +426,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,8 +547,9 @@ 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, + setup_samdb_rootdse(samdb, setup_path, names.schemadn, names.domaindn, + names.hostname, names.dnsdomain, names.realm, + names.rootdn, names.configdn, names.netbiosname, names.sitename) if erase: @@ -637,6 +642,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,6 +662,7 @@ 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): @@ -740,7 +747,8 @@ def setup_samdb(path, setup_path, session_info, credentials, lp, if serverrole == "domain controller": samdb.set_invocation_id(invocationid) - load_schema(setup_path, samdb, names.schemadn, names.netbiosname, names.configdn, names.sitename) + load_schema(setup_path, samdb, names.schemadn, names.netbiosname, + names.configdn, names.sitename) samdb.transaction_start() -- cgit From 3e97aa73c22ea036afb586b16a1d130ee46e5697 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 Apr 2008 16:32:28 +0200 Subject: Simplify some code, fix style. (This used to be commit 1c983e4e4dfb93387791c36dc96696c4fffcfeb7) --- source4/scripting/python/samba/provision.py | 201 ++++++++++++++-------------- 1 file changed, 99 insertions(+), 102 deletions(-) diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 9151f29603..f81cedc729 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -103,7 +103,7 @@ def check_install(lp, session_info, credentials): :param credentials: Credentials """ if lp.get("realm") == "": - raise Error("Realm empty") + raise Exception("Realm empty") ldb = Ldb(lp.get("sam database"), session_info=session_info, credentials=credentials, lp=lp) if len(ldb.search("(cn=Administrator)")) != 1: @@ -288,8 +288,8 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, realm = dnsdomain.upper() if lp.get("realm").upper() != realm: - raise Exception("realm '%s' in %s must match chosen realm '%s'" % - (lp.get("realm"), smbconf, realm)) + raise Exception("realm '%s' must match chosen realm '%s'" % + (lp.get("realm"), realm)) dnsdomain = dnsdomain.lower() @@ -299,7 +299,7 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, if domaindn is None: domaindn = "DC=" + dnsdomain.replace(".", ",DC=") if lp.get("workgroup").upper() != domain.upper(): - raise Error("workgroup '%s' in smb.conf must match chosen domain '%s'", + raise Exception("workgroup '%s' in smb.conf must match chosen domain '%s'", lp.get("workgroup"), domain) else: domain = netbiosname @@ -338,68 +338,52 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, return names -def load_or_make_smbconf(smbconf, setup_path, hostname, domain, realm, - serverrole, targetdir): - if targetdir is not None: - if not os.path.exists(targetdir): - os.mkdir(targetdir) - if not os.path.exists(os.path.join(targetdir, "etc")): - os.mkdir(os.path.join(targetdir, "etc")) - - smbconf = os.path.join(targetdir, "etc", "smb.conf") +def make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, + targetdir): + if hostname is None: + hostname = socket.gethostname().split(".")[0].lower() - # only install a new smb.conf if there isn't one there already + if serverrole is None: + serverrole = "standalone" - if not os.path.exists(smbconf): - if hostname is None: - hostname = socket.gethostname().split(".")[0].lower() + assert serverrole in ("domain controller", "member server", "standalone") + if serverrole == "domain controller": + smbconfsuffix = "dc" + elif serverrole == "member server": + smbconfsuffix = "member" + elif serverrole == "standalone": + smbconfsuffix = "standalone" - if serverrole is None: - serverrole = "standalone" + assert domain is not None + assert realm is not None - assert serverrole in ("domain controller", "member server", "standalone") - if serverrole == "domain controller": - smbconfsuffix = "dc" - elif serverrole == "member server": - smbconfsuffix = "member" - elif serverrole == "standalone": - smbconfsuffix = "standalone" - - assert domain is not None - assert realm is not None - - default_lp = param.LoadParm() - #Load non-existant file - default_lp.load(smbconf) - - if targetdir is not None: - privatedir_line = "private dir = " + os.path.abspath(os.path.join(targetdir, "private")) - lockdir_line = "lock dir = " + os.path.abspath(targetdir) + default_lp = param.LoadParm() + #Load non-existant file + default_lp.load(smbconf) + + if targetdir is not None: + privatedir_line = "private dir = " + os.path.abspath(os.path.join(targetdir, "private")) + lockdir_line = "lock dir = " + os.path.abspath(targetdir) - default_lp.set("lock dir", os.path.abspath(targetdir)) - else: - privatedir_line = "" - lockdir_line = "" - - sysvol = os.path.join(default_lp.get("lock dir"), "sysvol") - netlogon = os.path.join(sysvol, realm.lower(), "scripts") - - setup_file(setup_path("provision.smb.conf.%s" % smbconfsuffix), - smbconf, { - "HOSTNAME": hostname, - "DOMAIN": domain, - "REALM": realm, - "SERVERROLE": serverrole, - "NETLOGONPATH": netlogon, - "SYSVOLPATH": sysvol, - "PRIVATEDIR_LINE": privatedir_line, - "LOCKDIR_LINE": lockdir_line - }) + default_lp.set("lock dir", os.path.abspath(targetdir)) + else: + privatedir_line = "" + lockdir_line = "" - lp = param.LoadParm() - lp.load(smbconf) + sysvol = os.path.join(default_lp.get("lock dir"), "sysvol") + netlogon = os.path.join(sysvol, realm.lower(), "scripts") - return lp + setup_file(setup_path("provision.smb.conf.%s" % smbconfsuffix), + smbconf, { + "HOSTNAME": hostname, + "DOMAIN": domain, + "REALM": realm, + "SERVERROLE": serverrole, + "NETLOGONPATH": netlogon, + "SYSVOLPATH": sysvol, + "PRIVATEDIR_LINE": privatedir_line, + "LOCKDIR_LINE": lockdir_line + }) def setup_name_mappings(samdb, idmap, sid, domaindn, root_uid, nobody_uid, users_gid, wheel_gid): @@ -493,8 +477,8 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info, schemadn_ldb = "schema.ldb" if ldap_backend is not None: schema_ldb = ldap_backend - schemadn_ldb = ldap_backend - + schemadn_ldb = ldap_backend + if ldap_backend_type == "fedora-ds": backend_modules = ["nsuniqueid", "paged_searches"] # We can handle linked attributes here, as we don't have directory-side subtree operations @@ -886,14 +870,15 @@ FILL_NT4SYNC = "NT4SYNC" 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, - domain=None, hostname=None, hostip=None, hostip6=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=None): + credentials, smbconf=None, targetdir=None, samdb_fill=FILL_FULL, + realm=None, rootdn=None, domaindn=None, schemadn=None, + configdn=None, domain=None, hostname=None, hostip=None, + hostip6=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=None): """Provision samba4 :note: caution, this wipes all existing data! @@ -917,18 +902,9 @@ def provision(setup_dir, message, session_info, machinepass = misc.random_password(12) if dnspass is None: dnspass = misc.random_password(12) - if root is None: - root_uid = findnss(pwd.getpwnam, ["root"])[2] - else: - root_uid = findnss(pwd.getpwnam, [root])[2] - if nobody is None: - nobody_uid = findnss(pwd.getpwnam, ["nobody"])[2] - else: - nobody_uid = findnss(pwd.getpwnam, [nobody])[2] - if users is None: - users_gid = findnss(grp.getgrnam, ["users"])[2] - else: - users_gid = findnss(grp.getgrnam, [users])[2] + root_uid = findnss(pwd.getpwnam, [root or "root"])[2] + nobody_uid = findnss(pwd.getpwnam, [nobody or "nobody"])[2] + users_gid = findnss(grp.getgrnam, [users or "users"])[2] if wheel is None: wheel_gid = findnss(grp.getgrnam, ["wheel", "adm"])[2] else: @@ -936,7 +912,17 @@ def provision(setup_dir, message, session_info, if aci is None: aci = "# no aci for local ldb" - lp = load_or_make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, targetdir) + if smbconf is None: + os.makedirs(os.path.join(targetdir, "etc")) + smbconf = os.path.join(targetdir, "etc", "smb.conf") + + # only install a new smb.conf if there isn't one there already + if not os.path.exists(smbconf): + make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, + targetdir) + + lp = param.LoadParm() + lp.load(smbconf) names = guess_names(lp=lp, hostname=hostname, domain=domain, dnsdomain=realm, serverrole=serverrole, sitename=sitename, @@ -1080,7 +1066,7 @@ def provision_become_dc(setup_dir=None, ldap_backend=None, ldap_backend_type=None, sitename=DEFAULTSITE): def message(text): - """print a message if quiet is not set.""" + """print a message if quiet is not set.""" print text provision(setup_dir, message, system_session(), None, @@ -1115,11 +1101,22 @@ def provision_backend(setup_dir=None, message=None, if root is None: root = findnss(pwd.getpwnam, ["root"])[0] - lp = load_or_make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, targetdir) + if smbconf is None: + os.makedirs(os.path.join(targetdir, "etc")) + smbconf = os.path.join(targetdir, "etc", "smb.conf") + + # only install a new smb.conf if there isn't one there already + if not os.path.exists(smbconf): + make_smbconf(smbconf, setup_path, hostname, domain, realm, + serverrole, targetdir) + + lp = param.LoadParm() + lp.load(smbconf) names = guess_names(lp=lp, hostname=hostname, domain=domain, dnsdomain=realm, serverrole=serverrole, - rootdn=rootdn, domaindn=domaindn, configdn=configdn, schemadn=schemadn) + rootdn=rootdn, domaindn=domaindn, configdn=configdn, + schemadn=schemadn) paths = provision_paths_from_lp(lp, names.dnsdomain) @@ -1175,11 +1172,11 @@ def provision_backend(setup_dir=None, message=None, backend_schema = "99_ad.ldif" 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); + res = schemadb.search(expression="(&(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1)))(objectclass=attributeSchema))", base=names.schemadn, scope=SCOPE_SUBTREE, attrs=attrs); - memberof_config = "# Generated from schema in " + schemadb_path + "\n"; - refint_attributes = ""; - for i in range (0, len(res)): + memberof_config = "# Generated from schema in " + schemadb_path + "\n"; + refint_attributes = ""; + for i in range (0, len(res)): linkid = res[i]["linkID"][0] linkid = str(int(linkid) + 1) expression = "(&(objectclass=attributeSchema)(linkID=" + (linkid) + "))" @@ -1199,11 +1196,11 @@ memberof-dangling-error 32 """; - memberof_config = memberof_config + """ + memberof_config = memberof_config + """ overlay refint refint_attributes""" + refint_attributes + "\n"; - - setup_file(setup_path("slapd.conf"), paths.slapdconf, + + setup_file(setup_path("slapd.conf"), paths.slapdconf, {"DNSDOMAIN": names.dnsdomain, "LDAPDIR": paths.ldapdir, "DOMAINDN": names.domaindn, @@ -1212,18 +1209,18 @@ refint_attributes""" + refint_attributes + "\n"; "LDAPMANAGERDN": names.ldapmanagerdn, "LDAPMANAGERPASS": adminpass, "MEMBEROF_CONFIG": memberof_config}) - setup_file(setup_path("modules.conf"), paths.modulesconf, + 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")) - mapping = "schema-map-openldap-2.3" - backend_schema = "backend-schema.schema" + 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")) + 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) + 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) 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); @@ -1265,8 +1262,8 @@ def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn, hostip6_host_line = "" if hostip6 is not None: - hostip6_base_line = " IN AAAA " + hostip6 - hostip6_host_line = hostname + " IN AAAA " + hostip6 + hostip6_base_line = " IN AAAA " + hostip6 + hostip6_host_line = hostname + " IN AAAA " + hostip6 setup_file(setup_path("provision.zone"), path, { "DNSPASS_B64": b64encode(dnspass), -- cgit From 7c7880695b02df4cbe0faab959846c63d0cc0536 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 6 Apr 2008 00:40:01 +0200 Subject: More PEP8 compliancy. (This used to be commit d16b30d005933c9cc73f9196a3b77829d23687a0) --- source4/scripting/python/samba/provision.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index f81cedc729..4d5a9cb1f1 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -125,6 +125,10 @@ def findnss(nssfn, names): raise KeyError("Unable to find user/group %r" % names) +findnss_uid = lambda names: findnss(pwd.getpwnam, names)[2] +findnss_gid = lambda names: findnss(grp.getgrnam, names)[2] + + def open_ldb(session_info, credentials, lp, dbname): """Open a LDB, thrashing it if it is corrupt. @@ -293,7 +297,7 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, dnsdomain = dnsdomain.lower() - if (serverrole == "domain controller"): + if serverrole == "domain controller": if domain is None: domain = lp.get("workgroup") if domaindn is None: @@ -385,6 +389,7 @@ def make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, "LOCKDIR_LINE": lockdir_line }) + 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. @@ -902,13 +907,13 @@ def provision(setup_dir, message, session_info, machinepass = misc.random_password(12) if dnspass is None: dnspass = misc.random_password(12) - root_uid = findnss(pwd.getpwnam, [root or "root"])[2] - nobody_uid = findnss(pwd.getpwnam, [nobody or "nobody"])[2] - users_gid = findnss(grp.getgrnam, [users or "users"])[2] + root_uid = findnss_uid([root or "root"]) + nobody_uid = findnss_uid([nobody or "nobody"]) + users_gid = findnss_gid([users or "users"]) if wheel is None: - wheel_gid = findnss(grp.getgrnam, ["wheel", "adm"])[2] + wheel_gid = findnss_gid(["wheel", "adm"]) else: - wheel_gid = findnss(grp.getgrnam, [wheel])[2] + wheel_gid = findnss_gid([wheel]) if aci is None: aci = "# no aci for local ldb" @@ -925,8 +930,9 @@ def provision(setup_dir, message, session_info, lp.load(smbconf) names = guess_names(lp=lp, hostname=hostname, domain=domain, - dnsdomain=realm, serverrole=serverrole, sitename=sitename, - rootdn=rootdn, domaindn=domaindn, configdn=configdn, schemadn=schemadn) + dnsdomain=realm, serverrole=serverrole, + sitename=sitename, rootdn=rootdn, domaindn=domaindn, + configdn=configdn, schemadn=schemadn) paths = provision_paths_from_lp(lp, names.dnsdomain) @@ -936,7 +942,8 @@ def provision(setup_dir, message, session_info, if hostip6 is None: try: hostip6 = socket.getaddrinfo(names.hostname, None, socket.AF_INET6, socket.AI_CANONNAME, socket.IPPROTO_IP)[0][-1][0] - except socket.gaierror: pass + except socket.gaierror: + pass if serverrole is None: serverrole = lp.get("server role") -- cgit From 212644b5a1107ad81e5ce3bc3118c8983d3f2a86 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Mon, 14 Apr 2008 12:48:25 +0200 Subject: Attempt to fix the patchfile_preg backend for big endian machines. Update some functions to properly state what is not supported (yet). Registry .reg uses UCS-2, not UTF-16. (This used to be commit 664a035dd9fc6e3b50a771baa98f8d79360cc4c1) --- source4/lib/registry/patchfile_dotreg.c | 2 +- source4/lib/registry/patchfile_preg.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source4/lib/registry/patchfile_dotreg.c b/source4/lib/registry/patchfile_dotreg.c index 59f4044713..5aa7e2bab7 100644 --- a/source4/lib/registry/patchfile_dotreg.c +++ b/source4/lib/registry/patchfile_dotreg.c @@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* FIXME Newer .REG files, created by Windows XP and above use unicode UTF-16 */ +/* FIXME Newer .REG files, created by Windows XP and above use unicode UCS-2 */ #include "includes.h" #include "lib/registry/registry.h" diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c index 0fa367bfcb..5216a04c8b 100644 --- a/source4/lib/registry/patchfile_preg.c +++ b/source4/lib/registry/patchfile_preg.c @@ -42,30 +42,30 @@ static WERROR preg_read_utf16(struct smb_iconv_convenience *ic, int fd, char *c) /* FIXME These functions need to be implemented */ static WERROR reg_preg_diff_add_key(void *_data, const char *key_name) { - return WERR_OK; + return WERR_NOT_SUPPORTED; } static WERROR reg_preg_diff_del_key(void *_data, const char *key_name) { - return WERR_OK; + return WERR_NOT_SUPPORTED; } static WERROR reg_preg_diff_set_value(void *_data, const char *key_name, const char *value_name, uint32_t value_type, DATA_BLOB value_data) { - return WERR_OK; + return WERR_NOT_SUPPORTED; } static WERROR reg_preg_diff_del_value(void *_data, const char *key_name, const char *value_name) { - return WERR_OK; + return WERR_NOT_SUPPORTED; } static WERROR reg_preg_diff_del_all_values(void *_data, const char *key_name) { - return WERR_OK; + return WERR_NOT_SUPPORTED; } static WERROR reg_preg_diff_done(void *_data) @@ -149,6 +149,8 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, ret = WERR_GENERAL_FAILURE; goto cleanup; } + preg_header.version = IVAL(&preg_header.version, 0); + if (strncmp(preg_header.hdr, "PReg", 4) != 0) { DEBUG(0, ("This file is not a valid preg registry file\n")); ret = WERR_GENERAL_FAILURE; @@ -193,6 +195,8 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, ret = WERR_GENERAL_FAILURE; goto cleanup; } + value_type = IVAL(&value_type, 0); + /* Read past delimiter */ buf_ptr = buf; if (!(W_ERROR_IS_OK(preg_read_utf16(iconv_convenience, fd, buf_ptr)) && -- cgit From 12147fca2b3acd37eb20db82996714320cd4e9b2 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Mon, 14 Apr 2008 22:52:51 +0200 Subject: Add support for security descriptors. Also patched the regf backend to support this. Did not touch the ldb, dir and rpc backends yet. (This used to be commit c4626f21a898da27a051f2c67f8fd73f55d4fc7d) --- source4/lib/registry/hive.c | 18 ++++++++++ source4/lib/registry/interface.c | 23 +++---------- source4/lib/registry/local.c | 16 +++++++++ source4/lib/registry/regf.c | 64 +++++++++++++++++++++++++++++------ source4/lib/registry/registry.h | 21 +++++++----- source4/lib/registry/tests/hive.c | 56 +++++++++++++++++++++++++++++- source4/lib/registry/tests/registry.c | 8 ++--- 7 files changed, 164 insertions(+), 42 deletions(-) diff --git a/source4/lib/registry/hive.c b/source4/lib/registry/hive.c index 2a9b1a59ce..3bb5b566c9 100644 --- a/source4/lib/registry/hive.c +++ b/source4/lib/registry/hive.c @@ -143,6 +143,24 @@ WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx, return key->ops->enum_value(mem_ctx, key, idx, name, type, data); } +WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx, + struct hive_key *key, + struct security_descriptor **security) +{ + if (key->ops->get_sec_desc == NULL) + return WERR_NOT_SUPPORTED; + + return key->ops->get_sec_desc(mem_ctx, key, security); +} + +WERROR hive_set_sec_desc(struct hive_key *key, + const struct security_descriptor *security) +{ + if (key->ops->set_sec_desc == NULL) + return WERR_NOT_SUPPORTED; + + return key->ops->set_sec_desc(key, security); +} WERROR hive_key_del_value(struct hive_key *key, const char *name) { diff --git a/source4/lib/registry/interface.c b/source4/lib/registry/interface.c index a18fd2c28c..06b002859d 100644 --- a/source4/lib/registry/interface.c +++ b/source4/lib/registry/interface.c @@ -249,10 +249,10 @@ _PUBLIC_ WERROR reg_get_sec_desc(TALLOC_CTX *ctx, return WERR_INVALID_PARAM; /* A 'real' set function has preference */ - if (key->context->ops->get_security == NULL) + if (key->context->ops->get_sec_desc == NULL) return WERR_NOT_SUPPORTED; - return key->context->ops->get_security(ctx, key, secdesc); + return key->context->ops->get_sec_desc(ctx, key, secdesc); } /** @@ -283,27 +283,14 @@ _PUBLIC_ WERROR reg_key_flush(struct registry_key *key) return key->context->ops->flush_key(key); } -_PUBLIC_ WERROR reg_get_security(TALLOC_CTX *mem_ctx, - const struct registry_key *key, - struct security_descriptor **security) -{ - if (key == NULL) - return WERR_INVALID_PARAM; - - if (key->context->ops->get_security == NULL) - return WERR_NOT_SUPPORTED; - - return key->context->ops->get_security(mem_ctx, key, security); -} - -_PUBLIC_ WERROR reg_set_security(struct registry_key *key, +_PUBLIC_ WERROR reg_set_sec_desc(struct registry_key *key, struct security_descriptor *security) { if (key == NULL) return WERR_INVALID_PARAM; - if (key->context->ops->set_security == NULL) + if (key->context->ops->set_sec_desc == NULL) return WERR_NOT_SUPPORTED; - return key->context->ops->set_security(key, security); + return key->context->ops->set_sec_desc(key, security); } diff --git a/source4/lib/registry/local.c b/source4/lib/registry/local.c index 5bf2d86588..da381cfbff 100644 --- a/source4/lib/registry/local.c +++ b/source4/lib/registry/local.c @@ -278,7 +278,21 @@ static WERROR local_get_key_info(TALLOC_CTX *mem_ctx, last_change_time, max_subkeynamelen, max_valnamelen, max_valbufsize); } +static WERROR local_get_sec_desc(TALLOC_CTX *mem_ctx, + const struct registry_key *key, + struct security_descriptor **security) +{ + const struct local_key *local = (const struct local_key *)key; + return hive_get_sec_desc(mem_ctx, local->hive_key, security); +} +static WERROR local_set_sec_desc(struct registry_key *key, + const struct security_descriptor *security) +{ + const struct local_key *local = (const struct local_key *)key; + + return hive_set_sec_desc(local->hive_key, security); +} const static struct registry_operations local_ops = { .name = "local", .open_key = local_open_key, @@ -292,6 +306,8 @@ const static struct registry_operations local_ops = { .delete_value = local_delete_value, .flush_key = local_flush_key, .get_key_info = local_get_key_info, + .get_sec_desc = local_get_sec_desc, + .set_sec_desc = local_set_sec_desc, }; WERROR reg_open_local(TALLOC_CTX *mem_ctx, struct registry_context **ctx, diff --git a/source4/lib/registry/regf.c b/source4/lib/registry/regf.c index 46ccca922b..57a895aa00 100644 --- a/source4/lib/registry/regf.c +++ b/source4/lib/registry/regf.c @@ -25,6 +25,8 @@ #include "librpc/gen_ndr/winreg.h" #include "param/param.h" #include "lib/registry/registry.h" +#include "libcli/security/security.h" + static struct hive_operations reg_backend_regf; @@ -1915,9 +1917,12 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, { struct regf_data *regf; struct regf_hdr *regf_hdr; - int i; struct nk_block nk; + struct sk_block sk; WERROR error; + DATA_BLOB data; + struct security_descriptor *sd; + uint32_t sk_offset; regf = (struct regf_data *)talloc_zero(NULL, struct regf_data); @@ -1945,20 +1950,17 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, regf_hdr->version.minor = minor_version; regf_hdr->last_block = 0x1000; /* Block size */ regf_hdr->description = talloc_strdup(regf_hdr, - "registry created by Samba 4"); + "Registry created by Samba 4"); W_ERROR_HAVE_NO_MEMORY(regf_hdr->description); regf_hdr->chksum = 0; regf->header = regf_hdr; - i = 0; /* Create all hbin blocks */ regf->hbins = talloc_array(regf, struct hbin_block *, 1); W_ERROR_HAVE_NO_MEMORY(regf->hbins); regf->hbins[0] = NULL; - regf_hdr->data_offset = -1; /* FIXME */ - nk.header = "nk"; nk.type = REG_SUB_KEY; unix_to_nt_time(&nk.last_change, time(NULL)); @@ -1971,27 +1973,67 @@ WERROR reg_create_regf_file(TALLOC_CTX *parent_ctx, nk.num_values = 0; nk.values_offset = -1; memset(nk.unk3, 0, 5); - nk.clsname_offset = -1; /* FIXME: fill in */ + nk.clsname_offset = -1; nk.clsname_length = 0; - nk.key_name = ""; + nk.sk_offset = 0x80; + nk.key_name = "SambaRootKey"; + + /* + * It should be noted that changing the key_name to something shorter + * creates a shorter nk block, which makes the position of the sk block + * change. All Windows registries I've seen have the sk at 0x80. + * I therefore recommend that our regf files share that offset -- Wilco + */ + + /* Create a security descriptor. */ + sd = security_descriptor_dacl_create(regf, + 0, + NULL, NULL, + SID_NT_AUTHENTICATED_USERS, + SEC_ACE_TYPE_ACCESS_ALLOWED, + SEC_GENERIC_ALL, + SEC_ACE_FLAG_OBJECT_INHERIT, + NULL); + + /* Push the security descriptor to a blob */ + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(&data, regf, NULL, + sd, (ndr_push_flags_fn_t)ndr_push_security_descriptor))) { + DEBUG(0, ("Unable to push security descriptor\n")); + return WERR_GENERAL_FAILURE; + } - nk.sk_offset = -1; /* FIXME: fill in */ + ZERO_STRUCT(sk); + sk.header = "sk"; + sk.prev_offset = 0x80; + sk.next_offset = 0x80; + sk.ref_cnt = 1; + sk.rec_size = data.length; + sk.sec_desc = data.data; /* Store the new nk key */ regf->header->data_offset = hbin_store_tdr(regf, (tdr_push_fn_t)tdr_push_nk_block, &nk); + /* Store the sk block */ + sk_offset = hbin_store_tdr(regf, + (tdr_push_fn_t) tdr_push_sk_block, + &sk); + if (sk_offset != 0x80) { + DEBUG(0, ("Error storing sk block, should be at 0x80, stored at 0x%x\n", nk.sk_offset)); + return WERR_GENERAL_FAILURE; + } + *key = (struct hive_key *)regf_get_key(parent_ctx, regf, regf->header->data_offset); - /* We can drop our own reference now that *key will have created one */ - talloc_free(regf); - error = regf_save_hbin(regf); if (!W_ERROR_IS_OK(error)) { return error; } + + /* We can drop our own reference now that *key will have created one */ + talloc_free(regf); return WERR_OK; } diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h index a86294bf46..1348d1121f 100644 --- a/source4/lib/registry/registry.h +++ b/source4/lib/registry/registry.h @@ -184,6 +184,12 @@ WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx, struct hive_key *key, uint32_t idx, const char **name, uint32_t *type, DATA_BLOB *data); +WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx, + struct hive_key *key, + struct security_descriptor **security); + +WERROR hive_set_sec_desc(struct hive_key *key, + const struct security_descriptor *security); WERROR hive_key_del_value(struct hive_key *key, const char *name); @@ -311,11 +317,11 @@ struct registry_operations { uint32_t *type, DATA_BLOB *data); - WERROR (*get_security) (TALLOC_CTX *mem_ctx, + WERROR (*get_sec_desc) (TALLOC_CTX *mem_ctx, const struct registry_key *key, struct security_descriptor **security); - WERROR (*set_security) (struct registry_key *key, + WERROR (*set_sec_desc) (struct registry_key *key, const struct security_descriptor *security); WERROR (*load_key) (struct registry_key *key, @@ -461,12 +467,8 @@ struct registry_key *reg_import_hive_key(struct registry_context *ctx, struct hive_key *hive, uint32_t predef_key, const char **elements); -WERROR reg_get_security(TALLOC_CTX *mem_ctx, - const struct registry_key *key, - struct security_descriptor **security); - -WERROR reg_set_security(struct registry_key *key, - struct security_descriptor *security); +WERROR reg_set_sec_desc(struct registry_key *key, + const struct security_descriptor *security); struct reg_diff_callbacks { WERROR (*add_key) (void *callback_data, const char *key_name); @@ -490,6 +492,9 @@ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename, struct smb_iconv_convenience *iconv_convenience, struct reg_diff_callbacks **callbacks, void **callback_data); +WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, + struct reg_diff_callbacks **callbacks, + void **callback_data); WERROR reg_generate_diff_key(struct registry_key *oldkey, struct registry_key *newkey, const char *path, diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index a16736c761..4fe7f66c03 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -26,6 +26,7 @@ #include "librpc/gen_ndr/winreg.h" #include "system/filesys.h" #include "param/param.h" +#include "libcli/security/security.h" static bool test_del_nonexistant_key(struct torture_context *tctx, const void *test_data) @@ -297,6 +298,57 @@ static bool test_list_values(struct torture_context *tctx, return true; } +static bool test_hive_security(struct torture_context *tctx, const void *_data) +{ + struct hive_key *subkey = NULL; + const struct hive_key *root = _data; + WERROR error; + struct security_descriptor *osd, *nsd; + + osd = security_descriptor_dacl_create(tctx, + 0, + NULL, NULL, + SID_NT_AUTHENTICATED_USERS, + SEC_ACE_TYPE_ACCESS_ALLOWED, + SEC_GENERIC_ALL, + SEC_ACE_FLAG_OBJECT_INHERIT, + NULL); + + + error = hive_key_add_name(tctx, root, "SecurityKey", NULL, + osd, &subkey); + torture_assert_werr_ok(tctx, error, "hive_key_add_name"); + + error = hive_get_sec_desc(tctx, subkey, &nsd); + torture_assert_werr_ok (tctx, error, "getting security descriptor"); + + torture_assert(tctx, security_descriptor_equal(osd, nsd), + "security descriptor changed!"); + + /* Create a fresh security descriptor */ + talloc_free(osd); + osd = security_descriptor_dacl_create(tctx, + 0, + NULL, NULL, + SID_NT_AUTHENTICATED_USERS, + SEC_ACE_TYPE_ACCESS_ALLOWED, + SEC_GENERIC_ALL, + SEC_ACE_FLAG_OBJECT_INHERIT, + NULL); + + error = hive_set_sec_desc(subkey, osd); + torture_assert_werr_ok(tctx, error, "setting security descriptor"); + + printf("The second one is done.\n"); + error = hive_get_sec_desc(tctx, subkey, &nsd); + torture_assert_werr_ok (tctx, error, "getting security descriptor"); + + torture_assert(tctx, security_descriptor_equal(osd, nsd), + "security descriptor changed!"); + + return true; +} + static void tcase_add_tests(struct torture_tcase *tcase) { torture_tcase_add_simple_test_const(tcase, "del_nonexistant_key", @@ -324,6 +376,8 @@ static void tcase_add_tests(struct torture_tcase *tcase) test_del_key); torture_tcase_add_simple_test_const(tcase, "del_value", test_del_value); + torture_tcase_add_simple_test_const(tcase, "check hive security", + test_hive_security); } static bool hive_setup_dir(struct torture_context *tctx, void **data) @@ -381,7 +435,7 @@ static bool hive_setup_regf(struct torture_context *tctx, void **data) char *dirname; NTSTATUS status; - status = torture_temp_dir(tctx, "hive-dir", &dirname); + status = torture_temp_dir(tctx, "hive-regf", &dirname); if (!NT_STATUS_IS_OK(status)) return false; diff --git a/source4/lib/registry/tests/registry.c b/source4/lib/registry/tests/registry.c index b19a6abffb..97c1190a68 100644 --- a/source4/lib/registry/tests/registry.c +++ b/source4/lib/registry/tests/registry.c @@ -387,11 +387,11 @@ static bool test_security(struct torture_context *tctx, void *_data) SEC_ACE_FLAG_OBJECT_INHERIT, NULL); - error = reg_set_security(subkey, osd); - torture_assert_werr_ok(tctx, error, "setting security"); + error = reg_set_sec_desc(subkey, osd); + torture_assert_werr_ok(tctx, error, "setting security descriptor"); - error = reg_get_security(tctx, subkey, &nsd); - torture_assert_werr_ok (tctx, error, "setting security"); + error = reg_get_sec_desc(tctx, subkey, &nsd); + torture_assert_werr_ok (tctx, error, "getting security descriptor"); torture_assert(tctx, security_descriptor_equal(osd, nsd), "security descriptor changed!"); -- cgit From a31b6607f22f6b3e1b354db2f9f611b299a2f7ae Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Mon, 14 Apr 2008 22:56:14 +0200 Subject: Remove debug stuff. (This used to be commit 7ba2e5dc5b6d82457c298f7ecdb6baea43f04854) --- source4/lib/registry/tests/hive.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source4/lib/registry/tests/hive.c b/source4/lib/registry/tests/hive.c index 4fe7f66c03..474704b517 100644 --- a/source4/lib/registry/tests/hive.c +++ b/source4/lib/registry/tests/hive.c @@ -339,7 +339,6 @@ static bool test_hive_security(struct torture_context *tctx, const void *_data) error = hive_set_sec_desc(subkey, osd); torture_assert_werr_ok(tctx, error, "setting security descriptor"); - printf("The second one is done.\n"); error = hive_get_sec_desc(tctx, subkey, &nsd); torture_assert_werr_ok (tctx, error, "getting security descriptor"); -- cgit From 0b8d2b3cb779463a1e24039300ac2669862f9b64 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Tue, 15 Apr 2008 11:52:33 +0200 Subject: Fixed the patchfile tests and tidy up the patchfile backends. (This used to be commit 6e9b1e35a269af2eda79356c1525f5413656d648) --- source4/lib/registry/patchfile.c | 4 +- source4/lib/registry/patchfile_dotreg.c | 8 +- source4/lib/registry/patchfile_preg.c | 10 +- source4/lib/registry/registry.h | 4 + source4/lib/registry/tests/diff.c | 232 +++++++++++++++++++++++++++++--- 5 files changed, 226 insertions(+), 32 deletions(-) diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c index 15e3a158f2..eaeef341bb 100644 --- a/source4/lib/registry/patchfile.c +++ b/source4/lib/registry/patchfile.c @@ -45,7 +45,7 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey, void *callback_data) { int i; - struct registry_key *t1, *t2; + struct registry_key *t1 = NULL, *t2 = NULL; char *tmppath; const char *keyname1; WERROR error, error1, error2; @@ -295,7 +295,7 @@ _PUBLIC_ WERROR reg_diff_load(const char *filename, /* Reset position in file */ lseek(fd, 0, SEEK_SET); -#if 0 +#if 0 /* These backends are not supported yet. */ if (strncmp(hdr, "CREG", 4) == 0) { /* Must be a W9x CREG Config.pol file */ return reg_creg_diff_load(diff, fd); diff --git a/source4/lib/registry/patchfile_dotreg.c b/source4/lib/registry/patchfile_dotreg.c index 5aa7e2bab7..1bc9c60753 100644 --- a/source4/lib/registry/patchfile_dotreg.c +++ b/source4/lib/registry/patchfile_dotreg.c @@ -3,7 +3,7 @@ Reading .REG files Copyright (C) Jelmer Vernooij 2004-2007 - Copyright (C) Wilco Baan Hofman 2006 + Copyright (C) Wilco Baan Hofman 2006-2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -112,8 +112,8 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename, data->iconv_convenience = iconv_convenience; if (filename) { - data->fd = open(filename, O_CREAT, 0755); - if (data->fd == -1) { + data->fd = open(filename, O_CREAT|O_WRONLY, 0755); + if (data->fd < 0) { DEBUG(0, ("Unable to open %s\n", filename)); return WERR_BADFILE; } @@ -121,7 +121,7 @@ _PUBLIC_ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename, data->fd = STDOUT_FILENO; } - fdprintf(data->fd, "%s\n", HEADER_STRING); + fdprintf(data->fd, "%s\n\n", HEADER_STRING); *callbacks = talloc(ctx, struct reg_diff_callbacks); diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c index 5216a04c8b..a28096517c 100644 --- a/source4/lib/registry/patchfile_preg.c +++ b/source4/lib/registry/patchfile_preg.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. Reading Registry.pol PReg registry files - Copyright (C) Wilco Baan Hofman 2006 + Copyright (C) Wilco Baan Hofman 2006-2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -71,7 +71,7 @@ static WERROR reg_preg_diff_del_all_values(void *_data, const char *key_name) static WERROR reg_preg_diff_done(void *_data) { struct preg_data *data = (struct preg_data *)_data; - + close(data->fd); talloc_free(data); return WERR_OK; @@ -95,15 +95,15 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, *callback_data = data; if (filename) { - data->fd = open(filename, O_CREAT, 0755); - if (data->fd == -1) { + data->fd = open(filename, O_CREAT|O_WRONLY, 0755); + if (data->fd < 0) { DEBUG(0, ("Unable to open %s\n", filename)); return WERR_BADFILE; } } else { data->fd = STDOUT_FILENO; } - snprintf(preg_header.hdr, 4, "PReg"); + memcpy(preg_header.hdr, "PReg", 4); SIVAL(&preg_header, 4, 1); write(data->fd, (uint8_t *)&preg_header,8); diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h index 1348d1121f..573379aff5 100644 --- a/source4/lib/registry/registry.h +++ b/source4/lib/registry/registry.h @@ -500,6 +500,10 @@ WERROR reg_generate_diff_key(struct registry_key *oldkey, const char *path, const struct reg_diff_callbacks *callbacks, void *callback_data); +WERROR reg_diff_load(const char *filename, + struct smb_iconv_convenience *iconv_convenience, + const struct reg_diff_callbacks *callbacks, + void *callback_data); diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 690f71fcf7..da62342124 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -4,6 +4,7 @@ local testing of registry diff functionality Copyright (C) Jelmer Vernooij 2007 + Copyright (C) Wilco Baan Hofman 2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,27 +25,79 @@ #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" -static bool test_generate_diff(struct torture_context *test) +struct diff_tcase_data { + struct registry_context *r1_ctx; + struct registry_context *r2_ctx; + struct reg_diff_callbacks *callbacks; + void *callback_data; + char *tempdir; + char *filename; +}; + +static bool test_generate_diff(struct torture_context *tctx, void *tcase_data) { /* WERROR reg_generate_diff(struct registry_context *ctx1, struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks, void *callback_data) */ + WERROR error; + struct diff_tcase_data *td = tcase_data; + + error = reg_generate_diff(td->r1_ctx, td->r2_ctx, + td->callbacks, + td->callback_data); + torture_assert_werr_ok(tctx, error, "reg_generate_diff"); + return true; } - -static bool test_diff_load(struct torture_context *test) +#if 0 +static bool test_diff_load(struct torture_context *tctx, void *tcase_data) { - /* WERROR reg_diff_load(const char *filename, const struct reg_diff_callbacks *callbacks, void *callback_data) */ + struct diff_tcase_data *td = tcase_data; + struct smb_iconv_convenience *iconv_convenience; + struct reg_diff_callbacks *callbacks; + void *data; + WERROR error; + + iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); + + + error = reg_diff_load(td->filename, iconv_convenience, callbacks, data); + torture_assert_werr_ok(tctx, error, "reg_diff_load"); return true; } - -static bool test_diff_apply(struct torture_context *test) +#endif +static bool test_diff_apply(struct torture_context *tctx, void *tcase_data) { - /* _PUBLIC_ WERROR reg_diff_apply (const char *filename, struct registry_context *ctx) */ + struct diff_tcase_data *td = tcase_data; + struct registry_key *key; + WERROR error; + + error = reg_diff_apply(td->r1_ctx, td->filename); + torture_assert_werr_ok(tctx, error, "reg_diff_apply"); + + error = td->r1_ctx->ops->get_predefined_key(td->r1_ctx, HKEY_LOCAL_MACHINE, &key); + torture_assert_werr_ok(tctx, error, "Opening HKEY_LOCAL_MACHINE failed"); + + /* If this generates an error it could be that the apply doesn't work, + * but also that the reg_generate_diff didn't work. */ + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Software", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\Software failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Microsoft", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\Software\\Microsoft failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Windows", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Microsoft\\Windows failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "CurrentVersion", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Windows\\CurrentVersion failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Policies", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\CurrentVersion\\Policies failed"); + error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Explorer", &key); + torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Policies\\Explorer failed"); + + return true; } @@ -58,7 +111,7 @@ static WERROR test_add_key(void *callback_data, const char *key_name) return WERR_OK; } -static bool test_generate_diff_key_add(struct torture_context *test) +static bool test_generate_diff_key_add(struct torture_context *tctx, void *tcase_data) { struct reg_diff_callbacks cb; struct registry_key rk; @@ -69,15 +122,15 @@ static bool test_generate_diff_key_add(struct torture_context *test) cb.add_key = test_add_key; - if (W_ERROR_IS_OK(reg_generate_diff_key(&rk, NULL, "bla", &cb, test))) + if (W_ERROR_IS_OK(reg_generate_diff_key(&rk, NULL, "bla", &cb, tctx))) return false; - torture_assert_str_equal(test, added_key, "bla", "key added"); + torture_assert_str_equal(tctx, added_key, "bla", "key added"); return true; } -static bool test_generate_diff_key_null(struct torture_context *test) +static bool test_generate_diff_key_null(struct torture_context *tctx, void *tcase_data) { struct reg_diff_callbacks cb; @@ -88,19 +141,156 @@ static bool test_generate_diff_key_null(struct torture_context *test) return true; } +static void tcase_add_tests (struct torture_tcase *tcase) +{ + torture_tcase_add_simple_test(tcase, "test_generate_diff_key_add", + test_generate_diff_key_add); + torture_tcase_add_simple_test(tcase, "test_generate_diff_key_null", + test_generate_diff_key_null); + torture_tcase_add_simple_test(tcase, "test_generate_diff", + test_generate_diff); + torture_tcase_add_simple_test(tcase, "test_diff_apply", + test_diff_apply); +/* torture_tcase_add_simple_test(tcase, "test_diff_load", + test_diff_load); +*/ +} + +static bool diff_setup_tcase(struct torture_context *tctx, void **data) +{ + struct registry_context *r1_ctx, *r2_ctx; + WERROR error; + NTSTATUS status; + struct hive_key *r1_hklm, *r1_hkcu; + struct hive_key *r2_hklm, *r2_hkcu; + const char *filename; + struct diff_tcase_data *td; + struct registry_key *key, *newkey; + DATA_BLOB blob; + + td = talloc(tctx, struct diff_tcase_data); + + /* Create two registry contexts */ + error = reg_open_local(tctx, &r1_ctx, NULL, NULL); + torture_assert_werr_ok(tctx, error, "Opening registry 1 for patch tests failed"); + + error = reg_open_local(tctx, &r2_ctx, NULL, NULL); + torture_assert_werr_ok(tctx, error, "Opening registry 2 for patch tests failed"); + + /* Create temp directory */ + status = torture_temp_dir(tctx, "patchfile", &td->tempdir); + torture_assert_ntstatus_ok(tctx, status, "Creating temp dir failed"); + + /* Create and mount HKLM and HKCU hives for registry 1 */ + filename = talloc_asprintf(tctx, "%s/r1_local_machine.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hklm); + torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); + + error = reg_mount_hive(r1_ctx, r1_hklm, HKEY_LOCAL_MACHINE, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + filename = talloc_asprintf(tctx, "%s/r1_current_user.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hkcu); + torture_assert_werr_ok(tctx, error, "Opening current user file failed"); + + error = reg_mount_hive(r1_ctx, r1_hkcu, HKEY_CURRENT_USER, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + /* Create and mount HKLM and HKCU hives for registry 2 */ + filename = talloc_asprintf(tctx, "%s/r2_local_machine.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hklm); + torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); + + error = reg_mount_hive(r2_ctx, r2_hklm, HKEY_LOCAL_MACHINE, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + filename = talloc_asprintf(tctx, "%s/r2_current_user.ldb", td->tempdir); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hkcu); + torture_assert_werr_ok(tctx, error, "Opening current user file failed"); + + error = reg_mount_hive(r2_ctx, r2_hkcu, HKEY_CURRENT_USER, NULL); + torture_assert_werr_ok(tctx, error, "Mounting hive failed"); + + error = r1_ctx->ops->get_predefined_key(r2_ctx, HKEY_LOCAL_MACHINE, &key); + torture_assert_werr_ok(tctx, error, "Opening HKEY_LOCAL_MACHINE failed"); + error = r1_ctx->ops->create_key(r2_ctx, key, "Software", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\Sofware failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Microsoft", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Windows", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft\\Windows failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "CurrentVersion", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Windows\\CurrentVersion failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Policies", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\CurrentVersion\\Policies failed"); + error = r1_ctx->ops->create_key(r2_ctx, newkey, "Explorer", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Policies\\Explorer failed"); + + blob.data = (void *)talloc(r2_ctx, uint32_t); + SIVAL(blob.data, 0, 0x03ffffff); + blob.length = sizeof(uint32_t); + r1_ctx->ops->set_value(newkey, "NoDrives", REG_DWORD, blob); + + /* Set test case data */ + td->r1_ctx = r1_ctx; + td->r2_ctx = r2_ctx; + + *data = td; + + return true; +} + +static bool diff_setup_preg_tcase (struct torture_context *tctx, void **data) +{ + struct diff_tcase_data *td; + WERROR error; + + diff_setup_tcase(tctx, data); + td = *data; + + td->filename = talloc_asprintf(tctx, "%s/test.pol", td->tempdir); + error = reg_preg_diff_save(tctx, td->filename, &td->callbacks, &td->callback_data); + torture_assert_werr_ok(tctx, error, "reg_preg_diff_save"); + + return true; +} + +static bool diff_setup_dotreg_tcase (struct torture_context *tctx, void **data) +{ + struct diff_tcase_data *td; + struct smb_iconv_convenience *iconv_convenience; + WERROR error; + + diff_setup_tcase(tctx, data); + td = *data; + + iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); + + td->filename = talloc_asprintf(tctx, "%s/test.reg", td->tempdir); + error = reg_dotreg_diff_save(tctx, td->filename, iconv_convenience, &td->callbacks, &td->callback_data); + torture_assert_werr_ok(tctx, error, "reg_dotreg_diff_save"); + + return true; +} +static bool diff_teardown_tcase (struct torture_context *tctx, void *data) +{ + /* Done is called by generate_diff itself! */ + + return true; +} struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx) { + struct torture_tcase *tcase; struct torture_suite *suite = torture_suite_create(mem_ctx, "DIFF"); - torture_suite_add_simple_test(suite, "test_generate_diff_key_add", - test_generate_diff_key_add); - torture_suite_add_simple_test(suite, "test_generate_diff_key_null", - test_generate_diff_key_null); - torture_suite_add_simple_test(suite, "test_diff_apply", - test_diff_apply); - torture_suite_add_simple_test(suite, "test_generate_diff", - test_generate_diff); - torture_suite_add_simple_test(suite, "test_diff_load", - test_diff_load); + + tcase = torture_suite_add_tcase(suite, "PReg"); + torture_tcase_set_fixture(tcase, diff_setup_preg_tcase, diff_teardown_tcase); + tcase_add_tests(tcase); + + tcase = torture_suite_add_tcase(suite, "dotreg"); + torture_tcase_set_fixture(tcase, diff_setup_dotreg_tcase, diff_teardown_tcase); + tcase_add_tests(tcase); + return suite; } -- cgit From 5e687d79533684949deb9bd9bc86f88eab4ae310 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Tue, 15 Apr 2008 19:57:29 +0200 Subject: Fix PReg write support. Add tests for patch files (.REG and PReg). (This used to be commit 497977c36c621a4820be51cbcb7b78eac1e292b7) --- source4/lib/registry/patchfile.c | 23 ++++++++++- source4/lib/registry/patchfile_preg.c | 72 ++++++++++++++++++++++++++++++----- source4/lib/registry/registry.h | 1 + source4/lib/registry/tests/diff.c | 19 +++++---- 4 files changed, 97 insertions(+), 18 deletions(-) diff --git a/source4/lib/registry/patchfile.c b/source4/lib/registry/patchfile.c index eaeef341bb..0ede3106f0 100644 --- a/source4/lib/registry/patchfile.c +++ b/source4/lib/registry/patchfile.c @@ -320,12 +320,33 @@ static WERROR reg_diff_apply_add_key(void *_ctx, const char *key_name) { struct registry_context *ctx = (struct registry_context *)_ctx; struct registry_key *tmp; + char *buf, *buf_ptr; WERROR error; + /* Recursively create the path */ + buf = talloc_strdup(ctx, key_name); + buf_ptr = buf; + + while (*buf_ptr++ != '\0' ) { + if (*buf_ptr == '\\') { + *buf_ptr = '\0'; + error = reg_key_add_abs(ctx, ctx, buf, 0, NULL, &tmp); + + if (!W_ERROR_EQUAL(error, WERR_ALREADY_EXISTS) && + !W_ERROR_IS_OK(error)) { + DEBUG(0, ("Error adding new key '%s': %s\n", + key_name, win_errstr(error))); + return error; + } + *buf_ptr++ = '\\'; + } + } + + /* Add the key */ error = reg_key_add_abs(ctx, ctx, key_name, 0, NULL, &tmp); if (!W_ERROR_EQUAL(error, WERR_ALREADY_EXISTS) && - !W_ERROR_IS_OK(error)) { + !W_ERROR_IS_OK(error)) { DEBUG(0, ("Error adding new key '%s': %s\n", key_name, win_errstr(error))); return error; diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c index a28096517c..ea41a9e21b 100644 --- a/source4/lib/registry/patchfile_preg.c +++ b/source4/lib/registry/patchfile_preg.c @@ -23,9 +23,12 @@ #include "lib/registry/registry.h" #include "system/filesys.h" #include "param/param.h" +#include "librpc/gen_ndr/winreg.h" struct preg_data { int fd; + TALLOC_CTX *ctx; + struct smb_iconv_convenience *ic; }; static WERROR preg_read_utf16(struct smb_iconv_convenience *ic, int fd, char *c) @@ -38,25 +41,69 @@ static WERROR preg_read_utf16(struct smb_iconv_convenience *ic, int fd, char *c) push_codepoint(ic, c, v); return WERR_OK; } - -/* FIXME These functions need to be implemented */ -static WERROR reg_preg_diff_add_key(void *_data, const char *key_name) +static WERROR preg_write_utf16(struct smb_iconv_convenience *ic, int fd, const char *string) { - return WERR_NOT_SUPPORTED; + codepoint_t v; + uint16_t i; + size_t size; + + for (i = 0; i < strlen(string); i+=size) { + v = next_codepoint(ic, &string[i], &size); + if (write(fd, &v, 2) < 2) { + return WERR_GENERAL_FAILURE; + } + } + return WERR_OK; } - -static WERROR reg_preg_diff_del_key(void *_data, const char *key_name) +/* PReg does not support adding keys. */ +static WERROR reg_preg_diff_add_key(void *_data, const char *key_name) { - return WERR_NOT_SUPPORTED; + return WERR_OK; } static WERROR reg_preg_diff_set_value(void *_data, const char *key_name, const char *value_name, uint32_t value_type, DATA_BLOB value_data) { - return WERR_NOT_SUPPORTED; + struct preg_data *data = _data; + uint32_t buf; + + preg_write_utf16(data->ic, data->fd, "["); + preg_write_utf16(data->ic, data->fd, key_name); + preg_write_utf16(data->ic, data->fd, ";"); + preg_write_utf16(data->ic, data->fd, value_name); + preg_write_utf16(data->ic, data->fd, ";"); + SIVAL(&buf, 0, value_type); + write(data->fd, &buf, sizeof(uint32_t)); + preg_write_utf16(data->ic, data->fd, ";"); + SIVAL(&buf, 0, value_data.length); + write(data->fd, &buf, sizeof(uint32_t)); + preg_write_utf16(data->ic, data->fd, ";"); + write(data->fd, value_data.data, value_data.length); + preg_write_utf16(data->ic, data->fd, "]"); + + return WERR_OK; } +static WERROR reg_preg_diff_del_key(void *_data, const char *key_name) +{ + struct preg_data *data = _data; + char *parent_name; + DATA_BLOB blob; + + parent_name = talloc_strndup(data->ctx, key_name, strrchr(key_name, '\\')-key_name); + blob.data = (void *)talloc_strndup(data->ctx, key_name, + strlen(key_name)-(strrchr(key_name, '\\')-key_name)); + blob.length = strlen((char *)blob.data)+1; + + + /* FIXME: These values should be accumulated to be written at done(). */ + reg_preg_diff_set_value(_data, parent_name, "**DeleteKeys", REG_SZ, blob); + + return WERR_OK; +} + +/* FIXME These functions need to be implemented */ static WERROR reg_preg_diff_del_value(void *_data, const char *key_name, const char *value_name) { @@ -81,6 +128,7 @@ static WERROR reg_preg_diff_done(void *_data) * Save registry diff */ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, + struct smb_iconv_convenience *ic, struct reg_diff_callbacks **callbacks, void **callback_data) { @@ -103,10 +151,14 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, } else { data->fd = STDOUT_FILENO; } + memcpy(preg_header.hdr, "PReg", 4); SIVAL(&preg_header, 4, 1); write(data->fd, (uint8_t *)&preg_header,8); + data->ctx = ctx; + data->ic = ic; + *callbacks = talloc(ctx, struct reg_diff_callbacks); (*callbacks)->add_key = reg_preg_diff_add_key; @@ -179,7 +231,8 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, *buf_ptr != ';' && buf_ptr-buf < buf_size) { buf_ptr++; } - key = talloc_asprintf(mem_ctx, "\\%s", buf); + buf[buf_ptr-buf] = '\0'; + key = talloc_strdup(mem_ctx, buf); /* Get the name */ buf_ptr = buf; @@ -187,6 +240,7 @@ _PUBLIC_ WERROR reg_preg_diff_load(int fd, *buf_ptr != ';' && buf_ptr-buf < buf_size) { buf_ptr++; } + buf[buf_ptr-buf] = '\0'; value_name = talloc_strdup(mem_ctx, buf); /* Get the type */ diff --git a/source4/lib/registry/registry.h b/source4/lib/registry/registry.h index 573379aff5..6a98a60633 100644 --- a/source4/lib/registry/registry.h +++ b/source4/lib/registry/registry.h @@ -493,6 +493,7 @@ WERROR reg_dotreg_diff_save(TALLOC_CTX *ctx, const char *filename, struct reg_diff_callbacks **callbacks, void **callback_data); WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, + struct smb_iconv_convenience *ic, struct reg_diff_callbacks **callbacks, void **callback_data); WERROR reg_generate_diff_key(struct registry_key *oldkey, diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index da62342124..4bd868ea51 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -24,6 +24,7 @@ #include "lib/registry/registry.h" #include "torture/torture.h" #include "librpc/gen_ndr/winreg.h" +#include "param/param.h" struct diff_tcase_data { struct registry_context *r1_ctx; @@ -56,13 +57,12 @@ static bool test_generate_diff(struct torture_context *tctx, void *tcase_data) static bool test_diff_load(struct torture_context *tctx, void *tcase_data) { struct diff_tcase_data *td = tcase_data; - struct smb_iconv_convenience *iconv_convenience; + struct smb_iconv_convenience *ic; struct reg_diff_callbacks *callbacks; void *data; WERROR error; - iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); - + ic = lp_iconv_convenience(tctx->lp_ctx); error = reg_diff_load(td->filename, iconv_convenience, callbacks, data); torture_assert_werr_ok(tctx, error, "reg_diff_load"); @@ -244,13 +244,16 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) static bool diff_setup_preg_tcase (struct torture_context *tctx, void **data) { struct diff_tcase_data *td; + struct smb_iconv_convenience *ic; WERROR error; diff_setup_tcase(tctx, data); td = *data; - + + ic = lp_iconv_convenience(tctx->lp_ctx); + td->filename = talloc_asprintf(tctx, "%s/test.pol", td->tempdir); - error = reg_preg_diff_save(tctx, td->filename, &td->callbacks, &td->callback_data); + error = reg_preg_diff_save(tctx, td->filename, ic, &td->callbacks, &td->callback_data); torture_assert_werr_ok(tctx, error, "reg_preg_diff_save"); return true; @@ -259,16 +262,16 @@ static bool diff_setup_preg_tcase (struct torture_context *tctx, void **data) static bool diff_setup_dotreg_tcase (struct torture_context *tctx, void **data) { struct diff_tcase_data *td; - struct smb_iconv_convenience *iconv_convenience; + struct smb_iconv_convenience *ic; WERROR error; diff_setup_tcase(tctx, data); td = *data; - iconv_convenience = smb_iconv_convenience_init(tctx, "CP850", "UTF-8", 1); + ic = lp_iconv_convenience(tctx->lp_ctx); td->filename = talloc_asprintf(tctx, "%s/test.reg", td->tempdir); - error = reg_dotreg_diff_save(tctx, td->filename, iconv_convenience, &td->callbacks, &td->callback_data); + error = reg_dotreg_diff_save(tctx, td->filename, ic, &td->callbacks, &td->callback_data); torture_assert_werr_ok(tctx, error, "reg_dotreg_diff_save"); return true; -- cgit From 439f75f522d241aa78f06572c47ff6b871289793 Mon Sep 17 00:00:00 2001 From: Wilco Baan Hofman Date: Tue, 15 Apr 2008 21:35:59 +0200 Subject: More patchfile fixes. Write support should work now. (This used to be commit cc38f2f086b92bbe65bd6e7f4e03fdf7f21ef2f6) --- source4/lib/registry/patchfile_preg.c | 27 ++++++++++++++++++++------- source4/lib/registry/tests/diff.c | 22 +++++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c index ea41a9e21b..c2bc8d10b3 100644 --- a/source4/lib/registry/patchfile_preg.c +++ b/source4/lib/registry/patchfile_preg.c @@ -92,27 +92,40 @@ static WERROR reg_preg_diff_del_key(void *_data, const char *key_name) DATA_BLOB blob; parent_name = talloc_strndup(data->ctx, key_name, strrchr(key_name, '\\')-key_name); - blob.data = (void *)talloc_strndup(data->ctx, key_name, + blob.data = (void *)talloc_strndup(data->ctx, key_name+(strrchr(key_name, '\\')-key_name)+1, strlen(key_name)-(strrchr(key_name, '\\')-key_name)); blob.length = strlen((char *)blob.data)+1; /* FIXME: These values should be accumulated to be written at done(). */ - reg_preg_diff_set_value(_data, parent_name, "**DeleteKeys", REG_SZ, blob); - - return WERR_OK; + return reg_preg_diff_set_value(data, parent_name, "**DeleteKeys", REG_SZ, blob); } -/* FIXME These functions need to be implemented */ static WERROR reg_preg_diff_del_value(void *_data, const char *key_name, const char *value_name) { - return WERR_NOT_SUPPORTED; + struct preg_data *data = _data; + char *val; + DATA_BLOB blob; + + val = talloc_asprintf(data->ctx, "**Del.%s", value_name); + + blob.data = (void *)talloc(data->ctx, uint32_t); + *(uint32_t *)blob.data = 0; + blob.length = 4; + return reg_preg_diff_set_value(data, key_name, val, REG_DWORD, blob); } static WERROR reg_preg_diff_del_all_values(void *_data, const char *key_name) { - return WERR_NOT_SUPPORTED; + struct preg_data *data = _data; + DATA_BLOB blob; + + blob.data = (void *)talloc(data->ctx, uint32_t); + *(uint32_t *)blob.data = 0; + blob.length = 4; + + return reg_preg_diff_set_value(data, key_name, "**DelVals.", REG_DWORD, blob); } static WERROR reg_preg_diff_done(void *_data) diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 4bd868ea51..492f4de0b5 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -211,21 +211,29 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) error = reg_mount_hive(r2_ctx, r2_hkcu, HKEY_CURRENT_USER, NULL); torture_assert_werr_ok(tctx, error, "Mounting hive failed"); - error = r1_ctx->ops->get_predefined_key(r2_ctx, HKEY_LOCAL_MACHINE, &key); + error = r1_ctx->ops->get_predefined_key(r1_ctx, HKEY_CURRENT_USER, &key); + torture_assert_werr_ok(tctx, error, "Opening HKEY_CURRENT_USER failed"); + error = r1_ctx->ops->create_key(r1_ctx, key, "Network", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Opening HKCU\\Network failed"); + error = r1_ctx->ops->create_key(r1_ctx, newkey, "L", NULL, NULL, &newkey); + torture_assert_werr_ok(tctx, error, "Opening HKCU\\Network\\L failed"); + + error = r2_ctx->ops->get_predefined_key(r2_ctx, HKEY_LOCAL_MACHINE, &key); torture_assert_werr_ok(tctx, error, "Opening HKEY_LOCAL_MACHINE failed"); - error = r1_ctx->ops->create_key(r2_ctx, key, "Software", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, key, "Software", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\Sofware failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Microsoft", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Microsoft", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Windows", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Windows", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\Software\\Microsoft\\Windows failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "CurrentVersion", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "CurrentVersion", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Windows\\CurrentVersion failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Policies", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Policies", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\CurrentVersion\\Policies failed"); - error = r1_ctx->ops->create_key(r2_ctx, newkey, "Explorer", NULL, NULL, &newkey); + error = r2_ctx->ops->create_key(r2_ctx, newkey, "Explorer", NULL, NULL, &newkey); torture_assert_werr_ok(tctx, error, "Creating HKLM\\..\\Policies\\Explorer failed"); + blob.data = (void *)talloc(r2_ctx, uint32_t); SIVAL(blob.data, 0, 0x03ffffff); blob.length = sizeof(uint32_t); -- cgit From f01c377bc039b776ded213f455cdb79d682ae7b2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 22:08:31 +0200 Subject: Fix formatting, remove unused function. (This used to be commit 6ec206ba58777395b2d1251680b21648f4c0f78e) --- source4/lib/registry/tests/diff.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index 492f4de0b5..c7726545f6 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -37,11 +37,6 @@ struct diff_tcase_data { static bool test_generate_diff(struct torture_context *tctx, void *tcase_data) { - /* WERROR reg_generate_diff(struct registry_context *ctx1, - struct registry_context *ctx2, - const struct reg_diff_callbacks *callbacks, - void *callback_data) - */ WERROR error; struct diff_tcase_data *td = tcase_data; @@ -97,8 +92,6 @@ static bool test_diff_apply(struct torture_context *tctx, void *tcase_data) error = td->r1_ctx->ops->open_key(td->r1_ctx, key, "Explorer", &key); torture_assert_werr_ok(tctx, error, "Opening HKLM\\..\\Policies\\Explorer failed"); - - return true; } @@ -141,6 +134,7 @@ static bool test_generate_diff_key_null(struct torture_context *tctx, void *tcas return true; } + static void tcase_add_tests (struct torture_tcase *tcase) { torture_tcase_add_simple_test(tcase, "test_generate_diff_key_add", @@ -284,23 +278,18 @@ static bool diff_setup_dotreg_tcase (struct torture_context *tctx, void **data) return true; } -static bool diff_teardown_tcase (struct torture_context *tctx, void *data) -{ - /* Done is called by generate_diff itself! */ - return true; -} struct torture_suite *torture_registry_diff(TALLOC_CTX *mem_ctx) { struct torture_tcase *tcase; struct torture_suite *suite = torture_suite_create(mem_ctx, "DIFF"); tcase = torture_suite_add_tcase(suite, "PReg"); - torture_tcase_set_fixture(tcase, diff_setup_preg_tcase, diff_teardown_tcase); + torture_tcase_set_fixture(tcase, diff_setup_preg_tcase, NULL); tcase_add_tests(tcase); tcase = torture_suite_add_tcase(suite, "dotreg"); - torture_tcase_set_fixture(tcase, diff_setup_dotreg_tcase, diff_teardown_tcase); + torture_tcase_set_fixture(tcase, diff_setup_dotreg_tcase, NULL); tcase_add_tests(tcase); return suite; -- cgit From fd01b27edd5a83306f4ce567e31d43641dd003b8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 15 Apr 2008 22:19:05 +0200 Subject: Fix const. (This used to be commit b74fc23825a54eb101b413ee76b21ee605dfb16c) --- source4/lib/registry/interface.c | 2 +- source4/lib/registry/patchfile_preg.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/lib/registry/interface.c b/source4/lib/registry/interface.c index 06b002859d..0678af5237 100644 --- a/source4/lib/registry/interface.c +++ b/source4/lib/registry/interface.c @@ -284,7 +284,7 @@ _PUBLIC_ WERROR reg_key_flush(struct registry_key *key) } _PUBLIC_ WERROR reg_set_sec_desc(struct registry_key *key, - struct security_descriptor *security) + const struct security_descriptor *security) { if (key == NULL) return WERR_INVALID_PARAM; diff --git a/source4/lib/registry/patchfile_preg.c b/source4/lib/registry/patchfile_preg.c index c2bc8d10b3..bb46495c19 100644 --- a/source4/lib/registry/patchfile_preg.c +++ b/source4/lib/registry/patchfile_preg.c @@ -165,7 +165,7 @@ _PUBLIC_ WERROR reg_preg_diff_save(TALLOC_CTX *ctx, const char *filename, data->fd = STDOUT_FILENO; } - memcpy(preg_header.hdr, "PReg", 4); + strncpy(preg_header.hdr, "PReg", 4); SIVAL(&preg_header, 4, 1); write(data->fd, (uint8_t *)&preg_header,8); -- cgit From 7ba8dca59094eb83cbcec4011b0ec632956f27af Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 13:14:36 +1000 Subject: fixes to the SMB2 lock test after recent SMB2 locking changes (This used to be commit de7626e1c29f04e54afb6d95f4051bc52b17dd80) --- source4/torture/smb2/lock.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source4/torture/smb2/lock.c b/source4/torture/smb2/lock.c index e81647b497..1a56cb9cad 100644 --- a/source4/torture/smb2/lock.c +++ b/source4/torture/smb2/lock.c @@ -90,7 +90,7 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree lck.in.file.handle.data[0] -=1; lck.in.lock_count = 0x0001; - lck.in.reserved = 0xFFFFFFFF; + lck.in.reserved = 0x123ab1; lck.in.file.handle = h; el[0].offset = UINT64_MAX; el[0].length = UINT64_MAX; @@ -100,16 +100,20 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree CHECK_STATUS(status, NT_STATUS_OK); CHECK_VALUE(lck.out.reserved, 0); + lck.in.reserved = 0x123ab2; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED); + lck.in.reserved = 0x123ab3; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); CHECK_VALUE(lck.out.reserved, 0); + lck.in.reserved = 0x123ab4; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_LOCK_NOT_GRANTED); + lck.in.reserved = 0x123ab5; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); CHECK_VALUE(lck.out.reserved, 0); @@ -162,27 +166,27 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree lck.in.file.handle = h; el[0].offset = 0x00000000FFFFFFFF; el[0].length = 0x00000000FFFFFFFF; - el[0].reserved = 0x12345678; + el[0].reserved = 0x1234567; el[0].flags = SMB2_LOCK_FLAG_UNLOCK; status = smb2_lock(tree, &lck); - CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + CHECK_STATUS(status, NT_STATUS_OK); lck.in.lock_count = 0x0001; - lck.in.reserved = 0x12345678; + lck.in.reserved = 0x1234567; lck.in.file.handle = h; el[0].offset = 0x00000000FFFFFFFF; el[0].length = 0x00000000FFFFFFFF; el[0].reserved = 0x00000000; el[0].flags = SMB2_LOCK_FLAG_UNLOCK; status = smb2_lock(tree, &lck); - CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + CHECK_STATUS(status, NT_STATUS_OK); status = smb2_lock(tree, &lck); - CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + CHECK_STATUS(status, NT_STATUS_OK); status = smb2_lock(tree, &lck); - CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + CHECK_STATUS(status, NT_STATUS_OK); status = smb2_lock(tree, &lck); - CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + CHECK_STATUS(status, NT_STATUS_OK); done: return ret; -- cgit From 72739ac0d0bdd965264a69a6e796fd412b42d628 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 13:14:55 +1000 Subject: badly formed SMB2 packets get NT_STATUS_INVALID_PARAMETER (This used to be commit 1c5dd2d1b655218f875a4e512ed3e94fee624fe4) --- source4/smb_server/smb2/smb2_server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/smb_server/smb2/smb2_server.h b/source4/smb_server/smb2/smb2_server.h index fc40a92efc..ae4abbd71e 100644 --- a/source4/smb_server/smb2/smb2_server.h +++ b/source4/smb_server/smb2/smb2_server.h @@ -78,13 +78,13 @@ struct smbsrv_request; if (is_size < (size)) { \ DEBUG(0,("%s: buffer too small 0x%x. Expected 0x%x\n", \ __location__, (unsigned)is_size, (unsigned)want_size)); \ - smb2srv_send_error(req, NT_STATUS_FOOBAR); \ + smb2srv_send_error(req, NT_STATUS_INVALID_PARAMETER); \ return; \ }\ if (field_size != want_size) { \ DEBUG(0,("%s: unexpected fixed body size 0x%x. Expected 0x%x\n", \ __location__, (unsigned)field_size, (unsigned)want_size)); \ - smb2srv_send_error(req, NT_STATUS_FOOBAR); \ + smb2srv_send_error(req, NT_STATUS_INVALID_PARAMETER); \ return; \ } \ } while (0) -- cgit From 8f599b3781dac43c47b064d9bafc89e389b7c0db Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 13:43:04 +1000 Subject: added SMB2 gentest generation of SMB2 echo packets (This used to be commit 8f7cfa5d2e190ddb74ba859a3f68ec0ed33ae089) --- source4/torture/gentest_smb2.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index fc6dbcbb9a..71101dd672 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -1194,6 +1194,18 @@ static bool handler_flush(int instance) return true; } +/* + generate echo operations +*/ +static bool handler_echo(int instance) +{ + NTSTATUS status[NSERVERS]; + + GEN_CALL(smb2_keepalive(tree->session->transport)); + + return true; +} + #if 0 /* @@ -1606,6 +1618,7 @@ static struct { {"WRITE", handler_write}, {"LOCK", handler_lock}, {"FLUSH", handler_flush}, + {"ECHO", handler_echo}, }; -- cgit From dec930448f957aca7e70e975221a2ac060819b2e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 14:49:21 +1000 Subject: fixed parsing of the SMB2 ALL_INFO qfileinfo level (This used to be commit a7be5ba22e0cf2c61501f5a05e64673f31ba145c) --- source4/libcli/raw/interfaces.h | 3 ++- source4/libcli/raw/rawfileinfo.c | 3 ++- source4/smb_server/blob.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 3370021d48..bae0e67b02 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -684,7 +684,8 @@ union smb_fileinfo { uint32_t ea_size; uint32_t access_mask; uint64_t position; - uint64_t mode; + uint32_t mode; + uint32_t alignment_requirement; struct smb_wire_string fname; } out; } all_info2; diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 71900be49c..0ea5a93606 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -243,7 +243,8 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ parms->all_info2.out.ea_size = IVAL(blob->data, 0x48); parms->all_info2.out.access_mask = IVAL(blob->data, 0x4C); parms->all_info2.out.position = BVAL(blob->data, 0x50); - parms->all_info2.out.mode = BVAL(blob->data, 0x58); + parms->all_info2.out.mode = IVAL(blob->data, 0x58); + parms->all_info2.out.alignment_requirement = IVAL(blob->data, 0x5C); smbcli_blob_pull_string(NULL, mem_ctx, blob, &parms->all_info2.out.fname, 0x60, 0x64, STR_UNICODE); return NT_STATUS_OK; diff --git a/source4/smb_server/blob.c b/source4/smb_server/blob.c index 8834c4483c..65cdd2aea6 100644 --- a/source4/smb_server/blob.c +++ b/source4/smb_server/blob.c @@ -503,7 +503,8 @@ NTSTATUS smbsrv_push_passthru_fileinfo(TALLOC_CTX *mem_ctx, SIVAL(blob->data, 0x48, st->all_info2.out.ea_size); SIVAL(blob->data, 0x4C, st->all_info2.out.access_mask); SBVAL(blob->data, 0x50, st->all_info2.out.position); - SBVAL(blob->data, 0x58, st->all_info2.out.mode); + SIVAL(blob->data, 0x58, st->all_info2.out.mode); + SIVAL(blob->data, 0x5C, st->all_info2.out.alignment_requirement); BLOB_CHECK(smbsrv_blob_append_string(mem_ctx, blob, st->all_info2.out.fname.s, 0x60, default_str_flags, -- cgit From 61e78a2c611f68a63203d8457c50ec923b52e7ae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 14:50:36 +1000 Subject: minor cleanup in SMB2 getinfo test (This used to be commit b139b471072f20288f126b5a9ee7613cc6c40681) --- source4/torture/smb2/getinfo.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source4/torture/smb2/getinfo.c b/source4/torture/smb2/getinfo.c index c47a26277c..906d6e4f8d 100644 --- a/source4/torture/smb2/getinfo.c +++ b/source4/torture/smb2/getinfo.c @@ -51,9 +51,9 @@ static struct { { LEVEL(RAW_FILEINFO_COMPRESSION_INFORMATION) }, { LEVEL(RAW_FILEINFO_NETWORK_OPEN_INFORMATION) }, { LEVEL(RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION) }, -/* -disabled until we know how the alignment now works -{ LEVEL(RAW_FILEINFO_SMB2_ALL_EAS) }, */ +/* + { LEVEL(RAW_FILEINFO_SMB2_ALL_EAS) }, +*/ { LEVEL(RAW_FILEINFO_SMB2_ALL_INFORMATION) }, { LEVEL(RAW_FILEINFO_SEC_DESC) } }; @@ -107,9 +107,6 @@ static bool torture_smb2_fileinfo(struct torture_context *tctx, struct smb2_tree file_levels[i].dinfo.query_secdesc.in.secinfo_flags = 0x7; } if (file_levels[i].level == RAW_FILEINFO_SMB2_ALL_EAS) { - if (torture_setting_bool(tctx, "samba4", false)) { - continue; - } file_levels[i].finfo.all_eas.in.continue_flags = SMB2_CONTINUE_FLAG_RESTART; file_levels[i].dinfo.all_eas.in.continue_flags = @@ -183,6 +180,9 @@ bool torture_smb2_getinfo(struct torture_context *torture) return false; } + smb2_deltree(tree, FNAME); + smb2_deltree(tree, DNAME); + status = torture_setup_complex_file(tree, FNAME); if (!NT_STATUS_IS_OK(status)) { return false; -- cgit From ae629621da1a4d45a30fbf6c6ea1da99f01f8527 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 14:51:32 +1000 Subject: added --maskindexing and qfileinfo testing - added --maskindexing to mask the 0x2000 noindex bit in file attributes - added testing of qfileinfo in gentest_smb2 (This used to be commit 3883a7286fd32cd6c77269f67d1366c3b946b5a0) --- source4/torture/gentest_smb2.c | 183 +++++++++++++---------------------------- 1 file changed, 59 insertions(+), 124 deletions(-) diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index 71101dd672..8075465737 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -53,6 +53,7 @@ static struct gentest_options { const char *seeds_file; int use_preset_seeds; int fast_reconnect; + int mask_indexing; } options; /* mapping between open handles on the server and local handles */ @@ -542,15 +543,6 @@ static uint16_t gen_lock_flags(void) SMB2_LOCK_FLAG_FAIL_IMMEDIATELY); } -/* - generate a pid -*/ -static uint16_t gen_pid(void) -{ - if (gen_chance(10)) return gen_bits_mask(0xFFFF); - return getpid(); -} - /* generate a lock count */ @@ -598,34 +590,6 @@ static uint32_t gen_open_disp(void) return gen_int_range(0, 5); } -/* - generate an openx open mode -*/ -static uint16_t gen_openx_mode(void) -{ - if (gen_chance(20)) return gen_bits_mask(0xFFFF); - if (gen_chance(20)) return gen_bits_mask(0xFF); - return OPENX_MODE_DENY_NONE | gen_bits_mask(0x3); -} - -/* - generate an openx flags field -*/ -static uint16_t gen_openx_flags(void) -{ - if (gen_chance(20)) return gen_bits_mask(0xFFFF); - return gen_bits_mask(0x7); -} - -/* - generate an openx open function -*/ -static uint16_t gen_openx_func(void) -{ - if (gen_chance(20)) return gen_bits_mask(0xFFFF); - return gen_bits_mask(0x13); -} - /* generate a file attrib combination */ @@ -953,6 +917,16 @@ again: #define CHECK_EQUAL(field) do { \ if (parm[0].field != parm[1].field && !ignore_pattern(#field)) { \ + printf("Mismatch in %s - 0x%llx 0x%llx\n", #field, \ + (unsigned long long)parm[0].field, (unsigned long long)parm[1].field); \ + return false; \ + } \ +} while(0) + +#define CHECK_ATTRIB(field) do { \ + if (!options.mask_indexing) { \ + CHECK_EQUAL(field); \ + } else if ((~FILE_ATTRIBUTE_NONINDEXED & parm[0].field) != (~FILE_ATTRIBUTE_NONINDEXED & parm[1].field) && !ignore_pattern(#field)) { \ printf("Mismatch in %s - 0x%x 0x%x\n", #field, \ (int)parm[0].field, (int)parm[1].field); \ return false; \ @@ -1044,7 +1018,7 @@ static bool handler_create(int instance) CHECK_NTTIMES_EQUAL(out.change_time); CHECK_EQUAL(out.alloc_size); CHECK_EQUAL(out.size); - CHECK_EQUAL(out.file_attr); + CHECK_ATTRIB(out.file_attr); CHECK_EQUAL(out.reserved2); /* ntcreatex creates a new file handle */ @@ -1077,7 +1051,7 @@ static bool handler_close(int instance) CHECK_NTTIMES_EQUAL(out.change_time); CHECK_EQUAL(out.alloc_size); CHECK_EQUAL(out.size); - CHECK_EQUAL(out.file_attr); + CHECK_ATTRIB(out.file_attr); REMOVE_HANDLE(in.file.handle); @@ -1206,7 +1180,7 @@ static bool handler_echo(int instance) return true; } -#if 0 + /* generate a fileinfo query structure @@ -1219,16 +1193,13 @@ static void gen_fileinfo(int instance, union smb_fileinfo *info) enum smb_fileinfo_level level; const char *name; } levels[] = { - LVL(GETATTR), LVL(GETATTRE), LVL(STANDARD), - LVL(EA_SIZE), LVL(ALL_EAS), LVL(IS_NAME_VALID), - LVL(BASIC_INFO), LVL(STANDARD_INFO), LVL(EA_INFO), - LVL(NAME_INFO), LVL(ALL_INFO), LVL(ALT_NAME_INFO), - LVL(STREAM_INFO), LVL(COMPRESSION_INFO), LVL(BASIC_INFORMATION), + LVL(BASIC_INFORMATION), LVL(STANDARD_INFORMATION), LVL(INTERNAL_INFORMATION), LVL(EA_INFORMATION), LVL(ACCESS_INFORMATION), LVL(NAME_INFORMATION), LVL(POSITION_INFORMATION), - LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(ALL_INFORMATION), + LVL(MODE_INFORMATION), LVL(ALIGNMENT_INFORMATION), LVL(SMB2_ALL_INFORMATION), LVL(ALT_NAME_INFORMATION), LVL(STREAM_INFORMATION), LVL(COMPRESSION_INFORMATION), - LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION) + LVL(NETWORK_OPEN_INFORMATION), LVL(ATTRIBUTE_TAG_INFORMATION), + LVL(SMB2_ALL_EAS), LVL(SMB2_ALL_INFORMATION), }; do { i = gen_int_range(0, ARRAY_SIZE(levels)-1); @@ -1250,62 +1221,14 @@ static bool cmp_fileinfo(int instance, case RAW_FILEINFO_GENERIC: return false; - case RAW_FILEINFO_GETATTR: - CHECK_EQUAL(getattr.out.attrib); - CHECK_EQUAL(getattr.out.size); - CHECK_TIMES_EQUAL(getattr.out.write_time); - break; - - case RAW_FILEINFO_GETATTRE: - CHECK_TIMES_EQUAL(getattre.out.create_time); - CHECK_TIMES_EQUAL(getattre.out.access_time); - CHECK_TIMES_EQUAL(getattre.out.write_time); - CHECK_EQUAL(getattre.out.size); - CHECK_EQUAL(getattre.out.alloc_size); - CHECK_EQUAL(getattre.out.attrib); - break; - - case RAW_FILEINFO_STANDARD: - CHECK_TIMES_EQUAL(standard.out.create_time); - CHECK_TIMES_EQUAL(standard.out.access_time); - CHECK_TIMES_EQUAL(standard.out.write_time); - CHECK_EQUAL(standard.out.size); - CHECK_EQUAL(standard.out.alloc_size); - CHECK_EQUAL(standard.out.attrib); - break; - - case RAW_FILEINFO_EA_SIZE: - CHECK_TIMES_EQUAL(ea_size.out.create_time); - CHECK_TIMES_EQUAL(ea_size.out.access_time); - CHECK_TIMES_EQUAL(ea_size.out.write_time); - CHECK_EQUAL(ea_size.out.size); - CHECK_EQUAL(ea_size.out.alloc_size); - CHECK_EQUAL(ea_size.out.attrib); - CHECK_EQUAL(ea_size.out.ea_size); - break; - - case RAW_FILEINFO_ALL_EAS: - CHECK_EQUAL(all_eas.out.num_eas); - for (i=0;i Date: Thu, 22 May 2008 15:35:52 +1000 Subject: added EAs in the generated SMB2 create operation (This used to be commit 607bf6a946ffd7f768bda44c461ee82fcfc101c1) --- source4/torture/gentest_smb2.c | 44 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index 8075465737..a219403b27 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -684,6 +684,21 @@ static struct ea_struct gen_ea_struct(void) return ea; } +/* + generate an ea_struct +*/ +static struct smb_ea_list gen_ea_list(void) +{ + struct smb_ea_list eas; + int i; + eas.num_eas = gen_int_range(0, 3); + eas.eas = talloc_array(current_op.mem_ctx, struct ea_struct, eas.num_eas); + for (i=0;igeneric.level = levels[i].level; switch (info->generic.level) { - case RAW_SFILEINFO_SETATTR: - info->setattr.in.attrib = gen_attrib(); - info->setattr.in.write_time = gen_timet(); - break; - case RAW_SFILEINFO_SETATTRE: - info->setattre.in.create_time = gen_timet(); - info->setattre.in.access_time = gen_timet(); - info->setattre.in.write_time = gen_timet(); - break; - case RAW_SFILEINFO_STANDARD: - info->standard.in.create_time = gen_timet(); - info->standard.in.access_time = gen_timet(); - info->standard.in.write_time = gen_timet(); - break; case RAW_SFILEINFO_EA_SET: { static struct ea_struct ea; info->ea_set.in.num_eas = 1; @@ -1467,6 +1462,7 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info) } } +#if 0 /* generate setfileinfo operations */ @@ -1481,14 +1477,12 @@ static bool handler_sfileinfo(int instance) GEN_COPY_PARM; GEN_SET_FNUM(generic.in.file.fnum); - GEN_CALL(smb_raw_setfileinfo(tree, &parm[i])); + GEN_CALL(smb2_setinfo_file(tree, &parm[i])); return true; } - #endif - /* wipe any relevant files */ -- cgit From af82204f4355ac9011b61019bbbe40e7e3632d4c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 15:44:13 +1000 Subject: added testing of SMB2 setfileinfo in gentest_smb2 (This used to be commit c38658c6c05fd65d729693904d35886431582537) --- source4/torture/gentest_smb2.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index a219403b27..ef1ce9aadd 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -1406,14 +1406,6 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info) info->generic.level = levels[i].level; switch (info->generic.level) { - case RAW_SFILEINFO_EA_SET: { - static struct ea_struct ea; - info->ea_set.in.num_eas = 1; - info->ea_set.in.eas = &ea; - info->ea_set.in.eas[0] = gen_ea_struct(); - } - break; - case RAW_SFILEINFO_BASIC_INFO: case RAW_SFILEINFO_BASIC_INFORMATION: info->basic_info.in.create_time = gen_nttime(); info->basic_info.in.access_time = gen_nttime(); @@ -1421,15 +1413,12 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info) info->basic_info.in.change_time = gen_nttime(); info->basic_info.in.attrib = gen_attrib(); break; - case RAW_SFILEINFO_DISPOSITION_INFO: case RAW_SFILEINFO_DISPOSITION_INFORMATION: info->disposition_info.in.delete_on_close = gen_bool(); break; - case RAW_SFILEINFO_ALLOCATION_INFO: case RAW_SFILEINFO_ALLOCATION_INFORMATION: info->allocation_info.in.alloc_size = gen_alloc_size(); break; - case RAW_SFILEINFO_END_OF_FILE_INFO: case RAW_SFILEINFO_END_OF_FILE_INFORMATION: info->end_of_file_info.in.size = gen_offset(); break; @@ -1447,22 +1436,17 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info) break; case RAW_SFILEINFO_GENERIC: case RAW_SFILEINFO_SEC_DESC: - case RAW_SFILEINFO_UNIX_BASIC: - case RAW_SFILEINFO_UNIX_LINK: - case RAW_SFILEINFO_UNIX_HLINK: case RAW_SFILEINFO_1023: case RAW_SFILEINFO_1025: case RAW_SFILEINFO_1029: case RAW_SFILEINFO_1032: case RAW_SFILEINFO_1039: case RAW_SFILEINFO_1040: - case RAW_SFILEINFO_UNIX_INFO2: /* Untested */ break; } } -#if 0 /* generate setfileinfo operations */ @@ -1476,12 +1460,11 @@ static bool handler_sfileinfo(int instance) gen_setfileinfo(instance, &parm[0]); GEN_COPY_PARM; - GEN_SET_FNUM(generic.in.file.fnum); + GEN_SET_FNUM(generic.in.file.handle); GEN_CALL(smb2_setinfo_file(tree, &parm[i])); return true; } -#endif /* wipe any relevant files @@ -1546,7 +1529,8 @@ static struct { {"LOCK", handler_lock}, {"FLUSH", handler_flush}, {"ECHO", handler_echo}, - {"FILEINFO", handler_qfileinfo}, + {"QFILEINFO", handler_qfileinfo}, + {"SFILEINFO", handler_sfileinfo}, }; -- cgit From 7a9ffeca21666935ba08cd909b63fc063f7607f7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 17:53:50 +1000 Subject: check for invalid file attribute values in create (This used to be commit dd21e3d9d788a67d4673625ed4892a875f4600dc) --- source4/ntvfs/posix/pvfs_open.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 67937324cc..cc4f0add27 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -548,6 +548,10 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs, uint32_t oplock_level = OPLOCK_NONE, oplock_granted; bool allow_level_II_oplock = false; + if (io->ntcreatex.in.file_attr & ~FILE_ATTRIBUTE_ALL_MASK) { + return NT_STATUS_INVALID_PARAMETER; + } + if ((io->ntcreatex.in.file_attr & FILE_ATTRIBUTE_READONLY) && (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) { return NT_STATUS_CANNOT_DELETE; -- cgit From a6e5c70da75e62c84eff0911c279c6a9b0b00b45 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 17:54:06 +1000 Subject: added a define for all valid file attributes (This used to be commit 198ed9336756f973cebd7cc3df7f51e2c4575205) --- source4/libcli/raw/smb.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index e054ed6522..74869e8a45 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -370,6 +370,7 @@ #define FILE_ATTRIBUTE_OFFLINE 0x1000 #define FILE_ATTRIBUTE_NONINDEXED 0x2000 #define FILE_ATTRIBUTE_ENCRYPTED 0x4000 +#define FILE_ATTRIBUTE_ALL_MASK 0x7FFF /* Flags - combined with attributes. */ #define FILE_FLAG_WRITE_THROUGH 0x80000000L -- cgit From d5def936fe67c1cde2c4ed00834c4ce325dfcb55 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 22:46:29 +1000 Subject: pass in the required alignment to the EA construction routines (This used to be commit af31030e0b78b6b220740529901ec8d2d9f5a3fe) --- source4/libcli/raw/raweas.c | 9 +++++---- source4/libcli/raw/rawfile.c | 4 ++-- source4/libcli/smb2/create.c | 4 ++-- source4/smb_server/blob.c | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 8ea8e621c9..07b517ade3 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -54,13 +54,13 @@ static uint_t ea_name_list_size(uint_t num_names, struct ea_name *eas) This assumes the names are strict ascii, which should be a reasonable assumption */ -size_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas) +size_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas, unsigned alignment) { uint_t total = 0; int i; for (i=0;intcreatex.in.ea_list) { uint32_t ea_size = ea_list_size_chained(parms->ntcreatex.in.ea_list->num_eas, - parms->ntcreatex.in.ea_list->eas); + parms->ntcreatex.in.ea_list->eas, 4); ea_blob = data_blob_talloc(mem_ctx, NULL, ea_size); if (ea_blob.data == NULL) { return NULL; } ea_put_list_chained(ea_blob.data, parms->ntcreatex.in.ea_list->num_eas, - parms->ntcreatex.in.ea_list->eas); + parms->ntcreatex.in.ea_list->eas, 4); } nt.in.params = data_blob_talloc(mem_ctx, NULL, 53); diff --git a/source4/libcli/smb2/create.c b/source4/libcli/smb2/create.c index 6ac32a494f..9d28bbf8c4 100644 --- a/source4/libcli/smb2/create.c +++ b/source4/libcli/smb2/create.c @@ -117,8 +117,8 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create if (io->in.eas.num_eas != 0) { DATA_BLOB b = data_blob_talloc(req, NULL, - ea_list_size_chained(io->in.eas.num_eas, io->in.eas.eas)); - ea_put_list_chained(b.data, io->in.eas.num_eas, io->in.eas.eas); + ea_list_size_chained(io->in.eas.num_eas, io->in.eas.eas, 8)); + ea_put_list_chained(b.data, io->in.eas.num_eas, io->in.eas.eas, 8); status = smb2_create_blob_add(req, &io->in.blobs, SMB2_CREATE_TAG_EXTA, b); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/smb_server/blob.c b/source4/smb_server/blob.c index 65cdd2aea6..cea4c60e59 100644 --- a/source4/smb_server/blob.c +++ b/source4/smb_server/blob.c @@ -476,12 +476,12 @@ NTSTATUS smbsrv_push_passthru_fileinfo(TALLOC_CTX *mem_ctx, } list_size = ea_list_size_chained(st->all_eas.out.num_eas, - st->all_eas.out.eas); + st->all_eas.out.eas, 8); BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size)); ea_put_list_chained(blob->data, st->all_eas.out.num_eas, - st->all_eas.out.eas); + st->all_eas.out.eas, 8); return NT_STATUS_OK; case RAW_FILEINFO_SMB2_ALL_INFORMATION: -- cgit From 1ea0466289d782a52192a15c519237f7fdbe7a55 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 22:46:43 +1000 Subject: added a --noeas option to gentest_smb2 (This used to be commit 9d523debb7ee59bdadf9865e023be370b7ab7b39) --- source4/torture/gentest_smb2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index ef1ce9aadd..6546ba6768 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -54,6 +54,7 @@ static struct gentest_options { int use_preset_seeds; int fast_reconnect; int mask_indexing; + int no_eas; } options; /* mapping between open handles on the server and local handles */ @@ -691,6 +692,10 @@ static struct smb_ea_list gen_ea_list(void) { struct smb_ea_list eas; int i; + if (options.no_eas) { + ZERO_STRUCT(eas); + return eas; + } eas.num_eas = gen_int_range(0, 3); eas.eas = talloc_array(current_op.mem_ctx, struct ea_struct, eas.num_eas); for (i=0;i Date: Thu, 22 May 2008 23:00:08 +1000 Subject: fixes for EAs and filename in gentest_smb2 results - SMB2 returns 0 for a null EA - return the share qualified name for the filename in SMB2 ALL_INFO level (This used to be commit f9708184a2037f83ebb97c847414326a42436154) --- source4/ntvfs/posix/pvfs_qfileinfo.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source4/ntvfs/posix/pvfs_qfileinfo.c b/source4/ntvfs/posix/pvfs_qfileinfo.c index 6bc21e5e3e..102660a0bf 100644 --- a/source4/ntvfs/posix/pvfs_qfileinfo.c +++ b/source4/ntvfs/posix/pvfs_qfileinfo.c @@ -298,10 +298,21 @@ static NTSTATUS pvfs_map_fileinfo(struct pvfs_state *pvfs, (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)? 1 : 0; info->all_info2.out.file_id = name->dos.file_id; info->all_info2.out.ea_size = name->dos.ea_size; + if (info->all_info2.out.ea_size == 4) { + /* SMB2 uses zero for a empty EA set */ + info->all_info2.out.ea_size = 0; + } info->all_info2.out.access_mask = 0; /* only set by qfileinfo */ info->all_info2.out.position = 0; /* only set by qfileinfo */ info->all_info2.out.mode = 0; /* only set by qfileinfo */ - info->all_info2.out.fname.s = name->original_name; + /* windows wants the full path on disk for this + result, but I really don't want to expose that on + the wire, so I'll give the path with a share + prefix, which is a good approximation */ + info->all_info2.out.fname.s = talloc_asprintf(req, "\\%s\\%s", + pvfs->share_name, + name->original_name); + NT_STATUS_HAVE_NO_MEMORY(info->all_info2.out.fname.s); return NT_STATUS_OK; } -- cgit From 5ab27ba7f0facbad4ba14b4246bc47e05b5da347 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 22 May 2008 15:00:19 +0200 Subject: libreplace: we need to use AC_TRY_LINK() to make sure HAVE_IPV6 is correctly detected metze (This used to be commit 84b5652d3e5766521436e4c7d59615b08b2bb198) --- source4/lib/replace/libreplace_network.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/lib/replace/libreplace_network.m4 b/source4/lib/replace/libreplace_network.m4 index 6cde6b9e0c..4edb55c03a 100644 --- a/source4/lib/replace/libreplace_network.m4 +++ b/source4/lib/replace/libreplace_network.m4 @@ -341,7 +341,7 @@ fi dnl test for ipv6 AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[ - AC_TRY_COMPILE([ + AC_TRY_LINK([ #include /* for NULL */ #include #include -- cgit From 2e0f61a18ab002a90faa06477fa258e36b8a5fc0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 23:07:16 +1000 Subject: SMB2 read returns NT_STATUS_END_OF_FILE on read past end of file (This used to be commit 1590494daf5abe43e43402e7602f92267bcda34b) --- source4/ntvfs/ntvfs_generic.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c index a706e621c9..62a1427405 100644 --- a/source4/ntvfs/ntvfs_generic.c +++ b/source4/ntvfs/ntvfs_generic.c @@ -1276,6 +1276,11 @@ static NTSTATUS ntvfs_map_read_finish(struct ntvfs_module_context *ntvfs, rd->smb2.out.data.length= rd2->generic.out.nread; rd->smb2.out.remaining = 0; rd->smb2.out.reserved = 0; + if (NT_STATUS_IS_OK(status) && + rd->smb2.out.data.length == 0 && + rd->smb2.in.length != 0) { + status = NT_STATUS_END_OF_FILE; + } break; default: return NT_STATUS_INVALID_LEVEL; -- cgit From ec7a6ee8ab25f4550a68b286d9eba32b955a73a1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 May 2008 00:07:12 +1000 Subject: fix make test for EAs again - go back to 4 byte alignment until I work out the rules that Vista wants more exactly - add the zero sized EA handling for SMB2 more generically (This used to be commit 326b69bc8064cbea357864cecd6bd27b50c57184) --- source4/libcli/smb2/create.c | 4 ++-- source4/ntvfs/posix/pvfs_fileinfo.c | 5 +++++ source4/ntvfs/posix/pvfs_qfileinfo.c | 4 ---- source4/smb_server/blob.c | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source4/libcli/smb2/create.c b/source4/libcli/smb2/create.c index 9d28bbf8c4..b1b8b0ccfa 100644 --- a/source4/libcli/smb2/create.c +++ b/source4/libcli/smb2/create.c @@ -117,8 +117,8 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create if (io->in.eas.num_eas != 0) { DATA_BLOB b = data_blob_talloc(req, NULL, - ea_list_size_chained(io->in.eas.num_eas, io->in.eas.eas, 8)); - ea_put_list_chained(b.data, io->in.eas.num_eas, io->in.eas.eas, 8); + ea_list_size_chained(io->in.eas.num_eas, io->in.eas.eas, 4)); + ea_put_list_chained(b.data, io->in.eas.num_eas, io->in.eas.eas, 4); status = smb2_create_blob_add(req, &io->in.blobs, SMB2_CREATE_TAG_EXTA, b); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/ntvfs/posix/pvfs_fileinfo.c b/source4/ntvfs/posix/pvfs_fileinfo.c index 4c383ed45d..e35f42e955 100644 --- a/source4/ntvfs/posix/pvfs_fileinfo.c +++ b/source4/ntvfs/posix/pvfs_fileinfo.c @@ -75,6 +75,11 @@ NTSTATUS pvfs_fill_dos_info(struct pvfs_state *pvfs, struct pvfs_filename *name, name->dos.alloc_size = pvfs_round_alloc_size(pvfs, name->st.st_size); name->dos.nlink = name->st.st_nlink; name->dos.ea_size = 4; + if (pvfs->ntvfs->ctx->protocol == PROTOCOL_SMB2) { + /* SMB2 represents a null EA with zero bytes */ + name->dos.ea_size = 0; + } + name->dos.file_id = (((uint64_t)name->st.st_dev)<<32) | name->st.st_ino; name->dos.flags = 0; diff --git a/source4/ntvfs/posix/pvfs_qfileinfo.c b/source4/ntvfs/posix/pvfs_qfileinfo.c index 102660a0bf..6e3092b744 100644 --- a/source4/ntvfs/posix/pvfs_qfileinfo.c +++ b/source4/ntvfs/posix/pvfs_qfileinfo.c @@ -298,10 +298,6 @@ static NTSTATUS pvfs_map_fileinfo(struct pvfs_state *pvfs, (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)? 1 : 0; info->all_info2.out.file_id = name->dos.file_id; info->all_info2.out.ea_size = name->dos.ea_size; - if (info->all_info2.out.ea_size == 4) { - /* SMB2 uses zero for a empty EA set */ - info->all_info2.out.ea_size = 0; - } info->all_info2.out.access_mask = 0; /* only set by qfileinfo */ info->all_info2.out.position = 0; /* only set by qfileinfo */ info->all_info2.out.mode = 0; /* only set by qfileinfo */ diff --git a/source4/smb_server/blob.c b/source4/smb_server/blob.c index cea4c60e59..368b81d18e 100644 --- a/source4/smb_server/blob.c +++ b/source4/smb_server/blob.c @@ -476,12 +476,12 @@ NTSTATUS smbsrv_push_passthru_fileinfo(TALLOC_CTX *mem_ctx, } list_size = ea_list_size_chained(st->all_eas.out.num_eas, - st->all_eas.out.eas, 8); + st->all_eas.out.eas, 4); BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, list_size)); ea_put_list_chained(blob->data, st->all_eas.out.num_eas, - st->all_eas.out.eas, 8); + st->all_eas.out.eas, 4); return NT_STATUS_OK; case RAW_FILEINFO_SMB2_ALL_INFORMATION: -- cgit From 8ef3218c35f05e595d4fb49a79ebf9270cfbfd3b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 15:13:13 +0200 Subject: Add some notes about further enhancements of the Python pidl backend. (This used to be commit 8e4cd10e3fde9b52552549a9553cdd25ef30d6dd) --- source4/pidl/TODO | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source4/pidl/TODO b/source4/pidl/TODO index f1cca0ab23..bc5c49a46f 100644 --- a/source4/pidl/TODO +++ b/source4/pidl/TODO @@ -1,6 +1,3 @@ -- EJS output backend shouldn't use the NDR levels stuff but instead - as the "C levels" and NDR levels don't necessarily match. - - true multiple dimension array / strings in arrays support - compatibility mode for generating MIDL-readable data: @@ -31,3 +28,15 @@ - remove NDR_AUTO_REF_ALLOC flag - automatic test generator based on IDL pointer types + +- support converting structs to tuples in Python rather than objects +- convert structs with a single mattering member to that member directly, e.g.: + struct bar { + int size; + [size_is(size)] uint32 *array; + }; + + should be converted to an array of uint32's + +- python: fill in size members automatically in some places if the struct isn't being returned + (so we don't have to cope with the array growing) -- cgit From d0b355109705f70e848c58ccc4b7b5f0a9eaab40 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 16:50:14 +0200 Subject: Add some docstrings to credentials python module. (This used to be commit 7b4435a68c5515f2ec09c8ba251d11ca1427748d) --- source4/auth/credentials/credentials.i | 33 ++++++++--- source4/auth/credentials/credentials.py | 91 +++++++++++++++++++++++++++++ source4/auth/credentials/credentials_wrap.c | 75 ++++++++++++++++++------ 3 files changed, 174 insertions(+), 25 deletions(-) diff --git a/source4/auth/credentials/credentials.i b/source4/auth/credentials/credentials.i index 152d2e673c..89eb4924b3 100644 --- a/source4/auth/credentials/credentials.i +++ b/source4/auth/credentials/credentials.i @@ -59,36 +59,53 @@ typedef struct cli_credentials { return cli_credentials_init(NULL); } /* username */ + %feature("docstring") get_username "S.get_username() -> username\nObtain username."; const char *get_username(void); + %feature("docstring") set_username "S.set_username(name, obtained=CRED_SPECIFIED) -> None\nChange username."; bool set_username(const char *value, - enum credentials_obtained=CRED_SPECIFIED); + enum credentials_obtained obtained=CRED_SPECIFIED); /* password */ + %feature("docstring") get_password "S.get_password() -> password\n" \ + "Obtain password."; const char *get_password(void); + %feature("docstring") set_password "S.set_password(password, obtained=CRED_SPECIFIED) -> None\n" \ + "Change password."; bool set_password(const char *val, - enum credentials_obtained=CRED_SPECIFIED); + enum credentials_obtained obtained=CRED_SPECIFIED); /* domain */ + %feature("docstring") get_password "S.get_domain() -> domain\nObtain domain name."; const char *get_domain(void); + %feature("docstring") set_domain "S.set_domain(domain, obtained=CRED_SPECIFIED) -> None\n" \ + "Change domain name."; bool set_domain(const char *val, - enum credentials_obtained=CRED_SPECIFIED); + enum credentials_obtained obtained=CRED_SPECIFIED); /* realm */ + %feature("docstring") get_realm "S.get_realm() -> realm\nObtain realm name."; const char *get_realm(void); + %feature("docstring") set_realm "S.set_realm(realm, obtained=CRED_SPECIFIED) -> None\n" \ + "Change realm name."; bool set_realm(const char *val, - enum credentials_obtained=CRED_SPECIFIED); + enum credentials_obtained obtained=CRED_SPECIFIED); - /* Kerberos */ + /* Kerberos */ void set_kerberos_state(enum credentials_use_kerberos use_kerberos); + %feature("docstring") parse_string "S.parse_string(text, obtained=CRED_SPECIFIED) -> None\n" \ + "Parse credentials string."; void parse_string(const char *text, - enum credentials_obtained=CRED_SPECIFIED); + enum credentials_obtained obtained=CRED_SPECIFIED); /* bind dn */ + %feature("docstring") get_bind_dn "S.get_bind_dn() -> bind dn\nObtain bind DN."; const char *get_bind_dn(void); + %feature("docstring") set_bind_dn "S.set_bind_dn(bind_dn) -> None\nChange bind DN."; bool set_bind_dn(const char *bind_dn); - void set_anonymous(); + %feature("docstring") set_anonymous "S.set_anonymous() -> None\nUse anonymous credentials."; + void set_anonymous(); /* workstation name */ const char *get_workstation(void); @@ -104,8 +121,10 @@ typedef struct cli_credentials { bool authentication_requested(void); + %feature("docstring") wrong_password "S.wrong_password() -> bool\nIndicate the returned password was incorrect."; bool wrong_password(void); + %feature("docstring") set_cmdline_callbacks "S.set_cmdline_callbacks() -> bool\nUse command-line to obtain credentials not explicitly set."; bool set_cmdline_callbacks(); } } cli_credentials; diff --git a/source4/auth/credentials/credentials.py b/source4/auth/credentials/credentials.py index b2f2c4ecdd..fd00a8e6f0 100644 --- a/source4/auth/credentials/credentials.py +++ b/source4/auth/credentials/credentials.py @@ -66,6 +66,97 @@ class Credentials(object): __repr__ = _swig_repr def __init__(self, *args, **kwargs): _credentials.Credentials_swiginit(self,_credentials.new_Credentials(*args, **kwargs)) + def get_username(*args, **kwargs): + """ + S.get_username() -> username + Obtain username. + """ + return _credentials.Credentials_get_username(*args, **kwargs) + + def set_username(*args, **kwargs): + """ + S.set_username(name, obtained=CRED_SPECIFIED) -> None + Change username. + """ + return _credentials.Credentials_set_username(*args, **kwargs) + + def get_password(*args, **kwargs): + """ + S.get_password() -> password + Obtain password. + """ + return _credentials.Credentials_get_password(*args, **kwargs) + + def set_password(*args, **kwargs): + """ + S.set_password(password, obtained=CRED_SPECIFIED) -> None + Change password. + """ + return _credentials.Credentials_set_password(*args, **kwargs) + + def set_domain(*args, **kwargs): + """ + S.set_domain(domain, obtained=CRED_SPECIFIED) -> None + Change domain name. + """ + return _credentials.Credentials_set_domain(*args, **kwargs) + + def get_realm(*args, **kwargs): + """ + S.get_realm() -> realm + Obtain realm name. + """ + return _credentials.Credentials_get_realm(*args, **kwargs) + + def set_realm(*args, **kwargs): + """ + S.set_realm(realm, obtained=CRED_SPECIFIED) -> None + Change realm name. + """ + return _credentials.Credentials_set_realm(*args, **kwargs) + + def parse_string(*args, **kwargs): + """ + S.parse_string(text, obtained=CRED_SPECIFIED) -> None + Parse credentials string. + """ + return _credentials.Credentials_parse_string(*args, **kwargs) + + def get_bind_dn(*args, **kwargs): + """ + S.get_bind_dn() -> bind dn + Obtain bind DN. + """ + return _credentials.Credentials_get_bind_dn(*args, **kwargs) + + def set_bind_dn(*args, **kwargs): + """ + S.set_bind_dn(bind_dn) -> None + Change bind DN. + """ + return _credentials.Credentials_set_bind_dn(*args, **kwargs) + + def set_anonymous(*args, **kwargs): + """ + S.set_anonymous() -> None + Use anonymous credentials. + """ + return _credentials.Credentials_set_anonymous(*args, **kwargs) + + def wrong_password(*args, **kwargs): + """ + S.wrong_password() -> bool + Indicate the returned password was incorrect. + """ + return _credentials.Credentials_wrong_password(*args, **kwargs) + + def set_cmdline_callbacks(*args, **kwargs): + """ + S.set_cmdline_callbacks() -> bool + Use command-line to obtain credentials not explicitly set. + """ + return _credentials.Credentials_set_cmdline_callbacks(*args, **kwargs) + __swig_destroy__ = _credentials.delete_Credentials Credentials.get_username = new_instancemethod(_credentials.Credentials_get_username,None,Credentials) Credentials.set_username = new_instancemethod(_credentials.Credentials_set_username,None,Credentials) diff --git a/source4/auth/credentials/credentials_wrap.c b/source4/auth/credentials/credentials_wrap.c index d460f31927..81ba426e45 100644 --- a/source4/auth/credentials/credentials_wrap.c +++ b/source4/auth/credentials/credentials_wrap.c @@ -2881,7 +2881,7 @@ SWIGINTERN PyObject *_wrap_Credentials_set_username(PyObject *SWIGUNUSEDPARM(sel PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "value",(char *)"arg3", NULL + (char *) "self",(char *) "value",(char *) "obtained", NULL }; arg1 = NULL; @@ -2962,7 +2962,7 @@ SWIGINTERN PyObject *_wrap_Credentials_set_password(PyObject *SWIGUNUSEDPARM(sel PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "val",(char *)"arg3", NULL + (char *) "self",(char *) "val",(char *) "obtained", NULL }; arg1 = NULL; @@ -3043,7 +3043,7 @@ SWIGINTERN PyObject *_wrap_Credentials_set_domain(PyObject *SWIGUNUSEDPARM(self) PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "val",(char *)"arg3", NULL + (char *) "self",(char *) "val",(char *) "obtained", NULL }; arg1 = NULL; @@ -3124,7 +3124,7 @@ SWIGINTERN PyObject *_wrap_Credentials_set_realm(PyObject *SWIGUNUSEDPARM(self), PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "val",(char *)"arg3", NULL + (char *) "self",(char *) "val",(char *) "obtained", NULL }; arg1 = NULL; @@ -3214,7 +3214,7 @@ SWIGINTERN PyObject *_wrap_Credentials_parse_string(PyObject *SWIGUNUSEDPARM(sel PyObject * obj1 = 0 ; PyObject * obj2 = 0 ; char * kwnames[] = { - (char *) "self",(char *) "text",(char *)"arg3", NULL + (char *) "self",(char *) "text",(char *) "obtained", NULL }; arg1 = NULL; @@ -3690,19 +3690,52 @@ SWIGINTERN PyObject *Credentials_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObje static PyMethodDef SwigMethods[] = { { (char *)"new_Credentials", (PyCFunction)_wrap_new_Credentials, METH_NOARGS, NULL}, - { (char *)"Credentials_get_username", (PyCFunction) _wrap_Credentials_get_username, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_set_username", (PyCFunction) _wrap_Credentials_set_username, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_get_password", (PyCFunction) _wrap_Credentials_get_password, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_set_password", (PyCFunction) _wrap_Credentials_set_password, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Credentials_get_username", (PyCFunction) _wrap_Credentials_get_username, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.get_username() -> username\n" + "Obtain username.\n" + ""}, + { (char *)"Credentials_set_username", (PyCFunction) _wrap_Credentials_set_username, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_username(name, obtained=CRED_SPECIFIED) -> None\n" + "Change username.\n" + ""}, + { (char *)"Credentials_get_password", (PyCFunction) _wrap_Credentials_get_password, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.get_password() -> password\n" + "Obtain password.\n" + ""}, + { (char *)"Credentials_set_password", (PyCFunction) _wrap_Credentials_set_password, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_password(password, obtained=CRED_SPECIFIED) -> None\n" + "Change password.\n" + ""}, { (char *)"Credentials_get_domain", (PyCFunction) _wrap_Credentials_get_domain, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_set_domain", (PyCFunction) _wrap_Credentials_set_domain, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_get_realm", (PyCFunction) _wrap_Credentials_get_realm, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_set_realm", (PyCFunction) _wrap_Credentials_set_realm, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Credentials_set_domain", (PyCFunction) _wrap_Credentials_set_domain, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_domain(domain, obtained=CRED_SPECIFIED) -> None\n" + "Change domain name.\n" + ""}, + { (char *)"Credentials_get_realm", (PyCFunction) _wrap_Credentials_get_realm, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.get_realm() -> realm\n" + "Obtain realm name.\n" + ""}, + { (char *)"Credentials_set_realm", (PyCFunction) _wrap_Credentials_set_realm, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_realm(realm, obtained=CRED_SPECIFIED) -> None\n" + "Change realm name.\n" + ""}, { (char *)"Credentials_set_kerberos_state", (PyCFunction) _wrap_Credentials_set_kerberos_state, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_parse_string", (PyCFunction) _wrap_Credentials_parse_string, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_get_bind_dn", (PyCFunction) _wrap_Credentials_get_bind_dn, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_set_bind_dn", (PyCFunction) _wrap_Credentials_set_bind_dn, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_set_anonymous", (PyCFunction) _wrap_Credentials_set_anonymous, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Credentials_parse_string", (PyCFunction) _wrap_Credentials_parse_string, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.parse_string(text, obtained=CRED_SPECIFIED) -> None\n" + "Parse credentials string.\n" + ""}, + { (char *)"Credentials_get_bind_dn", (PyCFunction) _wrap_Credentials_get_bind_dn, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.get_bind_dn() -> bind dn\n" + "Obtain bind DN.\n" + ""}, + { (char *)"Credentials_set_bind_dn", (PyCFunction) _wrap_Credentials_set_bind_dn, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_bind_dn(bind_dn) -> None\n" + "Change bind DN.\n" + ""}, + { (char *)"Credentials_set_anonymous", (PyCFunction) _wrap_Credentials_set_anonymous, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_anonymous() -> None\n" + "Use anonymous credentials.\n" + ""}, { (char *)"Credentials_get_workstation", (PyCFunction) _wrap_Credentials_get_workstation, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_set_workstation", (PyCFunction) _wrap_Credentials_set_workstation, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_set_machine_account", (PyCFunction) _wrap_Credentials_set_machine_account, METH_VARARGS | METH_KEYWORDS, NULL}, @@ -3710,8 +3743,14 @@ static PyMethodDef SwigMethods[] = { { (char *)"Credentials_is_anonymous", (PyCFunction) _wrap_Credentials_is_anonymous, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_get_nt_hash", (PyCFunction) _wrap_Credentials_get_nt_hash, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_authentication_requested", (PyCFunction) _wrap_Credentials_authentication_requested, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_wrong_password", (PyCFunction) _wrap_Credentials_wrong_password, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Credentials_set_cmdline_callbacks", (PyCFunction) _wrap_Credentials_set_cmdline_callbacks, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Credentials_wrong_password", (PyCFunction) _wrap_Credentials_wrong_password, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.wrong_password() -> bool\n" + "Indicate the returned password was incorrect.\n" + ""}, + { (char *)"Credentials_set_cmdline_callbacks", (PyCFunction) _wrap_Credentials_set_cmdline_callbacks, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_cmdline_callbacks() -> bool\n" + "Use command-line to obtain credentials not explicitly set.\n" + ""}, { (char *)"delete_Credentials", (PyCFunction) _wrap_delete_Credentials, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Credentials_swigregister", Credentials_swigregister, METH_VARARGS, NULL}, { (char *)"Credentials_swiginit", Credentials_swiginit, METH_VARARGS, NULL}, -- cgit From 505cea9d4c9ae3b7baf401fd543500041c20f93d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 16:50:33 +0200 Subject: Add some docstrings to ldb python module, fix MessageElement name. (This used to be commit 717283331f8a1ebd80e7ec52d9bfe709f869ec86) --- source4/lib/ldb/ldb.i | 93 ++++++++++++--- source4/lib/ldb/ldb.py | 189 ++++++++++++++++++++++++++--- source4/lib/ldb/ldb_wrap.c | 292 ++++++++++++++++++++++++++++----------------- 3 files changed, 430 insertions(+), 144 deletions(-) diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 18e981f7be..6a807a7dde 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -40,7 +40,7 @@ typedef struct ldb_message ldb_msg; typedef struct ldb_context ldb; typedef struct ldb_dn ldb_dn; typedef struct ldb_ldif ldb_ldif; -typedef struct ldb_message_element ldb_msg_element; +typedef struct ldb_message_element ldb_message_element; typedef int ldb_error; typedef int ldb_int_error; @@ -210,21 +210,35 @@ fail: return ret; } ~ldb_dn() { talloc_free($self); } + %feature("docstring") validate "S.validate() -> bool\n" \ + "Validate DN is correct."; bool validate(); const char *get_casefold(); const char *get_linearized(); ldb_dn *parent() { return ldb_dn_get_parent(NULL, $self); } int compare(ldb_dn *other); bool is_valid(); + %feature("docstring") is_special "S.is_special() -> bool\n" \ + "Check whether this is a special LDB DN."; bool is_special(); + %feature("docstring") is_null "S.is_null() -> bool\n" \ + "Check whether this is a null DN."; bool is_null(); bool check_special(const char *name); int get_comp_num(); + %feature("docstring") add_child "S.add_child(dn) -> None\n" \ + "Add a child DN to this DN."; bool add_child(ldb_dn *child); + %feature("docstring") add_base "S.add_base(dn) -> None\n" \ + "Add a base DN to this DN."; bool add_base(ldb_dn *base); + %feature("docstring") canonical_str "S.canonical_str() -> string\n" \ + "Canonical version of this DN (like a posix path)."; const char *canonical_str() { return ldb_dn_canonical_string($self, $self); } + %feature("docstring") canonical_ex_str "S.canonical_ex_str() -> string\n" \ + "Canonical version of this DN (like a posix path, with terminating newline)."; const char *canonical_ex_str() { return ldb_dn_canonical_ex_string($self, $self); } @@ -289,7 +303,7 @@ int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, return ret; } -ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, +ldb_message_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *set_obj, int flags, const char *attr_name) { @@ -320,7 +334,7 @@ ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, } PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, - ldb_msg_element *me) + ldb_message_element *me) { int i; PyObject *result; @@ -339,9 +353,10 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, %} #endif +int ldb_msg_element_compare(ldb_message_element *, ldb_message_element *); /* ldb_message_element */ -%rename(__cmp__) ldb_message_element::compare; -%rename(MessageElement) ldb_msg_element; +%rename(MessageElement) ldb_message_element; +%rename(ldb_message_element_compare) ldb_msg_element_compare; typedef struct ldb_message_element { %extend { #ifdef SWIGPYTHON @@ -355,7 +370,7 @@ typedef struct ldb_message_element { return ldb_msg_element_to_set(NULL, $self); } - ldb_msg_element(PyObject *set_obj, int flags=0, const char *name = NULL) + ldb_message_element(PyObject *set_obj, int flags=0, const char *name = NULL) { return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } @@ -374,8 +389,8 @@ typedef struct ldb_message_element { return ldb_val_to_py_object(NULL, $self, &$self->values[i]); } - ~ldb_msg_element() { talloc_free($self); } - int compare(ldb_msg_element *); + ~ldb_message_element() { talloc_free($self); } + %rename(__cmp__) ldb_msg_element_compare; } %pythoncode { def __getitem__(self, i): @@ -398,21 +413,19 @@ typedef struct ldb_message_element { return False return True } -} ldb_msg_element; +} ldb_message_element; /* ldb_message */ %rename(Message) ldb_message; #ifdef SWIGPYTHON %rename(__delitem__) ldb_message::remove_attr; -%typemap(out) ldb_msg_element * { +%typemap(out) ldb_message_element * { if ($1 == NULL) PyErr_SetString(PyExc_KeyError, "no such element"); else $result = SWIG_NewPointerObj($1, SWIGTYPE_p_ldb_message_element, 0); } -//%typemap(out) ldb_msg_element *; - %inline { PyObject *ldb_msg_list_elements(ldb_msg *msg) @@ -443,10 +456,10 @@ typedef struct ldb_message { return ret; } ~ldb_msg() { talloc_free($self); } - ldb_msg_element *find_element(const char *name); + ldb_message_element *find_element(const char *name); #ifdef SWIGPYTHON - void __setitem__(const char *attr_name, ldb_msg_element *val) + void __setitem__(const char *attr_name, ldb_message_element *val) { struct ldb_message_element *el; @@ -613,7 +626,7 @@ PyObject *PyExc_LdbError; %typemap(in,numinputs=1) ldb_msg *add_msg { Py_ssize_t dict_pos, msg_pos; - ldb_msg_element *msgel; + ldb_message_element *msgel; PyObject *key, *value; if (PyDict_Check($input)) { @@ -660,6 +673,8 @@ typedef struct ldb_context { %extend { ldb(void) { return ldb_init(NULL); } + %feature("docstring") connect "S.connect(url,flags=0,options=None) -> None\n" \ + "Connect to a LDB URL."; ldb_error connect(const char *url, unsigned int flags = 0, const char *options[] = NULL); @@ -707,11 +722,19 @@ typedef struct ldb_context { return ret; } + %feature("docstring") delete "S.delete(dn) -> None\n" \ + "Remove an entry."; ldb_error delete(ldb_dn *dn); + %feature("docstring") rename "S.rename(old_dn, new_dn) -> None\n" \ + "Rename an entry."; ldb_error rename(ldb_dn *olddn, ldb_dn *newdn); struct ldb_control **parse_control_strings(TALLOC_CTX *mem_ctx, const char * const*control_strings); + %feature("docstring") add "S.add(message) -> None\n" \ + "Add an entry."; ldb_error add(ldb_msg *add_msg); + %feature("docstring") modify "S.modify(message) -> None\n" \ + "Modify an entry."; ldb_error modify(ldb_msg *message); ldb_dn *get_config_basedn(); ldb_dn *get_root_basedn(); @@ -747,20 +770,36 @@ typedef struct ldb_context { } const char *errstring(); + %feature("docstring") set_create_perms "S.set_create_perms(mode) -> None\n" \ + "Set mode to use when creating new LDB files."; void set_create_perms(unsigned int perms); + %feature("docstring") set_modules_dir "S.set_modules_dir(path) -> None\n" \ + "Set path LDB should search for modules"; void set_modules_dir(const char *path); ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context); + %feature("docstring") set_opaque "S.set_opaque(name, value) -> None\n" \ + "Set an opaque value on this LDB connection. \n" + ":note: Passing incorrect values may cause crashes."; ldb_error set_opaque(const char *name, void *value); + %feature("docstring") get_opaque "S.get_opaque(name) -> value\n" \ + "Get an opaque value set on this LDB connection. \n" + ":note: The returned value may not be useful in Python."; void *get_opaque(const char *name); + %feature("docstring") transaction_start "S.transaction_start() -> None\n" \ + "Start a new transaction."; ldb_error transaction_start(); + %feature("docstring") transaction_commit "S.transaction_commit() -> None\n" \ + "Commit currently active transaction."; ldb_error transaction_commit(); + %feature("docstring") transaction_commit "S.transaction_cancel() -> None\n" \ + "Cancel currently active transaction."; ldb_error transaction_cancel(); void schema_attribute_remove(const char *name); ldb_error schema_attribute_add(const char *attribute, unsigned flags, const char *syntax); - ldb_error setup_wellknown_attributes(void); - + ldb_error setup_wellknown_attributes(void); + #ifdef SWIGPYTHON %typemap(in,numinputs=0,noblock=1) struct ldb_result **result_as_bool (struct ldb_result *tmp) { $1 = &tmp; } %typemap(argout,noblock=1) struct ldb_result **result_as_bool { $result = ((*$1)->count > 0)?Py_True:Py_False; } @@ -771,6 +810,9 @@ typedef struct ldb_context { result_as_bool); } + %feature("docstring") parse_ldif "S.parse_ldif(ldif) -> iter(messages)\n" \ + "Parse a string formatted using LDIF."; + PyObject *parse_ldif(const char *s) { PyObject *list = PyList_New(0); @@ -791,12 +833,25 @@ typedef struct ldb_context { } %pythoncode { def __init__(self, url=None, flags=0, options=None): + """Create a new LDB object. + + Will also connect to the specified URL if one was given. + """ _ldb.Ldb_swiginit(self,_ldb.new_Ldb()) if url is not None: self.connect(url, flags, options) def search(self, base=None, scope=SCOPE_DEFAULT, expression=None, attrs=None, controls=None): + """Search in a database. + + :param base: Optional base DN to search + :param scope: Search scope (SCOPE_BASE, SCOPE_ONELEVEL or SCOPE_SUBTREE) + :param expression: Optional search expression + :param attrs: Attributes to return (defaults to all) + :param controls: Optional list of controls + :return: Iterator over Message objects + """ if not (attrs is None or isinstance(attrs, list)): raise TypeError("attributes not a list") parsed_controls = None @@ -816,6 +871,8 @@ typedef struct ldb_context { %nodefault Dn; %rename(valid_attr_name) ldb_valid_attr_name; +%feature("docstring") ldb_valid_attr_name "S.valid_attr_name(name) -> bool\n" + "Check whether the supplied name is a valid attribute name."; int ldb_valid_attr_name(const char *s); typedef unsigned long time_t; @@ -839,5 +896,7 @@ time_t ldb_string_to_time(const char *s); $1->name = (char *)PyObject_GetAttrString($input, (char *)"name"); } +%feature("docstring") ldb_register_module "S.register_module(module) -> None\n" + "Register a LDB module."; %rename(register_module) ldb_register_module; ldb_int_error ldb_register_module(const struct ldb_module_ops *); diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index e9f4055fbf..0149f05429 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -71,6 +71,55 @@ class Dn(object): def __init__(self, *args, **kwargs): _ldb.Dn_swiginit(self,_ldb.new_Dn(*args, **kwargs)) __swig_destroy__ = _ldb.delete_Dn + def validate(*args, **kwargs): + """ + S.validate() -> bool + Validate DN is correct. + """ + return _ldb.Dn_validate(*args, **kwargs) + + def is_special(*args, **kwargs): + """ + S.is_special() -> bool + Check whether this is a special LDB DN. + """ + return _ldb.Dn_is_special(*args, **kwargs) + + def is_null(*args, **kwargs): + """ + S.is_null() -> bool + Check whether this is a null DN. + """ + return _ldb.Dn_is_null(*args, **kwargs) + + def add_child(*args, **kwargs): + """ + S.add_child(dn) -> None + Add a child DN to this DN. + """ + return _ldb.Dn_add_child(*args, **kwargs) + + def add_base(*args, **kwargs): + """ + S.add_base(dn) -> None + Add a base DN to this DN. + """ + return _ldb.Dn_add_base(*args, **kwargs) + + def canonical_str(*args, **kwargs): + """ + S.canonical_str() -> string + Canonical version of this DN (like a posix path). + """ + return _ldb.Dn_canonical_str(*args, **kwargs) + + def canonical_ex_str(*args, **kwargs): + """ + S.canonical_ex_str() -> string + Canonical version of this DN (like a posix path, with terminating newline). + """ + return _ldb.Dn_canonical_ex_str(*args, **kwargs) + def __eq__(self, other): if isinstance(other, self.__class__): return self.__cmp__(other) == 0 @@ -97,11 +146,13 @@ Dn.__add__ = new_instancemethod(_ldb.Dn___add__,None,Dn) Dn_swigregister = _ldb.Dn_swigregister Dn_swigregister(Dn) -class ldb_msg_element(object): +ldb_msg_element_compare = _ldb.ldb_msg_element_compare +class MessageElement(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - def __init__(self, *args, **kwargs): raise AttributeError, "No constructor defined" __repr__ = _swig_repr - __swig_destroy__ = _ldb.delete_ldb_msg_element + def __init__(self, *args, **kwargs): + _ldb.MessageElement_swiginit(self,_ldb.new_MessageElement(*args, **kwargs)) + __swig_destroy__ = _ldb.delete_MessageElement def __getitem__(self, i): ret = self.get(i) if ret is None: @@ -122,17 +173,12 @@ class ldb_msg_element(object): return False return True -ldb_msg_element.__iter__ = new_instancemethod(_ldb.ldb_msg_element___iter__,None,ldb_msg_element) -ldb_msg_element.__set__ = new_instancemethod(_ldb.ldb_msg_element___set__,None,ldb_msg_element) -ldb_msg_element.__len__ = new_instancemethod(_ldb.ldb_msg_element___len__,None,ldb_msg_element) -ldb_msg_element.get = new_instancemethod(_ldb.ldb_msg_element_get,None,ldb_msg_element) -ldb_msg_element.__cmp__ = new_instancemethod(_ldb.ldb_msg_element___cmp__,None,ldb_msg_element) -ldb_msg_element_swigregister = _ldb.ldb_msg_element_swigregister -ldb_msg_element_swigregister(ldb_msg_element) - -def MessageElement(*args, **kwargs): - val = _ldb.new_MessageElement(*args, **kwargs) - return val +MessageElement.__iter__ = new_instancemethod(_ldb.MessageElement___iter__,None,MessageElement) +MessageElement.__set__ = new_instancemethod(_ldb.MessageElement___set__,None,MessageElement) +MessageElement.__len__ = new_instancemethod(_ldb.MessageElement___len__,None,MessageElement) +MessageElement.get = new_instancemethod(_ldb.MessageElement_get,None,MessageElement) +MessageElement_swigregister = _ldb.MessageElement_swigregister +MessageElement_swigregister(MessageElement) ldb_msg_list_elements = _ldb.ldb_msg_list_elements class Message(object): @@ -217,14 +263,113 @@ class Ldb(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self, *args, **kwargs): _ldb.Ldb_swiginit(self,_ldb.new_Ldb(*args, **kwargs)) + def connect(*args, **kwargs): + """ + S.connect(url,flags=0,options=None) -> None + Connect to a LDB URL. + """ + return _ldb.Ldb_connect(*args, **kwargs) + __swig_destroy__ = _ldb.delete_Ldb + def delete(*args, **kwargs): + """ + S.delete(dn) -> None + Remove an entry. + """ + return _ldb.Ldb_delete(*args, **kwargs) + + def rename(*args, **kwargs): + """ + S.rename(old_dn, new_dn) -> None + Rename an entry. + """ + return _ldb.Ldb_rename(*args, **kwargs) + + def add(*args, **kwargs): + """ + S.add(message) -> None + Add an entry. + """ + return _ldb.Ldb_add(*args, **kwargs) + + def modify(*args, **kwargs): + """ + S.modify(message) -> None + Modify an entry. + """ + return _ldb.Ldb_modify(*args, **kwargs) + + def set_create_perms(*args, **kwargs): + """ + S.set_create_perms(mode) -> None + Set mode to use when creating new LDB files. + """ + return _ldb.Ldb_set_create_perms(*args, **kwargs) + + def set_modules_dir(*args, **kwargs): + """ + S.set_modules_dir(path) -> None + Set path LDB should search for modules + """ + return _ldb.Ldb_set_modules_dir(*args, **kwargs) + + def set_opaque(*args, **kwargs): + """ + S.set_opaque(name, value) -> None + Set an opaque value on this LDB connection. + :note: Passing incorrect values may cause crashes. + """ + return _ldb.Ldb_set_opaque(*args, **kwargs) + + def get_opaque(*args, **kwargs): + """ + S.get_opaque(name) -> value + Get an opaque value set on this LDB connection. + :note: The returned value may not be useful in Python. + """ + return _ldb.Ldb_get_opaque(*args, **kwargs) + + def transaction_start(*args, **kwargs): + """ + S.transaction_start() -> None + Start a new transaction. + """ + return _ldb.Ldb_transaction_start(*args, **kwargs) + + def transaction_commit(*args, **kwargs): + """ + S.transaction_commit() -> None + Commit currently active transaction. + """ + return _ldb.Ldb_transaction_commit(*args, **kwargs) + + def parse_ldif(*args, **kwargs): + """ + S.parse_ldif(ldif) -> iter(messages) + Parse a string formatted using LDIF. + """ + return _ldb.Ldb_parse_ldif(*args, **kwargs) + def __init__(self, url=None, flags=0, options=None): + """Create a new LDB object. + + Will also connect to the specified URL if one was given. + """ _ldb.Ldb_swiginit(self,_ldb.new_Ldb()) if url is not None: self.connect(url, flags, options) def search(self, base=None, scope=SCOPE_DEFAULT, expression=None, attrs=None, controls=None): + """Search in a database. + + :param base: Optional base DN to search + :param scope: Search scope (SCOPE_BASE, SCOPE_ONELEVEL or SCOPE_SUBTREE) + :param expression: Optional search expression + :param attrs: Attributes to return (defaults to all) + :param controls: Optional list of controls + :return: Iterator over Message objects + """ if not (attrs is None or isinstance(attrs, list)): raise TypeError("attributes not a list") parsed_controls = None @@ -263,9 +408,21 @@ Ldb.__repr__ = new_instancemethod(_ldb.Ldb___repr__,None,Ldb) Ldb_swigregister = _ldb.Ldb_swigregister Ldb_swigregister(Ldb) -valid_attr_name = _ldb.valid_attr_name + +def valid_attr_name(*args, **kwargs): + """ + S.valid_attr_name(name) -> bool + Check whether the supplied name is a valid attribute name. + """ + return _ldb.valid_attr_name(*args, **kwargs) timestring = _ldb.timestring string_to_time = _ldb.string_to_time -register_module = _ldb.register_module + +def register_module(*args, **kwargs): + """ + S.register_module(module) -> None + Register a LDB module. + """ + return _ldb.register_module(*args, **kwargs) diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index d787266416..bfd507a8f2 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -2554,7 +2554,7 @@ typedef struct ldb_message ldb_msg; typedef struct ldb_context ldb; typedef struct ldb_dn ldb_dn; typedef struct ldb_ldif ldb_ldif; -typedef struct ldb_message_element ldb_msg_element; +typedef struct ldb_message_element ldb_message_element; typedef int ldb_error; typedef int ldb_int_error; @@ -2761,7 +2761,7 @@ int ldb_dn_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *object, return ret; } -ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, +ldb_message_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, PyObject *set_obj, int flags, const char *attr_name) { @@ -2792,7 +2792,7 @@ ldb_msg_element *ldb_msg_element_from_pyobject(TALLOC_CTX *mem_ctx, } PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, - ldb_msg_element *me) + ldb_message_element *me) { int i; PyObject *result; @@ -2809,10 +2809,10 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, } -SWIGINTERN PyObject *ldb_msg_element___iter__(ldb_msg_element *self){ +SWIGINTERN PyObject *ldb_message_element___iter__(ldb_message_element *self){ return PyObject_GetIter(ldb_msg_element_to_set(NULL, self)); } -SWIGINTERN PyObject *ldb_msg_element___set__(ldb_msg_element *self){ +SWIGINTERN PyObject *ldb_message_element___set__(ldb_message_element *self){ return ldb_msg_element_to_set(NULL, self); } @@ -2960,19 +2960,19 @@ SWIG_AsVal_int (PyObject * obj, int *val) return res; } -SWIGINTERN ldb_msg_element *new_ldb_msg_element(PyObject *set_obj,int flags,char const *name){ +SWIGINTERN ldb_message_element *new_ldb_message_element(PyObject *set_obj,int flags,char const *name){ return ldb_msg_element_from_pyobject(NULL, set_obj, flags, name); } -SWIGINTERN int ldb_msg_element___len__(ldb_msg_element *self){ +SWIGINTERN int ldb_message_element___len__(ldb_message_element *self){ return self->num_values; } -SWIGINTERN PyObject *ldb_msg_element_get(ldb_msg_element *self,int i){ +SWIGINTERN PyObject *ldb_message_element_get(ldb_message_element *self,int i){ if (i < 0 || i >= self->num_values) return Py_None; return ldb_val_to_py_object(NULL, self, &self->values[i]); } -SWIGINTERN void delete_ldb_msg_element(ldb_msg_element *self){ talloc_free(self); } +SWIGINTERN void delete_ldb_message_element(ldb_message_element *self){ talloc_free(self); } PyObject *ldb_msg_list_elements(ldb_msg *msg) { @@ -2995,7 +2995,7 @@ SWIGINTERN ldb_msg *new_ldb_msg(ldb_dn *dn){ return ret; } SWIGINTERN void delete_ldb_msg(ldb_msg *self){ talloc_free(self); } -SWIGINTERN void ldb_msg___setitem____SWIG_0(ldb_msg *self,char const *attr_name,ldb_msg_element *val){ +SWIGINTERN void ldb_msg___setitem____SWIG_0(ldb_msg *self,char const *attr_name,ldb_message_element *val){ struct ldb_message_element *el; ldb_msg_remove_attr(self, attr_name); @@ -3763,9 +3763,43 @@ SWIGINTERN PyObject *Dn_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) return SWIG_Python_InitShadowInstance(args); } -SWIGINTERN PyObject *_wrap_ldb_msg_element___iter__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_ldb_msg_element_compare(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; - ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; + ldb_message_element *arg1 = (ldb_message_element *) 0 ; + ldb_message_element *arg2 = (ldb_message_element *) 0 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + char * kwnames[] = { + (char *)"arg1",(char *)"arg2", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_msg_element_compare",kwnames,&obj0,&obj1)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element_compare" "', argument " "1"" of type '" "ldb_message_element *""'"); + } + arg1 = (ldb_message_element *)(argp1); + res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_message_element, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_msg_element_compare" "', argument " "2"" of type '" "ldb_message_element *""'"); + } + arg2 = (ldb_message_element *)(argp2); + result = (int)ldb_msg_element_compare(arg1,arg2); + resultobj = SWIG_From_int((int)(result)); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_MessageElement___iter__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + ldb_message_element *arg1 = (ldb_message_element *) 0 ; PyObject *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; @@ -3775,10 +3809,10 @@ SWIGINTERN PyObject *_wrap_ldb_msg_element___iter__(PyObject *SWIGUNUSEDPARM(sel swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element___iter__" "', argument " "1"" of type '" "ldb_msg_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MessageElement___iter__" "', argument " "1"" of type '" "ldb_message_element *""'"); } - arg1 = (ldb_msg_element *)(argp1); - result = (PyObject *)ldb_msg_element___iter__(arg1); + arg1 = (ldb_message_element *)(argp1); + result = (PyObject *)ldb_message_element___iter__(arg1); resultobj = result; return resultobj; fail: @@ -3786,9 +3820,9 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_msg_element___set__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_MessageElement___set__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; - ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; + ldb_message_element *arg1 = (ldb_message_element *) 0 ; PyObject *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; @@ -3798,10 +3832,10 @@ SWIGINTERN PyObject *_wrap_ldb_msg_element___set__(PyObject *SWIGUNUSEDPARM(self swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element___set__" "', argument " "1"" of type '" "ldb_msg_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MessageElement___set__" "', argument " "1"" of type '" "ldb_message_element *""'"); } - arg1 = (ldb_msg_element *)(argp1); - result = (PyObject *)ldb_msg_element___set__(arg1); + arg1 = (ldb_message_element *)(argp1); + result = (PyObject *)ldb_message_element___set__(arg1); resultobj = result; return resultobj; fail: @@ -3814,7 +3848,7 @@ SWIGINTERN PyObject *_wrap_new_MessageElement(PyObject *SWIGUNUSEDPARM(self), Py PyObject *arg1 = (PyObject *) 0 ; int arg2 = (int) 0 ; char *arg3 = (char *) NULL ; - ldb_msg_element *result = 0 ; + ldb_message_element *result = 0 ; int val2 ; int ecode2 = 0 ; int res3 ; @@ -3843,8 +3877,8 @@ SWIGINTERN PyObject *_wrap_new_MessageElement(PyObject *SWIGUNUSEDPARM(self), Py } arg3 = (char *)(buf3); } - result = (ldb_msg_element *)new_ldb_msg_element(arg1,arg2,(char const *)arg3); - resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ldb_message_element, SWIG_POINTER_OWN | 0 ); + result = (ldb_message_element *)new_ldb_message_element(arg1,arg2,(char const *)arg3); + resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ldb_message_element, SWIG_POINTER_NEW | 0 ); if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); return resultobj; fail: @@ -3853,9 +3887,9 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_msg_element___len__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_MessageElement___len__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; - ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; + ldb_message_element *arg1 = (ldb_message_element *) 0 ; int result; void *argp1 = 0 ; int res1 = 0 ; @@ -3865,10 +3899,10 @@ SWIGINTERN PyObject *_wrap_ldb_msg_element___len__(PyObject *SWIGUNUSEDPARM(self swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element___len__" "', argument " "1"" of type '" "ldb_msg_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MessageElement___len__" "', argument " "1"" of type '" "ldb_message_element *""'"); } - arg1 = (ldb_msg_element *)(argp1); - result = (int)ldb_msg_element___len__(arg1); + arg1 = (ldb_message_element *)(argp1); + result = (int)ldb_message_element___len__(arg1); resultobj = SWIG_From_int((int)(result)); return resultobj; fail: @@ -3876,9 +3910,9 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_msg_element_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_MessageElement_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; - ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; + ldb_message_element *arg1 = (ldb_message_element *) 0 ; int arg2 ; PyObject *result = 0 ; void *argp1 = 0 ; @@ -3891,18 +3925,18 @@ SWIGINTERN PyObject *_wrap_ldb_msg_element_get(PyObject *SWIGUNUSEDPARM(self), P (char *) "self",(char *) "i", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_msg_element_get",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:MessageElement_get",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element_get" "', argument " "1"" of type '" "ldb_msg_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MessageElement_get" "', argument " "1"" of type '" "ldb_message_element *""'"); } - arg1 = (ldb_msg_element *)(argp1); + arg1 = (ldb_message_element *)(argp1); ecode2 = SWIG_AsVal_int(obj1, &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "ldb_msg_element_get" "', argument " "2"" of type '" "int""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "MessageElement_get" "', argument " "2"" of type '" "int""'"); } arg2 = (int)(val2); - result = (PyObject *)ldb_msg_element_get(arg1,arg2); + result = (PyObject *)ldb_message_element_get(arg1,arg2); resultobj = result; return resultobj; fail: @@ -3910,9 +3944,9 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_ldb_msg_element(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_delete_MessageElement(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; - ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; + ldb_message_element *arg1 = (ldb_message_element *) 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject *swig_obj[1] ; @@ -3921,10 +3955,10 @@ SWIGINTERN PyObject *_wrap_delete_ldb_msg_element(PyObject *SWIGUNUSEDPARM(self) swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_ldb_message_element, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_ldb_msg_element" "', argument " "1"" of type '" "ldb_msg_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_MessageElement" "', argument " "1"" of type '" "ldb_message_element *""'"); } - arg1 = (ldb_msg_element *)(argp1); - delete_ldb_msg_element(arg1); + arg1 = (ldb_message_element *)(argp1); + delete_ldb_message_element(arg1); resultobj = SWIG_Py_Void(); return resultobj; @@ -3933,47 +3967,17 @@ fail: } -SWIGINTERN PyObject *_wrap_ldb_msg_element___cmp__(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - ldb_msg_element *arg1 = (ldb_msg_element *) 0 ; - ldb_msg_element *arg2 = (ldb_msg_element *) 0 ; - int result; - void *argp1 = 0 ; - int res1 = 0 ; - void *argp2 = 0 ; - int res2 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - char * kwnames[] = { - (char *) "self",(char *)"arg2", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_msg_element___cmp__",kwnames,&obj0,&obj1)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element___cmp__" "', argument " "1"" of type '" "ldb_msg_element *""'"); - } - arg1 = (ldb_msg_element *)(argp1); - res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_message_element, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_msg_element___cmp__" "', argument " "2"" of type '" "ldb_msg_element *""'"); - } - arg2 = (ldb_msg_element *)(argp2); - result = (int)ldb_msg_element_compare(arg1,arg2); - resultobj = SWIG_From_int((int)(result)); - return resultobj; -fail: - return NULL; -} - - -SWIGINTERN PyObject *ldb_msg_element_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *MessageElement_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_ldb_message_element, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *MessageElement_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + SWIGINTERN PyObject *_wrap_ldb_msg_list_elements(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb_msg *arg1 = (ldb_msg *) 0 ; @@ -4118,7 +4122,7 @@ SWIGINTERN PyObject *_wrap_Message_find_element(PyObject *SWIGUNUSEDPARM(self), PyObject *resultobj = 0; ldb_msg *arg1 = (ldb_msg *) 0 ; char *arg2 = (char *) 0 ; - ldb_msg_element *result = 0 ; + ldb_message_element *result = 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -4144,7 +4148,7 @@ SWIGINTERN PyObject *_wrap_Message_find_element(PyObject *SWIGUNUSEDPARM(self), if (arg1 == NULL) SWIG_exception(SWIG_ValueError, "Message can not be None"); - result = (ldb_msg_element *)ldb_msg_find_element(arg1,(char const *)arg2); + result = (ldb_message_element *)ldb_msg_find_element(arg1,(char const *)arg2); { if (result == NULL) PyErr_SetString(PyExc_KeyError, "no such element"); @@ -4163,7 +4167,7 @@ SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_0(PyObject *SWIGUNUSEDPARM( PyObject *resultobj = 0; ldb_msg *arg1 = (ldb_msg *) 0 ; char *arg2 = (char *) 0 ; - ldb_msg_element *arg3 = (ldb_msg_element *) 0 ; + ldb_message_element *arg3 = (ldb_message_element *) 0 ; void *argp1 = 0 ; int res1 = 0 ; int res2 ; @@ -4185,9 +4189,9 @@ SWIGINTERN PyObject *_wrap_Message___setitem____SWIG_0(PyObject *SWIGUNUSEDPARM( arg2 = (char *)(buf2); res3 = SWIG_ConvertPtr(swig_obj[2], &argp3,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Message___setitem__" "', argument " "3"" of type '" "ldb_msg_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "Message___setitem__" "', argument " "3"" of type '" "ldb_message_element *""'"); } - arg3 = (ldb_msg_element *)(argp3); + arg3 = (ldb_message_element *)(argp3); if (arg1 == NULL) SWIG_exception(SWIG_ValueError, "Message can not be None"); @@ -4262,7 +4266,7 @@ check_1: fail: SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'Message___setitem__'.\n" " Possible C/C++ prototypes are:\n" - " __setitem__(ldb_msg *,char const *,ldb_msg_element *)\n" + " __setitem__(ldb_msg *,char const *,ldb_message_element *)\n" " __setitem__(ldb_msg *,char const *,PyObject *)\n"); return NULL; } @@ -4787,7 +4791,7 @@ SWIGINTERN PyObject *_wrap_Ldb_add(PyObject *SWIGUNUSEDPARM(self), PyObject *arg arg1 = (ldb *)(argp1); { Py_ssize_t dict_pos, msg_pos; - ldb_msg_element *msgel; + ldb_message_element *msgel; PyObject *key, *value; if (PyDict_Check(obj1)) { @@ -5725,32 +5729,54 @@ static PyMethodDef SwigMethods[] = { { (char *)"ldb_val_to_py_object", (PyCFunction) _wrap_ldb_val_to_py_object, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"new_Dn", (PyCFunction) _wrap_new_Dn, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_Dn", (PyCFunction)_wrap_delete_Dn, METH_O, NULL}, - { (char *)"Dn_validate", (PyCFunction)_wrap_Dn_validate, METH_O, NULL}, + { (char *)"Dn_validate", (PyCFunction)_wrap_Dn_validate, METH_O, (char *)"\n" + "S.validate() -> bool\n" + "Validate DN is correct.\n" + ""}, { (char *)"Dn_get_casefold", (PyCFunction)_wrap_Dn_get_casefold, METH_O, NULL}, { (char *)"Dn___str__", (PyCFunction)_wrap_Dn___str__, METH_O, NULL}, { (char *)"Dn_parent", (PyCFunction)_wrap_Dn_parent, METH_O, NULL}, { (char *)"Dn___cmp__", (PyCFunction) _wrap_Dn___cmp__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Dn_is_valid", (PyCFunction)_wrap_Dn_is_valid, METH_O, NULL}, - { (char *)"Dn_is_special", (PyCFunction)_wrap_Dn_is_special, METH_O, NULL}, - { (char *)"Dn_is_null", (PyCFunction)_wrap_Dn_is_null, METH_O, NULL}, + { (char *)"Dn_is_special", (PyCFunction)_wrap_Dn_is_special, METH_O, (char *)"\n" + "S.is_special() -> bool\n" + "Check whether this is a special LDB DN.\n" + ""}, + { (char *)"Dn_is_null", (PyCFunction)_wrap_Dn_is_null, METH_O, (char *)"\n" + "S.is_null() -> bool\n" + "Check whether this is a null DN.\n" + ""}, { (char *)"Dn_check_special", (PyCFunction) _wrap_Dn_check_special, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Dn___len__", (PyCFunction)_wrap_Dn___len__, METH_O, NULL}, - { (char *)"Dn_add_child", (PyCFunction) _wrap_Dn_add_child, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Dn_add_base", (PyCFunction) _wrap_Dn_add_base, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Dn_canonical_str", (PyCFunction)_wrap_Dn_canonical_str, METH_O, NULL}, - { (char *)"Dn_canonical_ex_str", (PyCFunction)_wrap_Dn_canonical_ex_str, METH_O, NULL}, + { (char *)"Dn_add_child", (PyCFunction) _wrap_Dn_add_child, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.add_child(dn) -> None\n" + "Add a child DN to this DN.\n" + ""}, + { (char *)"Dn_add_base", (PyCFunction) _wrap_Dn_add_base, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.add_base(dn) -> None\n" + "Add a base DN to this DN.\n" + ""}, + { (char *)"Dn_canonical_str", (PyCFunction)_wrap_Dn_canonical_str, METH_O, (char *)"\n" + "S.canonical_str() -> string\n" + "Canonical version of this DN (like a posix path).\n" + ""}, + { (char *)"Dn_canonical_ex_str", (PyCFunction)_wrap_Dn_canonical_ex_str, METH_O, (char *)"\n" + "S.canonical_ex_str() -> string\n" + "Canonical version of this DN (like a posix path, with terminating newline).\n" + ""}, { (char *)"Dn___repr__", (PyCFunction)_wrap_Dn___repr__, METH_O, NULL}, { (char *)"Dn___add__", (PyCFunction) _wrap_Dn___add__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Dn_swigregister", Dn_swigregister, METH_VARARGS, NULL}, { (char *)"Dn_swiginit", Dn_swiginit, METH_VARARGS, NULL}, - { (char *)"ldb_msg_element___iter__", (PyCFunction)_wrap_ldb_msg_element___iter__, METH_O, NULL}, - { (char *)"ldb_msg_element___set__", (PyCFunction)_wrap_ldb_msg_element___set__, METH_O, NULL}, + { (char *)"ldb_msg_element_compare", (PyCFunction) _wrap_ldb_msg_element_compare, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"MessageElement___iter__", (PyCFunction)_wrap_MessageElement___iter__, METH_O, NULL}, + { (char *)"MessageElement___set__", (PyCFunction)_wrap_MessageElement___set__, METH_O, NULL}, { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_msg_element___len__", (PyCFunction)_wrap_ldb_msg_element___len__, METH_O, NULL}, - { (char *)"ldb_msg_element_get", (PyCFunction) _wrap_ldb_msg_element_get, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"delete_ldb_msg_element", (PyCFunction)_wrap_delete_ldb_msg_element, METH_O, NULL}, - { (char *)"ldb_msg_element___cmp__", (PyCFunction) _wrap_ldb_msg_element___cmp__, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_msg_element_swigregister", ldb_msg_element_swigregister, METH_VARARGS, NULL}, + { (char *)"MessageElement___len__", (PyCFunction)_wrap_MessageElement___len__, METH_O, NULL}, + { (char *)"MessageElement_get", (PyCFunction) _wrap_MessageElement_get, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"delete_MessageElement", (PyCFunction)_wrap_delete_MessageElement, METH_O, NULL}, + { (char *)"MessageElement_swigregister", MessageElement_swigregister, METH_VARARGS, NULL}, + { (char *)"MessageElement_swiginit", MessageElement_swiginit, METH_VARARGS, NULL}, { (char *)"ldb_msg_list_elements", (PyCFunction) _wrap_ldb_msg_list_elements, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Message_dn_set", _wrap_Message_dn_set, METH_VARARGS, NULL}, { (char *)"Message_dn_get", (PyCFunction)_wrap_Message_dn_get, METH_O, NULL}, @@ -5766,40 +5792,84 @@ static PyMethodDef SwigMethods[] = { { (char *)"Message_swiginit", Message_swiginit, METH_VARARGS, NULL}, { (char *)"ldb_ldif_to_pyobject", (PyCFunction) _wrap_ldb_ldif_to_pyobject, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"new_Ldb", (PyCFunction)_wrap_new_Ldb, METH_NOARGS, NULL}, - { (char *)"Ldb_connect", (PyCFunction) _wrap_Ldb_connect, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_connect", (PyCFunction) _wrap_Ldb_connect, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.connect(url,flags=0,options=None) -> None\n" + "Connect to a LDB URL.\n" + ""}, { (char *)"delete_Ldb", (PyCFunction)_wrap_delete_Ldb, METH_O, NULL}, { (char *)"Ldb_search_ex", (PyCFunction) _wrap_Ldb_search_ex, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_delete", (PyCFunction) _wrap_Ldb_delete, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_rename", (PyCFunction) _wrap_Ldb_rename, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_delete", (PyCFunction) _wrap_Ldb_delete, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.delete(dn) -> None\n" + "Remove an entry.\n" + ""}, + { (char *)"Ldb_rename", (PyCFunction) _wrap_Ldb_rename, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.rename(old_dn, new_dn) -> None\n" + "Rename an entry.\n" + ""}, { (char *)"Ldb_parse_control_strings", (PyCFunction) _wrap_Ldb_parse_control_strings, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_add", (PyCFunction) _wrap_Ldb_add, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_modify", (PyCFunction) _wrap_Ldb_modify, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_add", (PyCFunction) _wrap_Ldb_add, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.add(message) -> None\n" + "Add an entry.\n" + ""}, + { (char *)"Ldb_modify", (PyCFunction) _wrap_Ldb_modify, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.modify(message) -> None\n" + "Modify an entry.\n" + ""}, { (char *)"Ldb_get_config_basedn", (PyCFunction)_wrap_Ldb_get_config_basedn, METH_O, NULL}, { (char *)"Ldb_get_root_basedn", (PyCFunction)_wrap_Ldb_get_root_basedn, METH_O, NULL}, { (char *)"Ldb_get_schema_basedn", (PyCFunction)_wrap_Ldb_get_schema_basedn, METH_O, NULL}, { (char *)"Ldb_get_default_basedn", (PyCFunction)_wrap_Ldb_get_default_basedn, METH_O, NULL}, { (char *)"Ldb_schema_format_value", (PyCFunction) _wrap_Ldb_schema_format_value, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_errstring", (PyCFunction)_wrap_Ldb_errstring, METH_O, NULL}, - { (char *)"Ldb_set_create_perms", (PyCFunction) _wrap_Ldb_set_create_perms, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_set_modules_dir", (PyCFunction) _wrap_Ldb_set_modules_dir, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_set_create_perms", (PyCFunction) _wrap_Ldb_set_create_perms, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_create_perms(mode) -> None\n" + "Set mode to use when creating new LDB files.\n" + ""}, + { (char *)"Ldb_set_modules_dir", (PyCFunction) _wrap_Ldb_set_modules_dir, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_modules_dir(path) -> None\n" + "Set path LDB should search for modules\n" + ""}, { (char *)"Ldb_set_debug", (PyCFunction) _wrap_Ldb_set_debug, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_set_opaque", (PyCFunction) _wrap_Ldb_set_opaque, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_get_opaque", (PyCFunction) _wrap_Ldb_get_opaque, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_transaction_start", (PyCFunction)_wrap_Ldb_transaction_start, METH_O, NULL}, - { (char *)"Ldb_transaction_commit", (PyCFunction)_wrap_Ldb_transaction_commit, METH_O, NULL}, + { (char *)"Ldb_set_opaque", (PyCFunction) _wrap_Ldb_set_opaque, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_opaque(name, value) -> None\n" + "Set an opaque value on this LDB connection. \n" + ":note: Passing incorrect values may cause crashes.\n" + ""}, + { (char *)"Ldb_get_opaque", (PyCFunction) _wrap_Ldb_get_opaque, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.get_opaque(name) -> value\n" + "Get an opaque value set on this LDB connection. \n" + ":note: The returned value may not be useful in Python.\n" + ""}, + { (char *)"Ldb_transaction_start", (PyCFunction)_wrap_Ldb_transaction_start, METH_O, (char *)"\n" + "S.transaction_start() -> None\n" + "Start a new transaction.\n" + ""}, + { (char *)"Ldb_transaction_commit", (PyCFunction)_wrap_Ldb_transaction_commit, METH_O, (char *)"\n" + "S.transaction_commit() -> None\n" + "Commit currently active transaction.\n" + ""}, { (char *)"Ldb_transaction_cancel", (PyCFunction)_wrap_Ldb_transaction_cancel, METH_O, NULL}, { (char *)"Ldb_schema_attribute_remove", (PyCFunction) _wrap_Ldb_schema_attribute_remove, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_schema_attribute_add", (PyCFunction) _wrap_Ldb_schema_attribute_add, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_setup_wellknown_attributes", (PyCFunction)_wrap_Ldb_setup_wellknown_attributes, METH_O, NULL}, { (char *)"Ldb___contains__", (PyCFunction) _wrap_Ldb___contains__, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"Ldb_parse_ldif", (PyCFunction) _wrap_Ldb_parse_ldif, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_parse_ldif", (PyCFunction) _wrap_Ldb_parse_ldif, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.parse_ldif(ldif) -> iter(messages)\n" + "Parse a string formatted using LDIF.\n" + ""}, { (char *)"Ldb___repr__", (PyCFunction)_wrap_Ldb___repr__, METH_O, NULL}, { (char *)"Ldb_swigregister", Ldb_swigregister, METH_VARARGS, NULL}, { (char *)"Ldb_swiginit", Ldb_swiginit, METH_VARARGS, NULL}, - { (char *)"valid_attr_name", (PyCFunction) _wrap_valid_attr_name, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"valid_attr_name", (PyCFunction) _wrap_valid_attr_name, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.valid_attr_name(name) -> bool\n" + "Check whether the supplied name is a valid attribute name.\n" + ""}, { (char *)"timestring", (PyCFunction) _wrap_timestring, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"string_to_time", (PyCFunction) _wrap_string_to_time, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"register_module", (PyCFunction) _wrap_register_module, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"register_module", (PyCFunction) _wrap_register_module, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.register_module(module) -> None\n" + "Register a LDB module.\n" + ""}, { NULL, NULL, 0, NULL } }; @@ -5814,7 +5884,7 @@ static swig_type_info _swigt__p_ldb_context = {"_p_ldb_context", "struct ldb_con static swig_type_info _swigt__p_ldb_dn = {"_p_ldb_dn", "struct ldb_dn *|ldb_dn *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_ldif = {"_p_ldb_ldif", "struct ldb_ldif *|ldb_ldif *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_message = {"_p_ldb_message", "ldb_msg *|struct ldb_message *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_msg_element *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_message_element *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_module_ops = {"_p_ldb_module_ops", "struct ldb_module_ops *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_result = {"_p_ldb_result", "struct ldb_result *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_val = {"_p_ldb_val", "struct ldb_val *", 0, 0, (void*)0, 0}; -- cgit From fb2d69a140c123ff78df113532d4ead21f3362c3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:02:31 +0200 Subject: Add more docstrings in the ldb python module. (This used to be commit a649a010670ee2c0d155aa62654841cf1f2bab8f) --- source4/lib/ldb/ldb.i | 14 +++++++++++++- source4/lib/ldb/ldb.py | 21 ++++++++++++++++++++- source4/lib/ldb/ldb_wrap.c | 14 ++++++++++---- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 6a807a7dde..38a928ffb1 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -194,6 +194,7 @@ PyObject *ldb_val_to_py_object(struct ldb_context *ldb_ctx, %rename(__cmp__) ldb_dn::compare; %rename(__len__) ldb_dn::get_comp_num; %rename(Dn) ldb_dn; +%feature("docstring") ldb_dn "A LDB distinguished name."; typedef struct ldb_dn { %extend { ldb_dn(ldb *ldb_ctx, const char *str) @@ -356,6 +357,7 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, int ldb_msg_element_compare(ldb_message_element *, ldb_message_element *); /* ldb_message_element */ %rename(MessageElement) ldb_message_element; +%feature("docstring") ldb_message_element "Message element."; %rename(ldb_message_element_compare) ldb_msg_element_compare; typedef struct ldb_message_element { %extend { @@ -417,6 +419,7 @@ typedef struct ldb_message_element { /* ldb_message */ +%feature("docstring") ldb_message "Message."; %rename(Message) ldb_message; #ifdef SWIGPYTHON %rename(__delitem__) ldb_message::remove_attr; @@ -613,6 +616,7 @@ PyObject *PyExc_LdbError; } %rename(Ldb) ldb_context; +%feature("docstring") ldb_context "Connection to a LDB database."; %typemap(in,noblock=1) struct ldb_dn * { if (ldb_dn_from_pyobject(NULL, $input, arg1, &$1) != 0) { @@ -776,6 +780,9 @@ typedef struct ldb_context { %feature("docstring") set_modules_dir "S.set_modules_dir(path) -> None\n" \ "Set path LDB should search for modules"; void set_modules_dir(const char *path); + %feature("docstring") set_debug "S.set_debug(callback) -> None\n" \ + "Set callback for LDB debug messages.\n" \ + "The callback should accept a debug level and debug text."; ldb_error set_debug(void (*debug)(void *context, enum ldb_debug_level level, const char *fmt, va_list ap), void *context); @@ -793,7 +800,7 @@ typedef struct ldb_context { %feature("docstring") transaction_commit "S.transaction_commit() -> None\n" \ "Commit currently active transaction."; ldb_error transaction_commit(); - %feature("docstring") transaction_commit "S.transaction_cancel() -> None\n" \ + %feature("docstring") transaction_cancel "S.transaction_cancel() -> None\n" \ "Cancel currently active transaction."; ldb_error transaction_cancel(); void schema_attribute_remove(const char *name); @@ -877,6 +884,9 @@ int ldb_valid_attr_name(const char *s); typedef unsigned long time_t; +%feature("docstring") timestring "S.timestring(int) -> string\n" + "Generate a LDAP time string from a UNIX timestamp"; + %inline %{ static char *timestring(time_t t) { @@ -888,6 +898,8 @@ static char *timestring(time_t t) %} %rename(string_to_time) ldb_string_to_time; +%feature("docstring") string_to_time "S.string_to_time(string) -> int\n" + "Parse a LDAP time string into a UNIX timestamp."; time_t ldb_string_to_time(const char *s); %typemap(in,noblock=1) const struct ldb_module_ops * { diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index 0149f05429..56f34c8605 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -67,8 +67,10 @@ CHANGETYPE_DELETE = _ldb.CHANGETYPE_DELETE CHANGETYPE_MODIFY = _ldb.CHANGETYPE_MODIFY ldb_val_to_py_object = _ldb.ldb_val_to_py_object class Dn(object): + """A LDB Distinguished name.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self, *args, **kwargs): + """A LDB Distinguished name.""" _ldb.Dn_swiginit(self,_ldb.new_Dn(*args, **kwargs)) __swig_destroy__ = _ldb.delete_Dn def validate(*args, **kwargs): @@ -148,9 +150,11 @@ Dn_swigregister(Dn) ldb_msg_element_compare = _ldb.ldb_msg_element_compare class MessageElement(object): + """A message element.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): + """A message element.""" _ldb.MessageElement_swiginit(self,_ldb.new_MessageElement(*args, **kwargs)) __swig_destroy__ = _ldb.delete_MessageElement def __getitem__(self, i): @@ -182,6 +186,7 @@ MessageElement_swigregister(MessageElement) ldb_msg_list_elements = _ldb.ldb_msg_list_elements class Message(object): + """A LDB message.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr dn = _swig_property(_ldb.Message_dn_get, _ldb.Message_dn_set) @@ -260,6 +265,7 @@ LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED = _ldb.LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED LDB_ERR_AFFECTS_MULTIPLE_DSAS = _ldb.LDB_ERR_AFFECTS_MULTIPLE_DSAS LDB_ERR_OTHER = _ldb.LDB_ERR_OTHER class Ldb(object): + """A connection to a LDB database.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self, *args, **kwargs): _ldb.Ldb_swiginit(self,_ldb.new_Ldb(*args, **kwargs)) @@ -343,6 +349,13 @@ class Ldb(object): """ return _ldb.Ldb_transaction_commit(*args, **kwargs) + def transaction_cancel(*args, **kwargs): + """ + S.transaction_cancel() -> None + Cancel currently active transaction. + """ + return _ldb.Ldb_transaction_cancel(*args, **kwargs) + def parse_ldif(*args, **kwargs): """ S.parse_ldif(ldif) -> iter(messages) @@ -415,7 +428,13 @@ def valid_attr_name(*args, **kwargs): Check whether the supplied name is a valid attribute name. """ return _ldb.valid_attr_name(*args, **kwargs) -timestring = _ldb.timestring + +def timestring(*args, **kwargs): + """ + S.timestring(int) -> string + Generate a LDAP time string from a UNIX timestamp + """ + return _ldb.timestring(*args, **kwargs) string_to_time = _ldb.string_to_time def register_module(*args, **kwargs): diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index bfd507a8f2..95b71547ef 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -5727,7 +5727,7 @@ fail: static PyMethodDef SwigMethods[] = { { (char *)"ldb_val_to_py_object", (PyCFunction) _wrap_ldb_val_to_py_object, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"new_Dn", (PyCFunction) _wrap_new_Dn, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"new_Dn", (PyCFunction) _wrap_new_Dn, METH_VARARGS | METH_KEYWORDS, (char *)"A LDB Distinguished name."}, { (char *)"delete_Dn", (PyCFunction)_wrap_delete_Dn, METH_O, NULL}, { (char *)"Dn_validate", (PyCFunction)_wrap_Dn_validate, METH_O, (char *)"\n" "S.validate() -> bool\n" @@ -5771,7 +5771,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"ldb_msg_element_compare", (PyCFunction) _wrap_ldb_msg_element_compare, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"MessageElement___iter__", (PyCFunction)_wrap_MessageElement___iter__, METH_O, NULL}, { (char *)"MessageElement___set__", (PyCFunction)_wrap_MessageElement___set__, METH_O, NULL}, - { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, (char *)"A message element."}, { (char *)"MessageElement___len__", (PyCFunction)_wrap_MessageElement___len__, METH_O, NULL}, { (char *)"MessageElement_get", (PyCFunction) _wrap_MessageElement_get, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_MessageElement", (PyCFunction)_wrap_delete_MessageElement, METH_O, NULL}, @@ -5848,7 +5848,10 @@ static PyMethodDef SwigMethods[] = { "S.transaction_commit() -> None\n" "Commit currently active transaction.\n" ""}, - { (char *)"Ldb_transaction_cancel", (PyCFunction)_wrap_Ldb_transaction_cancel, METH_O, NULL}, + { (char *)"Ldb_transaction_cancel", (PyCFunction)_wrap_Ldb_transaction_cancel, METH_O, (char *)"\n" + "S.transaction_cancel() -> None\n" + "Cancel currently active transaction.\n" + ""}, { (char *)"Ldb_schema_attribute_remove", (PyCFunction) _wrap_Ldb_schema_attribute_remove, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_schema_attribute_add", (PyCFunction) _wrap_Ldb_schema_attribute_add, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Ldb_setup_wellknown_attributes", (PyCFunction)_wrap_Ldb_setup_wellknown_attributes, METH_O, NULL}, @@ -5864,7 +5867,10 @@ static PyMethodDef SwigMethods[] = { "S.valid_attr_name(name) -> bool\n" "Check whether the supplied name is a valid attribute name.\n" ""}, - { (char *)"timestring", (PyCFunction) _wrap_timestring, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"timestring", (PyCFunction) _wrap_timestring, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.timestring(int) -> string\n" + "Generate a LDAP time string from a UNIX timestamp\n" + ""}, { (char *)"string_to_time", (PyCFunction) _wrap_string_to_time, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"register_module", (PyCFunction) _wrap_register_module, METH_VARARGS | METH_KEYWORDS, (char *)"\n" "S.register_module(module) -> None\n" -- cgit From 9893651c0237c9dba43aadfb8f5f68be74bbfd6c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:15:00 +0200 Subject: Add module docstring, docstrings for constructors. (This used to be commit 67d738d6e65476263a2b7c236a57fe2b0a2dfe32) --- source4/lib/ldb/ldb.i | 12 ++++++++++-- source4/lib/ldb/ldb.py | 42 +++++++++++++++++++++++++++++++++++------- source4/lib/ldb/ldb_wrap.c | 23 ++++++++++++++++++----- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 38a928ffb1..2c5b7535b5 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -25,7 +25,11 @@ License along with this library; if not, see . */ -%module ldb +%define DOCSTRING +"An interface to LDB, a LDAP-like API that can either to talk an embedded database (TDB-based) or a standards-compliant LDAP server." +%enddef + +%module(docstring=DOCSTRING) ldb %{ @@ -197,6 +201,8 @@ PyObject *ldb_val_to_py_object(struct ldb_context *ldb_ctx, %feature("docstring") ldb_dn "A LDB distinguished name."; typedef struct ldb_dn { %extend { + %feature("docstring") ldb_dn "S.__init__(ldb, string)\n" \ + "Create a new DN."; ldb_dn(ldb *ldb_ctx, const char *str) { ldb_dn *ret = ldb_dn_new(ldb_ctx, ldb_ctx, str); @@ -216,6 +222,8 @@ fail: bool validate(); const char *get_casefold(); const char *get_linearized(); + %feature("docstring") parent "S.parent() -> dn\n" \ + "Get the parent for this DN."; ldb_dn *parent() { return ldb_dn_get_parent(NULL, $self); } int compare(ldb_dn *other); bool is_valid(); @@ -898,7 +906,7 @@ static char *timestring(time_t t) %} %rename(string_to_time) ldb_string_to_time; -%feature("docstring") string_to_time "S.string_to_time(string) -> int\n" +%feature("docstring") ldb_string_to_time "S.string_to_time(string) -> int\n" "Parse a LDAP time string into a UNIX timestamp."; time_t ldb_string_to_time(const char *s); diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index 56f34c8605..e458398b0b 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +An interface to LDB, a LDAP-like API that can either to talk an embedded database (TDB-based) or a standards-compliant LDAP server. +""" + import _ldb import new new_instancemethod = new.instancemethod @@ -67,10 +71,13 @@ CHANGETYPE_DELETE = _ldb.CHANGETYPE_DELETE CHANGETYPE_MODIFY = _ldb.CHANGETYPE_MODIFY ldb_val_to_py_object = _ldb.ldb_val_to_py_object class Dn(object): - """A LDB Distinguished name.""" + """A LDB distinguished name.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self, *args, **kwargs): - """A LDB Distinguished name.""" + """ + S.__init__(ldb, string) + Create a new DN. + """ _ldb.Dn_swiginit(self,_ldb.new_Dn(*args, **kwargs)) __swig_destroy__ = _ldb.delete_Dn def validate(*args, **kwargs): @@ -80,6 +87,13 @@ class Dn(object): """ return _ldb.Dn_validate(*args, **kwargs) + def parent(*args, **kwargs): + """ + S.parent() -> dn + Get the parent for this DN. + """ + return _ldb.Dn_parent(*args, **kwargs) + def is_special(*args, **kwargs): """ S.is_special() -> bool @@ -150,11 +164,11 @@ Dn_swigregister(Dn) ldb_msg_element_compare = _ldb.ldb_msg_element_compare class MessageElement(object): - """A message element.""" + """Message element.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): - """A message element.""" + """Message element.""" _ldb.MessageElement_swiginit(self,_ldb.new_MessageElement(*args, **kwargs)) __swig_destroy__ = _ldb.delete_MessageElement def __getitem__(self, i): @@ -186,7 +200,7 @@ MessageElement_swigregister(MessageElement) ldb_msg_list_elements = _ldb.ldb_msg_list_elements class Message(object): - """A LDB message.""" + """Message.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr dn = _swig_property(_ldb.Message_dn_get, _ldb.Message_dn_set) @@ -265,7 +279,7 @@ LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED = _ldb.LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED LDB_ERR_AFFECTS_MULTIPLE_DSAS = _ldb.LDB_ERR_AFFECTS_MULTIPLE_DSAS LDB_ERR_OTHER = _ldb.LDB_ERR_OTHER class Ldb(object): - """A connection to a LDB database.""" + """Connection to a LDB database.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') def __init__(self, *args, **kwargs): _ldb.Ldb_swiginit(self,_ldb.new_Ldb(*args, **kwargs)) @@ -319,6 +333,14 @@ class Ldb(object): """ return _ldb.Ldb_set_modules_dir(*args, **kwargs) + def set_debug(*args, **kwargs): + """ + S.set_debug(callback) -> None + Set callback for LDB debug messages. + The callback should accept a debug level and debug text. + """ + return _ldb.Ldb_set_debug(*args, **kwargs) + def set_opaque(*args, **kwargs): """ S.set_opaque(name, value) -> None @@ -435,7 +457,13 @@ def timestring(*args, **kwargs): Generate a LDAP time string from a UNIX timestamp """ return _ldb.timestring(*args, **kwargs) -string_to_time = _ldb.string_to_time + +def string_to_time(*args, **kwargs): + """ + S.string_to_time(string) -> int + Parse a LDAP time string into a UNIX timestamp. + """ + return _ldb.string_to_time(*args, **kwargs) def register_module(*args, **kwargs): """ diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index 95b71547ef..01d683245e 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -5727,7 +5727,10 @@ fail: static PyMethodDef SwigMethods[] = { { (char *)"ldb_val_to_py_object", (PyCFunction) _wrap_ldb_val_to_py_object, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"new_Dn", (PyCFunction) _wrap_new_Dn, METH_VARARGS | METH_KEYWORDS, (char *)"A LDB Distinguished name."}, + { (char *)"new_Dn", (PyCFunction) _wrap_new_Dn, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.__init__(ldb, string)\n" + "Create a new DN.\n" + ""}, { (char *)"delete_Dn", (PyCFunction)_wrap_delete_Dn, METH_O, NULL}, { (char *)"Dn_validate", (PyCFunction)_wrap_Dn_validate, METH_O, (char *)"\n" "S.validate() -> bool\n" @@ -5735,7 +5738,10 @@ static PyMethodDef SwigMethods[] = { ""}, { (char *)"Dn_get_casefold", (PyCFunction)_wrap_Dn_get_casefold, METH_O, NULL}, { (char *)"Dn___str__", (PyCFunction)_wrap_Dn___str__, METH_O, NULL}, - { (char *)"Dn_parent", (PyCFunction)_wrap_Dn_parent, METH_O, NULL}, + { (char *)"Dn_parent", (PyCFunction)_wrap_Dn_parent, METH_O, (char *)"\n" + "S.parent() -> dn\n" + "Get the parent for this DN.\n" + ""}, { (char *)"Dn___cmp__", (PyCFunction) _wrap_Dn___cmp__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Dn_is_valid", (PyCFunction)_wrap_Dn_is_valid, METH_O, NULL}, { (char *)"Dn_is_special", (PyCFunction)_wrap_Dn_is_special, METH_O, (char *)"\n" @@ -5771,7 +5777,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"ldb_msg_element_compare", (PyCFunction) _wrap_ldb_msg_element_compare, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"MessageElement___iter__", (PyCFunction)_wrap_MessageElement___iter__, METH_O, NULL}, { (char *)"MessageElement___set__", (PyCFunction)_wrap_MessageElement___set__, METH_O, NULL}, - { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, (char *)"A message element."}, + { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, (char *)"Message element."}, { (char *)"MessageElement___len__", (PyCFunction)_wrap_MessageElement___len__, METH_O, NULL}, { (char *)"MessageElement_get", (PyCFunction) _wrap_MessageElement_get, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_MessageElement", (PyCFunction)_wrap_delete_MessageElement, METH_O, NULL}, @@ -5829,7 +5835,11 @@ static PyMethodDef SwigMethods[] = { "S.set_modules_dir(path) -> None\n" "Set path LDB should search for modules\n" ""}, - { (char *)"Ldb_set_debug", (PyCFunction) _wrap_Ldb_set_debug, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Ldb_set_debug", (PyCFunction) _wrap_Ldb_set_debug, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_debug(callback) -> None\n" + "Set callback for LDB debug messages.\n" + "The callback should accept a debug level and debug text.\n" + ""}, { (char *)"Ldb_set_opaque", (PyCFunction) _wrap_Ldb_set_opaque, METH_VARARGS | METH_KEYWORDS, (char *)"\n" "S.set_opaque(name, value) -> None\n" "Set an opaque value on this LDB connection. \n" @@ -5871,7 +5881,10 @@ static PyMethodDef SwigMethods[] = { "S.timestring(int) -> string\n" "Generate a LDAP time string from a UNIX timestamp\n" ""}, - { (char *)"string_to_time", (PyCFunction) _wrap_string_to_time, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"string_to_time", (PyCFunction) _wrap_string_to_time, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.string_to_time(string) -> int\n" + "Parse a LDAP time string into a UNIX timestamp.\n" + ""}, { (char *)"register_module", (PyCFunction) _wrap_register_module, METH_VARARGS | METH_KEYWORDS, (char *)"\n" "S.register_module(module) -> None\n" "Register a LDB module.\n" -- cgit From 66762985e78f6f717658489b6618cb515ca6db71 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:26:55 +0200 Subject: Add some docstrings to tdb. (This used to be commit 3563d62663c36ff267011f1f6f9b256be21c32fb) --- source4/lib/tdb/tdb.i | 43 ++++++++- source4/lib/tdb/tdb.py | 180 ++++++++++++++++++++++++++++++------- source4/lib/tdb/tdb_wrap.c | 218 +++++++++++++++++++++++++++------------------ 3 files changed, 319 insertions(+), 122 deletions(-) diff --git a/source4/lib/tdb/tdb.i b/source4/lib/tdb/tdb.i index 704f0facc6..5f23568170 100644 --- a/source4/lib/tdb/tdb.i +++ b/source4/lib/tdb/tdb.i @@ -24,7 +24,11 @@ License along with this library; if not, see . */ -%module tdb +%define DOCSTRING +"TDB is a simple key-value database similar to GDBM that supports multiple writers." +%enddef + +%module(docstring=DOCSTRING) tdb %{ @@ -138,7 +142,8 @@ enum TDB_ERROR { $1 = TDB_REPLACE; } -%rename(Tdb) tdb; +%rename(Tdb) tdb_context; +%feature("docstring") tdb_context "A TDB file."; %typemap(out,noblock=1) tdb * { /* Throw an IOError exception from errno if tdb_open() returns NULL */ if ($1 == NULL) { @@ -150,34 +155,68 @@ enum TDB_ERROR { typedef struct tdb_context { %extend { + %feature("docstring") tdb "S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600)\n" + "Open a TDB file."; tdb(const char *name, int hash_size, int tdb_flags, int flags, mode_t mode) { return tdb_open(name, hash_size, tdb_flags, flags, mode); } enum TDB_ERROR error(); ~tdb() { tdb_close($self); } + %feature("docstring") close "S.close() -> None\n" + "Close the TDB file."; int close(); int append(TDB_DATA key, TDB_DATA new_dbuf); + %feature("docstring") errorstr "S.errorstr() -> errorstring\n" + "Obtain last error message."; const char *errorstr(); %rename(get) fetch; + %feature("docstring") fetch "S.fetch(key) -> value\n" + "Fetch a value."; TDB_DATA fetch(TDB_DATA key); + %feature("docstring") delete "S.delete(key) -> None\n" + "Delete an entry."; int delete(TDB_DATA key); + %feature("docstring") store "S.store(key, value, flag=TDB_REPLACE) -> None\n" + "Store an entry."; int store(TDB_DATA key, TDB_DATA dbuf, int flag); int exists(TDB_DATA key); + %feature("docstring") firstkey "S.firstkey() -> data\n" + "Return the first key in this database."; TDB_DATA firstkey(); + %feature("docstring") nextkey "S.nextkey(prev) -> data\n" + "Return the next key in this database."; TDB_DATA nextkey(TDB_DATA key); + %feature("docstring") lockall "S.lockall() -> bool"; int lockall(); + %feature("docstring") unlockall "S.unlockall() -> bool"; int unlockall(); + %feature("docstring") unlockall "S.lockall_read() -> bool"; int lockall_read(); + %feature("docstring") unlockall "S.unlockall_read() -> bool"; int unlockall_read(); + %feature("docstring") reopen "S.reopen() -> bool\n" + "Reopen this file."; int reopen(); + %feature("docstring") transaction_start "S.transaction_start() -> None\n" + "Start a new transaction."; int transaction_start(); + %feature("docstring") transaction_commit "S.transaction_commit() -> None\n" + "Commit the currently active transaction."; int transaction_commit(); + %feature("docstring") transaction_cancel "S.transaction_cancel() -> None\n" + "Cancel the currently active transaction."; int transaction_cancel(); int transaction_recover(); + %feature("docstring") hash_size "S.hash_size() -> int"; int hash_size(); + %feature("docstring") map_size "S.map_size() -> int"; size_t map_size(); + %feature("docstring") get_flags "S.get_flags() -> int"; int get_flags(); + %feature("docstring") set_max_dead "S.set_max_dead(int) -> None"; void set_max_dead(int max_dead); + %feature("docstring") name "S.name() -> path\n" \ + "Return filename of this TDB file."; const char *name(); } diff --git a/source4/lib/tdb/tdb.py b/source4/lib/tdb/tdb.py index eb76ca6459..a8c1d06e0d 100644 --- a/source4/lib/tdb/tdb.py +++ b/source4/lib/tdb/tdb.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +TDB is a simple key-value database similar to GDBM that supports multiple writers. +""" + import _tdb import new new_instancemethod = new.instancemethod @@ -78,11 +82,125 @@ TDB_ERR_LOCK_TIMEOUT = _tdb.TDB_ERR_LOCK_TIMEOUT TDB_ERR_NOEXIST = _tdb.TDB_ERR_NOEXIST TDB_ERR_EINVAL = _tdb.TDB_ERR_EINVAL TDB_ERR_RDONLY = _tdb.TDB_ERR_RDONLY -class tdb(object): +class Tdb(object): + """A TDB file.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') - def __init__(self, *args, **kwargs): raise AttributeError, "No constructor defined" __repr__ = _swig_repr - __swig_destroy__ = _tdb.delete_tdb + def __init__(self, *args, **kwargs): + """ + S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600) + Open a TDB file. + """ + _tdb.Tdb_swiginit(self,_tdb.new_Tdb(*args, **kwargs)) + __swig_destroy__ = _tdb.delete_Tdb + def close(*args, **kwargs): + """ + S.close() -> None + Close the TDB file. + """ + return _tdb.Tdb_close(*args, **kwargs) + + def errorstr(*args, **kwargs): + """ + S.errorstr() -> errorstring + Obtain last error message. + """ + return _tdb.Tdb_errorstr(*args, **kwargs) + + def get(*args, **kwargs): + """ + S.fetch(key) -> value + Fetch a value. + """ + return _tdb.Tdb_get(*args, **kwargs) + + def delete(*args, **kwargs): + """ + S.delete(key) -> None + Delete an entry. + """ + return _tdb.Tdb_delete(*args, **kwargs) + + def store(*args, **kwargs): + """ + S.store(key, value, flag=TDB_REPLACE) -> None + Store an entry. + """ + return _tdb.Tdb_store(*args, **kwargs) + + def firstkey(*args, **kwargs): + """ + S.firstkey() -> data + Return the first key in this database. + """ + return _tdb.Tdb_firstkey(*args, **kwargs) + + def nextkey(*args, **kwargs): + """ + S.nextkey(prev) -> data + Return the next key in this database. + """ + return _tdb.Tdb_nextkey(*args, **kwargs) + + def lock_all(*args, **kwargs): + """S.lockall() -> bool""" + return _tdb.Tdb_lock_all(*args, **kwargs) + + def unlock_all(*args, **kwargs): + """S.unlockall() -> bool""" + return _tdb.Tdb_unlock_all(*args, **kwargs) + + def reopen(*args, **kwargs): + """ + S.reopen() -> bool + Reopen this file. + """ + return _tdb.Tdb_reopen(*args, **kwargs) + + def transaction_start(*args, **kwargs): + """ + S.transaction_start() -> None + Start a new transaction. + """ + return _tdb.Tdb_transaction_start(*args, **kwargs) + + def transaction_commit(*args, **kwargs): + """ + S.transaction_commit() -> None + Commit the currently active transaction. + """ + return _tdb.Tdb_transaction_commit(*args, **kwargs) + + def transaction_cancel(*args, **kwargs): + """ + S.transaction_cancel() -> None + Cancel the currently active transaction. + """ + return _tdb.Tdb_transaction_cancel(*args, **kwargs) + + def hash_size(*args, **kwargs): + """S.hash_size() -> int""" + return _tdb.Tdb_hash_size(*args, **kwargs) + + def map_size(*args, **kwargs): + """S.map_size() -> int""" + return _tdb.Tdb_map_size(*args, **kwargs) + + def get_flags(*args, **kwargs): + """S.get_flags() -> int""" + return _tdb.Tdb_get_flags(*args, **kwargs) + + def set_max_dead(*args, **kwargs): + """S.set_max_dead(int) -> None""" + return _tdb.Tdb_set_max_dead(*args, **kwargs) + + def name(*args, **kwargs): + """ + S.name() -> path + Return filename of this TDB file. + """ + return _tdb.Tdb_name(*args, **kwargs) + def __repr__(self): return "Tdb('%s')" % self.name() @@ -178,36 +296,32 @@ class tdb(object): -tdb.error = new_instancemethod(_tdb.tdb_error,None,tdb) -tdb.close = new_instancemethod(_tdb.tdb_close,None,tdb) -tdb.append = new_instancemethod(_tdb.tdb_append,None,tdb) -tdb.errorstr = new_instancemethod(_tdb.tdb_errorstr,None,tdb) -tdb.get = new_instancemethod(_tdb.tdb_get,None,tdb) -tdb.delete = new_instancemethod(_tdb.tdb_delete,None,tdb) -tdb.store = new_instancemethod(_tdb.tdb_store,None,tdb) -tdb.exists = new_instancemethod(_tdb.tdb_exists,None,tdb) -tdb.firstkey = new_instancemethod(_tdb.tdb_firstkey,None,tdb) -tdb.nextkey = new_instancemethod(_tdb.tdb_nextkey,None,tdb) -tdb.lock_all = new_instancemethod(_tdb.tdb_lock_all,None,tdb) -tdb.unlock_all = new_instancemethod(_tdb.tdb_unlock_all,None,tdb) -tdb.read_lock_all = new_instancemethod(_tdb.tdb_read_lock_all,None,tdb) -tdb.read_unlock_all = new_instancemethod(_tdb.tdb_read_unlock_all,None,tdb) -tdb.reopen = new_instancemethod(_tdb.tdb_reopen,None,tdb) -tdb.transaction_start = new_instancemethod(_tdb.tdb_transaction_start,None,tdb) -tdb.transaction_commit = new_instancemethod(_tdb.tdb_transaction_commit,None,tdb) -tdb.transaction_cancel = new_instancemethod(_tdb.tdb_transaction_cancel,None,tdb) -tdb.transaction_recover = new_instancemethod(_tdb.tdb_transaction_recover,None,tdb) -tdb.hash_size = new_instancemethod(_tdb.tdb_hash_size,None,tdb) -tdb.map_size = new_instancemethod(_tdb.tdb_map_size,None,tdb) -tdb.get_flags = new_instancemethod(_tdb.tdb_get_flags,None,tdb) -tdb.set_max_dead = new_instancemethod(_tdb.tdb_set_max_dead,None,tdb) -tdb.name = new_instancemethod(_tdb.tdb_name,None,tdb) -tdb_swigregister = _tdb.tdb_swigregister -tdb_swigregister(tdb) - -def Tdb(*args, **kwargs): - val = _tdb.new_Tdb(*args, **kwargs) - return val +Tdb.error = new_instancemethod(_tdb.Tdb_error,None,Tdb) +Tdb.close = new_instancemethod(_tdb.Tdb_close,None,Tdb) +Tdb.append = new_instancemethod(_tdb.Tdb_append,None,Tdb) +Tdb.errorstr = new_instancemethod(_tdb.Tdb_errorstr,None,Tdb) +Tdb.get = new_instancemethod(_tdb.Tdb_get,None,Tdb) +Tdb.delete = new_instancemethod(_tdb.Tdb_delete,None,Tdb) +Tdb.store = new_instancemethod(_tdb.Tdb_store,None,Tdb) +Tdb.exists = new_instancemethod(_tdb.Tdb_exists,None,Tdb) +Tdb.firstkey = new_instancemethod(_tdb.Tdb_firstkey,None,Tdb) +Tdb.nextkey = new_instancemethod(_tdb.Tdb_nextkey,None,Tdb) +Tdb.lock_all = new_instancemethod(_tdb.Tdb_lock_all,None,Tdb) +Tdb.unlock_all = new_instancemethod(_tdb.Tdb_unlock_all,None,Tdb) +Tdb.read_lock_all = new_instancemethod(_tdb.Tdb_read_lock_all,None,Tdb) +Tdb.read_unlock_all = new_instancemethod(_tdb.Tdb_read_unlock_all,None,Tdb) +Tdb.reopen = new_instancemethod(_tdb.Tdb_reopen,None,Tdb) +Tdb.transaction_start = new_instancemethod(_tdb.Tdb_transaction_start,None,Tdb) +Tdb.transaction_commit = new_instancemethod(_tdb.Tdb_transaction_commit,None,Tdb) +Tdb.transaction_cancel = new_instancemethod(_tdb.Tdb_transaction_cancel,None,Tdb) +Tdb.transaction_recover = new_instancemethod(_tdb.Tdb_transaction_recover,None,Tdb) +Tdb.hash_size = new_instancemethod(_tdb.Tdb_hash_size,None,Tdb) +Tdb.map_size = new_instancemethod(_tdb.Tdb_map_size,None,Tdb) +Tdb.get_flags = new_instancemethod(_tdb.Tdb_get_flags,None,Tdb) +Tdb.set_max_dead = new_instancemethod(_tdb.Tdb_set_max_dead,None,Tdb) +Tdb.name = new_instancemethod(_tdb.Tdb_name,None,Tdb) +Tdb_swigregister = _tdb.Tdb_swigregister +Tdb_swigregister(Tdb) diff --git a/source4/lib/tdb/tdb_wrap.c b/source4/lib/tdb/tdb_wrap.c index f36d569937..27da552d33 100644 --- a/source4/lib/tdb/tdb_wrap.c +++ b/source4/lib/tdb/tdb_wrap.c @@ -2892,7 +2892,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_error(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_error(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; enum TDB_ERROR result; @@ -2904,7 +2904,7 @@ SWIGINTERN PyObject *_wrap_tdb_error(PyObject *SWIGUNUSEDPARM(self), PyObject *a swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_error" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_error" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (enum TDB_ERROR)tdb_error(arg1); @@ -2915,7 +2915,7 @@ fail: } -SWIGINTERN PyObject *_wrap_delete_tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_delete_Tdb(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; void *argp1 = 0 ; @@ -2926,7 +2926,7 @@ SWIGINTERN PyObject *_wrap_delete_tdb(PyObject *SWIGUNUSEDPARM(self), PyObject * swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, SWIG_POINTER_DISOWN | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_tdb" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_Tdb" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); delete_tdb(arg1); @@ -2938,7 +2938,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_close(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_close(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -2950,7 +2950,7 @@ SWIGINTERN PyObject *_wrap_tdb_close(PyObject *SWIGUNUSEDPARM(self), PyObject *a swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_close" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_close" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_close(arg1); @@ -2961,7 +2961,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_append(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Tdb_append(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; TDB_DATA arg2 ; @@ -2976,10 +2976,10 @@ SWIGINTERN PyObject *_wrap_tdb_append(PyObject *SWIGUNUSEDPARM(self), PyObject * (char *) "self",(char *) "key",(char *) "new_dbuf", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:tdb_append",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:Tdb_append",kwnames,&obj0,&obj1,&obj2)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_append" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_append" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); if (obj1 == Py_None) { @@ -3010,7 +3010,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_errorstr(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_errorstr(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; char *result = 0 ; @@ -3022,7 +3022,7 @@ SWIGINTERN PyObject *_wrap_tdb_errorstr(PyObject *SWIGUNUSEDPARM(self), PyObject swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_errorstr" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_errorstr" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (char *)tdb_errorstr(arg1); @@ -3033,7 +3033,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Tdb_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; TDB_DATA arg2 ; @@ -3046,10 +3046,10 @@ SWIGINTERN PyObject *_wrap_tdb_get(PyObject *SWIGUNUSEDPARM(self), PyObject *arg (char *) "self",(char *) "key", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:tdb_get",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_get",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_get" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_get" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); if (obj1 == Py_None) { @@ -3075,7 +3075,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Tdb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; TDB_DATA arg2 ; @@ -3088,10 +3088,10 @@ SWIGINTERN PyObject *_wrap_tdb_delete(PyObject *SWIGUNUSEDPARM(self), PyObject * (char *) "self",(char *) "key", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:tdb_delete",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_delete",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_delete" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_delete" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); if (obj1 == Py_None) { @@ -3112,7 +3112,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_store(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Tdb_store(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; TDB_DATA arg2 ; @@ -3132,10 +3132,10 @@ SWIGINTERN PyObject *_wrap_tdb_store(PyObject *SWIGUNUSEDPARM(self), PyObject *a }; arg4 = TDB_REPLACE; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:tdb_store",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:Tdb_store",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_store" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_store" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); if (obj1 == Py_None) { @@ -3161,7 +3161,7 @@ SWIGINTERN PyObject *_wrap_tdb_store(PyObject *SWIGUNUSEDPARM(self), PyObject *a if (obj3) { ecode4 = SWIG_AsVal_int(obj3, &val4); if (!SWIG_IsOK(ecode4)) { - SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "tdb_store" "', argument " "4"" of type '" "int""'"); + SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "Tdb_store" "', argument " "4"" of type '" "int""'"); } arg4 = (int)(val4); } @@ -3173,7 +3173,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_exists(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Tdb_exists(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; TDB_DATA arg2 ; @@ -3186,10 +3186,10 @@ SWIGINTERN PyObject *_wrap_tdb_exists(PyObject *SWIGUNUSEDPARM(self), PyObject * (char *) "self",(char *) "key", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:tdb_exists",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_exists",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_exists" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_exists" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); if (obj1 == Py_None) { @@ -3210,7 +3210,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_firstkey(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_firstkey(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; TDB_DATA result; @@ -3222,7 +3222,7 @@ SWIGINTERN PyObject *_wrap_tdb_firstkey(PyObject *SWIGUNUSEDPARM(self), PyObject swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_firstkey" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_firstkey" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = tdb_firstkey(arg1); @@ -3238,7 +3238,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_nextkey(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Tdb_nextkey(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; TDB_DATA arg2 ; @@ -3251,10 +3251,10 @@ SWIGINTERN PyObject *_wrap_tdb_nextkey(PyObject *SWIGUNUSEDPARM(self), PyObject (char *) "self",(char *) "key", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:tdb_nextkey",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_nextkey",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_nextkey" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_nextkey" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); if (obj1 == Py_None) { @@ -3280,7 +3280,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3292,7 +3292,7 @@ SWIGINTERN PyObject *_wrap_tdb_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_lock_all" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_lock_all" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_lockall(arg1); @@ -3303,7 +3303,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3315,7 +3315,7 @@ SWIGINTERN PyObject *_wrap_tdb_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObje swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_unlock_all" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_unlock_all" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_unlockall(arg1); @@ -3326,7 +3326,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_read_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_read_lock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3338,7 +3338,7 @@ SWIGINTERN PyObject *_wrap_tdb_read_lock_all(PyObject *SWIGUNUSEDPARM(self), PyO swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_read_lock_all" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_read_lock_all" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_lockall_read(arg1); @@ -3349,7 +3349,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_read_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_read_unlock_all(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3361,7 +3361,7 @@ SWIGINTERN PyObject *_wrap_tdb_read_unlock_all(PyObject *SWIGUNUSEDPARM(self), P swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_read_unlock_all" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_read_unlock_all" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_unlockall_read(arg1); @@ -3372,7 +3372,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_reopen(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_reopen(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3384,7 +3384,7 @@ SWIGINTERN PyObject *_wrap_tdb_reopen(PyObject *SWIGUNUSEDPARM(self), PyObject * swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_reopen" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_reopen" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_reopen(arg1); @@ -3395,7 +3395,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_transaction_start(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_transaction_start(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3407,7 +3407,7 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_start(PyObject *SWIGUNUSEDPARM(self), swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_start" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_start" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_transaction_start(arg1); @@ -3418,7 +3418,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_transaction_commit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_transaction_commit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3430,7 +3430,7 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_commit(PyObject *SWIGUNUSEDPARM(self) swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_commit" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_commit" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_transaction_commit(arg1); @@ -3441,7 +3441,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3453,7 +3453,7 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_cancel(PyObject *SWIGUNUSEDPARM(self) swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_cancel" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_cancel" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_transaction_cancel(arg1); @@ -3464,7 +3464,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_transaction_recover(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_transaction_recover(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3476,7 +3476,7 @@ SWIGINTERN PyObject *_wrap_tdb_transaction_recover(PyObject *SWIGUNUSEDPARM(self swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_transaction_recover" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_transaction_recover" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_transaction_recover(arg1); @@ -3487,7 +3487,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_hash_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_hash_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3499,7 +3499,7 @@ SWIGINTERN PyObject *_wrap_tdb_hash_size(PyObject *SWIGUNUSEDPARM(self), PyObjec swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_hash_size" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_hash_size" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_hash_size(arg1); @@ -3510,7 +3510,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_map_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_map_size(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; size_t result; @@ -3522,7 +3522,7 @@ SWIGINTERN PyObject *_wrap_tdb_map_size(PyObject *SWIGUNUSEDPARM(self), PyObject swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_map_size" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_map_size" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = tdb_map_size(arg1); @@ -3533,7 +3533,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_get_flags(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_get_flags(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int result; @@ -3545,7 +3545,7 @@ SWIGINTERN PyObject *_wrap_tdb_get_flags(PyObject *SWIGUNUSEDPARM(self), PyObjec swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_get_flags" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_get_flags" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (int)tdb_get_flags(arg1); @@ -3556,7 +3556,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_set_max_dead(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_Tdb_set_max_dead(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; int arg2 ; @@ -3570,15 +3570,15 @@ SWIGINTERN PyObject *_wrap_tdb_set_max_dead(PyObject *SWIGUNUSEDPARM(self), PyOb (char *) "self",(char *) "max_dead", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:tdb_set_max_dead",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:Tdb_set_max_dead",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_set_max_dead" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_set_max_dead" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); ecode2 = SWIG_AsVal_int(obj1, &val2); if (!SWIG_IsOK(ecode2)) { - SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "tdb_set_max_dead" "', argument " "2"" of type '" "int""'"); + SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Tdb_set_max_dead" "', argument " "2"" of type '" "int""'"); } arg2 = (int)(val2); tdb_set_max_dead(arg1,arg2); @@ -3589,7 +3589,7 @@ fail: } -SWIGINTERN PyObject *_wrap_tdb_name(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *_wrap_Tdb_name(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; tdb *arg1 = (tdb *) 0 ; char *result = 0 ; @@ -3601,7 +3601,7 @@ SWIGINTERN PyObject *_wrap_tdb_name(PyObject *SWIGUNUSEDPARM(self), PyObject *ar swig_obj[0] = args; res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_tdb_context, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "tdb_name" "', argument " "1"" of type '" "tdb *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Tdb_name" "', argument " "1"" of type '" "tdb *""'"); } arg1 = (tdb *)(argp1); result = (char *)tdb_name(arg1); @@ -3612,41 +3612,85 @@ fail: } -SWIGINTERN PyObject *tdb_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { +SWIGINTERN PyObject *Tdb_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *obj; if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL; SWIG_TypeNewClientData(SWIGTYPE_p_tdb_context, SWIG_NewClientData(obj)); return SWIG_Py_Void(); } +SWIGINTERN PyObject *Tdb_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + return SWIG_Python_InitShadowInstance(args); +} + static PyMethodDef SwigMethods[] = { - { (char *)"new_Tdb", (PyCFunction) _wrap_new_Tdb, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_error", (PyCFunction)_wrap_tdb_error, METH_O, NULL}, - { (char *)"delete_tdb", (PyCFunction)_wrap_delete_tdb, METH_O, NULL}, - { (char *)"tdb_close", (PyCFunction)_wrap_tdb_close, METH_O, NULL}, - { (char *)"tdb_append", (PyCFunction) _wrap_tdb_append, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_errorstr", (PyCFunction)_wrap_tdb_errorstr, METH_O, NULL}, - { (char *)"tdb_get", (PyCFunction) _wrap_tdb_get, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_delete", (PyCFunction) _wrap_tdb_delete, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_store", (PyCFunction) _wrap_tdb_store, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_exists", (PyCFunction) _wrap_tdb_exists, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_firstkey", (PyCFunction)_wrap_tdb_firstkey, METH_O, NULL}, - { (char *)"tdb_nextkey", (PyCFunction) _wrap_tdb_nextkey, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_lock_all", (PyCFunction)_wrap_tdb_lock_all, METH_O, NULL}, - { (char *)"tdb_unlock_all", (PyCFunction)_wrap_tdb_unlock_all, METH_O, NULL}, - { (char *)"tdb_read_lock_all", (PyCFunction)_wrap_tdb_read_lock_all, METH_O, NULL}, - { (char *)"tdb_read_unlock_all", (PyCFunction)_wrap_tdb_read_unlock_all, METH_O, NULL}, - { (char *)"tdb_reopen", (PyCFunction)_wrap_tdb_reopen, METH_O, NULL}, - { (char *)"tdb_transaction_start", (PyCFunction)_wrap_tdb_transaction_start, METH_O, NULL}, - { (char *)"tdb_transaction_commit", (PyCFunction)_wrap_tdb_transaction_commit, METH_O, NULL}, - { (char *)"tdb_transaction_cancel", (PyCFunction)_wrap_tdb_transaction_cancel, METH_O, NULL}, - { (char *)"tdb_transaction_recover", (PyCFunction)_wrap_tdb_transaction_recover, METH_O, NULL}, - { (char *)"tdb_hash_size", (PyCFunction)_wrap_tdb_hash_size, METH_O, NULL}, - { (char *)"tdb_map_size", (PyCFunction)_wrap_tdb_map_size, METH_O, NULL}, - { (char *)"tdb_get_flags", (PyCFunction)_wrap_tdb_get_flags, METH_O, NULL}, - { (char *)"tdb_set_max_dead", (PyCFunction) _wrap_tdb_set_max_dead, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"tdb_name", (PyCFunction)_wrap_tdb_name, METH_O, NULL}, - { (char *)"tdb_swigregister", tdb_swigregister, METH_VARARGS, NULL}, + { (char *)"new_Tdb", (PyCFunction) _wrap_new_Tdb, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.__init__(name,hash_size=0,tdb_flags=TDB_DEFAULT,flags=O_RDWR,mode=0600)\n" + "Open a TDB file.\n" + ""}, + { (char *)"Tdb_error", (PyCFunction)_wrap_Tdb_error, METH_O, NULL}, + { (char *)"delete_Tdb", (PyCFunction)_wrap_delete_Tdb, METH_O, NULL}, + { (char *)"Tdb_close", (PyCFunction)_wrap_Tdb_close, METH_O, (char *)"\n" + "S.close() -> None\n" + "Close the TDB file.\n" + ""}, + { (char *)"Tdb_append", (PyCFunction) _wrap_Tdb_append, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Tdb_errorstr", (PyCFunction)_wrap_Tdb_errorstr, METH_O, (char *)"\n" + "S.errorstr() -> errorstring\n" + "Obtain last error message.\n" + ""}, + { (char *)"Tdb_get", (PyCFunction) _wrap_Tdb_get, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.fetch(key) -> value\n" + "Fetch a value.\n" + ""}, + { (char *)"Tdb_delete", (PyCFunction) _wrap_Tdb_delete, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.delete(key) -> None\n" + "Delete an entry.\n" + ""}, + { (char *)"Tdb_store", (PyCFunction) _wrap_Tdb_store, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.store(key, value, flag=TDB_REPLACE) -> None\n" + "Store an entry.\n" + ""}, + { (char *)"Tdb_exists", (PyCFunction) _wrap_Tdb_exists, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"Tdb_firstkey", (PyCFunction)_wrap_Tdb_firstkey, METH_O, (char *)"\n" + "S.firstkey() -> data\n" + "Return the first key in this database.\n" + ""}, + { (char *)"Tdb_nextkey", (PyCFunction) _wrap_Tdb_nextkey, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.nextkey(prev) -> data\n" + "Return the next key in this database.\n" + ""}, + { (char *)"Tdb_lock_all", (PyCFunction)_wrap_Tdb_lock_all, METH_O, (char *)"S.lockall() -> bool"}, + { (char *)"Tdb_unlock_all", (PyCFunction)_wrap_Tdb_unlock_all, METH_O, (char *)"S.unlockall() -> bool"}, + { (char *)"Tdb_read_lock_all", (PyCFunction)_wrap_Tdb_read_lock_all, METH_O, NULL}, + { (char *)"Tdb_read_unlock_all", (PyCFunction)_wrap_Tdb_read_unlock_all, METH_O, NULL}, + { (char *)"Tdb_reopen", (PyCFunction)_wrap_Tdb_reopen, METH_O, (char *)"\n" + "S.reopen() -> bool\n" + "Reopen this file.\n" + ""}, + { (char *)"Tdb_transaction_start", (PyCFunction)_wrap_Tdb_transaction_start, METH_O, (char *)"\n" + "S.transaction_start() -> None\n" + "Start a new transaction.\n" + ""}, + { (char *)"Tdb_transaction_commit", (PyCFunction)_wrap_Tdb_transaction_commit, METH_O, (char *)"\n" + "S.transaction_commit() -> None\n" + "Commit the currently active transaction.\n" + ""}, + { (char *)"Tdb_transaction_cancel", (PyCFunction)_wrap_Tdb_transaction_cancel, METH_O, (char *)"\n" + "S.transaction_cancel() -> None\n" + "Cancel the currently active transaction.\n" + ""}, + { (char *)"Tdb_transaction_recover", (PyCFunction)_wrap_Tdb_transaction_recover, METH_O, NULL}, + { (char *)"Tdb_hash_size", (PyCFunction)_wrap_Tdb_hash_size, METH_O, (char *)"S.hash_size() -> int"}, + { (char *)"Tdb_map_size", (PyCFunction)_wrap_Tdb_map_size, METH_O, (char *)"S.map_size() -> int"}, + { (char *)"Tdb_get_flags", (PyCFunction)_wrap_Tdb_get_flags, METH_O, (char *)"S.get_flags() -> int"}, + { (char *)"Tdb_set_max_dead", (PyCFunction) _wrap_Tdb_set_max_dead, METH_VARARGS | METH_KEYWORDS, (char *)"S.set_max_dead(int) -> None"}, + { (char *)"Tdb_name", (PyCFunction)_wrap_Tdb_name, METH_O, (char *)"\n" + "S.name() -> path\n" + "Return filename of this TDB file.\n" + ""}, + { (char *)"Tdb_swigregister", Tdb_swigregister, METH_VARARGS, NULL}, + { (char *)"Tdb_swiginit", Tdb_swiginit, METH_VARARGS, NULL}, { NULL, NULL, 0, NULL } }; -- cgit From 73e2fc95901afbc71000461e7613515ca906bcff Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:33:23 +0200 Subject: Add docstrings in misc python module. (This used to be commit 5bf15122e6bb6dcbc2abd325db9522b2084d975f) --- source4/scripting/python/misc.i | 15 ++++++ source4/scripting/python/misc.py | 50 ++++++++++++++++--- source4/scripting/python/misc_wrap.c | 97 ++++++++++++++++++++++++++---------- 3 files changed, 129 insertions(+), 33 deletions(-) diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i index 6fa3bc93e3..9a4c124121 100644 --- a/source4/scripting/python/misc.i +++ b/source4/scripting/python/misc.i @@ -40,6 +40,15 @@ %rename(random_password) generate_random_str; char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); +%feature("docstring") ldb_set_credentials "S.set_credentials(credentials)\n" + "Set credentials to use when connecting."; + +%feature("docstring") ldb_set_session_info "S.set_session_info(session_info)\n" + "Set session info to use when connecting."; + +%feature("docstring") ldb_set_loadparm "S.set_loadparm(session_info)\n" + "Set loadparm context to use when connecting."; + %inline %{ void ldb_set_credentials(struct ldb_context *ldb, struct cli_credentials *creds) { @@ -58,14 +67,20 @@ void ldb_set_loadparm(struct ldb_context *ldb, struct loadparm_context *lp_ctx) %} +%feature("docstring") samdb_set_domain_sid "S.set_domain_sid(sid)\n" + "Set SID of domain to use."; bool samdb_set_domain_sid(struct ldb_context *ldb, const struct dom_sid *dom_sid_in); WERROR dsdb_attach_schema_from_ldif_file(struct ldb_context *ldb, const char *pf, const char *df); +%feature("docstring") samba_version_string "version()\n" + "Obtain the Samba version."; %rename(version) samba_version_string; const char *samba_version_string(void); int dsdb_set_global_schema(struct ldb_context *ldb); +%feature("docstring") ldb_register_samba_handlers "register_samba_handlers()\n" + "Register Samba-specific LDB modules and schemas."; int ldb_register_samba_handlers(struct ldb_context *ldb); %inline %{ diff --git a/source4/scripting/python/misc.py b/source4/scripting/python/misc.py index f1da4c687a..25e8d2de8c 100644 --- a/source4/scripting/python/misc.py +++ b/source4/scripting/python/misc.py @@ -1,5 +1,5 @@ # This file was automatically generated by SWIG (http://www.swig.org). -# Version 1.3.33 +# Version 1.3.35 # # Don't modify this file, modify the SWIG interface instead. @@ -62,14 +62,50 @@ import credentials import param import security random_password = _misc.random_password -ldb_set_credentials = _misc.ldb_set_credentials -ldb_set_session_info = _misc.ldb_set_session_info -ldb_set_loadparm = _misc.ldb_set_loadparm -samdb_set_domain_sid = _misc.samdb_set_domain_sid + +def ldb_set_credentials(*args, **kwargs): + """ + S.set_credentials(credentials) + Set credentials to use when connecting. + """ + return _misc.ldb_set_credentials(*args, **kwargs) + +def ldb_set_session_info(*args, **kwargs): + """ + S.set_session_info(session_info) + Set session info to use when connecting. + """ + return _misc.ldb_set_session_info(*args, **kwargs) + +def ldb_set_loadparm(*args, **kwargs): + """ + S.set_loadparm(session_info) + Set loadparm context to use when connecting. + """ + return _misc.ldb_set_loadparm(*args, **kwargs) + +def samdb_set_domain_sid(*args, **kwargs): + """ + S.set_domain_sid(sid) + Set SID of domain to use. + """ + return _misc.samdb_set_domain_sid(*args, **kwargs) dsdb_attach_schema_from_ldif_file = _misc.dsdb_attach_schema_from_ldif_file -version = _misc.version + +def version(*args): + """ + version() + Obtain the Samba version. + """ + return _misc.version(*args) dsdb_set_global_schema = _misc.dsdb_set_global_schema -ldb_register_samba_handlers = _misc.ldb_register_samba_handlers + +def ldb_register_samba_handlers(*args, **kwargs): + """ + register_samba_handlers() + Register Samba-specific LDB modules and schemas. + """ + return _misc.ldb_register_samba_handlers(*args, **kwargs) 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 4944515d15..22a072fc6f 100644 --- a/source4/scripting/python/misc_wrap.c +++ b/source4/scripting/python/misc_wrap.c @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.33 + * Version 1.3.35 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -126,7 +126,7 @@ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "3" +#define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE @@ -161,6 +161,7 @@ /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 @@ -301,10 +302,10 @@ SWIGINTERNINLINE int SWIG_CheckState(int r) { extern "C" { #endif -typedef void *(*swig_converter_func)(void *); +typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); -/* Structure to store inforomation on one type */ +/* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ @@ -431,8 +432,8 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* @@ -856,7 +857,7 @@ SWIG_Python_AddErrorMsg(const char* mesg) Py_DECREF(old_str); Py_DECREF(value); } else { - PyErr_Format(PyExc_RuntimeError, mesg); + PyErr_SetString(PyExc_RuntimeError, mesg); } } @@ -1416,7 +1417,7 @@ PySwigObject_dealloc(PyObject *v) { PySwigObject *sobj = (PySwigObject *) v; PyObject *next = sobj->next; - if (sobj->own) { + if (sobj->own == SWIG_POINTER_OWN) { swig_type_info *ty = sobj->ty; PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; PyObject *destroy = data ? data->destroy : 0; @@ -1434,12 +1435,13 @@ PySwigObject_dealloc(PyObject *v) res = ((*meth)(mself, v)); } Py_XDECREF(res); - } else { - const char *name = SWIG_TypePrettyName(ty); + } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", name); -#endif + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); } +#endif } Py_XDECREF(next); PyObject_DEL(v); @@ -1944,7 +1946,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj) SWIGRUNTIME int SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own) { + if (own == SWIG_POINTER_OWN) { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); if (sobj) { int oldown = sobj->own; @@ -1965,6 +1967,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int return SWIG_OK; } else { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; while (sobj) { void *vptr = sobj->ptr; if (ty) { @@ -1978,7 +1982,15 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int if (!tc) { sobj = (PySwigObject *)sobj->next; } else { - if (ptr) *ptr = SWIG_TypeCast(tc,vptr); + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } break; } } @@ -1988,7 +2000,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } } if (sobj) { - if (own) *own = sobj->own; + if (own) + *own = *own | sobj->own; if (flags & SWIG_POINTER_DISOWN) { sobj->own = 0; } @@ -2053,8 +2066,13 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { } if (ty) { swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (!tc) return SWIG_ERROR; - *ptr = SWIG_TypeCast(tc,vptr); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } } else { *ptr = vptr; } @@ -2519,7 +2537,7 @@ static swig_module_info swig_module = {swig_types, 27, 0, 0, 0, 0}; #define SWIG_name "_misc" -#define SWIGVERSION 0x010333 +#define SWIGVERSION 0x010335 #define SWIG_VERSION SWIGVERSION @@ -3199,14 +3217,32 @@ fail: 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}, - { (char *)"ldb_set_session_info", (PyCFunction) _wrap_ldb_set_session_info, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ldb_set_loadparm", (PyCFunction) _wrap_ldb_set_loadparm, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"samdb_set_domain_sid", (PyCFunction) _wrap_samdb_set_domain_sid, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ldb_set_credentials", (PyCFunction) _wrap_ldb_set_credentials, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_credentials(credentials)\n" + "Set credentials to use when connecting.\n" + ""}, + { (char *)"ldb_set_session_info", (PyCFunction) _wrap_ldb_set_session_info, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_session_info(session_info)\n" + "Set session info to use when connecting.\n" + ""}, + { (char *)"ldb_set_loadparm", (PyCFunction) _wrap_ldb_set_loadparm, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_loadparm(session_info)\n" + "Set loadparm context to use when connecting.\n" + ""}, + { (char *)"samdb_set_domain_sid", (PyCFunction) _wrap_samdb_set_domain_sid, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set_domain_sid(sid)\n" + "Set SID of domain to use.\n" + ""}, { (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 *)"version", (PyCFunction)_wrap_version, METH_NOARGS, (char *)"\n" + "version()\n" + "Obtain the Samba version.\n" + ""}, { (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 *)"ldb_register_samba_handlers", (PyCFunction) _wrap_ldb_register_samba_handlers, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "register_samba_handlers()\n" + "Register Samba-specific LDB modules and schemas.\n" + ""}, { (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 } @@ -3225,7 +3261,7 @@ static swig_type_info _swigt__p_ldb_context = {"_p_ldb_context", "struct ldb_con static swig_type_info _swigt__p_ldb_dn = {"_p_ldb_dn", "struct ldb_dn *|ldb_dn *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_ldif = {"_p_ldb_ldif", "struct ldb_ldif *|ldb_ldif *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_message = {"_p_ldb_message", "ldb_msg *|struct ldb_message *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_msg_element *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_ldb_message_element = {"_p_ldb_message_element", "struct ldb_message_element *|ldb_message_element *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_ldb_result = {"_p_ldb_result", "struct ldb_result *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0}; static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0}; @@ -3397,7 +3433,7 @@ SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; - int found; + int found, init; clientdata = clientdata; @@ -3407,6 +3443,9 @@ SWIG_InitializeModule(void *clientdata) { swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; + init = 1; + } else { + init = 0; } /* Try and load any already created modules */ @@ -3435,6 +3474,12 @@ SWIG_InitializeModule(void *clientdata) { module_head->next = &swig_module; } + /* When multiple interpeters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %d\n", swig_module.size); -- cgit From c401aa93573460f10256218a6a1902839b17b884 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 17:42:18 +0200 Subject: Use restructuredText formatting for docstrings. (This used to be commit 0cc58decd74d20f3d7dff93ddef1c8bce4d49ad0) --- source4/lib/ldb/ldb.i | 4 ++++ source4/lib/ldb/ldb.py | 2 ++ source4/scripting/python/samba/__init__.py | 2 ++ source4/scripting/python/samba/idmap.py | 2 ++ source4/scripting/python/samba/provision.py | 2 ++ source4/scripting/python/samba/samba3.py | 2 ++ source4/scripting/python/samba/samdb.py | 2 ++ source4/scripting/python/samba/upgrade.py | 2 ++ 8 files changed, 18 insertions(+) diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 2c5b7535b5..21bee63ea8 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -920,3 +920,7 @@ time_t ldb_string_to_time(const char *s); "Register a LDB module."; %rename(register_module) ldb_register_module; ldb_int_error ldb_register_module(const struct ldb_module_ops *); + +%pythoncode { +__docformat__ = "restructuredText" +} diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index e458398b0b..03869799c2 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -471,5 +471,7 @@ def register_module(*args, **kwargs): Register a LDB module. """ return _ldb.register_module(*args, **kwargs) +__docformat__ = "restructuredText" + diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 29afdb931d..c7d71d3747 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -20,6 +20,8 @@ # along with this program. If not, see . # +__docformat__ = "restructuredText" + import os def _in_source_tree(): diff --git a/source4/scripting/python/samba/idmap.py b/source4/scripting/python/samba/idmap.py index 16efcd0470..755ec52c7b 100644 --- a/source4/scripting/python/samba/idmap.py +++ b/source4/scripting/python/samba/idmap.py @@ -20,6 +20,8 @@ """Convenience functions for using the idmap database.""" +__docformat__ = "restructuredText" + import samba import misc import ldb diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index 69c7e8846d..68b43eff40 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -43,6 +43,8 @@ from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \ """Functions for setting up a Samba configuration.""" +__docformat__ = "restructuredText" + DEFAULTSITE = "Default-First-Site-Name" class InvalidNetbiosName(Exception): diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py index cffedb54af..9e802fa093 100644 --- a/source4/scripting/python/samba/samba3.py +++ b/source4/scripting/python/samba/samba3.py @@ -19,6 +19,8 @@ """Support for reading Samba 3 data files.""" +__docformat__ = "restructuredText" + REGISTRY_VALUE_PREFIX = "SAMBA_REGVAL" REGISTRY_DB_VERSION = 1 diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py index 198d1e9f5c..6465f49519 100644 --- a/source4/scripting/python/samba/samdb.py +++ b/source4/scripting/python/samba/samdb.py @@ -28,6 +28,8 @@ import ldb from samba.idmap import IDmapDB import pwd +__docformat__ = "restructuredText" + class SamDB(samba.Ldb): """The SAM database.""" diff --git a/source4/scripting/python/samba/upgrade.py b/source4/scripting/python/samba/upgrade.py index f40f2cffe7..0c83604e82 100644 --- a/source4/scripting/python/samba/upgrade.py +++ b/source4/scripting/python/samba/upgrade.py @@ -7,6 +7,8 @@ """Support code for upgrading from Samba 3 to Samba 4.""" +__docformat__ = "restructuredText" + from provision import findnss, provision, FILL_DRS import grp import ldb -- cgit From b8310221c60e75fc8fe9764958213033cc43fb84 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 18:03:01 +0200 Subject: Add docstring for samba.net.Join (This used to be commit 382de5455363ab1ae7436ff8da4b952d2b6541e9) --- source4/libnet/py_net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c index cf81d8070d..443da299c7 100644 --- a/source4/libnet/py_net.c +++ b/source4/libnet/py_net.c @@ -71,8 +71,11 @@ static PyObject *py_net_join(PyObject *cls, PyObject *args, PyObject *kwargs) return result; } +static char py_net_join_doc[] = "join(domain_name, netbios_name, join_type, level) -> (join_password, domain_sid, domain_name)\n\n" \ +"Join the domain with the specified name."; + static struct PyMethodDef net_methods[] = { - {"Join", (PyCFunction)py_net_join, METH_VARARGS|METH_KEYWORDS}, + {"Join", (PyCFunction)py_net_join, METH_VARARGS|METH_KEYWORDS, py_net_join_doc}, {NULL } }; -- cgit From 90471951285465130dba73b3c6c3acc912e751d6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 18:13:48 +0200 Subject: Add docstrings to param python module. (This used to be commit 39d27088e51867705ceec356759e7c3609a102bf) --- source4/param/param.i | 26 +++++++++++++++++ source4/param/param.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++ source4/param/param_wrap.c | 50 ++++++++++++++++++++++++++------- 3 files changed, 136 insertions(+), 10 deletions(-) diff --git a/source4/param/param.i b/source4/param/param.i index 2f62cb2f16..2c15f8f5e3 100644 --- a/source4/param/param.i +++ b/source4/param/param.i @@ -50,22 +50,36 @@ typedef struct loadparm_context { %extend { loadparm_context(TALLOC_CTX *mem_ctx) { return loadparm_init(mem_ctx); } struct loadparm_service *default_service() { return lp_default_service($self); } + %feature("docstring") load "S.load(filename) -> None\n" \ + "Load specified file."; bool load(const char *filename) { return lp_load($self, filename); } + %feature("docstring") load_default "S.load_default() -> None\n" \ + "Load default smb.conf file."; bool load_default() { return lp_load_default($self); } #ifdef SWIGPYTHON int __len__() { return lp_numservices($self); } struct loadparm_service *__getitem__(const char *name) { return lp_service($self, name); } #endif + %feature("docstring") configfile "S.configfile() -> string\n" \ + "Return name of last config file that was loaded."; const char *configfile() { return lp_configfile($self); } + %feature("docstring") is_mydomain "S.is_mydomain(domain_name) -> bool\n" \ + "Check whether the specified name matches our domain name."; bool is_mydomain(const char *domain) { return lp_is_mydomain($self, domain); } + %feature("docstring") is_myname "S.is_myname(netbios_name) -> bool\n" \ + "Check whether the specified name matches one of our netbios names."; bool is_myname(const char *name) { return lp_is_myname($self, name); } int use(struct param_context *param_ctx) { return param_use($self, param_ctx); } + %feature("docstring") set "S.set(name, value) -> bool\n" \ + "Change a parameter."; bool set(const char *parm_name, const char *parm_value) { if (parm_value == NULL) return false; return lp_set_cmdline($self, parm_name, parm_value); } + %feature("docstring") set "S.get(name, service_name) -> value\n" \ + "Find specified parameter."; PyObject *get(const char *param_name, const char *service_name) { struct parm_struct *parm = NULL; @@ -180,7 +194,11 @@ typedef struct loadparm_service { typedef struct param_context { %extend { param(TALLOC_CTX *mem_ctx) { return param_init(mem_ctx); } + %feature("docstring") add_section "S.get_section(name) -> section\n" + "Get an existing section."; struct param_section *get_section(const char *name); + %feature("docstring") add_section "S.add_section(name) -> section\n" + "Add a new section."; struct param_section *add_section(const char *name); struct param_opt *get(const char *name, const char *section_name="global"); const char *get_string(const char *name, const char *section_name="global"); @@ -198,10 +216,18 @@ typedef struct param_context { #endif + %feature("docstring") first_section "S.first_section() -> section\n" + "Find first section"; struct param_section *first_section() { return $self->sections; } + %feature("docstring") next_section "S.next_section(prev) -> section\n" + "Find next section"; struct param_section *next_section(struct param_section *s) { return s->next; } + %feature("docstring") read "S.read(filename) -> bool\n" + "Read a filename."; int read(const char *fn); + %feature("docstring") read "S.write(filename) -> bool\n" + "Write this object to a file."; int write(const char *fn); } %pythoncode { diff --git a/source4/param/param.py b/source4/param/param.py index 0419c75bfa..3aebaf0e02 100644 --- a/source4/param/param.py +++ b/source4/param/param.py @@ -62,6 +62,48 @@ class LoadParm(object): __repr__ = _swig_repr def __init__(self, *args, **kwargs): _param.LoadParm_swiginit(self,_param.new_LoadParm(*args, **kwargs)) + def load(*args, **kwargs): + """ + S.load(filename) -> None + Load specified file. + """ + return _param.LoadParm_load(*args, **kwargs) + + def load_default(*args, **kwargs): + """ + S.load_default() -> None + Load default smb.conf file. + """ + return _param.LoadParm_load_default(*args, **kwargs) + + def configfile(*args, **kwargs): + """ + S.configfile() -> string + Return name of last config file that was loaded. + """ + return _param.LoadParm_configfile(*args, **kwargs) + + def is_mydomain(*args, **kwargs): + """ + S.is_mydomain(domain_name) -> bool + Check whether the specified name matches our domain name. + """ + return _param.LoadParm_is_mydomain(*args, **kwargs) + + def is_myname(*args, **kwargs): + """ + S.is_myname(netbios_name) -> bool + Check whether the specified name matches one of our netbios names. + """ + return _param.LoadParm_is_myname(*args, **kwargs) + + def set(*args, **kwargs): + """ + S.set(name, value) -> bool + Change a parameter. + """ + return _param.LoadParm_set(*args, **kwargs) + __swig_destroy__ = _param.delete_LoadParm LoadParm.default_service = new_instancemethod(_param.LoadParm_default_service,None,LoadParm) LoadParm.load = new_instancemethod(_param.LoadParm_load,None,LoadParm) @@ -92,6 +134,34 @@ class ParamFile(object): __repr__ = _swig_repr def __init__(self, *args, **kwargs): _param.ParamFile_swiginit(self,_param.new_ParamFile(*args, **kwargs)) + def add_section(*args, **kwargs): + """ + S.add_section(name) -> section + Add a new section. + """ + return _param.ParamFile_add_section(*args, **kwargs) + + def first_section(*args, **kwargs): + """ + S.first_section() -> section + Find first section + """ + return _param.ParamFile_first_section(*args, **kwargs) + + def next_section(*args, **kwargs): + """ + S.next_section(prev) -> section + Find next section + """ + return _param.ParamFile_next_section(*args, **kwargs) + + def read(*args, **kwargs): + """ + S.read(filename) -> bool + Read a filename. + """ + return _param.ParamFile_read(*args, **kwargs) + def __getitem__(self, name): ret = self.get_section(name) if ret is None: diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c index d07be04a66..aff239312d 100644 --- a/source4/param/param_wrap.c +++ b/source4/param/param_wrap.c @@ -4168,15 +4168,33 @@ SWIGINTERN PyObject *Swig_var_default_config_get(void) { static PyMethodDef SwigMethods[] = { { (char *)"new_LoadParm", (PyCFunction)_wrap_new_LoadParm, METH_NOARGS, NULL}, { (char *)"LoadParm_default_service", (PyCFunction) _wrap_LoadParm_default_service, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"LoadParm_load", (PyCFunction) _wrap_LoadParm_load, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"LoadParm_load_default", (PyCFunction) _wrap_LoadParm_load_default, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_load", (PyCFunction) _wrap_LoadParm_load, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.load(filename) -> None\n" + "Load specified file.\n" + ""}, + { (char *)"LoadParm_load_default", (PyCFunction) _wrap_LoadParm_load_default, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.load_default() -> None\n" + "Load default smb.conf file.\n" + ""}, { (char *)"LoadParm___len__", (PyCFunction) _wrap_LoadParm___len__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"LoadParm___getitem__", (PyCFunction) _wrap_LoadParm___getitem__, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"LoadParm_configfile", (PyCFunction) _wrap_LoadParm_configfile, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"LoadParm_is_mydomain", (PyCFunction) _wrap_LoadParm_is_mydomain, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"LoadParm_is_myname", (PyCFunction) _wrap_LoadParm_is_myname, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_configfile", (PyCFunction) _wrap_LoadParm_configfile, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.configfile() -> string\n" + "Return name of last config file that was loaded.\n" + ""}, + { (char *)"LoadParm_is_mydomain", (PyCFunction) _wrap_LoadParm_is_mydomain, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.is_mydomain(domain_name) -> bool\n" + "Check whether the specified name matches our domain name.\n" + ""}, + { (char *)"LoadParm_is_myname", (PyCFunction) _wrap_LoadParm_is_myname, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.is_myname(netbios_name) -> bool\n" + "Check whether the specified name matches one of our netbios names.\n" + ""}, { (char *)"LoadParm_use", (PyCFunction) _wrap_LoadParm_use, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"LoadParm_set", (PyCFunction) _wrap_LoadParm_set, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"LoadParm_set", (PyCFunction) _wrap_LoadParm_set, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.set(name, value) -> bool\n" + "Change a parameter.\n" + ""}, { (char *)"LoadParm_get", (PyCFunction) _wrap_LoadParm_get, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_LoadParm", (PyCFunction) _wrap_delete_LoadParm, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"LoadParm_swigregister", LoadParm_swigregister, METH_VARARGS, NULL}, @@ -4187,14 +4205,26 @@ static PyMethodDef SwigMethods[] = { { (char *)"loadparm_service_swigregister", loadparm_service_swigregister, METH_VARARGS, NULL}, { (char *)"new_ParamFile", (PyCFunction)_wrap_new_ParamFile, METH_NOARGS, NULL}, { (char *)"ParamFile_get_section", (PyCFunction) _wrap_ParamFile_get_section, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ParamFile_add_section", (PyCFunction) _wrap_ParamFile_add_section, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_add_section", (PyCFunction) _wrap_ParamFile_add_section, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.add_section(name) -> section\n" + "Add a new section.\n" + ""}, { (char *)"ParamFile_get", (PyCFunction) _wrap_ParamFile_get, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_get_string", (PyCFunction) _wrap_ParamFile_get_string, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_set_string", (PyCFunction) _wrap_ParamFile_set_string, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"ParamFile_set", (PyCFunction) _wrap_ParamFile_set, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ParamFile_first_section", (PyCFunction)_wrap_ParamFile_first_section, METH_O, NULL}, - { (char *)"ParamFile_next_section", (PyCFunction) _wrap_ParamFile_next_section, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"ParamFile_read", (PyCFunction) _wrap_ParamFile_read, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"ParamFile_first_section", (PyCFunction)_wrap_ParamFile_first_section, METH_O, (char *)"\n" + "S.first_section() -> section\n" + "Find first section\n" + ""}, + { (char *)"ParamFile_next_section", (PyCFunction) _wrap_ParamFile_next_section, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.next_section(prev) -> section\n" + "Find next section\n" + ""}, + { (char *)"ParamFile_read", (PyCFunction) _wrap_ParamFile_read, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.read(filename) -> bool\n" + "Read a filename.\n" + ""}, { (char *)"ParamFile_write", (PyCFunction) _wrap_ParamFile_write, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"delete_ParamFile", (PyCFunction)_wrap_delete_ParamFile, METH_O, NULL}, { (char *)"ParamFile_swigregister", ParamFile_swigregister, METH_VARARGS, NULL}, -- cgit From 985d6d8dddd1e9ff1328575e068338ad43211643 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 18:24:10 +0200 Subject: add more docstrings to registry python module (This used to be commit 606f92db874c139ba532df53a87cc5b826215d9e) --- source4/lib/registry/registry.i | 24 +++++++++++++++ source4/lib/registry/registry.py | 60 +++++++++++++++++++++++++++++++++--- source4/lib/registry/registry_wrap.c | 30 ++++++++++++------ 3 files changed, 100 insertions(+), 14 deletions(-) diff --git a/source4/lib/registry/registry.i b/source4/lib/registry/registry.i index 5ffee4bb3d..7dd02b344c 100644 --- a/source4/lib/registry/registry.i +++ b/source4/lib/registry/registry.i @@ -93,11 +93,20 @@ WERROR reg_open_local(TALLOC_CTX *parent_ctx, struct registry_context **ctx); typedef struct registry_context { %extend { + %feature("docstring") get_predefined_key_by_name "S.get_predefined_key_by_name(name) -> key\n" + "Find a predefined key by name"; WERROR get_predefined_key_by_name(const char *name, struct registry_key **key); + %feature("docstring") key_del_abs "S.key_del_abs(name) -> None\n" + "Delete a key by absolute path."; WERROR key_del_abs(const char *path); + %feature("docstring") get_predefined_key "S.get_predefined_key(hkey_id) -> key\n" + "Find a predefined key by id"; WERROR get_predefined_key(uint32_t hkey_id, struct registry_key **key); + %feature("docstring") diff_apply "S.diff_apply(filename) -> None\n" + "Apply the diff from the specified file"; + WERROR diff_apply(const char *filename); WERROR generate_diff(struct registry_context *ctx2, const struct reg_diff_callbacks *callbacks, void *callback_data); @@ -106,6 +115,8 @@ typedef struct registry_context { const char **elements=NULL); struct registry_key *import_hive_key(struct hive_key *hive, uint32_t predef_key, const char **elements); + %feature("docstring") mount_hive "S.mount_hive(key, predef_name) -> None\n" + "Mount the specified key at the specified path."; WERROR mount_hive(struct hive_key *key, const char *predef_name) { int i; @@ -130,6 +141,7 @@ typedef struct registry_context { $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_hive_key, 0); } +%feature("docstring") reg_open_hive "S.__init__(location, session_info=None, credentials=None, loadparm_context=None)"; %rename(hive_key) reg_open_hive; WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location, struct auth_session_info *session_info, @@ -138,6 +150,7 @@ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location, struct loadparm_context *lp_ctx, struct hive_key **root); +%feature("docstring") reg_open_ldb_file "open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key"; %rename(open_ldb) reg_open_ldb_file; WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location, struct auth_session_info *session_info, @@ -146,10 +159,12 @@ WERROR reg_open_ldb_file(TALLOC_CTX *parent_ctx, const char *location, struct loadparm_context *lp_ctx, struct hive_key **k); +%feature("docstring") reg_create_directory "create_dir(location) -> key"; %rename(create_dir) reg_create_directory; WERROR reg_create_directory(TALLOC_CTX *parent_ctx, const char *location, struct hive_key **key); +%feature("docstring") reg_open_directory "open_dir(location) -> key"; %rename(open_dir) reg_open_directory; WERROR reg_open_directory(TALLOC_CTX *parent_ctx, const char *location, struct hive_key **key); @@ -158,15 +173,24 @@ WERROR reg_open_directory(TALLOC_CTX *parent_ctx, typedef struct hive_key { %extend { + %feature("docstring") del "S.del(name) -> None\n" + "Delete a subkey"; WERROR del(const char *name); + %feature("docstring") flush "S.flush() -> None\n" + "Flush this key to disk"; WERROR flush(void); + %feature("docstring") del_value "S.del_value(name) -> None\n" + "Delete a value"; WERROR del_value(const char *name); + %feature("docstring") set_value "S.set_value(name, type, data) -> None\n" + "Set a value"; WERROR set_value(const char *name, uint32_t type, const DATA_BLOB data); } } hive_key; %rename(open_samba) reg_open_samba; +%feature("docstring") reg_open_samba "open_samba() -> reg"; WERROR reg_open_samba(TALLOC_CTX *mem_ctx, struct registry_context **ctx, struct event_context *ev_ctx, diff --git a/source4/lib/registry/registry.py b/source4/lib/registry/registry.py index cb20d6039d..4c6e735414 100644 --- a/source4/lib/registry/registry.py +++ b/source4/lib/registry/registry.py @@ -66,6 +66,41 @@ Registry = _registry.Registry class reg(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr + def get_predefined_key_by_name(*args, **kwargs): + """ + S.get_predefined_key_by_name(name) -> key + Find a predefined key by name + """ + return _registry.reg_get_predefined_key_by_name(*args, **kwargs) + + def key_del_abs(*args, **kwargs): + """ + S.key_del_abs(name) -> None + Delete a key by absolute path. + """ + return _registry.reg_key_del_abs(*args, **kwargs) + + def get_predefined_key(*args, **kwargs): + """ + S.get_predefined_key(hkey_id) -> key + Find a predefined key by id + """ + return _registry.reg_get_predefined_key(*args, **kwargs) + + def diff_apply(*args, **kwargs): + """ + S.diff_apply(filename) -> None + Apply the diff from the specified file + """ + return _registry.reg_diff_apply(*args, **kwargs) + + def mount_hive(*args): + """ + S.mount_hive(key, predef_name) -> None + Mount the specified key at the specified path. + """ + return _registry.reg_mount_hive(*args) + def __init__(self, *args, **kwargs): _registry.reg_swiginit(self,_registry.new_reg(*args, **kwargs)) __swig_destroy__ = _registry.delete_reg @@ -79,11 +114,26 @@ reg.mount_hive = new_instancemethod(_registry.reg_mount_hive,None,reg) reg_swigregister = _registry.reg_swigregister reg_swigregister(reg) -hive_key = _registry.hive_key -open_ldb = _registry.open_ldb -create_dir = _registry.create_dir -open_dir = _registry.open_dir -open_samba = _registry.open_samba + +def hive_key(*args, **kwargs): + """S.__init__(location, session_info=None, credentials=None, loadparm_context=None)""" + return _registry.hive_key(*args, **kwargs) + +def open_ldb(*args, **kwargs): + """open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key""" + return _registry.open_ldb(*args, **kwargs) + +def create_dir(*args, **kwargs): + """create_dir(location) -> key""" + return _registry.create_dir(*args, **kwargs) + +def open_dir(*args, **kwargs): + """open_dir(location) -> key""" + return _registry.open_dir(*args, **kwargs) + +def open_samba(*args, **kwargs): + """open_samba() -> reg""" + return _registry.open_samba(*args, **kwargs) HKEY_CLASSES_ROOT = _registry.HKEY_CLASSES_ROOT HKEY_CURRENT_USER = _registry.HKEY_CURRENT_USER HKEY_LOCAL_MACHINE = _registry.HKEY_LOCAL_MACHINE diff --git a/source4/lib/registry/registry_wrap.c b/source4/lib/registry/registry_wrap.c index d9b85ee937..b066e42b41 100644 --- a/source4/lib/registry/registry_wrap.c +++ b/source4/lib/registry/registry_wrap.c @@ -3798,10 +3798,22 @@ static PyMethodDef SwigMethods[] = { { (char *)"reg_get_predef_name", (PyCFunction) _wrap_reg_get_predef_name, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"str_regtype", (PyCFunction) _wrap_str_regtype, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Registry", (PyCFunction)_wrap_Registry, METH_NOARGS, NULL}, - { (char *)"reg_get_predefined_key_by_name", (PyCFunction) _wrap_reg_get_predefined_key_by_name, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"reg_key_del_abs", (PyCFunction) _wrap_reg_key_del_abs, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"reg_get_predefined_key", (PyCFunction) _wrap_reg_get_predefined_key, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"reg_diff_apply", (PyCFunction) _wrap_reg_diff_apply, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"reg_get_predefined_key_by_name", (PyCFunction) _wrap_reg_get_predefined_key_by_name, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.get_predefined_key_by_name(name) -> key\n" + "Find a predefined key by name\n" + ""}, + { (char *)"reg_key_del_abs", (PyCFunction) _wrap_reg_key_del_abs, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.key_del_abs(name) -> None\n" + "Delete a key by absolute path.\n" + ""}, + { (char *)"reg_get_predefined_key", (PyCFunction) _wrap_reg_get_predefined_key, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.get_predefined_key(hkey_id) -> key\n" + "Find a predefined key by id\n" + ""}, + { (char *)"reg_diff_apply", (PyCFunction) _wrap_reg_diff_apply, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.diff_apply(filename) -> None\n" + "Apply the diff from the specified file\n" + ""}, { (char *)"reg_generate_diff", (PyCFunction) _wrap_reg_generate_diff, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"reg_import_hive_key", (PyCFunction) _wrap_reg_import_hive_key, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"reg_mount_hive", _wrap_reg_mount_hive, METH_VARARGS, NULL}, @@ -3809,11 +3821,11 @@ static PyMethodDef SwigMethods[] = { { (char *)"delete_reg", (PyCFunction)_wrap_delete_reg, METH_O, NULL}, { (char *)"reg_swigregister", reg_swigregister, METH_VARARGS, NULL}, { (char *)"reg_swiginit", reg_swiginit, METH_VARARGS, NULL}, - { (char *)"hive_key", (PyCFunction) _wrap_hive_key, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"open_ldb", (PyCFunction) _wrap_open_ldb, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"create_dir", (PyCFunction) _wrap_create_dir, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"open_dir", (PyCFunction) _wrap_open_dir, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"open_samba", (PyCFunction) _wrap_open_samba, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"hive_key", (PyCFunction) _wrap_hive_key, METH_VARARGS | METH_KEYWORDS, (char *)"S.__init__(location, session_info=None, credentials=None, loadparm_context=None)"}, + { (char *)"open_ldb", (PyCFunction) _wrap_open_ldb, METH_VARARGS | METH_KEYWORDS, (char *)"open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key"}, + { (char *)"create_dir", (PyCFunction) _wrap_create_dir, METH_VARARGS | METH_KEYWORDS, (char *)"create_dir(location) -> key"}, + { (char *)"open_dir", (PyCFunction) _wrap_open_dir, METH_VARARGS | METH_KEYWORDS, (char *)"open_dir(location) -> key"}, + { (char *)"open_samba", (PyCFunction) _wrap_open_samba, METH_VARARGS | METH_KEYWORDS, (char *)"open_samba() -> reg"}, { NULL, NULL, 0, NULL } }; -- cgit From 37d000d052795063f63a321835d60de55389c1bd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 18:47:18 +0200 Subject: Add docstrings to events python module. (This used to be commit 7d43d2c7c91c86246b9bb2ae7eda050079767e7a) --- source4/lib/events/events.i | 5 +++++ source4/lib/events/events.py | 19 +++++++++++++++++-- source4/lib/events/events_wrap.c | 10 +++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/source4/lib/events/events.i b/source4/lib/events/events.i index c16d482efc..7de8aec79d 100644 --- a/source4/lib/events/events.i +++ b/source4/lib/events/events.i @@ -27,8 +27,11 @@ typedef struct event_context event; typedef struct event_context { %extend { + %feature("docstring") event "S.__init__()"; event(TALLOC_CTX *mem_ctx) { return event_context_init(mem_ctx); } + %feature("docstring") loop_once "S.loop_once() -> int"; int loop_once(void); + %feature("docstring") loop_wait "S.loop_wait() -> int"; int loop_wait(void); } } event; @@ -44,6 +47,8 @@ typedef struct event_context { struct event_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char *name); +%feature("docstring") event_backend_list "event_backend_list() -> list"; const char **event_backend_list(TALLOC_CTX *mem_ctx); +%feature("docstring") event_set_default_backend "event_set_default_backend(name) -> None"; %rename(set_default_backend) event_set_default_backend; void event_set_default_backend(const char *backend); diff --git a/source4/lib/events/events.py b/source4/lib/events/events.py index 237726897d..264e0b7cdf 100644 --- a/source4/lib/events/events.py +++ b/source4/lib/events/events.py @@ -61,7 +61,16 @@ class event(object): thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') __repr__ = _swig_repr def __init__(self, *args, **kwargs): + """S.__init__()""" _events.event_swiginit(self,_events.new_event(*args, **kwargs)) + def loop_once(*args, **kwargs): + """S.loop_once() -> int""" + return _events.event_loop_once(*args, **kwargs) + + def loop_wait(*args, **kwargs): + """S.loop_wait() -> int""" + return _events.event_loop_wait(*args, **kwargs) + __swig_destroy__ = _events.delete_event event.loop_once = new_instancemethod(_events.event_loop_once,None,event) event.loop_wait = new_instancemethod(_events.event_loop_wait,None,event) @@ -69,7 +78,13 @@ event_swigregister = _events.event_swigregister event_swigregister(event) event_context_init_byname = _events.event_context_init_byname -event_backend_list = _events.event_backend_list -set_default_backend = _events.set_default_backend + +def event_backend_list(*args): + """event_backend_list() -> list""" + return _events.event_backend_list(*args) + +def set_default_backend(*args, **kwargs): + """event_set_default_backend(name) -> None""" + return _events.set_default_backend(*args, **kwargs) diff --git a/source4/lib/events/events_wrap.c b/source4/lib/events/events_wrap.c index 727485dfdb..ccaeab7ad6 100644 --- a/source4/lib/events/events_wrap.c +++ b/source4/lib/events/events_wrap.c @@ -2773,15 +2773,15 @@ fail: static PyMethodDef SwigMethods[] = { - { (char *)"new_event", (PyCFunction)_wrap_new_event, METH_NOARGS, NULL}, - { (char *)"event_loop_once", (PyCFunction)_wrap_event_loop_once, METH_O, NULL}, - { (char *)"event_loop_wait", (PyCFunction)_wrap_event_loop_wait, METH_O, NULL}, + { (char *)"new_event", (PyCFunction)_wrap_new_event, METH_NOARGS, (char *)"S.__init__()"}, + { (char *)"event_loop_once", (PyCFunction)_wrap_event_loop_once, METH_O, (char *)"S.loop_once() -> int"}, + { (char *)"event_loop_wait", (PyCFunction)_wrap_event_loop_wait, METH_O, (char *)"S.loop_wait() -> int"}, { (char *)"delete_event", (PyCFunction)_wrap_delete_event, METH_O, NULL}, { (char *)"event_swigregister", event_swigregister, METH_VARARGS, NULL}, { (char *)"event_swiginit", event_swiginit, METH_VARARGS, NULL}, { (char *)"event_context_init_byname", (PyCFunction) _wrap_event_context_init_byname, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"event_backend_list", (PyCFunction)_wrap_event_backend_list, METH_NOARGS, NULL}, - { (char *)"set_default_backend", (PyCFunction) _wrap_set_default_backend, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"event_backend_list", (PyCFunction)_wrap_event_backend_list, METH_NOARGS, (char *)"event_backend_list() -> list"}, + { (char *)"set_default_backend", (PyCFunction) _wrap_set_default_backend, METH_VARARGS | METH_KEYWORDS, (char *)"event_set_default_backend(name) -> None"}, { NULL, NULL, 0, NULL } }; -- cgit From c159d1221bddec5c855fda9236913c18fc7a49fa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 18:47:32 +0200 Subject: Add docstrings to samba3 and getopt modules. (This used to be commit bdf1c039db6c184a9f275a6e4bf3786570cc924a) --- source4/scripting/python/samba/getopt.py | 15 +++++++++++++++ source4/scripting/python/samba/samba3.py | 3 +++ 2 files changed, 18 insertions(+) diff --git a/source4/scripting/python/samba/getopt.py b/source4/scripting/python/samba/getopt.py index 7ec684a9d6..9ecb66e21c 100644 --- a/source4/scripting/python/samba/getopt.py +++ b/source4/scripting/python/samba/getopt.py @@ -17,10 +17,15 @@ # along with this program. If not, see . # +"""Support for parsing Samba-related command-line options.""" + import optparse from credentials import Credentials, AUTO_USE_KERBEROS, DONT_USE_KERBEROS, MUST_USE_KERBEROS +__docformat__ = "restructuredText" + class SambaOptions(optparse.OptionGroup): + """General Samba-related command line options.""" def __init__(self, parser): optparse.OptionGroup.__init__(self, parser, "Samba Common Options") self.add_option("-s", "--configfile", action="callback", @@ -29,12 +34,14 @@ class SambaOptions(optparse.OptionGroup): self._configfile = None def get_loadparm_path(self): + """Return the path to the smb.conf file specified on the command line. """ return self._configfile def _load_configfile(self, option, opt_str, arg, parser): self._configfile = arg def get_loadparm(self): + """Return a loadparm object with data specified on the command line. """ import os, param lp = param.LoadParm() if self._configfile is not None: @@ -45,12 +52,15 @@ class SambaOptions(optparse.OptionGroup): lp.load_default() return lp + class VersionOptions(optparse.OptionGroup): + """Command line option for printing Samba version.""" def __init__(self, parser): optparse.OptionGroup.__init__(self, parser, "Version Options") class CredentialsOptions(optparse.OptionGroup): + """Command line options for specifying credentials.""" def __init__(self, parser): self.no_pass = False optparse.OptionGroup.__init__(self, parser, "Credentials Options") @@ -91,6 +101,11 @@ class CredentialsOptions(optparse.OptionGroup): self.creds.set_bind_dn(arg) def get_credentials(self, lp): + """Obtain the credentials set on the command-line. + + :param lp: Loadparm object to use. + :return: Credentials object + """ self.creds.guess(lp) if not self.no_pass: self.creds.set_cmdline_callbacks() diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py index 9e802fa093..c1340b7760 100644 --- a/source4/scripting/python/samba/samba3.py +++ b/source4/scripting/python/samba/samba3.py @@ -309,6 +309,7 @@ class ShareInfoDatabase(TdbDatabase): class Shares: + """Container for share objects.""" def __init__(self, lp, shareinfo): self.lp = lp self.shareinfo = shareinfo @@ -494,6 +495,7 @@ class TdbSam(TdbDatabase): assert self.version in (0, 1, 2) def usernames(self): + """Iterate over the usernames in this Tdb database.""" for k in self.tdb.keys(): if k.startswith(TDBSAM_USER_PREFIX): yield k[len(TDBSAM_USER_PREFIX):].rstrip("\0") @@ -635,6 +637,7 @@ class WinsDatabase: return iter(self.entries) def items(self): + """Return the entries in this WINS database.""" return self.entries.items() def close(self): # for consistency -- cgit From 1a42178166e07add705da42ed1f936f95a7a4382 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 00:45:50 +0200 Subject: dcerpc is now samba.dcerpc, avoid including source code in API documentation. (This used to be commit a28a8ed53557451749007a119e979f561c6b0f59) --- source4/scripting/python/config.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk index 73607eb76c..b494ee6e8d 100644 --- a/source4/scripting/python/config.mk +++ b/source4/scripting/python/config.mk @@ -29,7 +29,9 @@ $(foreach pyfile, $(_PY_FILES),$(eval $(call python_py_module_template,$(patsubs $(eval $(call python_py_module_template,samba/misc.py,$(pyscriptsrcdir)/misc.py)) +EPYDOC_OPTIONS = --no-private --url http://www.samba.org/ --no-sourcecode + epydoc:: pythonmods - PYTHONPATH=$(pythonbuilddir) epydoc --no-private samba dcerpc tdb ldb subunit + PYTHONPATH=$(pythonbuilddir) epydoc $(EPYDOC_OPTIONS) samba tdb ldb subunit install:: installpython -- cgit From e56d2db3bd5c0edf115fbd30a68fcca8fe1bdd29 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 02:42:42 +0200 Subject: Properly fix symlink for module aliases. (This used to be commit 84d93728667921bf36a1b25c32bf8befa941a2c6) --- source4/build/make/templates.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/build/make/templates.mk b/source4/build/make/templates.mk index 1c0af4dee6..41a7ccd0a5 100644 --- a/source4/build/make/templates.mk +++ b/source4/build/make/templates.mk @@ -92,7 +92,7 @@ PLUGINS += bin/modules/$(2)/$(3).$$(SHLIBEXT) uninstallplugins:: @-rm $$(DESTDIR)$$(modulesdir)/$(2)/$(3).$$(SHLIBEXT) installplugins:: - @ln -fs $(basename $(1)) $$(DESTDIR)$$(modulesdir)/$(2)/$(3).$$(SHLIBEXT) + @ln -fs $(notdir $(1)) $$(DESTDIR)$$(modulesdir)/$(2)/$(3).$$(SHLIBEXT) endef -- cgit From 7cfcec2e9d8ea5ad9619848f60c846e805fb15a2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 02:44:42 +0200 Subject: Fix imports for minschema. (This used to be commit bda223a49e6bdeda68518cba27bc92df33784939) --- source4/scripting/bin/minschema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source4/scripting/bin/minschema.py b/source4/scripting/bin/minschema.py index 6dd5b42aff..111557126d 100755 --- a/source4/scripting/bin/minschema.py +++ b/source4/scripting/bin/minschema.py @@ -5,6 +5,8 @@ import optparse +import os, sys + # Find right directory when running from source tree sys.path.insert(0, "bin/python") -- cgit From 166105b0b6b4c23eeb563562c75abcd6fa8e01e2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 03:20:37 +0200 Subject: Fix bug after reprocessing swig files with newer version of SWIG. (This used to be commit 2155d76646f4235c8857460f562a9cc4cafe3ab1) --- source4/scripting/python/config.m4 | 2 +- source4/scripting/python/samba/__init__.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4 index 1a86951bfb..b599aaefb0 100644 --- a/source4/scripting/python/config.m4 +++ b/source4/scripting/python/config.m4 @@ -5,7 +5,7 @@ AC_ARG_VAR([PYTHON_VERSION],[The installed Python will be appended to the Python interpreter canonical name.]) -AC_PROG_SWIG(1.3.31) +AC_PROG_SWIG(1.3.35) AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]]) if test -z "$PYTHON"; then diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index c7d71d3747..94f9e4d005 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -73,15 +73,15 @@ class Ldb(ldb.Ldb): self.set_modules_dir(default_ldb_modules_dir) if credentials is not None: - self.set_credentials(self, credentials) + self.set_credentials(credentials) if session_info is not None: - self.set_session_info(self, session_info) + self.set_session_info(session_info) assert misc.ldb_register_samba_handlers(self) == 0 if lp is not None: - self.set_loadparm(self, lp) + self.set_loadparm(lp) def msg(l,text): print text -- cgit From a46450810b7d41dc11b1d35807307d9b19e68682 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 03:22:56 +0200 Subject: Regenerate with SWIG 1.3.35. (This used to be commit ce063eca498036937f99161a1f12e076c2ab313f) --- source4/auth/auth.py | 2 +- source4/auth/auth_wrap.c | 65 +++++++++++++++++++++++---------- source4/libcli/security/security.py | 2 +- source4/libcli/security/security_wrap.c | 65 +++++++++++++++++++++++---------- source4/libcli/swig/libcli_smb.py | 2 +- source4/libcli/swig/libcli_smb_wrap.c | 65 +++++++++++++++++++++++---------- source4/librpc/rpc/dcerpc.py | 2 + 7 files changed, 143 insertions(+), 60 deletions(-) diff --git a/source4/auth/auth.py b/source4/auth/auth.py index 88675f3626..1a7aa6d0e7 100644 --- a/source4/auth/auth.py +++ b/source4/auth/auth.py @@ -1,5 +1,5 @@ # This file was automatically generated by SWIG (http://www.swig.org). -# Version 1.3.33 +# Version 1.3.35 # # Don't modify this file, modify the SWIG interface instead. diff --git a/source4/auth/auth_wrap.c b/source4/auth/auth_wrap.c index af1827adc9..dea76ef87d 100644 --- a/source4/auth/auth_wrap.c +++ b/source4/auth/auth_wrap.c @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.33 + * Version 1.3.35 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -126,7 +126,7 @@ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "3" +#define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE @@ -161,6 +161,7 @@ /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 @@ -301,10 +302,10 @@ SWIGINTERNINLINE int SWIG_CheckState(int r) { extern "C" { #endif -typedef void *(*swig_converter_func)(void *); +typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); -/* Structure to store inforomation on one type */ +/* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ @@ -431,8 +432,8 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* @@ -856,7 +857,7 @@ SWIG_Python_AddErrorMsg(const char* mesg) Py_DECREF(old_str); Py_DECREF(value); } else { - PyErr_Format(PyExc_RuntimeError, mesg); + PyErr_SetString(PyExc_RuntimeError, mesg); } } @@ -1416,7 +1417,7 @@ PySwigObject_dealloc(PyObject *v) { PySwigObject *sobj = (PySwigObject *) v; PyObject *next = sobj->next; - if (sobj->own) { + if (sobj->own == SWIG_POINTER_OWN) { swig_type_info *ty = sobj->ty; PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; PyObject *destroy = data ? data->destroy : 0; @@ -1434,12 +1435,13 @@ PySwigObject_dealloc(PyObject *v) res = ((*meth)(mself, v)); } Py_XDECREF(res); - } else { - const char *name = SWIG_TypePrettyName(ty); + } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", name); -#endif + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); } +#endif } Py_XDECREF(next); PyObject_DEL(v); @@ -1944,7 +1946,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj) SWIGRUNTIME int SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own) { + if (own == SWIG_POINTER_OWN) { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); if (sobj) { int oldown = sobj->own; @@ -1965,6 +1967,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int return SWIG_OK; } else { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; while (sobj) { void *vptr = sobj->ptr; if (ty) { @@ -1978,7 +1982,15 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int if (!tc) { sobj = (PySwigObject *)sobj->next; } else { - if (ptr) *ptr = SWIG_TypeCast(tc,vptr); + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } break; } } @@ -1988,7 +2000,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } } if (sobj) { - if (own) *own = sobj->own; + if (own) + *own = *own | sobj->own; if (flags & SWIG_POINTER_DISOWN) { sobj->own = 0; } @@ -2053,8 +2066,13 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { } if (ty) { swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (!tc) return SWIG_ERROR; - *ptr = SWIG_TypeCast(tc,vptr); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } } else { *ptr = vptr; } @@ -2505,7 +2523,7 @@ static swig_module_info swig_module = {swig_types, 16, 0, 0, 0, 0}; #define SWIG_name "_auth" -#define SWIGVERSION 0x010333 +#define SWIGVERSION 0x010335 #define SWIG_VERSION SWIGVERSION @@ -2733,7 +2751,7 @@ SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; - int found; + int found, init; clientdata = clientdata; @@ -2743,6 +2761,9 @@ SWIG_InitializeModule(void *clientdata) { swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; + init = 1; + } else { + init = 0; } /* Try and load any already created modules */ @@ -2771,6 +2792,12 @@ SWIG_InitializeModule(void *clientdata) { module_head->next = &swig_module; } + /* When multiple interpeters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %d\n", swig_module.size); diff --git a/source4/libcli/security/security.py b/source4/libcli/security/security.py index 10b263b27b..7e56e22cef 100644 --- a/source4/libcli/security/security.py +++ b/source4/libcli/security/security.py @@ -1,5 +1,5 @@ # This file was automatically generated by SWIG (http://www.swig.org). -# Version 1.3.33 +# Version 1.3.35 # # Don't modify this file, modify the SWIG interface instead. diff --git a/source4/libcli/security/security_wrap.c b/source4/libcli/security/security_wrap.c index eb9e4c45d9..aabf6c27ee 100644 --- a/source4/libcli/security/security_wrap.c +++ b/source4/libcli/security/security_wrap.c @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.33 + * Version 1.3.35 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -126,7 +126,7 @@ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "3" +#define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE @@ -161,6 +161,7 @@ /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 @@ -301,10 +302,10 @@ SWIGINTERNINLINE int SWIG_CheckState(int r) { extern "C" { #endif -typedef void *(*swig_converter_func)(void *); +typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); -/* Structure to store inforomation on one type */ +/* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ @@ -431,8 +432,8 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* @@ -856,7 +857,7 @@ SWIG_Python_AddErrorMsg(const char* mesg) Py_DECREF(old_str); Py_DECREF(value); } else { - PyErr_Format(PyExc_RuntimeError, mesg); + PyErr_SetString(PyExc_RuntimeError, mesg); } } @@ -1416,7 +1417,7 @@ PySwigObject_dealloc(PyObject *v) { PySwigObject *sobj = (PySwigObject *) v; PyObject *next = sobj->next; - if (sobj->own) { + if (sobj->own == SWIG_POINTER_OWN) { swig_type_info *ty = sobj->ty; PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; PyObject *destroy = data ? data->destroy : 0; @@ -1434,12 +1435,13 @@ PySwigObject_dealloc(PyObject *v) res = ((*meth)(mself, v)); } Py_XDECREF(res); - } else { - const char *name = SWIG_TypePrettyName(ty); + } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", name); -#endif + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); } +#endif } Py_XDECREF(next); PyObject_DEL(v); @@ -1944,7 +1946,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj) SWIGRUNTIME int SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own) { + if (own == SWIG_POINTER_OWN) { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); if (sobj) { int oldown = sobj->own; @@ -1965,6 +1967,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int return SWIG_OK; } else { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; while (sobj) { void *vptr = sobj->ptr; if (ty) { @@ -1978,7 +1982,15 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int if (!tc) { sobj = (PySwigObject *)sobj->next; } else { - if (ptr) *ptr = SWIG_TypeCast(tc,vptr); + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } break; } } @@ -1988,7 +2000,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } } if (sobj) { - if (own) *own = sobj->own; + if (own) + *own = *own | sobj->own; if (flags & SWIG_POINTER_DISOWN) { sobj->own = 0; } @@ -2053,8 +2066,13 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { } if (ty) { swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (!tc) return SWIG_ERROR; - *ptr = SWIG_TypeCast(tc,vptr); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } } else { *ptr = vptr; } @@ -2503,7 +2521,7 @@ static swig_module_info swig_module = {swig_types, 14, 0, 0, 0, 0}; #define SWIG_name "_security" -#define SWIGVERSION 0x010333 +#define SWIGVERSION 0x010335 #define SWIG_VERSION SWIGVERSION @@ -3674,7 +3692,7 @@ SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; - int found; + int found, init; clientdata = clientdata; @@ -3684,6 +3702,9 @@ SWIG_InitializeModule(void *clientdata) { swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; + init = 1; + } else { + init = 0; } /* Try and load any already created modules */ @@ -3712,6 +3733,12 @@ SWIG_InitializeModule(void *clientdata) { module_head->next = &swig_module; } + /* When multiple interpeters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %d\n", swig_module.size); diff --git a/source4/libcli/swig/libcli_smb.py b/source4/libcli/swig/libcli_smb.py index 80c4040237..6e4fe036c7 100644 --- a/source4/libcli/swig/libcli_smb.py +++ b/source4/libcli/swig/libcli_smb.py @@ -1,5 +1,5 @@ # This file was automatically generated by SWIG (http://www.swig.org). -# Version 1.3.33 +# Version 1.3.35 # # Don't modify this file, modify the SWIG interface instead. diff --git a/source4/libcli/swig/libcli_smb_wrap.c b/source4/libcli/swig/libcli_smb_wrap.c index 8b71f2c3be..de8e6ba1e4 100644 --- a/source4/libcli/swig/libcli_smb_wrap.c +++ b/source4/libcli/swig/libcli_smb_wrap.c @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.33 + * Version 1.3.35 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -126,7 +126,7 @@ /* This should only be incremented when either the layout of swig_type_info changes, or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "3" +#define SWIG_RUNTIME_VERSION "4" /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ #ifdef SWIG_TYPE_TABLE @@ -161,6 +161,7 @@ /* Flags for pointer conversions */ #define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 /* Flags for new pointer objects */ #define SWIG_POINTER_OWN 0x1 @@ -301,10 +302,10 @@ SWIGINTERNINLINE int SWIG_CheckState(int r) { extern "C" { #endif -typedef void *(*swig_converter_func)(void *); +typedef void *(*swig_converter_func)(void *, int *); typedef struct swig_type_info *(*swig_dycast_func)(void **); -/* Structure to store inforomation on one type */ +/* Structure to store information on one type */ typedef struct swig_type_info { const char *name; /* mangled name of this type */ const char *str; /* human readable name of this type */ @@ -431,8 +432,8 @@ SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { Cast a pointer up an inheritance hierarchy */ SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); } /* @@ -856,7 +857,7 @@ SWIG_Python_AddErrorMsg(const char* mesg) Py_DECREF(old_str); Py_DECREF(value); } else { - PyErr_Format(PyExc_RuntimeError, mesg); + PyErr_SetString(PyExc_RuntimeError, mesg); } } @@ -1416,7 +1417,7 @@ PySwigObject_dealloc(PyObject *v) { PySwigObject *sobj = (PySwigObject *) v; PyObject *next = sobj->next; - if (sobj->own) { + if (sobj->own == SWIG_POINTER_OWN) { swig_type_info *ty = sobj->ty; PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; PyObject *destroy = data ? data->destroy : 0; @@ -1434,12 +1435,13 @@ PySwigObject_dealloc(PyObject *v) res = ((*meth)(mself, v)); } Py_XDECREF(res); - } else { - const char *name = SWIG_TypePrettyName(ty); + } #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", name); -#endif + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); } +#endif } Py_XDECREF(next); PyObject_DEL(v); @@ -1944,7 +1946,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj) SWIGRUNTIME int SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own) { + if (own == SWIG_POINTER_OWN) { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); if (sobj) { int oldown = sobj->own; @@ -1965,6 +1967,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int return SWIG_OK; } else { PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; while (sobj) { void *vptr = sobj->ptr; if (ty) { @@ -1978,7 +1982,15 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int if (!tc) { sobj = (PySwigObject *)sobj->next; } else { - if (ptr) *ptr = SWIG_TypeCast(tc,vptr); + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } break; } } @@ -1988,7 +2000,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int } } if (sobj) { - if (own) *own = sobj->own; + if (own) + *own = *own | sobj->own; if (flags & SWIG_POINTER_DISOWN) { sobj->own = 0; } @@ -2053,8 +2066,13 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { } if (ty) { swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (!tc) return SWIG_ERROR; - *ptr = SWIG_TypeCast(tc,vptr); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } } else { *ptr = vptr; } @@ -2495,7 +2513,7 @@ static swig_module_info swig_module = {swig_types, 6, 0, 0, 0, 0}; #define SWIG_name "_libcli_smb" -#define SWIGVERSION 0x010333 +#define SWIGVERSION 0x010335 #define SWIG_VERSION SWIGVERSION @@ -2769,7 +2787,7 @@ SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; swig_module_info *module_head, *iter; - int found; + int found, init; clientdata = clientdata; @@ -2779,6 +2797,9 @@ SWIG_InitializeModule(void *clientdata) { swig_module.type_initial = swig_type_initial; swig_module.cast_initial = swig_cast_initial; swig_module.next = &swig_module; + init = 1; + } else { + init = 0; } /* Try and load any already created modules */ @@ -2807,6 +2828,12 @@ SWIG_InitializeModule(void *clientdata) { module_head->next = &swig_module; } + /* When multiple interpeters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %d\n", swig_module.size); diff --git a/source4/librpc/rpc/dcerpc.py b/source4/librpc/rpc/dcerpc.py index db5b95cee8..9005ac5a4e 100644 --- a/source4/librpc/rpc/dcerpc.py +++ b/source4/librpc/rpc/dcerpc.py @@ -57,6 +57,8 @@ def _swig_setattr_nondynamic_method(set): return set_attr +import credentials +import param pipe_connect = _dcerpc.pipe_connect dcerpc_server_name = _dcerpc.dcerpc_server_name -- cgit From c6132465d166c2760b6ab291fea90c216b920372 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 12:34:50 +0200 Subject: Remove unused EJS testprogs. (This used to be commit e14c9302009b371f385612d2fd500773d238006a) --- testprogs/ejs/loadparm.js | 25 ------------------------- testprogs/ejs/resolveName.js | 13 ------------- 2 files changed, 38 deletions(-) delete mode 100644 testprogs/ejs/loadparm.js delete mode 100644 testprogs/ejs/resolveName.js diff --git a/testprogs/ejs/loadparm.js b/testprogs/ejs/loadparm.js deleted file mode 100644 index f56ca9f7fc..0000000000 --- a/testprogs/ejs/loadparm.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - demonstrate access to loadparm functions from ejs -*/ - -loadparm_init(local); - -function showParameter(name) { - print(name + ": "); - printVars(get(name)); -} - -for (v in ARGV) { - showParameter(ARGV[v]); -} - -print("defined services: "); -printVars(services()); - -showParameter("server services"); -showParameter("netbios name"); -showParameter("security"); -showParameter("workgroup"); -showParameter("log level"); -showParameter("server signing"); -showParameter("interfaces"); diff --git a/testprogs/ejs/resolveName.js b/testprogs/ejs/resolveName.js deleted file mode 100644 index 1619b69d69..0000000000 --- a/testprogs/ejs/resolveName.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - Demonstrate use of resolveName() js function -*/ - -var result = new Object(); - -res = resolveName(result, ARGV[0]); - -if (res.is_ok) { - println(result.value); -} else { - println(res.errstr); -} -- cgit From 4b95f9001b8af9c519ca0f0f6edf82964b63f409 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 03:56:20 +0200 Subject: Work around bug adding extra imports in generated file. (This used to be commit a34de3c619c8c112b4e1ee7ca5985a506730fcff) --- source4/librpc/rpc/dcerpc.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/source4/librpc/rpc/dcerpc.py b/source4/librpc/rpc/dcerpc.py index 9005ac5a4e..db5b95cee8 100644 --- a/source4/librpc/rpc/dcerpc.py +++ b/source4/librpc/rpc/dcerpc.py @@ -57,8 +57,6 @@ def _swig_setattr_nondynamic_method(set): return set_attr -import credentials -import param pipe_connect = _dcerpc.pipe_connect dcerpc_server_name = _dcerpc.dcerpc_server_name -- cgit From 564b6ed025bdfbd93876e084e9f3dd1a6774fa5c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 04:07:42 +0200 Subject: Add proper implementation of MessageElement.__cmp__. (This used to be commit 076e2cc356978ac313fcfdf8d8243f4ed1d629b0) --- source4/lib/ldb/ldb.i | 8 +++++--- source4/lib/ldb/ldb.py | 2 +- source4/lib/ldb/ldb_wrap.c | 17 ++++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source4/lib/ldb/ldb.i b/source4/lib/ldb/ldb.i index 21bee63ea8..061d13a2dd 100644 --- a/source4/lib/ldb/ldb.i +++ b/source4/lib/ldb/ldb.i @@ -362,14 +362,17 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, %} #endif -int ldb_msg_element_compare(ldb_message_element *, ldb_message_element *); /* ldb_message_element */ %rename(MessageElement) ldb_message_element; %feature("docstring") ldb_message_element "Message element."; -%rename(ldb_message_element_compare) ldb_msg_element_compare; typedef struct ldb_message_element { %extend { #ifdef SWIGPYTHON + int __cmp__(ldb_message_element *other) + { + return ldb_msg_element_compare($self, other); + } + PyObject *__iter__(void) { return PyObject_GetIter(ldb_msg_element_to_set(NULL, $self)); @@ -400,7 +403,6 @@ typedef struct ldb_message_element { } ~ldb_message_element() { talloc_free($self); } - %rename(__cmp__) ldb_msg_element_compare; } %pythoncode { def __getitem__(self, i): diff --git a/source4/lib/ldb/ldb.py b/source4/lib/ldb/ldb.py index 03869799c2..ae2c187367 100644 --- a/source4/lib/ldb/ldb.py +++ b/source4/lib/ldb/ldb.py @@ -162,7 +162,6 @@ Dn.__add__ = new_instancemethod(_ldb.Dn___add__,None,Dn) Dn_swigregister = _ldb.Dn_swigregister Dn_swigregister(Dn) -ldb_msg_element_compare = _ldb.ldb_msg_element_compare class MessageElement(object): """Message element.""" thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag') @@ -191,6 +190,7 @@ class MessageElement(object): return False return True +MessageElement.__cmp__ = new_instancemethod(_ldb.MessageElement___cmp__,None,MessageElement) MessageElement.__iter__ = new_instancemethod(_ldb.MessageElement___iter__,None,MessageElement) MessageElement.__set__ = new_instancemethod(_ldb.MessageElement___set__,None,MessageElement) MessageElement.__len__ = new_instancemethod(_ldb.MessageElement___len__,None,MessageElement) diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c index 01d683245e..744033cbf6 100644 --- a/source4/lib/ldb/ldb_wrap.c +++ b/source4/lib/ldb/ldb_wrap.c @@ -2809,6 +2809,9 @@ PyObject *ldb_msg_element_to_set(struct ldb_context *ldb_ctx, } +SWIGINTERN int ldb_message_element___cmp__(ldb_message_element *self,ldb_message_element *other){ + return ldb_msg_element_compare(self, other); + } SWIGINTERN PyObject *ldb_message_element___iter__(ldb_message_element *self){ return PyObject_GetIter(ldb_msg_element_to_set(NULL, self)); } @@ -3763,7 +3766,7 @@ SWIGINTERN PyObject *Dn_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) return SWIG_Python_InitShadowInstance(args); } -SWIGINTERN PyObject *_wrap_ldb_msg_element_compare(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { +SWIGINTERN PyObject *_wrap_MessageElement___cmp__(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { PyObject *resultobj = 0; ldb_message_element *arg1 = (ldb_message_element *) 0 ; ldb_message_element *arg2 = (ldb_message_element *) 0 ; @@ -3775,21 +3778,21 @@ SWIGINTERN PyObject *_wrap_ldb_msg_element_compare(PyObject *SWIGUNUSEDPARM(self PyObject * obj0 = 0 ; PyObject * obj1 = 0 ; char * kwnames[] = { - (char *)"arg1",(char *)"arg2", NULL + (char *) "self",(char *) "other", NULL }; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ldb_msg_element_compare",kwnames,&obj0,&obj1)) SWIG_fail; + if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:MessageElement___cmp__",kwnames,&obj0,&obj1)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ldb_msg_element_compare" "', argument " "1"" of type '" "ldb_message_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "MessageElement___cmp__" "', argument " "1"" of type '" "ldb_message_element *""'"); } arg1 = (ldb_message_element *)(argp1); res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_ldb_message_element, 0 | 0 ); if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ldb_msg_element_compare" "', argument " "2"" of type '" "ldb_message_element *""'"); + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MessageElement___cmp__" "', argument " "2"" of type '" "ldb_message_element *""'"); } arg2 = (ldb_message_element *)(argp2); - result = (int)ldb_msg_element_compare(arg1,arg2); + result = (int)ldb_message_element___cmp__(arg1,arg2); resultobj = SWIG_From_int((int)(result)); return resultobj; fail: @@ -5774,7 +5777,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"Dn___add__", (PyCFunction) _wrap_Dn___add__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"Dn_swigregister", Dn_swigregister, METH_VARARGS, NULL}, { (char *)"Dn_swiginit", Dn_swiginit, METH_VARARGS, NULL}, - { (char *)"ldb_msg_element_compare", (PyCFunction) _wrap_ldb_msg_element_compare, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"MessageElement___cmp__", (PyCFunction) _wrap_MessageElement___cmp__, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"MessageElement___iter__", (PyCFunction)_wrap_MessageElement___iter__, METH_O, NULL}, { (char *)"MessageElement___set__", (PyCFunction)_wrap_MessageElement___set__, METH_O, NULL}, { (char *)"new_MessageElement", (PyCFunction) _wrap_new_MessageElement, METH_VARARGS | METH_KEYWORDS, (char *)"Message element."}, -- cgit From 9c109fb51d9eb9df815ed52e6cd25a91b6eefbe8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 04:23:23 +0200 Subject: Disable building of EJS DCE/RPC support. (This used to be commit c7bc9321b38a360d2e8d5258fadb30790342d032) --- source4/librpc/config.mk | 114 ------------------------------------ source4/librpc/scripts/build_idl.sh | 2 +- 2 files changed, 1 insertion(+), 115 deletions(-) diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index cbb0d19564..c7cbf27667 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -607,120 +607,6 @@ PUBLIC_HEADERS += $(addprefix $(librpcsrcdir)/, rpc/dcerpc.h \ gen_ndr/epmapper.h gen_ndr/ndr_epmapper.h gen_ndr/ndr_epmapper_c.h) -[MODULE::RPC_EJS_ECHO] -INIT_FUNCTION = ejs_init_rpcecho -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_ECHO EJSRPC - -RPC_EJS_ECHO_OBJ_FILES = $(gen_ndrsrcdir)/ndr_echo_ejs.o - -[MODULE::RPC_EJS_MISC] -INIT_FUNCTION = ejs_init_misc -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_MISC EJSRPC - -RPC_EJS_MISC_OBJ_FILES = $(gen_ndrsrcdir)/ndr_misc_ejs.o - -[MODULE::RPC_EJS_SAMR] -INIT_FUNCTION = ejs_init_samr -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_SAMR EJSRPC RPC_EJS_LSA RPC_EJS_SECURITY RPC_EJS_MISC - -RPC_EJS_SAMR_OBJ_FILES = $(gen_ndrsrcdir)/ndr_samr_ejs.o - -[MODULE::RPC_EJS_SECURITY] -INIT_FUNCTION = ejs_init_security -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_SECURITY EJSRPC - -RPC_EJS_SECURITY_OBJ_FILES = $(gen_ndrsrcdir)/ndr_security_ejs.o - -[MODULE::RPC_EJS_LSA] -INIT_FUNCTION = ejs_init_lsarpc -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_LSA EJSRPC RPC_EJS_SECURITY RPC_EJS_MISC - -RPC_EJS_LSA_OBJ_FILES = $(gen_ndrsrcdir)/ndr_lsa_ejs.o - -[MODULE::RPC_EJS_DFS] -INIT_FUNCTION = ejs_init_netdfs -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_DFS EJSRPC - -RPC_EJS_DFS_OBJ_FILES = $(gen_ndrsrcdir)/ndr_dfs_ejs.o - -[MODULE::RPC_EJS_DRSUAPI] -INIT_FUNCTION = ejs_init_drsuapi -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_DRSUAPI EJSRPC RPC_EJS_MISC RPC_EJS_SAMR - -RPC_EJS_DRSUAPI_OBJ_FILES = $(gen_ndrsrcdir)/ndr_drsuapi_ejs.o - -[MODULE::RPC_EJS_SPOOLSS] -INIT_FUNCTION = ejs_init_spoolss -SUBSYSTEM = smbcalls -ENABLE = NO -PRIVATE_DEPENDENCIES = dcerpc NDR_SPOOLSS EJSRPC - -RPC_EJS_SPOOLSS_OBJ_FILES = $(gen_ndrsrcdir)/ndr_spoolss_ejs.o - -[MODULE::RPC_EJS_WKSSVC] -INIT_FUNCTION = ejs_init_wkssvc -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_WKSSVC EJSRPC RPC_EJS_SRVSVC RPC_EJS_MISC - -RPC_EJS_WKSSVC_OBJ_FILES = $(gen_ndrsrcdir)/ndr_wkssvc_ejs.o - -[MODULE::RPC_EJS_SRVSVC] -INIT_FUNCTION = ejs_init_srvsvc -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_SRVSVC EJSRPC RPC_EJS_MISC RPC_EJS_SVCCTL RPC_EJS_SECURITY - -RPC_EJS_SRVSVC_OBJ_FILES = $(gen_ndrsrcdir)/ndr_srvsvc_ejs.o - -[MODULE::RPC_EJS_EVENTLOG] -INIT_FUNCTION = ejs_init_eventlog -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_EVENTLOG EJSRPC RPC_EJS_MISC - -RPC_EJS_EVENTLOG_OBJ_FILES = $(gen_ndrsrcdir)/ndr_eventlog_ejs.o - -[MODULE::RPC_EJS_WINREG] -INIT_FUNCTION = ejs_init_winreg -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_WINREG EJSRPC RPC_EJS_INITSHUTDOWN \ - RPC_EJS_MISC RPC_EJS_SECURITY - -RPC_EJS_WINREG_OBJ_FILES = $(gen_ndrsrcdir)/ndr_winreg_ejs.o - -[MODULE::RPC_EJS_INITSHUTDOWN] -INIT_FUNCTION = ejs_init_initshutdown -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_INITSHUTDOWN EJSRPC - -RPC_EJS_INITSHUTDOWN_OBJ_FILES = $(gen_ndrsrcdir)/ndr_initshutdown_ejs.o - -[MODULE::RPC_EJS_NETLOGON] -INIT_FUNCTION = ejs_init_netlogon -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_NETLOGON EJSRPC RPC_EJS_SAMR RPC_EJS_SECURITY RPC_EJS_MISC - -RPC_EJS_NETLOGON_OBJ_FILES = $(gen_ndrsrcdir)/ndr_netlogon_ejs.o - -[MODULE::RPC_EJS_SVCCTL] -INIT_FUNCTION = ejs_init_svcctl -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_SVCCTL EJSRPC RPC_EJS_MISC - -RPC_EJS_SVCCTL_OBJ_FILES = $(gen_ndrsrcdir)/ndr_svcctl_ejs.o - -[MODULE::RPC_EJS_IRPC] -INIT_FUNCTION = ejs_init_irpc -SUBSYSTEM = smbcalls -PRIVATE_DEPENDENCIES = dcerpc NDR_IRPC EJSRPC - -RPC_EJS_IRPC_OBJ_FILES = $(gen_ndrsrcdir)/ndr_irpc_ejs.o - [PYTHON::swig_dcerpc] LIBRARY_REALNAME = samba/dcerpc/_dcerpc.$(SHLIBEXT) PUBLIC_DEPENDENCIES = LIBCLI_SMB NDR_MISC LIBSAMBA-UTIL LIBSAMBA-HOSTCONFIG dcerpc_samr RPC_NDR_LSA DYNCONFIG diff --git a/source4/librpc/scripts/build_idl.sh b/source4/librpc/scripts/build_idl.sh index 5796f40c61..3f13b64a2e 100755 --- a/source4/librpc/scripts/build_idl.sh +++ b/source4/librpc/scripts/build_idl.sh @@ -8,7 +8,7 @@ PIDL_EXTRA_ARGS="$*" [ -d $OUTDIR ] || mkdir -p $OUTDIR || exit 1 -PIDL="$PIDL --outputdir $OUTDIR --header --ndr-parser --server --client --swig --ejs --python $PIDL_EXTRA_ARGS" +PIDL="$PIDL --outputdir $OUTDIR --header --ndr-parser --server --client --swig --python $PIDL_EXTRA_ARGS" if [ x$FULLBUILD = xFULL ]; then echo Rebuilding all idl files in $IDLDIR -- cgit From 27005cb7a2182c50c8bf9e683de1bea2613a3078 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 05:13:31 +0200 Subject: Convert samr test to python. (This used to be commit 88d473b202e82b462ef82ffdeb4f1710918ffda5) --- source4/scripting/bin/samr.py | 114 +++++++++++++++++++ source4/scripting/python/samba/tests/dcerpc/sam.py | 2 + source4/selftest/samba4_tests.sh | 2 +- testprogs/ejs/samr.js | 126 --------------------- 4 files changed, 117 insertions(+), 127 deletions(-) create mode 100755 source4/scripting/bin/samr.py delete mode 100755 testprogs/ejs/samr.js diff --git a/source4/scripting/bin/samr.py b/source4/scripting/bin/samr.py new file mode 100755 index 0000000000..118cf759fe --- /dev/null +++ b/source4/scripting/bin/samr.py @@ -0,0 +1,114 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# Based on samr.js © Andrew Tridgell +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import sys + +sys.path.insert(0, "bin/python") + +from samba.dcerpc import samr, security + +def FillUserInfo(samr, dom_handle, users, level): + """fill a user array with user information from samrQueryUserInfo""" + for i in range(len(users)): + user_handle = samr.OpenUser(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, users[i].idx) + info = samr.QueryUserInfo(user_handle, level) + info.name = users[i].name + info.idx = users[i].idx + users[i] = info + samr.Close(user_handle) + +def toArray((handle, array, num_entries)): + ret = [] + for x in range(num_entries): + ret.append((array.entries[x].idx, array.entries[x].name)) + return ret + + +def test_Connect(samr): + """test the samr_Connect interface""" + print "Testing samr_Connect" + return samr.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) + +def test_LookupDomain(samr, handle, domain): + """test the samr_LookupDomain interface""" + print "Testing samr_LookupDomain" + return samr.LookupDomain(handle, domain) + +def test_OpenDomain(samr, handle, sid): + """test the samr_OpenDomain interface""" + print "Testing samr_OpenDomain" + return samr.OpenDomain(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, sid) + +def test_EnumDomainUsers(samr, dom_handle): + """test the samr_EnumDomainUsers interface""" + print "Testing samr_EnumDomainUsers" + users = toArray(samr.EnumDomainUsers(dom_handle, 0, 0, -1)) + print "Found %d users" % len(users) + for idx, user in users: + print "\t%s\t(%d)" % (user, idx) + +def test_EnumDomainGroups(samr, dom_handle): + """test the samr_EnumDomainGroups interface""" + print "Testing samr_EnumDomainGroups" + groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0, -1)) + print "Found %d groups" % len(groups) + for idx, group in groups: + print "\t" + group + "\t(" + idx + ")" + +def test_domain_ops(samr, dom_handle): + """test domain specific ops""" + test_EnumDomainUsers(samr, dom_handle) + test_EnumDomainGroups(samr, dom_handle) + +def test_EnumDomains(samr, handle): + """test the samr_EnumDomains interface""" + print "Testing samr_EnumDomains" + + domains = toArray(samr.EnumDomains(handle, 0, -1)) + print "Found %d domains" % len(domains) + for idx, domain in domains: + print "\t%s (%d)" % (domain, idx) + for idx, domain in domains: + print "Testing domain %s" % domain + sid = samr.LookupDomain(handle, domain) + dom_handle = test_OpenDomain(samr, handle, sid) + test_domain_ops(samr, dom_handle) + samr.Close(dom_handle) + +if len(sys.argv) != 2: + print "Usage: samr.js " + sys.exit(1) + +binding = sys.argv[1] + +print "Connecting to " + binding +try: + samr = samr.samr(binding) +except Exception, e: + print "Failed to connect to %s: %s" % (binding, e.message) + sys.exit(1) + +handle = test_Connect(samr) +test_EnumDomains(samr, handle) +samr.Close(handle) + +print "All OK" diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py index a6816153c0..81300c9e81 100644 --- a/source4/scripting/python/samba/tests/dcerpc/sam.py +++ b/source4/scripting/python/samba/tests/dcerpc/sam.py @@ -26,3 +26,5 @@ class SamrTests(RpcInterfaceTestCase): def test_connect5(self): (level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1()) + + diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index 2f65561ceb..9efd235ac4 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -64,7 +64,7 @@ SCRIPTDIR=$samba4srcdir/../testprogs/ejs smb4torture="$samba4bindir/smbtorture $TORTURE_OPTIONS" plantest "js.base" dc "$SCRIPTDIR/base.js" $CONFIGURATION -plantest "js.samr" dc "$SCRIPTDIR/samr.js" $CONFIGURATION ncalrpc: -U\$USERNAME%\$PASSWORD +plantest "samr.python" dc "$samba4bindir/../scripting/bin/samr.py" ncalrpc: plantest "js.echo" dc "$SCRIPTDIR/echo.js" $CONFIGURATION ncalrpc: -U\$USERNAME%\$PASSWORD #plantest "ejsnet.js" dc "$SCRIPTDIR/ejsnet.js" $CONFIGURATION -U\$USERNAME%\$PASSWORD \$DOMAIN ejstestuser plantest "js.ldb" none "$SCRIPTDIR/ldb.js" `pwd` $CONFIGURATION -d 10 diff --git a/testprogs/ejs/samr.js b/testprogs/ejs/samr.js deleted file mode 100755 index fbdae974be..0000000000 --- a/testprogs/ejs/samr.js +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env smbscript -/* - test samr calls from ejs -*/ - -var options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS"); -if (options == undefined) { - println("Failed to parse options"); - return -1; -} - -libinclude("base.js"); -libinclude("samr.js"); - - -/* - test the samr_Connect interface -*/ -function test_Connect(samr) -{ - print("Testing samr_Connect\n"); - return samrConnect(samr); -} - - -/* - test the samr_LookupDomain interface -*/ -function test_LookupDomain(samr, handle, domain) -{ - print("Testing samr_LookupDomain\n"); - return samrLookupDomain(samr, handle, domain); -} - -/* - test the samr_OpenDomain interface -*/ -function test_OpenDomain(samr, handle, sid) -{ - print("Testing samr_OpenDomain\n"); - return samrOpenDomain(samr, handle, sid); -} - -/* - test the samr_EnumDomainUsers interface -*/ -function test_EnumDomainUsers(samr, dom_handle) -{ - var i, users; - print("Testing samr_EnumDomainUsers\n"); - users = samrEnumDomainUsers(samr, dom_handle); - print("Found " + users.length + " users\n"); - for (i=0;i"); - return -1; -} -var binding = options.ARGV[0]; -var samr = samr_init(); - -print("Connecting to " + binding + "\n"); -status = samr.connect(binding); -if (status.is_ok != true) { - print("Failed to connect to " + binding + " - " + status.errstr + "\n"); - return -1; -} - -handle = test_Connect(samr); -test_EnumDomains(samr, handle); -samrClose(samr, handle); - -print("All OK\n"); -return 0; -- cgit From fb7e359561b77444feae0c71b034c7cac1820694 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 05:23:50 +0200 Subject: Remove unused echo ejs script. (This used to be commit 3a6b009d505503b2eb22acadeaac485151ed0173) --- source4/selftest/samba4_tests.sh | 1 - testprogs/ejs/echo.js | 235 --------------------------------------- 2 files changed, 236 deletions(-) delete mode 100755 testprogs/ejs/echo.js diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index 9efd235ac4..36cf2adccb 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -65,7 +65,6 @@ smb4torture="$samba4bindir/smbtorture $TORTURE_OPTIONS" plantest "js.base" dc "$SCRIPTDIR/base.js" $CONFIGURATION plantest "samr.python" dc "$samba4bindir/../scripting/bin/samr.py" ncalrpc: -plantest "js.echo" dc "$SCRIPTDIR/echo.js" $CONFIGURATION ncalrpc: -U\$USERNAME%\$PASSWORD #plantest "ejsnet.js" dc "$SCRIPTDIR/ejsnet.js" $CONFIGURATION -U\$USERNAME%\$PASSWORD \$DOMAIN ejstestuser plantest "js.ldb" none "$SCRIPTDIR/ldb.js" `pwd` $CONFIGURATION -d 10 plantest "js.winreg" dc $samba4srcdir/scripting/bin/winreg $CONFIGURATION ncalrpc: 'HKLM' -U\$USERNAME%\$PASSWORD diff --git a/testprogs/ejs/echo.js b/testprogs/ejs/echo.js deleted file mode 100755 index 3750baf0fb..0000000000 --- a/testprogs/ejs/echo.js +++ /dev/null @@ -1,235 +0,0 @@ -#!/usr/bin/env smbscript -/* - test echo pipe calls from ejs -*/ - -var options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS"); -if (options == undefined) { - println("Failed to parse options"); - return -1; -} - -libinclude("base.js"); - -/* - generate a ramp as an integer array - */ -function ramp_array(N) -{ - var a = new Array(N); - var data = datablob_init(); - for (i=0;i"); - return -1; -} -var binding = options.ARGV[0]; -var echo = rpcecho_init(); -datablob_init(echo); - -print("Connecting to " + binding + "\n"); -status = echo.connect(binding); -if (status.is_ok != true) { - printf("Failed to connect to %s - %s\n", binding, status.errstr); - return; -} - -test_AddOne(echo); -test_EchoData(echo); -test_SinkData(echo); -test_SourceData(echo); - -print("SKIPPING test_TestCall as pidl cannot generate code for it\n"); -/* test_TestCall(echo); */ -test_TestCall2(echo); -test_TestSleep(echo); -test_TestEnum(echo); -test_TestSurrounding(echo); -test_TestDoublePointer(echo); - -println("All OK\n"); -return 0; -- cgit From 5a5605afcdf94975d9acb9435034e91162a7d23e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 05:24:59 +0200 Subject: Remove unused ejs library functions. (This used to be commit 57eec87b19428fd763033988d0ba671524d90c69) --- source4/scripting/libjs/samr.js | 170 ---------------------- source4/scripting/libjs/winreg.js | 291 -------------------------------------- 2 files changed, 461 deletions(-) delete mode 100644 source4/scripting/libjs/samr.js delete mode 100644 source4/scripting/libjs/winreg.js diff --git a/source4/scripting/libjs/samr.js b/source4/scripting/libjs/samr.js deleted file mode 100644 index 6e8c70af3c..0000000000 --- a/source4/scripting/libjs/samr.js +++ /dev/null @@ -1,170 +0,0 @@ -/* - samr rpc utility functions - Copyright Andrew Tridgell 2005 - released under the GNU GPL version 3 or later -*/ - -if (global["HAVE_SAMR_JS"] != undefined) { - return; -} -HAVE_SAMR_JS=1 - -/* - return a list of names and indexes from a samArray -*/ -function samArray(output) -{ - var list = new Array(output.num_entries); - if (output.sam == NULL) { - return list; - } - var i, entries = output.sam.entries; - for (i=0;i= 0;idx++) { - io.input.enum_index = idx; - var status = this.winreg_EnumKey(io); - if (!status.is_ok) { - this.close(handle); - return list; - } - var out = io.output; - if (out.result == "WERR_MORE_DATA") { - io.input.name.size = io.input.name.size * 2; - idx--; - if (io.input.name.size > 32000) { - this.close(handle); - return list; - } - continue; - } - if (out.result != "WERR_OK") { - this.close(handle); - return list; - } - list[list.length] = out.name.name; - } - - this.close(handle); - return list; -} - - -/* - return a list of values for a winreg server given a path - usage: - list = reg.enum_values(path); - - each returned list element is an object containing a name, a - type and a value -*/ -function __winreg_enum_values(path) -{ - var data = datablob_init(); - var list = new Array(0); - - var handle = this.open_path(path); - if (handle == undefined) { - return undefined; - } - - var io = irpcObj(); - io.input.handle = handle; - io.input.name = new Object(); - io.input.name.length = 0; - io.input.name.size = 128; - io.input.name.name = ""; - io.input.type = 0; - io.input.value = new Array(0); - io.input.size = 1024; - io.input.length = 0; - - var idx; - for (idx=0;idx >= 0;idx++) { - io.input.enum_index = idx; - var status = this.winreg_EnumValue(io); - if (!status.is_ok) { - this.close(handle); - return list; - } - var out = io.output; - if (out.result == "WERR_MORE_DATA") { - io.input.size = io.input.size * 2; - io.input.name.size = io.input.name.size * 2; - idx--; - /* limit blobs to 1M */ - if (io.input.size > 1000000) { - this.close(handle); - return list; - } - continue; - } - if (out.result != "WERR_OK") { - this.close(handle); - return list; - } - var el = new Object(); - el.name = out.name.name; - el.type = out.type; - el.rawvalue = out.value; - el.value = data.regToVar(el.rawvalue, el.type); - el.size = out.size; - list[list.length] = el; - } - - this.close(handle); - return list; -} - - -/* - create a new key - ok = reg.create_key(path, key); -*/ -function __winreg_create_key(path, key) -{ - var handle = this.open_path(path); - if (handle == undefined) { - return undefined; - } - - var io = irpcObj(); - io.input.handle = handle; - io.input.name = key; - io.input.keyclass = NULL; - io.input.options = 0; - io.input.access_mask = this.SEC_FLAG_MAXIMUM_ALLOWED; - io.input.secdesc = NULL; - io.input.action_taken = 0; - - var status = this.winreg_CreateKey(io); - this.close(handle); - if (!status.is_ok) { - return false; - } - if (io.output.result != "WERR_OK") { - return false; - } - this.close(io.output.new_handle); - return true; -} - - -/* - return a string for a winreg type -*/ -function __winreg_typestring(type) -{ - return this.typenames[type]; -} - -/* - initialise the winreg lib, returning an object -*/ -function winregObj() -{ - var reg = winreg_init(); - security_init(reg); - - reg.typenames = new Array("REG_NONE", "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", - "REG_DWORD", "REG_DWORD_BIG_ENDIAN", "REG_LINK", "REG_MULTI_SZ", - "REG_RESOURCE_LIST", "REG_FULL_RESOURCE_DESCRIPTOR", - "REG_RESOURCE_REQUIREMENTS_LIST", "REG_QWORD"); - - reg.close = __winreg_close; - reg.open_hive = __winreg_open_hive; - reg.open_path = __winreg_open_path; - reg.enum_path = __winreg_enum_path; - reg.enum_values = __winreg_enum_values; - reg.create_key = __winreg_create_key; - reg.typestring = __winreg_typestring; - - return reg; -} -- cgit From 6ccb9785e7e1b2374a0121b5c70a2969b120a926 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 12:21:26 +0200 Subject: Add another test toe the python samr testsuite. (This used to be commit 480884c696c676bb978e9197271b99cc03bb66e6) --- source4/scripting/python/samba/tests/dcerpc/sam.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py index 81300c9e81..e685f9b4f4 100644 --- a/source4/scripting/python/samba/tests/dcerpc/sam.py +++ b/source4/scripting/python/samba/tests/dcerpc/sam.py @@ -1,7 +1,8 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- # Unix SMB/CIFS implementation. -# Copyright (C) Jelmer Vernooij 2008 +# Copyright © Jelmer Vernooij 2008 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,9 +18,17 @@ # along with this program. If not, see . # -from samba.dcerpc import samr +from samba.dcerpc import samr, security from samba.tests import RpcInterfaceTestCase +# FIXME: Pidl should be doing this for us +def toArray((handle, array, num_entries)): + ret = [] + for x in range(num_entries): + ret.append((array.entries[x].idx, array.entries[x].name)) + return ret + + class SamrTests(RpcInterfaceTestCase): def setUp(self): self.conn = samr.samr("ncalrpc:", self.get_loadparm()) @@ -27,4 +36,11 @@ class SamrTests(RpcInterfaceTestCase): def test_connect5(self): (level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1()) + def test_connect2(self): + (level, info, handle) = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) + + def test_EnumDomains(self): + handle = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) + domains = toArray(self.conn.EnumDomains(handle, 0, -1)) + self.conn.Close(handle) -- cgit From a9c96b2e7b9d7d894b194d520e4925e772ca0247 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 22 May 2008 13:00:04 +0200 Subject: Fix indentation. (This used to be commit 5c3d4fce06ae07663632cc50d9703ddbc728c737) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 884ee1d822..88f2daa3b8 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -203,7 +203,7 @@ sub PythonStruct($$$$$$) $self->pidl("return 0;"); $self->deindent; $self->pidl("}"); - $self->pidl(""); + $self->pidl(""); } $getsetters = "py_$name\_getsetters"; @@ -253,6 +253,20 @@ sub PythonStruct($$$$$$) return "&$typeobject"; } +sub get_metadata_var($) +{ + my ($e) = @_; + sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; } + + if (has_property($e, "length_is")) { + return get_var($e->{PROPERTIES}->{length_is}); + } elsif (has_property($e, "size_is")) { + return get_var($e->{PROPERTIES}->{size_is}); + } + + return undef; +} + sub PythonFunctionBody($$$) { my ($self, $fn, $iface, $prettyname) = @_; @@ -274,17 +288,10 @@ sub PythonFunctionBody($$$) my $metadata_args = { in => {}, out => {} }; - sub get_var($) { my $x = shift; $x =~ s/\*//g; return $x; } - # Determine arguments that are metadata for other arguments (size_is/length_is) foreach my $e (@{$fn->{ELEMENTS}}) { foreach my $dir (@{$e->{DIRECTION}}) { - my $main = undef; - if (has_property($e, "length_is")) { - $main = get_var($e->{PROPERTIES}->{length_is}); - } elsif (has_property($e, "size_is")) { - $main = get_var($e->{PROPERTIES}->{size_is}); - } + my $main = get_metadata_var($e); if ($main) { $metadata_args->{$dir}->{$main} = $e->{NAME}; } -- cgit From 4b701a265fa99f5490382168d369e8a9d994ed35 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 04:31:10 +0200 Subject: Fix imports for provision-backend. This needs a blackbox test... (This used to be commit 268c1de095411991ffb22ee835bfb88f8bce235a) --- source4/setup/provision-backend | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source4/setup/provision-backend b/source4/setup/provision-backend index 4f222c467a..54dc5839bf 100755 --- a/source4/setup/provision-backend +++ b/source4/setup/provision-backend @@ -22,14 +22,17 @@ # along with this program. If not, see . # +import os, sys + +sys.path.insert(0, "bin/python") + import getopt import optparse -import os, sys import samba -import param +from samba import param -from auth import system_session +from samba.auth import system_session import samba.getopt as options from samba.provision import (provision_backend) -- cgit From c78bf3c2c925060df3362625bbd1c3e96751c087 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 23 May 2008 09:45:46 +0200 Subject: pvfs_streams: directories don't have streams metze (This used to be commit 9ed7bb5afe6a73206bcba85f25305eb6630a5571) --- source4/ntvfs/posix/pvfs_streams.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source4/ntvfs/posix/pvfs_streams.c b/source4/ntvfs/posix/pvfs_streams.c index 7e6173ef2f..3cd9952fd5 100644 --- a/source4/ntvfs/posix/pvfs_streams.c +++ b/source4/ntvfs/posix/pvfs_streams.c @@ -36,6 +36,13 @@ NTSTATUS pvfs_stream_information(struct pvfs_state *pvfs, int i; NTSTATUS status; + /* directories don't have streams */ + if (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) { + info->num_streams = 0; + info->streams = NULL; + return NT_STATUS_OK; + } + streams = talloc(mem_ctx, struct xattr_DosStreams); if (streams == NULL) { return NT_STATUS_NO_MEMORY; -- cgit From 391b746430ad3d0b371930933e0a77e6a70a9ac0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 23 May 2008 09:46:50 +0200 Subject: pvfs_resolve: stream_name = "" is only the same as NULL for files metze (This used to be commit 47756129fdf01075bac06cdd24107d7dc8ba34af) --- source4/ntvfs/posix/pvfs_fileinfo.c | 2 ++ source4/ntvfs/posix/pvfs_resolve.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source4/ntvfs/posix/pvfs_fileinfo.c b/source4/ntvfs/posix/pvfs_fileinfo.c index e35f42e955..04f6ad78d0 100644 --- a/source4/ntvfs/posix/pvfs_fileinfo.c +++ b/source4/ntvfs/posix/pvfs_fileinfo.c @@ -58,6 +58,8 @@ NTSTATUS pvfs_fill_dos_info(struct pvfs_state *pvfs, struct pvfs_filename *name, if (S_ISDIR(name->st.st_mode)) { name->st.st_size = 0; name->st.st_nlink = 1; + } else if (name->stream_id == 0) { + name->stream_name = NULL; } /* for now just use the simple samba mapping */ diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c index 325bc74f8f..2e97925c49 100644 --- a/source4/ntvfs/posix/pvfs_resolve.c +++ b/source4/ntvfs/posix/pvfs_resolve.c @@ -202,7 +202,13 @@ static NTSTATUS parse_stream_name(struct pvfs_filename *name, const char *s) } *p = 0; if (strcmp(name->stream_name, "") == 0) { - name->stream_name = NULL; + /* + * we don't set stream_name to NULL, here + * as this would be wrong for directories + * + * pvfs_fill_dos_info() will set it to NULL + * if it's not a directory. + */ name->stream_id = 0; } else { name->stream_id = pvfs_name_hash(name->stream_name, -- cgit From 5d648b4aa5540e91fa7ea77668965eefd8926b1a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 23 May 2008 09:47:59 +0200 Subject: pvfs_open: return FILE_IS_A_DIRECTORY when opening a stream on a directory metze (This used to be commit 1421b1cc0c442be839be702647009ed5295f34a3) --- source4/ntvfs/posix/pvfs_open.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index cc4f0add27..926c99d37e 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -182,12 +182,19 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs, bool del_on_close; uint32_t create_options; uint32_t share_access; + bool forced; create_options = io->generic.in.create_options; share_access = io->generic.in.share_access; + forced = (io->generic.in.create_options & NTCREATEX_OPTIONS_DIRECTORY)?true:false; + if (name->stream_name) { - return NT_STATUS_NOT_A_DIRECTORY; + if (forced) { + return NT_STATUS_NOT_A_DIRECTORY; + } else { + return NT_STATUS_FILE_IS_A_DIRECTORY; + } } /* if the client says it must be a directory, and it isn't, -- cgit From 2f653e814a593e4581f28f8ed8158a84a591e9b4 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 23 May 2008 09:39:50 +0200 Subject: RAW-STREAMS: better test the bahavior of streams on directories Note: this has a samba3 specific code path, which we should fixed. metze (This used to be commit 5c5c86683877337ff60526a40e7b689f604e40f8) --- source4/torture/raw/streams.c | 95 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 10 deletions(-) diff --git a/source4/torture/raw/streams.c b/source4/torture/raw/streams.c index 1dab36c28b..8b2d327653 100644 --- a/source4/torture/raw/streams.c +++ b/source4/torture/raw/streams.c @@ -135,6 +135,11 @@ static bool check_stream_list(struct smbcli_state *cli, const char *fname, goto fail; } + if (num_exp == 0) { + ret = true; + goto fail; + } + exp_sort = talloc_memdup(tmp_ctx, exp, num_exp * sizeof(*exp)); if (exp_sort == NULL) { @@ -170,7 +175,81 @@ static bool check_stream_list(struct smbcli_state *cli, const char *fname, } /* - test basic io on streams + test bahavior of streams on directories +*/ +static bool test_stream_dir(struct torture_context *tctx, + struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +{ + NTSTATUS status; + union smb_open io; + const char *fname = BASEDIR "\\stream.txt"; + const char *sname1; + bool ret = true; + const char *basedir_data; + + basedir_data = talloc_asprintf(mem_ctx, "%s::$DATA", BASEDIR); + sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One"); + + printf("(%s) opening non-existant directory stream\n", __location__); + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA; + io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io.ntcreatex.in.share_access = 0; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = sname1; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY); + + printf("(%s) opening basedir stream\n", __location__); + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA; + io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; + io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY; + io.ntcreatex.in.share_access = 0; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = basedir_data; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY); + + printf("(%s) opening basedir ::$DATA stream\n", __location__); + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0x10; + io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.file_attr = 0; + io.ntcreatex.in.share_access = 0; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = basedir_data; + status = smb_raw_open(cli->tree, mem_ctx, &io); + if (torture_setting_bool(tctx, "samba3", false)) { + CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); + } else { + CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY); + } + + printf("(%s) list the streams on the basedir\n", __location__); + ret &= check_stream_list(cli, BASEDIR, 0, NULL); +done: + return ret; +} + +/* + test basic behavior of streams on directories */ static bool test_stream_io(struct torture_context *tctx, struct smbcli_state *cli, TALLOC_CTX *mem_ctx) @@ -191,12 +270,12 @@ static bool test_stream_io(struct torture_context *tctx, sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One"); sname2 = talloc_asprintf(mem_ctx, "%s:%s:$DaTa", fname, "Second Stream"); - printf("(%s) opening non-existant directory stream\n", __location__); + printf("(%s) creating a stream on a non-existant file\n", __location__); io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.root_fid = 0; io.ntcreatex.in.flags = 0; io.ntcreatex.in.access_mask = SEC_FILE_WRITE_DATA; - io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; + io.ntcreatex.in.create_options = 0; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; io.ntcreatex.in.share_access = 0; io.ntcreatex.in.alloc_size = 0; @@ -205,12 +284,6 @@ static bool test_stream_io(struct torture_context *tctx, io.ntcreatex.in.security_flags = 0; io.ntcreatex.in.fname = sname1; status = smb_raw_open(cli->tree, mem_ctx, &io); - CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY); - - printf("(%s) creating a stream on a non-existant file\n", __location__); - io.ntcreatex.in.create_options = 0; - io.ntcreatex.in.fname = sname1; - status = smb_raw_open(cli->tree, mem_ctx, &io); CHECK_STATUS(status, NT_STATUS_OK); fnum = io.ntcreatex.out.file.fnum; @@ -423,7 +496,7 @@ static bool test_stream_delete(struct torture_context *tctx, sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One"); - printf("(%s) opening non-existant directory stream\n", __location__); + printf("(%s) opening non-existant file stream\n", __location__); io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.root_fid = 0; io.ntcreatex.in.flags = 0; @@ -559,6 +632,8 @@ bool torture_raw_streams(struct torture_context *torture, return false; } + ret &= test_stream_dir(torture, cli, torture); + smb_raw_exit(cli->session); ret &= test_stream_io(torture, cli, torture); smb_raw_exit(cli->session); ret &= test_stream_sharemodes(torture, cli, torture); -- cgit From d9109c5342b19ec2cf811f9a61e9e2167e7ca3e4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 12:40:45 +0200 Subject: Self PYTHONPATH from selftest. (This used to be commit f7e350368b40f575b312d4e0045981d9b1dcadfe) --- source4/selftest/selftest.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl index 385d31bbfd..3270364a91 100755 --- a/source4/selftest/selftest.pl +++ b/source4/selftest/selftest.pl @@ -414,6 +414,7 @@ if (defined($ENV{PKG_CONFIG_PATH})) { } # Required for smbscript: $ENV{PATH} = "$old_pwd/bin:$old_pwd:$ENV{PATH}"; +$ENV{PYTHONPATH} = "$builddir/bin/python:$ENV{PYTHONPATH}"; if ($opt_socket_wrapper_keep_pcap) { # Socket wrapper keep pcap implies socket wrapper pcap -- cgit From 97cac27b334350f4452a7fe60658f533d851bbb9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 12:45:05 +0200 Subject: Fix syntax for return type in DCE/RPC interface python bindings. (This used to be commit 40652801fce937b37a43d37db9892821572cd6fd) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 88f2daa3b8..440b1bff97 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -658,7 +658,7 @@ sub Interface($$$) $self->pidl(""); my $signature = -"\"$interface->{NAME}(binding, lp_ctx=None, credentials=None) -> Connection to DCE/RPC interface.\\n\" +"\"$interface->{NAME}(binding, lp_ctx=None, credentials=None) -> connection\\n\" \"\\n\" \"binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\\n\" \"lp_ctx should be a path to a smb.conf file or a param.LoadParm object\\n\" -- cgit From 9adcd8c25e7e51ac7e4767763750c67e334bcdbb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 13:13:36 +0200 Subject: UFollow conventions for __repr__ contents for talloc python wrapper. (This used to be commit f2d437d646d0694498c14bc951f9745c4ecd902d) --- source4/scripting/python/pytalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c index aa0ae9bf90..d669eb0f24 100644 --- a/source4/scripting/python/pytalloc.c +++ b/source4/scripting/python/pytalloc.c @@ -41,5 +41,5 @@ 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("<%s>", type->tp_name); + return PyString_FromFormat("<%s talloc object at 0x%x>", type->tp_name, (intptr_t)py_obj); } -- cgit From dff31b1dc0ec1aea8cec9d5764f4f3a4c109a848 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 15:09:51 +0200 Subject: Create new context in pytalloc to avoid problems with talloc_free() freeing the wrong parent of a pointer. (This used to be commit 3f628f4dc9a57326442ebe2d2eaac9d279043aa6) --- source4/scripting/python/pytalloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c index d669eb0f24..ca476e9604 100644 --- a/source4/scripting/python/pytalloc.c +++ b/source4/scripting/python/pytalloc.c @@ -24,6 +24,7 @@ void py_talloc_dealloc(PyObject* self) { py_talloc_Object *obj = (py_talloc_Object *)self; talloc_free(obj->talloc_ctx); + obj->talloc_ctx = NULL; PyObject_Del(self); } @@ -31,7 +32,13 @@ PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr) { py_talloc_Object *ret = PyObject_New(py_talloc_Object, py_type); - ret->talloc_ctx = talloc_reference(NULL, mem_ctx); + ret->talloc_ctx = talloc_new(NULL); + if (ret->talloc_ctx == NULL) { + return NULL; + } + if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) { + return NULL; + } ret->ptr = ptr; return (PyObject *)ret; } -- cgit From 5eed56d0ad5245a346ea564bc34e882828394611 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 15:10:35 +0200 Subject: Fix bugs in samr python tests. (This used to be commit 09c6b106ac144820b8c072bda4dad3d8e2145ff0) --- source4/scripting/bin/samr.py | 6 +++--- source4/scripting/python/samba/tests/dcerpc/sam.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source4/scripting/bin/samr.py b/source4/scripting/bin/samr.py index 118cf759fe..e91b5bc312 100755 --- a/source4/scripting/bin/samr.py +++ b/source4/scripting/bin/samr.py @@ -24,7 +24,7 @@ import sys sys.path.insert(0, "bin/python") -from samba.dcerpc import samr, security +from samba.dcerpc import samr, security, lsa def FillUserInfo(samr, dom_handle, users, level): """fill a user array with user information from samrQueryUserInfo""" @@ -69,10 +69,10 @@ def test_EnumDomainUsers(samr, dom_handle): def test_EnumDomainGroups(samr, dom_handle): """test the samr_EnumDomainGroups interface""" print "Testing samr_EnumDomainGroups" - groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0, -1)) + groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0)) print "Found %d groups" % len(groups) for idx, group in groups: - print "\t" + group + "\t(" + idx + ")" + print "\t%s\t(%d)" % (group, idx) def test_domain_ops(samr, dom_handle): """test domain specific ops""" diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py index e685f9b4f4..50e00a3f9e 100644 --- a/source4/scripting/python/samba/tests/dcerpc/sam.py +++ b/source4/scripting/python/samba/tests/dcerpc/sam.py @@ -37,7 +37,7 @@ class SamrTests(RpcInterfaceTestCase): (level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1()) def test_connect2(self): - (level, info, handle) = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) + handle = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) def test_EnumDomains(self): handle = self.conn.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) -- cgit From 0b62a0875f01370f9db10c45253966f4fed74272 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 15:20:32 +0200 Subject: selftest: Use convenience function for prepending paths to environment variables. (This used to be commit f71cb65a9057fb426748dd5fe45cf2962da42ae4) --- source4/selftest/selftest.pl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl index 3270364a91..5854a94b8d 100755 --- a/source4/selftest/selftest.pl +++ b/source4/selftest/selftest.pl @@ -407,14 +407,19 @@ my $tls_enabled = not $opt_quick; $ENV{TLS_ENABLED} = ($tls_enabled?"yes":"no"); $ENV{LDB_MODULES_PATH} = "$old_pwd/bin/modules/ldb"; $ENV{LD_SAMBA_MODULE_PATH} = "$old_pwd/bin/modules"; -if (defined($ENV{PKG_CONFIG_PATH})) { - $ENV{PKG_CONFIG_PATH} = "$old_pwd/bin/pkgconfig:$ENV{PKG_CONFIG_PATH}"; -} else { - $ENV{PKG_CONFIG_PATH} = "$old_pwd/bin/pkgconfig"; +sub prefix_pathvar($$) +{ + my ($name, $newpath) = @_; + if (defined($ENV{$name})) { + $ENV{$name} = "$newpath:$ENV{$name}"; + } else { + $ENV{$name} = $newpath; + } } +prefix_pathvar("PKG_CONFIG_PATH", "$old_pwd/bin/pkgconfig"); # Required for smbscript: -$ENV{PATH} = "$old_pwd/bin:$old_pwd:$ENV{PATH}"; -$ENV{PYTHONPATH} = "$builddir/bin/python:$ENV{PYTHONPATH}"; +prefix_pathvar("PATH", "$old_pwd/bin"); +prefix_pathvar("PYTHONPATH", "$old_pwd/bin/python"); if ($opt_socket_wrapper_keep_pcap) { # Socket wrapper keep pcap implies socket wrapper pcap -- cgit From 33231f44da6c4eeb5dbf5e7d6d04237d32a63457 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 16:17:23 +0200 Subject: Report full 'path' of unexpected test results for easier inclusion in knownfailure file. (This used to be commit 33cc9b0f5fae7510d490928195016cf7fe3bbe42) --- source4/selftest/output/plain.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source4/selftest/output/plain.pm b/source4/selftest/output/plain.pm index f14e26b38d..4bec4e0fdc 100644 --- a/source4/selftest/output/plain.pm +++ b/source4/selftest/output/plain.pm @@ -123,7 +123,9 @@ sub end_test($$$$$) return; } - $append = "UNEXPECTED($result): $testname\n"; + my $fullname = join(".", @$parents).".$testname"; + + $append = "UNEXPECTED($result): $testname ($fullname)\n"; $self->{test_output}->{$self->{NAME}} .= $append; -- cgit From a255c9399518419b1028abac09fb9e0c1d572403 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 16:17:58 +0200 Subject: Cope with new event context parameter in API and removed parameters to reg_open_local(). (This used to be commit 0d5752c940360a0ceb5e23cd6f71cbc61271137a) --- source4/lib/registry/tests/diff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source4/lib/registry/tests/diff.c b/source4/lib/registry/tests/diff.c index c7726545f6..44ea090527 100644 --- a/source4/lib/registry/tests/diff.c +++ b/source4/lib/registry/tests/diff.c @@ -165,10 +165,10 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) td = talloc(tctx, struct diff_tcase_data); /* Create two registry contexts */ - error = reg_open_local(tctx, &r1_ctx, NULL, NULL); + error = reg_open_local(tctx, &r1_ctx); torture_assert_werr_ok(tctx, error, "Opening registry 1 for patch tests failed"); - error = reg_open_local(tctx, &r2_ctx, NULL, NULL); + error = reg_open_local(tctx, &r2_ctx); torture_assert_werr_ok(tctx, error, "Opening registry 2 for patch tests failed"); /* Create temp directory */ @@ -177,14 +177,14 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) /* Create and mount HKLM and HKCU hives for registry 1 */ filename = talloc_asprintf(tctx, "%s/r1_local_machine.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hklm); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r1_hklm); torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); error = reg_mount_hive(r1_ctx, r1_hklm, HKEY_LOCAL_MACHINE, NULL); torture_assert_werr_ok(tctx, error, "Mounting hive failed"); filename = talloc_asprintf(tctx, "%s/r1_current_user.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r1_hkcu); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r1_hkcu); torture_assert_werr_ok(tctx, error, "Opening current user file failed"); error = reg_mount_hive(r1_ctx, r1_hkcu, HKEY_CURRENT_USER, NULL); @@ -192,14 +192,14 @@ static bool diff_setup_tcase(struct torture_context *tctx, void **data) /* Create and mount HKLM and HKCU hives for registry 2 */ filename = talloc_asprintf(tctx, "%s/r2_local_machine.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hklm); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r2_hklm); torture_assert_werr_ok(tctx, error, "Opening local machine file failed"); error = reg_mount_hive(r2_ctx, r2_hklm, HKEY_LOCAL_MACHINE, NULL); torture_assert_werr_ok(tctx, error, "Mounting hive failed"); filename = talloc_asprintf(tctx, "%s/r2_current_user.ldb", td->tempdir); - error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->lp_ctx, &r2_hkcu); + error = reg_open_ldb_file(tctx, filename, NULL, NULL, tctx->ev, tctx->lp_ctx, &r2_hkcu); torture_assert_werr_ok(tctx, error, "Opening current user file failed"); error = reg_mount_hive(r2_ctx, r2_hkcu, HKEY_CURRENT_USER, NULL); -- cgit From 72251a1b7a3b999c2588fa64b7c12973bd819c2b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 16:19:00 +0200 Subject: Include test case name when reporting with subunit. This should make it possible to having a test fail against some test cases and success against other ones. (This used to be commit 0af138a85bba21a5009967e2610c898615fb536b) --- source4/torture/smbtorture.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c index 418f933993..44daa89e44 100644 --- a/source4/torture/smbtorture.c +++ b/source4/torture/smbtorture.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. SMB torture tester Copyright (C) Andrew Tridgell 1997-2003 - Copyright (C) Jelmer Vernooij 2006 + Copyright (C) Jelmer Vernooij 2006-2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -375,11 +375,24 @@ static void subunit_suite_start(struct torture_context *ctx, { } +static void subunit_print_testname(struct torture_context *ctx, + struct torture_tcase *tcase, + struct torture_test *test) +{ + if (!strcmp(tcase->name, test->name)) { + printf("%s", test->name); + } else { + printf("%s.%s", tcase->name, test->name); + } +} + static void subunit_test_start(struct torture_context *ctx, struct torture_tcase *tcase, struct torture_test *test) { - printf("test: %s\n", test->name); + printf("test: "); + subunit_print_testname(ctx, tcase, test); + printf("\n"); } static void subunit_test_result(struct torture_context *context, @@ -387,18 +400,20 @@ static void subunit_test_result(struct torture_context *context, { switch (res) { case TORTURE_OK: - printf("success: %s", context->active_test->name); + printf("success: "); break; case TORTURE_FAIL: - printf("failure: %s", context->active_test->name); + printf("failure: "); break; case TORTURE_ERROR: - printf("error: %s", context->active_test->name); + printf("error: "); break; case TORTURE_SKIP: - printf("skip: %s", context->active_test->name); + printf("skip: "); break; } + subunit_print_testname(context, context->active_tcase, context->active_test); + if (reason) printf(" [\n%s\n]", reason); printf("\n"); -- cgit From 72fce654072b2d7317ff21c95558bd365701d5dd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 16:19:51 +0200 Subject: getting/setting security options works for the regf backend now (This used to be commit 0f2de29dae1b29030c2c7bcee609919fce0d674b) --- source4/samba4-knownfail | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source4/samba4-knownfail b/source4/samba4-knownfail index 1d8651c80b..1f780f13f0 100644 --- a/source4/samba4-knownfail +++ b/source4/samba4-knownfail @@ -4,7 +4,8 @@ base.delaywrite.finfo update on close base.delete.*.deltest20a base.delete.*.deltest20b rpc.winreg.*security -local.registry.*.security # Not implemented yet +samba4.local.registry.(dir|ldb).check hive security +samba4.local.registry.local.security rpc.wkssvc rpc.handles.*.lsarpc-shared rpc.handles.*.mixed-shared -- cgit From e3d000f3bfad4126ab781f15848fff3bbd8abcc5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 16:29:08 +0200 Subject: Some more PEP improvements. (This used to be commit 015ca850df9b4c8112b033130023909b1d0b78b7) --- source4/scripting/python/samba/provision.py | 35 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index fe9b582d56..fdcc3dad77 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -1111,7 +1111,7 @@ def provision_become_dc(setup_dir=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, serverdn=serverdn, - domain=domain, hostname=hostname, hostip="127.0.0.1", domainsid=domainsid, machinepass=machinepass, serverrole="domain controller", sitename=sitename); + domain=domain, hostname=hostname, hostip="127.0.0.1", domainsid=domainsid, machinepass=machinepass, serverrole="domain controller", sitename=sitename) def setup_db_config(setup_path, dbdir): @@ -1120,9 +1120,9 @@ def setup_db_config(setup_path, dbdir): :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); + os.makedirs(os.path.join(dbdir, "bdb-logs"), 0700) if not os.path.isdir(os.path.join(dbdir, "tmp")): - os.makedirs(os.path.join(dbdir, "tmp"), 0700); + os.makedirs(os.path.join(dbdir, "tmp"), 0700) setup_file(setup_path("DB_CONFIG"), os.path.join(dbdir, "DB_CONFIG"), {"LDAPDBDIR": dbdir}) @@ -1145,8 +1145,9 @@ def provision_backend(setup_dir=None, message=None, root = findnss(pwd.getpwnam, ["root"])[0] if smbconf is None: - os.makedirs(os.path.join(targetdir, "etc")) - smbconf = os.path.join(targetdir, "etc", "smb.conf") + etcdir = os.path.join(targetdir, "etc") + os.makedirs(etcdir) + smbconf = os.path.join(etcdir, "smb.conf") # only install a new smb.conf if there isn't one there already if not os.path.exists(smbconf): @@ -1220,20 +1221,18 @@ def provision_backend(setup_dir=None, message=None, 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); + res = schemadb.search(expression="(&(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1)))(objectclass=attributeSchema))", base=names.schemadn, scope=SCOPE_SUBTREE, attrs=attrs) - memberof_config = "# Generated from schema in " + schemadb_path + "\n"; - refint_attributes = ""; + memberof_config = "# Generated from schema in %s\n" % schemadb_path + refint_attributes = "" for i in range (0, len(res)): - linkid = res[i]["linkID"][0] - linkid = str(int(linkid) + 1) - expression = "(&(objectclass=attributeSchema)(linkID=" + (linkid) + "))" + expression = "(&(objectclass=attributeSchema)(linkID=%d))" % (int(res[i]["linkID"][0])+1) target = schemadb.searchone(basedn=names.schemadn, expression=expression, attribute="lDAPDisplayName", - scope=SCOPE_SUBTREE); + scope=SCOPE_SUBTREE) if target is not None: - refint_attributes = refint_attributes + " " + target + " " + res[i]["lDAPDisplayName"][0]; + refint_attributes = refint_attributes + " " + target + " " + res[i]["lDAPDisplayName"][0] memberof_config = memberof_config + """overlay memberof memberof-dangling error memberof-refint TRUE @@ -1242,11 +1241,11 @@ memberof-member-ad """ + res[i]["lDAPDisplayName"][0] + """ memberof-memberof-ad """ + target + """ memberof-dangling-error 32 -"""; +""" memberof_config = memberof_config + """ overlay refint -refint_attributes""" + refint_attributes + "\n"; +refint_attributes""" + refint_attributes + "\n" setup_file(setup_path("slapd.conf"), paths.slapdconf, {"DNSDOMAIN": names.dnsdomain, @@ -1273,12 +1272,12 @@ refint_attributes""" + refint_attributes + "\n"; 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); + 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("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) @@ -1337,6 +1336,7 @@ def create_zone_file(path, setup_path, dnsdomain, domaindn, "HOSTIP6_HOST_LINE": hostip6_host_line, }) + def create_named_conf(path, setup_path, realm, dnsdomain, private_dir, keytab_name): """Write out a file containing zone statements suitable for inclusion in a @@ -1375,6 +1375,7 @@ def create_krb5_conf(path, setup_path, dnsdomain, hostname, realm): "REALM": realm, }) + def load_schema(setup_path, samdb, schemadn, netbiosname, configdn, sitename): """Load schema for the SamDB. -- cgit From a203ee1ab18ea68c6df436f8bb9fc0772611d5d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 16:43:26 +0200 Subject: Fix indentation, add docstring in provisioning script. (This used to be commit 86a8a085496c292b390c0d6362e3e4d9980df83f) --- source4/scripting/python/samba/provision.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index fdcc3dad77..a4730d8a07 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -48,6 +48,7 @@ __docformat__ = "restructuredText" DEFAULTSITE = "Default-First-Site-Name" class InvalidNetbiosName(Exception): + """A specified name was not a valid NetBIOS name.""" def __init__(self, name): super(InvalidNetbiosName, self).__init__("The name '%r' is not a valid NetBIOS name" % name) @@ -1233,7 +1234,7 @@ def provision_backend(setup_dir=None, message=None, scope=SCOPE_SUBTREE) if target is not None: refint_attributes = refint_attributes + " " + target + " " + res[i]["lDAPDisplayName"][0] - memberof_config = memberof_config + """overlay memberof + memberof_config += """overlay memberof memberof-dangling error memberof-refint TRUE memberof-group-oc top @@ -1243,7 +1244,7 @@ memberof-dangling-error 32 """ - memberof_config = memberof_config + """ + memberof_config += """ overlay refint refint_attributes""" + refint_attributes + "\n" @@ -1259,18 +1260,18 @@ refint_attributes""" + refint_attributes + "\n" setup_file(setup_path("modules.conf"), paths.modulesconf, {"REALM": names.realm}) - 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="") - 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 + 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="") + 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) -- cgit From 3811156e979da6168fc5b427fa2cf03d73e8f6a7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 19:25:05 +0200 Subject: More work allowing out-of-tree builds. Patch by Matthias Dieter Wallnöfer and me. (This used to be commit 6e29fbd5d06b02e2b0a55ae2994fce724aaa5bc5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source4/Makefile | 10 +++++----- source4/build/make/rules.mk | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source4/Makefile b/source4/Makefile index 0ee36ec830..069fece855 100644 --- a/source4/Makefile +++ b/source4/Makefile @@ -6,7 +6,7 @@ include mkconfig.mk pidldir := $(srcdir)/pidl -VPATH = $(builddir):$(srcdir):heimdal_build:heimdal/lib/asn1:heimdal/lib/krb5:heimdal/lib/gssapi:heimdal/lib/hdb:heimdal/lib/roken:heimdal/lib/des +VPATH = $(builddir):$(srcdir):$(srcdir)/heimdal_build:$(heimdalsrcdir)/lib/asn1:$(heimdalsrcdir)/lib/krb5:$(heimdalsrcdir)/lib/gssapi:$(heimdalsrcdir)/lib/hdb:$(heimdalsrcdir)/lib/roken:$(heimdalsrcdir)/lib/des BASEDIR = $(prefix) TORTUREDIR = $(libdir)/torture @@ -47,8 +47,8 @@ ALL_PREDEP = basics .NOTPARALLEL: endif -include build/make/rules.mk -include build/make/python.mk +include $(srcdir)/build/make/rules.mk +include $(srcdir)/build/make/python.mk include data.mk BINARIES += $(BIN_PROGS) $(SBIN_PROGS) @@ -233,8 +233,8 @@ data.mk: config.status $(MK_FILES) testcov-html:: -include pidl/config.mk -include selftest/config.mk +include $(pidldir)/config.mk +include $(srcdir)/selftest/config.mk showflags:: @echo ' pwd = '`/bin/pwd` diff --git a/source4/build/make/rules.mk b/source4/build/make/rules.mk index 176e67a691..27a214459a 100644 --- a/source4/build/make/rules.mk +++ b/source4/build/make/rules.mk @@ -86,7 +86,7 @@ unused_macros: @mkdir -p $(@D) @$(STLD) $(STLD_FLAGS) $@ $^ -include build/make/templates.mk +include $(make_utility_dir)/templates.mk ############################################################################### # File types -- cgit From dd7b0ebe2388b9031b91f6c59d6aa2bfeac7b0ef Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Fri, 23 May 2008 19:28:55 +0200 Subject: Fix typo in bugs.txt. (This used to be commit 66d7f35647a745958318ff8a3fb20c309598780e) --- BUGS.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUGS.txt b/BUGS.txt index 3ee3d63c56..52e1791928 100644 --- a/BUGS.txt +++ b/BUGS.txt @@ -3,4 +3,4 @@ than education you are insane, or perhaps just very interested. We welcome your testing, please file bug reports at https://bugzilla.samba.org/, product: Samba4. Please include as much -information as possible, such as SVN revision number and backtraces. +information as possible, such as GIT revision number and backtraces. -- cgit From b9c3aae792d06e01802c860f9cb8a463fb2a7428 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 May 2008 19:32:50 +0200 Subject: Include full path for python scripting dir to allow out-of-tree builds. (This used to be commit 01485bea87b7f7885ffed0cd3a0143baaa2d048e) --- source4/main.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/main.mk b/source4/main.mk index 5e31044c09..90473cce93 100644 --- a/source4/main.mk +++ b/source4/main.mk @@ -89,7 +89,7 @@ libclisrcdir := libcli mkinclude libcli/config.mk ejsscriptsrcdir := scripting/ejs mkinclude scripting/ejs/config.mk -pyscriptsrcdir := scripting/python +pyscriptsrcdir := $(srcdir)/scripting/python mkinclude scripting/python/config.mk kdcsrcdir := kdc mkinclude kdc/config.mk -- cgit From 73b789b6d25698dba15c867c71d0cdd8c264f352 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 04:01:57 +0200 Subject: Add docstrings to a couple more python modules. (This used to be commit b4560c90e5e8d3a35367d3a21d361dc4c9c0de23) --- source4/auth/auth.i | 6 ++++- source4/auth/auth.py | 4 +++ source4/auth/credentials/credentials.i | 2 +- source4/auth/credentials/credentials.py | 4 +++ source4/lib/events/events.i | 2 +- source4/lib/events/events.py | 4 +++ source4/lib/registry/registry.i | 6 ++++- source4/lib/registry/registry.py | 4 +++ source4/libcli/security/security.i | 13 +++++++++- source4/libcli/security/security.py | 40 ++++++++++++++++++++++++++++- source4/libcli/security/security_wrap.c | 25 ++++++++++++++---- source4/librpc/rpc/dcerpc.i | 6 ++++- source4/librpc/rpc/dcerpc.py | 4 +++ source4/param/param.i | 2 +- source4/param/param.py | 4 +++ source4/scripting/python/misc.i | 5 +++- source4/scripting/python/misc.py | 12 ++++++++- source4/scripting/python/misc_wrap.c | 5 +++- source4/scripting/python/samba/__init__.py | 2 ++ source4/scripting/python/samba/provision.py | 4 +-- 20 files changed, 136 insertions(+), 18 deletions(-) diff --git a/source4/auth/auth.i b/source4/auth/auth.i index b1743ef765..67c8137f67 100644 --- a/source4/auth/auth.i +++ b/source4/auth/auth.i @@ -16,7 +16,11 @@ along with this program. If not, see . */ -%module(package="samba.auth") auth +%define DOCSTRING +"Authentication and authorization support." +%enddef + +%module(docstring=DOCSTRING,package="samba.auth") auth %{ diff --git a/source4/auth/auth.py b/source4/auth/auth.py index 1a7aa6d0e7..226175a75b 100644 --- a/source4/auth/auth.py +++ b/source4/auth/auth.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +Authentication and authorization support. +""" + import _auth import new new_instancemethod = new.instancemethod diff --git a/source4/auth/credentials/credentials.i b/source4/auth/credentials/credentials.i index 89eb4924b3..bb31d6d4c0 100644 --- a/source4/auth/credentials/credentials.i +++ b/source4/auth/credentials/credentials.i @@ -16,7 +16,7 @@ along with this program. If not, see . */ -%module(package="samba.credentials") credentials +%module(docstring="Credentials management.",package="samba.credentials") credentials %{ diff --git a/source4/auth/credentials/credentials.py b/source4/auth/credentials/credentials.py index fd00a8e6f0..2cd56c3599 100644 --- a/source4/auth/credentials/credentials.py +++ b/source4/auth/credentials/credentials.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +Credentials management. +""" + import _credentials import new new_instancemethod = new.instancemethod diff --git a/source4/lib/events/events.i b/source4/lib/events/events.i index 7de8aec79d..5f790aeac5 100644 --- a/source4/lib/events/events.i +++ b/source4/lib/events/events.i @@ -16,7 +16,7 @@ along with this program. If not, see . */ -%module(package="samba.events") events; +%module(docstring="Event management.",package="samba.events") events; %import "../talloc/talloc.i"; diff --git a/source4/lib/events/events.py b/source4/lib/events/events.py index 264e0b7cdf..90695e3d92 100644 --- a/source4/lib/events/events.py +++ b/source4/lib/events/events.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +Event management. +""" + import _events import new new_instancemethod = new.instancemethod diff --git a/source4/lib/registry/registry.i b/source4/lib/registry/registry.i index 7dd02b344c..9420ba2014 100644 --- a/source4/lib/registry/registry.i +++ b/source4/lib/registry/registry.i @@ -16,7 +16,11 @@ along with this program. If not, see . */ -%module registry +%define DOCSTRING +"Access to various registry formats and the Samba registry." +%enddef + +%module(docstring=DOCSTRING) registry %{ /* Include headers */ diff --git a/source4/lib/registry/registry.py b/source4/lib/registry/registry.py index 4c6e735414..0aeefb86c1 100644 --- a/source4/lib/registry/registry.py +++ b/source4/lib/registry/registry.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +Access to various registry formats and the Samba registry. +""" + import _registry import new new_instancemethod = new.instancemethod diff --git a/source4/libcli/security/security.i b/source4/libcli/security/security.i index 647c9aea09..1d964cc3d5 100644 --- a/source4/libcli/security/security.i +++ b/source4/libcli/security/security.i @@ -16,7 +16,7 @@ along with this program. If not, see . */ -%module(package="samba.security") security +%module(docstring="Security-related classes.",package="samba.security") security %{ #include "includes.h" @@ -65,8 +65,14 @@ enum sec_privilege { typedef struct security_token { %extend { security_token(TALLOC_CTX *mem_ctx) { return security_token_initialise(mem_ctx); } + %feature("docstring") is_sid "S.is_sid(sid) -> bool\n" \ + "Check whether this token is of the specified SID."; bool is_sid(const struct dom_sid *sid); + %feature("docstring") is_system "S.is_system() -> bool\n" \ + "Check whether this is a system token."; bool is_system(); + %feature("docstring") is_anonymous "S.is_anonymus() -> bool\n" \ + "Check whether this is an anonymous token."; bool is_anonymous(); bool has_sid(const struct dom_sid *sid); bool has_builtin_administrators(); @@ -81,6 +87,8 @@ typedef struct security_token { typedef struct security_descriptor { %extend { security_descriptor(TALLOC_CTX *mem_ctx) { return security_descriptor_initialise(mem_ctx); } + %feature("docstring") sacl_add "S.sacl_add(ace) -> None\n" \ + "Add a security ace to this security descriptor"; NTSTATUS sacl_add(const struct security_ace *ace); NTSTATUS dacl_add(const struct security_ace *ace); NTSTATUS dacl_del(const struct dom_sid *trustee); @@ -111,6 +119,9 @@ typedef struct dom_sid { } } dom_sid; +%feature("docstring") random_sid "random_sid() -> sid\n" \ + "Generate a random SID"; + %inline %{ static struct dom_sid *random_sid(TALLOC_CTX *mem_ctx) { diff --git a/source4/libcli/security/security.py b/source4/libcli/security/security.py index 7e56e22cef..065c7a19e4 100644 --- a/source4/libcli/security/security.py +++ b/source4/libcli/security/security.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +Security-related classes. +""" + import _security import new new_instancemethod = new.instancemethod @@ -86,6 +90,27 @@ class SecurityToken(object): __repr__ = _swig_repr def __init__(self, *args, **kwargs): _security.SecurityToken_swiginit(self,_security.new_SecurityToken(*args, **kwargs)) + def is_sid(*args, **kwargs): + """ + S.is_sid(sid) -> bool + Check whether this token is of the specified SID. + """ + return _security.SecurityToken_is_sid(*args, **kwargs) + + def is_system(*args, **kwargs): + """ + S.is_system() -> bool + Check whether this is a system token. + """ + return _security.SecurityToken_is_system(*args, **kwargs) + + def is_anonymous(*args, **kwargs): + """ + S.is_anonymus() -> bool + Check whether this is an anonymous token. + """ + return _security.SecurityToken_is_anonymous(*args, **kwargs) + __swig_destroy__ = _security.delete_SecurityToken SecurityToken.is_sid = new_instancemethod(_security.SecurityToken_is_sid,None,SecurityToken) SecurityToken.is_system = new_instancemethod(_security.SecurityToken_is_system,None,SecurityToken) @@ -103,6 +128,13 @@ class security_descriptor(object): __repr__ = _swig_repr def __init__(self, *args, **kwargs): _security.security_descriptor_swiginit(self,_security.new_security_descriptor(*args, **kwargs)) + def sacl_add(*args, **kwargs): + """ + S.sacl_add(ace) -> None + Add a security ace to this security descriptor + """ + return _security.security_descriptor_sacl_add(*args, **kwargs) + __swig_destroy__ = _security.delete_security_descriptor security_descriptor.sacl_add = new_instancemethod(_security.security_descriptor_sacl_add,None,security_descriptor) security_descriptor.dacl_add = new_instancemethod(_security.security_descriptor_dacl_add,None,security_descriptor) @@ -123,7 +155,13 @@ Sid.__eq__ = new_instancemethod(_security.Sid___eq__,None,Sid) Sid_swigregister = _security.Sid_swigregister Sid_swigregister(Sid) -random_sid = _security.random_sid + +def random_sid(*args): + """ + random_sid() -> sid + Generate a random SID + """ + return _security.random_sid(*args) privilege_name = _security.privilege_name privilege_id = _security.privilege_id diff --git a/source4/libcli/security/security_wrap.c b/source4/libcli/security/security_wrap.c index aabf6c27ee..a10626c043 100644 --- a/source4/libcli/security/security_wrap.c +++ b/source4/libcli/security/security_wrap.c @@ -3527,9 +3527,18 @@ fail: static PyMethodDef SwigMethods[] = { { (char *)"new_SecurityToken", (PyCFunction)_wrap_new_SecurityToken, METH_NOARGS, NULL}, - { (char *)"SecurityToken_is_sid", (PyCFunction) _wrap_SecurityToken_is_sid, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"SecurityToken_is_system", (PyCFunction)_wrap_SecurityToken_is_system, METH_O, NULL}, - { (char *)"SecurityToken_is_anonymous", (PyCFunction)_wrap_SecurityToken_is_anonymous, METH_O, NULL}, + { (char *)"SecurityToken_is_sid", (PyCFunction) _wrap_SecurityToken_is_sid, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.is_sid(sid) -> bool\n" + "Check whether this token is of the specified SID.\n" + ""}, + { (char *)"SecurityToken_is_system", (PyCFunction)_wrap_SecurityToken_is_system, METH_O, (char *)"\n" + "S.is_system() -> bool\n" + "Check whether this is a system token.\n" + ""}, + { (char *)"SecurityToken_is_anonymous", (PyCFunction)_wrap_SecurityToken_is_anonymous, METH_O, (char *)"\n" + "S.is_anonymus() -> bool\n" + "Check whether this is an anonymous token.\n" + ""}, { (char *)"SecurityToken_has_sid", (PyCFunction) _wrap_SecurityToken_has_sid, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"SecurityToken_has_builtin_administrators", (PyCFunction)_wrap_SecurityToken_has_builtin_administrators, METH_O, NULL}, { (char *)"SecurityToken_has_nt_authenticated_users", (PyCFunction)_wrap_SecurityToken_has_nt_authenticated_users, METH_O, NULL}, @@ -3539,7 +3548,10 @@ static PyMethodDef SwigMethods[] = { { (char *)"SecurityToken_swigregister", SecurityToken_swigregister, METH_VARARGS, NULL}, { (char *)"SecurityToken_swiginit", SecurityToken_swiginit, METH_VARARGS, NULL}, { (char *)"new_security_descriptor", (PyCFunction)_wrap_new_security_descriptor, METH_NOARGS, NULL}, - { (char *)"security_descriptor_sacl_add", (PyCFunction) _wrap_security_descriptor_sacl_add, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"security_descriptor_sacl_add", (PyCFunction) _wrap_security_descriptor_sacl_add, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.sacl_add(ace) -> None\n" + "Add a security ace to this security descriptor\n" + ""}, { (char *)"security_descriptor_dacl_add", (PyCFunction) _wrap_security_descriptor_dacl_add, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"security_descriptor_dacl_del", (PyCFunction) _wrap_security_descriptor_dacl_del, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"security_descriptor_sacl_del", (PyCFunction) _wrap_security_descriptor_sacl_del, METH_VARARGS | METH_KEYWORDS, NULL}, @@ -3553,7 +3565,10 @@ static PyMethodDef SwigMethods[] = { { (char *)"delete_Sid", (PyCFunction)_wrap_delete_Sid, METH_O, NULL}, { (char *)"Sid_swigregister", Sid_swigregister, METH_VARARGS, NULL}, { (char *)"Sid_swiginit", Sid_swiginit, METH_VARARGS, NULL}, - { (char *)"random_sid", (PyCFunction)_wrap_random_sid, METH_NOARGS, NULL}, + { (char *)"random_sid", (PyCFunction)_wrap_random_sid, METH_NOARGS, (char *)"\n" + "random_sid() -> sid\n" + "Generate a random SID\n" + ""}, { (char *)"privilege_name", (PyCFunction) _wrap_privilege_name, METH_VARARGS | METH_KEYWORDS, NULL}, { (char *)"privilege_id", (PyCFunction) _wrap_privilege_id, METH_VARARGS | METH_KEYWORDS, NULL}, { NULL, NULL, 0, NULL } diff --git a/source4/librpc/rpc/dcerpc.i b/source4/librpc/rpc/dcerpc.i index f958d82e2e..2d7c27b07a 100644 --- a/source4/librpc/rpc/dcerpc.i +++ b/source4/librpc/rpc/dcerpc.i @@ -22,7 +22,11 @@ along with this program. If not, see . */ -%module dcerpc +%define DOCSTRING +"DCE/RPC protocol implementation" +%enddef + +%module(docstring=DOCSTRING) dcerpc %{ diff --git a/source4/librpc/rpc/dcerpc.py b/source4/librpc/rpc/dcerpc.py index db5b95cee8..5c26656230 100644 --- a/source4/librpc/rpc/dcerpc.py +++ b/source4/librpc/rpc/dcerpc.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +DCE/RPC protocol implementation +""" + import _dcerpc import new new_instancemethod = new.instancemethod diff --git a/source4/param/param.i b/source4/param/param.i index 2c15f8f5e3..ad42919998 100644 --- a/source4/param/param.i +++ b/source4/param/param.i @@ -16,7 +16,7 @@ along with this program. If not, see . */ -%module(package="samba.param") param +%module(docstring="Parsing and writing Samba configuration files.",package="samba.param") param %{ #include diff --git a/source4/param/param.py b/source4/param/param.py index 3aebaf0e02..46c75cef97 100644 --- a/source4/param/param.py +++ b/source4/param/param.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +Parsing and writing Samba configuration files. +""" + import _param import new new_instancemethod = new.instancemethod diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i index 9a4c124121..56b862552a 100644 --- a/source4/scripting/python/misc.i +++ b/source4/scripting/python/misc.i @@ -16,7 +16,7 @@ along with this program. If not, see . */ -%module(package="samba.misc") misc +%module(docstring="Python bindings for miscellaneous Samba functions.",package="samba.misc") misc %{ #include "includes.h" @@ -37,6 +37,9 @@ %import "../../libcli/security/security.i" %import "../../libcli/util/errors.i" +%feature("docstring") generate_random_str "S.random_password(len) -> string\n" \ + "Generate random password with specified length."; + %rename(random_password) generate_random_str; char *generate_random_str(TALLOC_CTX *mem_ctx, size_t len); diff --git a/source4/scripting/python/misc.py b/source4/scripting/python/misc.py index 25e8d2de8c..0c14944001 100644 --- a/source4/scripting/python/misc.py +++ b/source4/scripting/python/misc.py @@ -3,6 +3,10 @@ # # Don't modify this file, modify the SWIG interface instead. +""" +Python bindings for miscellaneous Samba functions. +""" + import _misc import new new_instancemethod = new.instancemethod @@ -61,7 +65,13 @@ import ldb import credentials import param import security -random_password = _misc.random_password + +def random_password(*args, **kwargs): + """ + S.random_password(len) -> string + Generate random password with specified length. + """ + return _misc.random_password(*args, **kwargs) def ldb_set_credentials(*args, **kwargs): """ diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c index 22a072fc6f..8c57237e5b 100644 --- a/source4/scripting/python/misc_wrap.c +++ b/source4/scripting/python/misc_wrap.c @@ -3216,7 +3216,10 @@ fail: static PyMethodDef SwigMethods[] = { - { (char *)"random_password", (PyCFunction) _wrap_random_password, METH_VARARGS | METH_KEYWORDS, NULL}, + { (char *)"random_password", (PyCFunction) _wrap_random_password, METH_VARARGS | METH_KEYWORDS, (char *)"\n" + "S.random_password(len) -> string\n" + "Generate random password with specified length.\n" + ""}, { (char *)"ldb_set_credentials", (PyCFunction) _wrap_ldb_set_credentials, METH_VARARGS | METH_KEYWORDS, (char *)"\n" "S.set_credentials(credentials)\n" "Set credentials to use when connecting.\n" diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py index 94f9e4d005..e191227108 100644 --- a/source4/scripting/python/samba/__init__.py +++ b/source4/scripting/python/samba/__init__.py @@ -20,6 +20,8 @@ # along with this program. If not, see . # +"""Samba 4.""" + __docformat__ = "restructuredText" import os diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py index a4730d8a07..3914fa8376 100644 --- a/source4/scripting/python/samba/provision.py +++ b/source4/scripting/python/samba/provision.py @@ -22,6 +22,8 @@ # along with this program. If not, see . # +"""Functions for setting up a Samba configuration.""" + from base64 import b64encode import os import pwd @@ -41,8 +43,6 @@ import urllib from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \ LDB_ERR_NO_SUCH_OBJECT, timestring, CHANGETYPE_MODIFY, CHANGETYPE_NONE -"""Functions for setting up a Samba configuration.""" - __docformat__ = "restructuredText" DEFAULTSITE = "Default-First-Site-Name" -- cgit From 453396c67b47bac0b39b276a332cf39c87d36d71 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 18:18:21 +0200 Subject: Initial work on IRPC Python support. (This used to be commit df01b040f7450c3be29f369a993955fbc4678bd9) --- source4/lib/messaging/pyirpc.c | 201 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 source4/lib/messaging/pyirpc.c diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c new file mode 100644 index 0000000000..49ca51fb33 --- /dev/null +++ b/source4/lib/messaging/pyirpc.c @@ -0,0 +1,201 @@ +/* + Unix SMB/CIFS implementation. + Copyright © Jelmer Vernooij 2008 + + Based on the equivalent for EJS: + Copyright © Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include +#include "lib/messaging/irpc.h" + +/* + messaging clients need server IDs as well ... + */ +#define EJS_ID_BASE 0x30000000 + +/* + state of a irpc 'connection' +*/ +struct ejs_irpc_connection { + const char *server_name; + struct server_id *dest_ids; + struct messaging_context *msg_ctx; +}; + +/* + setup a context for talking to a irpc server + example: + status = irpc.connect("smb_server"); +*/ + +PyObject *py_irpc_connect(PyObject *args, PyObjet *kwargs) +{ + NTSTATUS status; + int i; + struct event_context *ev; + struct ejs_irpc_connection *p; + struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); + + /* validate arguments */ + if (argc != 1) { + ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); + return -1; + } + + p = talloc(this, struct ejs_irpc_connection); + if (p == NULL) { + return -1; + } + + p->server_name = argv[0]; + + ev = mprEventCtx(); + + /* create a messaging context, looping as we have no way to + allocate temporary server ids automatically */ + for (i=0;i<10000;i++) { + p->msg_ctx = messaging_init(p, + lp_messaging_path(p, mprLpCtx()), + cluster_id(EJS_ID_BASE, i), + lp_iconv_convenience(mprLpCtx()), + ev); + if (p->msg_ctx) break; + } + if (p->msg_ctx == NULL) { + ejsSetErrorMsg(eid, "irpc_connect unable to create a messaging context"); + talloc_free(p); + return -1; + } + + p->dest_ids = irpc_servers_byname(p->msg_ctx, p, p->server_name); + if (p->dest_ids == NULL || p->dest_ids[0].id == 0) { + talloc_free(p); + status = NT_STATUS_OBJECT_NAME_NOT_FOUND; + } else { + mprSetPtrChild(this, "irpc", p); + status = NT_STATUS_OK; + } + + mpr_Return(eid, mprNTSTATUS(status)); + return 0; +} + +/* + make an irpc call - called via the same interface as rpc +*/ +static int ejs_irpc_call(int eid, struct MprVar *io, + const struct ndr_interface_table *iface, int callnum, + ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) +{ + NTSTATUS status; + void *ptr; + struct ejs_rpc *ejs; + const struct ndr_interface_call *call; + struct ejs_irpc_connection *p; + struct irpc_request **reqs; + int i, count; + struct MprVar *results; + + p = (struct ejs_irpc_connection *)mprGetThisPtr(eid, "irpc"); + + ejs = talloc(mprMemCtx(), struct ejs_rpc); + if (ejs == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + call = &iface->calls[callnum]; + + ejs->eid = eid; + ejs->callname = call->name; + + /* allocate the C structure */ + ptr = talloc_zero_size(ejs, call->struct_size); + if (ptr == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + /* convert the mpr object into a C structure */ + status = ejs_pull(ejs, io, ptr); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } + + for (count=0;p->dest_ids[count].id;count++) /* noop */ ; + + /* we need to make a call per server */ + reqs = talloc_array(ejs, struct irpc_request *, count); + if (reqs == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + /* make the actual calls */ + for (i=0;imsg_ctx, p->dest_ids[i], + iface, callnum, ptr, ptr); + if (reqs[i] == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + talloc_steal(reqs, reqs[i]); + } + + mprSetVar(io, "results", mprObject("results")); + results = mprGetProperty(io, "results", NULL); + + /* and receive the results, placing them in io.results[i] */ + for (i=0;i Date: Sat, 24 May 2008 18:19:41 +0200 Subject: Remove remaining EJS RPC code, was unused. (This used to be commit c994fa427fdd1e9682a5ad506aafc77f942122d1) --- source4/scripting/ejs/config.mk | 8 +- source4/scripting/ejs/ejsrpc.c | 424 ---------------------------------- source4/scripting/ejs/ejsrpc.h | 172 -------------- source4/scripting/ejs/smbcalls_rpc.c | 385 ------------------------------ source4/scripting/libjs/management.js | 157 ------------- 5 files changed, 1 insertion(+), 1145 deletions(-) delete mode 100644 source4/scripting/ejs/ejsrpc.c delete mode 100644 source4/scripting/ejs/ejsrpc.h delete mode 100644 source4/scripting/ejs/smbcalls_rpc.c delete mode 100644 source4/scripting/libjs/management.js diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index c1a1ca1f0f..873dd09248 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -1,7 +1,3 @@ -[SUBSYSTEM::EJSRPC] - -EJSRPC_OBJ_FILES = $(ejsscriptsrcdir)/ejsrpc.o - [MODULE::smbcalls_config] OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls @@ -83,16 +79,14 @@ mkinclude ejsnet/config.mk [SUBSYSTEM::smbcalls] PRIVATE_DEPENDENCIES = \ EJS LIBSAMBA-UTIL \ - EJSRPC MESSAGING \ + MESSAGING \ LIBSAMBA-NET LIBCLI_SMB LIBPOPT \ CREDENTIALS POPT_CREDENTIALS POPT_SAMBA \ - dcerpc \ NDR_TABLE smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ smbcalls_cli.o \ - smbcalls_rpc.o \ smbcalls_options.o \ smbcalls_creds.o \ smbcalls_param.o \ diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c deleted file mode 100644 index c7c02dbd64..0000000000 --- a/source4/scripting/ejs/ejsrpc.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide interfaces to rpc calls from ejs scripts - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "scripting/ejs/smbcalls.h" -#include "librpc/gen_ndr/lsa.h" -#include "librpc/gen_ndr/winreg.h" -#include "scripting/ejs/ejsrpc.h" -#include "libcli/security/security.h" - -/* - set the switch var to be used by the next union switch -*/ -void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var) -{ - ejs->switch_var = switch_var; -} - -/* - panic in the ejs wrapper code - */ -NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why) -{ - ejsSetErrorMsg(ejs->eid, "rpc_call '%s' failed - %s", ejs->callname, why); - return NT_STATUS_INTERNAL_ERROR; -} - -/* - start the ejs pull process for a structure -*/ -NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) -{ - return mprGetVar(v, name); -} - - -/* - start the ejs push process for a structure -*/ -NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) -{ - EJS_CHECK(mprSetVar(*v, name, mprObject(name))); - return mprGetVar(v, name); -} - -/* - pull a uint8 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint8_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint8_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint16 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint16_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint16_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint32_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint32_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a int32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int32_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int32_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, time_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const time_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToNumber(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return mprSetVar(v, name, mprCreateNumberVar(*r)); -} - -NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, (uint64_t *)r); -} - -NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int64_t *r) -{ - return ejs_push_hyper(ejs, v, name, (const uint64_t *)r); -} - -NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return ejs_push_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return ejs_push_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const WERROR *r) -{ - return ejs_push_string(ejs, v, name, win_errstr(*r)); -} - -NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const NTSTATUS *r) -{ - return ejs_push_string(ejs, v, name, nt_errstr(*r)); -} - - -/* - pull a enum from a mpr variable to a C element - a enum is just treating as an unsigned integer at this level -*/ -NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, unsigned *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const unsigned *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - - -/* - pull a string -*/ -NTSTATUS ejs_pull_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s) -{ - EJS_CHECK(mprGetVar(&v, name)); - *s = mprToString(v); - return NT_STATUS_OK; -} - -/* - push a string -*/ -NTSTATUS ejs_push_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s) -{ - return mprSetVar(v, name, mprString(s)); -} - - -/* - pull a ipv4address (internally a string) -*/ -NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s) -{ - return ejs_pull_string(ejs, v, name, s); -} - -/* - push a ipv4address (internally a string) -*/ -NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s) -{ - return ejs_push_string(ejs, v, name, s); -} - - -NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct dom_sid *r) -{ - struct dom_sid *sid; - EJS_CHECK(mprGetVar(&v, name)); - sid = dom_sid_parse_talloc(ejs, mprToString(v)); - NT_STATUS_HAVE_NO_MEMORY(sid); - *r = *sid; - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct dom_sid *r) -{ - char *sidstr = dom_sid_string(ejs, r); - NT_STATUS_HAVE_NO_MEMORY(sidstr); - return mprSetVar(v, name, mprString(sidstr)); -} - -NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct GUID *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - return GUID_from_string(mprToString(v), r); -} - -NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct GUID *r) -{ - char *guid = GUID_string(ejs, r); - NT_STATUS_HAVE_NO_MEMORY(guid); - return mprSetVar(v, name, mprString(guid)); -} - -NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name) -{ - return mprSetVar(v, name, mprCreatePtrVar(NULL)); -} - -bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name) -{ - NTSTATUS status = mprGetVar(&v, name); - if (!NT_STATUS_IS_OK(status)) { - return false; - } - if (v->type == MPR_TYPE_PTR && v->ptr == NULL) { - return true; - } - return false; -} - -/* - pull a lsa_String -*/ -NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct lsa_String *r) -{ - return ejs_pull_string(ejs, v, name, &r->string); -} - -/* - push a lsa_String -*/ -NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct lsa_String *r) -{ - return ejs_push_string(ejs, v, name, r->string); -} - -/* - pull a winreg_String -*/ -NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct winreg_String *r) -{ - return ejs_pull_string(ejs, v, name, &r->name); -} - -/* - push a winreg_String -*/ -NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct winreg_String *r) -{ - return ejs_push_string(ejs, v, name, r->name); -} - -NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, DATA_BLOB *r) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const DATA_BLOB *r) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, bool *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToBool(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const bool *r) -{ - return mprSetVar(v, name, mprCreateBoolVar(*r)); -} - - -/* - pull a uint8 array from a mpr variable to a C element - treating as a data blob -*/ -NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - uint8_t *r, uint32_t length) -{ - NTSTATUS status; - DATA_BLOB *blob; - - status = mprGetVar(&v, name); - NT_STATUS_NOT_OK_RETURN(status); - - blob = mprToDataBlob(v); - if (blob == NULL) { - return NT_STATUS_OBJECT_NAME_INVALID; - } - if (blob->length != length) { - return NT_STATUS_INFO_LENGTH_MISMATCH; - } - memcpy(r, blob->data, length); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const uint8_t *r, uint32_t length) -{ - DATA_BLOB blob; - blob.data = (uint8_t *)discard_const(r); - blob.length = length; - mprSetVar(v, name, mprDataBlob(blob)); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h deleted file mode 100644 index cc22a26700..0000000000 --- a/source4/scripting/ejs/ejsrpc.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - ejs <-> rpc interface definitions - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "librpc/gen_ndr/security.h" -#include "librpc/rpc/dcerpc.h" - -struct ejs_rpc { - int eid; - const char *callname; - /* as ejs does only one pass, we can use a single var for switch - handling */ - uint32_t switch_var; -}; - -typedef NTSTATUS (*ejs_pull_t)(struct ejs_rpc *, struct MprVar *, const char *, void *); -typedef NTSTATUS (*ejs_push_t)(struct ejs_rpc *, struct MprVar *, const char *, const void *); -typedef NTSTATUS (*ejs_pull_function_t)(struct ejs_rpc *, struct MprVar *, void *); -typedef NTSTATUS (*ejs_push_function_t)(struct ejs_rpc *, struct MprVar *, const void *); - -NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why); -void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var); - -NTSTATUS smbcalls_register_ejs(const char *name, MprCFunction fn); - - -int ejs_rpc_call(int eid, int argc, struct MprVar **argv, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push); - -NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name); -NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name); - -NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint8_t *r); -NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint8_t *r); -NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint16_t *r); -NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint16_t *r); -NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint32_t *r); -NTSTATUS ejs_push_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int32_t *r); -NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int32_t *r); -NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint32_t *r); -NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int64_t *r); -NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int64_t *r); -NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, time_t *r); -NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const time_t *r); -NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, unsigned *r); -NTSTATUS ejs_push_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const unsigned *r); -NTSTATUS ejs_pull_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s); -NTSTATUS ejs_push_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s); -NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s); -NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s); -void ejs_set_constant_int(int eid, const char *name, int value); -void ejs_set_constant_string(int eid, const char *name, const char *value); - -NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct dom_sid *r); -NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct dom_sid *r); -NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name); -bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name); -NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const WERROR *r); -NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const NTSTATUS *r); -NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, DATA_BLOB *r); -NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const DATA_BLOB *r); -NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, bool *r); -NTSTATUS ejs_push_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const bool *r); - -NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - uint8_t *r, uint32_t length); -NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const uint8_t *r, uint32_t length); - -NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct GUID *r); -NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct GUID *r); - -struct lsa_String; -NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct lsa_String *r); -NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct lsa_String *r); - -struct winreg_String; -NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct winreg_String *r); -NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct winreg_String *r); - -#define EJS_ALLOC(ejs, s) do { \ - (s) = talloc_ptrtype(ejs, (s)); \ - if (!(s)) return ejs_panic(ejs, "out of memory"); \ -} while (0) - -#define EJS_ALLOC_N(ejs, s, n) do { \ - (s) = talloc_array_ptrtype(ejs, (s), n); \ - if (!(s)) return ejs_panic(ejs, "out of memory"); \ -} while (0) - -#define EJS_CHECK(cmd) do { \ - NTSTATUS _status; \ - _status = cmd; \ - if (!NT_STATUS_IS_OK(_status)) { \ - return _status; \ - } \ -} while (0) - -/* some types are equivalent for ejs */ -#define ejs_pull_dom_sid2 ejs_pull_dom_sid -#define ejs_push_dom_sid2 ejs_push_dom_sid -#define ejs_pull_dom_sid28 ejs_pull_dom_sid -#define ejs_push_dom_sid28 ejs_push_dom_sid -#define ejs_pull_NTTIME_hyper ejs_pull_NTTIME -#define ejs_push_NTTIME_hyper ejs_push_NTTIME -#define ejs_pull_NTTIME_1sec ejs_pull_NTTIME -#define ejs_push_NTTIME_1sec ejs_push_NTTIME - diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c deleted file mode 100644 index 94774d708b..0000000000 --- a/source4/scripting/ejs/smbcalls_rpc.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide interfaces to rpc calls from ejs scripts - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/echo.h" -#include "lib/cmdline/popt_common.h" -#include "lib/messaging/irpc.h" -#include "scripting/ejs/ejsrpc.h" -#include "lib/util/dlinklist.h" -#include "lib/events/events.h" -#include "librpc/ndr/ndr_table.h" -#include "auth/credentials/credentials.h" -#include "librpc/rpc/dcerpc.h" -#include "cluster/cluster.h" - -/* - state of a irpc 'connection' -*/ -struct ejs_irpc_connection { - const char *server_name; - struct server_id *dest_ids; - struct messaging_context *msg_ctx; -}; - -/* - messaging clients need server IDs as well ... - */ -#define EJS_ID_BASE 0x30000000 - -/* - setup a context for talking to a irpc server - example: - status = irpc.connect("smb_server"); -*/ -static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status; - int i; - struct event_context *ev; - struct ejs_irpc_connection *p; - struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); - - /* validate arguments */ - if (argc != 1) { - ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); - return -1; - } - - p = talloc(this, struct ejs_irpc_connection); - if (p == NULL) { - return -1; - } - - p->server_name = argv[0]; - - ev = mprEventCtx(); - - /* create a messaging context, looping as we have no way to - allocate temporary server ids automatically */ - for (i=0;i<10000;i++) { - p->msg_ctx = messaging_init(p, - lp_messaging_path(p, mprLpCtx()), - cluster_id(EJS_ID_BASE, i), - lp_iconv_convenience(mprLpCtx()), - ev); - if (p->msg_ctx) break; - } - if (p->msg_ctx == NULL) { - ejsSetErrorMsg(eid, "irpc_connect unable to create a messaging context"); - talloc_free(p); - return -1; - } - - p->dest_ids = irpc_servers_byname(p->msg_ctx, p, p->server_name); - if (p->dest_ids == NULL || p->dest_ids[0].id == 0) { - talloc_free(p); - status = NT_STATUS_OBJECT_NAME_NOT_FOUND; - } else { - mprSetPtrChild(this, "irpc", p); - status = NT_STATUS_OK; - } - - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - connect to an rpc server - examples: - status = rpc.connect("ncacn_ip_tcp:localhost"); - status = rpc.connect("ncacn_ip_tcp:localhost", "pipe_name"); -*/ -static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv) -{ - const char *binding, *pipe_name; - const struct ndr_interface_table *iface; - NTSTATUS status; - struct dcerpc_pipe *p; - struct cli_credentials *creds; - struct event_context *ev; - struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); - struct MprVar *credentials; - - /* validate arguments */ - if (argc < 1) { - ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); - return -1; - } - - binding = argv[0]; - if (strchr(binding, ':') == NULL) { - /* its an irpc connect */ - return ejs_irpc_connect(eid, argc, argv); - } - - if (argc > 1) { - pipe_name = argv[1]; - } else { - pipe_name = mprToString(mprGetProperty(this, "pipe_name", NULL)); - } - - iface = ndr_table_by_name(pipe_name); - if (iface == NULL) { - status = NT_STATUS_OBJECT_NAME_INVALID; - goto done; - } - - credentials = mprGetProperty(this, "credentials", NULL); - if (credentials) { - creds = (struct cli_credentials *) - mprGetPtr(credentials, "creds"); - } else { - creds = cmdline_credentials; - } - if (creds == NULL) { - creds = cli_credentials_init(mprMemCtx()); - cli_credentials_set_anonymous(creds); - } - - ev = mprEventCtx(); - - status = dcerpc_pipe_connect(this, &p, binding, iface, creds, ev, - mprLpCtx()); - if (!NT_STATUS_IS_OK(status)) goto done; - - /* callers don't allocate ref vars in the ejs interface */ - p->conn->flags |= DCERPC_NDR_REF_ALLOC; - - /* by making the pipe a child of the connection variable, it will - auto close when it goes out of scope in the script */ - mprSetPtrChild(this, "pipe", p); - -done: - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - make an irpc call - called via the same interface as rpc -*/ -static int ejs_irpc_call(int eid, struct MprVar *io, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) -{ - NTSTATUS status; - void *ptr; - struct ejs_rpc *ejs; - const struct ndr_interface_call *call; - struct ejs_irpc_connection *p; - struct irpc_request **reqs; - int i, count; - struct MprVar *results; - - p = (struct ejs_irpc_connection *)mprGetThisPtr(eid, "irpc"); - - ejs = talloc(mprMemCtx(), struct ejs_rpc); - if (ejs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - call = &iface->calls[callnum]; - - ejs->eid = eid; - ejs->callname = call->name; - - /* allocate the C structure */ - ptr = talloc_zero_size(ejs, call->struct_size); - if (ptr == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* convert the mpr object into a C structure */ - status = ejs_pull(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - for (count=0;p->dest_ids[count].id;count++) /* noop */ ; - - /* we need to make a call per server */ - reqs = talloc_array(ejs, struct irpc_request *, count); - if (reqs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* make the actual calls */ - for (i=0;imsg_ctx, p->dest_ids[i], - iface, callnum, ptr, ptr); - if (reqs[i] == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - talloc_steal(reqs, reqs[i]); - } - - mprSetVar(io, "results", mprObject("results")); - results = mprGetProperty(io, "results", NULL); - - /* and receive the results, placing them in io.results[i] */ - for (i=0;itype != MPR_TYPE_OBJECT) { - ejsSetErrorMsg(eid, "rpc_call invalid arguments"); - return -1; - } - - io = argv[0]; - - if (mprGetThisPtr(eid, "irpc")) { - /* its an irpc call */ - return ejs_irpc_call(eid, io, iface, callnum, ejs_pull, ejs_push); - } - - /* get the pipe info */ - p = mprGetThisPtr(eid, "pipe"); - if (p == NULL) { - ejsSetErrorMsg(eid, "rpc_call invalid pipe"); - return -1; - } - - ejs = talloc(mprMemCtx(), struct ejs_rpc); - if (ejs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - call = &iface->calls[callnum]; - - ejs->eid = eid; - ejs->callname = call->name; - - /* allocate the C structure */ - ptr = talloc_zero_size(ejs, call->struct_size); - if (ptr == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* convert the mpr object into a C structure */ - status = ejs_pull(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* make the actual call */ - req = dcerpc_ndr_request_send(p, NULL, iface, callnum, ptr, ptr); - - /* if requested, print the structure */ - if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) { - ndr_print_function_debug(call->ndr_print, call->name, NDR_IN, ptr); - } - - if (req == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - status = dcerpc_ndr_request_recv(req); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* print the 'out' structure, if needed */ - if (p->conn->flags & DCERPC_DEBUG_PRINT_OUT) { - ndr_print_function_debug(call->ndr_print, call->name, NDR_OUT, ptr); - } - - status = ejs_push(ejs, io, ptr); - -done: - talloc_free(ejs); - mpr_Return(eid, mprNTSTATUS(status)); - if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) { - return -1; - } - return 0; -} - -/* - hook called by generated RPC interfaces at the end of their init routines - used to add generic operations on the pipe -*/ -int ejs_rpc_init(struct MprVar *obj, const char *name) -{ - ndr_table_init(); - - mprSetStringCFunction(obj, "connect", ejs_rpc_connect); - if (mprGetProperty(obj, "pipe_name", NULL) == NULL) { - mprSetVar(obj, "pipe_name", mprString(name)); - } - return 0; -} diff --git a/source4/scripting/libjs/management.js b/source4/scripting/libjs/management.js deleted file mode 100644 index 4a43275156..0000000000 --- a/source4/scripting/libjs/management.js +++ /dev/null @@ -1,157 +0,0 @@ -/* - backend code for Samba4 management - Copyright Andrew Tridgell 2005 - Released under the GNU GPL version 3 or later -*/ - - -/* - return a list of current sessions -*/ -function smbsrv_sessions() -{ - var irpc = irpc_init(); - status = irpc.connect("smb_server"); - if (status.is_ok != true) { - return undefined; - } - - var io = irpcObj(); - io.input.level = irpc.SMBSRV_INFO_SESSIONS; - status = irpc.smbsrv_information(io); - if (status.is_ok != true) { - return undefined; - } - - /* gather the results into a single array */ - var i, count=0, ret = new Array(0); - for (i=0;i Date: Sat, 24 May 2008 18:25:27 +0200 Subject: Initialize module. (This used to be commit 3246258afb4f3b4a977a191f2f83c73e8ce9c65a) --- source4/lib/messaging/pyirpc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c index 49ca51fb33..8f6a8b6c72 100644 --- a/source4/lib/messaging/pyirpc.c +++ b/source4/lib/messaging/pyirpc.c @@ -197,5 +197,6 @@ done: static void initirpc(void) { - + PyObject *mod; + mod = Py_InitModule("irpc", irpc_methods); } -- cgit From 1cd3a2be3199b7e1a3aa2ef29234255b8c1675ba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 18:46:32 +0200 Subject: Add __ndr_pack__ method to all DCE/RPC structures. (This used to be commit 06d272b42f59d0a785697d207e6d7dbbcf355175) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 440b1bff97..ad3cab6ffb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -225,7 +225,33 @@ sub PythonStruct($$$$$$) $self->pidl("return py_talloc_import(&$name\_Type, ret);"); $self->deindent; $self->pidl("}"); + $self->pidl(""); + + $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + $self->pidl("DATA_BLOB blob;"); + $self->pidl("enum ndr_err_code err;"); + $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_push_$name);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("static PyMethodDef py_$name\_methods[] = {"); + $self->indent; + $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"NDR pack\" },"); + $self->pidl("{ NULL, NULL, 0, NULL }"); + $self->deindent; + $self->pidl("};"); $self->pidl(""); $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n"); @@ -243,6 +269,7 @@ sub PythonStruct($$$$$$) $self->pidl(".tp_getset = $getsetters,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->pidl(".tp_doc = $docstring,"); + $self->pidl(".tp_methods = py_$name\_methods,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); $self->pidl(".tp_new = py_$name\_new,"); $self->deindent; -- cgit From 14c4028f261cbbdba03cc8b3f0ec6e32a390c79e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 18:55:46 +0200 Subject: Support __ndr_unpack__ on DCE/RPC structures in Python. (This used to be commit 3b2bd4d849946aaff2b0adfbacdc15284670b916) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index ad3cab6ffb..56d54d3d36 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -244,11 +244,33 @@ sub PythonStruct($$$$$$) $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); $self->deindent; $self->pidl("}"); + $self->pidl(""); + $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + $self->pidl("DATA_BLOB blob;"); + $self->pidl("enum ndr_err_code err;"); + $self->pidl("if (!PyArg_ParseTuple(args, \"s#\", &blob.data, &blob.length))"); + $self->pidl("\treturn NULL;"); + $self->pidl(""); + $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_pull_$name);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return Py_None;"); + $self->deindent; + $self->pidl("}"); $self->pidl(""); $self->pidl("static PyMethodDef py_$name\_methods[] = {"); $self->indent; - $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"NDR pack\" },"); + $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },"); + $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },"); $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; $self->pidl("};"); -- cgit From f76697ce89606aa4e5ba1bb13f1fda6e33998695 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 18:57:15 +0200 Subject: Add convenience functions for packing/unpacking structs in python. (This used to be commit c5d7d48b32bcebf8a0495cbd4556e30587fa589f) --- source4/scripting/python/samba/ndr.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 source4/scripting/python/samba/ndr.py diff --git a/source4/scripting/python/samba/ndr.py b/source4/scripting/python/samba/ndr.py new file mode 100644 index 0000000000..e93fbc3c2e --- /dev/null +++ b/source4/scripting/python/samba/ndr.py @@ -0,0 +1,27 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +def ndr_pack(object): + return object.__ndr_pack__() + + +def ndr_unpack(cls, data): + object = cls() + object.__ndr_unpack__(data) + return object -- cgit From e3bbe61d8162ebb5bf4ef2d3702587b39b0c4284 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 19:49:54 +0200 Subject: Only provide __ndr_pack__ / __ndr_unpack__ if the push/pull functions are public. (This used to be commit dd43bdcb880d08013a600f81d40e5280db74c534) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 103 ++++++++++++++------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 56d54d3d36..b83f9a5360 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -227,54 +227,61 @@ sub PythonStruct($$$$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); - $self->pidl("DATA_BLOB blob;"); - $self->pidl("enum ndr_err_code err;"); - $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_push_$name);"); - $self->pidl("if (err != NDR_ERR_SUCCESS) {"); - $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); + my $py_methods = "NULL"; - $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); - $self->pidl("DATA_BLOB blob;"); - $self->pidl("enum ndr_err_code err;"); - $self->pidl("if (!PyArg_ParseTuple(args, \"s#\", &blob.data, &blob.length))"); - $self->pidl("\treturn NULL;"); - $self->pidl(""); - $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_pull_$name);"); - $self->pidl("if (err != NDR_ERR_SUCCESS) {"); - $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("return Py_None;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("static PyMethodDef py_$name\_methods[] = {"); - $self->indent; - $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },"); - $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },"); - $self->pidl("{ NULL, NULL, 0, NULL }"); - $self->deindent; - $self->pidl("};"); - $self->pidl(""); + # If the struct is not public there ndr_pull/ndr_push functions will + # be static so not callable from here + if (has_property($d, "public")) { + $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + $self->pidl("DATA_BLOB blob;"); + $self->pidl("enum ndr_err_code err;"); + $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_push_flags_fn_t)ndr_push_$name);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + + $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + $self->pidl("DATA_BLOB blob;"); + $self->pidl("enum ndr_err_code err;"); + $self->pidl("if (!PyArg_ParseTuple(args, \"(s#):__ndr_unpack__\", &blob.data, &blob.length))"); + $self->pidl("\treturn NULL;"); + $self->pidl(""); + $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return Py_None;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $py_methods = "py_$name\_methods"; + $self->pidl("static PyMethodDef $py_methods\[] = {"); + $self->indent; + $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },"); + $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },"); + $self->pidl("{ NULL, NULL, 0, NULL }"); + $self->deindent; + $self->pidl("};"); + $self->pidl(""); + } $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n"); $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); @@ -291,7 +298,7 @@ sub PythonStruct($$$$$$) $self->pidl(".tp_getset = $getsetters,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->pidl(".tp_doc = $docstring,"); - $self->pidl(".tp_methods = py_$name\_methods,"); + $self->pidl(".tp_methods = $py_methods,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); $self->pidl(".tp_new = py_$name\_new,"); $self->deindent; -- cgit From 05194ccdf875ee70cb9ee3f7c27147503d585a6d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 19:50:09 +0200 Subject: Add tests for new NDR pack/unpack functionality in Python DCE/RPC bindings. (This used to be commit 468d35827fd055c82c6d43d6ce6d3d561abed54d) --- source4/librpc/idl/echo.idl | 2 +- source4/scripting/python/samba/ndr.py | 1 + source4/scripting/python/samba/tests/dcerpc/rpcecho.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source4/librpc/idl/echo.idl b/source4/librpc/idl/echo.idl index 5ea37f1ac1..bf1e318674 100644 --- a/source4/librpc/idl/echo.idl +++ b/source4/librpc/idl/echo.idl @@ -38,7 +38,7 @@ interface rpcecho /* test some alignment issues */ - typedef struct { + typedef [public] struct { uint8 v; } echo_info1; diff --git a/source4/scripting/python/samba/ndr.py b/source4/scripting/python/samba/ndr.py index e93fbc3c2e..e718ff3422 100644 --- a/source4/scripting/python/samba/ndr.py +++ b/source4/scripting/python/samba/ndr.py @@ -1,4 +1,5 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- # Unix SMB/CIFS implementation. # Copyright © Jelmer Vernooij 2008 diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py index 3b37f8a9bc..9157f83fc9 100644 --- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py +++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py @@ -18,6 +18,7 @@ # from samba.dcerpc import echo +from samba.ndr import ndr_pack, ndr_unpack import unittest from samba.tests import RpcInterfaceTestCase @@ -40,3 +41,14 @@ class RpcEchoTests(RpcInterfaceTestCase): surrounding_struct.surrounding = [1,2,3,4] y = self.conn.TestSurrounding(surrounding_struct) self.assertEquals(8 * [0], y.surrounding) + + +class NdrEchoTests(unittest.TestCase): + def test_info1_push(self): + x = echo.info1() + x.v = 42 + self.assertEquals("\x2a", ndr_pack(x)) + + def test_info1_pull(self): + x = ndr_unpack(echo.info1, "\x42") + self.assertEquals(x.v, 66) -- cgit From 515b6ed5867bba8180bd0eeadbeab1c52bffc0ab Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 20:00:37 +0200 Subject: Share struct used for interfaces in Python code. (This used to be commit 8501a3fc31e688dba696667a187821480e8cb714) --- source4/librpc/rpc/pyrpc.h | 44 ++++++++++++++++++++++++++++ source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 19 ++++-------- source4/scripting/python/pyrpc.h | 39 ------------------------ 3 files changed, 50 insertions(+), 52 deletions(-) create mode 100644 source4/librpc/rpc/pyrpc.h delete mode 100644 source4/scripting/python/pyrpc.h diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h new file mode 100644 index 0000000000..c21f387cf6 --- /dev/null +++ b/source4/librpc/rpc/pyrpc.h @@ -0,0 +1,44 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#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); \ + fail; \ + } + +#define dom_sid2_Type dom_sid_Type +#define dom_sid28_Type dom_sid_Type +#define dom_sid2_Check dom_sid_Check +#define dom_sid28_Check dom_sid_Check + +/* This macro is only provided by Python >= 2.3 */ +#ifndef PyAPI_DATA +# define PyAPI_DATA(RTYPE) extern RTYPE +#endif + +typedef struct { + PyObject_HEAD + struct dcerpc_pipe *pipe; +} dcerpc_InterfaceObject; + +#endif /* _PYRPC_H_ */ diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index b83f9a5360..dea8f2c648 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -327,7 +327,7 @@ sub PythonFunctionBody($$$) { my ($self, $fn, $iface, $prettyname) = @_; - $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); + $self->pidl("dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); @@ -607,13 +607,6 @@ sub Interface($$$) if (defined $interface->{PROPERTIES}->{uuid}) { $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $interface->{NAME}_InterfaceType;\n"); - $self->pidl("typedef struct {"); - $self->indent; - $self->pidl("PyObject_HEAD"); - $self->pidl("struct dcerpc_pipe *pipe;"); - $self->deindent; - $self->pidl("} $interface->{NAME}_InterfaceObject;"); - $self->pidl(""); my @fns = (); @@ -646,7 +639,7 @@ sub Interface($$$) $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); $self->pidl("{"); $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *interface = ($interface->{NAME}_InterfaceObject *)self;"); + $self->pidl("dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self;"); $self->pidl("talloc_free(interface->pipe);"); $self->pidl("PyObject_Del(self);"); $self->deindent; @@ -656,7 +649,7 @@ sub Interface($$$) $self->pidl("static PyObject *interface_$interface->{NAME}_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); + $self->pidl("dcerpc_InterfaceObject *ret;"); $self->pidl("const char *binding_string;"); $self->pidl("struct cli_credentials *credentials;"); $self->pidl("struct loadparm_context *lp_ctx = NULL;"); @@ -696,7 +689,7 @@ sub Interface($$$) $self->deindent; $self->pidl("}"); - $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); + $self->pidl("ret = PyObject_New(dcerpc_InterfaceObject, &$interface->{NAME}_InterfaceType);"); $self->pidl(""); $self->pidl("event_ctx = event_context_init(mem_ctx);"); $self->pidl(""); @@ -732,7 +725,7 @@ sub Interface($$$) $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$basename.$interface->{NAME}\","); - $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); + $self->pidl(".tp_basicsize = sizeof(dcerpc_InterfaceObject),"); $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); $self->pidl(".tp_methods = interface_$interface->{NAME}_methods,"); $self->pidl(".tp_doc = $docstring,"); @@ -1085,7 +1078,7 @@ sub Parse($$$$$) #include #include \"librpc/rpc/dcerpc.h\" #include \"scripting/python/pytalloc.h\" -#include \"scripting/python/pyrpc.h\" +#include \"librpc/rpc/pyrpc.h\" #include \"lib/events/events.h\" #include \"$hdr\" #include \"$ndr_hdr\" diff --git a/source4/scripting/python/pyrpc.h b/source4/scripting/python/pyrpc.h deleted file mode 100644 index 93d583c10a..0000000000 --- a/source4/scripting/python/pyrpc.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Jelmer Vernooij 2008 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#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); \ - fail; \ - } - -#define dom_sid2_Type dom_sid_Type -#define dom_sid28_Type dom_sid_Type -#define dom_sid2_Check dom_sid_Check -#define dom_sid28_Check dom_sid_Check - -/* This macro is only provided by Python >= 2.3 */ -#ifndef PyAPI_DATA -# define PyAPI_DATA(RTYPE) extern RTYPE -#endif - -#endif /* _PYRPC_H_ */ -- cgit From 654be49c010949a0420412450971effdbd4ce585 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 21:02:56 +0200 Subject: Use manually written Python bindings for DCE/RPC rather than SWIG based. Use base class for pidl-generated DCE/RPC interface Python bindings. (This used to be commit 25e7fc8a2c7a5914c4db4bfe428fd0a8efbf0784) --- source4/librpc/config.mk | 39 +- source4/librpc/rpc/dcerpc.h | 8 + source4/librpc/rpc/dcerpc.i | 125 - source4/librpc/rpc/dcerpc.py | 83 +- source4/librpc/rpc/dcerpc_wrap.c | 3395 -------------------------- source4/librpc/rpc/pyrpc.c | 156 ++ source4/librpc/rpc/pyrpc.h | 2 + source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 12 +- 8 files changed, 204 insertions(+), 3616 deletions(-) delete mode 100644 source4/librpc/rpc/dcerpc.i delete mode 100644 source4/librpc/rpc/dcerpc_wrap.c create mode 100644 source4/librpc/rpc/pyrpc.c diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index c7cbf27667..2943c7b516 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -607,103 +607,102 @@ PUBLIC_HEADERS += $(addprefix $(librpcsrcdir)/, rpc/dcerpc.h \ gen_ndr/epmapper.h gen_ndr/ndr_epmapper.h gen_ndr/ndr_epmapper_c.h) -[PYTHON::swig_dcerpc] -LIBRARY_REALNAME = samba/dcerpc/_dcerpc.$(SHLIBEXT) -PUBLIC_DEPENDENCIES = LIBCLI_SMB NDR_MISC LIBSAMBA-UTIL LIBSAMBA-HOSTCONFIG dcerpc_samr RPC_NDR_LSA DYNCONFIG +[PYTHON::python_dcerpc] +LIBRARY_REALNAME = samba/dcerpc/base.$(SHLIBEXT) +PUBLIC_DEPENDENCIES = LIBCLI_SMB NDR_MISC LIBSAMBA-UTIL LIBSAMBA-HOSTCONFIG dcerpc_samr RPC_NDR_LSA DYNCONFIG swig_credentials param -swig_dcerpc_OBJ_FILES = $(dcerpcsrcdir)/dcerpc_wrap.o +python_dcerpc_OBJ_FILES = $(dcerpcsrcdir)/pyrpc.o $(eval $(call python_py_module_template,samba/dcerpc/__init__.py,$(dcerpcsrcdir)/dcerpc.py)) -$(swig_dcerpc_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL) [PYTHON::python_echo] LIBRARY_REALNAME = samba/dcerpc/echo.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_ECHO PYTALLOC param swig_credentials +PRIVATE_DEPENDENCIES = RPC_NDR_ECHO PYTALLOC param swig_credentials python_dcerpc python_echo_OBJ_FILES = $(gen_ndrsrcdir)/py_echo.o [PYTHON::python_winreg] LIBRARY_REALNAME = samba/dcerpc/winreg.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_WINREG python_misc PYTALLOC param swig_credentials python_dcerpc_misc python_lsa +PRIVATE_DEPENDENCIES = RPC_NDR_WINREG python_misc PYTALLOC param swig_credentials python_dcerpc_misc python_lsa python_dcerpc python_winreg_OBJ_FILES = $(gen_ndrsrcdir)/py_winreg.o [PYTHON::python_dcerpc_misc] LIBRARY_REALNAME = samba/dcerpc/misc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = PYTALLOC +PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc python_dcerpc_misc_OBJ_FILES = $(gen_ndrsrcdir)/py_misc.o [PYTHON::python_initshutdown] LIBRARY_REALNAME = samba/dcerpc/initshutdown.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_INITSHUTDOWN PYTALLOC param swig_credentials python_lsa python_dcerpc_security +PRIVATE_DEPENDENCIES = RPC_NDR_INITSHUTDOWN PYTALLOC param swig_credentials python_lsa python_dcerpc_security python_dcerpc python_initshutdown_OBJ_FILES = $(gen_ndrsrcdir)/py_initshutdown.o [PYTHON::python_epmapper] LIBRARY_REALNAME = samba/dcerpc/epmapper.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = dcerpc PYTALLOC param swig_credentials python_dcerpc_misc +PRIVATE_DEPENDENCIES = dcerpc PYTALLOC param swig_credentials python_dcerpc_misc python_dcerpc python_epmapper_OBJ_FILES = $(gen_ndrsrcdir)/py_epmapper.o [PYTHON::python_mgmt] LIBRARY_REALNAME = samba/dcerpc/mgmt.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = PYTALLOC param swig_credentials dcerpc python_dcerpc_misc +PRIVATE_DEPENDENCIES = PYTALLOC param swig_credentials dcerpc python_dcerpc_misc python_dcerpc python_mgmt_OBJ_FILES = $(gen_ndrsrcdir)/py_mgmt.o [PYTHON::python_atsvc] LIBRARY_REALNAME = samba/dcerpc/atsvc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = dcerpc_atsvc PYTALLOC param swig_credentials +PRIVATE_DEPENDENCIES = dcerpc_atsvc PYTALLOC param swig_credentials python_dcerpc python_atsvc_OBJ_FILES = $(gen_ndrsrcdir)/py_atsvc.o [PYTHON::python_samr] LIBRARY_REALNAME = samba/dcerpc/samr.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = dcerpc_samr PYTALLOC python_dcerpc_security python_lsa python_dcerpc_misc swig_credentials param +PRIVATE_DEPENDENCIES = dcerpc_samr PYTALLOC python_dcerpc_security python_lsa python_dcerpc_misc swig_credentials param python_dcerpc python_samr_OBJ_FILES = $(gen_ndrsrcdir)/py_samr.o [PYTHON::python_svcctl] LIBRARY_REALNAME = samba/dcerpc/svcctl.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_SVCCTL PYTALLOC param swig_credentials python_dcerpc_misc +PRIVATE_DEPENDENCIES = RPC_NDR_SVCCTL PYTALLOC param swig_credentials python_dcerpc_misc python_dcerpc python_svcctl_OBJ_FILES = $(gen_ndrsrcdir)/py_svcctl.o [PYTHON::python_lsa] LIBRARY_REALNAME = samba/dcerpc/lsa.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_LSA PYTALLOC param swig_credentials python_dcerpc_security +PRIVATE_DEPENDENCIES = RPC_NDR_LSA PYTALLOC param swig_credentials python_dcerpc_security python_dcerpc python_lsa_OBJ_FILES = $(gen_ndrsrcdir)/py_lsa.o [PYTHON::python_wkssvc] LIBRARY_REALNAME = samba/dcerpc/wkssvc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_WKSSVC PYTALLOC param swig_credentials python_lsa python_dcerpc_security +PRIVATE_DEPENDENCIES = RPC_NDR_WKSSVC PYTALLOC param swig_credentials python_lsa python_dcerpc_security python_dcerpc python_wkssvc_OBJ_FILES = $(gen_ndrsrcdir)/py_wkssvc.o [PYTHON::python_dfs] LIBRARY_REALNAME = samba/dcerpc/dfs.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_DFS PYTALLOC param swig_credentials python_dcerpc_misc +PRIVATE_DEPENDENCIES = RPC_NDR_DFS PYTALLOC param swig_credentials python_dcerpc_misc python_dcerpc python_dfs_OBJ_FILES = $(gen_ndrsrcdir)/py_dfs.o [PYTHON::python_unixinfo] LIBRARY_REALNAME = samba/dcerpc/unixinfo.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_UNIXINFO PYTALLOC param swig_credentials python_dcerpc_security python_dcerpc_misc +PRIVATE_DEPENDENCIES = RPC_NDR_UNIXINFO PYTALLOC param swig_credentials python_dcerpc_security python_dcerpc_misc python_dcerpc python_unixinfo_OBJ_FILES = $(gen_ndrsrcdir)/py_unixinfo.o [PYTHON::python_drsuapi] LIBRARY_REALNAME = samba/dcerpc/drsuapi.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = RPC_NDR_DRSUAPI PYTALLOC param swig_credentials python_dcerpc_misc python_dcerpc_security +PRIVATE_DEPENDENCIES = RPC_NDR_DRSUAPI PYTALLOC param swig_credentials python_dcerpc_misc python_dcerpc_security python_dcerpc python_drsuapi_OBJ_FILES = $(gen_ndrsrcdir)/py_drsuapi.o [PYTHON::python_dcerpc_security] LIBRARY_REALNAME = samba/dcerpc/security.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc_misc +PRIVATE_DEPENDENCIES = PYTALLOC python_dcerpc_misc python_dcerpc python_dcerpc_security_OBJ_FILES = $(gen_ndrsrcdir)/py_security.o diff --git a/source4/librpc/rpc/dcerpc.h b/source4/librpc/rpc/dcerpc.h index 805f5463a9..ca6311a4fc 100644 --- a/source4/librpc/rpc/dcerpc.h +++ b/source4/librpc/rpc/dcerpc.h @@ -362,5 +362,13 @@ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, struct epm_tower *tower, struct dcerpc_binding **b_out); +NTSTATUS dcerpc_request(struct dcerpc_pipe *p, + struct GUID *object, + uint16_t opnum, + bool async, + TALLOC_CTX *mem_ctx, + DATA_BLOB *stub_data_in, + DATA_BLOB *stub_data_out); + #endif /* __DCERPC_H__ */ diff --git a/source4/librpc/rpc/dcerpc.i b/source4/librpc/rpc/dcerpc.i deleted file mode 100644 index 2d7c27b07a..0000000000 --- a/source4/librpc/rpc/dcerpc.i +++ /dev/null @@ -1,125 +0,0 @@ -/* Tastes like -*- C -*- */ - -/* - Unix SMB/CIFS implementation. - - Swig interface to librpc functions. - - Copyright (C) Tim Potter 2004 - Copyright (C) Jelmer Vernooij 2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -%define DOCSTRING -"DCE/RPC protocol implementation" -%enddef - -%module(docstring=DOCSTRING) dcerpc - -%{ - -/* This symbol is used in both includes.h and Python.h which causes an - annoying compiler warning. */ - -#ifdef HAVE_FSTAT -#undef HAVE_FSTAT -#endif - -#include "includes.h" -#include "dynconfig.h" -#include "librpc/rpc/dcerpc.h" -#include "param/param.h" - -#undef strcpy - -%} - -%import "../../lib/talloc/talloc.i" -%import "../../auth/credentials/credentials.i" - -%typemap(in,noblock=1, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) { - $1 = &temp_dcerpc_pipe; -} - -%typemap(argout,noblock=1) struct dcerpc_pipe ** { - /* Set REF_ALLOC flag so we don't have to do too much extra - mucking around with ref variables in ndr unmarshalling. */ - - (*$1)->conn->flags |= DCERPC_NDR_REF_ALLOC; - - /* Return swig handle on dcerpc_pipe */ - - $result = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0); -} - -%types(struct dcerpc_pipe *); - -%rename(pipe_connect) dcerpc_pipe_connect; - -NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, - struct dcerpc_pipe **pp, - const char *binding, - const struct ndr_interface_table *table, - struct cli_credentials *credentials, - struct event_context *ev, - struct loadparm_context *lp_ctx); - -%typemap(in,noblock=1) DATA_BLOB * (DATA_BLOB temp_data_blob) { - temp_data_blob.data = PyString_AsString($input); - temp_data_blob.length = PyString_Size($input); - $1 = &temp_data_blob; -} - -const char *dcerpc_server_name(struct dcerpc_pipe *p); - -/* Some typemaps for easier access to resume handles. Really this can - also be done using the uint32 carray functions, but it's a bit of a - hassle. TODO: Fix memory leak here. */ - -%typemap(in,noblock=1) uint32_t *resume_handle { - $1 = malloc(sizeof(*$1)); - *$1 = PyLong_AsLong($input); -} - -%typemap(out,noblock=1) uint32_t *resume_handle { - $result = PyLong_FromLong(*$1); -} - -%typemap(in,noblock=1) struct policy_handle * { - - if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, - SWIG_POINTER_EXCEPTION)) == -1) - return NULL; - - if ($1 == NULL) { - PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle"); - return NULL; - } -} - -/* When returning a policy handle to Python we need to make a copy of - as the talloc context it is created under is destroyed after the - wrapper function returns. TODO: Fix memory leak created here. */ - -%typemap(out,noblock=1) struct policy_handle * { - if ($1) { - struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle)); - memcpy(temp, $1, sizeof(struct policy_handle)); - $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0); - } else { - Py_INCREF(Py_None); - $result = Py_None; - } -} diff --git a/source4/librpc/rpc/dcerpc.py b/source4/librpc/rpc/dcerpc.py index 5c26656230..1a76ecca8e 100644 --- a/source4/librpc/rpc/dcerpc.py +++ b/source4/librpc/rpc/dcerpc.py @@ -1,67 +1,20 @@ -# This file was automatically generated by SWIG (http://www.swig.org). -# Version 1.3.35 +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . # -# Don't modify this file, modify the SWIG interface instead. - -""" -DCE/RPC protocol implementation -""" - -import _dcerpc -import new -new_instancemethod = new.instancemethod -try: - _swig_property = property -except NameError: - pass # Python < 2.2 doesn't have 'property'. -def _swig_setattr_nondynamic(self,class_type,name,value,static=1): - if (name == "thisown"): return self.this.own(value) - if (name == "this"): - if type(value).__name__ == 'PySwigObject': - self.__dict__[name] = value - return - method = class_type.__swig_setmethods__.get(name,None) - if method: return method(self,value) - if (not static) or hasattr(self,name): - self.__dict__[name] = value - else: - raise AttributeError("You cannot add attributes to %s" % self) - -def _swig_setattr(self,class_type,name,value): - return _swig_setattr_nondynamic(self,class_type,name,value,0) - -def _swig_getattr(self,class_type,name): - if (name == "thisown"): return self.this.own() - method = class_type.__swig_getmethods__.get(name,None) - if method: return method(self) - raise AttributeError,name - -def _swig_repr(self): - try: strthis = "proxy of " + self.this.__repr__() - except: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) - -import types -try: - _object = types.ObjectType - _newclass = 1 -except AttributeError: - class _object : pass - _newclass = 0 -del types - - -def _swig_setattr_nondynamic_method(set): - def set_attr(self,name,value): - if (name == "thisown"): return self.this.own(value) - if hasattr(self,name) or (name == "this"): - set(self,name,value) - else: - raise AttributeError("You cannot add attributes to %s" % self) - return set_attr - - -pipe_connect = _dcerpc.pipe_connect -dcerpc_server_name = _dcerpc.dcerpc_server_name - +from base import * diff --git a/source4/librpc/rpc/dcerpc_wrap.c b/source4/librpc/rpc/dcerpc_wrap.c deleted file mode 100644 index ff5cdbd390..0000000000 --- a/source4/librpc/rpc/dcerpc_wrap.c +++ /dev/null @@ -1,3395 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.35 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - -#define SWIGPYTHON -#define SWIG_PYTHON_NO_BUILD_NONE -/* ----------------------------------------------------------------------------- - * This section contains generic SWIG labels for method/variable - * declarations/attributes, and other compiler dependent labels. - * ----------------------------------------------------------------------------- */ - -/* template workaround for compilers that cannot correctly implement the C++ standard */ -#ifndef SWIGTEMPLATEDISAMBIGUATOR -# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) -# define SWIGTEMPLATEDISAMBIGUATOR template -# elif defined(__HP_aCC) -/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ -/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ -# define SWIGTEMPLATEDISAMBIGUATOR template -# else -# define SWIGTEMPLATEDISAMBIGUATOR -# endif -#endif - -/* inline attribute */ -#ifndef SWIGINLINE -# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) -# define SWIGINLINE inline -# else -# define SWIGINLINE -# endif -#endif - -/* attribute recognised by some compilers to avoid 'unused' warnings */ -#ifndef SWIGUNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -# elif defined(__ICC) -# define SWIGUNUSED __attribute__ ((__unused__)) -# else -# define SWIGUNUSED -# endif -#endif - -#ifndef SWIGUNUSEDPARM -# ifdef __cplusplus -# define SWIGUNUSEDPARM(p) -# else -# define SWIGUNUSEDPARM(p) p SWIGUNUSED -# endif -#endif - -/* internal SWIG method */ -#ifndef SWIGINTERN -# define SWIGINTERN static SWIGUNUSED -#endif - -/* internal inline SWIG method */ -#ifndef SWIGINTERNINLINE -# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE -#endif - -/* exporting methods */ -#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) -# ifndef GCC_HASCLASSVISIBILITY -# define GCC_HASCLASSVISIBILITY -# endif -#endif - -#ifndef SWIGEXPORT -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# if defined(STATIC_LINKED) -# define SWIGEXPORT -# else -# define SWIGEXPORT __declspec(dllexport) -# endif -# else -# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) -# define SWIGEXPORT __attribute__ ((visibility("default"))) -# else -# define SWIGEXPORT -# endif -# endif -#endif - -/* calling conventions for Windows */ -#ifndef SWIGSTDCALL -# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# define SWIGSTDCALL __stdcall -# else -# define SWIGSTDCALL -# endif -#endif - -/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ -#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) -# define _CRT_SECURE_NO_DEPRECATE -#endif - -/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ -#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) -# define _SCL_SECURE_NO_DEPRECATE -#endif - - - -/* Python.h has to appear first */ -#include - -/* ----------------------------------------------------------------------------- - * swigrun.swg - * - * This file contains generic CAPI SWIG runtime support for pointer - * type checking. - * ----------------------------------------------------------------------------- */ - -/* This should only be incremented when either the layout of swig_type_info changes, - or for whatever reason, the runtime changes incompatibly */ -#define SWIG_RUNTIME_VERSION "4" - -/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ -#ifdef SWIG_TYPE_TABLE -# define SWIG_QUOTE_STRING(x) #x -# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) -# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) -#else -# define SWIG_TYPE_TABLE_NAME -#endif - -/* - You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for - creating a static or dynamic library from the swig runtime code. - In 99.9% of the cases, swig just needs to declare them as 'static'. - - But only do this if is strictly necessary, ie, if you have problems - with your compiler or so. -*/ - -#ifndef SWIGRUNTIME -# define SWIGRUNTIME SWIGINTERN -#endif - -#ifndef SWIGRUNTIMEINLINE -# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE -#endif - -/* Generic buffer size */ -#ifndef SWIG_BUFFER_SIZE -# define SWIG_BUFFER_SIZE 1024 -#endif - -/* Flags for pointer conversions */ -#define SWIG_POINTER_DISOWN 0x1 -#define SWIG_CAST_NEW_MEMORY 0x2 - -/* Flags for new pointer objects */ -#define SWIG_POINTER_OWN 0x1 - - -/* - Flags/methods for returning states. - - The swig conversion methods, as ConvertPtr, return and integer - that tells if the conversion was successful or not. And if not, - an error code can be returned (see swigerrors.swg for the codes). - - Use the following macros/flags to set or process the returning - states. - - In old swig versions, you usually write code as: - - if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { - // success code - } else { - //fail code - } - - Now you can be more explicit as: - - int res = SWIG_ConvertPtr(obj,vptr,ty.flags); - if (SWIG_IsOK(res)) { - // success code - } else { - // fail code - } - - that seems to be the same, but now you can also do - - Type *ptr; - int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); - if (SWIG_IsOK(res)) { - // success code - if (SWIG_IsNewObj(res) { - ... - delete *ptr; - } else { - ... - } - } else { - // fail code - } - - I.e., now SWIG_ConvertPtr can return new objects and you can - identify the case and take care of the deallocation. Of course that - requires also to SWIG_ConvertPtr to return new result values, as - - int SWIG_ConvertPtr(obj, ptr,...) { - if () { - if () { - *ptr = ; - return SWIG_NEWOBJ; - } else { - *ptr = ; - return SWIG_OLDOBJ; - } - } else { - return SWIG_BADOBJ; - } - } - - Of course, returning the plain '0(success)/-1(fail)' still works, but you can be - more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the - swig errors code. - - Finally, if the SWIG_CASTRANK_MODE is enabled, the result code - allows to return the 'cast rank', for example, if you have this - - int food(double) - int fooi(int); - - and you call - - food(1) // cast rank '1' (1 -> 1.0) - fooi(1) // cast rank '0' - - just use the SWIG_AddCast()/SWIG_CheckState() - - - */ -#define SWIG_OK (0) -#define SWIG_ERROR (-1) -#define SWIG_IsOK(r) (r >= 0) -#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) - -/* The CastRankLimit says how many bits are used for the cast rank */ -#define SWIG_CASTRANKLIMIT (1 << 8) -/* The NewMask denotes the object was created (using new/malloc) */ -#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) -/* The TmpMask is for in/out typemaps that use temporal objects */ -#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) -/* Simple returning values */ -#define SWIG_BADOBJ (SWIG_ERROR) -#define SWIG_OLDOBJ (SWIG_OK) -#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) -#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) -/* Check, add and del mask methods */ -#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) -#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) -#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) -#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) -#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) -#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) - - -/* Cast-Rank Mode */ -#if defined(SWIG_CASTRANK_MODE) -# ifndef SWIG_TypeRank -# define SWIG_TypeRank unsigned long -# endif -# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ -# define SWIG_MAXCASTRANK (2) -# endif -# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) -# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) -SWIGINTERNINLINE int SWIG_AddCast(int r) { - return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; -} -SWIGINTERNINLINE int SWIG_CheckState(int r) { - return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; -} -#else /* no cast-rank mode */ -# define SWIG_AddCast -# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) -#endif - - - - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void *(*swig_converter_func)(void *, int *); -typedef struct swig_type_info *(*swig_dycast_func)(void **); - -/* Structure to store information on one type */ -typedef struct swig_type_info { - const char *name; /* mangled name of this type */ - const char *str; /* human readable name of this type */ - swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ - struct swig_cast_info *cast; /* linked list of types that can cast into this type */ - void *clientdata; /* language specific type data */ - int owndata; /* flag if the structure owns the clientdata */ -} swig_type_info; - -/* Structure to store a type and conversion function used for casting */ -typedef struct swig_cast_info { - swig_type_info *type; /* pointer to type that is equivalent to this type */ - swig_converter_func converter; /* function to cast the void pointers */ - struct swig_cast_info *next; /* pointer to next cast in linked list */ - struct swig_cast_info *prev; /* pointer to the previous cast */ -} swig_cast_info; - -/* Structure used to store module information - * Each module generates one structure like this, and the runtime collects - * all of these structures and stores them in a circularly linked list.*/ -typedef struct swig_module_info { - swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ - size_t size; /* Number of types in this module */ - struct swig_module_info *next; /* Pointer to next element in circularly linked list */ - swig_type_info **type_initial; /* Array of initially generated type structures */ - swig_cast_info **cast_initial; /* Array of initially generated casting structures */ - void *clientdata; /* Language specific module data */ -} swig_module_info; - -/* - Compare two type names skipping the space characters, therefore - "char*" == "char *" and "Class" == "Class", etc. - - Return 0 when the two name types are equivalent, as in - strncmp, but skipping ' '. -*/ -SWIGRUNTIME int -SWIG_TypeNameComp(const char *f1, const char *l1, - const char *f2, const char *l2) { - for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { - while ((*f1 == ' ') && (f1 != l1)) ++f1; - while ((*f2 == ' ') && (f2 != l2)) ++f2; - if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; - } - return (int)((l1 - f1) - (l2 - f2)); -} - -/* - Check type equivalence in a name list like ||... - Return 0 if not equal, 1 if equal -*/ -SWIGRUNTIME int -SWIG_TypeEquiv(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - -/* - Check type equivalence in a name list like ||... - Return 0 if equal, -1 if nb < tb, 1 if nb > tb -*/ -SWIGRUNTIME int -SWIG_TypeCompare(const char *nb, const char *tb) { - int equiv = 0; - const char* te = tb + strlen(tb); - const char* ne = nb; - while (!equiv && *ne) { - for (nb = ne; *ne; ++ne) { - if (*ne == '|') break; - } - equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; - if (*ne) ++ne; - } - return equiv; -} - - -/* think of this as a c++ template<> or a scheme macro */ -#define SWIG_TypeCheck_Template(comparison, ty) \ - if (ty) { \ - swig_cast_info *iter = ty->cast; \ - while (iter) { \ - if (comparison) { \ - if (iter == ty->cast) return iter; \ - /* Move iter to the top of the linked list */ \ - iter->prev->next = iter->next; \ - if (iter->next) \ - iter->next->prev = iter->prev; \ - iter->next = ty->cast; \ - iter->prev = 0; \ - if (ty->cast) ty->cast->prev = iter; \ - ty->cast = iter; \ - return iter; \ - } \ - iter = iter->next; \ - } \ - } \ - return 0 - -/* - Check the typename -*/ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheck(const char *c, swig_type_info *ty) { - SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty); -} - -/* Same as previous function, except strcmp is replaced with a pointer comparison */ -SWIGRUNTIME swig_cast_info * -SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { - SWIG_TypeCheck_Template(iter->type == from, into); -} - -/* - Cast a pointer up an inheritance hierarchy -*/ -SWIGRUNTIMEINLINE void * -SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { - return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); -} - -/* - Dynamic pointer casting. Down an inheritance hierarchy -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { - swig_type_info *lastty = ty; - if (!ty || !ty->dcast) return ty; - while (ty && (ty->dcast)) { - ty = (*ty->dcast)(ptr); - if (ty) lastty = ty; - } - return lastty; -} - -/* - Return the name associated with this type -*/ -SWIGRUNTIMEINLINE const char * -SWIG_TypeName(const swig_type_info *ty) { - return ty->name; -} - -/* - Return the pretty name associated with this type, - that is an unmangled type name in a form presentable to the user. -*/ -SWIGRUNTIME const char * -SWIG_TypePrettyName(const swig_type_info *type) { - /* The "str" field contains the equivalent pretty names of the - type, separated by vertical-bar characters. We choose - to print the last name, as it is often (?) the most - specific. */ - if (!type) return NULL; - if (type->str != NULL) { - const char *last_name = type->str; - const char *s; - for (s = type->str; *s; s++) - if (*s == '|') last_name = s+1; - return last_name; - } - else - return type->name; -} - -/* - Set the clientdata field for a type -*/ -SWIGRUNTIME void -SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { - swig_cast_info *cast = ti->cast; - /* if (ti->clientdata == clientdata) return; */ - ti->clientdata = clientdata; - - while (cast) { - if (!cast->converter) { - swig_type_info *tc = cast->type; - if (!tc->clientdata) { - SWIG_TypeClientData(tc, clientdata); - } - } - cast = cast->next; - } -} -SWIGRUNTIME void -SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { - SWIG_TypeClientData(ti, clientdata); - ti->owndata = 1; -} - -/* - Search for a swig_type_info structure only by mangled name - Search is a O(log #types) - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_MangledTypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - swig_module_info *iter = start; - do { - if (iter->size) { - register size_t l = 0; - register size_t r = iter->size - 1; - do { - /* since l+r >= 0, we can (>> 1) instead (/ 2) */ - register size_t i = (l + r) >> 1; - const char *iname = iter->types[i]->name; - if (iname) { - register int compare = strcmp(name, iname); - if (compare == 0) { - return iter->types[i]; - } else if (compare < 0) { - if (i) { - r = i - 1; - } else { - break; - } - } else if (compare > 0) { - l = i + 1; - } - } else { - break; /* should never happen */ - } - } while (l <= r); - } - iter = iter->next; - } while (iter != end); - return 0; -} - -/* - Search for a swig_type_info structure for either a mangled name or a human readable name. - It first searches the mangled names of the types, which is a O(log #types) - If a type is not found it then searches the human readable names, which is O(#types). - - We start searching at module start, and finish searching when start == end. - Note: if start == end at the beginning of the function, we go all the way around - the circular list. -*/ -SWIGRUNTIME swig_type_info * -SWIG_TypeQueryModule(swig_module_info *start, - swig_module_info *end, - const char *name) { - /* STEP 1: Search the name field using binary search */ - swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); - if (ret) { - return ret; - } else { - /* STEP 2: If the type hasn't been found, do a complete search - of the str field (the human readable name) */ - swig_module_info *iter = start; - do { - register size_t i = 0; - for (; i < iter->size; ++i) { - if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) - return iter->types[i]; - } - iter = iter->next; - } while (iter != end); - } - - /* neither found a match */ - return 0; -} - -/* - Pack binary data into a string -*/ -SWIGRUNTIME char * -SWIG_PackData(char *c, void *ptr, size_t sz) { - static const char hex[17] = "0123456789abcdef"; - register const unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register unsigned char uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* - Unpack binary data from a string -*/ -SWIGRUNTIME const char * -SWIG_UnpackData(const char *c, void *ptr, size_t sz) { - register unsigned char *u = (unsigned char *) ptr; - register const unsigned char *eu = u + sz; - for (; u != eu; ++u) { - register char d = *(c++); - register unsigned char uu; - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - else - return (char *) 0; - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - else - return (char *) 0; - *u = uu; - } - return c; -} - -/* - Pack 'void *' into a string buffer. -*/ -SWIGRUNTIME char * -SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { - char *r = buff; - if ((2*sizeof(void *) + 2) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,&ptr,sizeof(void *)); - if (strlen(name) + 1 > (bsz - (r - buff))) return 0; - strcpy(r,name); - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - *ptr = (void *) 0; - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sizeof(void *)); -} - -SWIGRUNTIME char * -SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { - char *r = buff; - size_t lname = (name ? strlen(name) : 0); - if ((2*sz + 2 + lname) > bsz) return 0; - *(r++) = '_'; - r = SWIG_PackData(r,ptr,sz); - if (lname) { - strncpy(r,name,lname+1); - } else { - *r = 0; - } - return buff; -} - -SWIGRUNTIME const char * -SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { - if (*c != '_') { - if (strcmp(c,"NULL") == 0) { - memset(ptr,0,sz); - return name; - } else { - return 0; - } - } - return SWIG_UnpackData(++c,ptr,sz); -} - -#ifdef __cplusplus -} -#endif - -/* Errors in SWIG */ -#define SWIG_UnknownError -1 -#define SWIG_IOError -2 -#define SWIG_RuntimeError -3 -#define SWIG_IndexError -4 -#define SWIG_TypeError -5 -#define SWIG_DivisionByZero -6 -#define SWIG_OverflowError -7 -#define SWIG_SyntaxError -8 -#define SWIG_ValueError -9 -#define SWIG_SystemError -10 -#define SWIG_AttributeError -11 -#define SWIG_MemoryError -12 -#define SWIG_NullReferenceError -13 - - - - -/* Add PyOS_snprintf for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) -# define PyOS_snprintf _snprintf -# else -# define PyOS_snprintf snprintf -# endif -#endif - -/* A crude PyString_FromFormat implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 - -#ifndef SWIG_PYBUFFER_SIZE -# define SWIG_PYBUFFER_SIZE 1024 -#endif - -static PyObject * -PyString_FromFormat(const char *fmt, ...) { - va_list ap; - char buf[SWIG_PYBUFFER_SIZE * 2]; - int res; - va_start(ap, fmt); - res = vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); -} -#endif - -/* Add PyObject_Del for old Pythons */ -#if PY_VERSION_HEX < 0x01060000 -# define PyObject_Del(op) PyMem_DEL((op)) -#endif -#ifndef PyObject_DEL -# define PyObject_DEL PyObject_Del -#endif - -/* A crude PyExc_StopIteration exception for old Pythons */ -#if PY_VERSION_HEX < 0x02020000 -# ifndef PyExc_StopIteration -# define PyExc_StopIteration PyExc_RuntimeError -# endif -# ifndef PyObject_GenericGetAttr -# define PyObject_GenericGetAttr 0 -# endif -#endif -/* Py_NotImplemented is defined in 2.1 and up. */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef Py_NotImplemented -# define Py_NotImplemented PyExc_RuntimeError -# endif -#endif - - -/* A crude PyString_AsStringAndSize implementation for old Pythons */ -#if PY_VERSION_HEX < 0x02010000 -# ifndef PyString_AsStringAndSize -# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} -# endif -#endif - -/* PySequence_Size for old Pythons */ -#if PY_VERSION_HEX < 0x02000000 -# ifndef PySequence_Size -# define PySequence_Size PySequence_Length -# endif -#endif - - -/* PyBool_FromLong for old Pythons */ -#if PY_VERSION_HEX < 0x02030000 -static -PyObject *PyBool_FromLong(long ok) -{ - PyObject *result = ok ? Py_True : Py_False; - Py_INCREF(result); - return result; -} -#endif - -/* Py_ssize_t for old Pythons */ -/* This code is as recommended by: */ -/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) -typedef int Py_ssize_t; -# define PY_SSIZE_T_MAX INT_MAX -# define PY_SSIZE_T_MIN INT_MIN -#endif - -/* ----------------------------------------------------------------------------- - * error manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIME PyObject* -SWIG_Python_ErrorType(int code) { - PyObject* type = 0; - switch(code) { - case SWIG_MemoryError: - type = PyExc_MemoryError; - break; - case SWIG_IOError: - type = PyExc_IOError; - break; - case SWIG_RuntimeError: - type = PyExc_RuntimeError; - break; - case SWIG_IndexError: - type = PyExc_IndexError; - break; - case SWIG_TypeError: - type = PyExc_TypeError; - break; - case SWIG_DivisionByZero: - type = PyExc_ZeroDivisionError; - break; - case SWIG_OverflowError: - type = PyExc_OverflowError; - break; - case SWIG_SyntaxError: - type = PyExc_SyntaxError; - break; - case SWIG_ValueError: - type = PyExc_ValueError; - break; - case SWIG_SystemError: - type = PyExc_SystemError; - break; - case SWIG_AttributeError: - type = PyExc_AttributeError; - break; - default: - type = PyExc_RuntimeError; - } - return type; -} - - -SWIGRUNTIME void -SWIG_Python_AddErrorMsg(const char* mesg) -{ - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - - if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject *old_str = PyObject_Str(value); - PyErr_Clear(); - Py_XINCREF(type); - PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); - Py_DECREF(old_str); - Py_DECREF(value); - } else { - PyErr_SetString(PyExc_RuntimeError, mesg); - } -} - - - -#if defined(SWIG_PYTHON_NO_THREADS) -# if defined(SWIG_PYTHON_THREADS) -# undef SWIG_PYTHON_THREADS -# endif -#endif -#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ -# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) -# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ -# define SWIG_PYTHON_USE_GIL -# endif -# endif -# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ -# ifndef SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() -# endif -# ifdef __cplusplus /* C++ code */ - class SWIG_Python_Thread_Block { - bool status; - PyGILState_STATE state; - public: - void end() { if (status) { PyGILState_Release(state); status = false;} } - SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} - ~SWIG_Python_Thread_Block() { end(); } - }; - class SWIG_Python_Thread_Allow { - bool status; - PyThreadState *save; - public: - void end() { if (status) { PyEval_RestoreThread(save); status = false; }} - SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} - ~SWIG_Python_Thread_Allow() { end(); } - }; -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block -# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow -# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() -# else /* C code */ -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() -# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() -# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) -# endif -# else /* Old thread way, not implemented, user must provide it */ -# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) -# define SWIG_PYTHON_INITIALIZE_THREADS -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) -# define SWIG_PYTHON_THREAD_END_BLOCK -# endif -# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# endif -# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) -# define SWIG_PYTHON_THREAD_END_ALLOW -# endif -# endif -#else /* No thread support */ -# define SWIG_PYTHON_INITIALIZE_THREADS -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK -# define SWIG_PYTHON_THREAD_END_BLOCK -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW -# define SWIG_PYTHON_THREAD_END_ALLOW -#endif - -/* ----------------------------------------------------------------------------- - * Python API portion that goes into the runtime - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* ----------------------------------------------------------------------------- - * Constant declarations - * ----------------------------------------------------------------------------- */ - -/* Constant Types */ -#define SWIG_PY_POINTER 4 -#define SWIG_PY_BINARY 5 - -/* Constant information structure */ -typedef struct swig_const_info { - int type; - char *name; - long lvalue; - double dvalue; - void *pvalue; - swig_type_info **ptype; -} swig_const_info; - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - - -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * pyrun.swg - * - * This file contains the runtime support for Python modules - * and includes code for managing global variables and pointer - * type checking. - * - * ----------------------------------------------------------------------------- */ - -/* Common SWIG API */ - -/* for raw pointers */ -#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) -#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) -#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) -#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags) -#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) -#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) -#define swig_owntype int - -/* for raw packed data */ -#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - -/* for class or struct pointers */ -#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) -#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) - -/* for C or C++ function pointers */ -#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) -#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0) - -/* for C++ member pointers, ie, member methods */ -#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) -#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) - - -/* Runtime API */ - -#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() -#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) -#define SWIG_NewClientData(obj) PySwigClientData_New(obj) - -#define SWIG_SetErrorObj SWIG_Python_SetErrorObj -#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg -#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) -#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) -#define SWIG_fail goto fail - - -/* Runtime API implementation */ - -/* Error manipulation */ - -SWIGINTERN void -SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetObject(errtype, obj); - Py_DECREF(obj); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -SWIGINTERN void -SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { - SWIG_PYTHON_THREAD_BEGIN_BLOCK; - PyErr_SetString(errtype, (char *) msg); - SWIG_PYTHON_THREAD_END_BLOCK; -} - -#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) - -/* Set a constant value */ - -SWIGINTERN void -SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { - PyDict_SetItemString(d, (char*) name, obj); - Py_DECREF(obj); -} - -/* Append a value to the result obj */ - -SWIGINTERN PyObject* -SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { -#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyList_Check(result)) { - PyObject *o2 = result; - result = PyList_New(1); - PyList_SetItem(result, 0, o2); - } - PyList_Append(result,obj); - Py_DECREF(obj); - } - return result; -#else - PyObject* o2; - PyObject* o3; - if (!result) { - result = obj; - } else if (result == Py_None) { - Py_DECREF(result); - result = obj; - } else { - if (!PyTuple_Check(result)) { - o2 = result; - result = PyTuple_New(1); - PyTuple_SET_ITEM(result, 0, o2); - } - o3 = PyTuple_New(1); - PyTuple_SET_ITEM(o3, 0, obj); - o2 = result; - result = PySequence_Concat(o2, o3); - Py_DECREF(o2); - Py_DECREF(o3); - } - return result; -#endif -} - -/* Unpack the argument tuple */ - -SWIGINTERN int -SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) -{ - if (!args) { - if (!min && !max) { - return 1; - } else { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", - name, (min == max ? "" : "at least "), (int)min); - return 0; - } - } - if (!PyTuple_Check(args)) { - PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); - return 0; - } else { - register Py_ssize_t l = PyTuple_GET_SIZE(args); - if (l < min) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at least "), (int)min, (int)l); - return 0; - } else if (l > max) { - PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", - name, (min == max ? "" : "at most "), (int)max, (int)l); - return 0; - } else { - register int i; - for (i = 0; i < l; ++i) { - objs[i] = PyTuple_GET_ITEM(args, i); - } - for (; l < max; ++l) { - objs[l] = 0; - } - return i + 1; - } - } -} - -/* A functor is a function object with one single object argument */ -#if PY_VERSION_HEX >= 0x02020000 -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); -#else -#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); -#endif - -/* - Helper for static pointer initialization for both C and C++ code, for example - static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); -*/ -#ifdef __cplusplus -#define SWIG_STATIC_POINTER(var) var -#else -#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var -#endif - -/* ----------------------------------------------------------------------------- - * Pointer declarations - * ----------------------------------------------------------------------------- */ - -/* Flags for new pointer objects */ -#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) -#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) - -#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* cc-mode */ -#endif -#endif - -/* How to access Py_None */ -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -# ifndef SWIG_PYTHON_NO_BUILD_NONE -# ifndef SWIG_PYTHON_BUILD_NONE -# define SWIG_PYTHON_BUILD_NONE -# endif -# endif -#endif - -#ifdef SWIG_PYTHON_BUILD_NONE -# ifdef Py_None -# undef Py_None -# define Py_None SWIG_Py_None() -# endif -SWIGRUNTIMEINLINE PyObject * -_SWIG_Py_None(void) -{ - PyObject *none = Py_BuildValue((char*)""); - Py_DECREF(none); - return none; -} -SWIGRUNTIME PyObject * -SWIG_Py_None(void) -{ - static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); - return none; -} -#endif - -/* The python void return value */ - -SWIGRUNTIMEINLINE PyObject * -SWIG_Py_Void(void) -{ - PyObject *none = Py_None; - Py_INCREF(none); - return none; -} - -/* PySwigClientData */ - -typedef struct { - PyObject *klass; - PyObject *newraw; - PyObject *newargs; - PyObject *destroy; - int delargs; - int implicitconv; -} PySwigClientData; - -SWIGRUNTIMEINLINE int -SWIG_Python_CheckImplicit(swig_type_info *ty) -{ - PySwigClientData *data = (PySwigClientData *)ty->clientdata; - return data ? data->implicitconv : 0; -} - -SWIGRUNTIMEINLINE PyObject * -SWIG_Python_ExceptionType(swig_type_info *desc) { - PySwigClientData *data = desc ? (PySwigClientData *) desc->clientdata : 0; - PyObject *klass = data ? data->klass : 0; - return (klass ? klass : PyExc_RuntimeError); -} - - -SWIGRUNTIME PySwigClientData * -PySwigClientData_New(PyObject* obj) -{ - if (!obj) { - return 0; - } else { - PySwigClientData *data = (PySwigClientData *)malloc(sizeof(PySwigClientData)); - /* the klass element */ - data->klass = obj; - Py_INCREF(data->klass); - /* the newraw method and newargs arguments used to create a new raw instance */ - if (PyClass_Check(obj)) { - data->newraw = 0; - data->newargs = obj; - Py_INCREF(obj); - } else { -#if (PY_VERSION_HEX < 0x02020000) - data->newraw = 0; -#else - data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); -#endif - if (data->newraw) { - Py_INCREF(data->newraw); - data->newargs = PyTuple_New(1); - PyTuple_SetItem(data->newargs, 0, obj); - } else { - data->newargs = obj; - } - Py_INCREF(data->newargs); - } - /* the destroy method, aka as the C++ delete method */ - data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); - if (PyErr_Occurred()) { - PyErr_Clear(); - data->destroy = 0; - } - if (data->destroy) { - int flags; - Py_INCREF(data->destroy); - flags = PyCFunction_GET_FLAGS(data->destroy); -#ifdef METH_O - data->delargs = !(flags & (METH_O)); -#else - data->delargs = 0; -#endif - } else { - data->delargs = 0; - } - data->implicitconv = 0; - return data; - } -} - -SWIGRUNTIME void -PySwigClientData_Del(PySwigClientData* data) -{ - Py_XDECREF(data->newraw); - Py_XDECREF(data->newargs); - Py_XDECREF(data->destroy); -} - -/* =============== PySwigObject =====================*/ - -typedef struct { - PyObject_HEAD - void *ptr; - swig_type_info *ty; - int own; - PyObject *next; -} PySwigObject; - -SWIGRUNTIME PyObject * -PySwigObject_long(PySwigObject *v) -{ - return PyLong_FromVoidPtr(v->ptr); -} - -SWIGRUNTIME PyObject * -PySwigObject_format(const char* fmt, PySwigObject *v) -{ - PyObject *res = NULL; - PyObject *args = PyTuple_New(1); - if (args) { - if (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0) { - PyObject *ofmt = PyString_FromString(fmt); - if (ofmt) { - res = PyString_Format(ofmt,args); - Py_DECREF(ofmt); - } - Py_DECREF(args); - } - } - return res; -} - -SWIGRUNTIME PyObject * -PySwigObject_oct(PySwigObject *v) -{ - return PySwigObject_format("%o",v); -} - -SWIGRUNTIME PyObject * -PySwigObject_hex(PySwigObject *v) -{ - return PySwigObject_format("%x",v); -} - -SWIGRUNTIME PyObject * -#ifdef METH_NOARGS -PySwigObject_repr(PySwigObject *v) -#else -PySwigObject_repr(PySwigObject *v, PyObject *args) -#endif -{ - const char *name = SWIG_TypePrettyName(v->ty); - PyObject *hex = PySwigObject_hex(v); - PyObject *repr = PyString_FromFormat("", name, PyString_AsString(hex)); - Py_DECREF(hex); - if (v->next) { -#ifdef METH_NOARGS - PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next); -#else - PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next, args); -#endif - PyString_ConcatAndDel(&repr,nrep); - } - return repr; -} - -SWIGRUNTIME int -PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ -#ifdef METH_NOARGS - PyObject *repr = PySwigObject_repr(v); -#else - PyObject *repr = PySwigObject_repr(v, NULL); -#endif - if (repr) { - fputs(PyString_AsString(repr), fp); - Py_DECREF(repr); - return 0; - } else { - return 1; - } -} - -SWIGRUNTIME PyObject * -PySwigObject_str(PySwigObject *v) -{ - char result[SWIG_BUFFER_SIZE]; - return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? - PyString_FromString(result) : 0; -} - -SWIGRUNTIME int -PySwigObject_compare(PySwigObject *v, PySwigObject *w) -{ - void *i = v->ptr; - void *j = w->ptr; - return (i < j) ? -1 : ((i > j) ? 1 : 0); -} - -SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); - -SWIGRUNTIME PyTypeObject* -PySwigObject_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); - return type; -} - -SWIGRUNTIMEINLINE int -PySwigObject_Check(PyObject *op) { - return ((op)->ob_type == PySwigObject_type()) - || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0); -} - -SWIGRUNTIME PyObject * -PySwigObject_New(void *ptr, swig_type_info *ty, int own); - -SWIGRUNTIME void -PySwigObject_dealloc(PyObject *v) -{ - PySwigObject *sobj = (PySwigObject *) v; - PyObject *next = sobj->next; - if (sobj->own == SWIG_POINTER_OWN) { - swig_type_info *ty = sobj->ty; - PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; - PyObject *destroy = data ? data->destroy : 0; - if (destroy) { - /* destroy is always a VARARGS method */ - PyObject *res; - if (data->delargs) { - /* we need to create a temporal object to carry the destroy operation */ - PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); - } else { - PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); - PyObject *mself = PyCFunction_GET_SELF(destroy); - res = ((*meth)(mself, v)); - } - Py_XDECREF(res); - } -#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) - else { - const char *name = SWIG_TypePrettyName(ty); - printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); - } -#endif - } - Py_XDECREF(next); - PyObject_DEL(v); -} - -SWIGRUNTIME PyObject* -PySwigObject_append(PyObject* v, PyObject* next) -{ - PySwigObject *sobj = (PySwigObject *) v; -#ifndef METH_O - PyObject *tmp = 0; - if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; - next = tmp; -#endif - if (!PySwigObject_Check(next)) { - return NULL; - } - sobj->next = next; - Py_INCREF(next); - return SWIG_Py_Void(); -} - -SWIGRUNTIME PyObject* -#ifdef METH_NOARGS -PySwigObject_next(PyObject* v) -#else -PySwigObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *) v; - if (sobj->next) { - Py_INCREF(sobj->next); - return sobj->next; - } else { - return SWIG_Py_Void(); - } -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -PySwigObject_disown(PyObject *v) -#else -PySwigObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *)v; - sobj->own = 0; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -#ifdef METH_NOARGS -PySwigObject_acquire(PyObject *v) -#else -PySwigObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) -#endif -{ - PySwigObject *sobj = (PySwigObject *)v; - sobj->own = SWIG_POINTER_OWN; - return SWIG_Py_Void(); -} - -SWIGINTERN PyObject* -PySwigObject_own(PyObject *v, PyObject *args) -{ - PyObject *val = 0; -#if (PY_VERSION_HEX < 0x02020000) - if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) -#else - if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) -#endif - { - return NULL; - } - else - { - PySwigObject *sobj = (PySwigObject *)v; - PyObject *obj = PyBool_FromLong(sobj->own); - if (val) { -#ifdef METH_NOARGS - if (PyObject_IsTrue(val)) { - PySwigObject_acquire(v); - } else { - PySwigObject_disown(v); - } -#else - if (PyObject_IsTrue(val)) { - PySwigObject_acquire(v,args); - } else { - PySwigObject_disown(v,args); - } -#endif - } - return obj; - } -} - -#ifdef METH_O -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)PySwigObject_append, METH_O, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)PySwigObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_NOARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#else -static PyMethodDef -swigobject_methods[] = { - {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, - {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, - {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, - {(char *)"append", (PyCFunction)PySwigObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, - {(char *)"next", (PyCFunction)PySwigObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, - {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_VARARGS, (char *)"returns object representation"}, - {0, 0, 0, 0} -}; -#endif - -#if PY_VERSION_HEX < 0x02020000 -SWIGINTERN PyObject * -PySwigObject_getattr(PySwigObject *sobj,char *name) -{ - return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); -} -#endif - -SWIGRUNTIME PyTypeObject* -_PySwigObject_type(void) { - static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; - - static PyNumberMethods PySwigObject_as_number = { - (binaryfunc)0, /*nb_add*/ - (binaryfunc)0, /*nb_subtract*/ - (binaryfunc)0, /*nb_multiply*/ - (binaryfunc)0, /*nb_divide*/ - (binaryfunc)0, /*nb_remainder*/ - (binaryfunc)0, /*nb_divmod*/ - (ternaryfunc)0,/*nb_power*/ - (unaryfunc)0, /*nb_negative*/ - (unaryfunc)0, /*nb_positive*/ - (unaryfunc)0, /*nb_absolute*/ - (inquiry)0, /*nb_nonzero*/ - 0, /*nb_invert*/ - 0, /*nb_lshift*/ - 0, /*nb_rshift*/ - 0, /*nb_and*/ - 0, /*nb_xor*/ - 0, /*nb_or*/ - (coercion)0, /*nb_coerce*/ - (unaryfunc)PySwigObject_long, /*nb_int*/ - (unaryfunc)PySwigObject_long, /*nb_long*/ - (unaryfunc)0, /*nb_float*/ - (unaryfunc)PySwigObject_oct, /*nb_oct*/ - (unaryfunc)PySwigObject_hex, /*nb_hex*/ -#if PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ -#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ -#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ - 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ -#endif - }; - - static PyTypeObject pyswigobject_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - (char *)"PySwigObject", /* tp_name */ - sizeof(PySwigObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PySwigObject_dealloc, /* tp_dealloc */ - (printfunc)PySwigObject_print, /* tp_print */ -#if PY_VERSION_HEX < 0x02020000 - (getattrfunc)PySwigObject_getattr, /* tp_getattr */ -#else - (getattrfunc)0, /* tp_getattr */ -#endif - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)PySwigObject_compare, /* tp_compare */ - (reprfunc)PySwigObject_repr, /* tp_repr */ - &PySwigObject_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)PySwigObject_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigobject_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - swigobject_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - pyswigobject_type = tmp; - pyswigobject_type.ob_type = &PyType_Type; - type_init = 1; - } - return &pyswigobject_type; -} - -SWIGRUNTIME PyObject * -PySwigObject_New(void *ptr, swig_type_info *ty, int own) -{ - PySwigObject *sobj = PyObject_NEW(PySwigObject, PySwigObject_type()); - if (sobj) { - sobj->ptr = ptr; - sobj->ty = ty; - sobj->own = own; - sobj->next = 0; - } - return (PyObject *)sobj; -} - -/* ----------------------------------------------------------------------------- - * Implements a simple Swig Packed type, and use it instead of string - * ----------------------------------------------------------------------------- */ - -typedef struct { - PyObject_HEAD - void *pack; - swig_type_info *ty; - size_t size; -} PySwigPacked; - -SWIGRUNTIME int -PySwigPacked_print(PySwigPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) -{ - char result[SWIG_BUFFER_SIZE]; - fputs("pack, v->size, 0, sizeof(result))) { - fputs("at ", fp); - fputs(result, fp); - } - fputs(v->ty->name,fp); - fputs(">", fp); - return 0; -} - -SWIGRUNTIME PyObject * -PySwigPacked_repr(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { - return PyString_FromFormat("", result, v->ty->name); - } else { - return PyString_FromFormat("", v->ty->name); - } -} - -SWIGRUNTIME PyObject * -PySwigPacked_str(PySwigPacked *v) -{ - char result[SWIG_BUFFER_SIZE]; - if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ - return PyString_FromFormat("%s%s", result, v->ty->name); - } else { - return PyString_FromString(v->ty->name); - } -} - -SWIGRUNTIME int -PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) -{ - size_t i = v->size; - size_t j = w->size; - int s = (i < j) ? -1 : ((i > j) ? 1 : 0); - return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); -} - -SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); - -SWIGRUNTIME PyTypeObject* -PySwigPacked_type(void) { - static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); - return type; -} - -SWIGRUNTIMEINLINE int -PySwigPacked_Check(PyObject *op) { - return ((op)->ob_type == _PySwigPacked_type()) - || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0); -} - -SWIGRUNTIME void -PySwigPacked_dealloc(PyObject *v) -{ - if (PySwigPacked_Check(v)) { - PySwigPacked *sobj = (PySwigPacked *) v; - free(sobj->pack); - } - PyObject_DEL(v); -} - -SWIGRUNTIME PyTypeObject* -_PySwigPacked_type(void) { - static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; - static PyTypeObject pyswigpacked_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ - (char *)"PySwigPacked", /* tp_name */ - sizeof(PySwigPacked), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)PySwigPacked_dealloc, /* tp_dealloc */ - (printfunc)PySwigPacked_print, /* tp_print */ - (getattrfunc)0, /* tp_getattr */ - (setattrfunc)0, /* tp_setattr */ - (cmpfunc)PySwigPacked_compare, /* tp_compare */ - (reprfunc)PySwigPacked_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)0, /* tp_hash */ - (ternaryfunc)0, /* tp_call */ - (reprfunc)PySwigPacked_str, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - swigpacked_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ - 0, /* tp_bases */ - 0, /* tp_mro */ - 0, /* tp_cache */ - 0, /* tp_subclasses */ - 0, /* tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - pyswigpacked_type = tmp; - pyswigpacked_type.ob_type = &PyType_Type; - type_init = 1; - } - return &pyswigpacked_type; -} - -SWIGRUNTIME PyObject * -PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty) -{ - PySwigPacked *sobj = PyObject_NEW(PySwigPacked, PySwigPacked_type()); - if (sobj) { - void *pack = malloc(size); - if (pack) { - memcpy(pack, ptr, size); - sobj->pack = pack; - sobj->ty = ty; - sobj->size = size; - } else { - PyObject_DEL((PyObject *) sobj); - sobj = 0; - } - } - return (PyObject *) sobj; -} - -SWIGRUNTIME swig_type_info * -PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) -{ - if (PySwigPacked_Check(obj)) { - PySwigPacked *sobj = (PySwigPacked *)obj; - if (sobj->size != size) return 0; - memcpy(ptr, sobj->pack, size); - return sobj->ty; - } else { - return 0; - } -} - -/* ----------------------------------------------------------------------------- - * pointers/data manipulation - * ----------------------------------------------------------------------------- */ - -SWIGRUNTIMEINLINE PyObject * -_SWIG_This(void) -{ - return PyString_FromString("this"); -} - -SWIGRUNTIME PyObject * -SWIG_This(void) -{ - static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); - return swig_this; -} - -/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ - -SWIGRUNTIME PySwigObject * -SWIG_Python_GetSwigThis(PyObject *pyobj) -{ - if (PySwigObject_Check(pyobj)) { - return (PySwigObject *) pyobj; - } else { - PyObject *obj = 0; -#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) - if (PyInstance_Check(pyobj)) { - obj = _PyInstance_Lookup(pyobj, SWIG_This()); - } else { - PyObject **dictptr = _PyObject_GetDictPtr(pyobj); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; - } else { -#ifdef PyWeakref_CheckProxy - if (PyWeakref_CheckProxy(pyobj)) { - PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); - return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; - } -#endif - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } - } - } -#else - obj = PyObject_GetAttr(pyobj,SWIG_This()); - if (obj) { - Py_DECREF(obj); - } else { - if (PyErr_Occurred()) PyErr_Clear(); - return 0; - } -#endif - if (obj && !PySwigObject_Check(obj)) { - /* a PyObject is called 'this', try to get the 'real this' - PySwigObject from it */ - return SWIG_Python_GetSwigThis(obj); - } - return (PySwigObject *)obj; - } -} - -/* Acquire a pointer value */ - -SWIGRUNTIME int -SWIG_Python_AcquirePtr(PyObject *obj, int own) { - if (own == SWIG_POINTER_OWN) { - PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); - if (sobj) { - int oldown = sobj->own; - sobj->own = own; - return oldown; - } - } - return 0; -} - -/* Convert a pointer value */ - -SWIGRUNTIME int -SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { - if (!obj) return SWIG_ERROR; - if (obj == Py_None) { - if (ptr) *ptr = 0; - return SWIG_OK; - } else { - PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); - if (own) - *own = 0; - while (sobj) { - void *vptr = sobj->ptr; - if (ty) { - swig_type_info *to = sobj->ty; - if (to == ty) { - /* no type cast needed */ - if (ptr) *ptr = vptr; - break; - } else { - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) { - sobj = (PySwigObject *)sobj->next; - } else { - if (ptr) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - if (newmemory == SWIG_CAST_NEW_MEMORY) { - assert(own); - if (own) - *own = *own | SWIG_CAST_NEW_MEMORY; - } - } - break; - } - } - } else { - if (ptr) *ptr = vptr; - break; - } - } - if (sobj) { - if (own) - *own = *own | sobj->own; - if (flags & SWIG_POINTER_DISOWN) { - sobj->own = 0; - } - return SWIG_OK; - } else { - int res = SWIG_ERROR; - if (flags & SWIG_POINTER_IMPLICIT_CONV) { - PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; - if (data && !data->implicitconv) { - PyObject *klass = data->klass; - if (klass) { - PyObject *impconv; - data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ - impconv = SWIG_Python_CallFunctor(klass, obj); - data->implicitconv = 0; - if (PyErr_Occurred()) { - PyErr_Clear(); - impconv = 0; - } - if (impconv) { - PySwigObject *iobj = SWIG_Python_GetSwigThis(impconv); - if (iobj) { - void *vptr; - res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); - if (SWIG_IsOK(res)) { - if (ptr) { - *ptr = vptr; - /* transfer the ownership to 'ptr' */ - iobj->own = 0; - res = SWIG_AddCast(res); - res = SWIG_AddNewMask(res); - } else { - res = SWIG_AddCast(res); - } - } - } - Py_DECREF(impconv); - } - } - } - } - return res; - } - } -} - -/* Convert a function ptr value */ - -SWIGRUNTIME int -SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { - if (!PyCFunction_Check(obj)) { - return SWIG_ConvertPtr(obj, ptr, ty, 0); - } else { - void *vptr = 0; - - /* here we get the method pointer for callbacks */ - const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); - const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; - if (desc) { - desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; - if (!desc) return SWIG_ERROR; - } - if (ty) { - swig_cast_info *tc = SWIG_TypeCheck(desc,ty); - if (tc) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc,vptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - } else { - return SWIG_ERROR; - } - } else { - *ptr = vptr; - } - return SWIG_OK; - } -} - -/* Convert a packed value value */ - -SWIGRUNTIME int -SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { - swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz); - if (!to) return SWIG_ERROR; - if (ty) { - if (to != ty) { - /* check type cast? */ - swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); - if (!tc) return SWIG_ERROR; - } - } - return SWIG_OK; -} - -/* ----------------------------------------------------------------------------- - * Create a new pointer object - * ----------------------------------------------------------------------------- */ - -/* - Create a new instance object, whitout calling __init__, and set the - 'this' attribute. -*/ - -SWIGRUNTIME PyObject* -SWIG_Python_NewShadowInstance(PySwigClientData *data, PyObject *swig_this) -{ -#if (PY_VERSION_HEX >= 0x02020000) - PyObject *inst = 0; - PyObject *newraw = data->newraw; - if (newraw) { - inst = PyObject_Call(newraw, data->newargs, NULL); - if (inst) { -#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - PyObject *dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - PyDict_SetItem(dict, SWIG_This(), swig_this); - } - } -#else - PyObject *key = SWIG_This(); - PyObject_SetAttr(inst, key, swig_this); -#endif - } - } else { - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - } - return inst; -#else -#if (PY_VERSION_HEX >= 0x02010000) - PyObject *inst; - PyObject *dict = PyDict_New(); - PyDict_SetItem(dict, SWIG_This(), swig_this); - inst = PyInstance_NewRaw(data->newargs, dict); - Py_DECREF(dict); - return (PyObject *) inst; -#else - PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); - if (inst == NULL) { - return NULL; - } - inst->in_class = (PyClassObject *)data->newargs; - Py_INCREF(inst->in_class); - inst->in_dict = PyDict_New(); - if (inst->in_dict == NULL) { - Py_DECREF(inst); - return NULL; - } -#ifdef Py_TPFLAGS_HAVE_WEAKREFS - inst->in_weakreflist = NULL; -#endif -#ifdef Py_TPFLAGS_GC - PyObject_GC_Init(inst); -#endif - PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); - return (PyObject *) inst; -#endif -#endif -} - -SWIGRUNTIME void -SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) -{ - PyObject *dict; -#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) - PyObject **dictptr = _PyObject_GetDictPtr(inst); - if (dictptr != NULL) { - dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - } - PyDict_SetItem(dict, SWIG_This(), swig_this); - return; - } -#endif - dict = PyObject_GetAttrString(inst, (char*)"__dict__"); - PyDict_SetItem(dict, SWIG_This(), swig_this); - Py_DECREF(dict); -} - - -SWIGINTERN PyObject * -SWIG_Python_InitShadowInstance(PyObject *args) { - PyObject *obj[2]; - if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { - return NULL; - } else { - PySwigObject *sthis = SWIG_Python_GetSwigThis(obj[0]); - if (sthis) { - PySwigObject_append((PyObject*) sthis, obj[1]); - } else { - SWIG_Python_SetSwigThis(obj[0], obj[1]); - } - return SWIG_Py_Void(); - } -} - -/* Create a new pointer object */ - -SWIGRUNTIME PyObject * -SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { - if (!ptr) { - return SWIG_Py_Void(); - } else { - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - PyObject *robj = PySwigObject_New(ptr, type, own); - PySwigClientData *clientdata = type ? (PySwigClientData *)(type->clientdata) : 0; - if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { - PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); - if (inst) { - Py_DECREF(robj); - robj = inst; - } - } - return robj; - } -} - -/* Create a new packed object */ - -SWIGRUNTIMEINLINE PyObject * -SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { - return ptr ? PySwigPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); -} - -/* -----------------------------------------------------------------------------* - * Get type list - * -----------------------------------------------------------------------------*/ - -#ifdef SWIG_LINK_RUNTIME -void *SWIG_ReturnGlobalTypeList(void *); -#endif - -SWIGRUNTIME swig_module_info * -SWIG_Python_GetModule(void) { - static void *type_pointer = (void *)0; - /* first check if module already created */ - if (!type_pointer) { -#ifdef SWIG_LINK_RUNTIME - type_pointer = SWIG_ReturnGlobalTypeList((void *)0); -#else - type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); - if (PyErr_Occurred()) { - PyErr_Clear(); - type_pointer = (void *)0; - } -#endif - } - return (swig_module_info *) type_pointer; -} - -#if PY_MAJOR_VERSION < 2 -/* PyModule_AddObject function was introduced in Python 2.0. The following function - is copied out of Python/modsupport.c in python version 2.3.4 */ -SWIGINTERN int -PyModule_AddObject(PyObject *m, char *name, PyObject *o) -{ - PyObject *dict; - if (!PyModule_Check(m)) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs module as first arg"); - return SWIG_ERROR; - } - if (!o) { - PyErr_SetString(PyExc_TypeError, - "PyModule_AddObject() needs non-NULL value"); - return SWIG_ERROR; - } - - dict = PyModule_GetDict(m); - if (dict == NULL) { - /* Internal error -- modules must have a dict! */ - PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", - PyModule_GetName(m)); - return SWIG_ERROR; - } - if (PyDict_SetItemString(dict, name, o)) - return SWIG_ERROR; - Py_DECREF(o); - return SWIG_OK; -} -#endif - -SWIGRUNTIME void -SWIG_Python_DestroyModule(void *vptr) -{ - swig_module_info *swig_module = (swig_module_info *) vptr; - swig_type_info **types = swig_module->types; - size_t i; - for (i =0; i < swig_module->size; ++i) { - swig_type_info *ty = types[i]; - if (ty->owndata) { - PySwigClientData *data = (PySwigClientData *) ty->clientdata; - if (data) PySwigClientData_Del(data); - } - } - Py_DECREF(SWIG_This()); -} - -SWIGRUNTIME void -SWIG_Python_SetModule(swig_module_info *swig_module) { - static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ - - PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, - swig_empty_runtime_method_table); - PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); - if (pointer && module) { - PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); - } else { - Py_XDECREF(pointer); - } -} - -/* The python cached type query */ -SWIGRUNTIME PyObject * -SWIG_Python_TypeCache(void) { - static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); - return cache; -} - -SWIGRUNTIME swig_type_info * -SWIG_Python_TypeQuery(const char *type) -{ - PyObject *cache = SWIG_Python_TypeCache(); - PyObject *key = PyString_FromString(type); - PyObject *obj = PyDict_GetItem(cache, key); - swig_type_info *descriptor; - if (obj) { - descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); - } else { - swig_module_info *swig_module = SWIG_Python_GetModule(); - descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); - if (descriptor) { - obj = PyCObject_FromVoidPtr(descriptor, NULL); - PyDict_SetItem(cache, key, obj); - Py_DECREF(obj); - } - } - Py_DECREF(key); - return descriptor; -} - -/* - For backward compatibility only -*/ -#define SWIG_POINTER_EXCEPTION 0 -#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) -#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) - -SWIGRUNTIME int -SWIG_Python_AddErrMesg(const char* mesg, int infront) -{ - if (PyErr_Occurred()) { - PyObject *type = 0; - PyObject *value = 0; - PyObject *traceback = 0; - PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject *old_str = PyObject_Str(value); - Py_XINCREF(type); - PyErr_Clear(); - if (infront) { - PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str)); - } else { - PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); - } - Py_DECREF(old_str); - } - return 1; - } else { - return 0; - } -} - -SWIGRUNTIME int -SWIG_Python_ArgFail(int argnum) -{ - if (PyErr_Occurred()) { - /* add information about failing argument */ - char mesg[256]; - PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); - return SWIG_Python_AddErrMesg(mesg, 1); - } else { - return 0; - } -} - -SWIGRUNTIMEINLINE const char * -PySwigObject_GetDesc(PyObject *self) -{ - PySwigObject *v = (PySwigObject *)self; - swig_type_info *ty = v ? v->ty : 0; - return ty ? ty->str : (char*)""; -} - -SWIGRUNTIME void -SWIG_Python_TypeError(const char *type, PyObject *obj) -{ - if (type) { -#if defined(SWIG_COBJECT_TYPES) - if (obj && PySwigObject_Check(obj)) { - const char *otype = (const char *) PySwigObject_GetDesc(obj); - if (otype) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", - type, otype); - return; - } - } else -#endif - { - const char *otype = (obj ? obj->ob_type->tp_name : 0); - if (otype) { - PyObject *str = PyObject_Str(obj); - const char *cstr = str ? PyString_AsString(str) : 0; - if (cstr) { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", - type, otype, cstr); - } else { - PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", - type, otype); - } - Py_XDECREF(str); - return; - } - } - PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); - } else { - PyErr_Format(PyExc_TypeError, "unexpected type is received"); - } -} - - -/* Convert a pointer value, signal an exception on a type mismatch */ -SWIGRUNTIME void * -SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { - void *result; - if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { - PyErr_Clear(); - if (flags & SWIG_POINTER_EXCEPTION) { - SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); - SWIG_Python_ArgFail(argnum); - } - } - return result; -} - - -#ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif -} -#endif - - - -#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) - -#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else - - - -/* -------- TYPES TABLE (BEGIN) -------- */ - -#define SWIGTYPE_p_NTSTATUS swig_types[0] -#define SWIGTYPE_p_TALLOC_CTX swig_types[1] -#define SWIGTYPE_p_char swig_types[2] -#define SWIGTYPE_p_cli_credentials swig_types[3] -#define SWIGTYPE_p_dcerpc_pipe swig_types[4] -#define SWIGTYPE_p_event_context swig_types[5] -#define SWIGTYPE_p_int swig_types[6] -#define SWIGTYPE_p_loadparm_context swig_types[7] -#define SWIGTYPE_p_loadparm_service swig_types[8] -#define SWIGTYPE_p_long_long swig_types[9] -#define SWIGTYPE_p_ndr_interface_table swig_types[10] -#define SWIGTYPE_p_p_dcerpc_pipe swig_types[11] -#define SWIGTYPE_p_param_context swig_types[12] -#define SWIGTYPE_p_param_opt swig_types[13] -#define SWIGTYPE_p_param_section swig_types[14] -#define SWIGTYPE_p_short swig_types[15] -#define SWIGTYPE_p_signed_char swig_types[16] -#define SWIGTYPE_p_unsigned_char swig_types[17] -#define SWIGTYPE_p_unsigned_int swig_types[18] -#define SWIGTYPE_p_unsigned_long_long swig_types[19] -#define SWIGTYPE_p_unsigned_short swig_types[20] -static swig_type_info *swig_types[22]; -static swig_module_info swig_module = {swig_types, 21, 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) - -/* -------- TYPES TABLE (END) -------- */ - -#if (PY_VERSION_HEX <= 0x02000000) -# if !defined(SWIG_PYTHON_CLASSIC) -# error "This python version requires swig to be run with the '-classic' option" -# endif -#endif -#if (PY_VERSION_HEX <= 0x02020000) -# error "This python version requires swig to be run with the '-nomodern' option" -#endif -#if (PY_VERSION_HEX <= 0x02020000) -# error "This python version requires swig to be run with the '-nomodernargs' option" -#endif -#ifndef METH_O -# error "This python version requires swig to be run with the '-nofastunpack' option" -#endif -#ifdef SWIG_TypeQuery -# undef SWIG_TypeQuery -#endif -#define SWIG_TypeQuery SWIG_Python_TypeQuery - -/*----------------------------------------------- - @(target):= _dcerpc.so - ------------------------------------------------*/ -#define SWIG_init init_dcerpc - -#define SWIG_name "_dcerpc" - -#define SWIGVERSION 0x010335 -#define SWIG_VERSION SWIGVERSION - - -#define SWIG_as_voidptr(a) (void *)((const void *)(a)) -#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) - - - -/* This symbol is used in both includes.h and Python.h which causes an - annoying compiler warning. */ - -#ifdef HAVE_FSTAT -#undef HAVE_FSTAT -#endif - -#include "includes.h" -#include "dynconfig.h" -#include "librpc/rpc/dcerpc.h" -#include "param/param.h" - -#undef strcpy - - - -SWIGINTERN swig_type_info* -SWIG_pchar_descriptor(void) -{ - static int init = 0; - static swig_type_info* info = 0; - if (!init) { - info = SWIG_TypeQuery("_p_char"); - init = 1; - } - return info; -} - - -SWIGINTERN int -SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc) -{ - if (PyString_Check(obj)) { - char *cstr; Py_ssize_t len; - PyString_AsStringAndSize(obj, &cstr, &len); - if (cptr) { - if (alloc) { - /* - In python the user should not be able to modify the inner - string representation. To warranty that, if you define - SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string - buffer is always returned. - - The default behavior is just to return the pointer value, - so, be careful. - */ -#if defined(SWIG_PYTHON_SAFE_CSTRINGS) - if (*alloc != SWIG_OLDOBJ) -#else - if (*alloc == SWIG_NEWOBJ) -#endif - { - *cptr = (char *)memcpy((char *)malloc((len + 1)*sizeof(char)), cstr, sizeof(char)*(len + 1)); - *alloc = SWIG_NEWOBJ; - } - else { - *cptr = cstr; - *alloc = SWIG_OLDOBJ; - } - } else { - *cptr = PyString_AsString(obj); - } - } - if (psize) *psize = len + 1; - return SWIG_OK; - } else { - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - if (pchar_descriptor) { - void* vptr = 0; - if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) { - if (cptr) *cptr = (char *) vptr; - if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0; - if (alloc) *alloc = SWIG_OLDOBJ; - return SWIG_OK; - } - } - } - return SWIG_TypeError; -} - - - - - -SWIGINTERNINLINE PyObject * -SWIG_FromCharPtrAndSize(const char* carray, size_t size) -{ - if (carray) { - if (size > INT_MAX) { - swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); - return pchar_descriptor ? - SWIG_NewPointerObj((char *)(carray), pchar_descriptor, 0) : SWIG_Py_Void(); - } else { - return PyString_FromStringAndSize(carray, (int)(size)); - } - } else { - return SWIG_Py_Void(); - } -} - - -SWIGINTERNINLINE PyObject * -SWIG_FromCharPtr(const char *cptr) -{ - return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); -} - -#ifdef __cplusplus -extern "C" { -#endif -SWIGINTERN PyObject *_wrap_pipe_connect(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - TALLOC_CTX *arg1 = (TALLOC_CTX *) 0 ; - struct dcerpc_pipe **arg2 = (struct dcerpc_pipe **) 0 ; - char *arg3 = (char *) 0 ; - struct ndr_interface_table *arg4 = (struct ndr_interface_table *) 0 ; - struct cli_credentials *arg5 = (struct cli_credentials *) 0 ; - struct event_context *arg6 = (struct event_context *) 0 ; - struct loadparm_context *arg7 = (struct loadparm_context *) 0 ; - NTSTATUS result; - void *argp2 = 0 ; - int res2 = 0 ; - int res3 ; - char *buf3 = 0 ; - int alloc3 = 0 ; - void *argp4 = 0 ; - int res4 = 0 ; - void *argp5 = 0 ; - int res5 = 0 ; - void *argp6 = 0 ; - int res6 = 0 ; - void *argp7 = 0 ; - int res7 = 0 ; - PyObject * obj0 = 0 ; - PyObject * obj1 = 0 ; - PyObject * obj2 = 0 ; - PyObject * obj3 = 0 ; - PyObject * obj4 = 0 ; - PyObject * obj5 = 0 ; - char * kwnames[] = { - (char *) "pp",(char *) "binding",(char *) "table",(char *) "credentials",(char *) "ev",(char *) "lp_ctx", NULL - }; - - arg5 = NULL; - arg7 = loadparm_init(NULL); - arg1 = NULL; - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|OOO:pipe_connect",kwnames,&obj0,&obj1,&obj2,&obj3,&obj4,&obj5)) SWIG_fail; - res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_p_dcerpc_pipe, 0 | 0 ); - if (!SWIG_IsOK(res2)) { - SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "pipe_connect" "', argument " "2"" of type '" "struct dcerpc_pipe **""'"); - } - arg2 = (struct dcerpc_pipe **)(argp2); - res3 = SWIG_AsCharPtrAndSize(obj1, &buf3, NULL, &alloc3); - if (!SWIG_IsOK(res3)) { - SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "pipe_connect" "', argument " "3"" of type '" "char const *""'"); - } - arg3 = (char *)(buf3); - res4 = SWIG_ConvertPtr(obj2, &argp4,SWIGTYPE_p_ndr_interface_table, 0 | 0 ); - if (!SWIG_IsOK(res4)) { - SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "pipe_connect" "', argument " "4"" of type '" "struct ndr_interface_table const *""'"); - } - arg4 = (struct ndr_interface_table *)(argp4); - if (obj3) { - res5 = SWIG_ConvertPtr(obj3, &argp5,SWIGTYPE_p_cli_credentials, 0 | 0 ); - if (!SWIG_IsOK(res5)) { - SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "pipe_connect" "', argument " "5"" of type '" "struct cli_credentials *""'"); - } - arg5 = (struct cli_credentials *)(argp5); - } - if (obj4) { - res6 = SWIG_ConvertPtr(obj4, &argp6,SWIGTYPE_p_event_context, 0 | 0 ); - if (!SWIG_IsOK(res6)) { - SWIG_exception_fail(SWIG_ArgError(res6), "in method '" "pipe_connect" "', argument " "6"" of type '" "struct event_context *""'"); - } - arg6 = (struct event_context *)(argp6); - } - if (obj5) { - res7 = SWIG_ConvertPtr(obj5, &argp7,SWIGTYPE_p_loadparm_context, 0 | 0 ); - if (!SWIG_IsOK(res7)) { - SWIG_exception_fail(SWIG_ArgError(res7), "in method '" "pipe_connect" "', argument " "7"" of type '" "struct loadparm_context *""'"); - } - arg7 = (struct loadparm_context *)(argp7); - } - result = dcerpc_pipe_connect(arg1,arg2,(char const *)arg3,(struct ndr_interface_table const *)arg4,arg5,arg6,arg7); - resultobj = SWIG_NewPointerObj((NTSTATUS *)memcpy((NTSTATUS *)malloc(sizeof(NTSTATUS)),&result,sizeof(NTSTATUS)), SWIGTYPE_p_NTSTATUS, SWIG_POINTER_OWN | 0 ); - /* Set REF_ALLOC flag so we don't have to do too much extra - mucking around with ref variables in ndr unmarshalling. */ - - (*arg2)->conn->flags |= DCERPC_NDR_REF_ALLOC; - - /* Return swig handle on dcerpc_pipe */ - - resultobj = SWIG_NewPointerObj(*arg2, SWIGTYPE_p_dcerpc_pipe, 0); - if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); - return resultobj; -fail: - if (alloc3 == SWIG_NEWOBJ) free((char*)buf3); - return NULL; -} - - -SWIGINTERN PyObject *_wrap_dcerpc_server_name(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) { - PyObject *resultobj = 0; - struct dcerpc_pipe *arg1 = (struct dcerpc_pipe *) 0 ; - char *result = 0 ; - void *argp1 = 0 ; - int res1 = 0 ; - PyObject * obj0 = 0 ; - char * kwnames[] = { - (char *) "p", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"O:dcerpc_server_name",kwnames,&obj0)) SWIG_fail; - res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_dcerpc_pipe, 0 | 0 ); - if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "dcerpc_server_name" "', argument " "1"" of type '" "struct dcerpc_pipe *""'"); - } - arg1 = (struct dcerpc_pipe *)(argp1); - result = (char *)dcerpc_server_name(arg1); - resultobj = SWIG_FromCharPtr((const char *)result); - return resultobj; -fail: - return NULL; -} - - -static PyMethodDef SwigMethods[] = { - { (char *)"pipe_connect", (PyCFunction) _wrap_pipe_connect, METH_VARARGS | METH_KEYWORDS, NULL}, - { (char *)"dcerpc_server_name", (PyCFunction) _wrap_dcerpc_server_name, METH_VARARGS | METH_KEYWORDS, NULL}, - { NULL, NULL, 0, NULL } -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ - -static swig_type_info _swigt__p_NTSTATUS = {"_p_NTSTATUS", "NTSTATUS *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_TALLOC_CTX = {"_p_TALLOC_CTX", "TALLOC_CTX *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_cli_credentials = {"_p_cli_credentials", "struct cli_credentials *|cli_credentials *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_dcerpc_pipe = {"_p_dcerpc_pipe", "struct dcerpc_pipe *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_event_context = {"_p_event_context", "struct event_context *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_int = {"_p_int", "intptr_t *|int *|int_least32_t *|int_fast32_t *|int32_t *|int_fast16_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "struct loadparm_context *|loadparm_context *", 0, 0, (void*)0, 0}; -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_ndr_interface_table = {"_p_ndr_interface_table", "struct ndr_interface_table *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_p_dcerpc_pipe = {"_p_p_dcerpc_pipe", "struct dcerpc_pipe **", 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}; -static swig_type_info _swigt__p_unsigned_char = {"_p_unsigned_char", "unsigned char *|uint_least8_t *|uint_fast8_t *|uint8_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_unsigned_int = {"_p_unsigned_int", "uintptr_t *|uint_least32_t *|uint_fast32_t *|uint32_t *|unsigned int *|uint_fast16_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_unsigned_long_long = {"_p_unsigned_long_long", "uint_least64_t *|uint_fast64_t *|uint64_t *|unsigned long long *|uintmax_t *", 0, 0, (void*)0, 0}; -static swig_type_info _swigt__p_unsigned_short = {"_p_unsigned_short", "unsigned short *|uint_least16_t *|uint16_t *", 0, 0, (void*)0, 0}; - -static swig_type_info *swig_type_initial[] = { - &_swigt__p_NTSTATUS, - &_swigt__p_TALLOC_CTX, - &_swigt__p_char, - &_swigt__p_cli_credentials, - &_swigt__p_dcerpc_pipe, - &_swigt__p_event_context, - &_swigt__p_int, - &_swigt__p_loadparm_context, - &_swigt__p_loadparm_service, - &_swigt__p_long_long, - &_swigt__p_ndr_interface_table, - &_swigt__p_p_dcerpc_pipe, - &_swigt__p_param_context, - &_swigt__p_param_opt, - &_swigt__p_param_section, - &_swigt__p_short, - &_swigt__p_signed_char, - &_swigt__p_unsigned_char, - &_swigt__p_unsigned_int, - &_swigt__p_unsigned_long_long, - &_swigt__p_unsigned_short, -}; - -static swig_cast_info _swigc__p_NTSTATUS[] = { {&_swigt__p_NTSTATUS, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_TALLOC_CTX[] = { {&_swigt__p_TALLOC_CTX, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_cli_credentials[] = { {&_swigt__p_cli_credentials, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_dcerpc_pipe[] = { {&_swigt__p_dcerpc_pipe, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_event_context[] = { {&_swigt__p_event_context, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_context, 0, 0, 0},{0, 0, 0, 0}}; -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_ndr_interface_table[] = { {&_swigt__p_ndr_interface_table, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_p_dcerpc_pipe[] = { {&_swigt__p_p_dcerpc_pipe, 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}}; -static swig_cast_info _swigc__p_unsigned_char[] = { {&_swigt__p_unsigned_char, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_unsigned_int[] = { {&_swigt__p_unsigned_int, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_unsigned_long_long[] = { {&_swigt__p_unsigned_long_long, 0, 0, 0},{0, 0, 0, 0}}; -static swig_cast_info _swigc__p_unsigned_short[] = { {&_swigt__p_unsigned_short, 0, 0, 0},{0, 0, 0, 0}}; - -static swig_cast_info *swig_cast_initial[] = { - _swigc__p_NTSTATUS, - _swigc__p_TALLOC_CTX, - _swigc__p_char, - _swigc__p_cli_credentials, - _swigc__p_dcerpc_pipe, - _swigc__p_event_context, - _swigc__p_int, - _swigc__p_loadparm_context, - _swigc__p_loadparm_service, - _swigc__p_long_long, - _swigc__p_ndr_interface_table, - _swigc__p_p_dcerpc_pipe, - _swigc__p_param_context, - _swigc__p_param_opt, - _swigc__p_param_section, - _swigc__p_short, - _swigc__p_signed_char, - _swigc__p_unsigned_char, - _swigc__p_unsigned_int, - _swigc__p_unsigned_long_long, - _swigc__p_unsigned_short, -}; - - -/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ - -static swig_const_info swig_const_table[] = { -{0, 0, 0, 0.0, 0, 0}}; - -#ifdef __cplusplus -} -#endif -/* ----------------------------------------------------------------------------- - * Type initialization: - * This problem is tough by the requirement that no dynamic - * memory is used. Also, since swig_type_info structures store pointers to - * swig_cast_info structures and swig_cast_info structures store pointers back - * to swig_type_info structures, we need some lookup code at initialization. - * The idea is that swig generates all the structures that are needed. - * The runtime then collects these partially filled structures. - * The SWIG_InitializeModule function takes these initial arrays out of - * swig_module, and does all the lookup, filling in the swig_module.types - * array with the correct data and linking the correct swig_cast_info - * structures together. - * - * The generated swig_type_info structures are assigned staticly to an initial - * array. We just loop through that array, and handle each type individually. - * First we lookup if this type has been already loaded, and if so, use the - * loaded structure instead of the generated one. Then we have to fill in the - * cast linked list. The cast data is initially stored in something like a - * two-dimensional array. Each row corresponds to a type (there are the same - * number of rows as there are in the swig_type_initial array). Each entry in - * a column is one of the swig_cast_info structures for that type. - * The cast_initial array is actually an array of arrays, because each row has - * a variable number of columns. So to actually build the cast linked list, - * we find the array of casts associated with the type, and loop through it - * adding the casts to the list. The one last trick we need to do is making - * sure the type pointer in the swig_cast_info struct is correct. - * - * First off, we lookup the cast->type name to see if it is already loaded. - * There are three cases to handle: - * 1) If the cast->type has already been loaded AND the type we are adding - * casting info to has not been loaded (it is in this module), THEN we - * replace the cast->type pointer with the type pointer that has already - * been loaded. - * 2) If BOTH types (the one we are adding casting info to, and the - * cast->type) are loaded, THEN the cast info has already been loaded by - * the previous module so we just ignore it. - * 3) Finally, if cast->type has not already been loaded, then we add that - * swig_cast_info to the linked list (because the cast->type) pointer will - * be correct. - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#if 0 -} /* c-mode */ -#endif -#endif - -#if 0 -#define SWIGRUNTIME_DEBUG -#endif - - -SWIGRUNTIME void -SWIG_InitializeModule(void *clientdata) { - size_t i; - swig_module_info *module_head, *iter; - int found, init; - - clientdata = clientdata; - - /* check to see if the circular list has been setup, if not, set it up */ - if (swig_module.next==0) { - /* Initialize the swig_module */ - swig_module.type_initial = swig_type_initial; - swig_module.cast_initial = swig_cast_initial; - swig_module.next = &swig_module; - init = 1; - } else { - init = 0; - } - - /* Try and load any already created modules */ - module_head = SWIG_GetModule(clientdata); - if (!module_head) { - /* This is the first module loaded for this interpreter */ - /* so set the swig module into the interpreter */ - SWIG_SetModule(clientdata, &swig_module); - module_head = &swig_module; - } else { - /* the interpreter has loaded a SWIG module, but has it loaded this one? */ - found=0; - iter=module_head; - do { - if (iter==&swig_module) { - found=1; - break; - } - iter=iter->next; - } while (iter!= module_head); - - /* if the is found in the list, then all is done and we may leave */ - if (found) return; - /* otherwise we must add out module into the list */ - swig_module.next = module_head->next; - module_head->next = &swig_module; - } - - /* When multiple interpeters are used, a module could have already been initialized in - a different interpreter, but not yet have a pointer in this interpreter. - In this case, we do not want to continue adding types... everything should be - set up already */ - if (init == 0) return; - - /* Now work on filling in swig_module.types */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: size %d\n", swig_module.size); -#endif - for (i = 0; i < swig_module.size; ++i) { - swig_type_info *type = 0; - swig_type_info *ret; - swig_cast_info *cast; - -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); -#endif - - /* if there is another module already loaded */ - if (swig_module.next != &swig_module) { - type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); - } - if (type) { - /* Overwrite clientdata field */ -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found type %s\n", type->name); -#endif - if (swig_module.type_initial[i]->clientdata) { - type->clientdata = swig_module.type_initial[i]->clientdata; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); -#endif - } - } else { - type = swig_module.type_initial[i]; - } - - /* Insert casting types */ - cast = swig_module.cast_initial[i]; - while (cast->type) { - /* Don't need to add information already in the list */ - ret = 0; -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); -#endif - if (swig_module.next != &swig_module) { - ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); -#ifdef SWIGRUNTIME_DEBUG - if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); -#endif - } - if (ret) { - if (type == swig_module.type_initial[i]) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: skip old type %s\n", ret->name); -#endif - cast->type = ret; - ret = 0; - } else { - /* Check for casting already in the list */ - swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); -#ifdef SWIGRUNTIME_DEBUG - if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); -#endif - if (!ocast) ret = 0; - } - } - - if (!ret) { -#ifdef SWIGRUNTIME_DEBUG - printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); -#endif - if (type->cast) { - type->cast->prev = cast; - cast->next = type->cast; - } - type->cast = cast; - } - cast++; - } - /* Set entry in modules->types array equal to the type */ - swig_module.types[i] = type; - } - swig_module.types[i] = 0; - -#ifdef SWIGRUNTIME_DEBUG - printf("**** SWIG_InitializeModule: Cast List ******\n"); - for (i = 0; i < swig_module.size; ++i) { - int j = 0; - swig_cast_info *cast = swig_module.cast_initial[i]; - printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); - while (cast->type) { - printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); - cast++; - ++j; - } - printf("---- Total casts: %d\n",j); - } - printf("**** SWIG_InitializeModule: Cast List ******\n"); -#endif -} - -/* This function will propagate the clientdata field of type to -* any new swig_type_info structures that have been added into the list -* of equivalent types. It is like calling -* SWIG_TypeClientData(type, clientdata) a second time. -*/ -SWIGRUNTIME void -SWIG_PropagateClientData(void) { - size_t i; - swig_cast_info *equiv; - static int init_run = 0; - - if (init_run) return; - init_run = 1; - - for (i = 0; i < swig_module.size; i++) { - if (swig_module.types[i]->clientdata) { - equiv = swig_module.types[i]->cast; - while (equiv) { - if (!equiv->converter) { - if (equiv->type && !equiv->type->clientdata) - SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); - } - equiv = equiv->next; - } - } - } -} - -#ifdef __cplusplus -#if 0 -{ - /* c-mode */ -#endif -} -#endif - - - -#ifdef __cplusplus -extern "C" { -#endif - - /* Python-specific SWIG API */ -#define SWIG_newvarlink() SWIG_Python_newvarlink() -#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) -#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) - - /* ----------------------------------------------------------------------------- - * global variable support code. - * ----------------------------------------------------------------------------- */ - - typedef struct swig_globalvar { - char *name; /* Name of global variable */ - PyObject *(*get_attr)(void); /* Return the current value */ - int (*set_attr)(PyObject *); /* Set the value */ - struct swig_globalvar *next; - } swig_globalvar; - - typedef struct swig_varlinkobject { - PyObject_HEAD - swig_globalvar *vars; - } swig_varlinkobject; - - SWIGINTERN PyObject * - swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { - return PyString_FromString(""); - } - - SWIGINTERN PyObject * - swig_varlink_str(swig_varlinkobject *v) { - PyObject *str = PyString_FromString("("); - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - PyString_ConcatAndDel(&str,PyString_FromString(var->name)); - if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); - } - PyString_ConcatAndDel(&str,PyString_FromString(")")); - return str; - } - - SWIGINTERN int - swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { - PyObject *str = swig_varlink_str(v); - fprintf(fp,"Swig global variables "); - fprintf(fp,"%s\n", PyString_AsString(str)); - Py_DECREF(str); - return 0; - } - - SWIGINTERN void - swig_varlink_dealloc(swig_varlinkobject *v) { - swig_globalvar *var = v->vars; - while (var) { - swig_globalvar *n = var->next; - free(var->name); - free(var); - var = n; - } - } - - SWIGINTERN PyObject * - swig_varlink_getattr(swig_varlinkobject *v, char *n) { - PyObject *res = NULL; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->get_attr)(); - break; - } - var = var->next; - } - if (res == NULL && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN int - swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { - int res = 1; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->set_attr)(p); - break; - } - var = var->next; - } - if (res == 1 && !PyErr_Occurred()) { - PyErr_SetString(PyExc_NameError,"Unknown C global variable"); - } - return res; - } - - SWIGINTERN PyTypeObject* - swig_varlink_type(void) { - static char varlink__doc__[] = "Swig var link object"; - static PyTypeObject varlink_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp - = { - PyObject_HEAD_INIT(NULL) - 0, /* Number of items in variable part (ob_size) */ - (char *)"swigvarlink", /* Type name (tp_name) */ - sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ - 0, /* Itemsize (tp_itemsize) */ - (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ - (printfunc) swig_varlink_print, /* Print (tp_print) */ - (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ - (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ - 0, /* tp_compare */ - (reprfunc) swig_varlink_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc)swig_varlink_str, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - 0, /* tp_flags */ - varlink__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ -#if PY_VERSION_HEX >= 0x02020000 - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ -#endif -#if PY_VERSION_HEX >= 0x02030000 - 0, /* tp_del */ -#endif -#ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ -#endif - }; - varlink_type = tmp; - varlink_type.ob_type = &PyType_Type; - type_init = 1; - } - return &varlink_type; - } - - /* Create a variable linking object for use later */ - SWIGINTERN PyObject * - SWIG_Python_newvarlink(void) { - swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); - if (result) { - result->vars = 0; - } - return ((PyObject*) result); - } - - SWIGINTERN void - SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { - swig_varlinkobject *v = (swig_varlinkobject *) p; - swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); - if (gv) { - size_t size = strlen(name)+1; - gv->name = (char *)malloc(size); - if (gv->name) { - strncpy(gv->name,name,size); - gv->get_attr = get_attr; - gv->set_attr = set_attr; - gv->next = v->vars; - } - } - v->vars = gv; - } - - SWIGINTERN PyObject * - SWIG_globals(void) { - static PyObject *_SWIG_globals = 0; - if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); - return _SWIG_globals; - } - - /* ----------------------------------------------------------------------------- - * constants/methods manipulation - * ----------------------------------------------------------------------------- */ - - /* Install Constants */ - SWIGINTERN void - SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { - PyObject *obj = 0; - size_t i; - for (i = 0; constants[i].type; ++i) { - switch(constants[i].type) { - case SWIG_PY_POINTER: - obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); - break; - case SWIG_PY_BINARY: - obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); - break; - default: - obj = 0; - break; - } - if (obj) { - PyDict_SetItemString(d, constants[i].name, obj); - Py_DECREF(obj); - } - } - } - - /* -----------------------------------------------------------------------------*/ - /* Fix SwigMethods to carry the callback ptrs when needed */ - /* -----------------------------------------------------------------------------*/ - - SWIGINTERN void - SWIG_Python_FixMethods(PyMethodDef *methods, - swig_const_info *const_table, - swig_type_info **types, - swig_type_info **types_initial) { - size_t i; - for (i = 0; methods[i].ml_name; ++i) { - const char *c = methods[i].ml_doc; - if (c && (c = strstr(c, "swig_ptr: "))) { - int j; - swig_const_info *ci = 0; - const char *name = c + 10; - for (j = 0; const_table[j].type; ++j) { - if (strncmp(const_table[j].name, name, - strlen(const_table[j].name)) == 0) { - ci = &(const_table[j]); - break; - } - } - if (ci) { - size_t shift = (ci->ptype) - types; - swig_type_info *ty = types_initial[shift]; - size_t ldoc = (c - methods[i].ml_doc); - size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; - char *ndoc = (char*)malloc(ldoc + lptr + 10); - if (ndoc) { - char *buff = ndoc; - void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; - if (ptr) { - strncpy(buff, methods[i].ml_doc, ldoc); - buff += ldoc; - strncpy(buff, "swig_ptr: ", 10); - buff += 10; - SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); - methods[i].ml_doc = ndoc; - } - } - } - } - } - } - -#ifdef __cplusplus -} -#endif - -/* -----------------------------------------------------------------------------* - * Partial Init method - * -----------------------------------------------------------------------------*/ - -#ifdef __cplusplus -extern "C" -#endif -SWIGEXPORT void SWIG_init(void) { - PyObject *m, *d; - - /* Fix SwigMethods to carry the callback ptrs when needed */ - SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); - - m = Py_InitModule((char *) SWIG_name, SwigMethods); - d = PyModule_GetDict(m); - - SWIG_InitializeModule(0); - SWIG_InstallConstants(d,swig_const_table); - - -} - diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c new file mode 100644 index 0000000000..6796e4beee --- /dev/null +++ b/source4/librpc/rpc/pyrpc.c @@ -0,0 +1,156 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include +#include "librpc/rpc/pyrpc.h" +#include "librpc/rpc/dcerpc.h" +#include "lib/events/events.h" + +static PyObject *py_iface_server_name(PyObject *obj, void *closure) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; + + return PyString_FromString(dcerpc_server_name(iface->pipe)); +} + +static PyGetSetDef dcerpc_interface_getsetters[] = { + { discard_const_p(char, "server_name"), py_iface_server_name, NULL }, + { NULL } +}; + +static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwargs) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; + int opnum; + DATA_BLOB data_in, data_out; + NTSTATUS status; + char *object; + const char *kwnames[] = { "opnum", "data", "object", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#|s:request", + discard_const_p(char *, kwnames), &opnum, &data_in.data, &data_in.length, &object)) { + return NULL; + } + + status = dcerpc_request(iface->pipe, NULL /* FIXME: object GUID */, opnum, false, NULL, &data_in, + &data_out); + + if (NT_STATUS_IS_ERR(status)) { + /* FIXME: Set more appropriate error */ + PyErr_SetString(PyExc_RuntimeError, "Unable to connect"); + return NULL; + } + + return PyString_FromStringAndSize((char *)data_out.data, data_out.length); +} + +static PyMethodDef dcerpc_interface_methods[] = { + { "request", (PyCFunction)py_iface_request, METH_VARARGS|METH_KEYWORDS, "S.request(opnum, data) -> data\nMake a raw request" }, + { NULL, NULL, 0, NULL }, +}; + + +static void dcerpc_interface_dealloc(PyObject* self) +{ + dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self; + talloc_free(interface->pipe); + PyObject_Del(self); +} + +static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObject *kwargs) +{ + dcerpc_InterfaceObject *ret; + const char *binding_string; + struct cli_credentials *credentials; + struct loadparm_context *lp_ctx = NULL; + PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None; + TALLOC_CTX *mem_ctx = NULL; + struct event_context *event_ctx; + NTSTATUS status; + + PyObject *syntax; + const char *kwnames[] = { + "binding", "syntax", "lp_ctx", "credentials", NULL + }; + extern struct loadparm_context *lp_from_py_object(PyObject *py_obj); + extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj); + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials)) { + return NULL; + } + + lp_ctx = lp_from_py_object(py_lp_ctx); + if (lp_ctx == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); + return NULL; + } + + credentials = cli_credentials_from_py_object(py_credentials); + if (credentials == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected credentials"); + return NULL; + } + ret = PyObject_New(dcerpc_InterfaceObject, &dcerpc_InterfaceType); + + event_ctx = event_context_init(mem_ctx); + + status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, + NULL, credentials, event_ctx, lp_ctx); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetString(PyExc_RuntimeError, nt_errstr(status)); + talloc_free(mem_ctx); + return NULL; + } + + ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC; + return (PyObject *)ret; +} + +PyTypeObject dcerpc_InterfaceType = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "dcerpc.ClientConnection", + .tp_basicsize = sizeof(dcerpc_InterfaceObject), + .tp_dealloc = dcerpc_interface_dealloc, + .tp_getset = dcerpc_interface_getsetters, + .tp_methods = dcerpc_interface_methods, + .tp_doc = "ClientConnection(binding, syntax, lp_ctx=None, credentials=None) -> connection\n" +"\n" +"binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1)\n" +"syntax should be a tuple with a GUID and version number of an interface\n" +"lp_ctx should be a path to a smb.conf file or a param.LoadParm object\n" +"credentials should be a credentials.Credentials object.\n\n", + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_new = dcerpc_interface_new, +}; + +void initbase(void) +{ + PyObject *m; + + if (PyType_Ready(&dcerpc_InterfaceType) < 0) + return; + + m = Py_InitModule3("base", NULL, "DCE/RPC protocol implementation"); + if (m == NULL) + return; + + Py_INCREF((PyObject *)&dcerpc_InterfaceType); + PyModule_AddObject(m, "ClientConnection", (PyObject *)&dcerpc_InterfaceType); +} diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index c21f387cf6..386b994494 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -41,4 +41,6 @@ typedef struct { struct dcerpc_pipe *pipe; } dcerpc_InterfaceObject; +PyAPI_DATA(PyTypeObject) dcerpc_InterfaceType; + #endif /* _PYRPC_H_ */ diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index dea8f2c648..f252dd4f27 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -636,16 +636,6 @@ sub Interface($$$) $self->pidl("};"); $self->pidl(""); - $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); - $self->pidl("{"); - $self->indent; - $self->pidl("dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self;"); - $self->pidl("talloc_free(interface->pipe);"); - $self->pidl("PyObject_Del(self);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("static PyObject *interface_$interface->{NAME}_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; @@ -726,7 +716,7 @@ sub Interface($$$) $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$basename.$interface->{NAME}\","); $self->pidl(".tp_basicsize = sizeof(dcerpc_InterfaceObject),"); - $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); + $self->pidl(".tp_base = &dcerpc_InterfaceType,"); $self->pidl(".tp_methods = interface_$interface->{NAME}_methods,"); $self->pidl(".tp_doc = $docstring,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); -- cgit From fe5be25547b5517ebc2e74d298921ae8c53650e5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 21:20:45 +0200 Subject: Allow request() call to do custom calls on DCE/RPC interfaces. (This used to be commit 9c2eff0289d7c5963da87d5e002f1b80e6e66cdd) --- source4/librpc/rpc/pyrpc.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 6796e4beee..cf16c582f4 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -25,9 +25,14 @@ static PyObject *py_iface_server_name(PyObject *obj, void *closure) { + const char *server_name; dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; + + server_name = dcerpc_server_name(iface->pipe); + if (server_name == NULL) + return Py_None; - return PyString_FromString(dcerpc_server_name(iface->pipe)); + return PyString_FromString(server_name); } static PyGetSetDef dcerpc_interface_getsetters[] = { @@ -41,24 +46,35 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar int opnum; DATA_BLOB data_in, data_out; NTSTATUS status; + char *in_data; + int in_length; + PyObject *ret; char *object; + TALLOC_CTX *mem_ctx = talloc_new(NULL); const char *kwnames[] = { "opnum", "data", "object", NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#|s:request", - discard_const_p(char *, kwnames), &opnum, &data_in.data, &data_in.length, &object)) { + discard_const_p(char *, kwnames), &opnum, &in_data, &in_length, &object)) { return NULL; } - status = dcerpc_request(iface->pipe, NULL /* FIXME: object GUID */, opnum, false, NULL, &data_in, - &data_out); + data_in.data = talloc_strndup(mem_ctx, in_data, in_length); + data_in.length = in_length; + + status = dcerpc_request(iface->pipe, NULL /* FIXME: object GUID */, + opnum, false, mem_ctx, &data_in, &data_out); if (NT_STATUS_IS_ERR(status)) { /* FIXME: Set more appropriate error */ PyErr_SetString(PyExc_RuntimeError, "Unable to connect"); + talloc_free(mem_ctx); return NULL; } - return PyString_FromStringAndSize((char *)data_out.data, data_out.length); + ret = PyString_FromStringAndSize((char *)data_out.data, data_out.length); + + talloc_free(mem_ctx); + return ret; } static PyMethodDef dcerpc_interface_methods[] = { -- cgit From f9c36fae757d197ee4de06f0ecf94ae13faad0de Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 21:38:33 +0200 Subject: Export functions for setting NTSTATUS and WERRORs in python. (This used to be commit 4bcb92d2d49d90863b1e64b15d055517fbfd263c) --- source4/libcli/util/errors.i | 10 ++++++---- source4/libcli/util/pyerrors.h | 29 +++++++++++++++++++++++++++++ source4/librpc/rpc/pyrpc.c | 6 +++--- source4/scripting/python/misc.i | 7 +++---- source4/scripting/python/misc_wrap.c | 6 ++++-- 5 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 source4/libcli/util/pyerrors.h diff --git a/source4/libcli/util/errors.i b/source4/libcli/util/errors.i index 17efcbf62a..1fcde04c85 100644 --- a/source4/libcli/util/errors.i +++ b/source4/libcli/util/errors.i @@ -18,10 +18,13 @@ */ #ifdef SWIGPYTHON +%{ +#include "libcli/util/pyerrors.h" +%} + %typemap(out,noblock=1) WERROR { if (!W_ERROR_IS_OK($1)) { - PyObject *obj = Py_BuildValue((char *)"(i,s)", W_ERROR_V($1), win_errstr($1)); - PyErr_SetObject(PyExc_RuntimeError, obj); + PyErr_SetWERROR($1); SWIG_fail; } else if ($result == NULL) { $result = Py_None; @@ -30,8 +33,7 @@ %typemap(out,noblock=1) NTSTATUS { if (NT_STATUS_IS_ERR($1)) { - PyObject *obj = Py_BuildValue((char *)"(i,s)", NT_STATUS_V($1), nt_errstr($1)); - PyErr_SetObject(PyExc_RuntimeError, obj); + PyErr_SetNTSTATUS($1); SWIG_fail; } else if ($result == NULL) { $result = Py_None; diff --git a/source4/libcli/util/pyerrors.h b/source4/libcli/util/pyerrors.h new file mode 100644 index 0000000000..49d9923130 --- /dev/null +++ b/source4/libcli/util/pyerrors.h @@ -0,0 +1,29 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Jelmer Vernooij 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __PYERRORS_H__ +#define __PYERRORS_H__ + +#define PyErr_SetWERROR(err) \ + PyErr_SetObject(PyExc_RuntimeError, Py_BuildValue((char *)"(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err)))) + +#define PyErr_SetNTSTATUS(status) \ + PyErr_SetObject(PyExc_RuntimeError, Py_BuildValue((char *)"(i,s)", NT_STATUS_V(status), discard_const_p(char, nt_errstr(status)))) + +#endif /* __PYERRORS_H__ */ diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index cf16c582f4..8a0486c05e 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -22,6 +22,7 @@ #include "librpc/rpc/pyrpc.h" #include "librpc/rpc/dcerpc.h" #include "lib/events/events.h" +#include "libcli/util/pyerrors.h" static PyObject *py_iface_server_name(PyObject *obj, void *closure) { @@ -58,15 +59,14 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar return NULL; } - data_in.data = talloc_strndup(mem_ctx, in_data, in_length); + data_in.data = (uint8_t *)talloc_strndup(mem_ctx, in_data, in_length); data_in.length = in_length; status = dcerpc_request(iface->pipe, NULL /* FIXME: object GUID */, opnum, false, mem_ctx, &data_in, &data_out); if (NT_STATUS_IS_ERR(status)) { - /* FIXME: Set more appropriate error */ - PyErr_SetString(PyExc_RuntimeError, "Unable to connect"); + PyErr_SetNTSTATUS(status); talloc_free(mem_ctx); return NULL; } diff --git a/source4/scripting/python/misc.i b/source4/scripting/python/misc.i index 56b862552a..1d331215b5 100644 --- a/source4/scripting/python/misc.i +++ b/source4/scripting/python/misc.i @@ -35,7 +35,7 @@ %import "../../auth/credentials/credentials.i" %import "../../param/param.i" %import "../../libcli/security/security.i" -%import "../../libcli/util/errors.i" +%include "../../libcli/util/errors.i" %feature("docstring") generate_random_str "S.random_password(len) -> string\n" \ "Generate random password with specified length."; @@ -97,7 +97,6 @@ bool dsdb_set_ntds_invocation_id(struct ldb_context *ldb, const char *guid) } %} -char *private_path(TALLOC_CTX* mem_ctx, - struct loadparm_context *lp_ctx, - const char *name); +char *private_path(TALLOC_CTX* mem_ctx, struct loadparm_context *lp_ctx, + const char *name); diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c index 8c57237e5b..888918ef53 100644 --- a/source4/scripting/python/misc_wrap.c +++ b/source4/scripting/python/misc_wrap.c @@ -2554,6 +2554,9 @@ static swig_module_info swig_module = {swig_types, 27, 0, 0, 0, 0}; #include "librpc/ndr/libndr.h" +#include "libcli/util/pyerrors.h" + + SWIGINTERN int SWIG_AsVal_double (PyObject *obj, double *val) { @@ -3046,8 +3049,7 @@ SWIGINTERN PyObject *_wrap_dsdb_attach_schema_from_ldif_file(PyObject *SWIGUNUSE "ldb context must be non-NULL"); result = dsdb_attach_schema_from_ldif_file(arg1,(char const *)arg2,(char const *)arg3); if (!W_ERROR_IS_OK(result)) { - PyObject *obj = Py_BuildValue((char *)"(i,s)", W_ERROR_V(result), win_errstr(result)); - PyErr_SetObject(PyExc_RuntimeError, obj); + PyErr_SetWERROR(result); SWIG_fail; } else if (resultobj == NULL) { resultobj = Py_None; -- cgit From 75e7962d2efb1aa6e45ca999b1a93829406de540 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 22:13:32 +0200 Subject: Add convenience functions for setting Python objects from errors. (This used to be commit f1de723b89251cbc8140b838941f304a34871bf3) --- source4/libcli/util/pyerrors.h | 8 ++++++-- source4/librpc/rpc/pyrpc.c | 1 - source4/librpc/rpc/pyrpc.h | 2 ++ source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 10 +++++----- source4/scripting/python/samba/tests/dcerpc/rpcecho.py | 5 +++++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/source4/libcli/util/pyerrors.h b/source4/libcli/util/pyerrors.h index 49d9923130..aaa35b4d26 100644 --- a/source4/libcli/util/pyerrors.h +++ b/source4/libcli/util/pyerrors.h @@ -20,10 +20,14 @@ #ifndef __PYERRORS_H__ #define __PYERRORS_H__ +#define PyErr_FromWERROR(err) Py_BuildValue("(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err))) + +#define PyErr_FromNTSTATUS(status) Py_BuildValue("(i,s)", NT_STATUS_V(status), discard_const_p(char, nt_errstr(status))) + #define PyErr_SetWERROR(err) \ - PyErr_SetObject(PyExc_RuntimeError, Py_BuildValue((char *)"(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err)))) + PyErr_SetObject(PyExc_RuntimeError, PyErr_FromWERROR(err)) #define PyErr_SetNTSTATUS(status) \ - PyErr_SetObject(PyExc_RuntimeError, Py_BuildValue((char *)"(i,s)", NT_STATUS_V(status), discard_const_p(char, nt_errstr(status)))) + PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNTSTATUS(status)) #endif /* __PYERRORS_H__ */ diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 8a0486c05e..33b3c63571 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -22,7 +22,6 @@ #include "librpc/rpc/pyrpc.h" #include "librpc/rpc/dcerpc.h" #include "lib/events/events.h" -#include "libcli/util/pyerrors.h" static PyObject *py_iface_server_name(PyObject *obj, void *closure) { diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 386b994494..3857f53634 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -20,6 +20,8 @@ #ifndef _PYRPC_H_ #define _PYRPC_H_ +#include "libcli/util/pyerrors.h" + #define PY_CHECK_TYPE(type, var, fail) \ if (!type ## _Check(var)) {\ PyErr_Format(PyExc_TypeError, "Expected type %s", type ## _Type.tp_name); \ diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index f252dd4f27..5e76ff027b 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -257,7 +257,7 @@ sub PythonStruct($$$$$$) $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); $self->pidl("DATA_BLOB blob;"); $self->pidl("enum ndr_err_code err;"); - $self->pidl("if (!PyArg_ParseTuple(args, \"(s#):__ndr_unpack__\", &blob.data, &blob.length))"); + $self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob.length))"); $self->pidl("\treturn NULL;"); $self->pidl(""); $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); @@ -501,7 +501,7 @@ sub handle_werror($$$$) $self->pidl("if (!W_ERROR_IS_OK($var)) {"); $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, win_errstr($var));"); + $self->pidl("PyErr_SetWERROR($var);"); $self->pidl("talloc_free($mem_ctx);") if ($mem_ctx); $self->pidl("return $retval;"); $self->deindent; @@ -515,7 +515,7 @@ sub handle_ntstatus($$$$) $self->pidl("if (NT_STATUS_IS_ERR($var)) {"); $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, nt_errstr($var));"); + $self->pidl("PyErr_SetNTSTATUS($var);"); $self->pidl("talloc_free($mem_ctx);") if ($mem_ctx); $self->pidl("return $retval;"); $self->deindent; @@ -926,11 +926,11 @@ sub ConvertScalarToPython($$$) } if ($ctypename eq "NTSTATUS") { - return "PyInt_FromLong(NT_STATUS_V($cvar))"; + return "PyErr_FromNTSTATUS($cvar)"; } if ($ctypename eq "WERROR") { - return "PyInt_FromLong(W_ERROR_V($cvar))"; + return "PyErr_FromWERROR($cvar)"; } if (($ctypename eq "string" or $ctypename eq "nbt_string" or $ctypename eq "nbt_name" or $ctypename eq "wrepl_nbt_name")) { diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py index 9157f83fc9..83279a0b30 100644 --- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py +++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py @@ -42,6 +42,11 @@ class RpcEchoTests(RpcInterfaceTestCase): y = self.conn.TestSurrounding(surrounding_struct) self.assertEquals(8 * [0], y.surrounding) + def test_manual_request(self): + self.assertEquals("\x01\x00\x00\x00", self.conn.request(0, chr(0) * 4)) + + def test_server_name(self): + self.assertEquals(None, self.conn.server_name) class NdrEchoTests(unittest.TestCase): def test_info1_push(self): -- cgit From 21ce0ff00688c560e60efd6c392c71f85229c9d4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 22:56:49 +0200 Subject: Allow connecting to a DCE/RPC interface with Python for which we don't have IDL. (This used to be commit e3178d522c95871f1db35d7e058906502387a553) --- source4/librpc/rpc/pyrpc.c | 64 +++++++++++++++++++++- .../scripting/python/samba/tests/dcerpc/bare.py | 30 ++++++++++ source4/selftest/samba4_tests.sh | 2 +- 3 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 source4/scripting/python/samba/tests/dcerpc/bare.py diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 33b3c63571..b87628f345 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -61,6 +61,8 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar data_in.data = (uint8_t *)talloc_strndup(mem_ctx, in_data, in_length); data_in.length = in_length; + ZERO_STRUCT(data_out); + status = dcerpc_request(iface->pipe, NULL /* FIXME: object GUID */, opnum, false, mem_ctx, &data_in, &data_out); @@ -89,6 +91,50 @@ static void dcerpc_interface_dealloc(PyObject* self) PyObject_Del(self); } +static bool PyString_AsGUID(PyObject *object, struct GUID *uuid) +{ + NTSTATUS status; + status = GUID_from_string(PyString_AsString(object), uuid); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return false; + } + return true; +} + +static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *syntax_id) +{ + ZERO_STRUCTP(syntax_id); + + if (PyString_Check(object)) { + return PyString_AsGUID(object, &syntax_id->uuid); + } else if (PyTuple_Check(object)) { + if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) { + PyErr_SetString(PyExc_ValueError, "Syntax ID tuple has invalid size"); + return false; + } + + if (!PyString_Check(PyTuple_GetItem(object, 0))) { + PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple"); + return false; + } + + if (!PyString_AsGUID(PyTuple_GetItem(object, 0), &syntax_id->uuid)) + return false; + + if (!PyInt_Check(PyTuple_GetItem(object, 1))) { + PyErr_SetString(PyExc_ValueError, "Expected version as second element in tuple"); + return false; + } + + syntax_id->if_version = PyInt_AsLong(PyTuple_GetItem(object, 1)); + return true; + } + + PyErr_SetString(PyExc_TypeError, "Expected UUID or syntax id tuple"); + return false; +} + static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObject *kwargs) { dcerpc_InterfaceObject *ret; @@ -106,6 +152,7 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje }; extern struct loadparm_context *lp_from_py_object(PyObject *py_obj); extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj); + struct ndr_interface_table *table; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials)) { return NULL; @@ -126,8 +173,23 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje event_ctx = event_context_init(mem_ctx); + /* Create a dummy interface table struct. TODO: In the future, we should rather just allow + * connecting without requiring an interface table. + */ + + table = talloc_zero(mem_ctx, struct ndr_interface_table); + + if (table == NULL) { + PyErr_SetString(PyExc_MemoryError, "Allocating interface table"); + return NULL; + } + + if (!ndr_syntax_from_py_object(syntax, &table->syntax_id)) { + return NULL; + } + status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, - NULL, credentials, event_ctx, lp_ctx); + table, credentials, event_ctx, lp_ctx); if (NT_STATUS_IS_ERR(status)) { PyErr_SetString(PyExc_RuntimeError, nt_errstr(status)); talloc_free(mem_ctx); diff --git a/source4/scripting/python/samba/tests/dcerpc/bare.py b/source4/scripting/python/samba/tests/dcerpc/bare.py new file mode 100644 index 0000000000..dae1dedeb3 --- /dev/null +++ b/source4/scripting/python/samba/tests/dcerpc/bare.py @@ -0,0 +1,30 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +from samba.dcerpc import ClientConnection +from unittest import TestCase + +class BareTestCase(TestCase): + def test_bare(self): + # Connect to the echo pipe + x = ClientConnection("ncalrpc:localhost[DEFAULT]", + ("60a15ec5-4de8-11d7-a637-005056a20182", 1)) + self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4)) + diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index 36cf2adccb..2076ed9c65 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -64,7 +64,6 @@ SCRIPTDIR=$samba4srcdir/../testprogs/ejs smb4torture="$samba4bindir/smbtorture $TORTURE_OPTIONS" plantest "js.base" dc "$SCRIPTDIR/base.js" $CONFIGURATION -plantest "samr.python" dc "$samba4bindir/../scripting/bin/samr.py" ncalrpc: #plantest "ejsnet.js" dc "$SCRIPTDIR/ejsnet.js" $CONFIGURATION -U\$USERNAME%\$PASSWORD \$DOMAIN ejstestuser plantest "js.ldb" none "$SCRIPTDIR/ldb.js" `pwd` $CONFIGURATION -d 10 plantest "js.winreg" dc $samba4srcdir/scripting/bin/winreg $CONFIGURATION ncalrpc: 'HKLM' -U\$USERNAME%\$PASSWORD @@ -341,6 +340,7 @@ plantest "samba.python" none $SUBUNITRUN samba.tests plantest "provision.python" none $SUBUNITRUN samba.tests.provision plantest "samba3.python" none $SUBUNITRUN samba.tests.samba3 plantest "samr.python" dc $SUBUNITRUN samba.tests.dcerpc.sam +plantest "dcerpc.bare.python" dc $SUBUNITRUN samba.tests.dcerpc.bare plantest "samdb.python" dc $SUBUNITRUN samba.tests.samdb plantest "unixinfo.python" dc $SUBUNITRUN samba.tests.dcerpc.unix plantest "events.python" none PYTHONPATH="$PYTHONPATH:lib/events" $SUBUNITRUN tests -- cgit From 2a6c4da9d10893f56915bfc19333ca776c6dab13 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 23:02:09 +0200 Subject: Support optional object argument when sending DCE/RPC requests. (This used to be commit 75ba01a0fad87a9a4788f4c2277d8db0513cef4a) --- source4/librpc/rpc/pyrpc.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index b87628f345..0f03fe851e 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -23,6 +23,17 @@ #include "librpc/rpc/dcerpc.h" #include "lib/events/events.h" +static bool PyString_AsGUID(PyObject *object, struct GUID *uuid) +{ + NTSTATUS status; + status = GUID_from_string(PyString_AsString(object), uuid); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return false; + } + return true; +} + static PyObject *py_iface_server_name(PyObject *obj, void *closure) { const char *server_name; @@ -49,11 +60,12 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar char *in_data; int in_length; PyObject *ret; - char *object; + PyObject *object = NULL; + struct GUID object_guid; TALLOC_CTX *mem_ctx = talloc_new(NULL); const char *kwnames[] = { "opnum", "data", "object", NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#|s:request", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "is#|O:request", discard_const_p(char *, kwnames), &opnum, &in_data, &in_length, &object)) { return NULL; } @@ -63,7 +75,11 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar ZERO_STRUCT(data_out); - status = dcerpc_request(iface->pipe, NULL /* FIXME: object GUID */, + if (object != NULL && !PyString_AsGUID(object, &object_guid)) { + return NULL; + } + + status = dcerpc_request(iface->pipe, object?&object_guid:NULL, opnum, false, mem_ctx, &data_in, &data_out); if (NT_STATUS_IS_ERR(status)) { @@ -79,7 +95,7 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar } static PyMethodDef dcerpc_interface_methods[] = { - { "request", (PyCFunction)py_iface_request, METH_VARARGS|METH_KEYWORDS, "S.request(opnum, data) -> data\nMake a raw request" }, + { "request", (PyCFunction)py_iface_request, METH_VARARGS|METH_KEYWORDS, "S.request(opnum, data, object=None) -> data\nMake a raw request" }, { NULL, NULL, 0, NULL }, }; @@ -91,17 +107,6 @@ static void dcerpc_interface_dealloc(PyObject* self) PyObject_Del(self); } -static bool PyString_AsGUID(PyObject *object, struct GUID *uuid) -{ - NTSTATUS status; - status = GUID_from_string(PyString_AsString(object), uuid); - if (NT_STATUS_IS_ERR(status)) { - PyErr_SetNTSTATUS(status); - return false; - } - return true; -} - static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *syntax_id) { ZERO_STRUCTP(syntax_id); -- cgit From 5863864f1d8df53b32f24cf41e726e3bddb528ce Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 23:07:16 +0200 Subject: Fix memory initialization in raw calls. (This used to be commit 788b2dbfe4b1ef14ab30d487d845e493be46fbd1) --- source4/librpc/rpc/pyrpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 0f03fe851e..1662140bbc 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -70,7 +70,7 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar return NULL; } - data_in.data = (uint8_t *)talloc_strndup(mem_ctx, in_data, in_length); + data_in.data = (uint8_t *)talloc_memdup(mem_ctx, in_data, in_length); data_in.length = in_length; ZERO_STRUCT(data_out); -- cgit From 21b6e9ec9ea08cc5e19a068d68331c178091caa6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 23:22:49 +0200 Subject: Add convenience function for creating objects with NDR error codes. (This used to be commit 991541a78c2428db89509081cc28072c9b542ffa) --- source4/librpc/rpc/pyrpc.h | 6 ++++++ source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 3857f53634..65501b6b83 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -45,4 +45,10 @@ typedef struct { PyAPI_DATA(PyTypeObject) dcerpc_InterfaceType; +#define PyErr_FromNdrError(err) PyErr_FromNTSTATUS(ndr_map_error2ntstatus(err)) + +#define PyErr_SetNdrError(err) \ + PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNdrError(err)) + + #endif /* _PYRPC_H_ */ diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 5e76ff027b..26197365ee 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -241,7 +241,7 @@ sub PythonStruct($$$$$$) $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_push_flags_fn_t)ndr_push_$name);"); $self->pidl("if (err != NDR_ERR_SUCCESS) {"); $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); + $self->pidl("PyErr_SetNdrError(err);"); $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); @@ -263,7 +263,7 @@ sub PythonStruct($$$$$$) $self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_pull_flags_fn_t)ndr_pull_$name);"); $self->pidl("if (err != NDR_ERR_SUCCESS) {"); $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); + $self->pidl("PyErr_SetNdrError(err);"); $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); -- cgit From 63c2a19e6e9d0e5e9b662fafe9fd531c2c073174 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 23:39:38 +0200 Subject: Add helper function to return DCE/RPC fault codes. (This used to be commit 4716cdfb5d5abad85cba18be89d72fe8ee18f359) --- source4/librpc/rpc/pyrpc.c | 17 +++++++++++++++-- source4/librpc/rpc/pyrpc.h | 1 + source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 1662140bbc..70875168c5 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -47,10 +47,23 @@ static PyObject *py_iface_server_name(PyObject *obj, void *closure) } static PyGetSetDef dcerpc_interface_getsetters[] = { - { discard_const_p(char, "server_name"), py_iface_server_name, NULL }, + { discard_const_p(char, "server_name"), py_iface_server_name, + "name of the server, if connected over SMB"}, { NULL } }; +void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status) +{ + if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { + const char *errstr = dcerpc_errstr(NULL, p->last_fault_code); + PyErr_SetObject(PyExc_RuntimeError, + Py_BuildValue("(i,s)", p->last_fault_code, + errstr)); + } else { + PyErr_SetNTSTATUS(status); + } +} + static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwargs) { dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; @@ -83,7 +96,7 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar opnum, false, mem_ctx, &data_in, &data_out); if (NT_STATUS_IS_ERR(status)) { - PyErr_SetNTSTATUS(status); + PyErr_SetDCERPCStatus(iface->pipe, status); talloc_free(mem_ctx); return NULL; } diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 65501b6b83..209d7d3f1f 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -50,5 +50,6 @@ PyAPI_DATA(PyTypeObject) dcerpc_InterfaceType; #define PyErr_SetNdrError(err) \ PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNdrError(err)) +void PyErr_SetDCERPCStatus(struct dcerpc_pipe *pipe, NTSTATUS status); #endif /* _PYRPC_H_ */ diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 26197365ee..2795d987f7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -409,7 +409,14 @@ sub PythonFunctionBody($$$) } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); - $self->handle_ntstatus("status", "NULL", "mem_ctx"); + $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); + $self->indent; + $self->pidl("PyErr_SetDCERPCStatus(iface->pipe, status);"); + $self->pidl("talloc_free(mem_ctx);"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); $env = GenerateFunctionOutEnv($fn, "r->"); my $i = 0; -- cgit From 4c1f0641d395e095d46cd0eb9a09055dd07f850b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 00:04:11 +0200 Subject: Check for fault codes when connecting. (This used to be commit 42537b1d5282784550120358f3641f299351fba7) --- source4/librpc/rpc/pyrpc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 70875168c5..1fc6e4e3c7 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -54,7 +54,7 @@ static PyGetSetDef dcerpc_interface_getsetters[] = { void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status) { - if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { + if (p != NULL && NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { const char *errstr = dcerpc_errstr(NULL, p->last_fault_code); PyErr_SetObject(PyExc_RuntimeError, Py_BuildValue("(i,s)", p->last_fault_code, @@ -206,10 +206,12 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje return NULL; } + ret->pipe = NULL; + status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, table, credentials, event_ctx, lp_ctx); if (NT_STATUS_IS_ERR(status)) { - PyErr_SetString(PyExc_RuntimeError, nt_errstr(status)); + PyErr_SetDCERPCStatus(ret->pipe, status); talloc_free(mem_ctx); return NULL; } -- cgit From a2446e5f8550582c0d4353bb85874dea17cf1d98 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 02:32:21 +0200 Subject: Add initial work for script that uses probing to figure out IDL. (This used to be commit 4e5687e813e50d0bc8d6314e389d1d7a0be2f8c1) --- source4/scripting/bin/autoidl.py | 161 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 source4/scripting/bin/autoidl.py diff --git a/source4/scripting/bin/autoidl.py b/source4/scripting/bin/autoidl.py new file mode 100755 index 0000000000..eed4ba3a80 --- /dev/null +++ b/source4/scripting/bin/autoidl.py @@ -0,0 +1,161 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import sys + +MAX_OPNUM = 1000 +MAX_BASE_SIZE = 0x1000 +MAX_IFACE_VERSION = 1000 + +DCERPC_FAULT_OP_RNG_ERROR = 0x1c010002 +DCERPC_FAULT_NDR = 0x6f7 +NT_STATUS_NET_WRITE_FAULT = -1073741614 + + +sys.path.insert(0, "bin/python") + +from samba.dcerpc import ClientConnection + +def find_num_funcs(conn): + for i in xrange(MAX_OPNUM): + try: + conn.request(i, "") + except RuntimeError, (num, msg): + if num == DCERPC_FAULT_OP_RNG_ERROR: + return i + raise Exception("More than %d functions" % MAX_OPNUM) + +class Function: + def __init__(self, conn, opnum): + self.conn = conn + self.opnum = opnum + + def request(self, data): + assert isinstance(data, str) + self.conn.request(self.opnum, data) + + def valid_ndr(self, data): + try: + self.request(data) + except RuntimeError, (num, msg): + if num == DCERPC_FAULT_NDR: + return False + return True + + def find_base_request(self, start=""): + """Find the smallest possible request that we can do that is + valid. + + This generally means sending all zeroes so we get NULL pointers where + possible.""" + # TODO: Don't try with just 0's as there may be switch_is() variables + # for which 0 is not a valid value or variables with range() set + # See how much input bytes we need + for i in range(MAX_BASE_SIZE): + data = start + chr(0) * i + if self.valid_ndr(data): + return data + return None + + def check_decision_byte(self, base_request, i): + """Check whether the specified byte is a possible "decision" byte, + e.g. a byte that is part of a pointer, array size variable or + discriminant. + + Note that this function only checks if a byte is definitely a decision + byte. It may return False in some cases while the byte is actually + a decision byte.""" + data = list(base_request) + data[i] = chr(1) + return not self.valid_ndr("".join(data)) + + def find_deferrant_data(self, base_request, idx): + data = list(base_request) + data[idx*4] = chr(1) + # Just check that this is a pointer to something non-empty: + assert not self.valid_ndr("".join(data)) + + newdata = self.find_base_request("".join(data)) + + if newdata is None: + return None + + assert newdata.startswith(data) + + return newdata[len(data):] + + def find_idl(self): + base_request = self.find_base_request() + + if base_request is None: + raise Exception("Unable to determine base size for opnum %d" % self.opnum) + + print "\tBase request is %r" % base_request + + decision_byte_map = map(lambda x: self.check_decision_byte(base_request, x), range(len(base_request))) + + print decision_byte_map + + # find pointers + possible_pointers = map(all, + [decision_byte_map[i*4:(i+1)*4] for i in range(int(len(base_request)/4))]) + print possible_pointers + + pointer_deferrant_bases = map( + lambda x: self.find_deferrant_data(base_request, x) if possible_pointers[x] else None, range(len(possible_pointers))) + + print pointer_deferrant_bases + + +if len(sys.argv) < 3: + print "Usage: autoidl []" + sys.exit(1) + +(binding, uuid) = sys.argv[1:3] +if len(sys.argv) == 4: + version = sys.argv[3] +else: + version = None + +if version is None: + for i in range(MAX_IFACE_VERSION): + try: + conn = ClientConnection(binding, (uuid, i)) + except RuntimeError, (num, msg): + if num == NT_STATUS_NET_WRITE_FAULT: + continue + raise + else: + break +else: + conn = ClientConnection(binding, (uuid, version)) + +print "Figuring out number of connections...", +num_funcs = find_num_funcs(conn) +print "%d" % num_funcs + +# Figure out the syntax for each one +for i in range(num_funcs): + print "Function %d" % i + data = Function(conn, i) + try: + data.find_idl() + except Exception, e: + print "Error: %r" % e -- cgit From 928ecbaebbde00515d08fd530db7c99169c905ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 04:23:03 +0200 Subject: Add support for secondary contexts from Python. (This used to be commit 16d1ad050546ae6500153438db8d3c857e6f3ad5) --- source4/librpc/rpc/pyrpc.c | 136 +++++++++++++++------ source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 26 +++- source4/samba4-knownfail | 2 - .../scripting/python/samba/tests/dcerpc/bare.py | 13 ++ .../scripting/python/samba/tests/dcerpc/rpcecho.py | 4 + 5 files changed, 136 insertions(+), 45 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 1fc6e4e3c7..aebd484b49 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -34,6 +34,41 @@ static bool PyString_AsGUID(PyObject *object, struct GUID *uuid) return true; } +static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *syntax_id) +{ + ZERO_STRUCTP(syntax_id); + + if (PyString_Check(object)) { + return PyString_AsGUID(object, &syntax_id->uuid); + } else if (PyTuple_Check(object)) { + if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) { + PyErr_SetString(PyExc_ValueError, "Syntax ID tuple has invalid size"); + return false; + } + + if (!PyString_Check(PyTuple_GetItem(object, 0))) { + PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple"); + return false; + } + + if (!PyString_AsGUID(PyTuple_GetItem(object, 0), &syntax_id->uuid)) + return false; + + if (!PyInt_Check(PyTuple_GetItem(object, 1))) { + PyErr_SetString(PyExc_ValueError, "Expected version as second element in tuple"); + return false; + } + + syntax_id->if_version = PyInt_AsLong(PyTuple_GetItem(object, 1)); + return true; + } + + PyErr_SetString(PyExc_TypeError, "Expected UUID or syntax id tuple"); + return false; +} + + + static PyObject *py_iface_server_name(PyObject *obj, void *closure) { const char *server_name; @@ -47,8 +82,8 @@ static PyObject *py_iface_server_name(PyObject *obj, void *closure) } static PyGetSetDef dcerpc_interface_getsetters[] = { - { discard_const_p(char, "server_name"), py_iface_server_name, - "name of the server, if connected over SMB"}, + { discard_const_p(char, "server_name"), py_iface_server_name, NULL, + discard_const_p(char, "name of the server, if connected over SMB") }, { NULL } }; @@ -107,8 +142,45 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar return ret; } +static PyObject *py_iface_later_context(PyObject *self, PyObject *args, PyObject *kwargs) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; + NTSTATUS status; + const char *kwnames[] = { "abstract_syntax", "transfer_syntax", NULL }; + PyObject *py_abstract_syntax = Py_None, *py_transfer_syntax = Py_None; + struct ndr_syntax_id abstract_syntax, transfer_syntax; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:alter_context", + discard_const_p(char *, kwnames), &py_abstract_syntax, + &py_transfer_syntax)) { + return NULL; + } + + if (!ndr_syntax_from_py_object(py_abstract_syntax, &abstract_syntax)) + return NULL; + + if (py_transfer_syntax == Py_None) { + transfer_syntax = ndr_transfer_syntax; + } else { + if (!ndr_syntax_from_py_object(py_transfer_syntax, + &transfer_syntax)) + return NULL; + } + + status = dcerpc_alter_context(iface->pipe, iface->pipe, &abstract_syntax, + &transfer_syntax); + + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetDCERPCStatus(iface->pipe, status); + return NULL; + } + + return Py_None; +} + static PyMethodDef dcerpc_interface_methods[] = { { "request", (PyCFunction)py_iface_request, METH_VARARGS|METH_KEYWORDS, "S.request(opnum, data, object=None) -> data\nMake a raw request" }, + { "alter_context", (PyCFunction)py_iface_later_context, METH_VARARGS|METH_KEYWORDS, "S.alter_context(syntax)\nChange to a different interface" }, { NULL, NULL, 0, NULL }, }; @@ -120,39 +192,6 @@ static void dcerpc_interface_dealloc(PyObject* self) PyObject_Del(self); } -static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *syntax_id) -{ - ZERO_STRUCTP(syntax_id); - - if (PyString_Check(object)) { - return PyString_AsGUID(object, &syntax_id->uuid); - } else if (PyTuple_Check(object)) { - if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) { - PyErr_SetString(PyExc_ValueError, "Syntax ID tuple has invalid size"); - return false; - } - - if (!PyString_Check(PyTuple_GetItem(object, 0))) { - PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple"); - return false; - } - - if (!PyString_AsGUID(PyTuple_GetItem(object, 0), &syntax_id->uuid)) - return false; - - if (!PyInt_Check(PyTuple_GetItem(object, 1))) { - PyErr_SetString(PyExc_ValueError, "Expected version as second element in tuple"); - return false; - } - - syntax_id->if_version = PyInt_AsLong(PyTuple_GetItem(object, 1)); - return true; - } - - PyErr_SetString(PyExc_TypeError, "Expected UUID or syntax id tuple"); - return false; -} - static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObject *kwargs) { dcerpc_InterfaceObject *ret; @@ -164,15 +203,15 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje struct event_context *event_ctx; NTSTATUS status; - PyObject *syntax; + PyObject *syntax, *py_basis = Py_None; const char *kwnames[] = { - "binding", "syntax", "lp_ctx", "credentials", NULL + "binding", "syntax", "lp_ctx", "credentials", "basis_connection", NULL }; extern struct loadparm_context *lp_from_py_object(PyObject *py_obj); extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj); struct ndr_interface_table *table; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OOO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials, &py_basis)) { return NULL; } @@ -208,8 +247,25 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje ret->pipe = NULL; - status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, - table, credentials, event_ctx, lp_ctx); + if (py_basis != Py_None) { + struct dcerpc_pipe *base_pipe; + + if (!PyObject_TypeCheck(py_basis, &dcerpc_InterfaceType)) { + PyErr_SetString(PyExc_ValueError, "basis_connection must be a DCE/RPC connection"); + talloc_free(mem_ctx); + return NULL; + } + + base_pipe = ((dcerpc_InterfaceObject *)py_basis)->pipe; + + status = dcerpc_secondary_context(base_pipe, &ret->pipe, + table); + ret->pipe = talloc_steal(NULL, ret->pipe); + } else { + status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, + table, credentials, event_ctx, lp_ctx); + } + if (NT_STATUS_IS_ERR(status)) { PyErr_SetDCERPCStatus(ret->pipe, status); talloc_free(mem_ctx); diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2795d987f7..dbbdb6bca1 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -650,20 +650,20 @@ sub Interface($$$) $self->pidl("const char *binding_string;"); $self->pidl("struct cli_credentials *credentials;"); $self->pidl("struct loadparm_context *lp_ctx = NULL;"); - $self->pidl("PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None;"); + $self->pidl("PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None, *py_basis = Py_None;"); $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); $self->pidl("struct event_context *event_ctx;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); $self->pidl("const char *kwnames[] = {"); $self->indent; - $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", NULL"); + $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", \"basis_connection\", NULL"); $self->deindent; $self->pidl("};"); $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);"); $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);"); $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s|OO:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s|OOO:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials, &py_basis)) {"); $self->indent; $self->pidl("return NULL;"); $self->deindent; @@ -691,8 +691,28 @@ sub Interface($$$) $self->pidl("event_ctx = event_context_init(mem_ctx);"); $self->pidl(""); + $self->pidl("if (py_basis != Py_None) {"); + $self->indent; + $self->pidl("struct dcerpc_pipe *base_pipe;"); + $self->pidl(""); + $self->pidl("if (!PyObject_TypeCheck(py_basis, &dcerpc_InterfaceType)) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_ValueError, \"basis_connection must be a DCE/RPC connection\");"); + $self->pidl("talloc_free(mem_ctx);"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("base_pipe = ((dcerpc_InterfaceObject *)py_basis)->pipe;"); + $self->pidl(""); + $self->pidl("status = dcerpc_secondary_context(base_pipe, &ret->pipe, &ndr_table_$interface->{NAME});"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); $self->pidl(" &ndr_table_$interface->{NAME}, credentials, event_ctx, lp_ctx);"); + $self->deindent; + $self->pidl("}"); $self->handle_ntstatus("status", "NULL", "mem_ctx"); $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;"); diff --git a/source4/samba4-knownfail b/source4/samba4-knownfail index 1f780f13f0..d489dd3d70 100644 --- a/source4/samba4-knownfail +++ b/source4/samba4-knownfail @@ -40,5 +40,3 @@ samba4.winbind.struct.*.SHOW_SEQUENCE # Not yet working in winbind samba4.winbind.struct.*.GETPWENT # Not yet working in winbind samba4.winbind.struct.*.SETPWENT # Not yet working in winbind samba4.winbind.struct.*.LOOKUP_NAME_SID # Not yet working in winbind - - diff --git a/source4/scripting/python/samba/tests/dcerpc/bare.py b/source4/scripting/python/samba/tests/dcerpc/bare.py index dae1dedeb3..eea6744e42 100644 --- a/source4/scripting/python/samba/tests/dcerpc/bare.py +++ b/source4/scripting/python/samba/tests/dcerpc/bare.py @@ -28,3 +28,16 @@ class BareTestCase(TestCase): ("60a15ec5-4de8-11d7-a637-005056a20182", 1)) self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4)) + #def test_alter_context(self): + # x = ClientConnection("ncalrpc:localhost[DEFAULT]", + # ("12345778-1234-abcd-ef00-0123456789ac", 1)) + # x.alter_context(("60a15ec5-4de8-11d7-a637-005056a20182", 1)) + # self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4)) + + def test_two_connections(self): + x = ClientConnection("ncalrpc:localhost[DEFAULT]", + ("60a15ec5-4de8-11d7-a637-005056a20182", 1)) + y = ClientConnection("ncalrpc:localhost", + ("60a15ec5-4de8-11d7-a637-005056a20182", 1), + basis_connection=x) + self.assertEquals("\x01\x00\x00\x00", y.request(0, chr(0) * 4)) diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py index 83279a0b30..7fd1bcc5b8 100644 --- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py +++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py @@ -26,6 +26,10 @@ class RpcEchoTests(RpcInterfaceTestCase): def setUp(self): self.conn = echo.rpcecho("ncalrpc:", self.get_loadparm()) + def test_two_contexts(self): + self.conn2 = echo.rpcecho("ncalrpc", basis_connection=self.conn) + self.assertEquals(3, self.conn2.AddOne(2)) + def test_addone(self): self.assertEquals(2, self.conn.AddOne(1)) -- cgit From 5211755563bb2738c328d24a813d86c77eca048f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 04:38:57 +0200 Subject: Expose request timeout variable in Python. (This used to be commit daed1432d22f5fa78907ee0fef9def8802538150) --- source4/librpc/rpc/pyrpc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index aebd484b49..a24c659a55 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -19,6 +19,7 @@ #include "includes.h" #include +#include #include "librpc/rpc/pyrpc.h" #include "librpc/rpc/dcerpc.h" #include "lib/events/events.h" @@ -82,11 +83,18 @@ static PyObject *py_iface_server_name(PyObject *obj, void *closure) } static PyGetSetDef dcerpc_interface_getsetters[] = { - { discard_const_p(char, "server_name"), py_iface_server_name, NULL, + { discard_const_p(char, "server_name"), py_iface_server_name, NULL, discard_const_p(char, "name of the server, if connected over SMB") }, { NULL } }; +static PyMemberDef dcerpc_interface_members[] = { + { discard_const_p(char, "request_timeout"), T_INT, + offsetof(struct dcerpc_pipe, request_timeout), 0, + discard_const_p(char, "request timeout, in seconds") }, + { NULL } +}; + void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status) { if (p != NULL && NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { @@ -282,6 +290,7 @@ PyTypeObject dcerpc_InterfaceType = { .tp_basicsize = sizeof(dcerpc_InterfaceObject), .tp_dealloc = dcerpc_interface_dealloc, .tp_getset = dcerpc_interface_getsetters, + .tp_members = dcerpc_interface_members, .tp_methods = dcerpc_interface_methods, .tp_doc = "ClientConnection(binding, syntax, lp_ctx=None, credentials=None) -> connection\n" "\n" -- cgit From 74126bc6d0211a7674156dfda8ab13054b403a1d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 04:54:38 +0200 Subject: Expose transfer and abstract syntax. (This used to be commit a875e07a37568b7e51c290074d5e3834c2caa4d6) --- source4/librpc/rpc/pyrpc.c | 36 ++++++++++++++++++++-- .../scripting/python/samba/tests/dcerpc/bare.py | 13 +++++--- .../scripting/python/samba/tests/dcerpc/rpcecho.py | 4 +++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index a24c659a55..26242e8235 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -68,8 +68,6 @@ static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *sy return false; } - - static PyObject *py_iface_server_name(PyObject *obj, void *closure) { const char *server_name; @@ -82,9 +80,43 @@ static PyObject *py_iface_server_name(PyObject *obj, void *closure) return PyString_FromString(server_name); } +static PyObject *py_ndr_syntax_id(struct ndr_syntax_id *syntax_id) +{ + PyObject *ret; + char *uuid_str; + + uuid_str = GUID_string(NULL, &syntax_id->uuid); + if (uuid_str == NULL) + return NULL; + + ret = Py_BuildValue("(s,i)", uuid_str, syntax_id->if_version); + + talloc_free(uuid_str); + + return ret; +} + +static PyObject *py_iface_abstract_syntax(PyObject *obj, void *closure) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; + + return py_ndr_syntax_id(&iface->pipe->syntax); +} + +static PyObject *py_iface_transfer_syntax(PyObject *obj, void *closure) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; + + return py_ndr_syntax_id(&iface->pipe->transfer_syntax); +} + static PyGetSetDef dcerpc_interface_getsetters[] = { { discard_const_p(char, "server_name"), py_iface_server_name, NULL, discard_const_p(char, "name of the server, if connected over SMB") }, + { discard_const_p(char, "abstract_syntax"), py_iface_abstract_syntax, NULL, + discard_const_p(char, "syntax id of the abstract syntax") }, + { discard_const_p(char, "transfer_syntax"), py_iface_transfer_syntax, NULL, + discard_const_p(char, "syntax id of the transfersyntax") }, { NULL } }; diff --git a/source4/scripting/python/samba/tests/dcerpc/bare.py b/source4/scripting/python/samba/tests/dcerpc/bare.py index eea6744e42..d75ffc381e 100644 --- a/source4/scripting/python/samba/tests/dcerpc/bare.py +++ b/source4/scripting/python/samba/tests/dcerpc/bare.py @@ -28,11 +28,14 @@ class BareTestCase(TestCase): ("60a15ec5-4de8-11d7-a637-005056a20182", 1)) self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4)) - #def test_alter_context(self): - # x = ClientConnection("ncalrpc:localhost[DEFAULT]", - # ("12345778-1234-abcd-ef00-0123456789ac", 1)) - # x.alter_context(("60a15ec5-4de8-11d7-a637-005056a20182", 1)) - # self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4)) + def test_alter_context(self): + x = ClientConnection("ncalrpc:localhost[DEFAULT]", + ("12345778-1234-abcd-ef00-0123456789ac", 1)) + y = ClientConnection("ncalrpc:localhost", + ("60a15ec5-4de8-11d7-a637-005056a20182", 1), + basis_connection=x) + x.alter_context(("60a15ec5-4de8-11d7-a637-005056a20182", 1)) + # FIXME: self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4)) def test_two_connections(self): x = ClientConnection("ncalrpc:localhost[DEFAULT]", diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py index 7fd1bcc5b8..68b7a42d52 100644 --- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py +++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py @@ -30,6 +30,10 @@ class RpcEchoTests(RpcInterfaceTestCase): self.conn2 = echo.rpcecho("ncalrpc", basis_connection=self.conn) self.assertEquals(3, self.conn2.AddOne(2)) + def test_abstract_syntax(self): + self.assertEquals(("60a15ec5-4de8-11d7-a637-005056a20182", 1), + self.conn.abstract_syntax) + def test_addone(self): self.assertEquals(2, self.conn.AddOne(1)) -- cgit From 5df9e0576ebd8ad737bb2580b52788601b6cf854 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 14:41:54 +0200 Subject: Fix missing colon. (This used to be commit 6b1576f544e2ea2b5ea0b234b724c4989dd49cca) --- source4/scripting/python/samba/tests/dcerpc/rpcecho.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py index 68b7a42d52..bbbd0d76ec 100644 --- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py +++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py @@ -27,7 +27,7 @@ class RpcEchoTests(RpcInterfaceTestCase): self.conn = echo.rpcecho("ncalrpc:", self.get_loadparm()) def test_two_contexts(self): - self.conn2 = echo.rpcecho("ncalrpc", basis_connection=self.conn) + self.conn2 = echo.rpcecho("ncalrpc:", basis_connection=self.conn) self.assertEquals(3, self.conn2.AddOne(2)) def test_abstract_syntax(self): -- cgit From 48433e4351701307e030ac8d596cc00a0ce969e3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 16:26:34 +0200 Subject: Start building IRPC Python support. (This used to be commit 5980c7bfd727825758bda1b94ddf7a7c3f691620) --- source4/lib/messaging/config.mk | 14 ++- source4/lib/messaging/pyirpc.c | 270 ++++++++++++++++++++++++++++++++++------ 2 files changed, 240 insertions(+), 44 deletions(-) diff --git a/source4/lib/messaging/config.mk b/source4/lib/messaging/config.mk index eaf7e3581e..f330ed7cab 100644 --- a/source4/lib/messaging/config.mk +++ b/source4/lib/messaging/config.mk @@ -1,6 +1,3 @@ - -################################################ -# Start SUBSYSTEM MESSAGING [SUBSYSTEM::MESSAGING] PUBLIC_DEPENDENCIES = \ LIBSAMBA-UTIL \ @@ -9,8 +6,13 @@ PUBLIC_DEPENDENCIES = \ UNIX_PRIVS \ UTIL_TDB \ CLUSTER \ - LIBNDR -# End SUBSYSTEM MESSAGING -################################################ + LIBNDR \ + samba-socket MESSAGING_OBJ_FILES = $(libmessagingsrcdir)/messaging.o + +[PYTHON::python_irpc] +LIBRARY_REALNAME = samba/irpc.$(SHLIBEXT) +PRIVATE_DEPENDENCIES = MESSAGING LIBEVENTS + +python_irpc_OBJ_FILES = $(libmessagingsrcdir)/pyirpc.o diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c index 8f6a8b6c72..ba3f830531 100644 --- a/source4/lib/messaging/pyirpc.c +++ b/source4/lib/messaging/pyirpc.c @@ -21,21 +21,182 @@ #include "includes.h" #include +#include "libcli/util/pyerrors.h" #include "lib/messaging/irpc.h" +#include "lib/events/events.h" +#include "cluster/cluster.h" +#include "param/param.h" +PyAPI_DATA(PyTypeObject) messaging_Type; +PyAPI_DATA(PyTypeObject) irpc_InterfaceType; /* messaging clients need server IDs as well ... */ -#define EJS_ID_BASE 0x30000000 +#define PY_ID_BASE 0x30000000 + +typedef struct { + PyObject_HEAD + TALLOC_CTX *mem_ctx; + struct messaging_context *msg_ctx; +} messaging_Object; + +PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) +{ + int i; + struct event_context *ev; + const char *kwnames[] = { "messaging_path", NULL }; + const char *messaging_path = NULL; + messaging_Object *ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s:connect", + discard_const_p(char *, kwnames), &messaging_path)) { + return NULL; + } + + ret = PyObject_New(messaging_Object, &messaging_Type); + if (ret == NULL) + return NULL; + + ret->mem_ctx = talloc_new(NULL); + + ev = event_context_init(ret->mem_ctx); + + if (messaging_path == NULL) { + messaging_path = lp_messaging_path(ret, global_loadparm); + } else { + messaging_path = talloc_strdup(ret->mem_ctx, messaging_path); + } + + /* create a messaging context, looping as we have no way to + allocate temporary server ids automatically */ + for (i=0;i<10000;i++) { + ret->msg_ctx = messaging_init(ret->mem_ctx, + messaging_path, + cluster_id(PY_ID_BASE, i), + lp_iconv_convenience(global_loadparm), + ev); + if (ret->msg_ctx) break; + } + + if (ret->msg_ctx == NULL) { + PyErr_SetString(PyExc_RuntimeError, "messaging_connect unable to create a messaging context"); + talloc_free(ret->mem_ctx); + return NULL; + } + + return (PyObject *)ret; +} + +static void py_messaging_dealloc(PyObject *self) +{ + messaging_Object *iface = (messaging_Object *)self; + talloc_free(iface->msg_ctx); + PyObject_Del(self); +} + +static bool server_id_from_py(PyObject *object, struct server_id *server_id) +{ + if (!PyTuple_Check(object)) { + PyErr_SetString(PyExc_ValueError, "Expected tuple"); + return false; + } + + return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node); +} + +static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + int msg_type; + DATA_BLOB data; + PyObject *target; + NTSTATUS status; + struct server_id server; + const char *kwnames[] = { "target", "msg_type", "data", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ois#|:send", + discard_const_p(char *, kwnames), &target, &msg_type, &data.data, &data.length)) { + return NULL; + } + + if (!server_id_from_py(target, &server)) + return NULL; + + status = messaging_send(iface->msg_ctx, server, msg_type, &data); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return Py_None; +} + +static void py_msg_callback_wrapper(struct messaging_context *msg, void *private, + uint32_t msg_type, + struct server_id server_id, DATA_BLOB *data) +{ + PyObject *callback = (PyObject *)private; + + PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, + server_id.id, server_id.id2, server_id.node, + data->data, data->length); +} + +static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + int msg_type; + PyObject *callback; + NTSTATUS status; + const char *kwnames[] = { "msg_type", "callback", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO|:send", + discard_const_p(char *, kwnames), &msg_type, &callback)) { + return NULL; + } + + Py_INCREF(callback); + + status = messaging_register(iface->msg_ctx, callback, + msg_type, py_msg_callback_wrapper); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return Py_None; +} + + +static PyMethodDef py_messaging_methods[] = { + { "send", (PyCFunction)py_messaging_send, METH_VARARGS|METH_KEYWORDS, + "S.send(target, msg_type, data) -> None\nSend a message" }, + { "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS, + "S.register(msg_type, callback) -> None\nRegister a message handler" }, + { NULL, NULL, 0, NULL } +}; + +PyTypeObject messaging_Type = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "irpc.Messaging", + .tp_basicsize = sizeof(messaging_Object), + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_new = py_messaging_connect, + .tp_dealloc = py_messaging_dealloc, + .tp_methods = py_messaging_methods, +}; + /* state of a irpc 'connection' */ -struct ejs_irpc_connection { +typedef struct { + PyObject_HEAD const char *server_name; struct server_id *dest_ids; struct messaging_context *msg_ctx; -}; + TALLOC_CTX *mem_ctx; +} irpc_InterfaceObject; /* setup a context for talking to a irpc server @@ -43,58 +204,77 @@ struct ejs_irpc_connection { status = irpc.connect("smb_server"); */ -PyObject *py_irpc_connect(PyObject *args, PyObjet *kwargs) +PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) { - NTSTATUS status; int i; struct event_context *ev; - struct ejs_irpc_connection *p; - struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); + const char *kwnames[] = { "server", "messaging_path", NULL }; + char *server; + const char *messaging_path = NULL; + irpc_InterfaceObject *ret; - /* validate arguments */ - if (argc != 1) { - ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); - return -1; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|s:connect", + discard_const_p(char *, kwnames), &server, &messaging_path)) { + return NULL; } - p = talloc(this, struct ejs_irpc_connection); - if (p == NULL) { - return -1; - } + ret = PyObject_New(irpc_InterfaceObject, &irpc_InterfaceType); + if (ret == NULL) + return NULL; + + ret->mem_ctx = talloc_new(NULL); - p->server_name = argv[0]; + ret->server_name = server; - ev = mprEventCtx(); + ev = event_context_init(ret->mem_ctx); + + if (messaging_path == NULL) { + messaging_path = lp_messaging_path(ret, global_loadparm); + } /* create a messaging context, looping as we have no way to allocate temporary server ids automatically */ for (i=0;i<10000;i++) { - p->msg_ctx = messaging_init(p, - lp_messaging_path(p, mprLpCtx()), - cluster_id(EJS_ID_BASE, i), - lp_iconv_convenience(mprLpCtx()), + ret->msg_ctx = messaging_init(ret->mem_ctx, + messaging_path, + cluster_id(PY_ID_BASE, i), + lp_iconv_convenience(global_loadparm), ev); - if (p->msg_ctx) break; + if (ret->msg_ctx) break; } - if (p->msg_ctx == NULL) { - ejsSetErrorMsg(eid, "irpc_connect unable to create a messaging context"); - talloc_free(p); - return -1; + if (ret->msg_ctx == NULL) { + PyErr_SetString(PyExc_RuntimeError, "irpc_connect unable to create a messaging context"); + talloc_free(ret->mem_ctx); + return NULL; } - p->dest_ids = irpc_servers_byname(p->msg_ctx, p, p->server_name); - if (p->dest_ids == NULL || p->dest_ids[0].id == 0) { - talloc_free(p); - status = NT_STATUS_OBJECT_NAME_NOT_FOUND; + ret->dest_ids = irpc_servers_byname(ret->msg_ctx, ret->mem_ctx, ret->server_name); + if (ret->dest_ids == NULL || ret->dest_ids[0].id == 0) { + talloc_free(ret->mem_ctx); + PyErr_SetNTSTATUS(NT_STATUS_OBJECT_NAME_NOT_FOUND); + return NULL; } else { - mprSetPtrChild(this, "irpc", p); - status = NT_STATUS_OK; + return (PyObject *)ret; } +} - mpr_Return(eid, mprNTSTATUS(status)); - return 0; +static void py_irpc_dealloc(PyObject *self) +{ + irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self; + talloc_free(iface->mem_ctx); + PyObject_Del(self); } +PyTypeObject irpc_InterfaceType = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "irpc.ClientConnection", + .tp_basicsize = sizeof(irpc_InterfaceObject), + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_new = py_irpc_connect, + .tp_dealloc = py_irpc_dealloc, +}; + +#if 0 /* make an irpc call - called via the same interface as rpc */ @@ -192,11 +372,25 @@ done: } return 0; } +#endif - - -static void initirpc(void) +void initirpc(void) { PyObject *mod; - mod = Py_InitModule("irpc", irpc_methods); + + if (PyType_Ready(&irpc_InterfaceType) < 0) + return; + + if (PyType_Ready(&messaging_Type) < 0) + return; + + mod = Py_InitModule3("irpc", NULL, "Internal RPC"); + if (mod == NULL) + return; + + Py_INCREF((PyObject *)&irpc_InterfaceType); + PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_InterfaceType); + + Py_INCREF((PyObject *)&messaging_Type); + PyModule_AddObject(mod, "Messaging", (PyObject *)&messaging_Type); } -- cgit From 2067fc60c50c1ca527faccdaa1fff56eec2d4c08 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 16:47:12 +0200 Subject: Add tests for irpc python bindings. (This used to be commit 1ce0632afeb94a69bf286706b3b1f9f4be7ea91f) --- source4/lib/messaging/tests/bindings.py | 25 +++++++++++++++++++++++++ source4/selftest/samba4_tests.sh | 1 + 2 files changed, 26 insertions(+) create mode 100644 source4/lib/messaging/tests/bindings.py diff --git a/source4/lib/messaging/tests/bindings.py b/source4/lib/messaging/tests/bindings.py new file mode 100644 index 0000000000..ffb4dae326 --- /dev/null +++ b/source4/lib/messaging/tests/bindings.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +from samba.irpc import Messaging +from unittest import TestCase + +class MessagingTests(TestCase): + pass diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index 2076ed9c65..11d909a2bc 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -344,6 +344,7 @@ plantest "dcerpc.bare.python" dc $SUBUNITRUN samba.tests.dcerpc.bare plantest "samdb.python" dc $SUBUNITRUN samba.tests.samdb plantest "unixinfo.python" dc $SUBUNITRUN samba.tests.dcerpc.unix plantest "events.python" none PYTHONPATH="$PYTHONPATH:lib/events" $SUBUNITRUN tests +plantest "messaging.python" none PYTHONPATH="$PYTHONPATH:lib/messaging/tests" $SUBUNITRUN bindings plantest "samba3sam.python" none PYTHONPATH="$PYTHONPATH:dsdb/samdb/ldb_modules/tests" $SUBUNITRUN samba3sam plantest "rpcecho.python" dc $SUBUNITRUN samba.tests.dcerpc.rpcecho plantest "winreg.python" dc $SUBUNITRUN -U\$USERNAME%\$PASSWORD samba.tests.dcerpc.registry -- cgit From 491f0a8dec0223928f3cb317280a0d7449c025e4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 17:53:10 +0200 Subject: Use separate function for in argument parsing. (This used to be commit 737059795ce150066ff775909030eebc54b595d9) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 159 +++++++++++++++++---------- 1 file changed, 102 insertions(+), 57 deletions(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index dbbdb6bca1..9cff4cd94b 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -323,25 +323,9 @@ sub get_metadata_var($) return undef; } -sub PythonFunctionBody($$$) +sub find_metadata_args($) { - my ($self, $fn, $iface, $prettyname) = @_; - - $self->pidl("dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;"); - $self->pidl("NTSTATUS status;"); - $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); - $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); - $self->pidl("PyObject *result = Py_None;"); - - my $env = GenerateFunctionInEnv($fn, "r->"); - my $result_size = 0; - - my $args_format = ""; - my $args_string = ""; - my $args_names = ""; - - my $signature = "S.$prettyname("; - + my ($fn) = @_; my $metadata_args = { in => {}, out => {} }; # Determine arguments that are metadata for other arguments (size_is/length_is) @@ -354,34 +338,37 @@ sub PythonFunctionBody($$$) } } + return $metadata_args; +} + +sub PythonFunctionBody($$$$$) +{ + my ($self, $fn, $iface, $prettyname, $infn, $insignature) = @_; + + $self->pidl("dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;"); + $self->pidl("NTSTATUS status;"); + $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); + $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); + $self->pidl("PyObject *result = Py_None;"); + + my $env = GenerateFunctionInEnv($fn, "r->"); + my $result_size = 0; + + my $signature = "S.$prettyname($insignature) -> "; + + my $metadata_args = find_metadata_args($fn); + foreach my $e (@{$fn->{ELEMENTS}}) { + next unless (grep(/out/,@{$e->{DIRECTION}})); next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}})); $self->pidl("PyObject *py_$e->{NAME};"); - if (grep(/out/,@{$e->{DIRECTION}})) { - $result_size++; - } - if (grep(/in/,@{$e->{DIRECTION}})) { - $args_format .= "O"; - $args_string .= ", &py_$e->{NAME}"; - $args_names .= "\"$e->{NAME}\", "; - $signature .= "$e->{NAME}, "; - } - } - if (substr($signature, -2) eq ", ") { - $signature = substr($signature, 0, -2); + $result_size++; } - $signature.= ") -> "; - - $self->pidl("const char *kwnames[] = {"); - $self->indent; - $self->pidl($args_names . "NULL"); - $self->deindent; - $self->pidl("};"); - $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"$args_format:$fn->{NAME}\", discard_const_p(char *, kwnames)$args_string)) {"); + $self->pidl("if (!$infn(args, kwargs, r)) {"); $self->indent; + $self->pidl("talloc_free(mem_ctx);"); $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); @@ -391,23 +378,6 @@ sub PythonFunctionBody($$$) $result_size++ unless ($fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "NTSTATUS"); } - my $fail = "talloc_free(mem_ctx); return NULL;"; - foreach my $e (@{$fn->{ELEMENTS}}) { - next unless (grep(/in/,@{$e->{DIRECTION}})); - if ($metadata_args->{in}->{$e->{NAME}}) { - my $py_var = "py_".$metadata_args->{in}->{$e->{NAME}}; - $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);"); - my $val = "PyList_Size($py_var)"; - if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { - $self->pidl("r->in.$e->{NAME} = talloc_ptrtype(mem_ctx, r->in.$e->{NAME});"); - $self->pidl("*r->in.$e->{NAME} = $val;"); - } else { - $self->pidl("r->in.$e->{NAME} = $val;"); - } - } else { - $self->ConvertObjectFromPython($env, "mem_ctx", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", $fail); - } - } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); $self->indent; @@ -471,6 +441,74 @@ sub PythonFunctionBody($$$) return $signature; } +sub PythonFunctionParseIn($$$) +{ + my ($self, $fn, $fnname) = @_; + my $metadata_args = find_metadata_args($fn); + + my $infnname = "$fnname\_in"; + + $self->pidl("static bool $infnname(PyObject *args, PyObject *kwargs, struct $fn->{NAME} *r)"); + $self->pidl("{"); + $self->indent; + my $args_format = ""; + my $args_string = ""; + my $args_names = ""; + my $signature = ""; + + foreach my $e (@{$fn->{ELEMENTS}}) { + next unless (grep(/in/,@{$e->{DIRECTION}})); + next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or + ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}})); + $self->pidl("PyObject *py_$e->{NAME};"); + $args_format .= "O"; + $args_string .= ", &py_$e->{NAME}"; + $args_names .= "\"$e->{NAME}\", "; + $signature .= "$e->{NAME}, "; + } + if (substr($signature, -2) eq ", ") { + $signature = substr($signature, 0, -2); + } + $self->pidl("const char *kwnames[] = {"); + $self->indent; + $self->pidl($args_names . "NULL"); + $self->deindent; + $self->pidl("};"); + + $self->pidl(""); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"$args_format:$fn->{NAME}\", discard_const_p(char *, kwnames)$args_string)) {"); + $self->indent; + $self->pidl("return false;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + + my $env = GenerateFunctionOutEnv($fn, "r->"); + + my $fail = "return false;"; + foreach my $e (@{$fn->{ELEMENTS}}) { + next unless (grep(/in/,@{$e->{DIRECTION}})); + if ($metadata_args->{in}->{$e->{NAME}}) { + my $py_var = "py_".$metadata_args->{in}->{$e->{NAME}}; + $self->pidl("PY_CHECK_TYPE(PyList, $py_var, $fail);"); + my $val = "PyList_Size($py_var)"; + if ($e->{LEVELS}[0]->{TYPE} eq "POINTER") { + $self->pidl("r->in.$e->{NAME} = talloc_ptrtype(r, r->in.$e->{NAME});"); + $self->pidl("*r->in.$e->{NAME} = $val;"); + } else { + $self->pidl("r->in.$e->{NAME} = $val;"); + } + } else { + $self->ConvertObjectFromPython($env, "r", $e, "py_$e->{NAME}", "r->in.$e->{NAME}", $fail); + } + } + $self->pidl("return true;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + return ($infnname, $signature); +} + sub PythonFunction($$$) { my ($self, $fn, $iface, $prettyname) = @_; @@ -478,6 +516,13 @@ sub PythonFunction($$$) my $fnname = "py_$fn->{NAME}"; my $docstring = $self->DocString($fn, $fn->{NAME}); + my $insignature; + my $infn; + + if (not has_property($fn, "todo")) { + ($infn, $insignature) = $self->PythonFunctionParseIn($fn, $fnname); + } + $self->pidl("static PyObject *$fnname(PyObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; @@ -486,7 +531,7 @@ sub PythonFunction($$$) $self->pidl("return NULL;"); unless ($docstring) { $docstring = "NULL"; } } else { - my $signature = $self->PythonFunctionBody($fn, $iface, $prettyname); + my $signature = $self->PythonFunctionBody($fn, $iface, $prettyname, $infn, $insignature); if ($docstring) { $docstring = "\"$signature\\n\\n\"$docstring"; -- cgit From 3421691e69f84228a9bd149d760e394043db5b5c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 18:15:55 +0200 Subject: Move result tuple generation out of main Python function running. (This used to be commit 5f07faf9c954229bf1cf6401eff81bdab4e242ae) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 81 +++++++++++++++++----------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 9cff4cd94b..0792e4fea3 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -343,7 +343,7 @@ sub find_metadata_args($) sub PythonFunctionBody($$$$$) { - my ($self, $fn, $iface, $prettyname, $infn, $insignature) = @_; + my ($self, $fn, $iface, $prettyname, $infn, $outfn) = @_; $self->pidl("dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); @@ -351,21 +351,6 @@ sub PythonFunctionBody($$$$$) $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); $self->pidl("PyObject *result = Py_None;"); - my $env = GenerateFunctionInEnv($fn, "r->"); - my $result_size = 0; - - my $signature = "S.$prettyname($insignature) -> "; - - my $metadata_args = find_metadata_args($fn); - - foreach my $e (@{$fn->{ELEMENTS}}) { - next unless (grep(/out/,@{$e->{DIRECTION}})); - next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or - ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}})); - $self->pidl("PyObject *py_$e->{NAME};"); - $result_size++; - } - $self->pidl("if (!$infn(args, kwargs, r)) {"); $self->indent; $self->pidl("talloc_free(mem_ctx);"); @@ -374,10 +359,6 @@ sub PythonFunctionBody($$$$$) $self->pidl("}"); $self->pidl(""); - if ($fn->{RETURN_TYPE}) { - $result_size++ unless ($fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "NTSTATUS"); - } - $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); $self->indent; @@ -388,7 +369,41 @@ sub PythonFunctionBody($$$$$) $self->pidl("}"); $self->pidl(""); - $env = GenerateFunctionOutEnv($fn, "r->"); + $self->pidl("result = $outfn(r);"); + $self->pidl(""); + $self->pidl("talloc_free(mem_ctx);"); + $self->pidl("return result;"); + +} + +sub PythonFunctionUnpackOut($$$) +{ + my ($self, $fn, $fnname) = @_; + + my $outfnname = "unpack_$fnname\_args_out"; + my $signature = ""; + + my $metadata_args = find_metadata_args($fn); + + my $env = GenerateFunctionOutEnv($fn, "r->"); + my $result_size = 0; + + $self->pidl("static PyObject *$outfnname(struct $fn->{NAME} *r)"); + $self->pidl("{"); + $self->indent; + $self->pidl("PyObject *result = Py_None;"); + foreach my $e (@{$fn->{ELEMENTS}}) { + next unless (grep(/out/,@{$e->{DIRECTION}})); + next if (($metadata_args->{in}->{$e->{NAME}} and grep(/in/, @{$e->{DIRECTION}})) or + ($metadata_args->{out}->{$e->{NAME}}) and grep(/out/, @{$e->{DIRECTION}})); + $self->pidl("PyObject *py_$e->{NAME};"); + $result_size++; + } + + if ($fn->{RETURN_TYPE}) { + $result_size++ unless ($fn->{RETURN_TYPE} eq "WERROR" or $fn->{RETURN_TYPE} eq "NTSTATUS"); + } + my $i = 0; if ($result_size > 1) { @@ -415,9 +430,9 @@ sub PythonFunctionBody($$$$$) } if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") { - $self->handle_ntstatus("r->out.result", "NULL", "mem_ctx"); + $self->handle_ntstatus("r->out.result", "NULL", undef); } elsif (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "WERROR") { - $self->handle_werror("r->out.result", "NULL", "mem_ctx"); + $self->handle_werror("r->out.result", "NULL", undef); } elsif (defined($fn->{RETURN_TYPE})) { my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result"); if ($result_size > 1) { @@ -435,18 +450,19 @@ sub PythonFunctionBody($$$$$) $signature .= ")"; } - $self->pidl("talloc_free(mem_ctx);"); $self->pidl("return result;"); + $self->deindent; + $self->pidl("}"); - return $signature; + return ($outfnname, $signature); } -sub PythonFunctionParseIn($$$) +sub PythonFunctionPackIn($$$) { my ($self, $fn, $fnname) = @_; my $metadata_args = find_metadata_args($fn); - my $infnname = "$fnname\_in"; + my $infnname = "pack_$fnname\_args_in"; $self->pidl("static bool $infnname(PyObject *args, PyObject *kwargs, struct $fn->{NAME} *r)"); $self->pidl("{"); @@ -516,11 +532,12 @@ sub PythonFunction($$$) my $fnname = "py_$fn->{NAME}"; my $docstring = $self->DocString($fn, $fn->{NAME}); - my $insignature; - my $infn; + my ($insignature, $outsignature); + my ($infn, $outfn); if (not has_property($fn, "todo")) { - ($infn, $insignature) = $self->PythonFunctionParseIn($fn, $fnname); + ($infn, $insignature) = $self->PythonFunctionPackIn($fn, $fnname); + ($outfn, $outsignature) = $self->PythonFunctionUnpackOut($fn, $fnname); } $self->pidl("static PyObject *$fnname(PyObject *self, PyObject *args, PyObject *kwargs)"); @@ -531,8 +548,8 @@ sub PythonFunction($$$) $self->pidl("return NULL;"); unless ($docstring) { $docstring = "NULL"; } } else { - my $signature = $self->PythonFunctionBody($fn, $iface, $prettyname, $infn, $insignature); - + $self->PythonFunctionBody($fn, $iface, $prettyname, $infn, $outfn); + my $signature = "S.$prettyname($insignature) -> $outsignature"; if ($docstring) { $docstring = "\"$signature\\n\\n\"$docstring"; } else { -- cgit From 01fd6886466f1976d30b4deba4fe224344f760c2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 18:27:32 +0200 Subject: Fix environment generation. (This used to be commit 19b46b50c982eb01909fe31d5abd304a1dd13577) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 0792e4fea3..720d066360 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -499,7 +499,7 @@ sub PythonFunctionPackIn($$$) $self->pidl("}"); $self->pidl(""); - my $env = GenerateFunctionOutEnv($fn, "r->"); + my $env = GenerateFunctionInEnv($fn, "r->"); my $fail = "return false;"; foreach my $e (@{$fn->{ELEMENTS}}) { -- cgit From 77acb789e2ea5eca3b0602e6397df76c5af55efe Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 23:14:48 +0200 Subject: Trim the size of the Python bindings a bit. (This used to be commit 717ce0b640a5c3aa62804b9869ef4dcc0f71b7ba) --- source4/librpc/rpc/dcerpc.h | 1 + source4/librpc/rpc/pyrpc.c | 101 ++++++++++++++++++++++++++- source4/librpc/rpc/pyrpc.h | 16 +++++ source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 83 +++++++--------------- 4 files changed, 141 insertions(+), 60 deletions(-) diff --git a/source4/librpc/rpc/dcerpc.h b/source4/librpc/rpc/dcerpc.h index ca6311a4fc..487f9f2eda 100644 --- a/source4/librpc/rpc/dcerpc.h +++ b/source4/librpc/rpc/dcerpc.h @@ -370,5 +370,6 @@ NTSTATUS dcerpc_request(struct dcerpc_pipe *p, DATA_BLOB *stub_data_in, DATA_BLOB *stub_data_out); +typedef NTSTATUS (*dcerpc_call_fn) (struct dcerpc_pipe *, TALLOC_CTX *, void *); #endif /* __DCERPC_H__ */ diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 26242e8235..b04ca0be30 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -24,6 +24,103 @@ #include "librpc/rpc/dcerpc.h" #include "lib/events/events.h" +typedef struct dcerpc_FunctionObject { + PyObject_HEAD + struct PyNdrRpcMethodDef *method_def; +} dcerpc_FunctionObject; + +static PyMemberDef dcerpc_function_members[] = { + { discard_const_p(char, "__opnum__"), T_LONG, + offsetof(struct dcerpc_FunctionObject, method_def), 0, + discard_const_p(char, "opnum") }, + { NULL } +}; + + +static PyObject * dcerpc_function_ndr_pack_in(PyObject *self, PyObject *args, PyObject *kwargs) +{ + /* FIXME */ + return Py_None; +} + +static PyMethodDef dcerpc_function_methods[] = { + { "__ndr_pack_in__", (PyCFunction)dcerpc_function_ndr_pack_in, METH_VARARGS|METH_KEYWORDS, NULL }, + { NULL, NULL, 0, NULL }, +}; + +PyTypeObject dcerpc_FunctionType = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "dcerpc.Function", + .tp_basicsize = sizeof(dcerpc_FunctionObject), + .tp_members = dcerpc_function_members, + .tp_methods = dcerpc_function_methods, + .tp_flags = Py_TPFLAGS_DEFAULT, +}; + +PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; + struct PyNdrRpcMethodDef *md = wrapped; + TALLOC_CTX *mem_ctx; + NTSTATUS status; + void *r; + PyObject *result = Py_None; + + if (md->pack_in_data == NULL || md->unpack_out_data == NULL) { + PyErr_SetString(PyExc_NotImplementedError, "No marshalling code available yet"); + return NULL; + } + + mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) + return NULL; + + r = talloc_zero_size(mem_ctx, md->table->calls[md->opnum].struct_size); + if (r == NULL) + return NULL; + + if (!md->pack_in_data(args, kwargs, r)) { + talloc_free(mem_ctx); + return NULL; + } + + status = md->call(iface->pipe, mem_ctx, r); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetDCERPCStatus(iface->pipe, status); + talloc_free(mem_ctx); + return NULL; + } + + result = md->unpack_out_data(r); + + talloc_free(mem_ctx); + return result; +} + + +PyObject *PyDescr_NewNdrRpcMethod(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *md) +{ + struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1); + + wb->name = md->name; + wb->flags = PyWrapperFlag_KEYWORDS; + wb->wrapper = py_dcerpc_call_wrapper; + wb->doc = md->doc; + + return PyDescr_NewWrapper(ifacetype, wb, md); +} + +bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *mds) +{ + int i; + for (i = 0; mds[i].name; i++) { + PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, + PyDescr_NewNdrRpcMethod(ifacetype, &mds[i])); + } + + return true; +} + static bool PyString_AsGUID(PyObject *object, struct GUID *uuid) { NTSTATUS status; @@ -311,7 +408,6 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje talloc_free(mem_ctx); return NULL; } - ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC; return (PyObject *)ret; } @@ -341,6 +437,9 @@ void initbase(void) if (PyType_Ready(&dcerpc_InterfaceType) < 0) return; + if (PyType_Ready(&dcerpc_FunctionType) < 0) + return; + m = Py_InitModule3("base", NULL, "DCE/RPC protocol implementation"); if (m == NULL) return; diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 209d7d3f1f..5ec9c6ed83 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -52,4 +52,20 @@ PyAPI_DATA(PyTypeObject) dcerpc_InterfaceType; void PyErr_SetDCERPCStatus(struct dcerpc_pipe *pipe, NTSTATUS status); +typedef bool (*py_data_pack_fn) (PyObject *args, PyObject *kwargs, void *r); +typedef PyObject *(*py_data_unpack_fn) (void *r); + +struct PyNdrRpcMethodDef { + const char *name; + const char *doc; + dcerpc_call_fn call; + py_data_pack_fn pack_in_data; + py_data_unpack_fn unpack_out_data; + uint32_t opnum; + const struct ndr_interface_table *table; +}; + +bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, struct PyNdrRpcMethodDef *mds); +PyObject *PyDescr_NewNdrRpcMethod(PyTypeObject *type, struct PyNdrRpcMethodDef *md); + #endif /* _PYRPC_H_ */ diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 720d066360..0832401d7d 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -21,7 +21,8 @@ $VERSION = '0.01'; sub new($) { my ($class) = @_; my $self = { res => "", res_hdr => "", tabs => "", constants => {}, - module_methods => [], module_objects => [], module_types => []}; + module_methods => [], module_objects => [], module_types => [], + readycode => [] }; bless($self, $class); } @@ -341,41 +342,6 @@ sub find_metadata_args($) return $metadata_args; } -sub PythonFunctionBody($$$$$) -{ - my ($self, $fn, $iface, $prettyname, $infn, $outfn) = @_; - - $self->pidl("dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;"); - $self->pidl("NTSTATUS status;"); - $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); - $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); - $self->pidl("PyObject *result = Py_None;"); - - $self->pidl("if (!$infn(args, kwargs, r)) {"); - $self->indent; - $self->pidl("talloc_free(mem_ctx);"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - - $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); - $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); - $self->indent; - $self->pidl("PyErr_SetDCERPCStatus(iface->pipe, status);"); - $self->pidl("talloc_free(mem_ctx);"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - - $self->pidl("result = $outfn(r);"); - $self->pidl(""); - $self->pidl("talloc_free(mem_ctx);"); - $self->pidl("return result;"); - -} - sub PythonFunctionUnpackOut($$$) { my ($self, $fn, $fnname) = @_; @@ -453,6 +419,7 @@ sub PythonFunctionUnpackOut($$$) $self->pidl("return result;"); $self->deindent; $self->pidl("}"); + $self->pidl(""); return ($outfnname, $signature); } @@ -535,20 +502,13 @@ sub PythonFunction($$$) my ($insignature, $outsignature); my ($infn, $outfn); - if (not has_property($fn, "todo")) { - ($infn, $insignature) = $self->PythonFunctionPackIn($fn, $fnname); - ($outfn, $outsignature) = $self->PythonFunctionUnpackOut($fn, $fnname); - } - - $self->pidl("static PyObject *$fnname(PyObject *self, PyObject *args, PyObject *kwargs)"); - $self->pidl("{"); - $self->indent; if (has_property($fn, "todo")) { - $self->pidl("PyErr_SetString(PyExc_NotImplementedError, \"No marshalling code available yet for $prettyname\");"); - $self->pidl("return NULL;"); unless ($docstring) { $docstring = "NULL"; } + $infn = "NULL"; + $outfn = "NULL"; } else { - $self->PythonFunctionBody($fn, $iface, $prettyname, $infn, $outfn); + ($infn, $insignature) = $self->PythonFunctionPackIn($fn, $fnname); + ($outfn, $outsignature) = $self->PythonFunctionUnpackOut($fn, $fnname); my $signature = "S.$prettyname($insignature) -> $outsignature"; if ($docstring) { $docstring = "\"$signature\\n\\n\"$docstring"; @@ -557,11 +517,7 @@ sub PythonFunction($$$) } } - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - - return ($fnname, $docstring); + return ($infn, $outfn, $docstring); } sub handle_werror($$$$) @@ -689,18 +645,18 @@ sub Interface($$$) $prettyname =~ s/^$interface->{NAME}_//; $prettyname =~ s/^$basename\_//; - my ($fnname, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}, $prettyname); + my ($infn, $outfn, $fndocstring) = $self->PythonFunction($d, $interface->{NAME}, $prettyname); - push (@fns, [$fnname, $prettyname, $fndocstring]); + push (@fns, [$infn, $outfn, "dcerpc_$d->{NAME}", $prettyname, $fndocstring, $d->{OPNUM}]); } - $self->pidl("static PyMethodDef interface_$interface->{NAME}\_methods[] = {"); + $self->pidl("static struct PyNdrRpcMethodDef interface_$interface->{NAME}\_methods[] = {"); $self->indent; foreach my $d (@fns) { - my ($c_fn, $prettyname, $docstring) = @$d; - $self->pidl("{ \"$prettyname\", (PyCFunction)$c_fn, METH_VARARGS|METH_KEYWORDS, $docstring },"); + my ($infn, $outfn, $callfn, $prettyname, $docstring, $opnum) = @$d; + $self->pidl("{ \"$prettyname\", $docstring, (dcerpc_call_fn)$callfn, (py_data_pack_fn)$infn, (py_data_unpack_fn)$outfn, $opnum, &ndr_table_$interface->{NAME} },"); } - $self->pidl("{ NULL, NULL, 0, NULL }"); + $self->pidl("{ NULL }"); $self->deindent; $self->pidl("};"); $self->pidl(""); @@ -806,7 +762,6 @@ sub Interface($$$) $self->pidl(".tp_name = \"$basename.$interface->{NAME}\","); $self->pidl(".tp_basicsize = sizeof(dcerpc_InterfaceObject),"); $self->pidl(".tp_base = &dcerpc_InterfaceType,"); - $self->pidl(".tp_methods = interface_$interface->{NAME}_methods,"); $self->pidl(".tp_doc = $docstring,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); $self->pidl(".tp_new = interface_$interface->{NAME}_new,"); @@ -816,6 +771,7 @@ sub Interface($$$) $self->pidl(""); $self->register_module_typeobject($interface->{NAME}, "&$interface->{NAME}_InterfaceType"); + $self->register_module_readycode(["if (!PyInterface_AddNdrRpcMethods(&$interface->{NAME}_InterfaceType, interface_$interface->{NAME}_methods))", "\treturn;", ""]); } $self->pidl_hdr("\n"); @@ -838,6 +794,13 @@ sub register_module_typeobject($$$) push (@{$self->{module_types}}, [$name, $py_name]) } +sub register_module_readycode($$) +{ + my ($self, $code) = @_; + + push (@{$self->{readycode}}, @$code); +} + sub register_module_object($$$) { my ($self, $name, $py_name) = @_; @@ -1195,6 +1158,8 @@ sub Parse($$$$$) $self->pidl("\treturn;"); } + $self->pidl($_) foreach (@{$self->{readycode}}); + $self->pidl(""); $self->pidl("m = Py_InitModule3(\"$basename\", $basename\_methods, \"$basename DCE/RPC\");"); -- cgit From eae3658674d7c04fe65b008223995ead9e2957e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 23:22:05 +0200 Subject: Fix compilation errors. (This used to be commit daae053365cf6c5be7b31aa51a239c2660cfc120) --- source4/librpc/rpc/pyrpc.c | 7 ++++++- source4/librpc/rpc/pyrpc.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index b04ca0be30..0248a9a6e2 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -101,13 +101,18 @@ PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *PyDescr_NewNdrRpcMethod(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *md) { struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1); + PyObject *ret; wb->name = md->name; wb->flags = PyWrapperFlag_KEYWORDS; wb->wrapper = py_dcerpc_call_wrapper; wb->doc = md->doc; - return PyDescr_NewWrapper(ifacetype, wb, md); + ret = PyDescr_NewWrapper(ifacetype, wb, md); + + PyObject_SetAttrString(ret, "foo", PyString_FromString("bla")); + + return ret; } bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *mds) diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 5ec9c6ed83..77705db9f6 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -21,6 +21,7 @@ #define _PYRPC_H_ #include "libcli/util/pyerrors.h" +#include "librpc/rpc/dcerpc.h" #define PY_CHECK_TYPE(type, var, fail) \ if (!type ## _Check(var)) {\ -- cgit From 22778de5823ce979a2e8d389e2029a78da543490 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 00:38:12 +0200 Subject: Remove some unused cruft. (This used to be commit 8f47157f09cbf4200f0f7c5efe8750fd5d316a3b) --- source4/librpc/rpc/pyrpc.c | 73 ++++++++++++---------------------------------- source4/librpc/rpc/pyrpc.h | 1 - 2 files changed, 18 insertions(+), 56 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 0248a9a6e2..fae3d727fa 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -24,43 +24,8 @@ #include "librpc/rpc/dcerpc.h" #include "lib/events/events.h" -typedef struct dcerpc_FunctionObject { - PyObject_HEAD - struct PyNdrRpcMethodDef *method_def; -} dcerpc_FunctionObject; - -static PyMemberDef dcerpc_function_members[] = { - { discard_const_p(char, "__opnum__"), T_LONG, - offsetof(struct dcerpc_FunctionObject, method_def), 0, - discard_const_p(char, "opnum") }, - { NULL } -}; - - -static PyObject * dcerpc_function_ndr_pack_in(PyObject *self, PyObject *args, PyObject *kwargs) +static PyObject *py_dcerpc_run_function(dcerpc_InterfaceObject *iface, struct PyNdrRpcMethodDef *md, PyObject *args, PyObject *kwargs) { - /* FIXME */ - return Py_None; -} - -static PyMethodDef dcerpc_function_methods[] = { - { "__ndr_pack_in__", (PyCFunction)dcerpc_function_ndr_pack_in, METH_VARARGS|METH_KEYWORDS, NULL }, - { NULL, NULL, 0, NULL }, -}; - -PyTypeObject dcerpc_FunctionType = { - PyObject_HEAD_INIT(NULL) 0, - .tp_name = "dcerpc.Function", - .tp_basicsize = sizeof(dcerpc_FunctionObject), - .tp_members = dcerpc_function_members, - .tp_methods = dcerpc_function_methods, - .tp_flags = Py_TPFLAGS_DEFAULT, -}; - -PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) -{ - dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; - struct PyNdrRpcMethodDef *md = wrapped; TALLOC_CTX *mem_ctx; NTSTATUS status; void *r; @@ -97,30 +62,31 @@ PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, return result; } +static PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; + struct PyNdrRpcMethodDef *md = wrapped; -PyObject *PyDescr_NewNdrRpcMethod(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *md) -{ - struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1); - PyObject *ret; - - wb->name = md->name; - wb->flags = PyWrapperFlag_KEYWORDS; - wb->wrapper = py_dcerpc_call_wrapper; - wb->doc = md->doc; - - ret = PyDescr_NewWrapper(ifacetype, wb, md); - - PyObject_SetAttrString(ret, "foo", PyString_FromString("bla")); - - return ret; + return py_dcerpc_run_function(iface, md, args, kwargs); } + bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *mds) { int i; for (i = 0; mds[i].name; i++) { + PyObject *ret; + struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1); + + wb->name = discard_const_p(char, mds[i].name); + wb->flags = PyWrapperFlag_KEYWORDS; + wb->wrapper = (wrapperfunc)py_dcerpc_call_wrapper; + wb->doc = discard_const_p(char, mds[i].doc); + + ret = PyDescr_NewWrapper(ifacetype, wb, &mds[i]); + PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, - PyDescr_NewNdrRpcMethod(ifacetype, &mds[i])); + (PyObject *)ret); } return true; @@ -442,9 +408,6 @@ void initbase(void) if (PyType_Ready(&dcerpc_InterfaceType) < 0) return; - if (PyType_Ready(&dcerpc_FunctionType) < 0) - return; - m = Py_InitModule3("base", NULL, "DCE/RPC protocol implementation"); if (m == NULL) return; diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 77705db9f6..0840030704 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -67,6 +67,5 @@ struct PyNdrRpcMethodDef { }; bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, struct PyNdrRpcMethodDef *mds); -PyObject *PyDescr_NewNdrRpcMethod(PyTypeObject *type, struct PyNdrRpcMethodDef *md); #endif /* _PYRPC_H_ */ -- cgit From 68cec4923a28946ab7ddd5a16a2f9442dc362fc6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 00:50:07 +0200 Subject: Add bindings for irpc_{add,remove}_name. (This used to be commit a75dbdec15ead785e0105dd61f980627e487fcb0) --- source4/lib/messaging/pyirpc.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c index ba3f830531..b43521e990 100644 --- a/source4/lib/messaging/pyirpc.c +++ b/source4/lib/messaging/pyirpc.c @@ -167,12 +167,51 @@ static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject return Py_None; } +static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + NTSTATUS status; + char *name; + const char *kwnames[] = { "name", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", + discard_const_p(char *, kwnames), &name)) { + return NULL; + } + + status = irpc_add_name(iface->msg_ctx, name); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return Py_None; +} + + +static PyObject *py_messaging_remove_name(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + char *name; + const char *kwnames[] = { "name", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", + discard_const_p(char *, kwnames), &name)) { + return NULL; + } + + irpc_remove_name(iface->msg_ctx, name); + + return Py_None; +} static PyMethodDef py_messaging_methods[] = { { "send", (PyCFunction)py_messaging_send, METH_VARARGS|METH_KEYWORDS, "S.send(target, msg_type, data) -> None\nSend a message" }, { "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS, "S.register(msg_type, callback) -> None\nRegister a message handler" }, + { "add_name", (PyCFunction)py_messaging_add_name, METH_VARARGS|METH_KEYWORDS, "S.add_name(name) -> None\nListen on another name" }, + { "remove_name", (PyCFunction)py_messaging_remove_name, METH_VARARGS|METH_KEYWORDS, "S.remove_name(name) -> None\nStop listening on a name" }, { NULL, NULL, 0, NULL } }; -- cgit From b058e556f89edc372377c91fd65fde6a4f05c835 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 01:10:24 +0200 Subject: Support messaging_client_init in the python bindings. (This used to be commit f2e8f9851044506ef80811a6b6c5d31632a1f112) --- source4/lib/messaging/pyirpc.c | 98 +++++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c index b43521e990..a1f05b79be 100644 --- a/source4/lib/messaging/pyirpc.c +++ b/source4/lib/messaging/pyirpc.c @@ -29,10 +29,18 @@ PyAPI_DATA(PyTypeObject) messaging_Type; PyAPI_DATA(PyTypeObject) irpc_InterfaceType; -/* - messaging clients need server IDs as well ... - */ -#define PY_ID_BASE 0x30000000 + +static bool server_id_from_py(PyObject *object, struct server_id *server_id) +{ + if (!PyTuple_Check(object)) { + PyErr_SetString(PyExc_ValueError, "Expected tuple"); + return false; + } + + return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node); +} + + typedef struct { PyObject_HEAD @@ -42,14 +50,14 @@ typedef struct { PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) { - int i; struct event_context *ev; - const char *kwnames[] = { "messaging_path", NULL }; + const char *kwnames[] = { "own_id", "messaging_path", NULL }; + PyObject *own_id = Py_None; const char *messaging_path = NULL; messaging_Object *ret; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s:connect", - discard_const_p(char *, kwnames), &messaging_path)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Os:connect", + discard_const_p(char *, kwnames), &own_id, &messaging_path)) { return NULL; } @@ -67,15 +75,22 @@ PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwa messaging_path = talloc_strdup(ret->mem_ctx, messaging_path); } - /* create a messaging context, looping as we have no way to - allocate temporary server ids automatically */ - for (i=0;i<10000;i++) { + if (own_id != Py_None) { + struct server_id server_id; + + if (!server_id_from_py(own_id, &server_id)) + return NULL; + ret->msg_ctx = messaging_init(ret->mem_ctx, messaging_path, - cluster_id(PY_ID_BASE, i), + server_id, + lp_iconv_convenience(global_loadparm), + ev); + } else { + ret->msg_ctx = messaging_client_init(ret->mem_ctx, + messaging_path, lp_iconv_convenience(global_loadparm), ev); - if (ret->msg_ctx) break; } if (ret->msg_ctx == NULL) { @@ -94,20 +109,10 @@ static void py_messaging_dealloc(PyObject *self) PyObject_Del(self); } -static bool server_id_from_py(PyObject *object, struct server_id *server_id) -{ - if (!PyTuple_Check(object)) { - PyErr_SetString(PyExc_ValueError, "Expected tuple"); - return false; - } - - return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node); -} - static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwargs) { messaging_Object *iface = (messaging_Object *)self; - int msg_type; + uint32_t msg_type; DATA_BLOB data; PyObject *target; NTSTATUS status; @@ -145,26 +150,31 @@ static void py_msg_callback_wrapper(struct messaging_context *msg, void *private static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject *kwargs) { messaging_Object *iface = (messaging_Object *)self; - int msg_type; + uint32_t msg_type = -1; PyObject *callback; NTSTATUS status; - const char *kwnames[] = { "msg_type", "callback", NULL }; + const char *kwnames[] = { "callback", "msg_type", NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO|:send", - discard_const_p(char *, kwnames), &msg_type, &callback)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", + discard_const_p(char *, kwnames), &callback, &msg_type)) { return NULL; } Py_INCREF(callback); - status = messaging_register(iface->msg_ctx, callback, - msg_type, py_msg_callback_wrapper); + if (msg_type == -1) { + status = messaging_register_tmp(iface->msg_ctx, callback, + py_msg_callback_wrapper, &msg_type); + } else { + status = messaging_register(iface->msg_ctx, callback, + msg_type, py_msg_callback_wrapper); + } if (NT_STATUS_IS_ERR(status)) { PyErr_SetNTSTATUS(status); return NULL; } - return Py_None; + return PyLong_FromLong(msg_type); } static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs) @@ -245,15 +255,15 @@ typedef struct { PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) { - int i; struct event_context *ev; - const char *kwnames[] = { "server", "messaging_path", NULL }; + const char *kwnames[] = { "server", "own_id", "messaging_path", NULL }; char *server; const char *messaging_path = NULL; + PyObject *own_id = Py_None; irpc_InterfaceObject *ret; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|s:connect", - discard_const_p(char *, kwnames), &server, &messaging_path)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Os:connect", + discard_const_p(char *, kwnames), &server, &own_id, &messaging_path)) { return NULL; } @@ -271,16 +281,24 @@ PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) messaging_path = lp_messaging_path(ret, global_loadparm); } - /* create a messaging context, looping as we have no way to - allocate temporary server ids automatically */ - for (i=0;i<10000;i++) { + if (own_id != Py_None) { + struct server_id server_id; + + if (!server_id_from_py(own_id, &server_id)) + return NULL; + ret->msg_ctx = messaging_init(ret->mem_ctx, messaging_path, - cluster_id(PY_ID_BASE, i), + server_id, + lp_iconv_convenience(global_loadparm), + ev); + } else { + ret->msg_ctx = messaging_client_init(ret->mem_ctx, + messaging_path, lp_iconv_convenience(global_loadparm), ev); - if (ret->msg_ctx) break; } + if (ret->msg_ctx == NULL) { PyErr_SetString(PyExc_RuntimeError, "irpc_connect unable to create a messaging context"); talloc_free(ret->mem_ctx); -- cgit From f22e4d0ce3db3b199d8bac1224064c57c5f373fc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 01:15:15 +0200 Subject: Add bindings for deregister. (This used to be commit 3e7b361f5952bd2f8a417510adf218b78234ed36) --- source4/lib/messaging/pyirpc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c index a1f05b79be..6e979a1ef8 100644 --- a/source4/lib/messaging/pyirpc.c +++ b/source4/lib/messaging/pyirpc.c @@ -177,6 +177,25 @@ static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject return PyLong_FromLong(msg_type); } +static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + uint32_t msg_type = -1; + PyObject *callback; + const char *kwnames[] = { "callback", "msg_type", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", + discard_const_p(char *, kwnames), &callback, &msg_type)) { + return NULL; + } + + messaging_deregister(iface->msg_ctx, msg_type, callback); + + Py_DECREF(callback); + + return Py_None; +} + static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs) { messaging_Object *iface = (messaging_Object *)self; @@ -220,6 +239,8 @@ static PyMethodDef py_messaging_methods[] = { "S.send(target, msg_type, data) -> None\nSend a message" }, { "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS, "S.register(msg_type, callback) -> None\nRegister a message handler" }, + { "deregister", (PyCFunction)py_messaging_deregister, METH_VARARGS|METH_KEYWORDS, + "S.deregister(msg_type, callback) -> None\nDeregister a message handler" }, { "add_name", (PyCFunction)py_messaging_add_name, METH_VARARGS|METH_KEYWORDS, "S.add_name(name) -> None\nListen on another name" }, { "remove_name", (PyCFunction)py_messaging_remove_name, METH_VARARGS|METH_KEYWORDS, "S.remove_name(name) -> None\nStop listening on a name" }, { NULL, NULL, 0, NULL } -- cgit From d9a6f04ddd8074c36fc8073ec9bd183438801817 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 01:52:35 +0200 Subject: Provide access to server_id from python bindings, add more tests. (This used to be commit adcd87ad07abbf60a0152deae4b975a2401d701b) --- source4/lib/messaging/irpc.h | 1 + source4/lib/messaging/messaging.c | 5 +++++ source4/lib/messaging/pyirpc.c | 34 ++++++++++++++++++++++++++++----- source4/lib/messaging/tests/bindings.py | 34 ++++++++++++++++++++++++++++++++- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/source4/lib/messaging/irpc.h b/source4/lib/messaging/irpc.h index f44c0af3ec..65e98dce2c 100644 --- a/source4/lib/messaging/irpc.h +++ b/source4/lib/messaging/irpc.h @@ -125,6 +125,7 @@ NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name); struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name); void irpc_remove_name(struct messaging_context *msg_ctx, const char *name); NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status); +struct server_id messaging_get_server_id(struct messaging_context *msg_ctx); #endif diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index e7b654894f..4b90e8c4fd 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -1113,3 +1113,8 @@ void irpc_remove_name(struct messaging_context *msg_ctx, const char *name) tdb_unlock_bystring(t->tdb, name); talloc_free(t); } + +struct server_id messaging_get_server_id(struct messaging_context *msg_ctx) +{ + return msg_ctx->server_id; +} diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c index 6e979a1ef8..5ef940817c 100644 --- a/source4/lib/messaging/pyirpc.c +++ b/source4/lib/messaging/pyirpc.c @@ -23,6 +23,7 @@ #include #include "libcli/util/pyerrors.h" #include "lib/messaging/irpc.h" +#include "lib/messaging/messaging.h" #include "lib/events/events.h" #include "cluster/cluster.h" #include "param/param.h" @@ -37,11 +38,17 @@ static bool server_id_from_py(PyObject *object, struct server_id *server_id) return false; } - return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node); + if (PyTuple_Size(object) == 3) { + return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node); + } else { + int id, id2; + if (!PyArg_ParseTuple(object, "ii", &id, &id2)) + return false; + *server_id = cluster_id(id, id2); + return true; + } } - - typedef struct { PyObject_HEAD TALLOC_CTX *mem_ctx; @@ -238,14 +245,30 @@ static PyMethodDef py_messaging_methods[] = { { "send", (PyCFunction)py_messaging_send, METH_VARARGS|METH_KEYWORDS, "S.send(target, msg_type, data) -> None\nSend a message" }, { "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS, - "S.register(msg_type, callback) -> None\nRegister a message handler" }, + "S.register(callback, msg_type=None) -> msg_type\nRegister a message handler" }, { "deregister", (PyCFunction)py_messaging_deregister, METH_VARARGS|METH_KEYWORDS, - "S.deregister(msg_type, callback) -> None\nDeregister a message handler" }, + "S.deregister(callback, msg_type) -> None\nDeregister a message handler" }, { "add_name", (PyCFunction)py_messaging_add_name, METH_VARARGS|METH_KEYWORDS, "S.add_name(name) -> None\nListen on another name" }, { "remove_name", (PyCFunction)py_messaging_remove_name, METH_VARARGS|METH_KEYWORDS, "S.remove_name(name) -> None\nStop listening on a name" }, { NULL, NULL, 0, NULL } }; +static PyObject *py_messaging_server_id(PyObject *obj, void *closure) +{ + messaging_Object *iface = (messaging_Object *)obj; + struct server_id server_id = messaging_get_server_id(iface->msg_ctx); + + return Py_BuildValue("(iii)", server_id.id, server_id.id2, + server_id.node); +} + +static PyGetSetDef py_messaging_getset[] = { + { discard_const_p(char, "server_id"), py_messaging_server_id, NULL, + discard_const_p(char, "local server id") }, + { NULL }, +}; + + PyTypeObject messaging_Type = { PyObject_HEAD_INIT(NULL) 0, .tp_name = "irpc.Messaging", @@ -254,6 +277,7 @@ PyTypeObject messaging_Type = { .tp_new = py_messaging_connect, .tp_dealloc = py_messaging_dealloc, .tp_methods = py_messaging_methods, + .tp_getset = py_messaging_getset, }; diff --git a/source4/lib/messaging/tests/bindings.py b/source4/lib/messaging/tests/bindings.py index ffb4dae326..3d58843799 100644 --- a/source4/lib/messaging/tests/bindings.py +++ b/source4/lib/messaging/tests/bindings.py @@ -22,4 +22,36 @@ from samba.irpc import Messaging from unittest import TestCase class MessagingTests(TestCase): - pass + def get_context(self, *args, **kwargs): + kwargs["messaging_path"] = "." + return Messaging(*args, **kwargs) + + def test_register(self): + x = self.get_context() + def callback(): + pass + msg_type = x.register(callback) + x.deregister(callback, msg_type) + + def test_assign_server_id(self): + x = self.get_context() + self.assertTrue(isinstance(x.server_id, tuple)) + self.assertEquals(3, len(x.server_id)) + + def test_ping_speed(self): + server_ctx = self.get_context((0, 1)) + def ping_callback(src, data): + server_ctx.send(src, data) + def exit_callback(): + print "received exit" + msg_ping = server_ctx.register(ping_callback) + msg_exit = server_ctx.register(exit_callback) + + def pong_callback(): + print "received pong" + client_ctx = self.get_context((0, 2)) + msg_pong = client_ctx.register(pong_callback) + + client_ctx.send((0,1), msg_ping, "testing") + client_ctx.send((0,1), msg_ping, "") + -- cgit From c17166fb3d9260d0c02e3f9f559413acde5ce048 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 02:04:00 +0200 Subject: Convert smbstatus to Python. (This used to be commit f14ad6cd92227c7ed5c570b581e5db82b7d42e25) --- source4/scripting/bin/smbstatus | 159 ++++++++++++++++------------------------ 1 file changed, 63 insertions(+), 96 deletions(-) diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 4dfc3365a1..782e83e4cf 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -1,96 +1,63 @@ -#!/bin/sh -exec smbscript "$0" ${1+"$@"} -/* - provide information on connected users and open files - Copyright Andrew Tridgell 2005 - Released under the GNU GPL version 3 or later -*/ - -libinclude("base.js"); -libinclude("management.js"); - -var options = new Object(); - -options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_VERSION", - "nbt"); -if (options == undefined) { - println("Failed to parse options: " + options.ERROR); - return -1; -} - -/* - show open sessions -*/ -function show_sessions() -{ - var sessions = smbsrv_sessions(); - var i; - var sys = sys_init(); - if (sessions == undefined) { - println("No sessions open"); - return; - } - printf("User Client Connected at\n"); - printf("-------------------------------------------------------------------------------\n"); - for (i=0;i Date: Mon, 26 May 2008 02:05:11 +0200 Subject: Remove unused EJS code. (This used to be commit 3b70a3de4aa63bd6c325fd620c71bd6111d3d2b8) --- source4/scripting/ejs/config.mk | 8 ---- source4/scripting/ejs/smbcalls_reg.c | 90 ------------------------------------ source4/scripting/libjs/auth.js | 18 -------- 3 files changed, 116 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_reg.c delete mode 100644 source4/scripting/libjs/auth.js diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 873dd09248..7ebf22ea32 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -13,14 +13,6 @@ PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR smbcalls_ldb_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_ldb.o -[MODULE::smbcalls_reg] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_reg -PRIVATE_DEPENDENCIES = registry SAMDB LIBNDR - -smbcalls_reg_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_reg.o - [MODULE::smbcalls_nbt] SUBSYSTEM = smbcalls OUTPUT_TYPE = MERGED_OBJ diff --git a/source4/scripting/ejs/smbcalls_reg.c b/source4/scripting/ejs/smbcalls_reg.c deleted file mode 100644 index ed8653d3a7..0000000000 --- a/source4/scripting/ejs/smbcalls_reg.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Jelmer Vernooij 2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "dsdb/samdb/samdb.h" -#include "librpc/ndr/libndr.h" -#include "lib/registry/registry.h" - -/* - get the connected db - */ -static struct registry_context *ejs_get_reg_context(int eid) -{ - struct registry_context *rctx = (struct registry_context *)mprGetThisPtr(eid, "registry"); - if (rctx == NULL) { - ejsSetErrorMsg(eid, "unable to find registry"); - } - return rctx; -} - -static int ejs_apply_patchfile(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct registry_context *rctx; - WERROR error; - - /* validate arguments */ - if (argc != 1) { - ejsSetErrorMsg(eid, "reg.apply_patchfile invalid number of arguments"); - return -1; - } - - rctx = ejs_get_reg_context(eid); - if (rctx == NULL) { - return -1; - } - - error = reg_diff_apply(rctx, mprToString(argv[0])); - - mpr_Return(eid, mprWERROR(error)); - - return 0; -} - -/* - initialise registry ejs subsystem -*/ -static int ejs_reg_open(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *reg = mprInitObject(eid, "registry", argc, argv); - struct registry_context *rctx; - WERROR error; - - error = reg_open_samba(mprMemCtx(), &rctx, mprEventCtx(), mprLpCtx(), NULL, NULL); - SMB_ASSERT(W_ERROR_IS_OK(error)); - - mprSetPtrChild(reg, "registry", rctx); - mprSetCFunction(reg, "apply_patchfile", ejs_apply_patchfile); - - return 0; -} - - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_reg(void) -{ - ejsDefineCFunction(-1, "reg_open", ejs_reg_open, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/libjs/auth.js b/source4/scripting/libjs/auth.js deleted file mode 100644 index 3fe81d0ea7..0000000000 --- a/source4/scripting/libjs/auth.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - auth js library functions - Copyright Andrew Tridgell 2005 - released under the GNU GPL version 3 or later -*/ - - -/* - get a list of domains for SWAT authentication -*/ -function getDomainList() -{ - var ret = new Array(2); - var lp = loadparm_init(); - ret[0] = "System User"; - ret[1] = lp.get("workgroup"); - return ret; -} -- cgit From 5c89184c42a51045f8c3810c25ce22d7be9e1750 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 02:07:47 +0200 Subject: Remove unused nss module. (This used to be commit 5f75a4f0c0343fe459f5c231f4b5ac89cea43b42) --- source4/scripting/ejs/config.mk | 8 -- source4/scripting/ejs/smbcalls_nss.c | 160 ----------------------------------- 2 files changed, 168 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_nss.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 7ebf22ea32..a3cc28a0b2 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -27,14 +27,6 @@ INIT_FUNCTION = smb_setup_ejs_random smbcalls_rand_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_rand.o -[MODULE::smbcalls_nss] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_nss -PRIVATE_DEPENDENCIES = NSS_WRAPPER - -smbcalls_nss_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_nss.o - [MODULE::smbcalls_data] SUBSYSTEM = smbcalls OUTPUT_TYPE = MERGED_OBJ diff --git a/source4/scripting/ejs/smbcalls_nss.c b/source4/scripting/ejs/smbcalls_nss.c deleted file mode 100644 index 58f86d3b6c..0000000000 --- a/source4/scripting/ejs/smbcalls_nss.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide access to getpwnam() and related calls - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "system/passwd.h" - - -/* - return a struct passwd as an object -*/ -static struct MprVar mpr_passwd(struct passwd *pwd) -{ - struct MprVar ret; - if (pwd == NULL) { - return mprCreateUndefinedVar(); - } - ret = mprObject("passwd"); - - mprSetVar(&ret, "pw_name", mprString(pwd->pw_name)); - mprSetVar(&ret, "pw_passwd", mprString(pwd->pw_passwd)); - mprSetVar(&ret, "pw_uid", mprCreateIntegerVar(pwd->pw_uid)); - mprSetVar(&ret, "pw_gid", mprCreateIntegerVar(pwd->pw_gid)); - mprSetVar(&ret, "pw_gecos", mprString(pwd->pw_gecos)); - mprSetVar(&ret, "pw_dir", mprString(pwd->pw_dir)); - mprSetVar(&ret, "pw_shell", mprString(pwd->pw_shell)); - return ret; -} - -/* - return a struct passwd as an object -*/ -static struct MprVar mpr_group(struct group *grp) -{ - struct MprVar ret; - if (grp == NULL) { - return mprCreateUndefinedVar(); - } - ret = mprObject("group"); - - mprSetVar(&ret, "gr_name", mprString(grp->gr_name)); - mprSetVar(&ret, "gr_passwd", mprString(grp->gr_passwd)); - mprSetVar(&ret, "gr_gid", mprCreateIntegerVar(grp->gr_gid)); - mprSetVar(&ret, "gr_mem", mprList("gr_mem", (const char **)grp->gr_mem)); - return ret; -} - - -/* - usage: - var pw = nss.getpwnam("root"); - - returns an object containing struct passwd entries -*/ -static int ejs_getpwnam(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "getpwnam invalid arguments"); - return -1; - } - - mpr_Return(eid, mpr_passwd(getpwnam(mprToString(argv[0])))); - return 0; -} - -/* - usage: - var pw = nss.getpwuid(0); - - returns an object containing struct passwd entries -*/ -static int ejs_getpwuid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || !mprVarIsNumber(argv[0]->type)) { - ejsSetErrorMsg(eid, "getpwuid invalid arguments"); - return -1; - } - mpr_Return(eid, mpr_passwd(getpwuid(mprToInt(argv[0])))); - return 0; -} - -/* - usage: - var pw = nss.getgrnam("users"); - - returns an object containing struct group entries -*/ -static int ejs_getgrnam(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "getgrnam invalid arguments"); - return -1; - } - mpr_Return(eid, mpr_group(getgrnam(mprToString(argv[0])))); - return 0; -} - -/* - usage: - var pw = nss.getgrgid(0); - - returns an object containing struct group entries -*/ -static int ejs_getgrgid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - /* validate arguments */ - if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "getgrgid invalid arguments"); - return -1; - } - mpr_Return(eid, mpr_group(getgrgid(mprToInt(argv[0])))); - return 0; -} - - -/* - initialise nss ejs subsystem -*/ -static int ejs_nss_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *nss = mprInitObject(eid, "nss", argc, argv); - - mprSetCFunction(nss, "getpwnam", ejs_getpwnam); - mprSetCFunction(nss, "getpwuid", ejs_getpwuid); - mprSetCFunction(nss, "getgrnam", ejs_getgrnam); - mprSetCFunction(nss, "getgrgid", ejs_getgrgid); - - return 0; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_nss(void) -{ - ejsDefineCFunction(-1, "nss_init", ejs_nss_init, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} -- cgit From fd712bb878dcfbe8a50e48361c96cc04a3ddacf5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 02:11:32 +0200 Subject: Remove unused cli ejs module. (This used to be commit 170d5aef80f37c26171a40e818cc8b557828d04b) --- source4/scripting/ejs/config.mk | 1 - source4/scripting/ejs/smbcalls.c | 1 - source4/scripting/ejs/smbcalls_cli.c | 722 ----------------------------------- 3 files changed, 724 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_cli.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index a3cc28a0b2..c5199669d5 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -70,7 +70,6 @@ PRIVATE_DEPENDENCIES = \ smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ - smbcalls_cli.o \ smbcalls_options.o \ smbcalls_creds.o \ smbcalls_param.o \ diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index 98d6be07bf..bdf70ca831 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -203,7 +203,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) ejs_exception_handler = exception_handler; - smb_setup_ejs_cli(); smb_setup_ejs_options(); smb_setup_ejs_credentials(); smb_setup_ejs_param(); diff --git a/source4/scripting/ejs/smbcalls_cli.c b/source4/scripting/ejs/smbcalls_cli.c deleted file mode 100644 index dbb36312da..0000000000 --- a/source4/scripting/ejs/smbcalls_cli.c +++ /dev/null @@ -1,722 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Tim Potter 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "libcli/raw/libcliraw.h" -#include "libcli/composite/composite.h" -#include "libcli/smb_composite/smb_composite.h" -#include "libcli/libcli.h" -#include "libcli/resolve/resolve.h" -#include "auth/credentials/credentials.h" -#include "param/param.h" - -#if 0 - -#include "librpc/gen_ndr/ndr_nbt.h" - -/* Connect to a server */ - -static int ejs_cli_connect(MprVarHandle eid, int argc, char **argv) -{ - struct smbcli_socket *sock; - struct smbcli_transport *transport; - struct nbt_name calling, called; - NTSTATUS result; - - if (argc != 1) { - ejsSetErrorMsg(eid, "connect invalid arguments"); - return -1; - } - - /* Socket connect */ - - sock = smbcli_sock_init(NULL, NULL); - - if (!sock) { - ejsSetErrorMsg(eid, "socket initialisation failed"); - return -1; - } - - if (!smbcli_sock_connect_byname(sock, argv[0], 0)) { - ejsSetErrorMsg(eid, "socket connect failed"); - return -1; - } - - transport = smbcli_transport_init(sock, sock, false); - - if (!transport) { - ejsSetErrorMsg(eid, "transport init failed"); - return -1; - } - - /* Send a netbios session request */ - - make_nbt_name_client(&calling, lp_netbios_name()); - - nbt_choose_called_name(NULL, &called, argv[0], NBT_NAME_SERVER); - - if (!smbcli_transport_connect(transport, &calling, &called)) { - ejsSetErrorMsg(eid, "transport establishment failed"); - return -1; - } - - result = smb_raw_negotiate(transport, lp_maxprotocol()); - - if (!NT_STATUS_IS_OK(result)) { - mpr_Return(eid, mprNTSTATUS(result)); - return 0; - } - - /* Return a socket object */ - - mpr_Return(eid, mprCreatePtrVar(transport)); - - return 0; -} - -/* Perform a session setup: - - session_setup(conn, "DOMAIN\\USERNAME%PASSWORD"); - session_setup(conn, USERNAME, PASSWORD); - session_setup(conn, DOMAIN, USERNAME, PASSWORD); - session_setup(conn); // anonymous - - */ - -static int ejs_cli_ssetup(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_transport *transport; - struct smbcli_session *session; - struct smb_composite_sesssetup setup; - struct cli_credentials *creds; - NTSTATUS status; - int result = -1; - - /* Argument parsing */ - - if (argc < 1 || argc > 4) { - ejsSetErrorMsg(eid, "session_setup invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a connect handle"); - return -1; - } - - transport = argv[0]->ptr; - creds = cli_credentials_init(transport); - cli_credentials_set_conf(creds); - - if (argc == 4) { - - /* DOMAIN, USERNAME, PASSWORD form */ - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 1 must be a string"); - goto done; - } - - cli_credentials_set_domain(creds, argv[1]->string, - CRED_SPECIFIED); - - if (!mprVarIsString(argv[2]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - goto done; - } - - cli_credentials_set_username(creds, argv[2]->string, - CRED_SPECIFIED); - - if (!mprVarIsString(argv[3]->type)) { - ejsSetErrorMsg(eid, "arg 3 must be a string"); - goto done; - } - - cli_credentials_set_password(creds, argv[3]->string, - CRED_SPECIFIED); - - } else if (argc == 3) { - - /* USERNAME, PASSWORD form */ - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg1 must be a string"); - goto done; - } - - cli_credentials_set_username(creds, argv[1]->string, - CRED_SPECIFIED); - - if (!mprVarIsString(argv[2]->type)) { - - ejsSetErrorMsg(eid, "arg2 must be a string"); - goto done; - } - - cli_credentials_set_password(creds, argv[2]->string, - CRED_SPECIFIED); - - } else if (argc == 2) { - - /* DOMAIN/USERNAME%PASSWORD form */ - - cli_credentials_parse_string(creds, argv[1]->string, - CRED_SPECIFIED); - - } else { - - /* Anonymous connection */ - - cli_credentials_set_anonymous(creds); - } - - /* Do session setup */ - - session = smbcli_session_init(transport, transport, false); - - if (!session) { - ejsSetErrorMsg(eid, "session init failed"); - return -1; - } - - setup.in.sesskey = transport->negotiate.sesskey; - setup.in.capabilities = transport->negotiate.capabilities; - setup.in.credentials = creds; - setup.in.workgroup = lp_workgroup(); - - status = smb_composite_sesssetup(session, &setup); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "session_setup: %s", nt_errstr(status)); - return -1; - } - - session->vuid = setup.out.vuid; - - /* Return a session object */ - - mpr_Return(eid, mprCreatePtrVar(session)); - - result = 0; - - done: - talloc_free(creds); - return result; -} - -/* Perform a tree connect - - tree_connect(session, SHARE); - - */ - -static int ejs_cli_tree_connect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_session *session; - struct smbcli_tree *tree; - union smb_tcon tcon; - TALLOC_CTX *mem_ctx; - NTSTATUS status; - const char *password = ""; - - /* Argument parsing */ - - if (argc != 2) { - ejsSetErrorMsg(eid, "tree_connect invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a session handle"); - return -1; - } - - session = argv[0]->ptr; - tree = smbcli_tree_init(session, session, false); - - if (!tree) { - ejsSetErrorMsg(eid, "tree init failed"); - return -1; - } - - mem_ctx = talloc_init("tcon"); - if (!mem_ctx) { - ejsSetErrorMsg(eid, "talloc_init failed"); - return -1; - } - - /* Do tree connect */ - - tcon.generic.level = RAW_TCON_TCONX; - tcon.tconx.in.flags = 0; - - if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL) { - tcon.tconx.in.password = data_blob(NULL, 0); - } else if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { - tcon.tconx.in.password = data_blob_talloc(mem_ctx, NULL, 24); - if (session->transport->negotiate.secblob.length < 8) { - ejsSetErrorMsg(eid, "invalid security blob"); - return -1; - } - SMBencrypt(password, session->transport->negotiate.secblob.data, tcon.tconx.in.password.data); - } else { - tcon.tconx.in.password = data_blob_talloc(mem_ctx, password, strlen(password)+1); - } - - tcon.tconx.in.path = argv[1]->string; - tcon.tconx.in.device = "?????"; - - status = smb_tree_connect(tree, mem_ctx, &tcon); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "tree_connect: %s", nt_errstr(status)); - return -1; - } - - tree->tid = tcon.tconx.out.tid; - - talloc_free(mem_ctx); - - mpr_Return(eid, mprCreatePtrVar(tree)); - - return 0; -} - -/* Perform a tree disconnect - - tree_disconnect(tree); - - */ -static int ejs_cli_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS status; - - /* Argument parsing */ - - if (argc != 1) { - ejsSetErrorMsg(eid, "tree_disconnect invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = argv[0]->ptr; - - status = smb_tree_disconnect(tree); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "tree_disconnect: %s", nt_errstr(status)); - return -1; - } - - talloc_free(tree); - - return 0; -} - -/* Perform a ulogoff - - session_logoff(session); - - */ -static int ejs_cli_session_logoff(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_session *session; - NTSTATUS status; - - /* Argument parsing */ - - if (argc != 1) { - ejsSetErrorMsg(eid, "session_logoff invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a session handle"); - return -1; - } - - session = argv[0]->ptr; - - status = smb_raw_ulogoff(session); - - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "session_logoff: %s", nt_errstr(status)); - return -1; - } - - talloc_free(session); - - return 0; -} - -/* Perform a connection close - - disconnect(conn); - - */ -static int ejs_cli_disconnect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_sock *sock; - - /* Argument parsing */ - - if (argc != 1) { - ejsSetErrorMsg(eid, "disconnect invalid arguments"); - return -1; - } - - if (!mprVarIsPtr(argv[0]->type)) { - ejsSetErrorMsg(eid, "first arg is not a connect handle"); - return -1; - } - - sock = argv[0]->ptr; - - talloc_free(sock); - - return 0; -} - -#endif - -/* Perform a tree connect: - - tree_handle = tree_connect("\\\\frogurt\\homes", "user%pass"); - */ - -static int ejs_tree_connect(MprVarHandle eid, int argc, char **argv) -{ - struct cli_credentials *creds; - struct smb_composite_connect io; - struct smbcli_tree *tree; - char *hostname, *sharename; - NTSTATUS result; - TALLOC_CTX *mem_ctx; - - if (argc != 2) { - ejsSetErrorMsg(eid, "tree_connect(): invalid number of args"); - return -1; - } - - /* Set up host, share destination */ - - mem_ctx = talloc_new(mprMemCtx()); - smbcli_parse_unc(argv[0], mem_ctx, &hostname, &sharename); - - /* Set up credentials */ - - creds = cli_credentials_init(NULL); - cli_credentials_set_conf(creds, mprLpCtx()); - cli_credentials_parse_string(creds, argv[1], CRED_SPECIFIED); - - /* Do connect */ - - io.in.dest_host = hostname; - io.in.dest_ports = lp_smb_ports(mprLpCtx()); - io.in.called_name = strupper_talloc(mem_ctx, hostname); - io.in.service = sharename; - io.in.service_type = "?????"; - io.in.credentials = creds; - io.in.fallback_to_anonymous = false; - io.in.workgroup = lp_workgroup(mprLpCtx()); - lp_smbcli_options(mprLpCtx(), &io.in.options); - - result = smb_composite_connect(&io, mem_ctx, - lp_resolve_context(mprLpCtx()), - NULL); - tree = io.out.tree; - - talloc_free(mem_ctx); - - if (!NT_STATUS_IS_OK(result)) { - mpr_Return(eid, mprNTSTATUS(result)); - return 0; - } - - mpr_Return(eid, mprCreatePtrVar(tree)); - - return 0; -} - -#define IS_TREE_HANDLE(x) (mprVarIsPtr((x)->type) && \ - talloc_check_name((x)->ptr, "struct smbcli_tree")) - -/* Perform a tree disconnect: - - tree_disconnect(tree_handle); - */ - -static int ejs_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 1) { - ejsSetErrorMsg(eid, - "tree_disconnect(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = talloc_get_type(argv[0]->ptr, struct smbcli_tree); - - result = smb_tree_disconnect(tree); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Create a directory: - - result = mkdir(tree_handle, DIRNAME); - */ - -static int ejs_mkdir(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 2) { - ejsSetErrorMsg(eid, "mkdir(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - result = smbcli_mkdir(tree, argv[1]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Remove a directory: - - result = rmdir(tree_handle, DIRNAME); - */ - -static int ejs_rmdir(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 2) { - ejsSetErrorMsg(eid, "rmdir(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - result = smbcli_rmdir(tree, argv[1]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Rename a file or directory: - - result = rename(tree_handle, SRCFILE, DESTFILE); - */ - -static int ejs_rename(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 3) { - ejsSetErrorMsg(eid, "rename(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - if (!mprVarIsString(argv[2]->type)) { - ejsSetErrorMsg(eid, "arg 3 must be a string"); - return -1; - } - - result = smbcli_rename(tree, argv[1]->string, argv[2]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* Unlink a file or directory: - - result = unlink(tree_handle, FILENAME); - */ - -static int ejs_unlink(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - NTSTATUS result; - - if (argc != 2) { - ejsSetErrorMsg(eid, "unlink(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - result = smbcli_unlink(tree, argv[1]->string); - - mpr_Return(eid, mprNTSTATUS(result)); - - return 0; -} - -/* List directory contents - - result = list(tree_handle, ARG1, ...); - */ - -static void ejs_list_helper(struct clilist_file_info *info, const char *mask, - void *state) - -{ - MprVar *result = (MprVar *)state; - char idx[16]; - - mprItoa(result->properties->numDataItems, idx, sizeof(idx)); - mprSetVar(result, idx, mprString(info->name)); -} - -static int ejs_list(MprVarHandle eid, int argc, MprVar **argv) -{ - struct smbcli_tree *tree; - char *mask; - uint16_t attribute; - MprVar result; - - if (argc != 3) { - ejsSetErrorMsg(eid, "list(): invalid number of args"); - return -1; - } - - if (!IS_TREE_HANDLE(argv[0])) { - ejsSetErrorMsg(eid, "first arg is not a tree handle"); - return -1; - } - - tree = (struct smbcli_tree *)argv[0]->ptr; - - if (!mprVarIsString(argv[1]->type)) { - ejsSetErrorMsg(eid, "arg 2 must be a string"); - return -1; - } - - mask = argv[1]->string; - - if (!mprVarIsNumber(argv[2]->type)) { - ejsSetErrorMsg(eid, "arg 3 must be a number"); - return -1; - } - - attribute = mprVarToInteger(argv[2]); - - result = mprObject("list"); - - smbcli_list(tree, mask, attribute, ejs_list_helper, &result); - - mpr_Return(eid, result); - - return 0; -} - -/* - setup C functions that be called from ejs -*/ -void smb_setup_ejs_cli(void) -{ - ejsDefineStringCFunction(-1, "tree_connect", ejs_tree_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "tree_disconnect", ejs_tree_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE); - - ejsDefineCFunction(-1, "mkdir", ejs_mkdir, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "rmdir", ejs_rmdir, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "rename", ejs_rename, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "unlink", ejs_unlink, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "list", ejs_list, NULL, MPR_VAR_SCRIPT_HANDLE); - - -#if 0 - ejsDefineStringCFunction(-1, "connect", ejs_cli_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "session_setup", ejs_cli_ssetup, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "tree_connect", ejs_cli_tree_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "tree_disconnect", ejs_cli_tree_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "session_logoff", ejs_cli_session_logoff, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "disconnect", ejs_cli_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE); -#endif -} -- cgit From d60d8e57d83acfc94fa36c59fcfb9c6e03ee02b6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 03:07:18 +0200 Subject: Implement IRPC calls over the internal messaging bus. (This used to be commit 777dc3a2c7b5bf855344ba3ae8c8b564c48fc0c6) --- source4/lib/messaging/pyirpc.c | 189 +++++++++++++++++---------- source4/librpc/rpc/pyrpc.c | 4 +- source4/librpc/rpc/pyrpc.h | 2 +- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 5 +- 4 files changed, 125 insertions(+), 75 deletions(-) diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c index 5ef940817c..41475daaff 100644 --- a/source4/lib/messaging/pyirpc.c +++ b/source4/lib/messaging/pyirpc.c @@ -22,11 +22,13 @@ #include "includes.h" #include #include "libcli/util/pyerrors.h" +#include "librpc/rpc/pyrpc.h" #include "lib/messaging/irpc.h" #include "lib/messaging/messaging.h" #include "lib/events/events.h" #include "cluster/cluster.h" #include "param/param.h" +#include "librpc/gen_ndr/py_irpc.h" PyAPI_DATA(PyTypeObject) messaging_Type; PyAPI_DATA(PyTypeObject) irpc_InterfaceType; @@ -360,69 +362,88 @@ PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) } } -static void py_irpc_dealloc(PyObject *self) +typedef struct { + PyObject_HEAD + struct irpc_request **reqs; + int count; + int current; + TALLOC_CTX *mem_ctx; + py_data_unpack_fn unpack_fn; +} irpc_ResultObject; + + +static PyObject *irpc_result_next(irpc_ResultObject *iterator) { - irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self; - talloc_free(iface->mem_ctx); + NTSTATUS status; + + if (iterator->current >= iterator->count) { + PyErr_SetString(PyExc_StopIteration, "No more results"); + return NULL; + } + + status = irpc_call_recv(iterator->reqs[iterator->current]); + iterator->current++; + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return iterator->unpack_fn(iterator->reqs[iterator->current-1]->r); +} + +static PyObject *irpc_result_len(irpc_ResultObject *self) +{ + return PyLong_FromLong(self->count); +} + +static PyMethodDef irpc_result_methods[] = { + { "__len__", (PyCFunction)irpc_result_len, METH_NOARGS, + "Number of elements returned"}, + { NULL } +}; + +static void irpc_result_dealloc(PyObject *self) +{ + talloc_free(((irpc_ResultObject *)self)->mem_ctx); PyObject_Del(self); } -PyTypeObject irpc_InterfaceType = { +PyTypeObject irpc_ResultIteratorType = { PyObject_HEAD_INIT(NULL) 0, - .tp_name = "irpc.ClientConnection", - .tp_basicsize = sizeof(irpc_InterfaceObject), + .tp_name = "irpc.ResultIterator", + .tp_basicsize = sizeof(irpc_ResultObject), .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - .tp_new = py_irpc_connect, - .tp_dealloc = py_irpc_dealloc, + .tp_iter = (iternextfunc)irpc_result_next, + .tp_methods = irpc_result_methods, + .tp_dealloc = irpc_result_dealloc, }; -#if 0 -/* - make an irpc call - called via the same interface as rpc -*/ -static int ejs_irpc_call(int eid, struct MprVar *io, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) +static PyObject *py_irpc_call(irpc_InterfaceObject *p, struct PyNdrRpcMethodDef *method_def, PyObject *args, PyObject *kwargs) { - NTSTATUS status; void *ptr; - struct ejs_rpc *ejs; - const struct ndr_interface_call *call; - struct ejs_irpc_connection *p; struct irpc_request **reqs; int i, count; - struct MprVar *results; - - p = (struct ejs_irpc_connection *)mprGetThisPtr(eid, "irpc"); - - ejs = talloc(mprMemCtx(), struct ejs_rpc); - if (ejs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - call = &iface->calls[callnum]; - - ejs->eid = eid; - ejs->callname = call->name; + NTSTATUS status; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + irpc_ResultObject *ret; /* allocate the C structure */ - ptr = talloc_zero_size(ejs, call->struct_size); + ptr = talloc_zero_size(mem_ctx, method_def->table->calls[method_def->opnum].struct_size); if (ptr == NULL) { status = NT_STATUS_NO_MEMORY; goto done; } /* convert the mpr object into a C structure */ - status = ejs_pull(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; + if (!method_def->pack_in_data(args, kwargs, ptr)) { + talloc_free(mem_ctx); + return NULL; } for (count=0;p->dest_ids[count].id;count++) /* noop */ ; /* we need to make a call per server */ - reqs = talloc_array(ejs, struct irpc_request *, count); + reqs = talloc_array(mem_ctx, struct irpc_request *, count); if (reqs == NULL) { status = NT_STATUS_NO_MEMORY; goto done; @@ -431,50 +452,72 @@ static int ejs_irpc_call(int eid, struct MprVar *io, /* make the actual calls */ for (i=0;imsg_ctx, p->dest_ids[i], - iface, callnum, ptr, ptr); + method_def->table, method_def->opnum, ptr, ptr); if (reqs[i] == NULL) { status = NT_STATUS_NO_MEMORY; goto done; } talloc_steal(reqs, reqs[i]); } - - mprSetVar(io, "results", mprObject("results")); - results = mprGetProperty(io, "results", NULL); - /* and receive the results, placing them in io.results[i] */ - for (i=0;imem_ctx = mem_ctx; + ret->reqs = reqs; + ret->count = count; + ret->current = 0; + ret->unpack_fn = method_def->unpack_out_data; - status = irpc_call_recv(reqs[i]); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - status = ejs_push(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } + return (PyObject *)ret; +done: + talloc_free(mem_ctx); + PyErr_SetNTSTATUS(status); + return NULL; +} - /* add to the results array */ - output = mprGetProperty(io, "output", NULL); - if (output) { - char idx[16]; - mprItoa(i, idx, sizeof(idx)); - mprSetProperty(results, idx, output); - mprDeleteProperty(io, "output"); - } - } - mprSetVar(results, "length", mprCreateIntegerVar(i)); +static PyObject *py_irpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) +{ + irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self; + struct PyNdrRpcMethodDef *md = wrapped; -done: - talloc_free(ejs); - mpr_Return(eid, mprNTSTATUS(status)); - if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) { - return -1; + return py_irpc_call(iface, md, args, kwargs); +} + +static void py_irpc_dealloc(PyObject *self) +{ + irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self; + talloc_free(iface->mem_ctx); + PyObject_Del(self); +} + +PyTypeObject irpc_InterfaceType = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "irpc.ClientConnection", + .tp_basicsize = sizeof(irpc_InterfaceObject), + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_new = py_irpc_connect, + .tp_dealloc = py_irpc_dealloc, +}; + +static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *mds) +{ + int i; + for (i = 0; mds[i].name; i++) { + PyObject *ret; + struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1); + + wb->name = discard_const_p(char, mds[i].name); + wb->flags = PyWrapperFlag_KEYWORDS; + wb->wrapper = (wrapperfunc)py_irpc_call_wrapper; + wb->doc = discard_const_p(char, mds[i].doc); + + ret = PyDescr_NewWrapper(ifacetype, wb, &mds[i]); + + PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, + (PyObject *)ret); } - return 0; + + return true; } -#endif void initirpc(void) { @@ -486,6 +529,12 @@ void initirpc(void) if (PyType_Ready(&messaging_Type) < 0) return; + if (PyType_Ready(&irpc_ResultIteratorType) < 0) + return; + + if (!irpc_AddNdrRpcMethods(&irpc_InterfaceType, py_ndr_irpc_methods)) + return; + mod = Py_InitModule3("irpc", NULL, "Internal RPC"); if (mod == NULL) return; diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index fae3d727fa..d8344be511 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -71,7 +71,7 @@ static PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wr } -bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *mds) +bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpcMethodDef *mds) { int i; for (i = 0; mds[i].name; i++) { @@ -83,7 +83,7 @@ bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethod wb->wrapper = (wrapperfunc)py_dcerpc_call_wrapper; wb->doc = discard_const_p(char, mds[i].doc); - ret = PyDescr_NewWrapper(ifacetype, wb, &mds[i]); + ret = PyDescr_NewWrapper(ifacetype, wb, discard_const_p(void, &mds[i])); PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, (PyObject *)ret); diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 0840030704..989aeecc7b 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -66,6 +66,6 @@ struct PyNdrRpcMethodDef { const struct ndr_interface_table *table; }; -bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, struct PyNdrRpcMethodDef *mds); +bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, const struct PyNdrRpcMethodDef *mds); #endif /* _PYRPC_H_ */ diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 0832401d7d..055ee13b10 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -650,7 +650,8 @@ sub Interface($$$) push (@fns, [$infn, $outfn, "dcerpc_$d->{NAME}", $prettyname, $fndocstring, $d->{OPNUM}]); } - $self->pidl("static struct PyNdrRpcMethodDef interface_$interface->{NAME}\_methods[] = {"); + $self->pidl("const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[] = {"); + $self->pidl_hdr("const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[];"); $self->indent; foreach my $d (@fns) { my ($infn, $outfn, $callfn, $prettyname, $docstring, $opnum) = @$d; @@ -771,7 +772,7 @@ sub Interface($$$) $self->pidl(""); $self->register_module_typeobject($interface->{NAME}, "&$interface->{NAME}_InterfaceType"); - $self->register_module_readycode(["if (!PyInterface_AddNdrRpcMethods(&$interface->{NAME}_InterfaceType, interface_$interface->{NAME}_methods))", "\treturn;", ""]); + $self->register_module_readycode(["if (!PyInterface_AddNdrRpcMethods(&$interface->{NAME}_InterfaceType, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]); } $self->pidl_hdr("\n"); -- cgit From d5434f0b4bcf744e5a5f0e933bdcf629d42a6478 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 04:14:28 +0200 Subject: Allow using IRPC functions on the messaging bus from Python. (This used to be commit 6ecf81ae13dffa05356c1177c617206c120fb7d7) --- source4/lib/messaging/config.mk | 8 +- source4/lib/messaging/pyirpc.c | 547 -------------------------- source4/lib/messaging/pymessaging.c | 556 +++++++++++++++++++++++++++ source4/librpc/config.mk | 17 + source4/librpc/rpc/pyrpc.h | 2 + source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 2 +- source4/scripting/bin/smbstatus | 39 +- 7 files changed, 603 insertions(+), 568 deletions(-) delete mode 100644 source4/lib/messaging/pyirpc.c create mode 100644 source4/lib/messaging/pymessaging.c diff --git a/source4/lib/messaging/config.mk b/source4/lib/messaging/config.mk index f330ed7cab..e92f78c8e3 100644 --- a/source4/lib/messaging/config.mk +++ b/source4/lib/messaging/config.mk @@ -11,8 +11,8 @@ PUBLIC_DEPENDENCIES = \ MESSAGING_OBJ_FILES = $(libmessagingsrcdir)/messaging.o -[PYTHON::python_irpc] -LIBRARY_REALNAME = samba/irpc.$(SHLIBEXT) -PRIVATE_DEPENDENCIES = MESSAGING LIBEVENTS +[PYTHON::python_messaging] +LIBRARY_REALNAME = samba/messaging.$(SHLIBEXT) +PRIVATE_DEPENDENCIES = MESSAGING LIBEVENTS python_irpc -python_irpc_OBJ_FILES = $(libmessagingsrcdir)/pyirpc.o +python_messaging_OBJ_FILES = $(libmessagingsrcdir)/pymessaging.o diff --git a/source4/lib/messaging/pyirpc.c b/source4/lib/messaging/pyirpc.c deleted file mode 100644 index 41475daaff..0000000000 --- a/source4/lib/messaging/pyirpc.c +++ /dev/null @@ -1,547 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Copyright © Jelmer Vernooij 2008 - - Based on the equivalent for EJS: - Copyright © Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include -#include "libcli/util/pyerrors.h" -#include "librpc/rpc/pyrpc.h" -#include "lib/messaging/irpc.h" -#include "lib/messaging/messaging.h" -#include "lib/events/events.h" -#include "cluster/cluster.h" -#include "param/param.h" -#include "librpc/gen_ndr/py_irpc.h" - -PyAPI_DATA(PyTypeObject) messaging_Type; -PyAPI_DATA(PyTypeObject) irpc_InterfaceType; - -static bool server_id_from_py(PyObject *object, struct server_id *server_id) -{ - if (!PyTuple_Check(object)) { - PyErr_SetString(PyExc_ValueError, "Expected tuple"); - return false; - } - - if (PyTuple_Size(object) == 3) { - return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node); - } else { - int id, id2; - if (!PyArg_ParseTuple(object, "ii", &id, &id2)) - return false; - *server_id = cluster_id(id, id2); - return true; - } -} - -typedef struct { - PyObject_HEAD - TALLOC_CTX *mem_ctx; - struct messaging_context *msg_ctx; -} messaging_Object; - -PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) -{ - struct event_context *ev; - const char *kwnames[] = { "own_id", "messaging_path", NULL }; - PyObject *own_id = Py_None; - const char *messaging_path = NULL; - messaging_Object *ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Os:connect", - discard_const_p(char *, kwnames), &own_id, &messaging_path)) { - return NULL; - } - - ret = PyObject_New(messaging_Object, &messaging_Type); - if (ret == NULL) - return NULL; - - ret->mem_ctx = talloc_new(NULL); - - ev = event_context_init(ret->mem_ctx); - - if (messaging_path == NULL) { - messaging_path = lp_messaging_path(ret, global_loadparm); - } else { - messaging_path = talloc_strdup(ret->mem_ctx, messaging_path); - } - - if (own_id != Py_None) { - struct server_id server_id; - - if (!server_id_from_py(own_id, &server_id)) - return NULL; - - ret->msg_ctx = messaging_init(ret->mem_ctx, - messaging_path, - server_id, - lp_iconv_convenience(global_loadparm), - ev); - } else { - ret->msg_ctx = messaging_client_init(ret->mem_ctx, - messaging_path, - lp_iconv_convenience(global_loadparm), - ev); - } - - if (ret->msg_ctx == NULL) { - PyErr_SetString(PyExc_RuntimeError, "messaging_connect unable to create a messaging context"); - talloc_free(ret->mem_ctx); - return NULL; - } - - return (PyObject *)ret; -} - -static void py_messaging_dealloc(PyObject *self) -{ - messaging_Object *iface = (messaging_Object *)self; - talloc_free(iface->msg_ctx); - PyObject_Del(self); -} - -static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwargs) -{ - messaging_Object *iface = (messaging_Object *)self; - uint32_t msg_type; - DATA_BLOB data; - PyObject *target; - NTSTATUS status; - struct server_id server; - const char *kwnames[] = { "target", "msg_type", "data", NULL }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ois#|:send", - discard_const_p(char *, kwnames), &target, &msg_type, &data.data, &data.length)) { - return NULL; - } - - if (!server_id_from_py(target, &server)) - return NULL; - - status = messaging_send(iface->msg_ctx, server, msg_type, &data); - if (NT_STATUS_IS_ERR(status)) { - PyErr_SetNTSTATUS(status); - return NULL; - } - - return Py_None; -} - -static void py_msg_callback_wrapper(struct messaging_context *msg, void *private, - uint32_t msg_type, - struct server_id server_id, DATA_BLOB *data) -{ - PyObject *callback = (PyObject *)private; - - PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, - server_id.id, server_id.id2, server_id.node, - data->data, data->length); -} - -static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject *kwargs) -{ - messaging_Object *iface = (messaging_Object *)self; - uint32_t msg_type = -1; - PyObject *callback; - NTSTATUS status; - const char *kwnames[] = { "callback", "msg_type", NULL }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", - discard_const_p(char *, kwnames), &callback, &msg_type)) { - return NULL; - } - - Py_INCREF(callback); - - if (msg_type == -1) { - status = messaging_register_tmp(iface->msg_ctx, callback, - py_msg_callback_wrapper, &msg_type); - } else { - status = messaging_register(iface->msg_ctx, callback, - msg_type, py_msg_callback_wrapper); - } - if (NT_STATUS_IS_ERR(status)) { - PyErr_SetNTSTATUS(status); - return NULL; - } - - return PyLong_FromLong(msg_type); -} - -static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObject *kwargs) -{ - messaging_Object *iface = (messaging_Object *)self; - uint32_t msg_type = -1; - PyObject *callback; - const char *kwnames[] = { "callback", "msg_type", NULL }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", - discard_const_p(char *, kwnames), &callback, &msg_type)) { - return NULL; - } - - messaging_deregister(iface->msg_ctx, msg_type, callback); - - Py_DECREF(callback); - - return Py_None; -} - -static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs) -{ - messaging_Object *iface = (messaging_Object *)self; - NTSTATUS status; - char *name; - const char *kwnames[] = { "name", NULL }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", - discard_const_p(char *, kwnames), &name)) { - return NULL; - } - - status = irpc_add_name(iface->msg_ctx, name); - if (NT_STATUS_IS_ERR(status)) { - PyErr_SetNTSTATUS(status); - return NULL; - } - - return Py_None; -} - - -static PyObject *py_messaging_remove_name(PyObject *self, PyObject *args, PyObject *kwargs) -{ - messaging_Object *iface = (messaging_Object *)self; - char *name; - const char *kwnames[] = { "name", NULL }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", - discard_const_p(char *, kwnames), &name)) { - return NULL; - } - - irpc_remove_name(iface->msg_ctx, name); - - return Py_None; -} - -static PyMethodDef py_messaging_methods[] = { - { "send", (PyCFunction)py_messaging_send, METH_VARARGS|METH_KEYWORDS, - "S.send(target, msg_type, data) -> None\nSend a message" }, - { "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS, - "S.register(callback, msg_type=None) -> msg_type\nRegister a message handler" }, - { "deregister", (PyCFunction)py_messaging_deregister, METH_VARARGS|METH_KEYWORDS, - "S.deregister(callback, msg_type) -> None\nDeregister a message handler" }, - { "add_name", (PyCFunction)py_messaging_add_name, METH_VARARGS|METH_KEYWORDS, "S.add_name(name) -> None\nListen on another name" }, - { "remove_name", (PyCFunction)py_messaging_remove_name, METH_VARARGS|METH_KEYWORDS, "S.remove_name(name) -> None\nStop listening on a name" }, - { NULL, NULL, 0, NULL } -}; - -static PyObject *py_messaging_server_id(PyObject *obj, void *closure) -{ - messaging_Object *iface = (messaging_Object *)obj; - struct server_id server_id = messaging_get_server_id(iface->msg_ctx); - - return Py_BuildValue("(iii)", server_id.id, server_id.id2, - server_id.node); -} - -static PyGetSetDef py_messaging_getset[] = { - { discard_const_p(char, "server_id"), py_messaging_server_id, NULL, - discard_const_p(char, "local server id") }, - { NULL }, -}; - - -PyTypeObject messaging_Type = { - PyObject_HEAD_INIT(NULL) 0, - .tp_name = "irpc.Messaging", - .tp_basicsize = sizeof(messaging_Object), - .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - .tp_new = py_messaging_connect, - .tp_dealloc = py_messaging_dealloc, - .tp_methods = py_messaging_methods, - .tp_getset = py_messaging_getset, -}; - - -/* - state of a irpc 'connection' -*/ -typedef struct { - PyObject_HEAD - const char *server_name; - struct server_id *dest_ids; - struct messaging_context *msg_ctx; - TALLOC_CTX *mem_ctx; -} irpc_InterfaceObject; - -/* - setup a context for talking to a irpc server - example: - status = irpc.connect("smb_server"); -*/ - -PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) -{ - struct event_context *ev; - const char *kwnames[] = { "server", "own_id", "messaging_path", NULL }; - char *server; - const char *messaging_path = NULL; - PyObject *own_id = Py_None; - irpc_InterfaceObject *ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Os:connect", - discard_const_p(char *, kwnames), &server, &own_id, &messaging_path)) { - return NULL; - } - - ret = PyObject_New(irpc_InterfaceObject, &irpc_InterfaceType); - if (ret == NULL) - return NULL; - - ret->mem_ctx = talloc_new(NULL); - - ret->server_name = server; - - ev = event_context_init(ret->mem_ctx); - - if (messaging_path == NULL) { - messaging_path = lp_messaging_path(ret, global_loadparm); - } - - if (own_id != Py_None) { - struct server_id server_id; - - if (!server_id_from_py(own_id, &server_id)) - return NULL; - - ret->msg_ctx = messaging_init(ret->mem_ctx, - messaging_path, - server_id, - lp_iconv_convenience(global_loadparm), - ev); - } else { - ret->msg_ctx = messaging_client_init(ret->mem_ctx, - messaging_path, - lp_iconv_convenience(global_loadparm), - ev); - } - - if (ret->msg_ctx == NULL) { - PyErr_SetString(PyExc_RuntimeError, "irpc_connect unable to create a messaging context"); - talloc_free(ret->mem_ctx); - return NULL; - } - - ret->dest_ids = irpc_servers_byname(ret->msg_ctx, ret->mem_ctx, ret->server_name); - if (ret->dest_ids == NULL || ret->dest_ids[0].id == 0) { - talloc_free(ret->mem_ctx); - PyErr_SetNTSTATUS(NT_STATUS_OBJECT_NAME_NOT_FOUND); - return NULL; - } else { - return (PyObject *)ret; - } -} - -typedef struct { - PyObject_HEAD - struct irpc_request **reqs; - int count; - int current; - TALLOC_CTX *mem_ctx; - py_data_unpack_fn unpack_fn; -} irpc_ResultObject; - - -static PyObject *irpc_result_next(irpc_ResultObject *iterator) -{ - NTSTATUS status; - - if (iterator->current >= iterator->count) { - PyErr_SetString(PyExc_StopIteration, "No more results"); - return NULL; - } - - status = irpc_call_recv(iterator->reqs[iterator->current]); - iterator->current++; - if (!NT_STATUS_IS_OK(status)) { - PyErr_SetNTSTATUS(status); - return NULL; - } - - return iterator->unpack_fn(iterator->reqs[iterator->current-1]->r); -} - -static PyObject *irpc_result_len(irpc_ResultObject *self) -{ - return PyLong_FromLong(self->count); -} - -static PyMethodDef irpc_result_methods[] = { - { "__len__", (PyCFunction)irpc_result_len, METH_NOARGS, - "Number of elements returned"}, - { NULL } -}; - -static void irpc_result_dealloc(PyObject *self) -{ - talloc_free(((irpc_ResultObject *)self)->mem_ctx); - PyObject_Del(self); -} - -PyTypeObject irpc_ResultIteratorType = { - PyObject_HEAD_INIT(NULL) 0, - .tp_name = "irpc.ResultIterator", - .tp_basicsize = sizeof(irpc_ResultObject), - .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - .tp_iter = (iternextfunc)irpc_result_next, - .tp_methods = irpc_result_methods, - .tp_dealloc = irpc_result_dealloc, -}; - -static PyObject *py_irpc_call(irpc_InterfaceObject *p, struct PyNdrRpcMethodDef *method_def, PyObject *args, PyObject *kwargs) -{ - void *ptr; - struct irpc_request **reqs; - int i, count; - NTSTATUS status; - TALLOC_CTX *mem_ctx = talloc_new(NULL); - irpc_ResultObject *ret; - - /* allocate the C structure */ - ptr = talloc_zero_size(mem_ctx, method_def->table->calls[method_def->opnum].struct_size); - if (ptr == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* convert the mpr object into a C structure */ - if (!method_def->pack_in_data(args, kwargs, ptr)) { - talloc_free(mem_ctx); - return NULL; - } - - for (count=0;p->dest_ids[count].id;count++) /* noop */ ; - - /* we need to make a call per server */ - reqs = talloc_array(mem_ctx, struct irpc_request *, count); - if (reqs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* make the actual calls */ - for (i=0;imsg_ctx, p->dest_ids[i], - method_def->table, method_def->opnum, ptr, ptr); - if (reqs[i] == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - talloc_steal(reqs, reqs[i]); - } - - ret = PyObject_New(irpc_ResultObject, &irpc_ResultIteratorType); - ret->mem_ctx = mem_ctx; - ret->reqs = reqs; - ret->count = count; - ret->current = 0; - ret->unpack_fn = method_def->unpack_out_data; - - return (PyObject *)ret; -done: - talloc_free(mem_ctx); - PyErr_SetNTSTATUS(status); - return NULL; -} - -static PyObject *py_irpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) -{ - irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self; - struct PyNdrRpcMethodDef *md = wrapped; - - return py_irpc_call(iface, md, args, kwargs); -} - -static void py_irpc_dealloc(PyObject *self) -{ - irpc_InterfaceObject *iface = (irpc_InterfaceObject *)self; - talloc_free(iface->mem_ctx); - PyObject_Del(self); -} - -PyTypeObject irpc_InterfaceType = { - PyObject_HEAD_INIT(NULL) 0, - .tp_name = "irpc.ClientConnection", - .tp_basicsize = sizeof(irpc_InterfaceObject), - .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - .tp_new = py_irpc_connect, - .tp_dealloc = py_irpc_dealloc, -}; - -static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, struct PyNdrRpcMethodDef *mds) -{ - int i; - for (i = 0; mds[i].name; i++) { - PyObject *ret; - struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1); - - wb->name = discard_const_p(char, mds[i].name); - wb->flags = PyWrapperFlag_KEYWORDS; - wb->wrapper = (wrapperfunc)py_irpc_call_wrapper; - wb->doc = discard_const_p(char, mds[i].doc); - - ret = PyDescr_NewWrapper(ifacetype, wb, &mds[i]); - - PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, - (PyObject *)ret); - } - - return true; -} - -void initirpc(void) -{ - PyObject *mod; - - if (PyType_Ready(&irpc_InterfaceType) < 0) - return; - - if (PyType_Ready(&messaging_Type) < 0) - return; - - if (PyType_Ready(&irpc_ResultIteratorType) < 0) - return; - - if (!irpc_AddNdrRpcMethods(&irpc_InterfaceType, py_ndr_irpc_methods)) - return; - - mod = Py_InitModule3("irpc", NULL, "Internal RPC"); - if (mod == NULL) - return; - - Py_INCREF((PyObject *)&irpc_InterfaceType); - PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_InterfaceType); - - Py_INCREF((PyObject *)&messaging_Type); - PyModule_AddObject(mod, "Messaging", (PyObject *)&messaging_Type); -} diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c new file mode 100644 index 0000000000..e05d5eb1f1 --- /dev/null +++ b/source4/lib/messaging/pymessaging.c @@ -0,0 +1,556 @@ +/* + Unix SMB/CIFS implementation. + Copyright © Jelmer Vernooij 2008 + + Based on the equivalent for EJS: + Copyright © Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include +#include "libcli/util/pyerrors.h" +#include "librpc/rpc/pyrpc.h" +#include "lib/messaging/irpc.h" +#include "lib/messaging/messaging.h" +#include "lib/events/events.h" +#include "cluster/cluster.h" +#include "param/param.h" +#include "librpc/gen_ndr/py_irpc.h" + +PyAPI_DATA(PyTypeObject) messaging_Type; +PyAPI_DATA(PyTypeObject) irpc_ClientConnectionType; + +static bool server_id_from_py(PyObject *object, struct server_id *server_id) +{ + if (!PyTuple_Check(object)) { + PyErr_SetString(PyExc_ValueError, "Expected tuple"); + return false; + } + + if (PyTuple_Size(object) == 3) { + return PyArg_ParseTuple(object, "iii", &server_id->id, &server_id->id2, &server_id->node); + } else { + int id, id2; + if (!PyArg_ParseTuple(object, "ii", &id, &id2)) + return false; + *server_id = cluster_id(id, id2); + return true; + } +} + +typedef struct { + PyObject_HEAD + TALLOC_CTX *mem_ctx; + struct messaging_context *msg_ctx; +} messaging_Object; + +PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) +{ + struct event_context *ev; + const char *kwnames[] = { "own_id", "messaging_path", NULL }; + PyObject *own_id = Py_None; + const char *messaging_path = NULL; + messaging_Object *ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Oz:connect", + discard_const_p(char *, kwnames), &own_id, &messaging_path)) { + return NULL; + } + + ret = PyObject_New(messaging_Object, &messaging_Type); + if (ret == NULL) + return NULL; + + ret->mem_ctx = talloc_new(NULL); + + ev = event_context_init(ret->mem_ctx); + + if (messaging_path == NULL) { + messaging_path = lp_messaging_path(ret, global_loadparm); + } else { + messaging_path = talloc_strdup(ret->mem_ctx, messaging_path); + } + + if (own_id != Py_None) { + struct server_id server_id; + + if (!server_id_from_py(own_id, &server_id)) + return NULL; + + ret->msg_ctx = messaging_init(ret->mem_ctx, + messaging_path, + server_id, + lp_iconv_convenience(global_loadparm), + ev); + } else { + ret->msg_ctx = messaging_client_init(ret->mem_ctx, + messaging_path, + lp_iconv_convenience(global_loadparm), + ev); + } + + if (ret->msg_ctx == NULL) { + PyErr_SetString(PyExc_RuntimeError, "messaging_connect unable to create a messaging context"); + talloc_free(ret->mem_ctx); + return NULL; + } + + return (PyObject *)ret; +} + +static void py_messaging_dealloc(PyObject *self) +{ + messaging_Object *iface = (messaging_Object *)self; + talloc_free(iface->msg_ctx); + PyObject_Del(self); +} + +static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + uint32_t msg_type; + DATA_BLOB data; + PyObject *target; + NTSTATUS status; + struct server_id server; + const char *kwnames[] = { "target", "msg_type", "data", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ois#|:send", + discard_const_p(char *, kwnames), &target, &msg_type, &data.data, &data.length)) { + return NULL; + } + + if (!server_id_from_py(target, &server)) + return NULL; + + status = messaging_send(iface->msg_ctx, server, msg_type, &data); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return Py_None; +} + +static void py_msg_callback_wrapper(struct messaging_context *msg, void *private, + uint32_t msg_type, + struct server_id server_id, DATA_BLOB *data) +{ + PyObject *callback = (PyObject *)private; + + PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, + server_id.id, server_id.id2, server_id.node, + data->data, data->length); +} + +static PyObject *py_messaging_register(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + uint32_t msg_type = -1; + PyObject *callback; + NTSTATUS status; + const char *kwnames[] = { "callback", "msg_type", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", + discard_const_p(char *, kwnames), &callback, &msg_type)) { + return NULL; + } + + Py_INCREF(callback); + + if (msg_type == -1) { + status = messaging_register_tmp(iface->msg_ctx, callback, + py_msg_callback_wrapper, &msg_type); + } else { + status = messaging_register(iface->msg_ctx, callback, + msg_type, py_msg_callback_wrapper); + } + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return PyLong_FromLong(msg_type); +} + +static PyObject *py_messaging_deregister(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + uint32_t msg_type = -1; + PyObject *callback; + const char *kwnames[] = { "callback", "msg_type", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:send", + discard_const_p(char *, kwnames), &callback, &msg_type)) { + return NULL; + } + + messaging_deregister(iface->msg_ctx, msg_type, callback); + + Py_DECREF(callback); + + return Py_None; +} + +static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + NTSTATUS status; + char *name; + const char *kwnames[] = { "name", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", + discard_const_p(char *, kwnames), &name)) { + return NULL; + } + + status = irpc_add_name(iface->msg_ctx, name); + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return Py_None; +} + + +static PyObject *py_messaging_remove_name(PyObject *self, PyObject *args, PyObject *kwargs) +{ + messaging_Object *iface = (messaging_Object *)self; + char *name; + const char *kwnames[] = { "name", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send", + discard_const_p(char *, kwnames), &name)) { + return NULL; + } + + irpc_remove_name(iface->msg_ctx, name); + + return Py_None; +} + +static PyMethodDef py_messaging_methods[] = { + { "send", (PyCFunction)py_messaging_send, METH_VARARGS|METH_KEYWORDS, + "S.send(target, msg_type, data) -> None\nSend a message" }, + { "register", (PyCFunction)py_messaging_register, METH_VARARGS|METH_KEYWORDS, + "S.register(callback, msg_type=None) -> msg_type\nRegister a message handler" }, + { "deregister", (PyCFunction)py_messaging_deregister, METH_VARARGS|METH_KEYWORDS, + "S.deregister(callback, msg_type) -> None\nDeregister a message handler" }, + { "add_name", (PyCFunction)py_messaging_add_name, METH_VARARGS|METH_KEYWORDS, "S.add_name(name) -> None\nListen on another name" }, + { "remove_name", (PyCFunction)py_messaging_remove_name, METH_VARARGS|METH_KEYWORDS, "S.remove_name(name) -> None\nStop listening on a name" }, + { NULL, NULL, 0, NULL } +}; + +static PyObject *py_messaging_server_id(PyObject *obj, void *closure) +{ + messaging_Object *iface = (messaging_Object *)obj; + struct server_id server_id = messaging_get_server_id(iface->msg_ctx); + + return Py_BuildValue("(iii)", server_id.id, server_id.id2, + server_id.node); +} + +static PyGetSetDef py_messaging_getset[] = { + { discard_const_p(char, "server_id"), py_messaging_server_id, NULL, + discard_const_p(char, "local server id") }, + { NULL }, +}; + + +PyTypeObject messaging_Type = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "irpc.Messaging", + .tp_basicsize = sizeof(messaging_Object), + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_new = py_messaging_connect, + .tp_dealloc = py_messaging_dealloc, + .tp_methods = py_messaging_methods, + .tp_getset = py_messaging_getset, + .tp_doc = "Messaging(own_id=None, messaging_path=None)\n" \ + "Create a new object that can be used to communicate with the peers in the specified messaging path.\n" \ + "If no path is specified, the default path from smb.conf will be used." +}; + + +/* + state of a irpc 'connection' +*/ +typedef struct { + PyObject_HEAD + const char *server_name; + struct server_id *dest_ids; + struct messaging_context *msg_ctx; + TALLOC_CTX *mem_ctx; +} irpc_ClientConnectionObject; + +/* + setup a context for talking to a irpc server + example: + status = irpc.connect("smb_server"); +*/ + +PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) +{ + struct event_context *ev; + const char *kwnames[] = { "server", "own_id", "messaging_path", NULL }; + char *server; + const char *messaging_path = NULL; + PyObject *own_id = Py_None; + irpc_ClientConnectionObject *ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Oz:connect", + discard_const_p(char *, kwnames), &server, &own_id, &messaging_path)) { + return NULL; + } + + ret = PyObject_New(irpc_ClientConnectionObject, &irpc_ClientConnectionType); + if (ret == NULL) + return NULL; + + ret->mem_ctx = talloc_new(NULL); + + ret->server_name = server; + + ev = event_context_init(ret->mem_ctx); + + if (messaging_path == NULL) { + messaging_path = lp_messaging_path(ret, global_loadparm); + } else { + messaging_path = talloc_strdup(ret->mem_ctx, messaging_path); + } + + if (own_id != Py_None) { + struct server_id server_id; + + if (!server_id_from_py(own_id, &server_id)) + return NULL; + + ret->msg_ctx = messaging_init(ret->mem_ctx, + messaging_path, + server_id, + lp_iconv_convenience(global_loadparm), + ev); + } else { + ret->msg_ctx = messaging_client_init(ret->mem_ctx, + messaging_path, + lp_iconv_convenience(global_loadparm), + ev); + } + + if (ret->msg_ctx == NULL) { + PyErr_SetString(PyExc_RuntimeError, "irpc_connect unable to create a messaging context"); + talloc_free(ret->mem_ctx); + return NULL; + } + + ret->dest_ids = irpc_servers_byname(ret->msg_ctx, ret->mem_ctx, ret->server_name); + if (ret->dest_ids == NULL || ret->dest_ids[0].id == 0) { + talloc_free(ret->mem_ctx); + PyErr_SetNTSTATUS(NT_STATUS_OBJECT_NAME_NOT_FOUND); + return NULL; + } else { + return (PyObject *)ret; + } +} + +typedef struct { + PyObject_HEAD + struct irpc_request **reqs; + int count; + int current; + TALLOC_CTX *mem_ctx; + py_data_unpack_fn unpack_fn; +} irpc_ResultObject; + + +static PyObject *irpc_result_next(irpc_ResultObject *iterator) +{ + NTSTATUS status; + + if (iterator->current >= iterator->count) { + PyErr_SetString(PyExc_StopIteration, "No more results"); + return NULL; + } + + status = irpc_call_recv(iterator->reqs[iterator->current]); + iterator->current++; + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + return iterator->unpack_fn(iterator->reqs[iterator->current-1]->r); +} + +static PyObject *irpc_result_len(irpc_ResultObject *self) +{ + return PyLong_FromLong(self->count); +} + +static PyMethodDef irpc_result_methods[] = { + { "__len__", (PyCFunction)irpc_result_len, METH_NOARGS, + "Number of elements returned"}, + { NULL } +}; + +static void irpc_result_dealloc(PyObject *self) +{ + talloc_free(((irpc_ResultObject *)self)->mem_ctx); + PyObject_Del(self); +} + +PyTypeObject irpc_ResultIteratorType = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "irpc.ResultIterator", + .tp_basicsize = sizeof(irpc_ResultObject), + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_iternext = (iternextfunc)irpc_result_next, + .tp_iter = PyObject_SelfIter, + .tp_methods = irpc_result_methods, + .tp_dealloc = irpc_result_dealloc, +}; + +static PyObject *py_irpc_call(irpc_ClientConnectionObject *p, struct PyNdrRpcMethodDef *method_def, PyObject *args, PyObject *kwargs) +{ + void *ptr; + struct irpc_request **reqs; + int i, count; + NTSTATUS status; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + irpc_ResultObject *ret; + + /* allocate the C structure */ + ptr = talloc_zero_size(mem_ctx, method_def->table->calls[method_def->opnum].struct_size); + if (ptr == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + /* convert the mpr object into a C structure */ + if (!method_def->pack_in_data(args, kwargs, ptr)) { + talloc_free(mem_ctx); + return NULL; + } + + for (count=0;p->dest_ids[count].id;count++) /* noop */ ; + + /* we need to make a call per server */ + reqs = talloc_array(mem_ctx, struct irpc_request *, count); + if (reqs == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + /* make the actual calls */ + for (i=0;imsg_ctx, p->dest_ids[i], + method_def->table, method_def->opnum, ptr, ptr); + if (reqs[i] == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + talloc_steal(reqs, reqs[i]); + } + + ret = PyObject_New(irpc_ResultObject, &irpc_ResultIteratorType); + ret->mem_ctx = mem_ctx; + ret->reqs = reqs; + ret->count = count; + ret->current = 0; + ret->unpack_fn = method_def->unpack_out_data; + + return (PyObject *)ret; +done: + talloc_free(mem_ctx); + PyErr_SetNTSTATUS(status); + return NULL; +} + +static PyObject *py_irpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) +{ + irpc_ClientConnectionObject *iface = (irpc_ClientConnectionObject *)self; + struct PyNdrRpcMethodDef *md = wrapped; + + return py_irpc_call(iface, md, args, kwargs); +} + +static void py_irpc_dealloc(PyObject *self) +{ + irpc_ClientConnectionObject *iface = (irpc_ClientConnectionObject *)self; + talloc_free(iface->mem_ctx); + PyObject_Del(self); +} + +PyTypeObject irpc_ClientConnectionType = { + PyObject_HEAD_INIT(NULL) 0, + .tp_name = "irpc.ClientConnection", + .tp_basicsize = sizeof(irpc_ClientConnectionObject), + .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_new = py_irpc_connect, + .tp_dealloc = py_irpc_dealloc, + .tp_doc = "ClientConnection(server, own_id=None, messaging_path=None)\n" \ + "Create a new IRPC client connection to communicate with the servers in the specified path.\n" \ + "If no path is specified, the default path from smb.conf will be used." +}; + +static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpcMethodDef *mds) +{ + int i; + for (i = 0; mds[i].name; i++) { + PyObject *ret; + struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1); + + wb->name = discard_const_p(char, mds[i].name); + wb->flags = PyWrapperFlag_KEYWORDS; + wb->wrapper = (wrapperfunc)py_irpc_call_wrapper; + wb->doc = discard_const_p(char, mds[i].doc); + + ret = PyDescr_NewWrapper(ifacetype, wb, discard_const_p(void, &mds[i])); + + PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, + (PyObject *)ret); + } + + return true; +} + +void initmessaging(void) +{ + PyObject *mod; + + if (PyType_Ready(&irpc_ClientConnectionType) < 0) + return; + + if (PyType_Ready(&messaging_Type) < 0) + return; + + if (PyType_Ready(&irpc_ResultIteratorType) < 0) + return; + + if (!irpc_AddNdrRpcMethods(&irpc_ClientConnectionType, py_ndr_irpc_methods)) + return; + + mod = Py_InitModule3("messaging", NULL, "Internal RPC"); + if (mod == NULL) + return; + + Py_INCREF((PyObject *)&irpc_ClientConnectionType); + PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_ClientConnectionType); + + Py_INCREF((PyObject *)&messaging_Type); + PyModule_AddObject(mod, "Messaging", (PyObject *)&messaging_Type); +} diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index 2943c7b516..ab25921ef8 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -434,6 +434,11 @@ PUBLIC_DEPENDENCIES = dcerpc NDR_UNIXINFO RPC_NDR_UNIXINFO_OBJ_FILES = $(gen_ndrsrcdir)/ndr_unixinfo_c.o +[SUBSYSTEM::RPC_NDR_IRPC] +PUBLIC_DEPENDENCIES = dcerpc NDR_IRPC + +RPC_NDR_IRPC_OBJ_FILES = $(gen_ndrsrcdir)/ndr_irpc_c.o + [LIBRARY::dcerpc_samr] PUBLIC_DEPENDENCIES = dcerpc NDR_SAMR @@ -658,6 +663,12 @@ PRIVATE_DEPENDENCIES = dcerpc_atsvc PYTALLOC param swig_credentials python_dcer python_atsvc_OBJ_FILES = $(gen_ndrsrcdir)/py_atsvc.o +[PYTHON::python_nbt] +LIBRARY_REALNAME = samba/nbt.$(SHLIBEXT) +PRIVATE_DEPENDENCIES = NDR_NBT PYTALLOC param swig_credentials python_dcerpc + +python_nbt_OBJ_FILES = $(gen_ndrsrcdir)/py_nbt.o + [PYTHON::python_samr] LIBRARY_REALNAME = samba/dcerpc/samr.$(SHLIBEXT) PRIVATE_DEPENDENCIES = dcerpc_samr PYTALLOC python_dcerpc_security python_lsa python_dcerpc_misc swig_credentials param python_dcerpc @@ -694,6 +705,12 @@ PRIVATE_DEPENDENCIES = RPC_NDR_UNIXINFO PYTALLOC param swig_credentials python_d python_unixinfo_OBJ_FILES = $(gen_ndrsrcdir)/py_unixinfo.o +[PYTHON::python_irpc] +LIBRARY_REALNAME = samba/irpc.$(SHLIBEXT) +PRIVATE_DEPENDENCIES = RPC_NDR_IRPC PYTALLOC param swig_credentials python_dcerpc_security python_dcerpc_misc python_dcerpc python_nbt + +python_irpc_OBJ_FILES = $(gen_ndrsrcdir)/py_irpc.o + [PYTHON::python_drsuapi] LIBRARY_REALNAME = samba/dcerpc/drsuapi.$(SHLIBEXT) PRIVATE_DEPENDENCIES = RPC_NDR_DRSUAPI PYTALLOC param swig_credentials python_dcerpc_misc python_dcerpc_security python_dcerpc diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 989aeecc7b..af9ca728d8 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -29,8 +29,10 @@ fail; \ } +#define dom_sid0_Type dom_sid_Type #define dom_sid2_Type dom_sid_Type #define dom_sid28_Type dom_sid_Type +#define dom_sid0_Check dom_sid_Check #define dom_sid2_Check dom_sid_Check #define dom_sid28_Check dom_sid_Check diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 055ee13b10..b5ae801ff8 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -651,7 +651,7 @@ sub Interface($$$) } $self->pidl("const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[] = {"); - $self->pidl_hdr("const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[];"); + $self->pidl_hdr("extern const struct PyNdrRpcMethodDef py_ndr_$interface->{NAME}\_methods[];"); $self->indent; foreach my $d (@fns) { my ($infn, $outfn, $callfn, $prettyname, $docstring, $opnum) = @$d; diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 782e83e4cf..6d852c279c 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -15,11 +15,12 @@ sys.path.insert(0, "bin/python") import optparse import samba.getopt as options -import samba.irpc +from samba import messaging, irpc -def show_sessions(): +def show_sessions(conn): """show open sessions""" - sessions = smbsrv_sessions() + conn = open_connection("smb_server") + sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next() print "User Client Connected at" print "-------------------------------------------------------------------------------" for session in sessions: @@ -27,37 +28,43 @@ def show_sessions(): print "%-30s %16s %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time)) print "" -def show_tcons(): +def show_tcons(open_connection): """show open tree connects""" - tcons = smbsrv_tcons() + conn = open_connection("smb_server") + tcons = conn.smbsrv_information(irpc.SMBSRV_INFO_TCONS).next() print "Share Client Connected at" print "-------------------------------------------------------------------------------" for tcon in tcons: print "%-30s %16s %s\n" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)) -def show_nbt(): +def show_nbt(open_connection): """show nbtd information""" - stats = nbtd_statistics() - print "NBT server statistics:", + conn = open_connection("nbt_server") + stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next() + print "NBT server statistics:" for r in stats: - print "\t" + r + ":\t" + stats[r] + "\n" + print "\t" + r + ":\t" + getattr(stats, r) + "\n" print "" parser = optparse.OptionParser("%s [options]" % sys.argv[0]) sambaopts = options.SambaOptions(parser) parser.add_option_group(sambaopts) -parser.add_option("--nbt", type="string", metavar="NBT", - help="show NetBIOS status") +parser.add_option("--messaging-path", type="string", metavar="PATH", + help="messaging path") +parser.add_option("--nbt", help="show NetBIOS status", action="store_true") + +opts, args = parser.parse_args() lp = sambaopts.get_loadparm() print "%s\n\n" % lp.get("server string") +def open_connection(name): + return messaging.ClientConnection(name, messaging_path=opts.messaging_path) + if opts.nbt: - show_nbt() + show_nbt(open_connection) else: - show_sessions() - show_tcons() - -return 0 + show_sessions(open_connection) + show_tcons(open_connection) -- cgit From 4b3641695ba42d0348e8eceadb02430342c1513c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 05:00:45 +0200 Subject: Finish smbstatus in Python. (This used to be commit 988508c2d3269cc88ed38df2fc207a1c0aaccc6b) --- source4/lib/messaging/pymessaging.c | 3 ++ source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 50 +++++++++++++++++++--------- source4/scripting/bin/smbstatus | 23 ++++++++----- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index e05d5eb1f1..1c22fb431a 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -530,6 +530,7 @@ static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpc void initmessaging(void) { + extern void initirpc(void); PyObject *mod; if (PyType_Ready(&irpc_ClientConnectionType) < 0) @@ -548,6 +549,8 @@ void initmessaging(void) if (mod == NULL) return; + initirpc(); + Py_INCREF((PyObject *)&irpc_ClientConnectionType); PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_ClientConnectionType); diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index b5ae801ff8..60d0dafc8a 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -21,7 +21,7 @@ $VERSION = '0.01'; sub new($) { my ($class) = @_; my $self = { res => "", res_hdr => "", tabs => "", constants => {}, - module_methods => [], module_objects => [], module_types => [], + module_methods => [], module_objects => [], ready_types => [], readycode => [] }; bless($self, $class); } @@ -108,7 +108,7 @@ sub FromUnionToPythonFunction($$$$) $self->indent; if ($e->{NAME}) { - $self->ConvertObjectToPython($mem_ctx, {}, $e, "$name->$e->{NAME}", "ret"); + $self->ConvertObjectToPython($mem_ctx, {}, $e, "$name->$e->{NAME}", "ret", "return NULL;"); } else { $self->pidl("ret = Py_None;"); } @@ -182,7 +182,7 @@ sub PythonStruct($$$$$$) $self->indent; $self->pidl("$cname *object = py_talloc_get_ptr(obj);"); $self->pidl("PyObject *py_$e->{NAME};"); - $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}"); + $self->ConvertObjectToPython("py_talloc_get_mem_ctx(obj)", $env, $e, $varname, "py_$e->{NAME}", "return NULL;"); $self->pidl("return py_$e->{NAME};"); $self->deindent; $self->pidl("}"); @@ -383,7 +383,7 @@ sub PythonFunctionUnpackOut($$$) next if ($metadata_args->{out}->{$e->{NAME}}); my $py_name = "py_$e->{NAME}"; if (grep(/out/,@{$e->{DIRECTION}})) { - $self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name); + $self->ConvertObjectToPython("r", $env, $e, "r->out.$e->{NAME}", $py_name, "return NULL;"); if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $py_name);"); $i++; @@ -792,7 +792,13 @@ sub register_module_typeobject($$$) $self->register_module_object($name, "(PyObject *)$py_name"); - push (@{$self->{module_types}}, [$name, $py_name]) + $self->check_ready_type($py_name); +} + +sub check_ready_type($$) +{ + my ($self, $py_name) = @_; + push (@{$self->{ready_types}}, $py_name) unless (grep(/^$py_name$/,@{$self->{ready_types}})); } sub register_module_readycode($$) @@ -1026,14 +1032,24 @@ sub ConvertObjectToPythonData($$$$$) die("unknown type ".mapTypeName($ctype) . ": $cvar"); } -sub ConvertObjectToPythonLevel($$$$$) +sub fail_on_null($$$) { - my ($self, $mem_ctx, $env, $e, $l, $var_name, $py_var) = @_; + my ($self, $var, $fail) = @_; + $self->pidl("if ($var == NULL) {"); + $self->indent; + $self->pidl($fail); + $self->deindent; + $self->pidl("}"); +} + +sub ConvertObjectToPythonLevel($$$$$$) +{ + my ($self, $mem_ctx, $env, $e, $l, $var_name, $py_var, $fail) = @_; my $nl = GetNextLevel($e, $l); if ($l->{TYPE} eq "POINTER") { if ($nl->{TYPE} eq "DATA" and Parse::Pidl::Typelist::scalar_is_reference($nl->{DATA_TYPE})) { - $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, $var_name, $py_var); + $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, $var_name, $py_var, $fail); return; } if ($l->{POINTER_TYPE} ne "ref") { @@ -1044,7 +1060,7 @@ sub ConvertObjectToPythonLevel($$$$$) $self->pidl("} else {"); $self->indent; } - $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, get_value_of($var_name), $py_var); + $self->ConvertObjectToPythonLevel($var_name, $env, $e, $nl, get_value_of($var_name), $py_var, $fail); if ($l->{POINTER_TYPE} ne "ref") { $self->deindent; $self->pidl("}"); @@ -1067,6 +1083,7 @@ sub ConvertObjectToPythonLevel($$$$$) $length = ParseExpr($length, $env, $e); $self->pidl("$py_var = PyList_New($length);"); + $self->fail_on_null($py_var, $fail); $self->pidl("{"); $self->indent; my $counter = "$e->{NAME}_cntr_$l->{LEVEL_INDEX}"; @@ -1075,7 +1092,7 @@ sub ConvertObjectToPythonLevel($$$$$) $self->indent; my $member_var = "py_$e->{NAME}_$l->{LEVEL_INDEX}"; $self->pidl("PyObject *$member_var;"); - $self->ConvertObjectToPythonLevel($var_name, $env, $e, GetNextLevel($e, $l), $var_name."[$counter]", $member_var); + $self->ConvertObjectToPythonLevel($var_name, $env, $e, GetNextLevel($e, $l), $var_name."[$counter]", $member_var, $fail); $self->pidl("PyList_SetItem($py_var, $counter, $member_var);"); $self->deindent; $self->pidl("}"); @@ -1086,6 +1103,8 @@ sub ConvertObjectToPythonLevel($$$$$) $var_name = get_pointer_to($var_name); my $switch = ParseExpr($l->{SWITCH_IS}, $env, $e); $self->pidl("$py_var = py_import_" . GetNextLevel($e, $l)->{DATA_TYPE} . "($mem_ctx, $switch, $var_name);"); + $self->fail_on_null($py_var, $fail); + } elsif ($l->{TYPE} eq "DATA") { if (not Parse::Pidl::Typelist::is_scalar($l->{DATA_TYPE})) { $var_name = get_pointer_to($var_name); @@ -1093,7 +1112,7 @@ sub ConvertObjectToPythonLevel($$$$$) my $conv = $self->ConvertObjectToPythonData($mem_ctx, $l->{DATA_TYPE}, $var_name); $self->pidl("$py_var = $conv;"); } elsif ($l->{TYPE} eq "SUBCONTEXT") { - $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var); + $self->ConvertObjectToPythonLevel($mem_ctx, $env, $e, GetNextLevel($e, $l), $var_name, $py_var, $fail); } else { die("Unknown level type $l->{TYPE} $var_name"); } @@ -1101,9 +1120,9 @@ sub ConvertObjectToPythonLevel($$$$$) sub ConvertObjectToPython($$$$$$) { - my ($self, $mem_ctx, $env, $ctype, $cvar, $py_var) = @_; + my ($self, $mem_ctx, $env, $ctype, $cvar, $py_var, $fail) = @_; - $self->ConvertObjectToPythonLevel($mem_ctx, $env, $ctype, $ctype->{LEVELS}[0], $cvar, $py_var); + $self->ConvertObjectToPythonLevel($mem_ctx, $env, $ctype, $ctype->{LEVELS}[0], $cvar, $py_var, $fail); } sub Parse($$$$$) @@ -1153,9 +1172,8 @@ sub Parse($$$$$) $self->pidl("PyObject *m;"); $self->pidl(""); - foreach (@{$self->{module_types}}) { - my ($object_name, $c_name) = @$_; - $self->pidl("if (PyType_Ready($c_name) < 0)"); + foreach (@{$self->{ready_types}}) { + $self->pidl("if (PyType_Ready($_) < 0)"); $self->pidl("\treturn;"); } diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 6d852c279c..7e58ee1269 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -9,13 +9,13 @@ # Released under the GNU GPL version 3 or later # -import sys +import os, sys sys.path.insert(0, "bin/python") import optparse import samba.getopt as options -from samba import messaging, irpc +from samba import irpc, messaging def show_sessions(conn): """show open sessions""" @@ -35,7 +35,7 @@ def show_tcons(open_connection): print "Share Client Connected at" print "-------------------------------------------------------------------------------" for tcon in tcons: - print "%-30s %16s %s\n" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)) + print "%-30s %16s %s" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)) def show_nbt(open_connection): @@ -43,9 +43,14 @@ def show_nbt(open_connection): conn = open_connection("nbt_server") stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next() print "NBT server statistics:" - for r in stats: - print "\t" + r + ":\t" + getattr(stats, r) + "\n" - print "" + fields = [("total_received", "Total received"), + ("total_sent", "Total sent"), + ("query_count", "Query count"), + ("register_count", "Register count"), + ("release_count", "Release count")] + for (field, description) in fields: + print "\t%s:\t%s" % (description, getattr(stats, field)) + print parser = optparse.OptionParser("%s [options]" % sys.argv[0]) sambaopts = options.SambaOptions(parser) @@ -58,10 +63,12 @@ opts, args = parser.parse_args() lp = sambaopts.get_loadparm() -print "%s\n\n" % lp.get("server string") +print "%s" % lp.get("server string") + +messaging_path = (opts.messaging_path or os.path.join(lp.get("private dir"), "smbd.tmp", "messaging")) def open_connection(name): - return messaging.ClientConnection(name, messaging_path=opts.messaging_path) + return messaging.ClientConnection(name, messaging_path=messaging_path) if opts.nbt: show_nbt(open_connection) -- cgit From 575f1243856f52f87ccb09f1235f1263b7c54b9b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 05:12:31 +0200 Subject: Cope with no server being active. (This used to be commit 893119bb4c9c297966d43d37fe73faa747b7c86e) --- source4/scripting/bin/smbstatus | 12 +++++++++--- source4/smb_server/smb_server.c | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus index 7e58ee1269..bbd0e84826 100755 --- a/source4/scripting/bin/smbstatus +++ b/source4/scripting/bin/smbstatus @@ -19,7 +19,7 @@ from samba import irpc, messaging def show_sessions(conn): """show open sessions""" - conn = open_connection("smb_server") + sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next() print "User Client Connected at" print "-------------------------------------------------------------------------------" @@ -73,5 +73,11 @@ def open_connection(name): if opts.nbt: show_nbt(open_connection) else: - show_sessions(open_connection) - show_tcons(open_connection) + try: + conn = open_connection("smb_server") + except RuntimeError, (num, msg): + if msg == 'NT_STATUS_OBJECT_NAME_NOT_FOUND': + print "No active connections" + else: + show_sessions(conn) + show_tcons(conn) diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index 367557dbb7..6eccb836d6 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -150,12 +150,12 @@ static void smbsrv_accept(struct stream_connection *conn) smb_conn->connection = conn; conn->private = smb_conn; - irpc_add_name(conn->msg_ctx, "smb_server"); - smb_conn->statistics.connect_time = timeval_current(); smbsrv_management_init(smb_conn); + irpc_add_name(conn->msg_ctx, "smb_server"); + if (!NT_STATUS_IS_OK(share_get_context_by_name(smb_conn, lp_share_backend(smb_conn->lp_ctx), smb_conn->connection->event.ctx, smb_conn->lp_ctx, &(smb_conn->share_context)))) { -- cgit From 976eca077d2ea9b44b4b62ae851ca9cc470e3729 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 17:56:49 +0200 Subject: Move some scripts to examples directory since they're not really generically useful. (This used to be commit 4026493e91f8096e5d602cd42f9a83d2d75042db) --- source4/scripting/bin/samba3dump | 4 +- source4/scripting/bin/samr.py | 114 ---------------------------- source4/scripting/bin/winreg.py | 87 --------------------- source4/scripting/python/examples/samr.py | 114 ++++++++++++++++++++++++++++ source4/scripting/python/examples/winreg.py | 87 +++++++++++++++++++++ 5 files changed, 203 insertions(+), 203 deletions(-) delete mode 100755 source4/scripting/bin/samr.py delete mode 100755 source4/scripting/bin/winreg.py create mode 100755 source4/scripting/python/examples/samr.py create mode 100755 source4/scripting/python/examples/winreg.py diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index d89667233f..c11f8dbd0d 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -14,7 +14,7 @@ sys.path.insert(0, "bin/python") import samba import samba.samba3 -parser = optparse.OptionParser("provision []") +parser = optparse.OptionParser("samba3dump []") parser.add_option("--format", type="choice", metavar="FORMAT", choices=["full", "summary"]) @@ -96,7 +96,7 @@ def print_samba3_secrets(secrets): def print_samba3_regdb(regdb): print_header("Registry") - from registry import str_regtype + from samba.registry import str_regtype for k in regdb.keys(): print "[%s]" % k diff --git a/source4/scripting/bin/samr.py b/source4/scripting/bin/samr.py deleted file mode 100755 index e91b5bc312..0000000000 --- a/source4/scripting/bin/samr.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# Unix SMB/CIFS implementation. -# Copyright © Jelmer Vernooij 2008 -# -# Based on samr.js © Andrew Tridgell -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -import sys - -sys.path.insert(0, "bin/python") - -from samba.dcerpc import samr, security, lsa - -def FillUserInfo(samr, dom_handle, users, level): - """fill a user array with user information from samrQueryUserInfo""" - for i in range(len(users)): - user_handle = samr.OpenUser(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, users[i].idx) - info = samr.QueryUserInfo(user_handle, level) - info.name = users[i].name - info.idx = users[i].idx - users[i] = info - samr.Close(user_handle) - -def toArray((handle, array, num_entries)): - ret = [] - for x in range(num_entries): - ret.append((array.entries[x].idx, array.entries[x].name)) - return ret - - -def test_Connect(samr): - """test the samr_Connect interface""" - print "Testing samr_Connect" - return samr.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) - -def test_LookupDomain(samr, handle, domain): - """test the samr_LookupDomain interface""" - print "Testing samr_LookupDomain" - return samr.LookupDomain(handle, domain) - -def test_OpenDomain(samr, handle, sid): - """test the samr_OpenDomain interface""" - print "Testing samr_OpenDomain" - return samr.OpenDomain(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, sid) - -def test_EnumDomainUsers(samr, dom_handle): - """test the samr_EnumDomainUsers interface""" - print "Testing samr_EnumDomainUsers" - users = toArray(samr.EnumDomainUsers(dom_handle, 0, 0, -1)) - print "Found %d users" % len(users) - for idx, user in users: - print "\t%s\t(%d)" % (user, idx) - -def test_EnumDomainGroups(samr, dom_handle): - """test the samr_EnumDomainGroups interface""" - print "Testing samr_EnumDomainGroups" - groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0)) - print "Found %d groups" % len(groups) - for idx, group in groups: - print "\t%s\t(%d)" % (group, idx) - -def test_domain_ops(samr, dom_handle): - """test domain specific ops""" - test_EnumDomainUsers(samr, dom_handle) - test_EnumDomainGroups(samr, dom_handle) - -def test_EnumDomains(samr, handle): - """test the samr_EnumDomains interface""" - print "Testing samr_EnumDomains" - - domains = toArray(samr.EnumDomains(handle, 0, -1)) - print "Found %d domains" % len(domains) - for idx, domain in domains: - print "\t%s (%d)" % (domain, idx) - for idx, domain in domains: - print "Testing domain %s" % domain - sid = samr.LookupDomain(handle, domain) - dom_handle = test_OpenDomain(samr, handle, sid) - test_domain_ops(samr, dom_handle) - samr.Close(dom_handle) - -if len(sys.argv) != 2: - print "Usage: samr.js " - sys.exit(1) - -binding = sys.argv[1] - -print "Connecting to " + binding -try: - samr = samr.samr(binding) -except Exception, e: - print "Failed to connect to %s: %s" % (binding, e.message) - sys.exit(1) - -handle = test_Connect(samr) -test_EnumDomains(samr, handle) -samr.Close(handle) - -print "All OK" diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py deleted file mode 100755 index 19d39e56ab..0000000000 --- a/source4/scripting/bin/winreg.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/python -# -# tool to manipulate a remote registry -# Copyright Andrew Tridgell 2005 -# Copyright Jelmer Vernooij 2007 -# Released under the GNU GPL v3 or later -# - -import sys - -# Find right directory when running from source tree -sys.path.insert(0, "bin/python") - -import winreg -import optparse -import samba.getopt as options - -parser = optparse.OptionParser("%s [path]" % sys.argv[0]) -sambaopts = options.SambaOptions(parser) -parser.add_option_group(sambaopts) -parser.add_option("--createkey", type="string", metavar="KEYNAME", - help="create a key") - -opts, args = parser.parse_args() - -if len(args) < 1: - parser.print_usage() - sys.exit(-1) - -binding = args[0] - -print "Connecting to " + binding -conn = winreg.winreg(binding, sambaopts.get_loadparm()) - -def list_values(key): - (num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:8] - for i in range(num_values): - name = winreg.StringBuf() - name.size = max_valnamelen - (name, type, data, _, data_len) = conn.EnumValue(key, i, name, 0, "", max_valbufsize, 0) - print "\ttype=%-30s size=%4d '%s'" % type, len, name - if type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ): - print "\t\t'%s'" % data -# if (v.type == reg.REG_MULTI_SZ) { -# for (j in v.value) { -# printf("\t\t'%s'\n", v.value[j]) -# } -# } -# if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) { -# printf("\t\t0x%08x (%d)\n", v.value, v.value) -# } -# if (v.type == reg.REG_QWORD) { -# printf("\t\t0x%llx (%lld)\n", v.value, v.value) -# } - -def list_path(key, path): - count = 0 - (num_subkeys, max_subkeylen, max_subkeysize) = conn.QueryInfoKey(key, winreg.String())[1:4] - for i in range(num_subkeys): - name = winreg.StringBuf() - name.size = max_subkeysize - keyclass = winreg.StringBuf() - keyclass.size = max_subkeysize - (name, _, _) = conn.EnumKey(key, i, name, keyclass=keyclass, last_changed_time=None)[0] - subkey = conn.OpenKey(key, name, 0, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) - count += list_path(subkey, "%s\\%s" % (path, name)) - list_values(subkey) - return count - -if len(args) > 1: - root = args[1] -else: - root = "HKLM" - -if opts.createkey: - reg.create_key("HKLM\\SOFTWARE", opt.createkey) -else: - print "Listing registry tree '%s'" % root - try: - root_key = getattr(conn, "Open%s" % root)(None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) - except AttributeError: - print "Unknown root key name %s" % root - sys.exit(1) - count = list_path(root_key, root) - if count == 0: - print "No entries found" - sys.exit(1) diff --git a/source4/scripting/python/examples/samr.py b/source4/scripting/python/examples/samr.py new file mode 100755 index 0000000000..1f2afbe688 --- /dev/null +++ b/source4/scripting/python/examples/samr.py @@ -0,0 +1,114 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# Based on samr.js © Andrew Tridgell +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import sys + +sys.path.insert(0, "bin/python") + +from samba.dcerpc import samr, security, lsa + +def FillUserInfo(samr, dom_handle, users, level): + """fill a user array with user information from samrQueryUserInfo""" + for i in range(len(users)): + user_handle = samr.OpenUser(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, users[i].idx) + info = samr.QueryUserInfo(user_handle, level) + info.name = users[i].name + info.idx = users[i].idx + users[i] = info + samr.Close(user_handle) + +def toArray((handle, array, num_entries)): + ret = [] + for x in range(num_entries): + ret.append((array.entries[x].idx, array.entries[x].name)) + return ret + + +def test_Connect(samr): + """test the samr_Connect interface""" + print "Testing samr_Connect" + return samr.Connect2(None, security.SEC_FLAG_MAXIMUM_ALLOWED) + +def test_LookupDomain(samr, handle, domain): + """test the samr_LookupDomain interface""" + print "Testing samr_LookupDomain" + return samr.LookupDomain(handle, domain) + +def test_OpenDomain(samr, handle, sid): + """test the samr_OpenDomain interface""" + print "Testing samr_OpenDomain" + return samr.OpenDomain(handle, security.SEC_FLAG_MAXIMUM_ALLOWED, sid) + +def test_EnumDomainUsers(samr, dom_handle): + """test the samr_EnumDomainUsers interface""" + print "Testing samr_EnumDomainUsers" + users = toArray(samr.EnumDomainUsers(dom_handle, 0, 0, -1)) + print "Found %d users" % len(users) + for idx, user in users: + print "\t%s\t(%d)" % (user, idx) + +def test_EnumDomainGroups(samr, dom_handle): + """test the samr_EnumDomainGroups interface""" + print "Testing samr_EnumDomainGroups" + groups = toArray(samr.EnumDomainGroups(dom_handle, 0, 0)) + print "Found %d groups" % len(groups) + for idx, group in groups: + print "\t%s\t(%d)" % (group, idx) + +def test_domain_ops(samr, dom_handle): + """test domain specific ops""" + test_EnumDomainUsers(samr, dom_handle) + test_EnumDomainGroups(samr, dom_handle) + +def test_EnumDomains(samr, handle): + """test the samr_EnumDomains interface""" + print "Testing samr_EnumDomains" + + domains = toArray(samr.EnumDomains(handle, 0, -1)) + print "Found %d domains" % len(domains) + for idx, domain in domains: + print "\t%s (%d)" % (domain, idx) + for idx, domain in domains: + print "Testing domain %s" % domain + sid = samr.LookupDomain(handle, domain) + dom_handle = test_OpenDomain(samr, handle, sid) + test_domain_ops(samr, dom_handle) + samr.Close(dom_handle) + +if len(sys.argv) != 2: + print "Usage: samr.js " + sys.exit(1) + +binding = sys.argv[1] + +print "Connecting to %s" % binding +try: + samr = samr.samr(binding) +except Exception, e: + print "Failed to connect to %s: %s" % (binding, e.message) + sys.exit(1) + +handle = test_Connect(samr) +test_EnumDomains(samr, handle) +samr.Close(handle) + +print "All OK" diff --git a/source4/scripting/python/examples/winreg.py b/source4/scripting/python/examples/winreg.py new file mode 100755 index 0000000000..19d39e56ab --- /dev/null +++ b/source4/scripting/python/examples/winreg.py @@ -0,0 +1,87 @@ +#!/usr/bin/python +# +# tool to manipulate a remote registry +# Copyright Andrew Tridgell 2005 +# Copyright Jelmer Vernooij 2007 +# Released under the GNU GPL v3 or later +# + +import sys + +# Find right directory when running from source tree +sys.path.insert(0, "bin/python") + +import winreg +import optparse +import samba.getopt as options + +parser = optparse.OptionParser("%s [path]" % sys.argv[0]) +sambaopts = options.SambaOptions(parser) +parser.add_option_group(sambaopts) +parser.add_option("--createkey", type="string", metavar="KEYNAME", + help="create a key") + +opts, args = parser.parse_args() + +if len(args) < 1: + parser.print_usage() + sys.exit(-1) + +binding = args[0] + +print "Connecting to " + binding +conn = winreg.winreg(binding, sambaopts.get_loadparm()) + +def list_values(key): + (num_values, max_valnamelen, max_valbufsize) = conn.QueryInfoKey(key, winreg.String())[4:8] + for i in range(num_values): + name = winreg.StringBuf() + name.size = max_valnamelen + (name, type, data, _, data_len) = conn.EnumValue(key, i, name, 0, "", max_valbufsize, 0) + print "\ttype=%-30s size=%4d '%s'" % type, len, name + if type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ): + print "\t\t'%s'" % data +# if (v.type == reg.REG_MULTI_SZ) { +# for (j in v.value) { +# printf("\t\t'%s'\n", v.value[j]) +# } +# } +# if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) { +# printf("\t\t0x%08x (%d)\n", v.value, v.value) +# } +# if (v.type == reg.REG_QWORD) { +# printf("\t\t0x%llx (%lld)\n", v.value, v.value) +# } + +def list_path(key, path): + count = 0 + (num_subkeys, max_subkeylen, max_subkeysize) = conn.QueryInfoKey(key, winreg.String())[1:4] + for i in range(num_subkeys): + name = winreg.StringBuf() + name.size = max_subkeysize + keyclass = winreg.StringBuf() + keyclass.size = max_subkeysize + (name, _, _) = conn.EnumKey(key, i, name, keyclass=keyclass, last_changed_time=None)[0] + subkey = conn.OpenKey(key, name, 0, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) + count += list_path(subkey, "%s\\%s" % (path, name)) + list_values(subkey) + return count + +if len(args) > 1: + root = args[1] +else: + root = "HKLM" + +if opts.createkey: + reg.create_key("HKLM\\SOFTWARE", opt.createkey) +else: + print "Listing registry tree '%s'" % root + try: + root_key = getattr(conn, "Open%s" % root)(None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) + except AttributeError: + print "Unknown root key name %s" % root + sys.exit(1) + count = list_path(root_key, root) + if count == 0: + print "No entries found" + sys.exit(1) -- cgit From 57f6663f3a029945fe7e799d4371131d9a20d306 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 17:52:58 +0200 Subject: Remove obsolete ejs winreg example. (This used to be commit f1a2d2bc00dac56080b2bd560074ec66d12a3129) --- source4/scripting/bin/winreg | 107 ------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100755 source4/scripting/bin/winreg diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg deleted file mode 100755 index 883c6d7ee3..0000000000 --- a/source4/scripting/bin/winreg +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/sh -exec smbscript "$0" ${1+"$@"} -/* - tool to manipulate a remote registry - Copyright Andrew Tridgell 2005 - Released under the GNU GPL version 3 or later -*/ - -var options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS", - "createkey=s"); -if (options == undefined) { - println("Failed to parse options"); - return -1; -} - -libinclude("base.js"); -libinclude("winreg.js"); - -if (options.ARGV.length < 1) { - println("Usage: winreg.js [path]"); - return -1; -} -var binding = options.ARGV[0]; -reg = winregObj(); - -print("Connecting to " + binding + "\n"); -status = reg.connect(binding); -if (status.is_ok != true) { - print("Failed to connect to " + binding + " - " + status.errstr + "\n"); - return -1; -} - -function list_values(path) { - var list = reg.enum_values(path); - var i; - if (list == undefined) { - return; - } - for (i=0;i 1) { - root = options.ARGV[1]; -} else { - root = ''; -} - -if (options.createkey) { - var ok = reg.create_key("HKLM\\SOFTWARE", options.createkey); - if (!ok) { - println("Failed to create key"); - } -} else { - printf("Listing registry tree '%s'\n", root); - var count = list_path(root); - if (count == 0) { - println("No entries found"); - return 1; - } -} -return 0; -- cgit From 58b1ab92a117cfcb311bdcb41fe563077ad39500 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 17:52:44 +0200 Subject: Fix import. (This used to be commit 17231443a0e3b0ebc4b75db3d721fe0b4e1170c6) --- source4/scripting/python/examples/winreg.py | 2 +- source4/web_server/swat/__init__.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 source4/web_server/swat/__init__.py diff --git a/source4/scripting/python/examples/winreg.py b/source4/scripting/python/examples/winreg.py index 19d39e56ab..80b48ecfd7 100755 --- a/source4/scripting/python/examples/winreg.py +++ b/source4/scripting/python/examples/winreg.py @@ -11,7 +11,7 @@ import sys # Find right directory when running from source tree sys.path.insert(0, "bin/python") -import winreg +from samba.dcerpc import winreg import optparse import samba.getopt as options diff --git a/source4/web_server/swat/__init__.py b/source4/web_server/swat/__init__.py new file mode 100644 index 0000000000..e0d85dbe2c --- /dev/null +++ b/source4/web_server/swat/__init__.py @@ -0,0 +1,27 @@ +#!/usr/bin/python + +# Unix SMB/CIFS implementation. +# Copyright © Jelmer Vernooij 2008 +# +# Implementation of SWAT that uses WSGI +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +def SWAT(environ, start_response): + status = '200 OK' + response_headers = [('Content-type','text/plain')] + start_response(status, response_headers) + return ['Hello world!\n'] + -- cgit From c5c1b3706af13fe729f435e7bf4ec1e73b719eef Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 May 2008 14:59:58 +1000 Subject: allow larger streams using the TDB backend (This used to be commit 8c0d756eb887477da867e069dbde3a7ad98d4ae0) --- source4/librpc/idl/xattr.idl | 3 ++- source4/ntvfs/posix/pvfs_streams.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/source4/librpc/idl/xattr.idl b/source4/librpc/idl/xattr.idl index 2010d51ce1..520341e6aa 100644 --- a/source4/librpc/idl/xattr.idl +++ b/source4/librpc/idl/xattr.idl @@ -86,7 +86,8 @@ interface xattr /* stream data is stored in attributes with the given prefix */ const char *XATTR_DOSSTREAM_PREFIX = "user.DosStream."; - const int XATTR_MAX_STREAM_SIZE = 0x4000; + const int XATTR_MAX_STREAM_SIZE = 0x4000; + const int XATTR_MAX_STREAM_SIZE_TDB = 0x100000; typedef struct { uint32 flags; diff --git a/source4/ntvfs/posix/pvfs_streams.c b/source4/ntvfs/posix/pvfs_streams.c index 3cd9952fd5..30d7ce2477 100644 --- a/source4/ntvfs/posix/pvfs_streams.c +++ b/source4/ntvfs/posix/pvfs_streams.c @@ -276,9 +276,12 @@ ssize_t pvfs_stream_write(struct pvfs_state *pvfs, if (count == 0) { return 0; } - if (offset > XATTR_MAX_STREAM_SIZE) { - errno = ENOSPC; - return -1; + + if (count+offset > XATTR_MAX_STREAM_SIZE) { + if (!pvfs->ea_db || count+offset > XATTR_MAX_STREAM_SIZE_TDB) { + errno = ENOSPC; + return -1; + } } /* we have to load the existing stream, then modify, then save */ @@ -332,7 +335,9 @@ NTSTATUS pvfs_stream_truncate(struct pvfs_state *pvfs, DATA_BLOB blob; if (length > XATTR_MAX_STREAM_SIZE) { - return NT_STATUS_DISK_FULL; + if (!pvfs->ea_db || length > XATTR_MAX_STREAM_SIZE_TDB) { + return NT_STATUS_DISK_FULL; + } } /* we have to load the existing stream, then modify, then save */ -- cgit From bf8d9e180e1e908e891e3755bbb70eab550f0638 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 May 2008 15:00:27 +1000 Subject: fill in reserved field on SMB2 flush (This used to be commit 400a3b39d5c151cf43e307af2fa702208d7cd472) --- source4/ntvfs/posix/pvfs_flush.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source4/ntvfs/posix/pvfs_flush.c b/source4/ntvfs/posix/pvfs_flush.c index 61e73cedba..6e09c1f34a 100644 --- a/source4/ntvfs/posix/pvfs_flush.c +++ b/source4/ntvfs/posix/pvfs_flush.c @@ -54,6 +54,7 @@ NTSTATUS pvfs_flush(struct ntvfs_module_context *ntvfs, return NT_STATUS_INVALID_HANDLE; } pvfs_flush_file(pvfs, f); + io->smb2.out.reserved = 0; return NT_STATUS_OK; case RAW_FLUSH_ALL: -- cgit From cf4899cf4cb3432384034211eaa57e8059c24afb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 May 2008 15:00:56 +1000 Subject: check use of mincnt past EOF in SMB (This used to be commit 763c9d344fa55da7a24c250d29542837c3ae3971) --- source4/torture/raw/read.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source4/torture/raw/read.c b/source4/torture/raw/read.c index c8420c279e..ada9b1f432 100644 --- a/source4/torture/raw/read.c +++ b/source4/torture/raw/read.c @@ -460,6 +460,23 @@ static bool test_readx(struct torture_context *tctx, struct smbcli_state *cli) CHECK_VALUE(io.readx.out.compaction_mode, 0); } + printf("Trying mincnt past EOF\n"); + memset(buf, 0, maxsize); + io.readx.in.offset = 0; + io.readx.in.mincnt = 100; + io.readx.in.maxcnt = 110; + status = smb_raw_read(cli->tree, &io); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(io.readx.out.remaining, 0xFFFF); + CHECK_VALUE(io.readx.out.compaction_mode, 0); + CHECK_VALUE(io.readx.out.nread, strlen(test_data)); + if (memcmp(buf, test_data, strlen(test_data)) != 0) { + ret = false; + printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf); + goto done; + } + + setup_buffer(buf, seed, maxsize); smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize); memset(buf, 0, maxsize); -- cgit From 2ad2bdda89c07c0b8ce754c3b0cd4664eefc697d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 May 2008 15:02:43 +1000 Subject: stricter checks for valid inputs in SMB2 open and lock (This used to be commit a7b5689a73adde59de28770aa3949660441291ea) --- source4/libcli/raw/interfaces.h | 1 + source4/libcli/raw/smb.h | 9 +++++++-- source4/ntvfs/ntvfs_generic.c | 18 ++++++++++++++++-- source4/ntvfs/posix/pvfs_open.c | 38 +++++++++++++++++++++++++++----------- source4/smb_server/smb/reply.c | 5 +++++ 5 files changed, 56 insertions(+), 15 deletions(-) diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index bae0e67b02..36d8c3abb0 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1919,6 +1919,7 @@ union smb_lock { #define SMB2_LOCK_FLAG_EXCLUSIVE 0x00000002 #define SMB2_LOCK_FLAG_UNLOCK 0x00000004 #define SMB2_LOCK_FLAG_FAIL_IMMEDIATELY 0x00000010 +#define SMB2_LOCK_FLAG_ALL_MASK 0x00000017 uint32_t flags; uint32_t reserved; } *locks; diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index 74869e8a45..5a92b99757 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -133,6 +133,7 @@ #define NTCREATEX_SHARE_ACCESS_READ 1 #define NTCREATEX_SHARE_ACCESS_WRITE 2 #define NTCREATEX_SHARE_ACCESS_DELETE 4 +#define NTCREATEX_SHARE_ACCESS_MASK 7 /* ntcreatex open_disposition field */ #define NTCREATEX_DISP_SUPERSEDE 0 /* supersede existing file (if it exists) */ @@ -154,14 +155,18 @@ #define NTCREATEX_OPTIONS_RANDOM_ACCESS 0x0800 #define NTCREATEX_OPTIONS_DELETE_ON_CLOSE 0x1000 #define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID 0x2000 -#define NTCREATEX_OPTIONS_UNKNOWN_400000 0x400000 - +#define NTCREATEX_OPTIONS_BACKUP_INTENT 0x4000 +#define NTCREATEX_OPTIONS_REPARSE_POINT 0x200000 +#define NTCREATEX_OPTIONS_UNKNOWN_400000 0x400000 /* create options these bits are for private use by backends, they are not valid on the wire */ #define NTCREATEX_OPTIONS_PRIVATE_MASK 0xFF000000 #define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x01000000 #define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x02000000 +#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK 0x00DFA188 + + /* ntcreatex impersonation field */ #define NTCREATEX_IMPERSONATION_ANONYMOUS 0 diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c index 62a1427405..9b4f235cde 100644 --- a/source4/ntvfs/ntvfs_generic.c +++ b/source4/ntvfs/ntvfs_generic.c @@ -522,6 +522,12 @@ NTSTATUS ntvfs_map_open(struct ntvfs_module_context *ntvfs, io2->generic.in.fname = io->smb2.in.fname; io2->generic.in.sec_desc = NULL; io2->generic.in.ea_list = NULL; + + /* we use a couple of bits of the create options internally */ + if (io2->generic.in.create_options & NTCREATEX_OPTIONS_PRIVATE_MASK) { + return NT_STATUS_INVALID_PARAMETER; + } + status = ntvfs->ops->open(ntvfs, req, io2); break; @@ -1031,6 +1037,9 @@ NTSTATUS ntvfs_map_lock(struct ntvfs_module_context *ntvfs, return NT_STATUS_NO_MEMORY; } for (i=0;ismb2.in.lock_count;i++) { + if (lck->smb2.in.locks[i].flags & ~SMB2_LOCK_FLAG_ALL_MASK) { + return NT_STATUS_INVALID_PARAMETER; + } if (lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_UNLOCK) { int j = lck2->generic.in.ulock_cnt; lck2->generic.in.ulock_cnt++; @@ -1277,10 +1286,15 @@ static NTSTATUS ntvfs_map_read_finish(struct ntvfs_module_context *ntvfs, rd->smb2.out.remaining = 0; rd->smb2.out.reserved = 0; if (NT_STATUS_IS_OK(status) && - rd->smb2.out.data.length == 0 && - rd->smb2.in.length != 0) { + rd->smb2.out.data.length == 0) { status = NT_STATUS_END_OF_FILE; } + /* SMB2 does honor the min_count field, SMB does not */ + if (NT_STATUS_IS_OK(status) && + rd->smb2.in.min_count > rd->smb2.out.data.length) { + rd->smb2.out.data.length = 0; + status = NT_STATUS_END_OF_FILE; + } break; default: return NT_STATUS_INVALID_LEVEL; diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 926c99d37e..59b42fe751 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -203,6 +203,13 @@ static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs, return NT_STATUS_NOT_A_DIRECTORY; } + /* found with gentest */ + if (io->ntcreatex.in.access_mask == SEC_FLAG_MAXIMUM_ALLOWED && + (io->ntcreatex.in.create_options & NTCREATEX_OPTIONS_DIRECTORY) && + (io->ntcreatex.in.create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) { + return NT_STATUS_INVALID_PARAMETER; + } + switch (io->generic.in.open_disposition) { case NTCREATEX_DISP_OPEN_IF: break; @@ -563,7 +570,7 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs, (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) { return NT_STATUS_CANNOT_DELETE; } - + status = pvfs_access_check_create(pvfs, req, name, &access_mask); NT_STATUS_NOT_OK_RETURN(status); @@ -1121,6 +1128,25 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, return ntvfs_map_open(ntvfs, req, io); } + create_options = io->generic.in.create_options; + share_access = io->generic.in.share_access; + access_mask = io->generic.in.access_mask; + + if (share_access & ~NTCREATEX_SHARE_ACCESS_MASK) { + return NT_STATUS_INVALID_PARAMETER; + } + + /* some create options are not supported */ + if (create_options & NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK) { + return NT_STATUS_NOT_SUPPORTED; + } + + /* other create options are not allowed */ + if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) && + !(access_mask & SEC_STD_DELETE)) { + return NT_STATUS_INVALID_PARAMETER; + } + /* resolve the cifs name to a posix name */ status = pvfs_resolve_name(pvfs, req, io->ntcreatex.in.fname, PVFS_RESOLVE_STREAMS, &name); @@ -1152,16 +1178,6 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, open doesn't match */ io->generic.in.file_attr &= ~FILE_ATTRIBUTE_DIRECTORY; - create_options = io->generic.in.create_options; - share_access = io->generic.in.share_access; - access_mask = io->generic.in.access_mask; - - /* certain create options are not allowed */ - if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) && - !(access_mask & SEC_STD_DELETE)) { - return NT_STATUS_INVALID_PARAMETER; - } - flags = 0; switch (io->generic.in.open_disposition) { diff --git a/source4/smb_server/smb/reply.c b/source4/smb_server/smb/reply.c index 40cad91062..d28f4b6072 100644 --- a/source4/smb_server/smb/reply.c +++ b/source4/smb_server/smb/reply.c @@ -2193,6 +2193,11 @@ void smbsrv_reply_ntcreate_and_X(struct smbsrv_request *req) io->ntcreatex.in.ea_list = NULL; io->ntcreatex.in.sec_desc = NULL; + /* we use a couple of bits of the create options internally */ + if (io->ntcreatex.in.create_options & NTCREATEX_OPTIONS_PRIVATE_MASK) { + return NT_STATUS_INVALID_PARAMETER; + } + /* we need a neater way to handle this alignment */ if ((req->flags2 & FLAGS2_UNICODE_STRINGS) && ucs2_align(req->in.buffer, req->in.data, STR_TERMINATE|STR_UNICODE)) { -- cgit From 98e72f574a9ce2a676bcb010e4e6ee2df39af4b6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 May 2008 15:03:51 +1000 Subject: remove temporary test code (This used to be commit 8995c2f12174ebacc4a6b0864b6583665494a14b) --- source4/torture/gentest_smb2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index 6546ba6768..46545699d0 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -1026,7 +1026,7 @@ static bool handler_create(int instance) /* mask out oplocks */ parm[0].in.oplock_level = 0; } - + GEN_COPY_PARM; GEN_CALL(smb2_create(tree, current_op.mem_ctx, &parm[i])); -- cgit From dce310ef4ec2eedb496e814cf341ad7caab821af Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 13:31:57 +0200 Subject: Remove evil hack which breaks Python bindings. (This used to be commit 1c179566cb39eb09e522dbce69230472a5d4e655) --- source4/lib/messaging/tests/bindings.py | 2 +- source4/libcli/nbt/nbtname.c | 21 +++++++++++++++++++++ source4/librpc/idl/nbt.idl | 18 ++++++------------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/source4/lib/messaging/tests/bindings.py b/source4/lib/messaging/tests/bindings.py index 3d58843799..c89538ddfa 100644 --- a/source4/lib/messaging/tests/bindings.py +++ b/source4/lib/messaging/tests/bindings.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # -from samba.irpc import Messaging +from samba.messaging import Messaging from unittest import TestCase class MessagingTests(TestCase): diff --git a/source4/libcli/nbt/nbtname.c b/source4/libcli/nbt/nbtname.c index 0d9073ccbb..97ae2e9d72 100644 --- a/source4/libcli/nbt/nbtname.c +++ b/source4/libcli/nbt/nbtname.c @@ -626,3 +626,24 @@ _PUBLIC_ void ndr_print_wrepl_nbt_name(struct ndr_print *ndr, const char *name, ndr_print_string(ndr, name, s); talloc_free(s); } + +_PUBLIC_ enum ndr_err_code ndr_push_nbt_res_rec(struct ndr_push *ndr, int ndr_flags, const struct nbt_res_rec *r) +{ + { + uint32_t _flags_save_STRUCT = ndr->flags; + ndr_set_flags(&ndr->flags, LIBNDR_PRINT_ARRAY_HEX); + if (ndr_flags & NDR_SCALARS) { + NDR_CHECK(ndr_push_align(ndr, 4)); + NDR_CHECK(ndr_push_nbt_name(ndr, NDR_SCALARS, &r->name)); + NDR_CHECK(ndr_push_nbt_qtype(ndr, NDR_SCALARS, r->rr_type)); + NDR_CHECK(ndr_push_nbt_qclass(ndr, NDR_SCALARS, r->rr_class)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->ttl)); + NDR_CHECK(ndr_push_set_switch_value(ndr, &r->rdata, ((((r->rr_type) == NBT_QTYPE_NETBIOS) && ((r->rdata).data.length == 2))?0:r->rr_type))); + NDR_CHECK(ndr_push_nbt_rdata(ndr, NDR_SCALARS, &r->rdata)); + } + if (ndr_flags & NDR_BUFFERS) { + } + ndr->flags = _flags_save_STRUCT; + } + return NDR_ERR_SUCCESS; +} diff --git a/source4/librpc/idl/nbt.idl b/source4/librpc/idl/nbt.idl index 783f04eb42..a6d0245455 100644 --- a/source4/librpc/idl/nbt.idl +++ b/source4/librpc/idl/nbt.idl @@ -73,11 +73,11 @@ interface nbt nbt_name_type type; } nbt_name; - typedef [enum16bit] enum { + typedef [public,enum16bit] enum { NBT_QCLASS_IP = 0x01 } nbt_qclass; - typedef [enum16bit] enum { + typedef [public,enum16bit] enum { NBT_QTYPE_ADDRESS = 0x0001, NBT_QTYPE_NAMESERVICE = 0x0002, NBT_QTYPE_NULL = 0x000A, @@ -160,30 +160,24 @@ interface nbt uint8 data[length]; } nbt_rdata_data; - typedef [nodiscriminant] union { + typedef [nodiscriminant,public] union { [case(NBT_QTYPE_NETBIOS)] nbt_rdata_netbios netbios; [case(NBT_QTYPE_STATUS)] nbt_rdata_status status; [default] nbt_rdata_data data; } nbt_rdata; /* - * this macro works arround the problem + * this macro works around the problem * that we need to use nbt_rdata_data * together with NBT_QTYPE_NETBIOS * for WACK replies */ -#define NBT_RES_REC_LEVEL(rr_type, rdata) (\ - (((rr_type) == NBT_QTYPE_NETBIOS) && \ - talloc_check_name(ndr, "struct ndr_push") && \ - ((rdata).data.length == 2)) \ - ? 0 : rr_type) - - typedef [flag(LIBNDR_PRINT_ARRAY_HEX)] struct { + typedef [flag(LIBNDR_PRINT_ARRAY_HEX),nopush] struct { nbt_name name; nbt_qtype rr_type; nbt_qclass rr_class; uint32 ttl; - [switch_is(NBT_RES_REC_LEVEL(rr_type, rdata))] nbt_rdata rdata; + [switch_is(rr_type)] nbt_rdata rdata; } nbt_res_rec; typedef [flag(NDR_NOALIGN|NDR_BIG_ENDIAN|NDR_PAHEX),public] struct { -- cgit From 9e37d25a92eaa7c65bb5d4822832fbf98a9504cb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 13:34:36 +0200 Subject: Remove unused scripts. (This used to be commit 3d22b72bb780065059f45ebeb6025d1bceb1f5b6) --- testprogs/ejs/argv.js | 14 -------------- testprogs/ejs/nbtstats | 33 --------------------------------- 2 files changed, 47 deletions(-) delete mode 100644 testprogs/ejs/argv.js delete mode 100755 testprogs/ejs/nbtstats diff --git a/testprogs/ejs/argv.js b/testprogs/ejs/argv.js deleted file mode 100644 index ffb6e007eb..0000000000 --- a/testprogs/ejs/argv.js +++ /dev/null @@ -1,14 +0,0 @@ -/* - demonstrate use of GetOptions -*/ - -var options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "myopt=s", - "intopt=i", - "noopt"); - -println("You called this script with arguments:"); - -printVars(options); diff --git a/testprogs/ejs/nbtstats b/testprogs/ejs/nbtstats deleted file mode 100755 index 1c8a6a5e7e..0000000000 --- a/testprogs/ejs/nbtstats +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env smbscript -/* - demonstrate access to irpc calls from ejs -*/ - -var options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA"); -if (options == undefined) { - println("Failed to parse options"); - return -1; -} - -var conn = new Object(); -var irpc = irpc_init(); - -status = irpc_connect(conn, "nbt_server"); -assert(status.is_ok == true); - -io = new Object(); -io.input = new Object(); -io.input.level = irpc.NBTD_INFO_STATISTICS; -status = irpc.nbtd_information(conn, io); -assert(status.is_ok == true); -assert(io.results.length == 1); - -print("nbt_server statistics:\n"); -stats = io.results[0].info.stats; - -for (r in stats) { - print("\t" + r + ":\t" + stats[r] + "\n"); -} -return 0; -- cgit From cbe439383a8f9322c3b0b51aca863cecd77cafcb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 13:36:05 +0200 Subject: remove unused credentials ejs module. (This used to be commit 9861cae1aebdef41f098df71be4e5a33f6af9bf1) --- source4/scripting/ejs/config.mk | 1 - source4/scripting/ejs/smbcalls.c | 1 - source4/scripting/ejs/smbcalls_creds.c | 275 --------------------------------- 3 files changed, 277 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_creds.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index c5199669d5..5022aba34d 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -71,7 +71,6 @@ PRIVATE_DEPENDENCIES = \ smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ smbcalls_options.o \ - smbcalls_creds.o \ smbcalls_param.o \ mprutil.o \ literal.o) diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index bdf70ca831..a90e1e62c8 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -204,7 +204,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) ejs_exception_handler = exception_handler; smb_setup_ejs_options(); - smb_setup_ejs_credentials(); smb_setup_ejs_param(); smb_setup_ejs_literal(); diff --git a/source4/scripting/ejs/smbcalls_creds.c b/source4/scripting/ejs/smbcalls_creds.c deleted file mode 100644 index fd73f0751f..0000000000 --- a/source4/scripting/ejs/smbcalls_creds.c +++ /dev/null @@ -1,275 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks credentials calls - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "lib/cmdline/popt_common.h" -#include "auth/credentials/credentials.h" - -/* - helper function to get the local objects credentials ptr -*/ -static struct cli_credentials *ejs_creds_get_credentials(int eid) -{ - struct cli_credentials *creds = (struct cli_credentials *)mprGetThisPtr(eid, "creds"); - if (creds == NULL) { - ejsSetErrorMsg(eid, "NULL ejs credentials"); - } - return creds; -} - -/* - get a domain -*/ -static int ejs_creds_get_domain(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - - mpr_Return(eid, mprString(cli_credentials_get_domain(creds))); - return 0; -} - - -/* - set a domain -*/ -static int ejs_creds_set_domain(MprVarHandle eid, int argc, char **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - if (argc != 1) { - ejsSetErrorMsg(eid, "bad arguments to set_domain"); - return -1; - } - - cli_credentials_set_domain(creds, argv[0], CRED_SPECIFIED); - mpr_Return(eid, mprCreateBoolVar(true)); - return 0; -} - - -/* - get a username -*/ -static int ejs_creds_get_username(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - - mpr_Return(eid, mprString(cli_credentials_get_username(creds))); - return 0; -} - - -/* - set a username -*/ -static int ejs_creds_set_username(MprVarHandle eid, int argc, char **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - if (argc != 1) { - ejsSetErrorMsg(eid, "bad arguments to set_username"); - return -1; - } - - cli_credentials_set_username(creds, argv[0], CRED_SPECIFIED); - mpr_Return(eid, mprCreateBoolVar(true)); - return 0; -} - - -/* - get user password -*/ -static int ejs_creds_get_password(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - - mpr_Return(eid, mprString(cli_credentials_get_password(creds))); - return 0; -} - - -/* - set user password -*/ -static int ejs_creds_set_password(MprVarHandle eid, int argc, char **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - if (argc != 1) { - ejsSetErrorMsg(eid, "bad arguments to set_password"); - return -1; - } - - cli_credentials_set_password(creds, argv[0], CRED_SPECIFIED); - mpr_Return(eid, mprCreateBoolVar(true)); - return 0; -} - - -/* - set realm -*/ -static int ejs_creds_set_realm(MprVarHandle eid, int argc, char **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - if (argc != 1) { - ejsSetErrorMsg(eid, "bad arguments to set_realm"); - return -1; - } - - cli_credentials_set_realm(creds, argv[0], CRED_SPECIFIED); - mpr_Return(eid, mprCreateBoolVar(true)); - return 0; -} - - -/* - get realm -*/ -static int ejs_creds_get_realm(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - - mpr_Return(eid, mprString(cli_credentials_get_realm(creds))); - return 0; -} - - -/* - set workstation -*/ -static int ejs_creds_set_workstation(MprVarHandle eid, int argc, char **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - if (argc != 1) { - ejsSetErrorMsg(eid, "bad arguments to set_workstation"); - return -1; - } - - cli_credentials_set_workstation(creds, argv[0], CRED_SPECIFIED); - mpr_Return(eid, mprCreateBoolVar(true)); - return 0; -} - - -/* - get workstation -*/ -static int ejs_creds_get_workstation(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - - mpr_Return(eid, mprString(cli_credentials_get_workstation(creds))); - return 0; -} - -/* - set machine account -*/ -static int ejs_creds_set_machine_account(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct cli_credentials *creds = ejs_creds_get_credentials(eid); - if (argc != 0) { - ejsSetErrorMsg(eid, "bad arguments to set_machine_account"); - return -1; - } - - if (NT_STATUS_IS_OK(cli_credentials_set_machine_account(creds, mprLpCtx()))) { - mpr_Return(eid, mprCreateBoolVar(true)); - } else { - mpr_Return(eid, mprCreateBoolVar(false)); - } - return 0; -} - - -/* - initialise credentials ejs object -*/ -static int ejs_credentials_obj(struct MprVar *obj, struct cli_credentials *creds) -{ - mprSetPtrChild(obj, "creds", creds); - - /* setup our object methods */ - mprSetCFunction(obj, "get_domain", ejs_creds_get_domain); - mprSetStringCFunction(obj, "set_domain", ejs_creds_set_domain); - mprSetCFunction(obj, "get_username", ejs_creds_get_username); - mprSetStringCFunction(obj, "set_username", ejs_creds_set_username); - mprSetCFunction(obj, "get_password", ejs_creds_get_password); - mprSetStringCFunction(obj, "set_password", ejs_creds_set_password); - mprSetCFunction(obj, "get_realm", ejs_creds_get_realm); - mprSetStringCFunction(obj, "set_realm", ejs_creds_set_realm); - mprSetCFunction(obj, "get_workstation", ejs_creds_get_workstation); - mprSetStringCFunction(obj, "set_workstation", ejs_creds_set_workstation); - mprSetCFunction(obj, "set_machine_account", ejs_creds_set_machine_account); - - return 0; -} - - -struct MprVar mprCredentials(struct cli_credentials *creds) -{ - struct MprVar mpv = mprObject("credentials"); - - ejs_credentials_obj(&mpv, creds); - - return mpv; -} - - -/* - initialise credentials ejs object -*/ -static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct cli_credentials *creds; - struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv); - - creds = cli_credentials_init(mprMemCtx()); - if (creds == NULL) { - return -1; - } - - cli_credentials_set_conf(creds, mprLpCtx()); - - return ejs_credentials_obj(obj, creds); -} - -/* - initialise cmdline credentials ejs object -*/ -int ejs_credentials_cmdline(int eid, int argc, struct MprVar **argv) -{ - struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv); - if (talloc_reference(mprMemCtx(), cmdline_credentials) == NULL) { - return -1; - } - return ejs_credentials_obj(obj, cmdline_credentials); -} - -/* - setup C functions that be called from ejs -*/ -void smb_setup_ejs_credentials(void) -{ - ejsDefineCFunction(-1, "credentials_init", ejs_credentials_init, NULL, MPR_VAR_SCRIPT_HANDLE); -} - -- cgit From ec362bdbc06a83d4b4656e5c3dde90c49adb2a64 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 13:40:17 +0200 Subject: Remove unused datablob and nbt ejs bindings. (This used to be commit f758553ac50d374f64a8763055dc4f12ab9b0c68) --- source4/scripting/ejs/config.mk | 14 -- source4/scripting/ejs/smbcalls.c | 1 - source4/scripting/ejs/smbcalls_data.c | 284 ---------------------------------- source4/scripting/ejs/smbcalls_nbt.c | 93 ----------- 4 files changed, 392 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_data.c delete mode 100644 source4/scripting/ejs/smbcalls_nbt.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 5022aba34d..d8068bebdd 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -13,13 +13,6 @@ PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR smbcalls_ldb_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_ldb.o -[MODULE::smbcalls_nbt] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_nbt - -smbcalls_nbt_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_nbt.o - [MODULE::smbcalls_rand] SUBSYSTEM = smbcalls OUTPUT_TYPE = MERGED_OBJ @@ -27,13 +20,6 @@ INIT_FUNCTION = smb_setup_ejs_random smbcalls_rand_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_rand.o -[MODULE::smbcalls_data] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_datablob - -smbcalls_data_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_data.o - [MODULE::smbcalls_auth] OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index a90e1e62c8..d17f048887 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -191,7 +191,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) extern NTSTATUS smb_setup_ejs_system(void); extern NTSTATUS smb_setup_ejs_ldb(void); extern NTSTATUS ejs_init_svcctl(void); - extern NTSTATUS smb_setup_ejs_nbt(void); extern NTSTATUS smb_setup_ejs_net(void); extern NTSTATUS ejs_init_srvsvc(void); extern NTSTATUS ejs_init_netlogon(void); diff --git a/source4/scripting/ejs/smbcalls_data.c b/source4/scripting/ejs/smbcalls_data.c deleted file mode 100644 index 19e1e173d6..0000000000 --- a/source4/scripting/ejs/smbcalls_data.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide access to data blobs - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/winreg.h" - -/* - create a data blob object from a ejs array of integers -*/ -static int ejs_blobFromArray(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *array, *v; - unsigned length, i; - DATA_BLOB blob; - - if (argc != 1) { - ejsSetErrorMsg(eid, "blobFromArray invalid arguments"); - return -1; - } - array = argv[0]; - - v = mprGetProperty(array, "length", NULL); - if (v == NULL) { - goto failed; - } - length = mprToInt(v); - - blob = data_blob_talloc(mprMemCtx(), NULL, length); - if (length != 0 && blob.data == NULL) { - goto failed; - } - - for (i=0;ilength;i++) { - mprAddArray(&array, i, mprCreateNumberVar(blob->data[i])); - } - mpr_Return(eid, array); - return 0; - -failed: - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; -} - - -/* - compare two data blobs -*/ -static int ejs_blobCompare(MprVarHandle eid, int argc, struct MprVar **argv) -{ - DATA_BLOB *blob1, *blob2; - bool ret = false; - - if (argc != 2) { - ejsSetErrorMsg(eid, "blobCompare invalid arguments"); - return -1; - } - - blob1 = mprToDataBlob(argv[0]); - blob2 = mprToDataBlob(argv[1]); - - if (blob1 == blob2) { - ret = true; - goto done; - } - if (blob1 == NULL || blob2 == NULL) { - ret = false; - goto done; - } - - if (blob1->length != blob2->length) { - ret = false; - goto done; - } - - if (memcmp(blob1->data, blob2->data, blob1->length) != 0) { - ret = false; - goto done; - } - ret = true; - -done: - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - - -/* - convert a blob in winreg format to a mpr variable - - usage: - v = data.regToVar(blob, type); -*/ -static int ejs_regToVar(MprVarHandle eid, int argc, struct MprVar **argv) -{ - DATA_BLOB *blob; - enum winreg_Type type; - struct MprVar v; - - if (argc != 2) { - ejsSetErrorMsg(eid, "regToVar invalid arguments"); - return -1; - } - - blob = mprToDataBlob(argv[0]); - type = mprToInt(argv[1]); - - if (blob == NULL) { - ejsSetErrorMsg(eid, "regToVar null data"); - return -1; - } - - switch (type) { - case REG_NONE: - v = mprCreateUndefinedVar(); - break; - - case REG_SZ: - case REG_EXPAND_SZ: { - char *s; - ssize_t len; - len = convert_string_talloc(mprMemCtx(), lp_iconv_convenience(mprLpCtx()), CH_UTF16, CH_UNIX, - blob->data, blob->length, (void **)&s); - if (len == -1) { - ejsSetErrorMsg(eid, "regToVar invalid REG_SZ string"); - return -1; - } - v = mprString(s); - talloc_free(s); - break; - } - - case REG_DWORD: { - if (blob->length != 4) { - ejsSetErrorMsg(eid, "regToVar invalid REG_DWORD length %ld", (long)blob->length); - return -1; - } - v = mprCreateNumberVar(IVAL(blob->data, 0)); - break; - } - - case REG_DWORD_BIG_ENDIAN: { - if (blob->length != 4) { - ejsSetErrorMsg(eid, "regToVar invalid REG_DWORD_BIG_ENDIAN length %ld", (long)blob->length); - return -1; - } - v = mprCreateNumberVar(RIVAL(blob->data, 0)); - break; - } - - case REG_QWORD: { - if (blob->length != 8) { - ejsSetErrorMsg(eid, "regToVar invalid REG_QWORD length %ld", (long)blob->length); - return -1; - } - v = mprCreateNumberVar(BVAL(blob->data, 0)); - break; - } - - case REG_MULTI_SZ: { - DATA_BLOB b = *blob; - const char **list = NULL; - while (b.length > 0) { - char *s; - ssize_t len; - size_t slen = utf16_len_n(b.data, b.length); - if (slen == 2 && b.length == 2 && SVAL(b.data, 0) == 0) { - break; - } - len = convert_string_talloc(mprMemCtx(), lp_iconv_convenience(mprLpCtx()), CH_UTF16, CH_UNIX, - b.data, slen, (void **)&s); - if (len == -1) { - ejsSetErrorMsg(eid, "regToVar invalid REG_MULTI_SZ string"); - return -1; - } - list = str_list_add(list, s); - talloc_free(s); - talloc_steal(mprMemCtx(), list); - b.data += slen; - b.length -= slen; - } - v = mprList("REG_MULTI_SZ", list); - talloc_free(list); - break; - } - - - case REG_FULL_RESOURCE_DESCRIPTOR: - case REG_RESOURCE_LIST: - case REG_BINARY: - case REG_RESOURCE_REQUIREMENTS_LIST: - case REG_LINK: - return ejs_blobToArray(eid, 1, argv); - - default: - ejsSetErrorMsg(eid, "regToVar invalid type %d", type); - return -1; - } - - mpr_Return(eid, v); - return 0; -} - -/* - initialise datablob ejs subsystem -*/ -static int ejs_datablob_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *obj = mprInitObject(eid, "datablob", argc, argv); - - mprSetCFunction(obj, "blobFromArray", ejs_blobFromArray); - mprSetCFunction(obj, "blobToArray", ejs_blobToArray); - mprSetCFunction(obj, "blobCompare", ejs_blobCompare); - mprSetCFunction(obj, "regToVar", ejs_regToVar); - - return 0; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_datablob(void) -{ - ejsDefineCFunction(-1, "datablob_init", ejs_datablob_init, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/smbcalls_nbt.c b/source4/scripting/ejs/smbcalls_nbt.c deleted file mode 100644 index 8c555bf821..0000000000 --- a/source4/scripting/ejs/smbcalls_nbt.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Tim Potter 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/nbt.h" -#include "lib/events/events.h" -#include "libcli/resolve/resolve.h" - -/* - look up a netbios name - - syntax: - resolveName(result, "frogurt"); - resolveName(result, "frogurt", 0x1c); -*/ - -static int ejs_resolve_name(MprVarHandle eid, int argc, struct MprVar **argv) -{ - int result = -1; - struct nbt_name name; - TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx()); - NTSTATUS nt_status; - const char *reply_addr; - - /* validate arguments */ - if (argc < 2 || argc > 3) { - ejsSetErrorMsg(eid, "resolveName invalid arguments"); - goto done; - } - - if (argv[0]->type != MPR_TYPE_OBJECT) { - ejsSetErrorMsg(eid, "resolvename invalid arguments"); - goto done; - } - - if (argv[1]->type != MPR_TYPE_STRING) { - ejsSetErrorMsg(eid, "resolveName invalid arguments"); - goto done; - } - - if (argc == 2) { - make_nbt_name_client(&name, mprToString(argv[1])); - } else { - if (!mprVarIsNumber(argv[1]->type)) { - ejsSetErrorMsg(eid, "resolveName invalid arguments"); - goto done; - } - make_nbt_name(&name, mprToString(argv[1]), mprToInt(argv[2])); - } - - result = 0; - - nt_status = resolve_name(lp_resolve_context(mprLpCtx()), &name, tmp_ctx, &reply_addr, mprEventCtx()); - - if (NT_STATUS_IS_OK(nt_status)) { - mprSetPropertyValue(argv[0], "value", mprString(reply_addr)); - } - - mpr_Return(eid, mprNTSTATUS(nt_status)); - - done: - talloc_free(tmp_ctx); - return result; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_nbt(void) -{ - ejsDefineCFunction(-1, "resolveName", ejs_resolve_name, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} -- cgit From 335688f640ed3f2b8a26dcf949b6175e2a95e802 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 13:43:54 +0200 Subject: Revert "remove unused credentials ejs module." This reverts commit 9861cae1aebdef41f098df71be4e5a33f6af9bf1. (This used to be commit a429dc730f97388f0b4478b44522b1fe53f8569a) --- source4/scripting/ejs/config.mk | 1 + source4/scripting/ejs/smbcalls.c | 1 + source4/scripting/ejs/smbcalls_creds.c | 275 +++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 source4/scripting/ejs/smbcalls_creds.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index d8068bebdd..540e55edb4 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -57,6 +57,7 @@ PRIVATE_DEPENDENCIES = \ smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ smbcalls_options.o \ + smbcalls_creds.o \ smbcalls_param.o \ mprutil.o \ literal.o) diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index d17f048887..880605bf10 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -203,6 +203,7 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) ejs_exception_handler = exception_handler; smb_setup_ejs_options(); + smb_setup_ejs_credentials(); smb_setup_ejs_param(); smb_setup_ejs_literal(); diff --git a/source4/scripting/ejs/smbcalls_creds.c b/source4/scripting/ejs/smbcalls_creds.c new file mode 100644 index 0000000000..fd73f0751f --- /dev/null +++ b/source4/scripting/ejs/smbcalls_creds.c @@ -0,0 +1,275 @@ +/* + Unix SMB/CIFS implementation. + + provide hooks credentials calls + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "scripting/ejs/smbcalls.h" +#include "lib/appweb/ejs/ejs.h" +#include "lib/cmdline/popt_common.h" +#include "auth/credentials/credentials.h" + +/* + helper function to get the local objects credentials ptr +*/ +static struct cli_credentials *ejs_creds_get_credentials(int eid) +{ + struct cli_credentials *creds = (struct cli_credentials *)mprGetThisPtr(eid, "creds"); + if (creds == NULL) { + ejsSetErrorMsg(eid, "NULL ejs credentials"); + } + return creds; +} + +/* + get a domain +*/ +static int ejs_creds_get_domain(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + + mpr_Return(eid, mprString(cli_credentials_get_domain(creds))); + return 0; +} + + +/* + set a domain +*/ +static int ejs_creds_set_domain(MprVarHandle eid, int argc, char **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + if (argc != 1) { + ejsSetErrorMsg(eid, "bad arguments to set_domain"); + return -1; + } + + cli_credentials_set_domain(creds, argv[0], CRED_SPECIFIED); + mpr_Return(eid, mprCreateBoolVar(true)); + return 0; +} + + +/* + get a username +*/ +static int ejs_creds_get_username(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + + mpr_Return(eid, mprString(cli_credentials_get_username(creds))); + return 0; +} + + +/* + set a username +*/ +static int ejs_creds_set_username(MprVarHandle eid, int argc, char **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + if (argc != 1) { + ejsSetErrorMsg(eid, "bad arguments to set_username"); + return -1; + } + + cli_credentials_set_username(creds, argv[0], CRED_SPECIFIED); + mpr_Return(eid, mprCreateBoolVar(true)); + return 0; +} + + +/* + get user password +*/ +static int ejs_creds_get_password(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + + mpr_Return(eid, mprString(cli_credentials_get_password(creds))); + return 0; +} + + +/* + set user password +*/ +static int ejs_creds_set_password(MprVarHandle eid, int argc, char **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + if (argc != 1) { + ejsSetErrorMsg(eid, "bad arguments to set_password"); + return -1; + } + + cli_credentials_set_password(creds, argv[0], CRED_SPECIFIED); + mpr_Return(eid, mprCreateBoolVar(true)); + return 0; +} + + +/* + set realm +*/ +static int ejs_creds_set_realm(MprVarHandle eid, int argc, char **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + if (argc != 1) { + ejsSetErrorMsg(eid, "bad arguments to set_realm"); + return -1; + } + + cli_credentials_set_realm(creds, argv[0], CRED_SPECIFIED); + mpr_Return(eid, mprCreateBoolVar(true)); + return 0; +} + + +/* + get realm +*/ +static int ejs_creds_get_realm(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + + mpr_Return(eid, mprString(cli_credentials_get_realm(creds))); + return 0; +} + + +/* + set workstation +*/ +static int ejs_creds_set_workstation(MprVarHandle eid, int argc, char **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + if (argc != 1) { + ejsSetErrorMsg(eid, "bad arguments to set_workstation"); + return -1; + } + + cli_credentials_set_workstation(creds, argv[0], CRED_SPECIFIED); + mpr_Return(eid, mprCreateBoolVar(true)); + return 0; +} + + +/* + get workstation +*/ +static int ejs_creds_get_workstation(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + + mpr_Return(eid, mprString(cli_credentials_get_workstation(creds))); + return 0; +} + +/* + set machine account +*/ +static int ejs_creds_set_machine_account(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct cli_credentials *creds = ejs_creds_get_credentials(eid); + if (argc != 0) { + ejsSetErrorMsg(eid, "bad arguments to set_machine_account"); + return -1; + } + + if (NT_STATUS_IS_OK(cli_credentials_set_machine_account(creds, mprLpCtx()))) { + mpr_Return(eid, mprCreateBoolVar(true)); + } else { + mpr_Return(eid, mprCreateBoolVar(false)); + } + return 0; +} + + +/* + initialise credentials ejs object +*/ +static int ejs_credentials_obj(struct MprVar *obj, struct cli_credentials *creds) +{ + mprSetPtrChild(obj, "creds", creds); + + /* setup our object methods */ + mprSetCFunction(obj, "get_domain", ejs_creds_get_domain); + mprSetStringCFunction(obj, "set_domain", ejs_creds_set_domain); + mprSetCFunction(obj, "get_username", ejs_creds_get_username); + mprSetStringCFunction(obj, "set_username", ejs_creds_set_username); + mprSetCFunction(obj, "get_password", ejs_creds_get_password); + mprSetStringCFunction(obj, "set_password", ejs_creds_set_password); + mprSetCFunction(obj, "get_realm", ejs_creds_get_realm); + mprSetStringCFunction(obj, "set_realm", ejs_creds_set_realm); + mprSetCFunction(obj, "get_workstation", ejs_creds_get_workstation); + mprSetStringCFunction(obj, "set_workstation", ejs_creds_set_workstation); + mprSetCFunction(obj, "set_machine_account", ejs_creds_set_machine_account); + + return 0; +} + + +struct MprVar mprCredentials(struct cli_credentials *creds) +{ + struct MprVar mpv = mprObject("credentials"); + + ejs_credentials_obj(&mpv, creds); + + return mpv; +} + + +/* + initialise credentials ejs object +*/ +static int ejs_credentials_init(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct cli_credentials *creds; + struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv); + + creds = cli_credentials_init(mprMemCtx()); + if (creds == NULL) { + return -1; + } + + cli_credentials_set_conf(creds, mprLpCtx()); + + return ejs_credentials_obj(obj, creds); +} + +/* + initialise cmdline credentials ejs object +*/ +int ejs_credentials_cmdline(int eid, int argc, struct MprVar **argv) +{ + struct MprVar *obj = mprInitObject(eid, "credentials", argc, argv); + if (talloc_reference(mprMemCtx(), cmdline_credentials) == NULL) { + return -1; + } + return ejs_credentials_obj(obj, cmdline_credentials); +} + +/* + setup C functions that be called from ejs +*/ +void smb_setup_ejs_credentials(void) +{ + ejsDefineCFunction(-1, "credentials_init", ejs_credentials_init, NULL, MPR_VAR_SCRIPT_HANDLE); +} + -- cgit From 4e9ca6caf913016292a3f7555bd91768d6f90efd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 14:00:28 +0200 Subject: Remove unused EJS net bindings. (This used to be commit 3923414849c5a3b14379e2cd3e61d862150800a6) --- source4/scripting/ejs/config.mk | 2 - source4/scripting/ejs/ejsnet/config.mk | 13 -- source4/scripting/ejs/ejsnet/mpr_host.c | 74 ------- source4/scripting/ejs/ejsnet/mpr_user.c | 173 --------------- source4/scripting/ejs/ejsnet/net_ctx.c | 230 -------------------- source4/scripting/ejs/ejsnet/net_host.c | 124 ----------- source4/scripting/ejs/ejsnet/net_user.c | 359 -------------------------------- source4/selftest/samba4_tests.sh | 1 - testprogs/ejs/ejsnet.js | 46 ---- testprogs/ejs/ejsnet/nethost.js | 45 ---- testprogs/ejs/ejsnet/netusr.js | 86 -------- 11 files changed, 1153 deletions(-) delete mode 100644 source4/scripting/ejs/ejsnet/config.mk delete mode 100644 source4/scripting/ejs/ejsnet/mpr_host.c delete mode 100644 source4/scripting/ejs/ejsnet/mpr_user.c delete mode 100644 source4/scripting/ejs/ejsnet/net_ctx.c delete mode 100644 source4/scripting/ejs/ejsnet/net_host.c delete mode 100644 source4/scripting/ejs/ejsnet/net_user.c delete mode 100755 testprogs/ejs/ejsnet.js delete mode 100644 testprogs/ejs/ejsnet/nethost.js delete mode 100644 testprogs/ejs/ejsnet/netusr.js diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 540e55edb4..9aad9c1566 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -44,8 +44,6 @@ INIT_FUNCTION = smb_setup_ejs_system smbcalls_sys_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_sys.o -mkinclude ejsnet/config.mk - [SUBSYSTEM::smbcalls] PRIVATE_DEPENDENCIES = \ EJS LIBSAMBA-UTIL \ diff --git a/source4/scripting/ejs/ejsnet/config.mk b/source4/scripting/ejs/ejsnet/config.mk deleted file mode 100644 index 710221e37d..0000000000 --- a/source4/scripting/ejs/ejsnet/config.mk +++ /dev/null @@ -1,13 +0,0 @@ -[MODULE::smbcalls_net] -SUBSYSTEM = smbcalls -INIT_FUNCTION = smb_setup_ejs_net -PRIVATE_DEPENDENCIES = LIBSAMBA-NET LIBCLI_SMB CREDENTIALS - -smbcalls_net_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/ejsnet/, \ - net_ctx.o \ - net_user.o \ - mpr_user.o \ - net_host.o \ - mpr_host.o) - -$(eval $(call proto_header_template,$(ejsscriptsrcdir)/ejsnet/proto.h,$(smbcalls_net_OBJ_FILES:.o=.c))) diff --git a/source4/scripting/ejs/ejsnet/mpr_host.c b/source4/scripting/ejs/ejsnet/mpr_host.c deleted file mode 100644 index 8258ea5256..0000000000 --- a/source4/scripting/ejs/ejsnet/mpr_host.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -/* - Properties: - DomainsList.Domains[0] - DomainsList.Status -*/ -struct MprVar mprDomainsList(TALLOC_CTX *mem_ctx, struct libnet_DomainList *list, NTSTATUS result) -{ - const char *name = "DomainsList"; - NTSTATUS status; - struct MprVar mprDomainList, mprDomains; - struct MprVar mprSid, mprDomainName; - struct MprVar mprDomain; - int i; - - if (list == NULL || mem_ctx == NULL) { - mprDomainList = mprCreateNullVar(); - goto done; - } - - mprDomains = mprArray("Domains"); - for (i = 0; i < list->out.count; i++) { - struct domainlist d = list->out.domains[i]; - - /* get domainlist fields */ - mprSid = mprString(d.sid); - mprDomainName = mprString(d.name); - - mprDomain = mprObject("Domain"); - mprSetVar(&mprDomain, "Name", mprDomainName); - mprSetVar(&mprDomain, "SID", mprSid); - - mprAddArray(&mprDomains, i, mprDomain); - } - - mprDomainList = mprObject(name); - status = mprSetVar(&mprDomainList, "Domains", mprDomains); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprDomainList, "Count", mprCreateIntegerVar(list->out.count)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprDomainList, "Status", mprNTSTATUS(result)); - -done: - return mprDomainList; -} diff --git a/source4/scripting/ejs/ejsnet/mpr_user.c b/source4/scripting/ejs/ejsnet/mpr_user.c deleted file mode 100644 index 6691a0f955..0000000000 --- a/source4/scripting/ejs/ejsnet/mpr_user.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -/* - Properties: - UserInfo.AccountName - UserInfo.FullName - UserInfo.Description - UserInfo.HomeDirectory - UserInfo.HomeDrive - UserInfo.Comment - UserInfo.LogonScript - UserInfo.AcctExpiry - UserInfo.AllowPasswordChange - UserInfo.ForcePasswordChange - */ -struct MprVar mprCreateUserInfo(TALLOC_CTX *mem_ctx, struct libnet_UserInfo *info) -{ - const char *name = "UserInfo"; - NTSTATUS status; - struct MprVar mprUserInfo; - struct MprVar mprAccountName, mprFullName, mprDescription; - struct MprVar mprHomeDir, mprHomeDrive, mprComment; - struct MprVar mprLogonScript; - struct MprVar mprAcctExpiry, mprAllowPassChange, mprForcePassChange; - - if (info == NULL || mem_ctx == NULL) { - mprUserInfo = mprCreateNullVar(); - goto done; - } - - mprUserInfo = mprObject(name); - - mprAccountName = mprString(info->out.account_name); - mprFullName = mprString(info->out.full_name); - mprDescription = mprString(info->out.description); - mprHomeDir = mprString(info->out.home_directory); - mprHomeDrive = mprString(info->out.home_drive); - mprComment = mprString(info->out.comment); - mprLogonScript = mprString(info->out.logon_script); - mprAcctExpiry = mprString(timestring(mem_ctx, info->out.acct_expiry->tv_sec)); - mprAllowPassChange = mprString(timestring(mem_ctx, info->out.allow_password_change->tv_sec)); - mprForcePassChange = mprString(timestring(mem_ctx, info->out.force_password_change->tv_sec)); - - status = mprSetVar(&mprUserInfo, "AccountName", mprAccountName); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "FullName", mprFullName); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "Description", mprDescription); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "HomeDirectory", mprHomeDir); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "HomeDrive", mprHomeDrive); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "Comment", mprComment); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "LogonScript", mprLogonScript); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "AcctExpiry", mprAcctExpiry); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "AllowPasswordChange", mprAllowPassChange); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprUserInfo, "ForcePasswordChange", mprForcePassChange); - if (!NT_STATUS_IS_OK(status)) goto done; - -done: - return mprUserInfo; -} - - -/* - Properties: - UserListCtx.Users[] - UserListCtx.ResumeIndex - UserListCtx.Count - UserListCtx.EndOfList - UserListCtx.Status - */ -struct MprVar mprUserListCtx(TALLOC_CTX *mem_ctx, struct libnet_UserList *list, NTSTATUS result) -{ - const char *name = "UserListCtx"; - NTSTATUS status; - bool endOfList; - struct MprVar mprListCtx, mprUserList; - struct MprVar mprUser, mprSid, mprUsername; - int i; - - if (list == NULL || mem_ctx == NULL) { - mprListCtx = mprCreateNullVar(); - goto done; - } - - endOfList = (NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) || - NT_STATUS_IS_OK(result)); - - mprUserList = mprArray("Users"); - for (i = 0; i < list->out.count; i++) { - struct userlist u = list->out.users[i]; - - /* get userlist fields */ - mprSid = mprString(u.sid); - mprUsername = mprString(u.username); - - /* create userlist object */ - mprUser = mprObject("User"); - mprSetVar(&mprUser, "Username", mprUsername); - mprSetVar(&mprUser, "SID", mprSid); - - /* add the object to the array being constructed */ - mprAddArray(&mprUserList, i, mprUser); - } - - mprListCtx = mprObject(name); - status = mprSetVar(&mprListCtx, "Users", mprUserList); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "Count", mprCreateIntegerVar(list->out.count)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "ResumeIndex", mprCreateIntegerVar((int)list->out.resume_index)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "EndOfList", mprCreateBoolVar(endOfList)); - if (!NT_STATUS_IS_OK(status)) goto done; - status = mprSetVar(&mprListCtx, "Status", mprNTSTATUS(result)); - -done: - return mprListCtx; -} - - -/* - Returns UserListCtx.ResumeIndex out of passed UserListCtx - */ -unsigned int mprListGetResumeIndex(struct MprVar *listCtx) -{ - NTSTATUS status; - unsigned int resume = 0; - struct MprVar *mprResumeIndex; - if (listCtx == NULL) return 0; - - mprResumeIndex = listCtx; - status = mprGetVar(&mprResumeIndex, "ResumeIndex"); - if (!NT_STATUS_IS_OK(status)) goto done; - - resume = (unsigned int) mprVarToInteger(mprResumeIndex); - -done: - return resume; -} diff --git a/source4/scripting/ejs/ejsnet/net_ctx.c b/source4/scripting/ejs/ejsnet/net_ctx.c deleted file mode 100644 index cbe163552e..0000000000 --- a/source4/scripting/ejs/ejsnet/net_ctx.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "scripting/ejs/smbcalls.h" -#include "libnet/libnet.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar** argv); -int ejs_net_hostman(MprVarHandle eid, int argc, struct MprVar** argv); - -static int ejs_net_join_domain(MprVarHandle eid, int argc, struct MprVar **argv); -static int ejs_net_samsync_ldb(MprVarHandle eid, int argc, struct MprVar **argv); - -/* - Usage: - net = NetContext(credentials); -*/ - -static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *event_mem_ctx = talloc_new(mprMemCtx()); - struct cli_credentials *creds; - struct libnet_context *ctx; - struct MprVar obj, mprCreds; - struct event_context *ev; - - if (!event_mem_ctx) { - ejsSetErrorMsg(eid, "talloc_new() failed"); - return -1; - } - ev = mprEventCtx(); - - ctx = libnet_context_init(ev, mprLpCtx()); - /* IF we generated a new event context, it will be under here, - * and we need it to last as long as the libnet context, so - * make it a child */ - talloc_steal(ctx, event_mem_ctx); - - if (argc == 0 || (argc == 1 && argv[0]->type == MPR_TYPE_NULL)) { - /* - create the default credentials - */ - creds = cli_credentials_init(ctx); - if (creds == NULL) { - ejsSetErrorMsg(eid, "cli_credential_init() failed"); - talloc_free(ctx); - return -1; - } - cli_credentials_set_conf(creds, mprLpCtx()); - cli_credentials_set_anonymous(creds); - - mprCreds = mprCredentials(creds); - - } else if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) { - /* - get credential values from credentials object - */ - mprCreds = *(argv[0]); - creds = (struct cli_credentials *)mprGetPtr(&mprCreds, "creds"); - if (creds == NULL) { - ejsSetErrorMsg(eid, "invalid credentials parameter"); - talloc_free(ctx); - return -1; - } - - } else { - ejsSetErrorMsg(eid, "NetContext invalid arguments, this function requires an object."); - talloc_free(ctx); - return -1; - } - - /* setup libnet_context credentials */ - ctx->cred = creds; - - /* create the NetContext object */ - obj = mprObject("NetContext"); - - /* add internal libnet_context pointer to the NetContext object */ - mprSetPtrChild(&obj, "ctx", ctx); - - /* add properties publicly available from js code */ - mprCreateProperty(&obj, "credentials", &mprCreds); - - /* add methods to the object */ - mprSetCFunction(&obj, "UserMgr", ejs_net_userman); - mprSetCFunction(&obj, "HostMgr", ejs_net_hostman); - mprSetCFunction(&obj, "JoinDomain", ejs_net_join_domain); - mprSetCFunction(&obj, "SamSyncLdb", ejs_net_samsync_ldb); - - /* return the object */ - mpr_Return(eid, obj); - - return 0; -} - - -static int ejs_net_join_domain(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - struct libnet_Join *join; - NTSTATUS status; - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - mem_ctx = talloc_new(mprMemCtx()); - - join = talloc(mem_ctx, struct libnet_Join); - if (!join) { - talloc_free(mem_ctx); - return -1; - } - - /* prepare parameters for the join */ - join->in.netbios_name = NULL; - join->in.join_type = SEC_CHAN_WKSTA; - join->in.domain_name = cli_credentials_get_domain(ctx->cred); - join->in.level = LIBNET_JOIN_AUTOMATIC; - join->out.error_string = NULL; - - if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) { - MprVar *netbios_name = mprGetProperty(argv[0], "netbios_name", NULL); - MprVar *domain_name = mprGetProperty(argv[0], "domain_name", NULL); - MprVar *join_type = mprGetProperty(argv[0], "join_type", NULL); - if (netbios_name) { - join->in.netbios_name = mprToString(netbios_name); - } - if (domain_name) { - join->in.domain_name = mprToString(domain_name); - } - if (join_type) { - join->in.join_type = mprToInt(join_type); - } - } - - if (!join->in.domain_name) { - ejsSetErrorMsg(eid, "a domain must be specified for to join"); - talloc_free(mem_ctx); - return -1; - } - - /* do the domain join */ - status = libnet_Join(ctx, join, join); - - if (!NT_STATUS_IS_OK(status)) { - MprVar error_string = mprString(join->out.error_string); - - mprSetPropertyValue(argv[0], "error_string", error_string); - mpr_Return(eid, mprCreateBoolVar(false)); - } else { - mpr_Return(eid, mprCreateBoolVar(true)); - } - talloc_free(mem_ctx); - return 0; -} - - -static int ejs_net_samsync_ldb(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - struct libnet_samsync_ldb *samsync; - NTSTATUS status; - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - mem_ctx = talloc_new(mprMemCtx()); - - samsync = talloc(mem_ctx, struct libnet_samsync_ldb); - if (!samsync) { - talloc_free(mem_ctx); - return -1; - } - - /* prepare parameters for the samsync */ - samsync->in.machine_account = NULL; - samsync->in.session_info = NULL; - samsync->in.binding_string = NULL; - samsync->out.error_string = NULL; - - if (argc == 1 && argv[0]->type == MPR_TYPE_OBJECT) { - MprVar *credentials = mprGetProperty(argv[0], "machine_account", NULL); - MprVar *session_info = mprGetProperty(argv[0], "session_info", NULL); - if (credentials) { - samsync->in.machine_account = talloc_get_type(mprGetPtr(credentials, "creds"), struct cli_credentials); - } - if (session_info) { - samsync->in.session_info = talloc_get_type(mprGetPtr(session_info, "session_info"), struct auth_session_info); - } - } - - /* do the domain samsync */ - status = libnet_samsync_ldb(ctx, samsync, samsync); - - if (!NT_STATUS_IS_OK(status)) { - MprVar error_string = mprString(samsync->out.error_string); - - mprSetPropertyValue(argv[0], "error_string", error_string); - mpr_Return(eid, mprCreateBoolVar(false)); - } else { - mpr_Return(eid, mprCreateBoolVar(true)); - } - talloc_free(mem_ctx); - return 0; -} - - -NTSTATUS smb_setup_ejs_net(void) -{ - ejsDefineCFunction(-1, "NetContext", ejs_net_context, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/ejsnet/net_host.c b/source4/scripting/ejs/ejsnet/net_host.c deleted file mode 100644 index 478da19db3..0000000000 --- a/source4/scripting/ejs/ejsnet/net_host.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/ejsnet/proto.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv); - - -/* - Usage: - hostCtx = net.HostMgr(hostname = ) -*/ -int ejs_net_hostman(MprVarHandle eid, int argc, struct MprVar** argv) -{ - struct libnet_context *ctx; - const char *hostname; - struct MprVar obj; - - /* libnet context */ - ctx = mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - return 0; - } - - /* fetch the arguments: host name */ - if (argc == 0) { - /* default host (machine) name is supplied in credentials */ - hostname = cli_credentials_get_workstation(ctx->cred); - - } else if (argc == 1 && mprVarIsString(argv[0]->type)) { - /* host name has been specified */ - hostname = mprToString(argv[0]); - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - return 0; - } - - /* create the NetHostCtx object */ - obj = mprObject("NetHostCtx"); - - /* create a copy of the string for the object */ - hostname = talloc_strdup(ctx, hostname); - - /* add internal libnet_context pointer to the NetHostCtx object */ - mprSetPtrChild(&obj, "ctx", ctx); - mprSetPtrChild(&obj, "hostname", hostname); - - /* add methods to the object */ - mprSetStringCFunction(&obj, "DomainList", ejs_net_domainlist); - - /* set the object returned by this function */ - mpr_Return(eid, obj); - - return 0; -} - - -static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status; - TALLOC_CTX *mem_ctx; - const char* hostname; - struct libnet_context *ctx; - struct libnet_DomainList req; - struct MprVar mprDomains; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* libnet context */ - ctx = mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - hostname = mprGetThisPtr(eid, "hostname"); - if (hostname == NULL) { - ejsSetErrorMsg(eid, "hostname property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.hostname = hostname; - - status = libnet_DomainList(ctx, mem_ctx, &req); - mprDomains = mprDomainsList(mem_ctx, &req, status); - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprDomains); - return 0; -} diff --git a/source4/scripting/ejs/ejsnet/net_user.c b/source4/scripting/ejs/ejsnet/net_user.c deleted file mode 100644 index 0c32035c6c..0000000000 --- a/source4/scripting/ejs/ejsnet/net_user.c +++ /dev/null @@ -1,359 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provides interfaces to libnet calls from ejs scripts - - Copyright (C) Rafal Szczesniak 2005-2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "libnet/libnet.h" -#include "scripting/ejs/ejsnet/proto.h" -#include "scripting/ejs/smbcalls.h" -#include "events/events.h" -#include "auth/credentials/credentials.h" - - -static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv); -static int ejs_net_deleteuser(MprVarHandle eid, int argc, char **argv); -static int ejs_net_userinfo(MprVarHandle eid, int argc, char **argv); -static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv); - - -/* - Usage: - usrCtx = net.UserMgr(domain = ); -*/ -int ejs_net_userman(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct libnet_context *ctx; - const char *userman_domain = NULL; - struct MprVar obj; - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - return 0; - } - - /* fetch the arguments: domain name */ - if (argc == 0) { - /* default domain name is supplied in credentials */ - userman_domain = cli_credentials_get_domain(ctx->cred); - - } else if (argc == 1 && mprVarIsString(argv[0]->type)) { - /* domain name can also be specified explicitly - (e.g. to connect BUILTIN domain) */ - userman_domain = mprToString(argv[0]); - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - return 0; - } - - /* any domain name must be specified anyway */ - if (userman_domain == NULL) { - ejsSetErrorMsg(eid, "a domain must be specified for user management"); - return 0; - } - - /* create 'net user' subcontext */ - obj = mprObject("NetUsrCtx"); - - /* we need to make a copy of the string for this object */ - userman_domain = talloc_strdup(ctx, userman_domain); - - /* add properties */ - mprSetPtrChild(&obj, "ctx", ctx); - mprSetPtrChild(&obj, "domain", userman_domain); - - /* add methods */ - mprSetStringCFunction(&obj, "Create", ejs_net_createuser); - mprSetStringCFunction(&obj, "Delete", ejs_net_deleteuser); - mprSetStringCFunction(&obj, "Info", ejs_net_userinfo); - mprSetCFunction(&obj, "List", ejs_net_userlist); - - /* set the object returned by this function */ - mpr_Return(eid, obj); - - return 0; -} - - -/* - Usage: - NTSTATUS = NetUsrCtx.Create(Username) -*/ -static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status = NT_STATUS_UNSUCCESSFUL; - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - const char *userman_domain = NULL; - const char *username = NULL; - struct libnet_CreateUser req; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments: username */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - username = argv[0]; - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where the account is to be created */ - userman_domain = (const char *)mprGetThisPtr(eid, "domain"); - if (userman_domain == NULL) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.domain_name = userman_domain; - req.in.user_name = argv[0]; - - status = libnet_CreateUser(ctx, mem_ctx, &req); - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "%s", req.out.error_string); - } - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - Usage: - NTSTATUS = NetUsrCtx.Delete(Username) -*/ -static int ejs_net_deleteuser(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status = NT_STATUS_UNSUCCESSFUL; - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - const char *userman_domain = NULL; - const char *username = NULL; - struct libnet_DeleteUser req; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments: username */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - username = argv[0]; - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where the account is to be deleted */ - userman_domain = mprGetThisPtr(eid, "domain"); - if (!userman_domain) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.domain_name = userman_domain; - req.in.user_name = username; - - status = libnet_DeleteUser(ctx, mem_ctx, &req); - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "%s", req.out.error_string); - } - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - Usage: - UserInfo = NetUsrCtx.Info(Username) -*/ -static int ejs_net_userinfo(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status = NT_STATUS_UNSUCCESSFUL; - TALLOC_CTX *mem_ctx; - struct libnet_context *ctx; - const char *userman_domain = NULL; - const char *username = NULL; - struct libnet_UserInfo req; - struct MprVar mprUserInfo; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments: username */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - username = argv[0]; - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where the user account is to be queried */ - userman_domain = mprGetThisPtr(eid, "domain"); - if (userman_domain == NULL) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - return -1; - } - - /* call the libnet function */ - req.in.domain_name = userman_domain; - req.in.data.user_name = username; - req.in.level = USER_INFO_BY_NAME; - - status = libnet_UserInfo(ctx, mem_ctx, &req); - if (!NT_STATUS_IS_OK(status)) { - ejsSetErrorMsg(eid, "%s", req.out.error_string); - - /* create null object to return */ - mprUserInfo = mprCreateNullVar(); - goto done; - } - - /* create UserInfo object */ - mprUserInfo = mprCreateUserInfo(ctx, &req); - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprUserInfo); - return 0; -} - - -/* - Usage: - UserListCtx = NetUsrCtx.List(UserListCtx) -*/ -static int ejs_net_userlist(MprVarHandle eid, int argc, struct MprVar **argv) -{ - TALLOC_CTX *mem_ctx; - NTSTATUS status; - struct libnet_context *ctx; - const char *userlist_domain; - int page_size = 512; /* TODO: this should be specified in a nicer way */ - struct libnet_UserList req; - struct MprVar mprListCtx, *mprInListCtx; - - mem_ctx = talloc_new(mprMemCtx()); - if (mem_ctx == NULL) { - ejsSetErrorMsg(eid, "could not create memory context - out of memory"); - goto done; - } - - /* fetch the arguments */ - if (argc == 0) { - ejsSetErrorMsg(eid, "too little arguments"); - goto done; - - } else if (argc == 1) { - if (mprVarIsObject(argv[0]->type)) { - /* this is a continuation call */ - mprInListCtx = argv[0]; - req.in.resume_index = mprListGetResumeIndex(mprInListCtx); - - } else { - /* this is a first call */ - req.in.resume_index = 0; - } - - } else { - ejsSetErrorMsg(eid, "too many arguments"); - goto done; - } - - /* libnet context */ - ctx = (struct libnet_context *)mprGetThisPtr(eid, "ctx"); - if (ctx == NULL) { - ejsSetErrorMsg(eid, "ctx property returns null pointer"); - goto done; - } - - /* domain where user accounts are to be enumerated */ - userlist_domain = mprGetThisPtr(eid, "domain"); - if (userlist_domain == NULL) { - ejsSetErrorMsg(eid, "domain property returns null pointer"); - goto done; - } - - /* call the libnet function */ - req.in.domain_name = userlist_domain; - req.in.page_size = page_size; - - status = libnet_UserList(ctx, mem_ctx, &req); - mprListCtx = mprUserListCtx(mem_ctx, &req, status); - -done: - talloc_free(mem_ctx); - mpr_Return(eid, mprListCtx); - return 0; -} diff --git a/source4/selftest/samba4_tests.sh b/source4/selftest/samba4_tests.sh index 11d909a2bc..1771a0da5c 100755 --- a/source4/selftest/samba4_tests.sh +++ b/source4/selftest/samba4_tests.sh @@ -64,7 +64,6 @@ SCRIPTDIR=$samba4srcdir/../testprogs/ejs smb4torture="$samba4bindir/smbtorture $TORTURE_OPTIONS" plantest "js.base" dc "$SCRIPTDIR/base.js" $CONFIGURATION -#plantest "ejsnet.js" dc "$SCRIPTDIR/ejsnet.js" $CONFIGURATION -U\$USERNAME%\$PASSWORD \$DOMAIN ejstestuser plantest "js.ldb" none "$SCRIPTDIR/ldb.js" `pwd` $CONFIGURATION -d 10 plantest "js.winreg" dc $samba4srcdir/scripting/bin/winreg $CONFIGURATION ncalrpc: 'HKLM' -U\$USERNAME%\$PASSWORD diff --git a/testprogs/ejs/ejsnet.js b/testprogs/ejs/ejsnet.js deleted file mode 100755 index a5570de34c..0000000000 --- a/testprogs/ejs/ejsnet.js +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env smbscript - -libinclude("base.js"); - -/* note: these require specifying a proper path in "js include" parameter */ -libinclude("ejsnet/netusr.js"); -libinclude("ejsnet/nethost.js"); - -function PrintNetHelp() -{ - println("Usage: ejsnet.js [options]"); -} - -/* here we start */ - -var options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS"); -if (options == undefined) { - PrintNetHelp(); - return -1; -} - -if (options.ARGV.length < 1) { - PrintNetHelp(); - return -1; -} - -/* use command line creds if available */ -var creds = options.get_credentials(); -var ctx = NetContext(creds); - -var cmd = options.ARGV[0]; -if (cmd == "user") { - UserManager(ctx, options); - -} else if (cmd == "host") { - HostManager(ctx, options); - -} else { - PrintNetHelp(); - return -1; -} - -return 0; diff --git a/testprogs/ejs/ejsnet/nethost.js b/testprogs/ejs/ejsnet/nethost.js deleted file mode 100644 index 9e11ae89c5..0000000000 --- a/testprogs/ejs/ejsnet/nethost.js +++ /dev/null @@ -1,45 +0,0 @@ -function PrintNetHostHelp() -{ - println("Host management - available commands:"); - println("\t domainlist - list users in specified domain"); -} - - -function ListDomains(hostCtx) -{ - var domain; - - var list = hostCtx.DomainList(); - if (list == undefined) { - println("Error when listing domains"); - return -1; - } - - for (var i = 0; i < list.Count; i++) { - domain = list.Domains[i]; - printf("%s\n", domain.Name); - } - - printf("\nResult: %s\n", list.Status.errstr); -} - - -function HostManager(ctx, options) -{ - var hostCtx; - - if (options.ARGV.length < 2) { - PrintNetHostHelp(); - return -1; - } - - var hostCmd = options.ARGV[1]; - - if (hostCmd == "domainlist") { - hostCtx = ctx.HostMgr(); - ListDomains(hostCtx); - - } else { - println("unknown command"); - } -} diff --git a/testprogs/ejs/ejsnet/netusr.js b/testprogs/ejs/ejsnet/netusr.js deleted file mode 100644 index da6e851ce7..0000000000 --- a/testprogs/ejs/ejsnet/netusr.js +++ /dev/null @@ -1,86 +0,0 @@ -function PrintNetUsrHelp(options) -{ - println("User management - available commands:"); - println("\t list - list users in specified domain"); - println("\t info - display user account information"); -} - - -function ListUsers(usrCtx) -{ - var list, user; - var finished = false; - - for (list = usrCtx.List(list); list.Status.is_ok && !finished; list = usrCtx.List(list)) { - for (i = 0; i < list.Count; i++) { - user = list.Users[i]; - printf("%s\n", user.Username); - } - - finished = list.EndOfList; - } - - printf("\nResult: %s\n", list.Status.errstr); -} - - -function UserInfo(usrCtx, username) -{ - var info; - - info = usrCtx.Info(username); - if (info == null) { - println("Account unknown"); - return -1; - } - - println("User account info:\n"); - printf("AccountName = %s\n", info.AccountName); - printf("Description = %s\n", info.Description); - printf("FullName = %s\n", info.FullName); - printf("AcctExpiry = %s\n", info.AcctExpiry); -} - - -function UserManager(ctx, options) -{ - var usrCtx; - - if (options.ARGV.length < 2) { - PrintNetUsrHelp(options); - return -1; - - } - - var usrCmd = options.ARGV[1]; - - if (usrCmd == "create") { - - } else if (usrCmd == "info") { - var userName; - - if (options.ARGV.length > 2) { - userName = options.ARGV[2]; - } else { - println("No username provided"); - return -1; - } - usrCtx = ctx.UserMgr(); - - UserInfo(usrCtx, userName); - - } else if (usrCmd == "list") { - - if (options.ARGV.length > 2) { - usrCtx = ctx.UserMgr(options.ARGV[2]); - } else { - usrCtx = ctx.UserMgr(); - } - - ListUsers(usrCtx); - - } else { - println("Unknown command specified."); - PrintNetUsrHelp(options); - } -} -- cgit From 75e2e1061ede31aacd0660fb99d4749d4518cb67 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 14:02:37 +0200 Subject: Remove unused rand EJS bindings. (This used to be commit 4016427b77b2bc202a8dc4064ddc7e13f36db06d) --- source4/scripting/ejs/config.mk | 7 --- source4/scripting/ejs/smbcalls_rand.c | 104 ---------------------------------- 2 files changed, 111 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_rand.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index 9aad9c1566..f94348278b 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -13,13 +13,6 @@ PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR smbcalls_ldb_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_ldb.o -[MODULE::smbcalls_rand] -SUBSYSTEM = smbcalls -OUTPUT_TYPE = MERGED_OBJ -INIT_FUNCTION = smb_setup_ejs_random - -smbcalls_rand_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_rand.o - [MODULE::smbcalls_auth] OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls diff --git a/source4/scripting/ejs/smbcalls_rand.c b/source4/scripting/ejs/smbcalls_rand.c deleted file mode 100644 index 58e0fa1fd1..0000000000 --- a/source4/scripting/ejs/smbcalls_rand.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide access to randomisation functions - - Copyright (C) Andrew Tridgell 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/ndr_misc.h" -#include "librpc/ndr/libndr.h" - -/* - usage: - var i = random(); -*/ -static int ejs_random(MprVarHandle eid, int argc, struct MprVar **argv) -{ - mpr_Return(eid, mprCreateIntegerVar(generate_random())); - return 0; -} - -/* - usage: - var s = randpass(len); -*/ -static int ejs_randpass(MprVarHandle eid, int argc, struct MprVar **argv) -{ - char *s; - if (argc != 1 || !mprVarIsNumber(argv[0]->type)) { - ejsSetErrorMsg(eid, "randpass invalid arguments"); - return -1; - } - s = generate_random_str(mprMemCtx(), mprToInt(argv[0])); - mpr_Return(eid, mprString(s)); - talloc_free(s); - return 0; -} - -/* - usage: - var guid = randguid(); -*/ -static int ejs_randguid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct GUID guid = GUID_random(); - char *s = GUID_string(mprMemCtx(), &guid); - mpr_Return(eid, mprString(s)); - talloc_free(s); - return 0; -} - -/* - usage: - var sid = randsid(); -*/ -static int ejs_randsid(MprVarHandle eid, int argc, struct MprVar **argv) -{ - char *s = talloc_asprintf(mprMemCtx(), "S-1-5-21-%u-%u-%u", - (unsigned)generate_random(), - (unsigned)generate_random(), - (unsigned)generate_random()); - mpr_Return(eid, mprString(s)); - talloc_free(s); - return 0; -} - -/* - initialise random ejs subsystem -*/ -static int ejs_random_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *obj = mprInitObject(eid, "random", argc, argv); - - mprSetCFunction(obj, "random", ejs_random); - mprSetCFunction(obj, "randpass", ejs_randpass); - mprSetCFunction(obj, "randguid", ejs_randguid); - mprSetCFunction(obj, "randsid", ejs_randsid); - return 0; -} - -/* - setup C functions that be called from ejs -*/ -NTSTATUS smb_setup_ejs_random(void) -{ - ejsDefineCFunction(-1, "random_init", ejs_random_init, NULL, MPR_VAR_SCRIPT_HANDLE); - return NT_STATUS_OK; -} -- cgit From 1b6396f114f29cabe6b640118f3258e54ceeab32 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 14:03:55 +0200 Subject: Remove unused param ejs bindings. (This used to be commit 4dd0d46e27696b6d29d4b6a63c56667ce5e03db6) --- source4/scripting/ejs/config.mk | 1 - source4/scripting/ejs/smbcalls.c | 1 - source4/scripting/ejs/smbcalls_param.c | 259 --------------------------------- 3 files changed, 261 deletions(-) delete mode 100644 source4/scripting/ejs/smbcalls_param.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index f94348278b..dc4ab776ec 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -49,7 +49,6 @@ smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ smbcalls_options.o \ smbcalls_creds.o \ - smbcalls_param.o \ mprutil.o \ literal.o) diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index 880605bf10..8b1fe06c77 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -204,7 +204,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) smb_setup_ejs_options(); smb_setup_ejs_credentials(); - smb_setup_ejs_param(); smb_setup_ejs_literal(); shared_init = load_samba_modules(NULL, mprLpCtx(), "smbcalls"); diff --git a/source4/scripting/ejs/smbcalls_param.c b/source4/scripting/ejs/smbcalls_param.c deleted file mode 100644 index 5fbb0bb017..0000000000 --- a/source4/scripting/ejs/smbcalls_param.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide hooks into smbd C calls from ejs scripts - - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "param/param.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" - -/* - get parameter - - value = param.get("name"); - value = param.get("section", "name"); -*/ -static int ejs_param_get(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - const char *ret; - if (argc != 1 && argc != 2) { - ejsSetErrorMsg(eid, "param.get invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - if (argc == 2) { - ret = param_get_string(ctx, argv[0], argv[1]); - } else { - ret = param_get_string(ctx, argv[0], NULL); - } - - if (ret) { - mpr_Return(eid, mprString(ret)); - } else { - mpr_Return(eid, mprCreateUndefinedVar()); - } - return 0; -} - -/* - get list parameter - - ok = param.get_list("name"); - ok = param.get_list("section", "name"); -*/ -static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - const char **ret; - - if (argc != 1 && argc != 2) { - ejsSetErrorMsg(eid, "param.get_list invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - if (argc == 2) { - ret = param_get_string_list(ctx, argv[0], argv[1], NULL); - } else { - ret = param_get_string_list(ctx, argv[0], NULL, NULL); - } - - if (ret != NULL) { - mpr_Return(eid, mprList("array", ret)); - } else { - mpr_Return(eid, mprCreateUndefinedVar()); - } - return 0; -} - -/* - set parameter - - ok = param.set("name", "value"); - ok = param.set("section", "name", "value"); -*/ -static int ejs_param_set(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct param_context *ctx; - const char **list; - const char *section, *paramname; - struct MprVar *value; - bool ret; - if (argc != 2 && argc != 3) { - ejsSetErrorMsg(eid, "param.set invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - - if (argc == 3) { - section = mprToString(argv[0]); - paramname = mprToString(argv[1]); - value = argv[2]; - } else { - section = NULL; - paramname = mprToString(argv[0]); - value = argv[1]; - } - - list = mprToList(mprMemCtx(), value); - if (list) { - ret = param_set_string_list(ctx, paramname, list, section); - } else { - ret = param_set_string(ctx, paramname, mprToString(value), section); - } - - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - -/* - param data as a two-level array - - data = param.data; - */ -static int ejs_param_data(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - struct MprVar ret; - struct param_section *sec; - - if (argc != 0) { - ejsSetErrorMsg(eid, "param.data does not take arguments"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - ret = mprObject("array"); - - for (sec = ctx->sections; sec; sec = sec->next) { - struct MprVar ps = mprObject("array"); - struct param_opt *p; - - for (p = sec->parameters; p; p = p->next) { - mprSetVar(&ps, p->key, mprString(p->value)); - } - - mprSetVar(&ret, sec->name, ps); - } - - mpr_Return(eid, ret); - - return 0; -} - -/* - load file - - ok = param.load(file); -*/ -static int ejs_param_load(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - bool ret; - - if (argc != 1) { - ejsSetErrorMsg(eid, "param.load invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - ret = param_read(ctx, argv[0]); - - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - - -/* - save file - - ok = param.save(file); -*/ -static int ejs_param_save(MprVarHandle eid, int argc, char **argv) -{ - struct param_context *ctx; - bool ret; - - if (argc != 1) { - ejsSetErrorMsg(eid, "param.save invalid argument count"); - return -1; - } - - ctx = (struct param_context *)mprGetThisPtr(eid, "param"); - mprAssert(ctx); - - ret = param_write(ctx, argv[0]); - - mpr_Return(eid, mprCreateBoolVar(ret)); - return 0; -} - -static void param_add_members(struct MprVar *obj) -{ - mprSetStringCFunction(obj, "get", ejs_param_get); - mprSetStringCFunction(obj, "get_list", ejs_param_get_list); - mprSetCFunction(obj, "set", ejs_param_set); - mprSetStringCFunction(obj, "load", ejs_param_load); - mprSetStringCFunction(obj, "save", ejs_param_save); - mprSetStringCFunction(obj, "data", ejs_param_data); -} - -/* - initialise param ejs subsystem -*/ -static int ejs_param_init(MprVarHandle eid, int argc, struct MprVar **argv) -{ - struct MprVar *obj = mprInitObject(eid, "param", argc, argv); - - mprSetPtrChild(obj, "param", param_init(mprMemCtx())); - - param_add_members(obj); - - return 0; -} - -struct MprVar mprParam(struct param_context *ctx) -{ - struct MprVar mpv = mprObject("param"); - mprSetPtrChild(&mpv, "param", ctx); - param_add_members(&mpv); - return mpv; -} - -/* - setup C functions that be called from ejs -*/ -void smb_setup_ejs_param(void) -{ - ejsDefineCFunction(-1, "param_init", ejs_param_init, NULL, MPR_VAR_SCRIPT_HANDLE); -} -- cgit From 3a76da248d2c3b8cf90ade4a441dd99c4583183f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 May 2008 14:08:17 +0200 Subject: Remove unused libjs functions. (This used to be commit 657a87fecc2e79e3c3f66c551e392cc341bca8cf) --- source4/scripting/libjs/base.js | 53 --------------- source4/scripting/libjs/encoder.js | 116 --------------------------------- source4/scripting/libjs/server_call.js | 83 ----------------------- 3 files changed, 252 deletions(-) delete mode 100644 source4/scripting/libjs/encoder.js delete mode 100644 source4/scripting/libjs/server_call.js diff --git a/source4/scripting/libjs/base.js b/source4/scripting/libjs/base.js index d861073a07..790dfeb3e0 100644 --- a/source4/scripting/libjs/base.js +++ b/source4/scripting/libjs/base.js @@ -20,48 +20,6 @@ function printf() print(vsprintf(arguments)); } -/* - helper function to setup a rpc io object, ready for input -*/ -function irpcObj() -{ - var o = new Object(); - o.input = new Object(); - return o; -} - -/* - check that a status result is OK -*/ -function check_status_ok(status) -{ - if (status.is_ok != true) { - printVars(status); - } - assert(status.is_ok == true); -} - -/* - check that two arrays are equal -*/ -function check_array_equal(a1, a2) -{ - assert(a1.length == a2.length); - for (i=0; i Date: Mon, 26 May 2008 14:10:34 +0200 Subject: Remove unused literal EJS bindings. (This used to be commit da3094d1ba86a8f4967ca1993383b0767439f79f) --- source4/scripting/ejs/config.mk | 3 +- source4/scripting/ejs/literal.c | 797 --------------------------------------- source4/scripting/ejs/smbcalls.c | 1 - 3 files changed, 1 insertion(+), 800 deletions(-) delete mode 100644 source4/scripting/ejs/literal.c diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index dc4ab776ec..34c0a9678e 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -49,8 +49,7 @@ smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ smbcalls_options.o \ smbcalls_creds.o \ - mprutil.o \ - literal.o) + mprutil.o) $(eval $(call proto_header_template,$(ejsscriptsrcdir)/proto.h,$(smbcalls_OBJ_FILES:.o=.c))) diff --git a/source4/scripting/ejs/literal.c b/source4/scripting/ejs/literal.c deleted file mode 100644 index 8307c211d3..0000000000 --- a/source4/scripting/ejs/literal.c +++ /dev/null @@ -1,797 +0,0 @@ -/* - * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. - * Michael Clark - * Copyright (c) 2006 Derrell Lipman - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See COPYING for details. - * - * Derrell Lipman: - * This version is modified from the original. It has been modified to - * natively use EJS variables rather than the original C object interface, and - * to use the talloc() family of functions for memory allocation. - */ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" - -enum json_tokener_error { - json_tokener_success, - json_tokener_error_oom, /* out of memory */ - json_tokener_error_parse_unexpected, - json_tokener_error_parse_null, - json_tokener_error_parse_date, - json_tokener_error_parse_boolean, - json_tokener_error_parse_number, - json_tokener_error_parse_array, - json_tokener_error_parse_object, - json_tokener_error_parse_string, - json_tokener_error_parse_comment, - json_tokener_error_parse_eof -}; - -enum json_tokener_state { - json_tokener_state_eatws, - json_tokener_state_start, - json_tokener_state_finish, - json_tokener_state_null, - json_tokener_state_date, - json_tokener_state_comment_start, - json_tokener_state_comment, - json_tokener_state_comment_eol, - json_tokener_state_comment_end, - json_tokener_state_string, - json_tokener_state_string_escape, - json_tokener_state_escape_unicode, - json_tokener_state_boolean, - json_tokener_state_number, - json_tokener_state_array, - json_tokener_state_datelist, - json_tokener_state_array_sep, - json_tokener_state_datelist_sep, - json_tokener_state_object, - json_tokener_state_object_field_start, - json_tokener_state_object_field, - json_tokener_state_object_field_end, - json_tokener_state_object_value, - json_tokener_state_object_sep -}; - -enum date_field { - date_field_year, - date_field_month, - date_field_day, - date_field_hour, - date_field_minute, - date_field_second, - date_field_millisecond -}; - -struct json_tokener -{ - char *source; - int pos; - void *ctx; - void *pb; -}; - -static const char *json_number_chars = "0123456789.+-e"; -static const char *json_hex_chars = "0123456789abcdef"; - -#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) - -extern struct MprVar json_tokener_parse(char *s); -static struct MprVar json_tokener_do_parse(struct json_tokener *this, - enum json_tokener_error *err_p); - -/* - * literal_to_var() parses a string into an ejs variable. The ejs - * variable is returned. Upon error, the javascript variable will be - * `undefined`. This was created for parsing JSON, but is generally useful - * for parsing the literal forms of objects and arrays, since ejs doesn't - * procide that functionality. - */ -int literal_to_var(int eid, int argc, char **argv) -{ - struct json_tokener tok; - struct MprVar obj; - enum json_tokener_error err = json_tokener_success; - - if (argc != 1) { - ejsSetErrorMsg(eid, - "literal_to_var() requires one parameter: " - "the string to be parsed."); - return -1; - } - - tok.source = argv[0]; - tok.pos = 0; - tok.ctx = talloc_new(mprMemCtx()); - if (tok.ctx == NULL) { - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; - } - tok.pb = talloc_zero_size(tok.ctx, 1); - if (tok.pb == NULL) { - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; - } - obj = json_tokener_do_parse(&tok, &err); - talloc_free(tok.pb); - if (err != json_tokener_success) { - mprDestroyVar(&obj); - mpr_Return(eid, mprCreateUndefinedVar()); - return 0; - } - mpr_Return(eid, obj); - return 0; -} - -static void *append_string(void *ctx, - char *orig, - char *append, - int size) -{ - if (!orig) { - return talloc_strndup(ctx, append, size); - } - - return talloc_strndup_append(orig, append, size); -} - - -static struct MprVar json_tokener_do_parse(struct json_tokener *this, - enum json_tokener_error *err_p) -{ - enum json_tokener_state state; - enum json_tokener_state saved_state; - enum date_field date_field; - struct MprVar current = mprCreateUndefinedVar(); - struct MprVar tempObj; - struct MprVar obj; - enum json_tokener_error err = json_tokener_success; - char date_script[] = "JSON_Date.create(0);"; - char *obj_field_name = NULL; - char *emsg = NULL; - char quote_char; - int deemed_double; - int start_offset; - char c; - - state = json_tokener_state_eatws; - saved_state = json_tokener_state_start; - - - do { - c = this->source[this->pos]; - switch(state) { - - case json_tokener_state_eatws: - if(isspace(c)) { - this->pos++; - } else if(c == '/') { - state = json_tokener_state_comment_start; - start_offset = this->pos++; - } else { - state = saved_state; - } - break; - - case json_tokener_state_start: - switch(c) { - case '{': - state = json_tokener_state_eatws; - saved_state = json_tokener_state_object; - current = mprObject(NULL); - this->pos++; - break; - case '[': - state = json_tokener_state_eatws; - saved_state = json_tokener_state_array; - current = mprArray(NULL); - this->pos++; - break; - case 'N': - case 'n': - start_offset = this->pos++; - if (this->source[this->pos] == 'e') { - state = json_tokener_state_date; - } else { - state = json_tokener_state_null; - } - break; - case '"': - case '\'': - quote_char = c; - talloc_free(this->pb); - this->pb = talloc_zero_size(this->ctx, 1); - if (this->pb == NULL) { - *err_p = json_tokener_error_oom; - goto out; - } - state = json_tokener_state_string; - start_offset = ++this->pos; - break; - case 'T': - case 't': - case 'F': - case 'f': - state = json_tokener_state_boolean; - start_offset = this->pos++; - break; -#if defined(__GNUC__) - case '0' ... '9': -#else - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': -#endif - case '-': - deemed_double = 0; - state = json_tokener_state_number; - start_offset = this->pos++; - break; - default: - err = json_tokener_error_parse_unexpected; - goto out; - } - break; - - case json_tokener_state_finish: - goto out; - - case json_tokener_state_null: - if(strncasecmp("null", - this->source + start_offset, - this->pos - start_offset)) { - *err_p = json_tokener_error_parse_null; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - - if(this->pos - start_offset == 4) { - mprDestroyVar(¤t); - current = mprCreateNullVar(); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - this->pos++; - } - break; - - case json_tokener_state_date: - if (this->pos - start_offset <= 18) { - if (strncasecmp("new Date(Date.UTC(", - this->source + start_offset, - this->pos - start_offset)) { - *err_p = json_tokener_error_parse_date; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } else { - this->pos++; - break; - } - } - - this->pos--; /* we went one too far */ - state = json_tokener_state_eatws; - saved_state = json_tokener_state_datelist; - - /* Create a JsonDate object */ - if (ejsEvalScript(0, - date_script, - &tempObj, - &emsg) != 0) { - *err_p = json_tokener_error_parse_date; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - mprDestroyVar(¤t); - mprCopyVar(¤t, &tempObj, MPR_DEEP_COPY); - date_field = date_field_year; - break; - - case json_tokener_state_comment_start: - if(c == '*') { - state = json_tokener_state_comment; - } else if(c == '/') { - state = json_tokener_state_comment_eol; - } else { - err = json_tokener_error_parse_comment; - goto out; - } - this->pos++; - break; - - case json_tokener_state_comment: - if(c == '*') state = json_tokener_state_comment_end; - this->pos++; - break; - - case json_tokener_state_comment_eol: - if(c == '\n') { - state = json_tokener_state_eatws; - } - this->pos++; - break; - - case json_tokener_state_comment_end: - if(c == '/') { - state = json_tokener_state_eatws; - } else { - state = json_tokener_state_comment; - } - this->pos++; - break; - - case json_tokener_state_string: - if(c == quote_char) { - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - current = mprString(this->pb); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == '\\') { - saved_state = json_tokener_state_string; - state = json_tokener_state_string_escape; - } - this->pos++; - break; - - case json_tokener_state_string_escape: - switch(c) { - case '"': - case '\\': - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - start_offset = this->pos++; - state = saved_state; - break; - case 'b': - case 'n': - case 'r': - case 't': - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - if (c == 'b') { - /* - * second param to append_string() - * gets temporarily modified; can't - * pass string constant. - */ - char buf[] = "\b"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (c == 'n') { - char buf[] = "\n"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (c == 'r') { - char buf[] = "\r"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (c == 't') { - char buf[] = "\t"; - this->pb = append_string(this->ctx, - this->pb, - buf, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } - start_offset = ++this->pos; - state = saved_state; - break; - case 'u': - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - start_offset = ++this->pos; - state = json_tokener_state_escape_unicode; - break; - default: - err = json_tokener_error_parse_string; - goto out; - } - break; - - case json_tokener_state_escape_unicode: - if(strchr(json_hex_chars, c)) { - this->pos++; - if(this->pos - start_offset == 4) { - unsigned char utf_out[3]; - unsigned int ucs_char = - (hexdigit(*(this->source + start_offset)) << 12) + - (hexdigit(*(this->source + start_offset + 1)) << 8) + - (hexdigit(*(this->source + start_offset + 2)) << 4) + - hexdigit(*(this->source + start_offset + 3)); - if (ucs_char < 0x80) { - utf_out[0] = ucs_char; - this->pb = append_string( - this->ctx, - this->pb, - (char *) utf_out, - 1); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else if (ucs_char < 0x800) { - utf_out[0] = 0xc0 | (ucs_char >> 6); - utf_out[1] = 0x80 | (ucs_char & 0x3f); - this->pb = append_string( - this->ctx, - this->pb, - (char *) utf_out, - 2); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } else { - utf_out[0] = 0xe0 | (ucs_char >> 12); - utf_out[1] = 0x80 | ((ucs_char >> 6) & 0x3f); - utf_out[2] = 0x80 | (ucs_char & 0x3f); - this->pb = append_string( - this->ctx, - this->pb, - (char *) utf_out, - 3); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - } - start_offset = this->pos; - state = saved_state; - } - } else { - err = json_tokener_error_parse_string; - goto out; - } - break; - - case json_tokener_state_boolean: - if(strncasecmp("true", this->source + start_offset, - this->pos - start_offset) == 0) { - if(this->pos - start_offset == 4) { - current = mprCreateBoolVar(1); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - this->pos++; - } - } else if(strncasecmp("false", this->source + start_offset, - this->pos - start_offset) == 0) { - if(this->pos - start_offset == 5) { - current = mprCreateBoolVar(0); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - this->pos++; - } - } else { - err = json_tokener_error_parse_boolean; - goto out; - } - break; - - case json_tokener_state_number: - if(!c || !strchr(json_number_chars, c)) { - int numi; - double numd; - char *tmp = talloc_strndup( - this->ctx, - this->source + start_offset, - this->pos - start_offset); - if (tmp == NULL) { - err = json_tokener_error_oom; - goto out; - } - if(!deemed_double && sscanf(tmp, "%d", &numi) == 1) { - current = mprCreateIntegerVar(numi); - } else if(deemed_double && sscanf(tmp, "%lf", &numd) == 1) { - current = mprCreateFloatVar(numd); - } else { - talloc_free(tmp); - err = json_tokener_error_parse_number; - goto out; - } - talloc_free(tmp); - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - if(c == '.' || c == 'e') deemed_double = 1; - this->pos++; - } - break; - - case json_tokener_state_array: - if(c == ']') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - int oldlen; - char idx[16]; - - obj = json_tokener_do_parse(this, &err); - if (err != json_tokener_success) { - goto out; - } - oldlen = mprToInt(mprGetProperty(¤t, - "length", - NULL)); - mprItoa(oldlen, idx, sizeof(idx)); - mprSetVar(¤t, idx, obj); - saved_state = json_tokener_state_array_sep; - state = json_tokener_state_eatws; - } - break; - - case json_tokener_state_datelist: - if(c == ')') { - if (this->source[this->pos+1] == ')') { - this->pos += 2; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - err = json_tokener_error_parse_date; - goto out; - } - } else { - obj = json_tokener_do_parse(this, &err); - if (err != json_tokener_success) { - goto out; - } - - /* date list items must be integers */ - if (obj.type != MPR_TYPE_INT) { - err = json_tokener_error_parse_date; - goto out; - } - - switch(date_field) { - case date_field_year: - mprSetVar(¤t, "year", obj); - break; - case date_field_month: - mprSetVar(¤t, "month", obj); - break; - case date_field_day: - mprSetVar(¤t, "day", obj); - break; - case date_field_hour: - mprSetVar(¤t, "hour", obj); - break; - case date_field_minute: - mprSetVar(¤t, "minute", obj); - break; - case date_field_second: - mprSetVar(¤t, "second", obj); - break; - case date_field_millisecond: - mprSetVar(¤t, "millisecond", obj); - break; - default: - err = json_tokener_error_parse_date; - goto out; - } - - /* advance to the next date field */ - date_field++; - - saved_state = json_tokener_state_datelist_sep; - state = json_tokener_state_eatws; - } - break; - - case json_tokener_state_array_sep: - if(c == ']') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == ',') { - this->pos++; - saved_state = json_tokener_state_array; - state = json_tokener_state_eatws; - } else { - *err_p = json_tokener_error_parse_array; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - break; - - case json_tokener_state_datelist_sep: - if(c == ')') { - if (this->source[this->pos+1] == ')') { - this->pos += 2; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else { - err = json_tokener_error_parse_date; - goto out; - } - } else if(c == ',') { - this->pos++; - saved_state = json_tokener_state_datelist; - state = json_tokener_state_eatws; - } else { - *err_p = json_tokener_error_parse_date; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - break; - - case json_tokener_state_object: - state = json_tokener_state_object_field_start; - start_offset = this->pos; - break; - - case json_tokener_state_object_field_start: - if(c == '}') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if (c == '"' || c == '\'') { - quote_char = c; - talloc_free(this->pb); - this->pb = talloc_zero_size(this->ctx, 1); - if (this->pb == NULL) { - *err_p = json_tokener_error_oom; - goto out; - } - state = json_tokener_state_object_field; - start_offset = ++this->pos; - } else { - err = json_tokener_error_parse_object; - goto out; - } - break; - - case json_tokener_state_object_field: - if(c == quote_char) { - this->pb = append_string( - this->ctx, - this->pb, - this->source + start_offset, - this->pos - start_offset); - if (this->pb == NULL) { - err = json_tokener_error_oom; - goto out; - } - obj_field_name = talloc_strdup(this->ctx, - this->pb); - if (obj_field_name == NULL) { - err = json_tokener_error_oom; - goto out; - } - saved_state = json_tokener_state_object_field_end; - state = json_tokener_state_eatws; - } else if(c == '\\') { - saved_state = json_tokener_state_object_field; - state = json_tokener_state_string_escape; - } - this->pos++; - break; - - case json_tokener_state_object_field_end: - if(c == ':') { - this->pos++; - saved_state = json_tokener_state_object_value; - state = json_tokener_state_eatws; - } else { - *err_p = json_tokener_error_parse_object; - mprDestroyVar(¤t); - return mprCreateUndefinedVar(); - } - break; - - case json_tokener_state_object_value: - obj = json_tokener_do_parse(this, &err); - if (err != json_tokener_success) { - goto out; - } - mprSetVar(¤t, obj_field_name, obj); - talloc_free(obj_field_name); - obj_field_name = NULL; - saved_state = json_tokener_state_object_sep; - state = json_tokener_state_eatws; - break; - - case json_tokener_state_object_sep: - if(c == '}') { - this->pos++; - saved_state = json_tokener_state_finish; - state = json_tokener_state_eatws; - } else if(c == ',') { - this->pos++; - saved_state = json_tokener_state_object; - state = json_tokener_state_eatws; - } else { - err = json_tokener_error_parse_object; - goto out; - } - break; - - } - } while(c); - - if(state != json_tokener_state_finish && - saved_state != json_tokener_state_finish) - err = json_tokener_error_parse_eof; - -out: - talloc_free(obj_field_name); - if(err == json_tokener_success) { - return current; - } else { - mprDestroyVar(¤t); - *err_p = err; - return mprCreateUndefinedVar(); - } -} - - -void smb_setup_ejs_literal(void) -{ - ejsDefineStringCFunction(-1, - "literal_to_var", - literal_to_var, - NULL, - MPR_VAR_SCRIPT_HANDLE); -} diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c index 8b1fe06c77..4314b51455 100644 --- a/source4/scripting/ejs/smbcalls.c +++ b/source4/scripting/ejs/smbcalls.c @@ -204,7 +204,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *)) smb_setup_ejs_options(); smb_setup_ejs_credentials(); - smb_setup_ejs_literal(); shared_init = load_samba_modules(NULL, mprLpCtx(), "smbcalls"); -- cgit From 0d8d6dbfd7f51500f393cf5a14a568a1271edf3f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 12:41:50 +1000 Subject: the start of a SMB2 create test suite (This used to be commit 16787e99f3de7255e315651c095486f90f65f2ca) --- source4/torture/smb2/config.mk | 3 +- source4/torture/smb2/create.c | 102 +++++++++++++++++++++++++++++++++++++++++ source4/torture/smb2/smb2.c | 1 + 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 source4/torture/smb2/create.c diff --git a/source4/torture/smb2/config.mk b/source4/torture/smb2/config.mk index 11c4e1fa2c..6c69f3043c 100644 --- a/source4/torture/smb2/config.mk +++ b/source4/torture/smb2/config.mk @@ -20,7 +20,8 @@ TORTURE_SMB2_OBJ_FILES = $(addprefix $(torturesrcdir)/smb2/, \ notify.o \ smb2.o \ persistent_handles.o \ - oplocks.o) + oplocks.o \ + create.o) $(eval $(call proto_header_template,$(torturesrcdir)/smb2/proto.h,$(TORTURE_SMB2_OBJ_FILES:.o=.c))) diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c new file mode 100644 index 0000000000..fba7b8464f --- /dev/null +++ b/source4/torture/smb2/create.c @@ -0,0 +1,102 @@ +/* + Unix SMB/CIFS implementation. + + SMB2 create test suite + + Copyright (C) Andrew Tridgell 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "libcli/smb2/smb2.h" +#include "libcli/smb2/smb2_calls.h" +#include "torture/torture.h" +#include "torture/smb2/proto.h" +#include "param/param.h" +#include "librpc/gen_ndr/ndr_security.h" + +#define FNAME "test_create.dat" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%s) Incorrect status %s - should be %s\n", \ + __location__, nt_errstr(status), nt_errstr(correct)); \ + return false; \ + }} while (0) + +/* + test some interesting combinations found by gentest + */ +bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tree *tree) +{ + struct smb2_create io; + NTSTATUS status; + TALLOC_CTX *tmp_ctx = talloc_new(tree); + + ZERO_STRUCT(io); + io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; + io.in.file_attributes = FILE_ATTRIBUTE_NORMAL; + io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF; + io.in.share_access = + NTCREATEX_SHARE_ACCESS_DELETE| + NTCREATEX_SHARE_ACCESS_READ| + NTCREATEX_SHARE_ACCESS_WRITE; + io.in.create_options = 0; + io.in.fname = FNAME; + + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb2_util_close(tree, io.out.file.handle); + CHECK_STATUS(status, NT_STATUS_OK); + + io.in.create_options = 0xF0000000; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + io.in.create_options = 0x00100000; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_NOT_SUPPORTED); + + io.in.create_options = 0xF0100000; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_NOT_SUPPORTED); + + talloc_free(tmp_ctx); + + return true; +} + +/* + basic testing of SMB2 create calls +*/ +bool torture_smb2_create(struct torture_context *torture) +{ + TALLOC_CTX *mem_ctx = talloc_new(NULL); + struct smb2_tree *tree; + bool ret = true; + + if (!torture_smb2_connection(torture, &tree)) { + return false; + } + + ret &= torture_smb2_create_gentest(torture, tree); + + smb2_deltree(tree, FNAME); + + talloc_free(mem_ctx); + + return ret; +} diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c index 37eadcf7fd..852effe3e2 100644 --- a/source4/torture/smb2/smb2.c +++ b/source4/torture/smb2/smb2.c @@ -135,6 +135,7 @@ NTSTATUS torture_smb2_init(void) torture_suite_add_simple_test(suite, "GETINFO", torture_smb2_getinfo); torture_suite_add_simple_test(suite, "SETINFO", torture_smb2_setinfo); torture_suite_add_simple_test(suite, "FIND", torture_smb2_find); + torture_suite_add_simple_test(suite, "CREATE", torture_smb2_create); torture_suite_add_suite(suite, torture_smb2_lock_init()); torture_suite_add_simple_test(suite, "NOTIFY", torture_smb2_notify); torture_suite_add_2smb2_test(suite, "PERSISTENT-HANDLES1", torture_smb2_persistent_handles1); -- cgit From 2814868e93116bb967a7438d95b6fd407246acc1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 12:42:19 +1000 Subject: don't alter the in blobs in a SMB2 create, otherwise two calls in a row will fail (This used to be commit 3b811a52fe9a8356337ad149d01a3498c09d900a) --- source4/libcli/smb2/create.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source4/libcli/smb2/create.c b/source4/libcli/smb2/create.c index b1b8b0ccfa..1901cb4977 100644 --- a/source4/libcli/smb2/create.c +++ b/source4/libcli/smb2/create.c @@ -94,6 +94,7 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create NTSTATUS status; DATA_BLOB blob = data_blob(NULL, 0); uint32_t i; + struct smb2_create_blobs blobs = io->in.blobs; req = smb2_request_init_tree(tree, SMB2_OP_CREATE, 0x38, true, 0); if (req == NULL) return NULL; @@ -119,7 +120,7 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create DATA_BLOB b = data_blob_talloc(req, NULL, ea_list_size_chained(io->in.eas.num_eas, io->in.eas.eas, 4)); ea_put_list_chained(b.data, io->in.eas.num_eas, io->in.eas.eas, 4); - status = smb2_create_blob_add(req, &io->in.blobs, + status = smb2_create_blob_add(req, &blobs, SMB2_CREATE_TAG_EXTA, b); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); @@ -130,22 +131,22 @@ struct smb2_request *smb2_create_send(struct smb2_tree *tree, struct smb2_create /* an empty MxAc tag seems to be used to ask the server to return the maximum access mask allowed on the file */ - status = smb2_create_blob_add(req, &io->in.blobs, + status = smb2_create_blob_add(req, &blobs, SMB2_CREATE_TAG_MXAC, data_blob(NULL, 0)); if (!NT_STATUS_IS_OK(status)) { talloc_free(req); return NULL; } - for (i=0; i < io->in.blobs.num_blobs; i++) { + for (i=0; i < blobs.num_blobs; i++) { bool last = false; const struct smb2_create_blob *c; - if ((i + 1) == io->in.blobs.num_blobs) { + if ((i + 1) == blobs.num_blobs) { last = true; } - c = &io->in.blobs.blobs[i]; + c = &blobs.blobs[i]; status = smb2_create_blob_push_one(req, &blob, c, last); if (!NT_STATUS_IS_OK(status)) { -- cgit From 506849f6008386dad5baa287e7e81a73af031622 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 12:42:43 +1000 Subject: check invalid create options in the right order (This used to be commit 73dbfb9b4148dbfdc30518c08db4658d189f4160) --- source4/ntvfs/ntvfs_generic.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c index 9b4f235cde..c5b88da3d1 100644 --- a/source4/ntvfs/ntvfs_generic.c +++ b/source4/ntvfs/ntvfs_generic.c @@ -523,9 +523,16 @@ NTSTATUS ntvfs_map_open(struct ntvfs_module_context *ntvfs, io2->generic.in.sec_desc = NULL; io2->generic.in.ea_list = NULL; + /* we need to check these bits before we check the private mask */ + if (io2->generic.in.create_options & NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK) { + status = NT_STATUS_NOT_SUPPORTED; + break; + } + /* we use a couple of bits of the create options internally */ if (io2->generic.in.create_options & NTCREATEX_OPTIONS_PRIVATE_MASK) { - return NT_STATUS_INVALID_PARAMETER; + status = NT_STATUS_INVALID_PARAMETER; + break; } status = ntvfs->ops->open(ntvfs, req, io2); -- cgit From 892712e4e77abbc4ec7b18623eb1cba86f7a2979 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 12:43:10 +1000 Subject: cleanup some warnings and add --skip-cleanup (This used to be commit c73dd078eaa20c7bf0b833e65b24c29aab738f25) --- source4/torture/gentest_smb2.c | 222 ++++++++++++++++++++++++++++++++--------- 1 file changed, 173 insertions(+), 49 deletions(-) diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index 46545699d0..428f325a76 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -55,6 +55,7 @@ static struct gentest_options { int fast_reconnect; int mask_indexing; int no_eas; + int skip_cleanup; } options; /* mapping between open handles on the server and local handles */ @@ -112,7 +113,8 @@ static struct smb2_handle bad_smb2_handle; #define BAD_HANDLE 0xFFFE -static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private); +static bool oplock_handler(struct smb2_transport *transport, const struct smb2_handle *handle, + uint8_t level, void *private_data); static void idle_func(struct smb2_transport *transport, void *private); /* @@ -208,7 +210,8 @@ static bool connect_servers(struct event_context *ev, return false; } -// smb2_oplock_handler(servers[i].cli[j]->transport, oplock_handler, NULL); + servers[i].tree[j]->session->transport->oplock.handler = oplock_handler; + servers[i].tree[j]->session->transport->oplock.private_data = (void *)(uintptr_t)((i<<8)|j); smb2_transport_idle_handler(servers[i].tree[j]->session->transport, idle_func, 50000, NULL); } } @@ -512,24 +515,37 @@ static uint32_t gen_bits_mask2(uint32_t mask1, uint32_t mask2) } /* - generate a boolean -*/ -static bool gen_bool(void) + generate reserved values + */ +static uint64_t gen_reserved8(void) { - return gen_bits_mask2(0x1, 0xFF); + return gen_bits_mask(0xFF); } -/* - generate ntrename flags -*/ -static uint16_t gen_rename_flags(void) +static uint64_t gen_reserved16(void) { - if (gen_chance(30)) return RENAME_FLAG_RENAME; - if (gen_chance(30)) return RENAME_FLAG_HARD_LINK; - if (gen_chance(30)) return RENAME_FLAG_COPY; return gen_bits_mask(0xFFFF); } +static uint64_t gen_reserved32(void) +{ + return gen_bits_mask(0xFFFFFFFF); +} + +static uint64_t gen_reserved64(void) +{ + return gen_bits_mask(0xFFFFFFFF) | (((uint64_t)gen_bits_mask(0xFFFFFFFF))<<32); +} + + + +/* + generate a boolean +*/ +static bool gen_bool(void) +{ + return gen_bits_mask2(0x1, 0xFF); +} /* return a set of lock flags @@ -552,15 +568,6 @@ static off_t gen_lock_count(void) return gen_int_range(0, 3); } -/* - generate a ntcreatex flags field -*/ -static uint32_t gen_ntcreatex_flags(void) -{ - if (gen_chance(70)) return NTCREATEX_FLAGS_EXTENDED; - return gen_bits_mask2(0x1F, 0xFFFFFFFF); -} - /* generate a NT access mask */ @@ -619,15 +626,6 @@ static NTTIME gen_nttime(void) return ret; } -/* - generate a milliseconds protocol timeout -*/ -static uint32_t gen_timeout(void) -{ - if (gen_chance(98)) return 0; - return random() % 50; -} - /* generate a file allocation size */ @@ -704,6 +702,107 @@ static struct smb_ea_list gen_ea_list(void) return eas; } +static void oplock_handler_close_recv(struct smb2_request *req) +{ + NTSTATUS status; + struct smb2_close io; + status = smb2_close_recv(req, &io); + if (!NT_STATUS_IS_OK(status)) { + printf("close failed in oplock_handler\n"); + smb_panic("close failed in oplock_handler"); + } +} + +static void oplock_handler_ack_callback(struct smb2_request *req) +{ + NTSTATUS status; + struct smb2_break br; + + status = smb2_break_recv(req, &br); + if (!NT_STATUS_IS_OK(status)) { + printf("oplock break ack failed in oplock_handler\n"); + smb_panic("oplock break ack failed in oplock_handler"); + } +} + +static bool send_oplock_ack(struct smb2_tree *tree, struct smb2_handle handle, + uint8_t level) +{ + struct smb2_break br; + struct smb2_request *req; + + ZERO_STRUCT(br); + br.in.file.handle = handle; + br.in.oplock_level = level; + br.in.reserved = gen_reserved8(); + br.in.reserved2 = gen_reserved32(); + + req = smb2_break_send(tree, &br); + if (req == NULL) return false; + req->async.fn = oplock_handler_ack_callback; + req->async.private_data = NULL; + return true; +} + +/* + the oplock handler will either ack the break or close the file +*/ +static bool oplock_handler(struct smb2_transport *transport, const struct smb2_handle *handle, + uint8_t level, void *private_data) +{ + struct smb2_close io; + unsigned i, j; + bool do_close; + struct smb2_tree *tree = NULL; + struct smb2_request *req; + + srandom(current_op.seed); + do_close = gen_chance(50); + + i = ((uintptr_t)private_data) >> 8; + j = ((uintptr_t)private_data) & 0xFF; + + if (i >= NSERVERS || j >= NINSTANCES) { + printf("Bad private_data in oplock_handler\n"); + return false; + } + + oplocks[i][j].got_break = true; + oplocks[i][j].server_handle = *handle; + oplocks[i][j].handle = fnum_to_handle(i, j, *handle); + oplocks[i][j].level = level; + oplocks[i][j].do_close = do_close; + tree = talloc_get_type(servers[i].tree[j], struct smb2_tree); + + if (!tree) { + printf("Oplock break not for one of our trees!?\n"); + return false; + } + + if (!do_close) { + printf("oplock ack handle=%d\n", oplocks[i][j].handle); + return send_oplock_ack(tree, *handle, level); + } + + printf("oplock close fnum=%d\n", oplocks[i][j].handle); + + ZERO_STRUCT(io); + io.in.file.handle = *handle; + io.in.flags = 0; + req = smb2_close_send(tree, &io); + + if (req == NULL) { + printf("WARNING: close failed in oplock_handler_close\n"); + return false; + } + + req->async.fn = oplock_handler_close_recv; + req->async.private_data = NULL; + + return true; +} + + /* the idle function tries to cope with getting an oplock break on a connection, and an operation on another connection blocking until that break is acked @@ -742,7 +841,7 @@ static bool compare_status(NTSTATUS status1, NTSTATUS status2) return false; } - +#if 0 /* check for pending packets on all connections */ @@ -758,6 +857,7 @@ static void check_pending(void) } } } +#endif /* check that the same oplock breaks have been received by all instances @@ -974,15 +1074,6 @@ again: CHECK_EQUAL(field.length); \ } while(0) -#define CHECK_TIMES_EQUAL(field) do { \ - if (labs(parm[0].field - parm[1].field) > time_skew() && \ - !ignore_pattern(#field)) { \ - printf("Mismatch in %s - 0x%x 0x%x\n", #field, \ - (int)parm[0].field, (int)parm[1].field); \ - return false; \ - } \ -} while(0) - #define CHECK_NTTIMES_EQUAL(field) do { \ if (labs(nt_time_to_unix(parm[0].field) - \ nt_time_to_unix(parm[1].field)) > time_skew() && \ @@ -1010,10 +1101,7 @@ static bool handler_create(int instance) if (gen_chance(2)) { parm[0].in.create_flags |= gen_bits_mask(0xFFFFFFFF); } - parm[0].in.reserved = gen_bits_levels(2, 95, 0x0, 100, 0xFFFFFFFF); - if (gen_chance(2)) { - parm[0].in.reserved |= gen_bits_mask(0xFFFFFFFF); - } + parm[0].in.reserved = gen_reserved64(); parm[0].in.desired_access = gen_access_mask(); parm[0].in.file_attributes = gen_attrib(); parm[0].in.share_access = gen_bits_mask2(0x7, 0xFFFFFFFF); @@ -1088,7 +1176,7 @@ static bool handler_read(int instance) NTSTATUS status[NSERVERS]; parm[0].in.file.handle.data[0] = gen_fnum(instance); - parm[0].in.reserved = gen_bits_mask2(0x0, 0xFF); + parm[0].in.reserved = gen_reserved8(); parm[0].in.length = gen_io_count(); parm[0].in.offset = gen_offset(); parm[0].in.min_count = gen_io_count(); @@ -1146,7 +1234,7 @@ static bool handler_lock(int instance) parm[0].level = RAW_LOCK_LOCKX; parm[0].in.file.handle.data[0] = gen_fnum(instance); parm[0].in.lock_count = gen_lock_count(); - parm[0].in.reserved = gen_bits_mask2(0, 0xFFFFFFFF); + parm[0].in.reserved = gen_reserved32(); parm[0].in.locks = talloc_array(current_op.mem_ctx, struct smb2_lock_element, @@ -1177,8 +1265,8 @@ static bool handler_flush(int instance) ZERO_STRUCT(parm[0]); parm[0].in.file.handle.data[0] = gen_fnum(instance); - parm[0].in.reserved1 = gen_bits_mask2(0x0, 0xFFFF); - parm[0].in.reserved2 = gen_bits_mask2(0x0, 0xFFFFFFFF); + parm[0].in.reserved1 = gen_reserved16(); + parm[0].in.reserved2 = gen_reserved32(); GEN_COPY_PARM; GEN_SET_FNUM(in.file.handle); @@ -1242,6 +1330,23 @@ static bool cmp_fileinfo(int instance, case RAW_FILEINFO_GENERIC: return false; + /* SMB1 specific values */ + case RAW_FILEINFO_GETATTR: + case RAW_FILEINFO_GETATTRE: + case RAW_FILEINFO_STANDARD: + case RAW_FILEINFO_EA_SIZE: + case RAW_FILEINFO_ALL_EAS: + case RAW_FILEINFO_IS_NAME_VALID: + case RAW_FILEINFO_BASIC_INFO: + case RAW_FILEINFO_STANDARD_INFO: + case RAW_FILEINFO_EA_INFO: + case RAW_FILEINFO_NAME_INFO: + case RAW_FILEINFO_ALL_INFO: + case RAW_FILEINFO_ALT_NAME_INFO: + case RAW_FILEINFO_STREAM_INFO: + case RAW_FILEINFO_COMPRESSION_INFO: + return false; + case RAW_FILEINFO_BASIC_INFORMATION: CHECK_NTTIMES_EQUAL(basic_info.out.create_time); CHECK_NTTIMES_EQUAL(basic_info.out.access_time); @@ -1411,6 +1516,16 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info) info->generic.level = levels[i].level; switch (info->generic.level) { + case RAW_SFILEINFO_SETATTR: + case RAW_SFILEINFO_SETATTRE: + case RAW_SFILEINFO_STANDARD: + case RAW_SFILEINFO_EA_SET: + case RAW_SFILEINFO_BASIC_INFO: + case RAW_SFILEINFO_DISPOSITION_INFO: + case RAW_SFILEINFO_END_OF_FILE_INFO: + case RAW_SFILEINFO_ALLOCATION_INFO: + break; + case RAW_SFILEINFO_BASIC_INFORMATION: info->basic_info.in.create_time = gen_nttime(); info->basic_info.in.access_time = gen_nttime(); @@ -1447,6 +1562,10 @@ static void gen_setfileinfo(int instance, union smb_setfileinfo *info) case RAW_SFILEINFO_1032: case RAW_SFILEINFO_1039: case RAW_SFILEINFO_1040: + case RAW_SFILEINFO_UNIX_BASIC: + case RAW_SFILEINFO_UNIX_INFO2: + case RAW_SFILEINFO_UNIX_LINK: + case RAW_SFILEINFO_UNIX_HLINK: /* Untested */ break; } @@ -1479,6 +1598,10 @@ static void wipe_files(void) int i; NTSTATUS status; + if (options.skip_cleanup) { + return; + } + for (i=0;i Date: Tue, 27 May 2008 14:06:27 +1000 Subject: cope better with read only files in smb2_deltree (This used to be commit 88a2c7b2f44f160836e477e460812df557204f51) --- source4/libcli/smb2/util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source4/libcli/smb2/util.c b/source4/libcli/smb2/util.c index 9eb344e83f..311cea94a0 100644 --- a/source4/libcli/smb2/util.c +++ b/source4/libcli/smb2/util.c @@ -127,6 +127,16 @@ int smb2_deltree(struct smb2_tree *tree, const char *dname) return 0; } + if (NT_STATUS_EQUAL(status, NT_STATUS_CANNOT_DELETE)) { + /* it could be read-only */ + status = smb2_util_setatr(tree, dname, FILE_ATTRIBUTE_NORMAL); + status = smb2_util_unlink(tree, dname); + } + if (NT_STATUS_IS_OK(status)) { + talloc_free(tmp_ctx); + return 1; + } + ZERO_STRUCT(create_parm); create_parm.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; create_parm.in.share_access = -- cgit From af4f6f445a2958b2a80c3849355eab93071cbc7c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 14:06:38 +1000 Subject: add a mask of invalid security bits (This used to be commit ccbf5238767605f020ede66c8027731487c8cf00) --- source4/librpc/idl/security.idl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source4/librpc/idl/security.idl b/source4/librpc/idl/security.idl index 314846c53f..f8e9e9e110 100644 --- a/source4/librpc/idl/security.idl +++ b/source4/librpc/idl/security.idl @@ -106,6 +106,9 @@ interface security const int SEC_ADS_LIST_OBJECT = 0x00000080; const int SEC_ADS_CONTROL_ACCESS = 0x00000100; + /* invalid bits */ + const int SEC_MASK_INVALID = 0x0ce0fe00; + /* generic->specific mappings for files */ const int SEC_RIGHTS_FILE_READ = SEC_STD_READ_CONTROL | SEC_STD_SYNCHRONIZE | -- cgit From 9a37e7ed93dabd1880513d10afc1135049f1fb4a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 14:06:51 +1000 Subject: Vista returns ACCESS_DENIED here (This used to be commit f5068c6e50215f6ea7108d58d783394a315ff14f) --- source4/ntvfs/posix/pvfs_acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/ntvfs/posix/pvfs_acl.c b/source4/ntvfs/posix/pvfs_acl.c index f1e469f790..507c22f050 100644 --- a/source4/ntvfs/posix/pvfs_acl.c +++ b/source4/ntvfs/posix/pvfs_acl.c @@ -457,7 +457,7 @@ NTSTATUS pvfs_access_check_unix(struct pvfs_state *pvfs, } if (uid != 0 && (*access_mask & SEC_FLAG_SYSTEM_SECURITY)) { - return NT_STATUS_PRIVILEGE_NOT_HELD; + return NT_STATUS_ACCESS_DENIED; } if (*access_mask & ~max_bits) { -- cgit From f0b4b15f64259fcdb18f21657434f592bb2f157e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 14:07:11 +1000 Subject: check for some more invalid bits in smb2 create (This used to be commit dcdaa9f5fd9150b16fb277213e864e5c39d831d6) --- source4/ntvfs/posix/pvfs_open.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 59b42fe751..328f064a57 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -1147,6 +1147,15 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, return NT_STATUS_INVALID_PARAMETER; } + if (access_mask & (SEC_MASK_INVALID | SEC_STD_SYNCHRONIZE)) { + return NT_STATUS_ACCESS_DENIED; + } + + if (io->ntcreatex.in.file_attr & (FILE_ATTRIBUTE_DEVICE| + FILE_ATTRIBUTE_VOLUME)) { + return NT_STATUS_INVALID_PARAMETER; + } + /* resolve the cifs name to a posix name */ status = pvfs_resolve_name(pvfs, req, io->ntcreatex.in.fname, PVFS_RESOLVE_STREAMS, &name); -- cgit From 95afe46a0ec550253255f963bc0afe89cf0444ad Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 14:07:27 +1000 Subject: expanded the SMB2 create testing (This used to be commit 71915128498674d9937780b9278fd2ac1eb06ba8) --- source4/torture/smb2/connect.c | 6 ++-- source4/torture/smb2/create.c | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/source4/torture/smb2/connect.c b/source4/torture/smb2/connect.c index 0004ea958e..826bb2d719 100644 --- a/source4/torture/smb2/connect.c +++ b/source4/torture/smb2/connect.c @@ -139,7 +139,7 @@ static NTSTATUS torture_smb2_write(struct torture_context *tctx, struct smb2_tre /* send a create */ -static struct smb2_handle torture_smb2_create(struct smb2_tree *tree, +static struct smb2_handle torture_smb2_createfile(struct smb2_tree *tree, const char *fname) { struct smb2_create io; @@ -200,8 +200,8 @@ bool torture_smb2_connect(struct torture_context *torture) return false; } - h1 = torture_smb2_create(tree, "test9.dat"); - h2 = torture_smb2_create(tree, "test9.dat"); + h1 = torture_smb2_createfile(tree, "test9.dat"); + h2 = torture_smb2_createfile(tree, "test9.dat"); status = torture_smb2_write(torture, tree, h1); if (!NT_STATUS_IS_OK(status)) { printf("Write failed - %s\n", nt_errstr(status)); diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c index fba7b8464f..0d8e4aefec 100644 --- a/source4/torture/smb2/create.c +++ b/source4/torture/smb2/create.c @@ -36,6 +36,13 @@ return false; \ }} while (0) +#define CHECK_EQUAL(v, correct) do { \ + if (v != correct) { \ + printf("(%s) Incorrect value for %s 0x%08x - should be 0x%08x\n", \ + __location__, #v, v, correct); \ + return false; \ + }} while (0) + /* test some interesting combinations found by gentest */ @@ -44,6 +51,7 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr struct smb2_create io; NTSTATUS status; TALLOC_CTX *tmp_ctx = talloc_new(tree); + uint32_t access_mask, file_attributes; ZERO_STRUCT(io); io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; @@ -74,6 +82,72 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr status = smb2_create(tree, tmp_ctx, &io); CHECK_STATUS(status, NT_STATUS_NOT_SUPPORTED); + io.in.create_options = 0; + + io.in.file_attributes = FILE_ATTRIBUTE_DEVICE; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + io.in.file_attributes = FILE_ATTRIBUTE_VOLUME; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + io.in.create_disposition = NTCREATEX_DISP_OPEN; + io.in.file_attributes = FILE_ATTRIBUTE_VOLUME; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + io.in.create_disposition = NTCREATEX_DISP_CREATE; + io.in.desired_access = 0x08000000; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); + + io.in.desired_access = 0x04000000; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); + + io.in.create_disposition = NTCREATEX_DISP_OPEN_IF; + io.in.file_attributes = 0; + access_mask = 0; + { + int i; + for (i=0;i<32;i++) { + io.in.desired_access = 1< Date: Tue, 27 May 2008 14:30:42 +1000 Subject: SEC_STD_SYNCHRONIZE is only invalid on SMB2 (This used to be commit 067f1271adaa13d537bbc92b19fe8d633cbaaf50) --- source4/ntvfs/posix/pvfs_open.c | 11 ++++++++++- source4/torture/smb2/create.c | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 328f064a57..739c127b98 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -565,6 +565,10 @@ static NTSTATUS pvfs_create_file(struct pvfs_state *pvfs, if (io->ntcreatex.in.file_attr & ~FILE_ATTRIBUTE_ALL_MASK) { return NT_STATUS_INVALID_PARAMETER; } + + if (io->ntcreatex.in.file_attr & FILE_ATTRIBUTE_ENCRYPTED) { + return NT_STATUS_ACCESS_DENIED; + } if ((io->ntcreatex.in.file_attr & FILE_ATTRIBUTE_READONLY) && (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) { @@ -1147,7 +1151,12 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, return NT_STATUS_INVALID_PARAMETER; } - if (access_mask & (SEC_MASK_INVALID | SEC_STD_SYNCHRONIZE)) { + if (access_mask & SEC_MASK_INVALID) { + return NT_STATUS_ACCESS_DENIED; + } + + if (req->ctx->protocol == PROTOCOL_SMB2 && + (access_mask & SEC_STD_SYNCHRONIZE)) { return NT_STATUS_ACCESS_DENIED; } diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c index 0d8e4aefec..3cc825bd62 100644 --- a/source4/torture/smb2/create.c +++ b/source4/torture/smb2/create.c @@ -51,7 +51,7 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr struct smb2_create io; NTSTATUS status; TALLOC_CTX *tmp_ctx = talloc_new(tree); - uint32_t access_mask, file_attributes; + uint32_t access_mask, file_attributes, denied_mask; ZERO_STRUCT(io); io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; @@ -130,6 +130,7 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; io.in.file_attributes = 0; access_mask = 0; + denied_mask = 0; { int i; for (i=0;i<32;i++) { @@ -138,6 +139,8 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr status = smb2_create(tree, tmp_ctx, &io); if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) { file_attributes |= io.in.file_attributes; + } else if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { + denied_mask |= io.in.file_attributes; } else { CHECK_STATUS(status, NT_STATUS_OK); status = smb2_util_close(tree, io.out.file.handle); @@ -146,7 +149,8 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr } } - CHECK_EQUAL(file_attributes, 0x0df0fe00); + CHECK_EQUAL(file_attributes, 0xffff87c8); + CHECK_EQUAL(denied_mask, 0x4000); talloc_free(tmp_ctx); -- cgit From 65e31a965ee6514610ec0d4ca52a5cd8772c5254 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 14:59:55 +1000 Subject: make the SEC_STD_SYNCHRONIZE test more specific (This used to be commit 8c263f91bda97eb910c8589b6cd987ec4a62d770) --- source4/ntvfs/posix/pvfs_open.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 739c127b98..cfa88b6baa 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -1155,13 +1155,16 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, return NT_STATUS_ACCESS_DENIED; } + /* what does this bit really mean?? */ if (req->ctx->protocol == PROTOCOL_SMB2 && - (access_mask & SEC_STD_SYNCHRONIZE)) { + (access_mask & SEC_STD_SYNCHRONIZE) && + !(access_mask & SEC_STD_READ_CONTROL)) { return NT_STATUS_ACCESS_DENIED; } if (io->ntcreatex.in.file_attr & (FILE_ATTRIBUTE_DEVICE| - FILE_ATTRIBUTE_VOLUME)) { + FILE_ATTRIBUTE_VOLUME| + (~FILE_ATTRIBUTE_ALL_MASK))) { return NT_STATUS_INVALID_PARAMETER; } -- cgit From 7ae464b548cc6f57b11733e5f5de36e4e1fa0265 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 15:00:05 +1000 Subject: another gentest derived test (This used to be commit bb546ab3779b235c5276ef9a714d1ca57b6815c9) --- source4/torture/smb2/create.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c index 3cc825bd62..9f7ceb20ad 100644 --- a/source4/torture/smb2/create.c +++ b/source4/torture/smb2/create.c @@ -152,6 +152,27 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr CHECK_EQUAL(file_attributes, 0xffff87c8); CHECK_EQUAL(denied_mask, 0x4000); + smb2_deltree(tree, FNAME); + + ZERO_STRUCT(io); + io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; + io.in.file_attributes = 0; + io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF; + io.in.share_access = + NTCREATEX_SHARE_ACCESS_READ| + NTCREATEX_SHARE_ACCESS_WRITE; + io.in.create_options = 0; + io.in.fname = FNAME ":stream1"; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + io.in.fname = FNAME; + io.in.file_attributes = 0x8040; + io.in.share_access = + NTCREATEX_SHARE_ACCESS_READ; + status = smb2_create(tree, tmp_ctx, &io); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + talloc_free(tmp_ctx); return true; -- cgit From cf274201b4e987faa822a137bb67fa191dabc5e8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 15:27:25 +1000 Subject: disable the SEC_STD_SYNCHRONIZE test until we know what it means (This used to be commit 897f4582bee72e319874e8a2d064ba442415571d) --- source4/ntvfs/posix/pvfs_open.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index cfa88b6baa..adcdeb1f2b 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -1155,12 +1155,14 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, return NT_STATUS_ACCESS_DENIED; } +#if 0 /* what does this bit really mean?? */ if (req->ctx->protocol == PROTOCOL_SMB2 && (access_mask & SEC_STD_SYNCHRONIZE) && !(access_mask & SEC_STD_READ_CONTROL)) { return NT_STATUS_ACCESS_DENIED; } +#endif if (io->ntcreatex.in.file_attr & (FILE_ATTRIBUTE_DEVICE| FILE_ATTRIBUTE_VOLUME| -- cgit From 848e7c5830a869d86d7fe236acc1e6a1949252d3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 16:02:10 +1000 Subject: it seems that lock flags are only validated when UNLOCK is set (This used to be commit d1bde5830cd56042236d72598e5cfe9c7abc4c47) --- source4/ntvfs/ntvfs_generic.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c index c5b88da3d1..e449e61b34 100644 --- a/source4/ntvfs/ntvfs_generic.c +++ b/source4/ntvfs/ntvfs_generic.c @@ -1044,11 +1044,12 @@ NTSTATUS ntvfs_map_lock(struct ntvfs_module_context *ntvfs, return NT_STATUS_NO_MEMORY; } for (i=0;ismb2.in.lock_count;i++) { - if (lck->smb2.in.locks[i].flags & ~SMB2_LOCK_FLAG_ALL_MASK) { - return NT_STATUS_INVALID_PARAMETER; - } if (lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_UNLOCK) { int j = lck2->generic.in.ulock_cnt; + if (lck->smb2.in.locks[i].flags & + (SMB2_LOCK_FLAG_SHARED|SMB2_LOCK_FLAG_EXCLUSIVE)) { + return NT_STATUS_INVALID_PARAMETER; + } lck2->generic.in.ulock_cnt++; lck2->generic.in.locks[j].pid = 0; lck2->generic.in.locks[j].offset = lck->smb2.in.locks[i].offset; -- cgit From 46e64417a3b14d1c33ca7e97080c64f8e67efec2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 16:02:27 +1000 Subject: another attempt at the damn SEC_STD_SYNCHRONIZE flag (This used to be commit 2ac27bfffa557d6c0f71c443b43a8d1967edb177) --- source4/ntvfs/posix/pvfs_open.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index adcdeb1f2b..908dd449af 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -1155,14 +1155,11 @@ NTSTATUS pvfs_open(struct ntvfs_module_context *ntvfs, return NT_STATUS_ACCESS_DENIED; } -#if 0 /* what does this bit really mean?? */ if (req->ctx->protocol == PROTOCOL_SMB2 && - (access_mask & SEC_STD_SYNCHRONIZE) && - !(access_mask & SEC_STD_READ_CONTROL)) { + access_mask == SEC_STD_SYNCHRONIZE) { return NT_STATUS_ACCESS_DENIED; } -#endif if (io->ntcreatex.in.file_attr & (FILE_ATTRIBUTE_DEVICE| FILE_ATTRIBUTE_VOLUME| -- cgit From c400933c02632caf0f8113594f4b0cd2afbcaef4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 16:02:43 +1000 Subject: added some SMB2 locking tests from gentest (This used to be commit 2932fcb04646bb921fb1daa365dd4c86cadfe4c0) --- source4/torture/smb2/lock.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source4/torture/smb2/lock.c b/source4/torture/smb2/lock.c index 1a56cb9cad..5f43c86b67 100644 --- a/source4/torture/smb2/lock.c +++ b/source4/torture/smb2/lock.c @@ -187,6 +187,36 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree CHECK_STATUS(status, NT_STATUS_OK); status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_OK); + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + + lck.in.lock_count = 0x0001; + lck.in.reserved = 0; + lck.in.file.handle = h; + el[0].offset = 1; + el[0].length = 1; + el[0].reserved = 0x00000000; + el[0].flags = ~SMB2_LOCK_FLAG_ALL_MASK; + + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + + el[0].flags = SMB2_LOCK_FLAG_UNLOCK | SMB2_LOCK_FLAG_EXCLUSIVE; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + el[0].flags = SMB2_LOCK_FLAG_UNLOCK | SMB2_LOCK_FLAG_SHARED; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + done: return ret; -- cgit From cb36437db2d75e7facc91cf0089f2caa20bf0ca0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 16:43:36 +1000 Subject: added support for the output fields of SMB2 close (This used to be commit 2633bc749792c224acc73a2e4ca723404331c19c) --- source4/libcli/raw/interfaces.h | 31 ++++++++++++++++---- source4/ntvfs/cifs/vfs_cifs.c | 10 +++++++ source4/ntvfs/ntvfs_generic.c | 63 +++++++++++++++++++++++++++++++++-------- source4/ntvfs/posix/pvfs_open.c | 29 +++++++++++++++++-- 4 files changed, 112 insertions(+), 21 deletions(-) diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 36d8c3abb0..68ebc19bdb 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1950,23 +1950,43 @@ union smb_lock { enum smb_close_level { RAW_CLOSE_CLOSE, RAW_CLOSE_SPLCLOSE, - RAW_CLOSE_SMB2 + RAW_CLOSE_SMB2, + RAW_CLOSE_GENERIC, }; -#define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE - /* union for close() backend call */ union smb_close { - /* SMBclose (and generic) interface */ + /* generic interface */ struct { enum smb_close_level level; struct { union smb_handle file; time_t write_time; +#define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0) + uint16_t flags; /* SMB2_CLOSE_FLAGS_* */ } in; - } close, generic; + struct { + uint16_t flags; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t alloc_size; + uint64_t size; + uint32_t file_attr; + } out; + } generic; + + /* SMBclose interface */ + struct { + enum smb_close_level level; + struct { + union smb_handle file; + time_t write_time; + } in; + } close; /* SMBsplclose interface - empty! */ struct { @@ -1984,7 +2004,6 @@ union smb_close { /* static body buffer 24 (0x18) bytes */ /* uint16_t buffer_code; 0x18 */ -#define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0) uint16_t flags; /* SMB2_CLOSE_FLAGS_* */ uint32_t _pad; } in; diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c index 2b61268733..844fa11cc5 100644 --- a/source4/ntvfs/cifs/vfs_cifs.c +++ b/source4/ntvfs/cifs/vfs_cifs.c @@ -769,6 +769,7 @@ static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs, struct cvfs_private *private = ntvfs->private_data; struct smbcli_request *c_req; struct cvfs_file *f; + union smb_close io2; SETUP_PID; @@ -776,6 +777,15 @@ static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs, private->map_generic) { return ntvfs_map_close(ntvfs, req, io); } + + if (io->generic.level == RAW_CLOSE_GENERIC) { + ZERO_STRUCT(io2); + io2.close.level = RAW_CLOSE_CLOSE; + io2.close.in.file = io->generic.in.file; + io2.close.in.write_time = io->generic.in.write_time; + io = &io2; + } + SETUP_FILE_HERE(f); /* Note, we aren't free-ing f, or it's h here. Should we? even if file-close fails, we'll remove it from the list, diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c index e449e61b34..a1c89e7df4 100644 --- a/source4/ntvfs/ntvfs_generic.c +++ b/source4/ntvfs/ntvfs_generic.c @@ -1407,6 +1407,36 @@ done: } +/* + NTVFS close generic to any mapper +*/ +static NTSTATUS ntvfs_map_close_finish(struct ntvfs_module_context *ntvfs, + struct ntvfs_request *req, + union smb_close *cl, + union smb_close *cl2, + NTSTATUS status) +{ + NT_STATUS_NOT_OK_RETURN(status); + + switch (cl->generic.level) { + case RAW_CLOSE_SMB2: + cl->smb2.out.flags = cl2->generic.out.flags; + cl->smb2.out._pad = 0; + cl->smb2.out.create_time = cl2->generic.out.create_time; + cl->smb2.out.access_time = cl2->generic.out.access_time; + cl->smb2.out.write_time = cl2->generic.out.write_time; + cl->smb2.out.change_time = cl2->generic.out.change_time; + cl->smb2.out.alloc_size = cl2->generic.out.alloc_size; + cl->smb2.out.size = cl2->generic.out.size; + cl->smb2.out.file_attr = cl2->generic.out.file_attr; + break; + default: + break; + } + + return status; +} + /* NTVFS close generic to any mapper */ @@ -1415,6 +1445,7 @@ NTSTATUS ntvfs_map_close(struct ntvfs_module_context *ntvfs, union smb_close *cl) { union smb_close *cl2; + NTSTATUS status; cl2 = talloc(req, union smb_close); if (cl2 == NULL) { @@ -1422,30 +1453,38 @@ NTSTATUS ntvfs_map_close(struct ntvfs_module_context *ntvfs, } switch (cl->generic.level) { - case RAW_CLOSE_CLOSE: + case RAW_CLOSE_GENERIC: return NT_STATUS_INVALID_LEVEL; + case RAW_CLOSE_CLOSE: + cl2->generic.level = RAW_CLOSE_GENERIC; + cl2->generic.in.file = cl->close.in.file; + cl2->generic.in.write_time = cl->close.in.write_time; + cl2->generic.in.flags = 0; + break; + case RAW_CLOSE_SPLCLOSE: - cl2->generic.level = RAW_CLOSE_CLOSE; - cl2->generic.in.file.ntvfs = cl->splclose.in.file.ntvfs; + cl2->generic.level = RAW_CLOSE_GENERIC; + cl2->generic.in.file = cl->splclose.in.file; cl2->generic.in.write_time = 0; + cl2->generic.in.flags = 0; break; case RAW_CLOSE_SMB2: - cl2->generic.level = RAW_CLOSE_CLOSE; - cl2->generic.in.file.ntvfs = cl->smb2.in.file.ntvfs; + cl2->generic.level = RAW_CLOSE_GENERIC; + cl2->generic.in.file = cl->smb2.in.file; cl2->generic.in.write_time = 0; - /* SMB2 Close has output parameter, but we just zero them */ - ZERO_STRUCT(cl->smb2.out); + cl2->generic.in.flags = cl->smb2.in.flags; break; } - /* - * we don't need to call ntvfs_map_async_setup() here, - * as close() doesn't have any output fields - */ + status = ntvfs_map_async_setup(ntvfs, req, cl, cl2, + (second_stage_t)ntvfs_map_close_finish); + NT_STATUS_NOT_OK_RETURN(status); + + status = ntvfs->ops->close(ntvfs, req, cl2); - return ntvfs->ops->close(ntvfs, req, cl2); + return ntvfs_map_async_finish(req, status); } /* diff --git a/source4/ntvfs/posix/pvfs_open.c b/source4/ntvfs/posix/pvfs_open.c index 908dd449af..49710806c7 100644 --- a/source4/ntvfs/posix/pvfs_open.c +++ b/source4/ntvfs/posix/pvfs_open.c @@ -1514,21 +1514,44 @@ NTSTATUS pvfs_close(struct ntvfs_module_context *ntvfs, return NT_STATUS_DOS(ERRSRV, ERRerror); } - if (io->generic.level != RAW_CLOSE_CLOSE) { + if (io->generic.level != RAW_CLOSE_GENERIC) { return ntvfs_map_close(ntvfs, req, io); } - f = pvfs_find_fd(pvfs, req, io->close.in.file.ntvfs); + f = pvfs_find_fd(pvfs, req, io->generic.in.file.ntvfs); if (!f) { return NT_STATUS_INVALID_HANDLE; } - if (!null_time(io->close.in.write_time)) { + if (!null_time(io->generic.in.write_time)) { unix_times.actime = 0; unix_times.modtime = io->close.in.write_time; utime(f->handle->name->full_name, &unix_times); } + if (io->generic.in.flags & SMB2_CLOSE_FLAGS_FULL_INFORMATION) { + struct pvfs_filename *name; + NTSTATUS status; + struct pvfs_file_handle *h = f->handle; + + status = pvfs_resolve_name_handle(pvfs, h); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + name = h->name; + + io->generic.out.flags = SMB2_CLOSE_FLAGS_FULL_INFORMATION; + io->generic.out.create_time = name->dos.create_time; + io->generic.out.access_time = name->dos.access_time; + io->generic.out.write_time = name->dos.write_time; + io->generic.out.change_time = name->dos.change_time; + io->generic.out.alloc_size = name->dos.alloc_size; + io->generic.out.size = name->st.st_size; + io->generic.out.file_attr = name->dos.attrib; + } else { + ZERO_STRUCT(io->generic.out); + } + talloc_free(f); return NT_STATUS_OK; -- cgit From beac55a88fd28b6003ba163f32539a7bdc2df1a6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 17:22:02 +1000 Subject: enforce lock ordering in SMB2 (This used to be commit 3bec932a89006521ba74bde7943b8cd5b4a660d8) --- source4/ntvfs/ntvfs_generic.c | 56 ++++++++++++++++---------------- source4/torture/smb2/lock.c | 74 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 31 deletions(-) diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c index a1c89e7df4..3d92c0be33 100644 --- a/source4/ntvfs/ntvfs_generic.c +++ b/source4/ntvfs/ntvfs_generic.c @@ -1027,7 +1027,7 @@ NTSTATUS ntvfs_map_lock(struct ntvfs_module_context *ntvfs, case RAW_LOCK_SMB2: { /* this is only approximate! We need to change the generic structure to fix this properly */ - int i; + int i, j; if (lck->smb2.in.lock_count < 1) { return NT_STATUS_INVALID_PARAMETER; } @@ -1044,34 +1044,36 @@ NTSTATUS ntvfs_map_lock(struct ntvfs_module_context *ntvfs, return NT_STATUS_NO_MEMORY; } for (i=0;ismb2.in.lock_count;i++) { - if (lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_UNLOCK) { - int j = lck2->generic.in.ulock_cnt; - if (lck->smb2.in.locks[i].flags & - (SMB2_LOCK_FLAG_SHARED|SMB2_LOCK_FLAG_EXCLUSIVE)) { - return NT_STATUS_INVALID_PARAMETER; - } - lck2->generic.in.ulock_cnt++; - lck2->generic.in.locks[j].pid = 0; - lck2->generic.in.locks[j].offset = lck->smb2.in.locks[i].offset; - lck2->generic.in.locks[j].count = lck->smb2.in.locks[i].length; - lck2->generic.in.locks[j].pid = 0; + if (!(lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_UNLOCK)) { + break; + } + j = lck2->generic.in.ulock_cnt; + if (lck->smb2.in.locks[i].flags & + (SMB2_LOCK_FLAG_SHARED|SMB2_LOCK_FLAG_EXCLUSIVE)) { + return NT_STATUS_INVALID_PARAMETER; } + lck2->generic.in.ulock_cnt++; + lck2->generic.in.locks[j].pid = 0; + lck2->generic.in.locks[j].offset = lck->smb2.in.locks[i].offset; + lck2->generic.in.locks[j].count = lck->smb2.in.locks[i].length; + lck2->generic.in.locks[j].pid = 0; } - for (i=0;ismb2.in.lock_count;i++) { - if (!(lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_UNLOCK)) { - int j = lck2->generic.in.ulock_cnt + - lck2->generic.in.lock_cnt; - lck2->generic.in.lock_cnt++; - lck2->generic.in.locks[j].pid = 0; - lck2->generic.in.locks[j].offset = lck->smb2.in.locks[i].offset; - lck2->generic.in.locks[j].count = lck->smb2.in.locks[i].length; - lck2->generic.in.locks[j].pid = 0; - if (!(lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_EXCLUSIVE)) { - lck2->generic.in.mode = LOCKING_ANDX_SHARED_LOCK; - } - if (lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_FAIL_IMMEDIATELY) { - lck2->generic.in.timeout = 0; - } + for (;ismb2.in.lock_count;i++) { + if (lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_UNLOCK) { + /* w2008 requires unlocks to come first */ + return NT_STATUS_INVALID_PARAMETER; + } + j = lck2->generic.in.ulock_cnt + lck2->generic.in.lock_cnt; + lck2->generic.in.lock_cnt++; + lck2->generic.in.locks[j].pid = 0; + lck2->generic.in.locks[j].offset = lck->smb2.in.locks[i].offset; + lck2->generic.in.locks[j].count = lck->smb2.in.locks[i].length; + lck2->generic.in.locks[j].pid = 0; + if (!(lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_EXCLUSIVE)) { + lck2->generic.in.mode = LOCKING_ANDX_SHARED_LOCK; + } + if (lck->smb2.in.locks[i].flags & SMB2_LOCK_FLAG_FAIL_IMMEDIATELY) { + lck2->generic.in.timeout = 0; } } /* initialize output value */ diff --git a/source4/torture/smb2/lock.c b/source4/torture/smb2/lock.c index 5f43c86b67..c708c9f770 100644 --- a/source4/torture/smb2/lock.c +++ b/source4/torture/smb2/lock.c @@ -51,7 +51,7 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree struct smb2_handle h; uint8_t buf[200]; struct smb2_lock lck; - struct smb2_lock_element el[1]; + struct smb2_lock_element el[2]; ZERO_STRUCT(buf); @@ -216,6 +216,72 @@ static bool test_valid_request(struct torture_context *torture, struct smb2_tree el[0].flags = SMB2_LOCK_FLAG_UNLOCK | SMB2_LOCK_FLAG_SHARED; status = smb2_lock(tree, &lck); CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + el[0].flags = SMB2_LOCK_FLAG_UNLOCK | SMB2_LOCK_FLAG_FAIL_IMMEDIATELY; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + + lck.in.lock_count = 2; + lck.in.reserved = 0; + lck.in.file.handle = h; + el[0].offset = 9999; + el[0].length = 1; + el[0].reserved = 0x00000000; + el[1].offset = 9999; + el[1].length = 1; + el[1].reserved = 0x00000000; + + lck.in.lock_count = 2; + el[0].flags = 0; + el[1].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); + + lck.in.lock_count = 2; + el[0].flags = 0; + el[1].flags = 0; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + lck.in.lock_count = 2; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + el[1].flags = 0; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + lck.in.lock_count = 1; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + lck.in.lock_count = 1; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + lck.in.lock_count = 1; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); + + lck.in.lock_count = 1; + el[0].flags = 0; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + lck.in.lock_count = 2; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + el[1].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_OK); + + lck.in.lock_count = 1; + el[0].flags = SMB2_LOCK_FLAG_UNLOCK; + status = smb2_lock(tree, &lck); + CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED); done: @@ -406,9 +472,9 @@ struct torture_suite *torture_smb2_lock_init(void) struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LOCK"); torture_suite_add_1smb2_test(suite, "VALID-REQUEST", test_valid_request); - torture_suite_add_1smb2_test(suite, "RW-NONE", test_lock_rw_none); - torture_suite_add_1smb2_test(suite, "RW-SHARED", test_lock_rw_shared); - torture_suite_add_1smb2_test(suite, "RW-EXCLUSIV", test_lock_rw_exclusiv); +// torture_suite_add_1smb2_test(suite, "RW-NONE", test_lock_rw_none); +// torture_suite_add_1smb2_test(suite, "RW-SHARED", test_lock_rw_shared); +// torture_suite_add_1smb2_test(suite, "RW-EXCLUSIV", test_lock_rw_exclusiv); suite->description = talloc_strdup(suite, "SMB2-LOCK tests"); -- cgit From a75d5075ea264777c5696b07140c95de5bdd456a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 18:19:22 +1000 Subject: re-enable some tests (This used to be commit c15b24a2f4346b6f07e1d5fd4f2bef7cd09cf350) --- source4/torture/smb2/lock.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source4/torture/smb2/lock.c b/source4/torture/smb2/lock.c index c708c9f770..4e21045a33 100644 --- a/source4/torture/smb2/lock.c +++ b/source4/torture/smb2/lock.c @@ -472,9 +472,9 @@ struct torture_suite *torture_smb2_lock_init(void) struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "LOCK"); torture_suite_add_1smb2_test(suite, "VALID-REQUEST", test_valid_request); -// torture_suite_add_1smb2_test(suite, "RW-NONE", test_lock_rw_none); -// torture_suite_add_1smb2_test(suite, "RW-SHARED", test_lock_rw_shared); -// torture_suite_add_1smb2_test(suite, "RW-EXCLUSIV", test_lock_rw_exclusiv); + torture_suite_add_1smb2_test(suite, "RW-NONE", test_lock_rw_none); + torture_suite_add_1smb2_test(suite, "RW-SHARED", test_lock_rw_shared); + torture_suite_add_1smb2_test(suite, "RW-EXCLUSIV", test_lock_rw_exclusiv); suite->description = talloc_strdup(suite, "SMB2-LOCK tests"); -- cgit From 4f0d968d1dd185a4f5b38c2669f520536b1f8445 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 18:20:04 +1000 Subject: added a basic SMB2 read test suite (This used to be commit 4aeda5c11414a4a7ef44da32be05209cb5caa90c) --- source4/torture/smb2/config.mk | 3 +- source4/torture/smb2/read.c | 141 +++++++++++++++++++++++++++++++++++++++++ source4/torture/smb2/smb2.c | 1 + 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 source4/torture/smb2/read.c diff --git a/source4/torture/smb2/config.mk b/source4/torture/smb2/config.mk index 6c69f3043c..9785303629 100644 --- a/source4/torture/smb2/config.mk +++ b/source4/torture/smb2/config.mk @@ -21,7 +21,8 @@ TORTURE_SMB2_OBJ_FILES = $(addprefix $(torturesrcdir)/smb2/, \ smb2.o \ persistent_handles.o \ oplocks.o \ - create.o) + create.o \ + read.o) $(eval $(call proto_header_template,$(torturesrcdir)/smb2/proto.h,$(TORTURE_SMB2_OBJ_FILES:.o=.c))) diff --git a/source4/torture/smb2/read.c b/source4/torture/smb2/read.c new file mode 100644 index 0000000000..3e1d077b7d --- /dev/null +++ b/source4/torture/smb2/read.c @@ -0,0 +1,141 @@ +/* + Unix SMB/CIFS implementation. + + SMB2 read test suite + + Copyright (C) Andrew Tridgell 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "libcli/smb2/smb2.h" +#include "libcli/smb2/smb2_calls.h" + +#include "torture/torture.h" +#include "torture/smb2/proto.h" + +#include "librpc/gen_ndr/ndr_security.h" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%s) Incorrect status %s - should be %s\n", \ + __location__, nt_errstr(status), nt_errstr(correct)); \ + ret = false; \ + goto done; \ + }} while (0) + +#define CHECK_VALUE(v, correct) do { \ + if ((v) != (correct)) { \ + printf("(%s) Incorrect value %s=%d - should be %d\n", \ + __location__, #v, v, correct); \ + ret = false; \ + goto done; \ + }} while (0) + +static bool test_read(struct torture_context *torture, struct smb2_tree *tree) +{ + bool ret = true; + NTSTATUS status; + struct smb2_handle h; + uint8_t buf[70000]; + struct smb2_read rd; + TALLOC_CTX *tmp_ctx = talloc_new(tree); + + ZERO_STRUCT(buf); + + status = torture_smb2_testfile(tree, "lock1.txt", &h); + CHECK_STATUS(status, NT_STATUS_OK); + + status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf)); + CHECK_STATUS(status, NT_STATUS_OK); + + ZERO_STRUCT(rd); + rd.in.file.handle = h; + rd.in.length = 10; + rd.in.offset = 0; + rd.in.min_count = 1; + + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(rd.out.data.length, 10); + + rd.in.min_count = 0; + rd.in.length = 10; + rd.in.offset = sizeof(buf); + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_END_OF_FILE); + + rd.in.min_count = 0; + rd.in.length = 0; + rd.in.offset = sizeof(buf); + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(rd.out.data.length, 0); + + rd.in.min_count = 1; + rd.in.length = 0; + rd.in.offset = sizeof(buf); + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_END_OF_FILE); + + rd.in.min_count = 0; + rd.in.length = 2; + rd.in.offset = sizeof(buf) - 1; + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_OK); + CHECK_VALUE(rd.out.data.length, 1); + + rd.in.min_count = 2; + rd.in.length = 1; + rd.in.offset = sizeof(buf) - 1; + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_END_OF_FILE); + + rd.in.min_count = 0x10000; + rd.in.length = 1; + rd.in.offset = 0; + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_END_OF_FILE); + + rd.in.min_count = 0x10000 - 2; + rd.in.length = 1; + rd.in.offset = 0; + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_END_OF_FILE); + + rd.in.min_count = 10; + rd.in.length = 5; + rd.in.offset = 0; + status = smb2_read(tree, tmp_ctx, &rd); + CHECK_STATUS(status, NT_STATUS_END_OF_FILE); + +done: + talloc_free(tmp_ctx); + return ret; +} + +/* basic testing of SMB2 read +*/ +struct torture_suite *torture_smb2_read_init(void) +{ + struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "READ"); + + torture_suite_add_1smb2_test(suite, "READ", test_read); + + suite->description = talloc_strdup(suite, "SMB2-READ tests"); + + return suite; +} + diff --git a/source4/torture/smb2/smb2.c b/source4/torture/smb2/smb2.c index 852effe3e2..f813148e1d 100644 --- a/source4/torture/smb2/smb2.c +++ b/source4/torture/smb2/smb2.c @@ -137,6 +137,7 @@ NTSTATUS torture_smb2_init(void) torture_suite_add_simple_test(suite, "FIND", torture_smb2_find); torture_suite_add_simple_test(suite, "CREATE", torture_smb2_create); torture_suite_add_suite(suite, torture_smb2_lock_init()); + torture_suite_add_suite(suite, torture_smb2_read_init()); torture_suite_add_simple_test(suite, "NOTIFY", torture_smb2_notify); torture_suite_add_2smb2_test(suite, "PERSISTENT-HANDLES1", torture_smb2_persistent_handles1); torture_suite_add_1smb2_test(suite, "OPLOCK-BATCH1", torture_smb2_oplock_batch1); -- cgit From 8daeee5c5d7d5851677089cceaf26a0e32675a96 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 18:20:23 +1000 Subject: ensure that we honor SMB2 read min_count properly (This used to be commit 318038d6f670efffa96d8b0db63f46b3752e1cd3) --- source4/libcli/raw/interfaces.h | 2 +- source4/ntvfs/ntvfs_generic.c | 12 +----------- source4/ntvfs/posix/pvfs_read.c | 8 ++++++++ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 68ebc19bdb..17c85138ac 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1647,7 +1647,7 @@ union smb_read { struct { union smb_handle file; uint64_t offset; - uint16_t mincnt; + uint32_t mincnt; /* enforced on SMB2, 16 bit on SMB */ uint32_t maxcnt; uint16_t remaining; bool read_for_execute; diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c index 3d92c0be33..06d89a717b 100644 --- a/source4/ntvfs/ntvfs_generic.c +++ b/source4/ntvfs/ntvfs_generic.c @@ -1295,16 +1295,6 @@ static NTSTATUS ntvfs_map_read_finish(struct ntvfs_module_context *ntvfs, rd->smb2.out.data.length= rd2->generic.out.nread; rd->smb2.out.remaining = 0; rd->smb2.out.reserved = 0; - if (NT_STATUS_IS_OK(status) && - rd->smb2.out.data.length == 0) { - status = NT_STATUS_END_OF_FILE; - } - /* SMB2 does honor the min_count field, SMB does not */ - if (NT_STATUS_IS_OK(status) && - rd->smb2.in.min_count > rd->smb2.out.data.length) { - rd->smb2.out.data.length = 0; - status = NT_STATUS_END_OF_FILE; - } break; default: return NT_STATUS_INVALID_LEVEL; @@ -1396,7 +1386,7 @@ NTSTATUS ntvfs_map_read(struct ntvfs_module_context *ntvfs, case RAW_READ_SMB2: rd2->readx.in.file.ntvfs= rd->smb2.in.file.ntvfs; rd2->readx.in.offset = rd->smb2.in.offset; - rd2->readx.in.mincnt = rd->smb2.in.length; + rd2->readx.in.mincnt = rd->smb2.in.min_count; rd2->readx.in.maxcnt = rd->smb2.in.length; rd2->readx.in.remaining = 0; rd2->readx.out.data = rd->smb2.out.data.data; diff --git a/source4/ntvfs/posix/pvfs_read.c b/source4/ntvfs/posix/pvfs_read.c index 418b7e09fb..a01a8a57e3 100644 --- a/source4/ntvfs/posix/pvfs_read.c +++ b/source4/ntvfs/posix/pvfs_read.c @@ -93,6 +93,14 @@ NTSTATUS pvfs_read(struct ntvfs_module_context *ntvfs, return pvfs_map_errno(pvfs, errno); } + /* only SMB2 honors mincnt */ + if (req->ctx->protocol == PROTOCOL_SMB2) { + if (rd->readx.in.mincnt > ret || + (ret == 0 && maxcnt > 0)) { + return NT_STATUS_END_OF_FILE; + } + } + f->handle->position = f->handle->seek_offset = rd->readx.in.offset + ret; rd->readx.out.nread = ret; -- cgit From ed3a095a5ae51d4826d79787fff03cf665319fe9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 19:10:35 +1000 Subject: fixed file_attributes test (This used to be commit 791ce0fe39a9d9e0d40b9850ff6f0cc9077fe2f1) --- source4/torture/smb2/create.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c index 9f7ceb20ad..87a53ed7cf 100644 --- a/source4/torture/smb2/create.c +++ b/source4/torture/smb2/create.c @@ -149,7 +149,7 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr } } - CHECK_EQUAL(file_attributes, 0xffff87c8); + CHECK_EQUAL(file_attributes, 0xffffbd48); CHECK_EQUAL(denied_mask, 0x4000); smb2_deltree(tree, FNAME); -- cgit From 6cdfbd838094749557ee752fee23579ce71a0d53 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 20:16:00 +1000 Subject: fixed uninitialised variable (This used to be commit 8d2e20fcb984c122fbf98cfe712b3145941d881d) --- source4/torture/smb2/create.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/torture/smb2/create.c b/source4/torture/smb2/create.c index 87a53ed7cf..9c9e7e2997 100644 --- a/source4/torture/smb2/create.c +++ b/source4/torture/smb2/create.c @@ -129,7 +129,7 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr io.in.create_disposition = NTCREATEX_DISP_OPEN_IF; io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; io.in.file_attributes = 0; - access_mask = 0; + file_attributes = 0; denied_mask = 0; { int i; @@ -149,7 +149,7 @@ bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tr } } - CHECK_EQUAL(file_attributes, 0xffffbd48); + CHECK_EQUAL(file_attributes, 0xffff8048); CHECK_EQUAL(denied_mask, 0x4000); smb2_deltree(tree, FNAME); -- cgit From 5c66b80c07bfa379971ffaed1936b43a44f4e581 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 13:38:39 +0200 Subject: Move version.o and dynconfig.o into their own directory. (This used to be commit 2cc924a412578c052a7793408300c28c8bc87c2d) --- source4/dynconfig.c | 86 ------------------------------------------- source4/dynconfig.h | 40 -------------------- source4/dynconfig.mk | 26 ------------- source4/dynconfig/config.mk | 23 ++++++++++++ source4/dynconfig/dynconfig.c | 86 +++++++++++++++++++++++++++++++++++++++++++ source4/dynconfig/dynconfig.h | 40 ++++++++++++++++++++ source4/dynconfig/version.c | 27 ++++++++++++++ source4/lib/version.c | 27 -------------- source4/main.mk | 3 +- source4/param/config.mk | 2 +- 10 files changed, 179 insertions(+), 181 deletions(-) delete mode 100644 source4/dynconfig.c delete mode 100644 source4/dynconfig.h delete mode 100644 source4/dynconfig.mk create mode 100644 source4/dynconfig/config.mk create mode 100644 source4/dynconfig/dynconfig.c create mode 100644 source4/dynconfig/dynconfig.h create mode 100644 source4/dynconfig/version.c delete mode 100644 source4/lib/version.c diff --git a/source4/dynconfig.c b/source4/dynconfig.c deleted file mode 100644 index 6dbbf872d9..0000000000 --- a/source4/dynconfig.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Copyright (C) 2001 by Martin Pool - Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003. - Copyright (C) Stefan Metzmacher 2003 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" - -/** - * @file dynconfig.c - * - * @brief Global configurations, initialized to configured defaults. - * - * This file should be the only file that depends on path - * configuration (--prefix, etc), so that if ./configure is re-run, - * all programs will be appropriately updated. Everything else in - * Samba should import extern variables from here, rather than relying - * on preprocessor macros. - * - * Eventually some of these may become even more variable, so that - * they can for example consistently be set across the whole of Samba - * by command-line parameters, config file entries, or environment - * variables. - * - * @todo Perhaps eventually these should be merged into the parameter - * table? There's kind of a chicken-and-egg situation there... - **/ - -/** Directory with generic binaries */ -_PUBLIC_ const char *dyn_BINDIR = BINDIR; - -/**< Location of smb.conf file. **/ -_PUBLIC_ const char *dyn_CONFIGFILE = CONFIGFILE; - -/** Log file directory. **/ -_PUBLIC_ const char *dyn_LOGFILEBASE = LOGFILEBASE; - -/** Directory for local RPC (ncalrpc: transport) */ -_PUBLIC_ const char *dyn_NCALRPCDIR = NCALRPCDIR; - -/** Statically configured LanMan hosts. **/ -_PUBLIC_ const char *dyn_LMHOSTSFILE = LMHOSTSFILE; - -/** Samba data directory. */ -_PUBLIC_ const char *dyn_DATADIR = DATADIR; - -_PUBLIC_ const char *dyn_MODULESDIR = MODULESDIR; - -/** - * @brief Directory holding lock files. - * - * Not writable, but used to set a default in the parameter table. - **/ -_PUBLIC_ const char *dyn_LOCKDIR = LOCKDIR; - -/** pid file directory */ -_PUBLIC_ const char *dyn_PIDDIR = PIDDIR; - -/** Private data directory; holds ldb files and the like */ -_PUBLIC_ const char *dyn_PRIVATE_DIR = PRIVATE_DIR; - -/** SWAT directory */ -_PUBLIC_ const char *dyn_SWATDIR = SWATDIR; - -/** SETUP files (source files used by the provision) */ -_PUBLIC_ const char *dyn_SETUPDIR = SETUPDIR; - -/** EJS Javascript library includes */ -_PUBLIC_ const char *dyn_JSDIR = JSDIR; - -/** Where to find the winbindd socket */ -_PUBLIC_ const char *dyn_WINBINDD_SOCKET_DIR = WINBINDD_SOCKET_DIR; diff --git a/source4/dynconfig.h b/source4/dynconfig.h deleted file mode 100644 index ac54db63d6..0000000000 --- a/source4/dynconfig.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Copyright (C) 2001 by Martin Pool - Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003. - - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file dynconfig.h - * - * @brief Exported global configurations. - **/ - -extern const char *dyn_BINDIR; -extern const char *dyn_CONFIGFILE; -extern const char *dyn_NCALRPCDIR; -extern const char *dyn_LOGFILEBASE; -extern const char *dyn_LMHOSTSFILE; -extern const char *dyn_DATADIR; -extern const char *dyn_MODULESDIR; -extern const char *dyn_LOCKDIR; -extern const char *dyn_PIDDIR; -extern const char *dyn_PRIVATE_DIR; -extern const char *dyn_SWATDIR; -extern const char *dyn_JSDIR; -extern const char *dyn_SETUPDIR; -extern const char *dyn_WINBINDD_SOCKET_DIR; diff --git a/source4/dynconfig.mk b/source4/dynconfig.mk deleted file mode 100644 index f365911c6a..0000000000 --- a/source4/dynconfig.mk +++ /dev/null @@ -1,26 +0,0 @@ -[SUBSYSTEM::DYNCONFIG] - -DYNCONFIG_OBJ_FILES = dynconfig.o - -# set these to where to find various files -# These can be overridden by command line switches (see smbd(8)) -# or in smb.conf (see smb.conf(5)) -CONFIGFILE = $(sysconfdir)/smb.conf -PKGCONFIGDIR = $(libdir)/pkgconfig -LMHOSTSFILE = $(sysconfdir)/lmhosts - -dynconfig.o: dynconfig.c Makefile - @echo Compiling $< - @$(CC) $(CFLAGS) $(CPPFLAGS) $(PICFLAG) -c $< -o $@ \ - -DCONFIGFILE=\"$(CONFIGFILE)\" -DBINDIR=\"$(bindir)\" \ - -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" \ - -DLOCKDIR=\"$(lockdir)\" -DPIDDIR=\"$(piddir)\" -DDATADIR=\"$(datadir)\" \ - -DLOGFILEBASE=\"$(logfilebase)\" \ - -DCONFIGDIR=\"$(sysconfdir)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\" \ - -DSWATDIR=\"$(SWATDIR)\" \ - -DPRIVATE_DIR=\"$(privatedir)\" \ - -DMODULESDIR=\"$(modulesdir)\" -DJSDIR=\"$(JSDIR)\" \ - -DTORTUREDIR=\"$(TORTUREDIR)\" \ - -DSETUPDIR=\"$(SETUPDIR)\" -DWINBINDD_SOCKET_DIR=\"$(winbindd_socket_dir)\" - - diff --git a/source4/dynconfig/config.mk b/source4/dynconfig/config.mk new file mode 100644 index 0000000000..5f2887f8b6 --- /dev/null +++ b/source4/dynconfig/config.mk @@ -0,0 +1,23 @@ +[SUBSYSTEM::DYNCONFIG] + +DYNCONFIG_OBJ_FILES = $(dynconfigsrcdir)/dynconfig.o \ + $(dynconfigsrcdir)/version.o + +# set these to where to find various files +# These can be overridden by command line switches (see smbd(8)) +# or in smb.conf (see smb.conf(5)) +CONFIGFILE = $(sysconfdir)/smb.conf +PKGCONFIGDIR = $(libdir)/pkgconfig +LMHOSTSFILE = $(sysconfdir)/lmhosts + +$(dynconfigsrcdir)/dynconfig.o: CFLAGS+=-DCONFIGFILE=\"$(CONFIGFILE)\" -DBINDIR=\"$(bindir)\" \ + -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" \ + -DLOCKDIR=\"$(lockdir)\" -DPIDDIR=\"$(piddir)\" -DDATADIR=\"$(datadir)\" \ + -DLOGFILEBASE=\"$(logfilebase)\" \ + -DCONFIGDIR=\"$(sysconfdir)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\" \ + -DSWATDIR=\"$(SWATDIR)\" \ + -DPRIVATE_DIR=\"$(privatedir)\" \ + -DMODULESDIR=\"$(modulesdir)\" -DJSDIR=\"$(JSDIR)\" \ + -DTORTUREDIR=\"$(TORTUREDIR)\" \ + -DSETUPDIR=\"$(SETUPDIR)\" -DWINBINDD_SOCKET_DIR=\"$(winbindd_socket_dir)\" + diff --git a/source4/dynconfig/dynconfig.c b/source4/dynconfig/dynconfig.c new file mode 100644 index 0000000000..6dbbf872d9 --- /dev/null +++ b/source4/dynconfig/dynconfig.c @@ -0,0 +1,86 @@ +/* + Unix SMB/CIFS implementation. + Copyright (C) 2001 by Martin Pool + Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003. + Copyright (C) Stefan Metzmacher 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" + +/** + * @file dynconfig.c + * + * @brief Global configurations, initialized to configured defaults. + * + * This file should be the only file that depends on path + * configuration (--prefix, etc), so that if ./configure is re-run, + * all programs will be appropriately updated. Everything else in + * Samba should import extern variables from here, rather than relying + * on preprocessor macros. + * + * Eventually some of these may become even more variable, so that + * they can for example consistently be set across the whole of Samba + * by command-line parameters, config file entries, or environment + * variables. + * + * @todo Perhaps eventually these should be merged into the parameter + * table? There's kind of a chicken-and-egg situation there... + **/ + +/** Directory with generic binaries */ +_PUBLIC_ const char *dyn_BINDIR = BINDIR; + +/**< Location of smb.conf file. **/ +_PUBLIC_ const char *dyn_CONFIGFILE = CONFIGFILE; + +/** Log file directory. **/ +_PUBLIC_ const char *dyn_LOGFILEBASE = LOGFILEBASE; + +/** Directory for local RPC (ncalrpc: transport) */ +_PUBLIC_ const char *dyn_NCALRPCDIR = NCALRPCDIR; + +/** Statically configured LanMan hosts. **/ +_PUBLIC_ const char *dyn_LMHOSTSFILE = LMHOSTSFILE; + +/** Samba data directory. */ +_PUBLIC_ const char *dyn_DATADIR = DATADIR; + +_PUBLIC_ const char *dyn_MODULESDIR = MODULESDIR; + +/** + * @brief Directory holding lock files. + * + * Not writable, but used to set a default in the parameter table. + **/ +_PUBLIC_ const char *dyn_LOCKDIR = LOCKDIR; + +/** pid file directory */ +_PUBLIC_ const char *dyn_PIDDIR = PIDDIR; + +/** Private data directory; holds ldb files and the like */ +_PUBLIC_ const char *dyn_PRIVATE_DIR = PRIVATE_DIR; + +/** SWAT directory */ +_PUBLIC_ const char *dyn_SWATDIR = SWATDIR; + +/** SETUP files (source files used by the provision) */ +_PUBLIC_ const char *dyn_SETUPDIR = SETUPDIR; + +/** EJS Javascript library includes */ +_PUBLIC_ const char *dyn_JSDIR = JSDIR; + +/** Where to find the winbindd socket */ +_PUBLIC_ const char *dyn_WINBINDD_SOCKET_DIR = WINBINDD_SOCKET_DIR; diff --git a/source4/dynconfig/dynconfig.h b/source4/dynconfig/dynconfig.h new file mode 100644 index 0000000000..ac54db63d6 --- /dev/null +++ b/source4/dynconfig/dynconfig.h @@ -0,0 +1,40 @@ +/* + Unix SMB/CIFS implementation. + Copyright (C) 2001 by Martin Pool + Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003. + + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file dynconfig.h + * + * @brief Exported global configurations. + **/ + +extern const char *dyn_BINDIR; +extern const char *dyn_CONFIGFILE; +extern const char *dyn_NCALRPCDIR; +extern const char *dyn_LOGFILEBASE; +extern const char *dyn_LMHOSTSFILE; +extern const char *dyn_DATADIR; +extern const char *dyn_MODULESDIR; +extern const char *dyn_LOCKDIR; +extern const char *dyn_PIDDIR; +extern const char *dyn_PRIVATE_DIR; +extern const char *dyn_SWATDIR; +extern const char *dyn_JSDIR; +extern const char *dyn_SETUPDIR; +extern const char *dyn_WINBINDD_SOCKET_DIR; diff --git a/source4/dynconfig/version.c b/source4/dynconfig/version.c new file mode 100644 index 0000000000..e81f463586 --- /dev/null +++ b/source4/dynconfig/version.c @@ -0,0 +1,27 @@ +/* + Unix SMB/CIFS implementation. + Samba Version functions + + Copyright (C) Stefan Metzmacher 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "version.h" + +const char *samba_version_string(void) +{ + return SAMBA_VERSION_STRING; +} diff --git a/source4/lib/version.c b/source4/lib/version.c deleted file mode 100644 index e81f463586..0000000000 --- a/source4/lib/version.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba Version functions - - Copyright (C) Stefan Metzmacher 2003 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "includes.h" -#include "version.h" - -const char *samba_version_string(void) -{ - return SAMBA_VERSION_STRING; -} diff --git a/source4/main.mk b/source4/main.mk index 90473cce93..b0de9525c1 100644 --- a/source4/main.mk +++ b/source4/main.mk @@ -1,4 +1,5 @@ -mkinclude dynconfig.mk +dynconfigsrcdir := dynconfig +mkinclude dynconfig/config.mk heimdalsrcdir := heimdal mkinclude heimdal_build/config.mk mkinclude config.mk diff --git a/source4/param/config.mk b/source4/param/config.mk index 02474d50b9..c169ce157e 100644 --- a/source4/param/config.mk +++ b/source4/param/config.mk @@ -6,7 +6,7 @@ LIBSAMBA-HOSTCONFIG_VERSION = 0.0.1 LIBSAMBA-HOSTCONFIG_SOVERSION = 0 LIBSAMBA-HOSTCONFIG_OBJ_FILES = $(addprefix $(paramsrcdir)/, \ - loadparm.o generic.o util.o) lib/version.o + loadparm.o generic.o util.o) PUBLIC_HEADERS += param/param.h -- cgit From 4fc224f48e28da253ebe5d7b44c766ac4a7e147c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:14:45 +0200 Subject: Use variable for ldb source directory. (This used to be commit 48bfce0ea51b952baef5bfa667405e8742e5016f) --- source4/lib/ldb/config.mk | 50 ++++++++++++++++++------------------- source4/lib/ldb/ldb_ildap/config.mk | 4 +-- source4/lib/ldb/python.mk | 6 ++--- source4/lib/ldb/tools/config.mk | 16 ++++++------ 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk index e8852980f6..d63b440788 100644 --- a/source4/lib/ldb/config.mk +++ b/source4/lib/ldb/config.mk @@ -2,11 +2,11 @@ # Start MODULE ldb_asq [MODULE::ldb_asq] PRIVATE_DEPENDENCIES = LIBTALLOC -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include INIT_FUNCTION = LDB_MODULE(asq) SUBSYSTEM = LIBLDB -ldb_asq_OBJ_FILES = lib/ldb/modules/asq.o +ldb_asq_OBJ_FILES = $(ldbdir)/modules/asq.o # End MODULE ldb_asq ################################################ @@ -14,106 +14,106 @@ ldb_asq_OBJ_FILES = lib/ldb/modules/asq.o # Start MODULE ldb_server_sort [MODULE::ldb_server_sort] PRIVATE_DEPENDENCIES = LIBTALLOC -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include INIT_FUNCTION = LDB_MODULE(server_sort) SUBSYSTEM = LIBLDB # End MODULE ldb_sort ################################################ -ldb_server_sort_OBJ_FILES = lib/ldb/modules/sort.o +ldb_server_sort_OBJ_FILES = $(ldbdir)/modules/sort.o ################################################ # Start MODULE ldb_paged_results [MODULE::ldb_paged_results] INIT_FUNCTION = LDB_MODULE(paged_results) -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include PRIVATE_DEPENDENCIES = LIBTALLOC SUBSYSTEM = LIBLDB # End MODULE ldb_paged_results ################################################ -ldb_paged_results_OBJ_FILES = lib/ldb/modules/paged_results.o +ldb_paged_results_OBJ_FILES = $(ldbdir)/modules/paged_results.o ################################################ # Start MODULE ldb_paged_results [MODULE::ldb_paged_searches] INIT_FUNCTION = LDB_MODULE(paged_searches) -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include PRIVATE_DEPENDENCIES = LIBTALLOC SUBSYSTEM = LIBLDB # End MODULE ldb_paged_results ################################################ -ldb_paged_searches_OBJ_FILES = lib/ldb/modules/paged_searches.o +ldb_paged_searches_OBJ_FILES = $(ldbdir)/modules/paged_searches.o ################################################ # Start MODULE ldb_operational [MODULE::ldb_operational] SUBSYSTEM = LIBLDB -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include PRIVATE_DEPENDENCIES = LIBTALLOC INIT_FUNCTION = LDB_MODULE(operational) # End MODULE ldb_operational ################################################ -ldb_operational_OBJ_FILES = lib/ldb/modules/operational.o +ldb_operational_OBJ_FILES = $(ldbdir)/modules/operational.o ################################################ # Start MODULE ldb_rdn_name [MODULE::ldb_rdn_name] SUBSYSTEM = LIBLDB -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include PRIVATE_DEPENDENCIES = LIBTALLOC INIT_FUNCTION = LDB_MODULE(rdn_name) # End MODULE ldb_rdn_name ################################################ -ldb_rdn_name_OBJ_FILES = lib/ldb/modules/rdn_name.o +ldb_rdn_name_OBJ_FILES = $(ldbdir)/modules/rdn_name.o -ldb_map_OBJ_FILES = $(addprefix lib/ldb/ldb_map/, ldb_map_inbound.o ldb_map_outbound.o ldb_map.o) +ldb_map_OBJ_FILES = $(addprefix $(ldbdir)/ldb_map/, ldb_map_inbound.o ldb_map_outbound.o ldb_map.o) -$(ldb_map_OBJ_FILES): CFLAGS+=-Ilib/ldb/ldb_map +$(ldb_map_OBJ_FILES): CFLAGS+=-I$(ldbdir)/ldb_map ################################################ # Start MODULE ldb_skel [MODULE::ldb_skel] SUBSYSTEM = LIBLDB -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include PRIVATE_DEPENDENCIES = LIBTALLOC INIT_FUNCTION = LDB_MODULE(skel) # End MODULE ldb_skel ################################################ -ldb_skel_OBJ_FILES = lib/ldb/modules/skel.o +ldb_skel_OBJ_FILES = $(ldbdir)/modules/skel.o ################################################ # Start MODULE ldb_sqlite3 [MODULE::ldb_sqlite3] SUBSYSTEM = LIBLDB -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include PRIVATE_DEPENDENCIES = LIBTALLOC SQLITE3 LIBTALLOC # End MODULE ldb_sqlite3 ################################################ -ldb_sqlite3_OBJ_FILES = lib/ldb/ldb_sqlite3/ldb_sqlite3.o +ldb_sqlite3_OBJ_FILES = $(ldbdir)/ldb_sqlite3/ldb_sqlite3.o ################################################ # Start MODULE ldb_tdb [MODULE::ldb_tdb] SUBSYSTEM = LIBLDB -CFLAGS = -Ilib/ldb/include -Ilib/ldb/ldb_tdb +CFLAGS = -I$(ldbdir)/include -I$(ldbdir)/ldb_tdb PRIVATE_DEPENDENCIES = \ LIBTDB LIBTALLOC # End MODULE ldb_tdb ################################################ -ldb_tdb_OBJ_FILES = $(addprefix lib/ldb/ldb_tdb/, ldb_tdb.o ldb_search.o ldb_pack.o ldb_index.o ldb_cache.o ldb_tdb_wrap.o) +ldb_tdb_OBJ_FILES = $(addprefix $(ldbdir)/ldb_tdb/, ldb_tdb.o ldb_search.o ldb_pack.o ldb_index.o ldb_cache.o ldb_tdb_wrap.o) ################################################ # Start SUBSYSTEM ldb [LIBRARY::LIBLDB] -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include INIT_FUNCTION_TYPE = extern const struct ldb_module_ops PUBLIC_DEPENDENCIES = \ LIBTALLOC @@ -128,7 +128,7 @@ PC_FILES += $(ldbdir)/ldb.pc LIBLDB_VERSION = 0.0.1 LIBLDB_SOVERSION = 0 -LIBLDB_OBJ_FILES = $(addprefix lib/ldb/common/, ldb.o ldb_ldif.o ldb_parse.o ldb_msg.o ldb_utf8.o ldb_debug.o ldb_modules.o ldb_match.o ldb_attributes.o attrib_handlers.o ldb_dn.o ldb_controls.o qsort.o) $(ldb_map_OBJ_FILES) +LIBLDB_OBJ_FILES = $(addprefix $(ldbdir)/common/, ldb.o ldb_ldif.o ldb_parse.o ldb_msg.o ldb_utf8.o ldb_debug.o ldb_modules.o ldb_match.o ldb_attributes.o attrib_handlers.o ldb_dn.o ldb_controls.o qsort.o) $(ldb_map_OBJ_FILES) PUBLIC_HEADERS += $(ldbdir)/include/ldb.h $(ldbdir)/include/ldb_errors.h @@ -142,7 +142,7 @@ PRIVATE_DEPENDENCIES = \ # End BINARY ldbtest ################################################ -ldbtest_OBJ_FILES = lib/ldb/tools/ldbtest.o +ldbtest_OBJ_FILES = $(ldbdir)/tools/ldbtest.o ################################################ # Start BINARY oLschema2ldif @@ -154,7 +154,7 @@ PRIVATE_DEPENDENCIES = \ ################################################ -oLschema2ldif_OBJ_FILES = $(addprefix lib/ldb/tools/, convert.o oLschema2ldif.o) +oLschema2ldif_OBJ_FILES = $(addprefix $(ldbdir)/tools/, convert.o oLschema2ldif.o) MANPAGES += $(ldbdir)/man/oLschema2ldif.1 @@ -167,7 +167,7 @@ PRIVATE_DEPENDENCIES = \ # End BINARY ad2oLschema ################################################ -ad2oLschema_OBJ_FILES = $(addprefix lib/ldb/tools/, convert.o ad2oLschema.o) +ad2oLschema_OBJ_FILES = $(addprefix $(ldbdir)/tools/, convert.o ad2oLschema.o) MANPAGES += $(ldbdir)/man/ad2oLschema.1 diff --git a/source4/lib/ldb/ldb_ildap/config.mk b/source4/lib/ldb/ldb_ildap/config.mk index 1b534645b6..94e3380038 100644 --- a/source4/lib/ldb/ldb_ildap/config.mk +++ b/source4/lib/ldb/ldb_ildap/config.mk @@ -2,12 +2,12 @@ # Start MODULE ldb_ildap [MODULE::ldb_ildap] SUBSYSTEM = LIBLDB -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include OUTPUT_TYPE = SHARED_LIBRARY PRIVATE_DEPENDENCIES = LIBTALLOC LIBCLI_LDAP CREDENTIALS ALIASES = ldapi ldaps ldap # End MODULE ldb_ildap ################################################ -ldb_ildap_OBJ_FILES = lib/ldb/ldb_ildap/ldb_ildap.o +ldb_ildap_OBJ_FILES = $(ldbdir)/ldb_ildap/ldb_ildap.o diff --git a/source4/lib/ldb/python.mk b/source4/lib/ldb/python.mk index 89aba8f276..96ae6a5720 100644 --- a/source4/lib/ldb/python.mk +++ b/source4/lib/ldb/python.mk @@ -1,10 +1,10 @@ [PYTHON::swig_ldb] LIBRARY_REALNAME = _ldb.$(SHLIBEXT) PUBLIC_DEPENDENCIES = LIBLDB -CFLAGS = -Ilib/ldb/include +CFLAGS = -I$(ldbdir)/include -swig_ldb_OBJ_FILES = lib/ldb/ldb_wrap.o +swig_ldb_OBJ_FILES = $(ldbdir)/ldb_wrap.o -$(eval $(call python_py_module_template,ldb.py,lib/ldb/ldb.py)) +$(eval $(call python_py_module_template,ldb.py,$(ldbdir)/ldb.py)) $(swig_ldb_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL) diff --git a/source4/lib/ldb/tools/config.mk b/source4/lib/ldb/tools/config.mk index 6729636434..051fd0c57b 100644 --- a/source4/lib/ldb/tools/config.mk +++ b/source4/lib/ldb/tools/config.mk @@ -1,13 +1,13 @@ ################################################ # Start SUBSYSTEM LIBLDB_CMDLINE [SUBSYSTEM::LIBLDB_CMDLINE] -CFLAGS = -Ilib/ldb -Ilib/ldb/include +CFLAGS = -I$(ldbdir) -I$(ldbdir)/include PUBLIC_DEPENDENCIES = LIBLDB LIBPOPT PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL POPT_SAMBA POPT_CREDENTIALS gensec # End SUBSYSTEM LIBLDB_CMDLINE ################################################ -LIBLDB_CMDLINE_OBJ_FILES = lib/ldb/tools/cmdline.o +LIBLDB_CMDLINE_OBJ_FILES = $(ldbdir)/tools/cmdline.o ################################################ # Start BINARY ldbadd @@ -19,7 +19,7 @@ PRIVATE_DEPENDENCIES = \ ################################################ -ldbadd_OBJ_FILES = lib/ldb/tools/ldbadd.o +ldbadd_OBJ_FILES = $(ldbdir)/tools/ldbadd.o MANPAGES += $(ldbdir)/man/ldbadd.1 @@ -32,7 +32,7 @@ PRIVATE_DEPENDENCIES = \ # End BINARY ldbdel ################################################ -ldbdel_OBJ_FILES = lib/ldb/tools/ldbdel.o +ldbdel_OBJ_FILES = $(ldbdir)/tools/ldbdel.o MANPAGES += $(ldbdir)/man/ldbdel.1 @@ -45,7 +45,7 @@ PRIVATE_DEPENDENCIES = \ # End BINARY ldbmodify ################################################ -ldbmodify_OBJ_FILES = lib/ldb/tools/ldbmodify.o +ldbmodify_OBJ_FILES = $(ldbdir)/tools/ldbmodify.o MANPAGES += $(ldbdir)/man/ldbmodify.1 ################################################ @@ -57,7 +57,7 @@ PRIVATE_DEPENDENCIES = \ # End BINARY ldbsearch ################################################ -ldbsearch_OBJ_FILES = lib/ldb/tools/ldbsearch.o +ldbsearch_OBJ_FILES = $(ldbdir)/tools/ldbsearch.o MANPAGES += $(ldbdir)/man/ldbsearch.1 @@ -70,7 +70,7 @@ PRIVATE_DEPENDENCIES = \ # End BINARY ldbedit ################################################ -ldbedit_OBJ_FILES = lib/ldb/tools/ldbedit.o +ldbedit_OBJ_FILES = $(ldbdir)/tools/ldbedit.o MANPAGES += $(ldbdir)/man/ldbedit.1 @@ -83,7 +83,7 @@ PRIVATE_DEPENDENCIES = \ # End BINARY ldbrename ################################################ -ldbrename_OBJ_FILES = lib/ldb/tools/ldbrename.o +ldbrename_OBJ_FILES = $(ldbdir)/tools/ldbrename.o MANPAGES += $(ldbdir)/man/ldbrename.1 -- cgit From 3d2d3060f21af273257c4007cfd67516e7e3453d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:27:53 +0200 Subject: Use variable for source directories. (This used to be commit e40fc0bc4bcf91c35baba1230354d3185a34076e) --- source4/heimdal_build/config.mk | 48 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index a4f24c9026..8011284210 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -1,7 +1,9 @@ +heimdalbuildsrcdir = $(heimdalsrcdir)/../heimdal_build + ####################### # Start SUBSYSTEM HEIMDAL_KDC [SUBSYSTEM::HEIMDAL_KDC] -CFLAGS = -Iheimdal_build -Iheimdal/kdc +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/kdc PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN HEIMDAL_KRB5 HEIMDAL_HDB HEIMDAL_HEIM_ASN1 HEIMDAL_DIGEST_ASN1 HEIMDAL_KX509_ASN1 PUBLIC_DEPENDENCIES = HEIMDAL_NTLM HEIMDAL_HCRYPTO # End SUBSYSTEM HEIMDAL_KDC @@ -24,14 +26,14 @@ HEIMDAL_KDC_OBJ_FILES = \ $(heimdalsrcdir)/kdc/kx509.o [SUBSYSTEM::HEIMDAL_NTLM] -CFLAGS = -Iheimdal_build -Iheimdal/lib/ntlm +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/ntlm PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN HEIMDAL_HCRYPTO HEIMDAL_KRB5 HEIMDAL_NTLM_OBJ_FILES = \ $(heimdalsrcdir)/lib/ntlm/ntlm.o [SUBSYSTEM::HEIMDAL_HDB_KEYS] -CFLAGS = -Iheimdal_build -Iheimdal/lib/hdb +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/hdb PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN HEIMDAL_HCRYPTO HEIMDAL_KRB5 \ HEIMDAL_HDB_ASN1 @@ -40,7 +42,7 @@ HEIMDAL_HDB_KEYS_OBJ_FILES = $(heimdalsrcdir)/lib/hdb/keys.o ####################### # Start SUBSYSTEM HEIMDAL_HDB [SUBSYSTEM::HEIMDAL_HDB] -CFLAGS = -Iheimdal_build -Iheimdal/lib/hdb +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/hdb PRIVATE_DEPENDENCIES = HDB_LDB HEIMDAL_KRB5 HEIMDAL_HDB_KEYS HEIMDAL_ROKEN HEIMDAL_HCRYPTO HEIMDAL_COM_ERR HEIMDAL_HDB_ASN1 # End SUBSYSTEM HEIMDAL_HDB ####################### @@ -58,7 +60,7 @@ HEIMDAL_HDB_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_GSSAPI [SUBSYSTEM::HEIMDAL_GSSAPI] -CFLAGS = -Iheimdal_build -Iheimdal/lib/gssapi -Iheimdal/lib/gssapi/gssapi -Iheimdal/lib/gssapi/spnego -Iheimdal/lib/gssapi/krb5 -Iheimdal/lib/gssapi/mech +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/gssapi -I$(heimdalsrcdir)/lib/gssapi/gssapi -I$(heimdalsrcdir)/lib/gssapi/spnego -I$(heimdalsrcdir)/lib/gssapi/krb5 -I$(heimdalsrcdir)/lib/gssapi/mech PRIVATE_DEPENDENCIES = HEIMDAL_HCRYPTO HEIMDAL_HEIM_ASN1 HEIMDAL_SPNEGO_ASN1 PUBLIC_DEPENDENCIES = HEIMDAL_ROKEN HEIMDAL_KRB5 # End SUBSYSTEM HEIMDAL_GSSAPI @@ -176,7 +178,7 @@ HEIMDAL_GSSAPI_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_KRB5 [SUBSYSTEM::HEIMDAL_KRB5] -CFLAGS = -Iheimdal_build -Iheimdal/lib/krb5 -Iheimdal/lib/asn1 -Iheimdal/lib/com_err +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/krb5 -I$(heimdalsrcdir)/lib/asn1 -I$(heimdalsrcdir)/lib/com_err PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN HEIMDAL_PKINIT_ASN1 HEIMDAL_WIND PUBLIC_DEPENDENCIES = HEIMDAL_KRB5_ASN1 HEIMDAL_GLUE HEIMDAL_HX509 HEIMDAL_HCRYPTO # End SUBSYSTEM HEIMDAL_KRB5 @@ -273,7 +275,7 @@ HEIMDAL_KRB5_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_HEIM_ASN1 [SUBSYSTEM::HEIMDAL_HEIM_ASN1] -CFLAGS = -Iheimdal_build -Iheimdal/lib/asn1 +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/asn1 PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN HEIMDAL_COM_ERR # End SUBSYSTEM HEIMDAL_KRB5 ####################### @@ -293,7 +295,7 @@ HEIMDAL_HEIM_ASN1_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_HCRYPTO_IMATH [SUBSYSTEM::HEIMDAL_HCRYPTO_IMATH] -CFLAGS = -Iheimdal_build -Iheimdal/lib/hcrypto/imath +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/hcrypto/imath PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN # End SUBSYSTEM HEIMDAL_HCRYPTO_IMATH ####################### @@ -303,7 +305,7 @@ HEIMDAL_HCRYPTO_IMATH_OBJ_FILES = \ $(heimdalsrcdir)/lib/hcrypto/imath/iprime.o [SUBSYSTEM::HEIMDAL_HCRYPTO] -CFLAGS = -Iheimdal_build -Iheimdal/lib/hcrypto -Iheimdal/lib +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/hcrypto -I$(heimdalsrcdir)/lib PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN HEIMDAL_HEIM_ASN1 HEIMDAL_HCRYPTO_IMATH HEIMDAL_RFC2459_ASN1 # End SUBSYSTEM HEIMDAL_HCRYPTO ####################### @@ -343,7 +345,7 @@ HEIMDAL_HCRYPTO_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_HX509 [SUBSYSTEM::HEIMDAL_HX509] -CFLAGS = -Iheimdal_build -Iheimdal/lib/hx509 +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/hx509 PRIVATE_DEPENDENCIES = \ HEIMDAL_ROKEN HEIMDAL_COM_ERR \ HEIMDAL_HEIM_ASN1 HEIMDAL_HCRYPTO \ @@ -383,7 +385,7 @@ HEIMDAL_HX509_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_WIND [SUBSYSTEM::HEIMDAL_WIND] -CFLAGS = -Iheimdal_build -Iheimdal/lib/wind +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/wind PRIVATE_DEPENDENCIES = \ HEIMDAL_ROKEN HEIMDAL_COM_ERR @@ -406,24 +408,24 @@ HEIMDAL_WIND_OBJ_FILES = \ ####################### [SUBSYSTEM::HEIMDAL_ROKEN_GETPROGNAME] -CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper HEIMDAL_ROKEN_GETPROGNAME_OBJ_FILES = $(heimdalsrcdir)/lib/roken/getprogname.o [SUBSYSTEM::HEIMDAL_ROKEN_CLOSEFROM] -CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper HEIMDAL_ROKEN_CLOSEFROM_OBJ_FILES = $(heimdalsrcdir)/lib/roken/closefrom.o [SUBSYSTEM::HEIMDAL_ROKEN_GETPROGNAME_H] -CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper HEIMDAL_ROKEN_GETPROGNAME_H_OBJ_FILES = $(heimdalsrcdir)/lib/roken/getprogname.ho ####################### # Start SUBSYSTEM HEIMDAL_ROKEN [SUBSYSTEM::HEIMDAL_ROKEN] -CFLAGS = -Iheimdal_build -Iheimdal/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper PUBLIC_DEPENDENCIES = \ HEIMDAL_ROKEN_GETPROGNAME \ HEIMDAL_ROKEN_CLOSEFROM \ @@ -466,7 +468,7 @@ HEIMDAL_ROKEN_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_GLUE [SUBSYSTEM::HEIMDAL_GLUE] -CFLAGS = -Iheimdal_build -Iheimdal/lib/krb5 -Iheimdal/lib/asn1 -Iheimdal/lib/com_err +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/krb5 -I$(heimdalsrcdir)/lib/asn1 -I$(heimdalsrcdir)/lib/com_err PUBLIC_DEPENDENCIES = LIBNETIF LIBSAMBA-HOSTCONFIG # End SUBSYSTEM HEIMDAL_GLUE ####################### @@ -476,7 +478,7 @@ HEIMDAL_GLUE_OBJ_FILES = heimdal_build/glue.o ####################### # Start SUBSYSTEM HEIMDAL_COM_ERR [SUBSYSTEM::HEIMDAL_COM_ERR] -CFLAGS = -Iheimdal_build -Iheimdal/lib/com_err +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/com_err PRIVATE_DEPENDENCIES = HEIMDAL_ROKEN # End SUBSYSTEM HEIMDAL_COM_ERR ####################### @@ -488,7 +490,7 @@ HEIMDAL_COM_ERR_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_ASN1_COMPILE_LEX [SUBSYSTEM::HEIMDAL_ASN1_COMPILE_LEX] -CFLAGS = -Iheimdal_build -Iheimdal/lib/asn1 -Iheimdal/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/asn1 -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper # End SUBSYSTEM HEIMDAL_ASN1_COMPILE_LEX ####################### @@ -497,7 +499,7 @@ HEIMDAL_ASN1_COMPILE_LEX_OBJ_FILES = $(heimdalsrcdir)/lib/asn1/lex.ho ####################### # Start BINARY asn1_compile [BINARY::asn1_compile] -CFLAGS = -Iheimdal_build -Iheimdal/lib/roken +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken USE_HOSTCC = YES PRIVATE_DEPENDENCIES = HEIMDAL_ASN1_COMPILE_LEX HEIMDAL_ROKEN_GETPROGNAME_H LIBREPLACE_NETWORK @@ -531,7 +533,7 @@ asn1_compile_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_COM_ERR_COMPILE_LEX [SUBSYSTEM::HEIMDAL_COM_ERR_COMPILE_LEX] -CFLAGS = -Iheimdal_build -Iheimdal/lib/com_err -Iheimdal/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/com_err -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper # End SUBSYSTEM HEIMDAL_COM_ERR_COMPILE_LEX ####################### @@ -540,7 +542,7 @@ HEIMDAL_COM_ERR_COMPILE_LEX_OBJ_FILES = $(heimdalsrcdir)/lib/com_err/lex.ho ####################### # Start BINARY compile_et [BINARY::compile_et] -CFLAGS = -Iheimdal_build -Iheimdal/lib/roken +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken USE_HOSTCC = YES PRIVATE_DEPENDENCIES = HEIMDAL_COM_ERR_COMPILE_LEX HEIMDAL_ROKEN_GETPROGNAME_H LIBREPLACE_NETWORK # End BINARY compile_et @@ -591,7 +593,7 @@ clean:: ####################### # Start SUBSYSTEM HEIMDAL [SUBSYSTEM::HEIMDAL] -CFLAGS = -Iheimdal_build +CFLAGS = -I$(heimdalbuildsrcdir) PUBLIC_DEPENDENCIES = \ HEIMDAL_GSSAPI HEIMDAL_KRB5 # End SUBSYSTEM HEIMDAL @@ -602,7 +604,7 @@ HEIMDAL_OBJ_FILES = $(heimdalsrcdir)/lib/vers/print_version.o ####################### # Start BINARY compile_et [BINARY::samba4kinit] -CFLAGS = -Iheimdal_build -Iheimdal/lib/roken +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken PRIVATE_DEPENDENCIES = HEIMDAL_KRB5 HEIMDAL_NTLM # End BINARY compile_et ####################### -- cgit From 936b973acbc756cc3b6cb0d9df85ebc28ba76ae7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:36:28 +0200 Subject: Use new dynconfig.h location. (This used to be commit c3f556915f09d078253e4c5539910a1cf420eeca) --- source4/lib/charset/util_unistr.c | 2 +- source4/lib/cmdline/popt_common.c | 2 +- source4/lib/ldb/config.mk | 2 ++ source4/lib/util/debug.c | 2 +- source4/nsswitch/wbinfo.c | 2 +- source4/param/loadparm.c | 2 +- source4/param/util.c | 2 +- source4/scripting/ejs/smbscript.c | 2 +- source4/torture/gentest.c | 2 +- source4/torture/gentest_smb2.c | 2 +- source4/torture/locktest.c | 2 +- source4/torture/masktest.c | 2 +- source4/torture/smbtorture.c | 2 +- 13 files changed, 14 insertions(+), 12 deletions(-) diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index c496c5d905..19a4f3236c 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -20,7 +20,7 @@ #include "includes.h" #include "system/locale.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "param/param.h" /** diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c index 73b3eecfbf..96d8b8b40a 100644 --- a/source4/lib/cmdline/popt_common.c +++ b/source4/lib/cmdline/popt_common.c @@ -23,7 +23,7 @@ #include "version.h" #include "lib/cmdline/popt_common.h" #include "param/param.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" /* Handle command line options: * -d,--debuglevel diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk index d63b440788..cc8f1e36ab 100644 --- a/source4/lib/ldb/config.mk +++ b/source4/lib/ldb/config.mk @@ -130,6 +130,8 @@ LIBLDB_SOVERSION = 0 LIBLDB_OBJ_FILES = $(addprefix $(ldbdir)/common/, ldb.o ldb_ldif.o ldb_parse.o ldb_msg.o ldb_utf8.o ldb_debug.o ldb_modules.o ldb_match.o ldb_attributes.o attrib_handlers.o ldb_dn.o ldb_controls.o qsort.o) $(ldb_map_OBJ_FILES) +$(LIBLDB_OBJ_FILES): CFLAGS+=-I$(ldbdir)/include + PUBLIC_HEADERS += $(ldbdir)/include/ldb.h $(ldbdir)/include/ldb_errors.h MANPAGES += $(ldbdir)/man/ldb.3 diff --git a/source4/lib/util/debug.c b/source4/lib/util/debug.c index 5c1abf5039..00dcbfc8bd 100644 --- a/source4/lib/util/debug.c +++ b/source4/lib/util/debug.c @@ -21,7 +21,7 @@ #include "includes.h" #include "system/filesys.h" #include "system/time.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" /** * @file diff --git a/source4/nsswitch/wbinfo.c b/source4/nsswitch/wbinfo.c index 7ead27939e..21c178cc7b 100644 --- a/source4/nsswitch/wbinfo.c +++ b/source4/nsswitch/wbinfo.c @@ -27,7 +27,7 @@ #include "libcli/auth/libcli_auth.h" #include "libcli/security/security.h" #include "lib/cmdline/popt_common.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "param/param.h" extern int winbindd_fd; diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c index 812162e170..b70e4c19f0 100644 --- a/source4/param/loadparm.c +++ b/source4/param/loadparm.c @@ -54,7 +54,7 @@ #include "includes.h" #include "version.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "system/time.h" #include "system/locale.h" #include "system/network.h" /* needed for TCP_NODELAY */ diff --git a/source4/param/util.c b/source4/param/util.c index 2baaefda8b..15e3b4768c 100644 --- a/source4/param/util.c +++ b/source4/param/util.c @@ -23,7 +23,7 @@ */ #include "includes.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "system/network.h" #include "system/filesys.h" #include "system/dir.h" diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c index 9ed4aa490f..db9fc9affa 100644 --- a/source4/scripting/ejs/smbscript.c +++ b/source4/scripting/ejs/smbscript.c @@ -26,7 +26,7 @@ #include "scripting/ejs/smbcalls.h" #include "auth/gensec/gensec.h" #include "ldb/include/ldb.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" static EjsId eid; diff --git a/source4/torture/gentest.c b/source4/torture/gentest.c index ae18fe809c..cd33074b4f 100644 --- a/source4/torture/gentest.c +++ b/source4/torture/gentest.c @@ -30,7 +30,7 @@ #include "libcli/resolve/resolve.h" #include "auth/gensec/gensec.h" #include "param/param.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #define NSERVERS 2 #define NINSTANCES 2 diff --git a/source4/torture/gentest_smb2.c b/source4/torture/gentest_smb2.c index 428f325a76..3e705dc60d 100644 --- a/source4/torture/gentest_smb2.c +++ b/source4/torture/gentest_smb2.c @@ -34,7 +34,7 @@ #include "libcli/resolve/resolve.h" #include "auth/gensec/gensec.h" #include "param/param.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #define NSERVERS 2 #define NINSTANCES 2 diff --git a/source4/torture/locktest.c b/source4/torture/locktest.c index 8959232edb..4a0dfc2a6f 100644 --- a/source4/torture/locktest.c +++ b/source4/torture/locktest.c @@ -27,7 +27,7 @@ #include "auth/gensec/gensec.h" #include "libcli/libcli.h" #include "param/param.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "libcli/resolve/resolve.h" static int numops = 1000; diff --git a/source4/torture/masktest.c b/source4/torture/masktest.c index 39b1296dbe..255d94382c 100644 --- a/source4/torture/masktest.c +++ b/source4/torture/masktest.c @@ -28,7 +28,7 @@ #include "auth/credentials/credentials.h" #include "auth/gensec/gensec.h" #include "param/param.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "libcli/resolve/resolve.h" #include "lib/events/events.h" diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c index 44daa89e44..e1e84247b4 100644 --- a/source4/torture/smbtorture.c +++ b/source4/torture/smbtorture.c @@ -28,7 +28,7 @@ #include "libcli/libcli.h" #include "lib/ldb/include/ldb.h" #include "lib/events/events.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "torture/smbtorture.h" #include "lib/util/dlinklist.h" -- cgit From b7a414138282124aaa543a2305bc6b26bbacdf5c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:41:00 +0200 Subject: Use variable for socket wrapper include path. (This used to be commit 01c0000def9492989c543e7ed6d48c58a3be1854) --- source4/heimdal_build/config.mk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index 8011284210..e167b6e8fd 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -408,24 +408,24 @@ HEIMDAL_WIND_OBJ_FILES = \ ####################### [SUBSYSTEM::HEIMDAL_ROKEN_GETPROGNAME] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) HEIMDAL_ROKEN_GETPROGNAME_OBJ_FILES = $(heimdalsrcdir)/lib/roken/getprogname.o [SUBSYSTEM::HEIMDAL_ROKEN_CLOSEFROM] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) HEIMDAL_ROKEN_CLOSEFROM_OBJ_FILES = $(heimdalsrcdir)/lib/roken/closefrom.o [SUBSYSTEM::HEIMDAL_ROKEN_GETPROGNAME_H] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) HEIMDAL_ROKEN_GETPROGNAME_H_OBJ_FILES = $(heimdalsrcdir)/lib/roken/getprogname.ho ####################### # Start SUBSYSTEM HEIMDAL_ROKEN [SUBSYSTEM::HEIMDAL_ROKEN] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) PUBLIC_DEPENDENCIES = \ HEIMDAL_ROKEN_GETPROGNAME \ HEIMDAL_ROKEN_CLOSEFROM \ @@ -490,7 +490,7 @@ HEIMDAL_COM_ERR_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_ASN1_COMPILE_LEX [SUBSYSTEM::HEIMDAL_ASN1_COMPILE_LEX] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/asn1 -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/asn1 -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) # End SUBSYSTEM HEIMDAL_ASN1_COMPILE_LEX ####################### @@ -533,7 +533,7 @@ asn1_compile_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_COM_ERR_COMPILE_LEX [SUBSYSTEM::HEIMDAL_COM_ERR_COMPILE_LEX] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/com_err -I$(heimdalsrcdir)/lib/roken -Ilib/socket_wrapper +CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/com_err -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) # End SUBSYSTEM HEIMDAL_COM_ERR_COMPILE_LEX ####################### -- cgit From 93a0f37f6ead117c5bdb2aa31d74c97c6e227e10 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:46:09 +0200 Subject: Disable CFLAGS hack when include path starts with variable. (This used to be commit 86ce8bf88acf3f9f9966ccf063bbf46d134ea4ba) --- source4/build/smb_build/makefile.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index 0269cfe8a3..e93e3eb767 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -262,6 +262,7 @@ sub CFlags($$) if($src_ne_build) { if($flag =~ m#^-I([^/].*$)#) { my $dir = $1; + next if ($dir =~ /^\$\(/); $dir =~ s#^\$\((?:src|build)dir\)/?##; push(@cflags, "-I$builddir/$dir", "-I$srcdir/$dir"); next; -- cgit From 134af89c80abc01df68bc9f8fb8607b9c1d79e64 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:58:13 +0200 Subject: Use variable for heimdal source dir in static deps file. (This used to be commit df603ad290700c2b286972cd7a6a28ac07f81f60) --- source4/static_deps.mk | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/source4/static_deps.mk b/source4/static_deps.mk index 7eb8fa10fe..de59d76e28 100644 --- a/source4/static_deps.mk +++ b/source4/static_deps.mk @@ -14,29 +14,29 @@ include/includes.h: \ librpc/gen_ndr/misc.h heimdal_basics: \ - heimdal/lib/hdb/hdb_asn1.h \ - heimdal/lib/gssapi/spnego_asn1.h \ - heimdal/lib/gssapi/gssapi_asn1.h \ - heimdal/lib/asn1/krb5_asn1.h \ - heimdal/lib/asn1/asn1_err.h \ - heimdal/lib/asn1/digest_asn1.h \ - heimdal/lib/asn1/pkcs8_asn1.h \ - heimdal/lib/asn1/pkcs9_asn1.h \ - heimdal/lib/asn1/pkcs12_asn1.h \ - heimdal/lib/asn1/cms_asn1.h \ - heimdal/lib/asn1/rfc2459_asn1.h \ - heimdal/lib/asn1/pkinit_asn1.h \ - heimdal/lib/asn1/kx509_asn1.h \ - heimdal/lib/hx509/ocsp_asn1.h \ - heimdal/lib/hx509/pkcs10_asn1.h \ - heimdal/lib/hdb/hdb_err.h \ - heimdal/lib/krb5/heim_err.h \ - heimdal/lib/krb5/k524_err.h \ - heimdal/lib/krb5/krb_err.h \ - heimdal/lib/krb5/krb5_err.h \ - heimdal/lib/gssapi/gkrb5_err.h \ - heimdal/lib/hx509/hx509_err.h \ - heimdal/lib/wind/wind_err.h + $(heimdalsrcdir)/lib/hdb/hdb_asn1.h \ + $(heimdalsrcdir)/lib/gssapi/spnego_asn1.h \ + $(heimdalsrcdir)/lib/gssapi/gssapi_asn1.h \ + $(heimdalsrcdir)/lib/asn1/krb5_asn1.h \ + $(heimdalsrcdir)/lib/asn1/asn1_err.h \ + $(heimdalsrcdir)/lib/asn1/digest_asn1.h \ + $(heimdalsrcdir)/lib/asn1/pkcs8_asn1.h \ + $(heimdalsrcdir)/lib/asn1/pkcs9_asn1.h \ + $(heimdalsrcdir)/lib/asn1/pkcs12_asn1.h \ + $(heimdalsrcdir)/lib/asn1/cms_asn1.h \ + $(heimdalsrcdir)/lib/asn1/rfc2459_asn1.h \ + $(heimdalsrcdir)/lib/asn1/pkinit_asn1.h \ + $(heimdalsrcdir)/lib/asn1/kx509_asn1.h \ + $(heimdalsrcdir)/lib/hx509/ocsp_asn1.h \ + $(heimdalsrcdir)/lib/hx509/pkcs10_asn1.h \ + $(heimdalsrcdir)/lib/hdb/hdb_err.h \ + $(heimdalsrcdir)/lib/krb5/heim_err.h \ + $(heimdalsrcdir)/lib/krb5/k524_err.h \ + $(heimdalsrcdir)/lib/krb5/krb_err.h \ + $(heimdalsrcdir)/lib/krb5/krb5_err.h \ + $(heimdalsrcdir)/lib/gssapi/gkrb5_err.h \ + $(heimdalsrcdir)/lib/hx509/hx509_err.h \ + $(heimdalsrcdir)/lib/wind/wind_err.h proto:: basics:: include/includes.h idl proto heimdal_basics -- cgit From ee114113d91db2a1e9f29918e7ab42a99acc89e4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 15:32:44 +0200 Subject: Use heimdalsrcdir variable for automatic dependencies. (This used to be commit c5db384160aefc21141e94004faf4e89a204ff69) --- source4/heimdal_build/asn1_deps.pl | 8 ++++---- source4/heimdal_build/config.mk | 28 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source4/heimdal_build/asn1_deps.pl b/source4/heimdal_build/asn1_deps.pl index a2fbb5e3d0..488404fcce 100755 --- a/source4/heimdal_build/asn1_deps.pl +++ b/source4/heimdal_build/asn1_deps.pl @@ -29,11 +29,11 @@ if (not defined $options) { my $header = "$dirname/$prefix.h"; -print "$header: $file bin/asn1_compile\n"; -print "\t\@echo \"Compiling ASN1 file $file\"\n"; -print "\t\@\$(builddir)/heimdal_build/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname bin/asn1_compile $file $prefix $options\n\n"; +print "$header: \$(heimdalsrcdir)/$file bin/asn1_compile\n"; +print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n"; +print "\t\@\$(builddir)/heimdal_build/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname bin/asn1_compile \$(heimdalsrcdir)/$file $prefix $options\n\n"; -open(IN,$file) or die("Can't open $file: $!"); +open(IN,"heimdal/$file") or die("Can't open heimdal/$file: $!"); my @lines = ; close(IN); foreach my $line (@lines) { diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index e167b6e8fd..6f97e53069 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -559,20 +559,20 @@ compile_et_OBJ_FILES = $(heimdalsrcdir)/lib/vers/print_version.ho \ ./heimdal_build/replace.ho -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/hdb/hdb.asn1 hdb_asn1 heimdal/lib/hdb | -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/gssapi/spnego/spnego.asn1 spnego_asn1 heimdal/lib/gssapi --sequence=MechTypeList | -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/gssapi/mech/gssapi.asn1 gssapi_asn1 heimdal/lib/gssapi| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/k5.asn1 krb5_asn1 heimdal/lib/asn1 --encode-rfc1510-bit-string --sequence=KRB5SignedPathPrincipals --sequence=AuthorizationData --sequence=METHOD-DATA| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/digest.asn1 digest_asn1 heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/pkcs8.asn1 pkcs8_asn1 heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/pkcs9.asn1 pkcs9_asn1 heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/pkcs12.asn1 pkcs12_asn1 heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/rfc2459.asn1 rfc2459_asn1 heimdal/lib/asn1 --preserve-binary=TBSCertificate --preserve-binary=TBSCRLCertList --preserve-binary=Name --sequence=GeneralNames --sequence=Extensions --sequence=CRLDistributionPoints| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/pkinit.asn1 pkinit_asn1 heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/CMS.asn1 cms_asn1 heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/hx509/ocsp.asn1 ocsp_asn1 heimdal/lib/hx509 --preserve-binary=OCSPTBSRequest --preserve-binary=OCSPResponseData| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/asn1/kx509.asn1 kx509_asn1 heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh asn1_deps.pl heimdal/lib/hx509/pkcs10.asn1 pkcs10_asn1 heimdal/lib/hx509 --preserve-binary=CertificationRequestInfo| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/hdb/hdb.asn1 hdb_asn1 \$\(heimdalsrcdir\)/lib/hdb | +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/gssapi/spnego/spnego.asn1 spnego_asn1 \$\(heimdalsrcdir\)/lib/gssapi --sequence=MechTypeList | +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/gssapi/mech/gssapi.asn1 gssapi_asn1 \$\(heimdalsrcdir\)/lib/gssapi| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/k5.asn1 krb5_asn1 \$\(heimdalsrcdir\)/lib/asn1 --encode-rfc1510-bit-string --sequence=KRB5SignedPathPrincipals --sequence=AuthorizationData --sequence=METHOD-DATA| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/digest.asn1 digest_asn1 \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/pkcs8.asn1 pkcs8_asn1 \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/pkcs9.asn1 pkcs9_asn1 \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/pkcs12.asn1 pkcs12_asn1 \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/rfc2459.asn1 rfc2459_asn1 \$\(heimdalsrcdir\)/lib/asn1 --preserve-binary=TBSCertificate --preserve-binary=TBSCRLCertList --preserve-binary=Name --sequence=GeneralNames --sequence=Extensions --sequence=CRLDistributionPoints| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/pkinit.asn1 pkinit_asn1 \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/CMS.asn1 cms_asn1 \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/hx509/ocsp.asn1 ocsp_asn1 \$\(heimdalsrcdir\)/lib/hx509 --preserve-binary=OCSPTBSRequest --preserve-binary=OCSPResponseData| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/asn1/kx509.asn1 kx509_asn1 \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh asn1_deps.pl lib/hx509/pkcs10.asn1 pkcs10_asn1 \$\(heimdalsrcdir\)/lib/hx509 --preserve-binary=CertificationRequestInfo| # # Ensure to update ./static_deps.mk when you add a new entry here! -- cgit From 44ca677e40f86b69aeec680280d527128e123c8f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 15:34:09 +0200 Subject: Use variables for more object file paths. (This used to be commit 5008116479209a1275d7f9b41ea293b27a8f7632) --- source4/heimdal_build/config.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index 6f97e53069..a600a499e5 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -463,7 +463,7 @@ HEIMDAL_ROKEN_OBJ_FILES = \ $(heimdalsrcdir)/lib/roken/simple_exec.o \ $(heimdalsrcdir)/lib/roken/strcollect.o \ $(heimdalsrcdir)/lib/roken/rtbl.o \ - ./heimdal_build/replace.o + $(heimdalbuildsrcdir)/replace.o ####################### # Start SUBSYSTEM HEIMDAL_GLUE @@ -524,8 +524,8 @@ asn1_compile_OBJ_FILES = \ $(heimdalsrcdir)/lib/roken/ecalloc.ho \ $(heimdalsrcdir)/lib/asn1/symbol.ho \ $(heimdalsrcdir)/lib/vers/print_version.ho \ - ./lib/socket_wrapper/socket_wrapper.ho \ - ./heimdal_build/replace.ho + $(socketwrappersrcdir)/socket_wrapper.ho \ + $(heimdalbuildsrcdir)/replace.ho # End BINARY asn1_compile ####################### @@ -555,8 +555,8 @@ compile_et_OBJ_FILES = $(heimdalsrcdir)/lib/vers/print_version.ho \ $(heimdalsrcdir)/lib/roken/get_window_size.ho \ $(heimdalsrcdir)/lib/roken/strupr.ho \ $(heimdalsrcdir)/lib/roken/setprogname.ho \ - ./lib/socket_wrapper/socket_wrapper.ho \ - ./heimdal_build/replace.ho + $(socketwrappersrcdir)/socket_wrapper.ho \ + $(heimdalsrcdir)/replace.ho mkinclude perl_path_wrapper.sh asn1_deps.pl lib/hdb/hdb.asn1 hdb_asn1 \$\(heimdalsrcdir\)/lib/hdb | -- cgit From 14b0987c630a424546211c46b8a8c5ca3c038226 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 15:38:13 +0200 Subject: use varibale for asn1 compiler. (This used to be commit 4543633ba046836d13da80d07d06c272c3abf9bc) --- source4/heimdal_build/asn1_deps.pl | 4 ++-- source4/heimdal_build/config.mk | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source4/heimdal_build/asn1_deps.pl b/source4/heimdal_build/asn1_deps.pl index 488404fcce..4910d47863 100755 --- a/source4/heimdal_build/asn1_deps.pl +++ b/source4/heimdal_build/asn1_deps.pl @@ -29,9 +29,9 @@ if (not defined $options) { my $header = "$dirname/$prefix.h"; -print "$header: \$(heimdalsrcdir)/$file bin/asn1_compile\n"; +print "$header: \$(heimdalsrcdir)/$file \$(ASN1C)\n"; print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n"; -print "\t\@\$(builddir)/heimdal_build/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname bin/asn1_compile \$(heimdalsrcdir)/$file $prefix $options\n\n"; +print "\t\@\$(builddir)/heimdal_build/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ASN1C) \$(heimdalsrcdir)/$file $prefix $options\n\n"; open(IN,"heimdal/$file") or die("Can't open heimdal/$file: $!"); my @lines = ; diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index a600a499e5..f13f1d38c4 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -503,6 +503,8 @@ CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken USE_HOSTCC = YES PRIVATE_DEPENDENCIES = HEIMDAL_ASN1_COMPILE_LEX HEIMDAL_ROKEN_GETPROGNAME_H LIBREPLACE_NETWORK +ASN1C = bin/asn1_compile + asn1_compile_OBJ_FILES = \ $(heimdalsrcdir)/lib/asn1/main.ho \ $(heimdalsrcdir)/lib/asn1/gen.ho \ -- cgit From 04b7b013064e7fa942d739df1e1d5b0b608a2b3a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 15:45:53 +0200 Subject: Move asn1 cflags definition to gmake. (This used to be commit 486d43355eb368c3f291ded5e353416e478ab862) --- source4/heimdal_build/config.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index f13f1d38c4..608bf2d2b8 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -499,7 +499,6 @@ HEIMDAL_ASN1_COMPILE_LEX_OBJ_FILES = $(heimdalsrcdir)/lib/asn1/lex.ho ####################### # Start BINARY asn1_compile [BINARY::asn1_compile] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken USE_HOSTCC = YES PRIVATE_DEPENDENCIES = HEIMDAL_ASN1_COMPILE_LEX HEIMDAL_ROKEN_GETPROGNAME_H LIBREPLACE_NETWORK @@ -529,6 +528,8 @@ asn1_compile_OBJ_FILES = \ $(socketwrappersrcdir)/socket_wrapper.ho \ $(heimdalbuildsrcdir)/replace.ho +$(asn1_compile_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken + # End BINARY asn1_compile ####################### @@ -558,7 +559,7 @@ compile_et_OBJ_FILES = $(heimdalsrcdir)/lib/vers/print_version.ho \ $(heimdalsrcdir)/lib/roken/strupr.ho \ $(heimdalsrcdir)/lib/roken/setprogname.ho \ $(socketwrappersrcdir)/socket_wrapper.ho \ - $(heimdalsrcdir)/replace.ho + $(heimdalbuildsrcdir)/replace.ho mkinclude perl_path_wrapper.sh asn1_deps.pl lib/hdb/hdb.asn1 hdb_asn1 \$\(heimdalsrcdir\)/lib/hdb | -- cgit From fa2216584288813d2c3a507cc01e9a4cb0193130 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 15:55:43 +0200 Subject: Use variables for et files too. (This used to be commit 953f796059e16ea082391cfd6a018531a2a5be4e) --- source4/heimdal_build/config.mk | 22 ++++++++++++---------- source4/heimdal_build/et_deps.pl | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index 608bf2d2b8..66a2ddbcc9 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -502,7 +502,7 @@ HEIMDAL_ASN1_COMPILE_LEX_OBJ_FILES = $(heimdalsrcdir)/lib/asn1/lex.ho USE_HOSTCC = YES PRIVATE_DEPENDENCIES = HEIMDAL_ASN1_COMPILE_LEX HEIMDAL_ROKEN_GETPROGNAME_H LIBREPLACE_NETWORK -ASN1C = bin/asn1_compile +ASN1C = $(builddir)/bin/asn1_compile asn1_compile_OBJ_FILES = \ $(heimdalsrcdir)/lib/asn1/main.ho \ @@ -551,6 +551,8 @@ PRIVATE_DEPENDENCIES = HEIMDAL_COM_ERR_COMPILE_LEX HEIMDAL_ROKEN_GETPROGNAME_H L # End BINARY compile_et ####################### +ET_COMPILER = $(builddir)/bin/compile_et + compile_et_OBJ_FILES = $(heimdalsrcdir)/lib/vers/print_version.ho \ $(heimdalsrcdir)/lib/com_err/parse.ho \ $(heimdalsrcdir)/lib/com_err/compile_et.ho \ @@ -580,15 +582,15 @@ mkinclude perl_path_wrapper.sh asn1_deps.pl lib/hx509/pkcs10.asn1 pkcs10_asn1 \$ # # Ensure to update ./static_deps.mk when you add a new entry here! # -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/asn1/asn1_err.et heimdal/lib/asn1| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/hdb/hdb_err.et heimdal/lib/hdb| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/krb5/heim_err.et heimdal/lib/krb5| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/krb5/k524_err.et heimdal/lib/krb5| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/krb5/krb_err.et heimdal/lib/krb5| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/krb5/krb5_err.et heimdal/lib/krb5| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/gssapi/krb5/gkrb5_err.et heimdal/lib/gssapi| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/hx509/hx509_err.et heimdal/lib/hx509| -mkinclude perl_path_wrapper.sh et_deps.pl heimdal/lib/wind/wind_err.et heimdal/lib/wind| +mkinclude perl_path_wrapper.sh et_deps.pl lib/asn1/asn1_err.et \$\(heimdalsrcdir\)/lib/asn1| +mkinclude perl_path_wrapper.sh et_deps.pl lib/hdb/hdb_err.et \$\(heimdalsrcdir\)/lib/hdb| +mkinclude perl_path_wrapper.sh et_deps.pl lib/krb5/heim_err.et \$\(heimdalsrcdir\)/lib/krb5| +mkinclude perl_path_wrapper.sh et_deps.pl lib/krb5/k524_err.et \$\(heimdalsrcdir\)/lib/krb5| +mkinclude perl_path_wrapper.sh et_deps.pl lib/krb5/krb_err.et \$\(heimdalsrcdir\)/lib/krb5| +mkinclude perl_path_wrapper.sh et_deps.pl lib/krb5/krb5_err.et \$\(heimdalsrcdir\)/lib/krb5| +mkinclude perl_path_wrapper.sh et_deps.pl lib/gssapi/krb5/gkrb5_err.et \$\(heimdalsrcdir\)/lib/gssapi| +mkinclude perl_path_wrapper.sh et_deps.pl lib/hx509/hx509_err.et \$\(heimdalsrcdir\)/lib/hx509| +mkinclude perl_path_wrapper.sh et_deps.pl lib/wind/wind_err.et \$\(heimdalsrcdir\)/lib/wind| clean:: @-rm -f bin/compile_et bin/asn1_compile diff --git a/source4/heimdal_build/et_deps.pl b/source4/heimdal_build/et_deps.pl index 2385dbd085..5ebab8692e 100755 --- a/source4/heimdal_build/et_deps.pl +++ b/source4/heimdal_build/et_deps.pl @@ -8,9 +8,9 @@ my $basename = basename($file); my $header = "$dirname/$basename"; $header =~ s/\.et$/.h/; my $source = "$dirname/$basename"; $source =~ s/\.et$/.c/; -print "$header $source: $file bin/compile_et\n"; +print "$header $source: \$(heimdalsrcdir)/$file \$(ET_COMPILER)\n"; print "\t\@echo \"Compiling error table $file\"\n"; -print "\t\@\$(builddir)/heimdal_build/et_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname bin/compile_et $file $source\n\n"; +print "\t\@\$(builddir)/heimdal_build/et_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ET_COMPILER) \$(heimdalsrcdir)/$file $source\n\n"; print "clean:: \n"; print "\t\@rm -f $header $source\n\n"; -- cgit From 16c883ca23a23d3784aec059ac949a066c29ac0d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 16:23:12 +0200 Subject: Move CFLAGS that are not inherited out of smb_build. (This used to be commit 49dcf4b8811f92684a7ddd266ac289d8fc8ca215) --- source4/build/smb_build/config_mk.pm | 2 -- source4/heimdal_build/config.mk | 9 +++++---- source4/lib/ldb/python.mk | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source4/build/smb_build/config_mk.pm b/source4/build/smb_build/config_mk.pm index 652a52fa60..8c7d75221c 100644 --- a/source4/build/smb_build/config_mk.pm +++ b/source4/build/smb_build/config_mk.pm @@ -25,7 +25,6 @@ my $section_types = { "PUBLIC_DEPENDENCIES" => "list", "ENABLE" => "bool", "LDFLAGS" => "list", - "CFLAGS" => "list", }, "SUBSYSTEM" => { "PRIVATE_DEPENDENCIES" => "list", @@ -60,7 +59,6 @@ my $section_types = { "ENABLE" => "bool", "INSTALLDIR" => "string", - "CFLAGS" => "list", "LDFLAGS" => "list", "STANDARD_VISIBILITY" => "string", diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index 66a2ddbcc9..95cad441f1 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -490,11 +490,11 @@ HEIMDAL_COM_ERR_OBJ_FILES = \ ####################### # Start SUBSYSTEM HEIMDAL_ASN1_COMPILE_LEX [SUBSYSTEM::HEIMDAL_ASN1_COMPILE_LEX] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/asn1 -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) # End SUBSYSTEM HEIMDAL_ASN1_COMPILE_LEX ####################### HEIMDAL_ASN1_COMPILE_LEX_OBJ_FILES = $(heimdalsrcdir)/lib/asn1/lex.ho +$(HEIMDAL_ASN1_COMPILE_LEX_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/asn1 -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) ####################### # Start BINARY asn1_compile @@ -528,7 +528,7 @@ asn1_compile_OBJ_FILES = \ $(socketwrappersrcdir)/socket_wrapper.ho \ $(heimdalbuildsrcdir)/replace.ho -$(asn1_compile_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken +$(asn1_compile_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(heimdalsrcdir)/lib/asn1 # End BINARY asn1_compile ####################### @@ -545,7 +545,6 @@ HEIMDAL_COM_ERR_COMPILE_LEX_OBJ_FILES = $(heimdalsrcdir)/lib/com_err/lex.ho ####################### # Start BINARY compile_et [BINARY::compile_et] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken USE_HOSTCC = YES PRIVATE_DEPENDENCIES = HEIMDAL_COM_ERR_COMPILE_LEX HEIMDAL_ROKEN_GETPROGNAME_H LIBREPLACE_NETWORK # End BINARY compile_et @@ -563,6 +562,7 @@ compile_et_OBJ_FILES = $(heimdalsrcdir)/lib/vers/print_version.ho \ $(socketwrappersrcdir)/socket_wrapper.ho \ $(heimdalbuildsrcdir)/replace.ho +$(compile_et_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken mkinclude perl_path_wrapper.sh asn1_deps.pl lib/hdb/hdb.asn1 hdb_asn1 \$\(heimdalsrcdir\)/lib/hdb | mkinclude perl_path_wrapper.sh asn1_deps.pl lib/gssapi/spnego/spnego.asn1 spnego_asn1 \$\(heimdalsrcdir\)/lib/gssapi --sequence=MechTypeList | @@ -609,7 +609,6 @@ HEIMDAL_OBJ_FILES = $(heimdalsrcdir)/lib/vers/print_version.o ####################### # Start BINARY compile_et [BINARY::samba4kinit] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken PRIVATE_DEPENDENCIES = HEIMDAL_KRB5 HEIMDAL_NTLM # End BINARY compile_et ####################### @@ -619,5 +618,7 @@ samba4kinit_OBJ_FILES = $(heimdalsrcdir)/kuser/kinit.o \ $(heimdalsrcdir)/lib/roken/setprogname.o \ $(heimdalsrcdir)/lib/roken/getarg.o +$(samba4kinit_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken + dist:: $(heimdalsrcdir)/lib/asn1/lex.c $(heimdalsrcdir)/lib/com_err/lex.c \ $(heimdalsrcdir)/lib/asn1/parse.c $(heimdalsrcdir)/lib/com_err/parse.c diff --git a/source4/lib/ldb/python.mk b/source4/lib/ldb/python.mk index 96ae6a5720..5325446e1e 100644 --- a/source4/lib/ldb/python.mk +++ b/source4/lib/ldb/python.mk @@ -1,9 +1,9 @@ [PYTHON::swig_ldb] LIBRARY_REALNAME = _ldb.$(SHLIBEXT) PUBLIC_DEPENDENCIES = LIBLDB -CFLAGS = -I$(ldbdir)/include swig_ldb_OBJ_FILES = $(ldbdir)/ldb_wrap.o +$(swig_ldb_OBJ_FILES): CFLAGS+=-I$(ldbdir)/include $(eval $(call python_py_module_template,ldb.py,$(ldbdir)/ldb.py)) -- cgit From 34402ecea613d386ca368a7bcb149e27cd7ef5c5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 16:44:04 +0200 Subject: Move source dir variables to Makefile. (This used to be commit fdc7c3568e5fbf510c874601d72798454b1c1ca6) --- source4/Makefile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ source4/main.mk | 47 ----------------------------------------------- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/source4/Makefile b/source4/Makefile index 069fece855..370be2a2da 100644 --- a/source4/Makefile +++ b/source4/Makefile @@ -49,6 +49,54 @@ endif include $(srcdir)/build/make/rules.mk include $(srcdir)/build/make/python.mk +dynconfigsrcdir := dynconfig +heimdalsrcdir := heimdal +dsdbsrcdir := dsdb +smbdsrcdir := smbd +clustersrcdir := cluster +libnetsrcdir := libnet +authsrcdir := auth +nsswitchsrcdir := nsswitch +libsrcdir := lib +libsocketsrcdir := lib/socket +libcharsetsrcdir := lib/charset +ldb_sambasrcdir := lib/ldb-samba +libtlssrcdir := lib/tls +libregistrysrcdir := lib/registry +libmessagingsrcdir := lib/messaging +libeventssrcdir := lib/events +libcmdlinesrcdir := lib/cmdline +socketwrappersrcdir := lib/socket_wrapper +nsswrappersrcdir := lib/nss_wrapper +appwebsrcdir := lib/appweb +libstreamsrcdir := lib/stream +libutilsrcdir := lib/util +libtdrsrcdir := lib/tdr +libdbwrapsrcdir := lib/dbwrap +libcryptosrcdir := lib/crypto +libtorturesrcdir := lib/torture +smb_serversrcdir := smb_server +libcompressionsrcdir := lib/compression +libgencachesrcdir := lib +paramsrcdir := param +rpc_serversrcdir := rpc_server +ldap_serversrcdir := ldap_server +web_serversrcdir := web_server +winbindsrcdir := winbind +nbt_serversrcdir := nbt_server +wrepl_serversrcdir := wrepl_server +cldap_serversrcdir := cldap_server +utilssrcdir := utils +clientsrcdir := client +torturesrcdir := torture +ntvfssrcdir := ntvfs +ntptrsrcdir := ntptr +librpcsrcdir := librpc +libclisrcdir := libcli +ejsscriptsrcdir := scripting/ejs +pyscriptsrcdir := $(srcdir)/scripting/python +kdcsrcdir := kdc + include data.mk BINARIES += $(BIN_PROGS) $(SBIN_PROGS) diff --git a/source4/main.mk b/source4/main.mk index b0de9525c1..4fd1502fae 100644 --- a/source4/main.mk +++ b/source4/main.mk @@ -1,96 +1,49 @@ -dynconfigsrcdir := dynconfig mkinclude dynconfig/config.mk -heimdalsrcdir := heimdal mkinclude heimdal_build/config.mk mkinclude config.mk -dsdbsrcdir := dsdb mkinclude dsdb/config.mk -smbdsrcdir := smbd mkinclude smbd/config.mk -clustersrcdir := cluster mkinclude cluster/config.mk mkinclude smbd/process_model.mk -libnetsrcdir := libnet mkinclude libnet/config.mk -authsrcdir := auth mkinclude auth/config.mk -nsswitchsrcdir := nsswitch mkinclude nsswitch/config.mk -libsrcdir := lib mkinclude lib/samba3/config.mk -libsocketsrcdir := lib/socket mkinclude lib/socket/config.mk -libcharsetsrcdir := lib/charset mkinclude lib/charset/config.mk -ldb_sambasrcdir := lib/ldb-samba mkinclude lib/ldb-samba/config.mk -libtlssrcdir := lib/tls mkinclude lib/tls/config.mk -libregistrysrcdir := lib/registry mkinclude lib/registry/config.mk -libmessagingsrcdir := lib/messaging mkinclude lib/messaging/config.mk -libeventssrcdir := lib/events mkinclude lib/events/config.mk -libcmdlinesrcdir := lib/cmdline mkinclude lib/cmdline/config.mk -socketwrappersrcdir := lib/socket_wrapper mkinclude lib/socket_wrapper/config.mk -nsswrappersrcdir := lib/nss_wrapper mkinclude lib/nss_wrapper/config.mk -appwebsrcdir := lib/appweb mkinclude lib/appweb/config.mk -libstreamsrcdir := lib/stream mkinclude lib/stream/config.mk -libutilsrcdir := lib/util mkinclude lib/util/config.mk -libtdrsrcdir := lib/tdr mkinclude lib/tdr/config.mk -libdbwrapsrcdir := lib/dbwrap mkinclude lib/dbwrap/config.mk -libcryptosrcdir := lib/crypto mkinclude lib/crypto/config.mk -libtorturesrcdir := lib/torture mkinclude lib/torture/config.mk -libcompressionsrcdir := lib/compression -libgencachesrcdir := lib mkinclude lib/basic.mk -paramsrcdir := param mkinclude param/config.mk -smb_serversrcdir := smb_server mkinclude smb_server/config.mk -rpc_serversrcdir := rpc_server mkinclude rpc_server/config.mk -ldap_serversrcdir := ldap_server mkinclude ldap_server/config.mk -web_serversrcdir := web_server mkinclude web_server/config.mk -winbindsrcdir := winbind mkinclude winbind/config.mk -nbt_serversrcdir := nbt_server mkinclude nbt_server/config.mk -wrepl_serversrcdir := wrepl_server mkinclude wrepl_server/config.mk -cldap_serversrcdir := cldap_server mkinclude cldap_server/config.mk -utilssrcdir := utils mkinclude utils/net/config.mk mkinclude utils/config.mk -ntvfssrcdir := ntvfs mkinclude ntvfs/config.mk -ntptrsrcdir := ntptr mkinclude ntptr/config.mk -torturesrcdir := torture mkinclude torture/config.mk -librpcsrcdir := librpc mkinclude librpc/config.mk -clientsrcdir := client mkinclude client/config.mk -libclisrcdir := libcli mkinclude libcli/config.mk -ejsscriptsrcdir := scripting/ejs mkinclude scripting/ejs/config.mk -pyscriptsrcdir := $(srcdir)/scripting/python mkinclude scripting/python/config.mk -kdcsrcdir := kdc mkinclude kdc/config.mk -- cgit From 03f6679f866905cbd45b07552b60547238b0b88e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 16:56:11 +0200 Subject: Move more CFLAGS to Makefile. (This used to be commit 0406713aad09b1ea4bd761519fd4897b94cfc7e5) --- source4/heimdal_build/config.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index 95cad441f1..ea353bcca3 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -408,19 +408,19 @@ HEIMDAL_WIND_OBJ_FILES = \ ####################### [SUBSYSTEM::HEIMDAL_ROKEN_GETPROGNAME] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) HEIMDAL_ROKEN_GETPROGNAME_OBJ_FILES = $(heimdalsrcdir)/lib/roken/getprogname.o +$(HEIMDAL_ROKEN_GETPROGNAME_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) [SUBSYSTEM::HEIMDAL_ROKEN_CLOSEFROM] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) HEIMDAL_ROKEN_CLOSEFROM_OBJ_FILES = $(heimdalsrcdir)/lib/roken/closefrom.o +$(HEIMDAL_ROKEN_CLOSEFROM): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) [SUBSYSTEM::HEIMDAL_ROKEN_GETPROGNAME_H] -CFLAGS = -I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) HEIMDAL_ROKEN_GETPROGNAME_H_OBJ_FILES = $(heimdalsrcdir)/lib/roken/getprogname.ho +$(HEIMDAL_ROKEN_GETPROGNAME_H_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) ####################### # Start SUBSYSTEM HEIMDAL_ROKEN -- cgit From 7ae9cb4f79d2d10566a62fa2159a1cf2b6e0bada Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 17:16:57 +0200 Subject: Don't throw away cflags if they start with a variable. (This used to be commit 9f81214239e1cf6563da4ed49d051fe56d3ab129) --- source4/build/smb_build/makefile.pm | 5 ++++- source4/heimdal_build/config.mk | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source4/build/smb_build/makefile.pm b/source4/build/smb_build/makefile.pm index e93e3eb767..73801c25fd 100644 --- a/source4/build/smb_build/makefile.pm +++ b/source4/build/smb_build/makefile.pm @@ -262,7 +262,10 @@ sub CFlags($$) if($src_ne_build) { if($flag =~ m#^-I([^/].*$)#) { my $dir = $1; - next if ($dir =~ /^\$\(/); + if ($dir =~ /^\$\(/) { + push (@cflags, $flag); + next; + } $dir =~ s#^\$\((?:src|build)dir\)/?##; push(@cflags, "-I$builddir/$dir", "-I$srcdir/$dir"); next; diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index ea353bcca3..8eea568ad7 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -415,7 +415,7 @@ $(HEIMDAL_ROKEN_GETPROGNAME_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heim [SUBSYSTEM::HEIMDAL_ROKEN_CLOSEFROM] HEIMDAL_ROKEN_CLOSEFROM_OBJ_FILES = $(heimdalsrcdir)/lib/roken/closefrom.o -$(HEIMDAL_ROKEN_CLOSEFROM): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) +$(HEIMDAL_ROKEN_CLOSEFROM_OBJ_FILES): CFLAGS+=-I$(heimdalbuildsrcdir) -I$(heimdalsrcdir)/lib/roken -I$(socketwrappersrcdir) [SUBSYSTEM::HEIMDAL_ROKEN_GETPROGNAME_H] -- cgit From 053cb704d9e51b4ef4c65e2143091270a01cc6a4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 17:21:13 +0200 Subject: Use variables in generated make fragments. (This used to be commit 269f8c9f6e9e5f6ad20319956573f09232b7c48f) --- source4/heimdal_build/asn1_deps.pl | 2 +- source4/heimdal_build/et_deps.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/heimdal_build/asn1_deps.pl b/source4/heimdal_build/asn1_deps.pl index 4910d47863..16b2bd7dbe 100755 --- a/source4/heimdal_build/asn1_deps.pl +++ b/source4/heimdal_build/asn1_deps.pl @@ -31,7 +31,7 @@ my $header = "$dirname/$prefix.h"; print "$header: \$(heimdalsrcdir)/$file \$(ASN1C)\n"; print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n"; -print "\t\@\$(builddir)/heimdal_build/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ASN1C) \$(heimdalsrcdir)/$file $prefix $options\n\n"; +print "\t\@\$(heimdalbuildsrcdir)/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ASN1C) \$(heimdalsrcdir)/$file $prefix $options\n\n"; open(IN,"heimdal/$file") or die("Can't open heimdal/$file: $!"); my @lines = ; diff --git a/source4/heimdal_build/et_deps.pl b/source4/heimdal_build/et_deps.pl index 5ebab8692e..d341ecced3 100755 --- a/source4/heimdal_build/et_deps.pl +++ b/source4/heimdal_build/et_deps.pl @@ -10,7 +10,7 @@ my $header = "$dirname/$basename"; $header =~ s/\.et$/.h/; my $source = "$dirname/$basename"; $source =~ s/\.et$/.c/; print "$header $source: \$(heimdalsrcdir)/$file \$(ET_COMPILER)\n"; print "\t\@echo \"Compiling error table $file\"\n"; -print "\t\@\$(builddir)/heimdal_build/et_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ET_COMPILER) \$(heimdalsrcdir)/$file $source\n\n"; +print "\t\@\$(heimdalbuildsrcdir)/et_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ET_COMPILER) \$(heimdalsrcdir)/$file $source\n\n"; print "clean:: \n"; print "\t\@rm -f $header $source\n\n"; -- cgit From e797e23e481a290c85872a7cc7df4d9b1ba9c31d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 18:13:50 +0200 Subject: Simplify handling of source directory in asn compile wrapper. (This used to be commit 2c01d342b27832b930b81b04a90ed5630c6f470d) --- source4/heimdal_build/asn1_compile_wrapper.sh | 28 +++++++-------------------- source4/heimdal_build/asn1_deps.pl | 2 +- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/source4/heimdal_build/asn1_compile_wrapper.sh b/source4/heimdal_build/asn1_compile_wrapper.sh index 96677c7e8e..c449bf8065 100755 --- a/source4/heimdal_build/asn1_compile_wrapper.sh +++ b/source4/heimdal_build/asn1_compile_wrapper.sh @@ -4,21 +4,15 @@ SELF=$0 SELFDIR=`dirname ${SELF}` -SRCDIR=$1 -BUILDDIR=$2 -DESTDIR=$3 +BUILDDIR=$1 +DESTDIR=$2 -CMD=$4 -FILE=$5 -NAME=$6 -shift 6 +CMD=$3 +FILE=$4 +NAME=$5 +shift 5 OPTIONS="$@" -test -z "${SRCDIR}" && { - echo "${SELF}:SRCDIR: '${SRCDIR}'" >&2; - exit 1; -} - test -z "${BUILDDIR}" && { echo "${SELF}:BUILDDIR: '${BUILDDIR}'" >&2; exit 1; @@ -46,14 +40,6 @@ test -z "${NAME}" && { CURDIR=`pwd` -cd ${SRCDIR} && { - ABS_SRCDIR=`pwd` - cd ${CURDIR} -} || { - echo "${SELF}:cannot cd into '${SRCDIR}'" >&2; - exit 1; -} - cd ${BUILDDIR} && { ABS_BUILDDIR=`pwd` cd ${CURDIR} @@ -63,7 +49,7 @@ cd ${BUILDDIR} && { } cd ${DESTDIR} && { - ${ABS_BUILDDIR}/${CMD} ${OPTIONS} ${ABS_SRCDIR}/${FILE} ${NAME} >&2 || exit 1; + ${ABS_BUILDDIR}/${CMD} ${OPTIONS} ${FILE} ${NAME} >&2 || exit 1; cd ${CURDIR} } || { echo "${SELF}:cannot cd into '${BUILDDIR}'" >&2; diff --git a/source4/heimdal_build/asn1_deps.pl b/source4/heimdal_build/asn1_deps.pl index 16b2bd7dbe..6121781760 100755 --- a/source4/heimdal_build/asn1_deps.pl +++ b/source4/heimdal_build/asn1_deps.pl @@ -31,7 +31,7 @@ my $header = "$dirname/$prefix.h"; print "$header: \$(heimdalsrcdir)/$file \$(ASN1C)\n"; print "\t\@echo \"Compiling ASN1 file \$(heimdalsrcdir)/$file\"\n"; -print "\t\@\$(heimdalbuildsrcdir)/asn1_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ASN1C) \$(heimdalsrcdir)/$file $prefix $options\n\n"; +print "\t\@\$(heimdalbuildsrcdir)/asn1_compile_wrapper.sh \$(builddir) $dirname \$(ASN1C) \$(abspath \$(heimdalsrcdir)/$file) $prefix $options\n\n"; open(IN,"heimdal/$file") or die("Can't open heimdal/$file: $!"); my @lines = ; -- cgit From 5c9f28d560f510003817e3e337e858522d56c622 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 18:16:13 +0200 Subject: Simplify handling of source directory in et compile wrapper. (This used to be commit 4e6fddda2e7d9e37f7b7ec99c5a58671f825a571) --- source4/heimdal_build/et_compile_wrapper.sh | 28 +++++++--------------------- source4/heimdal_build/et_deps.pl | 2 +- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/source4/heimdal_build/et_compile_wrapper.sh b/source4/heimdal_build/et_compile_wrapper.sh index d7d47ba363..ec3b39ff56 100755 --- a/source4/heimdal_build/et_compile_wrapper.sh +++ b/source4/heimdal_build/et_compile_wrapper.sh @@ -4,19 +4,13 @@ SELF=$0 SELFDIR=`dirname ${SELF}` -SRCDIR=$1 -BUILDDIR=$2 -DESTDIR=$3 +BUILDDIR=$1 +DESTDIR=$2 -CMD=$4 -FILE=$5 -SOURCE=$6 -shift 6 - -test -z "${SRCDIR}" && { - echo "${SELF}:SRCDIR: '${SRCDIR}'" >&2; - exit 1; -} +CMD=$3 +FILE=$4 +SOURCE=$5 +shift 5 test -z "${BUILDDIR}" && { echo "${SELF}:BUILDDIR: '${BUILDDIR}'" >&2; @@ -45,14 +39,6 @@ test -z "${SOURCE}" && { CURDIR=`pwd` -cd ${SRCDIR} && { - ABS_SRCDIR=`pwd` - cd ${CURDIR} -} || { - echo "${SELF}:cannot cd into '${SRCDIR}'" >&2; - exit 1; -} - cd ${BUILDDIR} && { ABS_BUILDDIR=`pwd` cd ${CURDIR} @@ -62,7 +48,7 @@ cd ${BUILDDIR} && { } cd ${DESTDIR} && { - ${ABS_BUILDDIR}/${CMD} ${ABS_SRCDIR}/${FILE} >&2 || exit 1; + ${ABS_BUILDDIR}/${CMD} ${FILE} >&2 || exit 1; cd ${CURDIR} TMP="${SOURCE}.$$" mv ${SOURCE} ${TMP} && { diff --git a/source4/heimdal_build/et_deps.pl b/source4/heimdal_build/et_deps.pl index d341ecced3..6a0485bb54 100755 --- a/source4/heimdal_build/et_deps.pl +++ b/source4/heimdal_build/et_deps.pl @@ -10,7 +10,7 @@ my $header = "$dirname/$basename"; $header =~ s/\.et$/.h/; my $source = "$dirname/$basename"; $source =~ s/\.et$/.c/; print "$header $source: \$(heimdalsrcdir)/$file \$(ET_COMPILER)\n"; print "\t\@echo \"Compiling error table $file\"\n"; -print "\t\@\$(heimdalbuildsrcdir)/et_compile_wrapper.sh \$(srcdir) \$(builddir) $dirname \$(ET_COMPILER) \$(heimdalsrcdir)/$file $source\n\n"; +print "\t\@\$(heimdalbuildsrcdir)/et_compile_wrapper.sh \$(builddir) $dirname \$(ET_COMPILER) \$(abspath \$(heimdalsrcdir)/$file) $source\n\n"; print "clean:: \n"; print "\t\@rm -f $header $source\n\n"; -- cgit From 1284308a35f4983609fd77633b6137fdf8df6c75 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 18:20:29 +0200 Subject: Use variable for ndr_netlogon.o path. (This used to be commit b5d9d7a0affb4dcd8b89830e6967e4a14b512619) --- source4/libcli/config.mk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source4/libcli/config.mk b/source4/libcli/config.mk index b24f3eb4af..02711eedb3 100644 --- a/source4/libcli/config.mk +++ b/source4/libcli/config.mk @@ -61,15 +61,14 @@ $(eval $(call proto_header_template,$(libclisrcdir)/nbt/nbt_proto.h,$(LIBCLI_NBT PUBLIC_DEPENDENCIES = LIBNDR \ NDR_SECURITY -LIBCLI_NDR_NETLOGON_OBJ_FILES = $(addprefix libcli/, \ - ndr_netlogon.o) +LIBCLI_NDR_NETLOGON_OBJ_FILES = $(addprefix $(libclisrcdir)/, ndr_netlogon.o) $(eval $(call proto_header_template,$(libclisrcdir)/ndr_netlogon_proto.h,$(LIBCLI_NDR_NETLOGON_OBJ_FILES:.o=.c))) [SUBSYSTEM::LIBCLI_NETLOGON] PUBLIC_DEPENDENCIES = LIBSAMBA-UTIL LIBCLI_NDR_NETLOGON -LIBCLI_NETLOGON_OBJ_FILES = $(addprefix libcli/, \ +LIBCLI_NETLOGON_OBJ_FILES = $(addprefix $(libclisrcdir)/, \ netlogon.o) $(eval $(call proto_header_template,$(libclisrcdir)/netlogon_proto.h,$(LIBCLI_NETLOGON_OBJ_FILES:.o=.c))) -- cgit From f56432e8c34b4a75621665d0c3f08e46963b441d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 18:29:00 +0200 Subject: Use variable path for heimdal glue code. (This used to be commit 3fce4889b3f6ddc38e3dd3e1ffd4e7252f370883) --- source4/heimdal_build/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/heimdal_build/config.mk b/source4/heimdal_build/config.mk index 8eea568ad7..17fc8c93ec 100644 --- a/source4/heimdal_build/config.mk +++ b/source4/heimdal_build/config.mk @@ -473,7 +473,7 @@ PUBLIC_DEPENDENCIES = LIBNETIF LIBSAMBA-HOSTCONFIG # End SUBSYSTEM HEIMDAL_GLUE ####################### -HEIMDAL_GLUE_OBJ_FILES = heimdal_build/glue.o +HEIMDAL_GLUE_OBJ_FILES = $(heimdalbuildsrcdir)/glue.o ####################### # Start SUBSYSTEM HEIMDAL_COM_ERR -- cgit From 4053e3c700c0996764585a5c6eaef6b70274537a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 18:38:05 +0200 Subject: Use variables for IDL file paths. (This used to be commit 683ba6de41b3fecc14c18502ff82b4fa617618e5) --- source4/librpc/idl-deps.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/librpc/idl-deps.pl b/source4/librpc/idl-deps.pl index e630ee4f61..49fba4c935 100755 --- a/source4/librpc/idl-deps.pl +++ b/source4/librpc/idl-deps.pl @@ -4,8 +4,8 @@ use strict; my %vars = (); foreach(@ARGV) { - push (@{$vars{IDL_FILES}}, $_); my $b = $_; $b =~ s/.*\/(.*?).idl$/$1/; + push (@{$vars{IDL_FILES}}, "\$(librpcsrcdir)/idl/$b.idl"); push (@{$vars{IDL_HEADER_FILES}}, "\$(librpcsrcdir)/gen_ndr/$b.h"); push (@{$vars{IDL_NDR_PARSE_H_FILES}}, "\$(librpcsrcdir)/gen_ndr/ndr_$b.h"); push (@{$vars{IDL_NDR_PARSE_C_FILES}}, "\$(librpcsrcdir)/gen_ndr/ndr_$b.c"); -- cgit From fd03ce3ac31c95ccd6128f4db6ff753c347d18b8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 18:46:05 +0200 Subject: Allow external use of regf idl. (This used to be commit 7b9b3ec02b27852cc32689a44c7f3fbbe43b7c6b) --- source4/lib/registry/config.mk | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source4/lib/registry/config.mk b/source4/lib/registry/config.mk index 44adc53524..fd1fd01a09 100644 --- a/source4/lib/registry/config.mk +++ b/source4/lib/registry/config.mk @@ -5,12 +5,11 @@ TDR_REGF_OBJ_FILES = $(libregistrysrcdir)/tdr_regf.o # Special support for external builddirs $(libregistrysrcdir)/regf.c: $(libregistrysrcdir)/tdr_regf.c -$(srcdir)/$(libregistrysrcdir)/regf.c: $(libregistrysrcdir)/tdr_regf.c $(libregistrysrcdir)/tdr_regf.h: $(libregistrysrcdir)/tdr_regf.c -$(libregistrysrcdir)/tdr_regf.c: $(srcdir)/$(libregistrysrcdir)/regf.idl - @CPP="$(CPP)" srcdir="$(srcdir)" $(PERL) $(srcdir)/pidl/pidl $(PIDL_ARGS) \ - --header --outputdir=lib/registry \ - --tdr-parser -- $(srcdir)/$(libregistrysrcdir)/regf.idl +$(libregistrysrcdir)/tdr_regf.c: $(libregistrysrcdir)/regf.idl + @CPP="$(CPP)" $(PERL) $(pidldir)/pidl $(PIDL_ARGS) \ + --header --outputdir=$(libregistrysrcdir) \ + --tdr-parser -- $(libregistrysrcdir)/regf.idl clean:: @-rm -f $(libregistrysrcdir)/regf.h $(libregistrysrcdir)/tdr_regf* -- cgit From 42cfbe272c0a4f1131d28f1de9121063869be2a3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 19:35:04 +0200 Subject: Add variable for smbreadline directory. (This used to be commit 94167c7d4273fbd6084d6ddae7fd15dcb189d62f) --- source4/Makefile | 1 + source4/lib/smbreadline/readline.m4 | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source4/Makefile b/source4/Makefile index 370be2a2da..20a0876962 100644 --- a/source4/Makefile +++ b/source4/Makefile @@ -63,6 +63,7 @@ libcharsetsrcdir := lib/charset ldb_sambasrcdir := lib/ldb-samba libtlssrcdir := lib/tls libregistrysrcdir := lib/registry +smbreadlinesrcdir := lib/smbreadline libmessagingsrcdir := lib/messaging libeventssrcdir := lib/events libcmdlinesrcdir := lib/cmdline diff --git a/source4/lib/smbreadline/readline.m4 b/source4/lib/smbreadline/readline.m4 index ab85bba438..ad6bc66690 100644 --- a/source4/lib/smbreadline/readline.m4 +++ b/source4/lib/smbreadline/readline.m4 @@ -79,10 +79,10 @@ AC_MSG_CHECKING(whether to use extern readline) if test x"$EXTERNAL_READLINE" = x"yes"; then AC_MSG_RESULT(yes) AC_DEFINE(HAVE_LIBREADLINE,1,[Whether the system has readline]) - SMB_SUBSYSTEM(SMBREADLINE, [lib/smbreadline/smbreadline.o], [READLINE]) + SMB_SUBSYSTEM(SMBREADLINE, [\$(smbreadlinesrcdir)/smbreadline.o], [READLINE]) SMB_EXT_LIB(READLINE, [${TERMLIBS}]) SMB_ENABLE(READLINE,YES) else - SMB_SUBSYSTEM(SMBREADLINE, [lib/smbreadline/smbreadline.o], []) + SMB_SUBSYSTEM(SMBREADLINE, [\$(smbreadlinesrcdir)/smbreadline.o], []) AC_MSG_RESULT(no) fi -- cgit From 52b230141b5ad9f317f97e7d257703614bab3985 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 19:47:16 +0200 Subject: Allow librpcsrcdir to be an absolute path. (This used to be commit 8c0b55114fe35d498626d9d60cc4716b821d4d4f) --- source4/librpc/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/librpc/config.mk b/source4/librpc/config.mk index ab25921ef8..a39f50411b 100644 --- a/source4/librpc/config.mk +++ b/source4/librpc/config.mk @@ -350,7 +350,7 @@ NDR_WINBIND_OBJ_FILES = $(gen_ndrsrcdir)/ndr_winbind.o #PUBLIC_HEADERS += $(gen_ndrsrcdir)/winbind.h $(librpcsrcdir)/idl-deps: - ./$(librpcsrcdir)/idl-deps.pl $(librpcsrcdir)/idl/*.idl >$@ + $(PERL) $(librpcsrcdir)/idl-deps.pl $(librpcsrcdir)/idl/*.idl >$@ clean:: rm -f $(librpcsrcdir)/idl-deps -- cgit