X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/c639979cc9b1517dd045105476d6a2805c3d468b..5663cdab5ec8730ade9938c1ace64a4859d9ef7b:/print-smb.c diff --git a/print-smb.c b/print-smb.c index daabd437..f0e992c4 100644 --- a/print-smb.c +++ b/print-smb.c @@ -10,11 +10,6 @@ #include "config.h" #endif -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.44 2007-07-14 21:08:57 guy Exp $"; -#endif - #include #include @@ -24,6 +19,8 @@ static const char rcsid[] _U_ = #include "extract.h" #include "smb.h" +static const char tstr[] = "[|SMB]"; + static int request = 0; static int unicodestr = 0; @@ -65,8 +62,8 @@ struct smbfnsint #define FLG_CHAIN (1 << 0) -static struct smbfns * -smbfind(int id, struct smbfns *list) +static const struct smbfns * +smbfind(int id, const struct smbfns *list) { int sindex; @@ -77,8 +74,8 @@ smbfind(int id, struct smbfns *list) return(&list[0]); } -static struct smbfnsint * -smbfindint(int id, struct smbfnsint *list) +static const struct smbfnsint * +smbfindint(int id, const struct smbfnsint *list) { int sindex; @@ -140,11 +137,11 @@ trans2_qfsinfo(const u_char *param, const u_char *data, int pcnt, int dcnt) } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } -struct smbfnsint trans2_fns[] = { +static const struct smbfnsint trans2_fns[] = { { 0, "TRANSACT2_OPEN", 0, { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w, w, w, w, w])\nPath=[S]", NULL, @@ -173,7 +170,7 @@ static void print_trans2(const u_char *words, const u_char *dat, const u_char *buf, const u_char *maxbuf) { u_int bcc; - static struct smbfnsint *fn = &trans2_fns[0]; + static const struct smbfnsint *fn = &trans2_fns[0]; const u_char *data, *param; const u_char *w = words + 1; const char *f1 = NULL, *f2 = NULL; @@ -234,7 +231,7 @@ print_trans2(const u_char *words, const u_char *dat, const u_char *buf, const u_ } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -316,7 +313,7 @@ print_browse(const u_char *param, int paramlen, const u_char *data, int datalen) } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -363,7 +360,7 @@ print_trans(const u_char *words, const u_char *data1, const u_char *buf, const u f4 = "|Data "; } - smb_fdata(words + 1, f1, SMBMIN(words + 1 + 2 * words[0], maxbuf), + smb_fdata(words + 1, f1, min(words + 1 + 2 * words[0], maxbuf), unicodestr); TCHECK2(*data1, 2); @@ -383,13 +380,13 @@ print_trans(const u_char *words, const u_char *data1, const u_char *buf, const u } if (paramlen) - smb_fdata(param, f3, SMBMIN(param + paramlen, maxbuf), unicodestr); + smb_fdata(param, f3, min(param + paramlen, maxbuf), unicodestr); if (datalen) - smb_fdata(data, f4, SMBMIN(data + datalen, maxbuf), unicodestr); + smb_fdata(data, f4, min(data + datalen, maxbuf), unicodestr); } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -414,24 +411,24 @@ print_negprot(const u_char *words, const u_char *data, const u_char *buf _U_, co } if (f1) - smb_fdata(words + 1, f1, SMBMIN(words + 1 + wct * 2, maxbuf), + smb_fdata(words + 1, f1, min(words + 1 + wct * 2, maxbuf), unicodestr); else - print_data(words + 1, SMBMIN(wct * 2, PTR_DIFF(maxbuf, words + 1))); + print_data(words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1))); TCHECK2(*data, 2); bcc = EXTRACT_LE_16BITS(data); printf("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), + smb_fdata(data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data), maxbuf), unicodestr); else - print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); + print_data(data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -458,24 +455,24 @@ print_sesssetup(const u_char *words, const u_char *data, const u_char *buf _U_, } if (f1) - smb_fdata(words + 1, f1, SMBMIN(words + 1 + wct * 2, maxbuf), + smb_fdata(words + 1, f1, min(words + 1 + wct * 2, maxbuf), unicodestr); else - print_data(words + 1, SMBMIN(wct * 2, PTR_DIFF(maxbuf, words + 1))); + print_data(words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1))); TCHECK2(*data, 2); bcc = EXTRACT_LE_16BITS(data); printf("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), + smb_fdata(data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data), maxbuf), unicodestr); else - print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); + print_data(data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -499,7 +496,7 @@ print_lockingandx(const u_char *words, const u_char *data, const u_char *buf _U_ f1 = "Com2=[w]\nOff2=[d]\n"; } - maxwords = SMBMIN(words + 1 + wct * 2, maxbuf); + maxwords = min(words + 1 + wct * 2, maxbuf); if (wct) smb_fdata(words + 1, f1, maxwords, unicodestr); @@ -508,19 +505,19 @@ print_lockingandx(const u_char *words, const u_char *data, const u_char *buf _U_ printf("smb_bcc=%u\n", bcc); if (bcc > 0) { if (f2) - smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), + smb_fdata(data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data), maxbuf), unicodestr); else - print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); + print_data(data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } -static struct smbfns smb_fns[] = { +static const struct smbfns smb_fns[] = { { -1, "SMBunknown", 0, DEFDESCRIPT }, { SMBtcon, "SMBtcon", 0, @@ -799,7 +796,7 @@ print_smb(const u_char *buf, const u_char *maxbuf) int command; u_int32_t nterror; const u_char *words, *maxwords, *data; - struct smbfns *fn; + const struct smbfns *fn; const char *fmt_smbheader = "[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n"; int smboffset; @@ -847,7 +844,7 @@ print_smb(const u_char *buf, const u_char *maxbuf) TCHECK(words[0]); wct = words[0]; data = words + 1 + wct * 2; - maxwords = SMBMIN(data, maxbuf); + maxwords = min(data, maxbuf); if (request) { f1 = fn->descript.req_f1; @@ -884,7 +881,7 @@ print_smb(const u_char *buf, const u_char *maxbuf) } else { if (bcc > 0) { printf("smb_buf[]=\n"); - print_data(data + 2, SMBMIN(bcc, PTR_DIFF(maxbuf, data + 2))); + print_data(data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2))); } } } @@ -898,14 +895,14 @@ print_smb(const u_char *buf, const u_char *maxbuf) if (command == 0xFF) break; TCHECK2(words[3], 2); - newsmboffset = EXTRACT_LE_16BITS(words + 3); + newsmboffset = EXTRACT_LE_16BITS(words + 3); fn = smbfind(command, smb_fns); printf("\nSMB PACKET: %s (%s) (CHAINED)\n", fn->name, request ? "REQUEST" : "REPLY"); if (newsmboffset <= smboffset) { - printf("Bad andX offset: %u < %u\n", newsmboffset, smboffset); + printf("Bad andX offset: %u <= %u\n", newsmboffset, smboffset); break; } smboffset = newsmboffset; @@ -914,7 +911,7 @@ print_smb(const u_char *buf, const u_char *maxbuf) printf("\n"); return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -1078,7 +1075,7 @@ nbt_tcp_print(const u_char *data, int length) } return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -1240,11 +1237,51 @@ out: fflush(stdout); return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } +/* + * Print an SMB-over-TCP packet received across tcp on port 445 + */ +void +smb_tcp_print (const u_char * data, int length) +{ + int caplen; + u_int smb_len; + const u_char *maxbuf; + + if (length < 4) + goto trunc; + if (snapend < data) + goto trunc; + caplen = snapend - data; + if (caplen < 4) + goto trunc; + maxbuf = data + caplen; + smb_len = EXTRACT_24BITS(data + 1); + length -= 4; + caplen -= 4; + + startbuf = data; + data += 4; + if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) { + if ((int)smb_len > caplen) { + if ((int)smb_len > length) + printf("WARNING: Packet is continued in later TCP segments\n"); + else + printf("WARNING: Short packet. Try increasing the snap length by %d\n", + smb_len - caplen); + } + print_smb(data, maxbuf > data + smb_len ? data + smb_len : maxbuf); + } else + printf("SMB-over-TCP packet:(raw data or continuation?)\n"); + return; +trunc: + printf("%s", tstr); + return; +} /* * print a NBT packet received across udp on port 138 @@ -1431,7 +1468,7 @@ out: printf("\n"); return; trunc: - printf("[|SMB]"); + printf("%s", tstr); return; } @@ -1459,8 +1496,7 @@ ipx_netbios_print(const u_char *data, u_int length) break; if (memcmp(&data[i], "\377SMB", 4) == 0) { smb_fdata(data, "\n>>> IPX transport ", &data[i], 0); - if (data != NULL) - print_smb(&data[i], maxbuf); + print_smb(&data[i], maxbuf); printf("\n"); fflush(stdout); break;