Пример #1
0
int apply_cipso(const char *path)
{
	struct stat sbuf;
	int fd;
	int ret;

	if (stat(path, &sbuf)) {
		fprintf(stderr, "stat() failed for '%s' : %s\n", path, strerror(errno));
		return -1;
	}

	if (S_ISDIR(sbuf.st_mode))
		return nftw(path, apply_cipso_cb, 1, FTW_PHYS|FTW_ACTIONRETVAL);

	fd = open(path, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "open() failed for '%s' : %s\n", path, strerror(errno));
		return -1;
	}

	ret = apply_cipso_file(fd);
	if (ret)
		fprintf(stderr, "Applying rules failed for '%s'.\n",  path);
	close(fd);
	return ret;
}
Пример #2
0
static int apply_cipso_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
	int fd;
	int ret;

	if (typeflag == FTW_D)
		return ftwbuf->level ? FTW_SKIP_SUBTREE : FTW_CONTINUE;
	else if (typeflag != FTW_F)
		return FTW_STOP;

	fd = open(fpath, O_RDONLY);
	if (fd < 0)
		return -1;

	ret = apply_cipso_file(fd) ? FTW_STOP : FTW_CONTINUE;
	close(fd);
	return ret;
}
Пример #3
0
int apply_cipso(const char *path)
{
	struct stat sbuf;
	int fd;
	int ret;

	errno = 0;
	if (stat(path, &sbuf))
		return -1;

	if (S_ISDIR(sbuf.st_mode))
		return nftw(path, apply_cipso_cb, 1, FTW_PHYS|FTW_ACTIONRETVAL);

	fd = open(path, O_RDONLY);
	if (fd < 0)
		return -1;

	ret = apply_cipso_file(fd);
	close(fd);
	return ret;
}
Пример #4
0
static int apply_cipso_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
	int fd;
	int ret;

	if (typeflag == FTW_D)
		return ftwbuf->level ? FTW_SKIP_SUBTREE : FTW_CONTINUE;
	else if (typeflag != FTW_F)
		return FTW_STOP;

	fd = open(fpath, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "open() failed for '%s' : %s\n", fpath, strerror(errno));
		return -1;
	}

	ret = apply_cipso_file(fd) ? FTW_STOP : FTW_CONTINUE;
	if (ret == FTW_STOP)
		fprintf(stderr, "Applying rules failed for '%s'.\n",  fpath);
	close(fd);
	return ret;
}
Пример #5
0
int main(int argc, char **argv)
{
	if (!smack_smackfs_path()) {
		fprintf(stderr, "SmackFS is not mounted.\n");
		exit(1);
	}

	if (argc > 2) {
		fprintf(stderr, "Usage: %s <path>\n", argv[0]);
		exit(1);
	}

	if (argc == 1) {
		if (apply_cipso_file(STDIN_FILENO))
			exit(1);
	} else {
		if (apply_cipso(argv[1]))
			exit(1);
	}

	exit(0);
}