The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 9 | /* \summary: SMB/CIFS printer */ |
| 10 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 11 | #ifdef HAVE_CONFIG_H |
| 12 | #include "config.h" |
| 13 | #endif |
| 14 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 15 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 16 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 17 | #include <string.h> |
| 18 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 19 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 20 | #include "extract.h" |
| 21 | #include "smb.h" |
| 22 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 23 | static const char tstr[] = "[|SMB]"; |
| 24 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 25 | static int request = 0; |
| 26 | static int unicodestr = 0; |
| 27 | |
| 28 | const u_char *startbuf = NULL; |
| 29 | |
| 30 | struct smbdescript { |
| 31 | const char *req_f1; |
| 32 | const char *req_f2; |
| 33 | const char *rep_f1; |
| 34 | const char *rep_f2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 35 | void (*fn)(netdissect_options *, const u_char *, const u_char *, const u_char *, const u_char *); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct smbdescriptint { |
| 39 | const char *req_f1; |
| 40 | const char *req_f2; |
| 41 | const char *rep_f1; |
| 42 | const char *rep_f2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 43 | void (*fn)(netdissect_options *, const u_char *, const u_char *, int, int); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct smbfns |
| 47 | { |
| 48 | int id; |
| 49 | const char *name; |
| 50 | int flags; |
| 51 | struct smbdescript descript; |
| 52 | }; |
| 53 | |
| 54 | struct smbfnsint |
| 55 | { |
| 56 | int id; |
| 57 | const char *name; |
| 58 | int flags; |
| 59 | struct smbdescriptint descript; |
| 60 | }; |
| 61 | |
| 62 | #define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL } |
| 63 | |
| 64 | #define FLG_CHAIN (1 << 0) |
| 65 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 66 | static const struct smbfns * |
| 67 | smbfind(int id, const struct smbfns *list) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 68 | { |
| 69 | int sindex; |
| 70 | |
| 71 | for (sindex = 0; list[sindex].name; sindex++) |
| 72 | if (list[sindex].id == id) |
| 73 | return(&list[sindex]); |
| 74 | |
| 75 | return(&list[0]); |
| 76 | } |
| 77 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 78 | static const struct smbfnsint * |
| 79 | smbfindint(int id, const struct smbfnsint *list) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 80 | { |
| 81 | int sindex; |
| 82 | |
| 83 | for (sindex = 0; list[sindex].name; sindex++) |
| 84 | if (list[sindex].id == id) |
| 85 | return(&list[sindex]); |
| 86 | |
| 87 | return(&list[0]); |
| 88 | } |
| 89 | |
| 90 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 91 | trans2_findfirst(netdissect_options *ndo, |
| 92 | const u_char *param, const u_char *data, int pcnt, int dcnt) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 93 | { |
| 94 | const char *fmt; |
| 95 | |
| 96 | if (request) |
| 97 | fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP4]\nFile=[S]\n"; |
| 98 | else |
| 99 | fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n"; |
| 100 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 101 | smb_fdata(ndo, param, fmt, param + pcnt, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 102 | if (dcnt) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 103 | ND_PRINT((ndo, "data:\n")); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 104 | smb_print_data(ndo, data, dcnt); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 109 | trans2_qfsinfo(netdissect_options *ndo, |
| 110 | const u_char *param, const u_char *data, int pcnt, int dcnt) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 111 | { |
| 112 | static int level = 0; |
| 113 | const char *fmt=""; |
| 114 | |
| 115 | if (request) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 116 | ND_TCHECK2(*param, 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 117 | level = EXTRACT_LE_16BITS(param); |
| 118 | fmt = "InfoLevel=[d]\n"; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 119 | smb_fdata(ndo, param, fmt, param + pcnt, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 120 | } else { |
| 121 | switch (level) { |
| 122 | case 1: |
| 123 | fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n"; |
| 124 | break; |
| 125 | case 2: |
| 126 | fmt = "CreationTime=[T2]VolNameLength=[lb]\nVolumeLabel=[c]\n"; |
| 127 | break; |
| 128 | case 0x105: |
| 129 | fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[lD]\nVolume=[C]\n"; |
| 130 | break; |
| 131 | default: |
| 132 | fmt = "UnknownLevel\n"; |
| 133 | break; |
| 134 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 135 | smb_fdata(ndo, data, fmt, data + dcnt, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 136 | } |
| 137 | if (dcnt) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 138 | ND_PRINT((ndo, "data:\n")); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 139 | smb_print_data(ndo, data, dcnt); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 140 | } |
| 141 | return; |
| 142 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 143 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 146 | static const struct smbfnsint trans2_fns[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 147 | { 0, "TRANSACT2_OPEN", 0, |
| 148 | { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w, w, w, w, w])\nPath=[S]", |
| 149 | NULL, |
| 150 | "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n", |
| 151 | NULL, NULL }}, |
| 152 | { 1, "TRANSACT2_FINDFIRST", 0, |
| 153 | { NULL, NULL, NULL, NULL, trans2_findfirst }}, |
| 154 | { 2, "TRANSACT2_FINDNEXT", 0, DEFDESCRIPT }, |
| 155 | { 3, "TRANSACT2_QFSINFO", 0, |
| 156 | { NULL, NULL, NULL, NULL, trans2_qfsinfo }}, |
| 157 | { 4, "TRANSACT2_SETFSINFO", 0, DEFDESCRIPT }, |
| 158 | { 5, "TRANSACT2_QPATHINFO", 0, DEFDESCRIPT }, |
| 159 | { 6, "TRANSACT2_SETPATHINFO", 0, DEFDESCRIPT }, |
| 160 | { 7, "TRANSACT2_QFILEINFO", 0, DEFDESCRIPT }, |
| 161 | { 8, "TRANSACT2_SETFILEINFO", 0, DEFDESCRIPT }, |
| 162 | { 9, "TRANSACT2_FSCTL", 0, DEFDESCRIPT }, |
| 163 | { 10, "TRANSACT2_IOCTL", 0, DEFDESCRIPT }, |
| 164 | { 11, "TRANSACT2_FINDNOTIFYFIRST", 0, DEFDESCRIPT }, |
| 165 | { 12, "TRANSACT2_FINDNOTIFYNEXT", 0, DEFDESCRIPT }, |
| 166 | { 13, "TRANSACT2_MKDIR", 0, DEFDESCRIPT }, |
| 167 | { -1, NULL, 0, DEFDESCRIPT } |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 172 | print_trans2(netdissect_options *ndo, |
| 173 | const u_char *words, const u_char *dat, const u_char *buf, const u_char *maxbuf) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 174 | { |
| 175 | u_int bcc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 176 | static const struct smbfnsint *fn = &trans2_fns[0]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 177 | const u_char *data, *param; |
| 178 | const u_char *w = words + 1; |
| 179 | const char *f1 = NULL, *f2 = NULL; |
| 180 | int pcnt, dcnt; |
| 181 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 182 | ND_TCHECK(words[0]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 183 | if (request) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 184 | ND_TCHECK2(w[14 * 2], 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 185 | pcnt = EXTRACT_LE_16BITS(w + 9 * 2); |
| 186 | param = buf + EXTRACT_LE_16BITS(w + 10 * 2); |
| 187 | dcnt = EXTRACT_LE_16BITS(w + 11 * 2); |
| 188 | data = buf + EXTRACT_LE_16BITS(w + 12 * 2); |
| 189 | fn = smbfindint(EXTRACT_LE_16BITS(w + 14 * 2), trans2_fns); |
| 190 | } else { |
| 191 | if (words[0] == 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 192 | ND_PRINT((ndo, "%s\n", fn->name)); |
| 193 | ND_PRINT((ndo, "Trans2Interim\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 194 | return; |
| 195 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 196 | ND_TCHECK2(w[7 * 2], 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 197 | pcnt = EXTRACT_LE_16BITS(w + 3 * 2); |
| 198 | param = buf + EXTRACT_LE_16BITS(w + 4 * 2); |
| 199 | dcnt = EXTRACT_LE_16BITS(w + 6 * 2); |
| 200 | data = buf + EXTRACT_LE_16BITS(w + 7 * 2); |
| 201 | } |
| 202 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 203 | ND_PRINT((ndo, "%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 204 | |
| 205 | if (request) { |
| 206 | if (words[0] == 8) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 207 | smb_fdata(ndo, words + 1, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 208 | "Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n", |
| 209 | maxbuf, unicodestr); |
| 210 | return; |
| 211 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 212 | smb_fdata(ndo, words + 1, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 213 | "TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[b][P1]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[b][P1]\n", |
| 214 | words + 1 + 14 * 2, unicodestr); |
| 215 | } |
| 216 | f1 = fn->descript.req_f1; |
| 217 | f2 = fn->descript.req_f2; |
| 218 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 219 | smb_fdata(ndo, words + 1, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 220 | "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[b][P1]\n", |
| 221 | words + 1 + 10 * 2, unicodestr); |
| 222 | f1 = fn->descript.rep_f1; |
| 223 | f2 = fn->descript.rep_f2; |
| 224 | } |
| 225 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 226 | ND_TCHECK2(*dat, 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 227 | bcc = EXTRACT_LE_16BITS(dat); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 228 | ND_PRINT((ndo, "smb_bcc=%u\n", bcc)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 229 | if (fn->descript.fn) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 230 | (*fn->descript.fn)(ndo, param, data, pcnt, dcnt); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 231 | else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 232 | smb_fdata(ndo, param, f1 ? f1 : "Parameters=\n", param + pcnt, unicodestr); |
| 233 | smb_fdata(ndo, data, f2 ? f2 : "Data=\n", data + dcnt, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 234 | } |
| 235 | return; |
| 236 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 237 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 238 | } |
| 239 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 240 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 241 | print_browse(netdissect_options *ndo, |
| 242 | const u_char *param, int paramlen, const u_char *data, int datalen) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 243 | { |
| 244 | const u_char *maxbuf = data + datalen; |
| 245 | int command; |
| 246 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 247 | ND_TCHECK(data[0]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 248 | command = data[0]; |
| 249 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 250 | smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 251 | |
| 252 | switch (command) { |
| 253 | case 0xF: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 254 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 255 | "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n", |
| 256 | maxbuf, unicodestr); |
| 257 | break; |
| 258 | |
| 259 | case 0x1: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 260 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 261 | "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n", |
| 262 | maxbuf, unicodestr); |
| 263 | break; |
| 264 | |
| 265 | case 0x2: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 266 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 267 | "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n", |
| 268 | maxbuf, unicodestr); |
| 269 | break; |
| 270 | |
| 271 | case 0xc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 272 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 273 | "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n", |
| 274 | maxbuf, unicodestr); |
| 275 | break; |
| 276 | |
| 277 | case 0x8: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 278 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 279 | "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n", |
| 280 | maxbuf, unicodestr); |
| 281 | break; |
| 282 | |
| 283 | case 0xb: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 284 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 285 | "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n", |
| 286 | maxbuf, unicodestr); |
| 287 | break; |
| 288 | |
| 289 | case 0x9: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 290 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 291 | "BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken=[W]\n", |
| 292 | maxbuf, unicodestr); |
| 293 | break; |
| 294 | |
| 295 | case 0xa: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 296 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 297 | "BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken=[W]\n*Name=[S]\n", |
| 298 | maxbuf, unicodestr); |
| 299 | break; |
| 300 | |
| 301 | case 0xd: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 302 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 303 | "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n", |
| 304 | maxbuf, unicodestr); |
| 305 | break; |
| 306 | |
| 307 | case 0xe: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 308 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 309 | "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf, unicodestr); |
| 310 | break; |
| 311 | |
| 312 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 313 | data = smb_fdata(ndo, data, "Unknown Browser Frame ", maxbuf, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 314 | break; |
| 315 | } |
| 316 | return; |
| 317 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 318 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
| 322 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 323 | print_ipc(netdissect_options *ndo, |
| 324 | const u_char *param, int paramlen, const u_char *data, int datalen) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 325 | { |
| 326 | if (paramlen) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 327 | smb_fdata(ndo, param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 328 | unicodestr); |
| 329 | if (datalen) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 330 | smb_fdata(ndo, data, "IPC ", data + datalen, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
| 334 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 335 | print_trans(netdissect_options *ndo, |
| 336 | const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 337 | { |
| 338 | u_int bcc; |
| 339 | const char *f1, *f2, *f3, *f4; |
| 340 | const u_char *data, *param; |
| 341 | const u_char *w = words + 1; |
| 342 | int datalen, paramlen; |
| 343 | |
| 344 | if (request) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 345 | ND_TCHECK2(w[12 * 2], 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 346 | paramlen = EXTRACT_LE_16BITS(w + 9 * 2); |
| 347 | param = buf + EXTRACT_LE_16BITS(w + 10 * 2); |
| 348 | datalen = EXTRACT_LE_16BITS(w + 11 * 2); |
| 349 | data = buf + EXTRACT_LE_16BITS(w + 12 * 2); |
| 350 | f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n"; |
| 351 | f2 = "|Name=[S]\n"; |
| 352 | f3 = "|Param "; |
| 353 | f4 = "|Data "; |
| 354 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 355 | ND_TCHECK2(w[7 * 2], 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 356 | paramlen = EXTRACT_LE_16BITS(w + 3 * 2); |
| 357 | param = buf + EXTRACT_LE_16BITS(w + 4 * 2); |
| 358 | datalen = EXTRACT_LE_16BITS(w + 6 * 2); |
| 359 | data = buf + EXTRACT_LE_16BITS(w + 7 * 2); |
| 360 | f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n"; |
| 361 | f2 = "|Unknown "; |
| 362 | f3 = "|Param "; |
| 363 | f4 = "|Data "; |
| 364 | } |
| 365 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 366 | smb_fdata(ndo, words + 1, f1, min(words + 1 + 2 * words[0], maxbuf), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 367 | unicodestr); |
| 368 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 369 | ND_TCHECK2(*data1, 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 370 | bcc = EXTRACT_LE_16BITS(data1); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 371 | ND_PRINT((ndo, "smb_bcc=%u\n", bcc)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 372 | if (bcc > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 373 | smb_fdata(ndo, data1 + 2, f2, maxbuf - (paramlen + datalen), unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 374 | |
| 375 | if (strcmp((const char *)(data1 + 2), "\\MAILSLOT\\BROWSE") == 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 376 | print_browse(ndo, param, paramlen, data, datalen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 377 | return; |
| 378 | } |
| 379 | |
| 380 | if (strcmp((const char *)(data1 + 2), "\\PIPE\\LANMAN") == 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 381 | print_ipc(ndo, param, paramlen, data, datalen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 382 | return; |
| 383 | } |
| 384 | |
| 385 | if (paramlen) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 386 | smb_fdata(ndo, param, f3, min(param + paramlen, maxbuf), unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 387 | if (datalen) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 388 | smb_fdata(ndo, data, f4, min(data + datalen, maxbuf), unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 389 | } |
| 390 | return; |
| 391 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 392 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
| 396 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 397 | print_negprot(netdissect_options *ndo, |
| 398 | const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 399 | { |
| 400 | u_int wct, bcc; |
| 401 | const char *f1 = NULL, *f2 = NULL; |
| 402 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 403 | ND_TCHECK(words[0]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 404 | wct = words[0]; |
| 405 | if (request) |
| 406 | f2 = "*|Dialect=[Y]\n"; |
| 407 | else { |
| 408 | if (wct == 1) |
| 409 | f1 = "Core Protocol\nDialectIndex=[d]"; |
| 410 | else if (wct == 17) |
| 411 | f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey="; |
| 412 | else if (wct == 13) |
| 413 | f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey="; |
| 414 | } |
| 415 | |
| 416 | if (f1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 417 | smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 418 | unicodestr); |
| 419 | else |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 420 | smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 421 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 422 | ND_TCHECK2(*data, 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 423 | bcc = EXTRACT_LE_16BITS(data); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 424 | ND_PRINT((ndo, "smb_bcc=%u\n", bcc)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 425 | if (bcc > 0) { |
| 426 | if (f2) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 427 | smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 428 | maxbuf), unicodestr); |
| 429 | else |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 430 | smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 431 | } |
| 432 | return; |
| 433 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 434 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 438 | print_sesssetup(netdissect_options *ndo, |
| 439 | const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 440 | { |
| 441 | u_int wct, bcc; |
| 442 | const char *f1 = NULL, *f2 = NULL; |
| 443 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 444 | ND_TCHECK(words[0]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 445 | wct = words[0]; |
| 446 | if (request) { |
| 447 | if (wct == 10) |
| 448 | f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n"; |
| 449 | else |
| 450 | f1 = "Com2=[B]\nRes1=[B]\nOff2=[d]\nMaxBuffer=[d]\nMaxMpx=[d]\nVcNumber=[d]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[d]\nCaseSensitivePasswordLength=[d]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n"; |
| 451 | } else { |
| 452 | if (wct == 3) { |
| 453 | f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n"; |
| 454 | } else if (wct == 13) { |
| 455 | f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n"; |
| 456 | f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n"; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | if (f1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 461 | smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 462 | unicodestr); |
| 463 | else |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 464 | smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 465 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 466 | ND_TCHECK2(*data, 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 467 | bcc = EXTRACT_LE_16BITS(data); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 468 | ND_PRINT((ndo, "smb_bcc=%u\n", bcc)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 469 | if (bcc > 0) { |
| 470 | if (f2) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 471 | smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 472 | maxbuf), unicodestr); |
| 473 | else |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 474 | smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 475 | } |
| 476 | return; |
| 477 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 478 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 482 | print_lockingandx(netdissect_options *ndo, |
| 483 | const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 484 | { |
| 485 | u_int wct, bcc; |
| 486 | const u_char *maxwords; |
| 487 | const char *f1 = NULL, *f2 = NULL; |
| 488 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 489 | ND_TCHECK(words[0]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 490 | wct = words[0]; |
| 491 | if (request) { |
| 492 | f1 = "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n"; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 493 | ND_TCHECK(words[7]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 494 | if (words[7] & 0x10) |
| 495 | f2 = "*Process=[d]\n[P2]Offset=[M]\nLength=[M]\n"; |
| 496 | else |
| 497 | f2 = "*Process=[d]\nOffset=[D]\nLength=[D]\n"; |
| 498 | } else { |
| 499 | f1 = "Com2=[w]\nOff2=[d]\n"; |
| 500 | } |
| 501 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 502 | maxwords = min(words + 1 + wct * 2, maxbuf); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 503 | if (wct) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 504 | smb_fdata(ndo, words + 1, f1, maxwords, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 505 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 506 | ND_TCHECK2(*data, 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 507 | bcc = EXTRACT_LE_16BITS(data); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 508 | ND_PRINT((ndo, "smb_bcc=%u\n", bcc)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 509 | if (bcc > 0) { |
| 510 | if (f2) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 511 | smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data), |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 512 | maxbuf), unicodestr); |
| 513 | else |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 514 | smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 515 | } |
| 516 | return; |
| 517 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 518 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 522 | static const struct smbfns smb_fns[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 523 | { -1, "SMBunknown", 0, DEFDESCRIPT }, |
| 524 | |
| 525 | { SMBtcon, "SMBtcon", 0, |
| 526 | { NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n", |
| 527 | "MaxXmit=[d]\nTreeId=[d]\n", NULL, |
| 528 | NULL } }, |
| 529 | |
| 530 | { SMBtdis, "SMBtdis", 0, DEFDESCRIPT }, |
| 531 | { SMBexit, "SMBexit", 0, DEFDESCRIPT }, |
| 532 | { SMBioctl, "SMBioctl", 0, DEFDESCRIPT }, |
| 533 | |
| 534 | { SMBecho, "SMBecho", 0, |
| 535 | { "ReverbCount=[d]\n", NULL, |
| 536 | "SequenceNum=[d]\n", NULL, |
| 537 | NULL } }, |
| 538 | |
| 539 | { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT }, |
| 540 | |
| 541 | { SMBgetatr, "SMBgetatr", 0, |
| 542 | { NULL, "Path=[Z]\n", |
| 543 | "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL, |
| 544 | NULL } }, |
| 545 | |
| 546 | { SMBsetatr, "SMBsetatr", 0, |
| 547 | { "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n", |
| 548 | NULL, NULL, NULL } }, |
| 549 | |
| 550 | { SMBchkpth, "SMBchkpth", 0, |
| 551 | { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, |
| 552 | |
| 553 | { SMBsearch, "SMBsearch", 0, |
| 554 | { "Count=[d]\nAttrib=[A]\n", |
| 555 | "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n", |
| 556 | "Count=[d]\n", |
| 557 | "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", |
| 558 | NULL } }, |
| 559 | |
| 560 | { SMBopen, "SMBopen", 0, |
| 561 | { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n", |
| 562 | "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n", |
| 563 | NULL, NULL } }, |
| 564 | |
| 565 | { SMBcreate, "SMBcreate", 0, |
| 566 | { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } }, |
| 567 | |
| 568 | { SMBmknew, "SMBmknew", 0, |
| 569 | { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } }, |
| 570 | |
| 571 | { SMBunlink, "SMBunlink", 0, |
| 572 | { "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } }, |
| 573 | |
| 574 | { SMBread, "SMBread", 0, |
| 575 | { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, |
| 576 | "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } }, |
| 577 | |
| 578 | { SMBwrite, "SMBwrite", 0, |
| 579 | { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, |
| 580 | "Count=[d]\n", NULL, NULL } }, |
| 581 | |
| 582 | { SMBclose, "SMBclose", 0, |
| 583 | { "Handle=[d]\nTime=[T2]", NULL, NULL, NULL, NULL } }, |
| 584 | |
| 585 | { SMBmkdir, "SMBmkdir", 0, |
| 586 | { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, |
| 587 | |
| 588 | { SMBrmdir, "SMBrmdir", 0, |
| 589 | { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, |
| 590 | |
| 591 | { SMBdskattr, "SMBdskattr", 0, |
| 592 | { NULL, NULL, |
| 593 | "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n", |
| 594 | NULL, NULL } }, |
| 595 | |
| 596 | { SMBmv, "SMBmv", 0, |
| 597 | { "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } }, |
| 598 | |
| 599 | /* |
| 600 | * this is a Pathworks specific call, allowing the |
| 601 | * changing of the root path |
| 602 | */ |
| 603 | { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } }, |
| 604 | |
| 605 | { SMBlseek, "SMBlseek", 0, |
| 606 | { "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } }, |
| 607 | |
| 608 | { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, |
| 609 | |
| 610 | { SMBsplopen, "SMBsplopen", 0, |
| 611 | { "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n", |
| 612 | NULL, NULL } }, |
| 613 | |
| 614 | { SMBsplclose, "SMBsplclose", 0, |
| 615 | { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, |
| 616 | |
| 617 | { SMBsplretq, "SMBsplretq", 0, |
| 618 | { "MaxCount=[d]\nStartIndex=[d]\n", NULL, |
| 619 | "Count=[d]\nIndex=[d]\n", |
| 620 | "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n", |
| 621 | NULL } }, |
| 622 | |
| 623 | { SMBsplwr, "SMBsplwr", 0, |
| 624 | { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, |
| 625 | |
| 626 | { SMBlock, "SMBlock", 0, |
| 627 | { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } }, |
| 628 | |
| 629 | { SMBunlock, "SMBunlock", 0, |
| 630 | { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } }, |
| 631 | |
| 632 | /* CORE+ PROTOCOL FOLLOWS */ |
| 633 | |
| 634 | { SMBreadbraw, "SMBreadbraw", 0, |
| 635 | { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n", |
| 636 | NULL, NULL, NULL, NULL } }, |
| 637 | |
| 638 | { SMBwritebraw, "SMBwritebraw", 0, |
| 639 | { "Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n", |
| 640 | NULL, "WriteRawAck", NULL, NULL } }, |
| 641 | |
| 642 | { SMBwritec, "SMBwritec", 0, |
| 643 | { NULL, NULL, "Count=[d]\n", NULL, NULL } }, |
| 644 | |
| 645 | { SMBwriteclose, "SMBwriteclose", 0, |
| 646 | { "Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])", |
| 647 | NULL, "Count=[d]\n", NULL, NULL } }, |
| 648 | |
| 649 | { SMBlockread, "SMBlockread", 0, |
| 650 | { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, |
| 651 | "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } }, |
| 652 | |
| 653 | { SMBwriteunlock, "SMBwriteunlock", 0, |
| 654 | { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL, |
| 655 | "Count=[d]\n", NULL, NULL } }, |
| 656 | |
| 657 | { SMBreadBmpx, "SMBreadBmpx", 0, |
| 658 | { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n", |
| 659 | NULL, |
| 660 | "Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n", |
| 661 | NULL, NULL } }, |
| 662 | |
| 663 | { SMBwriteBmpx, "SMBwriteBmpx", 0, |
| 664 | { "Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n", NULL, |
| 665 | "Remaining=[d]\n", NULL, NULL } }, |
| 666 | |
| 667 | { SMBwriteBs, "SMBwriteBs", 0, |
| 668 | { "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n", |
| 669 | NULL, "Count=[d]\n", NULL, NULL } }, |
| 670 | |
| 671 | { SMBsetattrE, "SMBsetattrE", 0, |
| 672 | { "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL, |
| 673 | NULL, NULL, NULL } }, |
| 674 | |
| 675 | { SMBgetattrE, "SMBgetattrE", 0, |
| 676 | { "Handle=[d]\n", NULL, |
| 677 | "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n", |
| 678 | NULL, NULL } }, |
| 679 | |
| 680 | { SMBtranss, "SMBtranss", 0, DEFDESCRIPT }, |
| 681 | { SMBioctls, "SMBioctls", 0, DEFDESCRIPT }, |
| 682 | |
| 683 | { SMBcopy, "SMBcopy", 0, |
| 684 | { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n", |
| 685 | "CopyCount=[d]\n", "|ErrStr=[S]\n", NULL } }, |
| 686 | |
| 687 | { SMBmove, "SMBmove", 0, |
| 688 | { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n", |
| 689 | "MoveCount=[d]\n", "|ErrStr=[S]\n", NULL } }, |
| 690 | |
| 691 | { SMBopenX, "SMBopenX", FLG_CHAIN, |
| 692 | { "Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n", |
| 693 | "Path=[S]\n", |
| 694 | "Com2=[w]\nOff2=[d]\nHandle=[d]\nAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n", |
| 695 | NULL, NULL } }, |
| 696 | |
| 697 | { SMBreadX, "SMBreadX", FLG_CHAIN, |
| 698 | { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n", |
| 699 | NULL, |
| 700 | "Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n", |
| 701 | NULL, NULL } }, |
| 702 | |
| 703 | { SMBwriteX, "SMBwriteX", FLG_CHAIN, |
| 704 | { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n", |
| 705 | NULL, |
| 706 | "Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n", |
| 707 | NULL, NULL } }, |
| 708 | |
| 709 | { SMBffirst, "SMBffirst", 0, |
| 710 | { "Count=[d]\nAttrib=[A]\n", |
| 711 | "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", |
| 712 | "Count=[d]\n", |
| 713 | "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", |
| 714 | NULL } }, |
| 715 | |
| 716 | { SMBfunique, "SMBfunique", 0, |
| 717 | { "Count=[d]\nAttrib=[A]\n", |
| 718 | "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", |
| 719 | "Count=[d]\n", |
| 720 | "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", |
| 721 | NULL } }, |
| 722 | |
| 723 | { SMBfclose, "SMBfclose", 0, |
| 724 | { "Count=[d]\nAttrib=[A]\n", |
| 725 | "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", |
| 726 | "Count=[d]\n", |
| 727 | "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n", |
| 728 | NULL } }, |
| 729 | |
| 730 | { SMBfindnclose, "SMBfindnclose", 0, |
| 731 | { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, |
| 732 | |
| 733 | { SMBfindclose, "SMBfindclose", 0, |
| 734 | { "Handle=[d]\n", NULL, NULL, NULL, NULL } }, |
| 735 | |
| 736 | { SMBsends, "SMBsends", 0, |
| 737 | { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } }, |
| 738 | |
| 739 | { SMBsendstrt, "SMBsendstrt", 0, |
| 740 | { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[d]\n", NULL, NULL } }, |
| 741 | |
| 742 | { SMBsendend, "SMBsendend", 0, |
| 743 | { "GroupID=[d]\n", NULL, NULL, NULL, NULL } }, |
| 744 | |
| 745 | { SMBsendtxt, "SMBsendtxt", 0, |
| 746 | { "GroupID=[d]\n", NULL, NULL, NULL, NULL } }, |
| 747 | |
| 748 | { SMBsendb, "SMBsendb", 0, |
| 749 | { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } }, |
| 750 | |
| 751 | { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT }, |
| 752 | { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT }, |
| 753 | { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT }, |
| 754 | |
| 755 | { SMBnegprot, "SMBnegprot", 0, |
| 756 | { NULL, NULL, NULL, NULL, print_negprot } }, |
| 757 | |
| 758 | { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN, |
| 759 | { NULL, NULL, NULL, NULL, print_sesssetup } }, |
| 760 | |
| 761 | { SMBtconX, "SMBtconX", FLG_CHAIN, |
| 762 | { "Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n", |
| 763 | NULL, "Com2=[w]\nOff2=[d]\n", "ServiceType=[R]\n", NULL } }, |
| 764 | |
| 765 | { SMBlockingX, "SMBlockingX", FLG_CHAIN, |
| 766 | { NULL, NULL, NULL, NULL, print_lockingandx } }, |
| 767 | |
| 768 | { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } }, |
| 769 | |
| 770 | { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT }, |
| 771 | { SMBctemp, "SMBctemp", 0, DEFDESCRIPT }, |
| 772 | { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT }, |
| 773 | { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } }, |
| 774 | |
| 775 | { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT }, |
| 776 | { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT }, |
| 777 | |
| 778 | { SMBntcreateX, "SMBntcreateX", FLG_CHAIN, |
| 779 | { "Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[ld]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n", |
| 780 | "Path=[C]\n", |
| 781 | "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n", |
| 782 | NULL, NULL } }, |
| 783 | |
| 784 | { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT }, |
| 785 | |
| 786 | { -1, NULL, 0, DEFDESCRIPT } |
| 787 | }; |
| 788 | |
| 789 | |
| 790 | /* |
| 791 | * print a SMB message |
| 792 | */ |
| 793 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 794 | print_smb(netdissect_options *ndo, |
| 795 | const u_char *buf, const u_char *maxbuf) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 796 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 797 | uint16_t flags2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 798 | int nterrcodes; |
| 799 | int command; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 800 | uint32_t nterror; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 801 | const u_char *words, *maxwords, *data; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 802 | const struct smbfns *fn; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 803 | const char *fmt_smbheader = |
| 804 | "[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n"; |
| 805 | int smboffset; |
| 806 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 807 | ND_TCHECK(buf[9]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 808 | request = (buf[9] & 0x80) ? 0 : 1; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 809 | startbuf = buf; |
| 810 | |
| 811 | command = buf[4]; |
| 812 | |
| 813 | fn = smbfind(command, smb_fns); |
| 814 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 815 | if (ndo->ndo_vflag > 1) |
| 816 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 817 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 818 | ND_PRINT((ndo, "SMB PACKET: %s (%s)\n", fn->name, request ? "REQUEST" : "REPLY")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 819 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 820 | if (ndo->ndo_vflag < 2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 821 | return; |
| 822 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 823 | ND_TCHECK_16BITS(&buf[10]); |
| 824 | flags2 = EXTRACT_LE_16BITS(&buf[10]); |
| 825 | unicodestr = flags2 & 0x8000; |
| 826 | nterrcodes = flags2 & 0x4000; |
| 827 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 828 | /* print out the header */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 829 | smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 830 | |
| 831 | if (nterrcodes) { |
| 832 | nterror = EXTRACT_LE_32BITS(&buf[5]); |
| 833 | if (nterror) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 834 | ND_PRINT((ndo, "NTError = %s\n", nt_errstr(nterror))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 835 | } else { |
| 836 | if (buf[5]) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 837 | ND_PRINT((ndo, "SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(&buf[7])))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | smboffset = 32; |
| 841 | |
| 842 | for (;;) { |
| 843 | const char *f1, *f2; |
| 844 | int wct; |
| 845 | u_int bcc; |
| 846 | int newsmboffset; |
| 847 | |
| 848 | words = buf + smboffset; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 849 | ND_TCHECK(words[0]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 850 | wct = words[0]; |
| 851 | data = words + 1 + wct * 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 852 | maxwords = min(data, maxbuf); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 853 | |
| 854 | if (request) { |
| 855 | f1 = fn->descript.req_f1; |
| 856 | f2 = fn->descript.req_f2; |
| 857 | } else { |
| 858 | f1 = fn->descript.rep_f1; |
| 859 | f2 = fn->descript.rep_f2; |
| 860 | } |
| 861 | |
| 862 | if (fn->descript.fn) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 863 | (*fn->descript.fn)(ndo, words, data, buf, maxbuf); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 864 | else { |
| 865 | if (wct) { |
| 866 | if (f1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 867 | smb_fdata(ndo, words + 1, f1, words + 1 + wct * 2, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 868 | else { |
| 869 | int i; |
| 870 | int v; |
| 871 | |
| 872 | for (i = 0; &words[1 + 2 * i] < maxwords; i++) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 873 | ND_TCHECK2(words[1 + 2 * i], 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 874 | v = EXTRACT_LE_16BITS(words + 1 + 2 * i); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 875 | ND_PRINT((ndo, "smb_vwv[%d]=%d (0x%X)\n", i, v, v)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 876 | } |
| 877 | } |
| 878 | } |
| 879 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 880 | ND_TCHECK2(*data, 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 881 | bcc = EXTRACT_LE_16BITS(data); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 882 | ND_PRINT((ndo, "smb_bcc=%u\n", bcc)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 883 | if (f2) { |
| 884 | if (bcc > 0) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 885 | smb_fdata(ndo, data + 2, f2, data + 2 + bcc, unicodestr); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 886 | } else { |
| 887 | if (bcc > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 888 | ND_PRINT((ndo, "smb_buf[]=\n")); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 889 | smb_print_data(ndo, data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | if ((fn->flags & FLG_CHAIN) == 0) |
| 895 | break; |
| 896 | if (wct == 0) |
| 897 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 898 | ND_TCHECK(words[1]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 899 | command = words[1]; |
| 900 | if (command == 0xFF) |
| 901 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 902 | ND_TCHECK2(words[3], 2); |
| 903 | newsmboffset = EXTRACT_LE_16BITS(words + 3); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 904 | |
| 905 | fn = smbfind(command, smb_fns); |
| 906 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 907 | ND_PRINT((ndo, "\nSMB PACKET: %s (%s) (CHAINED)\n", |
| 908 | fn->name, request ? "REQUEST" : "REPLY")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 909 | if (newsmboffset <= smboffset) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 910 | ND_PRINT((ndo, "Bad andX offset: %u <= %u\n", newsmboffset, smboffset)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 911 | break; |
| 912 | } |
| 913 | smboffset = newsmboffset; |
| 914 | } |
| 915 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 916 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 917 | return; |
| 918 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 919 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | |
| 923 | /* |
| 924 | * print a NBT packet received across tcp on port 139 |
| 925 | */ |
| 926 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 927 | nbt_tcp_print(netdissect_options *ndo, |
| 928 | const u_char *data, int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 929 | { |
| 930 | int caplen; |
| 931 | int type; |
| 932 | u_int nbt_len; |
| 933 | const u_char *maxbuf; |
| 934 | |
| 935 | if (length < 4) |
| 936 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 937 | if (ndo->ndo_snapend < data) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 938 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 939 | caplen = ndo->ndo_snapend - data; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 940 | if (caplen < 4) |
| 941 | goto trunc; |
| 942 | maxbuf = data + caplen; |
| 943 | type = data[0]; |
| 944 | nbt_len = EXTRACT_16BITS(data + 2); |
| 945 | length -= 4; |
| 946 | caplen -= 4; |
| 947 | |
| 948 | startbuf = data; |
| 949 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 950 | if (ndo->ndo_vflag < 2) { |
| 951 | ND_PRINT((ndo, " NBT Session Packet: ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 952 | switch (type) { |
| 953 | case 0x00: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 954 | ND_PRINT((ndo, "Session Message")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 955 | break; |
| 956 | |
| 957 | case 0x81: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 958 | ND_PRINT((ndo, "Session Request")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 959 | break; |
| 960 | |
| 961 | case 0x82: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 962 | ND_PRINT((ndo, "Session Granted")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 963 | break; |
| 964 | |
| 965 | case 0x83: |
| 966 | { |
| 967 | int ecode; |
| 968 | |
| 969 | if (nbt_len < 4) |
| 970 | goto trunc; |
| 971 | if (length < 4) |
| 972 | goto trunc; |
| 973 | if (caplen < 4) |
| 974 | goto trunc; |
| 975 | ecode = data[4]; |
| 976 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 977 | ND_PRINT((ndo, "Session Reject, ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 978 | switch (ecode) { |
| 979 | case 0x80: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 980 | ND_PRINT((ndo, "Not listening on called name")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 981 | break; |
| 982 | case 0x81: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 983 | ND_PRINT((ndo, "Not listening for calling name")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 984 | break; |
| 985 | case 0x82: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 986 | ND_PRINT((ndo, "Called name not present")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 987 | break; |
| 988 | case 0x83: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 989 | ND_PRINT((ndo, "Called name present, but insufficient resources")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 990 | break; |
| 991 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 992 | ND_PRINT((ndo, "Unspecified error 0x%X", ecode)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | } |
| 996 | break; |
| 997 | |
| 998 | case 0x85: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 999 | ND_PRINT((ndo, "Session Keepalive")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1000 | break; |
| 1001 | |
| 1002 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1003 | data = smb_fdata(ndo, data, "Unknown packet type [rB]", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1004 | break; |
| 1005 | } |
| 1006 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1007 | ND_PRINT((ndo, "\n>>> NBT Session Packet\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1008 | switch (type) { |
| 1009 | case 0x00: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1010 | data = smb_fdata(ndo, data, "[P1]NBT Session Message\nFlags=[B]\nLength=[rd]\n", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1011 | data + 4, 0); |
| 1012 | if (data == NULL) |
| 1013 | break; |
| 1014 | if (nbt_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) { |
| 1015 | if ((int)nbt_len > caplen) { |
| 1016 | if ((int)nbt_len > length) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1017 | ND_PRINT((ndo, "WARNING: Packet is continued in later TCP segments\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1018 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1019 | ND_PRINT((ndo, "WARNING: Short packet. Try increasing the snap length by %d\n", |
| 1020 | nbt_len - caplen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1021 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1022 | print_smb(ndo, data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1023 | } else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1024 | ND_PRINT((ndo, "Session packet:(raw data or continuation?)\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1025 | break; |
| 1026 | |
| 1027 | case 0x81: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1028 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1029 | "[P1]NBT Session Request\nFlags=[B]\nLength=[rd]\nDestination=[n1]\nSource=[n1]\n", |
| 1030 | maxbuf, 0); |
| 1031 | break; |
| 1032 | |
| 1033 | case 0x82: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1034 | data = smb_fdata(ndo, data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[rd]\n", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1035 | break; |
| 1036 | |
| 1037 | case 0x83: |
| 1038 | { |
| 1039 | const u_char *origdata; |
| 1040 | int ecode; |
| 1041 | |
| 1042 | origdata = data; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1043 | data = smb_fdata(ndo, data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[rd]\nReason=[B]\n", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1044 | maxbuf, 0); |
| 1045 | if (data == NULL) |
| 1046 | break; |
| 1047 | if (nbt_len >= 1 && caplen >= 1) { |
| 1048 | ecode = origdata[4]; |
| 1049 | switch (ecode) { |
| 1050 | case 0x80: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1051 | ND_PRINT((ndo, "Not listening on called name\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1052 | break; |
| 1053 | case 0x81: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1054 | ND_PRINT((ndo, "Not listening for calling name\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1055 | break; |
| 1056 | case 0x82: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1057 | ND_PRINT((ndo, "Called name not present\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1058 | break; |
| 1059 | case 0x83: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1060 | ND_PRINT((ndo, "Called name present, but insufficient resources\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1061 | break; |
| 1062 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1063 | ND_PRINT((ndo, "Unspecified error 0x%X\n", ecode)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1064 | break; |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | break; |
| 1069 | |
| 1070 | case 0x85: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1071 | data = smb_fdata(ndo, data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[rd]\n", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1072 | break; |
| 1073 | |
| 1074 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1075 | data = smb_fdata(ndo, data, "NBT - Unknown packet type\nType=[B]\n", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1076 | break; |
| 1077 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1078 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1079 | } |
| 1080 | return; |
| 1081 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1082 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1085 | static const struct tok opcode_str[] = { |
| 1086 | { 0, "QUERY" }, |
| 1087 | { 5, "REGISTRATION" }, |
| 1088 | { 6, "RELEASE" }, |
| 1089 | { 7, "WACK" }, |
| 1090 | { 8, "REFRESH(8)" }, |
| 1091 | { 9, "REFRESH" }, |
| 1092 | { 15, "MULTIHOMED REGISTRATION" }, |
| 1093 | { 0, NULL } |
| 1094 | }; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1095 | |
| 1096 | /* |
| 1097 | * print a NBT packet received across udp on port 137 |
| 1098 | */ |
| 1099 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1100 | nbt_udp137_print(netdissect_options *ndo, |
| 1101 | const u_char *data, int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1102 | { |
| 1103 | const u_char *maxbuf = data + length; |
| 1104 | int name_trn_id, response, opcode, nm_flags, rcode; |
| 1105 | int qdcount, ancount, nscount, arcount; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1106 | const u_char *p; |
| 1107 | int total, i; |
| 1108 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1109 | ND_TCHECK2(data[10], 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1110 | name_trn_id = EXTRACT_16BITS(data); |
| 1111 | response = (data[2] >> 7); |
| 1112 | opcode = (data[2] >> 3) & 0xF; |
| 1113 | nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4); |
| 1114 | rcode = data[3] & 0xF; |
| 1115 | qdcount = EXTRACT_16BITS(data + 4); |
| 1116 | ancount = EXTRACT_16BITS(data + 6); |
| 1117 | nscount = EXTRACT_16BITS(data + 8); |
| 1118 | arcount = EXTRACT_16BITS(data + 10); |
| 1119 | startbuf = data; |
| 1120 | |
| 1121 | if (maxbuf <= data) |
| 1122 | return; |
| 1123 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1124 | if (ndo->ndo_vflag > 1) |
| 1125 | ND_PRINT((ndo, "\n>>> ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1126 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1127 | ND_PRINT((ndo, "NBT UDP PACKET(137): %s", tok2str(opcode_str, "OPUNKNOWN", opcode))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1128 | if (response) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1129 | ND_PRINT((ndo, "; %s", rcode ? "NEGATIVE" : "POSITIVE")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1130 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1131 | ND_PRINT((ndo, "; %s; %s", response ? "RESPONSE" : "REQUEST", |
| 1132 | (nm_flags & 1) ? "BROADCAST" : "UNICAST")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1133 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1134 | if (ndo->ndo_vflag < 2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1135 | return; |
| 1136 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1137 | ND_PRINT((ndo, "\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1138 | name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1139 | arcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1140 | |
| 1141 | p = data + 12; |
| 1142 | |
| 1143 | total = ancount + nscount + arcount; |
| 1144 | |
| 1145 | if (qdcount > 100 || total > 100) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1146 | ND_PRINT((ndo, "Corrupt packet??\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | if (qdcount) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1151 | ND_PRINT((ndo, "QuestionRecords:\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1152 | for (i = 0; i < qdcount; i++) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1153 | p = smb_fdata(ndo, p, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1154 | "|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#", |
| 1155 | maxbuf, 0); |
| 1156 | if (p == NULL) |
| 1157 | goto out; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | if (total) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1162 | ND_PRINT((ndo, "\nResourceRecords:\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1163 | for (i = 0; i < total; i++) { |
| 1164 | int rdlen; |
| 1165 | int restype; |
| 1166 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1167 | p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1168 | if (p == NULL) |
| 1169 | goto out; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 1170 | ND_TCHECK_16BITS(p); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1171 | restype = EXTRACT_16BITS(p); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1172 | p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1173 | if (p == NULL) |
| 1174 | goto out; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 1175 | ND_TCHECK_16BITS(p); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1176 | rdlen = EXTRACT_16BITS(p); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1177 | ND_PRINT((ndo, "ResourceLength=%d\nResourceData=\n", rdlen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1178 | p += 2; |
| 1179 | if (rdlen == 6) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1180 | p = smb_fdata(ndo, p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1181 | if (p == NULL) |
| 1182 | goto out; |
| 1183 | } else { |
| 1184 | if (restype == 0x21) { |
| 1185 | int numnames; |
| 1186 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1187 | ND_TCHECK(*p); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1188 | numnames = p[0]; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1189 | p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1190 | if (p == NULL) |
| 1191 | goto out; |
| 1192 | while (numnames--) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1193 | p = smb_fdata(ndo, p, "Name=[n2]\t#", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1194 | if (p == NULL) |
| 1195 | goto out; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1196 | ND_TCHECK(*p); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1197 | if (p[0] & 0x80) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1198 | ND_PRINT((ndo, "<GROUP> ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1199 | switch (p[0] & 0x60) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1200 | case 0x00: ND_PRINT((ndo, "B ")); break; |
| 1201 | case 0x20: ND_PRINT((ndo, "P ")); break; |
| 1202 | case 0x40: ND_PRINT((ndo, "M ")); break; |
| 1203 | case 0x60: ND_PRINT((ndo, "_ ")); break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1204 | } |
| 1205 | if (p[0] & 0x10) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1206 | ND_PRINT((ndo, "<DEREGISTERING> ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1207 | if (p[0] & 0x08) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1208 | ND_PRINT((ndo, "<CONFLICT> ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1209 | if (p[0] & 0x04) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1210 | ND_PRINT((ndo, "<ACTIVE> ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1211 | if (p[0] & 0x02) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1212 | ND_PRINT((ndo, "<PERMANENT> ")); |
| 1213 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1214 | p += 2; |
| 1215 | } |
| 1216 | } else { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 1217 | smb_print_data(ndo, p, min(rdlen, length - (p - data))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1218 | p += rdlen; |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | if (p < maxbuf) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1225 | smb_fdata(ndo, p, "AdditionalData:\n", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1226 | |
| 1227 | out: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1228 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1229 | return; |
| 1230 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1231 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1234 | /* |
| 1235 | * Print an SMB-over-TCP packet received across tcp on port 445 |
| 1236 | */ |
| 1237 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1238 | smb_tcp_print(netdissect_options *ndo, |
| 1239 | const u_char * data, int length) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1240 | { |
| 1241 | int caplen; |
| 1242 | u_int smb_len; |
| 1243 | const u_char *maxbuf; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1244 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1245 | if (length < 4) |
| 1246 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1247 | if (ndo->ndo_snapend < data) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1248 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1249 | caplen = ndo->ndo_snapend - data; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1250 | if (caplen < 4) |
| 1251 | goto trunc; |
| 1252 | maxbuf = data + caplen; |
| 1253 | smb_len = EXTRACT_24BITS(data + 1); |
| 1254 | length -= 4; |
| 1255 | caplen -= 4; |
| 1256 | |
| 1257 | startbuf = data; |
| 1258 | data += 4; |
| 1259 | |
| 1260 | if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) { |
| 1261 | if ((int)smb_len > caplen) { |
| 1262 | if ((int)smb_len > length) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1263 | ND_PRINT((ndo, " WARNING: Packet is continued in later TCP segments\n")); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1264 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1265 | ND_PRINT((ndo, " WARNING: Short packet. Try increasing the snap length by %d\n", |
| 1266 | smb_len - caplen)); |
| 1267 | } else |
| 1268 | ND_PRINT((ndo, " ")); |
| 1269 | print_smb(ndo, data, maxbuf > data + smb_len ? data + smb_len : maxbuf); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1270 | } else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1271 | ND_PRINT((ndo, " SMB-over-TCP packet:(raw data or continuation?)\n")); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1272 | return; |
| 1273 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1274 | ND_PRINT((ndo, "%s", tstr)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 1275 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1276 | |
| 1277 | /* |
| 1278 | * print a NBT packet received across udp on port 138 |
| 1279 | */ |
| 1280 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1281 | nbt_udp138_print(netdissect_options *ndo, |
| 1282 | const u_char *data, int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1283 | { |
| 1284 | const u_char *maxbuf = data + length; |
| 1285 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1286 | if (maxbuf > ndo->ndo_snapend) |
| 1287 | maxbuf = ndo->ndo_snapend; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1288 | if (maxbuf <= data) |
| 1289 | return; |
| 1290 | startbuf = data; |
| 1291 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1292 | if (ndo->ndo_vflag < 2) { |
| 1293 | ND_PRINT((ndo, "NBT UDP PACKET(138)")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1294 | return; |
| 1295 | } |
| 1296 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1297 | data = smb_fdata(ndo, data, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1298 | "\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#", |
| 1299 | maxbuf, 0); |
| 1300 | |
| 1301 | if (data != NULL) { |
| 1302 | /* If there isn't enough data for "\377SMB", don't check for it. */ |
| 1303 | if (&data[3] >= maxbuf) |
| 1304 | goto out; |
| 1305 | |
| 1306 | if (memcmp(data, "\377SMB",4) == 0) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1307 | print_smb(ndo, data, maxbuf); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1308 | } |
| 1309 | out: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1310 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | |
| 1314 | /* |
| 1315 | print netbeui frames |
| 1316 | */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 1317 | static struct nbf_strings { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1318 | const char *name; |
| 1319 | const char *nonverbose; |
| 1320 | const char *verbose; |
| 1321 | } nbf_strings[0x20] = { |
| 1322 | { "Add Group Name Query", ", [P23]Name to add=[n2]#", |
| 1323 | "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" }, |
| 1324 | { "Add Name Query", ", [P23]Name to add=[n2]#", |
| 1325 | "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" }, |
| 1326 | { "Name In Conflict", NULL, NULL }, |
| 1327 | { "Status Query", NULL, NULL }, |
| 1328 | { NULL, NULL, NULL }, /* not used */ |
| 1329 | { NULL, NULL, NULL }, /* not used */ |
| 1330 | { NULL, NULL, NULL }, /* not used */ |
| 1331 | { "Terminate Trace", NULL, NULL }, |
| 1332 | { "Datagram", NULL, |
| 1333 | "[P7]Destination=[n2]\nSource=[n2]\n" }, |
| 1334 | { "Broadcast Datagram", NULL, |
| 1335 | "[P7]Destination=[n2]\nSource=[n2]\n" }, |
| 1336 | { "Name Query", ", [P7]Name=[n2]#", |
| 1337 | "[P1]SessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nName=[n2]\nName of sender=[n2]\n" }, |
| 1338 | { NULL, NULL, NULL }, /* not used */ |
| 1339 | { NULL, NULL, NULL }, /* not used */ |
| 1340 | { "Add Name Response", ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#", |
| 1341 | "AddNameInProcess=[B]\nGroupName=[w]\nTransmitCorrelator=[w][P2]\nDestination=[n2]\nSource=[n2]\n" }, |
| 1342 | { "Name Recognized", NULL, |
| 1343 | "[P1]Data2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n" }, |
| 1344 | { "Status Response", NULL, NULL }, |
| 1345 | { NULL, NULL, NULL }, /* not used */ |
| 1346 | { NULL, NULL, NULL }, /* not used */ |
| 1347 | { NULL, NULL, NULL }, /* not used */ |
| 1348 | { "Terminate Trace", NULL, NULL }, |
| 1349 | { "Data Ack", NULL, |
| 1350 | "[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1351 | { "Data First/Middle", NULL, |
| 1352 | "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1353 | { "Data Only/Last", NULL, |
| 1354 | "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1355 | { "Session Confirm", NULL, |
| 1356 | "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1357 | { "Session End", NULL, |
| 1358 | "[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1359 | { "Session Initialize", NULL, |
| 1360 | "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1361 | { "No Receive", NULL, |
| 1362 | "Flags=[{|SEND_NO_ACK}]\nDataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1363 | { "Receive Outstanding", NULL, |
| 1364 | "[P1]DataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1365 | { "Receive Continue", NULL, |
| 1366 | "[P2]TransmitCorrelator=[w]\n[P2]RemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" }, |
| 1367 | { NULL, NULL, NULL }, /* not used */ |
| 1368 | { NULL, NULL, NULL }, /* not used */ |
| 1369 | { "Session Alive", NULL, NULL } |
| 1370 | }; |
| 1371 | |
| 1372 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1373 | netbeui_print(netdissect_options *ndo, |
| 1374 | u_short control, const u_char *data, int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1375 | { |
| 1376 | const u_char *maxbuf = data + length; |
| 1377 | int len; |
| 1378 | int command; |
| 1379 | const u_char *data2; |
| 1380 | int is_truncated = 0; |
| 1381 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1382 | if (maxbuf > ndo->ndo_snapend) |
| 1383 | maxbuf = ndo->ndo_snapend; |
| 1384 | ND_TCHECK(data[4]); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1385 | len = EXTRACT_LE_16BITS(data); |
| 1386 | command = data[4]; |
| 1387 | data2 = data + len; |
| 1388 | if (data2 >= maxbuf) { |
| 1389 | data2 = maxbuf; |
| 1390 | is_truncated = 1; |
| 1391 | } |
| 1392 | |
| 1393 | startbuf = data; |
| 1394 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1395 | if (ndo->ndo_vflag < 2) { |
| 1396 | ND_PRINT((ndo, "NBF Packet: ")); |
| 1397 | data = smb_fdata(ndo, data, "[P5]#", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1398 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1399 | ND_PRINT((ndo, "\n>>> NBF Packet\nType=0x%X ", control)); |
| 1400 | data = smb_fdata(ndo, data, "Length=[d] Signature=[w] Command=[B]\n#", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1401 | } |
| 1402 | if (data == NULL) |
| 1403 | goto out; |
| 1404 | |
| 1405 | if (command > 0x1f || nbf_strings[command].name == NULL) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1406 | if (ndo->ndo_vflag < 2) |
| 1407 | data = smb_fdata(ndo, data, "Unknown NBF Command#", data2, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1408 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1409 | data = smb_fdata(ndo, data, "Unknown NBF Command\n", data2, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1410 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1411 | if (ndo->ndo_vflag < 2) { |
| 1412 | ND_PRINT((ndo, "%s", nbf_strings[command].name)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1413 | if (nbf_strings[command].nonverbose != NULL) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1414 | data = smb_fdata(ndo, data, nbf_strings[command].nonverbose, data2, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1415 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1416 | ND_PRINT((ndo, "%s:\n", nbf_strings[command].name)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1417 | if (nbf_strings[command].verbose != NULL) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1418 | data = smb_fdata(ndo, data, nbf_strings[command].verbose, data2, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1419 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1420 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1424 | if (ndo->ndo_vflag < 2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1425 | return; |
| 1426 | |
| 1427 | if (data == NULL) |
| 1428 | goto out; |
| 1429 | |
| 1430 | if (is_truncated) { |
| 1431 | /* data2 was past the end of the buffer */ |
| 1432 | goto out; |
| 1433 | } |
| 1434 | |
| 1435 | /* If this isn't a command that would contain an SMB message, quit. */ |
| 1436 | if (command != 0x08 && command != 0x09 && command != 0x15 && |
| 1437 | command != 0x16) |
| 1438 | goto out; |
| 1439 | |
| 1440 | /* If there isn't enough data for "\377SMB", don't look for it. */ |
| 1441 | if (&data2[3] >= maxbuf) |
| 1442 | goto out; |
| 1443 | |
| 1444 | if (memcmp(data2, "\377SMB",4) == 0) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1445 | print_smb(ndo, data2, maxbuf); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1446 | else { |
| 1447 | int i; |
| 1448 | for (i = 0; i < 128; i++) { |
| 1449 | if (&data2[i + 3] >= maxbuf) |
| 1450 | break; |
| 1451 | if (memcmp(&data2[i], "\377SMB", 4) == 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1452 | ND_PRINT((ndo, "found SMB packet at %d\n", i)); |
| 1453 | print_smb(ndo, &data2[i], maxbuf); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1454 | break; |
| 1455 | } |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | out: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1460 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1461 | return; |
| 1462 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1463 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | |
| 1467 | /* |
| 1468 | * print IPX-Netbios frames |
| 1469 | */ |
| 1470 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1471 | ipx_netbios_print(netdissect_options *ndo, |
| 1472 | const u_char *data, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1473 | { |
| 1474 | /* |
| 1475 | * this is a hack till I work out how to parse the rest of the |
| 1476 | * NetBIOS-over-IPX stuff |
| 1477 | */ |
| 1478 | int i; |
| 1479 | const u_char *maxbuf; |
| 1480 | |
| 1481 | maxbuf = data + length; |
| 1482 | /* Don't go past the end of the captured data in the packet. */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1483 | if (maxbuf > ndo->ndo_snapend) |
| 1484 | maxbuf = ndo->ndo_snapend; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1485 | startbuf = data; |
| 1486 | for (i = 0; i < 128; i++) { |
| 1487 | if (&data[i + 4] > maxbuf) |
| 1488 | break; |
| 1489 | if (memcmp(&data[i], "\377SMB", 4) == 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1490 | smb_fdata(ndo, data, "\n>>> IPX transport ", &data[i], 0); |
| 1491 | print_smb(ndo, &data[i], maxbuf); |
| 1492 | ND_PRINT((ndo, "\n")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1493 | break; |
| 1494 | } |
| 1495 | } |
| 1496 | if (i == 128) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1497 | smb_fdata(ndo, data, "\n>>> Unknown IPX ", maxbuf, 0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1498 | } |