Example #1
0
/* encode device info */
void
th_set_device(TAR *t, dev_t device)
{
#ifdef DEBUG
	printf("th_set_device(): major = %d, minor = %d\n",
	       major(device), minor(device));
#endif
	int_to_oct(major(device), t->th_buf.devmajor, 8);
	int_to_oct(minor(device), t->th_buf.devminor, 8);
}
Example #2
0
/* encode file mode */
void
th_set_mode(TAR *t, mode_t fmode)
{
	if (S_ISSOCK(fmode))
	{
		fmode &= ~S_IFSOCK;
		fmode |= S_IFIFO;
	}
	int_to_oct(fmode, (t)->th_buf.mode, 8);
}
Example #3
0
/* encode group info */
void
th_set_group(TAR *t, gid_t gid)
{
	struct group *gr;

	gr = getgrgid(gid);
	if (gr != NULL)
		strlcpy(t->th_buf.gname, gr->gr_name, sizeof(t->th_buf.gname));

	int_to_oct(gid, t->th_buf.gid, 8);
}
Example #4
0
/* encode user info */
void
th_set_user(TAR *t, uid_t uid)
{
	struct passwd *pw;

	pw = getpwuid(uid);
	if (pw != NULL)
		strlcpy(t->th_buf.uname, pw->pw_name, sizeof(t->th_buf.uname));

	int_to_oct(uid, t->th_buf.uid, 8);
}
Example #5
0
/* encode file mode */
void
th_set_mode(TAR *t, mode_t fmode)
{
#ifndef _WIN32
	if (S_ISSOCK(fmode))
	{
		fmode &= ~S_IFSOCK;
		fmode |= S_IFIFO;
	}
#endif
	int_to_oct((fmode & 0xFFF), (t)->th_buf.mode, 8);
}
int
util_tar_extract(const char *tar_filename, const char* index_file, const char* out_dir)
{
	TAR *tar = NULL;

	int ret = tar_open(&tar, tar_filename, &gztype, O_RDONLY, 0, TAR_GNU);
	if (ret != 0) {
		ERROR_ERRNO("Fail to open tarfile: %s\n", tar_filename);
		return ret;
	}
	//ret = tar_extract_all(tar, tar_prefix);
	while (th_read(tar) == 0) {
		char *archive_filename = th_get_pathname(tar);
		char *out_filename = mem_printf("%s/%s", out_dir, archive_filename);

		char *mode = mem_alloc0(4*sizeof(char));
		int_to_oct(th_get_mode(tar), mode, 4*sizeof(char));
		uid_t uid = th_get_uid(tar);
		gid_t gid = th_get_gid(tar);

		INFO("Writing file %s to %s", archive_filename, out_filename);
		if (TH_ISCHR(tar)) {
			// writing file attributes to index file (TODO use hashmap to handle duplicates)
			file_printf_append(index_file, "%s c %s %d %d %d %d\n",
				archive_filename, mode, uid, gid,
				th_get_devmajor(tar),
				th_get_devminor(tar));
		} else if (TH_ISBLK(tar)) {
			// writing file attributes to index file (TODO use hashmap to handle duplicates)
			file_printf_append(index_file, "%s b %s %d %d %d %d\n",
				archive_filename, mode, uid, gid,
				th_get_devmajor(tar),
				th_get_devminor(tar));
		} else {
			if (tar_extract_file(tar, out_filename) != 0) {
				INFO_ERRNO("Skipping file: %s", archive_filename);
			} else {
				// writing file attributes to index file (TODO use hashmap to handle duplicates)
				file_printf_append(index_file, "%s m %s %d %d\n",
					archive_filename, mode, uid, gid);
			}
		}

		mem_free(mode);
		mem_free(archive_filename);
		mem_free(out_filename);
	}

	ret |= tar_close(tar);
	return ret;
}
Example #7
0
/* encode file mode */
void
th_set_mode(TAR *t, mode_t fmode)
{
#ifndef WIN32
#ifndef __BEOS__
    if (S_ISSOCK(fmode))
    {
        fmode &= ~S_IFSOCK;
        fmode |= S_IFIFO;
    }
#endif
#endif
    /* Looks like on windows the st_mode is longer than 8 characters. */
    int_to_oct(fmode & 07777777, (t)->th_buf.mode, 8);
}
Example #8
0
/* magic, version, and checksum */
void
th_finish(TAR *t)
{
    int i, sum = 0;

    if (t->options & TAR_GNU)
        strncpy(t->th_buf.magic, "ustar  ", 8);
    else
    {
        strncpy(t->th_buf.version, TVERSION, TVERSLEN);
        strncpy(t->th_buf.magic, TMAGIC, TMAGLEN);
    }

    for (i = 0; i < T_BLOCKSIZE; i++)
        sum += ((char *)(&(t->th_buf)))[i];
    for (i = 0; i < 8; i++)
        sum += (' ' - t->th_buf.chksum[i]);
    int_to_oct(sum, t->th_buf.chksum, 8);
}
Example #9
0
/* magic, version, and checksum */
void
th_finish(TAR *t)
{
	if (t->options & TAR_GNU)
	{
		/* we're aiming for this result, but must do it in
		 * two calls to avoid FORTIFY segfaults on some Linux
		 * systems:
		 *      strncpy(t->th_buf.magic, "ustar  ", 8);
		 */
		strncpy(t->th_buf.magic, "ustar ", 6);
		strncpy(t->th_buf.version, " ", 2);
	}
	else
	{
		strncpy(t->th_buf.version, TVERSION, TVERSLEN);
		strncpy(t->th_buf.magic, TMAGIC, TMAGLEN);
	}

	int_to_oct(th_crc_calc(t), t->th_buf.chksum, 8);
}