aboutsummaryrefslogtreecommitdiffstats
path: root/packet-smb-browse.c
blob: 611cb4c11a5f9e41ad8f61c4a74e8035253e4460 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
/* packet-smb-browse.c
 * Routines for smb packet dissection
 * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
 *
 * $Id: packet-smb-browse.c,v 1.2 2000/04/08 01:28:13 sharpe Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@zing.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-pop.c
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>

#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif

#include <time.h>
#include <string.h>
#include <glib.h>
#include <ctype.h>
#include "packet.h"
#include "conversation.h"
#include "smb.h"
#include "alignment.h"

static int proto_smb_browse = -1;

static gint ett_browse = -1;
static gint ett_browse_flags = -1;
static gint ett_browse_election_criteria = -1;
static gint ett_browse_election_os = -1;
static gint ett_browse_election_desire = -1;



char *browse_commands[] = 
{ "Error, No such command!",       /* Value 0 */
  "Host Announcement",             /* Value 1 */
  "Request Announcement",          /* Value 2 */
  "Error, No such command!",       /* Value 3 */
  "Error, No such command!",       /* Value 4 */
  "Error, No such command!",       /* Value 5 */
  "Error, No such command!",       /* Value 6 */
  "Error, No such command!",       /* Value 7 */
  "Browser Election Request",      /* Value 8 */
  "Get Backup List Request",       /* Value 9 */
  "Get Backup List Response",      /* Value 10 */
  "Become Backup Browser",         /* Value 11 */
  "Domain/Workgroup Announcement", /* Value 12 */
  "Master Announcement",           /* Value 13 */
  "Error! No such command",        /* Value 14 */
  "Local Master Announcement"      /* Value 15 */
};

#define HOST_ANNOUNCE        1
#define REQUEST_ANNOUNCE     2
#define BROWSER_ELECTION     8
#define GETBACKUPLISTREQ     9
#define GETBACKUPLISTRESP   10
#define BECOMEBACKUPBROWSER 11
#define DOMAINANNOUNCEMENT  12
#define MASTERANNOUNCEMENT  13
#define LOCALMASTERANNOUNC  15

char *svr_types[32] = {
  "Workstation",
  "Server",
  "SQL Server",
  "Domain Controller",
  "Backup Controller",
  "Time Source",
  "Apple Server",
  "Novell Server",
  "Domain Member Server",
  "Print Queue Server",
  "Dialin Server",
  "Xenix Server",
  "NT Workstation",
  "Windows for Workgroups",
  "Unknown Server - FIXME",
  "NT Server",
  "Potential Browser",
  "Backup Browser",
  "Master Browser",
  "Domain Master Browser",
  "OSF",
  "VMS",
  "Windows 95 or above",
  "Unused",
  "Unused",
  "Unused",
  "Unused",
  "Unused",
  "Unused",
  "Unused",
  "Local List Only",
  "Domain Enum"
};

guint32 
dissect_mailslot_browse(const u_char *pd, int offset, frame_data *fd, proto_tree *parent, proto_tree *tree, struct smb_info si, int max_data, int SMB_offset, int errcode, int dirn, const u_char *command, int DataOffset, int DataCount)
{
  guint8               OpCode;
  guint8               UpdateCount;
  guint8               VersionMajor;
  guint8               VersionMinor;
  guint32              Periodicity;
  guint32              ServerType;
  guint16              SigConstant;
  guint32              Token;
  guint8               BackupServerCount;
  guint8               Flags;
  guint32              MBZ;
  guint8               ElectionVersion;
  guint32              ElectionCriteria;
  guint8               ElectionOS;
  guint8               ElectionDesire;
  guint16              ElectionRevision;
  guint32              ServerUpTime;
  const char           *ServerName;
  const char           *ServerComment;
  proto_tree           *browse_tree = NULL, *flags_tree = NULL, 
                       *OSflags = NULL, *DesireFlags = NULL;
  proto_item           *ti, *ec;
  guint32              loc_offset = DataOffset, count = 0;
  int                  i;

  if (check_col(fd, COL_PROTOCOL))
    col_add_str(fd, COL_PROTOCOL, "BROWSER");

  if (check_col(fd, COL_INFO)) /* Put in something, and replace it later */
    col_add_str(fd, COL_INFO, "Browse Announcement");

  /*
   * Now, decode the browse request 
   */

  OpCode = GBYTE(pd, loc_offset);

  if (check_col(fd, COL_INFO))
    col_add_fstr(fd, COL_INFO, (OpCode > (sizeof(browse_commands)/sizeof(char *))) ? "Error, No Such Command:%u" : browse_commands[OpCode], OpCode);
    
  if (tree) {  /* Add the browse tree */

    ti = proto_tree_add_item(parent, proto_smb_browse, DataOffset, DataCount, NULL);
    browse_tree = proto_item_add_subtree(ti, ett_browse);

    proto_tree_add_text(browse_tree, loc_offset, 1, "OpCode: %s", (OpCode > (sizeof(browse_commands)/sizeof(char *))) ? "Error, No Such Command" : browse_commands[OpCode]);

  }

  loc_offset += 1;    /* Skip the OpCode */

  switch (OpCode) {

  case DOMAINANNOUNCEMENT:
  case LOCALMASTERANNOUNC:
  case HOST_ANNOUNCE:

    UpdateCount = GBYTE(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 1, "Update Count: %u", UpdateCount);

    }

    loc_offset += 1;  /* Skip the Update Count */

    Periodicity = GWORD(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 4, "Update Periodicity: %u Sec", Periodicity/1000 );

    }

    loc_offset += 4;

    ServerName = pd + loc_offset;

    if (check_col(fd, COL_INFO)) {

      col_append_fstr(fd, COL_INFO, " %s", ServerName);

    }

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 16, (OpCode == DOMAINANNOUNCEMENT) ? "Domain/WorkGroup: %s": "Host Name: %s", ServerName);

    }

    loc_offset += 16;

    VersionMajor = GBYTE(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 1, "Major Version: %u", VersionMajor);

    }

    loc_offset += 1;

    VersionMinor = GBYTE(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 1, "Minor Version: %u", VersionMinor);

    }

    loc_offset += 1;

    ServerType = GWORD(pd, loc_offset);

    if (check_col(fd, COL_INFO)) {

      /* Append the type(s) of the system to the COL_INFO line ... */

      for (i = 0; i < 32; i++) {

	if (ServerType & (1 << i) && (strcmp("Unused", svr_types[i]) != 0))
	    col_append_fstr(fd, COL_INFO, ", %s", svr_types[i]);
	
      }
      
    }

    if (tree) {

      ti = proto_tree_add_text(browse_tree, loc_offset, 4, "Server Type: 0x%04x", ServerType);
      flags_tree = proto_item_add_subtree(ti, ett_browse_flags);
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0001, 32, "Workstation", "Not Workstation"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0002, 32, "Server", "Not Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0004, 32, "SQL Server", "Not SQL Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0008, 32, "Domain Controller", "Not Domain Controller"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0010, 32, "Backup Controller", "Not Backup Controller"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0020, 32, "Time Source", "Not Time Source"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0040, 32, "Apple Server", "Not Apple Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0080, 32, "Novell Server", "Not Novell Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0100, 32, "Domain Member Server", "Not Domain Member Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0200, 32, "Print Queue Server", "Not Print Queue Server"));      
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0400, 32, "Dialin Server", "Not Dialin Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x0800, 32, "Xenix Server", "Not Xenix Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x1000, 32, "NT Workstation", "Not NT Workstation"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x2000, 32, "Windows for Workgroups", "Not Windows for Workgroups"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x8000, 32, "NT Server", "Not NT Server"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x10000, 32, "Potential Browser", "Not Potential Browser"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x20000, 32, "Backup Browser", "Not Backup Browser"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x40000, 32, "Master Browser", "Not Master Browser"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x80000, 32, "Domain Master Browser", "Not Domain Master Browser"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x100000, 32, "OSF", "Not OSF"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x200000, 32, "VMS", "Not VMS"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x400000, 32, "Windows 95 or above", "Not Windows 95 or above"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x40000000, 32, "Local List Only", "Not Local List Only"));
      proto_tree_add_text(flags_tree, loc_offset, 4, "%s",
			  decode_boolean_bitfield(ServerType, 0x80000000, 32, "Domain Enum", "Not Domain Enum"));
    }
    loc_offset += 4;
    
    ElectionVersion = GSHORT(pd, loc_offset);
    
    if (tree) {
      
      proto_tree_add_text(browse_tree, loc_offset, 2, "Election Version: %u", ElectionVersion);

    }

    loc_offset += 2;

    SigConstant = GSHORT(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 2, "Signature: %u (0x%04X)", SigConstant, SigConstant);

    }

    loc_offset += 2;

    ServerComment = pd + loc_offset;

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, strlen(ServerComment) + 1, "Host Comment: %s", ServerComment);

    }

    break;

  case REQUEST_ANNOUNCE:

    Flags = GBYTE(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 1, "Unused Flags: %u", Flags);

    }

    loc_offset += 1;

    ServerName = pd + loc_offset;

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, strlen(ServerName) + 1, "Send List To: %s", ServerName);

    }

    break;

  case BROWSER_ELECTION:

    ElectionVersion = GBYTE(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 1, "Election Version = %u", ElectionVersion);

    }

    loc_offset += 1;

    ElectionCriteria = GWORD(pd, loc_offset);
    ElectionOS       = GBYTE(pd, loc_offset + 3);
    ElectionRevision = GSHORT(pd, loc_offset + 1);
    ElectionDesire   = GBYTE(pd, loc_offset);

    if (tree) {

      ti = proto_tree_add_text(browse_tree, loc_offset, 4, "Election Criteria = %u (0x%08X)", ElectionCriteria, ElectionCriteria);

      ec = proto_item_add_subtree(ti, ett_browse_election_criteria);

      ti = proto_tree_add_text(ec, loc_offset + 3, 1, "Election OS Summary: %u (0x%02X)", ElectionOS, ElectionOS);

      OSflags = proto_item_add_subtree(ti, ett_browse_election_os);

      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			    decode_boolean_bitfield(ElectionOS, 0x01, 8, "Windows for Workgroups", "Not Windows for Workgroups"));
      
      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			  decode_boolean_bitfield(ElectionOS, 0x02, 8, "Unknown", "Not used"));

      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			  decode_boolean_bitfield(ElectionOS, 0x04, 8, "Unknown", "Not used"));

      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			  decode_boolean_bitfield(ElectionOS, 0x08, 8, "Unknown", "Not used"));
      
      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			  decode_boolean_bitfield(ElectionOS, 0x10, 8, "Windows NT Workstation", "Not Windows NT Workstation"));
      
      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			  decode_boolean_bitfield(ElectionOS, 0x20, 8, "Windows NT Server", "Not Windows NT Server"));

      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			  decode_boolean_bitfield(ElectionOS, 0x40, 8, "Unknown", "Not used"));

      proto_tree_add_text(OSflags, loc_offset + 3, 1, "%s",
			  decode_boolean_bitfield(ElectionOS, 0x80, 8, "Unknown", "Not used"));

      proto_tree_add_text(ec, loc_offset + 1, 2, "Election Revision: %u (0x%04X)", ElectionRevision, ElectionRevision);

      ti = proto_tree_add_text(ec, loc_offset, 1, "Election Desire Summary: %u (0x%02X)", ElectionDesire, ElectionDesire);

      DesireFlags = proto_item_add_subtree(ti, ett_browse_election_desire);

      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x01, 8, "Backup Browse Server", "Not Backup Browse Server"));
      
      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x02, 8, "Standby Browse Server", "Not Standby Browse Server"));

      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x04, 8, "Master Browser", "Not Master Browser"));

      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x08, 8, "Domain Master Browse Server", "Not Domain Master Browse Server"));

      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x10, 8, "Unknown", "Not used"));

      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x20, 8, "WINS Client", "Not WINS Client"));

      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x40, 8, "Unknown", "Not used"));

      proto_tree_add_text(DesireFlags, loc_offset, 1, "%s",
			  decode_boolean_bitfield(ElectionDesire, 0x80, 8, "Windows NT Advanced Server", "Not Windows NT Advanced Server"));

    }

    loc_offset += 4;

    ServerUpTime = GWORD(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 4, "Server Up Time: %u Sec (%ums)", ServerUpTime/1000, ServerUpTime);

    }

    loc_offset += 4;

    MBZ = GWORD(pd, loc_offset);

    loc_offset += 4;

    ServerName = pd + loc_offset;

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, strlen(ServerName) + 1, "Election Server Name: %s", ServerName);

    }

    break;

  case GETBACKUPLISTREQ:

    BackupServerCount = GBYTE(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 1, "Backup List Requested Count: %u", BackupServerCount);

    }

    loc_offset += 1;

    Token = GWORD(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 4, "Backup Request Token: %u", Token);

    }

    break;

  case GETBACKUPLISTRESP:

    BackupServerCount = GBYTE(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 1, "Backup Server Count: %u", BackupServerCount);

    }

    loc_offset += 1;

    Token = GWORD(pd, loc_offset);

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, 4, "Backup Response Token: %u", Token);

    }

    loc_offset += 4;

    ServerName = pd + loc_offset;

    for (count = 1; count <= BackupServerCount; count++) {

      if (tree) {

	proto_tree_add_text(browse_tree, loc_offset, strlen(ServerName) + 1, "Backup Server: %s", ServerName);

      }

      loc_offset += strlen(ServerName) + 1;

      ServerName = pd + loc_offset;

    }

    break;

  case BECOMEBACKUPBROWSER:

    ServerName = pd + loc_offset;

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, strlen(ServerName) + 1, "Browser to Promote: %s", ServerName);

    }

    break;

  case MASTERANNOUNCEMENT:

    ServerName = pd + loc_offset;

    if (tree) {

      proto_tree_add_text(browse_tree, loc_offset, strlen(ServerName) + 1, "Server Name: %s", ServerName);

    }

    break;

  default:
    break;
  }
  
  return 1;  /* Success */

}


void
register_proto_smb_browse( void){


	static gint *ett[] = {
		&ett_browse,
		&ett_browse_flags,
		&ett_browse_election_criteria,
		&ett_browse_election_os,
		&ett_browse_election_desire
	};

    	proto_smb_browse = proto_register_protocol("Microsoft Windows Browser Protocol", "browser");           

	proto_register_subtree_array(ett, array_length(ett));          
}