2
Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
4
See the accompanying file LICENSE, version 2009-Jan-02 or later
5
(the contents of which are also included in unzip.h) for terms of use.
6
If, for some reason, all these files are missing, the Info-ZIP license
7
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
9
/*---------------------------------------------------------------------------
13
Unix-specific routines for use with Info-ZIP's UnZip 5.41 and later.
16
do_wild() <-- generic enough to put in fileio.c?
27
---------------------------------------------------------------------------*/
30
#define UNZIP_INTERNAL
35
#else /* SCO Unix, AIX, DNIX, TI SysV, Coherent 4.x, ... */
36
# if defined(__convexc__) || defined(SYSV) || defined(CRAY) || defined(BSD4_4)
40
#if defined(_AIX) || defined(__mpexl)
44
# if defined(_I386) || (defined(__COHERENT__) && (__COHERENT__ >= 0x420))
60
# include <sys/ndir.h>
70
# define dirent direct
75
typedef struct uxdirattr { /* struct for holding unix style directory */
76
struct uxdirattr *next; /* info until can be sorted and set at end */
77
char *fn; /* filename of directory */
79
iztimes t3; /* mtime, atime, ctime */
80
ztimbuf t2; /* modtime, actime */
82
unsigned perms; /* same as min_info.file_attr */
83
int have_uidgid; /* flag */
85
char fnbuf[1]; /* buffer stub for directory name */
87
#define UxAtt(d) ((uxdirattr *)d) /* typecast shortcut */
88
#endif /* SET_DIR_ATTRIB */
90
#ifdef ACORN_FTYPE_NFS
91
/* Acorn bits for NFS filetyping */
101
#endif /* ACORN_FTYPE_NFS */
103
/* static int created_dir; */ /* used in mapname(), checkdir() */
104
/* static int renamed_fullpath; */ /* ditto */
106
static unsigned filtattr OF((__GPRO__ unsigned perms));
109
/*****************************/
110
/* Strings used multiple */
111
/* times in unix.c */
112
/*****************************/
115
/* messages of code for setting file/directory attributes */
116
static ZCONST char CannotSetItemUidGid[] =
117
"warning: cannot set UID %lu and/or GID %lu for %s\n %s\n";
118
static ZCONST char CannotSetUidGid[] =
119
" (warning) cannot set UID %lu and/or GID %lu\n %s";
120
static ZCONST char CannotSetItemTimestamps[] =
121
"warning: cannot set modif./access times for %s\n %s\n";
122
static ZCONST char CannotSetTimestamps[] =
123
" (warning) cannot set modif./access times\n %s";
128
#ifdef NO_DIR /* for AT&T 3B1 */
130
#define opendir(path) fopen(path,"r")
131
#define closedir(dir) fclose(dir)
133
typedef struct zdir {
135
struct dirent *entry;
137
DIR *opendir OF((ZCONST char *dirspec));
138
void closedir OF((DIR *dirp));
139
struct dirent *readdir OF((DIR *dirp));
141
DIR *opendir(dirspec)
142
ZCONST char *dirspec;
146
if ((dirp = malloc(sizeof(DIR)) != NULL) {
147
if ((dirp->dirhandle = fopen(dirspec, "r")) == NULL) {
158
fclose(dirp->dirhandle);
163
* Apparently originally by Rich Salz.
164
* Cleaned up and modified by James W. Birdsall.
166
struct dirent *readdir(dirp)
174
if (fread(&(dirp->entry), sizeof (struct dirent), 1,
175
dirp->dirhandle) == 0)
176
return (struct dirent *)NULL;
177
else if ((dirp->entry).d_ino)
178
return &(dirp->entry);
180
} /* end function readdir() */
185
/**********************/
186
/* Function do_wild() */ /* for porting: dir separator; match(ignore_case) */
187
/**********************/
189
char *do_wild(__G__ wildspec)
191
ZCONST char *wildspec; /* only used first time on a given dir */
193
/* these statics are now declared in SYSTEM_SPECIFIC_GLOBALS in unxcfg.h:
194
static DIR *wild_dir = (DIR *)NULL;
195
static ZCONST char *wildname;
196
static char *dirname, matchname[FILNAMSIZ];
197
static int notfirstcall=FALSE, have_dirname, dirnamelen;
201
/* Even when we're just returning wildspec, we *always* do so in
202
* matchname[]--calling routine is allowed to append four characters
203
* to the returned string, and wildspec may be a pointer to argv[].
205
if (!G.notfirstcall) { /* first call: must initialize everything */
206
G.notfirstcall = TRUE;
208
if (!iswild(wildspec)) {
209
strncpy(G.matchname, wildspec, FILNAMSIZ);
210
G.matchname[FILNAMSIZ-1] = '\0';
211
G.have_dirname = FALSE;
216
/* break the wildspec into a directory part and a wildcard filename */
217
if ((G.wildname = (ZCONST char *)strrchr(wildspec, '/')) == NULL) {
220
G.have_dirname = FALSE;
221
G.wildname = wildspec;
223
++G.wildname; /* point at character after '/' */
224
G.dirnamelen = G.wildname - wildspec;
225
if ((G.dirname = (char *)malloc(G.dirnamelen+1)) == (char *)NULL) {
226
Info(slide, 0x201, ((char *)slide,
227
"warning: cannot allocate wildcard buffers\n"));
228
strncpy(G.matchname, wildspec, FILNAMSIZ);
229
G.matchname[FILNAMSIZ-1] = '\0';
230
return G.matchname; /* but maybe filespec was not a wildcard */
232
strncpy(G.dirname, wildspec, G.dirnamelen);
233
G.dirname[G.dirnamelen] = '\0'; /* terminate for strcpy below */
234
G.have_dirname = TRUE;
237
if ((G.wild_dir = (zvoid *)opendir(G.dirname)) != (zvoid *)NULL) {
238
while ((file = readdir((DIR *)G.wild_dir)) !=
239
(struct dirent *)NULL) {
240
Trace((stderr, "do_wild: readdir returns %s\n",
241
FnFilter1(file->d_name)));
242
if (file->d_name[0] == '.' && G.wildname[0] != '.')
243
continue; /* Unix: '*' and '?' do not match leading dot */
244
if (match(file->d_name, G.wildname, 0 WISEP) &&/*0=case sens.*/
245
/* skip "." and ".." directory entries */
246
strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) {
247
Trace((stderr, "do_wild: match() succeeds\n"));
248
if (G.have_dirname) {
249
strcpy(G.matchname, G.dirname);
250
strcpy(G.matchname+G.dirnamelen, file->d_name);
252
strcpy(G.matchname, file->d_name);
256
/* if we get to here directory is exhausted, so close it */
257
closedir((DIR *)G.wild_dir);
258
G.wild_dir = (zvoid *)NULL;
260
Trace((stderr, "do_wild: opendir(%s) returns NULL\n",
261
FnFilter1(G.dirname)));
263
/* return the raw wildspec in case that works (e.g., directory not
264
* searchable, but filespec was not wild and file is readable) */
265
strncpy(G.matchname, wildspec, FILNAMSIZ);
266
G.matchname[FILNAMSIZ-1] = '\0';
270
/* last time through, might have failed opendir but returned raw wildspec */
271
if ((DIR *)G.wild_dir == (DIR *)NULL) {
272
G.notfirstcall = FALSE; /* nothing left--reset for new wildspec */
278
/* If we've gotten this far, we've read and matched at least one entry
279
* successfully (in a previous call), so dirname has been copied into
282
while ((file = readdir((DIR *)G.wild_dir)) != (struct dirent *)NULL) {
283
Trace((stderr, "do_wild: readdir returns %s\n",
284
FnFilter1(file->d_name)));
285
if (file->d_name[0] == '.' && G.wildname[0] != '.')
286
continue; /* Unix: '*' and '?' do not match leading dot */
287
if (match(file->d_name, G.wildname, 0 WISEP)) { /* 0 == case sens. */
288
Trace((stderr, "do_wild: match() succeeds\n"));
289
if (G.have_dirname) {
290
/* strcpy(G.matchname, G.dirname); */
291
strcpy(G.matchname+G.dirnamelen, file->d_name);
293
strcpy(G.matchname, file->d_name);
298
closedir((DIR *)G.wild_dir); /* at least one entry read; nothing left */
299
G.wild_dir = (zvoid *)NULL;
300
G.notfirstcall = FALSE; /* reset for new wildspec */
305
} /* end function do_wild() */
313
# define S_ISUID 0004000 /* set user id on execution */
316
# define S_ISGID 0002000 /* set group id on execution */
319
# define S_ISVTX 0001000 /* save swapped text even after use */
322
/************************/
323
/* Function filtattr() */
324
/************************/
325
/* This is used to clear or keep the SUID and SGID bits on file permissions.
326
* It's possible that a file in an archive could have one of these bits set
327
* and, unknown to the person unzipping, could allow others to execute the
328
* file as the user or group. The new option -K bypasses this check.
331
static unsigned filtattr(__G__ perms)
335
/* keep setuid/setgid/tacky perms? */
337
perms &= ~(S_ISUID | S_ISGID | S_ISVTX);
339
return (0xffff & perms);
340
} /* end function filtattr() */
346
/**********************/
347
/* Function mapattr() */
348
/**********************/
354
ulg tmp = G.crec.external_file_attributes;
356
G.pInfo->file_attr = 0;
357
/* initialized to 0 for check in "default" branch below... */
359
switch (G.pInfo->hostnum) {
361
tmp = (unsigned)(tmp>>17 & 7); /* Amiga RWE bits */
362
G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
366
if ((tmp & 0xF0000000L) != 0x40000000L)
367
tmp &= 0x01FFFFFFL; /* not a dir, mask all ftype bits */
369
tmp &= 0x41FFFFFFL; /* leave directory bit as set */
380
G.pInfo->file_attr = (unsigned)(tmp >> 16);
381
if (G.pInfo->file_attr == 0 && G.extra_field) {
382
/* Some (non-Info-ZIP) implementations of Zip for Unix and
383
* VMS (and probably others ??) leave 0 in the upper 16-bit
384
* part of the external_file_attributes field. Instead, they
385
* store file permission attributes in some extra field.
386
* As a work-around, we search for the presence of one of
387
* these extra fields and fall back to the MSDOS compatible
388
* part of external_file_attributes if one of the known
389
* e.f. types has been detected.
390
* Later, we might implement extraction of the permission
391
* bits from the VMS extra field. But for now, the work-around
392
* should be sufficient to provide "readable" extracted files.
393
* (For ASI Unix e.f., an experimental remap of the e.f.
394
* mode value IS already provided!)
398
uch *ef = G.extra_field;
399
unsigned ef_len = G.crec.extra_field_length;
401
while (!r && ef_len >= EB_HEADSIZE) {
403
ebLen = (unsigned)makeword(ef+EB_LEN);
404
if (ebLen > (ef_len - EB_HEADSIZE))
405
/* discoverd some e.f. inconsistency! */
409
if (ebLen >= (EB_ASI_MODE+2)) {
411
(unsigned)makeword(ef+(EB_HEADSIZE+EB_ASI_MODE));
412
/* force stop of loop: */
413
ef_len = (ebLen + EB_HEADSIZE);
416
/* else: fall through! */
418
/* "found nondecypherable e.f. with perm. attr" */
423
ef_len -= (ebLen + EB_HEADSIZE);
424
ef += (ebLen + EB_HEADSIZE);
429
/* Check if the file is a (POSIX-compatible) symbolic link.
430
* We restrict symlink support to those "made-by" hosts that
431
* are known to support symbolic links.
433
G.pInfo->symlink = S_ISLNK(G.pInfo->file_attr) &&
434
SYMLINK_HOST(G.pInfo->hostnum);
439
/* all remaining cases: expand MSDOS read-only bit into write perms */
441
/* PKWARE's PKZip for Unix marks entries as FS_FAT_, but stores the
442
* Unix attributes in the upper 16 bits of the external attributes
443
* field, just like Info-ZIP's Zip for Unix. We try to use that
444
* value, after a check for consistency with the MSDOS attribute
447
G.pInfo->file_attr = (unsigned)(tmp >> 16);
454
/* Ensure that DOS subdir bit is set when the entry's name ends
455
* in a '/'. Some third-party Zip programs fail to set the subdir
456
* bit for directory entries.
458
if ((tmp & 0x10) == 0) {
459
extent fnlen = strlen(G.filename);
460
if (fnlen > 0 && G.filename[fnlen-1] == '/')
463
/* read-only bit --> write perms; subdir bit --> dir exec bit */
464
tmp = !(tmp & 1) << 1 | (tmp & 0x10) >> 4;
465
if ((G.pInfo->file_attr & 0700) == (unsigned)(0400 | tmp<<6)) {
466
/* keep previous G.pInfo->file_attr setting, when its "owner"
467
* part appears to be consistent with DOS attribute flags!
470
/* Entries "made by FS_FAT_" could have been zipped on a
471
* system that supports POSIX-style symbolic links.
473
G.pInfo->symlink = S_ISLNK(G.pInfo->file_attr) &&
474
(G.pInfo->hostnum == FS_FAT_);
478
G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
480
} /* end switch (host-OS-created-by) */
482
/* for originating systems with no concept of "group," "other," "system": */
483
umask( (int)(tmp=umask(0)) ); /* apply mask to expanded r/w(/x) perms */
484
G.pInfo->file_attr &= ~tmp;
488
} /* end function mapattr() */
494
/************************/
495
/* Function mapname() */
496
/************************/
498
int mapname(__G__ renamed)
503
* MPN_OK - no problem detected
504
* MPN_INF_TRUNC - caution (truncated filename)
505
* MPN_INF_SKIP - info "skip entry" (dir doesn't exist)
506
* MPN_ERR_SKIP - error -> skip entry
507
* MPN_ERR_TOOLONG - error -> path is too long
508
* MPN_NOMEM - error (memory allocation failed) -> skip entry
509
* [also MPN_VOL_LABEL, MPN_CREATED_DIR]
512
char pathcomp[FILNAMSIZ]; /* path-component buffer */
513
char *pp, *cp=(char *)NULL; /* character pointers */
514
char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
515
#ifdef ACORN_FTYPE_NFS
516
char *lastcomma=(char *)NULL; /* pointer to last comma in pathcomp */
517
RO_extra_block *ef_spark; /* pointer Acorn FTYPE ef block */
519
int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */
521
register unsigned workch; /* hold the character being tested */
524
/*---------------------------------------------------------------------------
525
Initialize various pointers and counters and stuff.
526
---------------------------------------------------------------------------*/
528
if (G.pInfo->vollabel)
529
return MPN_VOL_LABEL; /* can't set disk volume labels in Unix */
531
/* can create path as long as not just freshening, or if user told us */
532
G.create_dirs = (!uO.fflag || renamed);
534
G.created_dir = FALSE; /* not yet */
536
/* user gave full pathname: don't prepend rootpath */
537
G.renamed_fullpath = (renamed && (*G.filename == '/'));
539
if (checkdir(__G__ (char *)NULL, INIT) == MPN_NOMEM)
540
return MPN_NOMEM; /* initialize path buffer, unless no memory */
542
*pathcomp = '\0'; /* initialize translation buffer */
543
pp = pathcomp; /* point to translation buffer */
544
if (uO.jflag) /* junking directories */
545
cp = (char *)strrchr(G.filename, '/');
546
if (cp == (char *)NULL) /* no '/' or not junking dirs */
547
cp = G.filename; /* point to internal zipfile-member pathname */
549
++cp; /* point to start of last component of path */
551
/*---------------------------------------------------------------------------
552
Begin main loop through characters in filename.
553
---------------------------------------------------------------------------*/
555
while ((workch = (uch)*cp++) != 0) {
558
case '/': /* can assume -j flag not given */
560
if (strcmp(pathcomp, ".") == 0) {
561
/* don't bother appending "./" to the path */
563
} else if (!uO.ddotflag && strcmp(pathcomp, "..") == 0) {
564
/* "../" dir traversal detected, skip over it */
566
killed_ddot = TRUE; /* set "show message" flag */
568
/* when path component is not empty, append it now */
569
if (*pathcomp != '\0' &&
570
((error = checkdir(__G__ pathcomp, APPEND_DIR))
571
& MPN_MASK) > MPN_INF_TRUNC)
573
pp = pathcomp; /* reset conversion buffer for next piece */
574
lastsemi = (char *)NULL; /* leave direct. semi-colons alone */
577
#ifdef __CYGWIN__ /* Cygwin runs on Win32, apply FAT/NTFS filename rules */
578
case ':': /* drive spec not stored, so no colon allowed */
579
case '\\': /* '\\' may come as normal filename char (not */
580
case '<': /* dir sep char!) from unix-like file system */
581
case '>': /* no redirection symbols allowed either */
582
case '|': /* no pipe signs allowed */
583
case '"': /* no double quotes allowed */
584
case '?': /* no wildcards allowed */
586
*pp++ = '_'; /* these rules apply equally to FAT and NTFS */
590
case ';': /* VMS version (or DEC-20 attrib?) */
592
*pp++ = ';'; /* keep for now; remove VMS ";##" */
593
break; /* later, if requested */
595
#ifdef ACORN_FTYPE_NFS
596
case ',': /* NFS filetype extension */
598
*pp++ = ','; /* keep for now; may need to remove */
599
break; /* later, if requested */
603
case ' ': /* change spaces to underscore under */
604
*pp++ = '_'; /* MTS; leave as spaces under Unix */
609
/* disable control character filter when requested,
610
* else allow 8-bit characters (e.g. UTF-8) in filenames:
613
(isprint(workch) || (128 <= workch && workch <= 254)))
614
*pp++ = (char)workch;
617
} /* end while loop */
619
/* Show warning when stripping insecure "parent dir" path components */
620
if (killed_ddot && QCOND2) {
621
Info(slide, 0, ((char *)slide,
622
"warning: skipped \"../\" path component(s) in %s\n",
623
FnFilter1(G.filename)));
624
if (!(error & ~MPN_MASK))
625
error = (error & MPN_MASK) | PK_WARN;
628
/*---------------------------------------------------------------------------
629
Report if directory was created (and no file to create: filename ended
630
in '/'), check name to be sure it exists, and combine path and name be-
632
---------------------------------------------------------------------------*/
634
if (G.filename[strlen(G.filename) - 1] == '/') {
635
checkdir(__G__ G.filename, GETPATH);
638
Info(slide, 0, ((char *)slide, " creating: %s\n",
639
FnFilter1(G.filename)));
642
/* Filter out security-relevant attributes bits. */
643
G.pInfo->file_attr = filtattr(__G__ G.pInfo->file_attr);
644
/* When extracting non-UNIX directories or when extracting
645
* without UID/GID restoration or SGID preservation, any
646
* SGID flag inherited from the parent directory should be
647
* maintained to allow files extracted into this new folder
648
* to inherit the GID setting from the parent directory.
650
if (G.pInfo->hostnum != UNIX_ || !(uO.X_flag || uO.K_flag)) {
651
/* preserve SGID bit when inherited from parent dir */
652
if (!SSTAT(G.filename, &G.statbuf)) {
653
G.pInfo->file_attr |= G.statbuf.st_mode & S_ISGID;
655
perror("Could not read directory attributes");
659
/* set approx. dir perms (make sure can still read/write in dir) */
660
if (chmod(G.filename, G.pInfo->file_attr | 0700))
661
perror("chmod (directory attributes) error");
663
/* set dir time (note trailing '/') */
664
return (error & ~MPN_MASK) | MPN_CREATED_DIR;
666
/* dir existed already; don't look for data to extract */
667
return (error & ~MPN_MASK) | MPN_INF_SKIP;
670
*pp = '\0'; /* done with pathcomp: terminate it */
672
/* if not saving them, remove VMS version numbers (appended ";###") */
673
if (!uO.V_flag && lastsemi) {
675
while (isdigit((uch)(*pp)))
677
if (*pp == '\0') /* only digits between ';' and end: nuke */
681
/* On UNIX (and compatible systems), "." and ".." are reserved for
682
* directory navigation and cannot be used as regular file names.
683
* These reserved one-dot and two-dot names are mapped to "_" and "__".
685
if (strcmp(pathcomp, ".") == 0)
687
else if (strcmp(pathcomp, "..") == 0)
688
strcpy(pathcomp, "__");
690
#ifdef ACORN_FTYPE_NFS
691
/* translate Acorn filetype information if asked to do so */
692
if (uO.acorn_nfs_ext &&
693
(ef_spark = (RO_extra_block *)
694
getRISCOSexfield(G.extra_field, G.lrec.extra_field_length))
695
!= (RO_extra_block *)NULL)
697
/* file *must* have a RISC OS extra field */
698
long ft = (long)makelong(ef_spark->loadaddr);
702
while (isxdigit((uch)(*pp))) ++pp;
703
if (pp == lastcomma+4 && *pp == '\0') *lastcomma='\0'; /* nuke */
705
if ((ft & 1<<31)==0) ft=0x000FFD00;
706
sprintf(pathcomp+strlen(pathcomp), ",%03x", (int)(ft>>8) & 0xFFF);
708
#endif /* ACORN_FTYPE_NFS */
710
if (*pathcomp == '\0') {
711
Info(slide, 1, ((char *)slide, "mapname: conversion of %s failed\n",
712
FnFilter1(G.filename)));
713
return (error & ~MPN_MASK) | MPN_ERR_SKIP;
716
checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
717
checkdir(__G__ G.filename, GETPATH);
721
} /* end function mapname() */
726
#if 0 /*========== NOTES ==========*/
728
extract-to dir: a:path/
729
buildpath: path1/path2/ ... (NULL-terminated)
733
loop over chars in zipfile member name
734
checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
735
(d:/tmp/unzip/) (disk:[tmp.unzip.)
736
(d:/tmp/unzip/jj/) (disk:[tmp.unzip.jj.)
737
(d:/tmp/unzip/jj/temp/) (disk:[tmp.unzip.jj.temp.)
738
finally add filename itself and check for existence? (could use with rename)
739
(d:/tmp/unzip/jj/temp/msg.outdir) (disk:[tmp.unzip.jj.temp]msg.outdir)
740
checkdir(name, GETPATH) --> copy path to name and free space
747
/***********************/
748
/* Function checkdir() */
749
/***********************/
751
int checkdir(__G__ pathcomp, flag)
757
* MPN_OK - no problem detected
758
* MPN_INF_TRUNC - (on APPEND_NAME) truncated filename
759
* MPN_INF_SKIP - path doesn't exist, not allowed to create
760
* MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path
761
* exists and is not a directory, but is supposed to be
762
* MPN_ERR_TOOLONG - path is too long
763
* MPN_NOMEM - can't allocate memory for filename buffers
766
/* static int rootlen = 0; */ /* length of rootpath */
767
/* static char *rootpath; */ /* user's "extract-to" directory */
768
/* static char *buildpath; */ /* full path (so far) to extracted file */
769
/* static char *end; */ /* pointer to end of buildpath ('\0') */
772
# define FUNCTION (flag & FN_MASK)
776
/*---------------------------------------------------------------------------
777
APPEND_DIR: append the path component to the path being built and check
778
for its existence. If doesn't exist and we are creating directories, do
779
so for this one; else signal success or error as appropriate.
780
---------------------------------------------------------------------------*/
782
if (FUNCTION == APPEND_DIR) {
783
int too_long = FALSE;
788
Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp)));
789
while ((*G.end = *pathcomp++) != '\0')
791
#ifdef SHORT_NAMES /* path components restricted to 14 chars, typically */
792
if ((G.end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
793
*(G.end = old_end + FILENAME_MAX) = '\0';
796
/* GRR: could do better check, see if overrunning buffer as we go:
797
* check end-buildpath after each append, set warning variable if
798
* within 20 of FILNAMSIZ; then if var set, do careful check when
799
* appending. Clear variable when begin new path. */
801
/* next check: need to append '/', at least one-char name, '\0' */
802
if ((G.end-G.buildpath) > FILNAMSIZ-3)
803
too_long = TRUE; /* check if extracting dir? */
804
if (SSTAT(G.buildpath, &G.statbuf)) { /* path doesn't exist */
805
if (!G.create_dirs) { /* told not to create (freshening) */
807
return MPN_INF_SKIP; /* path doesn't exist: nothing to do */
810
Info(slide, 1, ((char *)slide,
811
"checkdir error: path too long: %s\n",
812
FnFilter1(G.buildpath)));
814
/* no room for filenames: fatal */
815
return MPN_ERR_TOOLONG;
817
if (mkdir(G.buildpath, 0777) == -1) { /* create the directory */
818
Info(slide, 1, ((char *)slide,
819
"checkdir error: cannot create %s\n\
821
unable to process %s.\n",
822
FnFilter2(G.buildpath),
824
FnFilter1(G.filename)));
826
/* path didn't exist, tried to create, failed */
829
G.created_dir = TRUE;
830
} else if (!S_ISDIR(G.statbuf.st_mode)) {
831
Info(slide, 1, ((char *)slide,
832
"checkdir error: %s exists but is not directory\n\
833
unable to process %s.\n",
834
FnFilter2(G.buildpath), FnFilter1(G.filename)));
836
/* path existed but wasn't dir */
840
Info(slide, 1, ((char *)slide,
841
"checkdir error: path too long: %s\n", FnFilter1(G.buildpath)));
843
/* no room for filenames: fatal */
844
return MPN_ERR_TOOLONG;
848
Trace((stderr, "buildpath now = [%s]\n", FnFilter1(G.buildpath)));
851
} /* end if (FUNCTION == APPEND_DIR) */
853
/*---------------------------------------------------------------------------
854
GETPATH: copy full path to the string pointed at by pathcomp, and free
856
---------------------------------------------------------------------------*/
858
if (FUNCTION == GETPATH) {
859
strcpy(pathcomp, G.buildpath);
860
Trace((stderr, "getting and freeing path [%s]\n",
861
FnFilter1(pathcomp)));
863
G.buildpath = G.end = (char *)NULL;
867
/*---------------------------------------------------------------------------
868
APPEND_NAME: assume the path component is the filename; append it and
869
return without checking for existence.
870
---------------------------------------------------------------------------*/
872
if (FUNCTION == APPEND_NAME) {
877
Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp)));
878
while ((*G.end = *pathcomp++) != '\0') {
880
#ifdef SHORT_NAMES /* truncate name at 14 characters, typically */
881
if ((G.end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
882
*(G.end = old_end + FILENAME_MAX) = '\0';
884
if ((G.end-G.buildpath) >= FILNAMSIZ) {
886
Info(slide, 0x201, ((char *)slide,
887
"checkdir warning: path too long; truncating\n\
889
FnFilter1(G.filename), FnFilter2(G.buildpath)));
890
return MPN_INF_TRUNC; /* filename truncated */
893
Trace((stderr, "buildpath now = [%s]\n", FnFilter1(G.buildpath)));
894
/* could check for existence here, prompt for new name... */
898
/*---------------------------------------------------------------------------
899
INIT: allocate and initialize buffer space for the file currently being
900
extracted. If file was renamed with an absolute path, don't prepend the
902
---------------------------------------------------------------------------*/
904
/* GRR: for VMS and TOPS-20, add up to 13 to strlen */
906
if (FUNCTION == INIT) {
907
Trace((stderr, "initializing buildpath to "));
908
#ifdef ACORN_FTYPE_NFS
909
if ((G.buildpath = (char *)malloc(strlen(G.filename)+G.rootlen+
910
(uO.acorn_nfs_ext ? 5 : 1)))
912
if ((G.buildpath = (char *)malloc(strlen(G.filename)+G.rootlen+1))
916
if ((G.rootlen > 0) && !G.renamed_fullpath) {
917
strcpy(G.buildpath, G.rootpath);
918
G.end = G.buildpath + G.rootlen;
923
Trace((stderr, "[%s]\n", FnFilter1(G.buildpath)));
927
/*---------------------------------------------------------------------------
928
ROOT: if appropriate, store the path in rootpath and create it if
929
necessary; else assume it's a zipfile member and return. This path
930
segment gets used in extracting all members from every zipfile specified
932
---------------------------------------------------------------------------*/
934
#if (!defined(SFX) || defined(SFX_EXDIR))
935
if (FUNCTION == ROOT) {
936
Trace((stderr, "initializing root path to [%s]\n",
937
FnFilter1(pathcomp)));
938
if (pathcomp == (char *)NULL) {
942
if (G.rootlen > 0) /* rootpath was already set, nothing to do */
944
if ((G.rootlen = strlen(pathcomp)) > 0) {
947
if ((tmproot = (char *)malloc(G.rootlen+2)) == (char *)NULL) {
951
strcpy(tmproot, pathcomp);
952
if (tmproot[G.rootlen-1] == '/') {
953
tmproot[--G.rootlen] = '\0';
955
if (G.rootlen > 0 && (SSTAT(tmproot, &G.statbuf) ||
956
!S_ISDIR(G.statbuf.st_mode)))
957
{ /* path does not exist */
958
if (!G.create_dirs /* || iswild(tmproot) */ ) {
961
/* skip (or treat as stored file) */
964
/* create the directory (could add loop here scanning tmproot
965
* to create more than one level, but why really necessary?) */
966
if (mkdir(tmproot, 0777) == -1) {
967
Info(slide, 1, ((char *)slide,
968
"checkdir: cannot create extraction directory: %s\n\
970
FnFilter1(tmproot), strerror(errno)));
973
/* path didn't exist, tried to create, and failed: */
974
/* file exists, or 2+ subdir levels required */
978
tmproot[G.rootlen++] = '/';
979
tmproot[G.rootlen] = '\0';
980
if ((G.rootpath = (char *)realloc(tmproot, G.rootlen+1)) == NULL) {
985
Trace((stderr, "rootpath now = [%s]\n", FnFilter1(G.rootpath)));
989
#endif /* !SFX || SFX_EXDIR */
991
/*---------------------------------------------------------------------------
992
END: free rootpath, immediately prior to program exit.
993
---------------------------------------------------------------------------*/
995
if (FUNCTION == END) {
996
Trace((stderr, "freeing rootpath\n"));
1004
return MPN_INVALID; /* should never reach */
1006
} /* end function checkdir() */
1014
/********************/
1015
/* Function mkdir() */
1016
/********************/
1018
int mkdir(path, mode)
1020
int mode; /* ignored */
1022
* returns: 0 - successful
1023
* -1 - failed (errno not set, however)
1026
char command[FILNAMSIZ+40]; /* buffer for system() call */
1028
/* GRR 930416: added single quotes around path to avoid bug with
1029
* creating directories with ampersands in name; not yet tested */
1030
sprintf(command, "IFS=\" \t\n\" /bin/mkdir '%s' 2>/dev/null", path);
1031
if (system(command))
1036
#endif /* NO_MKDIR */
1041
#if (!defined(MTS) || defined(SET_DIR_ATTRIB))
1042
static int get_extattribs OF((__GPRO__ iztimes *pzt, ulg z_uidgid[2]));
1044
static int get_extattribs(__G__ pzt, z_uidgid)
1049
/*---------------------------------------------------------------------------
1050
Convert from MSDOS-format local time and date to Unix-format 32-bit GMT
1051
time: adjust base year from 1980 to 1970, do usual conversions from
1052
yy/mm/dd hh:mm:ss to elapsed seconds, and account for timezone and day-
1053
light savings time differences. If we have a Unix extra field, however,
1054
we're laughing: both mtime and atime are ours. On the other hand, we
1055
then have to check for restoration of UID/GID.
1056
---------------------------------------------------------------------------*/
1057
int have_uidgid_flg;
1058
unsigned eb_izux_flg;
1060
eb_izux_flg = (G.extra_field ? ef_scan_for_izux(G.extra_field,
1061
G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,
1063
(G.tz_is_valid ? pzt : NULL),
1068
if (eb_izux_flg & EB_UT_FL_MTIME) {
1069
TTrace((stderr, "\nget_extattribs: Unix e.f. modif. time = %ld\n",
1072
pzt->mtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
1074
if (eb_izux_flg & EB_UT_FL_ATIME) {
1075
TTrace((stderr, "get_extattribs: Unix e.f. access time = %ld\n",
1078
pzt->atime = pzt->mtime;
1079
TTrace((stderr, "\nget_extattribs: modification/access times = %ld\n",
1083
/* if -X option was specified and we have UID/GID info, restore it */
1085
#ifdef RESTORE_UIDGID
1086
(uO.X_flag && (eb_izux_flg & EB_UX2_VALID));
1090
return have_uidgid_flg;
1092
#endif /* !MTS || SET_DIR_ATTRIB */
1098
/****************************/
1099
/* Function close_outfile() */
1100
/****************************/
1102
void close_outfile(__G) /* GRR: change to return PK-style warning level */
1106
iztimes t3; /* mtime, atime, ctime */
1107
ztimbuf t2; /* modtime, actime */
1110
int have_uidgid_flg;
1112
have_uidgid_flg = get_extattribs(__G__ &(zt.t3), z_uidgid);
1114
/*---------------------------------------------------------------------------
1115
If symbolic links are supported, allocate storage for a symlink control
1116
structure, put the uncompressed "data" and other required info in it, and
1117
add the structure to the "deferred symlinks" chain. Since we know it's a
1118
symbolic link to start with, we shouldn't have to worry about overflowing
1119
unsigned ints with unsigned longs.
1120
---------------------------------------------------------------------------*/
1124
extent ucsize = (extent)G.lrec.ucsize;
1125
# ifdef SET_SYMLINK_ATTRIBS
1126
extent attribsize = sizeof(unsigned) +
1127
(have_uidgid_flg ? sizeof(z_uidgid) : 0);
1129
extent attribsize = 0;
1131
/* size of the symlink entry is the sum of
1132
* (struct size (includes 1st '\0') + 1 additional trailing '\0'),
1133
* system specific attribute data size (might be 0),
1134
* and the lengths of name and link target.
1136
extent slnk_entrysize = (sizeof(slinkentry) + 1) + attribsize +
1137
ucsize + strlen(G.filename);
1138
slinkentry *slnk_entry;
1140
if (slnk_entrysize < ucsize) {
1141
Info(slide, 0x201, ((char *)slide,
1142
"warning: symbolic link (%s) failed: mem alloc overflow\n",
1143
FnFilter1(G.filename)));
1148
if ((slnk_entry = (slinkentry *)malloc(slnk_entrysize)) == NULL) {
1149
Info(slide, 0x201, ((char *)slide,
1150
"warning: symbolic link (%s) failed: no mem\n",
1151
FnFilter1(G.filename)));
1155
slnk_entry->next = NULL;
1156
slnk_entry->targetlen = ucsize;
1157
slnk_entry->attriblen = attribsize;
1158
# ifdef SET_SYMLINK_ATTRIBS
1159
memcpy(slnk_entry->buf, &(G.pInfo->file_attr),
1161
if (have_uidgid_flg)
1162
memcpy(slnk_entry->buf + 4, z_uidgid, sizeof(z_uidgid));
1164
slnk_entry->target = slnk_entry->buf + slnk_entry->attriblen;
1165
slnk_entry->fname = slnk_entry->target + ucsize + 1;
1166
strcpy(slnk_entry->fname, G.filename);
1168
/* move back to the start of the file to re-read the "link data" */
1171
if (fread(slnk_entry->target, 1, ucsize, G.outfile) != ucsize)
1173
Info(slide, 0x201, ((char *)slide,
1174
"warning: symbolic link (%s) failed\n",
1175
FnFilter1(G.filename)));
1180
fclose(G.outfile); /* close "link" file for good... */
1181
slnk_entry->target[ucsize] = '\0';
1183
Info(slide, 0, ((char *)slide, "-> %s ",
1184
FnFilter1(slnk_entry->target)));
1185
/* add this symlink record to the list of deferred symlinks */
1186
if (G.slink_last != NULL)
1187
G.slink_last->next = slnk_entry;
1189
G.slink_head = slnk_entry;
1190
G.slink_last = slnk_entry;
1193
#endif /* SYMLINKS */
1196
if (G.extra_field) {
1197
static void qlfix OF((__GPRO__ uch *ef_ptr, unsigned ef_len));
1199
qlfix(__G__ G.extra_field, G.lrec.extra_field_length);
1203
#if (defined(NO_FCHOWN))
1207
/* if -X option was specified and we have UID/GID info, restore it */
1209
/* check that both uid and gid values fit into their data sizes */
1210
&& ((ulg)(uid_t)(z_uidgid[0]) == z_uidgid[0])
1211
&& ((ulg)(gid_t)(z_uidgid[1]) == z_uidgid[1])) {
1212
TTrace((stderr, "close_outfile: restoring Unix UID/GID info\n"));
1213
#if (defined(NO_FCHOWN))
1214
if (chown(G.filename, (uid_t)z_uidgid[0], (gid_t)z_uidgid[1]))
1216
if (fchown(fileno(G.outfile), (uid_t)z_uidgid[0], (gid_t)z_uidgid[1]))
1220
Info(slide, 0x201, ((char *)slide, CannotSetItemUidGid,
1221
z_uidgid[0], z_uidgid[1], FnFilter1(G.filename),
1224
Info(slide, 0x201, ((char *)slide, CannotSetUidGid,
1225
z_uidgid[0], z_uidgid[1], strerror(errno)));
1229
#if (!defined(NO_FCHOWN) && defined(NO_FCHMOD))
1233
#if (!defined(NO_FCHOWN) && !defined(NO_FCHMOD))
1234
/*---------------------------------------------------------------------------
1235
Change the file permissions from default ones to those stored in the
1237
---------------------------------------------------------------------------*/
1239
if (fchmod(fileno(G.outfile), filtattr(__G__ G.pInfo->file_attr)))
1240
perror("fchmod (file attributes) error");
1243
#endif /* !NO_FCHOWN && !NO_FCHMOD */
1245
/* skip restoring time stamps on user's request */
1246
if (uO.D_flag <= 1) {
1247
/* set the file's access and modification times */
1248
if (utime(G.filename, &(zt.t2))) {
1250
Info(slide, 0x201, ((char *)slide, CannotSetItemTimestamps,
1251
FnFilter1(G.filename), strerror(errno)));
1253
Info(slide, 0x201, ((char *)slide, CannotSetTimestamps,
1258
#if (defined(NO_FCHOWN) || defined(NO_FCHMOD))
1259
/*---------------------------------------------------------------------------
1260
Change the file permissions from default ones to those stored in the
1262
---------------------------------------------------------------------------*/
1265
if (chmod(G.filename, filtattr(__G__ G.pInfo->file_attr)))
1266
perror("chmod (file attributes) error");
1268
#endif /* NO_FCHOWN || NO_FCHMOD */
1270
} /* end function close_outfile() */
1275
#if (defined(SYMLINKS) && defined(SET_SYMLINK_ATTRIBS))
1276
int set_symlnk_attribs(__G__ slnk_entry)
1278
slinkentry *slnk_entry;
1280
if (slnk_entry->attriblen > 0) {
1281
# if (!defined(NO_LCHOWN))
1282
if (slnk_entry->attriblen > sizeof(unsigned)) {
1283
ulg *z_uidgid_p = (zvoid *)(slnk_entry->buf + sizeof(unsigned));
1284
/* check that both uid and gid values fit into their data sizes */
1285
if (((ulg)(uid_t)(z_uidgid_p[0]) == z_uidgid_p[0]) &&
1286
((ulg)(gid_t)(z_uidgid_p[1]) == z_uidgid_p[1])) {
1288
"set_symlnk_attribs: restoring Unix UID/GID info for\n\
1290
FnFilter1(slnk_entry->fname)));
1291
if (lchown(slnk_entry->fname,
1292
(uid_t)z_uidgid_p[0], (gid_t)z_uidgid_p[1]))
1294
Info(slide, 0x201, ((char *)slide, CannotSetItemUidGid,
1295
z_uidgid_p[0], z_uidgid_p[1], FnFilter1(slnk_entry->fname),
1300
# endif /* !NO_LCHOWN */
1301
# if (!defined(NO_LCHMOD))
1303
"set_symlnk_attribs: restoring Unix attributes for\n %s\n",
1304
FnFilter1(slnk_entry->fname)));
1305
if (lchmod(slnk_entry->fname,
1306
filtattr(__G__ *(unsigned *)(zvoid *)slnk_entry->buf)))
1307
perror("lchmod (file attributes) error");
1308
# endif /* !NO_LCHMOD */
1310
/* currently, no error propagation... */
1312
} /* end function set_symlnk_attribs() */
1313
#endif /* SYMLINKS && SET_SYMLINK_ATTRIBS */
1316
#ifdef SET_DIR_ATTRIB
1317
/* messages of code for setting directory attributes */
1319
static ZCONST char DirlistChmodFailed[] =
1320
"warning: cannot set permissions for %s\n %s\n";
1324
int defer_dir_attribs(__G__ pd)
1330
d_entry = (uxdirattr *)malloc(sizeof(uxdirattr) + strlen(G.filename));
1331
*pd = (direntry *)d_entry;
1332
if (d_entry == (uxdirattr *)NULL) {
1335
d_entry->fn = d_entry->fnbuf;
1336
strcpy(d_entry->fn, G.filename);
1338
d_entry->perms = G.pInfo->file_attr;
1340
d_entry->have_uidgid = get_extattribs(__G__ &(d_entry->u.t3),
1343
} /* end function defer_dir_attribs() */
1346
int set_direc_attribs(__G__ d)
1352
if (UxAtt(d)->have_uidgid &&
1353
/* check that both uid and gid values fit into their data sizes */
1354
((ulg)(uid_t)(UxAtt(d)->uidgid[0]) == UxAtt(d)->uidgid[0]) &&
1355
((ulg)(gid_t)(UxAtt(d)->uidgid[1]) == UxAtt(d)->uidgid[1]) &&
1356
chown(UxAtt(d)->fn, (uid_t)UxAtt(d)->uidgid[0],
1357
(gid_t)UxAtt(d)->uidgid[1]))
1359
Info(slide, 0x201, ((char *)slide, CannotSetItemUidGid,
1360
UxAtt(d)->uidgid[0], UxAtt(d)->uidgid[1], FnFilter1(d->fn),
1365
/* Skip restoring directory time stamps on user' request. */
1366
if (uO.D_flag <= 0) {
1367
/* restore directory timestamps */
1368
if (utime(d->fn, &UxAtt(d)->u.t2)) {
1369
Info(slide, 0x201, ((char *)slide, CannotSetItemTimestamps,
1370
FnFilter1(d->fn), strerror(errno)));
1376
if (chmod(d->fn, UxAtt(d)->perms)) {
1377
Info(slide, 0x201, ((char *)slide, DirlistChmodFailed,
1378
FnFilter1(d->fn), strerror(errno)));
1382
#endif /* !NO_CHMOD */
1384
} /* end function set_direc_attribs() */
1386
#endif /* SET_DIR_ATTRIB */
1393
/***************************/
1394
/* Function stamp_file() */
1395
/***************************/
1397
int stamp_file(fname, modtime)
1403
tp.modtime = tp.actime = modtime;
1404
return (utime(fname, &tp));
1406
} /* end function stamp_file() */
1408
#endif /* TIMESTAMP */
1415
/************************/
1416
/* Function version() */
1417
/************************/
1422
#if (defined(__GNUC__) && defined(NX_CURRENT_COMPILER_RELEASE))
1423
char cc_namebuf[40];
1424
char cc_versbuf[40];
1426
#if (defined(__SUNPRO_C))
1427
char cc_versbuf[17];
1429
#if (defined(__HP_cc) || defined(__IBMC__))
1430
char cc_versbuf[25];
1432
#if (defined(__DECC_VER))
1433
char cc_versbuf[17];
1436
#if (defined(CRAY) && defined(_RELEASE))
1437
char cc_versbuf[40];
1438
#endif /* (CRAY && _RELEASE) */
1439
#endif /* __DECC_VER */
1440
#endif /* __HP_cc || __IBMC__ */
1441
#endif /* __SUNPRO_C */
1442
#endif /* (__GNUC__ && NX_CURRENT_COMPILER_RELEASE) */
1444
#if ((defined(CRAY) || defined(cray)) && defined(_UNICOS))
1445
char os_namebuf[40];
1447
#if defined(__NetBSD__)
1448
char os_namebuf[40];
1452
/* Pyramid, NeXT have problems with huge macro expansion, too: no Info() */
1453
sprintf((char *)slide, LoadFarString(CompiledWith),
1456
# ifdef NX_CURRENT_COMPILER_RELEASE
1457
(sprintf(cc_namebuf, "NeXT DevKit %d.%02d ",
1458
NX_CURRENT_COMPILER_RELEASE/100, NX_CURRENT_COMPILER_RELEASE%100),
1460
(strlen(__VERSION__) > 8)? "(gcc)" :
1461
(sprintf(cc_versbuf, "(gcc %s)", __VERSION__), cc_versbuf),
1463
"gcc ", __VERSION__,
1466
#if defined(__SUNPRO_C)
1467
"Sun C ", (sprintf(cc_versbuf, "version %x", __SUNPRO_C), cc_versbuf),
1469
#if (defined(__HP_cc))
1471
(((__HP_cc% 100) == 0) ?
1472
(sprintf(cc_versbuf, "version A.%02d.%02d",
1473
(__HP_cc/ 10000), ((__HP_cc% 10000)/ 100))) :
1474
(sprintf(cc_versbuf, "version A.%02d.%02d.%02d",
1475
(__HP_cc/ 10000), ((__HP_cc% 10000)/ 100), (__HP_cc% 100))),
1478
#if (defined(__DECC_VER))
1480
(sprintf(cc_versbuf, "%c%d.%d-%03d",
1481
((cc_verstyp = (__DECC_VER / 10000) % 10) == 6 ? 'T' :
1482
(cc_verstyp == 8 ? 'S' : 'V')),
1483
__DECC_VER / 10000000,
1484
(__DECC_VER % 10000000) / 100000, __DECC_VER % 1000),
1487
#if defined(CRAY) && defined(_RELEASE)
1488
"cc ", (sprintf(cc_versbuf, "version %d", _RELEASE), cc_versbuf),
1492
(sprintf(cc_versbuf, "version %d.%d.%d",
1493
(__IBMC__ / 100), ((__IBMC__ / 10) % 10), (__IBMC__ % 10)),
1498
# define IZ_CC_NAME "cc "
1500
IZ_CC_NAME, __VERSION__
1503
# define IZ_CC_NAME "cc"
1506
#endif /* ?__VERSION__ */
1507
#endif /* ?__IBMC__ */
1508
#endif /* ?(CRAY && _RELEASE) */
1509
#endif /* ?__DECC_VER */
1510
#endif /* ?__HP_cc */
1511
#endif /* ?__SUNPRO_C */
1512
#endif /* ?__GNUC__ */
1515
# define IZ_OS_NAME "Unix"
1519
#if defined(sgi) || defined(__sgi)
1520
" (Silicon Graphics IRIX)",
1525
" (Sun SPARC/Solaris)",
1526
# else /* may or may not be SunOS */
1530
# if defined(sun386) || defined(i386)
1533
# if defined(mc68020) || defined(__mc68020__)
1535
# else /* mc68010 or mc68000: Sun 2 or earlier */
1553
#if defined(CRAY) || defined(cray)
1555
(sprintf(os_namebuf, " (Cray UNICOS release %d)", _UNICOS), os_namebuf),
1560
#if defined(uts) || defined(UTS)
1565
" (NeXTStep/black)",
1567
" (NeXTStep for Intel)",
1569
#else /* the next dozen or so are somewhat order-dependent */
1588
(sprintf(os_namebuf, " (NetBSD 0.8%c)", (char)(NetBSD0_8 - 1 + 'A')),
1592
(sprintf(os_namebuf, " (NetBSD 0.9%c)", (char)(NetBSD0_9 - 1 + 'A')),
1596
(sprintf(os_namebuf, " (NetBSD 1.0%c)", (char)(NetBSD1_0 - 1 + 'A')),
1599
(BSD4_4 == 0.5)? " (NetBSD before 0.9)" : " (NetBSD 1.1 or later)",
1605
(BSD4_4 == 0.5)? " (FreeBSD 1.x)" : " (FreeBSD 2.0 or later)",
1608
(BSD4_4 == 0.5)? " (BSD/386 1.0)" : " (BSD/386 1.1 or later)",
1611
(BSD4_4 == 1)? " (386BSD, post-4.4 release)" : " (386BSD)",
1616
#if defined(i686) || defined(__i686) || defined(__i686__)
1619
#if defined(i586) || defined(__i586) || defined(__i586__)
1622
#if defined(i486) || defined(__i486) || defined(__i486__)
1625
#if defined(i386) || defined(__i386) || defined(__i386__)
1637
# else /* __alpha? */
1662
" Mac OS X Intel i32",
1665
" Mac OS X PowerPC",
1668
" Mac OS X PowerPC64",
1671
# endif /* __ppc64__ */
1672
# endif /* __ppc__ */
1673
# endif /* __i386__ */
1678
#endif /* QNX Neutrino */
1684
#endif /* Pyramid */
1691
#endif /* BSDI BSD/386 */
1693
#endif /* FreeBSD */
1694
#endif /* SCO Xenix */
1695
#endif /* SCO Unix */
1715
(*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
1717
} /* end function version() */
1727
long d_length __attribute__ ((packed)); /* file length */
1728
unsigned char d_access __attribute__ ((packed)); /* file access type */
1729
unsigned char d_type __attribute__ ((packed)); /* file type */
1730
long d_datalen __attribute__ ((packed)); /* data length */
1731
long d_reserved __attribute__ ((packed));/* Unused */
1732
short d_szname __attribute__ ((packed)); /* size of name */
1733
char d_name[36] __attribute__ ((packed));/* name area */
1734
long d_update __attribute__ ((packed)); /* last update */
1735
long d_refdate __attribute__ ((packed));
1736
long d_backup __attribute__ ((packed)); /* EOD */
1739
#define LONGID "QDOS02"
1740
#define EXTRALEN (sizeof(struct qdirect) + 8)
1741
#define JBLONGID "QZHD"
1742
#define JBEXTRALEN (sizeof(jbextra) - 4 * sizeof(char))
1745
char eb_header[4] __attribute__ ((packed)); /* place_holder */
1746
char longid[8] __attribute__ ((packed));
1747
struct qdirect header __attribute__ ((packed));
1751
char eb_header[4]; /* place_holder */
1753
struct qdirect header;
1758
/* The following two functions SH() and LG() convert big-endian short
1759
* and long numbers into native byte order. They are some kind of
1760
* counterpart to the generic UnZip's makeword() and makelong() functions.
1762
static ush SH(ush val)
1766
swapbuf[1] = (uch)(val & 0xff);
1767
swapbuf[0] = (uch)(val >> 8);
1768
return (*(ush *)swapbuf);
1773
static ulg LG(ulg val)
1775
/* convert the big-endian unsigned long number `val' to the machine
1776
* dependent representation
1780
swapbuf[1] = SH((ush)(val & 0xffff));
1781
swapbuf[0] = SH((ush)(val >> 16));
1782
return (*(ulg *)swapbuf);
1787
static void qlfix(__G__ ef_ptr, ef_len)
1792
while (ef_len >= EB_HEADSIZE)
1794
unsigned eb_id = makeword(EB_ID + ef_ptr);
1795
unsigned eb_len = makeword(EB_LEN + ef_ptr);
1797
if (eb_len > (ef_len - EB_HEADSIZE)) {
1798
/* discovered some extra field inconsistency! */
1800
"qlfix: block length %u > rest ef_size %u\n", eb_len,
1801
ef_len - EB_HEADSIZE));
1815
qdosextra *extra = (qdosextra *)ef_ptr;
1816
jbextra *jbp = (jbextra *)ef_ptr;
1818
if (!strncmp(extra->longid, LONGID, strlen(LONGID)))
1820
if (eb_len != EXTRALEN)
1822
Info(slide, 0x201, ((char *)slide,
1823
"warning: invalid length in Qdos field for %s\n",
1824
FnFilter1(G.filename)));
1826
Info(slide, 0x201, ((char *)slide,
1827
"warning: invalid length in Qdos field"));
1829
if (extra->header.d_type)
1831
dlen = extra->header.d_datalen;
1835
if (!strncmp(jbp->longid, JBLONGID, strlen(JBLONGID)))
1837
if (eb_len != JBEXTRALEN)
1839
Info(slide, 0x201, ((char *)slide,
1840
"warning: invalid length in QZ field for %s\n",
1841
FnFilter1(G.filename)));
1843
Info(slide, 0x201, ((char *)slide,
1844
"warning: invalid length in QZ field"));
1845
if (jbp->header.d_type)
1847
dlen = jbp->header.d_datalen;
1851
if ((long)LG(dlen) > 0)
1853
zfseeko(G.outfile, -8, SEEK_END);
1854
fread(&ntc, 8, 1, G.outfile);
1855
if (ntc.id != *(long *)"XTcc")
1857
ntc.id = *(long *)"XTcc";
1859
fwrite (&ntc, 8, 1, G.outfile);
1861
Info(slide, 0x201, ((char *)slide, "QData = %d", LG(dlen)));
1863
return; /* finished, cancel further extra field scanning */
1867
Trace((stderr,"qlfix: unknown extra field block, ID=%d\n",
1871
/* Skip this extra field block */
1872
ef_ptr += (eb_len + EB_HEADSIZE);
1873
ef_len -= (eb_len + EB_HEADSIZE);