r3590: Add some more commands to rpcclient from a patch by jbm. Add
authorTim Potter <tpot@samba.org>
Sun, 7 Nov 2004 01:11:11 +0000 (01:11 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:05:36 +0000 (13:05 -0500)
SamrQueryDomInfo, SamrQueryDomInfo2, SamrEnumDomainAliases, and
SamrEnumDomainUsers.
(This used to be commit 91eb405354a65bfd94bf59c21fe21f68fff7b9fd)

source4/scripting/swig/rpcclient
source4/scripting/swig/samr.py

index 2a3d12cc8e942f533e2f7ba242b8e7bc36cf23b2..aad4597053fd882f50222fe1e9222ba075522480 100755 (executable)
@@ -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
index 5fd87da3ad94bc7c38b2a5e545db182c26460cb5..d29b7f66825b3d9a83d4f21c81c9e50e65c384ee 100644 (file)
@@ -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."""