forked from wireshark/wireshark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket-afp.c
3586 lines (2982 loc) · 107 KB
/
packet-afp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* packet-afp.c
* Routines for afp packet dissection
* Copyright 2002, Didier Gautheron <dgautheron@magic.fr>
*
* $Id: packet-afp.c,v 1.15 2002/05/11 22:40:40 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* Copied from README.developer
* Copied from packet-dsi.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef NEED_SNPRINTF_H
# ifdef HAVE_STDARG_H
# include <stdarg.h>
# else
# include <varargs.h>
# endif
# include "snprintf.h"
#endif
#include <string.h>
#include <glib.h>
#include <epan/packet.h>
#include <epan/strutil.h>
#include <epan/conversation.h>
#include "packet-afp.h"
/* The information in this module (AFP) comes from:
AFP 2.1 & 2.2.pdf contained in AppleShare_IP_6.3_SDK
available from http://www.apple.com
AFP3.0.pdf from http://www.apple.com
The netatalk source code by Wesley Craig & Adrian Sun
http://netatalk.sf.net
*/
/* from netatalk/include/afp.h */
#define AFPTRANS_NONE 0
#define AFPTRANS_DDP (1 << 0)
#define AFPTRANS_TCP (1 << 1)
#define AFPTRANS_ALL (AFPTRANS_DDP | AFPTRANS_TCP)
/* server flags */
#define AFPSRVRINFO_COPY (1<<0) /* supports copyfile */
#define AFPSRVRINFO_PASSWD (1<<1) /* supports change password */
#define AFPSRVRINFO_NOSAVEPASSWD (1<<2) /* don't allow save password */
#define AFPSRVRINFO_SRVMSGS (1<<3) /* supports server messages */
#define AFPSRVRINFO_SRVSIGNATURE (1<<4) /* supports server signature */
#define AFPSRVRINFO_TCPIP (1<<5) /* supports tcpip */
#define AFPSRVRINFO_SRVNOTIFY (1<<6) /* supports server notifications */
#define AFPSRVRINFO_FASTBOZO (1<<15) /* fast copying */
/* AFP Attention Codes -- 4 bits */
#define AFPATTN_SHUTDOWN (1 << 15) /* shutdown/disconnect */
#define AFPATTN_CRASH (1 << 14) /* server crashed */
#define AFPATTN_MESG (1 << 13) /* server has message */
#define AFPATTN_NORECONNECT (1 << 12) /* don't reconnect */
/* server notification */
#define AFPATTN_NOTIFY (AFPATTN_MESG | AFPATTN_NORECONNECT)
/* extended bitmap -- 12 bits. volchanged is only useful w/ a server
* notification, and time is only useful for shutdown. */
#define AFPATTN_VOLCHANGED (1 << 0) /* volume has changed */
#define AFPATTN_TIME(x) ((x) & 0xfff) /* time in minutes */
/* AFP functions */
#define AFP_BYTELOCK 1
#define AFP_CLOSEVOL 2
#define AFP_CLOSEDIR 3
#define AFP_CLOSEFORK 4
#define AFP_COPYFILE 5
#define AFP_CREATEDIR 6
#define AFP_CREATEFILE 7
#define AFP_DELETE 8
#define AFP_ENUMERATE 9
#define AFP_FLUSH 10
#define AFP_FLUSHFORK 11
#define AFP_GETFORKPARAM 14
#define AFP_GETSRVINFO 15
#define AFP_GETSRVPARAM 16
#define AFP_GETVOLPARAM 17
#define AFP_LOGIN 18
#define AFP_LOGINCONT 19
#define AFP_LOGOUT 20
#define AFP_MAPID 21
#define AFP_MAPNAME 22
#define AFP_MOVE 23
#define AFP_OPENVOL 24
#define AFP_OPENDIR 25
#define AFP_OPENFORK 26
#define AFP_READ 27
#define AFP_RENAME 28
#define AFP_SETDIRPARAM 29
#define AFP_SETFILEPARAM 30
#define AFP_SETFORKPARAM 31
#define AFP_SETVOLPARAM 32
#define AFP_WRITE 33
#define AFP_GETFLDRPARAM 34
#define AFP_SETFLDRPARAM 35
#define AFP_CHANGEPW 36
#define AFP_GETSRVRMSG 38
#define AFP_CREATEID 39
#define AFP_DELETEID 40
#define AFP_RESOLVEID 41
#define AFP_EXCHANGEFILE 42
#define AFP_CATSEARCH 43
#define AFP_OPENDT 48
#define AFP_CLOSEDT 49
#define AFP_GETICON 51
#define AFP_GTICNINFO 52
#define AFP_ADDAPPL 53
#define AFP_RMVAPPL 54
#define AFP_GETAPPL 55
#define AFP_ADDCMT 56
#define AFP_RMVCMT 57
#define AFP_GETCMT 58
#define AFP_ADDICON 192
/* ----------------------------- */
static int proto_afp = -1;
static int hf_afp_reserved = -1;
static int hf_afp_command = -1; /* CommandCode */
static int hf_afp_AFPVersion = -1;
static int hf_afp_UAM = -1;
static int hf_afp_user = -1;
static int hf_afp_passwd = -1;
static int hf_afp_pad = -1;
static int hf_afp_vol_flag_passwd = -1;
static int hf_afp_vol_flag_unix_priv = -1;
static int hf_afp_server_time = -1;
static int hf_afp_vol_bitmap = -1;
static int hf_afp_vol_name_offset = -1;
static int hf_afp_vol_id = -1;
static int hf_afp_vol_attribute = -1;
static int hf_afp_vol_name = -1;
static int hf_afp_vol_signature = -1;
static int hf_afp_vol_creation_date = -1;
static int hf_afp_vol_modification_date = -1;
static int hf_afp_vol_backup_date = -1;
static int hf_afp_vol_bytes_free = -1;
static int hf_afp_vol_bytes_total = -1;
static int hf_afp_vol_ex_bytes_free = -1;
static int hf_afp_vol_ex_bytes_total = -1;
static int hf_afp_vol_block_size = -1;
/* desktop stuff */
static int hf_afp_comment = -1;
static int hf_afp_file_creator = -1;
static int hf_afp_file_type = -1;
static int hf_afp_icon_type = -1;
static int hf_afp_icon_length = -1;
static int hf_afp_icon_tag = -1;
static int hf_afp_icon_index = -1;
static int hf_afp_appl_index = -1;
static int hf_afp_appl_tag = -1;
static int hf_afp_did = -1;
static int hf_afp_file_id = -1;
static int hf_afp_file_DataForkLen = -1;
static int hf_afp_file_RsrcForkLen = -1;
static int hf_afp_file_ExtDataForkLen = -1;
static int hf_afp_file_ExtRsrcForkLen = -1;
static int hf_afp_dir_bitmap = -1;
static int hf_afp_dir_offspring = -1;
static int hf_afp_dir_OwnerID = -1;
static int hf_afp_dir_GroupID = -1;
static int hf_afp_file_bitmap = -1;
static int hf_afp_req_count = -1;
static int hf_afp_start_index = -1;
static int hf_afp_max_reply_size = -1;
static int hf_afp_file_flag = -1;
static int hf_afp_create_flag = -1;
static int hf_afp_struct_size = -1;
static int hf_afp_cat_count = -1;
static int hf_afp_cat_req_matches = -1;
static int hf_afp_cat_position = -1;
static int hf_afp_creation_date = -1;
static int hf_afp_modification_date = -1;
static int hf_afp_backup_date = -1;
static int hf_afp_finder_info = -1;
static int hf_afp_long_name_offset = -1;
static int hf_afp_short_name_offset = -1;
static int hf_afp_unicode_name_offset = -1;
static int hf_afp_unix_privs_uid = -1;
static int hf_afp_unix_privs_gid = -1;
static int hf_afp_unix_privs_permissions = -1;
static int hf_afp_unix_privs_ua_permissions = -1;
static int hf_afp_path_type = -1;
static int hf_afp_path_len = -1;
static int hf_afp_path_name = -1;
static int hf_afp_flag = -1;
static int hf_afp_dt_ref = -1;
static int hf_afp_ofork = -1;
static int hf_afp_ofork_len = -1;
static int hf_afp_offset = -1;
static int hf_afp_rw_count = -1;
static int hf_afp_newline_mask = -1;
static int hf_afp_newline_char = -1;
static int hf_afp_last_written = -1;
static int hf_afp_actual_count = -1;
static int hf_afp_fork_type = -1;
static int hf_afp_access_mode = -1;
static int hf_afp_access_read = -1;
static int hf_afp_access_write = -1;
static int hf_afp_access_deny_read = -1;
static int hf_afp_access_deny_write = -1;
static gint hf_afp_lock_op = -1;
static gint hf_afp_lock_from = -1;
static gint hf_afp_lock_offset = -1;
static gint hf_afp_lock_len = -1;
static gint hf_afp_lock_range_start = -1;
static gint ett_afp = -1;
static gint ett_afp_vol_attribute = -1;
static gint ett_afp_enumerate = -1;
static gint ett_afp_enumerate_line = -1;
static gint ett_afp_access_mode = -1;
static gint ett_afp_vol_bitmap = -1;
static gint ett_afp_dir_bitmap = -1;
static gint ett_afp_dir_attribute = -1;
static gint ett_afp_file_attribute = -1;
static gint ett_afp_file_bitmap = -1;
static gint ett_afp_unix_privs = -1;
static gint ett_afp_path_name = -1;
static gint ett_afp_lock_flags = -1;
static gint ett_afp_dir_ar = -1;
static gint ett_afp_server_vol = -1;
static gint ett_afp_vol_list = -1;
static gint ett_afp_vol_flag = -1;
static gint ett_afp_cat_search = -1;
static gint ett_afp_cat_r_bitmap = -1;
static gint ett_afp_cat_spec = -1;
static gint ett_afp_vol_did = -1;
static dissector_handle_t data_handle;
static const value_string vol_signature_vals[] = {
{1, "Flat"},
{2, "Fixed Directory ID"},
{3, "Variable Directory ID (deprecated)"},
{0, NULL }
};
static const value_string CommandCode_vals[] = {
{AFP_BYTELOCK, "FPByteRangeLock" },
{AFP_CLOSEVOL, "FPCloseVol" },
{AFP_CLOSEDIR, "FPCloseDir" },
{AFP_CLOSEFORK, "FPCloseFork" },
{AFP_COPYFILE, "FPCopyFile" },
{AFP_CREATEDIR, "FPCreateDir" },
{AFP_CREATEFILE, "FPCreateFile" },
{AFP_DELETE, "FPDelete" },
{AFP_ENUMERATE, "FPEnumerate" },
{AFP_FLUSH, "FPFlush" },
{AFP_FLUSHFORK, "FPFlushFork" },
{AFP_GETFORKPARAM, "FPGetForkParms" },
{AFP_GETSRVINFO, "FPGetSrvrInfo" },
{AFP_GETSRVPARAM, "FPGetSrvrParms" },
{AFP_GETVOLPARAM, "FPGetVolParms" },
{AFP_LOGIN, "FPLogin" },
{AFP_LOGINCONT, "FPLoginCont" },
{AFP_LOGOUT, "FPLogout" },
{AFP_MAPID, "FPMapID" },
{AFP_MAPNAME, "FPMapName" },
{AFP_MOVE, "FPMoveAndRename" },
{AFP_OPENVOL, "FPOpenVol" },
{AFP_OPENDIR, "FPOpenDir" },
{AFP_OPENFORK, "FPOpenFork" },
{AFP_READ, "FPRead" },
{AFP_RENAME, "FPRename" },
{AFP_SETDIRPARAM, "FPSetDirParms" },
{AFP_SETFILEPARAM, "FPSetFileParms" },
{AFP_SETFORKPARAM, "FPSetForkParms" },
{AFP_SETVOLPARAM, "FPSetVolParms" },
{AFP_WRITE, "FPWrite" },
{AFP_GETFLDRPARAM, "FPGetFileDirParms" },
{AFP_SETFLDRPARAM, "FPSetFileDirParms" },
{AFP_CHANGEPW, "FPChangePassword" },
{AFP_GETSRVRMSG, "FPGetSrvrMsg" },
{AFP_CREATEID, "FPCreateID" },
{AFP_DELETEID, "FPDeleteID" },
{AFP_RESOLVEID, "FPResolveID" },
{AFP_EXCHANGEFILE, "FPExchangeFiles" },
{AFP_CATSEARCH, "FPCatSearch" },
{AFP_OPENDT, "FPOpenDT" },
{AFP_CLOSEDT, "FPCloseDT" },
{AFP_GETICON, "FPGetIcon" },
{AFP_GTICNINFO, "FPGetIconInfo" },
{AFP_ADDAPPL, "FPAddAPPL" },
{AFP_RMVAPPL, "FPRemoveAPPL" },
{AFP_GETAPPL, "FPGetAPPL" },
{AFP_ADDCMT, "FPAddComment" },
{AFP_RMVCMT, "FPRemoveComment" },
{AFP_GETCMT, "FPGetComment" },
{AFP_ADDICON, "FPAddIcon" },
{0, NULL }
};
/* volume bitmap
from Apple AFP3.0.pdf
Table 1-2 p. 20
*/
#define kFPVolAttributeBit (1 << 0)
#define kFPVolSignatureBit (1 << 1)
#define kFPVolCreateDateBit (1 << 2)
#define kFPVolModDateBit (1 << 3)
#define kFPVolBackupDateBit (1 << 4)
#define kFPVolIDBit (1 << 5)
#define kFPVolBytesFreeBit (1 << 6)
#define kFPVolBytesTotalBit (1 << 7)
#define kFPVolNameBit (1 << 8)
#define kFPVolExtBytesFreeBit (1 << 9)
#define kFPVolExtBytesTotalBit (1 << 10)
#define kFPVolBlockSizeBit (1 << 11)
static int hf_afp_vol_bitmap_Attributes = -1;
static int hf_afp_vol_bitmap_Signature = -1;
static int hf_afp_vol_bitmap_CreateDate = -1;
static int hf_afp_vol_bitmap_ModDate = -1;
static int hf_afp_vol_bitmap_BackupDate = -1;
static int hf_afp_vol_bitmap_ID = -1;
static int hf_afp_vol_bitmap_BytesFree = -1;
static int hf_afp_vol_bitmap_BytesTotal = -1;
static int hf_afp_vol_bitmap_Name = -1;
static int hf_afp_vol_bitmap_ExtBytesFree = -1;
static int hf_afp_vol_bitmap_ExtBytesTotal = -1;
static int hf_afp_vol_bitmap_BlockSize = -1;
static int hf_afp_vol_attribute_ReadOnly = -1;
static int hf_afp_vol_attribute_HasVolumePassword = -1;
static int hf_afp_vol_attribute_SupportsFileIDs = -1;
static int hf_afp_vol_attribute_SupportsCatSearch = -1;
static int hf_afp_vol_attribute_SupportsBlankAccessPrivs = -1;
static int hf_afp_vol_attribute_SupportsUnixPrivs = -1;
static int hf_afp_vol_attribute_SupportsUTF8Names = -1;
static int hf_afp_dir_bitmap_Attributes = -1;
static int hf_afp_dir_bitmap_ParentDirID = -1;
static int hf_afp_dir_bitmap_CreateDate = -1;
static int hf_afp_dir_bitmap_ModDate = -1;
static int hf_afp_dir_bitmap_BackupDate = -1;
static int hf_afp_dir_bitmap_FinderInfo = -1;
static int hf_afp_dir_bitmap_LongName = -1;
static int hf_afp_dir_bitmap_ShortName = -1;
static int hf_afp_dir_bitmap_NodeID = -1;
static int hf_afp_dir_bitmap_OffspringCount = -1;
static int hf_afp_dir_bitmap_OwnerID = -1;
static int hf_afp_dir_bitmap_GroupID = -1;
static int hf_afp_dir_bitmap_AccessRights = -1;
static int hf_afp_dir_bitmap_UTF8Name = -1;
static int hf_afp_dir_bitmap_UnixPrivs = -1;
static int hf_afp_dir_attribute_Invisible = -1;
static int hf_afp_dir_attribute_IsExpFolder = -1;
static int hf_afp_dir_attribute_System = -1;
static int hf_afp_dir_attribute_Mounted = -1;
static int hf_afp_dir_attribute_InExpFolder = -1;
static int hf_afp_dir_attribute_BackUpNeeded = -1;
static int hf_afp_dir_attribute_RenameInhibit = -1;
static int hf_afp_dir_attribute_DeleteInhibit = -1;
static int hf_afp_dir_attribute_SetClear = -1;
static int hf_afp_file_bitmap_Attributes = -1;
static int hf_afp_file_bitmap_ParentDirID = -1;
static int hf_afp_file_bitmap_CreateDate = -1;
static int hf_afp_file_bitmap_ModDate = -1;
static int hf_afp_file_bitmap_BackupDate = -1;
static int hf_afp_file_bitmap_FinderInfo = -1;
static int hf_afp_file_bitmap_LongName = -1;
static int hf_afp_file_bitmap_ShortName = -1;
static int hf_afp_file_bitmap_NodeID = -1;
static int hf_afp_file_bitmap_DataForkLen = -1;
static int hf_afp_file_bitmap_RsrcForkLen = -1;
static int hf_afp_file_bitmap_ExtDataForkLen = -1;
static int hf_afp_file_bitmap_LaunchLimit = -1;
static int hf_afp_file_bitmap_UTF8Name = -1;
static int hf_afp_file_bitmap_ExtRsrcForkLen = -1;
static int hf_afp_file_bitmap_UnixPrivs = -1;
static int hf_afp_file_attribute_Invisible = -1;
static int hf_afp_file_attribute_MultiUser = -1;
static int hf_afp_file_attribute_System = -1;
static int hf_afp_file_attribute_DAlreadyOpen = -1;
static int hf_afp_file_attribute_RAlreadyOpen = -1;
static int hf_afp_file_attribute_WriteInhibit = -1;
static int hf_afp_file_attribute_BackUpNeeded = -1;
static int hf_afp_file_attribute_RenameInhibit = -1;
static int hf_afp_file_attribute_DeleteInhibit = -1;
static int hf_afp_file_attribute_CopyProtect = -1;
static int hf_afp_file_attribute_SetClear = -1;
static const value_string vol_bitmap_vals[] = {
{kFPVolAttributeBit, "VolAttribute"},
{kFPVolSignatureBit, "VolSignature"},
{kFPVolCreateDateBit, "VolCreateDate"},
{kFPVolModDateBit, "VolModDate"},
{kFPVolBackupDateBit, "VolBackupDate"},
{kFPVolIDBit, "VolID"},
{kFPVolBytesFreeBit, "VolBytesFree"},
{kFPVolBytesTotalBit, "VolBytesTotal"},
{kFPVolNameBit, "VolNameBit"},
{kFPVolExtBytesFreeBit, "VolExtBytesFree"},
{kFPVolExtBytesTotalBit, "VolExtBytesTotal"},
{kFPVolBlockSizeBit, "VolBlockSize"},
{0, NULL } };
static const value_string flag_vals[] = {
{0, "Start" },
{1, "End" },
{0, NULL } };
static const value_string path_type_vals[] = {
{1, "Short names" },
{2, "Long names" },
{3, "Unicode names" },
{0, NULL } };
/*
volume attribute from Apple AFP3.0.pdf
Table 1-3 p. 22
*/
#define kReadOnly (1 << 0)
#define kHasVolumePassword (1 << 1)
#define kSupportsFileIDs (1 << 2)
#define kSupportsCatSearch (1 << 3)
#define kSupportsBlankAccessPrivs (1 << 4)
#define kSupportsUnixPrivs (1 << 5)
#define kSupportsUTF8Names (1 << 6)
/*
directory bitmap from Apple AFP3.0.pdf
Table 1-4 p. 31
*/
#define kFPAttributeBit (1 << 0)
#define kFPParentDirIDBit (1 << 1)
#define kFPCreateDateBit (1 << 2)
#define kFPModDateBit (1 << 3)
#define kFPBackupDateBit (1 << 4)
#define kFPFinderInfoBit (1 << 5)
#define kFPLongNameBit (1 << 6)
#define kFPShortNameBit (1 << 7)
#define kFPNodeIDBit (1 << 8)
#define kFPOffspringCountBit (1 << 9)
#define kFPOwnerIDBit (1 << 10)
#define kFPGroupIDBit (1 << 11)
#define kFPAccessRightsBit (1 << 12)
#define kFPUTF8NameBit (1 << 13)
#define kFPUnixPrivsBit (1 << 14)
/*
directory Access Rights parameter AFP3.0.pdf
table 1-6 p. 34
*/
#define AR_O_SEARCH (1 << 0) /* owner has search access */
#define AR_O_READ (1 << 1) /* owner has read access */
#define AR_O_WRITE (1 << 2) /* owner has write access */
#define AR_G_SEARCH (1 << 8) /* group has search access */
#define AR_G_READ (1 << 9) /* group has read access */
#define AR_G_WRITE (1 << 10) /* group has write access */
#define AR_E_SEARCH (1 << 16) /* everyone has search access */
#define AR_E_READ (1 << 17) /* everyone has read access */
#define AR_E_WRITE (1 << 18) /* everyone has write access */
#define AR_U_SEARCH (1 << 24) /* user has search access */
#define AR_U_READ (1 << 25) /* user has read access */
#define AR_U_WRITE (1 << 26) /* user has write access */
#define AR_BLANK (1 << 28) /* Blank Access Privileges (use parent dir privileges) */
#define AR_U_OWN (1 << 31) /* user is the owner */
static int hf_afp_dir_ar = -1;
static int hf_afp_dir_ar_o_search = -1;
static int hf_afp_dir_ar_o_read = -1;
static int hf_afp_dir_ar_o_write = -1;
static int hf_afp_dir_ar_g_search = -1;
static int hf_afp_dir_ar_g_read = -1;
static int hf_afp_dir_ar_g_write = -1;
static int hf_afp_dir_ar_e_search = -1;
static int hf_afp_dir_ar_e_read = -1;
static int hf_afp_dir_ar_e_write = -1;
static int hf_afp_dir_ar_u_search = -1;
static int hf_afp_dir_ar_u_read = -1;
static int hf_afp_dir_ar_u_write = -1;
static int hf_afp_dir_ar_blank = -1;
static int hf_afp_dir_ar_u_own = -1;
/*
file bitmap AFP3.0.pdf
Table 1-7 p. 36
same as dir
kFPAttributeBit (bit 0)
kFPParentDirIDBit (bit 1)
kFPCreateDateBit (bit 2)
kFPModDateBit (bit 3)
kFPBackupDateBit (bit 4)
kFPFinderInfoBit (bit 5)
kFPLongNameBit (bit 6)
kFPShortNameBit (bit 7)
kFPNodeIDBit (bit 8)
kFPUTF8NameBit (bit 13)
*/
#define kFPDataForkLenBit (1 << 9)
#define kFPRsrcForkLenBit (1 << 10)
#define kFPExtDataForkLenBit (1 << 11)
#define kFPLaunchLimitBit (1 << 12)
#define kFPExtRsrcForkLenBit (1 << 14)
#define kFPUnixPrivsBit_file (1 << 15) /* :( */
/*
file attribute AFP3.0.pdf
Table 1-8 p. 37
*/
#define kFPInvisibleBit (1 << 0)
#define kFPMultiUserBit (1 << 1)
#define kFPSystemBit (1 << 2)
#define kFPDAlreadyOpenBit (1 << 3)
#define kFPRAlreadyOpenBit (1 << 4)
#define kFPWriteInhibitBit (1 << 5)
#define kFPBackUpNeededBit (1 << 6)
#define kFPRenameInhibitBit (1 << 7)
#define kFPDeleteInhibitBit (1 << 8)
#define kFPCopyProtectBit (1 << 10)
#define kFPSetClearBit (1 << 15)
/* dir attribute */
#define kIsExpFolder (1 << 1)
#define kMounted (1 << 3)
#define kInExpFolder (1 << 4)
#define hash_init_count 20
/* Hash functions */
static gint afp_equal (gconstpointer v, gconstpointer v2);
static guint afp_hash (gconstpointer v);
static guint afp_packet_init_count = 200;
typedef struct {
guint32 conversation;
guint16 seq;
} afp_request_key;
typedef struct {
guint8 command;
} afp_request_val;
static GHashTable *afp_request_hash = NULL;
static GMemChunk *afp_request_keys = NULL;
static GMemChunk *afp_request_vals = NULL;
/* Hash Functions */
static gint afp_equal (gconstpointer v, gconstpointer v2)
{
afp_request_key *val1 = (afp_request_key*)v;
afp_request_key *val2 = (afp_request_key*)v2;
if (val1->conversation == val2->conversation &&
val1->seq == val2->seq) {
return 1;
}
return 0;
}
static guint afp_hash (gconstpointer v)
{
afp_request_key *afp_key = (afp_request_key*)v;
return afp_key->seq;
}
/* --------------------------
*/
#define PAD(x) { proto_tree_add_item(tree, hf_afp_pad, tvb, offset, x, FALSE); offset += x; }
static guint16
decode_vol_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset)
{
proto_tree *sub_tree = NULL;
proto_item *item;
guint16 bitmap;
bitmap = tvb_get_ntohs(tvb, offset);
if (tree) {
item = proto_tree_add_item(tree, hf_afp_vol_bitmap, tvb, offset, 2,FALSE);
sub_tree = proto_item_add_subtree(item, ett_afp_vol_bitmap);
}
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_Attributes, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_Signature, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_CreateDate, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ModDate, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BackupDate, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ID, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BytesFree, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BytesTotal, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_Name, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ExtBytesFree, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ExtBytesTotal, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BlockSize , tvb, offset, 2,FALSE);
return bitmap;
}
/* -------------------------- */
static guint16
decode_vol_attribute (proto_tree *tree, tvbuff_t *tvb, gint offset)
{
proto_tree *sub_tree = NULL;
proto_item *item;
guint16 bitmap;
bitmap = tvb_get_ntohs(tvb, offset);
if (tree) {
item = proto_tree_add_item(tree, hf_afp_vol_attribute, tvb, offset, 2,FALSE);
sub_tree = proto_item_add_subtree(item, ett_afp_vol_attribute);
}
proto_tree_add_item(sub_tree, hf_afp_vol_attribute_ReadOnly ,tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_attribute_HasVolumePassword ,tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsFileIDs ,tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsCatSearch ,tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsBlankAccessPrivs,tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsUnixPrivs ,tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsUTF8Names ,tvb, offset, 2,FALSE);
return bitmap;
}
/* --------------------------
cf AFP3.0.pdf page 38
date are number of seconds from 12:00am on 01.01.2000 GMT
backup : 0x8000000 not set
from netatalk adouble.h
*/
#define DATE_NOT_SET 0x80000000
#define AD_DATE_DELTA 946684800
#define AD_DATE_TO_UNIX(x) (x + AD_DATE_DELTA)
static guint32
print_date(proto_tree *tree,int id, tvbuff_t *tvb, gint offset)
{
time_t date = tvb_get_ntohl(tvb, offset);
nstime_t tv;
tv.secs = AD_DATE_TO_UNIX(date);
tv.nsecs = 0;
proto_tree_add_time(tree, id, tvb, offset, 4, &tv);
return date;
}
/* -------------------------- */
static gint
parse_vol_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset, guint16 bitmap)
{
guint16 nameoff = 0;
if ((bitmap & kFPVolAttributeBit)) {
decode_vol_attribute(tree,tvb,offset);
offset += 2;
}
if ((bitmap & kFPVolSignatureBit)) {
proto_tree_add_item(tree, hf_afp_vol_signature,tvb, offset, 2, FALSE);
offset += 2;
}
if ((bitmap & kFPVolCreateDateBit)) {
print_date(tree, hf_afp_vol_creation_date,tvb, offset);
offset += 4;
}
if ((bitmap & kFPVolModDateBit)) {
print_date(tree, hf_afp_vol_modification_date,tvb, offset);
offset += 4;
}
if ((bitmap & kFPVolBackupDateBit)) {
print_date(tree, hf_afp_vol_backup_date,tvb, offset);
offset += 4;
}
if ((bitmap & kFPVolIDBit)) {
proto_tree_add_item(tree, hf_afp_vol_id, tvb, offset, 2,FALSE);
offset += 2;
}
if ((bitmap & kFPVolBytesFreeBit)) {
proto_tree_add_item(tree, hf_afp_vol_bytes_free,tvb, offset, 4, FALSE);
offset += 4;
}
if ((bitmap & kFPVolBytesTotalBit)) {
proto_tree_add_item(tree, hf_afp_vol_bytes_total,tvb, offset, 4, FALSE);
offset += 4;
}
if ((bitmap & kFPVolNameBit)) {
nameoff = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(tree, hf_afp_vol_name_offset,tvb, offset, 2, FALSE);
offset += 2;
}
if ((bitmap & kFPVolExtBytesFreeBit)) {
proto_tree_add_item(tree, hf_afp_vol_ex_bytes_free,tvb, offset, 8, FALSE);
offset += 8;
}
if ((bitmap & kFPVolExtBytesTotalBit)) {
proto_tree_add_item(tree, hf_afp_vol_ex_bytes_total,tvb, offset, 8, FALSE);
offset += 8;
}
if ((bitmap & kFPVolBlockSizeBit)) {
proto_tree_add_item(tree, hf_afp_vol_block_size,tvb, offset, 4, FALSE);
offset += 4;
}
if (nameoff) {
guint8 len;
len = tvb_get_guint8(tvb, offset);
proto_tree_add_item(tree, hf_afp_vol_name, tvb, offset, 1,FALSE);
offset += len +1;
}
return offset;
}
/* -------------------------- */
static guint16
decode_file_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset)
{
proto_tree *sub_tree = NULL;
proto_item *item;
guint16 bitmap;
bitmap = tvb_get_ntohs(tvb, offset);
if (tree) {
item = proto_tree_add_item(tree, hf_afp_file_bitmap, tvb, offset, 2,FALSE);
sub_tree = proto_item_add_subtree(item, ett_afp_file_bitmap);
}
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_Attributes , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ParentDirID , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_CreateDate , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ModDate , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_BackupDate , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_FinderInfo , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_LongName , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ShortName , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_NodeID , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_DataForkLen , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_RsrcForkLen , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ExtDataForkLen , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_LaunchLimit , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_UTF8Name , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ExtRsrcForkLen , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_bitmap_UnixPrivs , tvb, offset, 2,FALSE);
return bitmap;
}
/* -------------------------- */
static guint16
decode_file_attribute(proto_tree *tree, tvbuff_t *tvb, gint offset, int shared)
{
proto_tree *sub_tree = NULL;
proto_item *item;
guint16 attribute;
attribute = tvb_get_ntohs(tvb, offset);
if (tree) {
item = proto_tree_add_text(tree, tvb, offset, 2,
"File Attributes: 0x%04x", attribute);
sub_tree = proto_item_add_subtree(item, ett_afp_file_attribute);
}
proto_tree_add_item(sub_tree, hf_afp_file_attribute_Invisible , tvb, offset, 2,FALSE);
if (!shared)
proto_tree_add_item(sub_tree, hf_afp_file_attribute_MultiUser , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_attribute_System , tvb, offset, 2,FALSE);
if (!shared) {
proto_tree_add_item(sub_tree, hf_afp_file_attribute_DAlreadyOpen , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_attribute_RAlreadyOpen , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_attribute_WriteInhibit , tvb, offset, 2,FALSE);
}
proto_tree_add_item(sub_tree, hf_afp_file_attribute_BackUpNeeded , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_attribute_RenameInhibit, tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_attribute_DeleteInhibit, tvb, offset, 2,FALSE);
if (!shared)
proto_tree_add_item(sub_tree, hf_afp_file_attribute_CopyProtect , tvb, offset, 2,FALSE);
proto_tree_add_item(sub_tree, hf_afp_file_attribute_SetClear , tvb, offset, 2,FALSE);
return(attribute);
}
static void
decode_access_rights (proto_tree *tree, tvbuff_t *tvb, int hf, gint offset)
{
proto_tree *sub_tree;
proto_item *item;
if (tree) {
item = proto_tree_add_item(tree, hf, tvb, offset, 4, FALSE);
sub_tree = proto_item_add_subtree(item, ett_afp_dir_ar);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_o_search, tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_o_read , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_o_write , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_g_search, tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_g_read , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_g_write , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_e_search, tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_e_read , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_e_write , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_u_search, tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_u_read , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_u_write , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_blank , tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_dir_ar_u_own , tvb, offset, 4, FALSE);
}
}
static void
decode_unix_privs (proto_tree *tree, tvbuff_t *tvb, gint offset)
{
proto_tree *sub_tree;
proto_item *item;
if (tree) {
item = proto_tree_add_text(tree, tvb, offset, 16,
"UNIX privileges");
sub_tree = proto_item_add_subtree(item, ett_afp_unix_privs);
proto_tree_add_item(sub_tree, hf_afp_unix_privs_uid, tvb, offset, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_unix_privs_gid, tvb, offset+4, 4, FALSE);
proto_tree_add_item(sub_tree, hf_afp_unix_privs_permissions, tvb, offset+8, 4, FALSE);
decode_access_rights(sub_tree, tvb, hf_afp_unix_privs_ua_permissions, offset+12);
}
}
/* -------------------------- */
static gint
parse_file_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset, guint16 bitmap, int shared)
{
guint16 lnameoff = 0;
guint16 snameoff = 0;
guint16 unameoff = 0;
gint max_offset = 0;
gint org_offset = offset;
if ((bitmap & kFPAttributeBit)) {
decode_file_attribute(tree, tvb, offset, shared);
offset += 2;
}
if ((bitmap & kFPParentDirIDBit)) {
proto_tree_add_item(tree, hf_afp_did, tvb, offset, 4,FALSE);
offset += 4;
}
if ((bitmap & kFPCreateDateBit)) {
print_date(tree, hf_afp_creation_date,tvb, offset);
offset += 4;
}
if ((bitmap & kFPModDateBit)) {
print_date(tree, hf_afp_modification_date,tvb, offset);
offset += 4;
}
if ((bitmap & kFPBackupDateBit)) {
print_date(tree, hf_afp_backup_date,tvb, offset);
offset += 4;
}
if ((bitmap & kFPFinderInfoBit)) {
proto_tree_add_item(tree, hf_afp_finder_info,tvb, offset, 32, FALSE);
offset += 32;
}
if ((bitmap & kFPLongNameBit)) {
gint tp_ofs;
guint8 len;
lnameoff = tvb_get_ntohs(tvb, offset);
if (lnameoff) {
tp_ofs = lnameoff +org_offset;
proto_tree_add_item(tree, hf_afp_long_name_offset,tvb, offset, 2, FALSE);
len = tvb_get_guint8(tvb, tp_ofs);
proto_tree_add_item(tree, hf_afp_path_len, tvb, tp_ofs, 1,FALSE);
tp_ofs++;
proto_tree_add_item(tree, hf_afp_path_name, tvb, tp_ofs, len,FALSE);
tp_ofs += len;
max_offset = (tp_ofs >max_offset)?tp_ofs:max_offset;
}
offset += 2;
}
if ((bitmap & kFPShortNameBit)) {
snameoff = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(tree, hf_afp_short_name_offset,tvb, offset, 2, FALSE);
offset += 2;
}
if ((bitmap & kFPNodeIDBit)) {
proto_tree_add_item(tree, hf_afp_file_id, tvb, offset, 4,FALSE);
offset += 4;
}
if ((bitmap & kFPDataForkLenBit)) {
proto_tree_add_item(tree, hf_afp_file_DataForkLen, tvb, offset, 4,FALSE);
offset += 4;
}
if ((bitmap & kFPRsrcForkLenBit)) {
proto_tree_add_item(tree, hf_afp_file_RsrcForkLen, tvb, offset, 4,FALSE);
offset += 4;
}
if ((bitmap & kFPExtDataForkLenBit)) {
proto_tree_add_item(tree, hf_afp_file_ExtDataForkLen, tvb, offset, 8,FALSE);
offset += 8;
}
if ((bitmap & kFPLaunchLimitBit)) {
offset += 2; /* ? */
}
if ((bitmap & kFPUTF8NameBit)) {
unameoff = tvb_get_ntohs(tvb, offset);
proto_tree_add_item(tree, hf_afp_unicode_name_offset,tvb, offset, 2, FALSE);
offset += 2;
}
if ((bitmap & kFPExtRsrcForkLenBit)) {
proto_tree_add_item(tree, hf_afp_file_ExtRsrcForkLen, tvb, offset, 8,FALSE);
offset += 8;
}
if ((bitmap & kFPUnixPrivsBit_file)) {
/*
* XXX - the AFP 3.0 spec says this is "Four bytes", but
* also says the privileges are "stored in an FPUnixPrivs
* structure", which is 16 bytes long.
*
* We assume, for now, that the latter is true.
*/
decode_unix_privs(tree, tvb, offset);
offset += 16;
}
return (max_offset)?max_offset:offset;
}
/* -------------------------- */