Beispiel #1
0
void
populate(char *name)
{
	long blkno, isabs, chksum, linkflg;
	Fileinf f;

	tapefile = open(name, OREAD);
	if (tapefile<0)
		error("Can't open argument file");
	replete = 1;
	for (blkno = 0;;) {
		seek(tapefile, TBLOCK*blkno, 0);
		if (read(tapefile, dblock.dummy, sizeof(dblock.dummy))<sizeof(dblock.dummy))
			break;
		if (dblock.dbuf.name[0]=='\0')
			break;
		f.addr = blkno+1;
		f.mode = strtoul(dblock.dbuf.mode, 0, 8);
		f.uid = strtoul(dblock.dbuf.uid, 0, 8);
		f.gid = strtoul(dblock.dbuf.gid, 0, 8);
		if((uchar)dblock.dbuf.size[0] == 0x80)
			f.size = b8byte(dblock.dbuf.size+3);
		else
			f.size = strtoull(dblock.dbuf.size, 0, 8);
		f.mdate = strtoul(dblock.dbuf.mtime, 0, 8);
		chksum = strtoul(dblock.dbuf.chksum, 0, 8);
		/* the mode test is ugly but sometimes necessary */
		if (dblock.dbuf.linkflag == '5'
		|| (f.mode&0170000) == 040000
		||  strrchr(dblock.dbuf.name, '\0')[-1] == '/'){
			f.mode |= DMDIR;
			f.size = 0;
		}
		f.mode &= DMDIR|0777;
		linkflg = dblock.dbuf.linkflag=='s' || dblock.dbuf.linkflag=='1';
		isabs = dblock.dbuf.name[0]=='/';
		if (chksum != checksum()){
			fprint(1, "bad checksum on %.28s\n", dblock.dbuf.name);
			exits("checksum");
		}
		if (linkflg) {
			/*fprint(2, "link %s->%s skipped\n", dblock.dbuf.name,
			   dblock.dbuf.linkname);*/
			f.size = 0;
			blkno += 1;
			continue;
		}
		f.name = dblock.dbuf.name+isabs;
		if (f.name[0]=='\0')
			fprint(1, "null name skipped\n");
		else
			poppath(f, 1);
		blkno += 1 + (f.size+TBLOCK-1)/TBLOCK;
	}
}
Beispiel #2
0
void
populate(char *name)
{
	int64_t offset;
	int32_t isabs, magic, namesize, mode;
	Fileinf f;

	tapefile = open(name, OREAD);
	if (tapefile<0)
		error("Can't open argument file");
	replete = 1;
	for (offset = 0;;) {
		seek(tapefile, offset, 0);
		if (read(tapefile, (char *)&dblock.dbuf, TBLOCK)<TBLOCK)
			break;
		magic = getoct(dblock.dbuf.magic, sizeof(dblock.dbuf.magic));
		if (magic != 070707){
			print("%lo\n", magic);
			error("out of phase--get help");
		}
		if (dblock.nbuf.name[0]=='\0' || strcmp(dblock.nbuf.name, "TRAILER!!!")==0)
			break;
		mode = getoct(dblock.dbuf.mode, sizeof(dblock.dbuf.mode));
		f.mode = mode&0777;
		switch(mode & 0170000) {
		case 0040000:
			f.mode |= DMDIR;
			break;
		case 0100000:
			break;
		default:
			f.mode = 0;
			break;
		}
		f.uid = getoct(dblock.dbuf.uid, sizeof(dblock.dbuf.uid));
		f.gid = getoct(dblock.dbuf.gid, sizeof(dblock.dbuf.gid));
		f.size = getoct(dblock.dbuf.size, sizeof(dblock.dbuf.size));
		f.mdate = getoct(dblock.dbuf.mtime, sizeof(dblock.dbuf.mtime));
		namesize = getoct(dblock.dbuf.namesize, sizeof(dblock.dbuf.namesize));
		f.addr = offset+sizeof(struct header)+namesize;
		isabs = dblock.nbuf.name[0]=='/';
		f.name = &dblock.nbuf.name[isabs];
		poppath(f, 1);
		offset += sizeof(struct header)+namesize+f.size;
	}
}
Beispiel #3
0
void
populate(char *name)
{
	char *p;
	Fileinf f;
	ZipHead zh;
	int ok, entries;

	crctab = mkcrctab(ZCrcPoly);
	ok = inflateinit();
	if(ok != FlateOk)
		sysfatal("inflateinit failed: %s", flateerr(ok));

	bin = Bopen(name, OREAD);
	if (bin == nil)
		error("Can't open argument file");

	entries = findCDir(bin);
	if(entries < 0)
		sysfatal("empty file");

	while(entries-- > 0){
		memset(&zh, 0, sizeof(zh));
		if(!cheader(bin, &zh))
			break;
		f.addr = zh.off;
		if(zh.iattr & IS_TEXT)
			f.addr |= High64;
		f.mode = (zh.madevers == IS_MSDOS && zh.eattr & IS_RDONLY)? 0444: 0644;
		if (zh.meth == 0 && zh.uncsize == 0){
			p = strchr(zh.file, '\0');
			if(p > zh.file && p[-1] == '/')
				f.mode |= (DMDIR | 0111);
		}
		f.uid = 0;
		f.gid = 0;
		f.size = zh.uncsize;
		f.mdate = msdos2time(zh.modtime, zh.moddate);
		f.name = zh.file + ((zh.file[0] == '/')? 1: 0);
		poppath(f, 1);
		free(zh.file);
	}
	return ;
}
Beispiel #4
0
void
populate(char *name)
{
	int i, isabs, badcksum, goodcksum;
	struct tp *tpp;
	Fileinf f;

	replete = 1;
	tapefile = open(name, OREAD);
	if (tapefile<0)
		error("Can't open argument file");
	read(tapefile, dir, sizeof dir);
	badcksum = goodcksum = 0;
	for (i=0, tpp=&dir[8]; i<496; i++, tpp++) {
		unsigned char *sp = (unsigned char *)tpp;
		int j, cksum = 0;
		for (j=0; j<32; j++, sp+=2)
			cksum += sp[0] + (sp[1]<<8);
		cksum &= 0xFFFF;
		if (cksum!=0) {
			badcksum++;
			continue;
		}
		goodcksum++;
		if (tpp->name[0]=='\0')
			continue;
		f.addr = tpp->taddress[0] + (tpp->taddress[1]<<8);
		if (f.addr==0)
			continue;
		f.size = (tpp->size[0]<<16) + (tpp->size[1]<<0) + (tpp->size[2]<<8);
		f.mdate = (tpp->tmod[2]<<0) + (tpp->tmod[3]<<8)
		     +(tpp->tmod[0]<<16) + (tpp->tmod[1]<<24);
		f.mode = tpp->mode[0]&0777;
		f.uid = tpp->uid[0];
		f.gid = tpp->gid[0];
		isabs = tpp->name[0]=='/';
		f.name = (char *)tpp->name+isabs;
		poppath(f, 1);
	}
	fprint(2, "%d bad checksums, %d good\n", badcksum, goodcksum);
}
Beispiel #5
0
void
populate(char *name)
{
	int i, isabs;
	struct tap *tpp;
	Fileinf f;

	replete = 1;
	tapefile = open(name, OREAD);
	if (tapefile<0)
		error("Can't open argument file");
	read(tapefile, dir, sizeof dir);
	for (i=0, tpp=&dir[8]; i<192; i++, tpp++) {
		unsigned char *sp = (unsigned char *)tpp;
		int j, cksum = 0;
		for (j=0; j<32; j++, sp+=2)
			cksum += sp[0] + (sp[1]<<8);
		cksum &= 0xFFFF;
		if (cksum!=0) {
			print("cksum failure\n");
			continue;
		}
		if (tpp->name[0]=='\0')
			continue;
		f.addr = tpp->taddress[0] + (tpp->taddress[1]<<8);
		if (f.addr==0)
			continue;
		f.size = tpp->size[0] + (tpp->size[1]<<8);
		f.mdate = cvtime(tpp->tmod);
		f.mode = tpp->mode[0]&0777;
		f.uid = tpp->uid[0]&0377;
		isabs = tpp->name[0]=='/';
		f.name = (char *)tpp->name+isabs;
		if (verbose)
			print("%s mode %o uid %d, %s", f.name, f.mode, f.uid, ctime(f.mdate));
		poppath(f, 1);
	}
}
Beispiel #6
0
void
populate(char *name)
{
	int32_t chksum, linkflg;
	int64_t blkno;
	char *fname;
	Fileinf f;
	Hdr *hp;

	tapefile = open(name, OREAD);
	if (tapefile < 0)
		error("Can't open argument file");
	replete = 1;
	hp = &dblock;
	for (blkno = 0; ; blkno++) {
		seek(tapefile, Tblock*blkno, 0);
		if (readn(tapefile, hp->dummy, sizeof hp->dummy) < sizeof hp->dummy)
			break;
		fname = tarname(hp);
		if (fname[0] == '\0')
			break;

		/* crack header */
		f.addr = blkno + 1;
		f.mode = strtoul(hp->mode, 0, 8);
		f.uid  = strtoul(hp->uid, 0, 8);
		f.gid  = strtoul(hp->gid, 0, 8);
		if((uint8_t)hp->size[0] == 0x80)
			f.size = b8byte(hp->size+3);
		else
			f.size = strtoull(hp->size, 0, 8);
		f.mdate = strtoul(hp->mtime, 0, 8);
		chksum  = strtoul(hp->chksum, 0, 8);
		/* the mode test is ugly but sometimes necessary */
		if (hp->linkflag == LF_DIR || (f.mode&0170000) == 040000 ||
		    strrchr(fname, '\0')[-1] == '/'){
			f.mode |= DMDIR;
			f.size = 0;
		}
		f.mode &= DMDIR | 0777;

		/* make file name safe, canonical and free of . and .. */
		while (fname[0] == '/')		/* don't allow absolute paths */
			++fname;
		cleanname(fname);
		while (strncmp(fname, "../", 3) == 0)
			fname += 3;

		/* reject links */
		linkflg = hp->linkflag == LF_SYMLINK1 ||
			hp->linkflag == LF_SYMLINK2 || hp->linkflag == LF_LINK;
		if (chksum != checksum()){
			fprint(2, "%s: bad checksum on %.28s at offset %lld\n",
				argv0, fname, Tblock*blkno);
			exits("checksum");
		}
		if (linkflg) {
			/*fprint(2, "link %s->%s skipped\n", fname, hp->linkname);*/
			f.size = 0;
		} else {
			/* accept this file */
			f.name = fname;
			if (f.name[0] == '\0')
				fprint(2, "%s: null name skipped\n", argv0);
			else
				poppath(f, 1);
			blkno += (f.size + Tblock - 1)/Tblock;
		}
	}
}