This is a patch to allow libsemanage to handle an alternate root.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
What I want to add is the ability to do
semodule -n -B -p /tmp/BUILDROOT/
And have semodule build policy in
/tmp/BUILDROOT/etc/selinux/...
Basically this patch adds a new interface
semanage_set_root(char *path)
semanage_set_root("/tmp/BUILDROOT")
Which sets the alternate root.
All selinux_* calls are then replaced with matching semanage_* calls that will prepent the rootpath if it exists to the selinux_* values.
If the semanage_set_root() is never called, the selinux_* values will continue to be used.
We will be using this functionality so that we can build an entire install tree within our spec file and will no longer need to run semodule ... on initial installs or "unmodified" machines.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAk3nuaIACgkQrlYvE4MpobMtFwCdFrKV1bSEBlM6j3RzAkOzTbPJ HCwAoL+ZK8il8Ck7zeW7U/wP+jzaFeJ9
=wzzM
-----END PGP SIGNATURE-----
libsemanage/include/semanage/handle.h +3 -0
@@ -126,6 +126,9 @@ int semanage_is_connected(semanage_handle_t * sh);/* returns 1 if policy is MLS, 0 otherwise. */ int semanage_mls_enabled (semanage_handle_t *sh); +/* Change to alternate selinux root path */ +int semanage_set_root (const char *path); +/* META NOTES * * For all functions a non-negative number indicates success. For some
libsemanage/man/man3/semanage_set_root.3 new file +22 -0
@@ -0,0 +1,22 @@ +.TH semanage_set_root 3 "1 June 2011" "[email protected]" "Libsemanage API documentation" + +.SH "NAME" +semanage_set_root \- SELinux Management API + +.SH "SYNOPSIS" +Set the alternate root directory for SELinux configuration directory. + +.B #include <semanage/handle.h> + +.B extern const char *semanage_set_root(const char *path); + +.SH "DESCRIPTION" +.TP +This function sets an alternate root directory to for SELinux configuration paths to be used by the semanage library. + +.SH "RETURN VALUE" +In case of failure, -1 is returned. +Otherwise 0 is returned. + +.SH "SEE ALSO" +.BR semanage_handle_create "(3), " semanage_connect "(3), "
libsemanage/src/conf-parse.y +3 -2
@@ -21,6 +21,7 @@ %{ #include "semanage_conf.h" +#include "handle.h" #include <sepol/policydb.h> #include <selinux/selinux.h>
@@ -260,7 +261,7 @@ external_opt: PROG_PATH '=' ARG { PASSIGN(new_external->path, $3); } static int semanage_conf_init(semanage_conf_t * conf) { conf->store_type = SEMANAGE_CON_DIRECT; - conf->store_path = strdup(basename(selinux_policy_root())); + conf->store_path = strdup(basename(semanage_policy_root())); conf->policyvers = sepol_policy_kern_vers_max(); conf->expand_check = 1; conf->handle_unknown = -1;
@@ -390,7 +391,7 @@ static int parse_module_store(char *arg) if (strcmp(arg, "direct") == 0) { current_conf->store_type = SEMANAGE_CON_DIRECT; current_conf->store_path = - strdup(basename(selinux_policy_root())); + strdup(basename(semanage_policy_root())); current_conf->server_port = -1; free(arg); } else if (*arg == '/') {
libsemanage/src/direct_api.c +3 -3
@@ -95,7 +95,7 @@ int semanage_direct_is_managed(semanage_handle_t * sh) {char polpath[PATH_MAX ]; -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), +snprintf (polpath,PATH_MAX ,"%s%s" ,semanage_selinux_path (), sh->conf->store_path);if (semanage_check_init (polpath))
@@ -118,7 +118,7 @@ int semanage_direct_connect(semanage_handle_t * sh)char polpath[PATH_MAX ];const char *path; -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), +snprintf (polpath,PATH_MAX ,"%s%s" ,semanage_selinux_path (), sh->conf->store_path);if (semanage_check_init (polpath))
@@ -1539,7 +1539,7 @@ int semanage_direct_access_check(semanage_handle_t * sh) {char polpath[PATH_MAX ]; -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), +snprintf (polpath,PATH_MAX ,"%s%s" ,semanage_selinux_path (), sh->conf->store_path);if (semanage_check_init (polpath))
libsemanage/src/handle.c +133 -0
139 lines not on this page · raw message
libsemanage/src/handle_internal.h +14 -3
@@ -5,7 +5,18 @@#include "dso.h" hidden_proto(semanage_begin_transaction) - hidden_proto(semanage_handle_destroy) - hidden_proto(semanage_reload_policy) - hidden_proto(semanage_access_check) +hidden_proto(semanage_handle_destroy) +hidden_proto(semanage_reload_policy) +hidden_proto(semanage_access_check) +hidden_proto(semanage_set_root) + +extern const char *semanage_selinux_path(void); +extern const char *semanage_file_context_path(); +extern const char *semanage_file_context_local_path(); +extern const char *semanage_file_context_homedir_path(); +extern const char *semanage_homedir_context_path(); +extern const char *semanage_binary_policy_path(); +extern const char *semanage_usersconf_path(); +extern const char *semanage_netfilter_context_path(); +extern const char *semanage_policy_root();#endif
libsemanage/src/libsemanage.map +1 -0
@@ -14,6 +14,7 @@ LIBSEMANAGE_1.0 { semanage_module_get_version; semanage_select_store; semanage_module_get_enabled; semanage_reload_policy; semanage_set_reload; semanage_set_rebuild; + semanage_set_root; semanage_user_*; semanage_bool_*; semanage_seuser_*; semanage_iface_*; semanage_port_*; semanage_context_*; semanage_node_*;
libsemanage/src/semanage_store.c +13 -13
@@ -90,7 +90,7 @@ static const char *semanage_store_paths[SEMANAGE_NUM_STORES] = { "/tmp" }; -/* this is the module store path relative to selinux_policy_root() */ +/* this is the module store path relative to semanage_policy_root() */ #define SEMANAGE_MOD_DIR "/modules"/* relative path names to enum sandbox_paths for special files within * a sandbox */
@@ -170,11 +170,11 @@ static int semanage_init_paths(const char *root) semanage_relative_files[i]); } - len =strlen (selinux_path ()) +strlen (SEMANAGE_CONF_FILE ); + len =strlen (semanage_selinux_path ()) +strlen (SEMANAGE_CONF_FILE ); semanage_conf =calloc (len +1 ,sizeof (char ));if (!semanage_conf)return -1 ; -snprintf (semanage_conf, len,"%s%s" ,selinux_path (), +snprintf (semanage_conf, len,"%s%s" ,semanage_selinux_path (),SEMANAGE_CONF_FILE );return 0 ;
@@ -1071,14 +1071,14 @@ static int semanage_install_active(semanage_handle_t * sh)const char *active_fc_hd =semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_FC_HOMEDIRS ); -const char *running_fc =selinux_file_context_path (); -const char *running_fc_loc =selinux_file_context_local_path (); -const char *running_fc_hd =selinux_file_context_homedir_path (); -const char *running_hd =selinux_homedir_context_path (); -const char *running_policy =selinux_binary_policy_path (); -const char *running_seusers =selinux_usersconf_path (); -const char *running_nc =selinux_netfilter_context_path (); -const char *really_active_store =selinux_policy_root (); +const char *running_fc =semanage_file_context_path (); +const char *running_fc_loc =semanage_file_context_local_path (); +const char *running_fc_hd =semanage_file_context_homedir_path (); +const char *running_hd =semanage_homedir_context_path (); +const char *running_policy =semanage_binary_policy_path (); +const char *running_seusers =semanage_usersconf_path (); +const char *running_nc =semanage_netfilter_context_path (); +const char *really_active_store =semanage_policy_root ();/* This is very unelegant, the right thing to do is export the path * building code in libselinux so that you can get paths for a given
@@ -1099,11 +1099,11 @@ static int semanage_install_active(semanage_handle_t * sh) running_seusers += len; running_nc += len; - len =strlen (selinux_path ()) +strlen (sh->conf->store_path) +1 ; + len =strlen (semanage_selinux_path ()) +strlen (sh->conf->store_path) +1 ; storepath = (char *)malloc (len);if (!storepath) goto cleanup; -snprintf (storepath,PATH_MAX ,"%s%s" ,selinux_path (), +snprintf (storepath,PATH_MAX ,"%s%s" ,semanage_selinux_path (), sh->conf->store_path); snprintf(store_pol, PATH_MAX, "%s%s.%d", storepath,
strncpy(buff, methods[i].ml_doc, ldoc);
buff += ldoc;
strncpy(buff, "swig_ptr: ", 10);