r6540: Implement a bunch more SAMR functions.
authorTim Potter <tpot@samba.org>
Sun, 1 May 2005 02:40:00 +0000 (02:40 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:24 +0000 (13:16 -0500)
(This used to be commit 7ab240644ec6cfd0449df7e2dfe0eb1b8a52ccdb)

source4/scripting/swig/dcerpc.i
source4/scripting/swig/samr.py
source4/scripting/swig/torture/torture_samr.py

index e41d9e4e2f0b78783866a9e3f9a56476382d7ef8..60e661f18018732bf5573a49c025be4ccd4af76b 100644 (file)
@@ -231,6 +231,7 @@ char *nt_errstr(NTSTATUS nt_code);
 %array_functions(struct samr_String, samr_String_array);
 %array_functions(struct samr_SamEntry, samr_SamEntry_array);
 %array_functions(union samr_ConnectInfo, samr_ConnectInfo_array);
 %array_functions(struct samr_String, samr_String_array);
 %array_functions(struct samr_SamEntry, samr_SamEntry_array);
 %array_functions(union samr_ConnectInfo, samr_ConnectInfo_array);
+%array_functions(struct samr_RidType, samr_RidType_array);
 
 %array_functions(struct lsa_SidPtr, lsa_SidPtr_array);
 
 
 %array_functions(struct lsa_SidPtr, lsa_SidPtr_array);
 
index c254acd11b7271037259297a88d0cc7dd12f9a5e..314f78b8ad372640cc805338877839fad6b3b3ba 100644 (file)
@@ -17,7 +17,6 @@ def sid_to_string(sid):
 
     return result
 
 
     return result
 
-
 def string_to_sid(string):
     """Convert a string SID to a Python dictionary SID.  Throws a
     ValueError if the SID string was badly formed."""
 def string_to_sid(string):
     """Convert a string SID to a Python dictionary SID.  Throws a
     ValueError if the SID string was badly formed."""
@@ -88,7 +87,6 @@ def string_to_sid(string):
 
     return sid
 
 
     return sid
 
-
 def call_fn(fn, pipe, args):
     """Wrap up a RPC call and throw an exception is an error was returned."""
     
 def call_fn(fn, pipe, args):
     """Wrap up a RPC call and throw an exception is an error was returned."""
     
@@ -98,8 +96,7 @@ def call_fn(fn, pipe, args):
         raise dcerpc.NTSTATUS(result, dcerpc.nt_errstr(result));
 
     return result;
         raise dcerpc.NTSTATUS(result, dcerpc.nt_errstr(result));
 
     return result;
-
-    
+   
 class SamrHandle:
 
     def __init__(self, pipe, handle):
 class SamrHandle:
 
     def __init__(self, pipe, handle):
@@ -139,7 +136,6 @@ class SamrHandle:
         r.data_in.sdbuf = sdbuf
 
         call_fn(dcerpc.dcerpc_samr_SetSecurity, self.pipe, r)
         r.data_in.sdbuf = sdbuf
 
         call_fn(dcerpc.dcerpc_samr_SetSecurity, self.pipe, r)
-
         
 class ConnectHandle(SamrHandle):
 
         
 class ConnectHandle(SamrHandle):
 
@@ -206,6 +202,16 @@ class ConnectHandle(SamrHandle):
         return r.data_out.info
 
 
         return r.data_out.info
 
 
+    def SetBootKeyInformation(self, unknown1, unknown2, unknown3):
+        
+        r = dcerpc.samr_GetBootKeyInformation()
+        r.data_in.connect_handle = self.handle
+        r.data_in.unknown1 = unknown1
+        r.data_in.unknown2 = unknown2
+        r.data_in.unknown3 = unknown3
+
+        call_fn(dcerpc.dcerpc_samr_SetBootKeyInformation, self.pipe, r)
+
 class DomainHandle(SamrHandle):
 
     def QueryDomainInfo(self, level = 2):
 class DomainHandle(SamrHandle):
 
     def QueryDomainInfo(self, level = 2):
@@ -402,8 +408,10 @@ class DomainHandle(SamrHandle):
 
         call_fn(dcerpc.dcerpc_samr_LookupNames, self.pipe, r)
 
 
         call_fn(dcerpc.dcerpc_samr_LookupNames, self.pipe, r)
 
-        return ([dcerpc.uint32_array_getitem(r.data_out.rids.ids, i) for i in range(r.data_out.rids.count)],
-                [dcerpc.uint32_array_getitem(r.data_out.types.ids, i) for i in range(r.data_out.types.count)])
+        return ([dcerpc.uint32_array_getitem(r.data_out.rids.ids, i)
+                 for i in range(r.data_out.rids.count)],
+                [dcerpc.uint32_array_getitem(r.data_out.types.ids, i)
+                 for i in range(r.data_out.types.count)])
 
     def CreateDomainGroup(self, domain_name, access_mask = 0x02000000):
 
 
     def CreateDomainGroup(self, domain_name, access_mask = 0x02000000):
 
@@ -486,6 +494,28 @@ class DomainHandle(SamrHandle):
 
         return getattr(r.data_out.info, 'info%d' % level)
 
 
         return getattr(r.data_out.info, 'info%d' % level)
 
+    def GetBootKeyInformation(self):
+
+        r = dcerpc.samr_GetBootKeyInformation()
+        r.data_in.domain_handle = self.handle
+
+        call_fn(dcerpc.dcerpc_samr_GetBootKeyInformation, self.pipe, r)
+
+        return r.data_out.unknown
+
+    def SetBootKeyInformation(self):
+
+        r = dcerpc.samr_GetBootKeyInformation()
+        r.data_in.domain_handle = self.handle
+
+        call_fn(dcerpc.dcerpc_samr_GetBootKeyInformation, self.pipe, r)
+
+    def TestPrivateFunctionsDomain(self):
+
+        r = dcerpc.samr_TestPrivateFunctionsDomain()
+        r.data_in.domain_handle = self.handle
+
+        call_fn(dcerpc.dcerpc_samr_TestPrivateFunctionsDomain, self.pipe, r)
 
 class UserHandle(SamrHandle):
 
 
 class UserHandle(SamrHandle):
 
@@ -527,10 +557,57 @@ class UserHandle(SamrHandle):
 
         return r.data_out.info
 
 
         return r.data_out.info
 
+    def GetGroupsForUser(self):
+
+        r = dcerpc.samr_GetGroupsForUser()
+        r.data_in.user_handle = self.handle
+
+        call_fn(dcerpc.dcerpc_samr_GetGroupsForUser, self.pipe, r)
+
+        rid_types = [dcerpc.samr_RidType_array_getitem(r.data_out.rids.rid, x)
+                     for x in range(r.data_out.rids.count)]
+
+        return [(x.rid, x.type) for x in rid_types]
+
+    def TestPrivateFunctionsUser(self):
+
+        r = dcerpc.samr_TestPrivateFunctionsUser()
+        r.data_in.user_handle = self.handle
+
+        call_fn(dcerpc.dcerpc_samr_TestPrivateFunctionsUser, self.pipe, r)
+            
 class GroupHandle(SamrHandle):
 class GroupHandle(SamrHandle):
-    pass
-    
 
 
+    def QueryGroupInfo(self, level):
+
+        r = dcerpc.samr_QueryGroupInfo()
+        r.data_in.group_handle = self.handle
+        r.data_in.level = level
+
+        call_fn(dcerpc.dcerpc_samr_QueryGroupInfo, self.pipe, r)
+
+        return r.data_out.info
+
+    def SetGroupInfo(self, level, info):
+
+        r = dcerpc.samr_SetGroupInfo()
+        r.data_in.group_handle = self.handle
+        r.data_in.level = level
+        r.data_in.info = info
+
+        call_fn(dcerpc.dcerpc_samr_SetGroupInfo, self.pipe, r)
+
+    def QueryGroupMember(self):
+
+        r = dcerpc.samr_QueryGroupMember()
+        r.data_in.group_handle = self.handle
+
+        call_fn(dcerpc.dcerpc_samr_QueryGroupMember, self.pipe, r)
+
+        return [(dcerpc.uint32_array_getitem(r.data_out.rids.rids, x),
+                 dcerpc.uint32_array_getitem(r.data_out.rids.unknown, x))
+                for x in range(r.data_out.rids.count)]
+    
 class AliasHandle(SamrHandle):
 
     def DeleteDomAlias(self):
 class AliasHandle(SamrHandle):
 
     def DeleteDomAlias(self):
@@ -584,6 +661,18 @@ class AliasHandle(SamrHandle):
 
         call_fn(dcerpc.dcerpc_samr_AddMultipleMembersToAlias, self.pipe, r)
 
 
         call_fn(dcerpc.dcerpc_samr_AddMultipleMembersToAlias, self.pipe, r)
 
+    def GetMembersInAlias(self):
+
+        r = dcerpc.samr_GetMembersInAlias()
+        r.data_in.alias_handle = self.handle
+
+        call_fn(dcerpc.dcerpc_samr_GetMembersInAlias, self.pipe, r)
+
+        return [
+            sid_to_string(
+                dcerpc.lsa_SidPtr_array_getitem(r.data_out.sids.sids, x).sid)
+            for x in range(r.data_out.sids.num_sids)]
+
 def Connect(pipe, access_mask = 0x02000000):
 
     r = dcerpc.samr_Connect()
 def Connect(pipe, access_mask = 0x02000000):
 
     r = dcerpc.samr_Connect()
@@ -595,7 +684,6 @@ def Connect(pipe, access_mask = 0x02000000):
 
     return ConnectHandle(pipe, r.data_out.connect_handle)
 
 
     return ConnectHandle(pipe, r.data_out.connect_handle)
 
-
 def Connect2(pipe, system_name = '', access_mask = 0x02000000):
     """Connect to the SAMR pipe."""
 
 def Connect2(pipe, system_name = '', access_mask = 0x02000000):
     """Connect to the SAMR pipe."""
 
@@ -607,7 +695,6 @@ def Connect2(pipe, system_name = '', access_mask = 0x02000000):
 
     return ConnectHandle(pipe, r.data_out.connect_handle)
 
 
     return ConnectHandle(pipe, r.data_out.connect_handle)
 
-
 def Connect3(pipe, system_name = '', access_mask = 0x02000000):
 
     r = dcerpc.samr_Connect3()
 def Connect3(pipe, system_name = '', access_mask = 0x02000000):
 
     r = dcerpc.samr_Connect3()
@@ -645,30 +732,22 @@ def Connect5(pipe, system_name = '', access_mask = 0x02000000):
 
     return ConnectHandle(pipe, r.data_out.connect_handle)
     
 
     return ConnectHandle(pipe, r.data_out.connect_handle)
     
-# QueryGroupInfo
-# SetGroupInfo
 # AddGroupMember
 # DeleteDomainGroup
 # DeleteGroupMember
 # AddGroupMember
 # DeleteDomainGroup
 # DeleteGroupMember
-# QueryGroupMember
 # SetMemberAttributesofGroup
 # AddAliasMember
 # DeleteAliasMember
 # GetMembersinAlias
 # SetUserInfo
 # ChangePasswordUser
 # SetMemberAttributesofGroup
 # AddAliasMember
 # DeleteAliasMember
 # GetMembersinAlias
 # SetUserInfo
 # ChangePasswordUser
-# GetGroupsForUser
 # GetDisplayEnumerationIndex
 # GetDisplayEnumerationIndex
-# TestPrivateFunctionsDomain
-# TestPrivateFunctionsUser
 # RemoveMemberFromForeignDomain
 # GetDisplayEnumerationIndex2
 # RemoveMultipleMembersFromAlias
 # OemChangePasswordUser2
 # ChangePasswordUser2
 # SetUserInfo2
 # RemoveMemberFromForeignDomain
 # GetDisplayEnumerationIndex2
 # RemoveMultipleMembersFromAlias
 # OemChangePasswordUser2
 # ChangePasswordUser2
 # SetUserInfo2
-# SetBootKeyInformation
-# GetBootKeyInformation
 # ChangePasswordUser3
 # SetDsrmPassword
 # ValidatePassword
 # ChangePasswordUser3
 # SetDsrmPassword
 # ValidatePassword
index 9025fdd9786e10f1a6ea0ee1559d72e22a6dca4a..15c6dc1a76bec7b332a361c647c7687190be28ae 100755 (executable)
@@ -42,18 +42,43 @@ def test_UserHandle(user_handle):
             if arg[0] != 0xc0000003L:   # NT_STATUS_INVALID_INFO_CLASS
                 raise
 
             if arg[0] != 0xc0000003L:   # NT_STATUS_INVALID_INFO_CLASS
                 raise
 
+    # GetGroupsForUser()
+
+    user_handle.GetGroupsForUser()
+
+    # TestPrivateFunctionsUser()
+
+    try:
+        user_handle.TestPrivateFunctionsUser()
+    except dcerpc.NTSTATUS, arg:
+        if arg[0] != 0xC0000002L:
+            raise
+
 def test_GroupHandle(group_handle):
 
     # QuerySecurity()/SetSecurity()
 
     group_handle.SetSecurity(group_handle.QuerySecurity())
 
 def test_GroupHandle(group_handle):
 
     # QuerySecurity()/SetSecurity()
 
     group_handle.SetSecurity(group_handle.QuerySecurity())
 
+    # QueryGroupInfo()
+
+    for level in [1, 2, 3, 4, 5]:
+        info = group_handle.QueryGroupInfo(level)
+
+    # TODO: SetGroupinfo()
+
+    # QueryGroupMember()
+
+    group_handle.QueryGroupMember()
+
 def test_AliasHandle(alias_handle):
 
     # QuerySecurity()/SetSecurity()
 
     alias_handle.SetSecurity(alias_handle.QuerySecurity())
 
 def test_AliasHandle(alias_handle):
 
     # QuerySecurity()/SetSecurity()
 
     alias_handle.SetSecurity(alias_handle.QuerySecurity())
 
+    print alias_handle.GetMembersInAlias()
+
 def test_DomainHandle(name, sid, domain_handle):
 
     print 'testing %s (%s)' % (name, sid)
 def test_DomainHandle(name, sid, domain_handle):
 
     print 'testing %s (%s)' % (name, sid)
@@ -142,6 +167,21 @@ def test_DomainHandle(name, sid, domain_handle):
     # CreateDomainGroup
     # GetAliasMembership
 
     # CreateDomainGroup
     # GetAliasMembership
 
+    # GetBootKeyInformation()
+
+    try:
+        domain_handle.GetBootKeyInformation()
+    except dcerpc.NTSTATUS, arg:
+        pass
+
+    # TestPrivateFunctionsDomain()
+
+    try:
+        domain_handle.TestPrivateFunctionsDomain()
+    except dcerpc.NTSTATUS, arg:
+        if arg[0] != 0xC0000002L:
+            raise
+
 def test_ConnectHandle(connect_handle):
 
     print 'testing connect handle'
 def test_ConnectHandle(connect_handle):
 
     print 'testing connect handle'