Context reorganization
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest6 patches 85 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | Fix memory leakssrc/ src/ src/ +1 more | +12 | 2 replies | |
| 2/6 | Portsinclude/ src/ | +209 | 59 replies | |
| 3/6 | Usersinclude/ src/ src/ | +468 | 2 replies | |
| 4/6 | Booleansinclude/ src/ | +102 | 0 replies | |
| 5/6 | Policydb_convert in legacysrc/ src/ | +28 | 0 replies | |
| 6/6 | Summary | +0 | 4 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [ libsepol 0/6] Context reorganization
The following patch moves functions relating to context_struct_t into file contexts.c for better organization. It makes all of them take policydb as argument, and enforces the sepol_ prefix. It uses the new debugging system. It adds a structure for a high level representation of a context (sepol_ctxinfo_t), and a new function to convert from it (sepol_context_create), and makes use of that function to make the conversion from string (formerly sepol_context_to_sid) easier.
libsepol-1.1-context.diff
Disclaimer 1:
The following bit, as taken from the current policydb_context_isvalid fails for me currently. I don't understand the role of the cache here. Does genusers.c need to be modified to do something with the cache, when it loads the user? Do I need to correspondingly modify my own load_user function (which is based on genusers)?
+ if (!ebitmap_get_bit(&usrdatum->cache, c->role - 1))
+ /* user may not be associated with role */
+ return 0;
Disclaimer 2:
What purpose does the result_len serves in to_string/from_string functions? Shouldn't all those strings be null terminated? The former context_struct_to_string was done this way, so I didn't change it, but I don't see why this is necessary. Looking at mls_sid_to_context it would appear that it is null terminated (uses strcpy).
include/sepol/context.h +42 -4
@@ -16,12 +16,24 @@* clients of the security server. */ -#ifndef _CONTEXT_H_ -#define _CONTEXT_H_ +#ifndef _SEPOL_CONTEXT_H_ +#define _SEPOL_CONTEXT_H_#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 ; +/* * A security context consists of an authenticated user * identity, a role, a type and a MLS range.
@@ -33,7 +45,6 @@mls_range_t range; } context_struct_t; -static inline void mls_context_init (context_struct_t * c) {memset (&c->range,0 ,sizeof (c->range));
@@ -111,7 +122,34 @@ mls_context_cmp(c1, c2)); } -#endif /* _CONTEXT_H_ */ +struct policydb ; + +/* Create a context structure from high level representation */ +extern int sepol_context_create ( +struct policydb *policydb, +context_struct_t ** cptr, +sepol_ctxinfo_t * data); + +/* Create a context structure from string representation */ +extern int sepol_context_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 ( +struct policydb *policydb, +context_struct_t *context); + +/* Extract the context as string */ +extern int sepol_context_to_string ( +struct policydb *policydb, +context_struct_t * context, +char ** result, +size_t *result_len); + +#endif /* _SEPOL_CONTEXT_H_ */ /* FLASK */
include/sepol/policydb.h +5 -1
@@ -452,7 +452,11 @@extern int policydb_load_isids (policydb_t *p,sidtab_t *s); -extern int policydb_context_isvalid (policydb_t *p,context_struct_t *c); +/* Deprecated */ +static inline int policydb_context_isvalid (policydb_t *p,context_struct_t *c) { +return sepol_context_is_valid (p,c); +} +extern void symtabs_destroy (symtab_t *symtab);extern int scope_destroy (hashtab_key_t key,hashtab_datum_t datum,void *p);typedef void (*hashtab_destroy_func_t ) (hashtab_key_t k,hashtab_datum_t d,void *args);
src/context.c +281 -0
281 lines not on this page · raw message
src/policydb.c +0 -50
56 lines not on this page · raw message
src/services.c +24 -140
187 lines not on this page · raw message