Skip to contentSkip to conversation

link algorithm

PATCH New Joshua Brindle 1 participant 1 message Jun 23, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 6/10 link algorithm

This is the updated link algorithm that is able to handle mutual dependencies in optionals and modules. It turns on all optionals and iterates through disabling unfulfilled ones until there are no changes. It also cleans up a bit of the code and adds better error handling as well as fixing a pile of bugs in the linking code

libsepol/include/sepol/policydb/link.h +5 -0
diff -pruN -x .svn selinux.old/libsepol/include/sepol/policydb/link.h optionals-in-base-take2/libsepol/include/sepol/policydb/link.h
@@ -29,6 +29,11 @@
 #include <sepol/policydb/policydb.h>
 #include <stddef.h>
 
+/* error codes */
+#define SEPOL_LINK_ERROR      1 /* general error */
+#define SEPOL_LINK_NOTSUP     2 /* feature not supported in module language */
+#define SEPOL_LINK_REQNOTMET  3 /* requirements not met */
+
 extern int link_modules(sepol_handle_t *handle,
 			policydb_t *b, policydb_t **mods, int len,
 			int verbose);
libsepol/include/sepol/policydb/policydb.h +4 -2
diff -pruN -x .svn selinux.old/libsepol/include/sepol/policydb/policydb.h optionals-in-base-take2/libsepol/include/sepol/policydb/policydb.h
@@ -313,8 +313,8 @@ typedef struct scope_index {
  * can never have an ELSE branch. */
 typedef struct avrule_decl {
         uint32_t decl_id;
-        int enabled;    /* flag set during linking if this decl is enabled;
-                           parent avrule_block->enabled will point to me */
+        uint32_t enabled; /* whether this block is enabled */
+                         
         cond_list_t *cond_list;
         avrule_t *avrules;
         role_trans_rule_t *role_tr_rules;
@@ -332,6 +332,8 @@ typedef struct avrule_block {
         avrule_decl_t *branch_list;
         avrule_decl_t *enabled; /* pointer to which branch is enabled.  this is
                                    used in linking and never written to disk */
+#define AVRULE_OPTIONAL 1
+	uint32_t flags; 	/* any flags for this block, currently just optional */
         struct avrule_block *next;
 } avrule_block_t;
 
libsepol/src/link.c +387 -552

1,193 lines not on this page · raw message

libsepol/src/policydb.c +6 -4
diff -pruN -x .svn selinux.old/libsepol/src/policydb.c optionals-in-base-take2/libsepol/src/policydb.c
@@ -2469,13 +2469,13 @@ static int avrule_block_read(policydb_t 
                              struct policy_file *fp)
 {
         avrule_block_t *last_block = NULL, *curblock;
-        uint32_t *buf, num_blocks;
+        uint32_t *buf, num_blocks, nel;
 
         if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
                 return -1;
         }
         num_blocks = le32_to_cpu(buf[0]);
-
+	nel = num_blocks;
         while (num_blocks > 0) {
                 avrule_decl_t *last_decl = NULL, *curdecl;
                 uint32_t num_decls;
@@ -2487,6 +2487,10 @@ static int avrule_block_read(policydb_t 
 			free(curblock);
                         return -1;
                 }
+		/* if this is the first block its non-optional, else its optional */
+		if (num_blocks != nel)
+			curblock->flags |= AVRULE_OPTIONAL;
+
                 num_decls = le32_to_cpu(buf[0]);
                 while (num_decls > 0) {
                         if ((curdecl = avrule_decl_create(0)) == NULL) {
@@ -2519,8 +2523,6 @@ static int avrule_block_read(policydb_t 
                         num_decls--;
                 }
                
-                /* one must be careful to reconstruct the block chain
-                 * in its correct order */
                 if (*block == NULL) {
                         *block = curblock;
                 }

--
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.