~ubuntu-branches/ubuntu/quantal/unzip/quantal

« back to all changes in this revision

Viewing changes to atheos/atheos.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2009-05-08 20:02:40 UTC
  • mfrom: (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090508200240-rk23wg0jdoyc6caj
Tags: 6.0-1
* New upstream release. Closes: #496989.
* Enabled new Unicode support. Closes: #197427. This may or may not work
  for your already created zipfiles, but it's not a bug unless they were
  created using the Unicode feature present in zip 3.0.
* Built using DATE_FORMAT=DF_YMD so that unzip -l show dates in ISO format,
  as that's the only available one which makes sense. Closes: #312886.
* Enabled new bzip2 support. Closes: #426798.
* Exit code for zipgrep should now be the right one. Closes: #441997.
* The reason why a file may not be created is now shown. Closes: #478791.
* Summary of changes in this version not being the debian/* files:
- Manpages in section 1, not 1L.
- Branding patch. UnZip by Debian. Original by Info-ZIP.
- Always #include <unistd.h>. Debian GNU/kFreeBSD needs it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  Copyright (c) 1990-2005 Info-ZIP.  All rights reserved.
 
2
  Copyright (c) 1990-2008 Info-ZIP.  All rights reserved.
3
3
 
4
4
  See the accompanying file LICENSE, version 2000-Apr-09 or later
5
5
  (the contents of which are also included in unzip.h) for terms of use.
54
54
    } u;
55
55
    unsigned perms;             /* same as min_info.file_attr */
56
56
    int have_uidgid;            /* flag */
57
 
    ush uidgid[2];
 
57
    ulg uidgid[2];
58
58
    char fnbuf[1];              /* buffer stub for directory name */
59
59
} uxdirattr;
60
60
#define UxAtt(d)  ((uxdirattr *)d)    /* typecast shortcut */
211
211
#ifndef S_ISGID
212
212
# define S_ISGID        0002000 /* set group id on execution */
213
213
#endif
214
 
#ifndef S_ISVTX
 
214
#ifndef S_ISVTX
215
215
# define S_ISVTX        0001000 /* save swapped text even after use */
216
216
#endif
217
217
 
246
246
int mapattr(__G)
247
247
    __GDEF
248
248
{
 
249
    int r;
249
250
    ulg tmp = G.crec.external_file_attributes;
250
251
 
251
252
    G.pInfo->file_attr = 0;
271
272
        case BEOS_:
272
273
        case QDOS_:
273
274
        case TANDEM_:
 
275
            r = FALSE;
274
276
            G.pInfo->file_attr = (unsigned)(tmp >> 16);
275
 
            if (G.pInfo->file_attr != 0 || !G.extra_field) {
276
 
                return 0;
277
 
            } else {
 
277
            if (G.pInfo->file_attr == 0 && G.extra_field) {
278
278
                /* Some (non-Info-ZIP) implementations of Zip for Unix and
279
279
                 * VMS (and probably others ??) leave 0 in the upper 16-bit
280
280
                 * part of the external_file_attributes field. Instead, they
293
293
                unsigned ebLen;
294
294
                uch *ef = G.extra_field;
295
295
                unsigned ef_len = G.crec.extra_field_length;
296
 
                int r = FALSE;
297
296
 
298
297
                while (!r && ef_len >= EB_HEADSIZE) {
299
298
                    ebID = makeword(ef);
320
319
                    ef_len -= (ebLen + EB_HEADSIZE);
321
320
                    ef += (ebLen + EB_HEADSIZE);
322
321
                }
323
 
                if (!r)
324
 
                    return 0;
 
322
            }
 
323
            if (!r) {
 
324
#ifdef SYMLINKS
 
325
                /* Check if the file is a (POSIX-compatible) symbolic link.
 
326
                 * We restrict symlink support to those "made-by" hosts that
 
327
                 * are known to support symbolic links.
 
328
                 */
 
329
                G.pInfo->symlink = S_ISLNK(G.pInfo->file_attr) &&
 
330
                                   SYMLINK_HOST(G.pInfo->hostnum);
 
331
#endif
 
332
                return 0;
325
333
            }
326
334
            /* fall through! */
327
335
        /* all remaining cases:  expand MSDOS read-only bit into write perms */
350
358
            }
351
359
            /* read-only bit --> write perms; subdir bit --> dir exec bit */
352
360
            tmp = !(tmp & 1) << 1  |  (tmp & 0x10) >> 4;
353
 
            if ((G.pInfo->file_attr & 0700) == (unsigned)(0400 | tmp<<6))
 
361
            if ((G.pInfo->file_attr & 0700) == (unsigned)(0400 | tmp<<6)) {
354
362
                /* keep previous G.pInfo->file_attr setting, when its "owner"
355
363
                 * part appears to be consistent with DOS attribute flags!
356
364
                 */
 
365
#ifdef SYMLINKS
 
366
                /* Entries "made by FS_FAT_" could have been zipped on a
 
367
                 * system that supports POSIX-style symbolic links.
 
368
                 */
 
369
                G.pInfo->symlink = S_ISLNK(G.pInfo->file_attr) &&
 
370
                                   (G.pInfo->hostnum == FS_FAT_);
 
371
#endif
357
372
                return 0;
 
373
            }
358
374
            G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
359
375
            break;
360
376
    } /* end switch (host-OS-created-by) */
537
553
            *lastsemi = '\0';
538
554
    }
539
555
 
 
556
    /* On UNIX (and compatible systems), "." and ".." are reserved for
 
557
     * directory navigation and cannot be used as regular file names.
 
558
     * These reserved one-dot and two-dot names are mapped to "_" and "__".
 
559
     */
 
560
    if (strcmp(pathcomp, ".") == 0)
 
561
        *pathcomp = '_';
 
562
    else if (strcmp(pathcomp, "..") == 0)
 
563
        strcpy(pathcomp, "__");
 
564
 
540
565
#ifdef ACORN_FTYPE_NFS
541
566
    /* translate Acorn filetype information if asked to do so */
542
567
    if (uO.acorn_nfs_ext &&
833
858
 
834
859
 
835
860
 
836
 
static int get_extattribs OF((__GPRO__ iztimes *pzt, ush z_uidgid[2]));
 
861
static int get_extattribs OF((__GPRO__ iztimes *pzt, ulg z_uidgid[2]));
837
862
 
838
863
static int get_extattribs(__G__ pzt, z_uidgid)
839
864
    __GDEF
840
865
    iztimes *pzt;
841
 
    ush z_uidgid[2];
 
866
    ulg z_uidgid[2];
842
867
{
843
868
/*---------------------------------------------------------------------------
844
869
    Convert from MSDOS-format local time and date to Unix-format 32-bit GMT
899
924
        iztimes t3;             /* mtime, atime, ctime */
900
925
        struct utimbuf t2;      /* modtime, actime */
901
926
    } zt;
902
 
    ush z_uidgid[2];
 
927
    ulg z_uidgid[2];
903
928
    int have_uidgid_flg;
904
929
 
905
 
    fclose(G.outfile);
906
 
 
907
930
/*---------------------------------------------------------------------------
908
931
    If symbolic links are supported, allocate storage for a symlink control
909
932
    structure, put the uncompressed "data" and other required info in it, and
914
937
 
915
938
#ifdef SYMLINKS
916
939
    if (G.symlnk) {
917
 
        unsigned ucsize = (unsigned)G.lrec.ucsize;
 
940
        extent ucsize = (extent)G.lrec.ucsize;
918
941
        unsigned AtheOSef_len = 0;
919
942
        extent slnk_entrysize;
920
943
        uch *AtheOS_exfld = NULL;
929
952
            }
930
953
        }
931
954
 
932
 
        slnk_entrysize = sizeof(slinkentry) + AtheOSef_len + ucsize +
933
 
                         strlen(G.filename);
 
955
        /* size of the symlink entry is the sum of
 
956
         *  (struct size (includes 1st '\0') + 1 additional trailing '\0'),
 
957
         *  system specific attribute data size (might be 0),
 
958
         *  and the lengths of name and link target.
 
959
         */
 
960
        slnk_entrysize = (sizeof(slinkentry) + 1) + AtheOSef_len +
 
961
                         ucsize + strlen(G.filename);
934
962
 
935
 
        if ((unsigned)slnk_entrysize < ucsize) {
 
963
        if (slnk_entrysize < ucsize) {
936
964
            Info(slide, 0x201, ((char *)slide,
937
965
              "warning:  symbolic link (%s) failed: mem alloc overflow\n",
938
966
              FnFilter1(G.filename)));
 
967
            fclose(G.outfile);
939
968
            return;
940
969
        }
941
970
 
943
972
            Info(slide, 0x201, ((char *)slide,
944
973
              "warning:  symbolic link (%s) failed: no mem\n",
945
974
              FnFilter1(G.filename)));
 
975
            fclose(G.outfile);
946
976
            return;
947
977
        }
948
978
        slnk_entry->next = NULL;
955
985
            /* AtheOS_exfld should not be NULL because AtheOSef_len > 0 */
956
986
            memcpy(slnk_entry->buf, AtheOS_exfld, AtheOSef_len);
957
987
 
958
 
        /* reopen the "link data" file for reading */
959
 
        G.outfile = fopen(G.filename, FOPR);
 
988
        /* move back to the start of the file to re-read the "link data" */
 
989
        rewind(G.outfile);
960
990
 
961
 
        if (!G.outfile ||
962
 
            fread(slnk_entry->target, 1, ucsize, G.outfile) != (int)ucsize)
 
991
        if (fread(slnk_entry->target, 1, ucsize, G.outfile) != ucsize)
963
992
        {
964
993
            Info(slide, 0x201, ((char *)slide,
965
994
              "warning:  symbolic link (%s) failed\n",
983
1012
    }
984
1013
#endif /* SYMLINKS */
985
1014
 
 
1015
    fclose(G.outfile);
 
1016
 
986
1017
    /* handle the AtheOS extra field if present */
987
1018
    if (!uO.J_flag) {
988
1019
        void *ptr = scanAtheOSexfield(G.extra_field,
1002
1033
        {
1003
1034
            if (uO.qflag)
1004
1035
                Info(slide, 0x201, ((char *)slide,
1005
 
                  "warning:  cannot set UID %d and/or GID %d for %s\n",
 
1036
                  "warning:  cannot set UID %lu and/or GID %lu for %s\n",
1006
1037
                  z_uidgid[0], z_uidgid[1], FnFilter1(G.filename)));
1007
1038
            else
1008
1039
                Info(slide, 0x201, ((char *)slide,
1009
 
                  " (warning) cannot set UID %d and/or GID %d",
 
1040
                  " (warning) cannot set UID %lu and/or GID %lu",
1010
1041
                  z_uidgid[0], z_uidgid[1]));
1011
1042
        }
1012
1043
    }
1013
1044
 
1014
 
    /* set the file's access and modification times */
1015
 
    if (utime(G.filename, &(zt.t2))) {
1016
 
        if (uO.qflag)
1017
 
            Info(slide, 0x201, ((char *)slide,
1018
 
              "warning:  cannot set times for %s\n", FnFilter1(G.filename)));
1019
 
        else
1020
 
            Info(slide, 0x201, ((char *)slide,
1021
 
              " (warning) cannot set times"));
 
1045
    /* skip restoring time stamps on user's request */
 
1046
    if (uO.D_flag <= 1) {
 
1047
        /* set the file's access and modification times */
 
1048
        if (utime(G.filename, &(zt.t2))) {
 
1049
            if (uO.qflag)
 
1050
                Info(slide, 0x201, ((char *)slide,
 
1051
                  "warning:  cannot set times for %s\n",
 
1052
                  FnFilter1(G.filename)));
 
1053
            else
 
1054
                Info(slide, 0x201, ((char *)slide,
 
1055
                  " (warning) cannot set times"));
 
1056
        }
1022
1057
    }
1023
1058
 
1024
1059
/*---------------------------------------------------------------------------
1054
1089
#ifdef SET_DIR_ATTRIB
1055
1090
/* messages of code for setting directory attributes */
1056
1091
static ZCONST char Far DirlistUidGidFailed[] =
1057
 
  "warning:  cannot set UID %d and/or GID %d for %s\n";
 
1092
  "warning:  cannot set UID %lu and/or GID %lu for %s\n";
1058
1093
static ZCONST char Far DirlistUtimeFailed[] =
1059
1094
  "warning:  cannot set modification, access times for %s\n";
1060
1095
#  ifndef NO_CHMOD
1101
1136
        if (!errval)
1102
1137
            errval = PK_WARN;
1103
1138
    }
1104
 
    if (utime(d->fn, &UxAtt(d)->u.t2)) {
1105
 
        Info(slide, 0x201, ((char *)slide,
1106
 
          LoadFarString(DirlistUtimeFailed), FnFilter1(d->fn)));
1107
 
        if (!errval)
1108
 
            errval = PK_WARN;
 
1139
    /* Skip restoring directory time stamps on user' request. */
 
1140
    if (uO.D_flag <= 0) {
 
1141
        /* restore directory timestamps */
 
1142
        if (utime(d->fn, &UxAtt(d)->u.t2)) {
 
1143
            Info(slide, 0x201, ((char *)slide,
 
1144
              LoadFarString(DirlistUtimeFailed), FnFilter1(d->fn)));
 
1145
            if (!errval)
 
1146
                errval = PK_WARN;
 
1147
        }
1109
1148
    }
1110
1149
#ifndef NO_CHMOD
1111
1150
    if (chmod(d->fn, filtattr(__G__ UxAtt(d)->perms))) {