Fixed typo in dsrole basic domain info tree.
[metze/wireshark/wip.git] / packet-dcerpc-lsa-ds.c
1 /* packet-dcerpc-lsa-ds.c
2  * Routines for SMB \PIPE\lsarpc packet disassembly
3  * Copyright 2002, Tim Potter <tpot@samba.org>
4  * Copyright 2002, Jim McDonough <jmcd@samba.org>
5  *
6  * $Id: packet-dcerpc-lsa-ds.c,v 1.5 2002/11/19 05:28:16 tpot Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <glib.h>
32 #include <string.h>
33
34 #include <epan/packet.h>
35 #include "packet-dcerpc.h"
36 #include "packet-dcerpc-nt.h"
37 #include "smb.h"
38
39 #define LSA_DS_DSROLEGETDOMINFO 0x0000
40
41 #define LSA_DS_DSROLE_BASIC_INFO 0x0001
42 #define LSA_DS_DSROLE_UPGRADE_STATUS 0x0002
43 #define LSA_DS_DSROLE_OP_STATUS 0x0003
44
45 static int proto_dcerpc_lsa_ds = -1;
46
47 static int hf_lsa_ds_opnum = -1;
48 static int hf_lsa_ds_dominfo_level = -1;
49 static int hf_lsa_ds_machine_role = -1;
50 static int hf_lsa_ds_dominfo_flags = -1;
51 static int hf_lsa_ds_dominfo_netb_name = -1;
52 static int hf_lsa_ds_dominfo_dns_name = -1;
53 static int hf_lsa_ds_dominfo_forest_name = -1;
54 static int hf_lsa_ds_upgrade_state = -1;
55 static int hf_lsa_ds_previous_role = -1;
56 static int hf_lsa_ds_op_status = -1;
57 static int hf_lsa_ds_rc = -1;
58
59 static gint ett_dcerpc_lsa_ds = -1;
60 static gint ett_lsa_ds_domain_info = -1;
61 static gint ett_lsa_ds_basic_domain_info = -1;
62 static gint ett_lsa_ds_upgrade_status = -1;
63 static gint ett_lsa_ds_op_status = -1;
64
65 static int
66 lsa_ds_dissect_DSROLE_BASIC_INFO(tvbuff_t *tvb, int offset,
67         packet_info *pinfo, proto_tree *parent_tree, char *drep)
68 {
69         proto_item *item=NULL;
70         proto_tree *tree=NULL;
71         int old_offset=offset;
72
73         if(parent_tree){
74                 item = proto_tree_add_text(parent_tree, tvb, offset, -1,
75                         "DSROLE_BASIC_DOMAIN_INFO:");
76                 tree = proto_item_add_subtree(item, 
77                                               ett_lsa_ds_basic_domain_info);
78         }
79
80         /* role */
81         offset = dissect_ndr_uint16(tvb, offset, pinfo, tree, drep,
82                                     hf_lsa_ds_machine_role, 0);
83
84         /* flags */
85         offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep,
86                                     hf_lsa_ds_dominfo_flags, 0);
87
88         offset = dissect_ndr_pointer(tvb, offset, pinfo, tree, drep,
89                 dissect_ndr_nt_UNICODE_STRING_str, NDR_POINTER_UNIQUE,
90                 "NetBIOS domain name pointer", hf_lsa_ds_dominfo_netb_name, 0);
91         offset = dissect_ndr_pointer(tvb, offset, pinfo, tree, drep,
92                 dissect_ndr_nt_UNICODE_STRING_str, NDR_POINTER_UNIQUE,
93                 "DNS domain pointer", hf_lsa_ds_dominfo_dns_name, 0);
94         offset = dissect_ndr_pointer(tvb, offset, pinfo, tree, drep,
95                 dissect_ndr_nt_UNICODE_STRING_str, NDR_POINTER_UNIQUE,
96                 "DNS forest name pointer", hf_lsa_ds_dominfo_forest_name, 0);
97
98         /* GUID */
99         offset = dissect_nt_GUID(tvb, offset, pinfo, tree, drep);
100
101         proto_item_set_len(item, offset-old_offset);
102         return offset;
103 }
104
105 static int 
106 lsa_ds_dissect_DSROLE_UPGRADE_STATUS(tvbuff_t *tvb, int offset,
107                                      packet_info *pinfo, 
108                                      proto_tree *parent_tree, char *drep)
109 {
110         proto_item *item=NULL;
111         proto_tree *tree=NULL;
112         int old_offset=offset;
113
114         if(parent_tree){
115                 item = proto_tree_add_text(parent_tree, tvb, offset, -1,
116                         "DSROLE_UPGRADE_STATUS:");
117                 tree = proto_item_add_subtree(item, 
118                                               ett_lsa_ds_upgrade_status);
119         }
120
121         offset = dissect_ndr_uint32 (tvb, offset, pinfo, tree, drep,
122                                      hf_lsa_ds_upgrade_state, NULL);
123         offset = dissect_ndr_uint16 (tvb, offset, pinfo, tree, drep,
124                                      hf_lsa_ds_previous_role, NULL);
125         proto_item_set_len(item, offset-old_offset);
126
127         return offset;
128 }
129
130 static int
131 lsa_ds_dissect_DSROLE_OP_STATUS(tvbuff_t *tvb, int offset,
132                                      packet_info *pinfo, 
133                                      proto_tree *parent_tree, char *drep)
134 {
135         proto_item *item=NULL;
136         proto_tree *tree=NULL;
137         int old_offset=offset;
138
139         if(parent_tree){
140                 item = proto_tree_add_text(parent_tree, tvb, offset, -1,
141                         "DSROLE_OP_STATUS:");
142                 tree = proto_item_add_subtree(item, 
143                                               ett_lsa_ds_op_status);
144         }
145         offset = dissect_ndr_uint16 (tvb, offset, pinfo, tree, drep,
146                                      hf_lsa_ds_op_status, NULL);
147         proto_item_set_len(item, offset-old_offset);
148
149         return offset;
150 }
151         
152 static int
153 lsa_ds_dissect_DS_DOMINFO_CTR(tvbuff_t *tvb, int offset,
154         packet_info *pinfo, proto_tree *parent_tree, char *drep)
155 {
156         proto_item *item=NULL;
157         proto_tree *tree=NULL;
158         int old_offset=offset;
159         guint16 level;
160
161         if(parent_tree){
162                 item = proto_tree_add_text(parent_tree, tvb, offset, -1,
163                         "DOMAIN_INFO:");
164                 tree = proto_item_add_subtree(item, ett_lsa_ds_domain_info);
165         }
166
167         offset = dissect_ndr_uint16 (tvb, offset, pinfo, tree, drep,
168                                      hf_lsa_ds_dominfo_level, &level);
169
170         switch(level){
171         case LSA_DS_DSROLE_BASIC_INFO:
172                 offset = lsa_ds_dissect_DSROLE_BASIC_INFO(
173                         tvb, offset, pinfo, tree, drep);
174                 break;
175         case LSA_DS_DSROLE_UPGRADE_STATUS:
176                 offset = lsa_ds_dissect_DSROLE_UPGRADE_STATUS(
177                         tvb, offset, pinfo, tree, drep);
178                 break;
179         case LSA_DS_DSROLE_OP_STATUS:
180                 offset = lsa_ds_dissect_DSROLE_OP_STATUS(
181                         tvb, offset, pinfo, tree, drep);
182                 break;
183         }
184         proto_item_set_len(item, offset-old_offset);
185
186         return offset;
187 }
188
189 static int
190 lsa_ds_dissect_role_get_dom_info_rqst(tvbuff_t *tvb, int offset,
191         packet_info *pinfo, proto_tree *tree, char *drep)
192 {
193         offset = dissect_ndr_uint16(tvb, offset, pinfo, tree, drep,
194                                     hf_lsa_ds_dominfo_level, NULL);
195         return offset;
196 }
197
198 static int
199 lsa_ds_dissect_role_get_dom_info_reply(tvbuff_t *tvb, int offset,
200         packet_info *pinfo, proto_tree *tree, char *drep)
201 {
202         offset = dissect_ndr_pointer(tvb, offset, pinfo, tree, drep,
203                 lsa_ds_dissect_DS_DOMINFO_CTR, NDR_POINTER_UNIQUE,
204                 "DOMAIN_INFORMATION pointer", -1, 0);
205
206         offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, drep,
207                 hf_lsa_ds_rc, NULL);
208
209         return offset;
210 }
211
212
213 static const value_string lsa_ds_opnum_vals[] = {
214         { LSA_DS_DSROLEGETDOMINFO, "DsRoleGetDomInfo" },
215         { 0, NULL }
216 };
217
218 static const value_string lsa_ds_dominfo_levels[] = {
219         { LSA_DS_DSROLE_BASIC_INFO, "DsRoleBasicInfo"},
220         { LSA_DS_DSROLE_UPGRADE_STATUS, "DsRoleUpgradeStatus"},
221         { LSA_DS_DSROLE_OP_STATUS, "DsRoleOpStatus"},
222         { 0, NULL }
223 };
224
225 static const value_string lsa_ds_upgrade_vals[] = {
226         { 0, "Not currently upgrading"},
227         { 1, "Upgrade in progress"},
228         { 0, NULL }
229 };
230
231 static const value_string lsa_ds_previous_roles[] = {
232         { 0, "Unknown state" },
233         { 1, "Primary" },
234         { 2, "Backup" }
235 };
236
237 static const value_string lsa_ds_op_states[] = {
238         { 0, "Idle" },
239         { 1, "Active" },
240         { 2, "Needs reboot" }
241 };
242
243 void
244 proto_register_dcerpc_lsa_ds(void)
245 {
246         static hf_register_info hf[] = {
247
248         { &hf_lsa_ds_opnum,
249           { "Operation", "ls_ads.opnum", FT_UINT16, BASE_DEC,
250             VALS(lsa_ds_opnum_vals), 0x0, "Operation", HFILL }},
251         
252         { &hf_lsa_ds_dominfo_level,
253           { "Level", "lsa_ds.dominfo.level", FT_UINT16, BASE_DEC,
254             VALS(lsa_ds_dominfo_levels), 0x0, 
255             "Information level of requested data", HFILL }},
256
257         { &hf_lsa_ds_machine_role,
258           { "Machine role", "lsa_ds.role", FT_UINT16, BASE_HEX,
259             NULL, 0x0, "Role of machine in domain", HFILL}},
260
261         { &hf_lsa_ds_dominfo_flags,
262           { "Flags", "lsa_ds.dominfo.flags", FT_UINT32, BASE_HEX,
263             NULL, 0x0, "Machine flags", HFILL }},
264
265         { &hf_lsa_ds_dominfo_netb_name,
266           { "Netbios name", "lsa_ds.dominfo.nbname", FT_STRING, BASE_NONE,
267             NULL, 0x0, "Netbios Domain Name", HFILL}},
268
269         { &hf_lsa_ds_dominfo_dns_name,
270           { "DNS name", "lsa_ds.dominfo.dnsname", FT_STRING, BASE_NONE,
271             NULL, 0x0, "DNS Domain Name", HFILL}},
272
273         { &hf_lsa_ds_dominfo_forest_name,
274           { "Forest name", "lsa_ds.dominfo.forest", FT_STRING, BASE_NONE,
275             NULL, 0x0, "DNS Forest Name", HFILL}},
276
277         { &hf_lsa_ds_upgrade_state,
278           { "Upgrading", "ls_ads.upgrading", FT_UINT32, BASE_DEC,
279             VALS(lsa_ds_upgrade_vals), 0x0, "Upgrade State", HFILL }},
280         
281         { &hf_lsa_ds_previous_role,
282           { "Previous role", "ls_ads.upgrading", FT_UINT16, BASE_DEC,
283             VALS(lsa_ds_previous_roles), 0x0, 
284             "Previous server role before upgrade", HFILL }},
285
286         { &hf_lsa_ds_op_status,
287           { "Operational status", "ls_ads.op_status", FT_UINT16, BASE_DEC,
288             VALS(lsa_ds_op_states), 0x0, 
289             "Current operational status", HFILL }},
290         
291         { &hf_lsa_ds_rc,
292           { "Return code", "lsa_ds.rc", FT_UINT32, BASE_HEX,
293           VALS (NT_errors), 0x0, "LSA_DS return status code", HFILL }},
294         };
295
296         static gint *ett[] = {
297                 &ett_dcerpc_lsa_ds,
298                 &ett_lsa_ds_domain_info,
299                 &ett_lsa_ds_basic_domain_info,
300                 &ett_lsa_ds_upgrade_status,
301                 &ett_lsa_ds_op_status
302         };
303
304         proto_dcerpc_lsa_ds = proto_register_protocol(
305                 "Microsoft Local Security Architecture (Directory Services)", 
306                 "LSA_DS", "lsa_ds");
307         proto_register_field_array(proto_dcerpc_lsa_ds, hf, array_length(hf));
308         proto_register_subtree_array(ett, array_length(ett));
309 }
310
311 /* Protocol handoff */
312
313 static e_uuid_t uuid_dcerpc_lsa_ds = {
314         0x3919286a, 0xb10c, 0x11d0,
315         { 0x9b, 0xa8, 0x00, 0xc0, 0x4f, 0xd9, 0x2e, 0xf5}
316 };
317
318 static guint16 ver_dcerpc_lsa_ds = 0;
319
320 static dcerpc_sub_dissector lsa_ds_dissectors[] = {
321         { LSA_DS_DSROLEGETDOMINFO, "DsRoleGetDomInfo", 
322           lsa_ds_dissect_role_get_dom_info_rqst, 
323           lsa_ds_dissect_role_get_dom_info_reply },
324         { 0, NULL, NULL, NULL },
325 };
326
327 void
328 proto_reg_handoff_dcerpc_lsa_ds(void)
329 {
330         /* Register protocol as dcerpc */
331
332         dcerpc_init_uuid(proto_dcerpc_lsa_ds, ett_dcerpc_lsa_ds, 
333                          &uuid_dcerpc_lsa_ds, ver_dcerpc_lsa_ds, 
334                          lsa_ds_dissectors, -1);
335 }