smbd: Enhance debugging if chdir fails
authorVolker Lendecke <vl@samba.org>
Wed, 9 Jan 2019 16:24:57 +0000 (17:24 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 11 Sep 2019 19:59:34 +0000 (19:59 +0000)
This helps admins to figure out which user has a problem

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Volker Lendecke <vl@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/service.c
source3/smbd/uid.c

index 64b638346ae0ebfc12d9f28de3271b03c232e67c..7b3abe4c3e097ecdb3b6cf926b04b86870a32080 100644 (file)
@@ -152,17 +152,45 @@ bool chdir_current_service(connection_struct *conn)
 
        ret = vfs_ChDir(conn, &connectpath_fname);
        if (ret != 0) {
-               DEBUG(((errno!=EACCES)?0:3),
-                     ("chdir (%s) failed, reason: %s\n",
-                      conn->connectpath, strerror(errno)));
+               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));
+               }
                return false;
        }
 
        ret = vfs_ChDir(conn, &origpath_fname);
        if (ret != 0) {
-               DEBUG(((errno!=EACCES)?0:3),
-                       ("chdir (%s) failed, reason: %s\n",
-                       conn->origpath, strerror(errno)));
+               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;
        }
 
index 5425449d42c33e6650af15dd0ae1066cf134f7a4..8fa38e459dd2812a767f9b38b44586d2f5f2ee9f 100644 (file)
@@ -445,7 +445,6 @@ static bool change_to_user_internal(connection_struct *conn,
        if (current_user.need_chdir) {
                ok = chdir_current_service(conn);
                if (!ok) {
-                       DBG_ERR("chdir_current_service() failed!\n");
                        return false;
                }
                current_user.done_chdir = true;