--- linux-2.4.19-rsbac-v1.2.2/rsbac/data_structures/aci_data_structures.c.sik	Mon Oct 27 16:07:27 2003
+++ linux-2.4.19-rsbac-v1.2.2/rsbac/data_structures/aci_data_structures.c	Tue Oct 28 12:29:24 2003
@@ -102,7 +102,6 @@
 kdev_t rsbac_root_dev;
 #if defined(CONFIG_RSBAC_REG)
 EXPORT_SYMBOL(rsbac_root_dev);
-EXPORT_SYMBOL(rsbac_write_sem);
 #endif
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
 struct semaphore rsbac_write_sem = MUTEX;
@@ -279,9 +278,7 @@
    if (!sb_p || !sb_p->s_dev)
      return(FALSE);
    if (
-#ifdef CONFIG_RSBAC_DEBUG
        rsbac_debug_no_write ||
-#endif
        (sb_p->s_flags & MS_RDONLY)
        || in_interrupt())
      return(FALSE);
@@ -7494,7 +7491,7 @@
         interruptible_sleep_on(&rsbacd_wait);
         /* sleep */
 /*        schedule_timeout(auto_interval); */
-        if(rsbac_initialized)
+        if(rsbac_initialized && !rsbac_debug_no_write)
           {
             int err;
 /*
@@ -7505,7 +7502,9 @@
 #endif
 */
             /* call rsbac_write with lock_kernel() */
+            down(&rsbac_write_sem);
             err = rsbac_write(TRUE);
+            up(&rsbac_write_sem);
             if(err < 0)
               {
                 if(name)
@@ -7651,6 +7650,7 @@
     struct rsbac_device_list_item_t * device_p;
     struct rsbac_device_list_item_t * new_device_p;
     u_long flags;
+    boolean old_no_write;
 
     if(!sb_p)
       {
@@ -7723,6 +7723,10 @@
 	       (unsigned long) n - (unsigned long)(current+1));
       }
 #endif
+    down(&rsbac_write_sem);
+    old_no_write = rsbac_debug_no_write;
+    rsbac_debug_no_write = TRUE;
+    up(&rsbac_write_sem);
     /* wait for read access to device_list_head */
     rsbac_read_lock(&device_list_head.lock, &flags);
     device_p = lookup_device(sb_p->s_dev);
@@ -7770,6 +7774,7 @@
 #endif
         if(!new_device_p)
           {
+            rsbac_debug_no_write = old_no_write;
             return -RSBAC_ECOULDNOTADDDEVICE;
           }
 
@@ -7798,6 +7803,7 @@
                 printk(KERN_WARNING "rsbac_mount: adding device %02u:%02u failed!\n",
                        MAJOR(sb_p->s_dev), MINOR(sb_p->s_dev));
                 clear_device_item(new_device_p);
+                rsbac_debug_no_write = old_no_write;
                 return -RSBAC_ECOULDNOTADDDEVICE;
               }
           }
@@ -7879,6 +7885,7 @@
 #endif
     #endif  /* REG */
 
+    rsbac_debug_no_write = old_no_write;
     return(err);
   };
   
@@ -7893,6 +7900,9 @@
   {
     u_long flags;
     struct rsbac_device_list_item_t * device_p;
+#if defined(CONFIG_RSBAC_AUTO_WRITE)
+    boolean need_up = FALSE;
+#endif
 
     if(!sb_p)
       {
@@ -7913,11 +7923,16 @@
 #endif
     /* sync attribute lists */
 #if defined(CONFIG_RSBAC_AUTO_WRITE)
+    if(!rsbac_debug_no_write)
+      {
+        down(&rsbac_write_sem);
+        need_up = TRUE;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-    rsbac_write(TRUE);
+        rsbac_write(TRUE);
 #else
-    rsbac_write(FALSE);
+        rsbac_write(FALSE);
 #endif
+      }
 #endif /* CONFIG_RSBAC_AUTO_WRITE */
     /* call other umount functions */
     #if defined(CONFIG_RSBAC_AUTH)
@@ -7970,6 +7985,12 @@
     /* allow access */
     rsbac_write_unlock_irq(&device_list_head.lock, &flags);
 
+#if defined(CONFIG_RSBAC_AUTO_WRITE)
+    if(need_up)
+      {
+        up(&rsbac_write_sem);
+      }
+#endif /* CONFIG_RSBAC_AUTO_WRITE */
     return(0);
   };
 
@@ -9188,10 +9209,8 @@
         printk(KERN_WARNING "rsbac_write(): RSBAC not initialized\n");
         return(-RSBAC_ENOTINITIALIZED);
       }
-#ifdef CONFIG_RSBAC_DEBUG
     if(rsbac_debug_no_write)
       return 0;
-#endif
     
     subcount = rsbac_write_lists(need_lock);
     if(subcount > 0)
--- linux-2.4.19-rsbac-v1.2.2/rsbac/data_structures/gen_lists.c.sik	Mon Jul 14 10:56:36 2003
+++ linux-2.4.19-rsbac-v1.2.2/rsbac/data_structures/gen_lists.c	Tue Oct 28 11:23:55 2003
@@ -2659,14 +2659,14 @@
     rsbac_read_unlock(&list->lock, &flags);
 
     /* get rsbac write-to-disk semaphore */
-    down(&rsbac_write_sem);
+//    down(&rsbac_write_sem);
 
     /* open file */
     if ((err = rsbac_write_open(list->name,
                                 &file,
                                 list->device) ))
       {
-        up(&rsbac_write_sem);
+//        up(&rsbac_write_sem);
         /* free buffer */
         rsbac_vkfree(buffer, vmalloc_used);
         return(err);
@@ -2711,7 +2711,7 @@
     /* End of write access */
     rsbac_write_close(&file);
     /* free overall sem */
-    up(&rsbac_write_sem);
+//    up(&rsbac_write_sem);
     /* free buffer */
     rsbac_vkfree(buffer, vmalloc_used);
     /* update file timestamp list - but not for filelist itself to avoid looping */
@@ -2832,14 +2832,14 @@
     rsbac_read_unlock(&list->lock, &flags);
 
     /* get rsbac write-to-disk semaphore */
-    down(&rsbac_write_sem);
+//    down(&rsbac_write_sem);
 
     /* open file */
     if ((err = rsbac_write_open(list->name,
                                 &file,
                                 list->device) ))
       {
-        up(&rsbac_write_sem);
+//        up(&rsbac_write_sem);
         /* free buffer */
         rsbac_vkfree(buffer, vmalloc_used);
         return(err);
@@ -2884,7 +2884,7 @@
     /* End of write access */
     rsbac_write_close(&file);
     /* free overall sem */
-    up(&rsbac_write_sem);
+//    up(&rsbac_write_sem);
     /* free buffer */
     rsbac_vkfree(buffer, vmalloc_used);
     /* update file timestamp list */
