From 2931d5a6fca53c087a0809527ec5379f1a75f874 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 14 Jun 2012 11:24:01 -0700 Subject: [PATCH 1/2] Part 1 of fix for bug #8998 - Notify code can miss a ChDir. Factor out notify_parent_dir. --- source3/smbd/notify.c | 40 ++++++++++++++++++++++++++-------------- 1 files changed, 26 insertions(+), 14 deletions(-) diff --git a/source3/smbd/notify.c b/source3/smbd/notify.c index 24385c9..436a354 100644 --- a/source3/smbd/notify.c +++ b/source3/smbd/notify.c @@ -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); -- 1.7.7.3 From dd8cdbdbc89835210bf04be9cb032209086373e5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 14 Jun 2012 11:26:44 -0700 Subject: [PATCH 2/2] Part 2 of fix for bug #8998 - Notify code can miss a ChDir. Do a ChDir for notify_onelevel. --- source3/smbd/notify.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/source3/smbd/notify.c b/source3/smbd/notify.c index 436a354..d9a28eb 100644 --- a/source3/smbd/notify.c +++ b/source3/smbd/notify.c @@ -352,6 +352,7 @@ static void notify_parent_dir(connection_struct *conn, struct smb_filename smb_fname_parent; char *parent; const char *name; + char *oldwd; if (!parent_dirname(talloc_tos(), path, &parent, &name)) { return; @@ -360,12 +361,23 @@ static void notify_parent_dir(connection_struct *conn, ZERO_STRUCT(smb_fname_parent); smb_fname_parent.base_name = parent; - if (SMB_VFS_STAT(conn, &smb_fname_parent) == -1) { + oldwd = vfs_GetWd(parent, conn); + if (oldwd == NULL) { + goto done; + } + if (vfs_ChDir(conn, conn->connectpath) == -1) { goto done; } + + if (SMB_VFS_STAT(conn, &smb_fname_parent) == -1) { + goto chdir_done; + } + notify_onelevel(conn->notify_ctx, action, filter, SMB_VFS_FILE_ID_CREATE(conn, &smb_fname_parent.st), name); +chdir_done: + vfs_ChDir(conn, oldwd); done: TALLOC_FREE(parent); } -- 1.7.7.3