smbd: Rework create_conn_struct to use conn_new()
authorAndrew Bartlett <abartlet@samba.org>
Tue, 8 Jan 2013 21:02:23 +0000 (08:02 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 9 Jan 2013 03:54:22 +0000 (14:54 +1100)
This avoids issues with required structure elements not being initialised.

In particular, once conn->vuid_cache becomes a pointer, this ensures
that it is initalised in all cases.

Andrew Bartlett

Reviewed by: Jeremy Allison <jra@samba.org>

source3/smbd/msdfs.c

index e8a0610..8e80cbb 100644 (file)
@@ -234,12 +234,29 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
        connection_struct *conn;
        char *connpath;
        const char *vfs_user;
+       struct smbd_server_connection *sconn;
 
-       conn = talloc_zero(ctx, connection_struct);
+       sconn = talloc_zero(ctx, struct smbd_server_connection);
+       if (sconn == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       sconn->ev_ctx = ev;
+       sconn->msg_ctx = msg;
+       sconn->sock = -1;
+       sconn->smb1.echo_handler.trusted_fd = -1;
+       sconn->smb1.echo_handler.socket_lock_fd = -1;
+
+       conn = conn_new(sconn);
        if (conn == NULL) {
+               TALLOC_FREE(sconn);
                return NT_STATUS_NO_MEMORY;
        }
 
+       /* Now we have conn, we need to make sconn a child of conn,
+        * for a proper talloc tree */
+       talloc_steal(conn, sconn);
+
        connpath = talloc_strdup(conn, path);
        if (!connpath) {
                TALLOC_FREE(conn);
@@ -254,32 +271,11 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       conn->sconn = talloc_zero(conn, struct smbd_server_connection);
-       if (conn->sconn == NULL) {
-               TALLOC_FREE(conn);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       conn->sconn->ev_ctx = ev;
-       conn->sconn->msg_ctx = msg;
-       conn->sconn->sock = -1;
-       conn->sconn->smb1.echo_handler.trusted_fd = -1;
-       conn->sconn->smb1.echo_handler.socket_lock_fd = -1;
-
        /* needed for smbd_vfs_init() */
 
-       if (!(conn->params = talloc_zero(conn, struct share_params))) {
-               DEBUG(0, ("TALLOC failed\n"));
-               TALLOC_FREE(conn);
-               return NT_STATUS_NO_MEMORY;
-       }
-
        conn->params->service = snum;
        conn->cnum = TID_FIELD_INVALID;
 
-       DLIST_ADD(conn->sconn->connections, conn);
-       conn->sconn->num_connections++;
-
        if (session_info != NULL) {
                conn->session_info = copy_session_info(conn, session_info);
                if (conn->session_info == NULL) {