Samba 3.0.32 - internal change notify on share directory
Jeremy Allison
jra at samba.org
Tue Nov 18 20:20:40 GMT 2008
On Tue, Nov 18, 2008 at 12:10:24PM -0800, Jeremy Allison wrote:
> On Tue, Nov 18, 2008 at 02:48:02PM +0200, Dina Fine wrote:
> >
> > Hi
> >
> > It seems that when using change notify (internal only with no inotify
> > mechanism) the notification doesn't work on share directory path for
> > create and rename operations (and works only for delete).
> >
> > It appears that when working on share directory, the add change notify
> > request receives the following path "/share_path/." and cuts off the
> > "\." at the path end. The notification request is saved with
> > "/share_path" path.
> >
> > But on notify_trigger (fro example when creating file_name),
> > notify_fname creates a full path: "/share_path/./file_name" and doesn't
> > cut off the prefix "./" of the relative file path. Then notify_trigger
> > searches for the relevant subscription "/share_path/." in the tdb file
> > and of course fails.
> >
> > The attached patch solves the problem.
> > <<change_notify_on_volume_root.patch>>
> > Thanks,
> > Dina Fine
> > Software Engineer - Core Technologies
> > Exanet Ltd.
> >
>
> Great catch - thanks !
>
> I think we can do this without the strlen or tmp_path though, as
> we know we have a string of at least one character, so
> the statement :
>
> if (path[0] == '.' && path[1] == '/')
>
> will always be safe as the order of evauluation will be
> path[0] first only followed by path[1] if path[0] == '.'.
>
>
> So the patch could be as simple as the attached. I'll
> apply (with git-author attribution of course).
Actually we should also do the same to the path
creation in change_notify_create(), to ensure
all the paths are correctly canonicalized - which
would make the canonicalization code inside
notify_add() able to be removed (but I'm going
to leave it for now for stability).
So the complete patch should be (IMHO) the
attached. Please test !
Thanks,
Jeremy.
-------------- next part --------------
diff --git a/source/smbd/notify.c b/source/smbd/notify.c
index 6e24466..b65aeb1 100644
--- a/source/smbd/notify.c
+++ b/source/smbd/notify.c
@@ -211,6 +211,7 @@ NTSTATUS change_notify_create(struct files_struct *fsp, uint32 filter,
BOOL recursive)
{
char *fullpath;
+ const char *fspname;
struct notify_entry e;
NTSTATUS status;
@@ -221,8 +222,13 @@ NTSTATUS change_notify_create(struct files_struct *fsp, uint32 filter,
return NT_STATUS_NO_MEMORY;
}
+ fspname = fsp->fsp_name;
+ if (fspname[0] == '.' && fspname[1] == '/') {
+ fspname += 2;
+ }
+
if (asprintf(&fullpath, "%s/%s", fsp->conn->connectpath,
- fsp->fsp_name) == -1) {
+ fspname) == -1) {
DEBUG(0, ("asprintf failed\n"));
return NT_STATUS_NO_MEMORY;
}
@@ -349,6 +355,9 @@ void notify_fname(connection_struct *conn, uint32 action, uint32 filter,
{
char *fullpath;
+ if (path[0] == '.' && path[1] == '/') {
+ path += 2;
+ }
if (asprintf(&fullpath, "%s/%s", conn->connectpath, path) == -1) {
DEBUG(0, ("asprintf failed\n"));
return;
More information about the samba-technical
mailing list