141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (C) Andrew Tridgell 1995-1999
341c99275SPeter Avalos *
441c99275SPeter Avalos * This software may be distributed either under the terms of the
541c99275SPeter Avalos * BSD-style license that accompanies tcpdump or the GNU GPL version 2
641c99275SPeter Avalos * or later
741c99275SPeter Avalos */
841c99275SPeter Avalos
9411677aeSAaron LI /* \summary: SMB/CIFS printer */
10411677aeSAaron LI
1141c99275SPeter Avalos #ifdef HAVE_CONFIG_H
12*ed775ee7SAntonio Huete Jimenez #include <config.h>
1341c99275SPeter Avalos #endif
1441c99275SPeter Avalos
15*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
1641c99275SPeter Avalos
1741c99275SPeter Avalos #include <string.h>
1841c99275SPeter Avalos
19411677aeSAaron LI #include "netdissect.h"
2041c99275SPeter Avalos #include "extract.h"
2141c99275SPeter Avalos #include "smb.h"
2241c99275SPeter Avalos
23411677aeSAaron LI
2441c99275SPeter Avalos static int request = 0;
2541c99275SPeter Avalos static int unicodestr = 0;
2641c99275SPeter Avalos
27*ed775ee7SAntonio Huete Jimenez extern const u_char *startbuf;
28*ed775ee7SAntonio Huete Jimenez
2941c99275SPeter Avalos const u_char *startbuf = NULL;
3041c99275SPeter Avalos
3141c99275SPeter Avalos struct smbdescript {
3241c99275SPeter Avalos const char *req_f1;
3341c99275SPeter Avalos const char *req_f2;
3441c99275SPeter Avalos const char *rep_f1;
3541c99275SPeter Avalos const char *rep_f2;
36411677aeSAaron LI void (*fn)(netdissect_options *, const u_char *, const u_char *, const u_char *, const u_char *);
3741c99275SPeter Avalos };
3841c99275SPeter Avalos
3941c99275SPeter Avalos struct smbdescriptint {
4041c99275SPeter Avalos const char *req_f1;
4141c99275SPeter Avalos const char *req_f2;
4241c99275SPeter Avalos const char *rep_f1;
4341c99275SPeter Avalos const char *rep_f2;
44*ed775ee7SAntonio Huete Jimenez void (*fn)(netdissect_options *, const u_char *, const u_char *, u_int, u_int);
4541c99275SPeter Avalos };
4641c99275SPeter Avalos
4741c99275SPeter Avalos struct smbfns
4841c99275SPeter Avalos {
4941c99275SPeter Avalos int id;
5041c99275SPeter Avalos const char *name;
5141c99275SPeter Avalos int flags;
5241c99275SPeter Avalos struct smbdescript descript;
5341c99275SPeter Avalos };
5441c99275SPeter Avalos
5541c99275SPeter Avalos struct smbfnsint
5641c99275SPeter Avalos {
5741c99275SPeter Avalos int id;
5841c99275SPeter Avalos const char *name;
5941c99275SPeter Avalos int flags;
6041c99275SPeter Avalos struct smbdescriptint descript;
6141c99275SPeter Avalos };
6241c99275SPeter Avalos
6341c99275SPeter Avalos #define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL }
6441c99275SPeter Avalos
6541c99275SPeter Avalos #define FLG_CHAIN (1 << 0)
6641c99275SPeter Avalos
67411677aeSAaron LI static const struct smbfns *
smbfind(int id,const struct smbfns * list)68411677aeSAaron LI smbfind(int id, const struct smbfns *list)
6941c99275SPeter Avalos {
7041c99275SPeter Avalos int sindex;
7141c99275SPeter Avalos
7241c99275SPeter Avalos for (sindex = 0; list[sindex].name; sindex++)
7341c99275SPeter Avalos if (list[sindex].id == id)
7441c99275SPeter Avalos return(&list[sindex]);
7541c99275SPeter Avalos
7641c99275SPeter Avalos return(&list[0]);
7741c99275SPeter Avalos }
7841c99275SPeter Avalos
79411677aeSAaron LI static const struct smbfnsint *
smbfindint(int id,const struct smbfnsint * list)80411677aeSAaron LI smbfindint(int id, const struct smbfnsint *list)
8141c99275SPeter Avalos {
8241c99275SPeter Avalos int sindex;
8341c99275SPeter Avalos
8441c99275SPeter Avalos for (sindex = 0; list[sindex].name; sindex++)
8541c99275SPeter Avalos if (list[sindex].id == id)
8641c99275SPeter Avalos return(&list[sindex]);
8741c99275SPeter Avalos
8841c99275SPeter Avalos return(&list[0]);
8941c99275SPeter Avalos }
9041c99275SPeter Avalos
9141c99275SPeter Avalos static void
trans2_findfirst(netdissect_options * ndo,const u_char * param,const u_char * data,u_int pcnt,u_int dcnt)92411677aeSAaron LI trans2_findfirst(netdissect_options *ndo,
93*ed775ee7SAntonio Huete Jimenez const u_char *param, const u_char *data, u_int pcnt, u_int dcnt)
9441c99275SPeter Avalos {
9541c99275SPeter Avalos const char *fmt;
9641c99275SPeter Avalos
9741c99275SPeter Avalos if (request)
98*ed775ee7SAntonio Huete Jimenez fmt = "Attribute=[A]\nSearchCount=[u]\nFlags=[w]\nLevel=[uP4]\nFile=[S]\n";
9941c99275SPeter Avalos else
100*ed775ee7SAntonio Huete Jimenez fmt = "Handle=[w]\nCount=[u]\nEOS=[w]\nEoffset=[u]\nLastNameOfs=[w]\n";
10141c99275SPeter Avalos
102411677aeSAaron LI smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
10341c99275SPeter Avalos if (dcnt) {
104*ed775ee7SAntonio Huete Jimenez ND_PRINT("data:\n");
105*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, data, dcnt);
10641c99275SPeter Avalos }
10741c99275SPeter Avalos }
10841c99275SPeter Avalos
10941c99275SPeter Avalos static void
trans2_qfsinfo(netdissect_options * ndo,const u_char * param,const u_char * data,u_int pcnt,u_int dcnt)110411677aeSAaron LI trans2_qfsinfo(netdissect_options *ndo,
111*ed775ee7SAntonio Huete Jimenez const u_char *param, const u_char *data, u_int pcnt, u_int dcnt)
11241c99275SPeter Avalos {
113*ed775ee7SAntonio Huete Jimenez static u_int level = 0;
11441c99275SPeter Avalos const char *fmt="";
11541c99275SPeter Avalos
11641c99275SPeter Avalos if (request) {
117*ed775ee7SAntonio Huete Jimenez level = GET_LE_U_2(param);
118*ed775ee7SAntonio Huete Jimenez fmt = "InfoLevel=[u]\n";
119411677aeSAaron LI smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
12041c99275SPeter Avalos } else {
12141c99275SPeter Avalos switch (level) {
12241c99275SPeter Avalos case 1:
123*ed775ee7SAntonio Huete Jimenez fmt = "idFileSystem=[W]\nSectorUnit=[U]\nUnit=[U]\nAvail=[U]\nSectorSize=[u]\n";
12441c99275SPeter Avalos break;
12541c99275SPeter Avalos case 2:
12641c99275SPeter Avalos fmt = "CreationTime=[T2]VolNameLength=[lb]\nVolumeLabel=[c]\n";
12741c99275SPeter Avalos break;
12841c99275SPeter Avalos case 0x105:
129*ed775ee7SAntonio Huete Jimenez fmt = "Capabilities=[W]\nMaxFileLen=[U]\nVolNameLen=[lU]\nVolume=[C]\n";
13041c99275SPeter Avalos break;
13141c99275SPeter Avalos default:
13241c99275SPeter Avalos fmt = "UnknownLevel\n";
13341c99275SPeter Avalos break;
13441c99275SPeter Avalos }
135411677aeSAaron LI smb_fdata(ndo, data, fmt, data + dcnt, unicodestr);
13641c99275SPeter Avalos }
13741c99275SPeter Avalos if (dcnt) {
138*ed775ee7SAntonio Huete Jimenez ND_PRINT("data:\n");
139*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, data, dcnt);
14041c99275SPeter Avalos }
14141c99275SPeter Avalos }
14241c99275SPeter Avalos
143411677aeSAaron LI static const struct smbfnsint trans2_fns[] = {
14441c99275SPeter Avalos { 0, "TRANSACT2_OPEN", 0,
145*ed775ee7SAntonio Huete Jimenez { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[U]\nRes=([w, w, w, w, w])\nPath=[S]",
14641c99275SPeter Avalos NULL,
147*ed775ee7SAntonio Huete Jimenez "Handle=[u]\nAttrib=[A]\nTime=[T2]\nSize=[U]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[u]\n|EALength=[u]\n",
14841c99275SPeter Avalos NULL, NULL }},
14941c99275SPeter Avalos { 1, "TRANSACT2_FINDFIRST", 0,
15041c99275SPeter Avalos { NULL, NULL, NULL, NULL, trans2_findfirst }},
15141c99275SPeter Avalos { 2, "TRANSACT2_FINDNEXT", 0, DEFDESCRIPT },
15241c99275SPeter Avalos { 3, "TRANSACT2_QFSINFO", 0,
15341c99275SPeter Avalos { NULL, NULL, NULL, NULL, trans2_qfsinfo }},
15441c99275SPeter Avalos { 4, "TRANSACT2_SETFSINFO", 0, DEFDESCRIPT },
15541c99275SPeter Avalos { 5, "TRANSACT2_QPATHINFO", 0, DEFDESCRIPT },
15641c99275SPeter Avalos { 6, "TRANSACT2_SETPATHINFO", 0, DEFDESCRIPT },
15741c99275SPeter Avalos { 7, "TRANSACT2_QFILEINFO", 0, DEFDESCRIPT },
15841c99275SPeter Avalos { 8, "TRANSACT2_SETFILEINFO", 0, DEFDESCRIPT },
15941c99275SPeter Avalos { 9, "TRANSACT2_FSCTL", 0, DEFDESCRIPT },
16041c99275SPeter Avalos { 10, "TRANSACT2_IOCTL", 0, DEFDESCRIPT },
16141c99275SPeter Avalos { 11, "TRANSACT2_FINDNOTIFYFIRST", 0, DEFDESCRIPT },
16241c99275SPeter Avalos { 12, "TRANSACT2_FINDNOTIFYNEXT", 0, DEFDESCRIPT },
16341c99275SPeter Avalos { 13, "TRANSACT2_MKDIR", 0, DEFDESCRIPT },
16441c99275SPeter Avalos { -1, NULL, 0, DEFDESCRIPT }
16541c99275SPeter Avalos };
16641c99275SPeter Avalos
16741c99275SPeter Avalos
16841c99275SPeter Avalos static void
print_trans2(netdissect_options * ndo,const u_char * words,const u_char * dat,const u_char * buf,const u_char * maxbuf)169411677aeSAaron LI print_trans2(netdissect_options *ndo,
170411677aeSAaron LI const u_char *words, const u_char *dat, const u_char *buf, const u_char *maxbuf)
17141c99275SPeter Avalos {
17241c99275SPeter Avalos u_int bcc;
173411677aeSAaron LI static const struct smbfnsint *fn = &trans2_fns[0];
17441c99275SPeter Avalos const u_char *data, *param;
17541c99275SPeter Avalos const u_char *w = words + 1;
17641c99275SPeter Avalos const char *f1 = NULL, *f2 = NULL;
177*ed775ee7SAntonio Huete Jimenez u_int pcnt, dcnt;
17841c99275SPeter Avalos
179*ed775ee7SAntonio Huete Jimenez ND_TCHECK_1(words);
18041c99275SPeter Avalos if (request) {
181*ed775ee7SAntonio Huete Jimenez ND_TCHECK_2(w + (14 * 2));
182*ed775ee7SAntonio Huete Jimenez pcnt = GET_LE_U_2(w + 9 * 2);
183*ed775ee7SAntonio Huete Jimenez param = buf + GET_LE_U_2(w + 10 * 2);
184*ed775ee7SAntonio Huete Jimenez dcnt = GET_LE_U_2(w + 11 * 2);
185*ed775ee7SAntonio Huete Jimenez data = buf + GET_LE_U_2(w + 12 * 2);
186*ed775ee7SAntonio Huete Jimenez fn = smbfindint(GET_LE_U_2(w + 14 * 2), trans2_fns);
18741c99275SPeter Avalos } else {
188*ed775ee7SAntonio Huete Jimenez if (GET_U_1(words) == 0) {
189*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s\n", fn->name);
190*ed775ee7SAntonio Huete Jimenez ND_PRINT("Trans2Interim\n");
19141c99275SPeter Avalos return;
19241c99275SPeter Avalos }
193*ed775ee7SAntonio Huete Jimenez ND_TCHECK_2(w + (7 * 2));
194*ed775ee7SAntonio Huete Jimenez pcnt = GET_LE_U_2(w + 3 * 2);
195*ed775ee7SAntonio Huete Jimenez param = buf + GET_LE_U_2(w + 4 * 2);
196*ed775ee7SAntonio Huete Jimenez dcnt = GET_LE_U_2(w + 6 * 2);
197*ed775ee7SAntonio Huete Jimenez data = buf + GET_LE_U_2(w + 7 * 2);
19841c99275SPeter Avalos }
19941c99275SPeter Avalos
200*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s param_length=%u data_length=%u\n", fn->name, pcnt, dcnt);
20141c99275SPeter Avalos
20241c99275SPeter Avalos if (request) {
203*ed775ee7SAntonio Huete Jimenez if (GET_U_1(words) == 8) {
204411677aeSAaron LI smb_fdata(ndo, words + 1,
205*ed775ee7SAntonio Huete Jimenez "Trans2Secondary\nTotParam=[u]\nTotData=[u]\nParamCnt=[u]\nParamOff=[u]\nParamDisp=[u]\nDataCnt=[u]\nDataOff=[u]\nDataDisp=[u]\nHandle=[u]\n",
20641c99275SPeter Avalos maxbuf, unicodestr);
20741c99275SPeter Avalos return;
20841c99275SPeter Avalos } else {
209411677aeSAaron LI smb_fdata(ndo, words + 1,
210*ed775ee7SAntonio Huete Jimenez "TotParam=[u]\nTotData=[u]\nMaxParam=[u]\nMaxData=[u]\nMaxSetup=[b][P1]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[u]\nParamOff=[u]\nDataCnt=[u]\nDataOff=[u]\nSetupCnt=[b][P1]\n",
21141c99275SPeter Avalos words + 1 + 14 * 2, unicodestr);
21241c99275SPeter Avalos }
21341c99275SPeter Avalos f1 = fn->descript.req_f1;
21441c99275SPeter Avalos f2 = fn->descript.req_f2;
21541c99275SPeter Avalos } else {
216411677aeSAaron LI smb_fdata(ndo, words + 1,
217*ed775ee7SAntonio Huete Jimenez "TotParam=[u]\nTotData=[u]\nRes1=[w]\nParamCnt=[u]\nParamOff=[u]\nParamDisp[u]\nDataCnt=[u]\nDataOff=[u]\nDataDisp=[u]\nSetupCnt=[b][P1]\n",
21841c99275SPeter Avalos words + 1 + 10 * 2, unicodestr);
21941c99275SPeter Avalos f1 = fn->descript.rep_f1;
22041c99275SPeter Avalos f2 = fn->descript.rep_f2;
22141c99275SPeter Avalos }
22241c99275SPeter Avalos
223*ed775ee7SAntonio Huete Jimenez bcc = GET_LE_U_2(dat);
224*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_bcc=%u\n", bcc);
22541c99275SPeter Avalos if (fn->descript.fn)
226411677aeSAaron LI (*fn->descript.fn)(ndo, param, data, pcnt, dcnt);
22741c99275SPeter Avalos else {
228411677aeSAaron LI smb_fdata(ndo, param, f1 ? f1 : "Parameters=\n", param + pcnt, unicodestr);
229411677aeSAaron LI smb_fdata(ndo, data, f2 ? f2 : "Data=\n", data + dcnt, unicodestr);
23041c99275SPeter Avalos }
23141c99275SPeter Avalos return;
23241c99275SPeter Avalos trunc:
233*ed775ee7SAntonio Huete Jimenez nd_print_trunc(ndo);
23441c99275SPeter Avalos }
23541c99275SPeter Avalos
23641c99275SPeter Avalos static void
print_browse(netdissect_options * ndo,const u_char * param,u_int paramlen,const u_char * data,u_int datalen)237411677aeSAaron LI print_browse(netdissect_options *ndo,
238*ed775ee7SAntonio Huete Jimenez const u_char *param, u_int paramlen, const u_char *data, u_int datalen)
23941c99275SPeter Avalos {
24041c99275SPeter Avalos const u_char *maxbuf = data + datalen;
241*ed775ee7SAntonio Huete Jimenez u_int command;
24241c99275SPeter Avalos
243*ed775ee7SAntonio Huete Jimenez command = GET_U_1(data);
24441c99275SPeter Avalos
245411677aeSAaron LI smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr);
24641c99275SPeter Avalos
24741c99275SPeter Avalos switch (command) {
24841c99275SPeter Avalos case 0xF:
249411677aeSAaron LI data = smb_fdata(ndo, data,
250*ed775ee7SAntonio Huete Jimenez "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
25141c99275SPeter Avalos maxbuf, unicodestr);
25241c99275SPeter Avalos break;
25341c99275SPeter Avalos
25441c99275SPeter Avalos case 0x1:
255411677aeSAaron LI data = smb_fdata(ndo, data,
256*ed775ee7SAntonio Huete Jimenez "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
25741c99275SPeter Avalos maxbuf, unicodestr);
25841c99275SPeter Avalos break;
25941c99275SPeter Avalos
26041c99275SPeter Avalos case 0x2:
261411677aeSAaron LI data = smb_fdata(ndo, data,
26241c99275SPeter Avalos "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",
26341c99275SPeter Avalos maxbuf, unicodestr);
26441c99275SPeter Avalos break;
26541c99275SPeter Avalos
26641c99275SPeter Avalos case 0xc:
267411677aeSAaron LI data = smb_fdata(ndo, data,
268*ed775ee7SAntonio Huete Jimenez "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",
26941c99275SPeter Avalos maxbuf, unicodestr);
27041c99275SPeter Avalos break;
27141c99275SPeter Avalos
27241c99275SPeter Avalos case 0x8:
273411677aeSAaron LI data = smb_fdata(ndo, data,
27441c99275SPeter Avalos "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n",
27541c99275SPeter Avalos maxbuf, unicodestr);
27641c99275SPeter Avalos break;
27741c99275SPeter Avalos
27841c99275SPeter Avalos case 0xb:
279411677aeSAaron LI data = smb_fdata(ndo, data,
28041c99275SPeter Avalos "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",
28141c99275SPeter Avalos maxbuf, unicodestr);
28241c99275SPeter Avalos break;
28341c99275SPeter Avalos
28441c99275SPeter Avalos case 0x9:
285411677aeSAaron LI data = smb_fdata(ndo, data,
28641c99275SPeter Avalos "BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken=[W]\n",
28741c99275SPeter Avalos maxbuf, unicodestr);
28841c99275SPeter Avalos break;
28941c99275SPeter Avalos
29041c99275SPeter Avalos case 0xa:
291411677aeSAaron LI data = smb_fdata(ndo, data,
29241c99275SPeter Avalos "BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken=[W]\n*Name=[S]\n",
29341c99275SPeter Avalos maxbuf, unicodestr);
29441c99275SPeter Avalos break;
29541c99275SPeter Avalos
29641c99275SPeter Avalos case 0xd:
297411677aeSAaron LI data = smb_fdata(ndo, data,
29841c99275SPeter Avalos "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",
29941c99275SPeter Avalos maxbuf, unicodestr);
30041c99275SPeter Avalos break;
30141c99275SPeter Avalos
30241c99275SPeter Avalos case 0xe:
303411677aeSAaron LI data = smb_fdata(ndo, data,
30441c99275SPeter Avalos "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf, unicodestr);
30541c99275SPeter Avalos break;
30641c99275SPeter Avalos
30741c99275SPeter Avalos default:
308411677aeSAaron LI data = smb_fdata(ndo, data, "Unknown Browser Frame ", maxbuf, unicodestr);
30941c99275SPeter Avalos break;
31041c99275SPeter Avalos }
31141c99275SPeter Avalos }
31241c99275SPeter Avalos
31341c99275SPeter Avalos
31441c99275SPeter Avalos static void
print_ipc(netdissect_options * ndo,const u_char * param,u_int paramlen,const u_char * data,u_int datalen)315411677aeSAaron LI print_ipc(netdissect_options *ndo,
316*ed775ee7SAntonio Huete Jimenez const u_char *param, u_int paramlen, const u_char *data, u_int datalen)
31741c99275SPeter Avalos {
31841c99275SPeter Avalos if (paramlen)
319411677aeSAaron LI smb_fdata(ndo, param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen,
32041c99275SPeter Avalos unicodestr);
32141c99275SPeter Avalos if (datalen)
322411677aeSAaron LI smb_fdata(ndo, data, "IPC ", data + datalen, unicodestr);
32341c99275SPeter Avalos }
32441c99275SPeter Avalos
32541c99275SPeter Avalos
32641c99275SPeter Avalos static void
print_trans(netdissect_options * ndo,const u_char * words,const u_char * data1,const u_char * buf,const u_char * maxbuf)327411677aeSAaron LI print_trans(netdissect_options *ndo,
328411677aeSAaron LI const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf)
32941c99275SPeter Avalos {
33041c99275SPeter Avalos u_int bcc;
33141c99275SPeter Avalos const char *f1, *f2, *f3, *f4;
33241c99275SPeter Avalos const u_char *data, *param;
33341c99275SPeter Avalos const u_char *w = words + 1;
334*ed775ee7SAntonio Huete Jimenez u_int datalen, paramlen;
33541c99275SPeter Avalos
33641c99275SPeter Avalos if (request) {
337*ed775ee7SAntonio Huete Jimenez ND_TCHECK_2(w + (12 * 2));
338*ed775ee7SAntonio Huete Jimenez paramlen = GET_LE_U_2(w + 9 * 2);
339*ed775ee7SAntonio Huete Jimenez param = buf + GET_LE_U_2(w + 10 * 2);
340*ed775ee7SAntonio Huete Jimenez datalen = GET_LE_U_2(w + 11 * 2);
341*ed775ee7SAntonio Huete Jimenez data = buf + GET_LE_U_2(w + 12 * 2);
342*ed775ee7SAntonio Huete Jimenez f1 = "TotParamCnt=[u]\nTotDataCnt=[u]\nMaxParmCnt=[u]\nMaxDataCnt=[u]\nMaxSCnt=[u]\nTransFlags=[w]\nRes1=[w]\nRes2=[w]\nRes3=[w]\nParamCnt=[u]\nParamOff=[u]\nDataCnt=[u]\nDataOff=[u]\nSUCnt=[u]\n";
34341c99275SPeter Avalos f2 = "|Name=[S]\n";
34441c99275SPeter Avalos f3 = "|Param ";
34541c99275SPeter Avalos f4 = "|Data ";
34641c99275SPeter Avalos } else {
347*ed775ee7SAntonio Huete Jimenez ND_TCHECK_2(w + (7 * 2));
348*ed775ee7SAntonio Huete Jimenez paramlen = GET_LE_U_2(w + 3 * 2);
349*ed775ee7SAntonio Huete Jimenez param = buf + GET_LE_U_2(w + 4 * 2);
350*ed775ee7SAntonio Huete Jimenez datalen = GET_LE_U_2(w + 6 * 2);
351*ed775ee7SAntonio Huete Jimenez data = buf + GET_LE_U_2(w + 7 * 2);
352*ed775ee7SAntonio Huete Jimenez f1 = "TotParamCnt=[u]\nTotDataCnt=[u]\nRes1=[u]\nParamCnt=[u]\nParamOff=[u]\nRes2=[u]\nDataCnt=[u]\nDataOff=[u]\nRes3=[u]\nLsetup=[u]\n";
35341c99275SPeter Avalos f2 = "|Unknown ";
35441c99275SPeter Avalos f3 = "|Param ";
35541c99275SPeter Avalos f4 = "|Data ";
35641c99275SPeter Avalos }
35741c99275SPeter Avalos
358*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, words + 1, f1,
359*ed775ee7SAntonio Huete Jimenez ND_MIN(words + 1 + 2 * GET_U_1(words), maxbuf),
36041c99275SPeter Avalos unicodestr);
36141c99275SPeter Avalos
362*ed775ee7SAntonio Huete Jimenez bcc = GET_LE_U_2(data1);
363*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_bcc=%u\n", bcc);
36441c99275SPeter Avalos if (bcc > 0) {
365411677aeSAaron LI smb_fdata(ndo, data1 + 2, f2, maxbuf - (paramlen + datalen), unicodestr);
366*ed775ee7SAntonio Huete Jimenez
367411677aeSAaron LI #define MAILSLOT_BROWSE_STR "\\MAILSLOT\\BROWSE"
368*ed775ee7SAntonio Huete Jimenez ND_TCHECK_LEN(data1 + 2, strlen(MAILSLOT_BROWSE_STR) + 1);
369411677aeSAaron LI if (strcmp((const char *)(data1 + 2), MAILSLOT_BROWSE_STR) == 0) {
370411677aeSAaron LI print_browse(ndo, param, paramlen, data, datalen);
37141c99275SPeter Avalos return;
37241c99275SPeter Avalos }
373411677aeSAaron LI #undef MAILSLOT_BROWSE_STR
37441c99275SPeter Avalos
375411677aeSAaron LI #define PIPE_LANMAN_STR "\\PIPE\\LANMAN"
376*ed775ee7SAntonio Huete Jimenez ND_TCHECK_LEN(data1 + 2, strlen(PIPE_LANMAN_STR) + 1);
377411677aeSAaron LI if (strcmp((const char *)(data1 + 2), PIPE_LANMAN_STR) == 0) {
378411677aeSAaron LI print_ipc(ndo, param, paramlen, data, datalen);
37941c99275SPeter Avalos return;
38041c99275SPeter Avalos }
381411677aeSAaron LI #undef PIPE_LANMAN_STR
38241c99275SPeter Avalos
38341c99275SPeter Avalos if (paramlen)
384*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, param, f3, ND_MIN(param + paramlen, maxbuf), unicodestr);
38541c99275SPeter Avalos if (datalen)
386*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, data, f4, ND_MIN(data + datalen, maxbuf), unicodestr);
38741c99275SPeter Avalos }
38841c99275SPeter Avalos return;
38941c99275SPeter Avalos trunc:
390*ed775ee7SAntonio Huete Jimenez nd_print_trunc(ndo);
39141c99275SPeter Avalos }
39241c99275SPeter Avalos
39341c99275SPeter Avalos
39441c99275SPeter Avalos static void
print_negprot(netdissect_options * ndo,const u_char * words,const u_char * data,const u_char * buf _U_,const u_char * maxbuf)395411677aeSAaron LI print_negprot(netdissect_options *ndo,
396411677aeSAaron LI const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
39741c99275SPeter Avalos {
39841c99275SPeter Avalos u_int wct, bcc;
39941c99275SPeter Avalos const char *f1 = NULL, *f2 = NULL;
40041c99275SPeter Avalos
401*ed775ee7SAntonio Huete Jimenez wct = GET_U_1(words);
40241c99275SPeter Avalos if (request)
40341c99275SPeter Avalos f2 = "*|Dialect=[Y]\n";
40441c99275SPeter Avalos else {
40541c99275SPeter Avalos if (wct == 1)
406*ed775ee7SAntonio Huete Jimenez f1 = "Core Protocol\nDialectIndex=[u]";
40741c99275SPeter Avalos else if (wct == 17)
408*ed775ee7SAntonio Huete Jimenez f1 = "NT1 Protocol\nDialectIndex=[u]\nSecMode=[B]\nMaxMux=[u]\nNumVcs=[u]\nMaxBuffer=[U]\nRawSize=[U]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[u]\nCryptKey=";
40941c99275SPeter Avalos else if (wct == 13)
410*ed775ee7SAntonio Huete Jimenez f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[u]\nSecMode=[w]\nMaxXMit=[u]\nMaxMux=[u]\nMaxVcs=[u]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[u]\nRes=[W]\nCryptKey=";
41141c99275SPeter Avalos }
41241c99275SPeter Avalos
41341c99275SPeter Avalos if (f1)
414*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf),
41541c99275SPeter Avalos unicodestr);
41641c99275SPeter Avalos else
417*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, words + 1, ND_MIN(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
41841c99275SPeter Avalos
419*ed775ee7SAntonio Huete Jimenez bcc = GET_LE_U_2(data);
420*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_bcc=%u\n", bcc);
42141c99275SPeter Avalos if (bcc > 0) {
42241c99275SPeter Avalos if (f2)
423*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data),
42441c99275SPeter Avalos maxbuf), unicodestr);
42541c99275SPeter Avalos else
426*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, data + 2,
427*ed775ee7SAntonio Huete Jimenez ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
42841c99275SPeter Avalos }
42941c99275SPeter Avalos }
43041c99275SPeter Avalos
43141c99275SPeter Avalos static void
print_sesssetup(netdissect_options * ndo,const u_char * words,const u_char * data,const u_char * buf _U_,const u_char * maxbuf)432411677aeSAaron LI print_sesssetup(netdissect_options *ndo,
433411677aeSAaron LI const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
43441c99275SPeter Avalos {
43541c99275SPeter Avalos u_int wct, bcc;
43641c99275SPeter Avalos const char *f1 = NULL, *f2 = NULL;
43741c99275SPeter Avalos
438*ed775ee7SAntonio Huete Jimenez wct = GET_U_1(words);
43941c99275SPeter Avalos if (request) {
44041c99275SPeter Avalos if (wct == 10)
441*ed775ee7SAntonio Huete Jimenez f1 = "Com2=[w]\nOff2=[u]\nBufSize=[u]\nMpxMax=[u]\nVcNum=[u]\nSessionKey=[W]\nPassLen=[u]\nCryptLen=[u]\nCryptOff=[u]\nPass&Name=\n";
44241c99275SPeter Avalos else
443*ed775ee7SAntonio Huete Jimenez f1 = "Com2=[B]\nRes1=[B]\nOff2=[u]\nMaxBuffer=[u]\nMaxMpx=[u]\nVcNumber=[u]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[u]\nCaseSensitivePasswordLength=[u]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n";
44441c99275SPeter Avalos } else {
44541c99275SPeter Avalos if (wct == 3) {
446*ed775ee7SAntonio Huete Jimenez f1 = "Com2=[w]\nOff2=[u]\nAction=[w]\n";
44741c99275SPeter Avalos } else if (wct == 13) {
448*ed775ee7SAntonio Huete Jimenez f1 = "Com2=[B]\nRes=[B]\nOff2=[u]\nAction=[w]\n";
44941c99275SPeter Avalos f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n";
45041c99275SPeter Avalos }
45141c99275SPeter Avalos }
45241c99275SPeter Avalos
45341c99275SPeter Avalos if (f1)
454*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf),
45541c99275SPeter Avalos unicodestr);
45641c99275SPeter Avalos else
457*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, words + 1, ND_MIN(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
45841c99275SPeter Avalos
459*ed775ee7SAntonio Huete Jimenez bcc = GET_LE_U_2(data);
460*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_bcc=%u\n", bcc);
46141c99275SPeter Avalos if (bcc > 0) {
46241c99275SPeter Avalos if (f2)
463*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data),
46441c99275SPeter Avalos maxbuf), unicodestr);
46541c99275SPeter Avalos else
466*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, data + 2,
467*ed775ee7SAntonio Huete Jimenez ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
46841c99275SPeter Avalos }
46941c99275SPeter Avalos }
47041c99275SPeter Avalos
47141c99275SPeter Avalos static void
print_lockingandx(netdissect_options * ndo,const u_char * words,const u_char * data,const u_char * buf _U_,const u_char * maxbuf)472411677aeSAaron LI print_lockingandx(netdissect_options *ndo,
473411677aeSAaron LI const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
47441c99275SPeter Avalos {
47541c99275SPeter Avalos u_int wct, bcc;
47641c99275SPeter Avalos const u_char *maxwords;
47741c99275SPeter Avalos const char *f1 = NULL, *f2 = NULL;
47841c99275SPeter Avalos
479*ed775ee7SAntonio Huete Jimenez wct = GET_U_1(words);
48041c99275SPeter Avalos if (request) {
481*ed775ee7SAntonio Huete Jimenez f1 = "Com2=[w]\nOff2=[u]\nHandle=[u]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[u]\nLockCount=[u]\n";
482*ed775ee7SAntonio Huete Jimenez if (GET_U_1(words + 7) & 0x10)
483*ed775ee7SAntonio Huete Jimenez f2 = "*Process=[u]\n[P2]Offset=[M]\nLength=[M]\n";
48441c99275SPeter Avalos else
485*ed775ee7SAntonio Huete Jimenez f2 = "*Process=[u]\nOffset=[D]\nLength=[U]\n";
48641c99275SPeter Avalos } else {
487*ed775ee7SAntonio Huete Jimenez f1 = "Com2=[w]\nOff2=[u]\n";
48841c99275SPeter Avalos }
48941c99275SPeter Avalos
490*ed775ee7SAntonio Huete Jimenez maxwords = ND_MIN(words + 1 + wct * 2, maxbuf);
49141c99275SPeter Avalos if (wct)
492411677aeSAaron LI smb_fdata(ndo, words + 1, f1, maxwords, unicodestr);
49341c99275SPeter Avalos
494*ed775ee7SAntonio Huete Jimenez bcc = GET_LE_U_2(data);
495*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_bcc=%u\n", bcc);
49641c99275SPeter Avalos if (bcc > 0) {
49741c99275SPeter Avalos if (f2)
498*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data),
49941c99275SPeter Avalos maxbuf), unicodestr);
50041c99275SPeter Avalos else
501*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, data + 2,
502*ed775ee7SAntonio Huete Jimenez ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
50341c99275SPeter Avalos }
50441c99275SPeter Avalos }
50541c99275SPeter Avalos
50641c99275SPeter Avalos
507411677aeSAaron LI static const struct smbfns smb_fns[] = {
50841c99275SPeter Avalos { -1, "SMBunknown", 0, DEFDESCRIPT },
50941c99275SPeter Avalos
51041c99275SPeter Avalos { SMBtcon, "SMBtcon", 0,
51141c99275SPeter Avalos { NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n",
512*ed775ee7SAntonio Huete Jimenez "MaxXmit=[u]\nTreeId=[u]\n", NULL,
51341c99275SPeter Avalos NULL } },
51441c99275SPeter Avalos
51541c99275SPeter Avalos { SMBtdis, "SMBtdis", 0, DEFDESCRIPT },
51641c99275SPeter Avalos { SMBexit, "SMBexit", 0, DEFDESCRIPT },
51741c99275SPeter Avalos { SMBioctl, "SMBioctl", 0, DEFDESCRIPT },
51841c99275SPeter Avalos
51941c99275SPeter Avalos { SMBecho, "SMBecho", 0,
520*ed775ee7SAntonio Huete Jimenez { "ReverbCount=[u]\n", NULL,
521*ed775ee7SAntonio Huete Jimenez "SequenceNum=[u]\n", NULL,
52241c99275SPeter Avalos NULL } },
52341c99275SPeter Avalos
52441c99275SPeter Avalos { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT },
52541c99275SPeter Avalos
52641c99275SPeter Avalos { SMBgetatr, "SMBgetatr", 0,
52741c99275SPeter Avalos { NULL, "Path=[Z]\n",
528*ed775ee7SAntonio Huete Jimenez "Attribute=[A]\nTime=[T2]Size=[U]\nRes=([w,w,w,w,w])\n", NULL,
52941c99275SPeter Avalos NULL } },
53041c99275SPeter Avalos
53141c99275SPeter Avalos { SMBsetatr, "SMBsetatr", 0,
53241c99275SPeter Avalos { "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n",
53341c99275SPeter Avalos NULL, NULL, NULL } },
53441c99275SPeter Avalos
53541c99275SPeter Avalos { SMBchkpth, "SMBchkpth", 0,
53641c99275SPeter Avalos { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
53741c99275SPeter Avalos
53841c99275SPeter Avalos { SMBsearch, "SMBsearch", 0,
539*ed775ee7SAntonio Huete Jimenez { "Count=[u]\nAttrib=[A]\n",
540*ed775ee7SAntonio Huete Jimenez "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\n",
541*ed775ee7SAntonio Huete Jimenez "Count=[u]\n",
542*ed775ee7SAntonio Huete Jimenez "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
54341c99275SPeter Avalos NULL } },
54441c99275SPeter Avalos
54541c99275SPeter Avalos { SMBopen, "SMBopen", 0,
54641c99275SPeter Avalos { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n",
547*ed775ee7SAntonio Huete Jimenez "Handle=[u]\nOAttrib=[A]\nTime=[T2]Size=[U]\nAccess=[w]\n",
54841c99275SPeter Avalos NULL, NULL } },
54941c99275SPeter Avalos
55041c99275SPeter Avalos { SMBcreate, "SMBcreate", 0,
551*ed775ee7SAntonio Huete Jimenez { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[u]\n", NULL, NULL } },
55241c99275SPeter Avalos
55341c99275SPeter Avalos { SMBmknew, "SMBmknew", 0,
554*ed775ee7SAntonio Huete Jimenez { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[u]\n", NULL, NULL } },
55541c99275SPeter Avalos
55641c99275SPeter Avalos { SMBunlink, "SMBunlink", 0,
55741c99275SPeter Avalos { "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } },
55841c99275SPeter Avalos
55941c99275SPeter Avalos { SMBread, "SMBread", 0,
560*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
561*ed775ee7SAntonio Huete Jimenez "Count=[u]\nRes=([w,w,w,w])\n", NULL, NULL } },
56241c99275SPeter Avalos
56341c99275SPeter Avalos { SMBwrite, "SMBwrite", 0,
564*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
565*ed775ee7SAntonio Huete Jimenez "Count=[u]\n", NULL, NULL } },
56641c99275SPeter Avalos
56741c99275SPeter Avalos { SMBclose, "SMBclose", 0,
568*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nTime=[T2]", NULL, NULL, NULL, NULL } },
56941c99275SPeter Avalos
57041c99275SPeter Avalos { SMBmkdir, "SMBmkdir", 0,
57141c99275SPeter Avalos { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
57241c99275SPeter Avalos
57341c99275SPeter Avalos { SMBrmdir, "SMBrmdir", 0,
57441c99275SPeter Avalos { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
57541c99275SPeter Avalos
57641c99275SPeter Avalos { SMBdskattr, "SMBdskattr", 0,
57741c99275SPeter Avalos { NULL, NULL,
578*ed775ee7SAntonio Huete Jimenez "TotalUnits=[u]\nBlocksPerUnit=[u]\nBlockSize=[u]\nFreeUnits=[u]\nMedia=[w]\n",
57941c99275SPeter Avalos NULL, NULL } },
58041c99275SPeter Avalos
58141c99275SPeter Avalos { SMBmv, "SMBmv", 0,
58241c99275SPeter Avalos { "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } },
58341c99275SPeter Avalos
58441c99275SPeter Avalos /*
58541c99275SPeter Avalos * this is a Pathworks specific call, allowing the
58641c99275SPeter Avalos * changing of the root path
58741c99275SPeter Avalos */
58841c99275SPeter Avalos { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
58941c99275SPeter Avalos
59041c99275SPeter Avalos { SMBlseek, "SMBlseek", 0,
591*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
59241c99275SPeter Avalos
593*ed775ee7SAntonio Huete Jimenez { SMBflush, "SMBflush", 0, { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
59441c99275SPeter Avalos
59541c99275SPeter Avalos { SMBsplopen, "SMBsplopen", 0,
596*ed775ee7SAntonio Huete Jimenez { "SetupLen=[u]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[u]\n",
59741c99275SPeter Avalos NULL, NULL } },
59841c99275SPeter Avalos
59941c99275SPeter Avalos { SMBsplclose, "SMBsplclose", 0,
600*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
60141c99275SPeter Avalos
60241c99275SPeter Avalos { SMBsplretq, "SMBsplretq", 0,
603*ed775ee7SAntonio Huete Jimenez { "MaxCount=[u]\nStartIndex=[u]\n", NULL,
604*ed775ee7SAntonio Huete Jimenez "Count=[u]\nIndex=[u]\n",
605*ed775ee7SAntonio Huete Jimenez "*Time=[T2]Status=[B]\nJobID=[u]\nSize=[U]\nRes=[B]Name=[s16]\n",
60641c99275SPeter Avalos NULL } },
60741c99275SPeter Avalos
60841c99275SPeter Avalos { SMBsplwr, "SMBsplwr", 0,
609*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
61041c99275SPeter Avalos
61141c99275SPeter Avalos { SMBlock, "SMBlock", 0,
612*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nCount=[U]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
61341c99275SPeter Avalos
61441c99275SPeter Avalos { SMBunlock, "SMBunlock", 0,
615*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nCount=[U]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
61641c99275SPeter Avalos
61741c99275SPeter Avalos /* CORE+ PROTOCOL FOLLOWS */
61841c99275SPeter Avalos
61941c99275SPeter Avalos { SMBreadbraw, "SMBreadbraw", 0,
620*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nRes=[u]\n",
62141c99275SPeter Avalos NULL, NULL, NULL, NULL } },
62241c99275SPeter Avalos
62341c99275SPeter Avalos { SMBwritebraw, "SMBwritebraw", 0,
624*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nTotalCount=[u]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[u]\nDataOff=[u]\n",
62541c99275SPeter Avalos NULL, "WriteRawAck", NULL, NULL } },
62641c99275SPeter Avalos
62741c99275SPeter Avalos { SMBwritec, "SMBwritec", 0,
628*ed775ee7SAntonio Huete Jimenez { NULL, NULL, "Count=[u]\n", NULL, NULL } },
62941c99275SPeter Avalos
63041c99275SPeter Avalos { SMBwriteclose, "SMBwriteclose", 0,
631*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nCount=[u]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
632*ed775ee7SAntonio Huete Jimenez NULL, "Count=[u]\n", NULL, NULL } },
63341c99275SPeter Avalos
63441c99275SPeter Avalos { SMBlockread, "SMBlockread", 0,
635*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
636*ed775ee7SAntonio Huete Jimenez "Count=[u]\nRes=([w,w,w,w])\n", NULL, NULL } },
63741c99275SPeter Avalos
63841c99275SPeter Avalos { SMBwriteunlock, "SMBwriteunlock", 0,
639*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
640*ed775ee7SAntonio Huete Jimenez "Count=[u]\n", NULL, NULL } },
64141c99275SPeter Avalos
64241c99275SPeter Avalos { SMBreadBmpx, "SMBreadBmpx", 0,
643*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nRes=[w]\n",
64441c99275SPeter Avalos NULL,
645*ed775ee7SAntonio Huete Jimenez "Offset=[D]\nTotCount=[u]\nRemaining=[u]\nRes=([w,w])\nDataSize=[u]\nDataOff=[u]\n",
64641c99275SPeter Avalos NULL, NULL } },
64741c99275SPeter Avalos
64841c99275SPeter Avalos { SMBwriteBmpx, "SMBwriteBmpx", 0,
649*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nTotCount=[u]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[u]\nDataOff=[u]\n", NULL,
650*ed775ee7SAntonio Huete Jimenez "Remaining=[u]\n", NULL, NULL } },
65141c99275SPeter Avalos
65241c99275SPeter Avalos { SMBwriteBs, "SMBwriteBs", 0,
653*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nTotCount=[u]\nOffset=[D]\nRes=[W]\nDataSize=[u]\nDataOff=[u]\n",
654*ed775ee7SAntonio Huete Jimenez NULL, "Count=[u]\n", NULL, NULL } },
65541c99275SPeter Avalos
65641c99275SPeter Avalos { SMBsetattrE, "SMBsetattrE", 0,
657*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
65841c99275SPeter Avalos NULL, NULL, NULL } },
65941c99275SPeter Avalos
66041c99275SPeter Avalos { SMBgetattrE, "SMBgetattrE", 0,
661*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\n", NULL,
662*ed775ee7SAntonio Huete Jimenez "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[U]\nAllocSize=[U]\nAttribute=[A]\n",
66341c99275SPeter Avalos NULL, NULL } },
66441c99275SPeter Avalos
66541c99275SPeter Avalos { SMBtranss, "SMBtranss", 0, DEFDESCRIPT },
66641c99275SPeter Avalos { SMBioctls, "SMBioctls", 0, DEFDESCRIPT },
66741c99275SPeter Avalos
66841c99275SPeter Avalos { SMBcopy, "SMBcopy", 0,
669*ed775ee7SAntonio Huete Jimenez { "TreeID2=[u]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
670*ed775ee7SAntonio Huete Jimenez "CopyCount=[u]\n", "|ErrStr=[S]\n", NULL } },
67141c99275SPeter Avalos
67241c99275SPeter Avalos { SMBmove, "SMBmove", 0,
673*ed775ee7SAntonio Huete Jimenez { "TreeID2=[u]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
674*ed775ee7SAntonio Huete Jimenez "MoveCount=[u]\n", "|ErrStr=[S]\n", NULL } },
67541c99275SPeter Avalos
67641c99275SPeter Avalos { SMBopenX, "SMBopenX", FLG_CHAIN,
677*ed775ee7SAntonio Huete Jimenez { "Com2=[w]\nOff2=[u]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[U]\nTimeOut=[D]\nRes=[W]\n",
67841c99275SPeter Avalos "Path=[S]\n",
679*ed775ee7SAntonio Huete Jimenez "Com2=[w]\nOff2=[u]\nHandle=[u]\nAttrib=[A]\nTime=[T2]Size=[U]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n",
68041c99275SPeter Avalos NULL, NULL } },
68141c99275SPeter Avalos
68241c99275SPeter Avalos { SMBreadX, "SMBreadX", FLG_CHAIN,
683*ed775ee7SAntonio Huete Jimenez { "Com2=[w]\nOff2=[u]\nHandle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nCountLeft=[u]\n",
68441c99275SPeter Avalos NULL,
685*ed775ee7SAntonio Huete Jimenez "Com2=[w]\nOff2=[u]\nRemaining=[u]\nRes=[W]\nDataSize=[u]\nDataOff=[u]\nRes=([w,w,w,w])\n",
68641c99275SPeter Avalos NULL, NULL } },
68741c99275SPeter Avalos
68841c99275SPeter Avalos { SMBwriteX, "SMBwriteX", FLG_CHAIN,
689*ed775ee7SAntonio Huete Jimenez { "Com2=[w]\nOff2=[u]\nHandle=[u]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[u]\nRes=[w]\nDataSize=[u]\nDataOff=[u]\n",
69041c99275SPeter Avalos NULL,
691*ed775ee7SAntonio Huete Jimenez "Com2=[w]\nOff2=[u]\nCount=[u]\nRemaining=[u]\nRes=[W]\n",
69241c99275SPeter Avalos NULL, NULL } },
69341c99275SPeter Avalos
69441c99275SPeter Avalos { SMBffirst, "SMBffirst", 0,
695*ed775ee7SAntonio Huete Jimenez { "Count=[u]\nAttrib=[A]\n",
696*ed775ee7SAntonio Huete Jimenez "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
697*ed775ee7SAntonio Huete Jimenez "Count=[u]\n",
698*ed775ee7SAntonio Huete Jimenez "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
69941c99275SPeter Avalos NULL } },
70041c99275SPeter Avalos
70141c99275SPeter Avalos { SMBfunique, "SMBfunique", 0,
702*ed775ee7SAntonio Huete Jimenez { "Count=[u]\nAttrib=[A]\n",
703*ed775ee7SAntonio Huete Jimenez "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
704*ed775ee7SAntonio Huete Jimenez "Count=[u]\n",
705*ed775ee7SAntonio Huete Jimenez "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
70641c99275SPeter Avalos NULL } },
70741c99275SPeter Avalos
70841c99275SPeter Avalos { SMBfclose, "SMBfclose", 0,
709*ed775ee7SAntonio Huete Jimenez { "Count=[u]\nAttrib=[A]\n",
710*ed775ee7SAntonio Huete Jimenez "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
711*ed775ee7SAntonio Huete Jimenez "Count=[u]\n",
712*ed775ee7SAntonio Huete Jimenez "BlkType=[B]\nBlkLen=[u]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[U]\nName=[s13]\n",
71341c99275SPeter Avalos NULL } },
71441c99275SPeter Avalos
71541c99275SPeter Avalos { SMBfindnclose, "SMBfindnclose", 0,
716*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
71741c99275SPeter Avalos
71841c99275SPeter Avalos { SMBfindclose, "SMBfindclose", 0,
719*ed775ee7SAntonio Huete Jimenez { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
72041c99275SPeter Avalos
72141c99275SPeter Avalos { SMBsends, "SMBsends", 0,
72241c99275SPeter Avalos { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
72341c99275SPeter Avalos
72441c99275SPeter Avalos { SMBsendstrt, "SMBsendstrt", 0,
725*ed775ee7SAntonio Huete Jimenez { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[u]\n", NULL, NULL } },
72641c99275SPeter Avalos
72741c99275SPeter Avalos { SMBsendend, "SMBsendend", 0,
728*ed775ee7SAntonio Huete Jimenez { "GroupID=[u]\n", NULL, NULL, NULL, NULL } },
72941c99275SPeter Avalos
73041c99275SPeter Avalos { SMBsendtxt, "SMBsendtxt", 0,
731*ed775ee7SAntonio Huete Jimenez { "GroupID=[u]\n", NULL, NULL, NULL, NULL } },
73241c99275SPeter Avalos
73341c99275SPeter Avalos { SMBsendb, "SMBsendb", 0,
73441c99275SPeter Avalos { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
73541c99275SPeter Avalos
73641c99275SPeter Avalos { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT },
73741c99275SPeter Avalos { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT },
73841c99275SPeter Avalos { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT },
73941c99275SPeter Avalos
74041c99275SPeter Avalos { SMBnegprot, "SMBnegprot", 0,
74141c99275SPeter Avalos { NULL, NULL, NULL, NULL, print_negprot } },
74241c99275SPeter Avalos
74341c99275SPeter Avalos { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN,
74441c99275SPeter Avalos { NULL, NULL, NULL, NULL, print_sesssetup } },
74541c99275SPeter Avalos
74641c99275SPeter Avalos { SMBtconX, "SMBtconX", FLG_CHAIN,
747*ed775ee7SAntonio Huete Jimenez { "Com2=[w]\nOff2=[u]\nFlags=[w]\nPassLen=[u]\nPasswd&Path&Device=\n",
748*ed775ee7SAntonio Huete Jimenez NULL, "Com2=[w]\nOff2=[u]\n", "ServiceType=[R]\n", NULL } },
74941c99275SPeter Avalos
75041c99275SPeter Avalos { SMBlockingX, "SMBlockingX", FLG_CHAIN,
75141c99275SPeter Avalos { NULL, NULL, NULL, NULL, print_lockingandx } },
75241c99275SPeter Avalos
75341c99275SPeter Avalos { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } },
75441c99275SPeter Avalos
75541c99275SPeter Avalos { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT },
75641c99275SPeter Avalos { SMBctemp, "SMBctemp", 0, DEFDESCRIPT },
75741c99275SPeter Avalos { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT },
75841c99275SPeter Avalos { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } },
75941c99275SPeter Avalos
76041c99275SPeter Avalos { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT },
76141c99275SPeter Avalos { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
76241c99275SPeter Avalos
76341c99275SPeter Avalos { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
764*ed775ee7SAntonio Huete Jimenez { "Com2=[w]\nOff2=[u]\nRes=[b]\nNameLen=[lu]\nFlags=[W]\nRootDirectoryFid=[U]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n",
76541c99275SPeter Avalos "Path=[C]\n",
766*ed775ee7SAntonio Huete Jimenez "Com2=[w]\nOff2=[u]\nOplockLevel=[b]\nFid=[u]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n",
76741c99275SPeter Avalos NULL, NULL } },
76841c99275SPeter Avalos
76941c99275SPeter Avalos { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT },
77041c99275SPeter Avalos
77141c99275SPeter Avalos { -1, NULL, 0, DEFDESCRIPT }
77241c99275SPeter Avalos };
77341c99275SPeter Avalos
77441c99275SPeter Avalos
77541c99275SPeter Avalos /*
77641c99275SPeter Avalos * print a SMB message
77741c99275SPeter Avalos */
77841c99275SPeter Avalos static void
print_smb(netdissect_options * ndo,const u_char * buf,const u_char * maxbuf)779411677aeSAaron LI print_smb(netdissect_options *ndo,
780411677aeSAaron LI const u_char *buf, const u_char *maxbuf)
78141c99275SPeter Avalos {
782411677aeSAaron LI uint16_t flags2;
783*ed775ee7SAntonio Huete Jimenez u_int nterrcodes;
784*ed775ee7SAntonio Huete Jimenez u_int command;
785411677aeSAaron LI uint32_t nterror;
78641c99275SPeter Avalos const u_char *words, *maxwords, *data;
787411677aeSAaron LI const struct smbfns *fn;
78841c99275SPeter Avalos const char *fmt_smbheader =
789*ed775ee7SAntonio Huete Jimenez "[P4]SMB Command = [B]\nError class = [BP1]\nError code = [u]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [u]\nProc ID = [u]\nUID = [u]\nMID = [u]\nWord Count = [b]\n";
790*ed775ee7SAntonio Huete Jimenez u_int smboffset;
79141c99275SPeter Avalos
792*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "smb";
793*ed775ee7SAntonio Huete Jimenez
794*ed775ee7SAntonio Huete Jimenez request = (GET_U_1(buf + 9) & 0x80) ? 0 : 1;
79541c99275SPeter Avalos startbuf = buf;
79641c99275SPeter Avalos
797*ed775ee7SAntonio Huete Jimenez command = GET_U_1(buf + 4);
79841c99275SPeter Avalos
79941c99275SPeter Avalos fn = smbfind(command, smb_fns);
80041c99275SPeter Avalos
801411677aeSAaron LI if (ndo->ndo_vflag > 1)
802*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n");
80341c99275SPeter Avalos
804*ed775ee7SAntonio Huete Jimenez ND_PRINT("SMB PACKET: %s (%s)", fn->name, request ? "REQUEST" : "REPLY");
80541c99275SPeter Avalos
806411677aeSAaron LI if (ndo->ndo_vflag < 2)
80741c99275SPeter Avalos return;
80841c99275SPeter Avalos
809*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n");
810*ed775ee7SAntonio Huete Jimenez flags2 = GET_LE_U_2(buf + 10);
811411677aeSAaron LI unicodestr = flags2 & 0x8000;
812411677aeSAaron LI nterrcodes = flags2 & 0x4000;
813411677aeSAaron LI
81441c99275SPeter Avalos /* print out the header */
815411677aeSAaron LI smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr);
81641c99275SPeter Avalos
81741c99275SPeter Avalos if (nterrcodes) {
818*ed775ee7SAntonio Huete Jimenez nterror = GET_LE_U_4(buf + 5);
81941c99275SPeter Avalos if (nterror)
820*ed775ee7SAntonio Huete Jimenez ND_PRINT("NTError = %s\n", nt_errstr(nterror));
82141c99275SPeter Avalos } else {
822*ed775ee7SAntonio Huete Jimenez if (GET_U_1(buf + 5))
823*ed775ee7SAntonio Huete Jimenez ND_PRINT("SMBError = %s\n", smb_errstr(GET_U_1(buf + 5),
824*ed775ee7SAntonio Huete Jimenez GET_LE_U_2(buf + 7)));
82541c99275SPeter Avalos }
82641c99275SPeter Avalos
82741c99275SPeter Avalos smboffset = 32;
82841c99275SPeter Avalos
82941c99275SPeter Avalos for (;;) {
83041c99275SPeter Avalos const char *f1, *f2;
83141c99275SPeter Avalos int wct;
83241c99275SPeter Avalos u_int bcc;
833*ed775ee7SAntonio Huete Jimenez u_int newsmboffset;
83441c99275SPeter Avalos
83541c99275SPeter Avalos words = buf + smboffset;
836*ed775ee7SAntonio Huete Jimenez wct = GET_U_1(words);
83741c99275SPeter Avalos data = words + 1 + wct * 2;
838*ed775ee7SAntonio Huete Jimenez maxwords = ND_MIN(data, maxbuf);
83941c99275SPeter Avalos
84041c99275SPeter Avalos if (request) {
84141c99275SPeter Avalos f1 = fn->descript.req_f1;
84241c99275SPeter Avalos f2 = fn->descript.req_f2;
84341c99275SPeter Avalos } else {
84441c99275SPeter Avalos f1 = fn->descript.rep_f1;
84541c99275SPeter Avalos f2 = fn->descript.rep_f2;
84641c99275SPeter Avalos }
84741c99275SPeter Avalos
848*ed775ee7SAntonio Huete Jimenez smb_reset();
84941c99275SPeter Avalos if (fn->descript.fn)
850411677aeSAaron LI (*fn->descript.fn)(ndo, words, data, buf, maxbuf);
85141c99275SPeter Avalos else {
85241c99275SPeter Avalos if (wct) {
85341c99275SPeter Avalos if (f1)
854411677aeSAaron LI smb_fdata(ndo, words + 1, f1, words + 1 + wct * 2, unicodestr);
85541c99275SPeter Avalos else {
856*ed775ee7SAntonio Huete Jimenez u_int i;
857*ed775ee7SAntonio Huete Jimenez u_int v;
85841c99275SPeter Avalos
859*ed775ee7SAntonio Huete Jimenez for (i = 0; words + 1 + 2 * i < maxwords; i++) {
860*ed775ee7SAntonio Huete Jimenez v = GET_LE_U_2(words + 1 + 2 * i);
861*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_vwv[%u]=%u (0x%X)\n", i, v, v);
86241c99275SPeter Avalos }
86341c99275SPeter Avalos }
86441c99275SPeter Avalos }
86541c99275SPeter Avalos
866*ed775ee7SAntonio Huete Jimenez bcc = GET_LE_U_2(data);
867*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_bcc=%u\n", bcc);
86841c99275SPeter Avalos if (f2) {
86941c99275SPeter Avalos if (bcc > 0)
870411677aeSAaron LI smb_fdata(ndo, data + 2, f2, data + 2 + bcc, unicodestr);
87141c99275SPeter Avalos } else {
87241c99275SPeter Avalos if (bcc > 0) {
873*ed775ee7SAntonio Huete Jimenez ND_PRINT("smb_buf[]=\n");
874*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, data + 2, ND_MIN(bcc, ND_BYTES_BETWEEN(maxbuf, data + 2)));
87541c99275SPeter Avalos }
87641c99275SPeter Avalos }
87741c99275SPeter Avalos }
87841c99275SPeter Avalos
87941c99275SPeter Avalos if ((fn->flags & FLG_CHAIN) == 0)
88041c99275SPeter Avalos break;
88141c99275SPeter Avalos if (wct == 0)
88241c99275SPeter Avalos break;
883*ed775ee7SAntonio Huete Jimenez command = GET_U_1(words + 1);
88441c99275SPeter Avalos if (command == 0xFF)
88541c99275SPeter Avalos break;
886*ed775ee7SAntonio Huete Jimenez newsmboffset = GET_LE_U_2(words + 3);
88741c99275SPeter Avalos
88841c99275SPeter Avalos fn = smbfind(command, smb_fns);
88941c99275SPeter Avalos
890*ed775ee7SAntonio Huete Jimenez ND_PRINT("\nSMB PACKET: %s (%s) (CHAINED)\n",
891*ed775ee7SAntonio Huete Jimenez fn->name, request ? "REQUEST" : "REPLY");
89241c99275SPeter Avalos if (newsmboffset <= smboffset) {
893*ed775ee7SAntonio Huete Jimenez ND_PRINT("Bad andX offset: %u <= %u\n", newsmboffset, smboffset);
89441c99275SPeter Avalos break;
89541c99275SPeter Avalos }
89641c99275SPeter Avalos smboffset = newsmboffset;
89741c99275SPeter Avalos }
89841c99275SPeter Avalos }
89941c99275SPeter Avalos
90041c99275SPeter Avalos
90141c99275SPeter Avalos /*
90241c99275SPeter Avalos * print a NBT packet received across tcp on port 139
90341c99275SPeter Avalos */
90441c99275SPeter Avalos void
nbt_tcp_print(netdissect_options * ndo,const u_char * data,u_int length)905411677aeSAaron LI nbt_tcp_print(netdissect_options *ndo,
906*ed775ee7SAntonio Huete Jimenez const u_char *data, u_int length)
90741c99275SPeter Avalos {
908*ed775ee7SAntonio Huete Jimenez u_int caplen;
909*ed775ee7SAntonio Huete Jimenez u_int type;
91041c99275SPeter Avalos u_int nbt_len;
91141c99275SPeter Avalos const u_char *maxbuf;
91241c99275SPeter Avalos
913*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "nbt_tcp";
91441c99275SPeter Avalos if (length < 4)
91541c99275SPeter Avalos goto trunc;
916411677aeSAaron LI if (ndo->ndo_snapend < data)
91741c99275SPeter Avalos goto trunc;
918*ed775ee7SAntonio Huete Jimenez caplen = ND_BYTES_AVAILABLE_AFTER(data);
91941c99275SPeter Avalos if (caplen < 4)
92041c99275SPeter Avalos goto trunc;
92141c99275SPeter Avalos maxbuf = data + caplen;
922*ed775ee7SAntonio Huete Jimenez type = GET_U_1(data);
923*ed775ee7SAntonio Huete Jimenez nbt_len = GET_BE_U_2(data + 2);
92441c99275SPeter Avalos length -= 4;
92541c99275SPeter Avalos caplen -= 4;
92641c99275SPeter Avalos
92741c99275SPeter Avalos startbuf = data;
92841c99275SPeter Avalos
929411677aeSAaron LI if (ndo->ndo_vflag < 2) {
930*ed775ee7SAntonio Huete Jimenez ND_PRINT(" NBT Session Packet: ");
93141c99275SPeter Avalos switch (type) {
93241c99275SPeter Avalos case 0x00:
933*ed775ee7SAntonio Huete Jimenez ND_PRINT("Session Message");
93441c99275SPeter Avalos break;
93541c99275SPeter Avalos
93641c99275SPeter Avalos case 0x81:
937*ed775ee7SAntonio Huete Jimenez ND_PRINT("Session Request");
93841c99275SPeter Avalos break;
93941c99275SPeter Avalos
94041c99275SPeter Avalos case 0x82:
941*ed775ee7SAntonio Huete Jimenez ND_PRINT("Session Granted");
94241c99275SPeter Avalos break;
94341c99275SPeter Avalos
94441c99275SPeter Avalos case 0x83:
94541c99275SPeter Avalos {
946*ed775ee7SAntonio Huete Jimenez u_int ecode;
94741c99275SPeter Avalos
94841c99275SPeter Avalos if (nbt_len < 4)
94941c99275SPeter Avalos goto trunc;
95041c99275SPeter Avalos if (length < 4)
95141c99275SPeter Avalos goto trunc;
95241c99275SPeter Avalos if (caplen < 4)
95341c99275SPeter Avalos goto trunc;
954*ed775ee7SAntonio Huete Jimenez ecode = GET_U_1(data + 4);
95541c99275SPeter Avalos
956*ed775ee7SAntonio Huete Jimenez ND_PRINT("Session Reject, ");
95741c99275SPeter Avalos switch (ecode) {
95841c99275SPeter Avalos case 0x80:
959*ed775ee7SAntonio Huete Jimenez ND_PRINT("Not listening on called name");
96041c99275SPeter Avalos break;
96141c99275SPeter Avalos case 0x81:
962*ed775ee7SAntonio Huete Jimenez ND_PRINT("Not listening for calling name");
96341c99275SPeter Avalos break;
96441c99275SPeter Avalos case 0x82:
965*ed775ee7SAntonio Huete Jimenez ND_PRINT("Called name not present");
96641c99275SPeter Avalos break;
96741c99275SPeter Avalos case 0x83:
968*ed775ee7SAntonio Huete Jimenez ND_PRINT("Called name present, but insufficient resources");
96941c99275SPeter Avalos break;
97041c99275SPeter Avalos default:
971*ed775ee7SAntonio Huete Jimenez ND_PRINT("Unspecified error 0x%X", ecode);
97241c99275SPeter Avalos break;
97341c99275SPeter Avalos }
97441c99275SPeter Avalos }
97541c99275SPeter Avalos break;
97641c99275SPeter Avalos
97741c99275SPeter Avalos case 0x85:
978*ed775ee7SAntonio Huete Jimenez ND_PRINT("Session Keepalive");
97941c99275SPeter Avalos break;
98041c99275SPeter Avalos
98141c99275SPeter Avalos default:
982411677aeSAaron LI data = smb_fdata(ndo, data, "Unknown packet type [rB]", maxbuf, 0);
98341c99275SPeter Avalos break;
98441c99275SPeter Avalos }
98541c99275SPeter Avalos } else {
986*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n>>> NBT Session Packet\n");
98741c99275SPeter Avalos switch (type) {
98841c99275SPeter Avalos case 0x00:
989*ed775ee7SAntonio Huete Jimenez data = smb_fdata(ndo, data, "[P1]NBT Session Message\nFlags=[B]\nLength=[ru]\n",
99041c99275SPeter Avalos data + 4, 0);
99141c99275SPeter Avalos if (data == NULL)
99241c99275SPeter Avalos break;
99341c99275SPeter Avalos if (nbt_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
994*ed775ee7SAntonio Huete Jimenez if (nbt_len > caplen) {
995*ed775ee7SAntonio Huete Jimenez if (nbt_len > length)
996*ed775ee7SAntonio Huete Jimenez ND_PRINT("WARNING: Packet is continued in later TCP segments\n");
99741c99275SPeter Avalos else
998*ed775ee7SAntonio Huete Jimenez ND_PRINT("WARNING: Short packet. Try increasing the snap length by %u\n",
999*ed775ee7SAntonio Huete Jimenez nbt_len - caplen);
100041c99275SPeter Avalos }
1001411677aeSAaron LI print_smb(ndo, data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf);
100241c99275SPeter Avalos } else
1003*ed775ee7SAntonio Huete Jimenez ND_PRINT("Session packet:(raw data or continuation?)\n");
100441c99275SPeter Avalos break;
100541c99275SPeter Avalos
100641c99275SPeter Avalos case 0x81:
1007411677aeSAaron LI data = smb_fdata(ndo, data,
1008*ed775ee7SAntonio Huete Jimenez "[P1]NBT Session Request\nFlags=[B]\nLength=[ru]\nDestination=[n1]\nSource=[n1]\n",
100941c99275SPeter Avalos maxbuf, 0);
101041c99275SPeter Avalos break;
101141c99275SPeter Avalos
101241c99275SPeter Avalos case 0x82:
1013*ed775ee7SAntonio Huete Jimenez data = smb_fdata(ndo, data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[ru]\n", maxbuf, 0);
101441c99275SPeter Avalos break;
101541c99275SPeter Avalos
101641c99275SPeter Avalos case 0x83:
101741c99275SPeter Avalos {
101841c99275SPeter Avalos const u_char *origdata;
1019*ed775ee7SAntonio Huete Jimenez u_int ecode;
102041c99275SPeter Avalos
102141c99275SPeter Avalos origdata = data;
1022*ed775ee7SAntonio Huete Jimenez data = smb_fdata(ndo, data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[ru]\nReason=[B]\n",
102341c99275SPeter Avalos maxbuf, 0);
102441c99275SPeter Avalos if (data == NULL)
102541c99275SPeter Avalos break;
102641c99275SPeter Avalos if (nbt_len >= 1 && caplen >= 1) {
1027*ed775ee7SAntonio Huete Jimenez ecode = GET_U_1(origdata + 4);
102841c99275SPeter Avalos switch (ecode) {
102941c99275SPeter Avalos case 0x80:
1030*ed775ee7SAntonio Huete Jimenez ND_PRINT("Not listening on called name\n");
103141c99275SPeter Avalos break;
103241c99275SPeter Avalos case 0x81:
1033*ed775ee7SAntonio Huete Jimenez ND_PRINT("Not listening for calling name\n");
103441c99275SPeter Avalos break;
103541c99275SPeter Avalos case 0x82:
1036*ed775ee7SAntonio Huete Jimenez ND_PRINT("Called name not present\n");
103741c99275SPeter Avalos break;
103841c99275SPeter Avalos case 0x83:
1039*ed775ee7SAntonio Huete Jimenez ND_PRINT("Called name present, but insufficient resources\n");
104041c99275SPeter Avalos break;
104141c99275SPeter Avalos default:
1042*ed775ee7SAntonio Huete Jimenez ND_PRINT("Unspecified error 0x%X\n", ecode);
104341c99275SPeter Avalos break;
104441c99275SPeter Avalos }
104541c99275SPeter Avalos }
104641c99275SPeter Avalos }
104741c99275SPeter Avalos break;
104841c99275SPeter Avalos
104941c99275SPeter Avalos case 0x85:
1050*ed775ee7SAntonio Huete Jimenez data = smb_fdata(ndo, data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[ru]\n", maxbuf, 0);
105141c99275SPeter Avalos break;
105241c99275SPeter Avalos
105341c99275SPeter Avalos default:
1054411677aeSAaron LI data = smb_fdata(ndo, data, "NBT - Unknown packet type\nType=[B]\n", maxbuf, 0);
105541c99275SPeter Avalos break;
105641c99275SPeter Avalos }
105741c99275SPeter Avalos }
105841c99275SPeter Avalos return;
105941c99275SPeter Avalos trunc:
1060*ed775ee7SAntonio Huete Jimenez nd_print_trunc(ndo);
106141c99275SPeter Avalos }
106241c99275SPeter Avalos
1063411677aeSAaron LI static const struct tok opcode_str[] = {
1064411677aeSAaron LI { 0, "QUERY" },
1065411677aeSAaron LI { 5, "REGISTRATION" },
1066411677aeSAaron LI { 6, "RELEASE" },
1067411677aeSAaron LI { 7, "WACK" },
1068411677aeSAaron LI { 8, "REFRESH(8)" },
1069411677aeSAaron LI { 9, "REFRESH" },
1070411677aeSAaron LI { 15, "MULTIHOMED REGISTRATION" },
1071411677aeSAaron LI { 0, NULL }
1072411677aeSAaron LI };
107341c99275SPeter Avalos
107441c99275SPeter Avalos /*
107541c99275SPeter Avalos * print a NBT packet received across udp on port 137
107641c99275SPeter Avalos */
107741c99275SPeter Avalos void
nbt_udp137_print(netdissect_options * ndo,const u_char * data,u_int length)1078411677aeSAaron LI nbt_udp137_print(netdissect_options *ndo,
1079*ed775ee7SAntonio Huete Jimenez const u_char *data, u_int length)
108041c99275SPeter Avalos {
108141c99275SPeter Avalos const u_char *maxbuf = data + length;
1082*ed775ee7SAntonio Huete Jimenez u_int name_trn_id, response, opcode, nm_flags, rcode;
1083*ed775ee7SAntonio Huete Jimenez u_int qdcount, ancount, nscount, arcount;
108441c99275SPeter Avalos const u_char *p;
1085*ed775ee7SAntonio Huete Jimenez u_int total, i;
108641c99275SPeter Avalos
1087*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "nbt_udp137";
1088*ed775ee7SAntonio Huete Jimenez name_trn_id = GET_BE_U_2(data);
1089*ed775ee7SAntonio Huete Jimenez response = (GET_U_1(data + 2) >> 7);
1090*ed775ee7SAntonio Huete Jimenez opcode = (GET_U_1(data + 2) >> 3) & 0xF;
1091*ed775ee7SAntonio Huete Jimenez nm_flags = ((GET_U_1(data + 2) & 0x7) << 4) + (GET_U_1(data + 3) >> 4);
1092*ed775ee7SAntonio Huete Jimenez rcode = GET_U_1(data + 3) & 0xF;
1093*ed775ee7SAntonio Huete Jimenez qdcount = GET_BE_U_2(data + 4);
1094*ed775ee7SAntonio Huete Jimenez ancount = GET_BE_U_2(data + 6);
1095*ed775ee7SAntonio Huete Jimenez nscount = GET_BE_U_2(data + 8);
1096*ed775ee7SAntonio Huete Jimenez arcount = GET_BE_U_2(data + 10);
109741c99275SPeter Avalos startbuf = data;
109841c99275SPeter Avalos
109941c99275SPeter Avalos if (maxbuf <= data)
110041c99275SPeter Avalos return;
110141c99275SPeter Avalos
1102411677aeSAaron LI if (ndo->ndo_vflag > 1)
1103*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n>>> ");
110441c99275SPeter Avalos
1105*ed775ee7SAntonio Huete Jimenez ND_PRINT("NBT UDP PACKET(137): %s", tok2str(opcode_str, "OPUNKNOWN", opcode));
110641c99275SPeter Avalos if (response) {
1107*ed775ee7SAntonio Huete Jimenez ND_PRINT("; %s", rcode ? "NEGATIVE" : "POSITIVE");
110841c99275SPeter Avalos }
1109*ed775ee7SAntonio Huete Jimenez ND_PRINT("; %s; %s", response ? "RESPONSE" : "REQUEST",
1110*ed775ee7SAntonio Huete Jimenez (nm_flags & 1) ? "BROADCAST" : "UNICAST");
111141c99275SPeter Avalos
1112411677aeSAaron LI if (ndo->ndo_vflag < 2)
111341c99275SPeter Avalos return;
111441c99275SPeter Avalos
1115*ed775ee7SAntonio Huete Jimenez ND_PRINT("\nTrnID=0x%X\nOpCode=%u\nNmFlags=0x%X\nRcode=%u\nQueryCount=%u\nAnswerCount=%u\nAuthorityCount=%u\nAddressRecCount=%u\n",
111641c99275SPeter Avalos name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount,
1117*ed775ee7SAntonio Huete Jimenez arcount);
111841c99275SPeter Avalos
111941c99275SPeter Avalos p = data + 12;
112041c99275SPeter Avalos
112141c99275SPeter Avalos total = ancount + nscount + arcount;
112241c99275SPeter Avalos
112341c99275SPeter Avalos if (qdcount > 100 || total > 100) {
1124*ed775ee7SAntonio Huete Jimenez ND_PRINT("Corrupt packet??\n");
112541c99275SPeter Avalos return;
112641c99275SPeter Avalos }
112741c99275SPeter Avalos
112841c99275SPeter Avalos if (qdcount) {
1129*ed775ee7SAntonio Huete Jimenez ND_PRINT("QuestionRecords:\n");
113041c99275SPeter Avalos for (i = 0; i < qdcount; i++) {
1131411677aeSAaron LI p = smb_fdata(ndo, p,
113241c99275SPeter Avalos "|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",
113341c99275SPeter Avalos maxbuf, 0);
113441c99275SPeter Avalos if (p == NULL)
113541c99275SPeter Avalos goto out;
113641c99275SPeter Avalos }
113741c99275SPeter Avalos }
113841c99275SPeter Avalos
113941c99275SPeter Avalos if (total) {
1140*ed775ee7SAntonio Huete Jimenez ND_PRINT("\nResourceRecords:\n");
114141c99275SPeter Avalos for (i = 0; i < total; i++) {
1142*ed775ee7SAntonio Huete Jimenez u_int rdlen;
1143*ed775ee7SAntonio Huete Jimenez u_int restype;
114441c99275SPeter Avalos
1145411677aeSAaron LI p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0);
114641c99275SPeter Avalos if (p == NULL)
114741c99275SPeter Avalos goto out;
1148*ed775ee7SAntonio Huete Jimenez restype = GET_BE_U_2(p);
1149*ed775ee7SAntonio Huete Jimenez p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rU]\n", p + 8, 0);
115041c99275SPeter Avalos if (p == NULL)
115141c99275SPeter Avalos goto out;
1152*ed775ee7SAntonio Huete Jimenez rdlen = GET_BE_U_2(p);
1153*ed775ee7SAntonio Huete Jimenez ND_PRINT("ResourceLength=%u\nResourceData=\n", rdlen);
115441c99275SPeter Avalos p += 2;
115541c99275SPeter Avalos if (rdlen == 6) {
1156411677aeSAaron LI p = smb_fdata(ndo, p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen, 0);
115741c99275SPeter Avalos if (p == NULL)
115841c99275SPeter Avalos goto out;
115941c99275SPeter Avalos } else {
116041c99275SPeter Avalos if (restype == 0x21) {
1161*ed775ee7SAntonio Huete Jimenez u_int numnames;
116241c99275SPeter Avalos
1163*ed775ee7SAntonio Huete Jimenez numnames = GET_U_1(p);
1164411677aeSAaron LI p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0);
116541c99275SPeter Avalos if (p == NULL)
116641c99275SPeter Avalos goto out;
1167*ed775ee7SAntonio Huete Jimenez while (numnames) {
1168411677aeSAaron LI p = smb_fdata(ndo, p, "Name=[n2]\t#", maxbuf, 0);
116941c99275SPeter Avalos if (p == NULL)
117041c99275SPeter Avalos goto out;
1171*ed775ee7SAntonio Huete Jimenez ND_TCHECK_1(p);
1172*ed775ee7SAntonio Huete Jimenez if (p >= maxbuf)
1173*ed775ee7SAntonio Huete Jimenez goto out;
1174*ed775ee7SAntonio Huete Jimenez if (GET_U_1(p) & 0x80)
1175*ed775ee7SAntonio Huete Jimenez ND_PRINT("<GROUP> ");
1176*ed775ee7SAntonio Huete Jimenez switch (GET_U_1(p) & 0x60) {
1177*ed775ee7SAntonio Huete Jimenez case 0x00: ND_PRINT("B "); break;
1178*ed775ee7SAntonio Huete Jimenez case 0x20: ND_PRINT("P "); break;
1179*ed775ee7SAntonio Huete Jimenez case 0x40: ND_PRINT("M "); break;
1180*ed775ee7SAntonio Huete Jimenez case 0x60: ND_PRINT("_ "); break;
118141c99275SPeter Avalos }
1182*ed775ee7SAntonio Huete Jimenez if (GET_U_1(p) & 0x10)
1183*ed775ee7SAntonio Huete Jimenez ND_PRINT("<DEREGISTERING> ");
1184*ed775ee7SAntonio Huete Jimenez if (GET_U_1(p) & 0x08)
1185*ed775ee7SAntonio Huete Jimenez ND_PRINT("<CONFLICT> ");
1186*ed775ee7SAntonio Huete Jimenez if (GET_U_1(p) & 0x04)
1187*ed775ee7SAntonio Huete Jimenez ND_PRINT("<ACTIVE> ");
1188*ed775ee7SAntonio Huete Jimenez if (GET_U_1(p) & 0x02)
1189*ed775ee7SAntonio Huete Jimenez ND_PRINT("<PERMANENT> ");
1190*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n");
119141c99275SPeter Avalos p += 2;
1192*ed775ee7SAntonio Huete Jimenez numnames--;
119341c99275SPeter Avalos }
119441c99275SPeter Avalos } else {
1195*ed775ee7SAntonio Huete Jimenez if (p >= maxbuf)
1196*ed775ee7SAntonio Huete Jimenez goto out;
1197*ed775ee7SAntonio Huete Jimenez smb_data_print(ndo, p, ND_MIN(rdlen, length - ND_BYTES_BETWEEN(p, data)));
119841c99275SPeter Avalos p += rdlen;
119941c99275SPeter Avalos }
120041c99275SPeter Avalos }
120141c99275SPeter Avalos }
120241c99275SPeter Avalos }
120341c99275SPeter Avalos
120441c99275SPeter Avalos if (p < maxbuf)
1205411677aeSAaron LI smb_fdata(ndo, p, "AdditionalData:\n", maxbuf, 0);
120641c99275SPeter Avalos
120741c99275SPeter Avalos out:
120841c99275SPeter Avalos return;
120941c99275SPeter Avalos trunc:
1210*ed775ee7SAntonio Huete Jimenez nd_print_trunc(ndo);
121141c99275SPeter Avalos }
121241c99275SPeter Avalos
1213ea7b4bf5SPeter Avalos /*
1214ea7b4bf5SPeter Avalos * Print an SMB-over-TCP packet received across tcp on port 445
1215ea7b4bf5SPeter Avalos */
1216ea7b4bf5SPeter Avalos void
smb_tcp_print(netdissect_options * ndo,const u_char * data,u_int length)1217411677aeSAaron LI smb_tcp_print(netdissect_options *ndo,
1218*ed775ee7SAntonio Huete Jimenez const u_char * data, u_int length)
1219ea7b4bf5SPeter Avalos {
1220*ed775ee7SAntonio Huete Jimenez u_int caplen;
1221ea7b4bf5SPeter Avalos u_int smb_len;
1222ea7b4bf5SPeter Avalos const u_char *maxbuf;
122341c99275SPeter Avalos
1224*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "smb_tcp";
1225ea7b4bf5SPeter Avalos if (length < 4)
1226ea7b4bf5SPeter Avalos goto trunc;
1227411677aeSAaron LI if (ndo->ndo_snapend < data)
1228ea7b4bf5SPeter Avalos goto trunc;
1229*ed775ee7SAntonio Huete Jimenez caplen = ND_BYTES_AVAILABLE_AFTER(data);
1230ea7b4bf5SPeter Avalos if (caplen < 4)
1231ea7b4bf5SPeter Avalos goto trunc;
1232ea7b4bf5SPeter Avalos maxbuf = data + caplen;
1233*ed775ee7SAntonio Huete Jimenez smb_len = GET_BE_U_3(data + 1);
1234ea7b4bf5SPeter Avalos length -= 4;
1235ea7b4bf5SPeter Avalos caplen -= 4;
1236ea7b4bf5SPeter Avalos
1237ea7b4bf5SPeter Avalos startbuf = data;
1238ea7b4bf5SPeter Avalos data += 4;
1239ea7b4bf5SPeter Avalos
1240ea7b4bf5SPeter Avalos if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
1241*ed775ee7SAntonio Huete Jimenez if (smb_len > caplen) {
1242*ed775ee7SAntonio Huete Jimenez if (smb_len > length)
1243*ed775ee7SAntonio Huete Jimenez ND_PRINT(" WARNING: Packet is continued in later TCP segments\n");
1244ea7b4bf5SPeter Avalos else
1245*ed775ee7SAntonio Huete Jimenez ND_PRINT(" WARNING: Short packet. Try increasing the snap length by %u\n",
1246*ed775ee7SAntonio Huete Jimenez smb_len - caplen);
1247ea7b4bf5SPeter Avalos } else
1248*ed775ee7SAntonio Huete Jimenez ND_PRINT(" ");
1249411677aeSAaron LI print_smb(ndo, data, maxbuf > data + smb_len ? data + smb_len : maxbuf);
1250411677aeSAaron LI } else
1251*ed775ee7SAntonio Huete Jimenez ND_PRINT(" SMB-over-TCP packet:(raw data or continuation?)\n");
1252ea7b4bf5SPeter Avalos return;
1253ea7b4bf5SPeter Avalos trunc:
1254*ed775ee7SAntonio Huete Jimenez nd_print_trunc(ndo);
1255ea7b4bf5SPeter Avalos }
125641c99275SPeter Avalos
125741c99275SPeter Avalos /*
125841c99275SPeter Avalos * print a NBT packet received across udp on port 138
125941c99275SPeter Avalos */
126041c99275SPeter Avalos void
nbt_udp138_print(netdissect_options * ndo,const u_char * data,u_int length)1261411677aeSAaron LI nbt_udp138_print(netdissect_options *ndo,
1262*ed775ee7SAntonio Huete Jimenez const u_char *data, u_int length)
126341c99275SPeter Avalos {
126441c99275SPeter Avalos const u_char *maxbuf = data + length;
126541c99275SPeter Avalos
1266*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "nbt_udp138";
1267411677aeSAaron LI if (maxbuf > ndo->ndo_snapend)
1268411677aeSAaron LI maxbuf = ndo->ndo_snapend;
126941c99275SPeter Avalos if (maxbuf <= data)
127041c99275SPeter Avalos return;
127141c99275SPeter Avalos startbuf = data;
127241c99275SPeter Avalos
1273411677aeSAaron LI if (ndo->ndo_vflag < 2) {
1274*ed775ee7SAntonio Huete Jimenez ND_PRINT("NBT UDP PACKET(138)");
127541c99275SPeter Avalos return;
127641c99275SPeter Avalos }
127741c99275SPeter Avalos
1278411677aeSAaron LI data = smb_fdata(ndo, data,
1279*ed775ee7SAntonio Huete Jimenez "\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[ru] Length=[ru] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",
128041c99275SPeter Avalos maxbuf, 0);
128141c99275SPeter Avalos
128241c99275SPeter Avalos if (data != NULL) {
128341c99275SPeter Avalos /* If there isn't enough data for "\377SMB", don't check for it. */
1284*ed775ee7SAntonio Huete Jimenez if ((data + 3) >= maxbuf)
128541c99275SPeter Avalos goto out;
128641c99275SPeter Avalos
128741c99275SPeter Avalos if (memcmp(data, "\377SMB",4) == 0)
1288411677aeSAaron LI print_smb(ndo, data, maxbuf);
128941c99275SPeter Avalos }
129041c99275SPeter Avalos out:
1291*ed775ee7SAntonio Huete Jimenez return;
129241c99275SPeter Avalos }
129341c99275SPeter Avalos
129441c99275SPeter Avalos
129541c99275SPeter Avalos /*
129641c99275SPeter Avalos print netbeui frames
129741c99275SPeter Avalos */
1298411677aeSAaron LI static struct nbf_strings {
129941c99275SPeter Avalos const char *name;
130041c99275SPeter Avalos const char *nonverbose;
130141c99275SPeter Avalos const char *verbose;
130241c99275SPeter Avalos } nbf_strings[0x20] = {
130341c99275SPeter Avalos { "Add Group Name Query", ", [P23]Name to add=[n2]#",
130441c99275SPeter Avalos "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
130541c99275SPeter Avalos { "Add Name Query", ", [P23]Name to add=[n2]#",
130641c99275SPeter Avalos "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
130741c99275SPeter Avalos { "Name In Conflict", NULL, NULL },
130841c99275SPeter Avalos { "Status Query", NULL, NULL },
130941c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
131041c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
131141c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
131241c99275SPeter Avalos { "Terminate Trace", NULL, NULL },
131341c99275SPeter Avalos { "Datagram", NULL,
131441c99275SPeter Avalos "[P7]Destination=[n2]\nSource=[n2]\n" },
131541c99275SPeter Avalos { "Broadcast Datagram", NULL,
131641c99275SPeter Avalos "[P7]Destination=[n2]\nSource=[n2]\n" },
131741c99275SPeter Avalos { "Name Query", ", [P7]Name=[n2]#",
131841c99275SPeter Avalos "[P1]SessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nName=[n2]\nName of sender=[n2]\n" },
131941c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
132041c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
132141c99275SPeter Avalos { "Add Name Response", ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#",
132241c99275SPeter Avalos "AddNameInProcess=[B]\nGroupName=[w]\nTransmitCorrelator=[w][P2]\nDestination=[n2]\nSource=[n2]\n" },
132341c99275SPeter Avalos { "Name Recognized", NULL,
132441c99275SPeter Avalos "[P1]Data2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n" },
132541c99275SPeter Avalos { "Status Response", NULL, NULL },
132641c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
132741c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
132841c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
132941c99275SPeter Avalos { "Terminate Trace", NULL, NULL },
133041c99275SPeter Avalos { "Data Ack", NULL,
133141c99275SPeter Avalos "[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
133241c99275SPeter Avalos { "Data First/Middle", NULL,
133341c99275SPeter Avalos "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
133441c99275SPeter Avalos { "Data Only/Last", NULL,
133541c99275SPeter Avalos "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
133641c99275SPeter Avalos { "Session Confirm", NULL,
133741c99275SPeter Avalos "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
133841c99275SPeter Avalos { "Session End", NULL,
133941c99275SPeter Avalos "[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
134041c99275SPeter Avalos { "Session Initialize", NULL,
134141c99275SPeter Avalos "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
134241c99275SPeter Avalos { "No Receive", NULL,
134341c99275SPeter Avalos "Flags=[{|SEND_NO_ACK}]\nDataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
134441c99275SPeter Avalos { "Receive Outstanding", NULL,
134541c99275SPeter Avalos "[P1]DataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
134641c99275SPeter Avalos { "Receive Continue", NULL,
134741c99275SPeter Avalos "[P2]TransmitCorrelator=[w]\n[P2]RemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
134841c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
134941c99275SPeter Avalos { NULL, NULL, NULL }, /* not used */
135041c99275SPeter Avalos { "Session Alive", NULL, NULL }
135141c99275SPeter Avalos };
135241c99275SPeter Avalos
135341c99275SPeter Avalos void
netbeui_print(netdissect_options * ndo,u_short control,const u_char * data,u_int length)1354411677aeSAaron LI netbeui_print(netdissect_options *ndo,
1355*ed775ee7SAntonio Huete Jimenez u_short control, const u_char *data, u_int length)
135641c99275SPeter Avalos {
135741c99275SPeter Avalos const u_char *maxbuf = data + length;
1358*ed775ee7SAntonio Huete Jimenez u_int len;
1359*ed775ee7SAntonio Huete Jimenez u_int command;
136041c99275SPeter Avalos const u_char *data2;
136141c99275SPeter Avalos int is_truncated = 0;
136241c99275SPeter Avalos
1363*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "netbeui";
1364411677aeSAaron LI if (maxbuf > ndo->ndo_snapend)
1365411677aeSAaron LI maxbuf = ndo->ndo_snapend;
1366*ed775ee7SAntonio Huete Jimenez len = GET_LE_U_2(data);
1367*ed775ee7SAntonio Huete Jimenez command = GET_U_1(data + 4);
136841c99275SPeter Avalos data2 = data + len;
136941c99275SPeter Avalos if (data2 >= maxbuf) {
137041c99275SPeter Avalos data2 = maxbuf;
137141c99275SPeter Avalos is_truncated = 1;
137241c99275SPeter Avalos }
137341c99275SPeter Avalos
137441c99275SPeter Avalos startbuf = data;
137541c99275SPeter Avalos
1376411677aeSAaron LI if (ndo->ndo_vflag < 2) {
1377*ed775ee7SAntonio Huete Jimenez ND_PRINT("NBF Packet: ");
1378411677aeSAaron LI data = smb_fdata(ndo, data, "[P5]#", maxbuf, 0);
137941c99275SPeter Avalos } else {
1380*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n>>> NBF Packet\nType=0x%X ", control);
1381*ed775ee7SAntonio Huete Jimenez data = smb_fdata(ndo, data, "Length=[u] Signature=[w] Command=[B]\n#", maxbuf, 0);
138241c99275SPeter Avalos }
138341c99275SPeter Avalos if (data == NULL)
138441c99275SPeter Avalos goto out;
138541c99275SPeter Avalos
138641c99275SPeter Avalos if (command > 0x1f || nbf_strings[command].name == NULL) {
1387411677aeSAaron LI if (ndo->ndo_vflag < 2)
1388411677aeSAaron LI data = smb_fdata(ndo, data, "Unknown NBF Command#", data2, 0);
138941c99275SPeter Avalos else
1390411677aeSAaron LI data = smb_fdata(ndo, data, "Unknown NBF Command\n", data2, 0);
139141c99275SPeter Avalos } else {
1392411677aeSAaron LI if (ndo->ndo_vflag < 2) {
1393*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s", nbf_strings[command].name);
139441c99275SPeter Avalos if (nbf_strings[command].nonverbose != NULL)
1395411677aeSAaron LI data = smb_fdata(ndo, data, nbf_strings[command].nonverbose, data2, 0);
139641c99275SPeter Avalos } else {
1397*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s:\n", nbf_strings[command].name);
139841c99275SPeter Avalos if (nbf_strings[command].verbose != NULL)
1399411677aeSAaron LI data = smb_fdata(ndo, data, nbf_strings[command].verbose, data2, 0);
140041c99275SPeter Avalos else
1401*ed775ee7SAntonio Huete Jimenez ND_PRINT("\n");
140241c99275SPeter Avalos }
140341c99275SPeter Avalos }
140441c99275SPeter Avalos
1405411677aeSAaron LI if (ndo->ndo_vflag < 2)
140641c99275SPeter Avalos return;
140741c99275SPeter Avalos
140841c99275SPeter Avalos if (data == NULL)
140941c99275SPeter Avalos goto out;
141041c99275SPeter Avalos
141141c99275SPeter Avalos if (is_truncated) {
141241c99275SPeter Avalos /* data2 was past the end of the buffer */
141341c99275SPeter Avalos goto out;
141441c99275SPeter Avalos }
141541c99275SPeter Avalos
141641c99275SPeter Avalos /* If this isn't a command that would contain an SMB message, quit. */
141741c99275SPeter Avalos if (command != 0x08 && command != 0x09 && command != 0x15 &&
141841c99275SPeter Avalos command != 0x16)
141941c99275SPeter Avalos goto out;
142041c99275SPeter Avalos
142141c99275SPeter Avalos /* If there isn't enough data for "\377SMB", don't look for it. */
1422*ed775ee7SAntonio Huete Jimenez if ((data2 + 3) >= maxbuf)
142341c99275SPeter Avalos goto out;
142441c99275SPeter Avalos
142541c99275SPeter Avalos if (memcmp(data2, "\377SMB",4) == 0)
1426411677aeSAaron LI print_smb(ndo, data2, maxbuf);
142741c99275SPeter Avalos else {
1428*ed775ee7SAntonio Huete Jimenez u_int i;
142941c99275SPeter Avalos for (i = 0; i < 128; i++) {
1430*ed775ee7SAntonio Huete Jimenez if ((data2 + i + 3) >= maxbuf)
143141c99275SPeter Avalos break;
1432*ed775ee7SAntonio Huete Jimenez if (memcmp(data2 + i, "\377SMB", 4) == 0) {
1433*ed775ee7SAntonio Huete Jimenez ND_PRINT("found SMB packet at %u\n", i);
1434*ed775ee7SAntonio Huete Jimenez print_smb(ndo, data2 + i, maxbuf);
143541c99275SPeter Avalos break;
143641c99275SPeter Avalos }
143741c99275SPeter Avalos }
143841c99275SPeter Avalos }
143941c99275SPeter Avalos
144041c99275SPeter Avalos out:
144141c99275SPeter Avalos return;
144241c99275SPeter Avalos }
144341c99275SPeter Avalos
144441c99275SPeter Avalos
144541c99275SPeter Avalos /*
144641c99275SPeter Avalos * print IPX-Netbios frames
144741c99275SPeter Avalos */
144841c99275SPeter Avalos void
ipx_netbios_print(netdissect_options * ndo,const u_char * data,u_int length)1449411677aeSAaron LI ipx_netbios_print(netdissect_options *ndo,
1450411677aeSAaron LI const u_char *data, u_int length)
145141c99275SPeter Avalos {
145241c99275SPeter Avalos /*
145341c99275SPeter Avalos * this is a hack till I work out how to parse the rest of the
145441c99275SPeter Avalos * NetBIOS-over-IPX stuff
145541c99275SPeter Avalos */
1456*ed775ee7SAntonio Huete Jimenez u_int i;
145741c99275SPeter Avalos const u_char *maxbuf;
145841c99275SPeter Avalos
1459*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "ipx_netbios";
146041c99275SPeter Avalos maxbuf = data + length;
146141c99275SPeter Avalos /* Don't go past the end of the captured data in the packet. */
1462411677aeSAaron LI if (maxbuf > ndo->ndo_snapend)
1463411677aeSAaron LI maxbuf = ndo->ndo_snapend;
146441c99275SPeter Avalos startbuf = data;
146541c99275SPeter Avalos for (i = 0; i < 128; i++) {
1466*ed775ee7SAntonio Huete Jimenez if ((data + i + 4) > maxbuf)
146741c99275SPeter Avalos break;
1468*ed775ee7SAntonio Huete Jimenez if (memcmp(data + i, "\377SMB", 4) == 0) {
1469*ed775ee7SAntonio Huete Jimenez smb_fdata(ndo, data, "\n>>> IPX transport ", data + i, 0);
1470*ed775ee7SAntonio Huete Jimenez print_smb(ndo, data + i, maxbuf);
147141c99275SPeter Avalos break;
147241c99275SPeter Avalos }
147341c99275SPeter Avalos }
147441c99275SPeter Avalos if (i == 128)
1475411677aeSAaron LI smb_fdata(ndo, data, "\n>>> Unknown IPX ", maxbuf, 0);
147641c99275SPeter Avalos }
1477