RFC libsemanage move to var, enable/disable module, and priority support
cover RFC libsemanage move to var, enable/disable module, and priority support
Our motivations for this patchset are to:
* Move the semanage store - the portion of the SELinux configuration managed by libsemanage - to a more appropriate location in the filesystem. The current location - in /etc - is designated for administrator controlled configuration and is sometimes mounted read-only. By storing binary, program managed data in /etc libsemanage breaks administrator expectations.
* Enable the overriding of modules in the module store without require the original modules to removed or modified. This allows administrators to customize the policy more fully while allowing the distribution provided policies to be left unmodified and continue to be updated by the package manager.
* Provide the ability for an administrator to disable a module without removing or overriding that module.
[Move to /var/lib/selinux]
Move the libsemanage private store
from /etc/selinux/<policy type>/modules
to /var/lib/selinux/<policy type>
The benefits of this are:
* Permits the use of a read-only /etc.
* Conforms to the Filesystem Hierarchy Standard.
An additional change in layout structure moves the temporary space for the active policy to an external temporary space. This has the benefit of permitting source control management to be used on the private policy.
[Module Priorities]
Module priorities modify libsemanage and the module store to allow multiple modules with the same name to exist with different priorities. Only the highest priority module is used to create the final system policy. The addition of module priorities enables the modification of the system policy without modifying individual modules. For example, it allows an administrator to add his own policy module for apache, completely replacing the distribution provided module, without changing or removing the distribution policy. This has several benefits:
* Distribution provided policy package updates proceed normally - the distribution policy is inserted but the administrator provided policy remains active.
* Multiple levels allows distributors, 3rd party applications, system management tools (e.g., puppet), and local administrators to all make changes without conflicting.
* Semanage modifications of policy (e.g., port labeling) will be able to use high priority modules in the future to override defaults (requires the CIL[1] language changes).
[Enable/Disable Modules]
Modules gain an enabled / disabled status. Enabled modules are used by semanage when building the active policy, and disabled modules are ignored. The main benefit of this is that modules can be disabled without out removing them from the store.
[Patchset Breakdown]
The patchset is broken down as follows:
Bug fixes:
libsemanage: fix type in tests makefile -o -> -O
Move the libsemanage store to /var/lib/selinux:
semanage: move permissive module creation to /tmp
libsemanage: move the module store to /var/lib/selinux
libsemanage: split final files into /var/lib/selinux/tmp
libsemanage: update unit tests for move to /var/lib/selinux
Implement support for the new libsemanage store layout:
libsemanage: add default priority to semanage_handle_t
libsemanage: augment semanage_module_info_t and provide semanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and key
Provide private headers for upstream tools to use:
libsemanage: new private api for unstable functions
Extend semodule to support enable/disable, priorities, and detailed listings:
semodule: add priority, enabled, and extended listing
Migration script for moving the libsemanage store:
semanage store migration script
Thanks for you feedback!
Caleb
[1] CIL RFC: http://marc.info/?l=selinux&m=124759244409438&w=2
Caleb Case (13):
libsemanage: fix typo in tests makefile -o -> -O
semanage: move permissive module creation to /tmp
libsemanage: move the module store to /var/lib/selinux
libsemanage: split final files into /var/lib/selinux/tmp
libsemanage: update unit tests for move to /var/lib/selinux
libsemanage: add default priority to semanage_handle_t
libsemanage: augment semanage_module_info_t and provide
semanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and key
libsemanage: new private api for unstable functions
semodule: add priority, enabled, and extended listing semanage store migration script
libsemanage/include/Makefile | 3 + libsemanage/include/semanage/private/handle.h | 31 + libsemanage/include/semanage/private/modules.h | 281 ++++ libsemanage/include/semanage/private/semanage.h | 26 + libsemanage/src/boolean_internal.h | 4 +- libsemanage/src/booleans_file.c | 7 +- libsemanage/src/booleans_policydb.c | 6 +- libsemanage/src/database_file.c | 45 +- libsemanage/src/database_file.h | 3 +- libsemanage/src/database_policydb.c | 37 +- libsemanage/src/database_policydb.h | 3 +- libsemanage/src/direct_api.c | 1652 +++++++++++++++++++--- libsemanage/src/fcontext_internal.h | 3 +- libsemanage/src/fcontexts_file.c | 7 +- libsemanage/src/genhomedircon.c | 3 +- libsemanage/src/handle.c | 23 + libsemanage/src/handle.h | 3 + libsemanage/src/handle_internal.h | 1 + libsemanage/src/iface_internal.h | 4 +- libsemanage/src/interfaces_file.c | 7 +- libsemanage/src/interfaces_policydb.c | 6 +- libsemanage/src/libsemanage.map | 26 + libsemanage/src/module_internal.h | 21 + libsemanage/src/modules.c | 999 +++++++++++++- libsemanage/src/modules.h | 76 +- libsemanage/src/node_internal.h | 4 +- libsemanage/src/nodes_file.c | 7 +- libsemanage/src/nodes_policydb.c | 6 +- libsemanage/src/policy.h | 36 + libsemanage/src/port_internal.h | 4 +- libsemanage/src/ports_file.c | 7 +- libsemanage/src/ports_policydb.c | 6 +- libsemanage/src/semanage_store.c | 794 ++++++++--- libsemanage/src/semanage_store.h | 47 +- libsemanage/src/seuser_internal.h | 4 +- libsemanage/src/seusers_file.c | 7 +- libsemanage/src/user_internal.h | 6 +- libsemanage/src/users_base_file.c | 7 +- libsemanage/src/users_base_policydb.c | 6 +- libsemanage/src/users_extra_file.c | 7 +- libsemanage/tests/Makefile | 2 +- libsemanage/tests/test_semanage_store.c | 34 +- libsemanage/utils/semanage_migrate_etc_to_var.py | 301 ++++ policycoreutils/semanage/seobject.py | 15 +- policycoreutils/semodule/semodule.8 | 25 +- policycoreutils/semodule/semodule.c | 242 +++- 46 files changed, 4267 insertions(+), 577 deletions(-) create mode 100644 libsemanage/include/semanage/private/handle.h create mode 100644 libsemanage/include/semanage/private/modules.h create mode 100644 libsemanage/include/semanage/private/semanage.h create mode 100755 libsemanage/utils/semanage_migrate_etc_to_var.py
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/13 libsemanage: fix typo in tests makefile -o -> -O
Fixed typo in the tests Makefile where '-o' should have been '-O'.
--- libsemanage/tests/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
libsemanage/tests/Makefile +1 -1
@@ -11,7 +11,7 @@ LIBS = ../src/libsemanage.a ../../libselinux/src/libselinux.a ../../libsepol/src EXECUTABLE = libsemanage-tests CC = gcc -CFLAGS = -c -g -o0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter +CFLAGS = -c -g -O0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter INCLUDE = -I$(TESTSRC) -I$(TESTSRC)/../include LDFLAGS = -lcunit -lustr -lbz2 OBJECTS = $(SOURCES:.c=.o)
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/13 semanage: move permissive module creation to /tmp
semanage currently uses /var/lib/selinux/tmp to create permissive modules. However, with the move to /var, the same tmp directory is used for building policy binaries, causing a conflict. This patch creates a random temporary directory in /tmp and moves permissive module creation to that directory, avoiding the directory conflict.
This patch also imports shutil for rmtree to easily delete all created temporary files.
--- policycoreutils/semanage/seobject.py | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-)
policycoreutils/semanage/seobject.py +5 -10
@@ -21,7 +21,7 @@ # # -import pwd, grp, string, selinux, tempfile, os, re, sys, stat +import pwd, grp, string, selinux, tempfile, os, re, sys, stat, shutil from semanage import *; PROGNAME = "policycoreutils" import sepolgen.module as module
@@ -271,7 +271,8 @@ class permissiveRecords(semanageRecords): def add(self, type): import glob name = "permissive_%s" % type - dirname = "/var/lib/selinux" + dirname = tempfile.mkdtemp("-semanage") + savedir = os.getcwd() os.chdir(dirname) filename = "%s.te" % name modtxt = """
@@ -296,14 +297,8 @@ permissive %s; if rc >= 0: self.commit() - for root, dirs, files in os.walk("tmp", topdown = False): - for name in files: - os.remove(os.path.join(root, name)) - for name in dirs: - os.rmdir(os.path.join(root, name)) - os.removedirs("tmp") - for i in glob.glob("permissive_%s.*" % type): - os.remove(i) + os.chdir(savedir) + shutil.rmtree(dirname) if rc < 0: raise ValueError(_("Could not set permissive domain %s (module installation failed)") % name)
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 3/13 libsemanage: move the module store to /var/lib/selinux
This patch moves the module store from /etc/selinux/<store>/modules to /var/lib/selinux/<store>.
This move will allow for the use of a read-only /etc/selinux. Currently that is not possible with semanage because of the lock files.
A consequence of this move is that packagers of libsemanage should create the /var/lib/selinux directory.
--- libsemanage/src/direct_api.c | 20 ++---------------- libsemanage/src/semanage_store.c | 39 ++++++++++++++++++++++++------------- libsemanage/src/semanage_store.h | 5 +++- 3 files changed, 32 insertions(+), 32 deletions(-)
libsemanage/src/direct_api.c +3 -17
@@ -89,12 +89,7 @@ static struct semanage_policy_table direct_funcs = {int semanage_direct_is_managed (semanage_handle_t * sh) { -char polpath[PATH_MAX ]; - -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ())) goto err;if (semanage_access_check (sh) <0 )
@@ -111,13 +106,9 @@ int semanage_direct_is_managed(semanage_handle_t * sh)*/ int semanage_direct_connect (semanage_handle_t * sh) { -char polpath[PATH_MAX ];const char *path; -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ())) goto err;if (sh->create_store)
@@ -1416,12 +1407,7 @@ static int semanage_direct_list(semanage_handle_t * sh,int semanage_direct_access_check (semanage_handle_t * sh) { -char polpath[PATH_MAX ]; - -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ()))return -1 ;return semanage_store_access_check (sh);
libsemanage/src/semanage_store.c +25 -14
@@ -3,8 +3,9 @@* Jason Tang <[email protected]> * Christopher Ashworth <[email protected]> * Chris PeBenito <[email protected]> +* Caleb Case <[email protected]> * -* Copyright (C) 2004-2006 Tresys Technology, LLC +* Copyright (C) 2004-2006,2009 Tresys Technology, LLC * Copyright (C) 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or
@@ -88,8 +89,6 @@ static const char *semanage_store_paths[SEMANAGE_NUM_STORES] = {"/tmp" }; -/* this is the module store path relative to selinux_policy_root() */ -#define SEMANAGE_MOD_DIR "/modules"/* relative path names to enum sandbox_paths for special files within * a sandbox */ static const char *semanage_sandbox_paths[SEMANAGE_STORE_NUM_PATHS ] = {
@@ -157,14 +156,14 @@ static int semanage_init_paths(const char *root)if (!root)return -1 ; - prefix_len = (strlen (root) +strlen (SEMANAGE_MOD_DIR )); + prefix_len =strlen (root);for (i =0 ; i <SEMANAGE_NUM_FILES ; i++) { len = (strlen (semanage_relative_files[i]) + prefix_len); semanage_files[i] =calloc (len +1 ,sizeof (char ));if (!semanage_files[i])return -1 ; -sprintf (semanage_files[i],"%s%s%s" , root,SEMANAGE_MOD_DIR , +sprintf (semanage_files[i],"%s%s" , root, semanage_relative_files[i]); }
@@ -186,16 +185,11 @@ static int semanage_init_store_paths(const char *root)int i, j;size_t len;size_t prefix_len; -char *prefix;if (!root)return -1 ; - prefix_len = (strlen (root) +strlen (SEMANAGE_MOD_DIR )); - prefix =calloc (prefix_len +1 ,sizeof (char )); -if (!prefix) -return -1 ; -sprintf (prefix,"%s%s" , root,SEMANAGE_MOD_DIR ); + prefix_len =strlen (root);for (i =0 ; i <SEMANAGE_NUM_STORES ; i++) {for (j =0 ; j <SEMANAGE_STORE_NUM_PATHS ; j++) {
@@ -204,14 +198,13 @@ static int semanage_init_store_paths(const char *root) semanage_paths[i][j] =calloc (len +1 ,sizeof (char ));if (!semanage_paths[i][j]) goto cleanup; -sprintf (semanage_paths[i][j],"%s%s%s" , prefix, +sprintf (semanage_paths[i][j],"%s%s%s" , root, semanage_store_paths[i], semanage_sandbox_paths[j]); } } cleanup: -free (prefix);return 0 ; }
@@ -223,16 +216,28 @@ static int semanage_init_store_paths(const char *root)* * Note that this function is NOT thread-safe. */ -int semanage_check_init (const char *root) +int semanage_check_init (semanage_handle_t *sh,const char *prefix) {int rc;if (semanage_paths_initialized ==0 ) { +char root[PATH_MAX ]; + + rc =snprintf (root, +sizeof (root), +"%s/%s" , + prefix, + sh->conf->store_path); +if (rc <0 || rc >= (int )sizeof (root)) +return -1 ; + rc =semanage_init_paths (root);if (rc)return rc; + rc =semanage_init_store_paths (root);if (rc)return rc; + semanage_paths_initialized =1 ; }return 0 ;
@@ -259,6 +264,12 @@ const char *semanage_path(enum semanage_store_defs store,return semanage_paths[store][path_name]; } +/* Return the root of the semanage store. */ +const char *semanage_root_path (void ) +{ +return "/var/lib/selinux" ; +} +/* Return a fully-qualified path + filename to the semanage * configuration file. The caller must not alter the string returned * (and hence why this function return type is const).
libsemanage/src/semanage_store.h +4 -1
@@ -62,11 +62,14 @@ enum semanage_sandbox_defs { SEMANAGE_STORE_NUM_PATHS }; +const char *semanage_root_path (void ); +/* FIXME: this needs to be made a module store specific init and the * global configuration moved to another file. */ const char *semanage_conf_path (void ); -int semanage_check_init (const char *root); + +int semanage_check_init (semanage_handle_t *sh,const char *prefix);extern const char *semanage_fname (enum semanage_sandbox_defs file_enum);
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 4/13 libsemanage: split final files into /var/lib/selinux/tmp
This patch moves the final files from inside /var/lib/selinux/<store>/[active|previous|tmp] to /var/lib/selinux/tmp/<store>. The move is done to facilitate using source control management on the /var/lib/selinux/<store> directory. If these files remain in /var/lib/selinux/<store> they will pose a size problem if an SCM like git is used as we'd be storing lots of binary diffs. We are suggesting making this change now, rather than later when source policy, SCM, and CIL[1] support are available, to ease the migration burden.
These are the files that have been moved:
/var/lib/selinux/<store>/active/... /var/lib/selinux/tmp/<store>/...
file_contexts contexts/files/file_contexts
file_contexts.homedirs contexts/files/file_contexts.homedirs
file_contexts.local contexts/files/file_contexts.localnetfilter_contexts contexts/netfilter_contexts
policy.kern policy/policy.<policyversion>
seusers.final seusers
The layout of these files in /var/lib/selinux/tmp/<store> is designed to mirror their locations in /etc/selinux/<store>. This should help clarify the relationship between these final files and the files installed in etc.
One consequence of this move is that reverting to the previous policy version requires a policy rebuild. Currently you can revert without rebuilding.
[1] CIL RFC: http://marc.info/?l=selinux&m=124759244409438&w=2
--- libsemanage/src/boolean_internal.h | 4 +- libsemanage/src/booleans_file.c | 7 +- libsemanage/src/booleans_policydb.c | 6 +- libsemanage/src/database_file.c | 45 +--- libsemanage/src/database_file.h | 3 +- libsemanage/src/database_policydb.c | 37 +-- libsemanage/src/database_policydb.h | 3 +- libsemanage/src/direct_api.c | 76 ++++- libsemanage/src/fcontext_internal.h | 3 +- libsemanage/src/fcontexts_file.c | 7 +- libsemanage/src/genhomedircon.c | 3 +- libsemanage/src/iface_internal.h | 4 +- libsemanage/src/interfaces_file.c | 7 +- libsemanage/src/interfaces_policydb.c | 6 +- libsemanage/src/node_internal.h | 4 +- libsemanage/src/nodes_file.c | 7 +- libsemanage/src/nodes_policydb.c | 6 +- libsemanage/src/port_internal.h | 4 +- libsemanage/src/ports_file.c | 7 +- libsemanage/src/ports_policydb.c | 6 +- libsemanage/src/semanage_store.c | 517 +++++++++++++++++++++++++-------- libsemanage/src/semanage_store.h | 31 ++- libsemanage/src/seuser_internal.h | 4 +- libsemanage/src/seusers_file.c | 7 +- libsemanage/src/user_internal.h | 6 +- libsemanage/src/users_base_file.c | 7 +- libsemanage/src/users_base_policydb.c | 6 +- libsemanage/src/users_extra_file.c | 7 +- 28 files changed, 585 insertions(+), 245 deletions(-)
libsemanage/src/boolean_internal.h +3 -1
@@ -25,7 +25,9 @@ hidden_proto(semanage_bool_clone)extern record_table_t SEMANAGE_BOOL_RTABLE ;extern int bool_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig); +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig);extern void bool_file_dbase_release (dbase_config_t * dconfig);
libsemanage/src/booleans_file.c +5 -2
@@ -107,11 +107,14 @@ record_file_table_t SEMANAGE_BOOL_FILE_RTABLE = { };int bool_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_BOOL_RTABLE , &SEMANAGE_BOOL_FILE_RTABLE , &dconfig->dbase) <0 )return STATUS_ERR ;
libsemanage/src/booleans_policydb.c +5 -1
@@ -33,6 +33,7 @@ typedef struct dbase_policydb dbase_t;#include "boolean_internal.h" #include "debug.h" #include "database_policydb.h" +#include "semanage_store.h" /* BOOLEAN RECRORD (SEPOL): POLICYDB extension: method table */ record_policydb_table_t SEMANAGE_BOOL_POLICYDB_RTABLE = {
@@ -54,7 +55,10 @@ int bool_policydb_dbase_init(semanage_handle_t * handle, {if (dbase_policydb_init (handle, -"policy.kern" , +semanage_final_path (SEMANAGE_FINAL_SELINUX , +SEMANAGE_KERNEL ), +semanage_final_path (SEMANAGE_FINAL_TMP , +SEMANAGE_KERNEL ), &SEMANAGE_BOOL_RTABLE , &SEMANAGE_BOOL_POLICYDB_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/database_file.c +10 -35
113 lines not on this page · raw message
libsemanage/src/database_file.h +2 -1
@@ -28,7 +28,8 @@ typedef struct record_file_table {/* FILE - initialization */ extern int dbase_file_init (semanage_handle_t * handle, -const char *suffix, +const char *path_ro, +const char *path_rw,record_table_t * rtable,record_file_table_t * rftable,dbase_file_t ** dbase);
libsemanage/src/database_policydb.c +8 -29
@@ -25,8 +25,8 @@ typedef struct dbase_policydb dbase_t;/* POLICYDB dbase */ struct dbase_policydb { -/* Backing file suffix */ -const char *suffix; +/* Backing path for read-only[0] and transaction[1] */ +const char *path[2 ];/* Base record table */ record_table_t *rtable;
@@ -86,26 +86,6 @@ static int dbase_policydb_needs_resync(semanage_handle_t * handle,return 0 ; } -static int construct_filename (semanage_handle_t * handle, -dbase_policydb_t * dbase,char **filename) -{ - -const char *path = (handle->is_in_transaction) ? -semanage_path (SEMANAGE_TMP ,SEMANAGE_TOPLEVEL ) : -semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_TOPLEVEL ); -size_t fname_length =strlen (path) +strlen (dbase->suffix) +2 ; - -char *fname =malloc (fname_length); -if (!fname) { -ERR (handle,"out of memory, could not construct database name" ); -return STATUS_ERR ; - } -snprintf (fname, fname_length,"%s/%s" , path, dbase->suffix); - - *filename = fname; -return STATUS_SUCCESS ; -} -static int dbase_policydb_cache (semanage_handle_t * handle,dbase_policydb_t * dbase) {
@@ -113,7 +93,7 @@ static int dbase_policydb_cache(semanage_handle_t * handle,FILE *fp =NULL ;sepol_policydb_t *policydb =NULL ;sepol_policy_file_t *pf =NULL ; -char *fname =NULL ; +const char *fname =NULL ;/* Check if cache is needed */ if (dbase->attached)
@@ -122,8 +102,7 @@ static int dbase_policydb_cache(semanage_handle_t * handle,if (!dbase_policydb_needs_resync (handle, dbase))return STATUS_SUCCESS ; -if (construct_filename (handle, dbase, &fname) <0 ) - goto err; + fname = dbase->path[handle->is_in_transaction];if (sepol_policydb_create (&policydb) <0 ) {ERR (handle,"could not create policydb object" );
@@ -164,7 +143,6 @@ static int dbase_policydb_cache(semanage_handle_t * handle,/* Update the database policydb */ dbase->policydb = policydb; -free (fname);return STATUS_SUCCESS ; err:
@@ -173,7 +151,6 @@ static int dbase_policydb_cache(semanage_handle_t * handle,fclose (fp);sepol_policydb_free (policydb);sepol_policy_file_free (pf); -free (fname);return STATUS_ERR ; }
@@ -199,7 +176,8 @@ static int dbase_policydb_is_modified(dbase_policydb_t * dbase) }int dbase_policydb_init (semanage_handle_t * handle, -const char *suffix, +const char *path_ro, +const char *path_rw,record_table_t * rtable,record_policydb_table_t * rptable,dbase_policydb_t ** dbase)
@@ -211,7 +189,8 @@ int dbase_policydb_init(semanage_handle_t * handle,if (!tmp_dbase) goto omem; - tmp_dbase->suffix = suffix; + tmp_dbase->path[0 ] = path_ro; + tmp_dbase->path[1 ] = path_rw; tmp_dbase->rtable = rtable; tmp_dbase->rptable = rptable; tmp_dbase->policydb =NULL ;
libsemanage/src/database_policydb.h +2 -1
@@ -86,7 +86,8 @@ typedef struct record_policydb_table {/* Initialize database */ extern int dbase_policydb_init (semanage_handle_t * handle, -const char *suffix, +const char *path_ro, +const char *path_rw,record_table_t * rtable,record_policydb_table_t * rptable,dbase_policydb_t ** dbase);
libsemanage/src/direct_api.c +62 -14
158 lines not on this page · raw message
libsemanage/src/fcontext_internal.h +2 -1
@@ -30,7 +30,8 @@ hidden_proto(semanage_fcontext_key_create)extern record_table_t SEMANAGE_FCONTEXT_RTABLE ;extern int fcontext_file_dbase_init (semanage_handle_t * handle, -const char *fname, +const char *path_ro, +const char *path_rw,dbase_config_t * dconfig);extern void fcontext_file_dbase_release (dbase_config_t * dconfig);
libsemanage/src/fcontexts_file.c +5 -2
@@ -165,11 +165,14 @@ record_file_table_t SEMANAGE_FCONTEXT_FILE_RTABLE = { };int fcontext_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_FCONTEXT_RTABLE , &SEMANAGE_FCONTEXT_FILE_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/genhomedircon.c +2 -1
@@ -964,7 +964,8 @@ int semanage_genhomedircon(semanage_handle_t * sh, s.homedir_template_path =semanage_path (SEMANAGE_TMP ,SEMANAGE_HOMEDIR_TMPL ); - s.fcfilepath =semanage_path (SEMANAGE_TMP ,SEMANAGE_FC_HOMEDIRS ); + s.fcfilepath =semanage_final_path (SEMANAGE_FINAL_TMP , +SEMANAGE_FC_HOMEDIRS ); s.fallback_user =strdup (FALLBACK_USER ); s.fallback_user_prefix =strdup (FALLBACK_USER_PREFIX );
libsemanage/src/iface_internal.h +3 -1
@@ -31,7 +31,9 @@ extern int iface_policydb_dbase_init(semanage_handle_t * handle,extern void iface_policydb_dbase_release (dbase_config_t * dconfig);extern int iface_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig); +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig);extern void iface_file_dbase_release (dbase_config_t * dconfig);
libsemanage/src/interfaces_file.c +5 -2
@@ -152,11 +152,14 @@ record_file_table_t SEMANAGE_IFACE_FILE_RTABLE = { };int iface_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_IFACE_RTABLE , &SEMANAGE_IFACE_FILE_RTABLE , &dconfig->dbase) <0 )return STATUS_ERR ;
libsemanage/src/interfaces_policydb.c +5 -1
@@ -33,6 +33,7 @@ typedef struct dbase_policydb dbase_t;#include "iface_internal.h" #include "debug.h" #include "database_policydb.h" +#include "semanage_store.h" /* INTERFACE RECRORD (SEPOL): POLICYDB extension: method table */ record_policydb_table_t SEMANAGE_IFACE_POLICYDB_RTABLE = {
@@ -50,7 +51,10 @@ int iface_policydb_dbase_init(semanage_handle_t * handle, {if (dbase_policydb_init (handle, -"policy.kern" , +semanage_final_path (SEMANAGE_FINAL_SELINUX , +SEMANAGE_KERNEL ), +semanage_final_path (SEMANAGE_FINAL_TMP , +SEMANAGE_KERNEL ), &SEMANAGE_IFACE_RTABLE , &SEMANAGE_IFACE_POLICYDB_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/node_internal.h +3 -1
@@ -34,7 +34,9 @@ hidden_proto(semanage_node_create)extern record_table_t SEMANAGE_NODE_RTABLE ;extern int node_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig); +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig);extern void node_file_dbase_release (dbase_config_t * dconfig);
libsemanage/src/nodes_file.c +5 -2
@@ -161,11 +161,14 @@ record_file_table_t SEMANAGE_NODE_FILE_RTABLE = { };int node_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_NODE_RTABLE , &SEMANAGE_NODE_FILE_RTABLE , &dconfig->dbase) <0 )return STATUS_ERR ;
libsemanage/src/nodes_policydb.c +5 -1
@@ -32,6 +32,7 @@ typedef struct dbase_policydb dbase_t;#include "node_internal.h" #include "debug.h" #include "database_policydb.h" +#include "semanage_store.h" /* NODE RECORD (SEPOL): POLICYDB extension : method table */ record_policydb_table_t SEMANAGE_NODE_POLICYDB_RTABLE = {
@@ -49,7 +50,10 @@ int node_policydb_dbase_init(semanage_handle_t * handle, {if (dbase_policydb_init (handle, -"policy.kern" , +semanage_final_path (SEMANAGE_FINAL_SELINUX , +SEMANAGE_KERNEL ), +semanage_final_path (SEMANAGE_FINAL_TMP , +SEMANAGE_KERNEL ), &SEMANAGE_NODE_RTABLE , &SEMANAGE_NODE_POLICYDB_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/port_internal.h +3 -1
@@ -30,7 +30,9 @@ hidden_proto(semanage_port_create)extern record_table_t SEMANAGE_PORT_RTABLE ;extern int port_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig); +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig);extern void port_file_dbase_release (dbase_config_t * dconfig);
libsemanage/src/ports_file.c +5 -2
@@ -164,11 +164,14 @@ record_file_table_t SEMANAGE_PORT_FILE_RTABLE = { };int port_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_PORT_RTABLE , &SEMANAGE_PORT_FILE_RTABLE , &dconfig->dbase) <0 )return STATUS_ERR ;
libsemanage/src/ports_policydb.c +5 -1
@@ -32,6 +32,7 @@ typedef struct dbase_policydb dbase_t;#include "port_internal.h" #include "debug.h" #include "database_policydb.h" +#include "semanage_store.h" /* PORT RECORD (SEPOL): POLICYDB extension : method table */ record_policydb_table_t SEMANAGE_PORT_POLICYDB_RTABLE = {
@@ -49,7 +50,10 @@ int port_policydb_dbase_init(semanage_handle_t * handle, {if (dbase_policydb_init (handle, -"policy.kern" , +semanage_final_path (SEMANAGE_FINAL_SELINUX , +SEMANAGE_KERNEL ), +semanage_final_path (SEMANAGE_FINAL_TMP , +SEMANAGE_KERNEL ), &SEMANAGE_PORT_RTABLE , &SEMANAGE_PORT_POLICYDB_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/semanage_store.c +388 -129
667 lines not on this page · raw message
libsemanage/src/semanage_store.h +25 -6
@@ -39,10 +39,8 @@ enum semanage_store_defs {enum semanage_sandbox_defs {SEMANAGE_TOPLEVEL ,SEMANAGE_MODULES , -SEMANAGE_KERNEL ,SEMANAGE_BASE ,SEMANAGE_LINKED , -SEMANAGE_FC ,SEMANAGE_HOMEDIR_TMPL ,SEMANAGE_FC_TMPL ,SEMANAGE_COMMIT_NUM_FILE ,
@@ -50,18 +48,32 @@ enum semanage_sandbox_defs {SEMANAGE_INTERFACES_LOCAL ,SEMANAGE_NODES_LOCAL ,SEMANAGE_BOOLEANS_LOCAL , -SEMANAGE_FC_LOCAL ,SEMANAGE_SEUSERS_LOCAL ,SEMANAGE_USERS_BASE_LOCAL ,SEMANAGE_USERS_EXTRA_LOCAL , -SEMANAGE_SEUSERS ,SEMANAGE_USERS_EXTRA , -SEMANAGE_NC , -SEMANAGE_FC_HOMEDIRS ,SEMANAGE_DISABLE_DONTAUDIT , +SEMANAGE_MODULES_DISABLED ,SEMANAGE_STORE_NUM_PATHS }; +enum semanage_final_defs { +SEMANAGE_FINAL_TMP , +SEMANAGE_FINAL_SELINUX , +SEMANAGE_FINAL_NUM +}; + +enum semanage_final_path_defs { +SEMANAGE_FINAL_TOPLEVEL , +SEMANAGE_FC , +SEMANAGE_FC_HOMEDIRS , +SEMANAGE_FC_LOCAL , +SEMANAGE_KERNEL , +SEMANAGE_NC , +SEMANAGE_SEUSERS , +SEMANAGE_FINAL_PATH_NUM +}; +const char *semanage_root_path (void );/* FIXME: this needs to be made a module store specific init and the
@@ -76,14 +88,21 @@ extern const char *semanage_fname(enum semanage_sandbox_defs file_enum);extern const char *semanage_path (enum semanage_store_defs store,enum semanage_sandbox_defs file); +extern const char *semanage_final_path (enum semanage_final_defs root, +enum semanage_final_path_defs suffix); +int semanage_create_store (semanage_handle_t * sh,int create);int semanage_store_access_check (semanage_handle_t * sh);int semanage_remove_directory (const char *path); +int semanage_mkdir (semanage_handle_t *sh,const char *path); +int semanage_make_sandbox (semanage_handle_t * sh); +int semanage_make_final (semanage_handle_t * sh); +int semanage_get_modules_names (semanage_handle_t * sh,char ***filenames,int *len);
libsemanage/src/seuser_internal.h +3 -1
@@ -30,7 +30,9 @@ hidden_proto(semanage_seuser_clone)extern record_table_t SEMANAGE_SEUSER_RTABLE ;extern int seuser_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig); +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig);extern void seuser_file_dbase_release (dbase_config_t * dconfig);
libsemanage/src/seusers_file.c +5 -2
@@ -115,11 +115,14 @@ record_file_table_t SEMANAGE_SEUSER_FILE_RTABLE = { };int seuser_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_SEUSER_RTABLE , &SEMANAGE_SEUSER_FILE_RTABLE , &dconfig->dbase) <0 )return STATUS_ERR ;
libsemanage/src/user_internal.h +4 -2
@@ -41,14 +41,16 @@ extern record_table_t SEMANAGE_USER_EXTRA_RTABLE;/* USER BASE record, FILE backend */ extern int user_base_file_dbase_init (semanage_handle_t * handle, -const char *fname, +const char *path_ro, +const char *path_rw,dbase_config_t * dconfig);extern void user_base_file_dbase_release (dbase_config_t * dconfig);/* USER EXTRA record, FILE backend */ extern int user_extra_file_dbase_init (semanage_handle_t * handle, -const char *fname, +const char *path_ro, +const char *path_rw,dbase_config_t * dconfig);extern void user_extra_file_dbase_release (dbase_config_t * dconfig);
libsemanage/src/users_base_file.c +5 -2
@@ -202,11 +202,14 @@ record_file_table_t SEMANAGE_USER_BASE_FILE_RTABLE = { };int user_base_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_USER_BASE_RTABLE , &SEMANAGE_USER_BASE_FILE_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/users_base_policydb.c +5 -1
@@ -32,6 +32,7 @@ typedef struct dbase_policydb dbase_t;#include "user_internal.h" #include "debug.h" #include "database_policydb.h" +#include "semanage_store.h" /* USER BASE record: POLICYDB extension: method table */ record_policydb_table_t SEMANAGE_USER_BASE_POLICYDB_RTABLE = {
@@ -49,7 +50,10 @@ int user_base_policydb_dbase_init(semanage_handle_t * handle, {if (dbase_policydb_init (handle, -"policy.kern" , +semanage_final_path (SEMANAGE_FINAL_SELINUX , +SEMANAGE_KERNEL ), +semanage_final_path (SEMANAGE_FINAL_TMP , +SEMANAGE_KERNEL ), &SEMANAGE_USER_BASE_RTABLE , &SEMANAGE_USER_BASE_POLICYDB_RTABLE , &dconfig->dbase) <0 )
libsemanage/src/users_extra_file.c +5 -2
@@ -106,11 +106,14 @@ record_file_table_t SEMANAGE_USER_EXTRA_FILE_RTABLE = { };int user_extra_file_dbase_init (semanage_handle_t * handle, -const char *fname,dbase_config_t * dconfig) +const char *path_ro, +const char *path_rw, +dbase_config_t * dconfig) {if (dbase_file_init (handle, - fname, + path_ro, + path_rw, &SEMANAGE_USER_EXTRA_RTABLE , &SEMANAGE_USER_EXTRA_FILE_RTABLE , &dconfig->dbase) <0 )
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 5/13 libsemanage: update unit tests for move to /var/lib/selinux
This updates the unit tests to accommodate the change in layout (no top level 'modules' directory).
--- libsemanage/tests/test_semanage_store.c | 34 +++++++++++++++--------------- 1 files changed, 17 insertions(+), 17 deletions(-)
libsemanage/tests/test_semanage_store.c +17 -17
@@ -44,12 +44,12 @@#include <CUnit/Basic.h> semanage_handle_t *sh =NULL ; -const char *polpath ="./test-policy" ; -const char *lockpath ="./test-policy/modules" ; -const char *readlockpath ="./test-policy/modules/semanage.read.LOCK" ; -const char *translockpath ="./test-policy/modules/semanage.trans.LOCK" ; -const char *actpath ="./test-policy/modules/active" ; -const char *modpath ="./test-policy/modules/active/modules" ; +const char *rootpath ="./test-policy" ; +const char *polpath ="./test-policy/store/" ; +const char *readlockpath ="./test-policy/store/semanage.read.LOCK" ; +const char *translockpath ="./test-policy/store/semanage.trans.LOCK" ; +const char *actpath ="./test-policy/store/active" ; +const char *modpath ="./test-policy/store/active/modules" ;/* The suite initialization function. * Returns zero on success, non-zero otherwise.
@@ -59,11 +59,11 @@ int semanage_store_test_init(void)int err;/* create directories */ - err =mkdir (polpath,S_IRUSR |S_IWUSR |S_IXUSR ); + err =mkdir (rootpath,S_IRUSR |S_IWUSR |S_IXUSR );if (err !=0 )return -1 ; - err =mkdir (lockpath,S_IRUSR |S_IWUSR |S_IXUSR ); + err =mkdir (polpath,S_IRUSR |S_IWUSR |S_IXUSR );if (err !=0 )return -1 ;
@@ -83,8 +83,12 @@ int semanage_store_test_init(void)/* hide error messages */ sh->msg_callback = test_msg_handler; +/* use our own policy store */ +free (sh->conf->store_path); + sh->conf->store_path =strdup ("store" ); +/* initialize paths */ - err =semanage_check_init (polpath); + err =semanage_check_init (sh, rootpath);if (err !=0 )return -1 ;
@@ -107,11 +111,11 @@ int semanage_store_test_cleanup(void)if (err !=0 )return -1 ; - err =rmdir (lockpath); + err =rmdir (polpath);if (err !=0 )return -1 ; - err =rmdir (polpath); + err =rmdir (rootpath);if (err !=0 )return -1 ;
@@ -217,8 +221,6 @@ void test_semanage_store_access_check(void)/* check with no lock file and 000 */ err =chmod (modpath,0 );CU_ASSERT (err ==0 ); - err =chmod (lockpath,0 ); -CU_ASSERT (err ==0 ); err =chmod (polpath,0 );CU_ASSERT (err ==0 );
@@ -228,16 +230,14 @@ void test_semanage_store_access_check(void)/* check with no lock file and 500 */ err =chmod (polpath,S_IRUSR |S_IXUSR );CU_ASSERT (err ==0 ); - err =chmod (lockpath,S_IRUSR |S_IXUSR ); -CU_ASSERT (err ==0 ); err =chmod (modpath,S_IRUSR |S_IXUSR );CU_ASSERT (err ==0 ); err =semanage_store_access_check (sh);CU_ASSERT (err ==0 ); -/* check with no lock file but write in lockpath */ - err =chmod (lockpath,S_IRUSR |S_IWUSR |S_IXUSR ); +/* check with no lock file but write in polpath */ + err =chmod (polpath,S_IRUSR |S_IWUSR |S_IXUSR );CU_ASSERT (err ==0 ); err =semanage_store_access_check (sh);
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 6/13 libsemanage: add default priority to semanage_handle_t
For backwards compatiblity purposes we need to provide a default priority that the current set of module install/upgrade/remove functions can use.
The default priority is 400.
Adds semanage_module_validate_priority so that it can be used to verify the given priority. See next patch for other validation functions.
--- libsemanage/src/handle.c | 23 +++++++++++++++++++++++ libsemanage/src/handle.h | 3 +++ libsemanage/src/modules.c | 17 +++++++++++++++++ libsemanage/src/modules.h | 4 ++++ 4 files changed, 47 insertions(+), 0 deletions(-)
libsemanage/src/handle.c +23 -0
@@ -59,6 +59,9 @@ semanage_handle_t *semanage_handle_create(void) goto err;sepol_msg_set_callback (sh->sepolh, semanage_msg_relay_handler, sh); +/* Default priority is 400 */ + sh->priority =400 ; +/* By default do not rebuild the policy on commit * If any changes are made, this flag is ignored */ sh->do_rebuild =0 ;
@@ -137,6 +140,26 @@ void semanage_set_check_contexts(semanage_handle_t * sh, int do_check_contexts)return ; } +uint16_t semanage_get_default_priority (semanage_handle_t *sh) +{ +assert (sh !=NULL ); +return sh->priority; +} + +int semanage_set_default_priority (semanage_handle_t *sh,uint16_t priority) +{ +assert (sh !=NULL ); + +/* Verify priority */ +if (semanage_module_validate_priority (priority) <0 ) { +ERR (sh,"Priority %d is invalid." , priority); +return -1 ; + } + + sh->priority = priority; +return 0 ; +} +int semanage_is_connected (semanage_handle_t * sh) {assert (sh !=NULL );
libsemanage/src/handle.h +3 -0
@@ -23,6 +23,7 @@#ifndef _SEMANAGE_INTERNAL_HANDLE_H_#define _SEMANAGE_INTERNAL_HANDLE_H_ +#include <stdint.h> #include <stddef.h> #include "handle_internal.h" #include <sepol/handle.h>
@@ -55,6 +56,8 @@ struct semanage_handle {sepol_handle_t *sepolh;semanage_conf_t *conf; + +uint16_t priority;int is_connected;int is_in_transaction;int do_reload;/* whether to reload policy after commit */
libsemanage/src/modules.c +17 -0
@@ -215,3 +215,20 @@ const char *semanage_module_get_version(semanage_module_info_t * modinfo) } hidden_def(semanage_module_get_version) + +#define PRIORITY_MIN 1 +#define PRIORITY_MAX 999 + +/* Validates priority. +* +* returns -1 if priority is not in the valid range, returns 0 otherwise +*/ +int semanage_module_validate_priority (uint16_t priority) +{ +if (priority >=PRIORITY_MIN && priority <=PRIORITY_MAX ) { +return 0 ; + } + +return -1 ; +} +
libsemanage/src/modules.h +4 -0
@@ -21,6 +21,8 @@#ifndef _SEMANAGE_INTERNAL_MODULES_H_#define _SEMANAGE_INTERNAL_MODULES_H_ +#include <stdint.h> +#include "module_internal.h" struct semanage_module_info {
@@ -28,4 +30,6 @@ struct semanage_module_info { char *version; }; +int semanage_module_validate_priority (uint16_t priority); +#endif
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 7/13 libsemanage: augment semanage_module_info_t and provide semanage_module_key_t
Adds priority, language ext, and enabled fields to semanage_module_info_t.
Adds get/set functions for all semanage_module_info_t/key_t fields. This is necessary so that semanage_module_info_t/key_t can be used in the specifing meta data on source policies.
Adds create, destroy, and init functions for semanage_module_info_t and semanage_module_key_t. Create initializes and allocates, destroy deallocates fields (but not struct), and init initializes fields.
Provide several utility functions for converting a string priority to a uint16_t and validating fields.
Adds semanage_module_get_path for getting module specific file paths.
--- libsemanage/src/modules.c | 798 ++++++++++++++++++++++++++++++++++++++++++++- libsemanage/src/modules.h | 229 +++++++++++++- 2 files changed, 1023 insertions(+), 4 deletions(-)
libsemanage/src/modules.c +797 -1
@@ -1,7 +1,8 @@/* Author: Joshua Brindle <[email protected] * Jason Tang <[email protected]> +* Caleb Case <[email protected]> * -* Copyright (C) 2004-2005 Tresys Technology, LLC +* Copyright (C) 2004-2005,2009 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
@@ -28,6 +29,13 @@#include <assert.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> +#include <limits.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include <ctype.h> #include "handle.h" #include "modules.h"
@@ -187,8 +195,18 @@ int semanage_module_list(semanage_handle_t * sh,void semanage_module_info_datum_destroy (semanage_module_info_t * modinfo) {if (modinfo !=NULL ) { + modinfo->priority =0 ; +free (modinfo->name); + modinfo->name =NULL ; +free (modinfo->version); + modinfo->version =NULL ; + +free (modinfo->lang_ext); + modinfo->lang_ext =NULL ; + + modinfo->enabled =-1 ; } }
@@ -216,6 +234,642 @@ const char *semanage_module_get_version(semanage_module_info_t * modinfo)hidden_def (semanage_module_get_version) +int semanage_module_info_create(semanage_handle_t *sh, +semanage_module_info_t **modinfo) +{ +assert (sh); +assert (modinfo); + + *modinfo =malloc (sizeof (semanage_module_info_t)); +if (*modinfo ==NULL )return -1 ; + +return semanage_module_info_init (sh, *modinfo); +} + +int semanage_module_info_destroy (semanage_handle_t *sh, +semanage_module_info_t *modinfo) +{ +assert (sh); + +if (!modinfo) { +return 0 ; + } + +free (modinfo->name); +free (modinfo->version); +free (modinfo->lang_ext); + +return semanage_module_info_init (sh, modinfo); +} + +int semanage_module_info_init (semanage_handle_t *sh, +semanage_module_info_t *modinfo) +{ +assert (sh); +assert (modinfo); + + modinfo->priority =0 ; + modinfo->name =NULL ; + modinfo->version =NULL ; + modinfo->lang_ext =NULL ; + modinfo->enabled =-1 ; + +return 0 ; +} + +int semanage_module_info_clone (semanage_handle_t *sh, +const semanage_module_info_t *source, +semanage_module_info_t *target) +{ +assert (sh); +assert (source); +assert (target); + +int status =0 ; +int ret =0 ; + + ret =semanage_module_info_destroy (sh, target); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_priority (sh, target, source->priority); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_name (sh, target, source->name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_version (sh, target, source->version); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_lang_ext (sh, target, source->lang_ext); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_enabled (sh, target, source->enabled); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +cleanup: +if (status !=0 )semanage_module_info_destroy (sh, target); +return status; +} + +int semanage_module_info_get_priority (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +uint16_t *priority) +{ +assert (sh); +assert (modinfo); +assert (priority); + + *priority = modinfo->priority; + +return 0 ; +} + +int semanage_module_info_get_name (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +const char **name) +{ +assert (sh); +assert (modinfo); +assert (name); + + *name = modinfo->name; + +return 0 ; +} + +int semanage_module_info_get_version (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +const char **version) +{ +assert (sh); +assert (modinfo); +assert (version); + + *version = modinfo->version; + +return 0 ; +} + +int semanage_module_info_get_lang_ext (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +const char **lang_ext) +{ +assert (sh); +assert (modinfo); +assert (lang_ext); + + *lang_ext = modinfo->lang_ext; + +return 0 ; +} + +int semanage_module_info_get_enabled (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +int *enabled) +{ +assert (sh); +assert (modinfo); +assert (enabled); + + *enabled = modinfo->enabled; + +return 0 ; +} + +int semanage_module_info_set_priority (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +uint16_t priority) +{ +assert (sh); +assert (modinfo); + +/* Verify priority */ +if (semanage_module_validate_priority (priority) <0 ) { + errno =0 ; +ERR (sh,"Priority %d is invalid." , priority); +return -1 ; + } + + modinfo->priority = priority; + +return 0 ; +} + +int semanage_module_info_set_name (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +const char *name) +{ +assert (sh); +assert (modinfo); +assert (name); + +char * tmp; + +/* Verify name */ +if (semanage_module_validate_name (name) <0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , name); +return -1 ; + } + + tmp =strdup (name); +if (!tmp) { +return -1 ; + } + +free (modinfo->name); + modinfo->name = tmp; + +return 0 ; +} + +int semanage_module_info_set_version (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +const char *version) +{ +assert (sh); +assert (modinfo); +assert (version); + +char * tmp; + +/* Verify version */ +if (semanage_module_validate_version (version) <0 ) { + errno =0 ; +ERR (sh,"Version %s is invalid." , version); +return -1 ; + } + + tmp =strdup (version); +if (!tmp) { +return -1 ; + } + +free (modinfo->version); + modinfo->version = tmp; + +return 0 ; +} + +int semanage_module_info_set_lang_ext (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +const char *lang_ext) +{ +assert (sh); +assert (modinfo); +assert (lang_ext); + +char * tmp; + +/* Verify extension */ +if (semanage_module_validate_lang_ext (lang_ext) <0 ) { + errno =0 ; +ERR (sh,"Language extensions %s is invalid." , lang_ext); +return -1 ; + } + + tmp =strdup (lang_ext); +if (!tmp) { +return -1 ; + } + +free (modinfo->lang_ext); + modinfo->lang_ext = tmp; + +return 0 ; +} + +int semanage_module_info_set_enabled (semanage_handle_t *sh, +semanage_module_info_t *modinfo, +int enabled) +{ +assert (sh); +assert (modinfo); + +/* Verify enabled */ +if (semanage_module_validate_enabled (enabled) <0 ) { + errno =0 ; +ERR (sh,"Enabled status %d is invalid." , enabled); +return -1 ; + } + + modinfo->enabled = enabled; + +return 0 ; +} + +int semanage_module_get_path (semanage_handle_t *sh, +const semanage_module_info_t *modinfo, +enum semanage_module_path_type type, +char *path, +size_t len) +{ +assert (sh); +assert (modinfo); +assert (path); + +int status =0 ; +int ret =0 ; + +const char *modules_path =NULL ; +const char *file =NULL ; + + modules_path = sh->is_in_transaction ? +semanage_path (SEMANAGE_TMP ,SEMANAGE_MODULES ): +semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_MODULES ); + +switch (type) { +case SEMANAGE_MODULE_PATH_PRIORITY : +/* verify priority */ + ret =semanage_module_validate_priority (modinfo->priority); +if (ret <0 ) { + errno =0 ; +ERR (sh, +"Priority %d is invalid." , + modinfo->priority); + status = ret; + goto cleanup; + } + + ret =snprintf (path, + len, +"%s/%03u" , + modules_path, + modinfo->priority); +if (ret <0 || (size_t )ret >= len) { +ERR (sh,"Unable to compose priority path." ); + status =-1 ; + goto cleanup; + } +break ; +case SEMANAGE_MODULE_PATH_NAME : +/* verify priority and name */ + ret =semanage_module_validate_priority (modinfo->priority); +if (ret <0 ) { + errno =0 ; +ERR (sh, +"Priority %d is invalid." , + modinfo->priority); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_validate_name (modinfo->name); +if (ret <0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , modinfo->name); + status =-1 ; + goto cleanup; + } + + ret =snprintf (path, + len, +"%s/%03u/%s" , + modules_path, + modinfo->priority, + modinfo->name); +if (ret <0 || (size_t )ret >= len) { +ERR (sh,"Unable to compose name path." ); + status =-1 ; + goto cleanup; + } +break ; +case SEMANAGE_MODULE_PATH_HLL : +/* verify priority, name, and ext */ + ret =semanage_module_validate_lang_ext (modinfo->lang_ext); +if (ret <0 ) { + errno =0 ; +ERR (sh, +"Language extensions %s is invalid." , + modinfo->lang_ext); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_validate_priority (modinfo->priority); +if (ret <0 ) { + errno =0 ; +ERR (sh, +"Priority %d is invalid." , + modinfo->priority); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_validate_name (modinfo->name); +if (ret <0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , modinfo->name); + status =-1 ; + goto cleanup; + } + + ret =snprintf (path, + len, +"%s/%03u/%s/%s.%s" , + modules_path, + modinfo->priority, + modinfo->name, + modinfo->name, + modinfo->lang_ext); +if (ret <0 || (size_t )ret >= len) { +ERR (sh,"Unable to compose hll path." ); + status =-1 ; + goto cleanup; + } +break ; +case SEMANAGE_MODULE_PATH_CIL : +if (file ==NULL ) file ="cil" ; +case SEMANAGE_MODULE_PATH_LANG_EXT : +if (file ==NULL ) file ="lang_ext" ; +case SEMANAGE_MODULE_PATH_VERSION : +if (file ==NULL ) file ="version" ; + +/* verify priority and name */ + ret =semanage_module_validate_priority (modinfo->priority); +if (ret <0 ) { + errno =0 ; +ERR (sh, +"Priority %d is invalid." , + modinfo->priority); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_validate_name (modinfo->name); +if (ret <0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , modinfo->name); + status =-1 ; + goto cleanup; + } + + ret =snprintf (path, + len, +"%s/%03u/%s/%s" , + modules_path, + modinfo->priority, + modinfo->name, + file); +if (ret <0 || (size_t )ret >= len) { +ERR (sh, +"Unable to compose path for %s file." , + file); + status =-1 ; + goto cleanup; + } +break ; +case SEMANAGE_MODULE_PATH_DISABLED : +/* verify name */ + ret =semanage_module_validate_name (modinfo->name); +if (ret <0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , modinfo->name); + status =-1 ; + goto cleanup; + } + + ret =snprintf (path, + len, +"%s/disabled/%s" , + modules_path, + modinfo->name); +if (ret <0 || (size_t )ret >= len) { +ERR (sh, +"Unable to compose disabled status path." ); + status =-1 ; + goto cleanup; + } +break ; +default : +ERR (sh,"Invalid module path type %d." , type); + status =-1 ; + goto cleanup; + } + +cleanup: +return status; +} + +int semanage_module_key_create (semanage_handle_t *sh, +semanage_module_key_t **modkey) +{ +assert (sh); +assert (modkey); + + *modkey =malloc (sizeof (semanage_module_key_t)); +if (*modkey ==NULL )return -1 ; + +return semanage_module_key_init (sh, *modkey); +} + +int semanage_module_key_destroy (semanage_handle_t *sh, +semanage_module_key_t *modkey) +{ +assert (sh); + +if (modkey) { +free (modkey->name); + } + +return semanage_module_key_init (sh, modkey); +} + +int semanage_module_key_init (semanage_handle_t *sh, +semanage_module_key_t *modkey) +{ +assert (sh); +assert (modkey); + + modkey->name =NULL ; + modkey->priority =0 ; + +return 0 ; +} + +int semanage_module_key_get_name (semanage_handle_t *sh, +semanage_module_key_t *modkey, +const char **name) +{ +assert (sh); +assert (modkey); +assert (name); + + *name = modkey->name; + +return 0 ; +} + +int semanage_module_key_get_priority (semanage_handle_t *sh, +semanage_module_key_t *modkey, +uint16_t *priority) +{ +assert (sh); +assert (modkey); +assert (priority); + + *priority = modkey->priority; + +return 0 ; +} + +int semanage_module_key_set_name (semanage_handle_t *sh, +semanage_module_key_t *modkey, +const char *name) +{ +assert (sh); +assert (modkey); +assert (name); + +int status =0 ; +char *tmp =NULL ; + +if (semanage_module_validate_name (name) <0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , name); +return -1 ; + } + + tmp =strdup (name); +if (tmp ==NULL ) { + status =-1 ; + goto cleanup; + } + +free (modkey->name); + modkey->name = tmp; + +cleanup: +return status; +} + +int semanage_module_key_set_priority (semanage_handle_t *sh, +semanage_module_key_t *modkey, +uint16_t priority) +{ +assert (sh); +assert (modkey); + +if (semanage_module_validate_priority (priority) <0 ) { + errno =0 ; +ERR (sh,"Priority %d is invalid." , priority); +return -1 ; + } + + modkey->priority = priority; + +return 0 ; +} + + +/* Converts a string to a priority +* +* returns -1 if str is not a valid priority. +* returns 0 and sets priority if str is a valid priority +*/ +int semanage_string_to_priority (const char *str,uint16_t *priority) +{ +unsigned long val; +char *endptr =NULL ; +int status =-1 ; + +if (str ==NULL || priority ==NULL ) { + goto exit; + } + + errno =0 ; + + val =strtoul (str, &endptr,10 ); + +if (errno !=0 || endptr == str || *endptr !='\0' || val >UINT16_MAX ) { + goto exit; + } + +if (semanage_module_validate_priority ((uint16_t )val) <0 ) { + goto exit; + } + + *priority = val; + status =0 ; + +exit: +return status; +} + +/* Validates a module info struct. +* +* Returns -1 if module is invalid, 0 otherwise. +*/ +int semanage_module_info_validate (const semanage_module_info_t *modinfo) +{ +if (semanage_module_validate_priority (modinfo->priority) !=0 || +semanage_module_validate_name (modinfo->name) !=0 || +semanage_module_validate_version (modinfo->version) !=0 || +semanage_module_validate_lang_ext (modinfo->lang_ext) !=0 || +semanage_module_validate_enabled (modinfo->enabled) !=0 ) { +return -1 ; + } +return 0 ; +} +#define PRIORITY_MIN 1#define PRIORITY_MAX 999
@@ -232,3 +886,145 @@ int semanage_module_validate_priority(uint16_t priority)return -1 ; } +/* Validates module name. +* +* A module name must match one of the following regular expressions +* to be considered valid: +* +* ^[a-zA-Z](\.?[a-zA-Z0-9_-])*$ +* ^_base$ +* +* returns -1 if name is not valid, returns 0 otherwise +*/ +int semanage_module_validate_name (const char * name) +{ +int status =0 ; + +if (name ==NULL ) { + status =-1 ; + goto exit; + } + +if (strcmp (name,"_base" ) ==0 ) { + goto exit; + } + +if (!isalpha (*name)) { + status =-1 ; + goto exit; + } + +#define ISVALIDCHAR (c) (isalnum(c) || c == '_' || c == '-') + +for (name++; *name; name++) { +if (ISVALIDCHAR (*name)) { +continue ; + } +if (*name =='.' && name++ &&ISVALIDCHAR (*name)) { +continue ; + } + status =-1 ; + goto exit; + } + +#undef ISVALIDCHAR + +exit: +return status; +} + +/* Validates module enabled status. +* +* Valid enabled values are 1, 0, and -1. +* +* returns 0 if enabled is a valid value, returns -1 otherwise. +*/ +int semanage_module_validate_enabled (int enabled) +{ +if (enabled ==1 || enabled ==0 || enabled ==-1 ) { +return 0 ; + } + +return -1 ; +} + +/* Validate extension. +* +* An extension must match the following regular expression to be +* considered valid: +* +* ^[a-zA-Z0-9][a-zA-Z0-9_-]*$ +* +* returns 0 if ext is a valid value, returns -1 otherwise. +*/ +int semanage_module_validate_lang_ext (const char *ext) +{ +int status =0 ; + +if (ext ==NULL ) { + status =-1 ; + goto exit; + } + +if (!isalnum (*ext)) { + status =-1 ; + goto exit; + } + +#define ISVALIDCHAR (c) (isalnum(c) || c == '_' || c == '-') + +for (ext++; *ext; ext++) { +if (ISVALIDCHAR (*ext)) { +continue ; + } + status =-1 ; + goto exit; + } + +#undef ISVALIDCHAR + +exit: +return status; +} + +/* Validate version. +* +* A version must match the following regular expression to be +* considered valid: +* +* ^[:print:]+$ +* +* returns 0 if version is valid, returns -1 otherwise. +*/ +int semanage_module_validate_version (const char *version) +{ +int status =0 ; + +if (version ==NULL ) { + status =-1 ; + goto exit; + } + +/* must start with a printable char */ +if (!isprint (*version)) { + status =-1 ; + goto exit; + } + +/* everything else must be printable */ +#define ISVALIDCHAR (c) (isprint(c)) + +for (version++; *version; version++) { +if (ISVALIDCHAR (*version)) { +continue ; + } + status =-1 ; + goto exit; + } + +#undef ISVALIDCHAR + +exit: +return status; +} +
libsemanage/src/modules.h +226 -3
244 lines not on this page · raw message
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 8/13 libsemanage: get/set module info and enabled status
This provides the functions for enabling/disabling modules via a semanage_module_key_t and getting/setting module info.
Enabled/disabled status is indicated by the presence of an empty file in the disabled directory:
/var/lib/selinux/<policy type>/disabled/<module name>
The presence of a file there indicates that the module is disabled at all priorities. Enable/disabling of modules is done across all priorities simultaneously to avoid confusion that would likely arise from per priority settings.
semanage_module_get_module_info gathers up the on disk information about a module indicated by the module key and puts the information into module info. In order to facilitate an easy mechanism for getting the highest priority module of a given name, the key's priority value may be 0 and the highest priority module with the given name will be located.
semanage_direct_set_module_info is a helper function that writes module info to disk. The unused attribute is used to suppress warnings for compilation and is removed in the module install patch later in the series.
semanage_module_list_all behaves similar to semanage_module_list except it returns all modules at all priorities. semanage_module_list will only include the highest priority, enabled, non-base modules (this is its current behavior). See the module install patch later in the series for the modified semanage_module_list.
Adds a helper function for creating a directory if it doesn't already exist (used to automatically create the disabled, priority, and module dirs).
--- libsemanage/src/direct_api.c | 908 +++++++++++++++++++++++++++++++++++++++++- libsemanage/src/modules.c | 83 ++++ libsemanage/src/modules.h | 44 ++ libsemanage/src/policy.h | 21 + 4 files changed, 1055 insertions(+), 1 deletions(-)
libsemanage/src/direct_api.c +907 -1
@@ -34,6 +34,7 @@#include <sys/types.h> #include <limits.h> #include <errno.h> +#include <dirent.h> #include "user_internal.h" #include "seuser_internal.h"
@@ -70,6 +71,20 @@ static int semanage_direct_remove(semanage_handle_t * sh, char *module_name);static int semanage_direct_list (semanage_handle_t * sh,semanage_module_info_t ** modinfo,int *num_modules); +static int semanage_direct_get_enabled (semanage_handle_t *sh, +const semanage_module_key_t *modkey, +int *enabled); +static int semanage_direct_set_enabled (semanage_handle_t *sh, +const semanage_module_key_t *modkey, +int enabled); + +static int semanage_direct_get_module_info (semanage_handle_t *sh, +const semanage_module_key_t *modkey, +semanage_module_info_t **modinfo); + +static int semanage_direct_list_all (semanage_handle_t *sh, +semanage_module_info_t **modinfo, +int *num_modules);static struct semanage_policy_table direct_funcs = { .get_serial = semanage_direct_get_serial,
@@ -84,7 +99,11 @@ static struct semanage_policy_table direct_funcs = { .install_base = semanage_direct_install_base, .install_base_file = semanage_direct_install_base_file, .remove = semanage_direct_remove, - .list = semanage_direct_list + .list = semanage_direct_list, + .get_enabled = semanage_direct_get_enabled, + .set_enabled = semanage_direct_set_enabled, + .get_module_info = semanage_direct_get_module_info, + .list_all = semanage_direct_list_all, };int semanage_direct_is_managed (semanage_handle_t * sh)
@@ -1453,6 +1472,197 @@ static int semanage_direct_list(semanage_handle_t * sh,return retval; } +static int semanage_direct_get_enabled (semanage_handle_t *sh, +const semanage_module_key_t *modkey, +int *enabled) +{ +assert (sh); +assert (modkey); +assert (enabled); + +int status =0 ; +int ret =0 ; + +char path[PATH_MAX ]; +struct stat sb; +semanage_module_info_t *modinfo =NULL ; + +/* get module info */ + ret =semanage_module_get_module_info ( + sh, + modkey, + &modinfo); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* get disabled file path */ + ret =semanage_module_get_path ( + sh, + modinfo, +SEMANAGE_MODULE_PATH_DISABLED , + path, +sizeof (path)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +if (stat (path, &sb) <0 ) { + *enabled =1 ; + } +else { + *enabled =0 ; + } + +cleanup: +semanage_module_info_destroy (sh, modinfo); +free (modinfo); + +return status; +} + +static int semanage_direct_set_enabled (semanage_handle_t *sh, +const semanage_module_key_t *modkey, +int enabled) +{ +assert (sh); +assert (modkey); + +int status =0 ; +int ret =0 ; + +char fn[PATH_MAX ]; +const char *path =NULL ; +FILE *fp =NULL ; +semanage_module_info_t *modinfo =NULL ; + +/* check transaction */ +if (!sh->is_in_transaction) { +if (semanage_begin_transaction (sh) <0 ) { + status =-1 ; + goto cleanup; + } + } + +/* validate name */ + ret =semanage_module_validate_name (modkey->name); +if (ret !=0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , modkey->name); + status =-1 ; + goto cleanup; + } + +/* validate enabled */ + ret =semanage_module_validate_enabled (enabled); +if (ret !=0 ) { + errno =0 ; +ERR (sh,"Enabled status %d is invalid." , enabled); + status =-1 ; + goto cleanup; + } + +/* check for base module */ +if (strcmp (modkey->name,"_base" ) ==0 ) { +if (enabled ==0 ) { + errno =0 ; +ERR (sh,"Base module cannot be disabled." ); + status =-1 ; + goto cleanup; + } +else { + errno =0 ; +WARN (sh,"Base module is always enabled, redundant enabling of base module requested." ); + } + } + +/* check for disabled path, create if missing */ + path =semanage_path (SEMANAGE_TMP ,SEMANAGE_MODULES_DISABLED ); + + ret =semanage_mkdir (sh, path); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* get module info */ + ret =semanage_module_get_module_info ( + sh, + modkey, + &modinfo); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* get module disabled file */ + ret =semanage_module_get_path ( + sh, + modinfo, +SEMANAGE_MODULE_PATH_DISABLED , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +switch (enabled) { +case 0 :/* disable the module */ + fp =fopen (fn,"w" ); + +if (fp ==NULL ) { +ERR (sh, +"Unable to disable module %s" , + modkey->name); + status =-1 ; + goto cleanup; + } + +if (fclose (fp) !=0 ) { +ERR (sh, +"Unable to close disabled file for module %s" , + modkey->name); + status =-1 ; + goto cleanup; + } + + fp =NULL ; + +break ; +case 1 :/* enable the module */ +if (unlink (fn) <0 ) { +if (errno !=ENOENT ) { +ERR (sh, +"Unable to enable module %s" , + modkey->name); + status =-1 ; + goto cleanup; + } +else { +/* module already enabled */ + errno =0 ; + } + } + +break ; +case -1 :/* warn about ignored setting to default */ +WARN (sh, +"Setting module %s to 'default' state has no effect" , + modkey->name); +break ; + } + +cleanup: +semanage_module_info_destroy (sh, modinfo); +free (modinfo); + +if (fp !=NULL )fclose (fp); +return status; +} +int semanage_direct_access_check (semanage_handle_t * sh) {if (semanage_check_init (sh,semanage_root_path ()))
@@ -1479,3 +1689,699 @@ cleanup:sepol_policydb_free (p);return retval; } + +static int semanage_direct_get_module_info (semanage_handle_t *sh, +const semanage_module_key_t *modkey, +semanage_module_info_t **modinfo) +{ +assert (sh); +assert (modkey); +assert (modinfo); + +int status =0 ; +int ret =0 ; + +char fn[PATH_MAX ]; +FILE *fp =NULL ; +const char *modules_path =NULL ; +size_t size =0 ; +struct stat sb; +char *tmp =NULL ; + +int i =0 ; + +semanage_module_info_t *modinfos =NULL ; +int modinfos_len =0 ; +semanage_module_info_t *highest =NULL ; + +if (sh->is_in_transaction) { + modules_path =semanage_path (SEMANAGE_TMP ,SEMANAGE_MODULES ); + }else { + modules_path =semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_MODULES ); + } + +/* check module name */ + ret =semanage_module_validate_name (modkey->name); +if (ret <0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , modkey->name); + status =-1 ; + goto cleanup; + } + +/* if priority == 0, then find the highest priority available */ +if (modkey->priority ==0 ) { + ret =semanage_direct_list_all (sh, &modinfos, &modinfos_len); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +for (i =0 ; i < modinfos_len; i++) { + ret =strcmp (modinfos[i].name, modkey->name); +if (ret ==0 ) { + highest = &modinfos[i]; +break ; + } + } + +if (highest ==NULL ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_create (sh, modinfo); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_clone (sh, highest, *modinfo); +if (ret !=0 ) { + status =-1 ; + } + +/* skip to cleanup, module was found */ + goto cleanup; + } + +/* check module priority */ + ret =semanage_module_validate_priority (modkey->priority); +if (ret !=0 ) { + errno =0 ; +ERR (sh,"Priority %d is invalid." , modkey->priority); + status =-1 ; + goto cleanup; + } + +/* copy in key values */ + ret =semanage_module_info_create (sh, modinfo); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_priority (sh, *modinfo, modkey->priority); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_name (sh, *modinfo, modkey->name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* lookup module ext */ + ret =semanage_module_get_path (sh, + *modinfo, +SEMANAGE_MODULE_PATH_LANG_EXT , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + fp =fopen (fn,"r" ); + +if (fp ==NULL ) { +ERR (sh, +"Unable to open %s module lang ext file at %s." , + (*modinfo)->name, fn); + status =-1 ; + goto cleanup; + } + +/* set module ext */ +if (getline (&tmp, &size, fp) <0 ) { +ERR (sh, +"Unable to read %s module lang ext file." , + (*modinfo)->name); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_lang_ext (sh, *modinfo, tmp); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } +free (tmp); + tmp =NULL ; + +if (fclose (fp) !=0 ) { +ERR (sh, +"Unable to close %s module lang ext file." , + (*modinfo)->name); + status =-1 ; + goto cleanup; + } + + fp =NULL ; + +/* lookup module version */ + ret =semanage_module_get_path (sh, + *modinfo, +SEMANAGE_MODULE_PATH_VERSION , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + fp =fopen (fn,"r" ); + +if (fp ==NULL ) { +ERR (sh, +"Unable to open %s module version file." , + (*modinfo)->name); + status =-1 ; + goto cleanup; + } + +/* set module version */ +if (getline (&tmp, &size, fp) <0 ) { +ERR (sh, +"Unable to read %s module version file." , + (*modinfo)->name); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_version (sh, (*modinfo), tmp); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } +free (tmp); + tmp =NULL ; + +if (fclose (fp) !=0 ) { +ERR (sh, +"Unable to close %s module version file." , + (*modinfo)->name); + status =-1 ; + goto cleanup; + } + + fp =NULL ; + +/* lookup enabled/disabled status */ + ret =semanage_module_get_path (sh, + *modinfo, +SEMANAGE_MODULE_PATH_DISABLED , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* set enabled/disabled status */ +if (stat (fn, &sb) <0 ) { + ret =semanage_module_info_set_enabled (sh, *modinfo,1 ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + } +else { + ret =semanage_module_info_set_enabled (sh, *modinfo,0 ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + } + +cleanup: +free (tmp); + +if (modinfos !=NULL ) { +for (i =0 ; i < modinfos_len; i++) { +semanage_module_info_destroy (sh, &modinfos[i]); + } +free (modinfos); + } + +if (fp !=NULL )fclose (fp); +return status; +} + +__attribute__ ((unused)) +static int semanage_direct_set_module_info (semanage_handle_t *sh, +const semanage_module_info_t *modinfo) +{ +int status =0 ; +int ret =0 ; + +char fn[PATH_MAX ]; +const char *path =NULL ; +FILE *fp =NULL ; +int enabled =0 ; + +semanage_module_key_t modkey; + ret =semanage_module_key_init (sh, &modkey); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +semanage_module_info_t *modinfo_tmp =NULL ; + +/* check transaction */ +if (!sh->is_in_transaction) { +if (semanage_begin_transaction (sh) <0 ) { + status =-1 ; + goto cleanup; + } + } + +/* validate module */ + ret =semanage_module_info_validate (modinfo); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* check for base module */ +if (strcmp (modinfo->name,"_base" ) ==0 ) { +if (modinfo->enabled ==0 ) { + errno =0 ; +ERR (sh,"Base module cannot be disabled." ); + status =-1 ; + goto cleanup; + } + } + + sh->modules_modified =1 ; + +/* check for modules path, create if missing */ + path =semanage_path (SEMANAGE_TMP ,SEMANAGE_MODULES ); + + ret =semanage_mkdir (sh, path); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* write priority */ + ret =semanage_module_get_path (sh, + modinfo, +SEMANAGE_MODULE_PATH_PRIORITY , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_mkdir (sh, fn); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* write name */ + ret =semanage_module_get_path (sh, + modinfo, +SEMANAGE_MODULE_PATH_NAME , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_mkdir (sh, fn); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* write ext */ + ret =semanage_module_get_path (sh, + modinfo, +SEMANAGE_MODULE_PATH_LANG_EXT , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + fp =fopen (fn,"w" ); + +if (fp ==NULL ) { +ERR (sh,"Unable to open %s module ext file." , modinfo->name); + status =-1 ; + goto cleanup; + } + +if (fputs (modinfo->lang_ext, fp) <0 ) { +ERR (sh,"Unable to write %s module ext file." , modinfo->name); + status =-1 ; + goto cleanup; + } + +if (fclose (fp) !=0 ) { +ERR (sh,"Unable to close %s module ext file." , modinfo->name); + status =-1 ; + goto cleanup; + } + + fp =NULL ; + +/* write version */ + ret =semanage_module_get_path (sh, + modinfo, +SEMANAGE_MODULE_PATH_VERSION , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + fp =fopen (fn,"w" ); + +if (fp ==NULL ) { +ERR (sh, +"Unable to open %s module version file." , + modinfo->name); + status =-1 ; + goto cleanup; + } + +if (fputs (modinfo->version, fp) <0 ) { +ERR (sh, +"Unable to write %s module version file." , + modinfo->name); + status =-1 ; + goto cleanup; + } + +if (fclose (fp) !=0 ) { +ERR (sh, +"Unable to close %s module version file." , + modinfo->name); + status =-1 ; + goto cleanup; + } + + fp =NULL ; + +/* write enabled/disabled status */ + +/* check for disabled path, create if missing */ + path =semanage_path (SEMANAGE_TMP ,SEMANAGE_MODULES_DISABLED ); + + ret =semanage_mkdir (sh, path); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_get_path (sh, + modinfo, +SEMANAGE_MODULE_PATH_DISABLED , + fn, +sizeof (fn)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_key_set_name (sh, &modkey, modinfo->name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +if (modinfo->enabled ==-1 ) { +/* default to enabled */ + enabled =1 ; + +/* check if a module is already installed */ + ret =semanage_module_get_module_info (sh, + &modkey, + &modinfo_tmp); +if (ret ==0 ) { +/* set enabled status to current one */ + enabled = modinfo_tmp->enabled; + } + } +else { + enabled = modinfo->enabled; + } + + ret =semanage_module_set_enabled (sh, &modkey, enabled); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +cleanup: +if (fp !=NULL )fclose (fp); + +semanage_module_key_destroy (sh, &modkey); + +semanage_module_info_destroy (sh, modinfo_tmp); +free (modinfo_tmp); + +return status; +} + +static int semanage_priorities_filename_select (const struct dirent *d) +{ +if (d->d_name[0 ] =='.' || +strcmp (d->d_name,"disabled" ) ==0 ) +return 0 ; +return 1 ; +} + +static int semanage_modules_filename_select (const struct dirent *d) +{ +if (d->d_name[0 ] =='.' ) +return 0 ; +return 1 ; +} + +static int semanage_direct_list_all (semanage_handle_t *sh, +semanage_module_info_t **modinfos, +int *modinfos_len) +{ +assert (sh); +assert (modinfos); +assert (modinfos_len); + +int status =0 ; +int ret =0 ; + +int i =0 ; +int j =0 ; + + *modinfos =NULL ; + *modinfos_len =0 ; +void *tmp =NULL ; + +const char *toplevel =NULL ; + +struct dirent **priorities =NULL ; +int priorities_len =0 ; +char priority_path[PATH_MAX ]; + +struct dirent **modules =NULL ; +int modules_len =0 ; + +uint16_t priority =0 ; + +semanage_module_info_t modinfo; + ret =semanage_module_info_init (sh, &modinfo); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +semanage_module_info_t *modinfo_tmp =NULL ; + +if (sh->is_in_transaction) { + toplevel =semanage_path (SEMANAGE_TMP ,SEMANAGE_MODULES ); + }else { + toplevel =semanage_path (SEMANAGE_ACTIVE ,SEMANAGE_MODULES ); + } + +/* find priorities */ + priorities_len =scandir (toplevel, + &priorities, + semanage_priorities_filename_select, + versionsort); +if (priorities_len ==-1 ) { +ERR (sh,"Error while scanning directory %s." , toplevel); + status =-1 ; + goto cleanup; + } + +/* for each priority directory */ +/* loop through in reverse so that highest priority is first */ +for (i = priorities_len -1 ; i >=0 ; i--) { +/* convert priority string to uint16_t */ + ret =semanage_string_to_priority (priorities[i]->d_name, + &priority); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* set our priority */ + ret =semanage_module_info_set_priority (sh, + &modinfo, + priority); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* get the priority path */ + ret =semanage_module_get_path (sh, + &modinfo, +SEMANAGE_MODULE_PATH_PRIORITY , + priority_path, +sizeof (priority_path)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* cleanup old modules */ +if (modules !=NULL ) { +for (j =0 ; j < modules_len; j++) { +free (modules[j]); + modules[j] =NULL ; + } +free (modules); + modules =NULL ; + modules_len =0 ; + } + +/* find modules at this priority */ + modules_len =scandir (priority_path, + &modules, + semanage_modules_filename_select, + versionsort); +if (modules_len ==-1 ) { +ERR (sh, +"Error while scanning directory %s." , + priority_path); + status =-1 ; + goto cleanup; + } + +if (modules_len ==0 )continue ; + +/* add space for modules */ + tmp =realloc (*modinfos, +sizeof (semanage_module_info_t) * + (*modinfos_len + modules_len)); +if (tmp ==NULL ) { +ERR (sh,"Error allocating memory for module array." ); + status =-1 ; + goto cleanup; + } + *modinfos = tmp; + +/* for each module directory */ +for (j =0 ; j < modules_len; j++) { +/* set module name */ + ret =semanage_module_info_set_name ( + sh, + &modinfo, + modules[j]->d_name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* get module values */ + ret =semanage_direct_get_module_info ( + sh, + (const semanage_module_key_t *) + (&modinfo), + &modinfo_tmp); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* copy into array */ + ret =semanage_module_info_init ( + sh, + &((*modinfos)[*modinfos_len])); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_clone ( + sh, + modinfo_tmp, + &((*modinfos)[*modinfos_len])); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_destroy (sh, modinfo_tmp); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } +free (modinfo_tmp); + modinfo_tmp =NULL ; + + *modinfos_len +=1 ; + } + } + +cleanup: +semanage_module_info_destroy (sh, &modinfo); + +if (priorities !=NULL ) { +for (i =0 ; i < priorities_len; i++) { +free (priorities[i]); + } +free (priorities); + } + +if (modules !=NULL ) { +for (i =0 ; i < modules_len; i++) { +free (modules[i]); + } +free (modules); + } + + ret =semanage_module_info_destroy (sh, modinfo_tmp); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } +free (modinfo_tmp); + modinfo_tmp =NULL ; + +if (status !=0 ) { +if (modinfos !=NULL ) { +for (i =0 ; i < *modinfos_len; i++) { +semanage_module_info_destroy ( + sh, + &(*modinfos)[i]); + } +free (*modinfos); + *modinfos =NULL ; + *modinfos_len =0 ; + } + } + +return status; +}
libsemanage/src/modules.c +83 -0
92 lines not on this page · raw message
libsemanage/src/modules.h +44 -0
48 lines not on this page · raw message
libsemanage/src/policy.h +21 -0
@@ -70,6 +70,27 @@ struct semanage_policy_table {/* Install a base module */ int (*install_base_file) (struct semanage_handle *,const char *); + +/* Get module enabled status */ +int (*get_enabled) (struct semanage_handle *sh, +const semanage_module_key_t *key, +int *enabled); + +/* Set module enabled status */ +int (*set_enabled) (struct semanage_handle *sh, +const semanage_module_key_t *key, +int enabled); + +/* Get a module info */ +int (*get_module_info) (struct semanage_handle *, +const semanage_module_key_t *, +semanage_module_info_t **); + +/* List all policy modules */ +int (*list_all) (struct semanage_handle *, +semanage_module_info_t **, +int *); + };/* Should be backend independent */
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 9/13 libsemanage: provide function to get new base module path
The base module is being moved in with the other modules so that it can benefit from the priority framework. This patch provides a utility function for getting the highest priority base module path.
--- libsemanage/src/semanage_store.c | 61 ++++++++++++++++++++++++++++++++++++++ libsemanage/src/semanage_store.h | 10 ++++++ 2 files changed, 71 insertions(+), 0 deletions(-)
libsemanage/src/semanage_store.c +61 -0
@@ -491,6 +491,67 @@ const char *semanage_conf_path(void)return "/etc/selinux/semanage.conf" ; } +/* Locates the highest priority enabled base module +* and fills @path in with that value. @path must be +* pre-allocated with size @len. +* +* Returns 0 on success and -1 on error. +*/ +int semanage_base_path (semanage_handle_t *sh, +char *path, +size_t len) +{ +assert (sh); +assert (path); + +int status =0 ; +int ret =0 ; + +semanage_module_info_t *base =NULL ; + +/* set key for getting base module */ +semanage_module_key_t modkey; + ret =semanage_module_key_init (sh, &modkey); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_key_set_name (sh, &modkey,"_base" ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* get highest priority base module */ + ret =semanage_module_get_module_info (sh, &modkey, &base); +if (ret !=0 ) { +/* no base module found */ + status =-1 ; + goto cleanup; + } + +/* get the highest priority base module path */ + ret =semanage_module_get_path ( + sh, + base, +SEMANAGE_MODULE_PATH_HLL , + path, + len); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +cleanup: +semanage_module_key_destroy (sh, &modkey); + +semanage_module_info_destroy (sh, base); +free (base); + +return status; +} +/**************** functions that create module store ***************/ /* Check that the semanage store exists. If 'create' is non-zero then
libsemanage/src/semanage_store.h +10 -0
@@ -150,4 +150,14 @@ int semanage_nc_sort(semanage_handle_t * sh,size_t buf_len, char **sorted_buf, size_t * sorted_buf_len); +/* Locates the highest priority enabled base module +* and fills @path in with that value. @path must be +* pre-allocated with size @len. +* +* Returns 0 on success and -1 on error. +*/ +int semanage_base_path (semanage_handle_t *sh, +char *path, +size_t len); +#endif
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 10/13 libsemanage: installing/upgrading/removing modules via info and key
These functions install/upgrade/remove modules based on the module info/key. The motivation for these interfaces is to provide the additional information about a module (version, language, and enabled status) at install time and also to separate the meta-data in preparation for supporting source policies.
This patch combines the implementations of all the install/upgrade/remove functions to use the semanage_direct_install_info, semanage_direct_upgrade_info, and semanage_direct_remove_key functions. The motivation here is to reduce the amount of duplicate installation code (for example, semanage_direct_install and semanage_direct_install_file have separate but similar implementations).
With this patch the transition from the old store layout to the new one is finished. This is accomplished mostly through the modification of install functions and semanage_get_modules_names.
--- libsemanage/src/direct_api.c | 652 +++++++++++++++++++++++++++----------- libsemanage/src/modules.c | 61 ++++ libsemanage/src/modules.h | 48 +++ libsemanage/src/policy.h | 15 + libsemanage/src/semanage_store.c | 177 ++++++++--- libsemanage/src/semanage_store.h | 1 - 6 files changed, 713 insertions(+), 241 deletions(-)
libsemanage/src/direct_api.c +459 -193
@@ -86,6 +86,19 @@ static int semanage_direct_list_all(semanage_handle_t *sh, semanage_module_info_t **modinfo, int *num_modules); +static int semanage_direct_install_info (semanage_handle_t *sh, +const semanage_module_info_t *modinfo, +char *data, +size_t data_len); + +static int semanage_direct_upgrade_info (semanage_handle_t *sh, +const semanage_module_info_t *modinfo, +char *data, +size_t data_len); + +static int semanage_direct_remove_key (semanage_handle_t *sh, +const semanage_module_key_t *modkey); +static struct semanage_policy_table direct_funcs = { .get_serial = semanage_direct_get_serial, .destroy = semanage_direct_destroy,
@@ -104,6 +117,9 @@ static struct semanage_policy_table direct_funcs = { .set_enabled = semanage_direct_set_enabled, .get_module_info = semanage_direct_get_module_info, .list_all = semanage_direct_list_all, + .install_info = semanage_direct_install_info, + .upgrade_info = semanage_direct_upgrade_info, + .remove_key = semanage_direct_remove_key, };int semanage_direct_is_managed (semanage_handle_t * sh)
@@ -358,21 +374,19 @@ static int semanage_direct_begintrans(semanage_handle_t * sh)/********************* utility functions *********************/ /* Takes a module stored in 'module_data' and parses its headers. -* Sets reference variables 'filename' to module's fully qualified -* path name into the sandbox, 'module_name' to module's name, and +* Sets reference variables 'module_name' to module's name, and * 'version' to module's version. The caller is responsible for -* free()ing 'filename', 'module_name', and 'version'; they will be +* free()ing 'module_name', and 'version'; they will be * set to NULL upon entering this function. Returns 0 on success, -1 * if out of memory, or -2 if data did not represent a module. */ static int parse_module_headers (semanage_handle_t * sh,char *module_data,size_t data_len,char **module_name, -char **version,char **filename) +char **version) {struct sepol_policy_file *pf;int file_type; -const char *module_path; - *module_name = *version = *filename =NULL ; + *module_name = *version =NULL ;if (sepol_policy_file_create (&pf)) {ERR (sh,"Out of memory!" );
@@ -397,14 +411,7 @@ static int parse_module_headers(semanage_handle_t * sh, char *module_data,ERR (sh,"Data did not represent a module." );return -2 ; } -if ((module_path = -semanage_path (SEMANAGE_TMP ,SEMANAGE_MODULES )) ==NULL ) { -return -1 ; - } -if (asprintf (filename,"%s/%s.pp" , module_path, *module_name) ==-1 ) { -ERR (sh,"Out of memory!" ); -return -1 ; - } +return 0 ; }
@@ -592,27 +599,6 @@ static ssize_t map_file(semanage_handle_t *sh, int fd, char **data,return size; } -static int dupfile (const char *dest,int src_fd) { -int dest_fd =-1 ; -int retval =0 ; -int cnt; -char buf[1 <<18 ]; - -if (lseek (src_fd,0 ,SEEK_SET ) ==-1 )return -1 ; - -if ((dest_fd =open (dest,O_WRONLY |O_CREAT |O_TRUNC , -S_IRUSR |S_IWUSR )) ==-1 ) { -return -1 ; - } - -while (( retval ==0 ) && - ( cnt =read (src_fd, buf,sizeof (buf)))>0 ) { -if (write (dest_fd, buf, cnt) < cnt) retval =-1 ; - } -close (dest_fd); -return retval; -} -/* Writes a block of data to a file. Returns 0 on success, -1 on * error. */ static int write_file(semanage_handle_t * sh,
@@ -1074,25 +1060,61 @@ static int semanage_direct_commit(semanage_handle_t * sh)static int semanage_direct_install (semanage_handle_t * sh,char *data,size_t data_len) { +int status =0 ; +int ret =0 ; -int retval; -char *module_name =NULL , *version =NULL , *filename =NULL ; -if ((retval =parse_module_headers (sh, data, data_len, - &module_name, &version, - &filename)) !=0 ) { +char *module_name =NULL , *version =NULL ; +if ((status =parse_module_headers (sh, data, data_len, + &module_name, &version)) !=0 ) { goto cleanup; } -if (bzip (sh, filename, data, data_len) <=0 ) { -ERR (sh,"Error while writing to %s." , filename); - retval =-3 ; + +semanage_module_info_t modinfo; + ret =semanage_module_info_init (sh, &modinfo); +if (ret !=0 ) { + status =-1 ; goto cleanup; } - retval =0 ; - cleanup: + + ret =semanage_module_info_set_priority (sh, &modinfo, sh->priority); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_name (sh, &modinfo, module_name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_version (sh, &modinfo, version); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_lang_ext (sh, &modinfo,"pp" ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_enabled (sh, &modinfo,-1 ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + status =semanage_direct_install_info (sh, &modinfo, data, data_len); + +cleanup:free (version); -free (filename);free (module_name); -return retval; + +semanage_module_info_destroy (sh, &modinfo); + +return status; }/* Attempts to link a module to the sandbox's module directory, unlinking any
@@ -1118,24 +1140,7 @@ static int semanage_direct_install_file(semanage_handle_t * sh, goto cleanup; } -if (compressed) { -char *module_name =NULL , *version =NULL , *filename =NULL ; -if ((retval =parse_module_headers (sh, data, data_len, - &module_name, &version, - &filename)) !=0 ) { - goto cleanup; - } - -if (data_len >0 )munmap (data, data_len); - data_len =0 ; - retval =dupfile (filename, in_fd); -free (version); -free (filename); -free (module_name); - - }else { - retval =semanage_direct_install (sh, data, data_len); - } + retval =semanage_direct_install (sh, data, data_len); cleanup:close (in_fd);
@@ -1144,54 +1149,6 @@ static int semanage_direct_install_file(semanage_handle_t * sh,return retval; } - -static int get_direct_upgrade_filename (semanage_handle_t * sh, -char *data,size_t data_len,char **outfilename) { -int i, retval, num_modules =0 ; -char *module_name =NULL , *version =NULL , *filename =NULL ; -semanage_module_info_t *modinfo =NULL ; -if ((retval =parse_module_headers (sh, data, data_len, - &module_name, &version, - &filename)) !=0 ) { - goto cleanup; - } -if (semanage_direct_list (sh, &modinfo, &num_modules) <0 ) { - goto cleanup; - } - retval =-5 ; -for (i =0 ; i < num_modules; i++) { -semanage_module_info_t *m = -semanage_module_list_nth (modinfo, i); -if (strcmp (semanage_module_get_name (m), module_name) ==0 ) { -if (strverscmp (version,semanage_module_get_version (m)) - >0 ) { - retval =0 ; -break ; - }else { -ERR (sh,"Previous module %s is same or newer." , - module_name); - retval =-4 ; - goto cleanup; - } - } - } - cleanup: -free (version); -free (module_name); -for (i =0 ; modinfo !=NULL && i < num_modules; i++) { -semanage_module_info_t *m = -semanage_module_list_nth (modinfo, i); -semanage_module_info_datum_destroy (m); - } -free (modinfo); -if (retval ==0 ) { - *outfilename = filename; - }else { -free (filename); - } -return retval; -} -/* Similar to semanage_direct_install(), except that it checks that * there already exists a module with the same name and that the * module is an older version then the one in 'data'. Returns 0 on
@@ -1203,18 +1160,64 @@ static int get_direct_upgrade_filename(semanage_handle_t * sh,static int semanage_direct_upgrade (semanage_handle_t * sh,char *data,size_t data_len) { -char *filename =NULL ; -int retval =get_direct_upgrade_filename (sh, - data, data_len, - &filename); -if (retval ==0 ) { -if (bzip (sh, filename, data, data_len) <=0 ) { -ERR (sh,"Error while writing to %s." , filename); - retval =-3 ; - } -free (filename); +int status =0 ; +int ret =0 ; + +char *module_name =NULL , *version =NULL ; + status =parse_module_headers ( + sh, + data, + data_len, + &module_name, + &version); +if (status !=0 ) { + goto cleanup; } -return retval; + +semanage_module_info_t modinfo; + ret =semanage_module_info_init (sh, &modinfo); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_priority (sh, &modinfo, sh->priority); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_name (sh, &modinfo, module_name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_version (sh, &modinfo, version); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_lang_ext (sh, &modinfo,"pp" ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_enabled (sh, &modinfo,-1 ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + status =semanage_direct_upgrade_info (sh, &modinfo, data, data_len); + +cleanup: +free (module_name); +free (version); + +return status; }/* Attempts to link a module to the sandbox's module directory, unlinking any
@@ -1240,19 +1243,7 @@ static int semanage_direct_upgrade_file(semanage_handle_t * sh, goto cleanup; } -if (compressed) { -char *filename =NULL ; - retval =get_direct_upgrade_filename (sh, - data, data_len, - &filename); - -if (retval !=0 ) goto cleanup; - - retval =dupfile (filename, in_fd); -free (filename); - }else { - retval =semanage_direct_upgrade (sh, data, data_len); - } + retval =semanage_direct_upgrade (sh, data, data_len); cleanup:close (in_fd);
@@ -1270,22 +1261,62 @@ static int semanage_direct_upgrade_file(semanage_handle_t * sh,static int semanage_direct_install_base (semanage_handle_t * sh,char *base_data,size_t data_len) { -int retval =-1 ; -const char *filename =NULL ; -if ((retval =parse_base_headers (sh, base_data, data_len)) !=0 ) { +int status =0 ; +int ret =0 ; + + ret =parse_base_headers (sh, base_data, data_len); +if (ret !=0 ) { + status =-1 ; goto cleanup; } -if ((filename =semanage_path (SEMANAGE_TMP ,SEMANAGE_BASE )) ==NULL ) { + +semanage_module_info_t modinfo; + ret =semanage_module_info_init (sh, &modinfo); +if (ret !=0 ) { + status =-1 ; goto cleanup; } -if (bzip (sh, filename, base_data, data_len) <=0 ) { -ERR (sh,"Error while writing to %s." , filename); - retval =-3 ; + + ret =semanage_module_info_set_priority (sh, &modinfo, sh->priority); +if (ret !=0 ) { + status =-1 ; goto cleanup; } - retval =0 ; - cleanup: -return retval; + + ret =semanage_module_info_set_name (sh, &modinfo,"_base" ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_version (sh, &modinfo,"1.0.0" ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_lang_ext (sh, &modinfo,"pp" ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_module_info_set_enabled (sh, &modinfo,1 ); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + status =semanage_direct_install_info ( + sh, + &modinfo, + base_data, + data_len); + +cleanup: +semanage_module_info_destroy (sh, &modinfo); + +return status; }/* Writes a base module into a sandbox, overwriting any previous base
@@ -1310,19 +1341,7 @@ static int semanage_direct_install_base_file(semanage_handle_t * sh, goto cleanup; } -if (compressed) { -const char *filename =NULL ; -if ((retval =parse_base_headers (sh, data, data_len)) !=0 ) { - goto cleanup; - } -if ((filename =semanage_path (SEMANAGE_TMP ,SEMANAGE_BASE )) ==NULL ) { - goto cleanup; - } - - retval =dupfile (filename, in_fd); - }else { - retval =semanage_direct_install_base (sh, data, data_len); - } + retval =semanage_direct_install_base (sh, data, data_len); cleanup:close (in_fd);
@@ -1335,41 +1354,32 @@ static int semanage_direct_install_base_file(semanage_handle_t * sh,* of memory, -2 if module not found or could not be removed. */ static int semanage_direct_remove (semanage_handle_t * sh,char *module_name) { -int i, retval =-1 ; -char **module_filenames =NULL ; -int num_mod_files; -size_t name_len =strlen (module_name); -if (semanage_get_modules_names (sh, &module_filenames, &num_mod_files) == --1 ) { -return -1 ; +int status =0 ; +int ret =0 ; + +semanage_module_key_t modkey; + ret =semanage_module_key_init (sh, &modkey); +if (ret !=0 ) { + status =-1 ; + goto cleanup; } -for (i =0 ; i < num_mod_files; i++) { -char *base =strrchr (module_filenames[i],'/' ); -if (base ==NULL ) { -ERR (sh,"Could not read module names." ); - retval =-2 ; - goto cleanup; - } - base++; -if (memcmp (module_name, base, name_len) ==0 && -strcmp (base + name_len,".pp" ) ==0 ) { -if (unlink (module_filenames[i]) ==-1 ) { -ERR (sh,"Could not remove module file %s." , - module_filenames[i]); - retval =-2 ; - } - retval =0 ; - goto cleanup; - } + + ret =semanage_module_key_set_priority (sh, &modkey, sh->priority); +if (ret !=0 ) { + status =-1 ; + goto cleanup; } -ERR (sh,"Module %s was not found." , module_name); - retval =-2 ;/* module not found */ - cleanup: -for (i =0 ; module_filenames !=NULL && i < num_mod_files; i++) { -free (module_filenames[i]); + + ret =semanage_module_key_set_name (sh, &modkey, module_name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; } -free (module_filenames); -return retval; + + status =semanage_direct_remove_key (sh, &modkey); + +cleanup: +return status; }/* Allocate an array of module_info structures for each readable
@@ -1930,7 +1940,6 @@ cleanup:return status; } -__attribute__ ((unused))static int semanage_direct_set_module_info (semanage_handle_t *sh,const semanage_module_info_t *modinfo) {
@@ -2385,3 +2394,260 @@ cleanup:return status; } + +static int semanage_direct_install_info (semanage_handle_t *sh, +const semanage_module_info_t *modinfo, +char *data, +size_t data_len) +{ +assert (sh); +assert (modinfo); +assert (data); + +int status =0 ; +int ret =0 ; + +char path[PATH_MAX ]; + +semanage_module_info_t *higher_info =NULL ; +semanage_module_key_t higher_key; + ret =semanage_module_key_init (sh, &higher_key); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* validate module info */ + ret =semanage_module_info_validate (modinfo); +if (ret !=0 ) { + status =-2 ; + goto cleanup; + } + +/* Check for higher priority module and warn if there is one as +* it will override the module currently being installed. +*/ + ret =semanage_module_key_set_name (sh, &higher_key, modinfo->name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + + ret =semanage_direct_get_module_info (sh, &higher_key, &higher_info); +if (ret ==0 ) { +if (higher_info->priority > modinfo->priority) { + errno =0 ; +WARN (sh, +"A higher priority %s module exists at priority %d and will override the module currently being installed at priority %d." , + modinfo->name, + higher_info->priority, + modinfo->priority); + } +else if (higher_info->priority < modinfo->priority) { + errno =0 ; +INFO (sh, +"Overriding %s module at lower priority %d with module at priority %d." , + modinfo->name, + higher_info->priority, + modinfo->priority); + } + +if (higher_info->enabled ==0 && modinfo->enabled ==-1 ) { + errno =0 ; +WARN (sh, +"%s module will be disabled after install due to default enabled status." , + modinfo->name); + } + } + +/* set module meta data */ + ret =semanage_direct_set_module_info (sh, modinfo); +if (ret !=0 ) { + status =-2 ; + goto cleanup; + } + +/* install module source file */ + ret =semanage_module_get_path ( + sh, + modinfo, +SEMANAGE_MODULE_PATH_HLL , + path, +sizeof (path)); +if (ret !=0 ) { + status =-3 ; + goto cleanup; + } + + ret =bzip (sh, path, data, data_len); +if (ret <=0 ) { +ERR (sh,"Error while writing to %s." , path); + status =-3 ; + goto cleanup; + } + +cleanup: +semanage_module_key_destroy (sh, &higher_key); +semanage_module_info_destroy (sh, higher_info); +free (higher_info); + +return status; +} + +static int semanage_direct_upgrade_info (semanage_handle_t *sh, +const semanage_module_info_t *modinfo, +char *data, +size_t data_len) +{ +assert (sh); +assert (modinfo); +assert (data); + +int status =0 ; +int ret =0 ; + +semanage_module_info_t *existing =NULL ; + +/* get existing module data */ + ret =semanage_direct_get_module_info ( + sh, + (const semanage_module_key_t *)modinfo, + &existing); +if (ret ==0 ) { +/* verify this is an upgrade */ + ret =strverscmp (existing->version, modinfo->version); +if (ret >=0 ) { +ERR (sh, +"Existing module %s version %s >= %s." , + existing->name, + existing->version, + modinfo->version); + status =-4 ; + goto cleanup; + } + } + +/* install the module */ + status =semanage_direct_install_info (sh, modinfo, data, data_len); + +cleanup: +semanage_module_info_destroy (sh, existing); +free (existing); + +return status; +} + +static int semanage_direct_remove_key (semanage_handle_t *sh, +const semanage_module_key_t *modkey) +{ +assert (sh); +assert (modkey); + +int status =0 ; +int ret =0 ; + +char path[PATH_MAX ]; +semanage_module_info_t *modinfo =NULL ; + +semanage_module_key_t modkey_tmp; + ret =semanage_module_key_init (sh, &modkey_tmp); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* validate module key */ + ret =semanage_module_validate_priority (modkey->priority); +if (ret !=0 ) { + errno =0 ; +ERR (sh,"Priority %d is invalid." , modkey->priority); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_validate_name (modkey->name); +if (ret !=0 ) { + errno =0 ; +ERR (sh,"Name %s is invalid." , modkey->name); + status =-1 ; + goto cleanup; + } + + ret =semanage_module_key_set_name (sh, &modkey_tmp, modkey->name); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +/* get module path */ + ret =semanage_module_get_path ( + sh, + (const semanage_module_info_t *)modkey, +SEMANAGE_MODULE_PATH_NAME , + path, +sizeof (path)); +if (ret !=0 ) { + status =-2 ; + goto cleanup; + } + +/* remove directory */ + ret =semanage_remove_directory (path); +if (ret !=0 ) { +ERR (sh,"Unable to remove module directory %s." , path); + status =-2 ; + goto cleanup; + } + +/* check if its the last module at any priority */ + ret =semanage_module_get_module_info (sh, &modkey_tmp, &modinfo); +if (ret !=0 ) { +/* info that no other module will override */ + errno =0 ; +INFO (sh, +"Removing last %s module (no other %s module exists at another priority)." , + modkey->name, + modkey->name); + +/* remove disabled status file */ + ret =semanage_module_get_path ( + sh, + (const semanage_module_info_t *)modkey, +SEMANAGE_MODULE_PATH_DISABLED , + path, +sizeof (path)); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + +struct stat sb; +if (stat (path, &sb) ==0 ) { + ret =unlink (path); +if (ret !=0 ) { + status =-1 ; + goto cleanup; + } + } + } +else { +/* if a lower priority module is going to become active */ +if (modkey->priority > modinfo->priority) { +/* inform what the new active module will be */ + errno =0 ; +INFO (sh, +"%s module at priority %d is now active." , + modinfo->name, + modinfo->priority); + } + } + +cleanup: +semanage_module_key_destroy (sh, &modkey_tmp); + +semanage_module_info_destroy (sh, modinfo); +free (modinfo); + +return status; +} +
libsemanage/src/modules.c +61 -0
64 lines not on this page · raw message
libsemanage/src/modules.h +48 -0
52 lines not on this page · raw message
libsemanage/src/policy.h +15 -0
@@ -91,6 +91,21 @@ struct semanage_policy_table { semanage_module_info_t **, int *); +/* Install via module info */ +int (*install_info) (struct semanage_handle *, +const semanage_module_info_t *, +char *, +size_t ); + +/* Upgrade via module info */ +int (*upgrade_info) (struct semanage_handle *, +const semanage_module_info_t *, +char *, +size_t ); + +/* Remove via module key */ +int (*remove_key) (struct semanage_handle *, +const semanage_module_key_t *); };/* Should be backend independent */
libsemanage/src/semanage_store.c +130 -47
238 lines not on this page · raw message
libsemanage/src/semanage_store.h +0 -1
@@ -39,7 +39,6 @@ enum semanage_store_defs {enum semanage_sandbox_defs {SEMANAGE_TOPLEVEL ,SEMANAGE_MODULES , -SEMANAGE_BASE ,SEMANAGE_LINKED ,SEMANAGE_HOMEDIR_TMPL ,SEMANAGE_FC_TMPL ,
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 11/13 libsemanage: new private api for unstable functions
Rather than export the new functions as part of the stable API we chose to create a private API. The private API is unstable, may change in the future, and is mainly intended to be used by upstream tools like semodule. Keeping these new APIs private for a time will allow them to both get tested through upstream tools and be changed as necessary without causing the same change burdens as they would if they were in the public API.
The private API is found in the includes:
include/semanage/private/handle.h
* Exports the handle get/set default priority functions.
include/semanage/private/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/private/semanage.h
* Includes the other private headers.
This patch includes the modifications to the map file for exporting the necessary functions.
Internal prototypes were moved to the private API and the private headers included as necessary.
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);
}
---
libsemanage/include/Makefile | 3 +
libsemanage/include/semanage/private/handle.h | 31 +++
libsemanage/include/semanage/private/modules.h | 281 +++++++++++++++++++++++
libsemanage/include/semanage/private/semanage.h | 26 ++
libsemanage/src/handle_internal.h | 1 +
libsemanage/src/libsemanage.map | 26 ++
libsemanage/src/module_internal.h | 21 ++
libsemanage/src/modules.c | 40 ++++
libsemanage/src/modules.h | 253 +--------------------
9 files changed, 431 insertions(+), 251 deletions(-)
create mode 100644 libsemanage/include/semanage/private/handle.h
create mode 100644 libsemanage/include/semanage/private/modules.h
create mode 100644 libsemanage/include/semanage/private/semanage.hlibsemanage/include/Makefile +3 -0
@@ -5,6 +5,9 @@ INCDIR ?= $(PREFIX)/include/semanage install: test -d $(INCDIR) || install -m 755 -d $(INCDIR) install -m 644 $(wildcard semanage/*.h) $(INCDIR) + test -d $(INCDIR)/private || install -m 755 -d $(INCDIR)/private + install -m 644 $(wildcard semanage/private/*.h) $(INCDIR)/private indent: ../../scripts/Lindent $(wildcard semanage/*.h) + ../../scripts/Lindent $(wildcard semanage/private/*.h)
libsemanage/include/semanage/private/handle.h new file +31 -0
@@ -0,0 +1,31 @@ +/* Authors: Caleb Case <[email protected]> +* +* Copyright (C) 2009 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_PRIVATE_HANDLE_H_ +#define _SEMANAGE_PRIVATE_HANDLE_H_ + +#include <stdint.h> + +/* Get the default priority. */ +uint16_t semanage_get_default_priority (semanage_handle_t *sh); + +/* Set the default priority. */ +int semanage_set_default_priority (semanage_handle_t *sh,uint16_t priority); + +#endif
libsemanage/include/semanage/private/modules.h new file +281 -0
281 lines not on this page · raw message
libsemanage/include/semanage/private/semanage.h new file +26 -0
@@ -0,0 +1,26 @@ +/* Authors: Caleb Case <[email protected]> +* +* Copyright (C) 2009 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_PRIVATE_SEMANAGE_H_ +#define _SEMANAGE_PRIVATE_SEMANAGE_H_ + +#include <semanage/private/handle.h> +#include <semanage/private/modules.h> + +#endif
libsemanage/src/handle_internal.h +1 -0
@@ -2,6 +2,7 @@#define _SEMANAGE_HANDLE_INTERNAL_H_#include <semanage/handle.h> +#include <semanage/private/handle.h> #include "dso.h" hidden_proto (semanage_begin_transaction)
libsemanage/src/libsemanage.map +26 -0
@@ -18,5 +18,31 @@ LIBSEMANAGE_1.0 { semanage_is_connected; semanage_get_disable_dontaudit; semanage_set_disable_dontaudit; semanage_mls_enabled; semanage_set_check_contexts; + semanage_get_default_priority; semanage_set_default_priority; + semanage_module_info_create; + semanage_module_info_destroy; + semanage_module_info_get_priority; + semanage_module_info_get_name; + semanage_module_info_get_version; + semanage_module_info_get_lang_ext; + semanage_module_info_get_enabled; + semanage_module_info_set_priority; + semanage_module_info_set_name; + semanage_module_info_set_version; + semanage_module_info_set_lang_ext; + semanage_module_info_set_enabled; + semanage_module_key_create; + semanage_module_key_destroy; + semanage_module_key_get_priority; + semanage_module_key_get_name; + semanage_module_key_set_priority; + semanage_module_key_set_name; + semanage_module_get_module; + semanage_module_list_all; + semanage_module_get_enabled; + semanage_module_set_enabled; + semanage_module_install_info; + semanage_module_upgrade_info; + semanage_module_remove_key; local: *; };
libsemanage/src/module_internal.h +21 -0
@@ -2,10 +2,31 @@#define _SEMANAGE_MODULE_INTERNAL_H_#include <semanage/modules.h> +#include <semanage/private/modules.h> #include "dso.h" hidden_proto(semanage_module_get_name) hidden_proto(semanage_module_get_version) hidden_proto(semanage_module_info_datum_destroy) hidden_proto(semanage_module_list_nth) + hidden_proto(semanage_module_info_create) + hidden_proto(semanage_module_info_destroy) + hidden_proto(semanage_module_info_get_priority) + hidden_proto(semanage_module_info_get_name) + hidden_proto(semanage_module_info_get_version) + hidden_proto(semanage_module_info_get_lang_ext) + hidden_proto(semanage_module_info_get_enabled) + hidden_proto(semanage_module_info_set_priority) + hidden_proto(semanage_module_info_set_name) + hidden_proto(semanage_module_info_set_version) + hidden_proto(semanage_module_info_set_lang_ext) + hidden_proto(semanage_module_info_set_enabled) + hidden_proto(semanage_module_key_create) + hidden_proto(semanage_module_key_destroy) + hidden_proto(semanage_module_key_get_priority) + hidden_proto(semanage_module_key_get_name) + hidden_proto(semanage_module_key_set_priority) + hidden_proto(semanage_module_key_set_name) + hidden_proto(semanage_module_get_enabled) + hidden_proto(semanage_module_set_enabled)#endif
libsemanage/src/modules.c +40 -0
@@ -246,6 +246,8 @@ int semanage_module_info_create(semanage_handle_t *sh,return semanage_module_info_init (sh, *modinfo); } +hidden_def (semanage_module_info_create) + int semanage_module_info_destroy(semanage_handle_t *sh,semanage_module_info_t *modinfo) {
@@ -262,6 +264,8 @@ int semanage_module_info_destroy(semanage_handle_t *sh,return semanage_module_info_init (sh, modinfo); } +hidden_def (semanage_module_info_destroy) + int semanage_module_info_init(semanage_handle_t *sh,semanage_module_info_t *modinfo) {
@@ -342,6 +346,8 @@ int semanage_module_info_get_priority(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_get_priority) + int semanage_module_info_get_name(semanage_handle_t *sh, semanage_module_info_t *modinfo,const char **name)
@@ -355,6 +361,8 @@ int semanage_module_info_get_name(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_get_name) + int semanage_module_info_get_version(semanage_handle_t *sh, semanage_module_info_t *modinfo,const char **version)
@@ -368,6 +376,8 @@ int semanage_module_info_get_version(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_get_version) + int semanage_module_info_get_lang_ext(semanage_handle_t *sh, semanage_module_info_t *modinfo,const char **lang_ext)
@@ -381,6 +391,8 @@ int semanage_module_info_get_lang_ext(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_get_lang_ext) + int semanage_module_info_get_enabled(semanage_handle_t *sh, semanage_module_info_t *modinfo,int *enabled)
@@ -394,6 +406,8 @@ int semanage_module_info_get_enabled(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_get_enabled) + int semanage_module_info_set_priority(semanage_handle_t *sh, semanage_module_info_t *modinfo,uint16_t priority)
@@ -413,6 +427,8 @@ int semanage_module_info_set_priority(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_set_priority) + int semanage_module_info_set_name(semanage_handle_t *sh, semanage_module_info_t *modinfo,const char *name)
@@ -441,6 +457,8 @@ int semanage_module_info_set_name(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_set_name) + int semanage_module_info_set_version(semanage_handle_t *sh, semanage_module_info_t *modinfo,const char *version)
@@ -469,6 +487,8 @@ int semanage_module_info_set_version(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_set_version) + int semanage_module_info_set_lang_ext(semanage_handle_t *sh, semanage_module_info_t *modinfo,const char *lang_ext)
@@ -497,6 +517,8 @@ int semanage_module_info_set_lang_ext(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_info_set_lang_ext) + int semanage_module_info_set_enabled(semanage_handle_t *sh, semanage_module_info_t *modinfo,int enabled)
@@ -516,6 +538,8 @@ int semanage_module_info_set_enabled(semanage_handle_t *sh,return 0 ; } +hidden_def(semanage_module_info_set_enabled) + int semanage_module_get_path(semanage_handle_t *sh, const semanage_module_info_t *modinfo, enum semanage_module_path_type type,
@@ -721,6 +745,8 @@ int semanage_module_key_create(semanage_handle_t *sh,return semanage_module_key_init (sh, *modkey); } +hidden_def (semanage_module_key_create) + int semanage_module_key_destroy(semanage_handle_t *sh,semanage_module_key_t *modkey) {
@@ -733,6 +759,8 @@ int semanage_module_key_destroy(semanage_handle_t *sh,return semanage_module_key_init (sh, modkey); } +hidden_def (semanage_module_key_destroy) + int semanage_module_key_init(semanage_handle_t *sh,semanage_module_key_t *modkey) {
@@ -758,6 +786,8 @@ int semanage_module_key_get_name(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_key_get_name) + int semanage_module_key_get_priority(semanage_handle_t *sh, semanage_module_key_t *modkey,uint16_t *priority)
@@ -771,6 +801,8 @@ int semanage_module_key_get_priority(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_key_get_priority) + int semanage_module_key_set_name(semanage_handle_t *sh, semanage_module_key_t *modkey,const char *name)
@@ -801,6 +833,8 @@ cleanup:return status; } +hidden_def (semanage_module_key_set_name) + int semanage_module_key_set_priority(semanage_handle_t *sh, semanage_module_key_t *modkey,uint16_t priority)
@@ -819,6 +853,8 @@ int semanage_module_key_set_priority(semanage_handle_t *sh,return 0 ; } +hidden_def (semanage_module_key_set_priority) + int semanage_module_get_enabled(semanage_handle_t *sh,const semanage_module_key_t *modkey,int *enabled)
@@ -839,6 +875,8 @@ int semanage_module_get_enabled(semanage_handle_t *sh,return sh->funcs->get_enabled (sh, modkey, enabled); } +hidden_def (semanage_module_get_enabled) + int semanage_module_set_enabled(semanage_handle_t *sh,const semanage_module_key_t *modkey,int enabled)
@@ -863,6 +901,8 @@ int semanage_module_set_enabled(semanage_handle_t *sh,return sh->funcs->set_enabled (sh, modkey, enabled); } +hidden_def (semanage_module_set_enabled) +/* Converts a string to a priority * * returns -1 if str is not a valid priority.
libsemanage/src/modules.h +2 -251
283 lines not on this page · raw message
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 12/13 semodule: add priority, enabled, and extended listing
This updates the semodule tool with the ability to set the priority for commands, to enable/disable modules, and extended module listing options for displaying extra module information (e.g., priority, enabled status, and language extension).
[semodule priority]
-p --priority set the priority for following operations
Notes:
* This sets the priority for the following operations.
* It can be used any number of times with its effect continuing until the next priority is specified.
* The default priority is used if no priority has yet been specified.
Impact on current operations:
* Install module
* Without priority - Install at default priority.
* With priority - Install at specified priority.
* New warning when overriding (issued by libsemanage).
* Upgrade module
* Without priority - Upgrade at default priority (current upgrade semantics apply).
* With priority - Upgrade at specified priority (current upgrade semantics apply).
* New warning when overriding (issued by libsemanage).
* Remove module
* Without priority - Remove a module at the default if exists.
* With priority - Remove at that priority.
* New info messages (issued by libsemanage):
* If no modules exist at the given priority but do exist at other priorities, give an info message listing the modules and priority.
* If a new module at a lower priority will become active print a message.
* If the last module with this name is being removed print a message.
* Base
* The name of base module on install is fixed to "_base" (performed by libsemanage).
* Without priority - Install at default priority.
* With priority - Install at specified priority.
* New warning when overriding (issued by libsemanage).
* List modules
* See listing changes below.
Examples:
# install a module at default - this will install the module at priority 400 semodule -i foo.pp
# Install a module at a specific priority
semodule -p 500 -i foo.pp
[semodule enable/disable]
Add enable/disable status:
-e --enable enable the module (at all priorities) -d --disable disable the module (at all priorities)
Notes:
* Base modules are always enabled and cannot have their enabled/disabled status changed.
* New error when disabling a base module (from libsemanage).
* New warning when enabling a base module (from libsemanage).
Impact on current operations:
* Install module
* If a module with that name is already installed, then the enabled status will remain the same after installing the new module.
* New warning when installing a module which will be disabled by existing enabled status (from libsemanage).
* Upgrade module
* If a module with that name is already installed, then the enabled status will remain the same after installing the new module.
* New warning when installing a module which will be disabled by existing enabled status (from libsemanage).
* Remove module
* When the last module with a given name is removed (no more exist at other priorities) then the enabled status is forgotten.
* Base
* Base modules are always installed enabled and remain so (can't be disabled).
* List modules
* See listing changes below.
Examples:
# enable module semodule -e foo
# disable module semodule -d foo
[semodule list]
-l --list list modules as if by -lstandard
-lstandard --list=standard list name and version of highest priority,
enabled, non-base modules sorted alphabetical by name
-lfull --list=full list all fields of all modules columnated
sorted high priority to low, within priority alphabetical by name
Impact on current operations:
* List modules
* Default listing stays the same.
* New long options for 'standard' and 'full'.
Examples:
# list modules using standard method semodule -l semodule -lstandard semodule --list=standard
alsa 1.7.1
apm 1.9.1
apt 1.5.2
authlogin 2.0.0
avahi 1.10.3
bluetooth 3.1.3
...
# list modules using full method semodule -lfull semodule --list=full
600 alsa 1.7.1 disabled pp 400 _base 1.0.0 pp 400 alsa 1.7.1 disabled pp 400 apm 1.9.1 pp 400 apt 1.5.2 pp 400 authlogin 2.0.0 pp ... 100 alsa 1.7.1 disabled pp --- policycoreutils/semodule/semodule.8 | 25 ++++- policycoreutils/semodule/semodule.c | 242 +++++++++++++++++++++++++++++++---- 2 files changed, 239 insertions(+), 28 deletions(-)
policycoreutils/semodule/semodule.8 +24 -1
@@ -38,9 +38,26 @@ install/replace base module package .B \-r,\-\-remove=MODULE_NAME remove existing module .TP -.B \-l,\-\-list-modules +.B \-l,\-\-list-modules=[KIND] display list of installed modules (other than base) .TP +.B KIND: +.TP +standard +list highest priority, enabled, non-base modules +.TP +full +list all modules +.TP +.B \-p,\-\-priority=PRIORITY +set priority for following operations (1-999) +.TP +.B \-e,\-\-enabled=MODULE_NAME +enable module +.TP +.B \-d,\-\-disable=MODULE_NAME +disable module +.TP .B \-s,\-\-store name of the store to operate on .TP
@@ -69,6 +86,12 @@ $ semodule -B $ semodule -i *.pp # Install or replace all modules in the current directory. $ ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -b base.pp -i +# Disable a module. +$ semodule -d alsa +# Install a module at a specific priority. +$ semodule -p 100 -i alsa.pp +# List all modules. +$ semodule -l full .fi .SH SEE ALSO
policycoreutils/semodule/semodule.c +215 -27
318 lines not on this page · raw message
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 13/13 semanage store migration script
We created a migration script to ease the burden of transition from the old libsemanage store layout to the new. The script will detect all the stores in /etc/selinux using the old layout and convert them to the new layout in /var/lib/selinux. It also allows you to specify the default priority to use with -p and store to operate on with -s. After migration the script by default will leave the old store unchanged, but can be told to remove the old modules directory with -c.
Examples:
# Migrate all stores to the new layout.migrate.py
Migrating from /etc/selinux/targeted/modules/active to /var/lib/selinux/targeted/active Attempting to rebuild policy from /var/lib/selinux
# Migrate only the targeted store.migrate.py -s targeted
Migrating from /etc/selinux/targeted/modules/active to /var/lib/selinux/targeted/active Attempting to rebuild policy from /var/lib/selinux
# Migrate all, but install to priority 150.migrate.py -p 150
Migrating from /etc/selinux/targeted/modules/active to /var/lib/selinux/targeted/active Attempting to rebuild policy from /var/lib/selinux
--- libsemanage/utils/semanage_migrate_etc_to_var.py | 301 ++++++++++++++++++++++ 1 files changed, 301 insertions(+), 0 deletions(-) create mode 100755 libsemanage/utils/semanage_migrate_etc_to_var.py
libsemanage/utils/semanage_migrate_etc_to_var.py new file +301 -0
@@ -0,0 +1,301 @@ +#!/usr/bin/python -E + + +import os +import errno +import shutil +import sys +from optparse import OptionParser + +import bz2 +import ctypes + +sepol = ctypes.cdll.LoadLibrary('libsepol.so') + +try: + import selinux + import semanage +except: + print >> sys.stderr, "You must install libselinux-python and libsemanage-python before running this tool" + exit(1) + + + + +# For some reason this function doesn't exist in libselinux :\ +def copy_with_context(src, dst): + if DEBUG: + print "copying %s to %s" % (src, dst) + try: + con = selinux.lgetfilecon_raw(src)[1] + except: + print >> sys.stderr, "Could not get file context of %s" % src + exit(1) + + try: + selinux.setfscreatecon_raw(con) + except: + print >> sys.stderr, "Could not set fs create context: %s" %con + exit(1) + + try: + shutil.copy2(src, dst) + except OSError as (err, strerr): + print >> sys.stderr, "Could not copy %s to %s, %s" %(src, dst, strerr) + +def create_dir_from(src, dst, mode): + if DEBUG: print "Making directory %s" % dst + try: + con = selinux.lgetfilecon_raw(src)[1] + selinux.setfscreatecon_raw(con) + os.mkdir(dst, mode) + except OSError as (err, stderr): + if err == errno.EEXIST: + pass + else: + print >> sys.stderr, "Error creating %s" % dst + exit(1) + +def copy_module(store, name, con, base): + if DEBUG: print "Install module %s" % name + (file, ext) = os.path.splitext(name) + if ext != ".pp": + # Stray non-pp file in modules directory, skip + print >> sys.stderr, "warning: %s has invalid extension, skipping" % name + return + try: + selinux.setfscreatecon_raw(con) + + if base: + root = oldstore_path(store) + else: + root = oldmodules_path(store) + + bottomdir = bottomdir_path(store) + + # Special case "base" since you can have modules named base + if base: + file = "_base" + + os.mkdir("%s/%s" % (bottomdir, file)) + + copy_with_context(os.path.join(root, name), "%s/%s/%s%s" % (bottomdir, file, file, ext)) + + # This is the ext file that will eventually be used to choose a compiler + efile = open("%s/%s/lang_ext" % (bottomdir, file), "w+", 0600) + efile.write("pp") + efile.close() + + # This is the version file that stores the version of the module + version = "1.0.0" + if not base: + try: + pf = ctypes.c_void_p() + sepol.sepol_policy_file_create(ctypes.byref(pf)) + + pbuffer = None + try: + pbuffer = bz2.BZ2File(os.path.join(root, name)).read() + except: + pbuffer = open(os.path.join(root, name)).read() + + if (pbuffer == None): + raise Exception("Unable read policy file into memory.") + + cbuffer = ctypes.create_string_buffer(pbuffer) + sepol.sepol_policy_file_set_mem(pf, cbuffer, len(cbuffer)) + + header_file_type = ctypes.c_int() + header_name = ctypes.c_char_p() + header_version = ctypes.c_char_p() + + ret = sepol.sepol_module_package_info(pf, ctypes.byref(header_file_type), ctypes.byref(header_name), ctypes.byref(header_version)) + if (ret != 0): + raise Exception("Unable to parse package header.") + + version = header_version.value + + sepol.sepol_policy_file_free(pf) + + except Exception as e: + print >> sys.stderr, e + print >> sys.stderr, "warning: unable to determine version, using default value" + + efile = open("%s/%s/version" % (bottomdir, file), "w+", 0600) + efile.write(version) + efile.close() + + except: + print >> sys.stderr, "Error installing module %s" % name + +def migrate_store(store): + + oldstore = oldstore_path(store); + oldmodules = oldmodules_path(store); + newstore = newstore_path(store); + newmodules = newmodules_path(store); + bottomdir = bottomdir_path(store); + + print "Migrating from %s to %s" % (oldstore, newstore) + + # Build up new directory structure + create_dir_from(selinux.selinux_policy_root(), "%s/%s" % (newroot_path(), store), 0755) + create_dir_from(oldmodules, newstore, 0700) + create_dir_from(oldstore, newmodules, 0700) + create_dir_from(oldstore, bottomdir, 0700) + + # use whatever the file context of bottomdir is for the module directories + con = selinux.lgetfilecon_raw(bottomdir)[1] + + # Special case for base since it was in a different location + copy_module(store, "base.pp", con, 1) + + # Dir structure built, start copying files + for root, dirs, files in os.walk(oldstore): + if root == oldstore: + # This is the top level directory, need to move + for name in files: + # Check to see if it is in TOPPATHS and copy if so + if name in TOPPATHS: + copy_with_context(os.path.join(root, name), os.path.join(newstore, name)) + + elif root == oldmodules: + # This should be the modules directory + for name in files: + copy_module(store, name, con, 0) + +def rebuild_policy(): + # Ok, the modules are loaded, lets try to rebuild the policy + print "Attempting to rebuild policy from %s" % newroot_path() + + curstore = selinux.selinux_getpolicytype()[1] + + handle = semanage.semanage_handle_create() + if not handle: + print >> sys.stderr, "Could not create semanage handle" + exit(1) + + semanage.semanage_select_store(handle, curstore, semanage.SEMANAGE_CON_DIRECT) + + if not semanage.semanage_is_managed(handle): + semanage.semanage_handle_destroy(handle) + print >> sys.stderr, "SELinux policy is not managed or store cannot be accessed." + exit(1) + + rc = semanage.semanage_access_check(handle) + if rc < semanage.SEMANAGE_CAN_WRITE: + semanage.semanage_handle_destroy(handle) + print >> sys.stderr, "Cannot write to policy store." + exit(1) + + rc = semanage.semanage_connect(handle) + if rc < 0: + semanage.semanage_handle_destroy(handle) + print >> sys.stderr, "Could not establish semanage connection" + exit(1) + + semanage.semanage_set_rebuild(handle, 1) + + rc = semanage.semanage_begin_transaction(handle) + if rc < 0: + semanage.semanage_handle_destroy(handle) + print >> sys.stderr, "Could not begin transaction" + exit(1) + + rc = semanage.semanage_commit(handle) + if rc < 0: + print >> sys.stderr, "Could not commit transaction" + + semanage.semanage_handle_destroy(handle) + + +def oldroot_path(): + return "/etc/selinux" + +def oldstore_path(store): + return "%s/%s/modules/active" % (oldroot_path(), store) + +def oldmodules_path(store): + return "%s/modules" % oldstore_path(store) + +def newroot_path(): + return "/var/lib/selinux" + +def newstore_path(store): + return "%s/%s/active" % (newroot_path(), store) + +def newmodules_path(store): + return "%s/modules" % newstore_path(store) + +def bottomdir_path(store): + return "%s/%s" % (newmodules_path(store), PRIORITY) + + +if __name__ == "__main__": + + parser = OptionParser() + parser.add_option("-p", "--priority", dest="priority", default="100", + help="Set priority of modules in new store (default: 100)") + parser.add_option("-s", "--store", dest="store", default=None, + help="Store to read from and write to") + parser.add_option("-d", "--debug", dest="debug", action="store_true", default=False, + help="Output debug information") + parser.add_option("-c", "--clean", dest="clean", action="store_true", default=False, + help="Clean old modules directory after migrate (default: no)") + + (options, args) = parser.parse_args() + + DEBUG = options.debug + PRIORITY = options.priority + TYPE = options.store + CLEAN = options.clean + + # List of paths that go in the active 'root' + TOPPATHS = [ + "file_contexts", + "homedir_template", + "file_contexts.template", + "commit_num", + "ports.local", + "interfaces.local", + "nodes.local", + "booleans.local", + "file_contexts.local", + "seusers", + "users.local", + "users_extra.local", + "seusers.final", + "users_extra", + "netfilter_contexts", + "file_contexts.homedirs", + "disable_dontaudit" ] + + + create_dir_from(oldroot_path(), newroot_path(), 0755) + + stores = None + if TYPE is not None: + stores = [TYPE] + else: + stores = os.listdir(oldroot_path()) + + # find stores in oldroot and migrate them to newroot if necessary + for store in stores: + if not os.path.isdir(oldmodules_path(store)): + # already migrated or not an selinux store + continue + + if os.path.isdir(newstore_path(store)): + # store has already been migrated, but old modules dir still exits + print >> sys.stderr, "warning: Policy type %s has already been migrated, but modules still exist in the old store. Skipping store." % store + continue + + migrate_store(store) + + if CLEAN is True: + def remove_error(function, path, execinfo): + print >> sys.stderr, "warning: Unable to remove old store modules directory %s. Cleaning failed." % oldmodules_path(store) + shutil.rmtree(oldmodules_path(store), onerror=remove_error) + + rebuild_policy() +
Signature · 7 lines
1.6.0.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 13/13] semanage store migration script
Quoted 19 lines · Caleb Case
We created a migration script to ease the burden of transition from the old libsemanage store layout to the new. The script will detect all the stores in
/etc/selinuxusing the old layout and convert them to the new layout in/var/lib/selinux. It also allows you to specify the default priority to use with -p and store to operate on with -s. After migration the script by default will leave the old store unchanged, but can be told to remove the old modules directory with -c.Examples:
# Migrate all stores to the new layout.
migrate.pyMigrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinux# Migrate only the targeted store.
migrate.py-s targeted
Quoted 8 lines
Migrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinux# Migrate all, but install to priority 150.
migrate.py-p 150Migrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinux
I tried the following:
semanage login -a -s user_u pi
cp -a /etc/selinux /etc/selinux.orig
install new userlandmigrate.py
diff -ru /etc/selinux.orig /etc/selinux
The seusers entry for "pi" was dropped from the final seusers file in the rebuilt policy.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 13/13] semanage store migration script
Quoted 36 lines · Stephen Smalley
Quoted 19 lines · Caleb Case
We created a migration script to ease the burden of transition from the old libsemanage store layout to the new. The script will detect all the stores in
/etc/selinuxusing the old layout and convert them to the new layout in/var/lib/selinux. It also allows you to specify the default priority to use with -p and store to operate on with -s. After migration the script by default will leave the old store unchanged, but can be told to remove the old modules directory with -c.Examples:
# Migrate all stores to the new layout.
migrate.pyMigrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinux# Migrate only the targeted store.
migrate.py-s targetedQuoted 8 lines
Migrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinux# Migrate all, but install to priority 150.
migrate.py-p 150Migrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinuxI tried the following:
semanage login -a -suser_upi
cp -a/etc/selinux/etc/selinux.orig
install new userlandmigrate.py
diff -ru/etc/selinux.orig/etc/selinux
Quoted 3 lines
The seusers entry for "pi" was dropped from the final seusers file in the rebuilt policy.
I saw the same thing. I added a new login, but it does not show up after the migration with "semanage login -l" even though it is in /var/lib/selinux/targeted/active/seusers and seusers.final.
booleans, ports, file contexts, and permissive domains all show up after the migration, but there are some other issues.
1) For booleans I am getting this error:
# semanage boolean --on git_system_use_cifs
Traceback (most recent call last):
File "/usr/sbin/semanage", line 460, in <module>
process_args(sys.argv[1:])
File "/usr/sbin/semanage", line 407, in process_args
raise ValueError(_("Invalid command") % " ".join(argv))
TypeError: not all arguments converted during string formatting2) Either the priority stuff doesn't work or I am doing something wrong. Shouldn't either of the following not display any modules since they are all at priority 100?
"semodule -p 900 -l" or "semodule -p 900; semodule -l"
Both display all modules.
3) I can't remove the permissive domain created before the migration because the default priority level is 400, but the script put everything at priority 100 and I don't know how to change the priority for semanage.
# semanage permissive -d httpd_t libsemanage.semanage_direct_remove_key: Unable to remove module directory /var/lib/selinux/targeted/tmp/modules/400/permissive_httpd_t. (No such file or directory). /usr/sbin/semanage: Could not remove permissive domain httpd_t (remove failed)
Ports and file contexts addition and removal seems to work fine.
Signature · 9 lines
James Carter <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 13/13] semanage store migration script
Quoted 37 lines · James Carter
Quoted 36 lines · Stephen Smalley
Quoted 19 lines · Caleb Case
We created a migration script to ease the burden of transition from the old libsemanage store layout to the new. The script will detect all the stores in
/etc/selinuxusing the old layout and convert them to the new layout in/var/lib/selinux. It also allows you to specify the default priority to use with -p and store to operate on with -s. After migration the script by default will leave the old store unchanged, but can be told to remove the old modules directory with -c.Examples:
# Migrate all stores to the new layout.
migrate.pyMigrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinux# Migrate only the targeted store.
migrate.py-s targetedQuoted 8 lines
Migrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinux# Migrate all, but install to priority 150.
migrate.py-p 150Migrating from
/etc/selinux/targeted/modules/activeto/var/lib/selinux/targeted/activeAttempting to rebuild policy from/var/lib/selinuxI tried the following:
semanage login -a -suser_upi
cp -a/etc/selinux/etc/selinux.orig
install new userlandmigrate.py
diff -ru/etc/selinux.orig/etc/selinux
Quoted 7 lines
Quoted 3 lines
The seusers entry for "pi" was dropped from the final seusers file in the rebuilt policy.
I saw the same thing. I added a new login, but it does not show up after the migration with "semanage login -l" even though it is in
/var/lib/selinux/targeted/active/seusersand seusers.final.
I also noticed that /etc/selinux/targeted/seusers lacks the header comments (This file is auto-generated...). Searching /var/lib/selinux for a matching file, I find only one file - the seusers file in the minimum policy tree. How that ends up getting installed as the seusers file for targeted is a mystery to me...
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
RE: [PATCH 13/13] semanage store migration script
In reply to James CarterQuoted 11 lines
-----Original Message-----
From: James Carter [mailto:[email protected]]
Sent: Friday, January 08, 2010 4:00 PM
To: Stephen Smalley
Cc: Caleb Case; [email protected]; Chad Sellers; Karl MacMillan; Joshua Brindle
Subject: Re: [PATCH 13/13] semanage store migration scriptQuoted 2 lines · Stephen Smalley
Quoted 1 line · Caleb Case
We created a migration script to ease the burden of transition
from
Quoted 2 lines
the
Quoted 1 line
Quoted 1 line
old libsemanage store layout to the new. The script will detect
all
Quoted 2 lines
the
Quoted 1 line
Quoted 1 line
stores in
/etc/selinuxusing the old layout and convert them to
the
Quoted 2 lines
new
Quoted 1 line
Quoted 1 line
layout in
/var/lib/selinux. It also allows you to specify the
default
Quoted 3 lines
Quoted 1 line
Quoted 1 line
priority to use with -p and store to operate on with -s. After
migration
Quoted 1 line
Quoted 1 line
the script by default will leave the old store unchanged, but can
be
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
told to remove the old modules directory with -c.
Examples:
# Migrate all stores to the new layout.
migrate.pyMigrating from
/etc/selinux/targeted/modules/activeto
/var/lib/selinux/targeted/activeQuoted 6 lines
Quoted 6 lines
Attempting to rebuild policy from
/var/lib/selinux# Migrate only the targeted store.
migrate.py-s targetedMigrating from
/etc/selinux/targeted/modules/activeto
Quoted 18 lines
/var/lib/selinux/targeted/activeQuoted 6 lines
Quoted 6 lines
Attempting to rebuild policy from
/var/lib/selinux# Migrate all, but install to priority 150.
migrate.py-p 150Migrating from
/etc/selinux/targeted/modules/activeto
/var/lib/selinux/targeted/activeQuoted 10 lines
Quoted 1 line
Attempting to rebuild policy from
/var/lib/selinuxI tried the following:
semanage login -a -suser_upi
cp -a/etc/selinux/etc/selinux.orig
install new userlandmigrate.py
diff -ru/etc/selinux.orig/etc/selinuxThe seusers entry for "pi" was dropped from the final seusers file
in
Quoted 8 lines
Quoted 2 lines
the rebuilt policy.
I saw the same thing. I added a new login, but it does not show up after the migration with "semanage login -l" even though it is in
/var/lib/selinux/targeted/active/seusersand seusers.final.booleans, ports, file contexts, and permissive domains all show up
after
Quoted 15 lines
the migration, but there are some other issues.
1) For booleans I am getting this error:
# semanage boolean --on git_system_use_cifs Traceback (most recent call last): File "/usr/sbin/semanage", line 460, in <module> process_args(sys.argv[1:]) File "/usr/sbin/semanage", line 407, in process_args raise ValueError(_("Invalid command") % " ".join(argv)) TypeError: not all arguments converted during string formatting
Quoted 2 lines
2) Either the priority stuff doesn't work or I am doing something wrong. Shouldn't either of the following not display any modules
since
Quoted 5 lines
they are all at priority 100?
"semodule -p 900 -l" or "semodule -p 900; semodule -l"
Both display all modules.
The list command is not affected by the priority setting. Maybe it should be? Currently the priority is defaulted to 400 in semodule, but we could have it default to 0 and check in the -i/u/r cases for 0 and set to 400 and then filter the modules in -l if priority != 0.
Quoted 4 lines
3) I can't remove the permissive domain created before the migration because the default priority level is 400, but the script put
everything
Quoted 2 lines
at priority 100 and I don't know how to change the priority for semanage.
semanage hasn't been updated yet to let you specify priorities.
Quoted 4 lines
# semanage permissive -d httpd_t libsemanage.semanage_direct_remove_key: Unable to remove module directory
/var/lib/selinux/targeted/tmp/modules/400/permissive_httpd_t.
Quoted 11 lines
(No such file or directory).
/usr/sbin/semanage: Could not remove permissive domainhttpd_t(remove failed)Ports and file contexts addition and removal seems to work fine.
--
James Carter <[email protected]>
National Security Agency
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
RE: [PATCH 13/13] semanage store migration script
Quoted 88 lines · Caleb Case
Quoted 11 lines
-----Original Message-----
From: James Carter [mailto:[email protected]]
Sent: Friday, January 08, 2010 4:00 PM
To: Stephen Smalley
Cc: Caleb Case; [email protected]; Chad Sellers; Karl MacMillan; Joshua Brindle
Subject: Re: [PATCH 13/13] semanage store migration scriptQuoted 2 lines · Stephen Smalley
Quoted 1 line · Caleb Case
We created a migration script to ease the burden of transition
from
Quoted 2 lines
the
Quoted 1 line
Quoted 1 line
old libsemanage store layout to the new. The script will detect
all
Quoted 2 lines
the
Quoted 1 line
Quoted 1 line
stores in
/etc/selinuxusing the old layout and convert them tothe
Quoted 2 lines
new
Quoted 1 line
Quoted 1 line
layout in
/var/lib/selinux. It also allows you to specify thedefault
Quoted 3 lines
Quoted 1 line
Quoted 1 line
priority to use with -p and store to operate on with -s. After
migration
Quoted 1 line
Quoted 1 line
the script by default will leave the old store unchanged, but can
be
Quoted 15 lines
Quoted 8 lines
Quoted 8 lines
told to remove the old modules directory with -c.
Examples:
# Migrate all stores to the new layout.
migrate.pyMigrating from
/etc/selinux/targeted/modules/activeto
/var/lib/selinux/targeted/activeQuoted 6 lines
Quoted 6 lines
Attempting to rebuild policy from
/var/lib/selinux# Migrate only the targeted store.
migrate.py-s targetedMigrating from
/etc/selinux/targeted/modules/activetoQuoted 18 lines
/var/lib/selinux/targeted/activeQuoted 6 lines
Quoted 6 lines
Attempting to rebuild policy from
/var/lib/selinux# Migrate all, but install to priority 150.
migrate.py-p 150Migrating from
/etc/selinux/targeted/modules/activeto
/var/lib/selinux/targeted/activeQuoted 10 lines
Quoted 1 line
Attempting to rebuild policy from
/var/lib/selinuxI tried the following:
semanage login -a -suser_upi
cp -a/etc/selinux/etc/selinux.orig
install new userlandmigrate.py
diff -ru/etc/selinux.orig/etc/selinuxThe seusers entry for "pi" was dropped from the final seusers file
in
Quoted 8 lines
Quoted 2 lines
the rebuilt policy.
I saw the same thing. I added a new login, but it does not show up after the migration with "semanage login -l" even though it is in
/var/lib/selinux/targeted/active/seusersand seusers.final.booleans, ports, file contexts, and permissive domains all show up
after
Quoted 15 lines
the migration, but there are some other issues.
1) For booleans I am getting this error:
# semanage boolean --on git_system_use_cifs Traceback (most recent call last): File "/usr/sbin/semanage", line 460, in <module> process_args(sys.argv[1:]) File "/usr/sbin/semanage", line 407, in process_args raise ValueError(_("Invalid command") % " ".join(argv)) TypeError: not all arguments converted during string formattingQuoted 2 lines
2) Either the priority stuff doesn't work or I am doing something wrong. Shouldn't either of the following not display any modules
since
Quoted 2 lines
they are all at priority 100?
Quoted 9 lines
Quoted 3 lines
"semodule -p 900 -l" or "semodule -p 900; semodule -l"
Both display all modules.
The list command is not affected by the priority setting. Maybe it should be? Currently the priority is defaulted to 400 in semodule, but we could have it default to 0 and check in the -i/u/r cases for 0 and set to 400 and then filter the modules in -l if priority != 0.
It seems like most of the time a person will just want to see the enabled modules. At times, though, they might want to see which priority each enabled module is at, or to see all the modules at a given priority.
Quoted 10 lines
Quoted 4 lines
3) I can't remove the permissive domain created before the migration because the default priority level is 400, but the script put
everything
Quoted 2 lines
at priority 100 and I don't know how to change the priority for semanage.
semanage hasn't been updated yet to let you specify priorities.
I noticed. ;)
So why does the migration script put everything into priority 100 instead of the default priority?
Quoted 23 lines
Quoted 4 lines
# semanage permissive -d httpd_t libsemanage.semanage_direct_remove_key: Unable to remove module directory
/var/lib/selinux/targeted/tmp/modules/400/permissive_httpd_t.Quoted 11 lines
(No such file or directory).
/usr/sbin/semanage: Could not remove permissive domainhttpd_t(remove failed)Ports and file contexts addition and removal seems to work fine.
--
James Carter <[email protected]>
National Security Agency--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Signature · 8 lines
James Carter <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
RE: [PATCH 13/13] semanage store migration script
Quoted 1 line · On 2010-01-11 James Carter wrote:
On Fri, 2010-01-08 at 16:27 -0500, Caleb Case wrote:
<snip>
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
3) I can't remove the permissive domain created before the migration because the default priority level is 400, but the script put everything at priority 100 and I don't know how to change the priority for semanage.
Quoted 6 lines
Quoted 2 lines
semanage hasn't been updated yet to let you specify priorities.
I noticed. ;)
So why does the migration script put everything into priority 100 instead of the default priority?
priority 100 is for policies distributed by the distro, 400 is default for user actions (eg., running semodule without adding a priority)
I guess we could add some smarts to the migration script to put things like permissive modules and "local.pp" kinds of modules at 400.
or add a list of modules distributed by red hat *shrug*
I'm not sure any of these are good ideas, but they might soften the migration blow.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
RE: [PATCH 13/13] semanage store migration script
Quoted 18 lines · Joshua Brindle
Quoted 1 line · On 2010-01-11 James Carter wrote:
On Fri, 2010-01-08 at 16:27 -0500, Caleb Case wrote:
<snip>
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
3) I can't remove the permissive domain created before the migration because the default priority level is 400, but the script put everything at priority 100 and I don't know how to change the priority for semanage.
Quoted 6 lines
Quoted 2 lines
semanage hasn't been updated yet to let you specify priorities.
I noticed. ;)
So why does the migration script put everything into priority 100 instead of the default priority?
Quoted 8 lines
priority 100 is for policies distributed by the distro, 400 is default for user actions (eg., running semodule without adding a priority)
I guess we could add some smarts to the migration script to put things like permissive modules and "local.pp" kinds of modules at 400.
or add a list of modules distributed by red hat *shrug*
I'm not sure any of these are good ideas, but they might soften the migration blow.
Oh wait. I was thinking that 100 was a higher priority. I couldn't understand why everything was migrated into a higher priority than the default. Now it makes sense.
It still might make sense to put local.pp and permissive modules into the default priority. It could be very confusing to have these exist in multiple priorities.
Quoted 5 lines
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Signature · 8 lines
James Carter <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
In reply to Caleb CaseQuoted 21 lines · Caleb Case
This patch moves the final files from inside /var/lib/selinux/<store>/[active|previous|tmp] to /var/lib/selinux/tmp/<store>. The move is done to facilitate using source control management on the /var/lib/selinux/<store> directory. If these files remain in /var/lib/selinux/<store> they will pose a size problem if an SCM like git is used as we'd be storing lots of binary diffs. We are suggesting making this change now, rather than later when source policy, SCM, and CIL[1] support are available, to ease the migration burden.
These are the files that have been moved:
/var/lib/selinux/<store>/active/... /var/lib/selinux/tmp/<store>/...
file_contextscontexts/files/file_contexts
file_contexts.homedirs contexts/files/file_contexts.homedirs
file_contexts.local contexts/files/file_contexts.localnetfilter_contextscontexts/netfilter_contexts
policy.kern policy/policy.<policyversion>
seusers.final seusers
Quoted 8 lines
The layout of these files in /var/lib/selinux/tmp/<store> is designed to mirror their locations in /etc/selinux/<store>. This should help clarify the relationship between these final files and the files installed in etc.
One consequence of this move is that reverting to the previous policy version requires a policy rebuild. Currently you can revert without rebuilding.
That seems a little worrisome to me, as a rebuild might fail, e.g. what happens if we abort a transaction due to a lack of disk space and then try to revert, requiring a rebuild, only to run out of space during the rebuild?
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Caleb Case
This patch moves the final files from inside /var/lib/selinux/<store>/[active|previous|tmp] to /var/lib/selinux/tmp/<store>. The move is done to facilitate using source control management on the /var/lib/selinux/<store> directory. If these files remain in /var/lib/selinux/<store> they will pose a size problem if an SCM like git is used as we'd be storing lots of binary diffs. We are suggesting making this change now, rather than later when source policy, SCM, and CIL[1] support are available, to ease the migration burden.
These are the files that have been moved:
/var/lib/selinux/<store>/active/... /var/lib/selinux/tmp/<store>/...
file_contextscontexts/files/file_contexts
file_contexts.homedirs contexts/files/file_contexts.homedirs
file_contexts.local contexts/files/file_contexts.localnetfilter_contextscontexts/netfilter_contexts
policy.kern policy/policy.<policyversion>
seusers.final seusersThe layout of these files in /var/lib/selinux/tmp/<store> is designed to mirror their locations in /etc/selinux/<store>. This should help clarify the relationship between these final files and the files installed in etc.
Quoted 9 lines
Quoted 3 lines
One consequence of this move is that reverting to the previous policy version requires a policy rebuild. Currently you can revert without rebuilding.
That seems a little worrisome to me, as a rebuild might fail, e.g. what happens if we abort a transaction due to a lack of disk space and then try to revert, requiring a rebuild, only to run out of space during the rebuild?
If the transaction is aborted then the policy hasn't actually been changed, so I don't think that this example would be a problem. It is only after the transaction is complete that everything is written to the final location. Or am I missing something?
It would be a problem only if changes were made to the policy, that policy loaded, there were problems, and then the rebuild of the previous policy fails.
Signature · 8 lines
James Carter <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 37 lines · James Carter
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Caleb Case
This patch moves the final files from inside /var/lib/selinux/<store>/[active|previous|tmp] to /var/lib/selinux/tmp/<store>. The move is done to facilitate using source control management on the /var/lib/selinux/<store> directory. If these files remain in /var/lib/selinux/<store> they will pose a size problem if an SCM like git is used as we'd be storing lots of binary diffs. We are suggesting making this change now, rather than later when source policy, SCM, and CIL[1] support are available, to ease the migration burden.
These are the files that have been moved:
/var/lib/selinux/<store>/active/... /var/lib/selinux/tmp/<store>/...
file_contextscontexts/files/file_contexts
file_contexts.homedirs contexts/files/file_contexts.homedirs
file_contexts.local contexts/files/file_contexts.localnetfilter_contextscontexts/netfilter_contexts
policy.kern policy/policy.<policyversion>
seusers.final seusersThe layout of these files in /var/lib/selinux/tmp/<store> is designed to mirror their locations in /etc/selinux/<store>. This should help clarify the relationship between these final files and the files installed in etc.
Quoted 9 lines
Quoted 3 lines
One consequence of this move is that reverting to the previous policy version requires a policy rebuild. Currently you can revert without rebuilding.
That seems a little worrisome to me, as a rebuild might fail, e.g. what happens if we abort a transaction due to a lack of disk space and then try to revert, requiring a rebuild, only to run out of space during the rebuild?
Quoted 8 lines
If the transaction is aborted then the policy hasn't actually been changed, so I don't think that this example would be a problem. It is only after the transaction is complete that everything is written to the final location. Or am I missing something?
It would be a problem only if changes were made to the policy, that policy loaded, there were problems, and then the rebuild of the previous policy fails.
I'm unclear on what state things would be left in. I'm also unclear on the implications of writing these files to a single tmp/ location rather than having separate copies in active/, previous/, and tmp/ - I don't want us to unwittingly clobber files or leave them in intermediate states (as happened with the earlier attempt to hard link files among active/, previous/ and tmp/).
I tried running the code but I seem to see these "final files" still under the individual <store> directories in /var/lib/selinux rather than under tmp/.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 47 lines · Stephen Smalley
Quoted 37 lines · James Carter
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Caleb Case
This patch moves the final files from inside /var/lib/selinux/<store>/[active|previous|tmp] to /var/lib/selinux/tmp/<store>. The move is done to facilitate using source control management on the /var/lib/selinux/<store> directory. If these files remain in /var/lib/selinux/<store> they will pose a size problem if an SCM like git is used as we'd be storing lots of binary diffs. We are suggesting making this change now, rather than later when source policy, SCM, and CIL[1] support are available, to ease the migration burden.
These are the files that have been moved:
/var/lib/selinux/<store>/active/... /var/lib/selinux/tmp/<store>/...
file_contextscontexts/files/file_contexts file_contexts.homedirs contexts/files/file_contexts.homedirs file_contexts.local contexts/files/file_contexts.localnetfilter_contextscontexts/netfilter_contexts policy.kern policy/policy.<policyversion> seusers.final seusersThe layout of these files in /var/lib/selinux/tmp/<store> is designed to mirror their locations in /etc/selinux/<store>. This should help clarify the relationship between these final files and the files installed in etc.
Quoted 9 lines
Quoted 3 lines
One consequence of this move is that reverting to the previous policy version requires a policy rebuild. Currently you can revert without rebuilding.
That seems a little worrisome to me, as a rebuild might fail, e.g. what happens if we abort a transaction due to a lack of disk space and then try to revert, requiring a rebuild, only to run out of space during the rebuild?
Quoted 8 lines
If the transaction is aborted then the policy hasn't actually been changed, so I don't think that this example would be a problem. It is only after the transaction is complete that everything is written to the final location. Or am I missing something?
It would be a problem only if changes were made to the policy, that policy loaded, there were problems, and then the rebuild of the previous policy fails.
Quoted 6 lines
I'm unclear on what state things would be left in. I'm also unclear on the implications of writing these files to a single tmp/ location rather than having separate copies in active/, previous/, and tmp/ - I don't want us to unwittingly clobber files or leave them in intermediate states (as happened with the earlier attempt to hard link files among active/, previous/ and tmp/).
If there is an error and the transaction is aborted (for any reason), then the effect is that nothing has changed. /etc/selinux/<store> remains untouched. If this happens there shouldn't be any need to revert. Since the tmp/<store> is emptied and then populated with copies of the files from /etc/selinux/<store> when a transaction is started there shouldn't be any files around to clobber. After a transaction ends (successful or not), then tmp/<store> is emptied so we shouldn't leave any files around in intermediate states. Only on a successful transaction do we copy the files from tmp/<store> to /etc/selinux/<store>.
Quoted 4 lines
I tried running the code but I seem to see these "final files" still under the individual <store> directories in
/var/lib/selinuxrather than under tmp/.
I'm looking into this. After this patch the final files should all be moved to tmp/.
Quoted 11 lines
--
Stephen Smalley
National Security Agency--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
In reply to Stephen SmalleyQuoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 10:07 -0500, James Carter wrote:
<snip>
Quoted 4 lines
I tried running the code but I seem to see these "final files" still under the individual<store> directories in
/var/lib/selinuxrather than under tmp/.
I built patches 1-4 and made a fresh store from whatever was in /etc/selinux and I did not have any final files under /var/lib/selinux/targeted:
[root@F12 selinux]# pwd/var/lib/selinux
[root@F12 selinux]# find
.
./targeted
./targeted/active
./targeted/active/modules
./targeted/active/modules/100
./targeted/active/modules/100/_base
./targeted/active/modules/100/_base/hll
./targeted/active/modules/100/_base/ext
...
./targeted/active/modules/100/milter ./targeted/active/modules/100/milter/hll ./targeted/active/modules/100/milter/ext ./targeted/active/modules/100/permissive_bin_t ./targeted/active/modules/100/permissive_bin_t/hll ./targeted/active/modules/100/permissive_bin_t/ext ./targeted/active/file_contexts.template ./targeted/active/file_contexts ./targeted/active/homedir_template ./targeted/active/seusers.final ./targeted/active/users_extra ./targeted/active/netfilter_contexts ./targeted/active/file_contexts.homedirs ./targeted/active/commit_num
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 27 lines · Joshua Brindle
Quoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 10:07 -0500, James Carter wrote:
<snip>
Quoted 4 lines
I tried running the code but I seem to see these "final files" still under the individual<store> directories in
/var/lib/selinuxrather than under tmp/.I built patches 1-4 and made a fresh store from whatever was in
/etc/selinuxand I did not have any final files under/var/lib/selinux/targeted:[root@F12 selinux]# pwd
/var/lib/selinux
[root@F12 selinux]# find
.
./targeted
./targeted/active
./targeted/active/modules
./targeted/active/modules/100
./targeted/active/modules/100/_base
./targeted/active/modules/100/_base/hll
./targeted/active/modules/100/_base/ext...
Quoted 8 lines
./targeted/active/modules/100/milter ./targeted/active/modules/100/milter/hll ./targeted/active/modules/100/milter/ext ./targeted/active/modules/100/permissive_bin_t ./targeted/active/modules/100/permissive_bin_t/hll ./targeted/active/modules/100/permissive_bin_t/ext ./targeted/active/file_contexts.template ./targeted/active/file_contexts
That's a final file.
Quoted 2 lines
./targeted/active/homedir_template
./targeted/active/seusers.final
And there is one.
Quoted 2 lines
./targeted/active/users_extra
./targeted/active/netfilter_contexts
And another.
Quoted 2 lines
./targeted/active/file_contexts.homedirs
./targeted/active/commit_num
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 41 lines · Stephen Smalley
Quoted 26 lines · Joshua Brindle
Quoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 10:07 -0500, James Carter wrote:
<snip>
Quoted 4 lines
I tried running the code but I seem to see these "final files" still
under the individual<store> directories in/var/lib/selinuxrather than
under tmp/.I built patches 1-4 and made a fresh store from whatever was in
/etc/selinuxand I did not have any final files under/var/lib/selinux/targeted:[root@F12 selinux]# pwd
/var/lib/selinux
[root@F12 selinux]# find
.
./targeted
./targeted/active
./targeted/active/modules
./targeted/active/modules/100
./targeted/active/modules/100/_base
./targeted/active/modules/100/_base/hll
./targeted/active/modules/100/_base/ext...
Quoted 8 lines
./targeted/active/modules/100/milter ./targeted/active/modules/100/milter/hll ./targeted/active/modules/100/milter/ext ./targeted/active/modules/100/permissive_bin_t ./targeted/active/modules/100/permissive_bin_t/hll ./targeted/active/modules/100/permissive_bin_t/ext ./targeted/active/file_contexts.template ./targeted/active/file_contexts
That's a final file.
Quoted 2 lines
./targeted/active/homedir_template
./targeted/active/seusers.final
Quoted 9 lines
And there is one.
Quoted 2 lines
./targeted/active/users_extra
./targeted/active/netfilter_contextsAnd another.
Quoted 2 lines
./targeted/active/file_contexts.homedirs
./targeted/active/commit_num
oops, I foolishly scanned looking for policy.kern.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 4 lines · Joshua Brindle
Quoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 15:19 -0500, Joshua Brindle wrote:
<snip>
Quoted 2 lines
oops, I foolishly scanned looking for policy.kern.
No, it is worse than that, I wasn't actually running the code I was claiming to (as evidenced by the priority level and hll files)
Up to patch 4 my /var/lib/selinux now looks like this:
[root@F12 active]# find /var/lib/selinux/ /var/lib/selinux//var/lib/selinux/targeted /var/lib/selinux/targeted/semanage.read.LOCK /var/lib/selinux/targeted/semanage.trans.LOCK /var/lib/selinux/targeted/active /var/lib/selinux/targeted/active/modules /var/lib/selinux/targeted/active/modules/abrt.pp /var/lib/selinux/targeted/active/modules/ada.pp
.../var/lib/selinux/targeted/active/modules/xguest.pp /var/lib/selinux/targeted/active/modules/zabbix.pp /var/lib/selinux/targeted/active/modules/zebra.pp /var/lib/selinux/targeted/active/modules/zosremote.pp /var/lib/selinux/targeted/active/base.pp /var/lib/selinux/targeted/active/file_contexts.template /var/lib/selinux/targeted/active/homedir_template /var/lib/selinux/targeted/active/users_extra /var/lib/selinux/targeted/active/commit_num /var/lib/selinux/tmp
so I don't have any final files in targeted anymore, though I didn't try to stop semodule half-way and look in tmp.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 36 lines · Joshua Brindle
Quoted 4 lines · Joshua Brindle
Quoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 15:19 -0500, Joshua Brindle wrote:
<snip>
Quoted 2 lines
oops, I foolishly scanned looking for policy.kern.
No, it is worse than that, I wasn't actually running the code I was claiming to (as evidenced by the priority level and hll files)
Up to patch 4 my
/var/lib/selinuxnow looks like this:[root@F12 active]# find
/var/lib/selinux//var/lib/selinux//var/lib/selinux/targeted/var/lib/selinux/targeted/semanage.read.LOCK/var/lib/selinux/targeted/semanage.trans.LOCK/var/lib/selinux/targeted/active/var/lib/selinux/targeted/active/modules/var/lib/selinux/targeted/active/modules/abrt.pp/var/lib/selinux/targeted/active/modules/ada.pp
.../var/lib/selinux/targeted/active/modules/xguest.pp/var/lib/selinux/targeted/active/modules/zabbix.pp/var/lib/selinux/targeted/active/modules/zebra.pp/var/lib/selinux/targeted/active/modules/zosremote.pp/var/lib/selinux/targeted/active/base.pp/var/lib/selinux/targeted/active/file_contexts.template/var/lib/selinux/targeted/active/homedir_template/var/lib/selinux/targeted/active/users_extra/var/lib/selinux/targeted/active/commit_num/var/lib/selinux/tmp
Quoted 2 lines
so I don't have any final files in targeted anymore, though I didn't try to stop semodule half-way and look in tmp.
I haven't tried only up through patch 4, only with all 13 patches applied.
Also, I have all Fedora policies installed (yum install selinux-policy*), so I have mls, targeted, and minimum, although targeted is the active one.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 38 lines · Stephen Smalley
Quoted 34 lines · Joshua Brindle
Quoted 3 lines · Joshua Brindle
Quoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 15:19 -0500, Joshua Brindle wrote:
<snip>
Quoted 2 lines
oops, I foolishly scanned looking for policy.kern.
No, it is worse than that, I wasn't actually running the code I was claiming to (as evidenced by the priority level and hll files)
Up to patch 4 my
/var/lib/selinuxnow looks like this:[root@F12 active]# find
/var/lib/selinux//var/lib/selinux//var/lib/selinux/targeted/var/lib/selinux/targeted/semanage.read.LOCK/var/lib/selinux/targeted/semanage.trans.LOCK/var/lib/selinux/targeted/active/var/lib/selinux/targeted/active/modules/var/lib/selinux/targeted/active/modules/abrt.pp/var/lib/selinux/targeted/active/modules/ada.pp
.../var/lib/selinux/targeted/active/modules/xguest.pp/var/lib/selinux/targeted/active/modules/zabbix.pp/var/lib/selinux/targeted/active/modules/zebra.pp/var/lib/selinux/targeted/active/modules/zosremote.pp/var/lib/selinux/targeted/active/base.pp/var/lib/selinux/targeted/active/file_contexts.template/var/lib/selinux/targeted/active/homedir_template/var/lib/selinux/targeted/active/users_extra/var/lib/selinux/targeted/active/commit_num/var/lib/selinux/tmpQuoted 2 lines
so I don't have any final files in targeted anymore, though I didn't try to stop semodule half-way and look in tmp.
Quoted 7 lines
I haven't tried only up through patch 4, only with all 13 patches applied.
Also, I have all Fedora policies installed (yum install selinux-policy*), so I have mls, targeted, and minimum, although targeted is the active one.
Are you running the migrate script? I believe it is erroneously copying final files into the store:
+ # List of paths that go in the active 'root'
+ TOPPATHS = [
+ "file_contexts",
+ "homedir_template",
+ "file_contexts.template",
+ "commit_num",
+ "ports.local",
+ "interfaces.local",
+ "nodes.local",
+ "booleans.local",
+ "file_contexts.local",
+ "seusers",
+ "users.local",
+ "users_extra.local",
+ "seusers.final",
+ "users_extra",
+ "netfilter_contexts",
+ "file_contexts.homedirs",
+ "disable_dontaudit" ]
+
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
Quoted 42 lines · Joshua Brindle
Quoted 41 lines · Stephen Smalley
Quoted 34 lines · Joshua Brindle
Quoted 3 lines · Joshua Brindle
Quoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 15:19 -0500, Joshua Brindle wrote:
<snip>
Quoted 2 lines
oops, I foolishly scanned looking for policy.kern.
No, it is worse than that, I wasn't actually running the code I was claiming to (as evidenced by the priority level and hll files)
Up to patch 4 my
/var/lib/selinuxnow looks like this:[root@F12 active]# find
/var/lib/selinux//var/lib/selinux//var/lib/selinux/targeted/var/lib/selinux/targeted/semanage.read.LOCK/var/lib/selinux/targeted/semanage.trans.LOCK/var/lib/selinux/targeted/active/var/lib/selinux/targeted/active/modules/var/lib/selinux/targeted/active/modules/abrt.pp/var/lib/selinux/targeted/active/modules/ada.pp
.../var/lib/selinux/targeted/active/modules/xguest.pp/var/lib/selinux/targeted/active/modules/zabbix.pp/var/lib/selinux/targeted/active/modules/zebra.pp/var/lib/selinux/targeted/active/modules/zosremote.pp/var/lib/selinux/targeted/active/base.pp/var/lib/selinux/targeted/active/file_contexts.template/var/lib/selinux/targeted/active/homedir_template/var/lib/selinux/targeted/active/users_extra/var/lib/selinux/targeted/active/commit_num/var/lib/selinux/tmpQuoted 2 lines
so I don't have any final files in targeted anymore, though I didn't try to stop semodule half-way and look in tmp.
I haven't tried only up through patch 4, only with all 13 patches applied.
Quoted 6 lines
Quoted 4 lines
Also, I have all Fedora policies installed (yum install selinux-policy*), so I have mls, targeted, and minimum, although targeted is the active one.
Are you running the migrate script?
Yes.
Quoted 23 lines
I believe it is erroneously copying
final files into the store:(quoted diff) +20
-0+ # List of paths that go in the active 'root' + TOPPATHS = [ + "file_contexts", + "homedir_template", + "file_contexts.template", + "commit_num", + "ports.local", + "interfaces.local", + "nodes.local", + "booleans.local", + "file_contexts.local", + "seusers", + "users.local", + "users_extra.local", + "seusers.final", + "users_extra", + "netfilter_contexts", + "file_contexts.homedirs", + "disable_dontaudit" ] +
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/13] libsemanage: split final files into /var/lib/selinux/tmp
In reply to Joshua BrindleQuoted 61 lines · Joshua Brindle
Quoted 38 lines · Stephen Smalley
Quoted 34 lines · Joshua Brindle
Quoted 3 lines · Joshua Brindle
Quoted 1 line · Stephen Smalley
On Fri, 2010-01-08 at 15:19 -0500, Joshua Brindle wrote:
<snip>
Quoted 2 lines
oops, I foolishly scanned looking for policy.kern.
No, it is worse than that, I wasn't actually running the code I was claiming to (as evidenced by the priority level and hll files)
Up to patch 4 my
/var/lib/selinuxnow looks like this:[root@F12 active]# find
/var/lib/selinux//var/lib/selinux//var/lib/selinux/targeted/var/lib/selinux/targeted/semanage.read.LOCK/var/lib/selinux/targeted/semanage.trans.LOCK/var/lib/selinux/targeted/active/var/lib/selinux/targeted/active/modules/var/lib/selinux/targeted/active/modules/abrt.pp/var/lib/selinux/targeted/active/modules/ada.pp
.../var/lib/selinux/targeted/active/modules/xguest.pp/var/lib/selinux/targeted/active/modules/zabbix.pp/var/lib/selinux/targeted/active/modules/zebra.pp/var/lib/selinux/targeted/active/modules/zosremote.pp/var/lib/selinux/targeted/active/base.pp/var/lib/selinux/targeted/active/file_contexts.template/var/lib/selinux/targeted/active/homedir_template/var/lib/selinux/targeted/active/users_extra/var/lib/selinux/targeted/active/commit_num/var/lib/selinux/tmpQuoted 2 lines
so I don't have any final files in targeted anymore, though I didn't try to stop semodule half-way and look in tmp.
Quoted 7 lines
I haven't tried only up through patch 4, only with all 13 patches applied.
Also, I have all Fedora policies installed (yum install selinux-policy*), so I have mls, targeted, and minimum, although targeted is the active one.
Are you running the migrate script? I believe it is erroneously copying final files into the store:
(quoted diff) +10
-0+ # List of paths that go in the active 'root' + TOPPATHS = [ + "file_contexts", + "homedir_template", + "file_contexts.template", + "commit_num", + "ports.local", + "interfaces.local", + "nodes.local", + "booleans.local",
Review
Quoted 10 lines
(quoted diff) +10
-0+ "file_contexts.local", + "seusers", + "users.local", + "users_extra.local", + "seusers.final", + "users_extra", + "netfilter_contexts", + "file_contexts.homedirs", + "disable_dontaudit" ] +
That does appear to be the case. When I remove the final files, they do not reappear after I rebuild the policy.
Quoted 4 lines
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Signature · 8 lines
James Carter <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 03/13] libsemanage: move the module store to /var/lib/selinux
In reply to Caleb CaseQuoted 2 lines · Caleb Case
This patch moves the module store from /etc/selinux/<store>/modules to /var/lib/selinux/<store>.
Can the path prefix (i.e. /var/lib/selinux) be made configurable?
Quoted 196 lines
This move will allow for the use of a read-only
/etc/selinux. Currently that is not possible with semanage because of the lock files.A consequence of this move is that packagers of libsemanage should create the
/var/lib/selinuxdirectory.--- libsemanage/src/direct_api.c | 20 ++---------------- libsemanage/src/semanage_store.c | 39 ++++++++++++++++++++++++------------- libsemanage/src/semanage_store.h | 5 +++- 3 files changed, 32 insertions(+), 32 deletions(-)libsemanage/src/direct_api.c +3
-17@@ -89,12 +89,7 @@ static struct semanage_policy_table direct_funcs = {int semanage_direct_is_managed (semanage_handle_t * sh) { -char polpath[PATH_MAX ]; - -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ())) goto err;if (semanage_access_check (sh) <0 )@@ -111,13 +106,9 @@ int semanage_direct_is_managed(semanage_handle_t * sh)*/ int semanage_direct_connect (semanage_handle_t * sh) { -char polpath[PATH_MAX ];const char *path; -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ())) goto err;if (sh->create_store)@@ -1416,12 +1407,7 @@ static int semanage_direct_list(semanage_handle_t * sh,int semanage_direct_access_check (semanage_handle_t * sh) { -char polpath[PATH_MAX ]; - -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ()))return -1 ;return semanage_store_access_check (sh);libsemanage/src/semanage_store.c +25
-14@@ -3,8 +3,9 @@* Jason Tang <[email protected]> * Christopher Ashworth <[email protected]> * Chris PeBenito <[email protected]> +* Caleb Case <[email protected]> * -* Copyright (C) 2004-2006 Tresys Technology, LLC +* Copyright (C) 2004-2006,2009 Tresys Technology, LLC * Copyright (C) 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -88,8 +89,6 @@ static const char *semanage_store_paths[SEMANAGE_NUM_STORES] = {"/tmp" }; -/* this is the module store path relative to selinux_policy_root() */ -#define SEMANAGE_MOD_DIR "/modules"/* relative path names to enum sandbox_paths for special files within * a sandbox */ static const char *semanage_sandbox_paths[SEMANAGE_STORE_NUM_PATHS ] = {@@ -157,14 +156,14 @@ static int semanage_init_paths(const char *root)if (!root)return -1 ; - prefix_len = (strlen (root) +strlen (SEMANAGE_MOD_DIR )); + prefix_len =strlen (root);for (i =0 ; i <SEMANAGE_NUM_FILES ; i++) { len = (strlen (semanage_relative_files[i]) + prefix_len); semanage_files[i] =calloc (len +1 ,sizeof (char ));if (!semanage_files[i])return -1 ; -sprintf (semanage_files[i],"%s%s%s" , root,SEMANAGE_MOD_DIR , +sprintf (semanage_files[i],"%s%s" , root, semanage_relative_files[i]); }@@ -186,16 +185,11 @@ static int semanage_init_store_paths(const char *root)int i, j;size_t len;size_t prefix_len; -char *prefix;if (!root)return -1 ; - prefix_len = (strlen (root) +strlen (SEMANAGE_MOD_DIR )); - prefix =calloc (prefix_len +1 ,sizeof (char )); -if (!prefix) -return -1 ; -sprintf (prefix,"%s%s" , root,SEMANAGE_MOD_DIR ); + prefix_len =strlen (root);for (i =0 ; i <SEMANAGE_NUM_STORES ; i++) {for (j =0 ; j <SEMANAGE_STORE_NUM_PATHS ; j++) {@@ -204,14 +198,13 @@ static int semanage_init_store_paths(const char *root) semanage_paths[i][j] =calloc (len +1 ,sizeof (char ));if (!semanage_paths[i][j]) goto cleanup; -sprintf (semanage_paths[i][j],"%s%s%s" , prefix, +sprintf (semanage_paths[i][j],"%s%s%s" , root, semanage_store_paths[i], semanage_sandbox_paths[j]); } } cleanup: -free (prefix);return 0 ; }@@ -223,16 +216,28 @@ static int semanage_init_store_paths(const char *root)* * Note that this function is NOT thread-safe. */ -int semanage_check_init (const char *root) +int semanage_check_init (semanage_handle_t *sh,const char *prefix) {int rc;if (semanage_paths_initialized ==0 ) { +char root[PATH_MAX ]; + + rc =snprintf (root, +sizeof (root), +"%s/%s" , + prefix, + sh->conf->store_path); +if (rc <0 || rc >= (int )sizeof (root)) +return -1 ; + rc =semanage_init_paths (root);if (rc)return rc; + rc =semanage_init_store_paths (root);if (rc)return rc; + semanage_paths_initialized =1 ; }return 0 ;@@ -259,6 +264,12 @@ const char *semanage_path(enum semanage_store_defs store,return semanage_paths[store][path_name]; } +/* Return the root of the semanage store. */ +const char *semanage_root_path (void ) +{ +return "/var/lib/selinux" ; +} +/* Return a fully-qualified path + filename to the semanage * configuration file. The caller must not alter the string returned * (and hence why this function return type is const). libsemanage/src/semanage_store.h +4
-1@@ -62,11 +62,14 @@ enum semanage_sandbox_defs { SEMANAGE_STORE_NUM_PATHS }; +const char *semanage_root_path (void ); +/* FIXME: this needs to be made a module store specific init and the * global configuration moved to another file. */ const char *semanage_conf_path (void ); -int semanage_check_init (const char *root); + +int semanage_check_init (semanage_handle_t *sh,const char *prefix);extern const char *semanage_fname (enum semanage_sandbox_defs file_enum);
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 03/13] libsemanage: move the module store to /var/lib/selinux
Quoted 6 lines · Stephen Smalley
Quoted 2 lines · Caleb Case
This patch moves the module store from /etc/selinux/<store>/modules to /var/lib/selinux/<store>.
Can the path prefix (i.e.
/var/lib/selinux) be made configurable?
There would be no other prefixes other than /var/lib/selinux or /etc/selinux, or do you have something else in mind?
I guess that you are thinking of backwards compatibility, but you still won't have it even if you change the prefix because the directory structure is different (priority directories and such). I don't see what you would gain with changing the prefix.
Quoted 196 lines
Quoted 196 lines
This move will allow for the use of a read-only
/etc/selinux. Currently that is not possible with semanage because of the lock files.A consequence of this move is that packagers of libsemanage should create the
/var/lib/selinuxdirectory.--- libsemanage/src/direct_api.c | 20 ++---------------- libsemanage/src/semanage_store.c | 39 ++++++++++++++++++++++++------------- libsemanage/src/semanage_store.h | 5 +++- 3 files changed, 32 insertions(+), 32 deletions(-)libsemanage/src/direct_api.c +3
-17@@ -89,12 +89,7 @@ static struct semanage_policy_table direct_funcs = {int semanage_direct_is_managed (semanage_handle_t * sh) { -char polpath[PATH_MAX ]; - -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ())) goto err;if (semanage_access_check (sh) <0 )@@ -111,13 +106,9 @@ int semanage_direct_is_managed(semanage_handle_t * sh)*/ int semanage_direct_connect (semanage_handle_t * sh) { -char polpath[PATH_MAX ];const char *path; -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ())) goto err;if (sh->create_store)@@ -1416,12 +1407,7 @@ static int semanage_direct_list(semanage_handle_t * sh,int semanage_direct_access_check (semanage_handle_t * sh) { -char polpath[PATH_MAX ]; - -snprintf (polpath,PATH_MAX ,"%s%s" ,selinux_path (), - sh->conf->store_path); - -if (semanage_check_init (polpath)) +if (semanage_check_init (sh,semanage_root_path ()))return -1 ;return semanage_store_access_check (sh);libsemanage/src/semanage_store.c +25
-14@@ -3,8 +3,9 @@* Jason Tang <[email protected]> * Christopher Ashworth <[email protected]> * Chris PeBenito <[email protected]> +* Caleb Case <[email protected]> * -* Copyright (C) 2004-2006 Tresys Technology, LLC +* Copyright (C) 2004-2006,2009 Tresys Technology, LLC * Copyright (C) 2005 Red Hat, Inc. * * This library is free software; you can redistribute it and/or @@ -88,8 +89,6 @@ static const char *semanage_store_paths[SEMANAGE_NUM_STORES] = {"/tmp" }; -/* this is the module store path relative to selinux_policy_root() */ -#define SEMANAGE_MOD_DIR "/modules"/* relative path names to enum sandbox_paths for special files within * a sandbox */ static const char *semanage_sandbox_paths[SEMANAGE_STORE_NUM_PATHS ] = {@@ -157,14 +156,14 @@ static int semanage_init_paths(const char *root)if (!root)return -1 ; - prefix_len = (strlen (root) +strlen (SEMANAGE_MOD_DIR )); + prefix_len =strlen (root);for (i =0 ; i <SEMANAGE_NUM_FILES ; i++) { len = (strlen (semanage_relative_files[i]) + prefix_len); semanage_files[i] =calloc (len +1 ,sizeof (char ));if (!semanage_files[i])return -1 ; -sprintf (semanage_files[i],"%s%s%s" , root,SEMANAGE_MOD_DIR , +sprintf (semanage_files[i],"%s%s" , root, semanage_relative_files[i]); }@@ -186,16 +185,11 @@ static int semanage_init_store_paths(const char *root)int i, j;size_t len;size_t prefix_len; -char *prefix;if (!root)return -1 ; - prefix_len = (strlen (root) +strlen (SEMANAGE_MOD_DIR )); - prefix =calloc (prefix_len +1 ,sizeof (char )); -if (!prefix) -return -1 ; -sprintf (prefix,"%s%s" , root,SEMANAGE_MOD_DIR ); + prefix_len =strlen (root);for (i =0 ; i <SEMANAGE_NUM_STORES ; i++) {for (j =0 ; j <SEMANAGE_STORE_NUM_PATHS ; j++) {@@ -204,14 +198,13 @@ static int semanage_init_store_paths(const char *root) semanage_paths[i][j] =calloc (len +1 ,sizeof (char ));if (!semanage_paths[i][j]) goto cleanup; -sprintf (semanage_paths[i][j],"%s%s%s" , prefix, +sprintf (semanage_paths[i][j],"%s%s%s" , root, semanage_store_paths[i], semanage_sandbox_paths[j]); } } cleanup: -free (prefix);return 0 ; }@@ -223,16 +216,28 @@ static int semanage_init_store_paths(const char *root)* * Note that this function is NOT thread-safe. */ -int semanage_check_init (const char *root) +int semanage_check_init (semanage_handle_t *sh,const char *prefix) {int rc;if (semanage_paths_initialized ==0 ) { +char root[PATH_MAX ]; + + rc =snprintf (root, +sizeof (root), +"%s/%s" , + prefix, + sh->conf->store_path); +if (rc <0 || rc >= (int )sizeof (root)) +return -1 ; + rc =semanage_init_paths (root);if (rc)return rc; + rc =semanage_init_store_paths (root);if (rc)return rc; + semanage_paths_initialized =1 ; }return 0 ;@@ -259,6 +264,12 @@ const char *semanage_path(enum semanage_store_defs store,return semanage_paths[store][path_name]; } +/* Return the root of the semanage store. */ +const char *semanage_root_path (void ) +{ +return "/var/lib/selinux" ; +} +/* Return a fully-qualified path + filename to the semanage * configuration file. The caller must not alter the string returned * (and hence why this function return type is const). libsemanage/src/semanage_store.h +4
-1@@ -62,11 +62,14 @@ enum semanage_sandbox_defs { SEMANAGE_STORE_NUM_PATHS }; +const char *semanage_root_path (void ); +/* FIXME: this needs to be made a module store specific init and the * global configuration moved to another file. */ const char *semanage_conf_path (void ); -int semanage_check_init (const char *root); + +int semanage_check_init (semanage_handle_t *sh,const char *prefix);extern const char *semanage_fname (enum semanage_sandbox_defs file_enum);
Signature · 8 lines
James Carter <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 03/13] libsemanage: move the module store to /var/lib/selinux
Quoted 7 lines · James Carter
Quoted 6 lines · Stephen Smalley
Quoted 2 lines · Caleb Case
This patch moves the module store from /etc/selinux/<store>/modules to /var/lib/selinux/<store>.
Can the path prefix (i.e.
/var/lib/selinux) be made configurable?
Quoted 7 lines
There would be no other prefixes other than
/var/lib/selinuxor/etc/selinux, or do you have something else in mind?I guess that you are thinking of backwards compatibility, but you still won't have it even if you change the prefix because the directory structure is different (priority directories and such). I don't see what you would gain with changing the prefix.
I just dislike the notion that to change the location one would have to recompile the library. Even worse, one would have to modify the sources versus just altering a -D flag in the Makefile specifying the path prefix. We already have one such case in libsemanage with a FIXME comment next to it; I didn't want to extend the set of such cases.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 167 lines · Caleb Case
Our motivations for this patchset are to:
* Move the semanage store - the portion of the SELinux configuration managed by libsemanage - to a more appropriate location in the filesystem. The current location - in /etc - is designated for administrator controlled configuration and is sometimes mounted read-only. By storing binary, program managed data in /etc libsemanage breaks administrator expectations.
* Enable the overriding of modules in the module store without require the original modules to removed or modified. This allows administrators to customize the policy more fully while allowing the distribution provided policies to be left unmodified and continue to be updated by the package manager.
* Provide the ability for an administrator to disable a module without removing or overriding that module.
[Move to
/var/lib/selinux]Move the libsemanage private store
from /etc/selinux/<policy type>/modules
to /var/lib/selinux/<policy type>The benefits of this are:
* Permits the use of a read-only /etc.
* Conforms to the Filesystem Hierarchy Standard.
An additional change in layout structure moves the temporary space for the active policy to an external temporary space. This has the benefit of permitting source control management to be used on the private policy.
[Module Priorities]
Module priorities modify libsemanage and the module store to allow multiple modules with the same name to exist with different priorities. Only the highest priority module is used to create the final system policy. The addition of module priorities enables the modification of the system policy without modifying individual modules. For example, it allows an administrator to add his own policy module for apache, completely replacing the distribution provided module, without changing or removing the distribution policy. This has several benefits:
* Distribution provided policy package updates proceed normally - the distribution policy is inserted but the administrator provided policy remains active.
* Multiple levels allows distributors, 3rd party applications, system management tools (e.g., puppet), and local administrators to all make changes without conflicting.
* Semanage modifications of policy (e.g., port labeling) will be able to use high priority modules in the future to override defaults (requires the CIL[1] language changes).
[Enable/Disable Modules]
Modules gain an enabled / disabled status. Enabled modules are used by semanage when building the active policy, and disabled modules are ignored. The main benefit of this is that modules can be disabled without out removing them from the store.
[Patchset Breakdown]
The patchset is broken down as follows:
Bug fixes:
libsemanage: fix type in tests makefile -o -> -O
Move the libsemanage store to
/var/lib/selinux:semanage: move permissive module creation to /tmp
libsemanage: move the module store to/var/lib/selinux
libsemanage: split final files into/var/lib/selinux/tmp
libsemanage: update unit tests for move to/var/lib/selinuxImplement support for the new libsemanage store layout:
libsemanage: add default priority to
semanage_handle_t
libsemanage: augmentsemanage_module_info_tand providesemanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and keyProvide private headers for upstream tools to use:
libsemanage: new private api for unstable functions
Extend semodule to support enable/disable, priorities, and detailed listings:
semodule: add priority, enabled, and extended listing
Migration script for moving the libsemanage store:
semanage store migration script
Thanks for you feedback!
Caleb
[1] CIL RFC: http://marc.info/?l=selinux&m=124759244409438&w=2
Caleb Case (13):
libsemanage: fix typo in tests makefile -o -> -O
semanage: move permissive module creation to /tmp
libsemanage: move the module store to/var/lib/selinux
libsemanage: split final files into/var/lib/selinux/tmp
libsemanage: update unit tests for move to/var/lib/selinux
libsemanage: add default priority tosemanage_handle_t
libsemanage: augmentsemanage_module_info_tand provide
semanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and key
libsemanage: new private api for unstable functions
semodule: add priority, enabled, and extended listing semanage store migration scriptlibsemanage/include/Makefile | 3 + libsemanage/include/semanage/private/handle.h | 31 + libsemanage/include/semanage/private/modules.h | 281 ++++ libsemanage/include/semanage/private/semanage.h | 26 + libsemanage/src/boolean_internal.h | 4 +- libsemanage/src/booleans_file.c | 7 +- libsemanage/src/booleans_policydb.c | 6 +- libsemanage/src/database_file.c | 45 +- libsemanage/src/database_file.h | 3 +- libsemanage/src/database_policydb.c | 37 +- libsemanage/src/database_policydb.h | 3 +- libsemanage/src/direct_api.c | 1652 +++++++++++++++++++--- libsemanage/src/fcontext_internal.h | 3 +- libsemanage/src/fcontexts_file.c | 7 +- libsemanage/src/genhomedircon.c | 3 +- libsemanage/src/handle.c | 23 + libsemanage/src/handle.h | 3 + libsemanage/src/handle_internal.h | 1 + libsemanage/src/iface_internal.h | 4 +- libsemanage/src/interfaces_file.c | 7 +- libsemanage/src/interfaces_policydb.c | 6 +- libsemanage/src/libsemanage.map | 26 + libsemanage/src/module_internal.h | 21 + libsemanage/src/modules.c | 999 +++++++++++++- libsemanage/src/modules.h | 76 +- libsemanage/src/node_internal.h | 4 +- libsemanage/src/nodes_file.c | 7 +- libsemanage/src/nodes_policydb.c | 6 +- libsemanage/src/policy.h | 36 + libsemanage/src/port_internal.h | 4 +- libsemanage/src/ports_file.c | 7 +- libsemanage/src/ports_policydb.c | 6 +- libsemanage/src/semanage_store.c | 794 ++++++++--- libsemanage/src/semanage_store.h | 47 +- libsemanage/src/seuser_internal.h | 4 +- libsemanage/src/seusers_file.c | 7 +- libsemanage/src/user_internal.h | 6 +- libsemanage/src/users_base_file.c | 7 +- libsemanage/src/users_base_policydb.c | 6 +- libsemanage/src/users_extra_file.c | 7 +- libsemanage/tests/Makefile | 2 +- libsemanage/tests/test_semanage_store.c | 34 +- libsemanage/utils/semanage_migrate_etc_to_var.py | 301 ++++
Quoted 9 lines
policycoreutils/semanage/seobject.py | 15 +- policycoreutils/semodule/semodule.8 | 25 +- policycoreutils/semodule/semodule.c | 242 +++- 46 files changed, 4267 insertions(+), 577 deletions(-) create mode 100644 libsemanage/include/semanage/private/handle.h create mode 100644 libsemanage/include/semanage/private/modules.h create mode 100644 libsemanage/include/semanage/private/semanage.h create mode 100755 libsemanage/utils/semanage_migrate_etc_to_var.py
Well, there have been no comments on this patchset. I'm guessing that's because:
1) We've talked to some of you face to face about it already.
2) It's a big patchset, and you'd want to try it out a bit before commenting.
To address #2, I'd like to propose creating an upstream branch for these changes. This patchset is actually just the first patchset in a larger effort to improve policy infrastructure. I think an upstream branch will make it easier for many people to track those changes and try out the new features we're creating. Eventually that branch can be merged back into master.
Thoughts?
Thanks,
Chad Sellers
Oh, and in case it wasn't implied:
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 178 lines · Chad Sellers
Quoted 167 lines · Caleb Case
Our motivations for this patchset are to:
* Move the semanage store - the portion of the SELinux configuration managed by libsemanage - to a more appropriate location in the filesystem. The current location - in /etc - is designated for administrator controlled configuration and is sometimes mounted read-only. By storing binary, program managed data in /etc libsemanage breaks administrator expectations.
* Enable the overriding of modules in the module store without require the original modules to removed or modified. This allows administrators to customize the policy more fully while allowing the distribution provided policies to be left unmodified and continue to be updated by the package manager.
* Provide the ability for an administrator to disable a module without removing or overriding that module.
[Move to
/var/lib/selinux]Move the libsemanage private store
from /etc/selinux/<policy type>/modules
to /var/lib/selinux/<policy type>The benefits of this are:
* Permits the use of a read-only /etc.
* Conforms to the Filesystem Hierarchy Standard.
An additional change in layout structure moves the temporary space for the active policy to an external temporary space. This has the benefit of permitting source control management to be used on the private policy.
[Module Priorities]
Module priorities modify libsemanage and the module store to allow multiple modules with the same name to exist with different priorities. Only the highest priority module is used to create the final system policy. The addition of module priorities enables the modification of the system policy without modifying individual modules. For example, it allows an administrator to add his own policy module for apache, completely replacing the distribution provided module, without changing or removing the distribution policy. This has several benefits:
* Distribution provided policy package updates proceed normally - the distribution policy is inserted but the administrator provided policy remains active.
* Multiple levels allows distributors, 3rd party applications, system management tools (e.g., puppet), and local administrators to all make changes without conflicting.
* Semanage modifications of policy (e.g., port labeling) will be able to use high priority modules in the future to override defaults (requires the CIL[1] language changes).
[Enable/Disable Modules]
Modules gain an enabled / disabled status. Enabled modules are used by semanage when building the active policy, and disabled modules are ignored. The main benefit of this is that modules can be disabled without out removing them from the store.
[Patchset Breakdown]
The patchset is broken down as follows:
Bug fixes:
libsemanage: fix type in tests makefile -o -> -O
Move the libsemanage store to
/var/lib/selinux:semanage: move permissive module creation to /tmp
libsemanage: move the module store to/var/lib/selinux
libsemanage: split final files into/var/lib/selinux/tmp
libsemanage: update unit tests for move to/var/lib/selinuxImplement support for the new libsemanage store layout:
libsemanage: add default priority to
semanage_handle_t
libsemanage: augmentsemanage_module_info_tand providesemanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and keyProvide private headers for upstream tools to use:
libsemanage: new private api for unstable functions
Extend semodule to support enable/disable, priorities, and detailed listings:
semodule: add priority, enabled, and extended listing
Migration script for moving the libsemanage store:
semanage store migration script
Thanks for you feedback!
Caleb
[1] CIL RFC: http://marc.info/?l=selinux&m=124759244409438&w=2
Caleb Case (13):
libsemanage: fix typo in tests makefile -o -> -O
semanage: move permissive module creation to /tmp
libsemanage: move the module store to/var/lib/selinux
libsemanage: split final files into/var/lib/selinux/tmp
libsemanage: update unit tests for move to/var/lib/selinux
libsemanage: add default priority tosemanage_handle_t
libsemanage: augmentsemanage_module_info_tand provide
semanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and key
libsemanage: new private api for unstable functions
semodule: add priority, enabled, and extended listing semanage store migration scriptlibsemanage/include/Makefile | 3 + libsemanage/include/semanage/private/handle.h | 31 + libsemanage/include/semanage/private/modules.h | 281 ++++ libsemanage/include/semanage/private/semanage.h | 26 + libsemanage/src/boolean_internal.h | 4 +- libsemanage/src/booleans_file.c | 7 +- libsemanage/src/booleans_policydb.c | 6 +- libsemanage/src/database_file.c | 45 +- libsemanage/src/database_file.h | 3 +- libsemanage/src/database_policydb.c | 37 +- libsemanage/src/database_policydb.h | 3 +- libsemanage/src/direct_api.c | 1652 +++++++++++++++++++--- libsemanage/src/fcontext_internal.h | 3 +- libsemanage/src/fcontexts_file.c | 7 +- libsemanage/src/genhomedircon.c | 3 +- libsemanage/src/handle.c | 23 + libsemanage/src/handle.h | 3 + libsemanage/src/handle_internal.h | 1 + libsemanage/src/iface_internal.h | 4 +- libsemanage/src/interfaces_file.c | 7 +- libsemanage/src/interfaces_policydb.c | 6 +- libsemanage/src/libsemanage.map | 26 + libsemanage/src/module_internal.h | 21 + libsemanage/src/modules.c | 999 +++++++++++++- libsemanage/src/modules.h | 76 +- libsemanage/src/node_internal.h | 4 +- libsemanage/src/nodes_file.c | 7 +- libsemanage/src/nodes_policydb.c | 6 +- libsemanage/src/policy.h | 36 + libsemanage/src/port_internal.h | 4 +- libsemanage/src/ports_file.c | 7 +- libsemanage/src/ports_policydb.c | 6 +- libsemanage/src/semanage_store.c | 794 ++++++++--- libsemanage/src/semanage_store.h | 47 +- libsemanage/src/seuser_internal.h | 4 +- libsemanage/src/seusers_file.c | 7 +- libsemanage/src/user_internal.h | 6 +- libsemanage/src/users_base_file.c | 7 +- libsemanage/src/users_base_policydb.c | 6 +- libsemanage/src/users_extra_file.c | 7 +- libsemanage/tests/Makefile | 2 +- libsemanage/tests/test_semanage_store.c | 34 +- libsemanage/utils/semanage_migrate_etc_to_var.py | 301 ++++Quoted 9 lines
policycoreutils/semanage/seobject.py | 15 +- policycoreutils/semodule/semodule.8 | 25 +- policycoreutils/semodule/semodule.c | 242 +++- 46 files changed, 4267 insertions(+), 577 deletions(-) create mode 100644 libsemanage/include/semanage/private/handle.h create mode 100644 libsemanage/include/semanage/private/modules.h create mode 100644 libsemanage/include/semanage/private/semanage.h create mode 100755 libsemanage/utils/semanage_migrate_etc_to_var.py
Quoted 7 lines
Well, there have been no comments on this patchset. I'm guessing that's because:
1) We've talked to some of you face to face about it already.
2) It's a big patchset, and you'd want to try it out a bit before commenting.
I've been trying it out for the last few days. I haven't had any problems yet.
Quoted 8 lines
To address #2, I'd like to propose creating an upstream branch for these changes. This patchset is actually just the first patchset in a larger effort to improve policy infrastructure. I think an upstream branch will make it easier for many people to track those changes and try out the new features we're creating. Eventually that branch can be merged back into master.
Thoughts?
I think that creating an upstream branch would be a good idea.
Quoted 12 lines
Thanks,
Chad SellersOh, and in case it wasn't implied:
Acked-by Chad Sellers <[email protected]>--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Signature · 8 lines
James Carter <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 198 lines · James Carter
Quoted 180 lines · Chad Sellers
Quoted 169 lines · Caleb Case
Our motivations for this patchset are to:
* Move the semanage store - the portion of the SELinux configuration managed by libsemanage - to a more appropriate location in the filesystem. The current location - in /etc - is designated for administrator controlled configuration and is sometimes mounted read-only. By storing binary, program managed data in /etc libsemanage breaks administrator expectations.
* Enable the overriding of modules in the module store without require the original modules to removed or modified. This allows administrators to customize the policy more fully while allowing the distribution provided policies to be left unmodified and continue to be updated by the package manager.
* Provide the ability for an administrator to disable a module without removing or overriding that module.
[Move to
/var/lib/selinux]Move the libsemanage private store
from /etc/selinux/<policy type>/modules
to /var/lib/selinux/<policy type>The benefits of this are:
* Permits the use of a read-only /etc.
* Conforms to the Filesystem Hierarchy Standard.
An additional change in layout structure moves the temporary space for the active policy to an external temporary space. This has the benefit of permitting source control management to be used on the private policy.
[Module Priorities]
Module priorities modify libsemanage and the module store to allow multiple modules with the same name to exist with different priorities. Only the highest priority module is used to create the final system policy. The addition of module priorities enables the modification of the system policy without modifying individual modules. For example, it allows an administrator to add his own policy module for apache, completely replacing the distribution provided module, without changing or removing the distribution policy. This has several benefits:
* Distribution provided policy package updates proceed normally - the distribution policy is inserted but the administrator provided policy remains active.
* Multiple levels allows distributors, 3rd party applications, system management tools (e.g., puppet), and local administrators to all make changes without conflicting.
* Semanage modifications of policy (e.g., port labeling) will be able to use high priority modules in the future to override defaults (requires the CIL[1] language changes).
[Enable/Disable Modules]
Modules gain an enabled / disabled status. Enabled modules are used by semanage when building the active policy, and disabled modules are ignored. The main benefit of this is that modules can be disabled without out removing them from the store.
[Patchset Breakdown]
The patchset is broken down as follows:
Bug fixes:
libsemanage: fix type in tests makefile -o -> -O
Move the libsemanage store to
/var/lib/selinux:semanage: move permissive module creation to /tmp
libsemanage: move the module store to/var/lib/selinux
libsemanage: split final files into/var/lib/selinux/tmp
libsemanage: update unit tests for move to/var/lib/selinuxImplement support for the new libsemanage store layout:
libsemanage: add default priority to
semanage_handle_t
libsemanage: augmentsemanage_module_info_tand providesemanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and keyProvide private headers for upstream tools to use:
libsemanage: new private api for unstable functions
Extend semodule to support enable/disable, priorities, and detailed listings:
semodule: add priority, enabled, and extended listing
Migration script for moving the libsemanage store:
semanage store migration script
Thanks for you feedback!
Caleb
[1] CIL RFC: http://marc.info/?l=selinux&m=124759244409438&w=2
Caleb Case (13):
libsemanage: fix typo in tests makefile -o -> -O
semanage: move permissive module creation to /tmp
libsemanage: move the module store to/var/lib/selinux
libsemanage: split final files into/var/lib/selinux/tmp
libsemanage: update unit tests for move to/var/lib/selinux
libsemanage: add default priority tosemanage_handle_t
libsemanage: augmentsemanage_module_info_tand provide
semanage_module_key_t
libsemanage: get/set module info and enabled status
libsemanage: provide function to get new base module path
libsemanage: installing/upgrading/removing modules via info and key
libsemanage: new private api for unstable functions
semodule: add priority, enabled, and extended listing semanage store migration scriptlibsemanage/include/Makefile | 3 + libsemanage/include/semanage/private/handle.h | 31 + libsemanage/include/semanage/private/modules.h | 281 ++++ libsemanage/include/semanage/private/semanage.h | 26 + libsemanage/src/boolean_internal.h | 4 +- libsemanage/src/booleans_file.c | 7 +- libsemanage/src/booleans_policydb.c | 6 +- libsemanage/src/database_file.c | 45 +- libsemanage/src/database_file.h | 3 +- libsemanage/src/database_policydb.c | 37 +- libsemanage/src/database_policydb.h | 3 +- libsemanage/src/direct_api.c | 1652 +++++++++++++++++++--- libsemanage/src/fcontext_internal.h | 3 +- libsemanage/src/fcontexts_file.c | 7 +- libsemanage/src/genhomedircon.c | 3 +- libsemanage/src/handle.c | 23 + libsemanage/src/handle.h | 3 + libsemanage/src/handle_internal.h | 1 + libsemanage/src/iface_internal.h | 4 +- libsemanage/src/interfaces_file.c | 7 +- libsemanage/src/interfaces_policydb.c | 6 +- libsemanage/src/libsemanage.map | 26 + libsemanage/src/module_internal.h | 21 + libsemanage/src/modules.c | 999 +++++++++++++- libsemanage/src/modules.h | 76 +- libsemanage/src/node_internal.h | 4 +- libsemanage/src/nodes_file.c | 7 +- libsemanage/src/nodes_policydb.c | 6 +- libsemanage/src/policy.h | 36 + libsemanage/src/port_internal.h | 4 +- libsemanage/src/ports_file.c | 7 +- libsemanage/src/ports_policydb.c | 6 +- libsemanage/src/semanage_store.c | 794 ++++++++--- libsemanage/src/semanage_store.h | 47 +- libsemanage/src/seuser_internal.h | 4 +- libsemanage/src/seusers_file.c | 7 +- libsemanage/src/user_internal.h | 6 +- libsemanage/src/users_base_file.c | 7 +- libsemanage/src/users_base_policydb.c | 6 +- libsemanage/src/users_extra_file.c | 7 +- libsemanage/tests/Makefile | 2 +- libsemanage/tests/test_semanage_store.c | 34 +- libsemanage/utils/semanage_migrate_etc_to_var.py | 301 ++++Quoted 9 lines
policycoreutils/semanage/seobject.py | 15 +- policycoreutils/semodule/semodule.8 | 25 +- policycoreutils/semodule/semodule.c | 242 +++- 46 files changed, 4267 insertions(+), 577 deletions(-) create mode 100644 libsemanage/include/semanage/private/handle.h create mode 100644 libsemanage/include/semanage/private/modules.h create mode 100644 libsemanage/include/semanage/private/semanage.h create mode 100755 libsemanage/utils/semanage_migrate_etc_to_var.pyQuoted 7 lines
Well, there have been no comments on this patchset. I'm guessing that's because:
1) We've talked to some of you face to face about it already.
2) It's a big patchset, and you'd want to try it out a bit before commenting.I've been trying it out for the last few days. I haven't had any problems yet.
Quoted 7 lines
To address #2, I'd like to propose creating an upstream branch for these changes. This patchset is actually just the first patchset in a larger effort to improve policy infrastructure. I think an upstream branch will make it easier for many people to track those changes and try out the new features we're creating. Eventually that branch can be merged back into master.
Quoted 4 lines
Quoted 1 line
Thoughts?
I think that creating an upstream branch would be a good idea.
OK, I've created an upstream branch called src-policy and merged these patches there. The name may seem odd right now, but the patchset we're about to send (hopefully next week) will make it clear why it's named that. Anyone that wants to play with this can check out that branch, and anyone who wants to contribute can submit patches that apply to that branch. Note that all patches will still flow through the list for this branch.
Thanks,
Chad
Quoted 4 lines
Quoted 4 lines
Thanks,
Chad Sellers
Quoted 8 lines
Quoted 8 lines
Oh, and in case it wasn't implied:
Acked-by Chad Sellers <[email protected]>--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.