Author: jra
Date: 2007-04-24 12:56:23 +0000 (Tue, 24 Apr 2007)
New Revision: 22502

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=22502

Log:
Fix bug #4536 - delete symlinks to a directory correctly.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/smbd/reply.c
   branches/SAMBA_3_0_25/source/smbd/reply.c


Changeset:
Modified: branches/SAMBA_3_0/source/smbd/reply.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/reply.c      2007-04-24 09:35:55 UTC (rev 
22501)
+++ branches/SAMBA_3_0/source/smbd/reply.c      2007-04-24 12:56:23 UTC (rev 
22502)
@@ -3867,7 +3867,23 @@
        int ret;
        SMB_STRUCT_STAT st;
 
-       ret = SMB_VFS_RMDIR(conn,directory);
+       /* Might be a symlink. */
+       if(SMB_VFS_LSTAT(conn, directory, &st) != 0) {
+               return map_nt_error_from_unix(errno);
+       }
+
+       if (S_ISLNK(st.st_mode)) {
+               /* Is what it points to a directory ? */
+               if(SMB_VFS_STAT(conn, directory, &st) != 0) {
+                       return map_nt_error_from_unix(errno);
+               }
+               if (!(S_ISDIR(st.st_mode))) {
+                       return NT_STATUS_NOT_A_DIRECTORY;
+               }
+               ret = SMB_VFS_UNLINK(conn,directory);
+       } else {
+               ret = SMB_VFS_RMDIR(conn,directory);
+       }
        if (ret == 0) {
                notify_fname(conn, NOTIFY_ACTION_REMOVED,
                             FILE_NOTIFY_CHANGE_DIR_NAME,

Modified: branches/SAMBA_3_0_25/source/smbd/reply.c
===================================================================
--- branches/SAMBA_3_0_25/source/smbd/reply.c   2007-04-24 09:35:55 UTC (rev 
22501)
+++ branches/SAMBA_3_0_25/source/smbd/reply.c   2007-04-24 12:56:23 UTC (rev 
22502)
@@ -3866,7 +3866,23 @@
        int ret;
        SMB_STRUCT_STAT st;
 
-       ret = SMB_VFS_RMDIR(conn,directory);
+       /* Might be a symlink. */
+       if(SMB_VFS_LSTAT(conn, directory, &st) != 0) {
+               return map_nt_error_from_unix(errno);
+       }
+
+       if (S_ISLNK(st.st_mode)) {
+               /* Is what it points to a directory ? */
+               if(SMB_VFS_STAT(conn, directory, &st) != 0) {
+                       return map_nt_error_from_unix(errno);
+               }
+               if (!(S_ISDIR(st.st_mode))) {
+                       return NT_STATUS_NOT_A_DIRECTORY;
+               }
+               ret = SMB_VFS_UNLINK(conn,directory);
+       } else {
+               ret = SMB_VFS_RMDIR(conn,directory);
+       }
        if (ret == 0) {
                notify_fname(conn, NOTIFY_ACTION_REMOVED,
                             FILE_NOTIFY_CHANGE_DIR_NAME,

Reply via email to