summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-01-05 17:42:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:16:56 -0500
commit0a8e3fd23632f0c77c4e165cf6070cb1fbcca381 (patch)
tree9f231a527cfc6d8090aea4751bd90bba266e30d1 /source3/smbd
parent18bf0b29b4b9b466136f08c1b6777ad8517779ed (diff)
downloadsamba-0a8e3fd23632f0c77c4e165cf6070cb1fbcca381.tar.gz
samba-0a8e3fd23632f0c77c4e165cf6070cb1fbcca381.tar.bz2
samba-0a8e3fd23632f0c77c4e165cf6070cb1fbcca381.zip
r20558: Refactor rmdir_internals to use early termination rather
than lots of indented code. Change recursive_rmdir() to return the smbd standards of True on success, False on fail (it was doing the reverse, which was very confusing). Jeremy. (This used to be commit 27dc5bebda7ffbdcb2371638f6132063a953fba2)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/reply.c111
1 files changed, 56 insertions, 55 deletions
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index b99cb54840..793262f0af 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -3822,18 +3822,18 @@ int reply_mkdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
/****************************************************************************
Static function used by reply_rmdir to delete an entire directory
- tree recursively. Return False on ok, True on fail.
+ tree recursively. Return True on ok, False on fail.
****************************************************************************/
static BOOL recursive_rmdir(connection_struct *conn, char *directory)
{
const char *dname = NULL;
- BOOL ret = False;
+ BOOL ret = True;
long offset = 0;
struct smb_Dir *dir_hnd = OpenDir(conn, directory, NULL, 0);
if(dir_hnd == NULL)
- return True;
+ return False;
while((dname = ReadDirName(dir_hnd, &offset))) {
pstring fullname;
@@ -3848,7 +3848,7 @@ static BOOL recursive_rmdir(connection_struct *conn, char *directory)
/* Construct the full name. */
if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
errno = ENOMEM;
- ret = True;
+ ret = False;
break;
}
@@ -3857,21 +3857,21 @@ static BOOL recursive_rmdir(connection_struct *conn, char *directory)
pstrcat(fullname, dname);
if(SMB_VFS_LSTAT(conn,fullname, &st) != 0) {
- ret = True;
+ ret = False;
break;
}
if(st.st_mode & S_IFDIR) {
- if(recursive_rmdir(conn, fullname)!=0) {
- ret = True;
+ if(!recursive_rmdir(conn, fullname)) {
+ ret = False;
break;
}
if(SMB_VFS_RMDIR(conn,fullname) != 0) {
- ret = True;
+ ret = False;
break;
}
} else if(SMB_VFS_UNLINK(conn,fullname) != 0) {
- ret = True;
+ ret = False;
break;
}
}
@@ -3896,66 +3896,67 @@ BOOL rmdir_internals(connection_struct *conn, const char *directory)
* retry. If we fail to delete any of them (and we *don't*
* do a recursive delete) then fail the rmdir.
*/
- BOOL all_veto_files = True;
const char *dname;
+ long dirpos = 0;
struct smb_Dir *dir_hnd = OpenDir(conn, directory, NULL, 0);
- if(dir_hnd != NULL) {
- long dirpos = 0;
- while ((dname = ReadDirName(dir_hnd,&dirpos))) {
- if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
- continue;
- if (!is_visible_file(conn, directory, dname, &st, False))
- continue;
- if(!IS_VETO_PATH(conn, dname)) {
- all_veto_files = False;
- break;
- }
+ if(dir_hnd == NULL) {
+ errno = ENOTEMPTY;
+ goto err;
+ }
+
+ while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+ if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
+ continue;
+ if (!is_visible_file(conn, directory, dname, &st, False))
+ continue;
+ if(!IS_VETO_PATH(conn, dname)) {
+ CloseDir(dir_hnd);
+ errno = ENOTEMPTY;
+ goto err;
}
+ }
- if(all_veto_files) {
- RewindDir(dir_hnd,&dirpos);
- while ((dname = ReadDirName(dir_hnd,&dirpos))) {
- pstring fullname;
+ /* We only have veto files/directories. Recursive delete. */
- if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
- continue;
- if (!is_visible_file(conn, directory, dname, &st, False))
- continue;
+ RewindDir(dir_hnd,&dirpos);
+ while ((dname = ReadDirName(dir_hnd,&dirpos))) {
+ pstring fullname;
- /* Construct the full name. */
- if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
- errno = ENOMEM;
- break;
- }
+ if((strcmp(dname, ".") == 0) || (strcmp(dname, "..")==0))
+ continue;
+ if (!is_visible_file(conn, directory, dname, &st, False))
+ continue;
- pstrcpy(fullname, directory);
- pstrcat(fullname, "/");
- pstrcat(fullname, dname);
+ /* Construct the full name. */
+ if(strlen(directory) + strlen(dname) + 1 >= sizeof(fullname)) {
+ errno = ENOMEM;
+ break;
+ }
+
+ pstrcpy(fullname, directory);
+ pstrcat(fullname, "/");
+ pstrcat(fullname, dname);
- if(SMB_VFS_LSTAT(conn,fullname, &st) != 0)
- break;
- if(st.st_mode & S_IFDIR) {
- if(lp_recursive_veto_delete(SNUM(conn))) {
- if(recursive_rmdir(conn, fullname) != 0)
- break;
- }
- if(SMB_VFS_RMDIR(conn,fullname) != 0)
- break;
- } else if(SMB_VFS_UNLINK(conn,fullname) != 0)
+ if(SMB_VFS_LSTAT(conn,fullname, &st) != 0)
+ break;
+ if(st.st_mode & S_IFDIR) {
+ if(lp_recursive_veto_delete(SNUM(conn))) {
+ if(!recursive_rmdir(conn, fullname))
break;
}
- CloseDir(dir_hnd);
- /* Retry the rmdir */
- ok = (SMB_VFS_RMDIR(conn,directory) == 0);
- } else {
- CloseDir(dir_hnd);
- }
- } else {
- errno = ENOTEMPTY;
+ if(SMB_VFS_RMDIR(conn,fullname) != 0)
+ break;
+ } else if(SMB_VFS_UNLINK(conn,fullname) != 0)
+ break;
}
+ CloseDir(dir_hnd);
+ /* Retry the rmdir */
+ ok = (SMB_VFS_RMDIR(conn,directory) == 0);
}
+ err:
+
if (!ok) {
DEBUG(3,("rmdir_internals: couldn't remove directory %s : "
"%s\n", directory,strerror(errno)));