Beispiel #1
0
int apply_cipso_file(int fd)
{
	struct smack_cipso *cipso = NULL;
	int ret;

	ret = smack_cipso_new(&cipso);
	if (ret)
		return -1;

	ret = smack_cipso_add_from_file(cipso, fd);
	if (ret) {
		smack_cipso_free(cipso);
		return -1;
	}

	ret = smack_cipso_apply(cipso);
	smack_cipso_free(cipso);
	if (ret)
		return -1;

	return 0;
}
Beispiel #2
0
int apply_cipso_file(int fd)
{
	struct smack_cipso *cipso = NULL;
	int ret;

	cipso = smack_cipso_new(fd);
	if (cipso == NULL)
		return -1;

	ret = smack_cipso_apply(cipso);
	smack_cipso_free(cipso);
	if (ret)
		return -1;

	return 0;
}
Beispiel #3
0
struct smack_cipso *smack_cipso_new(int fd)
{
	struct smack_cipso *cipso = NULL;
	struct cipso_mapping *mapping = NULL;
	FILE *file = NULL;
	char buf[BUF_SIZE];
	char *label, *level, *cat, *ptr;
	long int val;
	int i;
	int newfd;

	newfd = dup(fd);
	if (newfd == -1)
		return NULL;

	file = fdopen(newfd, "r");
	if (file == NULL) {
		close(newfd);
		return NULL;
	}

	cipso = calloc(sizeof(struct smack_cipso ), 1);
	if (cipso == NULL) {
		fclose(file);
		return NULL;
	}

	while (fgets(buf, BUF_SIZE, file) != NULL) {
		mapping = calloc(sizeof(struct cipso_mapping), 1);
		if (mapping == NULL)
			goto err_out;

		label = strtok_r(buf, " \t\n", &ptr);
		level = strtok_r(NULL, " \t\n", &ptr);
		cat = strtok_r(NULL, " \t\n", &ptr);
		if (label == NULL || cat == NULL || level == NULL ||
		    strlen(label) > SMACK_LABEL_LEN) {
			errno = EINVAL;
			goto err_out;
		}

		strcpy(mapping->label, label);

		errno = 0;
		val = strtol(level, NULL, 10);
		if (errno)
			goto err_out;

		if (val < 0 || val > LEVEL_MAX) {
			errno = ERANGE;
			goto err_out;
		}

		mapping->level = val;

		for (i = 0; i < CAT_MAX_COUNT && cat != NULL; i++) {
			errno = 0;
			val = strtol(cat, NULL, 10);
			if (errno)
				goto err_out;

			if (val < 0 || val > CAT_MAX_VALUE) {
				errno = ERANGE;
				goto err_out;
			}

			mapping->cats[i] = val;

			cat = strtok_r(NULL, " \t\n", &ptr);
		}

		mapping->ncats = i;

		if (cipso->first == NULL) {
			cipso->first = cipso->last = mapping;
		} else {
			cipso->last->next = mapping;
			cipso->last = mapping;
		}
	}

	if (ferror(file))
		goto err_out;

	fclose(file);
	return cipso;
err_out:
	fclose(file);
	smack_cipso_free(cipso);
	free(mapping);
	return NULL;
}