-
Notifications
You must be signed in to change notification settings - Fork 0
/
transcript.c
1283 lines (1137 loc) · 32.1 KB
/
transcript.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
/*
* Copyright (c) 2003, 2007 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/
#include "config.h"
#include <sys/types.h>
#include <sys/param.h>
#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h>
#endif
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include "applefile.h"
#include "base64.h"
#include "radstat.h"
#include "transcript.h"
#include "argcargv.h"
#include "code.h"
#include "cksum.h"
#include "pathcmp.h"
#include "largefile.h"
#include "list.h"
#include "wildcard.h"
char * convert_path_type( char *path );
int read_kfile( char *kfile, int location );
static void t_remove( int type, char *shortname );
static void t_display( void );
struct transcript *tran_head = NULL;
static struct transcript *prev_tran = NULL;
extern int edit_path;
extern int case_sensitive;
extern int tran_format;
static char *kdir;
static struct list *kfile_list;
struct list *special_list;
struct list *exclude_list;
char *path_prefix = NULL;
int edit_path;
int skip;
int cksum;
int fs_minus;
int exclude_warnings = 0;
FILE *outtran;
char *
convert_path_type( char *path )
{
int len = 0;
static char buf[ MAXPATHLEN ];
len = strlen( path );
if ( len == 1 ) {
if (( tran_format == T_ABSOLUTE ) && ( path[ 0 ] == '.' )) {
buf[ 0 ] = '/';
buf[ 1 ] = '\0';
} else if (( tran_format == T_RELATIVE ) && ( path[ 0 ] == '/' )) {
buf[ 0 ] = '.';
buf[ 1 ] = '\0';
} else {
/* Nothing to convert */
return( path );
}
} else {
if (( tran_format == T_ABSOLUTE ) && ( path[ 0 ] == '.' )) {
if ( path[ 1 ] == '/' ) {
/* Move past leading '.' */
path++;
if ( snprintf( buf, sizeof( buf ), "%s",
path ) >= MAXPATHLEN ) {
return( NULL );
}
} else {
/* Instert leading '/' */
if ( snprintf( buf, sizeof( buf ), "/%s",
path ) >= MAXPATHLEN ) {
return( NULL );
}
}
} else if (( tran_format == T_RELATIVE ) && ( path[ 0 ] == '/' )) {
/* Instert leading '.' */
if ( snprintf( buf, sizeof( buf ), ".%s", path ) >= MAXPATHLEN ) {
return( NULL );
}
} else {
/* Nothing to convert */
return( path );
}
}
return( buf );
}
void
transcript_parse( struct transcript *tran )
{
char line[ 2 * MAXPATHLEN ];
int length;
char *epath;
char **argv;
int ac;
/* read in the next line in the transcript, loop through blanks and # */
do {
if (( fgets( line, MAXPATHLEN, tran->t_in )) == NULL ) {
tran->t_eof = 1;
return;
}
tran->t_linenum++;
/* check to see if line contains the whole line */
length = strlen( line );
if ( line[ length - 1 ] != '\n' ) {
fprintf( stderr, "%s: line %d: line too long\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
} while ((( ac = argcargv( line, &argv )) == 0 ) || ( *argv[ 0 ] == '#' ));
if ( ac < 3 ) {
fprintf( stderr, "%s: line %d: minimum 3 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
if ( strlen( argv[ 0 ] ) != 1 ) {
fprintf( stderr, "%s: line %d: %s is too long to be a type\n",
tran->t_fullname, tran->t_linenum, argv[ 0 ] );
exit( 2 );
}
if ( argv[ 0 ][ 0 ] == '-' ) {
argv++;
ac--;
tran->t_pinfo.pi_minus = 1;
} else {
tran->t_pinfo.pi_minus = 0;
}
if ( argv[ 0 ][ 0 ] == '+' ) {
argv++;
ac--;
}
tran->t_pinfo.pi_type = argv[ 0 ][ 0 ];
if (( epath = decode( argv[ 1 ] )) == NULL ) {
fprintf( stderr, "%s: line %d: path too long\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
/* Convert path to match transcript type */
if (( epath = convert_path_type( epath )) == NULL ) {;
fprintf( stderr, "%s: line %d: path too long\n", tran->t_fullname,
tran->t_linenum );
exit( 2 );
}
if ( pathcasecmp( epath, tran->t_pinfo.pi_name, case_sensitive ) <= 0 ) {
fprintf( stderr, "%s: line %d: bad sort order\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
strcpy( tran->t_pinfo.pi_name, epath );
/* reading and parsing the line */
switch( *argv[ 0 ] ) {
case 'd': /* dir */
if (( ac != 5 ) && ( ac != 6 )) {
fprintf( stderr, "%s: line %d: expected 5 or 6 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
tran->t_pinfo.pi_stat.st_mode = strtol( argv[ 2 ], NULL, 8 );
tran->t_pinfo.pi_stat.st_uid = atoi( argv[ 3 ] );
tran->t_pinfo.pi_stat.st_gid = atoi( argv[ 4 ] );
if ( ac == 6 ) {
base64_d( argv[ 5 ], strlen( argv[ 5 ] ),
(char *)tran->t_pinfo.pi_afinfo.ai.ai_data );
} else {
memset( tran->t_pinfo.pi_afinfo.ai.ai_data, 0, FINFOLEN );
}
break;
case 'p':
case 'D':
case 's':
if ( ac != 5 ) {
fprintf( stderr, "%s: line %d: expected 5 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
tran->t_pinfo.pi_stat.st_mode = strtol( argv[ 2 ], NULL, 8 );
tran->t_pinfo.pi_stat.st_uid = atoi( argv[ 3 ] );
tran->t_pinfo.pi_stat.st_gid = atoi( argv[ 4 ] );
break;
case 'b': /* block or char */
case 'c':
if ( ac != 7 ) {
fprintf( stderr, "%s: line %d: expected 7 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
tran->t_pinfo.pi_stat.st_mode = strtol( argv[ 2 ], NULL, 8 );
tran->t_pinfo.pi_stat.st_uid = atoi( argv[ 3 ] );
tran->t_pinfo.pi_stat.st_gid = atoi( argv[ 4 ] );
tran->t_pinfo.pi_stat.st_rdev =
makedev( ( unsigned )( atoi( argv[ 5 ] )),
( unsigned )( atoi( argv[ 6 ] )));
break;
case 'l': /* link */
if ( ac == 3 ) { /* link without owner, group, mode */
tran->t_pinfo.pi_stat.st_mode = 0777;
tran->t_pinfo.pi_stat.st_uid = 0;
tran->t_pinfo.pi_stat.st_gid = 0;
} else if ( ac == 6 ) { /* link with owner, group, mode */
tran->t_pinfo.pi_stat.st_mode = strtol( argv[ 2 ], NULL, 8 );
tran->t_pinfo.pi_stat.st_uid = atoi( argv[ 3 ] );
tran->t_pinfo.pi_stat.st_gid = atoi( argv[ 4 ] );
} else {
fprintf( stderr, "%s: line %d: expected 3 or 6 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
if (( epath = decode( argv[ ac - 1 ] )) == NULL ) {
fprintf( stderr, "%s: line %d: target path too long\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
strcpy( tran->t_pinfo.pi_link, epath );
break;
case 'h': /* hard */
if ( ac != 3 ) {
fprintf( stderr, "%s: line %d: expected 3 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
if (( epath = decode( argv[ 2 ] )) == NULL ) {
fprintf( stderr, "%s: line %d: target path too long\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
if (( epath = convert_path_type( epath )) == NULL ) {
fprintf( stderr, "%s: line %d: path too long\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
strcpy( tran->t_pinfo.pi_link, epath );
break;
case 'a': /* hfs applefile */
case 'f': /* file */
if ( ac != 8 ) {
fprintf( stderr, "%s: line %d: expected 8 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
tran->t_pinfo.pi_stat.st_mode = strtol( argv[ 2 ], NULL, 8 );
tran->t_pinfo.pi_stat.st_uid = atoi( argv[ 3 ] );
tran->t_pinfo.pi_stat.st_gid = atoi( argv[ 4 ] );
tran->t_pinfo.pi_stat.st_mtime = atoi( argv[ 5 ] );
tran->t_pinfo.pi_stat.st_size = strtoofft( argv[ 6 ], NULL, 10 );
if ( tran->t_type != T_NEGATIVE ) {
if (( cksum ) && ( strcmp( "-", argv [ 7 ] ) == 0 )) {
fprintf( stderr, "%s: line %d: no cksums in transcript\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
}
strcpy( tran->t_pinfo.pi_cksum_b64, argv[ 7 ] );
break;
case 'e': /* extended attribute */
if ( ac != 4 ) {
fprintf( stderr, "%s: line %d: expected 4 arguments, got %d\n",
tran->t_fullname, tran->t_linenum, ac );
exit( 2 );
}
tran->t_pinfo.pi_stat.st_mode = ( S_IFREG | (mode_t)0444 );
tran->t_pinfo.pi_stat.st_size = strtoofft( argv[ 2 ], NULL, 10 );
if ( tran->t_type != T_NEGATIVE ) {
if ( cksum && strcmp( "-", argv[ 3 ] ) == 0 ) {
fprintf( stderr, "%s: line %d: no cksums in transcript\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
}
if ( xattr_get_name( epath, tran->t_pinfo.pi_xattrname ) == NULL ) {
fprintf( stderr, "%s: line %d: bad xattr name\n",
tran->t_fullname, tran->t_linenum );
exit( 2 );
}
strcpy( tran->t_pinfo.pi_cksum_b64, argv[ 3 ] );
break;
default:
fprintf( stderr,
"%s: line %d: unknown file type '%c'\n",
tran->t_fullname, tran->t_linenum, *argv[ 0 ] );
exit( 2 );
}
return;
}
void
t_print( struct pathinfo *fs, struct transcript *tran, int flag )
{
struct pathinfo *cur;
char *epath;
dev_t dev;
int print_minus = 0;
#ifdef __APPLE__
static char null_buf[ 32 ] = { 0 };
#endif /* __APPLE__ */
if ( edit_path == APPLICABLE ) {
cur = &tran->t_pinfo;
if (( fs != NULL ) && ( fs->pi_type != 'd' ) &&
( fs->pi_type != 'h' ) && ( fs->pi_stat.st_nlink > 1 )) {
hardlink_changed( fs, 1 );
}
} else {
cur = fs; /* What if this is NULL? */
}
/* Print name of transcript if it changed since the last t_print */
if (( edit_path == APPLICABLE )
&& (( flag == PR_TRAN_ONLY ) || ( flag == PR_DOWNLOAD )
|| ( flag == PR_STATUS_NEG ))
&& ( prev_tran != tran )) {
fprintf( outtran, "%s:\n", tran->t_shortname );
prev_tran = tran;
}
/*
* If a file is missing from the edit_path that was chosen, a - is
* printed and then the file name that is missing is printed.
*/
if ( edit_path == APPLICABLE ) {
if ( flag == PR_FS_ONLY ) {
print_minus = 1;
cur = fs;
} else if ( flag == PR_STATUS_MINUS ) {
fprintf( outtran, "- " );
}
} else if (( edit_path == CREATABLE ) &&
(( flag == PR_TRAN_ONLY ) || ( fs->pi_type == 'X' ))) {
print_minus = 1;
cur = &tran->t_pinfo;
}
if ( print_minus ) {
/* set fs_minus so we can handle excluded files in dirs to be deleted */
fs_minus = 1;
fprintf( outtran, "- " );
}
if (( epath = encode( cur->pi_name )) == NULL ) {
fprintf( stderr, "Filename too long: %s\n", cur->pi_name );
exit( 2 );
}
/* print out info to file based on type */
switch( cur->pi_type ) {
case 's':
case 'D':
case 'p':
fprintf( outtran, "%c %-37s\t%.4lo %5d %5d\n", cur->pi_type, epath,
(unsigned long )( T_MODE & cur->pi_stat.st_mode ),
(int)cur->pi_stat.st_uid, (int)cur->pi_stat.st_gid );
break;
case 'd':
#ifdef __APPLE__
if ( memcmp( cur->pi_afinfo.ai.ai_data, null_buf,
sizeof( null_buf )) != 0 ) {
char finfo_e[ SZ_BASE64_E( FINFOLEN ) ];
base64_e( (char *)cur->pi_afinfo.ai.ai_data, FINFOLEN, finfo_e );
fprintf( outtran, "%c %-37s\t%.4lo %5d %5d %s\n", cur->pi_type,
epath,
(unsigned long)( T_MODE & cur->pi_stat.st_mode ),
(int)cur->pi_stat.st_uid, (int)cur->pi_stat.st_gid,
finfo_e );
break;
}
#endif /* __APPLE__ */
fprintf( outtran, "%c %-37s\t%.4lo %5d %5d\n", cur->pi_type, epath,
(unsigned long )( T_MODE & cur->pi_stat.st_mode ),
(int)cur->pi_stat.st_uid, (int)cur->pi_stat.st_gid );
break;
case 'l':
fprintf( outtran, "%c %-37s\t%.4lo %5d %5d ", cur->pi_type, epath,
(unsigned long)( T_MODE & cur->pi_stat.st_mode ),
(int)cur->pi_stat.st_uid, (int)cur->pi_stat.st_gid );
if (( epath = encode( cur->pi_link )) == NULL ) {
fprintf( stderr, "Filename too long: %s\n", cur->pi_link );
exit( 2 );
}
fprintf( outtran, "%s\n", epath );
break;
case 'h':
fprintf( outtran, "%c %-37s\t", cur->pi_type, epath );
if (( epath = encode( cur->pi_link )) == NULL ) {
fprintf( stderr, "Filename too long: %s\n", cur->pi_link );
exit( 2 );
}
fprintf( outtran, "%s\n", epath );
break;
case 'a': /* hfs applesingle file */
case 'f':
if (( edit_path == APPLICABLE ) && (( flag == PR_TRAN_ONLY ) ||
( flag == PR_DOWNLOAD ))) {
fprintf( outtran, "+ " );
}
/*
* If we don't have a checksum yet, and checksums are on, calculate
* it now. Note that this can only be the case if "cur" is the
* filesystem, because transcript_parse() won't read lines without
* checksums if they are enabled. But, don't get the checksum
* if we are just going to remove the file.
*/
if (( *cur->pi_cksum_b64 == '-' ) && cksum && !print_minus ) {
if ( cur->pi_type == 'f' ) {
if ( do_cksum( cur->pi_name, cur->pi_cksum_b64 ) < 0 ) {
perror( cur->pi_name );
exit( 2 );
}
} else if ( cur->pi_type == 'a' ) {
if ( do_acksum( cur->pi_name, cur->pi_cksum_b64,
&cur->pi_afinfo ) < 0 ) {
perror( cur->pi_name );
exit( 2 );
}
}
}
/*
* PR_STATUS_NEG means we've had a permission change on a file,
* but the corresponding transcript is negative, hence, retain
* the file system's mtime. Woof!
*/
fprintf( outtran, "%c %-37s\t%.4lo %5d %5d %9d %7" PRIofft "d %s\n",
cur->pi_type, epath,
(unsigned long)( T_MODE & cur->pi_stat.st_mode ),
(int)cur->pi_stat.st_uid, (int)cur->pi_stat.st_gid,
( flag == PR_STATUS_NEG ) ?
(int)fs->pi_stat.st_mtime : (int)cur->pi_stat.st_mtime,
cur->pi_stat.st_size, cur->pi_cksum_b64 );
break;
case 'e':
if (( edit_path == APPLICABLE ) && (( flag == PR_TRAN_ONLY ) ||
( flag == PR_DOWNLOAD ))) {
fprintf( outtran, "+ " );
}
if (( *cur->pi_cksum_b64 == '-' ) && cksum && !print_minus ) {
if ( do_xcksum( xattr_get_path( cur->pi_name ), cur->pi_cksum_b64,
cur->pi_xattrname ) < 0 ) {
perror( cur->pi_name );
exit( 2 );
}
}
fprintf( outtran, "%c %-37s\t%7" PRIofft "d %s\n",
cur->pi_type, epath, cur->pi_stat.st_size, cur->pi_cksum_b64 );
break;
case 'c':
case 'b':
dev = cur->pi_stat.st_rdev;
fprintf( outtran, "%c %-37s\t%.4lo %5d %5d %5d %5d\n",
cur->pi_type, epath,
(unsigned long )( T_MODE & cur->pi_stat.st_mode ),
(int)cur->pi_stat.st_uid, (int)cur->pi_stat.st_gid,
(int)major(dev), (int)minor(dev) );
break;
case 'X' :
perror( cur->pi_name );
exit( 2 );
default:
fprintf( stderr, "%s: Unknown type: %c\n", cur->pi_name, cur->pi_type );
exit( 2 );
}
}
static int
t_compare( struct pathinfo *fs, struct transcript *tran )
{
int cmp;
mode_t mode;
mode_t tran_mode;
dev_t dev;
/*
* If the transcript is at EOF, and we've exhausted the filesystem,
* just return T_MOVE_FS, as this will cause transcript() to return.
*/
if (( tran->t_eof ) && ( fs == NULL )) {
return T_MOVE_FS;
}
if ( tran->t_eof ) {
cmp = -1;
} else {
if ( fs == NULL ) {
/*
* If we've exhausted the filesystem, cmp = 1 means that
* name is in tran, but not fs.
*/
cmp = 1;
} else {
cmp = pathcasecmp( fs->pi_name, tran->t_pinfo.pi_name,
case_sensitive );
}
}
if ( cmp > 0 ) {
/* name is in the tran, but not the fs */
t_print( fs, tran, PR_TRAN_ONLY );
return T_MOVE_TRAN;
}
if ( cmp < 0 ) {
/* name is not in the tran */
t_print( fs, tran, PR_FS_ONLY );
return T_MOVE_FS;
}
/* convert the modes */
mode = ( T_MODE & fs->pi_stat.st_mode );
tran_mode = ( T_MODE & tran->t_pinfo.pi_stat.st_mode );
/* the names match so check types */
if ( fs->pi_type != tran->t_pinfo.pi_type ) {
t_print( fs, tran, PR_DOWNLOAD );
return T_MOVE_BOTH;
}
/* compare the other components for each file type */
switch( fs->pi_type ) {
case 'a': /* hfs applefile */
case 'f': /* file */
if ( tran->t_type != T_NEGATIVE ) {
if ( fs->pi_stat.st_size != tran->t_pinfo.pi_stat.st_size ) {
t_print( fs, tran, PR_DOWNLOAD );
break;
}
if ( cksum ) {
if ( fs->pi_type == 'f' ) {
if ( do_cksum( fs->pi_name, fs->pi_cksum_b64 ) < 0 ) {
perror( fs->pi_name );
exit( 2 );
}
} else if ( fs->pi_type == 'a' ) {
if ( do_acksum( fs->pi_name, fs->pi_cksum_b64,
&fs->pi_afinfo ) < 0 ) {
perror( fs->pi_name );
exit( 2 );
}
}
if ( strcmp( fs->pi_cksum_b64, tran->t_pinfo.pi_cksum_b64 ) != 0 ) {
t_print( fs, tran, PR_DOWNLOAD );
break;
}
} else if ( fs->pi_stat.st_mtime != tran->t_pinfo.pi_stat.st_mtime ) {
t_print( fs, tran, PR_DOWNLOAD );
break;
}
if ( fs->pi_stat.st_mtime != tran->t_pinfo.pi_stat.st_mtime ) {
t_print( fs, tran, PR_STATUS );
break;
}
}
if (( fs->pi_stat.st_uid != tran->t_pinfo.pi_stat.st_uid ) ||
( fs->pi_stat.st_gid != tran->t_pinfo.pi_stat.st_gid ) ||
( mode != tran_mode )) {
if (( tran->t_type == T_NEGATIVE ) && ( edit_path == APPLICABLE )) {
t_print( fs, tran, PR_STATUS_NEG );
} else {
t_print( fs, tran, PR_STATUS );
}
}
break;
case 'e': /* extended attribute */
if ( tran->t_type != T_NEGATIVE ) {
if ( cksum ) {
if ( do_xcksum( xattr_get_path( fs->pi_name ), fs->pi_cksum_b64,
fs->pi_xattrname ) < 0 ) {
perror( fs->pi_name );
exit( 2 );
}
if ( strcmp( fs->pi_cksum_b64,
tran->t_pinfo.pi_cksum_b64 ) != 0 ) {
t_print( fs, tran, PR_DOWNLOAD );
break;
}
} else if ( fs->pi_stat.st_size != tran->t_pinfo.pi_stat.st_size ) {
t_print( fs, tran, PR_DOWNLOAD );
}
}
break;
case 'd': /* dir */
#ifdef __APPLE__
if ( tran->t_type != T_NEGATIVE ) {
if (( fs->pi_stat.st_uid != tran->t_pinfo.pi_stat.st_uid ) ||
( fs->pi_stat.st_gid != tran->t_pinfo.pi_stat.st_gid ) ||
( memcmp( fs->pi_afinfo.ai.ai_data,
tran->t_pinfo.pi_afinfo.ai.ai_data, FINFOLEN ) != 0 ) ||
( mode != tran_mode )) {
t_print( fs, tran, PR_STATUS );
}
break;
}
#endif /* __APPLE__ */
if (( fs->pi_stat.st_uid != tran->t_pinfo.pi_stat.st_uid ) ||
( fs->pi_stat.st_gid != tran->t_pinfo.pi_stat.st_gid ) ||
( mode != tran_mode )) {
t_print( fs, tran, PR_STATUS );
}
break;
case 'D':
case 'p':
case 's':
if (( fs->pi_stat.st_uid != tran->t_pinfo.pi_stat.st_uid ) ||
( fs->pi_stat.st_gid != tran->t_pinfo.pi_stat.st_gid ) ||
( mode != tran_mode )) {
t_print( fs, tran, PR_STATUS );
}
break;
case 'l': /* link */
if ( tran->t_type != T_NEGATIVE ) {
if (( strcmp( fs->pi_link, tran->t_pinfo.pi_link ) != 0 )
#ifdef HAVE_LCHOWN
|| ( fs->pi_stat.st_uid != tran->t_pinfo.pi_stat.st_uid ) ||
( fs->pi_stat.st_gid != tran->t_pinfo.pi_stat.st_gid )
#endif /* HAVE_LCHOWN */
#ifdef HAVE_LCHMOD
|| ( mode != tran_mode )
#endif /* HAVE_LCHMOD */
/* strcmp */ ) {
t_print( fs, tran, PR_STATUS );
}
}
break;
case 'h': /* hard */
if (( strcmp( fs->pi_link, tran->t_pinfo.pi_link ) != 0 ) ||
( hardlink_changed( fs, 0 ) != 0 )) {
t_print( fs, tran, PR_STATUS );
}
break;
case 'c':
/*
* negative character special files only check major and minor
* devices numbers. pseudo ttys can change uid, gid and mode for
* every login and this is normal behavior.
*/
dev = fs->pi_stat.st_rdev;
if ( tran->t_type != T_NEGATIVE ) {
if (( fs->pi_stat.st_uid != tran->t_pinfo.pi_stat.st_uid ) ||
( fs->pi_stat.st_gid != tran->t_pinfo.pi_stat.st_gid ) ||
( dev != tran->t_pinfo.pi_stat.st_rdev ) ||
( mode != tran_mode )) {
t_print( fs, tran, PR_STATUS );
}
} else if ( dev != tran->t_pinfo.pi_stat.st_rdev ) {
t_print( fs, tran, PR_STATUS );
}
break;
case 'b':
dev = fs->pi_stat.st_rdev;
if (( fs->pi_stat.st_uid != tran->t_pinfo.pi_stat.st_uid ) ||
( fs->pi_stat.st_gid != tran->t_pinfo.pi_stat.st_gid ) ||
( dev != tran->t_pinfo.pi_stat.st_rdev ) ||
( mode != tran_mode )) {
t_print( fs, tran, PR_STATUS );
}
break;
default:
fprintf( stderr, "%s: Unknown type: %c\n", fs->pi_name, fs->pi_type );
break;
}
return T_MOVE_BOTH;
}
int
t_exclude( char *path )
{
struct node *cur;
if ( list_size( exclude_list ) > 0 ) {
for ( cur = exclude_list->l_head; cur != NULL; cur = cur->n_next ) {
if ( wildcard( cur->n_path, path, case_sensitive )) {
return( 1 );
}
}
}
return( 0 );
}
/*
* Loop through the list of transcripts and compare each
* to find which transcript to start with. Only switch to the
* transcript if it is not at EOF. A transcript at EOF may
* still be returned.
*/
struct transcript *
transcript_select( void )
{
struct transcript *next_tran = NULL;
struct transcript *begin_tran = NULL;
for (;;) {
for ( begin_tran = tran_head, next_tran = tran_head->t_next;
next_tran != NULL; next_tran = next_tran->t_next ) {
if ( begin_tran->t_eof ) {
begin_tran = next_tran;
continue;
}
if ( ! next_tran->t_eof ) {
if ( pathcasecmp( next_tran->t_pinfo.pi_name,
begin_tran->t_pinfo.pi_name, case_sensitive ) < 0 ) {
begin_tran = next_tran;
}
}
}
/* move ahead other transcripts that match */
for ( next_tran = begin_tran->t_next; next_tran != NULL;
next_tran = next_tran->t_next ) {
if ( pathcasecmp( begin_tran->t_pinfo.pi_name,
next_tran->t_pinfo.pi_name, case_sensitive ) == 0 ) {
transcript_parse( next_tran );
}
}
/* This is presumably the NULL transcript. */
if ( !begin_tran->t_eof ) {
/*
* If the highest precedence transcript line has a leading '-',
* then just pretend it's not there.
*/
if ( begin_tran->t_pinfo.pi_minus ) {
transcript_parse( begin_tran );
continue;
}
/* If we match an exclude pattern, pretend we don't see it */
if ( begin_tran->t_type != T_SPECIAL &&
t_exclude( begin_tran->t_pinfo.pi_name )) {
if ( exclude_warnings ) {
fprintf( stderr, "Warning: excluding %s\n",
begin_tran->t_pinfo.pi_name );
}
transcript_parse( begin_tran );
continue;
}
/* Don't look outside of the initial path. */
if ( !ischildcase( begin_tran->t_pinfo.pi_name, path_prefix,
case_sensitive )) {
transcript_parse( begin_tran );
continue;
}
}
return( begin_tran );
}
}
int
transcript( char *path, struct radstat *rs, int parent_minus )
{
struct pathinfo pi;
int enter = 0;
int len;
char epath[ MAXPATHLEN ];
char *linkpath;
struct transcript *tran = NULL;
fs_minus = 0;
/*
* path is NULL when we've been called after the filesystem has been
* exhausted, to consume any remaining transcripts.
*/
if ( path != NULL ) {
/*
* check for exclude match first to avoid any unnecessary work.
* special files still have highest precedence.
*/
if ( t_exclude( path ) && !parent_minus ) {
if ( list_size( special_list ) <= 0
|| list_check( special_list, path ) == 0 ) {
if ( exclude_warnings ) {
fprintf( stderr, "Warning: excluding %s\n", path );
}
/* move the transcripts ahead */
tran = transcript_select();
return( 0 );
}
}
strcpy( pi.pi_name, path );
pi.pi_stat = rs->rs_stat;
pi.pi_type = rs->rs_type;
pi.pi_afinfo = rs->rs_afinfo;
#ifdef ENABLE_XATTR
if ( rs->rs_xname != NULL ) {
strcpy( pi.pi_xattrname, rs->rs_xname );
} else {
pi.pi_xattrname[ 0 ] = '\0';
}
#endif /* ENABLE_XATTR */
/* if it's multiply referenced, check if it's a hardlink */
if ( !S_ISDIR( pi.pi_stat.st_mode ) && ( pi.pi_stat.st_nlink > 1 ) &&
(( linkpath = hardlink( &pi )) != NULL )) {
pi.pi_type = 'h';
strcpy( pi.pi_link, linkpath );
} else if ( S_ISLNK( pi.pi_stat.st_mode )) {
len = readlink( pi.pi_name, epath, MAXPATHLEN );
epath[ len ] = '\0';
strcpy( pi.pi_link, epath );
}
/* By default, go into directories */
if ( S_ISDIR( pi.pi_stat.st_mode )) {
enter = 1;
} else {
enter = 0;
}
/* initialize cksum field. */
strcpy( pi.pi_cksum_b64, "-" );
}
for (;;) {
tran = transcript_select();
switch ( t_compare(( path ? &pi : NULL ), tran )) {
case T_MOVE_FS :
return( enter );
case T_MOVE_BOTH :
/* But don't go into negative directories */
if (( tran->t_type == T_NEGATIVE ) &&
( tran->t_pinfo.pi_type == 'd' )) {
enter = 2;
}
transcript_parse( tran );
return( enter );
case T_MOVE_TRAN :
transcript_parse( tran );
break;
default :
fprintf( stderr, "t_compare returned an unexpected value!\n" );
exit( 2 );
}
}
}
void
t_new( int type, char *fullname, char *shortname, char *kfile )
{
struct transcript *new;
if (( new = (struct transcript *)malloc( sizeof( struct transcript )))
== NULL ) {
perror( "malloc" );
exit( 2 );
}
memset( new, 0, sizeof( struct transcript ));
new->t_type = type;
switch ( type ) {
case T_NULL :
new->t_eof = 1;
break;
case T_POSITIVE :
case T_NEGATIVE :
case T_SPECIAL :
new->t_eof = 0;
new->t_linenum = 0;
strcpy( new->t_shortname, shortname );
strcpy( new->t_fullname, fullname );
strcpy( new->t_kfile, kfile );
if (( new->t_in = fopen( fullname, "r" )) == NULL ) {
perror( fullname );
exit( 2 );
}
transcript_parse( new );
break;
default :
break;
}
new->t_next = tran_head;
if ( tran_head != NULL ) {
tran_head->t_prev = new;
new->t_num = new->t_next->t_num + 1;
}
tran_head = new;
return;
}
static void
t_remove( int type, char *shortname )
{
struct transcript *cur, *next = NULL;
cur = tran_head;
while ( cur->t_type != T_NULL ) {
next = cur->t_next;
if (( cur->t_type == type )
&& ( strcmp( cur->t_shortname, shortname ) == 0 )) {
if ( cur == tran_head ) {
tran_head = cur->t_next;
free( cur );
} else {
cur->t_prev->t_next = cur->t_next;
cur->t_next->t_prev = cur->t_prev;
free( cur );
}
}
cur = next;
}
return;
}
static void
t_display( void )
{
struct transcript *cur = NULL;
for ( cur = tran_head; cur != NULL; cur = cur->t_next ) {
printf( "%d: ", cur->t_num );
switch( cur->t_type ) {
case T_POSITIVE:
printf( "p %s\n", cur->t_shortname );
break;
case T_NEGATIVE:
printf( "n %s\n", cur->t_shortname );
break;
case T_SPECIAL:
printf( "s %s\n", cur->t_shortname );
break;
case T_NULL: