User, context, port records. Bugfixes.
The following patch replaces the previously added high level structures:
sepol_ctxinfo_tsepol_portinfo_tsepol_uinfo_t
with opaque records:
sepol_context_tsepol_port_tsepol_user_t
The idea is that those opaque records can be re-used by libsemanage (not sure exactly how to do that without re-implementing the entire interface and calling each sepol function). In any case, the change stands independently of libsemanage, and using opaque data structures in interfaces is a good idea.
Other changes:
- changed namespace to some functions in context.c to sepol_ctx_struct, in order not to conflict with the record namespace
- fixed a memory leak in context.c on mls-disabled systems with mls contexts
- fixed improper use of mls_context_to_sid in users.c that would cause a crash.
- made some error messages more clear/verbose
include/sepol/context.h +6 -20
@@ -21,18 +21,7 @@#include <sepol/ebitmap.h> #include <sepol/mls_types.h> - -/* -* High level representation of the context -* This structure provides sufficient information -* to construct a security context. -*/ -typedef struct sepol_ctxinfo { -const char * user; -const char * role; -const char * type; -const char * mls; -}sepol_ctxinfo_t ; +#include <sepol/context_record.h> /* * A security context consists of an authenticated user
@@ -125,31 +114,28 @@struct policydb ;/* Create a context structure from high level representation */ -extern int sepol_context_create ( +extern int sepol_ctx_struct_create (struct policydb *policydb,context_struct_t ** cptr, -sepol_ctxinfo_t * data); +sepol_context_t data);/* Create a context structure from string representation */ -extern int sepol_context_from_string ( +extern int sepol_ctx_struct_from_string (struct policydb * policydb,context_struct_t ** cptr,const char * con_str,size_t con_str_len);/* Check if the provided context is valid for this policy */ -extern int sepol_context_is_valid ( +extern int sepol_ctx_struct_is_valid (struct policydb *policydb,context_struct_t *context);/* Extract the context as string */ -extern int sepol_context_to_string ( +extern int sepol_ctx_struct_to_string (struct policydb *policydb,context_struct_t * context,char ** result,size_t *result_len);#endif /* _SEPOL_CONTEXT_H_ */ - -/* FLASK */ -
include/sepol/context_record.h +35 -0
@@ -0,0 +1,35 @@ +#ifndef _SEPOL_CONTEXT_RECORD_H_ +#define _SEPOL_CONTEXT_RECORD_H_ + +struct sepol_context; +typedef struct sepol_context *sepol_context_t ; + +/* We don't need a key, because the context is never stored +* in a data collection by itself */ + +/* User */ +extern const char *sepol_context_get_user (sepol_context_t con); +extern int sepol_context_set_user (sepol_context_t con,const char * user); + +/* Role */ +extern const char *sepol_context_get_role (sepol_context_t con); +extern int sepol_context_set_role (sepol_context_t con,const char * role); + +/* Type */ +extern const char *sepol_context_get_type (sepol_context_t con); +extern int sepol_context_set_type (sepol_context_t con,const char * type); + +/* MLS */ +extern const char *sepol_context_get_mls (sepol_context_t con); +extern int sepol_context_set_mls (sepol_context_t con,const char * mls_range); + +/* Create/Clone/Destroy */ +extern int sepol_context_create (sepol_context_t * con_ptr); +extern int sepol_context_clone (sepol_context_t con,sepol_context_t * con_ptr); +extern void sepol_context_free (sepol_context_t con); + +/* Parse to/from string */ +extern int sepol_context_from_string (const char * str,sepol_context_t * con); +extern char *sepol_context_to_string (sepol_context_t con); + +#endif
include/sepol/interfaces.h +3 -3
@@ -1,11 +1,11 @@#include <sepol/policydb.h> -#include <sepol/context.h> +#include <sepol/context_record.h> /* High level representation of an interface */ typedef struct sepol_iface {const char * name; -sepol_ctxinfo_t netif_con; -sepol_ctxinfo_t netmsg_con; +sepol_context_t netif_con; +sepol_context_t netmsg_con; }sepol_iface_t ;/* Create a low level interface structure from
include/sepol/policydb.h +1 -1
@@ -454,7 +454,7 @@/* Deprecated */ static inline int policydb_context_isvalid (policydb_t *p,context_struct_t *c) { -return sepol_context_is_valid (p,c); +return sepol_ctx_struct_is_valid (p,c); }extern void symtabs_destroy (symtab_t *symtab);
include/sepol/port_record.h +46 -0
46 lines not on this page · raw message
include/sepol/ports.h +6 -21
@@ -2,41 +2,26 @@#define _SEPOL_PORTS_H_#include <sepol/policydb.h> -#include <sepol/context.h> - -#define SEPOL_TCP_PROTO 0 -#define SEPOL_UDP_PROTO 1 - -/* High level representation of a port */ -typedef struct sepol_portinfo { - -/* Port parameters */ -int protocol; -int low, high; - -/* Sufficient information to construct -* the port context */ -sepol_ctxinfo_t con; -}sepol_portinfo_t ; +#include <sepol/port_record.h> /* Create a port structure from high level representation */ -extern int sepol_port_create ( +extern int sepol_port_struct_create (policydb_t * policydb,ocontext_t ** port, -sepol_portinfo_t * data); +sepol_port_t data);/* Get the current context mapping * for this port. Returns 1 if no match, -1 on error, 0 on * success. The returned data is allocated on the heap */ int sepol_port_get_context (policydb_t * policydb, -sepol_portinfo_t * data, +sepol_port_t data,char ** con_str,size_t * con_str_len);/* Load the given port into policy. No shadowing is allowed. */ extern int sepol_port_load (policydb_t * policydb, -sepol_portinfo_t * port); +sepol_port_t data); -#endif /* _SEPOL_PORTS_H_ */ +#endif
include/sepol/user_record.h +61 -0
61 lines not on this page · raw message
include/sepol/users.h +3 -11
@@ -2,17 +2,9 @@#define _SEPOL_USERS_H_#include <sepol/policydb.h> +#include <sepol/user_record.h> #include <sys/types.h> -/* High level representation of a user */ -typedef struct sepol_uinfo { -const char * name; -const char ** roles; -size_t num_roles; -const char * mls_level; -const char * mls_range; -}sepol_uinfo_t ; -/* Clear unused users */ extern void sepol_clear_unused_users (policydb_t * policydb);
@@ -21,7 +13,7 @@Load allows duplicates, but add does not. */ extern int sepol_user_add (policydb_t * policydb, -sepol_uinfo_t * user); +sepol_user_t user); extern int sepol_user_del( policydb_t* policydb,
@@ -29,7 +21,7 @@extern int sepol_user_load (policydb_t * policydb, -sepol_uinfo_t * user); +sepol_user_t user);/* Check if users or roles are valid */ extern int sepol_user_is_valid(
src/context.c +29 -52
159 lines not on this page · raw message
src/context_record.c +257 -0
257 lines not on this page · raw message
src/interfaces.c +7 -7
@@ -30,15 +30,15 @@ goto omem;/* Interface Context */ -if (sepol_context_create (policydb, &tmp_ifcon, - &data->netif_con) <0 ) +if (sepol_ctx_struct_create (policydb, + &tmp_ifcon, data->netif_con) <0 ) goto err;context_cpy (&tmp_iface->context[0 ], tmp_ifcon);free (tmp_ifcon);/* Message Context */ -if (sepol_context_create (policydb, &tmp_msgcon, - &data->netmsg_con) <0 ) +if (sepol_ctx_struct_create (policydb, &tmp_msgcon, + data->netmsg_con) <0 ) goto err;context_cpy (&tmp_iface->context[1 ], tmp_msgcon);free (tmp_msgcon);
@@ -67,11 +67,11 @@ head = policydb->ocontexts[OCON_NETIF ];for (c = head; c; c = c->next) {if (!strcmp (data->name, c->u.name)) { -if (sepol_context_to_string (policydb, +if (sepol_ctx_struct_to_string (policydb, &c->context[0 ], ifcon_str, ifcon_str_len) <0 ) goto err; -if (sepol_context_to_string (policydb, +if (sepol_ctx_struct_to_string (policydb, &c->context[1 ], msgcon_str, msgcon_str_len) <0 ) goto err;
@@ -82,7 +82,7 @@return STATUS_NODATA ; err: -DEBUG (__FUNCTION__,"could not construct context string for " +DEBUG (__FUNCTION__,"could not construct context string for " "interface %s\n" , data->name);return STATUS_ERR ; }
src/port_record.c +168 -0
168 lines not on this page · raw message
src/ports.c +28 -33
141 lines not on this page · raw message
src/services.c +2 -2
@@ -483,7 +483,7 @@char ** result, size_t *result_len) { - return sepol_context_to_string(policydb, context, result, result_len); + return sepol_ctx_struct_to_string(policydb, context, result, result_len); }/*
@@ -523,7 +523,7 @@context_struct_t * context =NULL ;/* First, create the context */ -if (sepol_context_from_string (policydb, &context, +if (sepol_ctx_struct_from_string (policydb, &context, scontext, scontext_len) <0 ) goto err;
src/user_record.c +341 -0
341 lines not on this page · raw message
src/users.c +55 -47
218 lines not on this page · raw message
Libsepol ongoing
The following ongoing things need IMHO need completion for libsepol. I just thought I'd list them here, since I'll be gone
for the next three weeks, and maybe someone wants to work on something.
1) Replace all use of printf/fprintf with new debug system
2) Replace all use of __sepol_debug_printf with new debug system
3) Replace boolean and interface data structures with opaque records for libsemanage (see how the other ones are done)
4) Move all non-exported functions without static callers out of the headers, and into internal headers.
5) Move checkpolicy scope support into libsepol, and add scope checking on symbol lookups (?)
6) Replace duplicate checkpolicy user/port/context support with calls to libsepol
--
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.
[ libsemanage ] Relay libsepol records
In reply to Ivan GyurdievThe following patch relays records in libsemange to the ones in libsepol - depends on previous patch for libsepol.
Records being added will be used in the future.
include/semanage/context_record.h +78 -0
@@ -0,0 +1,78 @@ +#ifndef _SEMANAGE_CONTEXT_RECORD_H_ +#define _SEMANAGE_CONTEXT_RECORD_H_ + +/* Implementation via sepol */ +#include <sepol/context_record.h> +typedef sepol_context_t semanage_context_t ; + +/* User */ +static inline +const char *semanage_context_get_user (semanage_context_t con) { +return sepol_context_get_user (con); +} + +static inline +int semanage_context_set_user (semanage_context_t con,const char * user) { +return sepol_context_set_user (con, user); +} + +/* Role */ +static inline +const char *semanage_context_get_role (semanage_context_t con) { +return sepol_context_get_role (con); +} + +static inline +int semanage_context_set_role (semanage_context_t con,const char * role) { +return sepol_context_set_role (con, role); +} + +/* Type */ +static inline +const char *semanage_context_get_type (semanage_context_t con) { +return sepol_context_get_type (con); +} + +static inline +int semanage_context_set_type (semanage_context_t con,const char * type) { +return sepol_context_set_type (con, type); +} + +/* MLS */ +static inline +const char *semanage_context_get_mls (semanage_context_t con) { +return sepol_context_get_mls (con); +} + +static inline +int semanage_context_set_mls (semanage_context_t con,const char * mls_range) { +return sepol_context_set_mls (con, mls_range); +} + +/* Create/Clone/Destroy */ +static inline +int semanage_context_create (semanage_context_t * con_ptr) { +return sepol_context_create (con_ptr); +} + +static inline +int semanage_context_clone (semanage_context_t con,semanage_context_t * con_ptr) { +return sepol_context_clone (con, con_ptr); +} + +static inline +void semanage_context_free (semanage_context_t con) { +sepol_context_free (con); +} + +/* Parse to/from string */ +static inline +int semanage_context_from_string (const char * str,semanage_context_t * con) { +return sepol_context_from_string (str, con); +} + +static inline +char *semanage_context_to_string (semanage_context_t con) { +return sepol_context_to_string (con); +} +#endif
include/semanage/port_record.h +95 -0
95 lines not on this page · raw message
include/semanage/user_record.h +119 -0
119 lines not on this page · raw message
Re: [ libsemanage ] Key extract function
The following patch implements the key extract function. The key is basically the part of the record that uniquely identifies it in a collection of the same records. This introduces the concept of a record collection in libsepol, which may be the wrong place for it, but I think for now it should stay there.
This patch provides a way to obtain the key given the data structure.
The key is part of the data structure, which may seem unnecessarily redundant, but I think it's the right interface - we may choose to change this behavior in the future, and it just seems wrong to pass a data structure partially filled as the key to functions like query() or destroy() (in semanage).
======
Note that the port key will create problems - I might need to change that, because the same key can match many different records, which breaks the definition of a key, and causes chaos in the libsemanage processing layer. I think for now leave it as is, and we'll fix it later if necessary - I am not entirely clear how libsemanage will work in order to select a proper key.
include/semanage/port_record.h +9 -2
@@ -20,8 +20,15 @@ int semanage_port_compare(semanage_port_static inline int semanage_port_key_create (int low,int high,int proto, -semanage_port_key_t * key) { -return sepol_port_key_create (low, high, proto, key); +semanage_port_key_t * key_ptr) { +return sepol_port_key_create (low, high, proto, key_ptr); +} + +static inline +int semanage_port_key_extract ( +semanage_port_t port, +semanage_port_key_t * key_ptr) { +return sepol_port_key_extract (port, key_ptr); } static inline
include/semanage/user_record.h +5 -0
@@ -12,6 +12,11 @@ int semanage_user_key_create(const char*return sepol_user_key_create (name, key); } +static inline +int semanage_user_key_extract (semanage_user_t user,semanage_user_key_t * key) { +return sepol_user_key_extract (user, key); +} +static inline void semanage_user_key_free (semanage_user_key_t key) {sepol_user_key_free (key);
include/sepol/port_record.h +5 -1
@@ -18,7 +18,11 @@ extern int sepol_port_compare(extern int sepol_port_key_create (int low,int high,int proto, -sepol_port_key_t * key); +sepol_port_key_t * key_ptr); + +extern int sepol_port_key_extract ( +sepol_port_t port, +sepol_port_key_t * key_ptr);extern void sepol_port_key_free (sepol_port_key_t key);
include/sepol/user_record.h +4 -0
@@ -11,6 +11,10 @@ extern int sepol_user_key_create(const char * name, sepol_user_key_t* key); +extern int sepol_user_key_extract ( +sepol_user_t user, +sepol_user_key_t * key_ptr); +extern void sepol_user_key_free (sepol_user_key_t key);
src/port_record.c +12 -0
@@ -46,6 +46,18 @@ int sepol_port_key_create(return STATUS_SUCCESS ; } +int sepol_port_key_extract (sepol_port_t port,sepol_port_key_t * key_ptr) { +if (sepol_port_key_create ( + port->low, port->high, port->proto, key_ptr) <0 ) { +DEBUG (__FUNCTION__,"could not extract key from " +"port %s %d:%d\n" ,sepol_port_get_proto_str (port), + port->low, port->high); +return STATUS_ERR ; + } + +return STATUS_SUCCESS ; +} +void sepol_port_key_free (sepol_port_key_t key) {free (key); }
src/user_record.c +10 -0
@@ -47,6 +47,16 @@ int sepol_user_key_create( *key_ptr = tmp_key;return STATUS_SUCCESS ; +} + +int sepol_user_key_extract (sepol_user_t user,sepol_user_key_t * key_ptr) { +if (sepol_user_key_create (user->name, key_ptr) <0 ) { +DEBUG (__FUNCTION__,"could not extract key from user %s\n" , + user->name); +return STATUS_ERR ; + } + +return STATUS_SUCCESS ; }void sepol_user_key_free (sepol_user_key_t key) {
Re: [ libsemanage ] Key extract function
Quoted 7 lines
Note that the port key will create problems - I might need to change that, because the same key can match many different records, which breaks the definition of a key, and causes chaos in the libsemanage processing layer. I think for now leave it as is, and we'll fix it later if necessary - I am not entirely clear how libsemanage will work in order to select a proper key.
Actually because shadowing is not allowed, this will work exactly as it should. Multiple keys can match the same value, but that's not a problem - that's a feature.
--
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: [ libsemanage ] Key extract function
In reply to Ivan GyurdievQuoted 6 lines · Ivan Gyurdiev
The following patch implements the key extract function. The key is basically the part of the record that uniquely identifies it in a collection of the same records. This introduces the concept of a record collection in libsepol, which may be the wrong place for it, but I think for now it should stay there.
Quoted 7 lines
This patch provides a way to obtain the key given the data structure.
The key is part of the data structure, which may seem unnecessarily redundant, but I think it's the right interface - we may choose to change this behavior in the future, and it just seems wrong to pass a data structure partially filled as the key to functions like
query()ordestroy()(in semanage).
Thanks, merged.
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: [ libsemanage ] Relay libsepol records
In reply to Ivan GyurdievQuoted 4 lines · Ivan Gyurdiev
The following patch relays records in libsemange to the ones in libsepol - depends on previous patch for libsepol.
Records being added will be used in the future.
Thanks, merged.
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 27 lines · Ivan Gyurdiev
The following patch replaces the previously added high level structures:
sepol_ctxinfo_tsepol_portinfo_tsepol_uinfo_twith opaque records:
sepol_context_tsepol_port_tsepol_user_tThe idea is that those opaque records can be re-used by libsemanage (not sure exactly how to do that without re-implementing the entire interface and calling each sepol function). In any case, the change stands independently of libsemanage, and using opaque data structures in interfaces is a good idea.
Other changes:
- changed namespace to some functions incontext.ctosepol_ctx_struct, in order not to conflict with the record namespace
Quoted 7 lines
- fixed a memory leak in
context.con mls-disabled systems with mls contexts- fixed improper use of
mls_context_to_sidinusers.cthat would cause a crash.- made some error messages more clear/verbose
Thanks, merged.
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.