fixed readonly handling in deltree
authorAndrew Tridgell <tridge@samba.org>
Tue, 23 Sep 2008 05:16:46 +0000 (15:16 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 23 Sep 2008 05:16:46 +0000 (15:16 +1000)
source4/libcli/clideltree.c
source4/libcli/smb2/util.c

index 2c306e501e23f8cba90f071f5cd6e57236066dcd..d59a03f194c8e05d2fed5c70005e7e7dd2dac988 100644 (file)
@@ -84,6 +84,7 @@ int smbcli_deltree(struct smbcli_tree *tree, const char *dname)
 {
        char *mask;
        struct delete_state dstate;
+       NTSTATUS status;
 
        dstate.tree = tree;
        dstate.total_deleted = 0;
@@ -98,6 +99,13 @@ int smbcli_deltree(struct smbcli_tree *tree, const char *dname)
            NT_STATUS_EQUAL(smbcli_nt_error(tree), NT_STATUS_NO_SUCH_FILE)) {
                return 0;
        }
+       if (NT_STATUS_EQUAL(status, NT_STATUS_CANNOT_DELETE)) {
+               /* it could be read-only */
+               status = smbcli_setatr(tree, dname, FILE_ATTRIBUTE_NORMAL, 0);
+               if (NT_STATUS_IS_OK(smbcli_unlink(tree, dname))) {
+                       return 1;
+               }
+       }
 
        asprintf(&mask, "%s\\*", dname);
        smbcli_unlink(dstate.tree, mask);
@@ -105,7 +113,14 @@ int smbcli_deltree(struct smbcli_tree *tree, const char *dname)
                 FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, 
                 delete_fn, &dstate);
        free(mask);
-       if (NT_STATUS_IS_ERR(smbcli_rmdir(dstate.tree, dname))) {
+
+       status = smbcli_rmdir(dstate.tree, dname);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_CANNOT_DELETE)) {
+               /* it could be read-only */
+               status = smbcli_setatr(dstate.tree, dname, FILE_ATTRIBUTE_NORMAL, 0);
+               status = smbcli_rmdir(dstate.tree, dname);
+       }
+       if (NT_STATUS_IS_ERR(status)) {
                DEBUG(2,("Failed to delete %s - %s\n", 
                         dname, smbcli_errstr(dstate.tree)));
                return -1;
index 311cea94a085a1494e49c8b7dd67d6bedf032de8..b149b3d6cec3a19a5a65ac228352ea95da1307d8 100644 (file)
@@ -197,6 +197,12 @@ int smb2_deltree(struct smb2_tree *tree, const char *dname)
        smb2_util_close(tree, create_parm.out.file.handle);
 
        status = smb2_util_rmdir(tree, dname);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_CANNOT_DELETE)) {
+               /* it could be read-only */
+               status = smb2_util_setatr(tree, dname, FILE_ATTRIBUTE_NORMAL);
+               status = smb2_util_rmdir(tree, dname);
+       }
+
        if (NT_STATUS_IS_ERR(status)) {
                DEBUG(2,("Failed to delete %s - %s\n", 
                         dname, nt_errstr(status)));