summaryrefslogtreecommitdiff
path: root/source3/locking/locking.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/locking/locking.c')
-rw-r--r--source3/locking/locking.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 13c7724656..111fc98bbe 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -1152,6 +1152,46 @@ NTSTATUS can_set_delete_on_close(files_struct *fsp, BOOL delete_on_close,
return NT_STATUS_ACCESS_DENIED;
}
+ /* Don't allow delete on close for non-empty directories. */
+ if (fsp->is_directory) {
+ long offset = 0;
+ NTSTATUS status;
+ SMB_STRUCT_STAT st;
+ struct dptr_struct *dirptr;
+ const char *name;
+
+ status = dptr_create(fsp->conn,
+ fsp->fsp_name,
+ False,
+ True,
+ 0,
+ "*",
+ True,
+ 0,
+ &dirptr);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ /* Read 3 entries. Ignore first 2 (they're . and .. ) */
+ name = dptr_ReadDirName(dirptr, &offset, &st);
+ if (!name) {
+ dptr_CloseDir(dirptr);
+ return NT_STATUS_ACCESS_DENIED;
+ }
+ name = dptr_ReadDirName(dirptr, &offset, &st);
+ if (!name) {
+ dptr_CloseDir(dirptr);
+ return NT_STATUS_ACCESS_DENIED;
+ }
+ name = dptr_ReadDirName(dirptr, &offset, &st);
+ dptr_CloseDir(dirptr);
+ if (name) {
+ DEBUG(10,("can_set_delete_on_close: got name %s - can't delete\n", name ));
+ return NT_STATUS_DIRECTORY_NOT_EMPTY;
+ }
+ }
+
return NT_STATUS_OK;
}