Correctly dissect LSA security descriptors, at least as they appear
[obnox/wireshark/wip.git] / packet-smb-browse.c
1 /* packet-smb-browse.c
2  * Routines for SMB Browser packet dissection
3  * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
4  *
5  * $Id: packet-smb-browse.c,v 1.21 2002/01/24 09:20:51 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-pop.c
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
40 #endif
41
42 #include <time.h>
43 #include <string.h>
44 #include <glib.h>
45 #include <ctype.h>
46 #include <epan/packet.h>
47 #include <epan/conversation.h>
48 #include "smb.h"
49 #include "alignment.h"
50
51 #include "packet-smb-browse.h"
52
53 static int proto_smb_browse = -1;
54 static int hf_command = -1;
55 static int hf_update_count = -1;
56 static int hf_periodicity = -1;
57 static int hf_server_name = -1;
58 static int hf_mb_server_name = -1;
59 static int hf_os_major = -1;
60 static int hf_os_minor = -1;
61 static int hf_server_type = -1;
62 static int hf_server_type_workstation = -1;
63 static int hf_server_type_server = -1;
64 static int hf_server_type_sql = -1;
65 static int hf_server_type_domain = -1;
66 static int hf_server_type_backup = -1;
67 static int hf_server_type_time = -1;
68 static int hf_server_type_apple = -1;
69 static int hf_server_type_novell = -1;
70 static int hf_server_type_member = -1;
71 static int hf_server_type_print = -1;
72 static int hf_server_type_dialin = -1;
73 static int hf_server_type_xenix = -1;
74 static int hf_server_type_ntw = -1;
75 static int hf_server_type_wfw = -1;
76 static int hf_server_type_nts = -1;
77 static int hf_server_type_potentialb = -1;
78 static int hf_server_type_backupb = -1;
79 static int hf_server_type_masterb = -1;
80 static int hf_server_type_domainmasterb = -1;
81 static int hf_server_type_osf = -1;
82 static int hf_server_type_vms = -1;
83 static int hf_server_type_w95 = -1;
84 static int hf_server_type_local = -1;
85 static int hf_server_type_domainenum = -1;
86 static int hf_election_version = -1;
87 static int hf_proto_major = -1;
88 static int hf_proto_minor = -1;
89 static int hf_sig_const = -1;
90 static int hf_server_comment = -1;
91 static int hf_unused_flags = -1;
92 static int hf_response_computer_name = -1;
93 static int hf_election_criteria = -1;
94 static int hf_election_desire = -1;
95 static int hf_election_desire_flags_backup = -1;
96 static int hf_election_desire_flags_standby = -1;
97 static int hf_election_desire_flags_master = -1;
98 static int hf_election_desire_flags_domain_master = -1;
99 static int hf_election_desire_flags_wins = -1;
100 static int hf_election_desire_flags_nt = -1;
101 static int hf_election_revision = -1;
102 static int hf_election_os = -1;
103 static int hf_election_os_wfw = -1;
104 static int hf_election_os_ntw = -1;
105 static int hf_election_os_nts = -1;
106 static int hf_server_uptime = -1;
107 static int hf_backup_count = -1;
108 static int hf_backup_token = -1;
109 static int hf_backup_server = -1;
110 static int hf_browser_to_promote = -1;
111
112 static gint ett_browse = -1;
113 static gint ett_browse_flags = -1;
114 static gint ett_browse_election_criteria = -1;
115 static gint ett_browse_election_os = -1;
116 static gint ett_browse_election_desire = -1;
117
118
119 #define SERVER_WORKSTATION              0
120 #define SERVER_SERVER                   1
121 #define SERVER_SQL_SERVER               2
122 #define SERVER_DOMAIN_CONTROLLER        3
123 #define SERVER_BACKUP_CONTROLLER        4
124 #define SERVER_TIME_SOURCE              5
125 #define SERVER_APPLE_SERVER             6
126 #define SERVER_NOVELL_SERVER            7
127 #define SERVER_DOMAIN_MEMBER_SERVER     8
128 #define SERVER_PRINT_QUEUE_SERVER       9
129 #define SERVER_DIALIN_SERVER            10
130 #define SERVER_XENIX_SERVER             11
131 #define SERVER_NT_WORKSTATION           12
132 #define SERVER_WINDOWS_FOR_WORKGROUPS   13
133 #define SERVER_NT_SERVER                15
134 #define SERVER_POTENTIAL_BROWSER        16
135 #define SERVER_BACKUP_BROWSER           17
136 #define SERVER_MASTER_BROWSER           18
137 #define SERVER_DOMAIN_MASTER_BROWSER    19
138 #define SERVER_OSF                      20
139 #define SERVER_VMS                      21
140 #define SERVER_WINDOWS_95               22
141 #define SERVER_LOCAL_LIST_ONLY          30
142 #define SERVER_DOMAIN_ENUM              31
143
144 static const value_string server_types[] = {
145         {SERVER_WORKSTATION,            "Workstation"},
146         {SERVER_SERVER,                 "Server"},
147         {SERVER_SQL_SERVER,             "SQL Server"},
148         {SERVER_DOMAIN_CONTROLLER,      "Domain Controller"},
149         {SERVER_BACKUP_CONTROLLER,      "Backup Controller"},
150         {SERVER_TIME_SOURCE,            "Time Source"},
151         {SERVER_APPLE_SERVER,           "Apple Server"},
152         {SERVER_NOVELL_SERVER,          "Novell Server"},
153         {SERVER_DOMAIN_MEMBER_SERVER,   "Domain Member Server"},
154         {SERVER_PRINT_QUEUE_SERVER,     "Print Queue Server"},
155         {SERVER_DIALIN_SERVER,          "Dialin Server"},
156         {SERVER_XENIX_SERVER,           "Xenix Server"},
157         {SERVER_NT_WORKSTATION,         "NT Workstation"},
158         {SERVER_WINDOWS_FOR_WORKGROUPS, "Windows for Workgroups"},
159         {SERVER_NT_SERVER,              "NT Server"},
160         {SERVER_POTENTIAL_BROWSER,      "Potential Browser"},
161         {SERVER_BACKUP_BROWSER,         "Backup Browser"},
162         {SERVER_MASTER_BROWSER,         "Master Browser"},
163         {SERVER_DOMAIN_MASTER_BROWSER,  "Domain Master Browser"},
164         {SERVER_OSF,                    "OSF"},
165         {SERVER_VMS,                    "VMS"},
166         {SERVER_WINDOWS_95,             "Windows 95 or above"},
167         {SERVER_LOCAL_LIST_ONLY,        "Local List Only"},
168         {SERVER_DOMAIN_ENUM,            "Domain Enum"},
169         {0,     NULL}
170 };
171
172 static const true_false_string tfs_workstation = {
173         "This is a Workstation",
174         "This is NOT a Workstation"
175 };
176 static const true_false_string tfs_server = {
177         "This is a Server",
178         "This is NOT a Server"
179 };
180 static const true_false_string tfs_sql = {
181         "This is an SQL server",
182         "This is NOT an SQL server"
183 };
184 static const true_false_string tfs_domain = {
185         "This is a Domain Controller",
186         "This is NOT a Domain Controller"
187 };
188 static const true_false_string tfs_backup = {
189         "This is a Backup Controller",
190         "This is NOT a Backup Controller"
191 };
192 static const true_false_string tfs_time = {
193         "This is a Time Source",
194         "This is NOT a Time Source"
195 };
196 static const true_false_string tfs_apple = {
197         "This is an Apple host",
198         "This is NOT an Apple host"
199 };
200 static const true_false_string tfs_novell = {
201         "This is a Novell server",
202         "This is NOT a Novell server"
203 };
204 static const true_false_string tfs_member = {
205         "This is a Domain Member server",
206         "This is NOT a Domain Member server"
207 };
208 static const true_false_string tfs_print = {
209         "This is a Print Queue server",
210         "This is NOT a Print Queue server"
211 };
212 static const true_false_string tfs_dialin = {
213         "This is a Dialin server",
214         "This is NOT a Dialin server"
215 };
216 static const true_false_string tfs_xenix = {
217         "This is a Xenix server",
218         "This is NOT a Xenix server"
219 };
220 static const true_false_string tfs_ntw = {
221         "This is an NT Workstation",
222         "This is NOT an NT Workstation"
223 };
224 static const true_false_string tfs_wfw = {
225         "This is a WfW host",
226         "This is NOT a WfW host"
227 };
228 static const true_false_string tfs_nts = {
229         "This is an NT Server",
230         "This is NOT an NT Server"
231 };
232 static const true_false_string tfs_potentialb = {
233         "This is a Potential Browser",
234         "This is NOT a Potential Browser"
235 };
236 static const true_false_string tfs_backupb = {
237         "This is a Backup Browser",
238         "This is NOT a Backup Browser"
239 };
240 static const true_false_string tfs_masterb = {
241         "This is a Master Browser",
242         "This is NOT a Master Browser"
243 };
244 static const true_false_string tfs_domainmasterb = {
245         "This is a Domain Master Browser",
246         "This is NOT a Domain Master Browser"
247 };
248 static const true_false_string tfs_osf = {
249         "This is an OSF host",
250         "This is NOT an OSF host"
251 };
252 static const true_false_string tfs_vms = {
253         "This is a VMS host",
254         "This is NOT a VMS host"
255 };
256 static const true_false_string tfs_w95 = {
257         "This is a Windows 95 or above host",
258         "This is NOT a Windows 95 or above host"
259 };
260 static const true_false_string tfs_local = {
261         "This is a local list only request",
262         "This is NOT a local list only request"
263 };
264 static const true_false_string tfs_domainenum = {
265         "This is a Domain Enum request",
266         "This is NOT a Domain Enum request"
267 };
268
269 #define DESIRE_BACKUP                   0
270 #define DESIRE_STANDBY                  1
271 #define DESIRE_MASTER                   2
272 #define DESIRE_DOMAIN_MASTER            3
273 #define DESIRE_WINS                     5
274 #define DESIRE_NT                       7
275
276 static const value_string desire_flags[] = {
277         {DESIRE_BACKUP,         "Backup Browse Server"},
278         {DESIRE_STANDBY,        "Standby Browse Server"},
279         {DESIRE_MASTER,         "Master Browser"},
280         {DESIRE_DOMAIN_MASTER,  "Domain Master Browse Server"},
281         {DESIRE_WINS,           "WINS Client"},
282         {DESIRE_NT,             "Windows NT Advanced Server"},
283         {0,                     NULL}
284 };
285
286 static const true_false_string tfs_desire_backup = {
287         "Backup Browse Server", 
288         "NOT Backup Browse Server"
289  };
290 static const true_false_string tfs_desire_standby = {
291         "Standby Browse Server",
292         "NOT Standby Browse Server"
293 };
294 static const true_false_string tfs_desire_master = {
295         "Master Browser",
296         "NOT Master Browser"
297 };
298 static const true_false_string tfs_desire_domain_master = {
299         "Domain Master Browse Server",
300         "NOT Domain Master Browse Server"
301 };
302 static const true_false_string tfs_desire_wins = {
303         "WINS Client",
304         "NOT WINS Client"
305 };
306 static const true_false_string tfs_desire_nt = {
307         "Windows NT Advanced Server",
308         "NOT Windows NT Advanced Server"
309 };
310
311 #define BROWSE_HOST_ANNOUNCE                    1
312 #define BROWSE_REQUEST_ANNOUNCE                 2
313 #define BROWSE_ELECTION_REQUEST                 8
314 #define BROWSE_BACKUP_LIST_REQUEST              9
315 #define BROWSE_BACKUP_LIST_RESPONSE             10
316 #define BROWSE_BECOME_BACKUP                    11
317 #define BROWSE_DOMAIN_ANNOUNCEMENT              12
318 #define BROWSE_MASTER_ANNOUNCEMENT              13
319 #define BROWSE_LOCAL_MASTER_ANNOUNCEMENT        15
320
321 static const value_string commands[] = {
322         {BROWSE_HOST_ANNOUNCE,          "Host Announcement"},
323         {BROWSE_REQUEST_ANNOUNCE,       "Request Announcement"},
324         {BROWSE_ELECTION_REQUEST,       "Browser Election Request"},
325         {BROWSE_BACKUP_LIST_REQUEST,    "Get Backup List Request"},
326         {BROWSE_BACKUP_LIST_RESPONSE,   "Get Backup List Response"},
327         {BROWSE_BECOME_BACKUP,          "Become Backup Browser"},
328         {BROWSE_DOMAIN_ANNOUNCEMENT,    "Domain/Workgroup Announcement"},
329         {BROWSE_MASTER_ANNOUNCEMENT,    "Master Announcement"},
330         {BROWSE_LOCAL_MASTER_ANNOUNCEMENT,"Local Master Announcement"},
331         {0,                             NULL}
332 };
333
334 #define OS_WFW                          0
335 #define OS_NTW                          4
336 #define OS_NTS                          5
337
338 static const value_string os_flags[] = {
339         {OS_WFW,                "Windows for Workgroups"},
340         {OS_NTW,                "Windows NT Workstation"},
341         {OS_NTS,                "Windows NT Server"},
342         {0,                     NULL}
343 };
344
345 static const true_false_string tfs_os_wfw = {
346         "Windows for Workgroups",
347         "Not Windows for Workgroups"
348 };
349 static const true_false_string tfs_os_ntw = {
350         "Windows NT Workstation",
351         "Not Windows NT Workstation"
352 };
353 static const true_false_string tfs_os_nts = {
354         "Windows NT Server",
355         "Not Windows NT Server"
356 };
357
358 static void
359 dissect_election_criterion_os(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
360 {
361         proto_tree *tree = NULL;
362         proto_item *item = NULL;
363         guint8 os;
364
365         os = tvb_get_guint8(tvb, offset);
366
367         if (parent_tree) {
368                 item = proto_tree_add_uint(parent_tree, hf_election_os, tvb, offset, 1, os);
369                 tree = proto_item_add_subtree(item, ett_browse_election_os);
370         }
371
372         proto_tree_add_boolean(tree, hf_election_os_wfw, 
373                 tvb, offset, 1, os);
374         proto_tree_add_boolean(tree, hf_election_os_ntw, 
375                 tvb, offset, 1, os);
376         proto_tree_add_boolean(tree, hf_election_os_nts, 
377                 tvb, offset, 1, os);
378
379 }
380
381 static void
382 dissect_election_criterion_desire(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
383 {
384         proto_tree *tree = NULL;
385         proto_item *item = NULL;
386         guint8 desire;
387
388         desire = tvb_get_guint8(tvb, offset);
389
390         if (parent_tree) {
391                 item = proto_tree_add_uint(parent_tree, hf_election_desire, tvb, offset, 1, desire);
392                 tree = proto_item_add_subtree(item, ett_browse_election_desire);
393         }
394
395         proto_tree_add_boolean(tree, hf_election_desire_flags_backup, 
396                 tvb, offset, 1, desire);
397         proto_tree_add_boolean(tree, hf_election_desire_flags_standby, 
398                 tvb, offset, 1, desire);
399         proto_tree_add_boolean(tree, hf_election_desire_flags_master, 
400                 tvb, offset, 1, desire);
401         proto_tree_add_boolean(tree, hf_election_desire_flags_domain_master, 
402                 tvb, offset, 1, desire);
403         proto_tree_add_boolean(tree, hf_election_desire_flags_wins, 
404                 tvb, offset, 1, desire);
405         proto_tree_add_boolean(tree, hf_election_desire_flags_nt, 
406                 tvb, offset, 1, desire);
407
408 }
409
410 static void
411 dissect_election_criterion(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
412 {
413         proto_tree *tree = NULL;
414         proto_item *item = NULL;
415         guint32 criterion;
416
417         criterion = tvb_get_letohl(tvb, offset);
418
419         if (parent_tree) {
420                 item = proto_tree_add_uint(parent_tree, hf_election_criteria, tvb, offset, 4, criterion);
421                 tree = proto_item_add_subtree(item, ett_browse_election_criteria);
422         }
423
424         /* election desire */
425         dissect_election_criterion_desire(tvb, pinfo, tree, offset);
426         offset += 1;
427
428         /* browser protocol major version */
429         proto_tree_add_item(tree, hf_proto_major, tvb, offset, 1, TRUE);
430         offset += 1;
431
432         /* browser protocol minor version */
433         proto_tree_add_item(tree, hf_proto_minor, tvb, offset, 1, TRUE);
434         offset += 1;
435
436         /* election os */
437         dissect_election_criterion_os(tvb, pinfo, tree, offset);
438         offset += 1;
439
440 }
441
442 /*
443  * XXX - this causes non-browser packets to have browser fields.
444  */
445 void
446 dissect_smb_server_type_flags(tvbuff_t *tvb, packet_info *pinfo,
447     proto_tree *parent_tree, int offset, gboolean infoflag)
448 {
449         proto_tree *tree = NULL;
450         proto_item *item = NULL;
451         guint32 flags;
452         int i;
453
454         flags = tvb_get_letohl(tvb, offset);
455
456         if (parent_tree) {
457                 item = proto_tree_add_uint(parent_tree, hf_server_type, tvb, offset, 4, flags);
458                 tree = proto_item_add_subtree(item, ett_browse_flags);
459         }
460
461         if (infoflag) {
462                 /* Append the type(s) of the system to the COL_INFO line ... */
463                 if (check_col(pinfo->cinfo, COL_INFO)) {
464                         for (i = 0; i < 32; i++) {
465                                 if (flags & (1<<i)) {
466                                         col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
467                                                 val_to_str(i, server_types,
468                                                 "Unknown server type:%d"));
469                                 }
470                         }
471                 }
472         }
473
474         proto_tree_add_boolean(tree, hf_server_type_workstation, 
475                 tvb, offset, 4, flags);
476         proto_tree_add_boolean(tree, hf_server_type_server, 
477                 tvb, offset, 4, flags);
478         proto_tree_add_boolean(tree, hf_server_type_sql, 
479                 tvb, offset, 4, flags);
480         proto_tree_add_boolean(tree, hf_server_type_domain, 
481                 tvb, offset, 4, flags);
482         proto_tree_add_boolean(tree, hf_server_type_backup, 
483                 tvb, offset, 4, flags);
484         proto_tree_add_boolean(tree, hf_server_type_time, 
485                 tvb, offset, 4, flags);
486         proto_tree_add_boolean(tree, hf_server_type_apple, 
487                 tvb, offset, 4, flags);
488         proto_tree_add_boolean(tree, hf_server_type_novell, 
489                 tvb, offset, 4, flags);
490         proto_tree_add_boolean(tree, hf_server_type_member, 
491                 tvb, offset, 4, flags);
492         proto_tree_add_boolean(tree, hf_server_type_print, 
493                 tvb, offset, 4, flags);
494         proto_tree_add_boolean(tree, hf_server_type_dialin, 
495                 tvb, offset, 4, flags);
496         proto_tree_add_boolean(tree, hf_server_type_xenix, 
497                 tvb, offset, 4, flags);
498         proto_tree_add_boolean(tree, hf_server_type_ntw, 
499                 tvb, offset, 4, flags);
500         proto_tree_add_boolean(tree, hf_server_type_wfw, 
501                 tvb, offset, 4, flags);
502         proto_tree_add_boolean(tree, hf_server_type_nts, 
503                 tvb, offset, 4, flags);
504         proto_tree_add_boolean(tree, hf_server_type_potentialb, 
505                 tvb, offset, 4, flags);
506         proto_tree_add_boolean(tree, hf_server_type_backupb, 
507                 tvb, offset, 4, flags);
508         proto_tree_add_boolean(tree, hf_server_type_masterb, 
509                 tvb, offset, 4, flags);
510         proto_tree_add_boolean(tree, hf_server_type_domainmasterb, 
511                 tvb, offset, 4, flags);
512         proto_tree_add_boolean(tree, hf_server_type_osf, 
513                 tvb, offset, 4, flags);
514         proto_tree_add_boolean(tree, hf_server_type_vms, 
515                 tvb, offset, 4, flags);
516         proto_tree_add_boolean(tree, hf_server_type_w95, 
517                 tvb, offset, 4, flags);
518         proto_tree_add_boolean(tree, hf_server_type_local, 
519                 tvb, offset, 4, flags);
520         proto_tree_add_boolean(tree, hf_server_type_domainenum, 
521                 tvb, offset, 4, flags);
522
523 }
524
525
526 gboolean
527 dissect_mailslot_browse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
528 {
529         int offset = 0;
530         guint8 cmd;
531         proto_tree *tree = NULL;
532         proto_item *item = NULL;
533         guint32 periodicity;
534         char host_name[17];
535         guint namelen;
536         guint8 server_count;
537         int i;
538         guint32 uptime;
539
540         if (!proto_is_protocol_enabled(proto_smb_browse)) {
541                 return FALSE;
542         }
543
544         pinfo->current_proto = "BROWSER";
545
546         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
547                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BROWSER");
548         }
549         if (check_col(pinfo->cinfo, COL_INFO)) {
550                 col_clear(pinfo->cinfo, COL_INFO);
551         }
552
553         cmd = tvb_get_guint8(tvb, offset);
554
555         if (check_col(pinfo->cinfo, COL_INFO)) {
556                 /* Put in something, and replace it later */
557                 col_set_str(pinfo->cinfo, COL_INFO, val_to_str(cmd, commands, "Unknown command:0x%02x"));
558         }
559
560
561         if (parent_tree) {
562                 item = proto_tree_add_item(parent_tree, proto_smb_browse, tvb, offset, -1, TRUE);
563
564                 tree = proto_item_add_subtree(item, ett_browse);
565         }
566
567         /* command */
568         proto_tree_add_uint(tree, hf_command, tvb, offset, 1, cmd);
569         offset += 1;
570
571         switch (cmd) {
572         case BROWSE_DOMAIN_ANNOUNCEMENT:
573         case BROWSE_LOCAL_MASTER_ANNOUNCEMENT:
574         case BROWSE_HOST_ANNOUNCE:
575                 /* update count */
576                 proto_tree_add_item(tree, hf_update_count, tvb, offset, 1, TRUE);
577                 offset += 1;
578
579                 /* periodicity (in milliseconds) */
580                 periodicity = tvb_get_letohl(tvb, offset);
581                 proto_tree_add_uint_format(tree, hf_periodicity, tvb, offset, 4,
582                     periodicity,
583                     "Update Periodicity: %s",
584                     time_msecs_to_str(periodicity));
585                 offset += 4;
586
587                 /* server name */
588                 tvb_get_nstringz0(tvb, offset, 16, host_name);
589                 if (check_col(pinfo->cinfo, COL_INFO)) {
590                         col_append_fstr(pinfo->cinfo, COL_INFO, " %s", host_name);
591                 }
592                 proto_tree_add_string_format(tree, hf_server_name,
593                         tvb, offset, 16,
594                         host_name,
595                         (cmd==BROWSE_DOMAIN_ANNOUNCEMENT)?
596                                 "Domain/Workgroup: %s":
597                                 "Host Name: %s", 
598                         host_name);
599                 offset += 16;
600
601                 /* OS major version */
602                 proto_tree_add_item(tree, hf_os_major, tvb, offset, 1, TRUE);
603                 offset += 1;
604
605                 /* OS minor version */
606                 proto_tree_add_item(tree, hf_os_minor, tvb, offset, 1, TRUE);
607                 offset += 1;
608
609                 /* server type flags */
610                 dissect_smb_server_type_flags(tvb, pinfo, tree, offset, TRUE);
611                 offset += 4;
612
613                 if (cmd == BROWSE_DOMAIN_ANNOUNCEMENT) {
614                         /*
615                          * Network Monitor claims this is a "Comment
616                          * Pointer".  I don't believe it.
617                          *
618                          * It's not a browser protocol major/minor
619                          * version number, and signature constant,
620                          * however.
621                          */
622                         proto_tree_add_text(tree, tvb, offset, 4,
623                             "Mysterious Field: 0x%08x",
624                             tvb_get_letohl(tvb, offset));
625                         offset += 4;
626                 } else {
627                         /* browser protocol major version */
628                         proto_tree_add_item(tree, hf_proto_major, tvb, offset, 1, TRUE);
629                         offset += 1;
630
631                         /* browser protocol minor version */
632                         proto_tree_add_item(tree, hf_proto_minor, tvb, offset, 1, TRUE);
633                         offset += 1;
634
635                         /* signature constant */
636                         proto_tree_add_item(tree, hf_sig_const, tvb, offset, 2, TRUE);
637                         offset += 2;
638                 }
639
640                 /* master browser server name or server comment */
641                 namelen = tvb_strsize(tvb, offset);
642                 proto_tree_add_item(tree,
643                         (cmd==BROWSE_DOMAIN_ANNOUNCEMENT)?
644                             hf_mb_server_name : hf_server_comment,
645                         tvb, offset, namelen, TRUE);
646                 offset += namelen;
647                 break;
648
649         case BROWSE_REQUEST_ANNOUNCE:
650                 /* unused/unknown flags */
651                 proto_tree_add_item(tree, hf_unused_flags,
652                         tvb, offset, 1, TRUE);
653                 offset += 1;
654
655                 /* name of computer to which to send reply */
656                 namelen = tvb_strsize(tvb, offset);
657                 proto_tree_add_item(tree, hf_response_computer_name, 
658                         tvb, offset, namelen, TRUE);
659                 offset += namelen;
660                 break;
661
662         case BROWSE_ELECTION_REQUEST:
663                 /* election version */
664                 proto_tree_add_item(tree, hf_election_version, tvb, offset, 1, TRUE);
665                 offset += 1;
666
667                 /* criterion */
668                 dissect_election_criterion(tvb, pinfo, tree, offset);
669                 offset += 4;
670
671                 /* server uptime */
672                 uptime = tvb_get_letohl(tvb, offset);
673                 proto_tree_add_uint_format(tree, hf_server_uptime,
674                     tvb, offset, 4, uptime,
675                     "Uptime: %s",
676                     time_msecs_to_str(uptime));
677                 offset += 4;
678
679                 /* next 4 bytes must be zero */
680                 offset += 4;
681
682                 /* server name */
683                 namelen = tvb_strsize(tvb, offset);
684                 proto_tree_add_item(tree, hf_server_name, 
685                         tvb, offset, namelen, TRUE);
686                 offset += namelen;
687                 break;
688
689         case BROWSE_BACKUP_LIST_REQUEST:
690                 /* backup list requested count */
691                 proto_tree_add_item(tree, hf_backup_count, tvb, offset, 1, TRUE);
692                 offset += 1;
693
694                 /* backup requested token */
695                 proto_tree_add_item(tree, hf_backup_token, tvb, offset, 4, TRUE);
696                 offset += 4;
697                 break;
698
699         case BROWSE_BACKUP_LIST_RESPONSE:
700                 /* backup list requested count */
701                 server_count = tvb_get_guint8(tvb, offset);
702                 proto_tree_add_uint(tree, hf_backup_count, tvb, offset, 1,
703                     server_count);
704                 offset += 1;
705
706                 /* backup requested token */
707                 proto_tree_add_item(tree, hf_backup_token, tvb, offset, 4, TRUE);
708                 offset += 4;
709
710                 /* backup server names */
711                 for (i = 0; i < server_count; i++) {
712                         namelen = tvb_strsize(tvb, offset);
713                         proto_tree_add_item(tree, hf_backup_server, 
714                                 tvb, offset, namelen, TRUE);
715                         offset += namelen;
716                 }
717                 break;
718
719         case BROWSE_MASTER_ANNOUNCEMENT:
720                 /* master browser server name */
721                 namelen = tvb_strsize(tvb, offset);
722                 proto_tree_add_item(tree, hf_mb_server_name, 
723                         tvb, offset, namelen, TRUE);
724                 offset += namelen;
725                 break;
726
727         case BROWSE_BECOME_BACKUP:
728                 /* name of browser to promote */
729                 namelen = tvb_strsize(tvb, offset);
730                 proto_tree_add_item(tree, hf_browser_to_promote, 
731                         tvb, offset, namelen, TRUE);
732                 offset += namelen;
733                 break;
734         }
735
736         return TRUE;
737 }
738
739 /*
740  * It appears that browser announcements sent to \MAILSLOT\LANMAN aren't
741  * the same as browser announcements sent to \MAILSLOT\BROWSE.
742  * Was that an older version of the protocol?
743  *
744  * The document at
745  *
746  *      http://www.samba.org/samba/ftp/specs/brow_rev.txt
747  *
748  * gives both formats of host announcement packets, saying that
749  * "[The first] format seems wrong", that one being what appears to
750  * show up in \MAILSLOT\LANMAN packets, and that "[The second one]
751  * may be better", that one being what appears to show up in
752  * \MAILSLOT\BROWSE packets.
753  *
754  * XXX - what other browser packets go out to that mailslot?
755  */
756 gboolean
757 dissect_mailslot_lanman(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
758 {
759         int offset = 0;
760         guint8 cmd;
761         proto_tree *tree = NULL;
762         proto_item *item = NULL;
763         guint32 periodicity;
764         const char *host_name;
765         guint namelen;
766
767         if (!proto_is_protocol_enabled(proto_smb_browse)) {
768                 return FALSE;
769         }
770
771         pinfo->current_proto = "BROWSER";
772
773         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
774                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BROWSER");
775         }
776         if (check_col(pinfo->cinfo, COL_INFO)) {
777                 col_clear(pinfo->cinfo, COL_INFO);
778         }
779
780         cmd = tvb_get_guint8(tvb, offset);
781
782         if (check_col(pinfo->cinfo, COL_INFO)) {
783                 /* Put in something, and replace it later */
784                 col_set_str(pinfo->cinfo, COL_INFO, val_to_str(cmd, commands, "Unknown command:0x%02x"));
785         }
786
787
788         if (parent_tree) {
789                 item = proto_tree_add_item(parent_tree, proto_smb_browse, tvb, offset, -1, TRUE);
790
791                 tree = proto_item_add_subtree(item, ett_browse);
792         }
793
794         /* command */
795         proto_tree_add_uint(tree, hf_command, tvb, offset, 1, cmd);
796         offset += 1;
797
798         switch (cmd) {
799         case BROWSE_DOMAIN_ANNOUNCEMENT:
800         case BROWSE_LOCAL_MASTER_ANNOUNCEMENT:
801         case BROWSE_HOST_ANNOUNCE:
802                 /* update count */
803                 proto_tree_add_item(tree, hf_update_count, tvb, offset, 1, TRUE);
804                 offset += 1;
805
806                 /* server type flags */
807                 dissect_smb_server_type_flags(tvb, pinfo, tree, offset,
808                     hf_server_type);
809                 offset += 4;
810
811                 /* OS major version */
812                 proto_tree_add_item(tree, hf_os_major, tvb, offset, 1, TRUE);
813                 offset += 1;
814
815                 /* OS minor version */
816                 proto_tree_add_item(tree, hf_os_minor, tvb, offset, 1, TRUE);
817                 offset += 1;
818
819                 /* periodicity (in seconds; convert to milliseconds) */
820                 periodicity = tvb_get_letohs(tvb, offset)*1000;
821                 proto_tree_add_uint_format(tree, hf_periodicity, tvb, offset, 2,
822                     periodicity,
823                     "Update Periodicity: %s",
824                     time_msecs_to_str(periodicity));
825                 offset += 2;
826
827                 /* server name */
828                 namelen = tvb_strsize(tvb, offset);
829                 host_name = tvb_get_ptr(tvb, offset, namelen);
830                 if (check_col(pinfo->cinfo, COL_INFO)) {
831                         col_append_fstr(pinfo->cinfo, COL_INFO, " %s", host_name);
832                 }
833                 proto_tree_add_item(tree, hf_server_name,
834                         tvb, offset, namelen, TRUE);
835                 offset += namelen;
836
837                 /* master browser server name or server comment */
838                 namelen = tvb_strsize(tvb, offset);
839                 proto_tree_add_item(tree,
840                         (cmd==BROWSE_DOMAIN_ANNOUNCEMENT)?
841                             hf_mb_server_name : hf_server_comment,
842                         tvb, offset, namelen, TRUE);
843                 offset += namelen;
844                 break;
845         }
846
847         return TRUE;
848 }
849
850 void
851 proto_register_smb_browse(void)
852 {
853         static hf_register_info hf[] = {
854                 { &hf_command,
855                         { "Command", "browser.command", FT_UINT8, BASE_HEX,
856                         VALS(commands), 0, "Browse command opcode", HFILL }},
857
858                 { &hf_update_count,
859                         { "Update Count", "browser.update_count", FT_UINT8, BASE_DEC,
860                         NULL, 0, "Browse Update Count", HFILL }},
861
862                 { &hf_periodicity,
863                         { "Update Periodicity", "browser.period", FT_UINT32, BASE_DEC,
864                         NULL, 0, "Update Periodicity in ms", HFILL }},
865
866                 { &hf_server_name,
867                         { "Server Name", "browser.server", FT_STRING, BASE_NONE,
868                         NULL, 0, "BROWSE Server Name", HFILL }},
869
870                 { &hf_mb_server_name,
871                         { "Master Browser Server Name", "browser.mb_server", FT_STRING, BASE_NONE,
872                         NULL, 0, "BROWSE Master Browser Server Name", HFILL }},
873
874                 { &hf_os_major,
875                         { "OS Major Version", "browser.os_major", FT_UINT8, BASE_DEC,
876                         NULL, 0, "Operating System Major Version", HFILL }},
877
878                 { &hf_os_minor,
879                         { "OS Minor Version", "browser.os_minor", FT_UINT8, BASE_DEC,
880                         NULL, 0, "Operating System Minor Version", HFILL }},
881
882                 { &hf_server_type,
883                         { "Server Type", "browser.server_type", FT_UINT32, BASE_HEX,
884                         NULL, 0, "Server Type Flags", HFILL }},
885
886                 { &hf_server_type_workstation,
887                         { "Workstation", "browser.server_type.workstation", FT_BOOLEAN, 32,
888                         TFS(&tfs_workstation), 1<<SERVER_WORKSTATION, "Is This A Workstation?", HFILL }},
889
890                 { &hf_server_type_server,
891                         { "Server", "browser.server_type.server", FT_BOOLEAN, 32,
892                         TFS(&tfs_server), 1<<SERVER_SERVER, "Is This A Server?", HFILL }},
893
894                 { &hf_server_type_sql,
895                         { "SQL", "browser.server_type.sql", FT_BOOLEAN, 32,
896                         TFS(&tfs_sql), 1<<SERVER_SQL_SERVER, "Is This A SQL Server?", HFILL }},
897
898                 { &hf_server_type_domain,
899                         { "Domain Controller", "browser.server_type.domain_controller", FT_BOOLEAN, 32,
900                         TFS(&tfs_domain), 1<<SERVER_DOMAIN_CONTROLLER, "Is This A Domain Controller?", HFILL }},
901
902                 { &hf_server_type_backup,
903                         { "Backup Controller", "browser.server_type.backup_controller", FT_BOOLEAN, 32,
904                         TFS(&tfs_backup), 1<<SERVER_BACKUP_CONTROLLER, "Is This A Backup Domain Controller?", HFILL }},
905
906                 { &hf_server_type_time,
907                         { "Time Source", "browser.server_type.time", FT_BOOLEAN, 32,
908                         TFS(&tfs_time), 1<<SERVER_TIME_SOURCE, "Is This A Time Source?", HFILL }},
909
910                 { &hf_server_type_apple,
911                         { "Apple", "browser.server_type.apple", FT_BOOLEAN, 32,
912                         TFS(&tfs_apple), 1<<SERVER_APPLE_SERVER, "Is This An Apple Server ?", HFILL }},
913
914                 { &hf_server_type_novell,
915                         { "Novell", "browser.server_type.novell", FT_BOOLEAN, 32,
916                         TFS(&tfs_novell), 1<<SERVER_NOVELL_SERVER, "Is This A Novell Server?", HFILL }},
917
918                 { &hf_server_type_member,
919                         { "Member", "browser.server_type.member", FT_BOOLEAN, 32,
920                         TFS(&tfs_member), 1<<SERVER_DOMAIN_MEMBER_SERVER, "Is This A Domain Member Server?", HFILL }},
921
922                 { &hf_server_type_print,
923                         { "Print", "browser.server_type.print", FT_BOOLEAN, 32,
924                         TFS(&tfs_print), 1<<SERVER_PRINT_QUEUE_SERVER, "Is This A Print Server?", HFILL }},
925
926                 { &hf_server_type_dialin,
927                         { "Dialin", "browser.server_type.dialin", FT_BOOLEAN, 32,
928                         TFS(&tfs_dialin), 1<<SERVER_DIALIN_SERVER, "Is This A Dialin Server?", HFILL }},
929
930                 { &hf_server_type_xenix,
931                         { "Xenix", "browser.server_type.xenix", FT_BOOLEAN, 32,
932                         TFS(&tfs_xenix), 1<<SERVER_XENIX_SERVER, "Is This A Xenix Server?", HFILL }},
933
934                 { &hf_server_type_ntw,
935                         { "NT Workstation", "browser.server_type.ntw", FT_BOOLEAN, 32,
936                         TFS(&tfs_ntw), 1<<SERVER_NT_WORKSTATION, "Is This A NT Workstation?", HFILL }},
937
938                 { &hf_server_type_wfw,
939                         { "WfW", "browser.server_type.wfw", FT_BOOLEAN, 32,
940                         TFS(&tfs_wfw), 1<<SERVER_WINDOWS_FOR_WORKGROUPS, "Is This A Windows For Workgroups Server?", HFILL }},
941
942                 { &hf_server_type_nts,
943                         { "NT Server", "browser.server_type.nts", FT_BOOLEAN, 32,
944                         TFS(&tfs_nts), 1<<SERVER_NT_SERVER, "Is This A NT Server?", HFILL }},
945
946                 { &hf_server_type_potentialb,
947                         { "Potential Browser", "browser.server_type.browser.potential", FT_BOOLEAN, 32,
948                         TFS(&tfs_potentialb), 1<<SERVER_POTENTIAL_BROWSER, "Is This A Potential Browser?", HFILL }},
949
950                 { &hf_server_type_backupb,
951                         { "Backup Browser", "browser.server_type.browser.backup", FT_BOOLEAN, 32,
952                         TFS(&tfs_backupb), 1<<SERVER_BACKUP_BROWSER, "Is This A Backup Browser?", HFILL }},
953
954                 { &hf_server_type_masterb,
955                         { "Master Browser", "browser.server_type.browser.master", FT_BOOLEAN, 32,
956                         TFS(&tfs_masterb), 1<<SERVER_MASTER_BROWSER, "Is This A Master Browser?", HFILL }},
957
958                 { &hf_server_type_domainmasterb,
959                         { "Domain Master Browser", "browser.server_type.browser.domain_master", FT_BOOLEAN, 32,
960                         TFS(&tfs_domainmasterb), 1<<SERVER_DOMAIN_MASTER_BROWSER, "Is This A Domain Master Browser?", HFILL }},
961
962                 { &hf_server_type_osf,
963                         { "OSF", "browser.server_type.osf", FT_BOOLEAN, 32,
964                         TFS(&tfs_osf), 1<<SERVER_OSF, "Is This An OSF server ?", HFILL }},
965
966                 { &hf_server_type_vms,
967                         { "VMS", "browser.server_type.vms", FT_BOOLEAN, 32,
968                         TFS(&tfs_vms), 1<<SERVER_VMS, "Is This A VMS Server?", HFILL }},
969
970                 { &hf_server_type_w95,
971                         { "Windows 95+", "browser.server_type.w95", FT_BOOLEAN, 32,
972                         TFS(&tfs_w95), 1<<SERVER_WINDOWS_95, "Is This A Windows 95 or above server?", HFILL }},
973
974                 { &hf_server_type_local,
975                         { "Local", "browser.server_type.local", FT_BOOLEAN, 32,
976                         TFS(&tfs_local), 1<<SERVER_LOCAL_LIST_ONLY, "Is This A Local List Only request?", HFILL }},
977
978                 { &hf_server_type_domainenum,
979                         { "Domain Enum", "browser.server_type.domainenum", FT_BOOLEAN, 32,
980                         TFS(&tfs_domainenum), 1<<SERVER_DOMAIN_ENUM, "Is This A Domain Enum request?", HFILL }},
981
982                 { &hf_election_version,
983                         { "Election Version", "browser.election.version", FT_UINT8, BASE_DEC,
984                         NULL, 0, "Election Version", HFILL }},
985
986                 { &hf_proto_major,
987                         { "Browser Protocol Major Version", "browser.proto_major", FT_UINT8, BASE_DEC,
988                         NULL, 0, "Browser Protocol Major Version", HFILL }},
989
990                 { &hf_proto_minor,
991                         { "Browser Protocol Minor Version", "browser.proto_minor", FT_UINT8, BASE_DEC,
992                         NULL, 0, "Browser Protocol Minor Version", HFILL }},
993
994                 { &hf_sig_const,
995                         { "Signature", "browser.sig", FT_UINT16, BASE_HEX,
996                         NULL, 0, "Signature Constant", HFILL }},
997
998                 { &hf_server_comment,
999                         { "Host Comment", "browser.comment", FT_STRINGZ, BASE_NONE,
1000                         NULL, 0, "Server Comment", HFILL }},
1001
1002                 { &hf_unused_flags,
1003                         { "Unused flags", "browser.unused", FT_UINT8, BASE_HEX,
1004                         NULL, 0, "Unused/unknown flags", HFILL }},
1005
1006                 { &hf_response_computer_name,
1007                         { "Response Computer Name", "browser.response_computer_name", FT_STRINGZ, BASE_NONE,
1008                         NULL, 0, "Response Computer Name", HFILL }},
1009
1010                 { &hf_election_criteria,
1011                         { "Election Criteria", "browser.election.criteria", FT_UINT32, BASE_HEX,
1012                         NULL, 0, "Election Criteria", HFILL }},
1013
1014                 { &hf_election_desire,
1015                         { "Election Desire", "browser.election.desire", FT_UINT8, BASE_HEX,
1016                         NULL, 0, "Election Desire", HFILL }},
1017
1018                 { &hf_election_desire_flags_backup,
1019                         { "Backup", "browser.election.desire.backup", FT_BOOLEAN, 8,
1020                         TFS(&tfs_desire_backup), 1<<DESIRE_BACKUP, "Is this a backup server", HFILL }},
1021
1022                 { &hf_election_desire_flags_standby,
1023                         { "Standby", "browser.election.desire.standby", FT_BOOLEAN, 8,
1024                         TFS(&tfs_desire_standby), 1<<DESIRE_STANDBY, "Is this a standby server?", HFILL }},
1025
1026                 { &hf_election_desire_flags_master,
1027                         { "Master", "browser.election.desire.master", FT_BOOLEAN, 8,
1028                         TFS(&tfs_desire_master), 1<<DESIRE_MASTER, "Is this a master server", HFILL }},
1029
1030                 { &hf_election_desire_flags_domain_master,
1031                         { "Domain Master", "browser.election.desire.domain_master", FT_BOOLEAN, 8,
1032                         TFS(&tfs_desire_domain_master), 1<<DESIRE_DOMAIN_MASTER, "Is this a domain master", HFILL }},
1033
1034                 { &hf_election_desire_flags_wins,
1035                         { "WINS", "browser.election.desire.wins", FT_BOOLEAN, 8,
1036                         TFS(&tfs_desire_wins), 1<<DESIRE_WINS, "Is this a WINS server", HFILL }},
1037
1038                 { &hf_election_desire_flags_nt,
1039                         { "NT", "browser.election.desire.nt", FT_BOOLEAN, 8,
1040                         TFS(&tfs_desire_nt), 1<<DESIRE_NT, "Is this a NT server", HFILL }},
1041
1042                 { &hf_election_revision,
1043                         { "Election Revision", "browser.election.revision", FT_UINT16, BASE_DEC,
1044                         NULL, 0, "Election Revision", HFILL }},
1045
1046                 { &hf_election_os,
1047                         { "Election OS", "browser.election.os", FT_UINT8, BASE_HEX,
1048                         NULL, 0, "Election OS", HFILL }},
1049
1050                 { &hf_election_os_wfw,
1051                         { "WfW", "browser.election.os.wfw", FT_BOOLEAN, 8,
1052                         TFS(&tfs_os_wfw), 1<<OS_WFW, "Is this a WfW host?", HFILL }},
1053
1054                 { &hf_election_os_ntw,
1055                         { "NT Workstation", "browser.election.os.ntw", FT_BOOLEAN, 8,
1056                         TFS(&tfs_os_ntw), 1<<OS_NTW, "Is this a NT Workstation?", HFILL }},
1057
1058                 { &hf_election_os_nts,
1059                         { "NT Server", "browser.election.os.nts", FT_BOOLEAN, 8,
1060                         TFS(&tfs_os_nts), 1<<OS_NTS, "Is this a NT Server?", HFILL }},
1061
1062                 { &hf_server_uptime,
1063                         { "Uptime", "browser.uptime", FT_UINT32, BASE_DEC,
1064                         NULL, 0, "Server uptime in ms", HFILL }},
1065
1066                 { &hf_backup_count,
1067                         { "Backup List Requested Count", "browser.backup.count", FT_UINT8, BASE_DEC,
1068                         NULL, 0, "Backup list requested count", HFILL }},
1069
1070                 { &hf_backup_token,
1071                         { "Backup Request Token", "browser.backup.token", FT_UINT32, BASE_DEC,
1072                         NULL, 0, "Backup requested/response token", HFILL }},
1073
1074                 { &hf_backup_server,
1075                         { "Backup Server", "browser.backup.server", FT_STRING, BASE_NONE,
1076                         NULL, 0, "Backup Server Name", HFILL }},
1077
1078                 { &hf_browser_to_promote,
1079                         { "Browser to Promote", "browser.browser_to_promote", FT_STRINGZ, BASE_NONE,
1080                         NULL, 0, "Browser to Promote", HFILL }},
1081
1082         };
1083
1084         static gint *ett[] = {
1085                 &ett_browse,
1086                 &ett_browse_flags,
1087                 &ett_browse_election_criteria,
1088                 &ett_browse_election_os,
1089                 &ett_browse_election_desire
1090         };
1091
1092         proto_smb_browse = proto_register_protocol("Microsoft Windows Browser Protocol",
1093             "BROWSER", "browser");
1094
1095         proto_register_field_array(proto_smb_browse, hf, array_length(hf));
1096         proto_register_subtree_array(ett, array_length(ett));          
1097 }