diff options
author | Tim Potter <tpot@samba.org> | 2004-11-07 01:11:11 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:05:36 -0500 |
commit | e34ee4fdaa4f8b6ae7167b663c2acda2654f2895 (patch) | |
tree | 55141d36380880db4ece7658b1bbda360d66521c | |
parent | 6c32daf320b1c70db38199ffcdb0e1c25a207a13 (diff) | |
download | samba-e34ee4fdaa4f8b6ae7167b663c2acda2654f2895.tar.gz samba-e34ee4fdaa4f8b6ae7167b663c2acda2654f2895.tar.bz2 samba-e34ee4fdaa4f8b6ae7167b663c2acda2654f2895.zip |
r3590: Add some more commands to rpcclient from a patch by jbm. Add
SamrQueryDomInfo, SamrQueryDomInfo2, SamrEnumDomainAliases, and
SamrEnumDomainUsers.
(This used to be commit 91eb405354a65bfd94bf59c21fe21f68fff7b9fd)
-rwxr-xr-x | source4/scripting/swig/rpcclient | 133 | ||||
-rw-r--r-- | source4/scripting/swig/samr.py | 59 |
2 files changed, 186 insertions, 6 deletions
diff --git a/source4/scripting/swig/rpcclient b/source4/scripting/swig/rpcclient index 2a3d12cc8e..aad4597053 100755 --- a/source4/scripting/swig/rpcclient +++ b/source4/scripting/swig/rpcclient @@ -3,7 +3,7 @@ import sys, os, string from cmd import Cmd from optparse import OptionParser - +from pprint import pprint import dcerpc, samr @@ -96,6 +96,137 @@ class rpcclient(Cmd): print connect_handle.LookupDomain(args[0]) + def do_SamrQueryDomInfo(self, line): + """Return information about a domain designated by its SID.""" + + usage = 'SamrQueryDomInfo DOMAIN_SID [info_level]' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if (len(args) == 0) or (len(args) > 2): + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + self.binding, + dcerpc.DCERPC_SAMR_UUID, dcerpc.DCERPC_SAMR_VERSION, + self.domain, self.username, self.password) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + if (len(args) == 2): + result = domain_handle.QueryDomainInfo(int(args[1])) + else: + result = domain_handle.QueryDomainInfo() + + pprint(result['info']) + + def do_SamrQueryDomInfo2(self, line): + """Return information about a domain designated by its SID. (Windows 2000 and >)""" + + usage = 'SamrQueryDomInfo2 DOMAIN_SID [info_level] (Windows 2000 and >)' + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if (len(args) == 0) or (len(args) > 2): + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + self.binding, + dcerpc.DCERPC_SAMR_UUID, dcerpc.DCERPC_SAMR_VERSION, + self.domain, self.username, self.password) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + if (len(args) == 2): + result = domain_handle.QueryDomainInfo2(int(args[1])) + else: + result = domain_handle.QueryDomainInfo2() + + pprint(result['info']) + + def do_SamrEnumDomainGroups(self, line): + """Return the list of groups of a domain designated by its SID.""" + + usage = 'SamrEnumDomainGroups DOMAIN_SID' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if len(args) != 1: + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + self.binding, + dcerpc.DCERPC_SAMR_UUID, dcerpc.DCERPC_SAMR_VERSION, + self.domain, self.username, self.password) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + result = domain_handle.EnumDomainGroups() + + for r in result['sam']['entries']: + print r['name']['name'] + + def do_SamrEnumDomainAliases(self, line): + """Return the list of aliases (local groups) of a domain designated by its SID.""" + + usage = 'SamrEnumDomainAliases DOMAIN_SID' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if len(args) != 1: + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + self.binding, + dcerpc.DCERPC_SAMR_UUID, dcerpc.DCERPC_SAMR_VERSION, + self.domain, self.username, self.password) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + result = domain_handle.EnumDomainAliases() + + for r in result['sam']['entries']: + print r['name']['name'] + + def do_SamrEnumDomainUsers(self, line): + """Return the list of users of a domain designated by its SID.""" + + usage = 'SamrEnumDomainUsers DOMAIN_SID [user_account_flags]' + + parser = OptionParser(usage) + options, args = parser.parse_args(string.split(line)) + + if (len(args) == 0) or (len(args) > 2): + print 'usage:', usage + return + + pipe = dcerpc.pipe_connect( + self.binding, + dcerpc.DCERPC_SAMR_UUID, dcerpc.DCERPC_SAMR_VERSION, + self.domain, self.username, self.password) + + connect_handle = samr.Connect(pipe) + domain_handle = connect_handle.OpenDomain(args[0]) + + if (len(args) == 2): + result = domain_handle.EnumDomainUsers(int(args[1])) + else: + result = domain_handle.EnumDomainUsers() + + for r in result['sam']['entries']: + print r['name']['name'] + if __name__ == '__main__': # Parse command line diff --git a/source4/scripting/swig/samr.py b/source4/scripting/swig/samr.py index 5fd87da3ad..d29b7f6682 100644 --- a/source4/scripting/swig/samr.py +++ b/source4/scripting/swig/samr.py @@ -73,11 +73,10 @@ def string_to_sid(string): string = string[match.end():] - print map(type, sub_auths) - return {'sid_rev_num': sid_rev_num, 'id_auth': id_auth, 'num_auths': num_auths, 'sub_auths': sub_auths} + class SamrHandle: def __init__(self, pipe, handle): @@ -92,6 +91,7 @@ class SamrHandle: dcerpc.samr_Close(self.pipe, r) + class ConnectHandle(SamrHandle): def EnumDomains(self): @@ -139,20 +139,69 @@ class ConnectHandle(SamrHandle): result = dcerpc.samr_OpenDomain(self.pipe, r) - return DomainHandle(pipe, result['domain_handle']) + return DomainHandle(self.pipe, result['domain_handle']) + class DomainHandle(SamrHandle): def QueryDomainInfo(self, level = 2): r = {} - r['domain_handle'] = self.domain_handle + r['domain_handle'] = self.handle r['level'] = level - result = dcerpc.samr_QueryDomainInfo(pipe, r) + result = dcerpc.samr_QueryDomainInfo(self.pipe, r) return result + def QueryDomainInfo2(self, level = 2): + + r = {} + r['domain_handle'] = self.handle + r['level'] = level + + result = dcerpc.samr_QueryDomainInfo2(self.pipe, r) + + return result + + def EnumDomainGroups(self): + + r = {} + r['domain_handle'] = self.handle + r['resume_handle'] = 0 + r['max_size'] = 1000 + + result = dcerpc.samr_EnumDomainGroups(self.pipe, r) + + return result + + def EnumDomainAliases(self): + + r = {} + r['domain_handle'] = self.handle + r['resume_handle'] = 0 + # acct_flags in SamrEnumerateAliasesInDomain has probably + # no meaning so use 0xffffffff like W2K + r['acct_flags'] = 0xffffffff + r['max_size'] = 1000 + + result = dcerpc.samr_EnumDomainAliases(self.pipe, r) + + return result + + def EnumDomainUsers(self, user_account_flags = 16): + + r = {} + r['domain_handle'] = self.handle + r['resume_handle'] = 0 + r['acct_flags'] = user_account_flags + r['max_size'] = 1000 + + result = dcerpc.samr_EnumDomainUsers(self.pipe, r) + + return result + + def Connect(pipe, system_name = None, access_mask = 0x02000000): """Connect to the SAMR pipe.""" |