⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unpack.c

📁 一套客户/服务器模式的备份系统代码,跨平台,支持linux,AIX, IRIX, FreeBSD, Digital Unix (OSF1), Solaris and HP-UX.
💻 C
📖 第 1 页 / 共 5 页
字号:
		fprintf(params->errfp,			T_("%s not found in archive.\n"), *fileidx);	    }	  }	}#endif	if(have_an_error){	  i = formaterr(&type, params, started);	  goto tryagain;	}	goto cleanup;      case INFORMATION:	read_size_t(len, size_t);	if(len + 1 > BUFFERSIZ)	  cptr = to_be_freed = NEWP(UChar, len + 1);	else	  cptr = buf;	i = params->inputfunc(cptr, len, params);	if(i < len){	  ZFREE(to_be_freed);	  goto eoferr;	}	i = params->inputfunc(&c, 1, params);	if(c != '.' || i < 1){	  ZFREE(to_be_freed);	  i = formaterr(&type, params, started);	  have_an_error = YES;	  goto tryagain;	}	cptr[len] = '\0';	if(verbose && verbosefunc)	  verbosefunc(cptr, params);	ZFREE(to_be_freed);	started = YES;	have_an_error = NO;	break;	      case DIRECTORY:	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';	convtorel(buf, params->relative);	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;	if(! name_in_list(buf, files, n_files, params->recursive, files_found)			|| invalid_time_or_uid(mtime, uid, params)			|| (params->uid && not_allowed(buf, params)))	  skip = YES;	name_in_list(buf, files, n_files, 0, files_found);	if(!skip){	  j = make_check_basedir(buf, 0700, uid, gid, params);	  if(! lstat(buf, &statb)){	    if(!IS_DIRECTORY(statb) && params->unlink){		unlink(buf);	    }	  }	  i = mkdir(buf, mode);	  if(j || (i && errno != EEXIST)){	    params->vars.errnum |= EUNPACKMKDIR;	    fprintf(errfp, T_("Error: cannot create directory `%s'\n"), buf);	  }	  else{	    set_props(buf, uid, gid, mtime, mode, acls, params);	    if(verbose && verbosefunc){		mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr);		strcat(verbosestr, "\n");		params->vars.uid = uid;		params->vars.mtime = mtime;		verbosefunc(verbosestr, params);	    }	  }	}	break;#ifndef _WIN32      case FIFO:      case SOCKET:	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';	convtorel(buf, params->relative);	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;	if(! name_in_list(buf, files, n_files, params->recursive, files_found)			|| invalid_time_or_uid(mtime, uid, params)			|| (params->uid && not_allowed(buf, params)))	  skip = YES;	name_in_list(buf, files, n_files, 0, files_found);	if(! skip){	  if(make_check_basedir(buf, 0700, uid, gid, params)){	    params->vars.errnum |= EUNPACKMKDIR;	    fprintf(errfp, T_("Error: cannot create directory `%s'\n"), buf);	  }	  else{	    if(params->unlink)		unlink(buf);	    if(type == FIFO){		i = mkfifo(buf, mode);	    }	    else{		if( (i = create_unix_socket(buf)) >= 0){		  close(i);		  i = 0;		}	    }	    if(i){		params->vars.errnum |= EUNPACKMKENT;		fprintf(errfp, T_("Error: cannot create %s `%s'\n"),			(type == FIFO ? "named pipe" : "socket"), buf);	    }	    else{	      set_props(buf, uid, gid, mtime, mode, acls, params);	      if(verbose && verbosefunc){		mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr);		strcat(verbosestr, "\n");		verbosefunc(verbosestr, params);		params->vars.uid = uid;		params->vars.mtime = mtime;	      }	    }	  }	}	break;      case BLOCKDEVICE:      case CHARDEVICE:	read_uns(mode, Uns32);	read_time_t(mtime, time_t);	read_int(uid, Int32);	read_int(gid, Int32);	read_uns(rdev, dev_t);	read_size_t(len, size_t);	i = params->inputfunc(buf, len, params);	if(i < len)	  goto eoferr;	buf[len] = '\0';	convtorel(buf, params->relative);	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;	if(! name_in_list(buf, files, n_files, params->recursive, files_found)			|| invalid_time_or_uid(mtime, uid, params)			|| (params->uid && not_allowed(buf, params)))	  skip = YES;	name_in_list(buf, files, n_files, 0, files_found);	if(! skip){	  if(make_check_basedir(buf, 0700, uid, gid, params)){	    params->vars.errnum |= EUNPACKMKDIR;	    fprintf(errfp, T_("Error: cannot create directory `%s'\n"), buf);	  }	  else{	    if(params->unlink)		unlink(buf);	    if(mknod(buf, mode, rdev)){		params->vars.errnum |= EUNPACKMKENT;		fprintf(errfp, T_("Error: cannot create device `%s'\n"), buf);	    }	    else{	      set_props(buf, uid, gid, mtime, mode, acls, params);	      if(verbose && verbosefunc){		mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr);		strcat(verbosestr, "\n");		params->vars.uid = uid;		params->vars.mtime = mtime;		verbosefunc(verbosestr, params);	      }	    }	  }	}	break;#endif      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 < 1)	  goto eoferr;	buf[len] = '\0';	convtorel(buf, params->relative);	i = params->inputfunc(&c, 1, params);	if(c != ';' || i < 1){	  i = formaterr(&type, params, started);	  have_an_error = YES;	  goto tryagain;	}	read_int(len, Int32);	i = params->inputfunc(buf2, len, params);	if(i < len)	  goto eoferr;	buf2[len] = '\0';	if(type == SYMLINK){	  if(params->relative > 1)	    convtorelcwd(buf2, buf, params->relative);	}	else	  convtorel(buf2, params->relative);	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;	if(! name_in_list(buf, files, n_files, params->recursive, files_found)			|| invalid_time_or_uid(mtime, uid, params)			|| (params->uid && not_allowed(buf, params)))	  skip = YES;	name_in_list(buf, files, n_files, 0, files_found);	if(! skip){	  if(params->unlink)	    unlink(buf);	  if(make_check_basedir(buf, 0700, uid, gid, params)){	    params->vars.errnum |= EUNPACKMKDIR;	    fprintf(errfp, T_("Error: cannot create directory `%s'\n"), buf);	  }	  else{	    if(type == HARDLINK){	      if(link(buf2, buf)){		params->vars.errnum |= EUNPACKMKENT;		fprintf(errfp, T_("Error: cannot create link `%s' to `%s'.\n"),				buf, buf2);	      }	      else{		set_props(buf, uid, gid, mtime, mode, acls, params);		if(verbose && verbosefunc){		  mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr);		  strcat(verbosestr, "\n");		  params->vars.uid = uid;		  params->vars.mtime = mtime;		  verbosefunc(verbosestr, params);		}	      }	    }	    if(type == SYMLINK){	      if(symlink(buf2, buf)){		params->vars.errnum |= EUNPACKMKENT;		fprintf(errfp, T_("Error: cannot create symlink `%s' to `%s'.\n"),				buf, buf2);	      }	      else{		/*set_props(buf, uid, gid, mtime, mode, acls, params);*/#ifdef	HAVE_LCHOWN		if(!params->ignoreown){		  if(lchown(buf, uid, gid)){		    params->vars.errnum |= EUNPACKSETPROPS;		    fprintf(params->errfp, T_("Warning: cannot lchown %s\n"), buf);		  }		}#endif		if(verbose && verbosefunc){		  mk_esc_seq(buf, ESCAPE_CHARACTER, verbosestr);		  strcat(verbosestr, "\n");		  params->vars.uid = uid;		  params->vars.mtime = mtime;		  verbosefunc(verbosestr, params);		}	      }	    }	  }	}	break;      case REGFILECKS:	cks = YES;#ifdef	USE_ZLIB	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';	convtorel(buf, params->relative);	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;	}#ifdef	USE_ZLIB	reset_zfile(&params->vars.zfile);#endif	read_off_t(filelen, off_t);		/* read filesize */	compressed = (buf2[0] ? YES : NO);	var_compr = (compressed && filelen == 0) ? YES : NO;	builtin_uncompress = NO;	if(! name_in_list(buf, files, n_files, params->recursive, files_found)			|| invalid_time_or_uid(mtime, uid, params)			|| (params->uid && not_allowed(buf, params)))	  skip = YES;	name_in_list(buf, files, n_files, 0, files_found);	if(!skip){	  if(make_check_basedir(buf, 0700, uid, gid, params)){	    params->vars.errnum |= EUNPACKMKDIR;	    fprintf(errfp, T_("Error: cannot create directory `%s'\n"), buf);	    skip = YES;	  }	}	fault = NO;	fd = -10;	if(skip)	  fault = YES;	if(! params->unlink && ! fault){	  if(! stat(buf, &statb)){	    params->vars.errnum |= EUNPACKEXISTS;	    fprintf(errfp, T_("Error: must not delete existing `%s'.\n"), buf);	    fault = YES;	  }	}	if(! compressed){		/* not compressed */	  if(!fault){	    unlink(buf);	    fd = open(buf, O_WRONLY | O_CREAT | O_BINARY, 0600);	    if(fd < 0){	      fd = -10;	      fault = YES;	      fprintf(errfp, T_("Error: Cannot create file `%s'.\n"), buf);	      params->vars.errnum |= EUNPACKMKENT;	    }	  }	  forever{	    if(filelen < BUFFERSIZ){	      len = (Int32) filelen;	      i = params->inputfunc(buf2, len, params);	      if(i < len){		if(fd != -10)		  close(fd);		goto eoferr;	      }#ifdef	USE_ZLIB	      if(cks)		crc32sum = crc32(crc32sum, buf2, i);#endif	      if(!fault){	        if(len != writefunc(fd, buf2, len)){		  params->vars.errnum |= EUNPACKWRITE;		  fprintf(errfp, T_("Error: writing to `%s' failed.\n"), buf);	        }	      }	      break;	    }	    i = params->inputfunc(buf2, BUFFERSIZ, params);	    if(i < BUFFERSIZ){	      if(fd != -10)	        close(fd);	      goto eoferr;	    }	    if(!fault){	      if(writefunc(fd, buf2, BUFFERSIZ) != BUFFERSIZ){		params->vars.errnum |= EUNPACKWRITE;	        fprintf(errfp, T_("Error: writing to `%s' failed.\n"), buf);		if(fd != -10)	          close(fd);	        fault = YES;		fd = -10;	      }	    }#ifdef	USE_ZLIB	    if(cks)		crc32sum = crc32(crc32sum, buf2, i);#endif	    filelen -= BUFFERSIZ;	  }	  if(fd != -10)	    close(fd);	}	else{			/* compressed */	  if(!fault){	    unlink(buf);	    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);		fault = YES;		compressed = NO;		buf2[0] = '\0';		params->vars.errnum |= EUNPACKNOCOMPR;#else		builtin_uncompress = YES;#endif	    }	    fd = open(buf, O_WRONLY | O_CREAT | O_BINARY, 0600);	    if(fd < 0){		fault = YES;		fprintf(errfp, T_("Error: Cannot create file `%s'.\n"), buf);		params->vars.errnum |= EUNPACKMKENT;	    }	    else{	      if(buf2[0]){		i = pipe(pp);		if(i){		  fault = YES;		  params->vars.errnum |= EUNPACKUNCOMPR;		  fprintf(errfp,			T_("Error: Cannot create pipe for uncompressing `%s'.\n"),				buf);		  close(fd);		  fd = -1;	        }		else{		  pid = fork_forced();		  if(pid < 0){		    fault = YES;		    fprintf(errfp, T_("Error: Cannot create file `%s'.\n"), buf);		    params->vars.errnum |= EUNPACKMKENT;		    close(fd);		    fd = -1;		  }		  else if(! pid){		/* child */		    char	**unzipargv;		    clr_timer();		    close(pp[1]);		    if(cmd2argvq(&unzipargv, buf2)){			close(pp[0]);			exit(1);		    }		    dup2(pp[0], 0);		    dup2(fd, 1);		    execvp(unzipargv[0], unzipargv + 1);		    exit(3);		  }		  close(pp[0]);		  close(fd);		  fd = pp[1];		}	      }		/* if there is an uncompress program */#ifdef	USE_ZLIB	      if(builtin_uncompress){		i = open_file_unzip(&params->vars.zfile, fd);		if(i){		  fprintf(errfp, T_("Error: Cannot uncompress `%s'.\n"), buf);		  params->vars.errnum |= EUNPACKUNCOMPR;		  close(fd);		  fd = -1;		  fault = YES;		}	      }	      else		params->vars.zfile.fd = fd;#endif	    }		/* if file could be opened for write */	  }		/* if there was no fault */	  forever{	    UChar	comprbuf[0x1000];	    if(var_compr){		fmterr = try_cont = NO;		i = params->inputfunc(buf2, 2, params);		if(i < 2){		  fmterr = YES;		}		else{		  xref_to_UnsN(&len, buf2, 16);		  if(len > 0xfff || len < 0)		    fmterr = try_cont = YES;		}		if(!fmterr){		  i = params->inputfunc(comprbuf, len, params);		  if(i < len){		    params->vars.errnum |= EUNPACKREAD;		    fmterr = YES;		  }		  else{		    if(!fault){	   	      if(write_file(fd, comprbuf, len, &params->vars.zfile,				len < 0xfff ? YES : NO, writefunc) != len){			fprintf(errfp, T_("Error: writing to `%s' failed.\n"), buf);			params->vars.errnum |= EUNPACKWRITE;			fault = YES;		      }		    }#ifdef	USE_ZLIB		    if(cks)			crc32sum = crc32(crc32sum, comprbuf, len);#endif		  }	        }		else{		  if(fd >= 0){		    if(pid > 0){			kill(pid, SIGTERM);			waitpid_forced(pid, &pst, 0);		    }		    close(fd);		  }#ifdef	USE_ZLIB		  if(builtin_uncompress)		    reset_zfile(&params->vars.zfile);#endif		  if(try_cont){		    i = formaterr(&type, params, started);		    have_an_error = YES;		    goto tryagain;		  }		  else		    goto eoferr;	 	}		if(len < 0xfff)		  break;		continue;	    }	    if(filelen < BUFFERSIZ){	      len = (Int32) filelen;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -