From 9ef33f5f5c786b83311ca088357fb2f0aa72fc9e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 May 2006 08:15:22 +0000 Subject: r15734: This is a major change to the NTVFS subsystem: - to use a struct ntvfs_handle instead of a uint16_t fnum. (to make it independend from the frontend protocol) - the allocation of handles now is provided by the frontend (smbsrv_*) via callbacks and not by each backend module - this also makes sure that file handles are only passed to the ntvfs subsystem when the tcon and session matches, so modules can rely on this and need to check this. - this allows multiple modules in the ntvfs module chain to allocate file handles. This can be used for virtual files like "\\$Extend\\$Quota:$Q:$INDEX_ALLOCATION"... - also this will make SMB2 with 128 bit file handles possible metze (This used to be commit 287fc1c22d670f6e568014b420f7f4cb31dc7958) --- source4/smb_server/handle.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 source4/smb_server/handle.c (limited to 'source4/smb_server/handle.c') diff --git a/source4/smb_server/handle.c b/source4/smb_server/handle.c new file mode 100644 index 0000000000..c2fea9e91c --- /dev/null +++ b/source4/smb_server/handle.c @@ -0,0 +1,137 @@ +/* + Unix SMB/CIFS implementation. + Manage smbsrv_handle structures + Copyright (C) Stefan Metzmacher 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "dlinklist.h" +#include "smb_server/smb_server.h" +#include "ntvfs/ntvfs.h" + + +/**************************************************************************** +init the handle structures +****************************************************************************/ +NTSTATUS smbsrv_init_handles(struct smbsrv_tcon *tcon, uint64_t limit) +{ + /* + * the idr_* functions take 'int' as limit, + * and only work with a max limit 0x00FFFFFF + */ + limit &= 0x00FFFFFF; + + tcon->handles.idtree_hid = idr_init(tcon); + NT_STATUS_HAVE_NO_MEMORY(tcon->handles.idtree_hid); + tcon->handles.idtree_limit = limit; + tcon->handles.list = NULL; + + return NT_STATUS_OK; +} + +/**************************************************************************** +find a handle given a handle id +****************************************************************************/ +static struct smbsrv_handle *smbsrv_handle_find(struct smbsrv_handles_context *handles_ctx, + uint64_t hid, struct timeval request_time) +{ + void *p; + struct smbsrv_handle *handle; + + if (hid == 0) return NULL; + + if (hid > handles_ctx->idtree_limit) return NULL; + + p = idr_find(handles_ctx->idtree_hid, hid); + if (!p) return NULL; + + handle = talloc_get_type(p, struct smbsrv_handle); + if (!handle) return NULL; + + /* only give it away when the ntvfs subsystem has made the handle valid */ + if (!handle->ntvfs) return NULL; + + handle->statistics.last_use_time = request_time; + + return handle; +} + +struct smbsrv_handle *smbsrv_smb_handle_find(struct smbsrv_tcon *smb_tcon, + uint16_t fnum, struct timeval request_time) +{ + return smbsrv_handle_find(&smb_tcon->handles, fnum, request_time); +} + +/* + destroy a connection structure +*/ +static int smbsrv_handle_destructor(void *ptr) +{ + struct smbsrv_handle *handle = talloc_get_type(ptr, struct smbsrv_handle); + struct smbsrv_handles_context *handles_ctx; + + handles_ctx = &handle->tcon->handles; + + idr_remove(handles_ctx->idtree_hid, handle->hid); + DLIST_REMOVE(handles_ctx->list, handle); + DLIST_REMOVE(handle->session->handles, &handle->session_item); + + /* tell the ntvfs backend that we are disconnecting */ + if (handle->ntvfs) { + talloc_free(handle->ntvfs); + handle->ntvfs = NULL; + } + + return 0; +} + +/* + find first available handle slot +*/ +struct smbsrv_handle *smbsrv_handle_new(struct smbsrv_request *req) +{ + struct smbsrv_handles_context *handles_ctx = &req->tcon->handles; + struct smbsrv_handle *handle; + int i; + + handle = talloc_zero(req, struct smbsrv_handle); + if (!handle) return NULL; + handle->tcon = req->tcon; + handle->session = req->session; + + i = idr_get_new_above(handles_ctx->idtree_hid, handle, 1, handles_ctx->idtree_limit); + if (i == -1) { + DEBUG(1,("ERROR! Out of handle structures\n")); + goto failed; + } + handle->hid = i; + handle->session_item.handle = handle; + + DLIST_ADD(handles_ctx->list, handle); + DLIST_ADD(handle->session->handles, &handle->session_item); + talloc_set_destructor(handle, smbsrv_handle_destructor); + + /* now fill in some statistics */ + handle->statistics.open_time = req->request_time; + handle->statistics.last_use_time = req->request_time; + + return handle; + +failed: + talloc_free(handle); + return NULL; +} -- cgit From 3cb64219e2cd492d25931f5442cbd484d6930950 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 May 2006 16:48:29 +0000 Subject: r15751: thanks to talloc_get_type() I noticed that I used smbsrv_request in the smb2srv code metze (This used to be commit 6c304a1a5f5dc6b2d3774682303874444a59b07d) --- source4/smb_server/handle.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'source4/smb_server/handle.c') diff --git a/source4/smb_server/handle.c b/source4/smb_server/handle.c index c2fea9e91c..07b49bf79d 100644 --- a/source4/smb_server/handle.c +++ b/source4/smb_server/handle.c @@ -76,6 +76,12 @@ struct smbsrv_handle *smbsrv_smb_handle_find(struct smbsrv_tcon *smb_tcon, return smbsrv_handle_find(&smb_tcon->handles, fnum, request_time); } +struct smbsrv_handle *smbsrv_smb2_handle_find(struct smbsrv_tcon *smb_tcon, + uint64_t hid, struct timeval request_time) +{ + return smbsrv_handle_find(&smb_tcon->handles, hid, request_time); +} + /* destroy a connection structure */ @@ -102,16 +108,19 @@ static int smbsrv_handle_destructor(void *ptr) /* find first available handle slot */ -struct smbsrv_handle *smbsrv_handle_new(struct smbsrv_request *req) +struct smbsrv_handle *smbsrv_handle_new(struct smbsrv_session *session, + struct smbsrv_tcon *tcon, + TALLOC_CTX *mem_ctx, + struct timeval request_time) { - struct smbsrv_handles_context *handles_ctx = &req->tcon->handles; + struct smbsrv_handles_context *handles_ctx = &tcon->handles; struct smbsrv_handle *handle; int i; - handle = talloc_zero(req, struct smbsrv_handle); + handle = talloc_zero(mem_ctx, struct smbsrv_handle); if (!handle) return NULL; - handle->tcon = req->tcon; - handle->session = req->session; + handle->tcon = tcon; + handle->session = session; i = idr_get_new_above(handles_ctx->idtree_hid, handle, 1, handles_ctx->idtree_limit); if (i == -1) { @@ -122,12 +131,12 @@ struct smbsrv_handle *smbsrv_handle_new(struct smbsrv_request *req) handle->session_item.handle = handle; DLIST_ADD(handles_ctx->list, handle); - DLIST_ADD(handle->session->handles, &handle->session_item); + DLIST_ADD(session->handles, &handle->session_item); talloc_set_destructor(handle, smbsrv_handle_destructor); /* now fill in some statistics */ - handle->statistics.open_time = req->request_time; - handle->statistics.last_use_time = req->request_time; + handle->statistics.open_time = request_time; + handle->statistics.last_use_time = request_time; return handle; -- cgit From 92acfc07998da1546182579ad12a063f025c9286 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2006 07:35:06 +0000 Subject: r15855: more talloc_set_destructor() typesafe fixes. nearly done ... (This used to be commit 396d82a231b6e3a91178db08b706626d4d4b420c) --- source4/smb_server/handle.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/smb_server/handle.c') diff --git a/source4/smb_server/handle.c b/source4/smb_server/handle.c index 07b49bf79d..ebeecac603 100644 --- a/source4/smb_server/handle.c +++ b/source4/smb_server/handle.c @@ -85,9 +85,8 @@ struct smbsrv_handle *smbsrv_smb2_handle_find(struct smbsrv_tcon *smb_tcon, /* destroy a connection structure */ -static int smbsrv_handle_destructor(void *ptr) +static int smbsrv_handle_destructor(struct smbsrv_handle *handle) { - struct smbsrv_handle *handle = talloc_get_type(ptr, struct smbsrv_handle); struct smbsrv_handles_context *handles_ctx; handles_ctx = &handle->tcon->handles; -- cgit From 0329d755a7611ba3897fc1ee9bdce410cc33d7f8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Aug 2006 11:29:34 +0000 Subject: r17930: Merge noinclude branch: * Move dlinklist.h, smb.h to subsystem-specific directories * Clean up ads.h and move what is left of it to dsdb/ (only place where it's used) (This used to be commit f7afa1cb77f3cfa7020b57de12e6003db7cfcc42) --- source4/smb_server/handle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/smb_server/handle.c') diff --git a/source4/smb_server/handle.c b/source4/smb_server/handle.c index ebeecac603..87575896bd 100644 --- a/source4/smb_server/handle.c +++ b/source4/smb_server/handle.c @@ -19,7 +19,7 @@ */ #include "includes.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" #include "smb_server/smb_server.h" #include "ntvfs/ntvfs.h" -- cgit From 10498e8a720d047ca3a013abbc9e406c630ab30a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 21 May 2007 17:23:56 +0000 Subject: r23044: - use uint32_t for handle id's - include the session vuid in the SMB2 128-Bit wire handles as SMB2 oplock breaks doesn't include a TID or VUID in the header we need to make sure the handle is unique for the whole TCP connection metze (This used to be commit 7c29b8a7e67c48478399788912b22c287fbd3b4e) --- source4/smb_server/handle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/smb_server/handle.c') diff --git a/source4/smb_server/handle.c b/source4/smb_server/handle.c index 87575896bd..5b3b925e1b 100644 --- a/source4/smb_server/handle.c +++ b/source4/smb_server/handle.c @@ -27,7 +27,7 @@ /**************************************************************************** init the handle structures ****************************************************************************/ -NTSTATUS smbsrv_init_handles(struct smbsrv_tcon *tcon, uint64_t limit) +NTSTATUS smbsrv_init_handles(struct smbsrv_tcon *tcon, uint32_t limit) { /* * the idr_* functions take 'int' as limit, @@ -47,7 +47,7 @@ NTSTATUS smbsrv_init_handles(struct smbsrv_tcon *tcon, uint64_t limit) find a handle given a handle id ****************************************************************************/ static struct smbsrv_handle *smbsrv_handle_find(struct smbsrv_handles_context *handles_ctx, - uint64_t hid, struct timeval request_time) + uint32_t hid, struct timeval request_time) { void *p; struct smbsrv_handle *handle; @@ -77,7 +77,7 @@ struct smbsrv_handle *smbsrv_smb_handle_find(struct smbsrv_tcon *smb_tcon, } struct smbsrv_handle *smbsrv_smb2_handle_find(struct smbsrv_tcon *smb_tcon, - uint64_t hid, struct timeval request_time) + uint32_t hid, struct timeval request_time) { return smbsrv_handle_find(&smb_tcon->handles, hid, request_time); } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/smb_server/handle.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/smb_server/handle.c') diff --git a/source4/smb_server/handle.c b/source4/smb_server/handle.c index 5b3b925e1b..56f9c5825e 100644 --- a/source4/smb_server/handle.c +++ b/source4/smb_server/handle.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit