Move cached cwd onto conn struct.
authorJeremy Allison <jra@samba.org>
Wed, 12 Sep 2012 18:39:37 +0000 (11:39 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 12 Sep 2012 20:06:06 +0000 (22:06 +0200)
This enables us to make VFS modules safe for use in root called
code when we've changed directory under conn->connectpath.

source3/include/vfs.h
source3/smbd/service.c
source3/smbd/vfs.c

index 8e48803fe7d3985eeebc675563d6881e53303473..c83e7ed54b8fe17eb9c886ff98b63d237382d3ae 100644 (file)
 /* Leave at 29 - not yet released. Add durable handle functions - metze/obnox */
 /* Leave at 29 - not yet released. Added sys_acl_blob_get_file and sys_acl_blob_get_fd */
 /* Bump to version 30 - Samba 4.0.0 will ship with interface version 30 */
 /* Leave at 29 - not yet released. Add durable handle functions - metze/obnox */
 /* Leave at 29 - not yet released. Added sys_acl_blob_get_file and sys_acl_blob_get_fd */
 /* Bump to version 30 - Samba 4.0.0 will ship with interface version 30 */
+/* Leave at 30 - not yet released. Added conn->cwd to save vfs_GetWd() calls. */
 #define SMB_VFS_INTERFACE_VERSION 30
 
 /*
 #define SMB_VFS_INTERFACE_VERSION 30
 
 /*
@@ -315,6 +316,7 @@ typedef struct connection_struct {
        enum timestamp_set_resolution ts_res;
        char *connectpath;
        char *origpath;
        enum timestamp_set_resolution ts_res;
        char *connectpath;
        char *origpath;
+       char *cwd; /* Working directory. */
 
        struct vfs_handle_struct *vfs_handles;          /* for the new plugins */
 
 
        struct vfs_handle_struct *vfs_handles;          /* for the new plugins */
 
index 0cd48f895046adbb45e9d13d270d79136a9d74c6..b2d3d4ddc1642b5d29dda97b243d0d8307951994 100644 (file)
@@ -164,6 +164,12 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath)
 
        talloc_free(conn->connectpath);
        conn->connectpath = destname;
 
        talloc_free(conn->connectpath);
        conn->connectpath = destname;
+       /* Ensure conn->cwd is initialized - start as conn->connectpath. */
+       TALLOC_FREE(conn->cwd);
+       conn->cwd = talloc_strdup(conn, conn->connectpath);
+       if (!conn->cwd) {
+               return false;
+       }
        return true;
 }
 
        return true;
 }
 
index 3eda2cf97be96ceb2bc414485e28d5e7ba1cee36..7d194404f4738e37620def3269bfece9df93566b 100644 (file)
@@ -799,13 +799,21 @@ const char *vfs_readdirname(connection_struct *conn, void *p,
 
 int vfs_ChDir(connection_struct *conn, const char *path)
 {
 
 int vfs_ChDir(connection_struct *conn, const char *path)
 {
+       int ret;
+
        if (strcsequal(path,".")) {
                return 0;
        }
 
        DEBUG(4,("vfs_ChDir to %s\n",path));
 
        if (strcsequal(path,".")) {
                return 0;
        }
 
        DEBUG(4,("vfs_ChDir to %s\n",path));
 
-       return SMB_VFS_CHDIR(conn,path);
+       ret = SMB_VFS_CHDIR(conn,path);
+       if (ret == 0) {
+               TALLOC_FREE(conn->cwd);
+               conn->cwd = vfs_GetWd(conn, conn);
+               DEBUG(4,("vfs_ChDir got %s\n",conn->cwd));
+       }
+       return ret;
 }
 
 /*******************************************************************
 }
 
 /*******************************************************************