--- linux-2.4.5-rsbac-1.1.1/fs/namei.c.orig	Wed May 30 14:31:08 2001
+++ linux-2.4.5-rsbac-1.1.1/fs/namei.c	Tue Jul  3 12:58:09 2001
@@ -2432,7 +2432,9 @@
         #ifdef CONFIG_RSBAC
         enum  rsbac_target_t          rsbac_target;
         union rsbac_target_id_t       rsbac_target_id;
+        union rsbac_target_id_t       rsbac_new_target_id;
         union rsbac_attribute_value_t rsbac_attribute_value;
+        boolean target_exists = FALSE;
         #endif
 
 	if (path_init(oldname, LOOKUP_PARENT, &oldnd))
@@ -2477,6 +2479,10 @@
 		if (newnd.last.name[newnd.last.len])
 			goto exit4;
 	}
+	new_dentry = lookup_hash(&newnd.last, new_dir);
+	error = PTR_ERR(new_dentry);
+	if (IS_ERR(new_dentry))
+		goto exit4;
 
         /* RSBAC */
         #ifdef CONFIG_RSBAC
@@ -2500,6 +2506,7 @@
                                rsbac_attribute_value))
           {
             error = -EPERM;
+            dput(new_dentry);
             goto exit4;
           }
         if (rsbac_debug_aef)
@@ -2517,19 +2524,62 @@
                                rsbac_attribute_value))
           {
             error = -EPERM;
+            dput(new_dentry);
             goto exit4;
           }
+        if(new_dentry->d_inode)
+          {
+            target_exists = TRUE;
+            if (rsbac_debug_aef)
+              printk(KERN_DEBUG
+                     "do_rename() [sys_rename()]: calling ADF for DELETE on existing target\n");
+            rsbac_target = T_FILE;
+            if (S_ISDIR(new_dentry->d_inode->i_mode))
+              rsbac_target = T_DIR;
+            else if (S_ISFIFO (new_dentry->d_inode->i_mode))
+              rsbac_target = T_FIFO;
+            rsbac_target_id.file.device = new_dentry->d_inode->i_dev;
+            rsbac_target_id.file.inode  = new_dentry->d_inode->i_ino;
+            rsbac_target_id.file.dentry_p = new_dentry;
+            rsbac_attribute_value.nlink = new_dentry->d_inode->i_nlink;
+            if (!rsbac_adf_request(R_DELETE,
+                                   current->pid,
+                                   rsbac_target,
+                                   rsbac_target_id,
+                                   A_nlink,
+                                   rsbac_attribute_value))
+              {
+                error = -EPERM;
+                dput(new_dentry);
+                goto exit4;
+              }
+          }
         #endif /* CONFIG_RSBAC */
 
-	new_dentry = lookup_hash(&newnd.last, new_dir);
-	error = PTR_ERR(new_dentry);
-	if (IS_ERR(new_dentry))
-		goto exit4;
-
 	lock_kernel();
 	error = vfs_rename(old_dir->d_inode, old_dentry,
 				   new_dir->d_inode, new_dentry);
 	unlock_kernel();
+
+        /* RSBAC: notify ADF of deleted file */
+        #ifdef CONFIG_RSBAC
+        if (target_exists && !error)
+          {
+            rsbac_new_target_id.dummy = 0;
+            if (rsbac_adf_set_attr(R_DELETE,
+                                   current->pid,
+                                   rsbac_target,
+                                   rsbac_target_id,
+                                   T_NONE,
+                                   rsbac_new_target_id,
+                                   A_nlink,
+                                   rsbac_attribute_value))
+              {
+                printk(KERN_WARNING
+                       "do_rename() [sys_rename()]: rsbac_adf_set_attr() returned error");
+              }
+          }
+        #endif
 
 	dput(new_dentry);
 exit4:
