Merge branch 'master' of ssh://git.samba.org/data/git/samba into abartlet-devel
[samba.git] / source3 / smbd / service.c
index c90d4d16bc273d2b9e97b7af2cf614cf15d44323..eb16a2601e312e76d90e63f3401fe781cf42c356 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include "smbd/globals.h"
 
 extern userdom_struct current_user_info;
 
@@ -167,8 +168,6 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath)
 
 bool set_current_service(connection_struct *conn, uint16 flags, bool do_chdir)
 {
-       static connection_struct *last_conn;
-       static uint16 last_flags;
        int snum;
 
        if (!conn)  {
@@ -235,6 +234,10 @@ static int load_registry_service(const char *servicename)
                return -1;
        }
 
+       if ((servicename == NULL) || (*servicename == '\0')) {
+               return -1;
+       }
+
        if (strequal(servicename, GLOBAL_NAME)) {
                return -2;
        }
@@ -646,6 +649,7 @@ static NTSTATUS create_connection_server_info(TALLOC_CTX *mem_ctx, int snum,
                         }
                 } else {
                         if (!user_ok_token(vuid_serverinfo->unix_name,
+                                          pdb_get_domain(vuid_serverinfo->sam_account),
                                            vuid_serverinfo->ptok, snum)) {
                                 DEBUG(2, ("user '%s' (from session setup) not "
                                           "permitted to access this share "
@@ -822,13 +826,21 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                status = find_forced_group(
                        conn->force_user, snum, conn->server_info->unix_name,
                        &conn->server_info->ptok->user_sids[1],
-                       &conn->server_info->gid);
+                       &conn->server_info->utok.gid);
 
                if (!NT_STATUS_IS_OK(status)) {
                        conn_free(conn);
                        *pstatus = status;
                        return NULL;
                }
+
+               /*
+                * We need to cache this gid, to use within
+                * change_to_user() separately from the conn->server_info
+                * struct. We only use conn->server_info directly if
+                * "force_user" was set.
+                */
+               conn->force_group_gid = conn->server_info->utok.gid;
        }
 
        conn->vuid = (vuser != NULL) ? vuser->vuid : UID_FIELD_INVALID;
@@ -838,9 +850,9 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                        lp_servicename(SNUM(conn)),
                                        conn->server_info->unix_name,
                                        conn->connectpath,
-                                       conn->server_info->gid,
-                                       get_current_username(),
-                                       current_user_info.domain,
+                                       conn->server_info->utok.gid,
+                                       conn->server_info->sanitized_username,
+                                       pdb_get_domain(conn->server_info->sam_account),
                                        lp_pathname(snum));
                if (!s) {
                        conn_free(conn);
@@ -960,9 +972,9 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                        lp_servicename(SNUM(conn)),
                                        conn->server_info->unix_name,
                                        conn->connectpath,
-                                       conn->server_info->gid,
-                                       get_current_username(),
-                                       current_user_info.domain,
+                                       conn->server_info->utok.gid,
+                                       conn->server_info->sanitized_username,
+                                       pdb_get_domain(conn->server_info->sam_account),
                                        lp_rootpreexec(snum));
                DEBUG(5,("cmd=%s\n",cmd));
                ret = smbrun(cmd,NULL);
@@ -999,9 +1011,9 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                        lp_servicename(SNUM(conn)),
                                        conn->server_info->unix_name,
                                        conn->connectpath,
-                                       conn->server_info->gid,
-                                       get_current_username(),
-                                       current_user_info.domain,
+                                       conn->server_info->utok.gid,
+                                       conn->server_info->sanitized_username,
+                                       pdb_get_domain(conn->server_info->sam_account),
                                        lp_preexec(snum));
                ret = smbrun(cmd,NULL);
                TALLOC_FREE(cmd);
@@ -1024,6 +1036,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                set_namearray( &conn->veto_list, lp_veto_files(snum));
                set_namearray( &conn->hide_list, lp_hide_files(snum));
                set_namearray( &conn->veto_oplock_list, lp_veto_oplocks(snum));
+               set_namearray( &conn->aio_write_behind_list,
+                               lp_aio_write_behind(snum));
        }
        
        /* Invoke VFS make connection hook - do this before the VFS_STAT call
@@ -1120,38 +1134,6 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        return NULL;
 }
 
-/***************************************************************************************
- Simple wrapper function for make_connection() to include a call to 
- vfs_chdir()
- **************************************************************************************/
-connection_struct *make_connection_with_chdir(const char *service_in,
-                                             DATA_BLOB password, 
-                                             const char *dev, uint16 vuid,
-                                             NTSTATUS *status)
-{
-       connection_struct *conn = NULL;
-       
-       conn = make_connection(service_in, password, dev, vuid, status);
-       
-       /*
-        * make_connection() does not change the directory for us any more
-        * so we have to do it as a separate step  --jerry
-        */
-        
-       if ( conn && vfs_ChDir(conn,conn->connectpath) != 0 ) {
-               DEBUG(0,("move_driver_to_download_area: Can't change "
-                        "directory to %s for [print$] (%s)\n",
-                        conn->connectpath,strerror(errno)));
-               yield_connection(conn, lp_servicename(SNUM(conn)));
-               conn_free(conn);
-               *status = NT_STATUS_UNSUCCESSFUL;
-               return NULL;
-       }
-       
-       return conn;
-}
-
 /****************************************************************************
  Make a connection to a service.
  *
@@ -1293,10 +1275,9 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password,
 
 void close_cnum(connection_struct *conn, uint16 vuid)
 {
-       if (IS_IPC(conn)) {
-               pipe_close_conn(conn);
-       } else {
-               file_close_conn(conn);
+       file_close_conn(conn);
+
+       if (!IS_IPC(conn)) {
                dptr_closecnum(conn);
        }
 
@@ -1322,9 +1303,9 @@ void close_cnum(connection_struct *conn, uint16 vuid)
                                        lp_servicename(SNUM(conn)),
                                        conn->server_info->unix_name,
                                        conn->connectpath,
-                                       conn->server_info->gid,
-                                       get_current_username(),
-                                       current_user_info.domain,
+                                       conn->server_info->utok.gid,
+                                       conn->server_info->sanitized_username,
+                                       pdb_get_domain(conn->server_info->sam_account),
                                        lp_postexec(SNUM(conn)));
                smbrun(cmd,NULL);
                TALLOC_FREE(cmd);
@@ -1338,9 +1319,9 @@ void close_cnum(connection_struct *conn, uint16 vuid)
                                        lp_servicename(SNUM(conn)),
                                        conn->server_info->unix_name,
                                        conn->connectpath,
-                                       conn->server_info->gid,
-                                       get_current_username(),
-                                       current_user_info.domain,
+                                       conn->server_info->utok.gid,
+                                       conn->server_info->sanitized_username,
+                                       pdb_get_domain(conn->server_info->sam_account),
                                        lp_rootpostexec(SNUM(conn)));
                smbrun(cmd,NULL);
                TALLOC_FREE(cmd);