smbd: remove dead code
[samba.git] / source3 / smbd / service.c
index 13cde984f76d7d1eb973b910cdb28b39313e0461..ea99f0d2129d83fc3eb52baa43e7930e92a295ea 100644 (file)
@@ -34,7 +34,7 @@
 #include "lib/afs/afs_funcs.h"
 #include "lib/util_path.h"
 
-static bool canonicalize_connect_path(connection_struct *conn)
+bool canonicalize_connect_path(connection_struct *conn)
 {
        bool ret;
        struct smb_filename con_fname = { .base_name = conn->connectpath };
@@ -80,6 +80,7 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath)
                                conn->connectpath,
                                NULL,
                                NULL,
+                               0,
                                0);
        if (conn->cwd_fsp->fsp_name == NULL) {
                return false;
@@ -146,55 +147,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;
 }
 
 /****************************************************************************
@@ -544,6 +536,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
        uid_t effuid;
        gid_t effgid;
        NTSTATUS status;
+       bool ok;
 
        fstrcpy(dev, pdev);
 
@@ -805,21 +798,20 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
 /* ROOT Activites: */
 
        /*
-        * If widelinks are disallowed we need to canonicalise the connect
+        * Canonicalise the connect
         * path here to ensure we don't have any symlinks in the
         * connectpath. We will be checking all paths on this connection are
         * below this directory. We must do this after the VFS init as we
         * depend on the realpath() pointer in the vfs table. JRA.
         */
-       if (!lp_widelinks(snum)) {
-               if (!canonicalize_connect_path(conn)) {
-                       DBG_ERR("canonicalize_connect_path failed "
-                       "for service %s, path %s\n",
-                               lp_const_servicename(snum),
-                               conn->connectpath);
-                       status = NT_STATUS_BAD_NETWORK_NAME;
-                       goto err_root_exit;
-               }
+       ok = canonicalize_connect_path(conn);
+       if (!ok) {
+               DBG_ERR("canonicalize_connect_path failed "
+               "for service %s, path %s\n",
+                       lp_const_servicename(snum),
+                       conn->connectpath);
+               status = NT_STATUS_BAD_NETWORK_NAME;
+               goto err_root_exit;
        }
 
        /* Add veto/hide lists */
@@ -837,6 +829,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                                        conn->connectpath,
                                        NULL,
                                        NULL,
+                                       0,
                                        0);
        if (smb_fname_cpath == NULL) {
                status = NT_STATUS_NO_MEMORY;
@@ -919,7 +912,7 @@ static NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
 
 static connection_struct *make_connection_smb1(struct smb_request *req,
                                        NTTIME now,
-                                       int snum, struct user_struct *vuser,
+                                       int snum,
                                        const char *pdev,
                                        NTSTATUS *pstatus)
 {
@@ -968,7 +961,7 @@ static connection_struct *make_connection_smb1(struct smb_request *req,
                return NULL;
        }
        tcon->global->session_global_id =
-               vuser->session->global->session_global_id;
+               req->session->global->session_global_id;
 
        tcon->compat = talloc_move(tcon, &conn);
        tcon->status = NT_STATUS_OK;
@@ -990,7 +983,6 @@ static connection_struct *make_connection_smb1(struct smb_request *req,
 connection_struct *make_connection_smb2(struct smbd_smb2_request *req,
                                        struct smbXsrv_tcon *tcon,
                                        int snum,
-                                       struct user_struct *vuser,
                                        const char *pdev,
                                        NTSTATUS *pstatus)
 {
@@ -1034,7 +1026,6 @@ connection_struct *make_connection(struct smb_request *req,
        const struct loadparm_substitution *lp_sub =
                loadparm_s3_global_substitution();
        uid_t euid;
-       struct user_struct *vuser = NULL;
        char *service = NULL;
        fstring dev;
        int snum = -1;
@@ -1054,8 +1045,7 @@ connection_struct *make_connection(struct smb_request *req,
                return NULL;
        }
 
-       vuser = get_valid_user_struct(sconn, vuid);
-       if (!vuser) {
+       if (session == NULL) {
                DEBUG(1,("make_connection: refusing to connect with "
                         "no session setup\n"));
                *status = NT_STATUS_ACCESS_DENIED;
@@ -1081,7 +1071,6 @@ connection_struct *make_connection(struct smb_request *req,
                          "created at session setup time\n"));
                return make_connection_smb1(req, now,
                                            session->homes_snum,
-                                           vuser,
                                            dev, status);
        } else if ((session->homes_snum != -1)
                   && strequal(service_in,
@@ -1090,7 +1079,6 @@ connection_struct *make_connection(struct smb_request *req,
                          "created at session setup time\n", service_in));
                return make_connection_smb1(req, now,
                                            session->homes_snum,
-                                           vuser,
                                            dev, status);
        }
 
@@ -1140,7 +1128,7 @@ connection_struct *make_connection(struct smb_request *req,
 
        DEBUG(5, ("making a connection to 'normal' service %s\n", service));
 
-       return make_connection_smb1(req, now, snum, vuser,
+       return make_connection_smb1(req, now, snum,
                                    dev, status);
 }