From: Stefan Metzmacher Date: Mon, 9 Nov 2020 13:00:43 +0000 (+0100) Subject: RawDCERPCTest: split prepare_pdu() and send_pdu_blob() out of send_pdu() X-Git-Tag: tdb-1.4.13~962 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=444f9c6624f5c997dfdc4ae0bfb8823a56fbef70;p=thirdparty%2Fsamba.git RawDCERPCTest: split prepare_pdu() and send_pdu_blob() out of send_pdu() 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 Reviewed-by: Andreas Schneider --- diff --git a/python/samba/tests/dcerpc/raw_testcase.py b/python/samba/tests/dcerpc/raw_testcase.py index c2871909abc..aaf063c2179 100644 --- a/python/samba/tests/dcerpc/raw_testcase.py +++ b/python/samba/tests/dcerpc/raw_testcase.py @@ -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: