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
|
--- mkhybrid-1.12a4.7/mkisofs.c Mon Aug 24 20:12:55 1998
+++ mkhybrid-1.12a4.7.new/mkisofs.c Thu Jan 14 11:53:57 1999
@@ -91,6 +91,7 @@
int verbose = 1;
int all_files = 0;
int follow_links = 0;
+int follow_links_sensible = 0;
int rationalize = 0;
int generate_tables = 0;
int print_size = 0;
@@ -106,6 +107,7 @@
char * system_id = SYSTEM_ID_DEFAULT;
char * boot_catalog = BOOT_CATALOG_DEFAULT;
char * boot_image = BOOT_IMAGE_DEFAULT;
+char follow_links_base[256];
int omit_period = 0; /* Violates iso9660, but these are a pain */
int transparent_compression = 0; /* So far only works with linux */
@@ -237,6 +239,8 @@
'D', NULL, "Disable deep directory relocation", ONE_DASH },
{ {"follow-links", no_argument, NULL, 'f'},
'f', NULL, "Follow symbolic links", ONE_DASH },
+ { {"follow-outside-links", required_argument, NULL, 'F'},
+ 'F', NULL, "Follow symbolic links which point outside the CD base directory", ONE_DASH },
#ifdef APPLE_HYB
{ {"apple", no_argument, NULL, 'g'},
'g', NULL, "Add Apple ISO9660 extensions", ONE_DASH },
@@ -682,6 +686,8 @@
char *log_file = 0; /* stderr log file re-direct */
#endif /* APPLE_HYB */
+ char old_dir[256];
+
if (argc < 2)
usage();
@@ -773,181 +779,189 @@
}
break;
case 'A':
- appid = optarg;
- if(strlen(appid) > 128) {
- fprintf(stderr,"Application-id string too long\n");
- exit(1);
- };
- break;
+ appid = optarg;
+ if(strlen(appid) > 128)
+ {
+ fprintf(stderr,"Application-id string too long\n");
+ exit(1);
+ }
+ break;
case 'd':
- omit_period++;
- break;
+ omit_period++;
+ break;
case 'D':
- RR_relocation_depth = 32767;
- break;
+ RR_relocation_depth = 32767;
+ break;
case 'f':
- follow_links++;
- break;
+ follow_links++;
+ break;
+ case 'F':
+ follow_links_sensible++;
+ getcwd (old_dir, 256);
+ chdir (optarg);
+ getcwd (follow_links_base, 256);
+ chdir (old_dir);
+ break;
case 'l':
- full_iso9660_filenames++;
- break;
+ full_iso9660_filenames++;
+ break;
case 'L':
- allow_leading_dots++;
- break;
+ allow_leading_dots++;
+ break;
case 'M':
- merge_image = optarg;
- break;
+ merge_image = optarg;
+ break;
case 'N':
- omit_version_number++;
- break;
+ omit_version_number++;
+ break;
case 'o':
- outfile = optarg;
- break;
+ outfile = optarg;
+ break;
case 'p':
- preparer = optarg;
- if(strlen(preparer) > 128) {
- fprintf(stderr,"Preparer string too long\n");
- exit(1);
- };
- break;
+ preparer = optarg;
+ if(strlen(preparer) > 128) {
+ fprintf(stderr,"Preparer string too long\n");
+ exit(1);
+ };
+ break;
case OPTION_PRINT_SIZE:
- print_size++;
- break;
+ print_size++;
+ break;
case 'P':
- publisher = optarg;
- if(strlen(publisher) > 128) {
- fprintf(stderr,"Publisher string too long\n");
- exit(1);
- };
- break;
+ publisher = optarg;
+ if(strlen(publisher) > 128) {
+ fprintf(stderr,"Publisher string too long\n");
+ exit(1);
+ };
+ break;
case OPTION_QUIET:
- verbose = 0;
- break;
+ verbose = 0;
+ break;
case 'R':
- use_RockRidge++;
- break;
+ use_RockRidge++;
+ break;
case 'r':
- rationalize++;
- use_RockRidge++;
- break;
+ rationalize++;
+ use_RockRidge++;
+ break;
case OPTION_SPLIT_OUTPUT:
- split_output++;
- break;
+ split_output++;
+ break;
#ifdef APPLE_HYB
case OPTION_TRANS_TBL:
- trans_tbl = optarg;
- /* fall through */
+ trans_tbl = optarg;
+ /* fall through */
#endif /* APPLE_HYB */
case 'T':
- generate_tables++;
- break;
+ generate_tables++;
+ break;
case 'V':
- volume_id = optarg;
- break;
+ volume_id = optarg;
+ break;
case 'v':
- verbose++;
- break;
+ verbose++;
+ break;
case 'z':
#ifdef VMS
- fprintf(stderr,"Transparent compression not supported with VMS\n");
- exit(1);
+ fprintf(stderr,"Transparent compression not supported with VMS\n");
+ exit(1);
#else
- transparent_compression++;
+ transparent_compression++;
#endif
- break;
+ break;
case 'x':
case 'm':
- /*
- * Somehow two options to do basically the same thing got added somewhere along
- * the way. The 'match' code supports limited globbing, so this is the one
- * that got selected. Unfortunately the 'x' switch is probably more intuitive.
+ /*
+ * Somehow two options to do basically the same thing got added somewhere along
+ * the way. The 'match' code supports limited globbing, so this is the one
+ * that got selected. Unfortunately the 'x' switch is probably more intuitive.
*/
- add_match(optarg);
- break;
+ add_match(optarg);
+ break;
case OPTION_I_HIDE:
- i_add_match(optarg);
- break;
+ i_add_match(optarg);
+ break;
case OPTION_J_HIDE:
- j_add_match(optarg);
- break;
+ j_add_match(optarg);
+ break;
case OPTION_HELP:
- usage ();
- exit (0);
- break;
+ usage ();
+ exit (0);
+ break;
case OPTION_NOSPLIT_SL_COMPONENT:
- split_SL_component = 0;
- break;
+ split_SL_component = 0;
+ break;
case OPTION_NOSPLIT_SL_FIELD:
- split_SL_field = 0;
- break;
+ split_SL_field = 0;
+ break;
#ifdef APPLE_HYB
case 'H':
- afpfile = optarg;
- hfs_last = MAP_LAST;
- break;
+ afpfile = optarg;
+ hfs_last = MAP_LAST;
+ break;
case 'h':
- apple_hyb = 1;
- break;
+ apple_hyb = 1;
+ break;
case 'g':
- apple_ext = 1;
- break;
+ apple_ext = 1;
+ break;
case OPTION_PROBE:
- probe = 1;
- break;
+ probe = 1;
+ break;
case OPTION_MACNAME:
- mac_name = 1;
- break;
+ mac_name = 1;
+ break;
case OPTION_NOMACFILES:
- nomacfiles = 1;
- break;
+ nomacfiles = 1;
+ break;
case OPTION_BOOT_HFS_FILE:
- hfs_boot_file = optarg;
- break;
+ hfs_boot_file = optarg;
+ break;
case OPTION_MAGIC_FILE:
- magic_file = optarg;
- hfs_last = MAG_LAST;
- break;
- /* Mac/Unix types to include */
+ magic_file = optarg;
+ hfs_last = MAG_LAST;
+ break;
+ /* Mac/Unix types to include */
case OPTION_CAP:
- hfs_select |= DO_CAP;
- break;
+ hfs_select |= DO_CAP;
+ break;
case OPTION_NETA:
- hfs_select |= DO_NETA;
- break;
+ hfs_select |= DO_NETA;
+ break;
case OPTION_DBL:
- hfs_select |= DO_DBL;
- break;
+ hfs_select |= DO_DBL;
+ break;
case OPTION_ESH:
case OPTION_USH:
- hfs_select |= DO_ESH;
- break;
+ hfs_select |= DO_ESH;
+ break;
case OPTION_FE:
- hfs_select |= DO_FEU;
- hfs_select |= DO_FEL;
- break;
+ hfs_select |= DO_FEU;
+ hfs_select |= DO_FEL;
+ break;
case OPTION_SGI:
case OPTION_XIN:
- hfs_select |= DO_SGI;
- break;
+ hfs_select |= DO_SGI;
+ break;
case OPTION_MBIN:
- hfs_select |= DO_MBIN;
- break;
+ hfs_select |= DO_MBIN;
+ break;
case OPTION_SGL:
- hfs_select |= DO_SGL;
- break;
+ hfs_select |= DO_SGL;
+ break;
case OPTION_CREATE_DT:
- create_dt = 0;
- break;
+ create_dt = 0;
+ break;
case OPTION_HFS_HIDE:
- hfs_add_match(optarg);
- break;
+ hfs_add_match(optarg);
+ break;
case OPTION_LOG_FILE:
- log_file = optarg;
- break;
+ log_file = optarg;
+ break;
#endif /* APPLE_HYB */
default:
- usage();
- exit(1);
+ usage();
+ exit(1);
}
parse_input_files:
diff -u mkhybrid-1.12a4.7/mkisofs.h mkhybrid-1.12a4.7.new/mkisofs.h
--- mkhybrid-1.12a4.7/mkisofs.h Mon Aug 24 19:55:07 1998
+++ mkhybrid-1.12a4.7.new/mkisofs.h Tue Jan 12 11:27:10 1999
@@ -280,6 +280,8 @@
extern int use_Joliet;
extern int rationalize;
extern int follow_links;
+extern int follow_links_sensible;
+extern char follow_links_base[];
extern int verbose;
extern int all_files;
extern int generate_tables;
--- mkhybrid-1.12a4.7/tree.c Mon Aug 24 20:06:37 1998
+++ mkhybrid-1.12a4.7.new/tree.c Thu Jan 14 12:03:29 1999
@@ -827,165 +827,181 @@
char *, path,
struct directory_entry *, de)
{
- DIR * current_dir;
- char whole_path[1024];
- struct dirent * d_entry;
- struct directory * parent;
- int dflag;
- char * old_path;
+ DIR * current_dir;
+ char whole_path[1024];
+ struct dirent * d_entry;
+ struct directory * parent;
+ int dflag;
+ char * old_path;
- current_dir = opendir(path);
- d_entry = NULL;
+ current_dir = opendir(path);
+ d_entry = NULL;
- /* Apparently NFS sometimes allows you to open the directory, but
- then refuses to allow you to read the contents. Allow for this */
+ /* Apparently NFS sometimes allows you to open the directory, but
+ then refuses to allow you to read the contents. Allow for this */
- old_path = path;
+ old_path = path;
- if(current_dir) d_entry = readdir(current_dir);
+ if(current_dir) d_entry = readdir(current_dir);
- if(!current_dir || !d_entry)
+ if(!current_dir || !d_entry)
{
- fprintf(stderr,"Unable to open directory %s\n", path);
- de->isorec.flags[0] &= ~2; /* Mark as not a directory */
- if(current_dir) closedir(current_dir);
- return 0;
+ fprintf(stderr,"Unable to open directory %s\n", path);
+ de->isorec.flags[0] &= ~2; /* Mark as not a directory */
+ if(current_dir) closedir(current_dir);
+ return 0;
}
- parent = de->filedir;
- /* Set up the struct for the current directory, and insert it into the
- tree */
+ parent = de->filedir;
+ /* Set up the struct for the current directory, and insert it into the
+ tree */
#ifdef VMS
- vms_path_fixup(path);
+ vms_path_fixup(path);
#endif
- /*
- * if entry for this sub-directory is hidden, then hide this directory
- */
- if (de->de_flags & INHIBIT_ISO9660_ENTRY)
- this_dir->dir_flags |= INHIBIT_ISO9660_ENTRY;
+ /*
+ * if entry for this sub-directory is hidden, then hide this directory
+ */
+ if (de->de_flags & INHIBIT_ISO9660_ENTRY)
+ this_dir->dir_flags |= INHIBIT_ISO9660_ENTRY;
- if (de->de_flags & INHIBIT_JOLIET_ENTRY)
- this_dir->dir_flags |= INHIBIT_JOLIET_ENTRY;
+ if (de->de_flags & INHIBIT_JOLIET_ENTRY)
+ this_dir->dir_flags |= INHIBIT_JOLIET_ENTRY;
- /*
- * Now we scan the directory itself, and look at what is inside of it.
- */
- dflag = 0;
- while(1==1){
+ /*
+ * Now we scan the directory itself, and look at what is inside of it.
+ */
+ dflag = 0;
+ while(1==1)
+ {
- /* The first time through, skip this, since we already asked for
- the first entry when we opened the directory. */
- if(dflag) d_entry = readdir(current_dir);
- dflag++;
-
- if(!d_entry) break;
-
- /* OK, got a valid entry */
-
- /* If we do not want all files, then pitch the backups. */
- if(!all_files){
- if( strchr(d_entry->d_name,'~')
- || strchr(d_entry->d_name,'#'))
- {
- if( verbose > 0 )
- {
- fprintf(stderr, "Ignoring file %s\n", d_entry->d_name);
- }
- continue;
- }
- }
+ /* The first time through, skip this, since we already asked for
+ the first entry when we opened the directory. */
+ if(dflag)
+ d_entry = readdir(current_dir);
+ dflag++;
+
+ if(!d_entry)
+ break;
+
+ /* OK, got a valid entry */
+
+ /* If we do not want all files, then pitch the backups. */
+ if(!all_files)
+ {
+ if(strchr(d_entry->d_name,'~') || strchr(d_entry->d_name,'#'))
+ {
+ if( verbose > 0 )
+ fprintf(stderr, "Ignoring file %s\n", d_entry->d_name);
+ continue;
+ }
+ }
#ifdef APPLE_HYB
- if (apple_both) {
- /* exclude certain HFS type files/directories for the time being */
- if (hfs_exclude(d_entry->d_name))
- continue;
- }
+ if (apple_both) {
+ /* exclude certain HFS type files/directories for the time being */
+ if (hfs_exclude(d_entry->d_name))
+ continue;
+ }
#endif /* APPLE_HYB */
- if(strlen(path)+strlen(d_entry->d_name) + 2 > sizeof(whole_path)){
- fprintf(stderr, "Overflow of stat buffer\n");
- exit(1);
- };
+ if(strlen(path)+strlen(d_entry->d_name) + 2 > sizeof(whole_path))
+ {
+ fprintf(stderr, "Overflow of stat buffer\n");
+ exit(1);
+ };
- /* Generate the complete ASCII path for this file */
- strcpy(whole_path, path);
+ /* Generate the complete ASCII path for this file */
+ strcpy(whole_path, path);
#ifndef VMS
- if(whole_path[strlen(whole_path)-1] != '/')
- strcat(whole_path, "/");
+ if(whole_path[strlen(whole_path)-1] != '/')
+ strcat(whole_path, "/");
#endif
- strcat(whole_path, d_entry->d_name);
+ strcat(whole_path, d_entry->d_name);
- /** Should we exclude this file ? */
- if (matches(d_entry->d_name) || matches(whole_path)) {
- if (verbose > 1) {
- fprintf(stderr, "Excluded by match: %s\n", whole_path);
- }
- continue;
- }
+ /** Should we exclude this file ? */
+ if (matches(d_entry->d_name) || matches(whole_path))
+ {
+ if (verbose > 1)
+ fprintf(stderr, "Excluded by match: %s\n", whole_path);
+ continue;
+ }
- if( generate_tables
#ifdef APPLE_HYB
- && strcmp(d_entry->d_name, trans_tbl) == 0 )
+ if(generate_tables && strcmp(d_entry->d_name, trans_tbl) == 0 )
#else
- && strcmp(d_entry->d_name, "TRANS.TBL") == 0 )
+ if(generate_tables && strcmp(d_entry->d_name, "TRANS.TBL") == 0 )
#endif /* APPLE_HYB */
- {
- /*
- * Ignore this entry. We are going to be generating new
- * versions of these files, and we need to ignore any
- * originals that we might have found.
- */
- if (verbose > 1)
- {
- fprintf(stderr, "Excluded: %s\n",whole_path);
- }
- continue;
- }
-
- /*
- * If we already have a '.' or a '..' entry, then don't
- * insert new ones.
- */
- if( strcmp(d_entry->d_name, ".") == 0
- && this_dir->dir_flags & DIR_HAS_DOT )
- {
- continue;
- }
-
- if( strcmp(d_entry->d_name, "..") == 0
- && this_dir->dir_flags & DIR_HAS_DOTDOT )
- {
- continue;
- }
+ {
+ /*
+ * Ignore this entry. We are going to be generating new
+ * versions of these files, and we need to ignore any
+ * originals that we might have found.
+ */
+ if (verbose > 1)
+ fprintf(stderr, "Excluded: %s\n",whole_path);
+ continue;
+ }
+
+ /*
+ * If we already have a '.' or a '..' entry, then don't
+ * insert new ones.
+ */
+ if(strcmp(d_entry->d_name,".") == 0 && this_dir->dir_flags & DIR_HAS_DOT)
+ continue;
+
+ if(strcmp(d_entry->d_name,"..") == 0 && this_dir->dir_flags&DIR_HAS_DOTDOT)
+ continue;
#if 0
- if (verbose > 1) fprintf(stderr, "%s\n",whole_path);
+ if (verbose > 1) fprintf(stderr, "%s\n",whole_path);
#endif
- /*
+ /*
* This actually adds the entry to the directory in question.
*/
#ifdef APPLE_HYB
- insert_file_entry(this_dir, whole_path, d_entry->d_name, 0);
+ insert_file_entry(this_dir, whole_path, d_entry->d_name, 0);
#else
- insert_file_entry(this_dir, whole_path, d_entry->d_name);
+ insert_file_entry(this_dir, whole_path, d_entry->d_name);
#endif /* APPLE_HYB */
- }
- closedir(current_dir);
+ }
+
+ closedir(current_dir);
#ifdef APPLE_HYB
- /* if we cached the HFS info stuff for this directory, then delete it */
- if (this_dir->hfs_info) {
- del_hfs_info(this_dir->hfs_info);
- this_dir->hfs_info = 0;
- }
+/* if we cached the HFS info stuff for this directory, then delete it */
+ if (this_dir->hfs_info) {
+ del_hfs_info(this_dir->hfs_info);
+ this_dir->hfs_info = 0;
+ }
#endif /* APPLE_HYB */
-
- return 1;
+ return 1;
}
+/* check_dirlevel: returns 1 if
+ * name is below the tree of follow_links_base */
+int check_dirlevel (char *name)
+{
+ char old[256] = {0,}, buf[256] = {0,}, b2[256], *c;
+
+ strcpy (b2, name);
+ c = strrchr (b2, '/');
+ if (c)
+ {
+ *c = '\0';
+ getcwd (old, 256);
+ chdir (b2);
+ getcwd (buf, 256);
+ chdir (old);
+
+ if (!strncmp (buf, follow_links_base, strlen (follow_links_base)))
+ return 1;
+ return 0;
+ }
+ else
+ return 1;
+}
/*
* Function: insert_file_entry
@@ -1008,132 +1024,170 @@
char *, short_name,
int, have_rsrc)
#else
-int
+ int
FDECL3(insert_file_entry,struct directory *, this_dir,
char *, whole_path,
char *, short_name)
#endif /* APPLE_HYB */
{
- struct stat statbuf, lstatbuf;
- struct directory_entry * s_entry, *s_entry1;
- int lstatus;
- int status;
- int deep_flag;
+ struct stat statbuf, lstatbuf;
+ struct directory_entry * s_entry, *s_entry1;
+ int lstatus;
+ int status;
+ int deep_flag;
#ifdef APPLE_HYB
- int x_hfs = 0;
- int htype;
+ int x_hfs = 0;
+ int htype;
#endif /* APPLE_HYB */
+ char link_buf[256];
+ int do_follow_links = 0;
- status = stat_filter(whole_path, &statbuf);
+ status = stat_filter(whole_path, &statbuf);
- lstatus = lstat_filter(whole_path, &lstatbuf);
+ lstatus = lstat_filter(whole_path, &lstatbuf);
- if( (status == -1) && (lstatus == -1) )
+ if( (status == -1) && (lstatus == -1) )
{
- /*
- * This means that the file doesn't exist, or isn't accessible.
- * Sometimes this is because of NFS permissions problems.
- */
- fprintf(stderr, "Non-existant or inaccessible: %s\n",whole_path);
- return 0;
+ /*
+ * This means that the file doesn't exist, or isn't accessible.
+ * Sometimes this is because of NFS permissions problems.
+ */
+ fprintf(stderr, "Non-existant or inaccessible: %s\n",whole_path);
+ return 0;
}
- if(this_dir == root && strcmp(short_name, ".") == 0)
- root_statbuf = statbuf; /* Save this for later on */
+ if(this_dir == root && strcmp(short_name, ".") == 0)
+ root_statbuf = statbuf; /* Save this for later on */
/* We do this to make sure that the root entries are consistent */
- if(this_dir == root && strcmp(short_name, "..") == 0)
+ if(this_dir == root && strcmp(short_name, "..") == 0)
{
- statbuf = root_statbuf;
- lstatbuf = root_statbuf;
+ statbuf = root_statbuf;
+ lstatbuf = root_statbuf;
}
- if(S_ISLNK(lstatbuf.st_mode))
- {
+ if(S_ISLNK(lstatbuf.st_mode))
+ {
- /* Here we decide how to handle the symbolic links. Here
- we handle the general case - if we are not following
- links or there is an error, then we must change
- something. If RR is in use, it is easy, we let RR
- describe the file. If not, then we punt the file. */
+ /* Here we decide how to handle the symbolic links. Here
+ we handle the general case - if we are not following
+ links or there is an error, then we must change
+ something. If RR is in use, it is easy, we let RR
+ describe the file. If not, then we punt the file. */
- if((status || !follow_links))
- {
- if(use_RockRidge)
- {
- status = 0;
- statbuf.st_size = 0;
- STAT_INODE(statbuf) = UNCACHED_INODE;
- statbuf.st_dev = (dev_t) UNCACHED_DEVICE;
- statbuf.st_mode = (statbuf.st_mode & ~S_IFMT) | S_IFREG;
- } else {
- if(follow_links)
+ /* First check for the sensible follow_links option */
+ if (follow_links_sensible)
{
- fprintf(stderr,
- "Unable to stat file %s - ignoring and continuing.\n",
- whole_path);
+ /* Where does the link point to? */
+ memset (link_buf, 0, 256);
+ readlink (whole_path, link_buf, 255);
+ if (check_dirlevel (link_buf))
+ {
+ /* Treat it as a symlink */
+ if (!use_RockRidge)
+ {
+ fprintf (stderr, "Ignoring symlink %s (which wouldn't be followed)\n",
+ whole_path);
+ }
+ else
+ {
+ do_follow_links = 0;
+ if (status)
+ {
+ status = 0;
+ statbuf.st_size = 0;
+ STAT_INODE(statbuf) = UNCACHED_INODE;
+ statbuf.st_dev = (dev_t) UNCACHED_DEVICE;
+ statbuf.st_mode = (statbuf.st_mode & ~S_IFMT) | S_IFREG;
+ }
+ }
+ }
+ else
+ {
+ /* Follow the link */
+ do_follow_links = 1;
+ }
}
- else
+ else if (!follow_links_sensible)
+ do_follow_links = follow_links;
+
+ if((status || !do_follow_links))
{
- fprintf(stderr,
- "Symlink %s ignored - continuing.\n",
- whole_path);
- return 0; /* Non Rock Ridge discs - ignore all symlinks */
+ if(use_RockRidge)
+ {
+ status = 0;
+ statbuf.st_size = 0;
+ STAT_INODE(statbuf) = UNCACHED_INODE;
+ statbuf.st_dev = (dev_t) UNCACHED_DEVICE;
+ statbuf.st_mode = (statbuf.st_mode & ~S_IFMT) | S_IFREG;
+ } else {
+ if(do_follow_links)
+ {
+ fprintf(stderr,
+ "Unable to stat file %s - ignoring and continuing.\n",
+ whole_path);
+ }
+ else
+ {
+ fprintf(stderr,
+ "Symlink %s ignored - continuing.\n",
+ whole_path);
+ return 0; /* Non Rock Ridge discs - ignore all symlinks */
+ }
+ }
}
- }
- }
- /* Here we handle a different kind of case. Here we have
- a symlink, but we want to follow symlinks. If we run
- across a directory loop, then we need to pretend that
- we are not following symlinks for this file. If this
- is the first time we have seen this, then make this
- seem as if there was no symlink there in the first
- place */
+ /* Here we handle a different kind of case. Here we have
+ a symlink, but we want to follow symlinks. If we run
+ across a directory loop, then we need to pretend that
+ we are not following symlinks for this file. If this
+ is the first time we have seen this, then make this
+ seem as if there was no symlink there in the first
+ place */
- if( follow_links
- && S_ISDIR(statbuf.st_mode) )
- {
- if( strcmp(short_name, ".")
- && strcmp(short_name, "..") )
- {
- if(find_directory_hash(statbuf.st_dev, STAT_INODE(statbuf)))
+ if( do_follow_links
+ && S_ISDIR(statbuf.st_mode) )
{
- if(!use_RockRidge)
- {
- fprintf(stderr, "Already cached directory seen (%s)\n",
- whole_path);
- return 0;
- }
- statbuf.st_size = 0;
- STAT_INODE(statbuf) = UNCACHED_INODE;
- statbuf.st_dev = (dev_t) UNCACHED_DEVICE;
- statbuf.st_mode = (statbuf.st_mode & ~S_IFMT) | S_IFREG;
+ if( strcmp(short_name, ".")
+ && strcmp(short_name, "..") )
+ {
+ if(find_directory_hash(statbuf.st_dev, STAT_INODE(statbuf)))
+ {
+ if(!use_RockRidge)
+ {
+ fprintf(stderr, "Already cached directory seen (%s)\n",
+ whole_path);
+ return 0;
+ }
+ statbuf.st_size = 0;
+ STAT_INODE(statbuf) = UNCACHED_INODE;
+ statbuf.st_dev = (dev_t) UNCACHED_DEVICE;
+ statbuf.st_mode = (statbuf.st_mode & ~S_IFMT) | S_IFREG;
+ }
+ else
+ {
+ lstatbuf = statbuf;
+ add_directory_hash(statbuf.st_dev, STAT_INODE(statbuf));
+ }
+ }
}
- else
+
+ /*
+ * For non-directories, we just copy the stat information over
+ * so we correctly include this file.
+ */
+ if( do_follow_links
+ && !S_ISDIR(statbuf.st_mode) )
{
- lstatbuf = statbuf;
- add_directory_hash(statbuf.st_dev, STAT_INODE(statbuf));
+ lstatbuf = statbuf;
}
- }
- }
-
- /*
- * For non-directories, we just copy the stat information over
- * so we correctly include this file.
- */
- if( follow_links
- && !S_ISDIR(statbuf.st_mode) )
- {
- lstatbuf = statbuf;
- }
}
/*
* Add directories to the cache so that we don't waste space even
* if we are supposed to be following symlinks.
*/
- if( follow_links
+ if( do_follow_links
&& strcmp(short_name, ".")
&& strcmp(short_name, "..")
&& S_ISDIR(statbuf.st_mode) )
@@ -1158,7 +1212,7 @@
/* Add this so that we can detect directory loops with hard links.
If we are set up to follow symlinks, then we skip this checking. */
- if( !follow_links
+ if( !do_follow_links
&& S_ISDIR(lstatbuf.st_mode)
&& strcmp(short_name, ".")
&& strcmp(short_name, "..") )
|