/*
**  Copyright 1998-2003 University of Illinois Board of Trustees
**  Copyright 1998-2003 Mark D. Roth
**  All rights reserved.
**
**  append.c - libtar code to append files to a tar archive
**
**  Mark D. Roth <roth@uiuc.edu>
**  Campus Information Technologies and Educational Services
**  University of Illinois at Urbana-Champaign
*/

#include <internal.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <sys/param.h>
#include <sys/types.h>
#include <stdbool.h>

#include <sys/capability.h>
#include <sys/xattr.h>
#include <linux/fs.h>
#include <linux/xattr.h>

#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <selinux/selinux.h>

#ifdef USE_FSCRYPT
#include "fscrypt_policy.h"
#endif

#include "android_utils.h"

#ifdef TW_LIBTAR_DEBUG
#define DEBUG 1
#endif

struct tar_dev
{
	dev_t td_dev;
	libtar_hash_t *td_h;
};
typedef struct tar_dev tar_dev_t;

struct tar_ino
{
	ino_t ti_ino;
	char ti_name[MAXPATHLEN];
};
typedef struct tar_ino tar_ino_t;


/* free memory associated with a tar_dev_t */
void
tar_dev_free(tar_dev_t *tdp)
{
	libtar_hash_free(tdp->td_h, free);
	free(tdp);
}


/* appends a file to the tar archive */
int
tar_append_file(TAR *t, const char *realname, const char *savename)
{
	struct stat s;
	int i;
	libtar_hashptr_t hp;
	tar_dev_t *td = NULL;
	tar_ino_t *ti = NULL;
	char path[MAXPATHLEN];
	int filefd;

#ifdef DEBUG
	LOG("==> tar_append_file(TAR=0x%p (\"%s\"), realname=\"%s\", "
	       "savename=\"%s\")\n", (void*) t, t->pathname, realname,
	       (savename ? savename : "[NULL]"));
#endif

	if (lstat(realname, &s) != 0)
	{
#ifdef DEBUG
		perror("lstat()");
#endif
		return -1;
	}

	/* set header block */
#ifdef DEBUG
	LOG("tar_append_file(): setting header block...");
#endif
	memset(&(t->th_buf), 0, sizeof(struct tar_header));
	th_set_from_stat(t, &s);

	/* set the header path */
#ifdef DEBUG
	LOG("tar_append_file(): setting header path...");
#endif
	th_set_path(t, (savename ? savename : realname));

	/* get selinux context */
	if (t->options & TAR_STORE_SELINUX)
	{
		if (t->th_buf.selinux_context != NULL)
		{
			free(t->th_buf.selinux_context);
			t->th_buf.selinux_context = NULL;
		}

		char* selinux_context = NULL;
		if (lgetfilecon(realname, &selinux_context) >= 0)
		{
			t->th_buf.selinux_context = strdup(selinux_context);
			LOG("  ==> set selinux context: %s\n", selinux_context);
			freecon(selinux_context);
		}
		else
		{
#ifdef DEBUG
			perror("Failed to get selinux context");
#endif
		}
	}

#ifdef USE_FSCRYPT
	if (TH_ISDIR(t) && t->options & TAR_STORE_FSCRYPT_POL)
	{
		if (t->th_buf.fep != NULL)
		{
			free(t->th_buf.fep);
			t->th_buf.fep = NULL;
		}
		t->th_buf.fep = (fscrypt_policy *)malloc(sizeof(fscrypt_policy));
		if (!t->th_buf.fep) {
			LOG("malloc fs_encryption_policy\n");
			return -1;
		}

		if (fscrypt_policy_get_struct(realname, t->th_buf.fep)) {
			uint8_t size, hex_size, *descriptor;
			size = get_policy_size(t->th_buf.fep, false);
			hex_size = get_policy_size(t->th_buf.fep, true);
			descriptor = get_policy_descriptor(t->th_buf.fep);
			char user_ce[4], user_de[4], system_de[4];
			sprintf(user_ce,"%u%s", t->th_buf.fep->version, USER_CE_FSCRYPT_POLICY);
			sprintf(user_de,"%u%s", t->th_buf.fep->version, USER_DE_FSCRYPT_POLICY);
			sprintf(system_de,"%u%s", t->th_buf.fep->version, SYSTEM_DE_FSCRYPT_POLICY);
#ifdef DEBUG
			LOG("version: %u\n", t->th_buf.fep->version);
#endif
			uint8_t tar_policy[size];
			char policy_hex[hex_size];
			memset(tar_policy, 0, sizeof(tar_policy));
			bytes_to_hex(descriptor, size, policy_hex);
			if (lookup_ref_key(t->th_buf.fep,  &tar_policy[0])) {
				if (strncmp((char *) tar_policy, user_ce, sizeof(user_ce) - 1) == 0 
				|| strncmp((char *) tar_policy, user_de, sizeof(user_de) - 1) == 0 
				|| strncmp((char *) tar_policy, system_de, sizeof(system_de)) == 0) {
					memcpy(descriptor, tar_policy, size);
					LOG("found fscrypt policy '%s' - '%s' - '%s'\n", realname, descriptor, policy_hex);
				} else {
					LOG("failed to match fscrypt tar policy for '%s' - '%s'\n", realname, policy_hex);
					free(t->th_buf.fep);
					t->th_buf.fep = NULL;
				}
			} else {
				LOG("failed to lookup fscrypt tar policy for '%s' - '%s'\n", realname, policy_hex);
				free(t->th_buf.fep);
				t->th_buf.fep = NULL;
			}
		}
		else {
			// no policy found, but this is not an error as not all dirs will have a policy
			free(t->th_buf.fep);
			t->th_buf.fep = NULL;
		}
	}
#endif

	/* get posix file capabilities */
	if (TH_ISREG(t) && t->options & TAR_STORE_POSIX_CAP)
	{
		if (t->th_buf.has_cap_data)
		{
			memset(&t->th_buf.cap_data, 0, sizeof(struct vfs_cap_data));
			t->th_buf.has_cap_data = 0;
		}

		if (getxattr(realname, XATTR_NAME_CAPS, &t->th_buf.cap_data, sizeof(struct vfs_cap_data)) >= 0)
		{
			t->th_buf.has_cap_data = 1;
#if 1 //def DEBUG
			print_caps(&t->th_buf.cap_data);
#endif
		}
	}

	/* get android user.default xattr */
	if (TH_ISDIR(t) && t->options & TAR_STORE_ANDROID_USER_XATTR)
	{
		if (getxattr(realname, "user.default", NULL, 0) >= 0)
		{
			t->th_buf.has_user_default = 1;
#if 1 //def DEBUG
			LOG("storing xattr user.default\n");
#endif
		}
		if (getxattr(realname, "user.inode_cache", NULL, 0) >= 0)
		{
			t->th_buf.has_user_cache = 1;
#if 1 //def DEBUG
			LOG("storing xattr user.inode_cache\n");
#endif
		}
		if (getxattr(realname, "user.inode_code_cache", NULL, 0) >= 0)
		{
			t->th_buf.has_user_code_cache = 1;
#if 1 //def DEBUG
			LOG("storing xattr user.inode_code_cache\n");
#endif
		}
	}

	/* check if it's a hardlink */
#ifdef DEBUG
	LOG("tar_append_file(): checking inode cache for hardlink...");
#endif
	libtar_hashptr_reset(&hp);
	if (libtar_hash_getkey(t->h, &hp, &(s.st_dev),
			       (libtar_matchfunc_t)dev_match) != 0)
		td = (tar_dev_t *)libtar_hashptr_data(&hp);
	else
	{
#ifdef DEBUG
		LOG("+++ adding hash for device (0x%x, 0x%x)...\n",
		       major(s.st_dev), minor(s.st_dev));
#endif
		td = (tar_dev_t *)calloc(1, sizeof(tar_dev_t));
		td->td_dev = s.st_dev;
		td->td_h = libtar_hash_new(256, (libtar_hashfunc_t)ino_hash);
		if (td->td_h == NULL)
			return -1;
		if (libtar_hash_add(t->h, td) == -1)
			return -1;
	}
	libtar_hashptr_reset(&hp);
	if (libtar_hash_getkey(td->td_h, &hp, &(s.st_ino),
			       (libtar_matchfunc_t)ino_match) != 0)
	{
		ti = (tar_ino_t *)libtar_hashptr_data(&hp);
#ifdef DEBUG
		LOG("    tar_append_file(): encoding hard link \"%s\" "
		       "to \"%s\"...\n", realname, ti->ti_name);
#endif
		t->th_buf.typeflag = LNKTYPE;
		th_set_link(t, ti->ti_name);
	}
	else
	{
#ifdef DEBUG
		LOG("+++ adding entry: device (0x%d,0x%x), inode %lu"
		       "(\"%s\")...\n", major(s.st_dev), minor(s.st_dev),
		       (unsigned long) s.st_ino, realname);
#endif
		ti = (tar_ino_t *)calloc(1, sizeof(tar_ino_t));
		if (ti == NULL)
			return -1;
		ti->ti_ino = s.st_ino;
		snprintf(ti->ti_name, sizeof(ti->ti_name), "%s",
			 savename ? savename : realname);
		libtar_hash_add(td->td_h, ti);
	}

	/* check if it's a symlink */
	if (TH_ISSYM(t))
	{
		i = readlink(realname, path, sizeof(path));
		if (i == -1)
			return -1;
		if (i >= MAXPATHLEN)
			i = MAXPATHLEN - 1;
		path[i] = '\0';
#ifdef DEBUG
		LOG("tar_append_file(): encoding symlink \"%s\" -> "
		       "\"%s\"...\n", realname, path);
#endif
		th_set_link(t, path);
	}

	/* print file info */
	if (t->options & TAR_VERBOSE)
		LOG("%s\n", th_get_pathname(t));

#if defined(O_BINARY)
        filefd = open(realname, O_RDONLY|O_BINARY);
#else
        filefd = open(realname, O_RDONLY);
#endif
        if (filefd == -1)
        {
                if (errno == ENOKEY) {
                        LOG("Required key not available, skipping file\n");
			close(filefd);
			return 0;
                }
        }
	close(filefd);
#ifdef DEBUG
	LOG("tar_append_file(): writing header");
#endif
	/* write header */
	if (th_write(t) != 0)
	{
#ifdef DEBUG
		LOG("t->fd = %ld\n", t->fd);
#endif
		return -1;
	}
#ifdef DEBUG
	LOG("tar_append_file(): back from th_write()");
#endif

	/* if it's a regular file, write the contents as well */
	if (TH_ISREG(t) && tar_append_regfile(t, realname) != 0)
		return -1;

	return 0;
}


/* write EOF indicator */
int
tar_append_eof(TAR *t)
{
	int i, j;
	char block[T_BLOCKSIZE];

	memset(&block, 0, T_BLOCKSIZE);
	for (j = 0; j < 2; j++)
	{
		i = tar_block_write(t, &block);
		if (i != T_BLOCKSIZE)
		{
			if (i != -1)
				errno = EINVAL;
			return -1;
		}
	}

	return 0;
}


/* add file contents to a tarchive */
int
tar_append_regfile(TAR *t, const char *realname)
{
	char block[T_BLOCKSIZE];
	int filefd;
	int64_t i, size;
	ssize_t j;
	int rv = -1;

#if defined(O_BINARY)
	filefd = open(realname, O_RDONLY|O_BINARY);
#else
	filefd = open(realname, O_RDONLY);
#endif
	if (filefd == -1)
	{
#ifdef DEBUG
		perror("open()");
#endif
		return -1;
	}

	size = th_get_size(t);
	for (i = size; i > T_BLOCKSIZE; i -= T_BLOCKSIZE)
	{
		j = read(filefd, &block, T_BLOCKSIZE);
		if (j != T_BLOCKSIZE)
		{
			if (j != -1)
				errno = EINVAL;
			goto fail;
		}
		if (tar_block_write(t, &block) == -1)
			goto fail;
	}

	if (i > 0)
	{
		j = read(filefd, &block, i);
		if (j == -1)
			goto fail;
		memset(&(block[i]), 0, T_BLOCKSIZE - i);
		if (tar_block_write(t, &block) == -1)
			goto fail;
	}

	/* success! */
	rv = 0;
fail:
	close(filefd);

	return rv;
}


/* add file contents to a tarchive */
int
tar_append_file_contents(TAR *t, const char *savename, mode_t mode,
                         uid_t uid, gid_t gid, void *buf, size_t len)
{
	struct stat st;

	memset(&st, 0, sizeof(st));
	st.st_mode = S_IFREG | mode;
	st.st_uid = uid;
	st.st_gid = gid;
	st.st_mtime = time(NULL);
	st.st_size = len;

	th_set_from_stat(t, &st);
	th_set_path(t, savename);

	/* write header */
	if (th_write(t) != 0)
	{
#ifdef DEBUG
		fprintf(stderr, "tar_append_file_contents(): could not write header, t->fd = %ld\n", t->fd);
#endif
		return -1;
	}

	return tar_append_buffer(t, buf, len);
}

int
tar_append_buffer(TAR *t, void *buf, size_t len)
{
	char block[T_BLOCKSIZE];
	int i;
	size_t size = len;

	for (i = size; i > T_BLOCKSIZE; i -= T_BLOCKSIZE)
	{
		if (tar_block_write(t, buf) == -1)
			return -1;
		buf = (char *)buf + T_BLOCKSIZE;
	}

	if (i > 0)
	{
		memcpy(block, buf, i);
		memset(&(block[i]), 0, T_BLOCKSIZE - i);
		if (tar_block_write(t, &block) == -1)
			return -1;
	}

	return 0;
}

