mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
librpc:tools: Migrate ndrdump to new cmdline option parser
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
70a09d2cee
commit
a8052d70cb
@ -24,7 +24,7 @@
|
||||
#include "librpc/ndr/libndr.h"
|
||||
#include "librpc/ndr/ndr_table.h"
|
||||
#include "librpc/gen_ndr/ndr_dcerpc.h"
|
||||
#include "lib/cmdline/popt_common.h"
|
||||
#include "lib/cmdline/cmdline.h"
|
||||
#include "param/param.h"
|
||||
#include "lib/util/base64.h"
|
||||
|
||||
@ -316,11 +316,12 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
|
||||
"Try to print structures that fail to parse (used to develop parsers, segfaults are likely).", NULL },
|
||||
POPT_COMMON_SAMBA
|
||||
POPT_COMMON_VERSION
|
||||
{0}
|
||||
POPT_TABLEEND
|
||||
};
|
||||
uint32_t highest_ofs;
|
||||
struct dcerpc_sec_verification_trailer *sec_vt = NULL;
|
||||
|
||||
bool ok;
|
||||
|
||||
ndr_table_init();
|
||||
|
||||
/* Initialise samba stuff */
|
||||
@ -328,10 +329,31 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
|
||||
|
||||
setlinebuf(stdout);
|
||||
|
||||
setup_logging("ndrdump", DEBUG_STDOUT);
|
||||
mem_ctx = talloc_init("ndrdump.c/main");
|
||||
if (mem_ctx == NULL) {
|
||||
exit(ENOMEM);
|
||||
}
|
||||
|
||||
ok = samba_cmdline_init(mem_ctx,
|
||||
SAMBA_CMDLINE_CONFIG_CLIENT,
|
||||
false /* require_smbconf */);
|
||||
if (!ok) {
|
||||
DBG_ERR("Failed to init cmdline parser!\n");
|
||||
TALLOC_FREE(mem_ctx);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pc = samba_popt_get_context(getprogname(),
|
||||
argc,
|
||||
argv,
|
||||
long_options,
|
||||
0);
|
||||
if (pc == NULL) {
|
||||
DBG_ERR("Failed to setup popt context!\n");
|
||||
TALLOC_FREE(mem_ctx);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pc = poptGetContext("ndrdump", argc, argv, long_options, 0);
|
||||
|
||||
poptSetOtherOptionHelp(
|
||||
pc, "<pipe|uuid> <format> <in|out|struct> [<filename>]");
|
||||
|
||||
@ -427,9 +449,6 @@ static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mem_ctx = talloc_init("ndrdump");
|
||||
|
||||
st = talloc_zero_size(mem_ctx, f->struct_size);
|
||||
if (!st) {
|
||||
printf("Unable to allocate %d bytes for %s structure\n",
|
||||
|
@ -3,5 +3,5 @@
|
||||
bld.SAMBA_BINARY('ndrdump',
|
||||
source='ndrdump.c',
|
||||
manpages='ndrdump.1',
|
||||
deps='samba-hostconfig samba-util popt POPT_SAMBA ndr-table samba-errors NDR_DCERPC'
|
||||
deps='samba-hostconfig samba-util popt CMDLINE_S4 ndr-table samba-errors NDR_DCERPC'
|
||||
)
|
||||
|
@ -33,33 +33,33 @@ class NdrDumpTests(BlackboxTestCase):
|
||||
return os.path.join(data_path_dir, name)
|
||||
|
||||
def test_ndrdump_with_in(self):
|
||||
self.check_run(("ndrdump samr samr_CreateUser in %s" %
|
||||
self.check_run(("ndrdump --debug-stdout samr samr_CreateUser in %s" %
|
||||
(self.data_path("samr-CreateUser-in.dat"))))
|
||||
|
||||
def test_ndrdump_with_out(self):
|
||||
self.check_run(("ndrdump samr samr_CreateUser out %s" %
|
||||
self.check_run(("ndrdump --debug-stdout samr samr_CreateUser out %s" %
|
||||
(self.data_path("samr-CreateUser-out.dat"))))
|
||||
|
||||
def test_ndrdump_context_file(self):
|
||||
self.check_run(
|
||||
("ndrdump --context-file %s samr samr_CreateUser out %s" %
|
||||
("ndrdump --debug-stdout --context-file %s samr samr_CreateUser out %s" %
|
||||
(self.data_path("samr-CreateUser-in.dat"),
|
||||
self.data_path("samr-CreateUser-out.dat"))))
|
||||
|
||||
def test_ndrdump_with_validate(self):
|
||||
self.check_run(("ndrdump --validate samr samr_CreateUser in %s" %
|
||||
self.check_run(("ndrdump --debug-stdout --validate samr samr_CreateUser in %s" %
|
||||
(self.data_path("samr-CreateUser-in.dat"))))
|
||||
|
||||
def test_ndrdump_with_hex_decode_function(self):
|
||||
self.check_run(
|
||||
("ndrdump dns decode_dns_name_packet in --hex-input %s" %
|
||||
("ndrdump --debug-stdout dns decode_dns_name_packet in --hex-input %s" %
|
||||
self.data_path("dns-decode_dns_name_packet-hex.dat")))
|
||||
|
||||
def test_ndrdump_with_hex_struct_name(self):
|
||||
expected = open(self.data_path("dns-decode_dns_name_packet-hex.txt")).read()
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump dns dns_name_packet struct --hex-input %s" %
|
||||
"ndrdump --debug-stdout dns dns_name_packet struct --hex-input %s" %
|
||||
self.data_path("dns-decode_dns_name_packet-hex.dat"))
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -78,7 +78,7 @@ class NdrDumpTests(BlackboxTestCase):
|
||||
buffers: ARRAY(5)'''
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump krb5pac PAC_DATA struct %s" %
|
||||
"ndrdump --debug-stdout krb5pac PAC_DATA struct %s" %
|
||||
self.data_path("krb5pac-PAC_DATA.dat"))
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -96,7 +96,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump misc 0 struct %s" %
|
||||
"ndrdump --debug-stdout misc 0 struct %s" %
|
||||
self.data_path("misc-GUID.dat"))
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -110,7 +110,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
"ndrdump misc netr_SchannelType --input=x struct",
|
||||
"ndrdump --debug-stdout misc netr_SchannelType --input=x struct",
|
||||
1)
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -124,7 +124,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
"ndrdump -d0 misc GUID struct --input=abcdefg", 2)
|
||||
"ndrdump --debug-stdout -d0 misc GUID struct --input=abcdefg", 2)
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
|
||||
@ -140,7 +140,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
"ndrdump -d0 misc GUID struct --input=abcdefg --dump-data", 2)
|
||||
"ndrdump --debug-stdout -d0 misc GUID struct --input=abcdefg --dump-data", 2)
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
|
||||
@ -162,7 +162,7 @@ dump of failed-to-parse GUID complete
|
||||
'''
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
"ndrdump -d0 misc GUID struct --input=abcdefg --dump-data --print-after-parse-failure", 2)
|
||||
"ndrdump --debug-stdout -d0 misc GUID struct --input=abcdefg --dump-data --print-after-parse-failure", 2)
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
|
||||
@ -192,7 +192,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_output(
|
||||
'ndrdump clusapi clusapi_QueryAllValues out ' +\
|
||||
'ndrdump --debug-stdout clusapi clusapi_QueryAllValues out ' +\
|
||||
'--base64-input --input=' +\
|
||||
'AAAAAQEAAAAAAAAAAAAAAAgAAAAA/wAA/wAAAAAJAAAACAAzMzI3NjI2OTMyNzY4NAEAAIAyDf8AAP8AAAAACAAAABzxKQgAAA==')
|
||||
except BlackboxProcessError as e:
|
||||
@ -204,7 +204,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
'ndrdump IOXIDResolver ResolveOxid out ' +\
|
||||
'ndrdump --debug-stdout IOXIDResolver ResolveOxid out ' +\
|
||||
'--base64-input --input=' +\
|
||||
'c87PMf7CBAUAAAAADgQMBASjfPqKw0KPld6DY87PMfQ=',
|
||||
2)
|
||||
@ -217,7 +217,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
'ndrdump IOXIDResolver ResolveOxid2 out ' +\
|
||||
'ndrdump --debug-stdout IOXIDResolver ResolveOxid2 out ' +\
|
||||
'--base64-input --input=' +\
|
||||
'AAAAAQ0K9Q0AAAAAAAAAA6ampqampqampqampqampqampqampqamNAAAAAAtNDQ=',
|
||||
2)
|
||||
@ -238,7 +238,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_output(
|
||||
'ndrdump IOXIDResolver ServerAlive out ' +\
|
||||
'ndrdump --debug-stdout IOXIDResolver ServerAlive out ' +\
|
||||
'--base64-input --input=' +\
|
||||
'AAAAAQ02CgoKCgoAAAAAAAAAAwAAAAEAADM5NjE2MTc3Njg0MjT8haxJC2GHCgoK9QA=')
|
||||
except BlackboxProcessError as e:
|
||||
@ -250,7 +250,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
'ndrdump IRemoteActivation RemoteActivation out ' +\
|
||||
'ndrdump --debug-stdout IRemoteActivation RemoteActivation out ' +\
|
||||
'--base64-input --input=' +\
|
||||
'AAAAAQAAAAAAAABKAAD/AAAAAP4AAAAAAAAASgAAAAAAAAABIiIjIiIiIiIiIiIiIiMiAAAAAAD/AAAAAAAA',
|
||||
2)
|
||||
@ -262,7 +262,7 @@ dump OK
|
||||
expected = open(self.data_path("fuzzed_ntlmssp-AUTHENTICATE_MESSAGE.txt")).read()
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump ntlmssp AUTHENTICATE_MESSAGE struct --base64-input %s --validate" %
|
||||
"ndrdump --debug-stdout ntlmssp AUTHENTICATE_MESSAGE struct --base64-input %s --validate" %
|
||||
self.data_path("fuzzed_ntlmssp-AUTHENTICATE_MESSAGE.b64.txt"))
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -273,7 +273,7 @@ dump OK
|
||||
def test_ndrdump_fuzzed_PackagesBlob(self):
|
||||
expected = 'ndr_pull_string: ndr_pull_error\\(Buffer Size Error\\):'
|
||||
command = (
|
||||
"ndrdump drsblobs package_PackagesBlob struct --input='aw=='"
|
||||
"ndrdump --debug-stdout drsblobs package_PackagesBlob struct --input='aw=='"
|
||||
" --base64-input")
|
||||
try:
|
||||
actual = self.check_exit_code(command, 2)
|
||||
@ -287,7 +287,7 @@ dump OK
|
||||
expected = open(self.data_path("fuzzed_drsuapi_DsAddEntry_1.txt")).read()
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump drsuapi drsuapi_DsAddEntry in --base64-input --validate %s" %
|
||||
"ndrdump --debug-stdout drsuapi drsuapi_DsAddEntry in --base64-input --validate %s" %
|
||||
self.data_path("fuzzed_drsuapi_DsAddEntry_1.b64.txt"))
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -299,7 +299,7 @@ dump OK
|
||||
expected = "Maximum Recursion Exceeded"
|
||||
try:
|
||||
self.check_output(
|
||||
"ndrdump drsuapi 17 out --base64-input %s" %
|
||||
"ndrdump --debug-stdout drsuapi 17 out --base64-input %s" %
|
||||
self.data_path(
|
||||
"fuzzed_drsuapi_DsaAddressListItem_V1-in.b64.txt"))
|
||||
self.fail("Input should have been rejected with %s" % expected)
|
||||
@ -311,7 +311,7 @@ dump OK
|
||||
expected = open(self.data_path("fuzzed_drsuapi_DsReplicaAttribute.txt")).read()
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump drsuapi drsuapi_DsReplicaAttribute struct --base64-input --validate %s" %
|
||||
"ndrdump --debug-stdout drsuapi drsuapi_DsReplicaAttribute struct --base64-input --validate %s" %
|
||||
self.data_path("fuzzed_drsuapi_DsReplicaAttribute.b64.txt"))
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -329,7 +329,7 @@ dump OK
|
||||
# extraneous output.
|
||||
actual = self.check_output(
|
||||
"ndrdump krb5ccache CCACHE struct "
|
||||
"--configfile /dev/null -d1 --validate " +
|
||||
"--configfile /dev/null --debug-stdout -d1 --validate " +
|
||||
self.data_path("../../../source3/selftest/"
|
||||
"ktest-krb5_ccache-2"))
|
||||
except BlackboxProcessError as e:
|
||||
@ -347,7 +347,7 @@ dump OK
|
||||
# extraneous output.
|
||||
actual = self.check_output(
|
||||
"ndrdump krb5ccache CCACHE struct "
|
||||
"--configfile /dev/null -d1 --validate " +
|
||||
"--configfile /dev/null --debug-stdout -d1 --validate " +
|
||||
self.data_path("../../../source3/selftest/"
|
||||
"ktest-krb5_ccache-3"))
|
||||
except BlackboxProcessError as e:
|
||||
@ -385,7 +385,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump spoolss spoolss_EnumForms out --base64-input " +\
|
||||
"ndrdump --debug-stdout spoolss spoolss_EnumForms out --base64-input " +\
|
||||
"--input AAAAAQAAAAAAAAAAAAEAAACpqakAAA="
|
||||
)
|
||||
except BlackboxProcessError as e:
|
||||
@ -402,7 +402,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump xattr xattr_NTACL struct --hex-input %s --validate" %
|
||||
"ndrdump --debug-stdout xattr xattr_NTACL struct --hex-input %s --validate" %
|
||||
self.data_path("xattr_NTACL.dat"))
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -417,7 +417,7 @@ dump OK
|
||||
expected = open(self.data_path("dnsp-DnssrvRpcRecord.txt")).read().encode('utf8')
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump dnsp dnsp_DnssrvRpcRecord struct " +\
|
||||
"ndrdump --debug-stdout dnsp dnsp_DnssrvRpcRecord struct " +\
|
||||
"--input BQAPAAXwAAC3AAAAAAADhAAAAAAAAAAAAAoBAAA= "+\
|
||||
"--base64-input --validate")
|
||||
except BlackboxProcessError as e:
|
||||
@ -449,7 +449,7 @@ dump OK
|
||||
'''
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump krb5pac PAC_BUFFER struct --validate --input " +\
|
||||
"ndrdump --debug-stdout krb5pac PAC_BUFFER struct --validate --input " +\
|
||||
"QPM4QcaShwQAAAAAAAAABvX/ADw8Jf9wFh+gEoQ= --base64-input")
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -461,7 +461,7 @@ dump OK
|
||||
expected = open(self.data_path("fuzzed_ntlmssp-CHALLENGE_MESSAGE.txt")).read().encode('utf8')
|
||||
try:
|
||||
actual = self.check_exit_code(
|
||||
"ndrdump ntlmssp CHALLENGE_MESSAGE struct --validate --input " +\
|
||||
"ndrdump --debug-stdout ntlmssp CHALLENGE_MESSAGE struct --validate --input " +\
|
||||
"'AAAACwIAAAAAJwIAAAAAAAcAAAAAAAAAAIAbhG8uyk9dAL0mQE73MAAAAAAAAAAA' --base64-input",
|
||||
1)
|
||||
except BlackboxProcessError as e:
|
||||
@ -479,7 +479,7 @@ dump OK
|
||||
expected = open(self.data_path("fuzzed_drsuapi_DsGetNCChanges.txt"), 'rb').read()
|
||||
try:
|
||||
actual = self.check_output(
|
||||
"ndrdump drsuapi 3 out --base64-input --input " +\
|
||||
"ndrdump --debug-stdout drsuapi 3 out --base64-input --input " +\
|
||||
"AQAAAAEAAAAGAKoAAAAGAKoGAAMAAQAAAAYAEwAAAAAAAAAA/wAAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAABbAAAAAAAAAAAAAAkRAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPkAAAAAAAABAAD4BgATAAAAAAAAAAD/AAAAAAAAAD8AAAAAAAAAAAAAAAAAAAAAAFsAAAAAAAAAAAAABgAQAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAMAAAABAAAACREAAAEAAAABAAAAAAAAAAYAEAABAAgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAA=")
|
||||
except BlackboxProcessError as e:
|
||||
self.fail(e)
|
||||
@ -489,7 +489,7 @@ dump OK
|
||||
def test_ndrdump_fuzzed_ndr_compression(self):
|
||||
expected = 'pull returned Buffer Size Error'
|
||||
command = (
|
||||
"ndrdump drsuapi 3 out --base64-input "
|
||||
"ndrdump --debug-stdout drsuapi 3 out --base64-input "
|
||||
"--input BwAAAAcAAAAGAAAAAwAgICAgICAJAAAAICAgIAkAAAAgIAAA//////8=")
|
||||
try:
|
||||
actual = self.check_exit_code(command, 2)
|
||||
@ -512,7 +512,7 @@ dump OK
|
||||
dump OK
|
||||
'''
|
||||
command = (
|
||||
"ndrdump dnsp dnsp_DnsProperty_short struct --base64-input "
|
||||
"ndrdump --debug-stdout dnsp dnsp_DnsProperty_short struct --base64-input "
|
||||
"--input AAAAAAAAAAAAAAAAAQAAAJIAAAAAAAAA")
|
||||
try:
|
||||
actual = self.check_output(command)
|
||||
|
Loading…
x
Reference in New Issue
Block a user