]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: avoid double chdir() in chdir_current_service()
authorRalph Boehme <slow@samba.org>
Wed, 22 Jan 2020 09:52:39 +0000 (10:52 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 6 Feb 2020 11:44:07 +0000 (11:44 +0000)
Since 8e81090789e4cc3ba9e5aa792d4e52971909c894 we're doing chdir() twice, first
into conn->connectpath, then into conn->origpath.

Before commit 8e81090789e4cc3ba9e5aa792d4e52971909c894 if
chdir(conn->connectpath) succeeded, we wouldn't do the second chdir().

While at it, simplify the logging logic: if chdir() fails in this core function,
just always log is as error including the unix token.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14256
RN: smbd does a chdir() twice per request

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Feb  6 11:44:07 UTC 2020 on sn-devel-184

source3/smbd/service.c

index 1abc23ad422887015adaa6d7a9eef77e884d90c2..03125a30dad56acb2b23838936ebcbe1aab638ac 100644 (file)
@@ -146,55 +146,46 @@ bool chdir_current_service(connection_struct *conn)
        const struct smb_filename origpath_fname = {
                .base_name = conn->origpath,
        };
+       int saved_errno = 0;
+       char *utok_str = NULL;
        int ret;
 
        conn->lastused_count++;
 
        ret = vfs_ChDir(conn, &connectpath_fname);
-       if (ret != 0) {
-               int saved_errno = errno;
-
-               if (saved_errno == EACCES) {
-                       char *str = utok_string(
-                               talloc_tos(),
-                               conn->session_info->unix_token);
-                       DBG_WARNING("vfs_ChDir(%s) got "
-                                   "permission denied, current "
-                                   "token: %s\n",
-                                   conn->connectpath, str);
-                       TALLOC_FREE(str);
-               } else {
-                       DBG_ERR("vfs_ChDir(%s) failed: "
-                               "%s!\n",
-                               conn->connectpath,
-                               strerror(saved_errno));
-               }
+       if (ret == 0) {
+               return true;
+       }
+       saved_errno = errno;
+
+       utok_str = utok_string(talloc_tos(),
+                              conn->session_info->unix_token);
+       if (utok_str == NULL) {
+               errno = saved_errno;
                return false;
        }
 
+       DBG_ERR("vfs_ChDir(%s) failed: %s. Current token: %s\n",
+               conn->connectpath,
+               strerror(saved_errno),
+               utok_str);
+
        ret = vfs_ChDir(conn, &origpath_fname);
-       if (ret != 0) {
-               int saved_errno = errno;
-
-               if (saved_errno == EACCES) {
-                       char *str = utok_string(
-                               talloc_tos(),
-                               conn->session_info->unix_token);
-                       DBG_WARNING("vfs_ChDir(%s) got "
-                                   "permission denied, current "
-                                   "token: %s\n",
-                                   conn->origpath, str);
-                       TALLOC_FREE(str);
-               } else {
-                       DBG_ERR("vfs_ChDir(%s) failed: "
-                               "%s!\n",
-                               conn->origpath,
-                               strerror(saved_errno));
-               }
-               return false;
+       if (ret == 0) {
+               TALLOC_FREE(utok_str);
+               return true;
        }
+       saved_errno = errno;
 
-       return true;
+       DBG_ERR("vfs_ChDir(%s) failed: %s. Current token: %s\n",
+               conn->origpath,
+               strerror(saved_errno),
+               utok_str);
+
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return false;
 }
 
 /****************************************************************************