user - to_record fn, mls cleanups
- moves code from user iterate() to user_to_record, like it was done for other things (this code can now be shared for query).
- renames mls_struct_* prefix to mls_* for consistency w/ other mls code
- change context_from_string to use mls_from_string, which simplifies this function (because that's a better interface that respects const char*, for example)
libsepol/include/sepol/policydb/mls.h +2 -2
@@ -34,12 +34,12 @@#include <sepol/policydb/context.h> #include <sepol/policydb/policydb.h> -extern int mls_struct_from_string ( +extern int mls_from_string (policydb_t * policydb,const char * str,context_struct_t * mls); -extern int mls_struct_to_string ( +extern int mls_to_string (policydb_t * policydb,context_struct_t * mls,char ** str);
libsepol/src/context.c +10 -16
@@ -124,10 +124,9 @@ int context_to_string(return STATUS_ERR ; } - -/* Create a policy-dependent context structure, corresponding -* to the provided high level representation */ - +/* +* Create a context structure from the given record +*/ int context_from_record( policydb_t* policydb, context_struct_t** cptr,
@@ -142,13 +141,10 @@ int context_from_record(char * user =strdup (sepol_context_get_user (record));char * role =strdup (sepol_context_get_role (record));char * type =strdup (sepol_context_get_type (record)); - -const char * tmp =sepol_context_get_mls (record); -char * mls = tmp ?strdup (tmp):NULL ; -char * mls_ptr = mls; +const char * mls =sepol_context_get_mls (record); scontext = (context_struct_t *)malloc (sizeof (context_struct_t)); -if (!user || !role || !type || (tmp && !mls) || !scontext) { +if (!user || !role || !type || !mls || !scontext) {DEBUG (__FUNCTION__,"out of memory\n" ); goto err; }
@@ -185,7 +181,6 @@ int context_from_record(if (mls && !policydb->mls) {DEBUG (__FUNCTION__,"Warning! mls context \"%s\" found, " "but mls is disabled\n" , mls); -free (mls); mls =NULL ; }else if (!mls && policydb->mls) {
@@ -193,7 +188,7 @@ int context_from_record( "mls context found\n"); goto err_destroy; } -if (mls && (mls_context_to_sid (policydb,'$' , &mls_ptr, scontext) <0 )) { +if (mls && (mls_from_string (policydb, mls, scontext) <0 )) {DEBUG (__FUNCTION__,"invalid mls context: %s\n" , mls); goto err_destroy; }
@@ -217,7 +212,6 @@ int context_from_record(free (user);free (type);free (role); -free (mls);return STATUS_SUCCESS ; err_destroy:
@@ -228,13 +222,13 @@ int context_from_record(free (user);free (type);free (role); -free (mls);DEBUG (__FUNCTION__,"error creating context structure\n" );return STATUS_ERR ; } -/* Create a record from the context structure */ - +/* +* Create a record from the given context structure +*/ int context_to_record( policydb_t* policydb, context_struct_t* context,
@@ -259,7 +253,7 @@ int context_to_record( goto err;if (policydb->mls) { -if (mls_struct_to_string (policydb, context, &mls) <0 ) +if (mls_to_string (policydb, context, &mls) <0 ) goto err;if (sepol_context_set_mls (tmp_record, mls) <0 )
libsepol/src/mls.c +2 -2
@@ -38,7 +38,7 @@#include "debug.h" #include "private.h" -int mls_struct_to_string ( +int mls_to_string (policydb_t * policydb,context_struct_t * mls,char ** str) {
@@ -73,7 +73,7 @@ int mls_struct_to_string( } -int mls_struct_from_string ( +int mls_from_string (policydb_t * policydb,const char * str,context_struct_t * mls) {
libsepol/src/users.c +73 -60
178 lines not on this page · raw message