Useradd Integration (v. 2)
Subsystems (2)
Quoted 4 lines
Next, I will work on writing C functions for manipulating the
homedir_templatefile. They will be analogous tousers_file.c, and basically move genhomedircon's job into the libsepol library.
Actually, I think it would be better if I pulled out iterate, mod_user, add... into a more generic thing I can reuse for net_contexts, and homedir...
So: a method for iterating records in a file...
for modifying records in a file.
Then the structure of the record would be specified for each thing I want to iterate over - instead of user_config_t, it would be something else, with a different parse function.
I haven't actually seen the checkpolicy parsing code, and how modular it is - I used the genusers parsing code... If the checkpolicy code is sufficiently modular, I should be able to reuse that...
Signature · 8 lines
Ivan Gyurdiev <[email protected]> Cornell University -- 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: Useradd Integration (v. 3)
In reply to Ivan GyurdievQuoted 2 lines
Next - homedir template file..
Or rather...file_contexts format..
I have no intention of calling genhomedircon,
so the template is useless for me, and will
just be harder to deal with..
Signature · 8 lines
Ivan Gyurdiev <[email protected]> Cornell University -- 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.
Here's v.2 of my useradd patch.
I'm sure it has lots of bugs - I have yet to pass valgrind, and address FIXMEs.. but at least it shows something working here.. I also still haven't addressed Steven's concerns about multiline parsing, and proper default role, but I'll
get to that eventually.
Patch does:
- break up libsepol genusers into policy and file portions, to allow future work on different backends than a flat file
- several handlers to do various things like add user, delete user, iterate users, modify user, add role, delete role, set roles
- designate functions that work with the policy image as "backwards compatibility". Instead, we will work with the policydb, which will be faster, and simpler. That way the image doesn't have to be analyzed and the db reconstructed on every function call.
- unify most of policycoreutils/load_policy.c into a single function in libselinux. This will simplify reloading the policy from different programs. If you're wondering why that portion of the headers is in selinux-sepol.h, it's because I can't add <sepol/policydb.h> due to header conflict (sidtab).
- first pass useradd integration. No usermod and userdel integration yet
==========
Next, I will work on writing C functions for manipulating the homedir_template file. They will be analogous to users_file.c, and basically move genhomedircon's job into the libsepol library.
The idea is that the users_file functions will invoke template manipulating functions whenever the user is added, deleted, or the user's default role is changed. It will properly edit file_contexts.homedirs, and also restorecon the right things if the user's defrole is changed.
Signature · 2 lines
Ivan Gyurdiev <[email protected]> Cornell University
include/selinux/selinux.h +4 -1
@@ -1,6 +1,7 @@#ifndef _SELINUX_H_#define _SELINUX_H_ +#include <stdlib.h> #include <sys/types.h> #include <stdarg.h>
@@ -9,6 +10,8 @@ {#endif +extern void security_debug (int on); +/* Return 1 if we are running on a SELinux kernel, or 0 if not or -1 if we get an error. */ extern int is_selinux_enabled (void );/* Return 1 if we are running on a SELinux MLS kernel, or 0 otherwise. */
@@ -133,7 +136,7 @@const char *username, security_context_t **con); -/* Load a policy configuration. */ +/* Load a policy image. */ extern int security_load_policy (void *data,size_t len);/* Translate boolean strict to name value pair. */
include/selinux/selinux-sepol.h +26 -0
@@ -0,0 +1,26 @@ +#ifndef _SELINUX_SEPOL_H +#define _SELINUX_SEPOL_H + +#include <sepol/policydb.h> + +/* Create a policy database */ +int security_create_policydb ( +policydb_t ** policydb, +const char * polpath_arg, +const char * boolpath_arg, +int setbools_arg); + +/* Create a policydb from the default configuration */ +static inline int security_create_default_policydb (policydb_t ** policydb) { +return security_create_policydb (policydb,NULL ,NULL ,1 ); +} + +/* Destroy a policy database */ +static inline void security_destroy_policydb (policydb_t * policydb) { +policydb_destroy (policydb); +free (policydb); +} + +/* Load a policy database */ +extern int security_load_policydb (policydb_t * policydb); +#endif
src/debug.c +5 -1
@@ -1,7 +1,11 @@#include <stdarg.h> #include <stdio.h> -int seldebug =1 ; +static int seldebug =1 ; + +void security_debug (int on) { + seldebug = on; +} __attribute__ ((format (printf,1 ,2 )))void __selinux_debug_printf (const char *fmt, ...) {
src/load_policy.c +0 -27
@@ -1,27 +0,0 @@ -#include <unistd.h> -#include <sys/types.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> -#include <selinux/selinux.h> -#include "policy.h" -#include <limits.h> - -int security_load_policy (void *data,size_t len) -{ -char path[PATH_MAX ]; -int fd, ret; - -snprintf (path,sizeof path,"%s/load" , selinux_mnt); - fd =open (path,O_RDWR ); -if (fd <0 ) -return -1 ; - - ret =write (fd, data, len); -close (fd); -if (ret <0 ) -return -1 ; -return 0 ; -} -
src/Makefile +1 -0
@@ -13,6 +13,7 @@ LOBJS= $(patsubst %.c,%.lo,$(wildcard *.c)) CFLAGS = -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute override CFLAGS += -I../include -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 +LDFLAGS = -lsepol RANLIB=ranlib all: $(LIBA) $(LIBSO)
src/policy.c +279 -0
279 lines not on this page · raw message
src/selinux_internal.h +3 -0
@@ -1,6 +1,9 @@#include <selinux/selinux.h> #include "dso.h" +__attribute__ ((format (printf,1 ,2 ))) +void __selinux_debug_printf (const char *fmt, ...); + hidden_proto(security_set_boolean) hidden_proto(security_commit_booleans) hidden_proto(security_check_context)
include/sepol/booleans.h +10 -0
@@ -0,0 +1,10 @@ +#ifndef _SEPOL_BOOLEANS_H +#define _SEPOL_BOOLEANS_H + +#include <sepol/policydb.h> + +extern int sepol_load_booleans (policydb_t * policydb,const char *boolpath); +extern int sepol_load_booleans_array ( +policydb_t * policydb,char **names,int *values,int nel); + +#endif
include/sepol/context.h +0 -1
@@ -20,7 +20,6 @@#define _CONTEXT_H_#include <sepol/ebitmap.h> -#include <sepol/sepol.h> #include <sepol/mls_types.h> /*
include/sepol/hashtab.h +2 -2
@@ -18,8 +18,8 @@#include <errno.h> #include <stdio.h> -typedef char *hashtab_key_t ;/* generic key type */ -typedef void *hashtab_datum_t ;/* generic datum type */ +typedef char *hashtab_key_t ;/* generic key type */ +typedef void *hashtab_datum_t ;/* generic datum type */ typedef struct hashtab_node *hashtab_ptr_t ;
include/sepol/mls_types.h +0 -1
@@ -19,7 +19,6 @@#include <stdint.h> #include <sepol/ebitmap.h> -#include <sepol/sepol.h> #include <sepol/flask_types.h> typedef struct mls_level {
include/sepol/policydb.h +4 -0
@@ -289,6 +289,10 @@extern int policydb_write (struct policydb *p,struct policy_file *pf); +extern int policydb_from_image (void * data,size_t len,policydb_t * policydb); + +extern int policydb_to_image (policydb_t * policydb,void **newdata,size_t *newlen); +#define PERM_SYMTAB_SIZE 32/* Identify specific policy version changes */
include/sepol/sepol.h +28 -5
@@ -3,6 +3,16 @@#include <sys/types.h> #include <stdio.h> +#include <stdarg.h> + +/* Draw in extra headers that should be visible from outside */ + +#include <sepol/policydb.h> +#include <sepol/booleans.h> +#include <sepol/users_policy.h> +#include <sepol/users_file.h> + +/*==== Backwards Compatibility definitions ==== */ /* Given an existing binary policy (starting at 'data', with length 'len') and a boolean configuration file named by 'boolpath', rewrite the binary
@@ -16,20 +26,32 @@with 'nel' elements, rewrite the binary policy for the boolean settings. The binary policy is rewritten in place in memory. Returns 0 upon success or -1 otherwise. */ -extern int sepol_genbools_array (void *data,size_t len,char **names,int *values,int nel); +extern int sepol_genbools_array ( +void *data,size_t len, +char **names,int *values,int nel);/* Given an existing binary policy (starting at 'data with length 'len') and user configurations living in 'usersdir', generate a new binary policy for the new user configurations. Sets '*newdata' and '*newlen' to refer to the new binary policy image. */ -extern int sepol_genusers (void *data,size_t len, -const char *usersdir, -void **newdata,size_t *newlen); +extern int sepol_genusers ( +void *data,size_t len,const char *usersdir, +void **newdata,size_t *newlen); + +static inline int sepol_genbools_policydb ( +policydb_t * policydb,char *boolpath) { + +return sepol_load_booleans (policydb, boolpath); +}/* Enable or disable deletion of users by sepol_genusers(3) when a user in original binary policy image is not defined by the new user configurations. Defaults to disabled. */ -extern void sepol_set_delusers (int on); +static inline void sepol_set_delusers (int on) { +sepol_policy_set_delusers (on); +} + +/* ==== End backwards compatibility ==== */ /* Set internal policydb from a file for subsequent service calls. */ extern int sepol_set_policydb_from_file (FILE *fp);
@@ -39,4 +61,5 @@/* Turn on or off sepol error messages. */ extern void sepol_debug (int on); +#endif
include/sepol/services.h +0 -7
@@ -25,13 +25,6 @@extern int sepol_set_policydb (policydb_t *p);extern int sepol_set_sidtab (sidtab_t *s); -/* Modify a policydb for boolean settings. */ -int sepol_genbools_policydb (policydb_t *policydb,const char *booleans); - -/* Modify a policydb for user settings. */ -int sepol_genusers_policydb (policydb_t *policydb, -const char *usersdir); -/* Load the security policy. This initializes the policydb and sidtab based on the provided binary policy. */ int sepol_load_policy (void * data,size_t len);
include/sepol/user_config.h +90 -0
90 lines not on this page · raw message
include/sepol/users_file.h +74 -0
74 lines not on this page · raw message
include/sepol/users_policy.h +18 -0
@@ -0,0 +1,18 @@ +#ifndef __SEPOL_USERS_INTERNAL_H +#define __SEPOL_USERS_INTERNAL_H + +#include <sepol/policydb.h> +#include <sepol/user_config.h> + +/* Del users */ +extern void sepol_policy_set_delusers (int on); + +/* Clear unused users (before reloading policy */ +void sepol_policy_clear_unused (policydb_t * policydb); + +/* Add/delete/load users from the policy */ +extern int sepol_policy_add_user (policydb_t * policydb,user_config_t user); +extern int sepol_policy_del_user (policydb_t * policydb,const char * username); +extern int sepol_policy_load_user (user_config_t user,void * policydb); + +#endif
src/booleans.c +172 -0
172 lines not on this page · raw message
src/compatibility.c +87 -0
87 lines not on this page · raw message
src/debug.c +18 -0
@@ -0,0 +1,18 @@ +#include <stdarg.h> +#include <stdio.h> + +static int gdebug =1 ; + +void sepol_debug (int on) { + gdebug = on; +} + +__attribute__ ((format (printf,1 ,2 ))) +void __sepol_debug_printf (const char *fmt, ...) { +if (gdebug) { +va_list ap; +va_start (ap, fmt); +vfprintf (stderr, fmt, ap); +va_end (ap); + } +}
src/genbools.c +0 -238
238 lines not on this page · raw message
src/genbools.c.~1.8.~ +0 -177
177 lines not on this page · raw message
src/genusers.c +0 -477
477 lines not on this page · raw message
src/genusers.c.~1.2.~ +0 -404
404 lines not on this page · raw message
src/libsepol.map +1 -1
@@ -1,4 +1,4 @@ { - global: sepol_genbools*; sepol_set_policydb_from_file; sepol_check_context; sepol_genusers; sepol_debug; sepol_set_delusers; + global: sepol_genbools*; sepol_set_policydb_from_file; sepol_check_context; sepol_genusers; sepol_debug; sepol_set_delusers; uc_*; user_*; sepol_file_*; sepol_policy_*; policydb_*_image; policydb_destroy; sepol_load_booleans*; local: *; };
src/Makefile +1 -1
@@ -10,7 +10,7 @@ LIBSO=$(TARGET).$(LIBVERSION) OBJS= $(patsubst %.c,%.o,$(wildcard *.c)) LOBJS= $(patsubst %.c,%.lo,$(wildcard *.c)) -CFLAGS = -Wall +CFLAGS = -Wall -g override CFLAGS += -I. -I../include -D_GNU_SOURCE all: $(LIBA) $(LIBSO)
src/policydb.c +0 -3
@@ -1756,6 +1756,3 @@return 0 ; } - - -
src/policydb_convert.c +98 -0
98 lines not on this page · raw message
src/private.h +9 -1
@@ -4,6 +4,12 @@#include <byteswap.h> #include <endian.h> +#include <sepol/policydb.h> + +#define SEPOL_SUCCESS 0 +#define SEPOL_ERR -1 +#define SEPOL_HANDLER_ERR -2 +#define SEPOL_HANDLER_SIGDEL 1#if __BYTE_ORDER == __LITTLE_ENDIAN#define cpu_to_le32 (x) (x)
@@ -25,7 +31,9 @@ };extern struct policydb_compat_info *policydb_lookup_compat (int version); -extern void __sepol_debug_printf (const char *fmt, ...); + +__attribute__ ((format (printf,1 ,2 ))) +void __sepol_debug_printf (const char *fmt, ...);/* Reading from a policy "file". */ static inline void *next_entry (struct policy_file * fp,size_t bytes)
src/user_config.c +148 -0
148 lines not on this page · raw message
src/user_config_handlers.c +42 -0
42 lines not on this page · raw message
src/users_file.c +505 -0
418 lines not on this page · raw message
src/users_policy.c +344 -0
344 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
src/selinux.c +160 -0
160 lines not on this page · raw message
src/useradd.c +78 -7
85 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Re: Useradd Integration (v. 3)
In reply to Ivan GyurdievQuoted 7 lines · Ivan Gyurdiev
Quoted 3 lines
Next, I will work on writing C functions for manipulating the
homedir_templatefile. They will be analogous tousers_file.c, and basically move genhomedircon's job into the libsepol library.Actually, I think it would be better if I pulled out iterate,
mod_user, add... into a more generic thing I can reuse fornet_contexts, and homedir...
Attached libsepol changes for v.3.
I've changed some of the functions above into
generic parser utilities, and created a concept of a record - you can provide a table of methods for how to work with a particular record, and then use the record_file.c methods to iterate over records in a file using the same code, just a different parsing function.
I am still not quite happy with this. It could be made simpler, and better. I'm pretty sure the MLS parsing code is broken, and I need to rewrite/test this.
On the other hand I got multiline parsing to work, and parsing is simpler in general. I can also reuse a large part of the code to parse other things than the users file.
Next - homedir template file..
Signature · 2 lines
Ivan Gyurdiev <[email protected]> Cornell University
include/sepol/booleans.h +10 -0
@@ -0,0 +1,10 @@ +#ifndef _SEPOL_BOOLEANS_H +#define _SEPOL_BOOLEANS_H + +#include <sepol/policydb.h> + +extern int sepol_load_booleans (policydb_t * policydb,const char *boolpath); +extern int sepol_load_booleans_array ( +policydb_t * policydb,char **names,int *values,int nel); + +#endif
include/sepol/context.h +0 -1
@@ -20,7 +20,6 @@#define _CONTEXT_H_#include <sepol/ebitmap.h> -#include <sepol/sepol.h> #include <sepol/mls_types.h> /*
include/sepol/hashtab.h +2 -2
@@ -18,8 +18,8 @@#include <errno.h> #include <stdio.h> -typedef char *hashtab_key_t ;/* generic key type */ -typedef void *hashtab_datum_t ;/* generic datum type */ +typedef char *hashtab_key_t ;/* generic key type */ +typedef void *hashtab_datum_t ;/* generic datum type */ typedef struct hashtab_node *hashtab_ptr_t ;
include/sepol/mls_types.h +0 -1
@@ -19,7 +19,6 @@#include <stdint.h> #include <sepol/ebitmap.h> -#include <sepol/sepol.h> #include <sepol/flask_types.h> typedef struct mls_level {
include/sepol/policydb.h +4 -0
@@ -289,6 +289,10 @@extern int policydb_write (struct policydb *p,struct policy_file *pf); +extern int policydb_from_image (void * data,size_t len,policydb_t * policydb); + +extern int policydb_to_image (policydb_t * policydb,void **newdata,size_t *newlen); +#define PERM_SYMTAB_SIZE 32/* Identify specific policy version changes */
include/sepol/sepol.h +35 -5
@@ -3,6 +3,16 @@#include <sys/types.h> #include <stdio.h> +#include <stdarg.h> + +/* Draw in extra headers that should be visible from outside */ + +#include <sepol/policydb.h> +#include <sepol/booleans.h> +#include <sepol/users_policy.h> +#include <sepol/users_file.h> + +/*==== Backwards Compatibility definitions ==== */ /* Given an existing binary policy (starting at 'data', with length 'len') and a boolean configuration file named by 'boolpath', rewrite the binary
@@ -16,20 +26,39 @@with 'nel' elements, rewrite the binary policy for the boolean settings. The binary policy is rewritten in place in memory. Returns 0 upon success or -1 otherwise. */ -extern int sepol_genbools_array (void *data,size_t len,char **names,int *values,int nel); +extern int sepol_genbools_array ( +void *data,size_t len, +char **names,int *values,int nel);/* Given an existing binary policy (starting at 'data with length 'len') and user configurations living in 'usersdir', generate a new binary policy for the new user configurations. Sets '*newdata' and '*newlen' to refer to the new binary policy image. */ -extern int sepol_genusers (void *data,size_t len, -const char *usersdir, -void **newdata,size_t *newlen); +extern int sepol_genusers ( +void *data,size_t len, +const char *usersdir, +void **newdata,size_t *newlen); + +static inline int sepol_genbools_policydb ( +policydb_t * policydb,char *boolpath) { + +return sepol_load_booleans (policydb, boolpath); +} + +static inline int sepol_genusers_policydb ( +policydb_t * policydb,const char * usersdir) { + +return sepol_load_users_file (policydb, usersdir); +}/* Enable or disable deletion of users by sepol_genusers(3) when a user in original binary policy image is not defined by the new user configurations. Defaults to disabled. */ -extern void sepol_set_delusers (int on); +static inline void sepol_set_delusers (int on) { +sepol_set_delusers_policy (on); +} + +/* ==== End backwards compatibility ==== */ /* Set internal policydb from a file for subsequent service calls. */ extern int sepol_set_policydb_from_file (FILE *fp);
@@ -39,4 +68,5 @@/* Turn on or off sepol error messages. */ extern void sepol_debug (int on); +#endif
include/sepol/services.h +0 -7
@@ -25,13 +25,6 @@extern int sepol_set_policydb (policydb_t *p);extern int sepol_set_sidtab (sidtab_t *s); -/* Modify a policydb for boolean settings. */ -int sepol_genbools_policydb (policydb_t *policydb,const char *booleans); - -/* Modify a policydb for user settings. */ -int sepol_genusers_policydb (policydb_t *policydb, -const char *usersdir); -/* Load the security policy. This initializes the policydb and sidtab based on the provided binary policy. */ int sepol_load_policy (void * data,size_t len);
include/sepol/user_config.h +90 -0
90 lines not on this page · raw message
include/sepol/users_file.h +39 -0
@@ -0,0 +1,39 @@ +#ifndef _SEPOL_USERS_FILE_H +#define _SEPOL_USERS_FILE_H + +#include <sepol/user_config.h> +#include <sepol/policydb.h> + +extern int sepol_load_users_file ( +policydb_t * policydb, +const char * usersdir); + +extern int sepol_add_user_file ( +policydb_t * policydb, +const char * usersdir, +user_config_t user); + +extern int sepol_del_user_file ( +policydb_t * policydb, +const char * usersdir, +const char * username); + +extern int sepol_set_roles_file ( +policydb_t * policydb, +const char * usersdir, +const char * username, +const char ** roles); + +extern int sepol_add_role_file ( +policydb_t * policydb, +const char * usersdir, +const char * username, +const char * role); + +extern int sepol_del_role_file ( +policydb_t * policydb, +const char * usersdir, +const char * username, +const char * role); + +#endif
include/sepol/users_policy.h +18 -0
@@ -0,0 +1,18 @@ +#ifndef __SEPOL_USERS_INTERNAL_H +#define __SEPOL_USERS_INTERNAL_H + +#include <sepol/policydb.h> +#include <sepol/user_config.h> + +/* Del users */ +extern void sepol_set_delusers_policy (int on); + +/* Clear unused users (before reloading policy */ +void sepol_clear_users_policy (policydb_t *policydb); + +/* Add/delete/load users from the policy */ +extern int sepol_add_user_policy (policydb_t *policydb,user_config_t user); +extern int sepol_del_user_policy (policydb_t *policydb,const char *username); +extern int sepol_load_user_policy (policydb_t *policydb,user_config_t user); + +#endif
src/booleans.c +172 -0
172 lines not on this page · raw message
src/compatibility.c +87 -0
87 lines not on this page · raw message
src/debug.c +18 -0
@@ -0,0 +1,18 @@ +#include <stdarg.h> +#include <stdio.h> + +static int gdebug =1 ; + +void sepol_debug (int on) { + gdebug = on; +} + +__attribute__ ((format (printf,1 ,2 ))) +void __sepol_debug_printf (const char *fmt, ...) { +if (gdebug) { +va_list ap; +va_start (ap, fmt); +vfprintf (stderr, fmt, ap); +va_end (ap); + } +}
src/genbools.c +0 -238
238 lines not on this page · raw message
src/genbools.c.~1.8.~ +0 -177
177 lines not on this page · raw message
src/genusers.c +0 -477
477 lines not on this page · raw message
src/genusers.c.~1.2.~ +0 -404
404 lines not on this page · raw message
src/libsepol.map +1 -1
@@ -1,4 +1,4 @@ { - global: sepol_genbools*; sepol_set_policydb_from_file; sepol_check_context; sepol_genusers; sepol_debug; sepol_set_delusers; + global: sepol_*; policydb_*_image; policydb_destroy; uc_*; local: *; };
src/Makefile +1 -1
@@ -10,7 +10,7 @@ LIBSO=$(TARGET).$(LIBVERSION) OBJS= $(patsubst %.c,%.o,$(wildcard *.c)) LOBJS= $(patsubst %.c,%.lo,$(wildcard *.c)) -CFLAGS = -Wall +CFLAGS = -Wall -g override CFLAGS += -I. -I../include -D_GNU_SOURCE all: $(LIBA) $(LIBSO)
src/policydb.c +0 -3
@@ -1756,6 +1756,3 @@return 0 ; } - - -
src/policydb_convert.c +98 -0
98 lines not on this page · raw message
src/private.h +8 -1
@@ -4,6 +4,11 @@#include <byteswap.h> #include <endian.h> +#include <sepol/policydb.h> + +#define SEPOL_EXIT 1 +#define SEPOL_SUCCESS 0 +#define SEPOL_ERR -1#if __BYTE_ORDER == __LITTLE_ENDIAN#define cpu_to_le32 (x) (x)
@@ -25,7 +30,9 @@ };extern struct policydb_compat_info *policydb_lookup_compat (int version); -extern void __sepol_debug_printf (const char *fmt, ...); + +__attribute__ ((format (printf,1 ,2 ))) +void __sepol_debug_printf (const char *fmt, ...);/* Reading from a policy "file". */ static inline void *next_entry (struct policy_file * fp,size_t bytes)
src/record_file.c +343 -0
343 lines not on this page · raw message
src/record_file.h +73 -0
73 lines not on this page · raw message
src/user_config.c +157 -0
157 lines not on this page · raw message
src/users_file.c +480 -0
447 lines not on this page · raw message
src/users_policy.c +345 -0
345 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.