Remove connection_struct->mem_ctx, connection_struct is its own parent
authorVolker Lendecke <vl@samba.org>
Mon, 28 Apr 2008 08:31:49 +0000 (10:31 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 5 May 2008 09:23:13 +0000 (11:23 +0200)
(This used to be commit 559180f7d30606d1999399d954ceedc798c669a4)

source3/include/smb.h
source3/modules/vfs_fileid.c
source3/smbd/conn.c
source3/smbd/dfree.c
source3/smbd/ipc.c
source3/smbd/msdfs.c
source3/smbd/nttrans.c
source3/smbd/posix_acls.c
source3/smbd/service.c
source3/smbd/trans2.c
source3/smbd/vfs.c

index ce91d81c2d17b5e85402e17ad019e2990c14edcb..f3295e12bd4df08e1b5d415c4a79b1deb23dc96f 100644 (file)
@@ -616,7 +616,6 @@ struct share_iterator {
 
 typedef struct connection_struct {
        struct connection_struct *next, *prev;
-       TALLOC_CTX *mem_ctx; /* long-lived memory context for things hanging off this struct. */
        unsigned cnum; /* an index passed over the wire */
        struct share_params *params;
        bool force_user;
index 5954a10ddb71fa0724b49430ec0220d6d5fc9f35..1cbd857a357bc63581b628a3afe66634e8ca6eeb 100644 (file)
@@ -182,7 +182,7 @@ static int fileid_connect(struct vfs_handle_struct *handle,
        struct fileid_handle_data *data;
        const char *algorithm;
 
-       data = talloc_zero(handle->conn->mem_ctx, struct fileid_handle_data);
+       data = talloc_zero(handle->conn, struct fileid_handle_data);
        if (!data) {
                DEBUG(0, ("talloc_zero() failed\n"));
                return -1;
index 5aedadc56b0ddaaed9075b58224c8d1cb8ece7fb..af18e905c08576ec9b81ac6ed75e9cac304051fa 100644 (file)
@@ -92,7 +92,6 @@ thinking the server is still available.
 ****************************************************************************/
 connection_struct *conn_new(void)
 {
-       TALLOC_CTX *mem_ctx;
        connection_struct *conn;
        int i;
         int find_offset = 1;
@@ -140,18 +139,12 @@ find_again:
                return NULL;
        }
 
-       if ((mem_ctx=talloc_init("connection_struct"))==NULL) {
-               DEBUG(0,("talloc_init(connection_struct) failed!\n"));
-               return NULL;
-       }
-
-       if (!(conn=TALLOC_ZERO_P(mem_ctx, connection_struct)) ||
-           !(conn->params = TALLOC_P(mem_ctx, struct share_params))) {
+       if (!(conn=TALLOC_ZERO_P(NULL, connection_struct)) ||
+           !(conn->params = TALLOC_P(conn, struct share_params))) {
                DEBUG(0,("TALLOC_ZERO() failed!\n"));
-               TALLOC_FREE(mem_ctx);
+               TALLOC_FREE(conn);
                return NULL;
        }
-       conn->mem_ctx = mem_ctx;
        conn->cnum = i;
 
        bitmap_set(bmap, i);
@@ -262,7 +255,6 @@ void conn_clear_vuid_cache(uint16 vuid)
 void conn_free_internal(connection_struct *conn)
 {
        vfs_handle_struct *handle = NULL, *thandle = NULL;
-       TALLOC_CTX *mem_ctx = NULL;
        struct trans_state *state = NULL;
 
        /* Free vfs_connection_struct */
@@ -292,9 +284,8 @@ void conn_free_internal(connection_struct *conn)
        string_free(&conn->connectpath);
        string_free(&conn->origpath);
 
-       mem_ctx = conn->mem_ctx;
        ZERO_STRUCTP(conn);
-       talloc_destroy(mem_ctx);
+       talloc_destroy(conn);
 }
 
 /****************************************************************************
index 9e7f18a1308c01f785d32b0dcb47ff7fb556c2ff..1ddcd48d40469b8d049e8ea51b13946315b53fa1 100644 (file)
@@ -206,7 +206,7 @@ SMB_BIG_UINT get_dfree_info(connection_struct *conn,
 
        /* No cached info or time to refresh. */
        if (!dfc) {
-               dfc = TALLOC_P(conn->mem_ctx, struct dfree_cached_info);
+               dfc = TALLOC_P(conn, struct dfree_cached_info);
                if (!dfc) {
                        return dfree_ret;
                }
index 6961a5caf15ac17fddf0600124325f9ed6f0e486..59a5dfdd3f3859520e8bf588c760ad14c17b3e9c 100644 (file)
@@ -525,7 +525,7 @@ void reply_trans(struct smb_request *req)
                return;
        }
 
-       if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
+       if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
                DEBUG(0, ("talloc failed\n"));
                reply_nterror(req, NT_STATUS_NO_MEMORY);
                END_PROFILE(SMBtrans);
index fb757a5f7469f76e9385c0ca64de2c0be3f71fa1..14062e129d1f4ce7e77c4465efcd34c62188fc39 100644 (file)
@@ -175,36 +175,37 @@ static NTSTATUS parse_dfs_path(const char *pathname,
 *********************************************************/
 
 static NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
-                               connection_struct *conn,
+                               connection_struct **pconn,
                                int snum,
                                const char *path)
 {
+       connection_struct *conn;
        char *connpath;
 
-       ZERO_STRUCTP(conn);
+       conn = TALLOC_ZERO_P(ctx, connection_struct);
+       if (conn == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
-       connpath = talloc_strdup(ctx, path);
+       connpath = talloc_strdup(conn, path);
        if (!connpath) {
+               TALLOC_FREE(conn);
                return NT_STATUS_NO_MEMORY;
        }
-       connpath = talloc_string_sub(ctx,
+       connpath = talloc_string_sub(conn,
                                connpath,
                                "%S",
                                lp_servicename(snum));
        if (!connpath) {
+               TALLOC_FREE(conn);
                return NT_STATUS_NO_MEMORY;
        }
 
        /* needed for smbd_vfs_init() */
 
-       if ((conn->mem_ctx=talloc_init("connection_struct")) == NULL) {
-               DEBUG(0,("talloc_init(connection_struct) failed!\n"));
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       if (!(conn->params = TALLOC_ZERO_P(conn->mem_ctx,
-                                       struct share_params))) {
+       if (!(conn->params = TALLOC_ZERO_P(conn, struct share_params))) {
                DEBUG(0, ("TALLOC failed\n"));
+               TALLOC_FREE(conn);
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -234,6 +235,8 @@ static NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
                return status;
        }
 
+       *pconn = conn;
+
        return NT_STATUS_OK;
 }
 
@@ -709,8 +712,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
                        int *consumedcntp,
                        bool *self_referralp)
 {
-       struct connection_struct conns;
-       struct connection_struct *conn = &conns;
+       struct connection_struct *conn;
        char *targetpath = NULL;
        int snum;
        NTSTATUS status = NT_STATUS_NOT_FOUND;
@@ -721,7 +723,6 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       ZERO_STRUCT(conns);
        *self_referralp = False;
 
        status = parse_dfs_path(dfs_path, False, pdp, &dummy);
@@ -825,7 +826,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
                return NT_STATUS_OK;
        }
 
-       status = create_conn_struct(ctx, conn, snum, lp_pathname(snum));
+       status = create_conn_struct(ctx, &conn, snum, lp_pathname(snum));
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(pdp);
                return status;
@@ -1251,7 +1252,7 @@ bool create_junction(TALLOC_CTX *ctx,
 
 static bool junction_to_local_path(const struct junction_map *jucn,
                                char **pp_path_out,
-                               connection_struct *conn_out)
+                               connection_struct **conn_out)
 {
        int snum;
 
@@ -1265,7 +1266,7 @@ static bool junction_to_local_path(const struct junction_map *jucn,
                return False;
        }
 
-       *pp_path_out = talloc_asprintf(conn_out->mem_ctx,
+       *pp_path_out = talloc_asprintf(conn_out,
                        "%s/%s",
                        lp_pathname(snum),
                        jucn->volume_name);
@@ -1280,20 +1281,17 @@ bool create_msdfs_link(const struct junction_map *jucn,
 {
        char *path = NULL;
        char *msdfs_link = NULL;
-       connection_struct conns;
-       connection_struct *conn = &conns;
+       connection_struct *conn;
        int i=0;
        bool insert_comma = False;
        bool ret = False;
 
-       ZERO_STRUCT(conns);
-
-       if(!junction_to_local_path(jucn, &path, conn)) {
+       if(!junction_to_local_path(jucn, &path, &conn)) {
                return False;
        }
 
        /* Form the msdfs_link contents */
-       msdfs_link = talloc_strdup(conn->mem_ctx, "msdfs:");
+       msdfs_link = talloc_strdup(conn, "msdfs:");
        if (!msdfs_link) {
                goto out;
        }
@@ -1353,13 +1351,10 @@ out:
 bool remove_msdfs_link(const struct junction_map *jucn)
 {
        char *path = NULL;
-       connection_struct conns;
-       connection_struct *conn = &conns;
+       connection_struct *conn;
        bool ret = False;
 
-       ZERO_STRUCT(conns);
-
-       if( junction_to_local_path(jucn, &path, conn) ) {
+       if( junction_to_local_path(jucn, &path, &conn) ) {
                if( SMB_VFS_UNLINK(conn, path) == 0 ) {
                        ret = True;
                }
@@ -1380,9 +1375,7 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
        char *dname = NULL;
        const char *connect_path = lp_pathname(snum);
        const char *msdfs_proxy = lp_msdfs_proxy(snum);
-       connection_struct conn;
-
-       ZERO_STRUCT(conn);
+       connection_struct *conn;
 
        if(*connect_path == '\0') {
                return 0;
@@ -1406,24 +1399,24 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
        }
 
        /* Now enumerate all dfs links */
-       dirp = SMB_VFS_OPENDIR(&conn, ".", NULL, 0);
+       dirp = SMB_VFS_OPENDIR(conn, ".", NULL, 0);
        if(!dirp) {
                goto out;
        }
 
-       while ((dname = vfs_readdirname(&conn, dirp)) != NULL) {
-               if (is_msdfs_link(&conn,
+       while ((dname = vfs_readdirname(conn, dirp)) != NULL) {
+               if (is_msdfs_link(conn,
                                dname,
                                NULL)) {
                        cnt++;
                }
        }
 
-       SMB_VFS_CLOSEDIR(&conn,dirp);
+       SMB_VFS_CLOSEDIR(conn,dirp);
 
 out:
 
-       conn_free_internal(&conn);
+       conn_free_internal(conn);
        return cnt;
 }
 
@@ -1441,11 +1434,9 @@ static int form_junctions(TALLOC_CTX *ctx,
        const char *connect_path = lp_pathname(snum);
        char *service_name = lp_servicename(snum);
        const char *msdfs_proxy = lp_msdfs_proxy(snum);
-       connection_struct conn;
+       connection_struct *conn;
        struct referral *ref = NULL;
 
-       ZERO_STRUCT(conn);
-
        if (jn_remain == 0) {
                return 0;
        }
@@ -1501,21 +1492,21 @@ static int form_junctions(TALLOC_CTX *ctx,
        }
 
        /* Now enumerate all dfs links */
-       dirp = SMB_VFS_OPENDIR(&conn, ".", NULL, 0);
+       dirp = SMB_VFS_OPENDIR(conn, ".", NULL, 0);
        if(!dirp) {
                goto out;
        }
 
-       while ((dname = vfs_readdirname(&conn, dirp)) != NULL) {
+       while ((dname = vfs_readdirname(conn, dirp)) != NULL) {
                char *link_target = NULL;
                if (cnt >= jn_remain) {
-                       SMB_VFS_CLOSEDIR(&conn,dirp);
+                       SMB_VFS_CLOSEDIR(conn,dirp);
                        DEBUG(2, ("form_junctions: ran out of MSDFS "
                                "junction slots"));
                        goto out;
                }
                if (is_msdfs_link_internal(ctx,
-                                       &conn,
+                                       conn,
                                        dname, &link_target,
                                        NULL)) {
                        if (parse_msdfs_symlink(ctx,
@@ -1539,10 +1530,10 @@ static int form_junctions(TALLOC_CTX *ctx,
 out:
 
        if (dirp) {
-               SMB_VFS_CLOSEDIR(&conn,dirp);
+               SMB_VFS_CLOSEDIR(conn,dirp);
        }
 
-       conn_free_internal(&conn);
+       conn_free_internal(conn);
        return cnt;
 }
 
index ae7bd8b7b722a095d565ccd13b621a1e4a8723a1..ec4126c1f74bfaa0ef6e97a98a0f72cf0366bb6a 100644 (file)
@@ -2595,7 +2595,7 @@ void reply_nttrans(struct smb_request *req)
                return;
        }
 
-       if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
+       if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
                reply_doserror(req, ERRSRV, ERRaccess);
                END_PROFILE(SMBnttrans);
                return;
index 732199e0e9ea7771683f664b586fd3e4abdccbb2..33042faf56dcee04c5f1fe5147583ef8df0651b4 100644 (file)
@@ -4262,30 +4262,29 @@ bool set_unix_posix_acl(connection_struct *conn, files_struct *fsp, const char *
 SEC_DESC *get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname)
 {
        SEC_DESC *psd, *ret_sd;
-       connection_struct conn;
+       connection_struct *conn;
        files_struct finfo;
        struct fd_handle fh;
 
-       ZERO_STRUCT( conn );
-
-       if ( !(conn.mem_ctx = talloc_init( "novfs_get_nt_acl" )) ) {
-               DEBUG(0,("get_nt_acl_no_snum: talloc() failed!\n"));
+       conn = TALLOC_ZERO_P(ctx, connection_struct);
+       if (conn == NULL) {
+               DEBUG(0, ("talloc failed\n"));
                return NULL;
        }
 
-       if (!(conn.params = TALLOC_P(conn.mem_ctx, struct share_params))) {
+       if (!(conn->params = TALLOC_P(conn, struct share_params))) {
                DEBUG(0,("get_nt_acl_no_snum: talloc() failed!\n"));
-               TALLOC_FREE(conn.mem_ctx);
+               TALLOC_FREE(conn);
                return NULL;
        }
 
-       conn.params->service = -1;
+       conn->params->service = -1;
 
-       set_conn_connectpath(&conn, "/");
+       set_conn_connectpath(conn, "/");
 
-       if (!smbd_vfs_init(&conn)) {
+       if (!smbd_vfs_init(conn)) {
                DEBUG(0,("get_nt_acl_no_snum: Unable to create a fake connection struct!\n"));
-               conn_free_internal( &conn );
+               conn_free_internal( conn );
                return NULL;
         }
 
@@ -4293,20 +4292,20 @@ SEC_DESC *get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname)
        ZERO_STRUCT( fh );
 
        finfo.fnum = -1;
-       finfo.conn = &conn;
+       finfo.conn = conn;
        finfo.fh = &fh;
        finfo.fh->fd = -1;
        finfo.fsp_name = CONST_DISCARD(char *,fname);
 
        if (!NT_STATUS_IS_OK(posix_fget_nt_acl( &finfo, DACL_SECURITY_INFORMATION, &psd))) {
                DEBUG(0,("get_nt_acl_no_snum: get_nt_acl returned zero.\n"));
-               conn_free_internal( &conn );
+               conn_free_internal( conn );
                return NULL;
        }
 
        ret_sd = dup_sec_desc( ctx, psd );
 
-       conn_free_internal( &conn );
+       conn_free_internal( conn );
 
        return ret_sd;
 }
index 33b2cb26c1a6b58e40b7304a7c656c099209d454..a405ffc9bcccc219770d48005cb929aadab034d9 100644 (file)
@@ -529,12 +529,12 @@ static NTSTATUS find_forced_user(connection_struct *conn, bool vuser_is_guest, f
        char *fuser, *found_username;
        NTSTATUS result;
 
-       if (!(fuser = talloc_string_sub(conn->mem_ctx, lp_force_user(snum), "%S",
+       if (!(fuser = talloc_string_sub(conn, lp_force_user(snum), "%S",
                                        lp_servicename(snum)))) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       result = create_token_from_username(conn->mem_ctx, fuser, vuser_is_guest,
+       result = create_token_from_username(conn, fuser, vuser_is_guest,
                                            &conn->uid, &conn->gid, &found_username,
                                            &conn->nt_user_token);
        if (!NT_STATUS_IS_OK(result)) {
@@ -697,7 +697,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        *status = NT_STATUS_NO_SUCH_USER;
                        return NULL;
                }
-               status2 = create_token_from_username(conn->mem_ctx, pass->pw_name, True,
+               status2 = create_token_from_username(conn, pass->pw_name, True,
                                                     &conn->uid, &conn->gid,
                                                     &found_username,
                                                     &conn->nt_user_token);
@@ -757,7 +757,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                        return NULL;
                }
                pass = Get_Pwnam_alloc(talloc_tos(), user);
-               status2 = create_token_from_username(conn->mem_ctx, pass->pw_name, True,
+               status2 = create_token_from_username(conn, pass->pw_name, True,
                                                     &conn->uid, &conn->gid,
                                                     &found_username,
                                                     &conn->nt_user_token);
@@ -903,7 +903,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                                           sid_string_dbg(sid)));
                                continue;
                        }
-                       if (!add_gid_to_array_unique(conn->mem_ctx, gid, &conn->groups,
+                       if (!add_gid_to_array_unique(conn, gid, &conn->groups,
                                                &conn->ngroups)) {
                                DEBUG(0, ("add_gid_to_array_unique failed\n"));
                                conn_free(conn);
@@ -1017,7 +1017,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        }
 
        if ((!conn->printer) && (!conn->ipc)) {
-               conn->notify_ctx = notify_init(conn->mem_ctx, server_id_self(),
+               conn->notify_ctx = notify_init(conn, server_id_self(),
                                               smbd_messaging_context(),
                                               smbd_event_context(),
                                               conn);
index e7157d02ecc8b42a5b0dfec6ab0018bd17097a5f..4d60eecda9ec3f24445401845e9ccccf9884c013 100644 (file)
@@ -7542,7 +7542,7 @@ void reply_trans2(struct smb_request *req)
                }
        }
 
-       if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
+       if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
                DEBUG(0, ("talloc failed\n"));
                reply_nterror(req, NT_STATUS_NO_MEMORY);
                END_PROFILE(SMBtrans2);
index 33a3a43aa474a9a76d6e9a18e5d3ba1db2bd23f5..1e137dd9089160616d022f9e435486a87cc6b899 100644 (file)
@@ -177,7 +177,7 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
                goto fail;
        }
 
-       handle = TALLOC_ZERO_P(conn->mem_ctx,vfs_handle_struct);
+       handle = TALLOC_ZERO_P(connvfs_handle_struct);
        if (!handle) {
                DEBUG(0,("TALLOC_ZERO() failed!\n"));
                goto fail;
@@ -185,7 +185,7 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
        memcpy(&handle->vfs_next, &conn->vfs, sizeof(struct vfs_ops));
        handle->conn = conn;
        if (module_param) {
-               handle->param = talloc_strdup(conn->mem_ctx, module_param);
+               handle->param = talloc_strdup(conn, module_param);
        }
        DLIST_ADD(conn->vfs_handles, handle);
 
@@ -232,7 +232,7 @@ void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle, files_struct *fsp,
        }
 
        ext = (struct vfs_fsp_data *)TALLOC_ZERO(
-               handle->conn->mem_ctx, sizeof(struct vfs_fsp_data) + ext_size);
+               handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
        if (ext == NULL) {
                return NULL;
        }