]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
RawDCERPCTest: split prepare_pdu() and send_pdu_blob() out of send_pdu()
authorStefan Metzmacher <metze@samba.org>
Mon, 9 Nov 2020 13:00:43 +0000 (14:00 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 10 Oct 2024 14:01:04 +0000 (14:01 +0000)
This will make it possible to alter pdus before sending them to the
server.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14356

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
python/samba/tests/dcerpc/raw_testcase.py

index c2871909abc9af29ccb2b24f159111d3898655d4..aaf063c217992620cffa4534724d1620f3c06328 100644 (file)
@@ -677,34 +677,45 @@ class RawDCERPCTest(TestCase):
         self.secondary_address = None
         self.connect()
 
-    def send_pdu(self, req, ndr_print=None, hexdump=None):
+    def prepare_pdu(self, req, ndr_print=None, hexdump=None):
         if ndr_print is None:
             ndr_print = self.do_ndr_print
+        if hexdump is None:
+            hexdump = self.do_hexdump
+        req_pdu = ndr_pack(req)
+        if ndr_print:
+            sys.stderr.write("prepare_pdu: %s" % samba.ndr.ndr_print(req))
+        if hexdump:
+            sys.stderr.write("prepare_pdu: %d\n%s" % (len(req_pdu), self.hexdump(req_pdu)))
+        return req_pdu
+
+    def send_pdu_blob(self, req_pdu, hexdump=None):
         if hexdump is None:
             hexdump = self.do_hexdump
         try:
-            req_pdu = ndr_pack(req)
-            if ndr_print:
-                sys.stderr.write("send_pdu: %s" % samba.ndr.ndr_print(req))
             if hexdump:
-                sys.stderr.write("send_pdu: %d\n%s" % (len(req_pdu), self.hexdump(req_pdu)))
+                sys.stderr.write("send_pdu_blob: %d\n%s" % (len(req_pdu), self.hexdump(req_pdu)))
             while True:
                 sent = self.s.send(req_pdu, 0)
                 if sent == len(req_pdu):
                     break
                 req_pdu = req_pdu[sent:]
         except socket.error as e:
-            self._disconnect("send_pdu: %s" % e)
+            self._disconnect("send_pdu_blob: %s" % e)
             raise
         except IOError as e:
-            self._disconnect("send_pdu: %s" % e)
+            self._disconnect("send_pdu_blob: %s" % e)
             raise
         except NTSTATUSError as e:
-            self._disconnect("send_pdu: %s" % e)
+            self._disconnect("send_pdu_blob: %s" % e)
             raise
         finally:
             pass
 
+    def send_pdu(self, req, ndr_print=None, hexdump=None):
+        req_pdu = self.prepare_pdu(req, ndr_print=ndr_print, hexdump=False)
+        return self.send_pdu_blob(req_pdu, hexdump=hexdump)
+
     def recv_raw(self, hexdump=None, timeout=None):
         rep_pdu = None
         if hexdump is None: