Move the uglyness of #ifdef REALPATH_TAKES_NULL into the vfs_default
authorJeremy Allison <jra@samba.org>
Sat, 20 Nov 2010 00:29:26 +0000 (16:29 -0800)
committerJeremy Allison <jra@samba.org>
Sat, 20 Nov 2010 01:15:50 +0000 (02:15 +0100)
module, change the signature of VFS_REALPATH to always return a
malloc'ed string.

Needed to make some privileges work I plan on doing shortly
easier to code.

Jeremy.

Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Sat Nov 20 02:15:50 CET 2010 on sn-devel-104

14 files changed:
examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_cap.c
source3/modules/vfs_catia.c
source3/modules/vfs_default.c
source3/modules/vfs_full_audit.c
source3/modules/vfs_onefs_shadow_copy.c
source3/modules/vfs_shadow_copy2.c
source3/modules/vfs_time_audit.c
source3/smbd/service.c
source3/smbd/vfs.c
source3/torture/cmd_vfs.c

index a7814957de0d6c8c2554d9620c42b2c05912f3d9..42f4e48cd9017a32e2bf245e358a205010f82c5e 100644 (file)
@@ -356,7 +356,7 @@ static int skel_mknod(vfs_handle_struct *handle,  const char *path, mode_t mode,
        return -1;
 }
 
-static char *skel_realpath(vfs_handle_struct *handle,  const char *path, char *resolved_path)
+static char *skel_realpath(vfs_handle_struct *handle,  const char *path)
 {
        errno = ENOSYS;
        return NULL;
index 3be5cf93369b6cd40721bb281094b791a5eb17af..42e54a8871d67f617cc01b7a530788c017190e8c 100644 (file)
@@ -332,9 +332,9 @@ static int skel_mknod(vfs_handle_struct *handle,  const char *path, mode_t mode,
        return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev);
 }
 
-static char *skel_realpath(vfs_handle_struct *handle,  const char *path, char *resolved_path)
+static char *skel_realpath(vfs_handle_struct *handle,  const char *path)
 {
-       return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
+       return SMB_VFS_NEXT_REALPATH(handle, path);
 }
 
 static NTSTATUS skel_notify_watch(struct vfs_handle_struct *handle,
index 9ec4c3ec69cdab80fd27597ae256e882bb86dbf9..9121069a276dcacf7e7ac0354767b15a06dfdf38 100644 (file)
 /* Leave at 27 - not yet released. Add translate_name VFS call to convert
                 UNIX names to Windows supported names -- asrinivasan. */
 /* Changed to version 28 - Add private_flags uint32_t to CREATE call. */
+/* Leave at 28 - not yet released. Change realpath to assume NULL and return a
+                malloc'ed path. JRA. */
 #define SMB_VFS_INTERFACE_VERSION 28
 
 
@@ -257,7 +259,7 @@ struct vfs_fn_pointers {
        int (*vfs_readlink)(struct vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz);
        int (*link)(struct vfs_handle_struct *handle, const char *oldpath, const char *newpath);
        int (*mknod)(struct vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev);
-       char *(*realpath)(struct vfs_handle_struct *handle, const char *path, char *resolved_path);
+       char *(*realpath)(struct vfs_handle_struct *handle, const char *path);
        NTSTATUS (*notify_watch)(struct vfs_handle_struct *handle,
                                 struct sys_notify_context *ctx,
                                 struct notify_entry *e,
@@ -619,8 +621,7 @@ int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
                      const char *newpath);
 int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
                       mode_t mode, SMB_DEV_T dev);
-char *smb_vfs_call_realpath(struct vfs_handle_struct *handle,
-                           const char *path, char *resolved_path);
+char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path);
 NTSTATUS smb_vfs_call_notify_watch(struct vfs_handle_struct *handle,
                                   struct sys_notify_context *ctx,
                                   struct notify_entry *e,
index 4472e3a52ab9bca3fa36e82709ac946a27a9a306..5b38e64cbfd533bba0d7b529644983b58f3e6eeb 100644 (file)
 #define SMB_VFS_NEXT_MKNOD(handle, path, mode, dev) \
        smb_vfs_call_mknod((handle)->next, (path), (mode), (dev))
 
-#define SMB_VFS_REALPATH(conn, path, resolved_path) \
-       smb_vfs_call_realpath((conn)->vfs_handles, (path), (resolved_path))
-#define SMB_VFS_NEXT_REALPATH(handle, path, resolved_path) \
-       smb_vfs_call_realpath((handle)->next, (path), (resolved_path))
+#define SMB_VFS_REALPATH(conn, path) \
+       smb_vfs_call_realpath((conn)->vfs_handles, (path))
+#define SMB_VFS_NEXT_REALPATH(handle, path) \
+       smb_vfs_call_realpath((handle)->next, (path))
 
 #define SMB_VFS_NOTIFY_WATCH(conn, ctx, e, callback, private_data, handle_p) \
        smb_vfs_call_notify_watch((conn)->vfs_handles, (ctx), (e), (callback), (private_data), (handle_p))
index 35fa740dd09aa078cfe78e83196c1623683f041f..89f16891a9b09140ab915730fe6f36689e45c908 100644 (file)
@@ -384,7 +384,7 @@ static int cap_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, S
        return SMB_VFS_NEXT_MKNOD(handle, cappath, mode, dev);
 }
 
-static char *cap_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path)
+static char *cap_realpath(vfs_handle_struct *handle, const char *path)
 {
         /* monyo need capencode'ed and capdecode'ed? */
        char *cappath = capencode(talloc_tos(), path);
@@ -393,7 +393,7 @@ static char *cap_realpath(vfs_handle_struct *handle, const char *path, char *res
                errno = ENOMEM;
                return NULL;
        }
-       return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
+       return SMB_VFS_NEXT_REALPATH(handle, cappath);
 }
 
 static int cap_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
index 177458bce28ad1ae93ea6efa655a025b844d57a0..af6efd28df795881e8b00cfc3d6757711431723c 100644 (file)
@@ -634,8 +634,7 @@ static int catia_ntimes(vfs_handle_struct *handle,
 }
 
 static char *
-catia_realpath(vfs_handle_struct *handle, const char *path,
-              char *resolved_path)
+catia_realpath(vfs_handle_struct *handle, const char *path)
 {
        char *mapped_name = NULL;
        NTSTATUS status;
@@ -648,7 +647,7 @@ catia_realpath(vfs_handle_struct *handle, const char *path,
                return NULL;
        }
 
-       ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name, resolved_path);
+       ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name);
        TALLOC_FREE(mapped_name);
 
        return ret;
index 6f5b09a5a9c4b248e1b2b38d8e4a2917aab5ca7e..eb0e0b95a64dca74f263db464fb567d5a170a9b1 100644 (file)
@@ -1064,12 +1064,25 @@ static int vfswrap_mknod(vfs_handle_struct *handle,  const char *pathname, mode_
        return result;
 }
 
-static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path, char *resolved_path)
+static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path)
 {
        char *result;
 
        START_PROFILE(syscall_realpath);
-       result = realpath(path, resolved_path);
+#ifdef REALPATH_TAKES_NULL
+       result = realpath(path, NULL);
+#else
+       result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
+       if (result) {
+               char *resolved_path = realpath(path, result);
+               if (!resolved_path) {
+                       SAFE_FREE(result);
+               } else {
+                       /* SMB_ASSERT(result == resovled_path) ? */
+                       result = resolved_path;
+               }
+       }
+#endif
        END_PROFILE(syscall_realpath);
        return result;
 }
index 23ca1496bf8348dc8b007d0b37446cba711d2fe6..3328128d861c6f107a888e90583fae09c8d6c769 100644 (file)
@@ -1324,11 +1324,11 @@ static int smb_full_audit_mknod(vfs_handle_struct *handle,
 }
 
 static char *smb_full_audit_realpath(vfs_handle_struct *handle,
-                           const char *path, char *resolved_path)
+                           const char *path)
 {
        char *result;
 
-       result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
+       result = SMB_VFS_NEXT_REALPATH(handle, path);
 
        do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
 
index cf84e581713c0151a282650e942bd1f98d41fd09..bcc40f0d9fa00c2ce9bfe01df31d911b529b8f6a 100644 (file)
@@ -471,11 +471,10 @@ onefs_shadow_copy_mknod(vfs_handle_struct *handle, const char *path,
 }
 
 static char *
-onefs_shadow_copy_realpath(vfs_handle_struct *handle, const char *path,
-                          char *resolved_path)
+onefs_shadow_copy_realpath(vfs_handle_struct *handle, const char *path)
 {
        SHADOW_NEXT(REALPATH,
-                   (handle, cpath ?: path, resolved_path),
+                   (handle, cpath ?: path),
                    char *);
 }
 
index 502f815235cd74aa0176aec17dcd64a4e624af6d..ba6b3441b86d5ccae1d23b6d2e5d15498d5f242e 100644 (file)
@@ -653,7 +653,7 @@ static int shadow_copy2_mknod(vfs_handle_struct *handle,
 }
 
 static char *shadow_copy2_realpath(vfs_handle_struct *handle,
-                           const char *fname, char *resolved_path)
+                           const char *fname)
 {
        const char *gmt;
 
@@ -671,10 +671,10 @@ static char *shadow_copy2_realpath(vfs_handle_struct *handle,
                copy[gmt - fname + 1] = '\0';
 
                DEBUG(10, ("calling NEXT_REALPATH with %s\n", copy));
-               SHADOW2_NEXT(REALPATH, (handle, name, resolved_path), char *,
+               SHADOW2_NEXT(REALPATH, (handle, copy), char *,
                             NULL);
        }
-        SHADOW2_NEXT(REALPATH, (handle, name, resolved_path), char *, NULL);
+        SHADOW2_NEXT(REALPATH, (handle, name), char *, NULL);
 }
 
 static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
index 84e41753ed9746d32fd56ad70b0b6a6350cb40f5..af4fd3313a2006f3bdee88081fe24c1a8e8d919f 100644 (file)
@@ -1066,14 +1066,14 @@ static int smb_time_audit_mknod(vfs_handle_struct *handle,
 }
 
 static char *smb_time_audit_realpath(vfs_handle_struct *handle,
-                                    const char *path, char *resolved_path)
+                                    const char *path)
 {
        char *result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
+       result = SMB_VFS_NEXT_REALPATH(handle, path);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
index 5b6d9087a3bc267b5d1fc2724ac50db03fea4a1f..a58f17c07031cbd4d45b8988f81d556446f629a1 100644 (file)
@@ -26,23 +26,14 @@ extern userdom_struct current_user_info;
 
 static bool canonicalize_connect_path(connection_struct *conn)
 {
-#ifdef REALPATH_TAKES_NULL
        bool ret;
-       char *resolved_name = SMB_VFS_REALPATH(conn,conn->connectpath,NULL);
+       char *resolved_name = SMB_VFS_REALPATH(conn,conn->connectpath);
        if (!resolved_name) {
                return false;
        }
        ret = set_conn_connectpath(conn,resolved_name);
        SAFE_FREE(resolved_name);
        return ret;
-#else
-        char resolved_name_buf[PATH_MAX+1];
-       char *resolved_name = SMB_VFS_REALPATH(conn,conn->connectpath,resolved_name_buf);
-       if (!resolved_name) {
-               return false;
-       }
-       return set_conn_connectpath(conn,resolved_name);
-#endif /* REALPATH_TAKES_NULL */
 }
 
 /****************************************************************************
index d516456f8dbb9fc534cde7eec42000e50c47b73f..7042518ce203c49e6825dbbe322856724453c322 100644 (file)
@@ -841,22 +841,12 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
 
 NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
 {
-#ifdef REALPATH_TAKES_NULL
-       bool free_resolved_name = True;
-#else
-        char resolved_name_buf[PATH_MAX+1];
-       bool free_resolved_name = False;
-#endif
        char *resolved_name = NULL;
        char *p = NULL;
 
        DEBUG(3,("check_reduced_name [%s] [%s]\n", fname, conn->connectpath));
 
-#ifdef REALPATH_TAKES_NULL
-       resolved_name = SMB_VFS_REALPATH(conn,fname,NULL);
-#else
-       resolved_name = SMB_VFS_REALPATH(conn,fname,resolved_name_buf);
-#endif
+       resolved_name = SMB_VFS_REALPATH(conn,fname);
 
        if (!resolved_name) {
                switch (errno) {
@@ -889,11 +879,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                                        }
                                }
 
-#ifdef REALPATH_TAKES_NULL
-                               resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,NULL);
-#else
-                               resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,resolved_name_buf);
-#endif
+                               resolved_name = SMB_VFS_REALPATH(conn,tmp_fname);
                                if (!resolved_name) {
                                        NTSTATUS status = map_nt_error_from_unix(errno);
 
@@ -915,7 +901,6 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                                if (!tmp_fname) {
                                        return NT_STATUS_NO_MEMORY;
                                }
-#ifdef REALPATH_TAKES_NULL
                                SAFE_FREE(resolved_name);
                                resolved_name = SMB_STRDUP(tmp_fname);
                                if (!resolved_name) {
@@ -923,10 +908,6 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                                                  "fail for %s\n", tmp_fname));
                                        return NT_STATUS_NO_MEMORY;
                                }
-#else
-                               safe_strcpy(resolved_name_buf, tmp_fname, PATH_MAX);
-                               resolved_name = resolved_name_buf;
-#endif
                                break;
                        }
                        default:
@@ -942,9 +923,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
        if (*resolved_name != '/') {
                DEBUG(0,("check_reduced_name: realpath doesn't return "
                         "absolute paths !\n"));
-               if (free_resolved_name) {
-                       SAFE_FREE(resolved_name);
-               }
+               SAFE_FREE(resolved_name);
                return NT_STATUS_OBJECT_NAME_INVALID;
        }
 
@@ -956,9 +935,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                    if (conn_rootdir == NULL) {
                            DEBUG(2, ("check_reduced_name: Could not get "
                                      "conn_rootdir\n"));
-                           if (free_resolved_name) {
-                                   SAFE_FREE(resolved_name);
-                           }
+                           SAFE_FREE(resolved_name);
                            return NT_STATUS_ACCESS_DENIED;
                    }
 
@@ -967,9 +944,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                            DEBUG(2, ("check_reduced_name: Bad access "
                                      "attempt: %s is a symlink outside the "
                                      "share path\n", fname));
-                           if (free_resolved_name) {
-                                   SAFE_FREE(resolved_name);
-                           }
+                           SAFE_FREE(resolved_name);
                            return NT_STATUS_ACCESS_DENIED;
                    }
        }
@@ -986,17 +961,13 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                status = create_synthetic_smb_fname(talloc_tos(), fname, NULL,
                                                    NULL, &smb_fname);
                if (!NT_STATUS_IS_OK(status)) {
-                       if (free_resolved_name) {
-                               SAFE_FREE(resolved_name);
-                       }
+                       SAFE_FREE(resolved_name);
                         return status;
                }
 
                if ( (SMB_VFS_LSTAT(conn, smb_fname) != -1) &&
                                 (S_ISLNK(smb_fname->st.st_ex_mode)) ) {
-                       if (free_resolved_name) {
-                               SAFE_FREE(resolved_name);
-                       }
+                       SAFE_FREE(resolved_name);
                         DEBUG(3,("check_reduced_name: denied: file path name "
                                 "%s is a symlink\n",resolved_name));
                        TALLOC_FREE(smb_fname);
@@ -1008,9 +979,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
 
        DEBUG(3,("check_reduced_name: %s reduced to %s\n", fname,
                 resolved_name));
-       if (free_resolved_name) {
-               SAFE_FREE(resolved_name);
-       }
+       SAFE_FREE(resolved_name);
        return NT_STATUS_OK;
 }
 
@@ -1486,11 +1455,10 @@ int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
        return handle->fns->mknod(handle, path, mode, dev);
 }
 
-char *smb_vfs_call_realpath(struct vfs_handle_struct *handle,
-                           const char *path, char *resolved_path)
+char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path)
 {
        VFS_FIND(realpath);
-       return handle->fns->realpath(handle, path, resolved_path);
+       return handle->fns->realpath(handle, path);
 }
 
 NTSTATUS smb_vfs_call_notify_watch(struct vfs_handle_struct *handle,
index cd550a4f4849d3e58b51ac62022a0f0979591f89..ea5004ce639364b93a58eb8bc938f80212ae60da 100644 (file)
@@ -1128,14 +1128,12 @@ static NTSTATUS cmd_mknod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 
 static NTSTATUS cmd_realpath(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       char respath[PATH_MAX];
-       
        if (argc != 2) {
                printf("Usage: realpath <path>\n");
                return NT_STATUS_OK;
        }
 
-       if (SMB_VFS_REALPATH(vfs->conn, argv[1], respath) == NULL) {
+       if (SMB_VFS_REALPATH(vfs->conn, argv[1]) == NULL) {
                printf("realpath: error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
        }