From d62563342e8c83d67dbcfb0c4b8e2ed886742006 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 28 Apr 2008 10:31:49 +0200 Subject: [PATCH] Remove connection_struct->mem_ctx, connection_struct is its own parent (This used to be commit 559180f7d30606d1999399d954ceedc798c669a4) --- source3/include/smb.h | 1 - source3/modules/vfs_fileid.c | 2 +- source3/smbd/conn.c | 17 ++------ source3/smbd/dfree.c | 2 +- source3/smbd/ipc.c | 2 +- source3/smbd/msdfs.c | 81 ++++++++++++++++-------------------- source3/smbd/nttrans.c | 2 +- source3/smbd/posix_acls.c | 27 ++++++------ source3/smbd/service.c | 12 +++--- source3/smbd/trans2.c | 2 +- source3/smbd/vfs.c | 6 +-- 11 files changed, 67 insertions(+), 87 deletions(-) diff --git a/source3/include/smb.h b/source3/include/smb.h index ce91d81c2d1..f3295e12bd4 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -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; diff --git a/source3/modules/vfs_fileid.c b/source3/modules/vfs_fileid.c index 5954a10ddb7..1cbd857a357 100644 --- a/source3/modules/vfs_fileid.c +++ b/source3/modules/vfs_fileid.c @@ -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; diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c index 5aedadc56b0..af18e905c08 100644 --- a/source3/smbd/conn.c +++ b/source3/smbd/conn.c @@ -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); } /**************************************************************************** diff --git a/source3/smbd/dfree.c b/source3/smbd/dfree.c index 9e7f18a1308..1ddcd48d404 100644 --- a/source3/smbd/dfree.c +++ b/source3/smbd/dfree.c @@ -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; } diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c index 6961a5caf15..59a5dfdd3f3 100644 --- a/source3/smbd/ipc.c +++ b/source3/smbd/ipc.c @@ -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); diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index fb757a5f746..14062e129d1 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -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; } diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index ae7bd8b7b72..ec4126c1f74 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -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; diff --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c index 732199e0e9e..33042faf56d 100644 --- a/source3/smbd/posix_acls.c +++ b/source3/smbd/posix_acls.c @@ -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; } diff --git a/source3/smbd/service.c b/source3/smbd/service.c index 33b2cb26c1a..a405ffc9bcc 100644 --- a/source3/smbd/service.c +++ b/source3/smbd/service.c @@ -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); diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index e7157d02ecc..4d60eecda9e 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -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); diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 33a3a43aa47..1e137dd9089 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -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(conn, vfs_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; } -- 2.34.1