summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-01-22 16:39:56 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-01-22 16:39:56 +0100
commit4075a2ba982ea56ff925e0a33839f0760fd71911 (patch)
tree87d87734257f814b7960a843e54455c447f34a9e /source4/scripting
parent24da29746998de1001d18871dcbe8d37643667d5 (diff)
parent35c68316442808a135aafa864d19592108a4d879 (diff)
downloadsamba-4075a2ba982ea56ff925e0a33839f0760fd71911.tar.gz
samba-4075a2ba982ea56ff925e0a33839f0760fd71911.tar.bz2
samba-4075a2ba982ea56ff925e0a33839f0760fd71911.zip
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-python
(This used to be commit 2f57e25f8f692889d9e057e13256f8a24c5ec10c)
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/bin/epdump.py24
-rwxr-xr-x[-rw-r--r--]source4/scripting/bin/winreg.py133
-rw-r--r--source4/scripting/ejs/config.mk12
-rw-r--r--source4/scripting/ejs/ejsnet/net_user.c8
-rw-r--r--source4/scripting/libjs/provision.js52
-rw-r--r--source4/scripting/python/STATUS26
-rw-r--r--source4/scripting/python/config.m472
-rw-r--r--source4/scripting/python/config.mk12
-rw-r--r--source4/scripting/python/modules.c13
-rw-r--r--source4/scripting/python/pyrpc.h29
-rw-r--r--source4/scripting/python/pytalloc.c45
-rw-r--r--source4/scripting/python/pytalloc.h51
-rw-r--r--source4/scripting/python/samba/__init__.py14
-rw-r--r--source4/scripting/python/samba/provision.py40
-rw-r--r--source4/scripting/python/samba/samdb.py4
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/__init__.py0
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/registry.py50
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/rpcecho.py44
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/sam.py28
-rw-r--r--source4/scripting/python/uuidmodule.c8
20 files changed, 435 insertions, 230 deletions
diff --git a/source4/scripting/bin/epdump.py b/source4/scripting/bin/epdump.py
new file mode 100644
index 0000000000..15dee33774
--- /dev/null
+++ b/source4/scripting/bin/epdump.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
+#
+
+import sys
+
+if len(sys.argv) < 2:
+ print "Usage: %s <binding-string>" % sys.argv[0]
+ sys.exit(1)
diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py
index 6cdc3a5898..f68f2d12f2 100644..100755
--- a/source4/scripting/bin/winreg.py
+++ b/source4/scripting/bin/winreg.py
@@ -7,87 +7,76 @@
#
import sys
+import winreg
+import optparse
+import samba.getopt as options
-options = GetOptions(ARGV,
- "POPT_AUTOHELP",
- "POPT_COMMON_SAMBA",
- "POPT_COMMON_CREDENTIALS",
- "createkey=s")
-if (options == undefined) {
- print "Failed to parse options"
- sys.exit(-1)
+parser = optparse.OptionParser("%s <BINDING> [path]" % sys.argv[0])
+parser.add_option_group(options.SambaOptions(parser))
+parser.add_option("--createkey", type="string", metavar="KEYNAME",
+ help="create a key")
-if len(sys.argv < 2:
- print "Usage: %s <BINDING> [path]" % sys.argv[0]
- sys.exit(-1)
+opts, args = parser.parse_args()
-binding = options.ARGV[0]
-reg = winregObj()
+if len(args) < 1:
+ parser.print_usage()
+ sys.exit(-1)
+
+binding = args[0]
print "Connecting to " + binding
-status = reg.connect(binding)
-if (status.is_ok != true) {
- print("Failed to connect to " + binding + " - " + status.errstr + "\n")
- return -1
-}
+conn = winreg.winreg(binding, opts.configfile)
-def list_values(path):
- list = reg.enum_values(path)
- if (list == undefined) {
- return
- }
- for (i=0;i<list.length;i++) {
- v = list[i]
- printf("\ttype=%-30s size=%4d '%s'\n", reg.typestring(v.type), v.size, v.name)
- if (v.type == reg.REG_SZ || v.type == reg.REG_EXPAND_SZ) {
- printf("\t\t'%s'\n", v.value)
- }
- 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_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(path):
- count = 0
- list = reg.enum_path(path)
- if (list == undefined) {
- println("Unable to list " + path)
- return 0
- }
- list_values(path)
- count = count + list.length
- for (i=0;i<list.length;i++) {
- if (path) {
- npath = path + "\\" + list[i]
- } else {
- npath = list[i]
- }
- println(npath)
- count = count + list_path(npath)
- }
- return count
+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(sys.argv) > 2:
- root = sys.argv[2]
+if len(args) > 1:
+ root = args[1]
else:
- root = ''
+ root = "HKLM"
-if options.createkey:
- try:
- reg.create_key("HKLM\\SOFTWARE", options.createkey)
- except:
- print "Failed to create key"
+if opts.createkey:
+ reg.create_key("HKLM\\SOFTWARE", opt.createkey)
else:
- printf("Listing registry tree '%s'\n", root)
- count = list_path(root)
+ 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:
- println("No entries found")
- sys.exit(1)
+ print "No entries found"
+ sys.exit(1)
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk
index 8b680ba973..656ecdae16 100644
--- a/source4/scripting/ejs/config.mk
+++ b/source4/scripting/ejs/config.mk
@@ -1,10 +1,6 @@
-#######################
-# Start LIBRARY EJSRPC
[SUBSYSTEM::EJSRPC]
OBJ_FILES = \
ejsrpc.o
-# End SUBSYSTEM EJSRPC
-#######################
[MODULE::smbcalls_config]
OBJ_FILES = smbcalls_config.o
@@ -79,11 +75,7 @@ INIT_FUNCTION = smb_setup_ejs_system
include ejsnet/config.mk
-#######################
-# Start LIBRARY smbcalls
-[LIBRARY::smbcalls]
-SO_VERSION = 0
-VERSION = 0.0.1
+[SUBSYSTEM::smbcalls]
PRIVATE_PROTO_HEADER = proto.h
OBJ_FILES = \
smbcalls.o \
@@ -101,8 +93,6 @@ PRIVATE_DEPENDENCIES = \
CREDENTIALS POPT_CREDENTIALS POPT_SAMBA \
dcerpc \
NDR_TABLE
-# End SUBSYSTEM smbcalls
-#######################
#######################
# Start BINARY SMBSCRIPT
diff --git a/source4/scripting/ejs/ejsnet/net_user.c b/source4/scripting/ejs/ejsnet/net_user.c
index 34524cc0fa..57e538d3b4 100644
--- a/source4/scripting/ejs/ejsnet/net_user.c
+++ b/source4/scripting/ejs/ejsnet/net_user.c
@@ -195,9 +195,9 @@ static int ejs_net_deleteuser(MprVarHandle eid, int argc, char **argv)
ejsSetErrorMsg(eid, "ctx property returns null pointer");
goto done;
}
-
+
/* domain where the account is to be deleted */
- userman_domain = (struct libnet_context *)mprGetThisPtr(eid, "domain");
+ userman_domain = mprGetThisPtr(eid, "domain");
if (!userman_domain) {
ejsSetErrorMsg(eid, "domain property returns null pointer");
goto done;
@@ -258,9 +258,9 @@ static int ejs_net_userinfo(MprVarHandle eid, int argc, char **argv)
ejsSetErrorMsg(eid, "ctx property returns null pointer");
goto done;
}
-
+
/* domain where the user account is to be queried */
- userman_domain = (struct libnet_context *)mprGetThisPtr(eid, "domain");
+ userman_domain = mprGetThisPtr(eid, "domain");
if (userman_domain == NULL) {
ejsSetErrorMsg(eid, "domain property returns null pointer");
return -1;
diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js
index 0da02ae276..0cca49dec9 100644
--- a/source4/scripting/libjs/provision.js
+++ b/source4/scripting/libjs/provision.js
@@ -170,7 +170,7 @@ function ldb_erase(info, ldb)
/* and the rest */
attrs = new Array("dn");
var basedn = "";
- var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
+ var res = ldb.search("(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
var i;
if (res.error != 0) {
ldb_delete(info, ldb);
@@ -180,7 +180,7 @@ function ldb_erase(info, ldb)
ldb.del(res.msgs[i].dn);
}
- var res = ldb.search("(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
+ var res = ldb.search("(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", basedn, ldb.SCOPE_SUBTREE, attrs);
if (res.error != 0 || res.msgs.length != 0) {
ldb_delete(info, ldb);
return;
@@ -207,8 +207,8 @@ function ldb_erase_partitions(info, ldb, ldapbackend)
return;
}
for (j=0; j<res.msgs[0].namingContexts.length; j++) {
- var anything = "(|(objectclass=*)(dn=*))";
- var attrs = new Array("dn");
+ var anything = "(|(objectclass=*)(distinguishedName=*))";
+ var attrs = new Array("distinguishedName");
var basedn = res.msgs[0].namingContexts[j];
var k;
var previous_remaining = 1;
@@ -398,9 +398,6 @@ function provision_default_paths(subobj)
paths.named_conf = lp.get("private dir") + "/named.conf";
paths.winsdb = "wins.ldb";
paths.ldapdir = lp.get("private dir") + "/ldap";
- paths.ldap_basedn_ldif = paths.ldapdir + "/" + dnsdomain + ".ldif";
- paths.ldap_config_basedn_ldif = paths.ldapdir + "/" + dnsdomain + "-config.ldif";
- paths.ldap_schema_basedn_ldif = paths.ldapdir + "/" + dnsdomain + "-schema.ldif";
paths.s4_ldapi_socket = lp.get("private dir") + "/ldapi";
paths.phpldapadminconfig = lp.get("private dir") + "/phpldapadmin-config.php";
@@ -866,6 +863,12 @@ function provision_schema(subobj, message, tmp_schema_path, paths)
/* This will erase anything in the tmp db */
var samdb = open_ldb(info, tmp_schema_path, true);
+ message("Setting up sam.ldb attributes\n");
+ setup_add_ldif("provision_init.ldif", info, samdb, false);
+
+ message("Setting up sam.ldb rootDSE\n");
+ setup_add_ldif("provision_rootdse_add.ldif", info, samdb, false);
+
message("Adding schema container (permitted to fail)\n");
var add_ok = setup_add_ldif("provision_schema_basedn.ldif", info, samdb, true);
message("Modifying schema container\n");
@@ -934,34 +937,6 @@ function provision_dns(subobj, message, paths, session_info, credentials)
message("Please install the zone located in " + paths.dns + " into your DNS server. A sample BIND configuration snippit is at " + paths.named_conf + "\n");
}
-/* Write out a DNS zone file, from the info in the current database */
-function provision_ldapbase(subobj, message, paths)
-{
- var ok = provision_fix_subobj(subobj, paths);
- assert(ok);
-
- message("Setting up LDAP base entry: " + subobj.DOMAINDN + " \n");
- var rdns = split(",", subobj.DOMAINDN);
- subobj.EXTENSIBLEOBJECT = "objectClass: extensibleObject";
-
- subobj.RDN_DC = substr(rdns[0], strlen("DC="));
-
- sys.mkdir(paths.ldapdir, 0700);
-
- setup_file("provision_basedn.ldif",
- message, paths.ldap_basedn_ldif,
- subobj);
-
- setup_file("provision_configuration_basedn.ldif",
- message, paths.ldap_config_basedn_ldif,
- subobj);
-
- setup_file("provision_schema_basedn.ldif",
- message, paths.ldap_schema_basedn_ldif,
- subobj);
-
-}
-
/*
guess reasonably default options for provisioning
@@ -1038,14 +1013,13 @@ function provision_guess()
subobj.DOMAINDN_LDB = "users.ldb";
subobj.CONFIGDN_LDB = "configuration.ldb";
subobj.SCHEMADN_LDB = "schema.ldb";
- subobj.DOMAINDN_MOD = "pdc_fsmo,password_hash";
- subobj.CONFIGDN_MOD = "naming_fsmo";
- subobj.SCHEMADN_MOD = "schema_fsmo";
+ subobj.DOMAINDN_MOD = "pdc_fsmo,password_hash,instancetype";
+ subobj.CONFIGDN_MOD = "naming_fsmo,instancetype";
+ subobj.SCHEMADN_MOD = "schema_fsmo,instancetype";
subobj.DOMAINDN_MOD2 = ",objectguid";
subobj.CONFIGDN_MOD2 = ",objectguid";
subobj.SCHEMADN_MOD2 = ",objectguid";
- subobj.EXTENSIBLEOBJECT = "# no objectClass: extensibleObject for local ldb";
subobj.ACI = "# no aci for local ldb";
return subobj;
diff --git a/source4/scripting/python/STATUS b/source4/scripting/python/STATUS
index c82275fff8..6e6475bfde 100644
--- a/source4/scripting/python/STATUS
+++ b/source4/scripting/python/STATUS
@@ -1,23 +1,15 @@
-dsdb/samdb/ldb_modules/tests/samba3sam.py
-lib/ldb/tests/python/ldap.py
-provisioning in LDAP mode
-SWAT
+dsdb/samdb/ldb_modules/tests/samba3sam.py: Fix remaining failing tests
+lib/ldb/tests/python/ldap.py: Fix remaining 3 FIXME's
+provisioning in LDAP mode(TEST_LDAP=yes PROVISION_PYTHON=yes make test)
command-line vampire
provisioning: combine some of the python dictionaries
-hierarchy
-DCE/RPC bindings
- - pidl:
- Parse::Pidl::Samba::Python
- - wrap struct/bitmap/enum/union types
- - __ndr_pack__/__ndr_unpack__ members
- Parse::Pidl::Samba::NDR::Python
- - pidl generated client fns
- - one class per interface
- - AddOne()
-
- - scripting/bin/smbstatus.py
- - scripting/bin/winreg.py
+finish scripting/bin/smbstatus.py
not important before making Python the default:
+- hierarchy (rename samr -> dcerpc.samr, misc -> samba.misc, etc)
- scripting/python/samba/upgrade.py
- install python modules into system
+- SWAT
+- __ndr_pack__/__ndr_unpack__ members for the NDR struct bindings
+- generate docstrings in DCE/RPC bindings
+- eliminate some variables from the python interface because they can be induced
diff --git a/source4/scripting/python/config.m4 b/source4/scripting/python/config.m4
index 348f9197f7..908efd1588 100644
--- a/source4/scripting/python/config.m4
+++ b/source4/scripting/python/config.m4
@@ -13,6 +13,32 @@ if test -z "$PYTHON"; then
AC_MSG_WARN([No python found])
fi
+AC_DEFUN([TRY_LINK_PYTHON],
+[
+ if test $working_python = no; then
+ ac_save_LIBS="$LIBS"
+ ac_save_CFLAGS="$CFLAGS"
+ LIBS="$LIBS $1"
+ CFLAGS="$CFLAGS $2"
+
+ AC_TRY_LINK([
+ #include <Python.h>
+ #include <stdlib.h>
+ ],[
+ Py_InitModule(NULL, NULL);
+ ],[
+ PYTHON_LDFLAGS="$1"
+ PYTHON_CFLAGS="$2"
+ working_python=yes
+ ])
+ LIBS="$ac_save_LIBS"
+ CFLAGS="$ac_save_CFLAGS"
+ fi
+])
+
+dnl assume no working python
+working_python=no
+
if test -z "$PYTHON_VERSION"; then
AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config])
else
@@ -20,50 +46,28 @@ else
fi
if test -z "$PYTHON_CONFIG"; then
- working_python=no
AC_MSG_WARN([No python-config found])
else
- working_python=yes
- PYTHON_LDFLAGS=`$PYTHON_CONFIG --ldflags`
- PYTHON_CFLAGS=`$PYTHON_CONFIG --cflags`
+ TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --includes`])
+ TRY_LINK_PYTHON([`$PYTHON_CONFIG --ldflags`], [`$PYTHON_CONFIG --cflags`])
fi
-if test $working_python = no && test x$PYTHON != x
+if test x$PYTHON != x
then
- PYTHON_CFLAGS=`$PYTHON -c "from distutils import sysconfig; print '-I%s -I%s %s' % (sysconfig.get_python_inc(), sysconfig.get_python_inc(plat_specific=True), sysconfig.get_config_var('CFLAGS'))"`
- PYTHON_LDFLAGS=`$PYTHON -c "from distutils import sysconfig; print '%s %s -lpython%s -L%s' % (sysconfig.get_config_var('LIBS'), sysconfig.get_config_var('SYSLIBS'), sysconfig.get_config_var('VERSION'), sysconfig.get_config_var('LIBPL'))"`
- working_python=yes
+ DISTUTILS_CFLAGS=`$PYTHON -c "from distutils import sysconfig; print '-I%s -I%s %s' % (sysconfig.get_python_inc(), sysconfig.get_python_inc(plat_specific=True), sysconfig.get_config_var('CFLAGS'))"`
+ DISTUTILS_LDFLAGS=`$PYTHON -c "from distutils import sysconfig; print '%s %s -lpython%s -L%s' % (sysconfig.get_config_var('LIBS'), sysconfig.get_config_var('SYSLIBS'), sysconfig.get_config_var('VERSION'), sysconfig.get_config_var('LIBPL'))"`
+ TRY_LINK_PYTHON($DISTUTILS_LDFLAGS, $DISTUTILS_CFLAGS)
fi
SMB_EXT_LIB(EXT_LIB_PYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CFLAGS])
AC_MSG_CHECKING(working python module support)
-if test x$working_python = xyes
-then
- ac_save_LIBS="$LIBS"
- ac_save_CFLAGS="$CFLAGS"
- LIBS="$LIBS $PYTHON_LDFLAGS"
- CFLAGS="$CFLAGS $PYTHON_CFLAGS"
-
- AC_TRY_LINK([
- #include <Python.h>
- #include <stdlib.h>
- ],[
- Py_InitModule(NULL, NULL);
- ],[
- SMB_ENABLE(EXT_LIB_PYTHON,YES)
- SMB_ENABLE(smbpython,YES)
- SMB_ENABLE(LIBPYTHON,YES)
- AC_MSG_RESULT([yes])
- ],[
- SMB_ENABLE(EXT_LIB_PYTHON,NO)
- SMB_ENABLE(LIBPYTHON,NO)
- SMB_ENABLE(smbpython,NO)
- AC_MSG_RESULT([no])
- ])
-
- LIBS="$ac_save_LIBS"
- CFLAGS="$ac_save_CFLAGS"
+if test $working_python = yes; then
+ SMB_ENABLE(EXT_LIB_PYTHON,YES)
+ SMB_ENABLE(smbpython,YES)
+ SMB_ENABLE(LIBPYTHON,YES)
+ AC_MSG_RESULT([yes])
else
AC_MSG_ERROR([Python not found. Please install Python 2.x and its development headers/libraries.])
fi
+
diff --git a/source4/scripting/python/config.mk b/source4/scripting/python/config.mk
index cfd179aff5..450da0e90a 100644
--- a/source4/scripting/python/config.mk
+++ b/source4/scripting/python/config.mk
@@ -5,7 +5,7 @@ OBJ_FILES = smbpython.o
[SUBSYSTEM::LIBPYTHON]
PUBLIC_DEPENDENCIES = EXT_LIB_PYTHON
INIT_FUNCTION_SENTINEL = { NULL, NULL }
-OBJ_FILES = modules.o
+OBJ_FILES = modules.o pytalloc.o
[PYTHON::python_uuid]
PRIVATE_DEPENDENCIES = LIBNDR
@@ -16,7 +16,7 @@ PRIVATE_DEPENDENCIES = LIBNDR LIBLDB SAMDB CREDENTIALS
SWIG_FILE = misc.i
# Swig extensions
-swig: pythonmods
+swig:: pythonmods
.SUFFIXES: _wrap.c .i
@@ -28,13 +28,19 @@ realdistclean::
@-rm -f bin/python/*
# FIXME: Remove _wrap.c files
-pythonmods: $(PYTHON_DSOS)
+pythonmods:: $(PYTHON_DSOS) $(PYTHON_PYS)
PYDOCTOR_MODULES=bin/python/ldb.py bin/python/auth.py bin/python/credentials.py bin/python/registry.py bin/python/tdb.py bin/python/security.py bin/python/events.py bin/python/net.py
pydoctor:: pythonmods
LD_LIBRARY_PATH=bin/shared PYTHONPATH=bin/python pydoctor --make-html --docformat=restructuredtext --add-package scripting/python/samba/ $(addprefix --add-module , $(PYDOCTOR_MODULES))
+installpython:: pythonmods
+ @$(SHELL) $(srcdir)/script/installpython.sh \
+ $(INSTALLPERMS) \
+ $(DESTDIR)$(PYTHONDIR) \
+ scripting/python bin/python
+
clean::
@echo "Removing python modules"
@rm -f bin/python/*
diff --git a/source4/scripting/python/modules.c b/source4/scripting/python/modules.c
index 55df51d881..fff981e941 100644
--- a/source4/scripting/python/modules.c
+++ b/source4/scripting/python/modules.c
@@ -35,6 +35,19 @@ extern void init_events(void);
extern void inituuid(void);
extern void init_net(void);
extern void initecho(void);
+extern void initwinreg(void);
+extern void initepmapper(void);
+extern void initinitshutdown(void);
+static void initdcerpc_misc(void) {}
+extern void initmgmt(void);
+extern void initatsvc(void);
+extern void initsamr(void);
+static void initdcerpc_security(void) {}
+extern void initlsa(void);
+extern void initsvcctl(void);
+extern void initwkssvc(void);
+extern void init_libcli_nbt(void);
+extern void init_libcli_smb(void);
static struct _inittab py_modules[] = { STATIC_LIBPYTHON_MODULES };
diff --git a/source4/scripting/python/pyrpc.h b/source4/scripting/python/pyrpc.h
new file mode 100644
index 0000000000..5390c6923d
--- /dev/null
+++ b/source4/scripting/python/pyrpc.h
@@ -0,0 +1,29 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
+*/
+
+#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_sid28_Check
diff --git a/source4/scripting/python/pytalloc.c b/source4/scripting/python/pytalloc.c
new file mode 100644
index 0000000000..d8d3efe69c
--- /dev/null
+++ b/source4/scripting/python/pytalloc.c
@@ -0,0 +1,45 @@
+/*
+ Unix SMB/CIFS implementation.
+ Python/Talloc glue
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "scripting/python/pytalloc.h"
+
+void py_talloc_dealloc(PyObject* self)
+{
+ py_talloc_Object *obj = (py_talloc_Object *)self;
+ talloc_free(obj->talloc_ctx);
+ PyObject_Del(self);
+}
+
+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->ptr = ptr;
+ return (PyObject *)ret;
+}
+
+PyObject *py_talloc_default_repr(PyObject *py_obj)
+{
+ py_talloc_Object *obj = (py_talloc_Object *)py_obj;
+
+ return PyString_FromFormat("<talloc: %s>",
+ talloc_get_name(obj->talloc_ctx));
+}
diff --git a/source4/scripting/python/pytalloc.h b/source4/scripting/python/pytalloc.h
new file mode 100644
index 0000000000..aad5840a67
--- /dev/null
+++ b/source4/scripting/python/pytalloc.h
@@ -0,0 +1,51 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _PY_TALLOC_H_
+#define _PY_TALLOC_H_
+
+#include <Python.h>
+
+typedef struct {
+ PyObject_HEAD
+ TALLOC_CTX *talloc_ctx;
+ void *ptr;
+} py_talloc_Object;
+
+/* Deallocate a py_talloc_Object */
+void py_talloc_dealloc(PyObject* self);
+
+/* Retrieve the pointer for a py_talloc_object. Like talloc_get_type()
+ * but for py_talloc_Objects. */
+
+/* FIXME: Call PyErr_SetString(PyExc_TypeError, "expected " __STR(type) ")
+ * when talloc_get_type() returns NULL. */
+#define py_talloc_get_type(py_obj, type) \
+ talloc_get_type(py_talloc_get_ptr(py_obj), type)
+
+#define py_talloc_get_ptr(py_obj) ((py_talloc_Object *)py_obj)->ptr
+#define py_talloc_get_mem_ctx(py_obj) ((py_talloc_Object *)py_obj)->talloc_ctx
+
+PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
+#define py_talloc_import(py_type, talloc_ptr) py_talloc_import_ex(py_type, talloc_ptr, talloc_ptr)
+
+/* Sane default implementation of reprfunc. */
+PyObject *py_talloc_default_repr(PyObject *py_obj);
+
+#endif /* _PY_TALLOC_H_ */
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index e0b9e1d410..483929661d 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -112,28 +112,28 @@ class Ldb(ldb.Ldb):
for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES",
"@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
try:
- self.delete(ldb.Dn(self, attr))
+ self.delete(attr)
except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
# Ignore missing dn errors
pass
- basedn = ldb.Dn(self, "")
+ basedn = ""
# and the rest
for msg in self.search(basedn, ldb.SCOPE_SUBTREE,
- "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))",
- ["dn"]):
+ "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))",
+ ["distinguishedName"]):
try:
self.delete(msg.dn)
except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
# Ignor eno such object errors
pass
- res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"])
+ res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", ["distinguishedName"])
assert len(res) == 0
def erase_partitions(self):
"""Erase an ldb, removing all records."""
- res = self.search(ldb.Dn(self, ""), ldb.SCOPE_BASE, "(objectClass=*)",
+ res = self.search("", ldb.SCOPE_BASE, "(objectClass=*)",
["namingContexts"])
assert len(res) == 1
if not "namingContexts" in res[0]:
@@ -145,7 +145,7 @@ class Ldb(ldb.Ldb):
k = 0
while ++k < 10 and (previous_remaining != current_remaining):
# and the rest
- res2 = self.search(ldb.Dn(self, basedn), ldb.SCOPE_SUBTREE, "(|(objectclass=*)(dn=*))", ["dn"])
+ res2 = self.search(basedn, ldb.SCOPE_SUBTREE, "(|(objectclass=*)(distinguishedName=*))", ["distinguishedName"])
previous_remaining = current_remaining
current_remaining = len(res2)
for msg in res2:
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index db3749f721..d59cea121e 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -20,7 +20,7 @@ import samba
from samba import Ldb, substitute_var, valid_netbios_name
from samba.samdb import SamDB
import security
-from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
+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."""
@@ -64,7 +64,7 @@ def install_ok(lp, session_info, credentials):
return False
ldb = Ldb(lp.get("sam database"), session_info=session_info,
credentials=credentials, lp=lp)
- if len(ldb.search(ldb.Dn("(cn=Administrator)"))) != 1:
+ if len(ldb.search("(cn=Administrator)")) != 1:
return False
return True
@@ -180,12 +180,6 @@ def provision_paths_from_lp(lp, dnsdomain):
paths.dns_keytab = os.path.join(private_dir, "dns.keytab")
paths.dns = os.path.join(private_dir, dnsdomain + ".zone")
paths.winsdb = os.path.join(private_dir, "wins.ldb")
- paths.ldap_basedn_ldif = os.path.join(private_dir,
- dnsdomain + ".ldif")
- paths.ldap_config_basedn_ldif = os.path.join(private_dir,
- dnsdomain + "-config.ldif")
- paths.ldap_schema_basedn_ldif = os.path.join(private_dir,
- dnsdomain + "-schema.ldif")
paths.s4_ldapi_path = os.path.join(private_dir, "ldapi")
paths.phpldapadminconfig = os.path.join(private_dir,
"phpldapadmin-config.php")
@@ -465,7 +459,6 @@ def setup_samdb(path, setup_path, session_info, credentials, lp,
setup_add_ldif(samdb, setup_path("provision_basedn.ldif"), {
"DOMAINDN": domaindn,
"ACI": aci,
- "EXTENSIBLEOBJECT": "# no objectClass: extensibleObject for local ldb",
"RDN_DC": rdn_dc,
})
@@ -766,9 +759,9 @@ def provision(lp, setup_dir, message, blank, paths, session_info,
samdb = SamDB(paths.samdb, session_info=session_info,
credentials=credentials, lp=lp)
- domainguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID")
+ domainguid = samdb.searchone(domaindn, "objectGUID")
assert isinstance(domainguid, str)
- hostguid = samdb.searchone(Dn(samdb, domaindn), "objectGUID",
+ hostguid = samdb.searchone(domaindn, "objectGUID",
expression="(&(objectClass=computer)(cn=%s))" % hostname,
scope=SCOPE_SUBTREE)
assert isinstance(hostguid, str)
@@ -823,31 +816,6 @@ def create_zone_file(path, setup_path, samdb, dnsdomain, domaindn,
})
-def provision_ldapbase(setup_dir, message, paths):
- """Write out a DNS zone file, from the info in the current database."""
- message("Setting up LDAP base entry: %s" % domaindn)
- rdns = domaindn.split(",")
-
- rdn_dc = rdns[0][len("DC="):]
-
- def setup_path(file):
- return os.path.join(setup_dir, file)
-
- setup_file(setup_path("provision_basedn.ldif"),
- paths.ldap_basedn_ldif)
-
- setup_file(setup_path("provision_configuration_basedn.ldif"),
- paths.ldap_config_basedn_ldif)
-
- setup_file(setup_path("provision_schema_basedn.ldif"),
- paths.ldap_schema_basedn_ldif, {
- "SCHEMADN": schemadn,
- "ACI": "# no aci for local ldb",
- "EXTENSIBLEOBJECT": "objectClass: extensibleObject"})
-
- message("Please install the LDIF located in " + paths.ldap_basedn_ldif + ", " + paths.ldap_config_basedn_ldif + " and " + paths.ldap_schema_basedn_ldif + " into your LDAP server, and re-run with --ldap-backend=ldap://my.ldap.server")
-
-
def load_schema(setup_path, samdb, schemadn, netbiosname, configdn):
"""Load schema.
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index 2af56d8d8e..353eaee198 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -60,7 +60,7 @@ description: %s
:param sid: SID of the NT-side of the mapping.
:param unixname: Unix name to map to.
"""
- res = self.search(ldb.Dn(self, domaindn), ldb.SCOPE_SUBTREE,
+ res = self.search(domaindn, ldb.SCOPE_SUBTREE,
"objectSid=%s" % sid, ["dn"])
assert len(res) == 1, "Failed to find record for objectSid %s" % sid
@@ -103,7 +103,7 @@ userAccountControl: %u
res = self.search("", SCOPE_BASE, "defaultNamingContext=*",
["defaultNamingContext"])
assert(len(res) == 1 and res[0].defaultNamingContext is not None)
- domain_dn = res[0].defaultNamingContext
+ domain_dn = res[0]["defaultNamingContext"][0]
assert(domain_dn is not None)
dom_users = self.searchone(domain_dn, "dn", "name=Domain Users")
assert(dom_users is not None)
diff --git a/source4/scripting/python/samba/tests/dcerpc/__init__.py b/source4/scripting/python/samba/tests/dcerpc/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/__init__.py
diff --git a/source4/scripting/python/samba/tests/dcerpc/registry.py b/source4/scripting/python/samba/tests/dcerpc/registry.py
new file mode 100644
index 0000000000..f3f0b0fb1a
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/registry.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
+#
+
+import winreg
+from param import LoadParm
+import unittest
+
+class WinregTests(unittest.TestCase):
+ def setUp(self):
+ lp_ctx = LoadParm()
+ lp_ctx.load("st/client/client.conf")
+ self.conn = winreg.winreg("ncalrpc:", lp_ctx)
+
+ def get_hklm(self):
+ return self.conn.OpenHKLM(None,
+ winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+
+ def test_hklm(self):
+ handle = self.conn.OpenHKLM(None,
+ winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+ self.conn.CloseKey(handle)
+
+ def test_getversion(self):
+ handle = self.get_hklm()
+ version = self.conn.GetVersion(handle)
+ self.assertEquals(int, version.__class__)
+ self.conn.CloseKey(handle)
+
+ def test_getkeyinfo(self):
+ handle = self.conn.OpenHKLM(None,
+ winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS)
+ x = self.conn.QueryInfoKey(handle, winreg.String())
+ self.assertEquals(9, len(x)) # should return a 9-tuple
+ self.conn.CloseKey(handle)
diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
new file mode 100644
index 0000000000..52c2bb8c72
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
+#
+
+import echo
+from param import LoadParm
+import unittest
+
+class RpcEchoTests(unittest.TestCase):
+ def setUp(self):
+ lp_ctx = LoadParm()
+ lp_ctx.load("st/client/client.conf")
+ self.conn = echo.rpcecho("ncalrpc:", lp_ctx)
+
+ def test_addone(self):
+ self.assertEquals(2, self.conn.AddOne(1))
+
+ def test_echodata(self):
+ self.assertEquals([1,2,3], self.conn.EchoData(3, [1, 2, 3]))
+
+ def test_call(self):
+ self.assertEquals(u"foobar", self.conn.TestCall(u"foobar"))
+
+ def test_surrounding(self):
+ surrounding_struct = echo.Surrounding()
+ surrounding_struct.x = 4
+ surrounding_struct.surrounding = [1,2,3,4]
+ y = self.conn.TestSurrounding(surrounding_struct)
+ self.assertEquals(8 * [0], y.surrounding)
diff --git a/source4/scripting/python/samba/tests/dcerpc/sam.py b/source4/scripting/python/samba/tests/dcerpc/sam.py
new file mode 100644
index 0000000000..50caaf2348
--- /dev/null
+++ b/source4/scripting/python/samba/tests/dcerpc/sam.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+# Unix SMB/CIFS implementation.
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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 <http://www.gnu.org/licenses/>.
+#
+
+import samr
+import unittest
+
+class SamrTests(unittest.TestCase):
+ def setUp(self):
+ self.conn = samr.samr("ncalrpc:", "st/client/client.conf")
+
+ def test_connect5(self):
+ (level, info, handle) = self.conn.Connect5(None, 0, 1, samr.ConnectInfo1())
diff --git a/source4/scripting/python/uuidmodule.c b/source4/scripting/python/uuidmodule.c
index 02c929d4a5..e05b286dd0 100644
--- a/source4/scripting/python/uuidmodule.c
+++ b/source4/scripting/python/uuidmodule.c
@@ -18,7 +18,7 @@
*/
#include "includes.h"
-#include "Python.h"
+#include <Python.h>
#include "librpc/ndr/libndr.h"
static PyObject *uuid_random(PyObject *self, PyObject *args)
@@ -47,11 +47,9 @@ static PyMethodDef methods[] = {
{ NULL, NULL }
};
-PyDoc_STRVAR(param_doc, "UUID helper routines");
-
-PyMODINIT_FUNC inituuid(void)
+void inituuid(void)
{
- PyObject *mod = Py_InitModule3((char *)"uuid", methods, param_doc);
+ PyObject *mod = Py_InitModule3((char *)"uuid", methods, "UUID helper routines");
if (mod == NULL)
return;
}