Check if policy file is MLS enabled
libsepol/include/sepol/policydb.h +8 -0
@@ -53,6 +53,14 @@ extern void sepol_policy_file_set_fp(sepextern void sepol_policy_file_set_handle (sepol_policy_file_t *pf,sepol_handle_t *handle); +/* +* Check if the policy file enables MLS +*/ + +extern int sepol_policy_file_mls_enabled ( +sepol_policy_file_t * spf, +int * mls_enabled); +/* Policydb public interfaces. */ /* Create and free memory associated with a policydb. */
libsepol/src/policydb_public.c +60 -0
72 lines not on this page · raw message
libsepol/src/user_record.c +1 -1
@@ -271,7 +271,7 @@ int sepol_user_get_roles(hidden_def (sepol_user_get_roles) void sepol_user_del_role( -sepol_handle_t * handle, +sepol_handle_t * handle,sepol_user_t * user,const char * role) {
A much better way to do this would be to extract the header reading from policydb_read and make a helper function that does it. You will still be able to do a partial parse of the binary but only 1 function will have to be changed when a format change happens.
Quoted 103 lines · Ivan Gyurdiev
------------------------------------------------------------------------
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policycoreutils --exclude libsemanage --exclude 'booleans_kernel.*' --exclude 'database_pserver.*'
old/libsepol/include/sepol/policydb.hnew/libsepol/include/sepol/policydb.hlibsepol/include/sepol/policydb.h +8
-0@@ -53,6 +53,14 @@ extern void sepol_policy_file_set_fp(sepextern void sepol_policy_file_set_handle (sepol_policy_file_t *pf,sepol_handle_t *handle); +/* +* Check if the policy file enables MLS +*/ + +extern int sepol_policy_file_mls_enabled ( +sepol_policy_file_t * spf, +int * mls_enabled); +/* Policydb public interfaces. */ /* Create and free memory associated with a policydb. */ diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policycoreutils --exclude libsemanage --exclude 'booleans_kernel.*' --exclude 'database_pserver.*'
old/libsepol/src/policydb_public.cnew/libsepol/src/policydb_public.clibsepol/src/policydb_public.c +60
-0@@ -1,6 +1,8 @@#include <stdlib.h> +#include "handle.h" #include "debug.h" +#include "private.h" #include <sepol/policydb/policydb.h> #include "policydb_internal.h" @@ -60,6 +62,64 @@ void sepol_policy_file_free(sepol_policyfree (pf); } +int sepol_policy_file_mls_enabled ( +sepol_policy_file_t * spf, +int * mls_enabled) { + +sepol_handle_t * handle = spf->pf.handle; +struct policy_file * pf = &spf->pf; +unsigned int policy_type; +uint32_t *buf; + +/** +* 4 bytes magic +* 4 bytes ID length x +* x bytes ID string +* (modules only): 4 bytes module type +* 4 bytes policy version +* 4 bytes mls status */ + +/* Magic, ID length */ +if (!(buf =next_entry (pf,sizeof (uint32_t )*2 ))) + goto err; + +/* Check policy type */ + buf[0 ] =le32_to_cpu (buf[0 ]); +if (buf[0 ] ==POLICYDB_MAGIC ) + policy_type =POLICY_KERN ; +else if (buf[0 ] ==POLICYDB_MOD_MAGIC ) + policy_type =POLICY_MOD ; +else { +ERR (handle,"policydb magic number %#08x does not " +"match expected magic number %#08x or %#08x" , + buf[0 ],POLICYDB_MAGIC ,POLICYDB_MOD_MAGIC ); +return STATUS_ERR ; + } + +/* Skip ID string */ + buf[1 ] =le32_to_cpu (buf[1 ]); +if (!next_entry (pf, buf[1 ])) + goto err; + +/* Skip module type */ +if (policy_type ==POLICY_MOD && + !next_entry (pf,sizeof (uint32_t ))) + goto err; + +/* Skip policy version */ +if (!(buf =next_entry (pf,sizeof (uint32_t )*2 ))) + goto err; + +/* Is MLS enabled? */ + buf[1 ] =le32_to_cpu (buf[1 ]); + *mls_enabled = (buf[1 ] &POLICYDB_CONFIG_MLS )?1 :0 ; +return STATUS_SUCCESS ; + + err: +ERR (handle,"truncated policy file - could not check MLS status" ); +return STATUS_ERR ; +} +/* Policydb interfaces. */ int sepol_policydb_create (sepol_policydb_t **sp)diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policycoreutils --exclude libsemanage --exclude 'booleans_kernel.*' --exclude 'database_pserver.*'
old/libsepol/src/user_record.cnew/libsepol/src/user_record.c
libsepol/src/user_record.c int sepol_user_get_roles( · line 277
Quoted 8 lines
libsepol/src/user_record.c +1
-1@@ -271,7 +271,7 @@ int sepol_user_get_roles(hidden_def (sepol_user_get_roles) void sepol_user_del_role( -sepol_handle_t * handle, +sepol_handle_t * handle,sepol_user_t * user,const char * role) {
--
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 1 line · Joshua Brindle
A much better way to do this would be to extract the header reading from
policydb_readand make a helper function that does it. You will still be able to do a partial parse of the binary but only 1 function will have to be changed when a format change happens.
That's true.. will fix.
--
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 6 lines · Ivan Gyurdiev
Quoted 4 lines · Joshua Brindle
A much better way to do this would be to extract the header reading from
policydb_readand make a helper function that does it. You will still be able to do a partial parse of the binary but only 1 function will have to be changed when a format change happens.That's true.. will fix.
Other issue here (as noted off-list) is whether this should be acting on a module/policy file directly or on a module package file. The latter seems more suitable for use by libsemanage, like the existing _info interface.
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 12 lines
Quoted 5 lines
Quoted 3 lines
A much better way to do this would be to extract the header reading from
policydb_readand make a helper function that does it. You will still be able to do a partial parse of the binary but only 1 function will have to be changed when a format change happens.That's true.. will fix.
Other issue here (as noted off-list) is whether this should be acting on a module/policy file directly or on a module package file. The latter seems more suitable for use by libsemanage, like the existing
_infointerface.
We could put the fields that get_package_info returns into a structure, and add the mls status to those?
--
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 2 lines · Ivan Gyurdiev
We could put the fields that
get_package_inforeturns into a structure, and add the mls status to those?
I'd just add it as an extra argument to sepol_module_package_info, or add a separate interface for it. Structure doesn't really buy you anything.
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 8 lines · Ivan Gyurdiev
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
A much better way to do this would be to extract the header reading from
policydb_readand make a helper function that does it. You will still be able to do a partial parse of the binary but only 1 function will have to be changed when a format change happens.That's true.. will fix.
Quoted 8 lines
Quoted 6 lines
Other issue here (as noted off-list) is whether this should be acting on a module/policy file directly or on a module package file. The latter seems more suitable for use by libsemanage, like the existing
_infointerface.We could put the fields that
get_package_inforeturns into a structure, and add the mls status to those?
Actually, given that the MLS-enabled code in libsemanage already gracefully handles the case where the MLS range is omitted, why not just remove the conditional altogether and avoid the need for this interface in sepol?
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 15 lines · Stephen Smalley
Quoted 14 lines · Ivan Gyurdiev
Quoted 14 lines
Quoted 7 lines
Quoted 5 lines
A much better way to do this would be to extract the header reading from
policydb_readand make a helper function that does it. You will still be able to do a partial parse of the binary but only 1 function will have to be changed when a format change happens.That's true.. will fix.
Other issue here (as noted off-list) is whether this should be acting on a module/policy file directly or on a module package file. The latter seems more suitable for use by libsemanage, like the existing
_infointerface.
Quoted 7 lines
Quoted 2 lines
We could put the fields that
get_package_inforeturns into a structure, and add the mls status to those?Actually, given that the MLS-enabled code in libsemanage already gracefully handles the case where the MLS range is omitted, why not just remove the conditional altogether and avoid the need for this interface in sepol?
Patch below.
Index: libsemanage/src/seusers_file.c
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libsemanage/src/seusers_file.c,v retrieving revision 1.10
src/seusers_file.c +15 -17
@@ -80,23 +80,21 @@ static int seuser_parse(free (str); str =NULL ; -if (is_selinux_mls_enabled ()) { -if (parse_skip_space (handle, info) <0 ) - goto err; -if (parse_optional_ch (info,':' ) ==STATUS_NODATA ) - goto out; -if (parse_skip_space (handle, info) <0 ) - goto err; - -/* NOTE: does not allow spaces/multiline */ -if (parse_fetch_string (handle, info, &str,' ' ) <0 ) - goto err; - -if (semanage_seuser_set_mlsrange (handle, seuser, str) <0 ) - goto err; -free (str); - str =NULL ; - } +if (parse_skip_space (handle, info) <0 ) + goto err; +if (parse_optional_ch (info,':' ) ==STATUS_NODATA ) + goto out; +if (parse_skip_space (handle, info) <0 ) + goto err; + +/* NOTE: does not allow spaces/multiline */ +if (parse_fetch_string (handle, info, &str,' ' ) <0 ) + goto err; + +if (semanage_seuser_set_mlsrange (handle, seuser, str) <0 ) + goto err; +free (str); + str =NULL ;if (parse_assert_space (handle, info) <0 ) goto err;
Index: libsemanage/src/users_file.c
===================================================================
RCS file: /nfshome/pal/CVS/selinux-usr/libsemanage/src/users_file.c,v retrieving revision 1.19
src/users_file.c +31 -34
72 lines not on this page · raw message
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.