vfs_netatalk should be using strstr_m, not strstr to find .AppleDouble paths.
[mat/samba.git] / source3 / modules / vfs_netatalk.c
index 2bcd42af4cad0ed6d73320366b213751f5ecb508..3e5606b553fc1a15536bbaeacd9990fe2aebfc2c 100644 (file)
@@ -19,6 +19,8 @@
  */
 
 #include "includes.h"
+#include "smbd/smbd.h"
+#include "system/filesys.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
 /* atalk functions */
 
 static int atalk_build_paths(TALLOC_CTX *ctx, const char *path,
-  const char *fname, char **adbl_path, char **orig_path, 
-  SMB_STRUCT_STAT *adbl_info, SMB_STRUCT_STAT *orig_info);
+                            const char *fname,
+                            char **adbl_path, char **orig_path,
+                            SMB_STRUCT_STAT *adbl_info,
+                            SMB_STRUCT_STAT *orig_info);
 
 static int atalk_unlink_file(const char *path);
 
@@ -52,9 +56,11 @@ static int atalk_get_path_ptr(char *path)
        return ptr;
 }
 
-static int atalk_build_paths(TALLOC_CTX *ctx, const char *path, const char *fname,
-                              char **adbl_path, char **orig_path,
-                              SMB_STRUCT_STAT *adbl_info, SMB_STRUCT_STAT *orig_info)
+static int atalk_build_paths(TALLOC_CTX *ctx, const char *path,
+                            const char *fname,
+                            char **adbl_path, char **orig_path,
+                            SMB_STRUCT_STAT *adbl_info,
+                            SMB_STRUCT_STAT *orig_info)
 {
        int ptr0 = 0;
        int ptr1 = 0;
@@ -67,7 +73,7 @@ static int atalk_build_paths(TALLOC_CTX *ctx, const char *path, const char *fnam
 #if 0
        DEBUG(3, ("ATALK: PATH: %s[%s]\n", path, fname));
 #endif
-       if (strstr(path, APPLEDOUBLE) || strstr(fname, APPLEDOUBLE)) {
+       if (strstr_m(path, APPLEDOUBLE) || strstr_m(fname, APPLEDOUBLE)) {
                DEBUG(3, ("ATALK: path %s[%s] already contains %s\n", path, fname, APPLEDOUBLE));
                return -1;
        }
@@ -80,7 +86,7 @@ static int atalk_build_paths(TALLOC_CTX *ctx, const char *path, const char *fnam
        /* get pointer to last '/' */
        ptr1 = atalk_get_path_ptr(*orig_path);
 
-       sys_lstat(*orig_path, orig_info, lp_fake_dir_create_times());
+       sys_lstat(*orig_path, orig_info, false);
 
        if (S_ISDIR(orig_info->st_ex_mode)) {
                *adbl_path = talloc_asprintf(ctx, "%s/%s/%s/", 
@@ -95,7 +101,7 @@ static int atalk_build_paths(TALLOC_CTX *ctx, const char *path, const char *fnam
 #if 0
        DEBUG(3, ("ATALK: DEBUG:\n%s\n%s\n", *orig_path, *adbl_path)); 
 #endif
-       sys_lstat(*adbl_path, adbl_info, lp_fake_dir_create_times());
+       sys_lstat(*adbl_path, adbl_info, false);
        return 0;
 }
 
@@ -120,12 +126,12 @@ static void atalk_add_to_list(name_compare_entry **list)
 
        if (cur_list) {
                for (i = 0, count = 0; cur_list[i].name; i ++, count ++) {
-                       if (strstr(cur_list[i].name, APPLEDOUBLE))
+                       if (strstr_m(cur_list[i].name, APPLEDOUBLE))
                                return;
                }
        }
 
-       if (!(new_list = SMB_CALLOC_ARRAY(name_compare_entry, (count == 0 ? 1 : count + 1))))
+       if (!(new_list = SMB_CALLOC_ARRAY(name_compare_entry, count + 2)))
                return;
 
        for (i = 0; i < count; i ++) {
@@ -192,6 +198,31 @@ static SMB_STRUCT_DIR *atalk_opendir(struct vfs_handle_struct *handle, const cha
        return ret;
 }
 
+static SMB_STRUCT_DIR *atalk_fdopendir(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
+{
+       SMB_STRUCT_DIR *ret = 0;
+
+       ret = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
+
+       if (ret == NULL) {
+               return ret;
+       }
+
+       /*
+        * when we try to perform delete operation upon file which has fork
+        * in ./.AppleDouble and this directory wasn't hidden by Samba,
+        * MS Windows explorer causes the error: "Cannot find the specified file"
+        * There is some workaround to avoid this situation, i.e. if
+        * connection has not .AppleDouble entry in either veto or hide 
+        * list then it would be nice to add one.
+        */
+
+       atalk_add_to_list(&handle->conn->hide_list);
+       atalk_add_to_list(&handle->conn->veto_list);
+
+       return ret;
+}
+
 static int atalk_rmdir(struct vfs_handle_struct *handle, const char *path)
 {
        bool add = False;
@@ -204,7 +235,7 @@ static int atalk_rmdir(struct vfs_handle_struct *handle, const char *path)
         * from this module, gotta use talloc stuff..
         */
 
-       strstr(path, APPLEDOUBLE) ? (add = False) : (add = True);
+       strstr_m(path, APPLEDOUBLE) ? (add = False) : (add = True);
 
        if (!(ctx = talloc_init("remove_directory")))
                goto exit_rmdir;
@@ -286,13 +317,13 @@ static int atalk_unlink(struct vfs_handle_struct *handle,
        if (!handle->conn->hide_list) return ret;
 
        for (i = 0; handle->conn->veto_list[i].name; i ++) {
-               if (strstr(handle->conn->veto_list[i].name, APPLEDOUBLE))
+               if (strstr_m(handle->conn->veto_list[i].name, APPLEDOUBLE))
                        break;
        }
 
        if (!handle->conn->veto_list[i].name) {
                for (i = 0; handle->conn->hide_list[i].name; i ++) {
-                       if (strstr(handle->conn->hide_list[i].name, APPLEDOUBLE))
+                       if (strstr_m(handle->conn->hide_list[i].name, APPLEDOUBLE))
                                break;
                        else {
                                DEBUG(3, ("ATALK: %s is not hidden, skipped..\n",
@@ -304,7 +335,7 @@ static int atalk_unlink(struct vfs_handle_struct *handle,
 
        if (atalk_build_paths(talloc_tos(), handle->conn->origpath, path,
                              &adbl_path, &orig_path,
-         &adbl_info, &orig_info) != 0)
+                             &adbl_info, &orig_info) != 0)
                goto exit_unlink;
 
        if (S_ISDIR(orig_info.st_ex_mode) || S_ISREG(orig_info.st_ex_mode)) {
@@ -337,8 +368,8 @@ static int atalk_chmod(struct vfs_handle_struct *handle, const char *path, mode_
        if (!(ctx = talloc_init("chmod_file")))
                return ret;
 
-       if (atalk_build_paths(ctx, handle->conn->origpath, path, &adbl_path, &orig_path,
-         &adbl_info, &orig_info) != 0)
+       if (atalk_build_paths(ctx, handle->conn->origpath, path, &adbl_path,
+                             &orig_path, &adbl_info, &orig_info) != 0)
                goto exit_chmod;
 
        if (!S_ISDIR(orig_info.st_ex_mode) && !S_ISREG(orig_info.st_ex_mode)) {
@@ -369,8 +400,9 @@ static int atalk_chown(struct vfs_handle_struct *handle, const char *path, uid_t
        if (!(ctx = talloc_init("chown_file")))
                return ret;
 
-       if (atalk_build_paths(ctx, handle->conn->origpath, path, &adbl_path, &orig_path,
-         &adbl_info, &orig_info) != 0)
+       if (atalk_build_paths(ctx, handle->conn->origpath, path,
+                             &adbl_path, &orig_path,
+                             &adbl_info, &orig_info) != 0)
                goto exit_chown;
 
        if (!S_ISDIR(orig_info.st_ex_mode) && !S_ISREG(orig_info.st_ex_mode)) {
@@ -403,8 +435,9 @@ static int atalk_lchown(struct vfs_handle_struct *handle, const char *path, uid_
        if (!(ctx = talloc_init("lchown_file")))
                return ret;
 
-       if (atalk_build_paths(ctx, handle->conn->origpath, path, &adbl_path, &orig_path,
-         &adbl_info, &orig_info) != 0)
+       if (atalk_build_paths(ctx, handle->conn->origpath, path,
+                             &adbl_path, &orig_path,
+                             &adbl_info, &orig_info) != 0)
                goto exit_lchown;
 
        if (!S_ISDIR(orig_info.st_ex_mode) && !S_ISREG(orig_info.st_ex_mode)) {
@@ -423,6 +456,7 @@ exit_lchown:
 
 static struct vfs_fn_pointers vfs_netatalk_fns = {
        .opendir = atalk_opendir,
+       .fdopendir = atalk_fdopendir,
        .rmdir = atalk_rmdir,
        .rename = atalk_rename,
        .unlink = atalk_unlink,