r3174: added pvfs_is_open() to allow us to check for open files on unlink. We
authorAndrew Tridgell <tridge@samba.org>
Mon, 25 Oct 2004 01:29:31 +0000 (01:29 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:04:36 +0000 (13:04 -0500)
now pass BASE-UNLINK.
(This used to be commit f23a2f8538bda8f6790e86c93ee22436388b2975)

source4/ntvfs/common/opendb.c
source4/ntvfs/posix/pvfs_open.c
source4/ntvfs/posix/pvfs_unlink.c

index 3def23f1907d808a2f1f4df3a6e983f4e09f1c47..5c962fbad006f3c0ed53f81e370c48e9fed6bd53 100644 (file)
@@ -335,3 +335,23 @@ NTSTATUS odb_set_create_options(struct odb_lock *lck,
 
        return status;
 }
+
+
+/*
+  determine if a file is open
+*/
+BOOL odb_is_open(struct odb_context *odb, DATA_BLOB *key)
+{
+       TDB_DATA dbuf;
+       TDB_DATA kbuf;
+
+       kbuf.dptr = key->data;
+       kbuf.dsize = key->length;
+
+       dbuf = tdb_fetch(odb->w->tdb, kbuf);
+       if (dbuf.dptr == NULL) {
+               return False;
+       }
+       free(dbuf.dptr);
+       return True;
+}
index e587ebbf9500d45c333a82e1813a2d952c835151..7f066267066575a72fbfcc0ea5a88d960a6f78a0 100644 (file)
@@ -703,3 +703,20 @@ NTSTATUS pvfs_change_create_options(struct pvfs_state *pvfs,
 
        return status;
 }
+
+
+/*
+  determine if a file is open - used to prevent some operations on open files
+*/
+BOOL pvfs_is_open(struct pvfs_state *pvfs, struct pvfs_filename *name)
+{
+       NTSTATUS status;
+       DATA_BLOB key;
+
+       status = pvfs_locking_key(name, name, &key);
+       if (!NT_STATUS_IS_OK(status)) {
+               return False;
+       }
+
+       return odb_is_open(pvfs->odb_context, &key);
+}
index 0f4ff8b148377d6a04fb45d20339482231f6b7bb..d5e25b5622c7beb063308828d9f33582bec70eef 100644 (file)
@@ -80,6 +80,10 @@ NTSTATUS pvfs_unlink(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
+       if (pvfs_is_open(pvfs, name)) {
+               return NT_STATUS_SHARING_VIOLATION;
+       }
+
        dir = talloc_p(req, struct pvfs_dir);
        if (dir == NULL) {
                return NT_STATUS_NO_MEMORY;