Blame src/boolean_record.c

Packit Service 102278
/* Copyright (C) 2005 Red Hat, Inc. */
Packit Service 102278
Packit Service 102278
/* Object: semanage_bool_t (Policy Boolean)
Packit Service 102278
 * Object: semanage_bool_key_t (Policy Boolean Key)
Packit Service 102278
 * Implements: record_t (Database Record)
Packit Service 102278
 * Implements: record_key_t (Database Record Key)
Packit Service 102278
 */
Packit Service 102278
Packit Service 102278
#include <string.h>
Packit Service 102278
#include <sepol/boolean_record.h>
Packit Service 102278
#include "handle_internal.h"
Packit Service 102278
Packit Service 102278
typedef sepol_bool_t semanage_bool_t;
Packit Service 102278
typedef sepol_bool_key_t semanage_bool_key_t;
Packit Service 102278
#define _SEMANAGE_BOOL_DEFINED_
Packit Service 102278
Packit Service 102278
typedef semanage_bool_t record_t;
Packit Service 102278
typedef semanage_bool_key_t record_key_t;
Packit Service 102278
#define DBASE_RECORD_DEFINED
Packit Service 102278
Packit Service 102278
#include "boolean_internal.h"
Packit Service 102278
#include "handle.h"
Packit Service 102278
#include "database.h"
Packit Service 102278
#include <stdlib.h>
Packit Service 102278
#include <selinux/selinux.h>
Packit Service 102278
Packit Service 102278
/* Key */
Packit Service 102278
int semanage_bool_key_create(semanage_handle_t * handle,
Packit Service 102278
			     const char *name, semanage_bool_key_t ** key)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_key_create(handle->sepolh, name, key);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
int semanage_bool_key_extract(semanage_handle_t * handle,
Packit Service 102278
			      const semanage_bool_t * boolean,
Packit Service 102278
			      semanage_bool_key_t ** key)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_key_extract(handle->sepolh, boolean, key);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_key_extract)
Packit Service 102278
Packit Service 102278
void semanage_bool_key_free(semanage_bool_key_t * key)
Packit Service 102278
{
Packit Service 102278
	sepol_bool_key_free(key);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_key_free)
Packit Service 102278
Packit Service 102278
int semanage_bool_compare(const semanage_bool_t * boolean,
Packit Service 102278
			  const semanage_bool_key_t * key)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_compare(boolean, key);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_compare)
Packit Service 102278
Packit Service 102278
int semanage_bool_compare2(const semanage_bool_t * boolean,
Packit Service 102278
			   const semanage_bool_t * boolean2)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_compare2(boolean, boolean2);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_compare2)
Packit Service 102278
Packit Service 102278
static int semanage_bool_compare2_qsort(const semanage_bool_t ** boolean,
Packit Service 102278
					const semanage_bool_t ** boolean2)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_compare2(*boolean, *boolean2);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
/* Name */
Packit Service 102278
const char *semanage_bool_get_name(const semanage_bool_t * boolean)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_get_name(boolean);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_get_name)
Packit Service 102278
Packit Service 102278
int semanage_bool_set_name(semanage_handle_t * handle,
Packit Service 102278
			   semanage_bool_t * boolean, const char *name)
Packit Service 102278
{
Packit Service 102278
	int rc = -1;
Packit Service 102278
	const char *prefix = semanage_root();
Packit Service 102278
	const char *storename = handle->conf->store_path;
Packit Service 102278
	const char *selinux_root = selinux_policy_root();
Packit Service 102278
	char *oldroot;
Packit Service 102278
	char *olddir;
Packit Service 102278
	char *subname = NULL;
Packit Service 102278
	char *newroot = NULL;
Packit Service 102278
	char *end;
Packit Service 102278
Packit Service 102278
	if (!selinux_root)
Packit Service 102278
		return -1;
Packit Service 102278
Packit Service 102278
	oldroot = strdup(selinux_root);
Packit Service 102278
	if (!oldroot)
Packit Service 102278
		return -1;
Packit Service 102278
	olddir = strdup(oldroot);
Packit Service 102278
	if (!olddir)
Packit Service 102278
		goto out;
Packit Service 102278
	end = strrchr(olddir, '/');
Packit Service 102278
	if (!end)
Packit Service 102278
		goto out;
Packit Service 102278
	end++;
Packit Service 102278
	*end = '\0';
Packit Service 102278
	rc = asprintf(&newroot, "%s%s%s", prefix, olddir, storename);
Packit Service 102278
	if (rc < 0)
Packit Service 102278
		goto out;
Packit Service 102278
Packit Service 102278
	if (strcmp(oldroot, newroot)) {
Packit Service 102278
		rc = selinux_set_policy_root(newroot);
Packit Service 102278
		if (rc)
Packit Service 102278
			goto out;
Packit Service 102278
	}
Packit Service 102278
Packit Service 102278
	subname = selinux_boolean_sub(name);
Packit Service 102278
	if (!subname) {
Packit Service 102278
		rc = -1;
Packit Service 102278
		goto out;
Packit Service 102278
	}
Packit Service 102278
Packit Service 102278
	if (strcmp(oldroot, newroot)) {
Packit Service 102278
		rc = selinux_set_policy_root(oldroot);
Packit Service 102278
		if (rc)
Packit Service 102278
			goto out;
Packit Service 102278
	}
Packit Service 102278
Packit Service 102278
	rc = sepol_bool_set_name(handle->sepolh, boolean, subname);
Packit Service 102278
out:
Packit Service 102278
	free(subname);
Packit Service 102278
	free(oldroot);
Packit Service 102278
	free(olddir);
Packit Service 102278
	free(newroot);
Packit Service 102278
	return rc;
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_set_name)
Packit Service 102278
Packit Service 102278
/* Value */
Packit Service 102278
int semanage_bool_get_value(const semanage_bool_t * boolean)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_get_value(boolean);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_get_value)
Packit Service 102278
Packit Service 102278
void semanage_bool_set_value(semanage_bool_t * boolean, int value)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	sepol_bool_set_value(boolean, value);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_set_value)
Packit Service 102278
Packit Service 102278
/* Create/Clone/Destroy */
Packit Service 102278
int semanage_bool_create(semanage_handle_t * handle,
Packit Service 102278
			 semanage_bool_t ** bool_ptr)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_create(handle->sepolh, bool_ptr);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_create)
Packit Service 102278
Packit Service 102278
int semanage_bool_clone(semanage_handle_t * handle,
Packit Service 102278
			const semanage_bool_t * boolean,
Packit Service 102278
			semanage_bool_t ** bool_ptr)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	return sepol_bool_clone(handle->sepolh, boolean, bool_ptr);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_clone)
Packit Service 102278
Packit Service 102278
void semanage_bool_free(semanage_bool_t * boolean)
Packit Service 102278
{
Packit Service 102278
Packit Service 102278
	sepol_bool_free(boolean);
Packit Service 102278
}
Packit Service 102278
Packit Service 102278
hidden_def(semanage_bool_free)
Packit Service 102278
Packit Service 102278
/* Record base functions */
Packit Service 102278
record_table_t SEMANAGE_BOOL_RTABLE = {
Packit Service 102278
	.create = semanage_bool_create,
Packit Service 102278
	.key_extract = semanage_bool_key_extract,
Packit Service 102278
	.key_free = semanage_bool_key_free,
Packit Service 102278
	.clone = semanage_bool_clone,
Packit Service 102278
	.compare = semanage_bool_compare,
Packit Service 102278
	.compare2 = semanage_bool_compare2,
Packit Service 102278
	.compare2_qsort = semanage_bool_compare2_qsort,
Packit Service 102278
	.free = semanage_bool_free,
Packit Service 102278
};