blob: bcd7363dec955c22a7cb42db4ee8bdd2d26f7fb0 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (C) Andrew Tridgell 1995-1999
3 *
4 * This software may be distributed either under the terms of the
5 * BSD-style license that accompanies tcpdump or the GNU GPL version 2
6 * or later
7 */
8
Elliott Hughese2e3bd12017-05-15 10:59:29 -07009/* \summary: SMB/CIFS printer */
10
The Android Open Source Project2949f582009-03-03 19:30:46 -080011#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070012#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080013#endif
14
Elliott Hughes820eced2021-08-20 18:00:50 -070015#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080016
The Android Open Source Project2949f582009-03-03 19:30:46 -080017#include <string.h>
18
Elliott Hughese2e3bd12017-05-15 10:59:29 -070019#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080020#include "extract.h"
21#include "smb.h"
22
Elliott Hughes892a68b2015-10-19 14:43:53 -070023
The Android Open Source Project2949f582009-03-03 19:30:46 -080024static int request = 0;
25static int unicodestr = 0;
26
Elliott Hughes820eced2021-08-20 18:00:50 -070027extern const u_char *startbuf;
28
The Android Open Source Project2949f582009-03-03 19:30:46 -080029const u_char *startbuf = NULL;
30
31struct smbdescript {
32 const char *req_f1;
33 const char *req_f2;
34 const char *rep_f1;
35 const char *rep_f2;
Elliott Hughes892a68b2015-10-19 14:43:53 -070036 void (*fn)(netdissect_options *, const u_char *, const u_char *, const u_char *, const u_char *);
The Android Open Source Project2949f582009-03-03 19:30:46 -080037};
38
39struct smbdescriptint {
40 const char *req_f1;
41 const char *req_f2;
42 const char *rep_f1;
43 const char *rep_f2;
Elliott Hughes820eced2021-08-20 18:00:50 -070044 void (*fn)(netdissect_options *, const u_char *, const u_char *, u_int, u_int);
The Android Open Source Project2949f582009-03-03 19:30:46 -080045};
46
47struct smbfns
48{
49 int id;
50 const char *name;
51 int flags;
52 struct smbdescript descript;
53};
54
55struct smbfnsint
56{
57 int id;
58 const char *name;
59 int flags;
60 struct smbdescriptint descript;
61};
62
63#define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL }
64
65#define FLG_CHAIN (1 << 0)
66
Elliott Hughes892a68b2015-10-19 14:43:53 -070067static const struct smbfns *
68smbfind(int id, const struct smbfns *list)
The Android Open Source Project2949f582009-03-03 19:30:46 -080069{
70 int sindex;
71
72 for (sindex = 0; list[sindex].name; sindex++)
73 if (list[sindex].id == id)
74 return(&list[sindex]);
75
76 return(&list[0]);
77}
78
Elliott Hughes892a68b2015-10-19 14:43:53 -070079static const struct smbfnsint *
80smbfindint(int id, const struct smbfnsint *list)
The Android Open Source Project2949f582009-03-03 19:30:46 -080081{
82 int sindex;
83
84 for (sindex = 0; list[sindex].name; sindex++)
85 if (list[sindex].id == id)
86 return(&list[sindex]);
87
88 return(&list[0]);
89}
90
91static void
Elliott Hughes892a68b2015-10-19 14:43:53 -070092trans2_findfirst(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -070093 const u_char *param, const u_char *data, u_int pcnt, u_int dcnt)
The Android Open Source Project2949f582009-03-03 19:30:46 -080094{
95 const char *fmt;
96
97 if (request)
Elliott Hughes820eced2021-08-20 18:00:50 -070098 fmt = "Attribute=[A]\nSearchCount=[u]\nFlags=[w]\nLevel=[uP4]\nFile=[S]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -080099 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700100 fmt = "Handle=[w]\nCount=[u]\nEOS=[w]\nEoffset=[u]\nLastNameOfs=[w]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800101
Elliott Hughes892a68b2015-10-19 14:43:53 -0700102 smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800103 if (dcnt) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700104 ND_PRINT("data:\n");
105 smb_data_print(ndo, data, dcnt);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800106 }
107}
108
109static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700110trans2_qfsinfo(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700111 const u_char *param, const u_char *data, u_int pcnt, u_int dcnt)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800112{
Elliott Hughes820eced2021-08-20 18:00:50 -0700113 static u_int level = 0;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800114 const char *fmt="";
115
116 if (request) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700117 level = GET_LE_U_2(param);
118 fmt = "InfoLevel=[u]\n";
Elliott Hughes892a68b2015-10-19 14:43:53 -0700119 smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800120 } else {
121 switch (level) {
122 case 1:
Elliott Hughes820eced2021-08-20 18:00:50 -0700123 fmt = "idFileSystem=[W]\nSectorUnit=[U]\nUnit=[U]\nAvail=[U]\nSectorSize=[u]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800124 break;
125 case 2:
126 fmt = "CreationTime=[T2]VolNameLength=[lb]\nVolumeLabel=[c]\n";
127 break;
128 case 0x105:
Elliott Hughes820eced2021-08-20 18:00:50 -0700129 fmt = "Capabilities=[W]\nMaxFileLen=[U]\nVolNameLen=[lU]\nVolume=[C]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800130 break;
131 default:
132 fmt = "UnknownLevel\n";
133 break;
134 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700135 smb_fdata(ndo, data, fmt, data + dcnt, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800136 }
137 if (dcnt) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700138 ND_PRINT("data:\n");
139 smb_data_print(ndo, data, dcnt);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800140 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800141}
142
Elliott Hughes892a68b2015-10-19 14:43:53 -0700143static const struct smbfnsint trans2_fns[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800144 { 0, "TRANSACT2_OPEN", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700145 { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[U]\nRes=([w, w, w, w, w])\nPath=[S]",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800146 NULL,
Elliott Hughes820eced2021-08-20 18:00:50 -0700147 "Handle=[u]\nAttrib=[A]\nTime=[T2]\nSize=[U]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[u]\n|EALength=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800148 NULL, NULL }},
149 { 1, "TRANSACT2_FINDFIRST", 0,
150 { NULL, NULL, NULL, NULL, trans2_findfirst }},
151 { 2, "TRANSACT2_FINDNEXT", 0, DEFDESCRIPT },
152 { 3, "TRANSACT2_QFSINFO", 0,
153 { NULL, NULL, NULL, NULL, trans2_qfsinfo }},
154 { 4, "TRANSACT2_SETFSINFO", 0, DEFDESCRIPT },
155 { 5, "TRANSACT2_QPATHINFO", 0, DEFDESCRIPT },
156 { 6, "TRANSACT2_SETPATHINFO", 0, DEFDESCRIPT },
157 { 7, "TRANSACT2_QFILEINFO", 0, DEFDESCRIPT },
158 { 8, "TRANSACT2_SETFILEINFO", 0, DEFDESCRIPT },
159 { 9, "TRANSACT2_FSCTL", 0, DEFDESCRIPT },
160 { 10, "TRANSACT2_IOCTL", 0, DEFDESCRIPT },
161 { 11, "TRANSACT2_FINDNOTIFYFIRST", 0, DEFDESCRIPT },
162 { 12, "TRANSACT2_FINDNOTIFYNEXT", 0, DEFDESCRIPT },
163 { 13, "TRANSACT2_MKDIR", 0, DEFDESCRIPT },
164 { -1, NULL, 0, DEFDESCRIPT }
165};
166
167
168static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700169print_trans2(netdissect_options *ndo,
170 const u_char *words, const u_char *dat, const u_char *buf, const u_char *maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800171{
172 u_int bcc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700173 static const struct smbfnsint *fn = &trans2_fns[0];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800174 const u_char *data, *param;
175 const u_char *w = words + 1;
176 const char *f1 = NULL, *f2 = NULL;
Elliott Hughes820eced2021-08-20 18:00:50 -0700177 u_int pcnt, dcnt;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800178
Elliott Hughes820eced2021-08-20 18:00:50 -0700179 ND_TCHECK_1(words);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800180 if (request) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700181 ND_TCHECK_2(w + (14 * 2));
182 pcnt = GET_LE_U_2(w + 9 * 2);
183 param = buf + GET_LE_U_2(w + 10 * 2);
184 dcnt = GET_LE_U_2(w + 11 * 2);
185 data = buf + GET_LE_U_2(w + 12 * 2);
186 fn = smbfindint(GET_LE_U_2(w + 14 * 2), trans2_fns);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800187 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700188 if (GET_U_1(words) == 0) {
189 ND_PRINT("%s\n", fn->name);
190 ND_PRINT("Trans2Interim\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800191 return;
192 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700193 ND_TCHECK_2(w + (7 * 2));
194 pcnt = GET_LE_U_2(w + 3 * 2);
195 param = buf + GET_LE_U_2(w + 4 * 2);
196 dcnt = GET_LE_U_2(w + 6 * 2);
197 data = buf + GET_LE_U_2(w + 7 * 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800198 }
199
Elliott Hughes820eced2021-08-20 18:00:50 -0700200 ND_PRINT("%s param_length=%u data_length=%u\n", fn->name, pcnt, dcnt);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800201
202 if (request) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700203 if (GET_U_1(words) == 8) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700204 smb_fdata(ndo, words + 1,
Elliott Hughes820eced2021-08-20 18:00:50 -0700205 "Trans2Secondary\nTotParam=[u]\nTotData=[u]\nParamCnt=[u]\nParamOff=[u]\nParamDisp=[u]\nDataCnt=[u]\nDataOff=[u]\nDataDisp=[u]\nHandle=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800206 maxbuf, unicodestr);
207 return;
208 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700209 smb_fdata(ndo, words + 1,
Elliott Hughes820eced2021-08-20 18:00:50 -0700210 "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800211 words + 1 + 14 * 2, unicodestr);
212 }
213 f1 = fn->descript.req_f1;
214 f2 = fn->descript.req_f2;
215 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700216 smb_fdata(ndo, words + 1,
Elliott Hughes820eced2021-08-20 18:00:50 -0700217 "TotParam=[u]\nTotData=[u]\nRes1=[w]\nParamCnt=[u]\nParamOff=[u]\nParamDisp[u]\nDataCnt=[u]\nDataOff=[u]\nDataDisp=[u]\nSetupCnt=[b][P1]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800218 words + 1 + 10 * 2, unicodestr);
219 f1 = fn->descript.rep_f1;
220 f2 = fn->descript.rep_f2;
221 }
222
Elliott Hughes820eced2021-08-20 18:00:50 -0700223 bcc = GET_LE_U_2(dat);
224 ND_PRINT("smb_bcc=%u\n", bcc);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800225 if (fn->descript.fn)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700226 (*fn->descript.fn)(ndo, param, data, pcnt, dcnt);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800227 else {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700228 smb_fdata(ndo, param, f1 ? f1 : "Parameters=\n", param + pcnt, unicodestr);
229 smb_fdata(ndo, data, f2 ? f2 : "Data=\n", data + dcnt, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800230 }
231 return;
232trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700233 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800234}
235
The Android Open Source Project2949f582009-03-03 19:30:46 -0800236static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700237print_browse(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700238 const u_char *param, u_int paramlen, const u_char *data, u_int datalen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800239{
240 const u_char *maxbuf = data + datalen;
Elliott Hughes820eced2021-08-20 18:00:50 -0700241 u_int command;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800242
Elliott Hughes820eced2021-08-20 18:00:50 -0700243 command = GET_U_1(data);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800244
Elliott Hughes892a68b2015-10-19 14:43:53 -0700245 smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800246
247 switch (command) {
248 case 0xF:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700249 data = smb_fdata(ndo, data,
Elliott Hughes820eced2021-08-20 18:00:50 -0700250 "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800251 maxbuf, unicodestr);
252 break;
253
254 case 0x1:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700255 data = smb_fdata(ndo, data,
Elliott Hughes820eced2021-08-20 18:00:50 -0700256 "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800257 maxbuf, unicodestr);
258 break;
259
260 case 0x2:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700261 data = smb_fdata(ndo, data,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800262 "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",
263 maxbuf, unicodestr);
264 break;
265
266 case 0xc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700267 data = smb_fdata(ndo, data,
Elliott Hughes820eced2021-08-20 18:00:50 -0700268 "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[u]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800269 maxbuf, unicodestr);
270 break;
271
272 case 0x8:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700273 data = smb_fdata(ndo, data,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800274 "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n",
275 maxbuf, unicodestr);
276 break;
277
278 case 0xb:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700279 data = smb_fdata(ndo, data,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800280 "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",
281 maxbuf, unicodestr);
282 break;
283
284 case 0x9:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700285 data = smb_fdata(ndo, data,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800286 "BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken=[W]\n",
287 maxbuf, unicodestr);
288 break;
289
290 case 0xa:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700291 data = smb_fdata(ndo, data,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800292 "BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken=[W]\n*Name=[S]\n",
293 maxbuf, unicodestr);
294 break;
295
296 case 0xd:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700297 data = smb_fdata(ndo, data,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800298 "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",
299 maxbuf, unicodestr);
300 break;
301
302 case 0xe:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700303 data = smb_fdata(ndo, data,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800304 "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf, unicodestr);
305 break;
306
307 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700308 data = smb_fdata(ndo, data, "Unknown Browser Frame ", maxbuf, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800309 break;
310 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800311}
312
313
314static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700315print_ipc(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700316 const u_char *param, u_int paramlen, const u_char *data, u_int datalen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800317{
318 if (paramlen)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700319 smb_fdata(ndo, param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800320 unicodestr);
321 if (datalen)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700322 smb_fdata(ndo, data, "IPC ", data + datalen, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800323}
324
325
326static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700327print_trans(netdissect_options *ndo,
328 const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800329{
330 u_int bcc;
331 const char *f1, *f2, *f3, *f4;
332 const u_char *data, *param;
333 const u_char *w = words + 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700334 u_int datalen, paramlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800335
336 if (request) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700337 ND_TCHECK_2(w + (12 * 2));
338 paramlen = GET_LE_U_2(w + 9 * 2);
339 param = buf + GET_LE_U_2(w + 10 * 2);
340 datalen = GET_LE_U_2(w + 11 * 2);
341 data = buf + GET_LE_U_2(w + 12 * 2);
342 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";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800343 f2 = "|Name=[S]\n";
344 f3 = "|Param ";
345 f4 = "|Data ";
346 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700347 ND_TCHECK_2(w + (7 * 2));
348 paramlen = GET_LE_U_2(w + 3 * 2);
349 param = buf + GET_LE_U_2(w + 4 * 2);
350 datalen = GET_LE_U_2(w + 6 * 2);
351 data = buf + GET_LE_U_2(w + 7 * 2);
352 f1 = "TotParamCnt=[u]\nTotDataCnt=[u]\nRes1=[u]\nParamCnt=[u]\nParamOff=[u]\nRes2=[u]\nDataCnt=[u]\nDataOff=[u]\nRes3=[u]\nLsetup=[u]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800353 f2 = "|Unknown ";
354 f3 = "|Param ";
355 f4 = "|Data ";
356 }
357
Elliott Hughes820eced2021-08-20 18:00:50 -0700358 smb_fdata(ndo, words + 1, f1,
359 ND_MIN(words + 1 + 2 * GET_U_1(words), maxbuf),
360 unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800361
Elliott Hughes820eced2021-08-20 18:00:50 -0700362 bcc = GET_LE_U_2(data1);
363 ND_PRINT("smb_bcc=%u\n", bcc);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800364 if (bcc > 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700365 smb_fdata(ndo, data1 + 2, f2, maxbuf - (paramlen + datalen), unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800366
Elliott Hughes820eced2021-08-20 18:00:50 -0700367#define MAILSLOT_BROWSE_STR "\\MAILSLOT\\BROWSE"
368 ND_TCHECK_LEN(data1 + 2, strlen(MAILSLOT_BROWSE_STR) + 1);
369 if (strcmp((const char *)(data1 + 2), MAILSLOT_BROWSE_STR) == 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700370 print_browse(ndo, param, paramlen, data, datalen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800371 return;
372 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700373#undef MAILSLOT_BROWSE_STR
The Android Open Source Project2949f582009-03-03 19:30:46 -0800374
Elliott Hughes820eced2021-08-20 18:00:50 -0700375#define PIPE_LANMAN_STR "\\PIPE\\LANMAN"
376 ND_TCHECK_LEN(data1 + 2, strlen(PIPE_LANMAN_STR) + 1);
377 if (strcmp((const char *)(data1 + 2), PIPE_LANMAN_STR) == 0) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700378 print_ipc(ndo, param, paramlen, data, datalen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800379 return;
380 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700381#undef PIPE_LANMAN_STR
The Android Open Source Project2949f582009-03-03 19:30:46 -0800382
383 if (paramlen)
Elliott Hughes820eced2021-08-20 18:00:50 -0700384 smb_fdata(ndo, param, f3, ND_MIN(param + paramlen, maxbuf), unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800385 if (datalen)
Elliott Hughes820eced2021-08-20 18:00:50 -0700386 smb_fdata(ndo, data, f4, ND_MIN(data + datalen, maxbuf), unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800387 }
388 return;
389trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700390 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800391}
392
393
394static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700395print_negprot(netdissect_options *ndo,
396 const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800397{
398 u_int wct, bcc;
399 const char *f1 = NULL, *f2 = NULL;
400
Elliott Hughes820eced2021-08-20 18:00:50 -0700401 wct = GET_U_1(words);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800402 if (request)
403 f2 = "*|Dialect=[Y]\n";
404 else {
405 if (wct == 1)
Elliott Hughes820eced2021-08-20 18:00:50 -0700406 f1 = "Core Protocol\nDialectIndex=[u]";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800407 else if (wct == 17)
Elliott Hughes820eced2021-08-20 18:00:50 -0700408 f1 = "NT1 Protocol\nDialectIndex=[u]\nSecMode=[B]\nMaxMux=[u]\nNumVcs=[u]\nMaxBuffer=[U]\nRawSize=[U]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[u]\nCryptKey=";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800409 else if (wct == 13)
Elliott Hughes820eced2021-08-20 18:00:50 -0700410 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=";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800411 }
412
413 if (f1)
Elliott Hughes820eced2021-08-20 18:00:50 -0700414 smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800415 unicodestr);
416 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700417 smb_data_print(ndo, words + 1, ND_MIN(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800418
Elliott Hughes820eced2021-08-20 18:00:50 -0700419 bcc = GET_LE_U_2(data);
420 ND_PRINT("smb_bcc=%u\n", bcc);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800421 if (bcc > 0) {
422 if (f2)
Elliott Hughes820eced2021-08-20 18:00:50 -0700423 smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data),
424 maxbuf), unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800425 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700426 smb_data_print(ndo, data + 2,
427 ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800428 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800429}
430
431static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700432print_sesssetup(netdissect_options *ndo,
433 const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800434{
435 u_int wct, bcc;
436 const char *f1 = NULL, *f2 = NULL;
437
Elliott Hughes820eced2021-08-20 18:00:50 -0700438 wct = GET_U_1(words);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800439 if (request) {
440 if (wct == 10)
Elliott Hughes820eced2021-08-20 18:00:50 -0700441 f1 = "Com2=[w]\nOff2=[u]\nBufSize=[u]\nMpxMax=[u]\nVcNum=[u]\nSessionKey=[W]\nPassLen=[u]\nCryptLen=[u]\nCryptOff=[u]\nPass&Name=\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800442 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700443 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";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800444 } else {
445 if (wct == 3) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700446 f1 = "Com2=[w]\nOff2=[u]\nAction=[w]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800447 } else if (wct == 13) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700448 f1 = "Com2=[B]\nRes=[B]\nOff2=[u]\nAction=[w]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800449 f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n";
450 }
451 }
452
453 if (f1)
Elliott Hughes820eced2021-08-20 18:00:50 -0700454 smb_fdata(ndo, words + 1, f1, ND_MIN(words + 1 + wct * 2, maxbuf),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800455 unicodestr);
456 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700457 smb_data_print(ndo, words + 1, ND_MIN(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800458
Elliott Hughes820eced2021-08-20 18:00:50 -0700459 bcc = GET_LE_U_2(data);
460 ND_PRINT("smb_bcc=%u\n", bcc);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800461 if (bcc > 0) {
462 if (f2)
Elliott Hughes820eced2021-08-20 18:00:50 -0700463 smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data),
464 maxbuf), unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800465 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700466 smb_data_print(ndo, data + 2,
467 ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800468 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800469}
470
471static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700472print_lockingandx(netdissect_options *ndo,
473 const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800474{
475 u_int wct, bcc;
476 const u_char *maxwords;
477 const char *f1 = NULL, *f2 = NULL;
478
Elliott Hughes820eced2021-08-20 18:00:50 -0700479 wct = GET_U_1(words);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800480 if (request) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700481 f1 = "Com2=[w]\nOff2=[u]\nHandle=[u]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[u]\nLockCount=[u]\n";
482 if (GET_U_1(words + 7) & 0x10)
483 f2 = "*Process=[u]\n[P2]Offset=[M]\nLength=[M]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800484 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700485 f2 = "*Process=[u]\nOffset=[D]\nLength=[U]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800486 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700487 f1 = "Com2=[w]\nOff2=[u]\n";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800488 }
489
Elliott Hughes820eced2021-08-20 18:00:50 -0700490 maxwords = ND_MIN(words + 1 + wct * 2, maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800491 if (wct)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700492 smb_fdata(ndo, words + 1, f1, maxwords, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800493
Elliott Hughes820eced2021-08-20 18:00:50 -0700494 bcc = GET_LE_U_2(data);
495 ND_PRINT("smb_bcc=%u\n", bcc);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800496 if (bcc > 0) {
497 if (f2)
Elliott Hughes820eced2021-08-20 18:00:50 -0700498 smb_fdata(ndo, data + 2, f2, ND_MIN(data + 2 + GET_LE_U_2(data),
499 maxbuf), unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800500 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700501 smb_data_print(ndo, data + 2,
502 ND_MIN(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800503 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800504}
505
506
Elliott Hughes892a68b2015-10-19 14:43:53 -0700507static const struct smbfns smb_fns[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800508 { -1, "SMBunknown", 0, DEFDESCRIPT },
509
510 { SMBtcon, "SMBtcon", 0,
511 { NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n",
Elliott Hughes820eced2021-08-20 18:00:50 -0700512 "MaxXmit=[u]\nTreeId=[u]\n", NULL,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800513 NULL } },
514
515 { SMBtdis, "SMBtdis", 0, DEFDESCRIPT },
516 { SMBexit, "SMBexit", 0, DEFDESCRIPT },
517 { SMBioctl, "SMBioctl", 0, DEFDESCRIPT },
518
519 { SMBecho, "SMBecho", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700520 { "ReverbCount=[u]\n", NULL,
521 "SequenceNum=[u]\n", NULL,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800522 NULL } },
523
524 { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT },
525
526 { SMBgetatr, "SMBgetatr", 0,
527 { NULL, "Path=[Z]\n",
Elliott Hughes820eced2021-08-20 18:00:50 -0700528 "Attribute=[A]\nTime=[T2]Size=[U]\nRes=([w,w,w,w,w])\n", NULL,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800529 NULL } },
530
531 { SMBsetatr, "SMBsetatr", 0,
532 { "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n",
533 NULL, NULL, NULL } },
534
535 { SMBchkpth, "SMBchkpth", 0,
536 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
537
538 { SMBsearch, "SMBsearch", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700539 { "Count=[u]\nAttrib=[A]\n",
540 "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\nRes2=[W]\n",
541 "Count=[u]\n",
542 "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800543 NULL } },
544
545 { SMBopen, "SMBopen", 0,
546 { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n",
Elliott Hughes820eced2021-08-20 18:00:50 -0700547 "Handle=[u]\nOAttrib=[A]\nTime=[T2]Size=[U]\nAccess=[w]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800548 NULL, NULL } },
549
550 { SMBcreate, "SMBcreate", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700551 { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800552
553 { SMBmknew, "SMBmknew", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700554 { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800555
556 { SMBunlink, "SMBunlink", 0,
557 { "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } },
558
559 { SMBread, "SMBread", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700560 { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
561 "Count=[u]\nRes=([w,w,w,w])\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800562
563 { SMBwrite, "SMBwrite", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700564 { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
565 "Count=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800566
567 { SMBclose, "SMBclose", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700568 { "Handle=[u]\nTime=[T2]", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800569
570 { SMBmkdir, "SMBmkdir", 0,
571 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
572
573 { SMBrmdir, "SMBrmdir", 0,
574 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
575
576 { SMBdskattr, "SMBdskattr", 0,
577 { NULL, NULL,
Elliott Hughes820eced2021-08-20 18:00:50 -0700578 "TotalUnits=[u]\nBlocksPerUnit=[u]\nBlockSize=[u]\nFreeUnits=[u]\nMedia=[w]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800579 NULL, NULL } },
580
581 { SMBmv, "SMBmv", 0,
582 { "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } },
583
584 /*
585 * this is a Pathworks specific call, allowing the
586 * changing of the root path
587 */
588 { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
589
590 { SMBlseek, "SMBlseek", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700591 { "Handle=[u]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800592
Elliott Hughes820eced2021-08-20 18:00:50 -0700593 { SMBflush, "SMBflush", 0, { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800594
595 { SMBsplopen, "SMBsplopen", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700596 { "SetupLen=[u]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800597 NULL, NULL } },
598
599 { SMBsplclose, "SMBsplclose", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700600 { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800601
602 { SMBsplretq, "SMBsplretq", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700603 { "MaxCount=[u]\nStartIndex=[u]\n", NULL,
604 "Count=[u]\nIndex=[u]\n",
605 "*Time=[T2]Status=[B]\nJobID=[u]\nSize=[U]\nRes=[B]Name=[s16]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800606 NULL } },
607
608 { SMBsplwr, "SMBsplwr", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700609 { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800610
611 { SMBlock, "SMBlock", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700612 { "Handle=[u]\nCount=[U]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800613
614 { SMBunlock, "SMBunlock", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700615 { "Handle=[u]\nCount=[U]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800616
617 /* CORE+ PROTOCOL FOLLOWS */
618
619 { SMBreadbraw, "SMBreadbraw", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700620 { "Handle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nRes=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800621 NULL, NULL, NULL, NULL } },
622
623 { SMBwritebraw, "SMBwritebraw", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700624 { "Handle=[u]\nTotalCount=[u]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[u]\nDataOff=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800625 NULL, "WriteRawAck", NULL, NULL } },
626
627 { SMBwritec, "SMBwritec", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700628 { NULL, NULL, "Count=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800629
630 { SMBwriteclose, "SMBwriteclose", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700631 { "Handle=[u]\nCount=[u]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
632 NULL, "Count=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800633
634 { SMBlockread, "SMBlockread", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700635 { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
636 "Count=[u]\nRes=([w,w,w,w])\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800637
638 { SMBwriteunlock, "SMBwriteunlock", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700639 { "Handle=[u]\nByteCount=[u]\nOffset=[D]\nCountLeft=[u]\n", NULL,
640 "Count=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800641
642 { SMBreadBmpx, "SMBreadBmpx", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700643 { "Handle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nRes=[w]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800644 NULL,
Elliott Hughes820eced2021-08-20 18:00:50 -0700645 "Offset=[D]\nTotCount=[u]\nRemaining=[u]\nRes=([w,w])\nDataSize=[u]\nDataOff=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800646 NULL, NULL } },
647
648 { SMBwriteBmpx, "SMBwriteBmpx", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700649 { "Handle=[u]\nTotCount=[u]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[u]\nDataOff=[u]\n", NULL,
650 "Remaining=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800651
652 { SMBwriteBs, "SMBwriteBs", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700653 { "Handle=[u]\nTotCount=[u]\nOffset=[D]\nRes=[W]\nDataSize=[u]\nDataOff=[u]\n",
654 NULL, "Count=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800655
656 { SMBsetattrE, "SMBsetattrE", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700657 { "Handle=[u]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800658 NULL, NULL, NULL } },
659
660 { SMBgetattrE, "SMBgetattrE", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700661 { "Handle=[u]\n", NULL,
662 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[U]\nAllocSize=[U]\nAttribute=[A]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800663 NULL, NULL } },
664
665 { SMBtranss, "SMBtranss", 0, DEFDESCRIPT },
666 { SMBioctls, "SMBioctls", 0, DEFDESCRIPT },
667
668 { SMBcopy, "SMBcopy", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700669 { "TreeID2=[u]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
670 "CopyCount=[u]\n", "|ErrStr=[S]\n", NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800671
672 { SMBmove, "SMBmove", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700673 { "TreeID2=[u]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
674 "MoveCount=[u]\n", "|ErrStr=[S]\n", NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800675
676 { SMBopenX, "SMBopenX", FLG_CHAIN,
Elliott Hughes820eced2021-08-20 18:00:50 -0700677 { "Com2=[w]\nOff2=[u]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[U]\nTimeOut=[D]\nRes=[W]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800678 "Path=[S]\n",
Elliott Hughes820eced2021-08-20 18:00:50 -0700679 "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800680 NULL, NULL } },
681
682 { SMBreadX, "SMBreadX", FLG_CHAIN,
Elliott Hughes820eced2021-08-20 18:00:50 -0700683 { "Com2=[w]\nOff2=[u]\nHandle=[u]\nOffset=[D]\nMaxCount=[u]\nMinCount=[u]\nTimeOut=[D]\nCountLeft=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800684 NULL,
Elliott Hughes820eced2021-08-20 18:00:50 -0700685 "Com2=[w]\nOff2=[u]\nRemaining=[u]\nRes=[W]\nDataSize=[u]\nDataOff=[u]\nRes=([w,w,w,w])\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800686 NULL, NULL } },
687
688 { SMBwriteX, "SMBwriteX", FLG_CHAIN,
Elliott Hughes820eced2021-08-20 18:00:50 -0700689 { "Com2=[w]\nOff2=[u]\nHandle=[u]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[u]\nRes=[w]\nDataSize=[u]\nDataOff=[u]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800690 NULL,
Elliott Hughes820eced2021-08-20 18:00:50 -0700691 "Com2=[w]\nOff2=[u]\nCount=[u]\nRemaining=[u]\nRes=[W]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800692 NULL, NULL } },
693
694 { SMBffirst, "SMBffirst", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700695 { "Count=[u]\nAttrib=[A]\n",
696 "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
697 "Count=[u]\n",
698 "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800699 NULL } },
700
701 { SMBfunique, "SMBfunique", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700702 { "Count=[u]\nAttrib=[A]\n",
703 "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
704 "Count=[u]\n",
705 "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800706 NULL } },
707
708 { SMBfclose, "SMBfclose", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700709 { "Count=[u]\nAttrib=[A]\n",
710 "Path=[Z]\nBlkType=[B]\nBlkLen=[u]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[u]\nSrv2=[w]\n",
711 "Count=[u]\n",
712 "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800713 NULL } },
714
715 { SMBfindnclose, "SMBfindnclose", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700716 { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800717
718 { SMBfindclose, "SMBfindclose", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700719 { "Handle=[u]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800720
721 { SMBsends, "SMBsends", 0,
722 { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
723
724 { SMBsendstrt, "SMBsendstrt", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700725 { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[u]\n", NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800726
727 { SMBsendend, "SMBsendend", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700728 { "GroupID=[u]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800729
730 { SMBsendtxt, "SMBsendtxt", 0,
Elliott Hughes820eced2021-08-20 18:00:50 -0700731 { "GroupID=[u]\n", NULL, NULL, NULL, NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800732
733 { SMBsendb, "SMBsendb", 0,
734 { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
735
736 { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT },
737 { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT },
738 { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT },
739
740 { SMBnegprot, "SMBnegprot", 0,
741 { NULL, NULL, NULL, NULL, print_negprot } },
742
743 { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN,
744 { NULL, NULL, NULL, NULL, print_sesssetup } },
745
746 { SMBtconX, "SMBtconX", FLG_CHAIN,
Elliott Hughes820eced2021-08-20 18:00:50 -0700747 { "Com2=[w]\nOff2=[u]\nFlags=[w]\nPassLen=[u]\nPasswd&Path&Device=\n",
748 NULL, "Com2=[w]\nOff2=[u]\n", "ServiceType=[R]\n", NULL } },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800749
750 { SMBlockingX, "SMBlockingX", FLG_CHAIN,
751 { NULL, NULL, NULL, NULL, print_lockingandx } },
752
753 { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } },
754
755 { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT },
756 { SMBctemp, "SMBctemp", 0, DEFDESCRIPT },
757 { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT },
758 { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } },
759
760 { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT },
761 { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
762
763 { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
Elliott Hughes820eced2021-08-20 18:00:50 -0700764 { "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800765 "Path=[C]\n",
Elliott Hughes820eced2021-08-20 18:00:50 -0700766 "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",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800767 NULL, NULL } },
768
769 { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT },
770
771 { -1, NULL, 0, DEFDESCRIPT }
772};
773
774
775/*
776 * print a SMB message
777 */
778static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700779print_smb(netdissect_options *ndo,
780 const u_char *buf, const u_char *maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800781{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700782 uint16_t flags2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700783 u_int nterrcodes;
784 u_int command;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700785 uint32_t nterror;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800786 const u_char *words, *maxwords, *data;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700787 const struct smbfns *fn;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800788 const char *fmt_smbheader =
Elliott Hughes820eced2021-08-20 18:00:50 -0700789 "[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 u_int smboffset;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800791
Elliott Hughes820eced2021-08-20 18:00:50 -0700792 ndo->ndo_protocol = "smb";
793
794 request = (GET_U_1(buf + 9) & 0x80) ? 0 : 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800795 startbuf = buf;
796
Elliott Hughes820eced2021-08-20 18:00:50 -0700797 command = GET_U_1(buf + 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800798
799 fn = smbfind(command, smb_fns);
800
Elliott Hughes892a68b2015-10-19 14:43:53 -0700801 if (ndo->ndo_vflag > 1)
Elliott Hughes820eced2021-08-20 18:00:50 -0700802 ND_PRINT("\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800803
Elliott Hughes820eced2021-08-20 18:00:50 -0700804 ND_PRINT("SMB PACKET: %s (%s)", fn->name, request ? "REQUEST" : "REPLY");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800805
Elliott Hughes892a68b2015-10-19 14:43:53 -0700806 if (ndo->ndo_vflag < 2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800807 return;
808
Elliott Hughes820eced2021-08-20 18:00:50 -0700809 ND_PRINT("\n");
810 flags2 = GET_LE_U_2(buf + 10);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700811 unicodestr = flags2 & 0x8000;
812 nterrcodes = flags2 & 0x4000;
813
The Android Open Source Project2949f582009-03-03 19:30:46 -0800814 /* print out the header */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700815 smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800816
817 if (nterrcodes) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700818 nterror = GET_LE_U_4(buf + 5);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800819 if (nterror)
Elliott Hughes820eced2021-08-20 18:00:50 -0700820 ND_PRINT("NTError = %s\n", nt_errstr(nterror));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800821 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700822 if (GET_U_1(buf + 5))
823 ND_PRINT("SMBError = %s\n", smb_errstr(GET_U_1(buf + 5),
824 GET_LE_U_2(buf + 7)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800825 }
826
827 smboffset = 32;
828
829 for (;;) {
830 const char *f1, *f2;
831 int wct;
832 u_int bcc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700833 u_int newsmboffset;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800834
835 words = buf + smboffset;
Elliott Hughes820eced2021-08-20 18:00:50 -0700836 wct = GET_U_1(words);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800837 data = words + 1 + wct * 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700838 maxwords = ND_MIN(data, maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800839
840 if (request) {
841 f1 = fn->descript.req_f1;
842 f2 = fn->descript.req_f2;
843 } else {
844 f1 = fn->descript.rep_f1;
845 f2 = fn->descript.rep_f2;
846 }
847
Elliott Hughes820eced2021-08-20 18:00:50 -0700848 smb_reset();
The Android Open Source Project2949f582009-03-03 19:30:46 -0800849 if (fn->descript.fn)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700850 (*fn->descript.fn)(ndo, words, data, buf, maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800851 else {
852 if (wct) {
853 if (f1)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700854 smb_fdata(ndo, words + 1, f1, words + 1 + wct * 2, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800855 else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700856 u_int i;
857 u_int v;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800858
Elliott Hughes820eced2021-08-20 18:00:50 -0700859 for (i = 0; words + 1 + 2 * i < maxwords; i++) {
860 v = GET_LE_U_2(words + 1 + 2 * i);
861 ND_PRINT("smb_vwv[%u]=%u (0x%X)\n", i, v, v);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800862 }
863 }
864 }
865
Elliott Hughes820eced2021-08-20 18:00:50 -0700866 bcc = GET_LE_U_2(data);
867 ND_PRINT("smb_bcc=%u\n", bcc);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800868 if (f2) {
869 if (bcc > 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700870 smb_fdata(ndo, data + 2, f2, data + 2 + bcc, unicodestr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800871 } else {
872 if (bcc > 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700873 ND_PRINT("smb_buf[]=\n");
874 smb_data_print(ndo, data + 2, ND_MIN(bcc, ND_BYTES_BETWEEN(maxbuf, data + 2)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800875 }
876 }
877 }
878
879 if ((fn->flags & FLG_CHAIN) == 0)
880 break;
881 if (wct == 0)
882 break;
Elliott Hughes820eced2021-08-20 18:00:50 -0700883 command = GET_U_1(words + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800884 if (command == 0xFF)
885 break;
Elliott Hughes820eced2021-08-20 18:00:50 -0700886 newsmboffset = GET_LE_U_2(words + 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800887
888 fn = smbfind(command, smb_fns);
889
Elliott Hughes820eced2021-08-20 18:00:50 -0700890 ND_PRINT("\nSMB PACKET: %s (%s) (CHAINED)\n",
891 fn->name, request ? "REQUEST" : "REPLY");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800892 if (newsmboffset <= smboffset) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700893 ND_PRINT("Bad andX offset: %u <= %u\n", newsmboffset, smboffset);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800894 break;
895 }
896 smboffset = newsmboffset;
897 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800898}
899
900
901/*
902 * print a NBT packet received across tcp on port 139
903 */
904void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700905nbt_tcp_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700906 const u_char *data, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800907{
Elliott Hughes820eced2021-08-20 18:00:50 -0700908 u_int caplen;
909 u_int type;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800910 u_int nbt_len;
911 const u_char *maxbuf;
912
Elliott Hughes820eced2021-08-20 18:00:50 -0700913 ndo->ndo_protocol = "nbt_tcp";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800914 if (length < 4)
915 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700916 if (ndo->ndo_snapend < data)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800917 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700918 caplen = ND_BYTES_AVAILABLE_AFTER(data);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800919 if (caplen < 4)
920 goto trunc;
921 maxbuf = data + caplen;
Elliott Hughes820eced2021-08-20 18:00:50 -0700922 type = GET_U_1(data);
923 nbt_len = GET_BE_U_2(data + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800924 length -= 4;
925 caplen -= 4;
926
927 startbuf = data;
928
Elliott Hughes892a68b2015-10-19 14:43:53 -0700929 if (ndo->ndo_vflag < 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700930 ND_PRINT(" NBT Session Packet: ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 switch (type) {
932 case 0x00:
Elliott Hughes820eced2021-08-20 18:00:50 -0700933 ND_PRINT("Session Message");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800934 break;
935
936 case 0x81:
Elliott Hughes820eced2021-08-20 18:00:50 -0700937 ND_PRINT("Session Request");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800938 break;
939
940 case 0x82:
Elliott Hughes820eced2021-08-20 18:00:50 -0700941 ND_PRINT("Session Granted");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800942 break;
943
944 case 0x83:
945 {
Elliott Hughes820eced2021-08-20 18:00:50 -0700946 u_int ecode;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800947
948 if (nbt_len < 4)
949 goto trunc;
950 if (length < 4)
951 goto trunc;
952 if (caplen < 4)
953 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700954 ecode = GET_U_1(data + 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800955
Elliott Hughes820eced2021-08-20 18:00:50 -0700956 ND_PRINT("Session Reject, ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800957 switch (ecode) {
958 case 0x80:
Elliott Hughes820eced2021-08-20 18:00:50 -0700959 ND_PRINT("Not listening on called name");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800960 break;
961 case 0x81:
Elliott Hughes820eced2021-08-20 18:00:50 -0700962 ND_PRINT("Not listening for calling name");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800963 break;
964 case 0x82:
Elliott Hughes820eced2021-08-20 18:00:50 -0700965 ND_PRINT("Called name not present");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800966 break;
967 case 0x83:
Elliott Hughes820eced2021-08-20 18:00:50 -0700968 ND_PRINT("Called name present, but insufficient resources");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800969 break;
970 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700971 ND_PRINT("Unspecified error 0x%X", ecode);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800972 break;
973 }
974 }
975 break;
976
977 case 0x85:
Elliott Hughes820eced2021-08-20 18:00:50 -0700978 ND_PRINT("Session Keepalive");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800979 break;
980
981 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700982 data = smb_fdata(ndo, data, "Unknown packet type [rB]", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800983 break;
984 }
985 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700986 ND_PRINT("\n>>> NBT Session Packet\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800987 switch (type) {
988 case 0x00:
Elliott Hughes820eced2021-08-20 18:00:50 -0700989 data = smb_fdata(ndo, data, "[P1]NBT Session Message\nFlags=[B]\nLength=[ru]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800990 data + 4, 0);
991 if (data == NULL)
992 break;
993 if (nbt_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700994 if (nbt_len > caplen) {
995 if (nbt_len > length)
996 ND_PRINT("WARNING: Packet is continued in later TCP segments\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800997 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700998 ND_PRINT("WARNING: Short packet. Try increasing the snap length by %u\n",
999 nbt_len - caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001000 }
Elliott Hughes892a68b2015-10-19 14:43:53 -07001001 print_smb(ndo, data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001002 } else
Elliott Hughes820eced2021-08-20 18:00:50 -07001003 ND_PRINT("Session packet:(raw data or continuation?)\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001004 break;
1005
1006 case 0x81:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001007 data = smb_fdata(ndo, data,
Elliott Hughes820eced2021-08-20 18:00:50 -07001008 "[P1]NBT Session Request\nFlags=[B]\nLength=[ru]\nDestination=[n1]\nSource=[n1]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001009 maxbuf, 0);
1010 break;
1011
1012 case 0x82:
Elliott Hughes820eced2021-08-20 18:00:50 -07001013 data = smb_fdata(ndo, data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[ru]\n", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001014 break;
1015
1016 case 0x83:
1017 {
1018 const u_char *origdata;
Elliott Hughes820eced2021-08-20 18:00:50 -07001019 u_int ecode;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001020
1021 origdata = data;
Elliott Hughes820eced2021-08-20 18:00:50 -07001022 data = smb_fdata(ndo, data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[ru]\nReason=[B]\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001023 maxbuf, 0);
1024 if (data == NULL)
1025 break;
1026 if (nbt_len >= 1 && caplen >= 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001027 ecode = GET_U_1(origdata + 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001028 switch (ecode) {
1029 case 0x80:
Elliott Hughes820eced2021-08-20 18:00:50 -07001030 ND_PRINT("Not listening on called name\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001031 break;
1032 case 0x81:
Elliott Hughes820eced2021-08-20 18:00:50 -07001033 ND_PRINT("Not listening for calling name\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001034 break;
1035 case 0x82:
Elliott Hughes820eced2021-08-20 18:00:50 -07001036 ND_PRINT("Called name not present\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001037 break;
1038 case 0x83:
Elliott Hughes820eced2021-08-20 18:00:50 -07001039 ND_PRINT("Called name present, but insufficient resources\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001040 break;
1041 default:
Elliott Hughes820eced2021-08-20 18:00:50 -07001042 ND_PRINT("Unspecified error 0x%X\n", ecode);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001043 break;
1044 }
1045 }
1046 }
1047 break;
1048
1049 case 0x85:
Elliott Hughes820eced2021-08-20 18:00:50 -07001050 data = smb_fdata(ndo, data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[ru]\n", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001051 break;
1052
1053 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -07001054 data = smb_fdata(ndo, data, "NBT - Unknown packet type\nType=[B]\n", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001055 break;
1056 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001057 }
1058 return;
1059trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001060 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001061}
1062
Elliott Hughes892a68b2015-10-19 14:43:53 -07001063static const struct tok opcode_str[] = {
1064 { 0, "QUERY" },
1065 { 5, "REGISTRATION" },
1066 { 6, "RELEASE" },
1067 { 7, "WACK" },
1068 { 8, "REFRESH(8)" },
1069 { 9, "REFRESH" },
1070 { 15, "MULTIHOMED REGISTRATION" },
1071 { 0, NULL }
1072};
The Android Open Source Project2949f582009-03-03 19:30:46 -08001073
1074/*
1075 * print a NBT packet received across udp on port 137
1076 */
1077void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001078nbt_udp137_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -07001079 const u_char *data, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001080{
1081 const u_char *maxbuf = data + length;
Elliott Hughes820eced2021-08-20 18:00:50 -07001082 u_int name_trn_id, response, opcode, nm_flags, rcode;
1083 u_int qdcount, ancount, nscount, arcount;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001084 const u_char *p;
Elliott Hughes820eced2021-08-20 18:00:50 -07001085 u_int total, i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001086
Elliott Hughes820eced2021-08-20 18:00:50 -07001087 ndo->ndo_protocol = "nbt_udp137";
1088 name_trn_id = GET_BE_U_2(data);
1089 response = (GET_U_1(data + 2) >> 7);
1090 opcode = (GET_U_1(data + 2) >> 3) & 0xF;
1091 nm_flags = ((GET_U_1(data + 2) & 0x7) << 4) + (GET_U_1(data + 3) >> 4);
1092 rcode = GET_U_1(data + 3) & 0xF;
1093 qdcount = GET_BE_U_2(data + 4);
1094 ancount = GET_BE_U_2(data + 6);
1095 nscount = GET_BE_U_2(data + 8);
1096 arcount = GET_BE_U_2(data + 10);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001097 startbuf = data;
1098
1099 if (maxbuf <= data)
1100 return;
1101
Elliott Hughes892a68b2015-10-19 14:43:53 -07001102 if (ndo->ndo_vflag > 1)
Elliott Hughes820eced2021-08-20 18:00:50 -07001103 ND_PRINT("\n>>> ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001104
Elliott Hughes820eced2021-08-20 18:00:50 -07001105 ND_PRINT("NBT UDP PACKET(137): %s", tok2str(opcode_str, "OPUNKNOWN", opcode));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001106 if (response) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001107 ND_PRINT("; %s", rcode ? "NEGATIVE" : "POSITIVE");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001108 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001109 ND_PRINT("; %s; %s", response ? "RESPONSE" : "REQUEST",
1110 (nm_flags & 1) ? "BROADCAST" : "UNICAST");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001111
Elliott Hughes892a68b2015-10-19 14:43:53 -07001112 if (ndo->ndo_vflag < 2)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001113 return;
1114
Elliott Hughes820eced2021-08-20 18:00:50 -07001115 ND_PRINT("\nTrnID=0x%X\nOpCode=%u\nNmFlags=0x%X\nRcode=%u\nQueryCount=%u\nAnswerCount=%u\nAuthorityCount=%u\nAddressRecCount=%u\n",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001116 name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount,
Elliott Hughes820eced2021-08-20 18:00:50 -07001117 arcount);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001118
1119 p = data + 12;
1120
1121 total = ancount + nscount + arcount;
1122
1123 if (qdcount > 100 || total > 100) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001124 ND_PRINT("Corrupt packet??\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001125 return;
1126 }
1127
1128 if (qdcount) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001129 ND_PRINT("QuestionRecords:\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001130 for (i = 0; i < qdcount; i++) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001131 p = smb_fdata(ndo, p,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001132 "|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",
1133 maxbuf, 0);
1134 if (p == NULL)
1135 goto out;
1136 }
1137 }
1138
1139 if (total) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001140 ND_PRINT("\nResourceRecords:\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001141 for (i = 0; i < total; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001142 u_int rdlen;
1143 u_int restype;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001144
Elliott Hughes892a68b2015-10-19 14:43:53 -07001145 p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001146 if (p == NULL)
1147 goto out;
Elliott Hughes820eced2021-08-20 18:00:50 -07001148 restype = GET_BE_U_2(p);
1149 p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rU]\n", p + 8, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001150 if (p == NULL)
1151 goto out;
Elliott Hughes820eced2021-08-20 18:00:50 -07001152 rdlen = GET_BE_U_2(p);
1153 ND_PRINT("ResourceLength=%u\nResourceData=\n", rdlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001154 p += 2;
1155 if (rdlen == 6) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001156 p = smb_fdata(ndo, p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001157 if (p == NULL)
1158 goto out;
1159 } else {
1160 if (restype == 0x21) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001161 u_int numnames;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001162
Elliott Hughes820eced2021-08-20 18:00:50 -07001163 numnames = GET_U_1(p);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001164 p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001165 if (p == NULL)
1166 goto out;
Elliott Hughes820eced2021-08-20 18:00:50 -07001167 while (numnames) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001168 p = smb_fdata(ndo, p, "Name=[n2]\t#", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001169 if (p == NULL)
1170 goto out;
Elliott Hughes820eced2021-08-20 18:00:50 -07001171 ND_TCHECK_1(p);
1172 if (p >= maxbuf)
1173 goto out;
1174 if (GET_U_1(p) & 0x80)
1175 ND_PRINT("<GROUP> ");
1176 switch (GET_U_1(p) & 0x60) {
1177 case 0x00: ND_PRINT("B "); break;
1178 case 0x20: ND_PRINT("P "); break;
1179 case 0x40: ND_PRINT("M "); break;
1180 case 0x60: ND_PRINT("_ "); break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001181 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001182 if (GET_U_1(p) & 0x10)
1183 ND_PRINT("<DEREGISTERING> ");
1184 if (GET_U_1(p) & 0x08)
1185 ND_PRINT("<CONFLICT> ");
1186 if (GET_U_1(p) & 0x04)
1187 ND_PRINT("<ACTIVE> ");
1188 if (GET_U_1(p) & 0x02)
1189 ND_PRINT("<PERMANENT> ");
1190 ND_PRINT("\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001191 p += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -07001192 numnames--;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001193 }
1194 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001195 if (p >= maxbuf)
1196 goto out;
1197 smb_data_print(ndo, p, ND_MIN(rdlen, length - ND_BYTES_BETWEEN(p, data)));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001198 p += rdlen;
1199 }
1200 }
1201 }
1202 }
1203
1204 if (p < maxbuf)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001205 smb_fdata(ndo, p, "AdditionalData:\n", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001206
1207out:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001208 return;
1209trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001210 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001211}
1212
JP Abgrall53f17a92014-02-12 14:02:41 -08001213/*
1214 * Print an SMB-over-TCP packet received across tcp on port 445
1215 */
1216void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001217smb_tcp_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -07001218 const u_char * data, u_int length)
JP Abgrall53f17a92014-02-12 14:02:41 -08001219{
Elliott Hughes820eced2021-08-20 18:00:50 -07001220 u_int caplen;
JP Abgrall53f17a92014-02-12 14:02:41 -08001221 u_int smb_len;
1222 const u_char *maxbuf;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001223
Elliott Hughes820eced2021-08-20 18:00:50 -07001224 ndo->ndo_protocol = "smb_tcp";
JP Abgrall53f17a92014-02-12 14:02:41 -08001225 if (length < 4)
1226 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -07001227 if (ndo->ndo_snapend < data)
JP Abgrall53f17a92014-02-12 14:02:41 -08001228 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001229 caplen = ND_BYTES_AVAILABLE_AFTER(data);
JP Abgrall53f17a92014-02-12 14:02:41 -08001230 if (caplen < 4)
1231 goto trunc;
1232 maxbuf = data + caplen;
Elliott Hughes820eced2021-08-20 18:00:50 -07001233 smb_len = GET_BE_U_3(data + 1);
JP Abgrall53f17a92014-02-12 14:02:41 -08001234 length -= 4;
1235 caplen -= 4;
1236
1237 startbuf = data;
1238 data += 4;
1239
1240 if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001241 if (smb_len > caplen) {
1242 if (smb_len > length)
1243 ND_PRINT(" WARNING: Packet is continued in later TCP segments\n");
JP Abgrall53f17a92014-02-12 14:02:41 -08001244 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001245 ND_PRINT(" WARNING: Short packet. Try increasing the snap length by %u\n",
1246 smb_len - caplen);
Elliott Hughes892a68b2015-10-19 14:43:53 -07001247 } else
Elliott Hughes820eced2021-08-20 18:00:50 -07001248 ND_PRINT(" ");
Elliott Hughes892a68b2015-10-19 14:43:53 -07001249 print_smb(ndo, data, maxbuf > data + smb_len ? data + smb_len : maxbuf);
JP Abgrall53f17a92014-02-12 14:02:41 -08001250 } else
Elliott Hughes820eced2021-08-20 18:00:50 -07001251 ND_PRINT(" SMB-over-TCP packet:(raw data or continuation?)\n");
JP Abgrall53f17a92014-02-12 14:02:41 -08001252 return;
1253trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001254 nd_print_trunc(ndo);
JP Abgrall53f17a92014-02-12 14:02:41 -08001255}
The Android Open Source Project2949f582009-03-03 19:30:46 -08001256
1257/*
1258 * print a NBT packet received across udp on port 138
1259 */
1260void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001261nbt_udp138_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -07001262 const u_char *data, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001263{
1264 const u_char *maxbuf = data + length;
1265
Elliott Hughes820eced2021-08-20 18:00:50 -07001266 ndo->ndo_protocol = "nbt_udp138";
Elliott Hughes892a68b2015-10-19 14:43:53 -07001267 if (maxbuf > ndo->ndo_snapend)
1268 maxbuf = ndo->ndo_snapend;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001269 if (maxbuf <= data)
1270 return;
1271 startbuf = data;
1272
Elliott Hughes892a68b2015-10-19 14:43:53 -07001273 if (ndo->ndo_vflag < 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001274 ND_PRINT("NBT UDP PACKET(138)");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001275 return;
1276 }
1277
Elliott Hughes892a68b2015-10-19 14:43:53 -07001278 data = smb_fdata(ndo, data,
Elliott Hughes820eced2021-08-20 18:00:50 -07001279 "\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#",
The Android Open Source Project2949f582009-03-03 19:30:46 -08001280 maxbuf, 0);
1281
1282 if (data != NULL) {
1283 /* If there isn't enough data for "\377SMB", don't check for it. */
Elliott Hughes820eced2021-08-20 18:00:50 -07001284 if ((data + 3) >= maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001285 goto out;
1286
1287 if (memcmp(data, "\377SMB",4) == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001288 print_smb(ndo, data, maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001289 }
1290out:
Elliott Hughes820eced2021-08-20 18:00:50 -07001291 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001292}
1293
1294
1295/*
1296 print netbeui frames
1297*/
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001298static struct nbf_strings {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001299 const char *name;
1300 const char *nonverbose;
1301 const char *verbose;
1302} nbf_strings[0x20] = {
1303 { "Add Group Name Query", ", [P23]Name to add=[n2]#",
1304 "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
1305 { "Add Name Query", ", [P23]Name to add=[n2]#",
1306 "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
1307 { "Name In Conflict", NULL, NULL },
1308 { "Status Query", NULL, NULL },
1309 { NULL, NULL, NULL }, /* not used */
1310 { NULL, NULL, NULL }, /* not used */
1311 { NULL, NULL, NULL }, /* not used */
1312 { "Terminate Trace", NULL, NULL },
1313 { "Datagram", NULL,
1314 "[P7]Destination=[n2]\nSource=[n2]\n" },
1315 { "Broadcast Datagram", NULL,
1316 "[P7]Destination=[n2]\nSource=[n2]\n" },
1317 { "Name Query", ", [P7]Name=[n2]#",
1318 "[P1]SessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nName=[n2]\nName of sender=[n2]\n" },
1319 { NULL, NULL, NULL }, /* not used */
1320 { NULL, NULL, NULL }, /* not used */
1321 { "Add Name Response", ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#",
1322 "AddNameInProcess=[B]\nGroupName=[w]\nTransmitCorrelator=[w][P2]\nDestination=[n2]\nSource=[n2]\n" },
1323 { "Name Recognized", NULL,
1324 "[P1]Data2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n" },
1325 { "Status Response", NULL, NULL },
1326 { NULL, NULL, NULL }, /* not used */
1327 { NULL, NULL, NULL }, /* not used */
1328 { NULL, NULL, NULL }, /* not used */
1329 { "Terminate Trace", NULL, NULL },
1330 { "Data Ack", NULL,
1331 "[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1332 { "Data First/Middle", NULL,
1333 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1334 { "Data Only/Last", NULL,
1335 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1336 { "Session Confirm", NULL,
1337 "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1338 { "Session End", NULL,
1339 "[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1340 { "Session Initialize", NULL,
1341 "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1342 { "No Receive", NULL,
1343 "Flags=[{|SEND_NO_ACK}]\nDataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1344 { "Receive Outstanding", NULL,
1345 "[P1]DataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1346 { "Receive Continue", NULL,
1347 "[P2]TransmitCorrelator=[w]\n[P2]RemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1348 { NULL, NULL, NULL }, /* not used */
1349 { NULL, NULL, NULL }, /* not used */
1350 { "Session Alive", NULL, NULL }
1351};
1352
1353void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001354netbeui_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -07001355 u_short control, const u_char *data, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001356{
1357 const u_char *maxbuf = data + length;
Elliott Hughes820eced2021-08-20 18:00:50 -07001358 u_int len;
1359 u_int command;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001360 const u_char *data2;
1361 int is_truncated = 0;
1362
Elliott Hughes820eced2021-08-20 18:00:50 -07001363 ndo->ndo_protocol = "netbeui";
Elliott Hughes892a68b2015-10-19 14:43:53 -07001364 if (maxbuf > ndo->ndo_snapend)
1365 maxbuf = ndo->ndo_snapend;
Elliott Hughes820eced2021-08-20 18:00:50 -07001366 len = GET_LE_U_2(data);
1367 command = GET_U_1(data + 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001368 data2 = data + len;
1369 if (data2 >= maxbuf) {
1370 data2 = maxbuf;
1371 is_truncated = 1;
1372 }
1373
1374 startbuf = data;
1375
Elliott Hughes892a68b2015-10-19 14:43:53 -07001376 if (ndo->ndo_vflag < 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001377 ND_PRINT("NBF Packet: ");
Elliott Hughes892a68b2015-10-19 14:43:53 -07001378 data = smb_fdata(ndo, data, "[P5]#", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001379 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001380 ND_PRINT("\n>>> NBF Packet\nType=0x%X ", control);
1381 data = smb_fdata(ndo, data, "Length=[u] Signature=[w] Command=[B]\n#", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001382 }
1383 if (data == NULL)
1384 goto out;
1385
1386 if (command > 0x1f || nbf_strings[command].name == NULL) {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001387 if (ndo->ndo_vflag < 2)
1388 data = smb_fdata(ndo, data, "Unknown NBF Command#", data2, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001389 else
Elliott Hughes892a68b2015-10-19 14:43:53 -07001390 data = smb_fdata(ndo, data, "Unknown NBF Command\n", data2, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001391 } else {
Elliott Hughes892a68b2015-10-19 14:43:53 -07001392 if (ndo->ndo_vflag < 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001393 ND_PRINT("%s", nbf_strings[command].name);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001394 if (nbf_strings[command].nonverbose != NULL)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001395 data = smb_fdata(ndo, data, nbf_strings[command].nonverbose, data2, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001396 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001397 ND_PRINT("%s:\n", nbf_strings[command].name);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001398 if (nbf_strings[command].verbose != NULL)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001399 data = smb_fdata(ndo, data, nbf_strings[command].verbose, data2, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001400 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001401 ND_PRINT("\n");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001402 }
1403 }
1404
Elliott Hughes892a68b2015-10-19 14:43:53 -07001405 if (ndo->ndo_vflag < 2)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001406 return;
1407
1408 if (data == NULL)
1409 goto out;
1410
1411 if (is_truncated) {
1412 /* data2 was past the end of the buffer */
1413 goto out;
1414 }
1415
1416 /* If this isn't a command that would contain an SMB message, quit. */
1417 if (command != 0x08 && command != 0x09 && command != 0x15 &&
1418 command != 0x16)
1419 goto out;
1420
1421 /* If there isn't enough data for "\377SMB", don't look for it. */
Elliott Hughes820eced2021-08-20 18:00:50 -07001422 if ((data2 + 3) >= maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001423 goto out;
1424
1425 if (memcmp(data2, "\377SMB",4) == 0)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001426 print_smb(ndo, data2, maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001427 else {
Elliott Hughes820eced2021-08-20 18:00:50 -07001428 u_int i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001429 for (i = 0; i < 128; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001430 if ((data2 + i + 3) >= maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001431 break;
Elliott Hughes820eced2021-08-20 18:00:50 -07001432 if (memcmp(data2 + i, "\377SMB", 4) == 0) {
1433 ND_PRINT("found SMB packet at %u\n", i);
1434 print_smb(ndo, data2 + i, maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001435 break;
1436 }
1437 }
1438 }
1439
1440out:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001441 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001442}
1443
1444
1445/*
1446 * print IPX-Netbios frames
1447 */
1448void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001449ipx_netbios_print(netdissect_options *ndo,
1450 const u_char *data, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001451{
1452 /*
1453 * this is a hack till I work out how to parse the rest of the
1454 * NetBIOS-over-IPX stuff
1455 */
Elliott Hughes820eced2021-08-20 18:00:50 -07001456 u_int i;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001457 const u_char *maxbuf;
1458
Elliott Hughes820eced2021-08-20 18:00:50 -07001459 ndo->ndo_protocol = "ipx_netbios";
The Android Open Source Project2949f582009-03-03 19:30:46 -08001460 maxbuf = data + length;
1461 /* Don't go past the end of the captured data in the packet. */
Elliott Hughes892a68b2015-10-19 14:43:53 -07001462 if (maxbuf > ndo->ndo_snapend)
1463 maxbuf = ndo->ndo_snapend;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001464 startbuf = data;
1465 for (i = 0; i < 128; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001466 if ((data + i + 4) > maxbuf)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001467 break;
Elliott Hughes820eced2021-08-20 18:00:50 -07001468 if (memcmp(data + i, "\377SMB", 4) == 0) {
1469 smb_fdata(ndo, data, "\n>>> IPX transport ", data + i, 0);
1470 print_smb(ndo, data + i, maxbuf);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001471 break;
1472 }
1473 }
1474 if (i == 128)
Elliott Hughes892a68b2015-10-19 14:43:53 -07001475 smb_fdata(ndo, data, "\n>>> Unknown IPX ", maxbuf, 0);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001476}