Revert "smbd: add smbd_server_connection->raw_ev_ctx pointer"
[garming/samba-autobuild/.git] / source3 / smbd / msdfs.c
index ff836138cd777fba16d229b10864f10e920eca05..19cb301f56b3404331ae25e121944d44c3626472 100644 (file)
@@ -28,6 +28,7 @@
 #include "smbd/globals.h"
 #include "msdfs.h"
 #include "auth.h"
+#include "../auth/auth_util.h"
 #include "lib/param/loadparm.h"
 #include "libcli/security/security.h"
 #include "librpc/gen_ndr/ndr_dfsblobs.h"
@@ -240,7 +241,6 @@ static NTSTATUS parse_dfs_path(connection_struct *conn,
 *********************************************************/
 
 static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
-                           struct tevent_context *ev,
                            struct messaging_context *msg,
                            connection_struct **pconn,
                            int snum,
@@ -258,7 +258,12 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       sconn->ev_ctx = ev;
+       sconn->ev_ctx = samba_tevent_context_init(sconn);
+       if (sconn->ev_ctx == NULL) {
+               TALLOC_FREE(sconn);
+               return NT_STATUS_NO_MEMORY;
+       }
+
        sconn->msg_ctx = msg;
 
        conn = conn_new(sconn);
@@ -301,7 +306,12 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
                        TALLOC_FREE(conn);
                        return NT_STATUS_NO_MEMORY;
                }
-               vfs_user = conn->session_info->unix_info->unix_name;
+               /* unix_info could be NULL in session_info */
+               if (conn->session_info->unix_info != NULL) {
+                       vfs_user = conn->session_info->unix_info->unix_name;
+               } else {
+                       vfs_user = get_current_username();
+               }
        } else {
                /* use current authenticated user in absence of session_info */
                vfs_user = get_current_username();
@@ -353,7 +363,15 @@ static NTSTATUS create_conn_struct_as_root(TALLOC_CTX *ctx,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
+       talloc_free(conn->origpath);
+       conn->origpath = talloc_strdup(conn, conn->connectpath);
+       if (conn->origpath == NULL) {
+               conn_free(conn);
+               return NT_STATUS_NO_MEMORY;
+       }
+
        conn->fs_capabilities = SMB_VFS_FS_CAPABILITIES(conn, &conn->ts_res);
+       conn->tcon_done = true;
        *pconn = talloc_move(ctx, &conn);
 
        return NT_STATUS_OK;
@@ -387,7 +405,6 @@ NTSTATUS create_conn_struct_tos(struct messaging_context *msg,
                                struct conn_struct_tos **_c)
 {
        struct conn_struct_tos *c = NULL;
-       struct tevent_context *ev = NULL;
        NTSTATUS status;
 
        *_c = NULL;
@@ -397,15 +414,8 @@ NTSTATUS create_conn_struct_tos(struct messaging_context *msg,
                return NT_STATUS_NO_MEMORY;
        }
 
-       ev = samba_tevent_context_init(c);
-       if (ev == NULL) {
-               TALLOC_FREE(c);
-               return NT_STATUS_NO_MEMORY;
-       }
-
        become_root();
        status = create_conn_struct_as_root(c,
-                                           ev,
                                            msg,
                                            &c->conn,
                                            snum,
@@ -1097,7 +1107,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
                return NT_STATUS_OK;
        }
 
-       status = create_conn_struct_tos_cwd(server_messaging_context(),
+       status = create_conn_struct_tos_cwd(global_messaging_context(),
                                            snum,
                                            lp_path(frame, snum),
                                            NULL,
@@ -1311,7 +1321,7 @@ static bool junction_to_local_path_tos(const struct junction_map *jucn,
        if(snum < 0) {
                return False;
        }
-       status = create_conn_struct_tos_cwd(server_messaging_context(),
+       status = create_conn_struct_tos_cwd(global_messaging_context(),
                                            snum,
                                            lp_path(talloc_tos(), snum),
                                            NULL,
@@ -1481,7 +1491,7 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
         * Fake up a connection struct for the VFS layer.
         */
 
-       status = create_conn_struct_tos_cwd(server_messaging_context(),
+       status = create_conn_struct_tos_cwd(global_messaging_context(),
                                            snum,
                                            connect_path,
                                            NULL,
@@ -1578,7 +1588,7 @@ static int form_junctions(TALLOC_CTX *ctx,
         * Fake up a connection struct for the VFS layer.
         */
 
-       status = create_conn_struct_tos_cwd(server_messaging_context(),
+       status = create_conn_struct_tos_cwd(global_messaging_context(),
                                            snum,
                                            connect_path,
                                            NULL,