#include "db_wrap.h"
#include "smb_server/smb_server.h"
#include "lib/messaging/irpc.h"
+#include "librpc/gen_ndr/ndr_opendb.h"
struct odb_context {
struct tdb_wrap *w;
struct messaging_context *messaging_ctx;
};
-/*
- the database is indexed by a file_key, and contains entries of the
- following form
-*/
-struct odb_entry {
- uint32_t server;
- void *file_handle;
- uint32_t stream_id;
- uint32_t share_access;
- uint32_t create_options;
- uint32_t access_mask;
- void *notify_ptr;
- BOOL pending;
-};
-
-
/*
an odb lock handle. You must obtain one of these using odb_lock() before doing
any other operations.
return NT_STATUS_OK on no conflict
*/
-static NTSTATUS share_conflict(struct odb_entry *e1, struct odb_entry *e2)
+static NTSTATUS share_conflict(struct opendb_entry *e1, struct opendb_entry *e2)
{
- if (e1->pending || e2->pending) return NT_STATUS_OK;
-
/* if either open involves no read.write or delete access then
it can't conflict */
if (!(e1->access_mask & (SEC_FILE_WRITE_DATA |
CHECK_MASK(e2->access_mask, SEC_STD_DELETE,
e1->share_access, NTCREATEX_SHARE_ACCESS_DELETE);
- /* if a delete is pending then a second open is not allowed */
- if ((e1->create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) ||
- (e2->create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) {
- return NT_STATUS_DELETE_PENDING;
- }
-
return NT_STATUS_OK;
}
/*
- register an open file in the open files database. This implements the share_access
- rules
+ pull a record, translating from the db format to the opendb_file structure defined
+ in opendb.idl
*/
-NTSTATUS odb_open_file(struct odb_lock *lck, void *file_handle,
- uint32_t stream_id,
- uint32_t share_access, uint32_t create_options,
- uint32_t access_mask)
+static NTSTATUS odb_pull_record(struct odb_lock *lck, struct opendb_file *file)
{
struct odb_context *odb = lck->odb;
TDB_DATA dbuf;
- struct odb_entry e;
- int i, count;
- struct odb_entry *elist;
+ DATA_BLOB blob;
+ NTSTATUS status;
dbuf = tdb_fetch(odb->w->tdb, lck->key);
-
- e.server = odb->server;
- e.file_handle = file_handle;
- e.stream_id = stream_id;
- e.share_access = share_access;
- e.create_options = create_options;
- e.access_mask = access_mask;
- e.notify_ptr = NULL;
- e.pending = False;
-
- /* check the existing file opens to see if they
- conflict */
- elist = (struct odb_entry *)dbuf.dptr;
- count = dbuf.dsize / sizeof(struct odb_entry);
-
- for (i=0;i<count;i++) {
- NTSTATUS status;
- status = share_conflict(elist+i, &e);
- if (!NT_STATUS_IS_OK(status)) {
- if (dbuf.dptr) free(dbuf.dptr);
- return status;
- }
+ if (dbuf.dptr == NULL) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
- elist = realloc_p(dbuf.dptr, struct odb_entry, count+1);
- if (elist == NULL) {
- if (dbuf.dptr) free(dbuf.dptr);
- return NT_STATUS_NO_MEMORY;
- }
+ blob.data = dbuf.dptr;
+ blob.length = dbuf.dsize;
- dbuf.dptr = (uint8_t *)elist;
- dbuf.dsize = (count+1) * sizeof(struct odb_entry);
+ status = ndr_pull_struct_blob(&blob, lck, file, (ndr_pull_flags_fn_t)ndr_pull_opendb_file);
- memcpy(dbuf.dptr + (count*sizeof(struct odb_entry)),
- &e, sizeof(struct odb_entry));
+ free(dbuf.dptr);
- if (tdb_store(odb->w->tdb, lck->key, dbuf, TDB_REPLACE) != 0) {
- free(dbuf.dptr);
+ return status;
+}
+
+/*
+ push a record, translating from the opendb_file structure defined in opendb.idl
+*/
+static NTSTATUS odb_push_record(struct odb_lock *lck, struct opendb_file *file)
+{
+ struct odb_context *odb = lck->odb;
+ TDB_DATA dbuf;
+ DATA_BLOB blob;
+ NTSTATUS status;
+ int ret;
+
+ if (file->num_entries == 0) {
+ ret = tdb_delete(odb->w->tdb, lck->key);
+ if (ret != 0) {
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+ return NT_STATUS_OK;
+ }
+
+ status = ndr_push_struct_blob(&blob, lck, file, (ndr_push_flags_fn_t)ndr_push_opendb_file);
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ dbuf.dptr = blob.data;
+ dbuf.dsize = blob.length;
+
+ ret = tdb_store(odb->w->tdb, lck->key, dbuf, TDB_REPLACE);
+ data_blob_free(&blob);
+ if (ret != 0) {
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- free(dbuf.dptr);
return NT_STATUS_OK;
}
/*
- register a pending open file in the open files database
+ register an open file in the open files database. This implements the share_access
+ rules
+
+ Note that the path is only used by the delete on close logic, not
+ for comparing with other filenames
*/
-NTSTATUS odb_open_file_pending(struct odb_lock *lck, void *private)
+NTSTATUS odb_open_file(struct odb_lock *lck, void *file_handle,
+ uint32_t stream_id, uint32_t share_access,
+ uint32_t access_mask, BOOL delete_on_close,
+ const char *path)
{
struct odb_context *odb = lck->odb;
- TDB_DATA dbuf;
- struct odb_entry e;
- struct odb_entry *elist;
- int count;
-
- dbuf = tdb_fetch(odb->w->tdb, lck->key);
+ struct opendb_entry e;
+ int i;
+ struct opendb_file file;
+ NTSTATUS status;
- e.server = odb->server;
- e.file_handle = NULL;
- e.stream_id = 0;
- e.share_access = 0;
- e.create_options = 0;
- e.access_mask = 0;
- e.notify_ptr = private;
- e.pending = True;
-
- /* check the existing file opens to see if they
- conflict */
- elist = (struct odb_entry *)dbuf.dptr;
- count = dbuf.dsize / sizeof(struct odb_entry);
-
- elist = realloc_p(dbuf.dptr, struct odb_entry, count+1);
- if (elist == NULL) {
- if (dbuf.dptr) free(dbuf.dptr);
- return NT_STATUS_NO_MEMORY;
+ status = odb_pull_record(lck, &file);
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ /* initialise a blank structure */
+ ZERO_STRUCT(file);
+ file.path = path;
+ } else {
+ NT_STATUS_NOT_OK_RETURN(status);
}
- dbuf.dptr = (uint8_t *)elist;
- dbuf.dsize = (count+1) * sizeof(struct odb_entry);
- memcpy(dbuf.dptr + (count*sizeof(struct odb_entry)),
- &e, sizeof(struct odb_entry));
+ if (file.delete_on_close ||
+ (file.num_entries != 0 && delete_on_close)) {
+ /* while delete on close is set, no new opens are allowed */
+ return NT_STATUS_DELETE_PENDING;
+ }
- if (tdb_store(odb->w->tdb, lck->key, dbuf, TDB_REPLACE) != 0) {
- free(dbuf.dptr);
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ /* see if it conflicts */
+ e.server = odb->server;
+ e.file_handle = file_handle;
+ e.stream_id = stream_id;
+ e.share_access = share_access;
+ e.access_mask = access_mask;
+ e.delete_on_close = delete_on_close;
+
+ for (i=0;i<file.num_entries;i++) {
+ status = share_conflict(&file.entries[i], &e);
+ NT_STATUS_NOT_OK_RETURN(status);
}
- free(dbuf.dptr);
- return NT_STATUS_OK;
+ /* it doesn't, so add it to the end */
+ file.entries = talloc_realloc(lck, file.entries, struct opendb_entry,
+ file.num_entries+1);
+ NT_STATUS_HAVE_NO_MEMORY(file.entries);
+
+ file.entries[file.num_entries] = e;
+ file.num_entries++;
+
+ return odb_push_record(lck, &file);
}
/*
- remove a opendb entry
+ register a pending open file in the open files database
*/
-NTSTATUS odb_close_file(struct odb_lock *lck, void *file_handle)
+NTSTATUS odb_open_file_pending(struct odb_lock *lck, void *private)
{
struct odb_context *odb = lck->odb;
- TDB_DATA dbuf;
- struct odb_entry *elist;
- int i, count;
+ struct opendb_file file;
NTSTATUS status;
+
+ status = odb_pull_record(lck, &file);
+ NT_STATUS_NOT_OK_RETURN(status);
- dbuf = tdb_fetch(odb->w->tdb, lck->key);
+ file.pending = talloc_realloc(lck, file.pending, struct opendb_pending,
+ file.num_pending+1);
+ NT_STATUS_HAVE_NO_MEMORY(file.pending);
- if (dbuf.dptr == NULL) {
- return NT_STATUS_UNSUCCESSFUL;
- }
+ file.pending[file.num_pending].server = odb->server;
+ file.pending[file.num_pending].notify_ptr = private;
- elist = (struct odb_entry *)dbuf.dptr;
- count = dbuf.dsize / sizeof(struct odb_entry);
+ file.num_pending++;
- /* send any pending notifications, removing them once sent */
- for (i=0;i<count;i++) {
- if (elist[i].pending) {
- messaging_send_ptr(odb->messaging_ctx, elist[i].server,
- MSG_PVFS_RETRY_OPEN, elist[i].notify_ptr);
- memmove(&elist[i], &elist[i+1], sizeof(struct odb_entry)*(count-(i+1)));
- i--;
- count--;
- }
- }
+ return odb_push_record(lck, &file);
+}
+
+
+/*
+ remove a opendb entry
+*/
+NTSTATUS odb_close_file(struct odb_lock *lck, void *file_handle)
+{
+ struct odb_context *odb = lck->odb;
+ struct opendb_file file;
+ int i;
+ NTSTATUS status;
+
+ status = odb_pull_record(lck, &file);
+ NT_STATUS_NOT_OK_RETURN(status);
/* find the entry, and delete it */
- for (i=0;i<count;i++) {
- if (file_handle == elist[i].file_handle &&
- odb->server == elist[i].server) {
- if (i < count-1) {
- memmove(elist+i, elist+i+1,
- (count - (i+1)) * sizeof(struct odb_entry));
+ for (i=0;i<file.num_entries;i++) {
+ if (file_handle == file.entries[i].file_handle &&
+ odb->server == file.entries[i].server) {
+ if (file.entries[i].delete_on_close) {
+ file.delete_on_close = True;
+ }
+ if (i < file.num_entries-1) {
+ memmove(file.entries+i, file.entries+i+1,
+ (file.num_entries - (i+1)) *
+ sizeof(struct opendb_entry));
}
break;
}
}
- status = NT_STATUS_OK;
-
- if (i == count) {
- status = NT_STATUS_UNSUCCESSFUL;
- } else if (count == 1) {
- if (tdb_delete(odb->w->tdb, lck->key) != 0) {
- status = NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
- } else {
- dbuf.dsize = (count-1) * sizeof(struct odb_entry);
- if (tdb_store(odb->w->tdb, lck->key, dbuf, TDB_REPLACE) != 0) {
- status = NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
+ if (i == file.num_entries) {
+ return NT_STATUS_UNSUCCESSFUL;
}
- free(dbuf.dptr);
+ /* send any pending notifications, removing them once sent */
+ for (i=0;i<file.num_pending;i++) {
+ messaging_send_ptr(odb->messaging_ctx, file.pending[i].server,
+ MSG_PVFS_RETRY_OPEN,
+ file.pending[i].notify_ptr);
+ }
+ file.num_pending = 0;
- return status;
+ file.num_entries--;
+
+ return odb_push_record(lck, &file);
}
NTSTATUS odb_remove_pending(struct odb_lock *lck, void *private)
{
struct odb_context *odb = lck->odb;
- TDB_DATA dbuf;
- struct odb_entry *elist;
- int i, count;
+ int i;
NTSTATUS status;
+ struct opendb_file file;
- dbuf = tdb_fetch(odb->w->tdb, lck->key);
-
- if (dbuf.dptr == NULL) {
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- elist = (struct odb_entry *)dbuf.dptr;
- count = dbuf.dsize / sizeof(struct odb_entry);
+ status = odb_pull_record(lck, &file);
+ NT_STATUS_NOT_OK_RETURN(status);
/* find the entry, and delete it */
- for (i=0;i<count;i++) {
- if (private == elist[i].notify_ptr &&
- odb->server == elist[i].server) {
- if (i < count-1) {
- memmove(elist+i, elist+i+1,
- (count - (i+1)) * sizeof(struct odb_entry));
+ for (i=0;i<file.num_pending;i++) {
+ if (private == file.pending[i].notify_ptr &&
+ odb->server == file.pending[i].server) {
+ if (i < file.num_pending-1) {
+ memmove(file.pending+i, file.pending+i+1,
+ (file.num_pending - (i+1)) *
+ sizeof(struct opendb_pending));
}
break;
}
}
- status = NT_STATUS_OK;
-
- if (i == count) {
- status = NT_STATUS_UNSUCCESSFUL;
- } else if (count == 1) {
- if (tdb_delete(odb->w->tdb, lck->key) != 0) {
- status = NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
- } else {
- dbuf.dsize = (count-1) * sizeof(struct odb_entry);
- if (tdb_store(odb->w->tdb, lck->key, dbuf, TDB_REPLACE) != 0) {
- status = NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
+ if (i == file.num_pending) {
+ return NT_STATUS_UNSUCCESSFUL;
}
- free(dbuf.dptr);
-
- return status;
+ file.num_pending--;
+
+ return odb_push_record(lck, &file);
}
/*
- update create options on an open file
+ rename the path in a open file
*/
-NTSTATUS odb_set_create_options(struct odb_lock *lck,
- void *file_handle, uint32_t create_options)
+NTSTATUS odb_rename(struct odb_lock *lck, const char *path)
{
- struct odb_context *odb = lck->odb;
- TDB_DATA dbuf;
- struct odb_entry *elist;
- int i, count;
+ struct opendb_file file;
NTSTATUS status;
- dbuf = tdb_fetch(odb->w->tdb, lck->key);
- if (dbuf.dptr == NULL) {
- return NT_STATUS_UNSUCCESSFUL;
+ status = odb_pull_record(lck, &file);
+ if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)) {
+ /* not having the record at all is OK */
+ return NT_STATUS_OK;
}
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ file.path = path;
+ return odb_push_record(lck, &file);
+}
+
+/*
+ update delete on close flag on an open file
+*/
+NTSTATUS odb_set_delete_on_close(struct odb_lock *lck, BOOL del_on_close)
+{
+ NTSTATUS status;
+ struct opendb_file file;
- elist = (struct odb_entry *)dbuf.dptr;
- count = dbuf.dsize / sizeof(struct odb_entry);
+ status = odb_pull_record(lck, &file);
+ NT_STATUS_NOT_OK_RETURN(status);
- /* find the entry, and modify it */
- for (i=0;i<count;i++) {
- if (file_handle == elist[i].file_handle &&
- odb->server == elist[i].server) {
- elist[i].create_options = create_options;
- break;
- }
+ file.delete_on_close = del_on_close;
+
+ return odb_push_record(lck, &file);
+}
+
+/*
+ return the current value of the delete_on_close bit, and how many
+ people still have the file open
+*/
+NTSTATUS odb_get_delete_on_close(struct odb_context *odb,
+ DATA_BLOB *key, BOOL *del_on_close,
+ int *open_count, char **path)
+{
+ NTSTATUS status;
+ struct opendb_file file;
+ struct odb_lock *lck;
+
+ lck = odb_lock(odb, odb, key);
+ NT_STATUS_HAVE_NO_MEMORY(lck);
+
+ status = odb_pull_record(lck, &file);
+ if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)) {
+ talloc_free(lck);
+ (*del_on_close) = False;
+ return NT_STATUS_OK;
+ }
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(lck);
+ return status;
}
- if (tdb_store(odb->w->tdb, lck->key, dbuf, TDB_REPLACE) != 0) {
- status = NT_STATUS_INTERNAL_DB_CORRUPTION;
- } else {
- status = NT_STATUS_OK;
+ (*del_on_close) = file.delete_on_close;
+ if (open_count != NULL) {
+ (*open_count) = file.num_entries;
+ }
+ if (path != NULL) {
+ *path = talloc_strdup(odb, file.path);
+ NT_STATUS_HAVE_NO_MEMORY(*path);
+ if (file.num_entries == 1 && file.entries[0].delete_on_close) {
+ (*del_on_close) = True;
+ }
}
- free(dbuf.dptr);
+ talloc_free(lck);
- return status;
+ return NT_STATUS_OK;
}
determine if a file can be opened with the given share_access,
create_options and access_mask
*/
-NTSTATUS odb_can_open(struct odb_context *odb, DATA_BLOB *key,
+NTSTATUS odb_can_open(struct odb_lock *lck,
uint32_t share_access, uint32_t create_options,
uint32_t access_mask)
{
- TDB_DATA dbuf;
- TDB_DATA kbuf;
- struct odb_entry *elist;
- int i, count;
- struct odb_entry e;
-
- kbuf.dptr = key->data;
- kbuf.dsize = key->length;
+ struct odb_context *odb = lck->odb;
+ NTSTATUS status;
+ struct opendb_file file;
+ struct opendb_entry e;
+ int i;
- dbuf = tdb_fetch(odb->w->tdb, kbuf);
- if (dbuf.dptr == NULL) {
+ status = odb_pull_record(lck, &file);
+ if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
return NT_STATUS_OK;
}
+ NT_STATUS_NOT_OK_RETURN(status);
- elist = (struct odb_entry *)dbuf.dptr;
- count = dbuf.dsize / sizeof(struct odb_entry);
+ if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) &&
+ file.num_entries != 0) {
+ return NT_STATUS_SHARING_VIOLATION;
+ }
- if (count == 0) {
- free(dbuf.dptr);
- return NT_STATUS_OK;
+ if (file.delete_on_close) {
+ return NT_STATUS_DELETE_PENDING;
}
- e.server = odb->server;
- e.file_handle = NULL;
- e.stream_id = 0;
- e.share_access = share_access;
- e.create_options = create_options;
- e.access_mask = access_mask;
- e.notify_ptr = NULL;
- e.pending = False;
-
- for (i=0;i<count;i++) {
- NTSTATUS status;
- status = share_conflict(elist+i, &e);
+ e.server = odb->server;
+ e.file_handle = NULL;
+ e.stream_id = 0;
+ e.share_access = share_access;
+ e.access_mask = access_mask;
+
+ for (i=0;i<file.num_entries;i++) {
+ status = share_conflict(&file.entries[i], &e);
if (!NT_STATUS_IS_OK(status)) {
- if (dbuf.dptr) free(dbuf.dptr);
/* note that we discard the error code
here. We do this as unless we are actually
doing an open (which comes via a sdifferent
}
}
- free(dbuf.dptr);
return NT_STATUS_OK;
}
static int pvfs_dir_handle_destructor(void *p)
{
struct pvfs_file_handle *h = p;
+ int open_count;
+ char *path;
- if (h->create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
- NTSTATUS status = pvfs_xattr_unlink_hook(h->pvfs, h->name->full_name);
+ if (h->name->stream_name == NULL &&
+ pvfs_delete_on_close_set(h->pvfs, h, &open_count, &path) &&
+ open_count == 1) {
+ NTSTATUS status;
+ status = pvfs_xattr_unlink_hook(h->pvfs, path);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0,("Warning: xattr rmdir hook failed for '%s' - %s\n",
- h->name->full_name, nt_errstr(status)));
+ DEBUG(0,("Warning: xattr unlink hook failed for '%s' - %s\n",
+ path, nt_errstr(status)));
+ }
+ if (rmdir(path) != 0) {
+ DEBUG(0,("pvfs_dir_handle_destructor: failed to rmdir '%s' - %s\n",
+ path, strerror(errno)));
+ }
+ }
+
+ if (h->have_opendb_entry) {
+ struct odb_lock *lck;
+ NTSTATUS status;
+
+ lck = odb_lock(h, h->pvfs->odb_context, &h->odb_locking_key);
+ if (lck == NULL) {
+ DEBUG(0,("Unable to lock opendb for close\n"));
+ return 0;
}
- if (rmdir(h->name->full_name) != 0 && errno != ENOTEMPTY) {
- DEBUG(0,("pvfs_close: failed to rmdir '%s' - %s\n",
- h->name->full_name, strerror(errno)));
+
+ status = odb_close_file(lck, h);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("Unable to remove opendb entry for '%s' - %s\n",
+ h->name->full_name, nt_errstr(status)));
}
+
+ talloc_free(lck);
}
return 0;
return status;
}
+/*
+ form the lock context used for opendb locking. Note that we must
+ zero here to take account of possible padding on some architectures
+*/
+static NTSTATUS pvfs_locking_key(struct pvfs_filename *name,
+ TALLOC_CTX *mem_ctx, DATA_BLOB *key)
+{
+ struct {
+ dev_t device;
+ ino_t inode;
+ } lock_context;
+ ZERO_STRUCT(lock_context);
+
+ lock_context.device = name->st.st_dev;
+ lock_context.inode = name->st.st_ino;
+
+ *key = data_blob_talloc(mem_ctx, &lock_context, sizeof(lock_context));
+ if (key->data == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ return NT_STATUS_OK;
+}
+
+
+/*
+ create a new directory
+*/
+static NTSTATUS pvfs_create_directory(struct pvfs_state *pvfs,
+ struct smbsrv_request *req,
+ struct pvfs_filename *name,
+ union smb_open *io)
+{
+ struct pvfs_file *f;
+ NTSTATUS status;
+ int fnum, ret;
+ struct odb_lock *lck;
+ uint32_t create_options = io->generic.in.create_options;
+ uint32_t share_access = io->generic.in.share_access;
+ uint32_t access_mask = io->generic.in.access_mask;
+ mode_t mode;
+ uint32_t attrib;
+ BOOL del_on_close;
+
+ if ((io->ntcreatex.in.file_attr & FILE_ATTRIBUTE_READONLY) &&
+ (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) {
+ return NT_STATUS_CANNOT_DELETE;
+ }
+
+ status = pvfs_access_check_create(pvfs, req, name, &access_mask);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ f = talloc(req, struct pvfs_file);
+ if (f == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ f->handle = talloc(f, struct pvfs_file_handle);
+ if (f->handle == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ fnum = idr_get_new_above(pvfs->idtree_fnum, f, PVFS_MIN_NEW_FNUM, UINT16_MAX);
+ if (fnum == -1) {
+ return NT_STATUS_TOO_MANY_OPENED_FILES;
+ }
+
+ attrib = io->ntcreatex.in.file_attr | FILE_ATTRIBUTE_DIRECTORY;
+ mode = pvfs_fileperms(pvfs, attrib);
+
+ /* create the directory */
+ ret = mkdir(name->full_name, mode);
+ if (ret == -1) {
+ idr_remove(pvfs->idtree_fnum, fnum);
+ return pvfs_map_errno(pvfs, errno);
+ }
+
+ pvfs_xattr_unlink_hook(pvfs, name->full_name);
+
+ /* re-resolve the new directory */
+ status = pvfs_resolve_name_fd(pvfs, -1, name);
+ if (!NT_STATUS_IS_OK(status)) {
+ idr_remove(pvfs->idtree_fnum, fnum);
+ rmdir(name->full_name);
+ return status;
+ }
+
+ name->dos.attrib = attrib;
+
+ status = pvfs_open_setup_eas_acl(pvfs, req, name, -1, fnum, io);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto cleanup_delete;
+ }
+
+ /* form the lock context used for opendb locking */
+ status = pvfs_locking_key(name, f->handle, &f->handle->odb_locking_key);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto cleanup_delete;
+ }
+
+ /* grab a lock on the open file record */
+ lck = odb_lock(req, pvfs->odb_context, &f->handle->odb_locking_key);
+ if (lck == NULL) {
+ DEBUG(0,("pvfs_open: failed to lock file '%s' in opendb\n",
+ name->full_name));
+ /* we were supposed to do a blocking lock, so something
+ is badly wrong! */
+ status = NT_STATUS_INTERNAL_DB_CORRUPTION;
+ goto cleanup_delete;
+ }
+
+ if (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
+ del_on_close = True;
+ } else {
+ del_on_close = False;
+ }
+
+ status = odb_open_file(lck, f->handle, name->stream_id,
+ share_access, access_mask, del_on_close, name->full_name);
+ talloc_free(lck);
+ if (!NT_STATUS_IS_OK(status)) {
+ /* bad news, we must have hit a race */
+ idr_remove(pvfs->idtree_fnum, fnum);
+ return status;
+ }
+
+ f->fnum = fnum;
+ f->session = req->session;
+ f->smbpid = req->smbpid;
+ f->pvfs = pvfs;
+ f->pending_list = NULL;
+ f->lock_count = 0;
+ f->share_access = io->generic.in.share_access;
+ f->access_mask = access_mask;
+ f->impersonation = io->generic.in.impersonation;
+
+ f->handle->pvfs = pvfs;
+ f->handle->name = talloc_steal(f->handle, name);
+ f->handle->fd = -1;
+ f->handle->create_options = io->generic.in.create_options;
+ f->handle->seek_offset = 0;
+ f->handle->position = 0;
+ f->handle->mode = 0;
+ f->handle->have_opendb_entry = True;
+ f->handle->sticky_write_time = False;
+
+ DLIST_ADD(pvfs->open_files, f);
+
+ /* setup a destructor to avoid file descriptor leaks on
+ abnormal termination */
+ talloc_set_destructor(f, pvfs_dir_fnum_destructor);
+ talloc_set_destructor(f->handle, pvfs_dir_handle_destructor);
+
+ io->generic.out.oplock_level = OPLOCK_NONE;
+ io->generic.out.fnum = f->fnum;
+ io->generic.out.create_action = NTCREATEX_ACTION_CREATED;
+ io->generic.out.create_time = name->dos.create_time;
+ io->generic.out.access_time = name->dos.access_time;
+ io->generic.out.write_time = name->dos.write_time;
+ io->generic.out.change_time = name->dos.change_time;
+ io->generic.out.attrib = name->dos.attrib;
+ io->generic.out.alloc_size = name->dos.alloc_size;
+ io->generic.out.size = name->st.st_size;
+ io->generic.out.file_type = FILE_TYPE_DISK;
+ io->generic.out.ipc_state = 0;
+ io->generic.out.is_directory = 0;
+
+ /* success - keep the file handle */
+ talloc_steal(pvfs, f);
+
+ return NT_STATUS_OK;
+
+cleanup_delete:
+ idr_remove(pvfs->idtree_fnum, fnum);
+ rmdir(name->full_name);
+ return status;
+}
+
+#if 0
+/*
+ open a directory
+*/
+static NTSTATUS pvfs_open_directory(struct pvfs_state *pvfs,
+ struct smbsrv_request *req,
+ struct pvfs_filename *name,
+ union smb_open *io)
+{
+ struct pvfs_file *f;
+ NTSTATUS status;
+ int fnum;
+ struct odb_lock *lck;
+ uint32_t create_options;
+ uint32_t share_access;
+ uint32_t access_mask;
+ BOOL del_on_close;
+
+ create_options = io->generic.in.create_options;
+ share_access = io->generic.in.share_access;
+ access_mask = io->generic.in.access_mask;
+
+ /* certain create options are not allowed */
+ if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) &&
+ !(access_mask & SEC_STD_DELETE)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ switch (io->generic.in.open_disposition) {
+ case NTCREATEX_DISP_SUPERSEDE:
+ case NTCREATEX_DISP_OVERWRITE_IF:
+ case NTCREATEX_DISP_OPEN_IF:
+ break;
+
+ case NTCREATEX_DISP_OPEN:
+ case NTCREATEX_DISP_OVERWRITE:
+ if (!name->exists) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ }
+ break;
+
+ case NTCREATEX_DISP_CREATE:
+ if (name->exists) {
+ return NT_STATUS_OBJECT_NAME_COLLISION;
+ }
+ break;
+
+ default:
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ /* handle creating a new directory separately */
+ if (!name->exists) {
+ status = pvfs_create_directory(pvfs, req, name, io);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+ return status;
+ }
+
+ /* we've hit a race - the directory was created during this call */
+ if (io->generic.in.open_disposition == NTCREATEX_DISP_CREATE) {
+ return status;
+ }
+
+ /* try re-resolving the name */
+ status = pvfs_resolve_name(pvfs, req, io->ntcreatex.in.fname, 0, &name);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+ /* fall through to a normal open */
+ }
+
+ if ((name->dos.attrib & FILE_ATTRIBUTE_READONLY) &&
+ (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) {
+ return NT_STATUS_CANNOT_DELETE;
+ }
+
+ /* check the security descriptor */
+ status = pvfs_access_check(pvfs, req, name, &access_mask);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ f = talloc(req, struct pvfs_file);
+ if (f == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ f->handle = talloc(f, struct pvfs_file_handle);
+ if (f->handle == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ /* allocate a fnum */
+ fnum = idr_get_new_above(pvfs->idtree_fnum, f, PVFS_MIN_DIR_FNUM, UINT16_MAX);
+ if (fnum == -1) {
+ return NT_STATUS_TOO_MANY_OPENED_FILES;
+ }
+
+ f->fnum = fnum;
+ f->session = req->session;
+ f->smbpid = req->smbpid;
+ f->pvfs = pvfs;
+ f->pending_list = NULL;
+ f->lock_count = 0;
+ f->share_access = io->generic.in.share_access;
+ f->access_mask = access_mask;
+ f->impersonation = io->generic.in.impersonation;
+
+ f->handle->pvfs = pvfs;
+ f->handle->fd = -1;
+ f->handle->name = talloc_steal(f->handle, name);
+ f->handle->create_options = io->generic.in.create_options;
+ f->handle->seek_offset = 0;
+ f->handle->position = 0;
+ f->handle->mode = 0;
+ f->handle->have_opendb_entry = False;
+ f->handle->sticky_write_time = False;
+
+ /* form the lock context used for opendb locking */
+ status = pvfs_locking_key(name, f->handle, &f->handle->odb_locking_key);
+ if (!NT_STATUS_IS_OK(status)) {
+ idr_remove(pvfs->idtree_fnum, f->fnum);
+ return status;
+ }
+
+ /* get a lock on this file before the actual open */
+ lck = odb_lock(req, pvfs->odb_context, &f->handle->odb_locking_key);
+ if (lck == NULL) {
+ DEBUG(0,("pvfs_open: failed to lock file '%s' in opendb\n",
+ name->full_name));
+ /* we were supposed to do a blocking lock, so something
+ is badly wrong! */
+ idr_remove(pvfs->idtree_fnum, fnum);
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ DLIST_ADD(pvfs->open_files, f);
+
+ /* setup a destructor to avoid file descriptor leaks on
+ abnormal termination */
+ talloc_set_destructor(f, pvfs_dir_fnum_destructor);
+ talloc_set_destructor(f->handle, pvfs_dir_handle_destructor);
+
+ if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) &&
+ pvfs_directory_empty(pvfs, f->handle->name)) {
+ del_on_close = True;
+ } else {
+ del_on_close = False;
+ }
+
+ /* see if we are allowed to open at the same time as existing opens */
+ status = odb_open_file(lck, f->handle, f->handle->name->stream_id,
+ share_access, access_mask, del_on_close, name->full_name);
+
+#if 0
+ /* we don't do async open retries on directories yet */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION) &&
+ (req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
+ return pvfs_open_setup_retry(ntvfs, req, io, f, lck);
+ }
+#endif
+
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(lck);
+ return status;
+ }
+
+ f->handle->have_opendb_entry = True;
+
+ talloc_free(lck);
+
+ io->generic.out.oplock_level = OPLOCK_NONE;
+ io->generic.out.fnum = f->fnum;
+ io->generic.out.create_action = NTCREATEX_ACTION_EXISTED;
+ io->generic.out.create_time = name->dos.create_time;
+ io->generic.out.access_time = name->dos.access_time;
+ io->generic.out.write_time = name->dos.write_time;
+ io->generic.out.change_time = name->dos.change_time;
+ io->generic.out.attrib = name->dos.attrib;
+ io->generic.out.alloc_size = name->dos.alloc_size;
+ io->generic.out.size = name->st.st_size;
+ io->generic.out.file_type = FILE_TYPE_DISK;
+ io->generic.out.ipc_state = 0;
+ io->generic.out.is_directory = 0;
+
+ /* success - keep the file handle */
+ talloc_steal(f->pvfs, f);
+
+ return NT_STATUS_OK;
+}
+#endif
+
+#if 1
/*
open a directory
*/
NTSTATUS status;
uint32_t create_action;
uint32_t access_mask = io->generic.in.access_mask;
+ struct odb_lock *lck;
+ BOOL del_on_close;
+ uint32_t create_options;
+ uint32_t share_access;
+
+ create_options = io->generic.in.create_options;
+ share_access = io->generic.in.share_access;
if (name->stream_name) {
return NT_STATUS_NOT_A_DIRECTORY;
f->handle->mode = 0;
f->handle->sticky_write_time = False;
- DLIST_ADD(pvfs->open_files, f);
+ if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) &&
+ pvfs_directory_empty(pvfs, f->handle->name)) {
+ del_on_close = True;
+ } else {
+ del_on_close = False;
+ }
+
+
+ if (name->exists) {
+ /* form the lock context used for opendb locking */
+ status = pvfs_locking_key(name, f->handle, &f->handle->odb_locking_key);
+ if (!NT_STATUS_IS_OK(status)) {
+ idr_remove(pvfs->idtree_fnum, f->fnum);
+ return status;
+ }
+
+ /* get a lock on this file before the actual open */
+ lck = odb_lock(req, pvfs->odb_context, &f->handle->odb_locking_key);
+ if (lck == NULL) {
+ DEBUG(0,("pvfs_open: failed to lock file '%s' in opendb\n",
+ name->full_name));
+ /* we were supposed to do a blocking lock, so something
+ is badly wrong! */
+ idr_remove(pvfs->idtree_fnum, fnum);
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ /* see if we are allowed to open at the same time as existing opens */
+ status = odb_open_file(lck, f->handle, f->handle->name->stream_id,
+ share_access, access_mask, del_on_close, name->full_name);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ idr_remove(pvfs->idtree_fnum, f->fnum);
+ talloc_free(lck);
+ return status;
+ }
+
+ f->handle->have_opendb_entry = True;
+ }
- /* TODO: should we check in the opendb? Do directory opens
- follow the share_access rules? */
+ DLIST_ADD(pvfs->open_files, f);
/* setup destructors to avoid leaks on abnormal termination */
talloc_set_destructor(f->handle, pvfs_dir_handle_destructor);
if (!name->exists) {
uint32_t attrib = io->generic.in.file_attr | FILE_ATTRIBUTE_DIRECTORY;
mode_t mode = pvfs_fileperms(pvfs, attrib);
+
if (mkdir(name->full_name, mode) == -1) {
idr_remove(pvfs->idtree_fnum, fnum);
return pvfs_map_errno(pvfs,errno);
goto cleanup_delete;
}
+ /* form the lock context used for opendb locking */
+ status = pvfs_locking_key(name, f->handle, &f->handle->odb_locking_key);
+ if (!NT_STATUS_IS_OK(status)) {
+ idr_remove(pvfs->idtree_fnum, f->fnum);
+ return status;
+ }
+
+ lck = odb_lock(req, pvfs->odb_context, &f->handle->odb_locking_key);
+ if (lck == NULL) {
+ DEBUG(0,("pvfs_open: failed to lock file '%s' in opendb\n",
+ name->full_name));
+ /* we were supposed to do a blocking lock, so something
+ is badly wrong! */
+ idr_remove(pvfs->idtree_fnum, fnum);
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ status = odb_open_file(lck, f->handle, f->handle->name->stream_id,
+ share_access, access_mask, del_on_close, name->full_name);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ goto cleanup_delete;
+ }
+
+ f->handle->have_opendb_entry = True;
+
create_action = NTCREATEX_ACTION_CREATED;
} else {
create_action = NTCREATEX_ACTION_EXISTED;
rmdir(name->full_name);
return status;
}
+#endif
/*
destroy a struct pvfs_file_handle
static int pvfs_handle_destructor(void *p)
{
struct pvfs_file_handle *h = p;
+ int open_count;
+ char *path;
/* the write time is no longer sticky */
if (h->sticky_write_time) {
h->fd = -1;
}
- if ((h->create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) &&
- h->name->stream_name == NULL) {
+ if (h->name->stream_name == NULL &&
+ pvfs_delete_on_close_set(h->pvfs, h, &open_count, &path) &&
+ open_count == 1) {
NTSTATUS status;
- status = pvfs_xattr_unlink_hook(h->pvfs, h->name->full_name);
+ status = pvfs_xattr_unlink_hook(h->pvfs, path);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("Warning: xattr unlink hook failed for '%s' - %s\n",
- h->name->full_name, nt_errstr(status)));
+ path, nt_errstr(status)));
}
- if (unlink(h->name->full_name) != 0) {
+ if (unlink(path) != 0) {
DEBUG(0,("pvfs_close: failed to delete '%s' - %s\n",
- h->name->full_name, strerror(errno)));
+ path, strerror(errno)));
}
}
}
-/*
- form the lock context used for opendb locking. Note that we must
- zero here to take account of possible padding on some architectures
-*/
-static NTSTATUS pvfs_locking_key(struct pvfs_filename *name,
- TALLOC_CTX *mem_ctx, DATA_BLOB *key)
-{
- struct {
- dev_t device;
- ino_t inode;
- } lock_context;
- ZERO_STRUCT(lock_context);
-
- lock_context.device = name->st.st_dev;
- lock_context.inode = name->st.st_ino;
-
- *key = data_blob_talloc(mem_ctx, &lock_context, sizeof(lock_context));
- if (key->data == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- return NT_STATUS_OK;
-}
-
/*
form the lock context used for byte range locking. This is separate
from the locking key used for opendb locking as it needs to take
uint32_t access_mask = io->generic.in.access_mask;
mode_t mode;
uint32_t attrib;
+ BOOL del_on_close;
+ struct pvfs_filename *parent;
if ((io->ntcreatex.in.file_attr & FILE_ATTRIBUTE_READONLY) &&
(create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) {
}
status = pvfs_access_check_create(pvfs, req, name, &access_mask);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ /* check that the parent isn't opened with delete on close set */
+ status = pvfs_resolve_parent(pvfs, req, name, &parent);
+ if (NT_STATUS_IS_OK(status)) {
+ DATA_BLOB locking_key;
+ status = pvfs_locking_key(parent, req, &locking_key);
+ NT_STATUS_NOT_OK_RETURN(status);
+ status = odb_get_delete_on_close(pvfs->odb_context, &locking_key,
+ &del_on_close, NULL, NULL);
+ NT_STATUS_NOT_OK_RETURN(status);
+ if (del_on_close) {
+ return NT_STATUS_DELETE_PENDING;
+ }
}
if (access_mask & (SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA)) {
goto cleanup_delete;
}
+ if (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
+ del_on_close = True;
+ } else {
+ del_on_close = False;
+ }
+
status = odb_open_file(lck, f->handle, name->stream_id,
- share_access, create_options, access_mask);
+ share_access, access_mask, del_on_close, name->full_name);
talloc_free(lck);
if (!NT_STATUS_IS_OK(status)) {
/* bad news, we must have hit a race - we don't delete the file
talloc_set_destructor(f, pvfs_fnum_destructor);
talloc_set_destructor(f->handle, pvfs_handle_destructor);
-
/* see if we are allowed to open at the same time as existing opens */
status = odb_open_file(lck, f->handle, f->handle->name->stream_id,
- share_access, create_options, access_mask);
+ share_access, access_mask, False, name->full_name);
/* on a sharing violation we need to retry when the file is closed by
the other user, or after 1 second */
/*
- change the create options on an already open file
+ change the delete on close flag on an already open file
*/
-NTSTATUS pvfs_change_create_options(struct pvfs_state *pvfs,
- struct smbsrv_request *req,
- struct pvfs_file *f, uint32_t create_options)
+NTSTATUS pvfs_set_delete_on_close(struct pvfs_state *pvfs,
+ struct smbsrv_request *req,
+ struct pvfs_file *f, BOOL del_on_close)
{
struct odb_lock *lck;
NTSTATUS status;
- if (f->handle->create_options == create_options) {
- return NT_STATUS_OK;
- }
-
- if ((f->handle->name->dos.attrib & FILE_ATTRIBUTE_READONLY) &&
- (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) {
+ if ((f->handle->name->dos.attrib & FILE_ATTRIBUTE_READONLY) && del_on_close) {
return NT_STATUS_CANNOT_DELETE;
}
-
- if (f->handle->name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) {
- if (!pvfs_directory_empty(pvfs, f->handle->name)) {
- return NT_STATUS_DIRECTORY_NOT_EMPTY;
- }
- f->handle->create_options = create_options;
- return NT_STATUS_OK;
+
+ if ((f->handle->name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) &&
+ !pvfs_directory_empty(pvfs, f->handle->name)) {
+ return NT_STATUS_DIRECTORY_NOT_EMPTY;
}
+ if (del_on_close) {
+ f->handle->create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
+ } else {
+ f->handle->create_options &= ~NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
+ }
+
lck = odb_lock(req, pvfs->odb_context, &f->handle->odb_locking_key);
if (lck == NULL) {
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
- status = odb_set_create_options(lck, f->handle, create_options);
- if (NT_STATUS_IS_OK(status)) {
- f->handle->create_options = create_options;
- }
+ status = odb_set_delete_on_close(lck, del_on_close);
talloc_free(lck);
*/
NTSTATUS pvfs_can_delete(struct pvfs_state *pvfs,
struct smbsrv_request *req,
- struct pvfs_filename *name)
+ struct pvfs_filename *name,
+ struct odb_lock **lckp)
{
NTSTATUS status;
DATA_BLOB key;
+ struct odb_lock *lck;
status = pvfs_locking_key(name, name, &key);
if (!NT_STATUS_IS_OK(status)) {
return NT_STATUS_NO_MEMORY;
}
- status = odb_can_open(pvfs->odb_context, &key,
+ lck = odb_lock(req, pvfs->odb_context, &key);
+ if (lck == NULL) {
+ DEBUG(0,("Unable to lock opendb for can_delete\n"));
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ status = odb_can_open(lck,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE |
NTCREATEX_SHARE_ACCESS_DELETE,
status = pvfs_access_check_simple(pvfs, req, name, SEC_STD_DELETE);
}
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(lck);
+ *lckp = lck;
+ } else if (lckp != NULL) {
+ *lckp = lck;
+ }
+
return status;
}
determine if a file can be renamed, or if it is prevented by an
already open file
*/
-NTSTATUS pvfs_can_rename(struct pvfs_state *pvfs, struct pvfs_filename *name)
+NTSTATUS pvfs_can_rename(struct pvfs_state *pvfs,
+ struct smbsrv_request *req,
+ struct pvfs_filename *name,
+ struct odb_lock **lckp)
{
NTSTATUS status;
DATA_BLOB key;
+ struct odb_lock *lck;
status = pvfs_locking_key(name, name, &key);
if (!NT_STATUS_IS_OK(status)) {
return NT_STATUS_NO_MEMORY;
}
- status = odb_can_open(pvfs->odb_context, &key,
+ lck = odb_lock(req, pvfs->odb_context, &key);
+ if (lck == NULL) {
+ DEBUG(0,("Unable to lock opendb for can_stat\n"));
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ status = odb_can_open(lck,
NTCREATEX_SHARE_ACCESS_READ |
NTCREATEX_SHARE_ACCESS_WRITE,
0,
SEC_STD_DELETE);
+ if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(lck);
+ *lckp = lck;
+ } else if (lckp != NULL) {
+ *lckp = lck;
+ }
+
return status;
}
+
+/*
+ determine if file meta data can be accessed, or if it is prevented by an
+ already open file
+*/
+NTSTATUS pvfs_can_stat(struct pvfs_state *pvfs,
+ struct smbsrv_request *req,
+ struct pvfs_filename *name)
+{
+ NTSTATUS status;
+ DATA_BLOB key;
+ struct odb_lock *lck;
+
+ status = pvfs_locking_key(name, name, &key);
+ if (!NT_STATUS_IS_OK(status)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ lck = odb_lock(req, pvfs->odb_context, &key);
+ if (lck == NULL) {
+ DEBUG(0,("Unable to lock opendb for can_stat\n"));
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ status = odb_can_open(lck,
+ NTCREATEX_SHARE_ACCESS_READ |
+ NTCREATEX_SHARE_ACCESS_WRITE,
+ 0, 0);
+
+ return status;
+}
+
+
+/*
+ determine if delete on close is set on
+*/
+BOOL pvfs_delete_on_close_set(struct pvfs_state *pvfs, struct pvfs_file_handle *h,
+ int *open_count, char **path)
+{
+ NTSTATUS status;
+ BOOL del_on_close;
+
+ status = odb_get_delete_on_close(pvfs->odb_context, &h->odb_locking_key,
+ &del_on_close, open_count, path);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1,("WARNING: unable to determine delete on close status for open file\n"));
+ return False;
+ }
+
+ return del_on_close;
+}