--- smbd/dir.c 2006-11-14 06:42:12.000000000 -0800 +++ smbd/dir.c 2007-02-01 11:22:03.000000000 -0800 @@ -1255,3 +1255,35 @@ } return False; } + +NTSTATUS deleteDirOk(files_struct *fsp) +{ + NTSTATUS status=NT_STATUS_OK; + + if (fsp && fsp->conn) + { + struct smb_Dir *dir_hnd = OpenDir(fsp->conn, fsp->fsp_name, NULL, 0); + if (dir_hnd != NULL) + { + const char *dname; + SMB_STRUCT_STAT st; + long dirpos = 0; + while ((dname = ReadDirName(dir_hnd,&dirpos))) + { + if ((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0)) + continue; + if (!is_visible_file(fsp->conn, fsp->fsp_name, dname, &st, False)) + continue; + if (!IS_VETO_PATH(fsp->conn, dname)) + { + status = NT_STATUS_DIRECTORY_NOT_EMPTY; + break; + } + } + } + CloseDir(dir_hnd); + } + + return status; +} + --- locking/locking.c 2006-07-10 09:27:52.000000000 -0700 +++ /root/jam/locking.c 2007-02-01 11:21:53.000000000 -0800 @@ -1118,6 +1118,8 @@ return True; } +extern NTSTATUS deleteDirOk(files_struct *fsp); + /**************************************************************************** Deal with the internal needs of setting the delete on close flag. Note that as the tdb locking is recursive, it is safe to call this from within @@ -1166,6 +1168,19 @@ return NT_STATUS_ACCESS_DENIED; } + if (fsp->is_directory) + { + if (delete_on_close) + { + NTSTATUS dirStatus=deleteDirOk(fsp); + if (!NT_STATUS_IS_OK(dirStatus)) + { + DEBUG(5, ("can_set_delete_on_close: ERROR directory '%s' not empty\n",fsp->fsp_name)); + return dirStatus; + } + } + } + return NT_STATUS_OK; }