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(+) (limited to 'source4/scripting/bin') 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 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 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 source4/scripting/bin/samr.py (limited to 'source4/scripting/bin') 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" -- 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 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/scripting/bin') 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""" -- 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 (limited to 'source4/scripting/bin') 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 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(-) (limited to 'source4/scripting/bin') 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 04:14:28 +0200 Subject: Allow using IRPC functions on the messaging bus from Python. (This used to be commit 6ecf81ae13dffa05356c1177c617206c120fb7d7) --- source4/scripting/bin/smbstatus | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'source4/scripting/bin') 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/scripting/bin/smbstatus | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source4/scripting/bin') 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 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source4/scripting/bin') 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) -- 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 ------------------------------ 3 files changed, 2 insertions(+), 203 deletions(-) delete mode 100755 source4/scripting/bin/samr.py delete mode 100755 source4/scripting/bin/winreg.py (limited to 'source4/scripting/bin') 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) -- 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 (limited to 'source4/scripting/bin') 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