Part 1 of fix for bug #8998 - Notify code can miss a ChDir.
authorVolker Lendecke <Volker.Lendecke@SerNet.DE>
Thu, 14 Jun 2012 18:24:01 +0000 (11:24 -0700)
committerKarolin Seeger <kseeger@samba.org>
Fri, 15 Jun 2012 19:06:16 +0000 (21:06 +0200)
Factor out notify_parent_dir.

source3/smbd/notify.c

index 24385c94a0d04e14bbef067857a6a547c2d1b495..436a35439018ab967839fc47b49630034adbabbb 100644 (file)
@@ -345,28 +345,40 @@ void remove_pending_change_notify_requests_by_fid(files_struct *fsp,
        }
 }
 
-void notify_fname(connection_struct *conn, uint32 action, uint32 filter,
-                 const char *path)
+static void notify_parent_dir(connection_struct *conn,
+                             uint32 action, uint32 filter,
+                             const char *path)
 {
-       char *fullpath;
+       struct smb_filename smb_fname_parent;
        char *parent;
        const char *name;
 
-       if (path[0] == '.' && path[1] == '/') {
-               path += 2;
+       if (!parent_dirname(talloc_tos(), path, &parent, &name)) {
+               return;
        }
-       if (parent_dirname(talloc_tos(), path, &parent, &name)) {
-               struct smb_filename smb_fname_parent;
 
-               ZERO_STRUCT(smb_fname_parent);
-               smb_fname_parent.base_name = parent;
+       ZERO_STRUCT(smb_fname_parent);
+       smb_fname_parent.base_name = parent;
 
-               if (SMB_VFS_STAT(conn, &smb_fname_parent) != -1) {
-                       notify_onelevel(conn->notify_ctx, action, filter,
-                           SMB_VFS_FILE_ID_CREATE(conn, &smb_fname_parent.st),
-                           name);
-               }
+       if (SMB_VFS_STAT(conn, &smb_fname_parent) == -1) {
+               goto done;
+       }
+       notify_onelevel(conn->notify_ctx, action, filter,
+                       SMB_VFS_FILE_ID_CREATE(conn, &smb_fname_parent.st),
+                       name);
+done:
+       TALLOC_FREE(parent);
+}
+
+void notify_fname(connection_struct *conn, uint32 action, uint32 filter,
+                 const char *path)
+{
+       char *fullpath;
+
+       if (path[0] == '.' && path[1] == '/') {
+               path += 2;
        }
+       notify_parent_dir(conn, action, filter, path);
 
        fullpath = talloc_asprintf(talloc_tos(), "%s/%s", conn->connectpath,
                                   path);