From 2fddd2e2d5fb32ff15a170acc443218481986b91 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 13 Oct 2008 15:58:45 +0200 Subject: Share ndrdump implementation. --- source3/lib/util.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index ec43ea7037..418ae41392 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -2217,25 +2217,60 @@ void print_asc(int level, const unsigned char *buf,int len) DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.')); } -void dump_data(int level, const unsigned char *buf1,int len) +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + */ +static void _dump_data(int level, const uint8_t *buf, int len, + bool omit_zero_bytes) { - const unsigned char *buf = (const unsigned char *)buf1; int i=0; + const uint8_t empty[16]; + bool skipped = false; + if (len<=0) return; if (!DEBUGLVL(level)) return; - - DEBUGADD(level,("[%03X] ",i)); + + memset(&empty, '\0', 16); + for (i=0;i 0) && + (len > i+16) && + (memcmp(&buf[i], &empty, 16) == 0)) + { + i +=16; + continue; + } + + if (i i+16) && + (memcmp(&buf[i], &empty, 16) == 0)) { + if (!skipped) { + DEBUGADD(level,("skipping zero buffer bytes\n")); + skipped = true; + } + } } } + if (i%16) { int n; n = 16 - (i%16); @@ -2248,8 +2283,32 @@ void dump_data(int level, const unsigned char *buf1,int len) if (n>0) print_asc(level,&buf[i-n],n); DEBUGADD(level,("\n")); } + +} + +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + */ +_PUBLIC_ void dump_data(int level, const uint8_t *buf, int len) +{ + _dump_data(level, buf, len, false); } +/** + * Write dump of binary data to the log file. + * + * The data is only written if the log level is at least level. + * 16 zero bytes in a row are ommited + */ +_PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len) +{ + _dump_data(level, buf, len, true); +} + + + void dump_data_pw(const char *msg, const uchar * data, size_t len) { #ifdef DEBUG_PASSWORD -- cgit