2008-08-19 19:30:36 +00:00
|
|
|
/* Authors: Joshua Brindle <jbrindle@tresys.com>
|
|
|
|
* Jason Tang <jtang@tresys.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Tresys Technology, LLC
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SEMANAGE_HANDLE_H_
|
|
|
|
#define _SEMANAGE_HANDLE_H_
|
|
|
|
|
libsemanage: add functions to public api
include/semanage/handle.h
* Exports the handle get/set default priority functions.
include/semanage/module.h
* Exports the module info management functions.
* Exports the get/set enabled status functions.
* Exports the module key management functions.
* Exports the module install, upgrade, remove info/key functions.
include/semanage/semanage.h
This patch includes the modifications to the map file for exporting the
necessary functions.
Examples:
/* changing the default priority for a distro install */
semanage_set_default_priority(sh, 100);
/* creating module meta data */
semanage_module_info_t *modinfo = NULL;
semanage_module_info_create(sh, &modinfo);
/* filling in that data */
semanage_module_info_set_priority(
sh,
modinfo,
semanage_get_default_priority(sh));
semanage_module_info_set_name(
sh,
modinfo,
"mymodule");
semanage_module_info_set_version(
sh,
modinfo,
"0.1.2");
semanage_module_info_set_lang_ext(
sh,
modinfo,
"pp");
semanage_module_info_set_enabled(
sh,
modinfo,
-1); /* Sets enabled to default:
* If the module was already enabled/disabled
* then it will remain so after install.
* If it wasn't, then it will be enabled.
*/
/* install the module */
semanage_module_install_info(sh, modinfo, data, data_len);
/* cleanup modinfo */
semanage_module_info_destroy(sh, modinfo);
/* create a key for retrieving a module's meta data */
semanage_module_key_t *modkey = NULL;
semanage_module_key_create(sh, &modkey);
/* Only set the module name, this will find the highest
* priority module of that name.
*/
semanage_module_key_set_name(sh, modkey, "mymodule");
/* get the newly installed module */
semanage_module_get_module_info(sh, modkey, &modinfo);
/* get the priority of the module found */
uint16_t priority = 0;
semanage_module_info_get_priority(sh, modinfo, &priority);
/* set the priority in the key to the one found */
semanage_module_key_set_priority(sh, modkey, priority);
/* remove the highest priority module with the name "mymodule" */
semanage_module_remove_key(sh, modkey);
/* print all the modules installed */
semanage_module_info_t *modinfos = NULL;
int modinfos_len = 0;
semanage_module_list_all(sh, &modinfos, &modinfos_len);
char *name = NULL;
int i = 0;
for (i = 0; i < modinfos_len; i++) {
semanage_module_info_get_priority(
sh,
semanage_module_list_nth(modinfos, i),
&priority);
semanage_module_info_get_name(
sh,
semanage_module_list_nth(modinfos, i),
&name);
printf("%d\t%s\n", priority, name);
}
Signed-off-by: Chad Sellers <csellers@tresys.com>
2009-12-23 23:25:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
/* All accesses with semanage are through a "semanage_handle". The
|
|
|
|
* handle may ultimately reference local config files,
|
|
|
|
* the binary policy file, a module store, or a policy management server.
|
|
|
|
*/
|
|
|
|
struct semanage_handle;
|
|
|
|
typedef struct semanage_handle semanage_handle_t;
|
|
|
|
|
|
|
|
/* Create and return a semanage handle.
|
|
|
|
The handle is initially in the disconnected state. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern semanage_handle_t *semanage_handle_create(void);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* Deallocate all space associated with a semanage_handle_t, including
|
|
|
|
* the pointer itself. CAUTION: this function does not disconnect
|
|
|
|
* from the backend; be sure that a semanage_disconnect() was
|
|
|
|
* previously called if the handle was connected. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_handle_destroy(semanage_handle_t *);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* This is the type of connection to the store, for now only
|
|
|
|
* direct is supported */
|
|
|
|
enum semanage_connect_type {
|
|
|
|
SEMANAGE_CON_INVALID = 0, SEMANAGE_CON_DIRECT,
|
|
|
|
SEMANAGE_CON_POLSERV_LOCAL, SEMANAGE_CON_POLSERV_REMOTE
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This function allows you to specify the store to connect to.
|
|
|
|
* It must be called after semanage_handle_create but before
|
|
|
|
* semanage_connect. The argument should be the full path to the store.
|
|
|
|
*/
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_select_store(semanage_handle_t * handle, char *path,
|
|
|
|
enum semanage_connect_type storetype);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* Just reload the policy */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_reload_policy(semanage_handle_t * handle);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* set whether to reload the policy or not after a commit,
|
|
|
|
* 1 for yes (default), 0 for no */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_reload(semanage_handle_t * handle, int do_reload);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* set whether to rebuild the policy on commit, even if no
|
|
|
|
* changes were performed.
|
|
|
|
* 1 for yes, 0 for no (default) */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_rebuild(semanage_handle_t * handle, int do_rebuild);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2014-02-07 16:15:40 +00:00
|
|
|
/* Fills *compiler_path with the location of the hll compiler sh->conf->compiler_directory_path
|
|
|
|
* corresponding to lang_ext.
|
|
|
|
* Upon success returns 0, -1 on error. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_get_hll_compiler_path(semanage_handle_t *sh, char *lang_ext, char **compiler_path);
|
2014-02-07 16:15:40 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
/* create the store if it does not exist, this only has an effect on
|
|
|
|
* direct connections and must be called before semanage_connect
|
|
|
|
* 1 for yes, 0 for no (default) */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_create_store(semanage_handle_t * handle, int create_store);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2009-07-07 17:32:48 +00:00
|
|
|
/*Get whether or not dontaudits will be disabled upon commit */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_get_disable_dontaudit(semanage_handle_t * handle);
|
2009-07-07 17:32:48 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
/* Set whether or not to disable dontaudits upon commit */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_disable_dontaudit(semanage_handle_t * handle, int disable_dontaudit);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2009-10-21 15:37:51 +00:00
|
|
|
/* Set whether or not to execute setfiles to check file contexts upon commit */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_check_contexts(semanage_handle_t * sh, int do_check_contexts);
|
2009-10-21 15:37:51 +00:00
|
|
|
|
libsemanage: add functions to public api
include/semanage/handle.h
* Exports the handle get/set default priority functions.
include/semanage/module.h
* Exports the module info management functions.
* Exports the get/set enabled status functions.
* Exports the module key management functions.
* Exports the module install, upgrade, remove info/key functions.
include/semanage/semanage.h
This patch includes the modifications to the map file for exporting the
necessary functions.
Examples:
/* changing the default priority for a distro install */
semanage_set_default_priority(sh, 100);
/* creating module meta data */
semanage_module_info_t *modinfo = NULL;
semanage_module_info_create(sh, &modinfo);
/* filling in that data */
semanage_module_info_set_priority(
sh,
modinfo,
semanage_get_default_priority(sh));
semanage_module_info_set_name(
sh,
modinfo,
"mymodule");
semanage_module_info_set_version(
sh,
modinfo,
"0.1.2");
semanage_module_info_set_lang_ext(
sh,
modinfo,
"pp");
semanage_module_info_set_enabled(
sh,
modinfo,
-1); /* Sets enabled to default:
* If the module was already enabled/disabled
* then it will remain so after install.
* If it wasn't, then it will be enabled.
*/
/* install the module */
semanage_module_install_info(sh, modinfo, data, data_len);
/* cleanup modinfo */
semanage_module_info_destroy(sh, modinfo);
/* create a key for retrieving a module's meta data */
semanage_module_key_t *modkey = NULL;
semanage_module_key_create(sh, &modkey);
/* Only set the module name, this will find the highest
* priority module of that name.
*/
semanage_module_key_set_name(sh, modkey, "mymodule");
/* get the newly installed module */
semanage_module_get_module_info(sh, modkey, &modinfo);
/* get the priority of the module found */
uint16_t priority = 0;
semanage_module_info_get_priority(sh, modinfo, &priority);
/* set the priority in the key to the one found */
semanage_module_key_set_priority(sh, modkey, priority);
/* remove the highest priority module with the name "mymodule" */
semanage_module_remove_key(sh, modkey);
/* print all the modules installed */
semanage_module_info_t *modinfos = NULL;
int modinfos_len = 0;
semanage_module_list_all(sh, &modinfos, &modinfos_len);
char *name = NULL;
int i = 0;
for (i = 0; i < modinfos_len; i++) {
semanage_module_info_get_priority(
sh,
semanage_module_list_nth(modinfos, i),
&priority);
semanage_module_info_get_name(
sh,
semanage_module_list_nth(modinfos, i),
&name);
printf("%d\t%s\n", priority, name);
}
Signed-off-by: Chad Sellers <csellers@tresys.com>
2009-12-23 23:25:58 +00:00
|
|
|
/* Get the default priority. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern uint16_t semanage_get_default_priority(semanage_handle_t *sh);
|
libsemanage: add functions to public api
include/semanage/handle.h
* Exports the handle get/set default priority functions.
include/semanage/module.h
* Exports the module info management functions.
* Exports the get/set enabled status functions.
* Exports the module key management functions.
* Exports the module install, upgrade, remove info/key functions.
include/semanage/semanage.h
This patch includes the modifications to the map file for exporting the
necessary functions.
Examples:
/* changing the default priority for a distro install */
semanage_set_default_priority(sh, 100);
/* creating module meta data */
semanage_module_info_t *modinfo = NULL;
semanage_module_info_create(sh, &modinfo);
/* filling in that data */
semanage_module_info_set_priority(
sh,
modinfo,
semanage_get_default_priority(sh));
semanage_module_info_set_name(
sh,
modinfo,
"mymodule");
semanage_module_info_set_version(
sh,
modinfo,
"0.1.2");
semanage_module_info_set_lang_ext(
sh,
modinfo,
"pp");
semanage_module_info_set_enabled(
sh,
modinfo,
-1); /* Sets enabled to default:
* If the module was already enabled/disabled
* then it will remain so after install.
* If it wasn't, then it will be enabled.
*/
/* install the module */
semanage_module_install_info(sh, modinfo, data, data_len);
/* cleanup modinfo */
semanage_module_info_destroy(sh, modinfo);
/* create a key for retrieving a module's meta data */
semanage_module_key_t *modkey = NULL;
semanage_module_key_create(sh, &modkey);
/* Only set the module name, this will find the highest
* priority module of that name.
*/
semanage_module_key_set_name(sh, modkey, "mymodule");
/* get the newly installed module */
semanage_module_get_module_info(sh, modkey, &modinfo);
/* get the priority of the module found */
uint16_t priority = 0;
semanage_module_info_get_priority(sh, modinfo, &priority);
/* set the priority in the key to the one found */
semanage_module_key_set_priority(sh, modkey, priority);
/* remove the highest priority module with the name "mymodule" */
semanage_module_remove_key(sh, modkey);
/* print all the modules installed */
semanage_module_info_t *modinfos = NULL;
int modinfos_len = 0;
semanage_module_list_all(sh, &modinfos, &modinfos_len);
char *name = NULL;
int i = 0;
for (i = 0; i < modinfos_len; i++) {
semanage_module_info_get_priority(
sh,
semanage_module_list_nth(modinfos, i),
&priority);
semanage_module_info_get_name(
sh,
semanage_module_list_nth(modinfos, i),
&name);
printf("%d\t%s\n", priority, name);
}
Signed-off-by: Chad Sellers <csellers@tresys.com>
2009-12-23 23:25:58 +00:00
|
|
|
|
|
|
|
/* Set the default priority. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_set_default_priority(semanage_handle_t *sh, uint16_t priority);
|
libsemanage: add functions to public api
include/semanage/handle.h
* Exports the handle get/set default priority functions.
include/semanage/module.h
* Exports the module info management functions.
* Exports the get/set enabled status functions.
* Exports the module key management functions.
* Exports the module install, upgrade, remove info/key functions.
include/semanage/semanage.h
This patch includes the modifications to the map file for exporting the
necessary functions.
Examples:
/* changing the default priority for a distro install */
semanage_set_default_priority(sh, 100);
/* creating module meta data */
semanage_module_info_t *modinfo = NULL;
semanage_module_info_create(sh, &modinfo);
/* filling in that data */
semanage_module_info_set_priority(
sh,
modinfo,
semanage_get_default_priority(sh));
semanage_module_info_set_name(
sh,
modinfo,
"mymodule");
semanage_module_info_set_version(
sh,
modinfo,
"0.1.2");
semanage_module_info_set_lang_ext(
sh,
modinfo,
"pp");
semanage_module_info_set_enabled(
sh,
modinfo,
-1); /* Sets enabled to default:
* If the module was already enabled/disabled
* then it will remain so after install.
* If it wasn't, then it will be enabled.
*/
/* install the module */
semanage_module_install_info(sh, modinfo, data, data_len);
/* cleanup modinfo */
semanage_module_info_destroy(sh, modinfo);
/* create a key for retrieving a module's meta data */
semanage_module_key_t *modkey = NULL;
semanage_module_key_create(sh, &modkey);
/* Only set the module name, this will find the highest
* priority module of that name.
*/
semanage_module_key_set_name(sh, modkey, "mymodule");
/* get the newly installed module */
semanage_module_get_module_info(sh, modkey, &modinfo);
/* get the priority of the module found */
uint16_t priority = 0;
semanage_module_info_get_priority(sh, modinfo, &priority);
/* set the priority in the key to the one found */
semanage_module_key_set_priority(sh, modkey, priority);
/* remove the highest priority module with the name "mymodule" */
semanage_module_remove_key(sh, modkey);
/* print all the modules installed */
semanage_module_info_t *modinfos = NULL;
int modinfos_len = 0;
semanage_module_list_all(sh, &modinfos, &modinfos_len);
char *name = NULL;
int i = 0;
for (i = 0; i < modinfos_len; i++) {
semanage_module_info_get_priority(
sh,
semanage_module_list_nth(modinfos, i),
&priority);
semanage_module_info_get_name(
sh,
semanage_module_list_nth(modinfos, i),
&name);
printf("%d\t%s\n", priority, name);
}
Signed-off-by: Chad Sellers <csellers@tresys.com>
2009-12-23 23:25:58 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
/* Check whether policy is managed via libsemanage on this system.
|
|
|
|
* Must be called prior to trying to connect.
|
|
|
|
* Return 1 if policy is managed via libsemanage on this system,
|
|
|
|
* 0 if policy is not managed, or -1 on error.
|
|
|
|
*/
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_is_managed(semanage_handle_t *);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* "Connect" to a manager based on the configuration and
|
|
|
|
* associate the provided handle with the connection.
|
|
|
|
* If the connect fails then this function returns a negative value,
|
|
|
|
* else it returns zero.
|
|
|
|
*/
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_connect(semanage_handle_t *);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* Disconnect from the manager given by the handle. If already
|
|
|
|
* disconnected then this function does nothing. Return 0 if
|
|
|
|
* disconnected properly or already disconnected, negative value on
|
|
|
|
* error. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_disconnect(semanage_handle_t *);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* Attempt to obtain a transaction lock on the manager. If another
|
|
|
|
* process has the lock then this function may block, depending upon
|
|
|
|
* the timeout value in the handle.
|
|
|
|
*
|
|
|
|
* Note that if the semanage_handle has not yet obtained a transaction
|
|
|
|
* lock whenever a writer function is called, there will be an
|
|
|
|
* implicit call to this function. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_begin_transaction(semanage_handle_t *);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* Attempt to commit all changes since this transaction began. If the
|
|
|
|
* commit is successful then increment the "policy sequence number"
|
|
|
|
* and then release the transaction lock. Return that policy number
|
|
|
|
* afterwards, or -1 on error.
|
|
|
|
*/
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_commit(semanage_handle_t *);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
#define SEMANAGE_CAN_READ 1
|
|
|
|
#define SEMANAGE_CAN_WRITE 2
|
|
|
|
/* returns SEMANAGE_CAN_READ or SEMANAGE_CAN_WRITE if the store is readable
|
2016-05-01 18:18:03 +00:00
|
|
|
* or writable, respectively. <0 if an error occurred */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_access_check(semanage_handle_t * sh);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
/* returns 0 if not connected, 1 if connected */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_is_connected(semanage_handle_t * sh);
|
2008-08-19 19:30:36 +00:00
|
|
|
|
2008-11-10 20:32:56 +00:00
|
|
|
/* returns 1 if policy is MLS, 0 otherwise. */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_mls_enabled(semanage_handle_t *sh);
|
2008-11-10 20:32:56 +00:00
|
|
|
|
2011-11-22 18:35:29 +00:00
|
|
|
/* Change to alternate semanage root path */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_set_root(const char *path);
|
2011-11-22 18:35:29 +00:00
|
|
|
|
|
|
|
/* Get the current semanage root path */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern const char * semanage_root(void);
|
2011-11-22 18:35:29 +00:00
|
|
|
|
2011-09-01 03:29:46 +00:00
|
|
|
/* Get whether or not needless unused branch of tunables would be preserved */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_get_preserve_tunables(semanage_handle_t * handle);
|
2011-09-01 03:29:46 +00:00
|
|
|
|
|
|
|
/* Set whether or not to preserve the needless unused branch of tunables */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_preserve_tunables(semanage_handle_t * handle, int preserve_tunables);
|
2011-09-01 03:29:46 +00:00
|
|
|
|
2014-02-07 16:15:40 +00:00
|
|
|
/* Get the flag value for whether or not caching is ignored for compiled CIL modules from HLL files */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern int semanage_get_ignore_module_cache(semanage_handle_t *handle);
|
2014-02-07 16:15:40 +00:00
|
|
|
|
|
|
|
/* Set semanage_handle flag for whether or not to ignore caching of compiled CIL modules from HLL files */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_ignore_module_cache(semanage_handle_t *handle, int ignore_module_cache);
|
2014-02-07 16:15:40 +00:00
|
|
|
|
2014-04-03 20:39:41 +00:00
|
|
|
/* set the store root path for semanage output files */
|
2019-10-13 10:52:16 +00:00
|
|
|
extern void semanage_set_store_root(semanage_handle_t *sh, const char *store_root);
|
2014-04-03 20:39:41 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
/* META NOTES
|
|
|
|
*
|
|
|
|
* For all functions a non-negative number indicates success. For some
|
|
|
|
* functions a >=0 returned value is the "policy sequence number". This
|
|
|
|
* number keeps tracks of policy revisions and is used to detect if
|
|
|
|
* one semanage client has committed policy changes while another is
|
|
|
|
* still connected.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif
|