📄 unpack.c
字号:
break; case HARDLINK: case SYMLINK: read_uns(mode, Uns32); read_time_t(mtime, time_t); read_int(uid, Int32); read_int(gid, Int32); read_size_t(len, size_t); i = params->inputfunc(buf, len, params); if(i < len) goto eoferr; buf[len] = '\0'; i = params->inputfunc(&c, 1, params); if(c != ';' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr); if(verbose) sprintf(verbosestr + strlen(verbosestr), T_("%s (%slink to "), (type == SYMLINK ? "@" : "="), (type == SYMLINK ? T_("symbolic ") : "")); read_size_t(len, size_t); i = params->inputfunc(buf, len, params); if(i < len) goto eoferr; buf[len] = '\0'; i = params->inputfunc(&c, 1, params); if(c != '.' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } if(verbose){ mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr + strlen(verbosestr)); strcat(verbosestr, ")"); } strcat(verbosestr, "\n"); params->vars.uid = uid; params->vars.mtime = mtime; verbosefunc(verbosestr, params); have_an_error = NO; started = YES; break; case REGFILECKS: cks = YES;#ifdef USE_ZLIB if(params->check) crc32sum = crc32(0L, NULL, 0);#else fprintf(stderr, T_("Warning: CRC32 checksumming not available (requires zlib)\n"));#endif case REGFILE: read_uns(mode, Uns32); read_time_t(mtime, time_t); read_int(uid, Int32); read_int(gid, Int32); read_size_t(len, size_t); i = params->inputfunc(buf, len, params); /* read filename */ if(i < len) goto eoferr; buf[len] = '\0'; i = params->inputfunc(&c, 1, params); if(c != ';' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } read_size_t(len, size_t); /* read uncompresscmd */ i = params->inputfunc(buf2, len, params); if(i < len) goto eoferr; buf2[len] = '\0'; i = params->inputfunc(&c, 1, params); if(c != ';' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } read_off_t(filelen, off_t); /* read filesize */ compressed = (buf2[0] ? YES : NO); var_compr = (compressed && filelen == 0) ? YES : NO; builtin_uncompress = NO; mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr); if(!compressed || !verbose) strcat(verbosestr, "\n"); else sprintf(verbosestr + strlen(verbosestr), T_(" (to be uncompressed by %s)\n"), buf2); params->vars.uid = uid; params->vars.mtime = mtime; verbosefunc(verbosestr, params); ucfd = -1; biu_error = NO; if(params->check){ if(compressed){ /* check integrity of compressed */ builtin_uncompress = NO; if(buf2[0] == '.' && (! buf2[1] || buf2[1] == ' ')){ if(buf2[1]) memmove(buf2, buf2 + 2, strlen(buf2) - 2 + 1); else buf2[0] = '\0';#ifndef USE_ZLIB fprintf(errfp, T_("Error: Built-in (un)compression not available for file `%s'.\n"), buf); compressed = NO; buf2[0] = '\0'; params->vars.errnum |= EUNPACKNOCOMPR;#else builtin_uncompress = YES;#endif } if(compressed){ if(buf2[0]){ i = pipe(pp); if(i){ fprintf(errfp, T_("Error: Cannot check file `%s' for integrity.\n"), buf); params->vars.errnum |= EGENFAULT; } else{ pid = fork_forced(); if(pid < 0){ fprintf(errfp, T_("Error: Cannot check file `%s' for integrity.\n"), buf); params->vars.errnum |= EGENFAULT; } else if(! pid){ /* child */ char **unzipargv; int fd; clr_timer(); close(pp[1]); if(cmd2argvq(&unzipargv, buf2)){ close(pp[0]); exit(1); } fd = open(NULLFILE, O_WRONLY | O_BINARY, 0600); if(fd < 0){ fprintf(stderr, "Fatal: Cannot open " NULLFILE ".\n"); exit(2); } dup2(pp[0], 0); dup2(fd, 1); dup2(fd, 2); execvp(unzipargv[0], unzipargv + 1); exit(3); } close(pp[0]); ucfd = pp[1]; } } else{ ucfd = open(NULLFILE, O_WRONLY | O_BINARY, 0600); if(ucfd < 0){ fprintf(stderr, "Fatal: Cannot open " NULLFILE ".\n"); exit(2); } }#ifdef USE_ZLIB if(builtin_uncompress){ i = open_file_unzip(¶ms->vars.zfile, ucfd); if(i){ fprintf(errfp, T_("Error: Cannot uncompress `%s'.\n"), buf); close(ucfd); ucfd = -1; params->vars.errnum |= EUNPACKUNCOMPR; } } else params->vars.zfile.fd = ucfd;#endif } } } forever{ UChar comprbuf[0x1000]; if(var_compr){ fmterr = NO; i = params->inputfunc(buf, 2, params); if(i < 2){ fmterr = YES; params->vars.errnum |= EUNPACKREAD; } else{ xref_to_UnsN(&len, buf, 16); if(len < 0 || len > 0xfff) fmterr = YES; } if(!fmterr){ i = params->inputfunc(comprbuf, len, params); if(i < len){ fmterr = YES; } else{ if(ucfd >= 0){ j = write_file(ucfd, comprbuf, len, ¶ms->vars.zfile, len < 0xfff ? YES : NO, writefunc); if(j < 0) biu_error = YES; }#ifdef USE_ZLIB if(params->check && cks) crc32sum = crc32(crc32sum, comprbuf, i);#endif } } else{ i = formaterr(&type, params, started); have_an_error = YES; close(ucfd); goto tryagain; } if(len < 0xfff) break; continue; } if(filelen < BUFFERSIZ){ len = (Int32) filelen; i = params->inputfunc(buf, len, params); if(i < len){ params->vars.errnum |= EUNPACKREAD; i = formaterr(&type, params, started); have_an_error = YES; close(ucfd); goto tryagain; } if(ucfd >= 0){ j = write_file(ucfd, buf, i, ¶ms->vars.zfile, YES, writefunc); if(j < 0) biu_error = YES; }#ifdef USE_ZLIB if(params->check && cks) crc32sum = crc32(crc32sum, buf, i);#endif break; } i = params->inputfunc(buf, BUFFERSIZ, params); if(i < BUFFERSIZ){ params->vars.errnum |= EUNPACKREAD; i = formaterr(&type, params, started); have_an_error = YES; close(ucfd); goto tryagain; } if(ucfd >= 0){ j = write_file(ucfd, buf, i, ¶ms->vars.zfile, NO, writefunc); if(j < 0) biu_error = YES; }#ifdef USE_ZLIB if(params->check && cks) crc32sum = crc32(crc32sum, buf, i);#endif filelen -= BUFFERSIZ; } if(ucfd >= 0){ close(ucfd); pst = 0; if(pid > 0){ waitpid_forced(pid, &pst, 0); pst = WEXITSTATUS(pst); } if(biu_error || pst){ fprintf(stderr, T_("Integrity check: This compressed file seems to be corrupted.\n")); params->vars.errnum |= EUNPACKUNCOMPR; } }#ifdef USE_ZLIB if(builtin_uncompress){ reset_zfile(¶ms->vars.zfile); }#endif j = (cks ? 4 : 0); i = params->inputfunc(buf, 1 + j, params); if(buf[j] != '.' || i < 1 + j){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; }#ifdef USE_ZLIB if(cks && params->check){ xref_to_Uns32(&lu, buf); if(lu != crc32sum){ fprintf(stderr, T_("Integrity check: Wrong CRC32 checksum.\n")); params->vars.errnum |= EUNPACKUNCOMPR; } }#endif started = YES; have_an_error = NO; break; case FILECONTENTSCKS: cks = YES;#ifdef USE_ZLIB if(params->check) crc32sum = crc32(0L, NULL, 0);#else fprintf(stderr, T_("Warning: CRC32 checksumming not available (requires zlib)\n"));#endif case FILECONTENTS: read_time_t(mtime, time_t); case FILECONTENTS_O: read_size_t(len, size_t); i = params->inputfunc(buf, len, params); /* read filename */ if(i < len) goto eoferr; buf[len] = '\0'; i = params->inputfunc(&c, 1, params); if(c != ';' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } read_size_t(len, size_t); /* read uncompresscmd */ i = params->inputfunc(buf2, len, params); if(i < len) goto eoferr; buf2[len] = '\0'; i = params->inputfunc(&c, 1, params); if(c != ';' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } compressed = (buf2[0] ? YES : NO); builtin_uncompress = NO; mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr); if(verbose) strcat(verbosestr, "<"); if(!compressed || !verbose) strcat(verbosestr, "\n"); else sprintf(verbosestr + strlen(verbosestr), T_(" (to be uncompressed by %s)\n"), buf2); verbosefunc(verbosestr, params); biu_error = NO; ucfd = -1; if(params->check && compressed){ /* check integrity of compressed */ builtin_uncompress = NO; if(buf2[0] == '.' && (! buf2[1] || buf2[1] == ' ')){ if(buf2[1]) memmove(buf2, buf2 + 2, strlen(buf2) - 2 + 1); else buf2[0] = '\0';#ifndef USE_ZLIB fprintf(errfp, T_("Error: Built-in (un)compression not available for file `%s'.\n"), buf); compressed = NO; buf2[0] = '\0'; params->vars.errnum |= EUNPACKNOCOMPR;#else builtin_uncompress = YES;#endif } if(buf2[0]){ i = pipe(pp); if(i){ fprintf(errfp, T_("Error: Cannot check file `%s' for integrity.\n"), buf); params->vars.errnum |= EGENFAULT; } else{ pid = fork_forced(); if(pid < 0){ fprintf(errfp, T_("Error: Cannot check file `%s' for integrity.\n"), buf); params->vars.errnum |= EGENFAULT; } else if(! pid){ /* child */ char **unzipargv; int fd; clr_timer(); close(pp[1]); if(cmd2argvq(&unzipargv, buf2)){ close(pp[0]); exit(1); } fd = open(NULLFILE, O_WRONLY | O_BINARY, 0600); if(fd < 0) exit(2); dup2(pp[0], 0); dup2(fd, 1); dup2(fd, 2); execvp(unzipargv[0], unzipargv + 1); exit(3); } close(pp[0]); ucfd = pp[1]; } } else{ ucfd = open(NULLFILE, O_WRONLY | O_BINARY, 0600); if(ucfd < 0){ fprintf(stderr, "Fatal: Cannot open " NULLFILE ".\n"); exit(2); } }#ifdef USE_ZLIB if(builtin_uncompress){ i = open_file_unzip(¶ms->vars.zfile, ucfd); if(i){ fprintf(errfp, T_("Error: Cannot uncompress `%s'.\n"), buf); close(ucfd); ucfd = -1; params->vars.errnum |= EUNPACKUNCOMPR; } } else params->vars.zfile.fd = ucfd;#endif } do{ i = params->inputfunc(buf2, 1, params); if(i < 1) goto eoferr; cptr = buf2 + 1; i = params->inputfunc(cptr, buf2[0], params); if(i < buf2[0]){ params->vars.errnum |= EUNPACKFORMAT; goto eoferr; } if(ucfd >= 0){ j = write_file(ucfd, cptr, i, ¶ms->vars.zfile, i < 0xff ? YES : NO, writefunc); if(j < 0) biu_error = YES; }#ifdef USE_ZLIB if(params->check && cks) crc32sum = crc32(crc32sum, cptr, i);#endif } while(buf2[0] == (UChar) 0xff); if(ucfd >= 0){ close(ucfd); pst = 0; if(pid > 0){ waitpid_forced(pid, &pst, 0); pst = WEXITSTATUS(pst); } if(biu_error || pst){ fprintf(stderr, T_("Integrity check: This compressed file seems to be corrupted.\n")); params->vars.errnum |= EUNPACKUNCOMPR; } }#ifdef USE_ZLIB if(builtin_uncompress){ reset_zfile(¶ms->vars.zfile); }#endif j = (cks ? 4 : 0); i = params->inputfunc(buf, 1 + j, params); if(buf[j] != '.' || i < 1 + j){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; }#ifdef USE_ZLIB if(cks && params->check){ xref_to_Uns32(&lu, buf); if(lu != crc32sum){ fprintf(stderr, T_("Integrity check: Wrong CRC32 checksum.\n")); params->vars.errnum |= EUNPACKUNCOMPR; } }#endif started = YES; have_an_error = NO; break; case SOLARIS2_ACL: /* just parse */ case HPUX10_ACL: /* have the same structure */ read_int(i, int); for(i *= 3; i > 0; i--) read_int(li, Int32); i = params->inputfunc(&c, 1, params); if(c != '.' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } started = YES; have_an_error = NO; break; case POSIX_ACL: read_int(j, int); for(i = 0; i < 3; i++){ if(j & (1 << i)){ read_int(k, int); for(; k > 0; k -= BUFFERSIZ){ n = (k > BUFFERSIZ ? BUFFERSIZ : k); if(params->inputfunc(buf, n, params) < n){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } n = params->inputfunc(&c, 1, params); if(c != ';' || n < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } } } } i = params->inputfunc(&c, 1, params); if(c != '.' || i < 1){ i = formaterr(&type, params, started); have_an_error = YES; goto tryagain; } started = YES; have_an_error = NO; break; case COMMANDINOUTCKS: cks = YES;#ifdef USE_ZLIB if(params->check) crc32sum = crc32(0L, NULL, 0);#else fprintf(stderr, T_("Warning: CRC32 checksumming not available (requires zlib)\n"));#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -