summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsource4/scripting/bin/samr.py114
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/sam.py2
-rwxr-xr-xsource4/selftest/samba4_tests.sh2
-rwxr-xr-xtestprogs/ejs/samr.js126
4 files changed, 117 insertions, 127 deletions
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 <jelmer@samba.org> 2008
+#
+# Based on samr.js © Andrew Tridgell <tridge@samba.org>
+#
+# 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
+
+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 <BINDING>"
+ 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<users.length;i++) {
- println("\t" + users[i].name + "\t(" + users[i].idx + ")");
- }
-}
-
-/*
- test the samr_EnumDomainGroups interface
-*/
-function test_EnumDomainGroups(samr, dom_handle)
-{
- print("Testing samr_EnumDomainGroups\n");
- var i, groups = samrEnumDomainGroups(samr, dom_handle);
- print("Found " + groups.length + " groups\n");
- for (i=0;i<groups.length;i++) {
- println("\t" + groups[i].name + "\t(" + groups[i].idx + ")");
- }
-}
-
-/*
- test domain specific ops
-*/
-function test_domain_ops(samr, dom_handle)
-{
- test_EnumDomainUsers(samr, dom_handle);
- test_EnumDomainGroups(samr, dom_handle);
-}
-
-
-
-/*
- test the samr_EnumDomains interface
-*/
-function test_EnumDomains(samr, handle)
-{
- var i, domains;
- print("Testing samr_EnumDomains\n");
-
- domains = samrEnumDomains(samr, handle);
- print("Found " + domains.length + " domains\n");
- for (i=0;i<domains.length;i++) {
- print("\t" + domains[i].name + "\n");
- }
- for (i=0;i<domains.length;i++) {
- print("Testing domain " + domains[i].name + "\n");
- sid = samrLookupDomain(samr, handle, domains[i].name);
- dom_handle = test_OpenDomain(samr, handle, sid);
- test_domain_ops(samr, dom_handle);
- samrClose(samr, dom_handle);
- }
-}
-
-if (options.ARGV.length != 1) {
- println("Usage: samr.js <BINDING>");
- 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;