s3-notify: Lift "/." handling up one level
authorVolker Lendecke <vl@samba.org>
Thu, 15 Mar 2012 12:02:15 +0000 (13:02 +0100)
committerVolker Lendecke <vl@samba.org>
Fri, 16 Mar 2012 13:28:42 +0000 (14:28 +0100)
This slightly simplifies the code

Autobuild-User: Volker Lendecke <vl@samba.org>
Autobuild-Date: Fri Mar 16 14:28:44 CET 2012 on sn-devel-104

source3/smbd/notify.c
source3/smbd/notify_internal.c

index 37d585b89602d07b1ceea8665b12f2b4f1404b7c..534ed8477bc2664c8310ac960fca44796bd11b5b 100644 (file)
@@ -178,6 +178,7 @@ NTSTATUS change_notify_create(struct files_struct *fsp, uint32 filter,
                              bool recursive)
 {
        char *fullpath;
+       size_t len;
        struct notify_entry e;
        NTSTATUS status;
 
@@ -202,6 +203,14 @@ NTSTATUS change_notify_create(struct files_struct *fsp, uint32 filter,
                return NT_STATUS_NO_MEMORY;
        }
 
+       /*
+        * Avoid /. at the end of the path name. notify can't deal with it.
+        */
+       len = strlen(fullpath);
+       if (len > 1 && fullpath[len-1] == '.' && fullpath[len-2] == '/') {
+               fullpath[len-2] = '\0';
+       }
+
        ZERO_STRUCT(e);
        e.path = fullpath;
        e.dir_fd = fsp->fh->fd;
index 599c9941693e81e4ab82ea491f24e2c75b6dc0da..906f7674dead607af1b1acb6665f77f4214447f2 100644 (file)
@@ -511,9 +511,7 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
 {
        struct notify_entry e = *e0;
        NTSTATUS status;
-       char *tmp_path = NULL;
        struct notify_list *listel;
-       size_t len;
        int depth;
 
        /* see if change notify is enabled at all */
@@ -521,17 +519,6 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
                return NT_STATUS_NOT_IMPLEMENTED;
        }
 
-       /* cope with /. on the end of the path */
-       len = strlen(e.path);
-       if (len > 1 && e.path[len-1] == '.' && e.path[len-2] == '/') {
-               tmp_path = talloc_strndup(notify, e.path, len-2);
-               if (tmp_path == NULL) {
-                       status = NT_STATUS_NO_MEMORY;
-                       goto done;
-               }
-               e.path = tmp_path;
-       }
-
        depth = count_chars(e.path, '/');
 
        listel = talloc_zero(notify, struct notify_list);
@@ -586,8 +573,6 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
        }
        status = NT_STATUS_OK;
 done:
-       talloc_free(tmp_path);
-
        return status;
 }