From Greg Morris:
[obnox/wireshark/wip.git] / epan / dissectors / packet-ncp-nmas.c
1 /* packet-ncp-nmas.c
2  * Routines for Novell Modular Authentication Service
3  * Greg Morris <gmorris@novell.com>
4  * Copyright (c) Novell, Inc. 2002-2004
5  *
6  * $Id$
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 <string.h>
32 #include <glib.h>
33 #include <epan/packet.h>
34 #include <epan/prefs.h>
35 #include "packet-ncp-int.h"
36 #include "packet-ncp-nmas.h"
37
38 static gint ett_nmas = -1;
39
40 static int proto_nmas = -1;
41 static int hf_func = -1;
42 static int hf_subfunc = -1;
43 static int hf_ping_version = -1;
44 static int hf_ping_flags = -1;
45 static int hf_frag_handle = -1;
46 static int hf_length = -1;
47 static int hf_subverb = -1;
48 static int hf_tree = -1;
49 static int hf_user = -1;
50 static int hf_nmas_version = -1;
51 static int hf_msg_version = -1;
52 static int hf_session_ident = -1;
53 static int hf_msg_verb = -1;
54 static int hf_attribute = -1;
55 static int hf_clearence = -1;
56 static int hf_login_sequence = -1;
57 static int hf_opaque = -1;
58 static int hf_data = -1;
59 static int hf_return_code = -1;
60 static int hf_lsm_verb = -1;
61 static int hf_squeue_bytes = -1;
62 static int hf_cqueue_bytes = -1;
63 static int hf_num_creds = -1;
64 static int hf_cred_type = -1;
65 static int hf_login_state = -1;
66 static int hf_enc_cred = -1;
67 static int hf_enc_data = -1;
68 static int hf_reply_buffer_size = -1;
69 static int hf_encrypt_error = -1;
70
71 static const value_string nmas_func_enum[] = {
72     { 0x01, "Ping" },
73     { 0x02, "Fragment" },
74     { 0x03, "Abort" },
75     { 0,    NULL }
76 };
77
78 static const value_string nmas_subverb_enum[] = {
79     { 0, "Fragmented Ping" },
80     { 2, "Client Put Data" },
81     { 4, "Client Get Data" },
82     { 6, "Client Get User NDS Credentials" },
83     { 8, "Login Store Management" },
84     { 10, "Writable Object Check" },
85     { 1242, "Message Handler" },
86     { 0,          NULL }
87 };
88
89 static const value_string nmas_msgverb_enum[] = {
90     { 1, "Echo Data" },
91     { 3, "Start Session" },
92     { 5, "Client Write Data" },
93     { 7, "Client Read Data" },
94     { 9, "End Session" },
95     { 0,          NULL }
96 };
97
98 static const value_string nmas_attribute_enum[] = {
99     { 1, "User Name" },
100     { 2, "Tree Name" },
101     { 4, "Clearence" },
102     { 11, "Login Sequence" },
103     { 0,          NULL }
104 };
105
106 static const value_string nmas_lsmverb_enum[] = {
107     { 1, "Put Login Configuration" },
108     { 2, "Get Login Configuration" },
109     { 3, "Get All Configurations" },
110     { 4, "Delete Login Configuration" },
111     { 5, "Put Login Secret" },
112     { 6, "Delete Login Secret" },
113     { 7, "Set Password" },
114     { 8, "Change Password" },
115     { 9, "Delete Password" },
116     { 10, "Get Password" },
117     { 11, "Check Password Policy" },
118     { 0,          NULL }
119 };
120
121 static const value_string nmas_errors_enum[] = {
122     { 0xFFFFF9A1, "(-1631) FRAGMENT FAILURE" },
123     { 0xFFFFF9A0, "(-1632) BAD REQUEST SYNTAX" },
124     { 0xFFFFF99F, "(-1633) BUFFER OVERFLOW" },
125     { 0xFFFFF99E, "(-1634) SYSTEM RESOURCES" },
126     { 0xFFFFF99D, "(-1635) INSUFFICIENT MEMORY" },
127     { 0xFFFFF99C, "(-1636) NOT SUPPORTED" },
128     { 0xFFFFF99B, "(-1637) BUFFER UNDERFLOW" },
129     { 0xFFFFF99A, "(-1638) NOT FOUND" },
130     { 0xFFFFF999, "(-1639) INVALID OPERATION" },
131     { 0xFFFFF998, "(-1640) ASN1 DECODE" },
132     { 0xFFFFF997, "(-1641) ASN1 ENCODE" },
133     { 0xFFFFF996, "(-1642) LOGIN FAILED" },
134     { 0xFFFFF995, "(-1643) INVALID PARAMETER" },
135     { 0xFFFFF994, "(-1644) TIMED OUT RECOVERABLE" },
136     { 0xFFFFF993, "(-1645) TIMED OUT NOT RECOVERABLE" },
137     { 0xFFFFF992, "(-1646) TIMED OUT UNKNOWN" },
138     { 0xFFFFF991, "(-1647) AUTHORIZATION FAILURE" },
139     { 0xFFFFF990, "(-1648) INVALID DISTINGUSHED NAME" },
140     { 0xFFFFF98F, "(-1649) CANNOT RESOLVE DISTINGUISHED NAME" },
141     { 0xFFFFF98E, "(-1650) CANNOT RESOLVE CONNECTION" },
142     { 0xFFFFF98D, "(-1651) NO CRYPTOGRAPHY" },
143     { 0xFFFFF98C, "(-1652) INVALID VERSION" },
144     { 0xFFFFF98B, "(-1653) SYNC NEEDED" },
145     { 0xFFFFF98A, "(-1654) PROTOCOL STATE" },
146     { 0xFFFFF989, "(-1655) INVALID HANDLE" },
147     { 0xFFFFF988, "(-1656) INVALID METHOD" },
148     { 0xFFFFF987, "(-1657) DEVELOPMENT VERSION" },
149     { 0xFFFFF986, "(-1658) MISSING KEY" },
150     { 0xFFFFF985, "(-1659) ACCESS NOT ALLOWED" },
151     { 0xFFFFF984, "(-1660) SEQUENCE NOT FOUND" },
152     { 0xFFFFF983, "(-1661) CLEARANCE NOT FOUND" },
153     { 0xFFFFF982, "(-1662) LOGIN SERVER METHOD NOT FOUND" },
154     { 0xFFFFF981, "(-1663) LOGIN CLIENT METHOD NOT FOUND" },
155     { 0xFFFFF980, "(-1664) SERVER NOT FOUND" },
156     { 0xFFFFF97F, "(-1665) LOGIN ATTRIBUTE NOT FOUND" },
157     { 0xFFFFF97E, "(-1666) LEGACY INVALID PASSWORD" },
158     { 0xFFFFF97D, "(-1667) ACCOUNT DISABLED" },
159     { 0xFFFFF97C, "(-1668) ACCOUNT LOCKED" },
160     { 0xFFFFF97B, "(-1669) ADDRESS RESTRICTION" },
161     { 0xFFFFF97A, "(-1670) CONNECTION CLEARED" },
162     { 0xFFFFF979, "(-1671) TIME RESTRICTION" },
163     { 0xFFFFF978, "(-1672) SHORT TERM SECRET" },
164     { 0xFFFFF977, "(-1673) NO NMAS ON TREE" },
165     { 0xFFFFF976, "(-1674) NO NMAS ON SERVER" },
166     { 0xFFFFF975, "(-1675) REQUEST CHALLENGED" },
167     { 0xFFFFF974, "(-1676) LOGIN CANCELED" },
168     { 0xFFFFF973, "(-1677) LOCAL CREDENTIAL STORE" },
169     { 0xFFFFF972, "(-1678) REMOTE CREDENTIAL STORE" },
170     { 0xFFFFF971, "(-1679) SMC NICM" },
171     { 0xFFFFF970, "(-1680) SEQUENCE NOT AUTHORIZED" },
172     { 0xFFFFF96F, "(-1681) TRANSPORT" },
173     { 0xFFFFF96E, "(-1682) CRYPTO FAILED INIT" },
174     { 0xFFFFF96D, "(-1683) DOUBLEBYTE FAILED INIT" },
175     { 0xFFFFF96C, "(-1684) CODEPAGE FAILED INIT" },
176     { 0xFFFFF96B, "(-1685) UNICODE FAILED INIT" },
177     { 0xFFFFF96A, "(-1686) DLL FAILED LOADING" },
178     { 0xFFFFF969, "(-1687) EVALUATION VERSION WARNING" },
179     { 0xFFFFF968, "(-1688) CONCURRENT LOGIN" },
180     { 0xFFFFF969, "(-1689) THREAD CREATE" },
181     { 0xFFFFF96A, "(-1690) SECURE CHANNEL REQUIRED" },
182     { 0xFFFFF96B, "(-1691) NO DEFAULT USER SEQUENCE" },
183     { 0xFFFFF96C, "(-1692) NO TREENAME" },
184     { 0xFFFFF96D, "(-1693) MECHANISM NOT FOUND" },
185     { 0,          NULL }
186 };
187
188 #if 0
189 static int
190 align_4(tvbuff_t *tvb, int aoffset)
191 {
192        if(tvb_length_remaining(tvb, aoffset) > 4 )
193        {
194                 return (aoffset%4);
195        }
196        return 0;
197 }
198 #endif
199
200 static int
201 nmas_string(tvbuff_t* tvb, int hfinfo, proto_tree *nmas_tree, int offset, gboolean little)
202 {
203         int     foffset = offset;
204         guint32 str_length;
205         char    buffer[1024];
206         guint32 i;
207         guint16 c_char;
208         guint32 length_remaining = 0;
209         
210         if (little) {
211             str_length = tvb_get_letohl(tvb, foffset);
212         }
213         else
214         {
215             str_length = tvb_get_ntohl(tvb, foffset);
216         }
217         foffset += 4;
218         if(str_length > 1024)
219         {
220                 proto_tree_add_string(nmas_tree, hfinfo, tvb, foffset,
221                     length_remaining + 4, "<String too long to process>");
222                 foffset += length_remaining;
223                 return foffset;
224         }
225         if(str_length == 0)
226         {
227             proto_tree_add_string(nmas_tree, hfinfo, tvb, offset,
228                 4, "<Not Specified>");
229             return foffset;
230         }
231         /*
232          * XXX - other than the special-casing of null bytes,
233          * we could just use "proto_tree_add_item()", as for
234          * FT_STRING, FT_STRINGZ, and FT_UINT_STRING fields,
235          * the display representation of an item is generated
236          * using "format_text()", so it handles non-printable
237          * characters.
238          */
239         for ( i = 0; i < str_length; i++ )
240         {
241                 c_char = tvb_get_guint8(tvb, foffset );
242                 if (c_char<0x20 || c_char>0x7e)
243                 {
244                         if (c_char != 0x00)
245                         { 
246                                 c_char = 0x2e;
247                                 buffer[i] = c_char & 0xff;
248                         }
249                         else
250                         {
251                                 i--;
252                                 str_length--;
253                         }
254                 }
255                 else
256                 {
257                         buffer[i] = c_char & 0xff;
258                 }
259                 foffset++;
260                 length_remaining--;
261                 
262                 if(length_remaining==1)
263                 {
264                         i++;
265                         break;
266                 }        
267         }
268         buffer[i] = '\0';
269         
270         if (little) {
271             str_length = tvb_get_letohl(tvb, offset);
272         }
273         else
274         {
275             str_length = tvb_get_ntohl(tvb, offset);
276         }
277         proto_tree_add_string(nmas_tree, hfinfo, tvb, offset+4,
278                 str_length, buffer);
279         /*foffset += align_4(tvb, foffset);*/
280         return foffset;
281 }
282
283 void
284 dissect_nmas_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, ncp_req_hash_value *request_value)
285 {
286     guint8              func, subfunc = 0;
287     guint32             msg_length=0, cur_string_len=0;
288     guint32             foffset;
289     guint32             subverb=0;
290     guint32             attribute=0;
291     guint8              msgverb=0;
292     proto_tree          *atree;
293     proto_item          *aitem;
294     
295     foffset = 6;
296     func = tvb_get_guint8(tvb, foffset);
297     foffset += 1;
298     subfunc = tvb_get_guint8(tvb, foffset);
299     foffset += 1;
300     
301     /* Fill in the INFO column. */
302     if (check_col(pinfo->cinfo, COL_INFO)) {
303        col_set_str(pinfo->cinfo, COL_PROTOCOL, "NMAS");
304        col_add_fstr(pinfo->cinfo, COL_INFO, "C NMAS - %s",
305                     val_to_str(subfunc, nmas_func_enum, "Unknown (0x%02x)"));
306     }
307     aitem = proto_tree_add_text(ncp_tree, tvb, foffset, -1, "Packet Type: %s",
308                                 val_to_str(subfunc, nmas_func_enum, "Unknown (0x%02x)"));
309     atree = proto_item_add_subtree(aitem, ett_nmas);
310     switch (subfunc) {
311     case 1:
312         proto_tree_add_item(atree, hf_ping_version, tvb, foffset, 4, TRUE);
313         foffset += 4;
314         proto_tree_add_item(atree, hf_ping_flags, tvb, foffset, 4, TRUE);
315         foffset += 4;
316         break;
317     case 2:
318         proto_tree_add_item(atree, hf_frag_handle, tvb, foffset, 4, TRUE);
319         foffset += 4;
320         foffset += 4; /* Dont know what this is */
321         proto_tree_add_item(atree, hf_length, tvb, foffset, 4, TRUE);
322         msg_length = tvb_get_letohl(tvb, foffset);
323         foffset += 4;
324         foffset += 12;
325         msg_length -= 16;
326         proto_tree_add_item(atree, hf_subverb, tvb, foffset, 4, TRUE);
327         subverb = tvb_get_letohl(tvb, foffset);
328         if (request_value) {
329             request_value->req_nds_flags=subverb; /* Store the NMAS fragment verb */
330         }
331         foffset += 4;
332         msg_length -= 4;
333         if (check_col(pinfo->cinfo, COL_INFO)) {
334             col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
335                             val_to_str(subverb, nmas_subverb_enum, "Unknown subverb (%u)"));
336         }
337         switch (subverb) {
338         case 0:             /* Fragmented Ping */
339             proto_tree_add_item(atree, hf_ping_version, tvb, foffset, 4, TRUE);
340             foffset += 4;
341             proto_tree_add_item(atree, hf_ping_flags, tvb, foffset, 4, TRUE);
342             foffset += 4;
343             break;
344         case 2:             /* Client Put Data */
345             proto_tree_add_item(atree, hf_opaque, tvb, foffset, msg_length, FALSE);
346             foffset += msg_length;
347             break;
348         case 4:             /* Client Get Data */
349         case 6:             /* Client Get User NDS Credentials */
350             /* No Op */
351             break;
352         case 8:             /* Login Store Management */
353             proto_tree_add_item(atree, hf_reply_buffer_size, tvb, foffset, 1, TRUE);
354             foffset += 4;
355             msgverb = tvb_get_guint8(tvb, foffset); 
356             if (request_value) {
357                 request_value->nds_request_verb=msgverb; /* Use nds_request_verb for passed subverb */
358             }
359             proto_tree_add_item(atree, hf_lsm_verb, tvb, foffset, 1, TRUE);
360             foffset += 4;
361             if (check_col(pinfo->cinfo, COL_INFO)) {
362                 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
363                                 val_to_str(msgverb, nmas_lsmverb_enum, "Unknown (%u)"));
364             }
365             switch (msgverb)
366             {
367             case 1:
368                 break;
369             case 2:
370                 break;
371             case 4:
372                 break;
373             case 5:
374                 break;
375             case 6:
376                 break;
377             default:
378                 break;
379             }
380             break;
381         case 10:            /* Writable Object Check */
382             /* The first GUINT32 value is the len of the header? */
383             foffset += 4; 
384             /* The next two GUINT32 values are reserved and always 0 */
385             foffset += 8;
386             foffset = nmas_string(tvb, hf_tree, atree, foffset, TRUE);
387             foffset = nmas_string(tvb, hf_user, atree, foffset, TRUE);
388             break;
389         case 1242:          /* Message Handler */
390             foffset += 4;
391             proto_tree_add_item(atree, hf_msg_version, tvb, foffset, 4, FALSE);
392             foffset += 4;
393             proto_tree_add_item(atree, hf_session_ident, tvb, foffset, 4, FALSE);
394             foffset += 4;
395             foffset += 3;
396             msgverb = tvb_get_guint8(tvb, foffset);
397             if (request_value) {
398                 request_value->nds_request_verb=msgverb; /* Use nds_request_verb for passed verb */
399             }
400             proto_tree_add_item(atree, hf_msg_verb, tvb, foffset, 1, FALSE);
401             foffset += 1;
402             msg_length -= 12;
403             if (check_col(pinfo->cinfo, COL_INFO)) {
404                 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
405                                 val_to_str(msgverb, nmas_msgverb_enum, "Unknown (%u)"));
406             }
407             switch(msgverb)
408             {
409             case 1:
410                 msg_length = tvb_get_ntohl(tvb, foffset);
411                 proto_tree_add_item(atree, hf_length, tvb, foffset, 4, FALSE);
412                 foffset += 4;
413                 proto_tree_add_item(atree, hf_data, tvb, foffset, msg_length, FALSE);
414                 foffset += msg_length;
415                 break;
416             case 3:
417                 msg_length = tvb_get_ntohl(tvb, foffset);
418                 msg_length -= 4;
419                 proto_tree_add_item(atree, hf_length, tvb, foffset, 4, FALSE);
420                 foffset += 4;
421                 while (msg_length > 0)
422                 {
423                     attribute = tvb_get_ntohl(tvb, foffset);
424                     foffset += 4;
425                     cur_string_len=tvb_get_ntohl(tvb, foffset);
426                     switch (attribute) {
427                     case 1:
428                         foffset = nmas_string(tvb, hf_user, atree, foffset, FALSE);
429                         break;
430                     case 2:
431                         foffset = nmas_string(tvb, hf_tree, atree, foffset, FALSE);
432                         break;
433                     case 4:
434                         foffset = nmas_string(tvb, hf_clearence, atree, foffset, FALSE);
435                         break;
436                     case 11:
437                         foffset = nmas_string(tvb, hf_login_sequence, atree, foffset, FALSE);
438                         break;
439                     default:
440                         break;
441                     }
442                     msg_length -= cur_string_len;
443                     if (tvb_reported_length_remaining(tvb, foffset)<5)
444                     {
445                         break;
446                     }
447                 }
448                 break;
449             case 5:
450                 proto_tree_add_item(atree, hf_opaque, tvb, foffset, msg_length, FALSE);
451                 foffset += msg_length;
452                 break;
453             case 7:
454             case 9:
455                 /* No Op */
456                 break;
457             default:
458                 break;
459             }
460             break;
461         default:
462             break;
463         }
464         break;
465     case 3:
466         /* No Op */
467         break;
468     default:
469         break;
470     }
471 }
472
473 void
474 dissect_nmas_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ncp_tree, guint8 func _U_, guint8 subfunc, ncp_req_hash_value *request_value)
475 {
476     guint32             foffset=0, roffset=0;
477     guint32             subverb=0;
478     guint8              msgverb=0;
479     guint32             msg_length=0;
480     guint32             return_code=0, encrypt_error=0;
481     proto_tree          *atree;
482     proto_item          *aitem;
483     
484     foffset = 8;
485     if (request_value) {
486         subverb = request_value->req_nds_flags;
487         msgverb = request_value->nds_request_verb;
488     }
489     if (check_col(pinfo->cinfo, COL_INFO)) {
490        col_set_str(pinfo->cinfo, COL_PROTOCOL, "NMAS");
491     }
492     if (tvb_reported_length_remaining(tvb, foffset)<4) {
493         return;
494     }
495         
496     aitem = proto_tree_add_text(ncp_tree, tvb, foffset, -1, "Packet Type: %s",
497                                 val_to_str(subfunc, nmas_func_enum, "Unknown (0x%02x)"));
498     atree = proto_item_add_subtree(aitem, ett_nmas);
499     switch (subfunc) {
500     case 1:
501         proto_tree_add_item(atree, hf_ping_flags, tvb, foffset, 4, TRUE);
502         foffset += 4;
503         proto_tree_add_item(atree, hf_nmas_version, tvb, foffset, 4, TRUE);
504         foffset += 4;
505         break;
506     case 2:
507         proto_tree_add_item(atree, hf_length, tvb, foffset, 4, TRUE);
508         msg_length = tvb_get_letohl(tvb, foffset);
509         foffset +=4;
510         proto_tree_add_item(atree, hf_frag_handle, tvb, foffset, 4, TRUE);
511         foffset += 4;
512         return_code = tvb_get_letohl(tvb, foffset);
513         roffset = foffset;
514         foffset += 4;
515         msg_length -= 8;
516         proto_tree_add_text(atree, tvb, foffset, -1, "Verb: %s",
517                             val_to_str(subverb, nmas_subverb_enum, "Unknown (%u)"));
518         if (return_code == 0)
519         {
520             switch (subverb) {
521             case 0:             /* Fragmented Ping */
522                 proto_tree_add_item(atree, hf_ping_flags, tvb, foffset, 4, TRUE);
523                 foffset += 4;
524                 proto_tree_add_item(atree, hf_nmas_version, tvb, foffset, 4, TRUE);
525                 foffset += 4;
526                 break;
527             case 2:             /* Client Put Data */
528                 proto_tree_add_item(atree, hf_squeue_bytes, tvb, foffset, 4, TRUE);
529                 foffset += 4;
530                 proto_tree_add_item(atree, hf_cqueue_bytes, tvb, foffset, 4, TRUE);
531                 foffset += 4;
532                 break;
533             case 4:             /* Client Get Data */
534                 proto_tree_add_item(atree, hf_opaque, tvb, foffset, msg_length, TRUE);
535                 foffset += msg_length;
536                 break;
537             case 6:             /* Client Get User NDS Credentials */
538                 proto_tree_add_item(atree, hf_num_creds, tvb, foffset, 4, TRUE);
539                 foffset += 4;
540                 proto_tree_add_item(atree, hf_cred_type, tvb, foffset, 4, TRUE);
541                 foffset += 4;
542                 proto_tree_add_item(atree, hf_login_state, tvb, foffset, 4, TRUE);
543                 foffset += 4;
544                 msg_length -= 12;
545                 proto_tree_add_item(atree, hf_enc_cred, tvb, foffset, msg_length, TRUE);
546                 foffset += msg_length;
547                 break;
548             case 8:             /* Login Store Management */
549                 proto_tree_add_text(atree, tvb, foffset, -1, "Subverb: %s",
550                                     val_to_str(msgverb, nmas_lsmverb_enum, "Unknown (%u)"));
551                 switch(msgverb)
552                 {
553                     /* The data within these structures is all encrypted. */
554                 case 1:
555                 case 3:
556                 case 5:
557                 case 7:
558                 case 9:
559                     proto_tree_add_item(atree, hf_enc_data, tvb, foffset, msg_length, TRUE);
560                     foffset += msg_length;
561                     break;
562                 default:
563                     break;
564                 }
565                 break;
566             case 10:            /* Writable Object Check */
567                 proto_tree_add_item(atree, hf_nmas_version, tvb, foffset, 4, TRUE);
568                 foffset += 4;
569                 break;
570             case 1242:          /* Message Handler */
571                 proto_tree_add_text(atree, tvb, foffset, -1, "Subverb: %s",
572                                     val_to_str(msgverb, nmas_msgverb_enum, "Unknown (%u)"));
573                 switch(msgverb)
574                 {
575                 case 1:
576                     msg_length = tvb_get_ntohl(tvb, foffset);
577                     proto_tree_add_item(atree, hf_length, tvb, foffset, 4, FALSE);
578                     foffset += 4;
579                     proto_tree_add_item(atree, hf_data, tvb, foffset, msg_length, FALSE);
580                     foffset += msg_length;
581                     break;
582                 case 3:
583                     proto_tree_add_item(atree, hf_session_ident, tvb, foffset, 4, FALSE);
584                     foffset += 4;
585                     break;
586                 case 5:
587                     /* No Op */
588                     break;
589                 case 7:
590                     encrypt_error = tvb_get_ntohl(tvb, foffset);
591                     if (match_strval(encrypt_error, nmas_errors_enum)!=NULL)
592                     {
593                         if (check_col(pinfo->cinfo, COL_INFO)) {
594                            col_add_fstr(pinfo->cinfo, COL_INFO, "R Payload Error - %s", match_strval(encrypt_error, nmas_errors_enum));
595                         }
596                         proto_tree_add_item(atree, hf_encrypt_error, tvb, foffset, 4, FALSE);
597                     }
598                     else
599                     {
600                         proto_tree_add_item(atree, hf_opaque, tvb, foffset, msg_length, FALSE);
601                     }
602                     foffset += msg_length;
603                     break;
604                 case 9:
605                     /* No Op */
606                     break;
607                 default:
608                     break;
609                 }
610                 break;
611             default:
612                 break;
613             }
614         }
615         if (match_strval(return_code, nmas_errors_enum)!=NULL) 
616         {
617             proto_tree_add_item(atree, hf_return_code, tvb, roffset, 4, TRUE);
618             if (check_col(pinfo->cinfo, COL_INFO)) {
619                col_add_fstr(pinfo->cinfo, COL_INFO, "R Error - %s", match_strval(return_code, nmas_errors_enum));
620             }
621         }
622         else
623         {
624             if (return_code!=0)
625             {
626                 proto_tree_add_item(atree, hf_return_code, tvb, roffset, 4, TRUE);
627                 if (check_col(pinfo->cinfo, COL_INFO)) {
628                    col_add_fstr(pinfo->cinfo, COL_INFO, "R Unknown NMAS Error - 0x%08x", return_code);
629                 }
630             }
631         }
632         /*if (return_code == 0 && msgverb!=7) {*/
633
634         if (return_code == 0) {
635             proto_tree_add_text(atree, tvb, roffset, 4, "Return Code: Success (0x00000000)");
636         }
637         break;
638     case 3:
639         break;
640     default:
641         break;
642     }
643 }
644
645 void
646 proto_register_nmas(void)
647 {
648     static hf_register_info hf_nmas[] = {
649         { &hf_func,
650         { "Function",           "nmas.func", FT_UINT8, BASE_HEX, NULL, 0x0,
651             "Function", HFILL }},
652
653         { &hf_subfunc,
654         { "Subfunction",                "nmas.subfunc", FT_UINT8, BASE_HEX, NULL, 0x0,
655             "Subfunction", HFILL }},
656
657         { &hf_ping_version,
658         { "Ping Version",               "nmas.ping_version", FT_UINT32, BASE_HEX, NULL, 0x0,
659             "Ping Version", HFILL }},
660
661         { &hf_ping_flags,
662         { "Flags",              "nmas.ping_flags", FT_UINT32, BASE_HEX, NULL, 0x0,
663             "Flags", HFILL }},
664
665         { &hf_frag_handle,
666         { "Fragment Handle",        "nmas.frag_handle", FT_UINT32, BASE_HEX, NULL, 0x0,
667             "Fragment Handle", HFILL }},
668
669         { &hf_length,
670         { "Length",        "nmas.length", FT_UINT32, BASE_DEC, NULL, 0x0,
671             "Length", HFILL }},
672
673         { &hf_subverb,
674         { "Sub Verb",    "nmas.subverb",
675           FT_UINT32,    BASE_HEX,   VALS(nmas_subverb_enum),   0x0,
676           "Sub Verb", HFILL }},
677
678         { &hf_tree,
679         { "Tree",    "nmas.tree",
680           FT_STRING,    BASE_NONE,   NULL,   0x0,
681           "Tree", HFILL }},
682
683         { &hf_user,
684         { "User",    "nmas.user",
685           FT_STRING,    BASE_NONE,   NULL,   0x0,
686           "User", HFILL }},
687
688         { &hf_nmas_version,
689         { "NMAS Protocol Version",        "nmas.version", FT_UINT32, BASE_HEX, NULL, 0x0,
690             "NMAS Protocol Version", HFILL }},
691
692         { &hf_msg_version,
693         { "Message Version",        "nmas.msg_version", FT_UINT32, BASE_HEX, NULL, 0x0,
694             "Message Version", HFILL }},
695
696         { &hf_session_ident,
697         { "Session Identifier",        "nmas.session_ident", FT_UINT32, BASE_HEX, NULL, 0x0,
698             "Session Identifier", HFILL }},
699
700         { &hf_msg_verb,
701         { "Message Verb",        "nmas.msg_verb", FT_UINT8, BASE_HEX, VALS(nmas_msgverb_enum), 0x0,
702             "Message Verb", HFILL }},
703         
704         { &hf_attribute,
705         { "Attribute Type",        "nmas.attribute", FT_UINT32, BASE_DEC, VALS(nmas_attribute_enum), 0x0,
706             "Attribute Type", HFILL }},
707
708         { &hf_clearence,
709         { "Requested Clearence",    "nmas.clearence",
710           FT_STRING,    BASE_NONE,   NULL,   0x0,
711           "Requested Clearence", HFILL }},
712
713         { &hf_login_sequence,
714         { "Requested Login Sequence",    "nmas.login_seq",
715           FT_STRING,    BASE_NONE,   NULL,   0x0,
716           "Requested Login Sequence", HFILL }},
717
718         { &hf_opaque,
719         { "Opaque Data",    "nmas.opaque",
720           FT_BYTES,    BASE_NONE,   NULL,   0x0,
721           "Opaque Data", HFILL }},
722
723         { &hf_data,
724         { "Data",    "nmas.data",
725           FT_BYTES,    BASE_NONE,   NULL,   0x0,
726           "Data", HFILL }},
727         
728         { &hf_return_code,
729         { "Return Code",        "nmas.return_code", FT_UINT32, BASE_HEX, VALS(nmas_errors_enum), 0x0,
730             "Return Code", HFILL }},
731        
732         { &hf_lsm_verb,
733         { "Login Store Message Verb",        "nmas.lsm_verb", FT_UINT8, BASE_HEX, VALS(nmas_lsmverb_enum), 0x0,
734             "Login Store Message Verb", HFILL }},
735
736         { &hf_squeue_bytes,
737         { "Server Queue Number of Bytes",        "nmas.squeue_bytes", FT_UINT32, BASE_DEC, NULL, 0x0,
738             "Server Queue Number of Bytes", HFILL }},
739
740         { &hf_cqueue_bytes,
741         { "Client Queue Number of Bytes",        "nmas.cqueue_bytes", FT_UINT32, BASE_DEC, NULL, 0x0,
742             "Client Queue Number of Bytes", HFILL }},
743
744         { &hf_num_creds,
745         { "Number of Credentials",        "nmas.num_creds", FT_UINT32, BASE_DEC, NULL, 0x0,
746             "Number of Credentials", HFILL }},
747
748         { &hf_cred_type,
749         { "Credential Type",        "nmas.cred_type", FT_UINT32, BASE_DEC, NULL, 0x0,
750             "Credential Type", HFILL }},
751         
752         { &hf_login_state,
753         { "Login State",        "nmas.login_state", FT_UINT32, BASE_DEC, NULL, 0x0,
754             "Login State", HFILL }},
755
756         { &hf_enc_cred,
757         { "Encrypted Credential",    "nmas.enc_cred",
758           FT_BYTES,    BASE_NONE,   NULL,   0x0,
759           "Encrypted Credential", HFILL }},
760
761         { &hf_enc_data,
762         { "Encrypted Data",    "nmas.enc_data",
763           FT_BYTES,    BASE_NONE,   NULL,   0x0,
764           "Encrypted Data", HFILL }},
765     
766         { &hf_reply_buffer_size,
767         { "Reply Buffer Size",        "nmas.buf_size", FT_UINT32, BASE_DEC, NULL, 0x0,
768             "Reply Buffer Size", HFILL }},
769     
770         { &hf_encrypt_error,
771         { "Payload Error",        "nmas.encrypt_error", FT_UINT32, BASE_HEX, VALS(nmas_errors_enum), 0x0,
772             "Payload/Encryption Return Code", HFILL }},
773         
774     };
775
776     static gint *ett[] = {
777         &ett_nmas,
778     };
779     
780     proto_nmas = proto_register_protocol("Novell Modular Authentication Service", "NMAS", "nmas");
781     proto_register_field_array(proto_nmas, hf_nmas, array_length(hf_nmas));
782     proto_register_subtree_array(ett, array_length(ett));
783 }