smbd: split out set_current_case_sensitive() and chdir_current_service() functions
authorStefan Metzmacher <metze@samba.org>
Wed, 13 Jun 2018 09:03:01 +0000 (11:03 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 18 Jun 2018 06:59:16 +0000 (08:59 +0200)
We'll soon use them independend from set_current_service().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/proto.h
source3/smbd/service.c

index 2851d6d5f7df623eb51c575bf02c3f5c621c983b..a6b8a05cb4c67bd4be2fe0438a55edb0862e2f3b 100644 (file)
@@ -1061,6 +1061,8 @@ void smbd_exit_server_cleanly(const char *const reason) _NORETURN_;
 
 bool set_conn_connectpath(connection_struct *conn, const char *connectpath);
 NTSTATUS set_conn_force_user_group(connection_struct *conn, int snum);
+void set_current_case_sensitive(connection_struct *conn, uint16_t flags);
+bool chdir_current_service(connection_struct *conn);
 bool set_current_service(connection_struct *conn, uint16_t flags, bool do_chdir);
 void load_registry_shares(void);
 int add_home_service(const char *service, const char *username, const char *homedir);
index 75a47dee0caae891a5364ee00a858400250ad17c..35b1a4617e85ed13a24e3c2bf4110dc4485dc067 100644 (file)
@@ -90,40 +90,17 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath)
  Load parameters specific to a connection/service.
 ****************************************************************************/
 
-bool set_current_service(connection_struct *conn, uint16_t flags, bool do_chdir)
+void set_current_case_sensitive(connection_struct *conn, uint16_t flags)
 {
        int snum;
        enum remote_arch_types ra_type;
 
-       if (!conn)  {
-               last_conn = NULL;
-               return(False);
-       }
-
-       conn->lastused_count++;
+       SMB_ASSERT(conn != NULL);
 
        snum = SNUM(conn);
 
-       {
-               struct smb_filename connectpath_fname = {
-                       .base_name = conn->connectpath
-               };
-               struct smb_filename origpath_fname = {
-                       .base_name = conn->origpath
-               };
-
-               if (do_chdir &&
-                   vfs_ChDir(conn, &connectpath_fname) != 0 &&
-                   vfs_ChDir(conn, &origpath_fname) != 0) {
-                       DEBUG(((errno!=EACCES)?0:3),
-                               ("chdir (%s) failed, reason: %s\n",
-                               conn->connectpath, strerror(errno)));
-                       return(False);
-               }
-       }
-
        if ((conn == last_conn) && (last_flags == flags)) {
-               return(True);
+               return;
        }
 
        last_conn = conn;
@@ -157,6 +134,56 @@ bool set_current_service(connection_struct *conn, uint16_t flags, bool do_chdir)
                conn->case_sensitive = false;
                break;
        }
+       return;
+}
+
+bool chdir_current_service(connection_struct *conn)
+{
+       const struct smb_filename connectpath_fname = {
+               .base_name = conn->connectpath,
+       };
+       const struct smb_filename origpath_fname = {
+               .base_name = conn->origpath,
+       };
+       int ret;
+
+       conn->lastused_count++;
+
+       ret = vfs_ChDir(conn, &connectpath_fname);
+       if (ret != 0) {
+               DEBUG(((errno!=EACCES)?0:3),
+                     ("chdir (%s) failed, reason: %s\n",
+                      conn->connectpath, strerror(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)));
+               return false;
+       }
+
+       return true;
+}
+
+bool set_current_service(connection_struct *conn, uint16_t flags, bool do_chdir)
+{
+       bool ok;
+
+       if (conn == NULL)  {
+               return false;
+       }
+
+       if (do_chdir) {
+               ok = chdir_current_service(conn);
+               if (!ok) {
+                       return false;
+               }
+       }
+
+       set_current_case_sensitive(conn, flags);
        return true;
 }