X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/bcf0fb3b48edc9e642c4101e2ccf964a30cdb6f1..dcca20dd391f15c5c63d3b033fb7d7749bb1d8cd:/smbutil.c?ds=sidebyside diff --git a/smbutil.c b/smbutil.c index 95740daa..38bd76de 100644 --- a/smbutil.c +++ b/smbutil.c @@ -6,31 +6,30 @@ * or later */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include #include -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "smb.h" -static u_int32_t stringlen; +static uint32_t stringlen; extern const u_char *startbuf; /* * interpret a 32 bit dos packed date/time to some parameters */ static void -interpret_dos_date(u_int32_t date, struct tm *tp) +interpret_dos_date(uint32_t date, struct tm *tp) { - u_int32_t p0, p1, p2, p3; + uint32_t p0, p1, p2, p3; p0 = date & 0xFF; p1 = ((date & 0xFF00) >> 8) & 0xFF; @@ -50,7 +49,7 @@ interpret_dos_date(u_int32_t date, struct tm *tp) * create a unix date from a dos date */ static time_t -int_unix_date(u_int32_t dos_date) +int_unix_date(uint32_t dos_date) { struct tm t; @@ -72,9 +71,9 @@ int_unix_date(u_int32_t dos_date) static time_t make_unix_date(const u_char *date_ptr) { - u_int32_t dos_date = 0; + uint32_t dos_date = 0; - dos_date = EXTRACT_LE_32BITS(date_ptr); + dos_date = EXTRACT_LE_U_4(date_ptr); return int_unix_date(dos_date); } @@ -86,9 +85,9 @@ make_unix_date(const u_char *date_ptr) static time_t make_unix_date2(const u_char *date_ptr) { - u_int32_t x, x2; + uint32_t x, x2; - x = EXTRACT_LE_32BITS(date_ptr); + x = EXTRACT_LE_U_4(date_ptr); x2 = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16); return int_unix_date(x2); } @@ -104,7 +103,7 @@ interpret_long_date(const u_char *p) time_t ret; /* this gives us seconds since jan 1st 1601 (approx) */ - d = (EXTRACT_LE_32BITS(p + 4) * 256.0 + p[3]) * (1.0e-7 * (1 << 24)); + d = (EXTRACT_LE_U_4(p + 4) * 256.0 + p[3]) * (1.0e-7 * (1 << 24)); /* now adjust by 369 years to make the secs since 1970 */ d -= 369.0 * 365.25 * 24 * 60 * 60; @@ -133,8 +132,9 @@ name_interpret(netdissect_options *ndo, if (in >= maxbuf) return(-1); /* name goes past the end of the buffer */ - ND_TCHECK2(*in, 1); - len = (*in++) / 2; + ND_TCHECK_1(in); + len = EXTRACT_U_1(in) / 2; + in++; *out=0; @@ -142,7 +142,7 @@ name_interpret(netdissect_options *ndo, return(0); while (len--) { - ND_TCHECK2(*in, 2); + ND_TCHECK_2(in); if (in + 1 >= maxbuf) return(-1); /* name goes past the end of the buffer */ if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') { @@ -175,18 +175,18 @@ name_ptr(netdissect_options *ndo, p = buf + ofs; if (p >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - ND_TCHECK2(*p, 1); + ND_TCHECK_1(p); c = *p; /* XXX - this should use the same code that the DNS dissector does */ if ((c & 0xC0) == 0xC0) { - u_int16_t l; + uint16_t l; - ND_TCHECK2(*p, 2); + ND_TCHECK_2(p); if ((p + 1) >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - l = EXTRACT_16BITS(p) & 0x3FFF; + l = EXTRACT_BE_U_2(p) & 0x3FFF; if (l == 0) { /* We have a pointer that points to itself. */ return(NULL); @@ -194,7 +194,7 @@ name_ptr(netdissect_options *ndo, p = buf + l; if (p >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - ND_TCHECK2(*p, 1); + ND_TCHECK_1(p); } return(p); @@ -229,15 +229,16 @@ name_len(netdissect_options *ndo, if (s >= maxbuf) return(-1); /* name goes past the end of the buffer */ - ND_TCHECK2(*s, 1); + ND_TCHECK_1(s); c = *s; if ((c & 0xC0) == 0xC0) return(2); while (*s) { if (s >= maxbuf) return(-1); /* name goes past the end of the buffer */ - ND_TCHECK2(*s, 1); + ND_TCHECK_1(s); s += (*s) + 1; + ND_TCHECK_1(s); } return(PTR_DIFF(s, s0) + 1); @@ -272,8 +273,7 @@ name_type_str(int name_type) } void -print_data(netdissect_options *ndo, - const unsigned char *buf, int len) +smb_print_data(netdissect_options *ndo, const unsigned char *buf, int len) { int i = 0; @@ -341,11 +341,11 @@ write_bits(netdissect_options *ndo, #define MAX_UNISTR_SIZE 1000 static const char * unistr(netdissect_options *ndo, - const u_char *s, u_int32_t *len, int use_unicode) + const u_char *s, uint32_t *len, int use_unicode) { static char buf[MAX_UNISTR_SIZE+1]; size_t l = 0; - u_int32_t strsize; + uint32_t strsize; const u_char *sp; if (use_unicode) { @@ -374,7 +374,7 @@ unistr(netdissect_options *ndo, strsize = *len - 1; } else { for (;;) { - ND_TCHECK2(sp[0], 2); + ND_TCHECK_2(sp); *len += 2; if (sp[0] == 0 && sp[1] == 0) break; @@ -406,7 +406,7 @@ unistr(netdissect_options *ndo, } } else { while (strsize != 0) { - ND_TCHECK2(s[0], 2); + ND_TCHECK_2(s); if (l >= MAX_UNISTR_SIZE) break; if (s[1] == 0 && ND_ISPRINT(s[0])) { @@ -450,8 +450,8 @@ smb_fdata1(netdissect_options *ndo, break; case 'A': - ND_TCHECK2(buf[0], 2); - write_bits(ndo, EXTRACT_LE_16BITS(buf), attrib_fmt); + ND_TCHECK_2(buf); + write_bits(ndo, EXTRACT_LE_U_2(buf), attrib_fmt); buf += 2; fmt++; break; @@ -504,9 +504,9 @@ smb_fdata1(netdissect_options *ndo, case 'd': { unsigned int x; - ND_TCHECK2(buf[0], 2); - x = reverse ? EXTRACT_16BITS(buf) : - EXTRACT_LE_16BITS(buf); + ND_TCHECK_2(buf); + x = reverse ? EXTRACT_BE_U_2(buf) : + EXTRACT_LE_U_2(buf); ND_PRINT((ndo, "%d (0x%x)", x, x)); buf += 2; fmt++; @@ -515,9 +515,9 @@ smb_fdata1(netdissect_options *ndo, case 'D': { unsigned int x; - ND_TCHECK2(buf[0], 4); - x = reverse ? EXTRACT_32BITS(buf) : - EXTRACT_LE_32BITS(buf); + ND_TCHECK_4(buf); + x = reverse ? EXTRACT_BE_U_4(buf) : + EXTRACT_LE_U_4(buf); ND_PRINT((ndo, "%d (0x%x)", x, x)); buf += 4; fmt++; @@ -525,10 +525,10 @@ smb_fdata1(netdissect_options *ndo, } case 'L': { - u_int64_t x; - ND_TCHECK2(buf[0], 8); - x = reverse ? EXTRACT_64BITS(buf) : - EXTRACT_LE_64BITS(buf); + uint64_t x; + ND_TCHECK_8(buf); + x = reverse ? EXTRACT_BE_U_8(buf) : + EXTRACT_LE_U_8(buf); ND_PRINT((ndo, "%" PRIu64 " (0x%" PRIx64 ")", x, x)); buf += 8; fmt++; @@ -537,14 +537,14 @@ smb_fdata1(netdissect_options *ndo, case 'M': { /* Weird mixed-endian length values in 64-bit locks */ - u_int32_t x1, x2; - u_int64_t x; - ND_TCHECK2(buf[0], 8); - x1 = reverse ? EXTRACT_32BITS(buf) : - EXTRACT_LE_32BITS(buf); - x2 = reverse ? EXTRACT_32BITS(buf + 4) : - EXTRACT_LE_32BITS(buf + 4); - x = (((u_int64_t)x1) << 32) | x2; + uint32_t x1, x2; + uint64_t x; + ND_TCHECK_8(buf); + x1 = reverse ? EXTRACT_BE_U_4(buf) : + EXTRACT_LE_U_4(buf); + x2 = reverse ? EXTRACT_BE_U_4(buf + 4) : + EXTRACT_LE_U_4(buf + 4); + x = (((uint64_t)x1) << 32) | x2; ND_PRINT((ndo, "%" PRIu64 " (0x%" PRIx64 ")", x, x)); buf += 8; fmt++; @@ -563,9 +563,9 @@ smb_fdata1(netdissect_options *ndo, case 'w': { unsigned int x; - ND_TCHECK2(buf[0], 2); - x = reverse ? EXTRACT_16BITS(buf) : - EXTRACT_LE_16BITS(buf); + ND_TCHECK_2(buf); + x = reverse ? EXTRACT_BE_U_2(buf) : + EXTRACT_LE_U_2(buf); ND_PRINT((ndo, "0x%X", x)); buf += 2; fmt++; @@ -574,9 +574,9 @@ smb_fdata1(netdissect_options *ndo, case 'W': { unsigned int x; - ND_TCHECK2(buf[0], 4); - x = reverse ? EXTRACT_32BITS(buf) : - EXTRACT_LE_32BITS(buf); + ND_TCHECK_4(buf); + x = reverse ? EXTRACT_BE_U_4(buf) : + EXTRACT_LE_U_4(buf); ND_PRINT((ndo, "0x%X", x)); buf += 4; fmt++; @@ -595,17 +595,17 @@ smb_fdata1(netdissect_options *ndo, break; case 'd': - ND_TCHECK2(buf[0], 2); - stringlen = reverse ? EXTRACT_16BITS(buf) : - EXTRACT_LE_16BITS(buf); + ND_TCHECK_2(buf); + stringlen = reverse ? EXTRACT_BE_U_2(buf) : + EXTRACT_LE_U_2(buf); ND_PRINT((ndo, "%u", stringlen)); buf += 2; break; case 'D': - ND_TCHECK2(buf[0], 4); - stringlen = reverse ? EXTRACT_32BITS(buf) : - EXTRACT_LE_32BITS(buf); + ND_TCHECK_4(buf); + stringlen = reverse ? EXTRACT_BE_U_4(buf) : + EXTRACT_LE_U_4(buf); ND_PRINT((ndo, "%u", stringlen)); buf += 4; break; @@ -618,7 +618,7 @@ smb_fdata1(netdissect_options *ndo, { /*XXX unistr() */ const char *s; - u_int32_t len; + uint32_t len; len = 0; s = unistr(ndo, buf, &len, (*fmt == 'R') ? 0 : unicodestr); @@ -633,11 +633,11 @@ smb_fdata1(netdissect_options *ndo, case 'Y': /* like 'Z', but always ASCII */ { const char *s; - u_int32_t len; + uint32_t len; ND_TCHECK(*buf); if (*buf != 4 && *buf != 2) { - ND_PRINT((ndo, "Error! ASCIIZ buffer of type %u", *buf)); + ND_PRINT((ndo, "Error! ASCIIZ buffer of type %u", EXTRACT_U_1(buf))); return maxbuf; /* give up */ } len = 0; @@ -685,8 +685,10 @@ smb_fdata1(netdissect_options *ndo, { int l = atoi(fmt + 1); ND_TCHECK2(*buf, l); - while (l--) - ND_PRINT((ndo, "%02x", *buf++)); + while (l--) { + ND_PRINT((ndo, "%02x", EXTRACT_U_1(buf))); + buf++; + } fmt++; while (isdigit((unsigned char)*fmt)) fmt++; @@ -730,12 +732,12 @@ smb_fdata1(netdissect_options *ndo, time_t t; struct tm *lt; const char *tstring; - u_int32_t x; + uint32_t x; switch (atoi(fmt + 1)) { case 1: - ND_TCHECK2(buf[0], 4); - x = EXTRACT_LE_32BITS(buf); + ND_TCHECK_4(buf); + x = EXTRACT_LE_U_4(buf); if (x == 0 || x == 0xFFFFFFFF) t = 0; else @@ -743,8 +745,8 @@ smb_fdata1(netdissect_options *ndo, buf += 4; break; case 2: - ND_TCHECK2(buf[0], 4); - x = EXTRACT_LE_32BITS(buf); + ND_TCHECK_4(buf); + x = EXTRACT_LE_U_4(buf); if (x == 0 || x == 0xFFFFFFFF) t = 0; else @@ -752,7 +754,7 @@ smb_fdata1(netdissect_options *ndo, buf += 4; break; case 3: - ND_TCHECK2(buf[0], 8); + ND_TCHECK_8(buf); t = interpret_long_date(buf); buf += 8; break; @@ -861,7 +863,7 @@ smb_fdata(netdissect_options *ndo, if (!depth && buf < maxbuf) { size_t len = PTR_DIFF(maxbuf, buf); ND_PRINT((ndo, "Data: (%lu bytes)\n", (unsigned long)len)); - print_data(ndo, buf, len); + smb_print_data(ndo, buf, len); return(buf + len); } return(buf); @@ -1013,7 +1015,7 @@ smb_errstr(int class, int num) } typedef struct { - u_int32_t code; + uint32_t code; const char *name; } nt_err_code_struct; @@ -1877,7 +1879,7 @@ static const nt_err_code_struct nt_errors[] = { * return an NT error string from a SMB buffer */ const char * -nt_errstr(u_int32_t err) +nt_errstr(uint32_t err) { static char ret[128]; int i;