static int makeflow_archive_task_adheres_to_sandbox( struct batch_task *t ){
	int rc = 0;
	struct batch_file *f;
	struct list_cursor *cur = list_cursor_create(t->input_files);
	// Iterate through input files
	for(list_seek(cur, 0); list_get(cur, (void**)&f); list_next(cur)) {
		// If your using an absolute path or trying to get our of a directory using the (..)
		if(path_has_doubledots(f->inner_name) || f->inner_name[0] == '/'){
			// Print out a debug error
			debug(D_MAKEFLOW_HOOK, 
				"task %d will not be archived as input file %s->%s does not adhere to the sandbox model of execution", 
				t->taskid, f->outer_name, f->inner_name);
			rc = 1;
		}
	}
	// Frees memory of list cursor
	list_cursor_destroy(cur);
	

	cur = list_cursor_create(t->output_files);
	// Iterates through output files
	for(list_seek(cur, 0); list_get(cur, (void**)&f); list_next(cur)) {
		// Same check as input files
		if(path_has_doubledots(f->inner_name) || f->inner_name[0] == '/'){
			// Prints out a debug error
			debug(D_MAKEFLOW_HOOK, 
				"task %d will not be archived as output file %s->%s does not adhere to the sandbox model of execution", 
				t->taskid, f->outer_name, f->inner_name);
			rc = 1;
		}
	}
	// Frees memory of list cursor
	list_cursor_destroy(cur);

	return rc;
}
Esempio n. 2
0
int makeflow_clean_mount_target(const char *target) {
	file_type t_type;

	if(!target || !*target) return 0;

	/* Check whether target already exists. */
	if(access(target, F_OK)) {
		debug(D_DEBUG, "the target (%s) does not exist!\n", target);
		return 0;
	}

	/* Check whether the target is an absolute path. */
	if(target[0] == '/') {
		debug(D_DEBUG, "the target (%s) should not be an absolute path!\n", target);
		fprintf(stderr, "the target (%s) should not be an absolute path!\n", target);
		return -1;
	}

	/* check whether target includes .. */
	if(path_has_doubledots(target)) {
		debug(D_DEBUG, "the target (%s) include ..!\n", target);
		fprintf(stderr, "the target (%s) include ..!\n", target);
		return -1;
	}

	/* check whether target is REG, LNK, DIR */
	if((t_type = check_file_type(target)) == FILE_TYPE_UNSUPPORTED)
		return -1;

	if(unlink_recursive(target)) {
		debug(D_DEBUG, "Failed to remove %s!\n", target);
		fprintf(stderr, "Failed to remove %s!\n", target);
		return -1;
	}

	return 0;
}