Remove the char * argument from the SMB_VFS_GETWD() call. Now always
authorJeremy Allison <jra@samba.org>
Tue, 31 May 2011 23:36:06 +0000 (16:36 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 1 Jun 2011 02:06:12 +0000 (04:06 +0200)
returns malloc'ed memory.

Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Wed Jun  1 04:06:12 CEST 2011 on sn-devel-104

examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_default.c
source3/modules/vfs_full_audit.c
source3/modules/vfs_time_audit.c
source3/smbd/vfs.c
source3/torture/cmd_vfs.c

index f60f0fe1628c09e2bd98be1e3d09c9afa4941f7d..f8399935d38153ea8de3bd5cde2c3198462e059a 100644 (file)
@@ -293,7 +293,7 @@ static int skel_chdir(vfs_handle_struct *handle,  const char *path)
        return -1;
 }
 
-static char *skel_getwd(vfs_handle_struct *handle,  char *buf)
+static char *skel_getwd(vfs_handle_struct *handle)
 {
        errno = ENOSYS;
        return NULL;
index f06e02afe5ffc329fd913c9fd308f5d9b158d20c..7c91a615b1f4c4a2a43585759f52a05f57188aa4 100644 (file)
@@ -280,9 +280,9 @@ static int skel_chdir(vfs_handle_struct *handle,  const char *path)
        return SMB_VFS_NEXT_CHDIR(handle, path);
 }
 
-static char *skel_getwd(vfs_handle_struct *handle,  char *buf)
+static char *skel_getwd(vfs_handle_struct *handle)
 {
-       return SMB_VFS_NEXT_GETWD(handle, buf);
+       return SMB_VFS_NEXT_GETWD(handle);
 }
 
 static int skel_ntimes(vfs_handle_struct *handle,
index 185bc7687c88f56a0576aed94c739d7d69d7611a..145b52c5c2dedc223200be1f441866318afc78d9 100644 (file)
                to split out the two possible uses. JRA. */
 /* Leave at 28 - not yet released. Add fdopendir. JRA. */
 /* Leave at 28 - not yet released. Rename open function to open_fn. - gd */
+/* Leave at 28 - not yet released. Make getwd function always return malloced memory. JRA. */
 #define SMB_VFS_INTERFACE_VERSION 28
 
 /*
@@ -250,7 +251,7 @@ struct vfs_fn_pointers {
        int (*fchown)(struct vfs_handle_struct *handle, struct files_struct *fsp, uid_t uid, gid_t gid);
        int (*lchown)(struct vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid);
        int (*chdir)(struct vfs_handle_struct *handle, const char *path);
-       char *(*getwd)(struct vfs_handle_struct *handle, char *buf);
+       char *(*getwd)(struct vfs_handle_struct *handle);
        int (*ntimes)(struct vfs_handle_struct *handle,
                      const struct smb_filename *smb_fname,
                      struct smb_file_time *ft);
@@ -613,7 +614,7 @@ int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
 int smb_vfs_call_lchown(struct vfs_handle_struct *handle, const char *path,
                        uid_t uid, gid_t gid);
 int smb_vfs_call_chdir(struct vfs_handle_struct *handle, const char *path);
-char *smb_vfs_call_getwd(struct vfs_handle_struct *handle, char *buf);
+char *smb_vfs_call_getwd(struct vfs_handle_struct *handle);
 int smb_vfs_call_ntimes(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        struct smb_file_time *ft);
index 4b1d1d258b8b7cd49e0cea6bd729e423cb995d91..c7686f1db526cbffb743921831f4dc57a0f1e1e9 100644 (file)
 #define SMB_VFS_NEXT_CHDIR(handle, path) \
        smb_vfs_call_chdir((handle)->next, (path))
 
-#define SMB_VFS_GETWD(conn, buf) \
-       smb_vfs_call_getwd((conn)->vfs_handles, (buf))
-#define SMB_VFS_NEXT_GETWD(handle, buf) \
-       smb_vfs_call_getwd((handle)->next, (buf))
+#define SMB_VFS_GETWD(conn) \
+       smb_vfs_call_getwd((conn)->vfs_handles)
+#define SMB_VFS_NEXT_GETWD(handle) \
+       smb_vfs_call_getwd((handle)->next)
 
 #define SMB_VFS_NTIMES(conn, path, ts) \
        smb_vfs_call_ntimes((conn)->vfs_handles, (path), (ts))
index faacf25599216b53d1ead72f586cddcde2463109..2dc7ec75b82d3ebc9b04c5ee02dcb6883c093a0c 100644 (file)
@@ -748,16 +748,14 @@ static int vfswrap_chdir(vfs_handle_struct *handle,  const char *path)
        return result;
 }
 
-static char *vfswrap_getwd(vfs_handle_struct *handle,  char *path)
+static char *vfswrap_getwd(vfs_handle_struct *handle)
 {
        char *result;
 
        START_PROFILE(syscall_getwd);
        result = sys_getwd();
        END_PROFILE(syscall_getwd);
-       /* FIXME - with a VFS change. JRA !! */
-       strlcpy(path, result, PATH_MAX);
-       return path;
+       return result;
 }
 
 /*********************************************************************
index 3b9c20a16b958b196c5ab698df3009af10e1a24a..bf7dacdc1f0d0240a08d2ca17ed8c10ca60d12a2 100644 (file)
@@ -1208,14 +1208,14 @@ static int smb_full_audit_chdir(vfs_handle_struct *handle,
        return result;
 }
 
-static char *smb_full_audit_getwd(vfs_handle_struct *handle,
-                        char *path)
+static char *smb_full_audit_getwd(vfs_handle_struct *handle)
 {
        char *result;
 
-       result = SMB_VFS_NEXT_GETWD(handle, path);
+       result = SMB_VFS_NEXT_GETWD(handle);
        
-       do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path);
+       do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s",
+               result == NULL? "" : result);
 
        return result;
 }
index d21542ca79ec97bb9383f563129d5453cbffadb0..0f32619458a33e6434b2e5f23ab073a1054151ec 100644 (file)
@@ -869,14 +869,14 @@ static int smb_time_audit_chdir(vfs_handle_struct *handle, const char *path)
        return result;
 }
 
-static char *smb_time_audit_getwd(vfs_handle_struct *handle, char *path)
+static char *smb_time_audit_getwd(vfs_handle_struct *handle)
 {
        char *result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_GETWD(handle, path);
+       result = SMB_VFS_NEXT_GETWD(handle);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
index 015fc56a78c9d632af4eb59d56b3cb29e0841cd2..8c526fa8821bbd81d1e0d7d0240a63e1b2d0f057 100644 (file)
@@ -795,7 +795,7 @@ int vfs_ChDir(connection_struct *conn, const char *path)
 
 char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
 {
-        char s[PATH_MAX+1];
+        char *current_dir = NULL;
        char *result = NULL;
        DATA_BLOB cache_value;
        struct file_id key;
@@ -803,8 +803,6 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
        struct smb_filename *smb_fname_full = NULL;
        NTSTATUS status;
 
-       *s = 0;
-
        if (!lp_getwd_cache()) {
                goto nocache;
        }
@@ -866,7 +864,8 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
         * systems, or the not quite so bad getwd.
         */
 
-       if (!SMB_VFS_GETWD(conn,s)) {
+       current_dir = SMB_VFS_GETWD(conn);
+       if (current_dir == NULL) {
                DEBUG(0, ("vfs_GetWd: SMB_VFS_GETWD call failed: %s\n",
                          strerror(errno)));
                goto out;
@@ -877,10 +876,11 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
 
                memcache_add(smbd_memcache(), GETWD_CACHE,
                             data_blob_const(&key, sizeof(key)),
-                            data_blob_const(s, strlen(s)+1));
+                            data_blob_const(current_dir,
+                                               strlen(current_dir)+1));
        }
 
-       result = talloc_strdup(ctx, s);
+       result = talloc_strdup(ctx, current_dir);
        if (result == NULL) {
                errno = ENOMEM;
        }
@@ -888,6 +888,7 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
  out:
        TALLOC_FREE(smb_fname_dot);
        TALLOC_FREE(smb_fname_full);
+       SAFE_FREE(current_dir);
        return result;
 }
 
@@ -1553,10 +1554,10 @@ int smb_vfs_call_chdir(struct vfs_handle_struct *handle, const char *path)
        return handle->fns->chdir(handle, path);
 }
 
-char *smb_vfs_call_getwd(struct vfs_handle_struct *handle, char *buf)
+char *smb_vfs_call_getwd(struct vfs_handle_struct *handle)
 {
        VFS_FIND(getwd);
-       return handle->fns->getwd(handle, buf);
+       return handle->fns->getwd(handle);
 }
 
 int smb_vfs_call_ntimes(struct vfs_handle_struct *handle,
index 2c3a41600243a30cd617acf34ee2a58e9d67e8da..c73bf6f36bb0a266b6532407746a3aa11cccfbb5 100644 (file)
@@ -889,13 +889,14 @@ static NTSTATUS cmd_fchown(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 
 static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       char buf[PATH_MAX];
-       if (SMB_VFS_GETWD(vfs->conn, buf) == NULL) {
+       char *buf = SMB_VFS_GETWD(vfs->conn);
+       if (buf == NULL) {
                printf("getwd: error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
        }
 
        printf("getwd: %s\n", buf);
+       SAFE_FREE(buf);
        return NT_STATUS_OK;
 }