This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
/* Pseudo-open the file (note - no fd's created). */
if(S_ISDIR(pst->st_mode)) {
- status = open_directory(conn, name, pst,
+ status = open_directory(conn, NULL, name, pst,
READ_CONTROL_ACCESS,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN,
0, /* no create options. */
+ FILE_ATTRIBUTE_DIRECTORY,
NULL, &fsp);
} else {
- status = open_file_stat(conn, name, pst, &fsp);
+ status = open_file_stat(conn, NULL, name, pst, &fsp);
}
if (!NT_STATUS_IS_OK(status)) {
if(S_ISDIR(pst->st_mode)) {
return True;
} else {
- status = open_file_ntcreate(conn, name, pst,
+ status = open_file_ntcreate(conn, NULL, name, pst,
FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN,
}
if (hide_unreadable || hide_unwriteable || hide_special) {
+ pstring link_target;
char *entry = NULL;
if (asprintf(&entry, "%s/%s", dir_path, name) == -1) {
/* If it's a dfs symlink, ignore _hide xxxx_ options */
if (lp_host_msdfs() &&
lp_msdfs_root(SNUM(conn)) &&
- /* We get away with NULL talloc ctx here as
- we're not interested in the link contents
- so we have nothing to free. */
- is_msdfs_link(NULL, conn, entry, NULL, NULL, NULL)) {
+ is_msdfs_link(conn, entry, link_target, NULL)) {
SAFE_FREE(entry);
return True;
}
}
return False;
}
+
+/*****************************************************************
+ Is this directory empty ?
+*****************************************************************/
+
+NTSTATUS can_delete_directory(struct connection_struct *conn,
+ const char *dirname)
+{
+ NTSTATUS status = NT_STATUS_OK;
+ long dirpos = 0;
+ const char *dname;
+ struct smb_Dir *dir_hnd = OpenDir(conn, dirname, NULL, 0);
+
+ if (!dir_hnd) {
+ return map_nt_error_from_unix(errno);
+ }
+
+ while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+ SMB_STRUCT_STAT st;
+
+ /* Quick check for "." and ".." */
+ if (dname[0] == '.') {
+ if (!dname[1] || (dname[1] == '.' && !dname[2])) {
+ continue;
+ }
+ }
+
+ if (!is_visible_file(conn, dirname, dname, &st, True)) {
+ continue;
+ }
+
+ DEBUG(10,("can_delete_directory: got name %s - can't delete\n", dname ));
+ status = NT_STATUS_DIRECTORY_NOT_EMPTY;
+ break;
+ }
+ CloseDir(dir_hnd);
+
+ return status;
+}