From 2b788aa6ce41c5c0a6892cb412cf40a7cbc73f2a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Nov 2010 16:29:26 -0800 Subject: Move the uglyness of #ifdef REALPATH_TAKES_NULL into the vfs_default 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 Autobuild-Date: Sat Nov 20 02:15:50 CET 2010 on sn-devel-104 --- source3/smbd/service.c | 11 +---------- source3/smbd/vfs.c | 52 ++++++++++---------------------------------------- 2 files changed, 11 insertions(+), 52 deletions(-) (limited to 'source3/smbd') diff --git a/source3/smbd/service.c b/source3/smbd/service.c index 5b6d9087a3..a58f17c070 100644 --- a/source3/smbd/service.c +++ b/source3/smbd/service.c @@ -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 */ } /**************************************************************************** diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index d516456f8d..7042518ce2 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -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, -- cgit