From 26ecaa32266e0c8699f280dd190811c310f2939c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 3 Feb 2004 05:47:36 +0000 Subject: - move all SMB server stuff to smb_server/* and create the SMB server subsystem - remove unused XML and MYSQL configure tests metze (This used to be commit 956d212c83d8ebd8e31ec109f17dc2105ca72c30) --- source4/smb_server/session.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 source4/smb_server/session.c (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c new file mode 100644 index 0000000000..7f85fca2ac --- /dev/null +++ b/source4/smb_server/session.c @@ -0,0 +1,42 @@ +/* + Unix SMB/CIFS implementation. + session handling for utmp and PAM + Copyright (C) tridge@samba.org 2001 + Copyright (C) abartlet@pcug.org.au 2001 + + 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. +*/ + +/* a "session" is claimed when we do a SessionSetupX operation + and is yielded when the corresponding vuid is destroyed. + + sessions are used to populate utmp and PAM session structures +*/ + +#include "includes.h" + +/* called when a session is created */ +BOOL session_claim(struct server_context *smb, user_struct *vuser) +{ + DEBUG(0,("rewrite: Not doing session claim\n")); + return True; +} + +/* called when a session is destroyed */ +void session_yield(user_struct *vuser) +{ + DEBUG(0,("rewrite: Not doing session yield\n")); +} + -- cgit From d4ae6ae74d712b74800e360590052d318d2fd101 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 28 Jun 2004 07:41:15 +0000 Subject: r1277: rename struct server_context to smbsrv_ontext because I need server_context fot the generic server infastructure metze (This used to be commit 0712f9f30797e65362c99423c0cf158a2f539000) --- source4/smb_server/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 7f85fca2ac..dc131b366c 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -28,7 +28,7 @@ #include "includes.h" /* called when a session is created */ -BOOL session_claim(struct server_context *smb, user_struct *vuser) +BOOL session_claim(struct smbsrv_context *smb_ctx, user_struct *vuser) { DEBUG(0,("rewrite: Not doing session claim\n")); return True; -- cgit From 118f3edd27f5adacc1da636ed05b33f04999584f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 29 Jun 2004 07:40:14 +0000 Subject: r1291: rename struct smbsrv_context to smbsrv_connection because this is the connection state per transport layer (tcp) connection I also moved the substructs directly into smbsrv_connection, because they don't need a struct name and we should allway pass the complete smbsrv_connection struct into functions metze (This used to be commit 60f823f201fcedf5473008e8453a6351e73a92c7) --- source4/smb_server/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index dc131b366c..8df12faff9 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -28,7 +28,7 @@ #include "includes.h" /* called when a session is created */ -BOOL session_claim(struct smbsrv_context *smb_ctx, user_struct *vuser) +BOOL session_claim(struct smbsrv_connection *smb_ctx, user_struct *vuser) { DEBUG(0,("rewrite: Not doing session claim\n")); return True; -- cgit From 5779a7da9aecb7329eb47e93000dc8b9de96d9ae Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 14 Jul 2004 12:44:31 +0000 Subject: r1499: combine struct user_struct and struct smbsrv_user to a struct smbsrv_session that the same as cli_session for the client we need a gensec_security pointer there (spnego support will follow) prefix some related functions with smbsrv_ metze (This used to be commit f276378157bb9994c4c91ce46150a510de5c33f8) --- source4/smb_server/session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 8df12faff9..1567484a49 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -28,14 +28,14 @@ #include "includes.h" /* called when a session is created */ -BOOL session_claim(struct smbsrv_connection *smb_ctx, user_struct *vuser) +BOOL session_claim(struct smbsrv_session *sess) { DEBUG(0,("rewrite: Not doing session claim\n")); return True; } /* called when a session is destroyed */ -void session_yield(user_struct *vuser) +void session_yield(struct smbsrv_session *sess) { DEBUG(0,("rewrite: Not doing session yield\n")); } -- cgit From 79c9d6db55a72d630caa296691ea5ad54b30fc4c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 26 Oct 2004 09:32:11 +0000 Subject: r3256: get rid of the unused session_claim() and session_yield() calls (This used to be commit f1c5be396b62203fb183431ea6218eed38976d0b) --- source4/smb_server/session.c | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 1567484a49..876702aa1c 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -27,16 +27,3 @@ #include "includes.h" -/* called when a session is created */ -BOOL session_claim(struct smbsrv_session *sess) -{ - DEBUG(0,("rewrite: Not doing session claim\n")); - return True; -} - -/* called when a session is destroyed */ -void session_yield(struct smbsrv_session *sess) -{ - DEBUG(0,("rewrite: Not doing session yield\n")); -} - -- cgit From b1dba5e7fbe50ffe9504ddc9fb2125a3d5cb237b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 12 Apr 2005 05:21:38 +0000 Subject: r6309: Remove this file it is empty and unreferenced. (In preperation for renaming password.c over the top, as it deals with sessions, not passwords). Andrew Bartlett (This used to be commit 0bba8da460f77946ba9ee5db58ae2329e9e57e1a) --- source4/smb_server/session.c | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 source4/smb_server/session.c (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c deleted file mode 100644 index 876702aa1c..0000000000 --- a/source4/smb_server/session.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - Unix SMB/CIFS implementation. - session handling for utmp and PAM - Copyright (C) tridge@samba.org 2001 - Copyright (C) abartlet@pcug.org.au 2001 - - 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. -*/ - -/* a "session" is claimed when we do a SessionSetupX operation - and is yielded when the corresponding vuid is destroyed. - - sessions are used to populate utmp and PAM session structures -*/ - -#include "includes.h" - -- cgit From f3e3f3aab6a2a117966893ef3264443bdb20f186 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 12 Apr 2005 05:36:28 +0000 Subject: r6310: Rename password.c to session.c, and remove the linked list of all outstanding sessions, as we don't use it. Andrew Bartlett (This used to be commit 0cbd11a0f2448f2021fa1d8ad85a0a6f52192ee8) --- source4/smb_server/session.c | 139 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 source4/smb_server/session.c (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c new file mode 100644 index 0000000000..5de30f423a --- /dev/null +++ b/source4/smb_server/session.c @@ -0,0 +1,139 @@ +/* + Unix SMB/CIFS implementation. + Password and authentication handling + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Andrew Bartlett 2005 + + 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" + + +/**************************************************************************** +init the tcon structures +****************************************************************************/ +void smbsrv_vuid_init(struct smbsrv_connection *smb_conn) +{ + smb_conn->sessions.idtree_vuid = idr_init(smb_conn); +} + + +/**************************************************************************** +Find the session structure assoicated with a VUID (not one from an in-progress session setup) +****************************************************************************/ +struct smbsrv_session *smbsrv_session_find(struct smbsrv_connection *smb_conn, uint16_t vuid) +{ + struct smbsrv_session *sess = idr_find(smb_conn->sessions.idtree_vuid, vuid); + if (sess && sess->finished_sesssetup) { + return sess; + } + return NULL; +} + +/**************************************************************************** + Find a VUID assoicated with an in-progress session setup +****************************************************************************/ +struct smbsrv_session *smbsrv_session_find_sesssetup(struct smbsrv_connection *smb_conn, uint16_t vuid) +{ + struct smbsrv_session *sess = idr_find(smb_conn->sessions.idtree_vuid, vuid); + if (sess && !sess->finished_sesssetup) { + return sess; + } + return NULL; +} + +/**************************************************************************** +invalidate a session +****************************************************************************/ +static int smbsrv_session_destructor(void *p) +{ + struct smbsrv_session *sess = p; + struct smbsrv_connection *smb_conn = sess->smb_conn; + + /* clear the vuid from the 'cache' on each connection, and + from the vuid 'owner' of connections */ + /* REWRITE: conn_clear_vuid_cache(smb, vuid); */ + + smb_conn->sessions.num_validated_vuids--; + + idr_remove(smb_conn->sessions.idtree_vuid, sess->vuid); + return 0; +} + +/**************************************************************************** +invalidate a uid +****************************************************************************/ +void smbsrv_invalidate_vuid(struct smbsrv_connection *smb_conn, uint16_t vuid) +{ + struct smbsrv_session *sess = smbsrv_session_find(smb_conn, vuid); + talloc_free(sess); +} + +/** + * register that a valid login has been performed, establish 'session'. + * @param session_info The token returned from the authentication process (if the authentication has completed) + * (now 'owned' by register_vuid) + * + * @param smb_name The untranslated name of the user + * + * @return Newly allocated vuid, biased by an offset. (This allows us to + * tell random client vuid's (normally zero) from valid vuids.) + * + */ + +struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_conn, + struct auth_session_info *session_info, + struct gensec_security *gensec_ctx) +{ + struct smbsrv_session *sess = NULL; + int i; + + /* Ensure no vuid gets registered in share level security. */ + /* TODO: replace lp_security with a flag in smbsrv_connection */ + if (lp_security() == SEC_SHARE) + return UID_FIELD_INVALID; + + sess = talloc(smb_conn, struct smbsrv_session); + if (sess == NULL) { + DEBUG(0,("talloc(smb_conn->mem_ctx, struct smbsrv_session) failed\n")); + return sess; + } + + ZERO_STRUCTP(sess); + + i = idr_get_new_above(smb_conn->sessions.idtree_vuid, sess, VUID_OFFSET, UINT16_MAX); + if (i == -1) { + DEBUG(1,("ERROR! Out of connection structures\n")); + talloc_free(sess); + return NULL; + } + sess->vuid = i; + + smb_conn->sessions.num_validated_vuids++; + + /* use this to keep tabs on all our info from the authentication */ + sess->session_info = talloc_reference(sess, session_info); + + sess->gensec_ctx = talloc_reference(sess, gensec_ctx); + + sess->smb_conn = smb_conn; + + talloc_set_destructor(sess, smbsrv_session_destructor); + + return sess; +} -- cgit From ab06749443dacb47cc98233f29cb5e17f277b6a6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 12 Apr 2005 06:51:36 +0000 Subject: r6312: Metze reminds me this header is no longer required. Andrew Bartlett (This used to be commit c67a9370c4e8f94aad68abba073779bb0edf742b) --- source4/smb_server/session.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 5de30f423a..bc2ac5fcb7 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -20,7 +20,6 @@ */ #include "includes.h" -#include "dlinklist.h" #include "smb_server/smb_server.h" -- cgit From 8047db6e4b9cbaccb8a21b8947f6d04a7ca3c436 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 17 Jun 2005 06:36:13 +0000 Subject: r7676: Make VUID and TID choice random, as this gives us protection against replay attacks under SMB signing, where the session key is a fixed derivitive of the user's password. This removes the VID offset, but I'm not worried about random client bytes mattering here, given the space (and the fact that it applies to very, very old clients). Andrew Bartlett (This used to be commit eb1d37c5a91a6bc4515469e1ae026d28c12d7149) --- source4/smb_server/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index bc2ac5fcb7..d7b7f22cd8 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -115,7 +115,7 @@ struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_con ZERO_STRUCTP(sess); - i = idr_get_new_above(smb_conn->sessions.idtree_vuid, sess, VUID_OFFSET, UINT16_MAX); + i = idr_get_new_random(smb_conn->sessions.idtree_vuid, sess, UINT16_MAX); if (i == -1) { DEBUG(1,("ERROR! Out of connection structures\n")); talloc_free(sess); -- cgit From 25428433e3e279491f0b6f73e2489140517ae454 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Jul 2005 03:58:44 +0000 Subject: r8574: added server side irpc calls for listing the current sessions (This used to be commit 391cfe3c9645a19f8f5ff5c11b1ac03ee0b10f8f) --- source4/smb_server/session.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index d7b7f22cd8..0bee536b93 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. Password and authentication handling - Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Andrew Tridgell 1992-2005 Copyright (C) Andrew Bartlett 2005 This program is free software; you can redistribute it and/or modify @@ -21,6 +21,7 @@ #include "includes.h" #include "smb_server/smb_server.h" +#include "dlinklist.h" /**************************************************************************** @@ -61,7 +62,7 @@ invalidate a session ****************************************************************************/ static int smbsrv_session_destructor(void *p) { - struct smbsrv_session *sess = p; + struct smbsrv_session *sess = talloc_get_type(p, struct smbsrv_session); struct smbsrv_connection *smb_conn = sess->smb_conn; /* clear the vuid from the 'cache' on each connection, and @@ -71,6 +72,8 @@ static int smbsrv_session_destructor(void *p) smb_conn->sessions.num_validated_vuids--; idr_remove(smb_conn->sessions.idtree_vuid, sess->vuid); + + DLIST_REMOVE(smb_conn->sessions.list, sess); return 0; } @@ -129,8 +132,10 @@ struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_con sess->session_info = talloc_reference(sess, session_info); sess->gensec_ctx = talloc_reference(sess, gensec_ctx); - sess->smb_conn = smb_conn; + sess->connect_time = timeval_current(); + + DLIST_ADD(smb_conn->sessions.list, sess); talloc_set_destructor(sess, smbsrv_session_destructor); -- cgit From 58bf4b160eb292bb40c79f65e4bc6a6f244577b9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 17 Nov 2005 12:52:40 +0000 Subject: r11759: fix up the SEC_SHARE handling, when we want to support that later we need to fake a smbsrv_session for each smbsrv_tcon... metze (This used to be commit 5b5fb1772034fbfebbb7174df235c8c11d4819fe) --- source4/smb_server/session.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 0bee536b93..50bea16ee2 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -106,9 +106,7 @@ struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_con int i; /* Ensure no vuid gets registered in share level security. */ - /* TODO: replace lp_security with a flag in smbsrv_connection */ - if (lp_security() == SEC_SHARE) - return UID_FIELD_INVALID; + if (smb_conn->config.security == SEC_SHARE) return NULL; sess = talloc(smb_conn, struct smbsrv_session); if (sess == NULL) { @@ -120,7 +118,7 @@ struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_con i = idr_get_new_random(smb_conn->sessions.idtree_vuid, sess, UINT16_MAX); if (i == -1) { - DEBUG(1,("ERROR! Out of connection structures\n")); + DEBUG(1,("ERROR! Out of connection structures\n")); talloc_free(sess); return NULL; } -- cgit From 799724aae7f431ef721b15745a89f01b12b10d9c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 18 Nov 2005 08:44:36 +0000 Subject: r11774: - move SMB specific initialisation of the smbsrv_connection out of smb_server.c - add a generic incoming packet handler, which handles the first incoming packet and passes to the protocol specifc packet handler metze (This used to be commit f89deac1cb8a7e5651116d96b9a94d5cc8293076) --- source4/smb_server/session.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 50bea16ee2..ba141f96ec 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -25,14 +25,15 @@ /**************************************************************************** -init the tcon structures +init the session structures ****************************************************************************/ -void smbsrv_vuid_init(struct smbsrv_connection *smb_conn) +NTSTATUS smbsrv_init_sessions(struct smbsrv_connection *smb_conn) { smb_conn->sessions.idtree_vuid = idr_init(smb_conn); + NT_STATUS_HAVE_NO_MEMORY(smb_conn->sessions.idtree_vuid); + return NT_STATUS_OK; } - /**************************************************************************** Find the session structure assoicated with a VUID (not one from an in-progress session setup) ****************************************************************************/ -- cgit From ab33c314a489ab0571de3cb93d1de749e3459e3a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 18 Nov 2005 12:57:48 +0000 Subject: r11783: - make the VIUD field in smbsrv_session 64bit, as SMB2 needs it - add an idtree_limit to limit the max VUID we give the clients it's UINT16_MAX (0xffff) for the SMB protocol - add auth_time to the smbsrv_session statistics - use the session_info as marker for finished and non-finished session setups metze (This used to be commit 7eb10048b2c4e5ee9c39750dc877514ed9235a76) --- source4/smb_server/session.c | 155 +++++++++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 65 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index ba141f96ec..967c02bfc9 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -24,84 +24,117 @@ #include "dlinklist.h" -/**************************************************************************** -init the session structures -****************************************************************************/ -NTSTATUS smbsrv_init_sessions(struct smbsrv_connection *smb_conn) +/* + * init the sessions structures + */ +NTSTATUS smbsrv_init_sessions(struct smbsrv_connection *smb_conn, uint64_t limit) { - smb_conn->sessions.idtree_vuid = idr_init(smb_conn); + /* + * the idr_* functions take 'int' as limit, + * and only work with a max limit 0x00FFFFFF + */ + limit &= 0x00FFFFFF; + + smb_conn->sessions.idtree_vuid = idr_init(smb_conn); NT_STATUS_HAVE_NO_MEMORY(smb_conn->sessions.idtree_vuid); + smb_conn->sessions.idtree_limit = limit; + smb_conn->sessions.list = NULL; + return NT_STATUS_OK; } -/**************************************************************************** -Find the session structure assoicated with a VUID (not one from an in-progress session setup) -****************************************************************************/ -struct smbsrv_session *smbsrv_session_find(struct smbsrv_connection *smb_conn, uint16_t vuid) +/* + * Find the session structure assoicated with a VUID + * (not one from an in-progress session setup) + */ +struct smbsrv_session *smbsrv_session_find(struct smbsrv_connection *smb_conn, uint64_t vuid) { - struct smbsrv_session *sess = idr_find(smb_conn->sessions.idtree_vuid, vuid); - if (sess && sess->finished_sesssetup) { + void *p; + struct smbsrv_session *sess; + + if (vuid == 0) return NULL; + + if (vuid > smb_conn->sessions.idtree_limit) return NULL; + + p = idr_find(smb_conn->sessions.idtree_vuid, vuid); + if (!p) return NULL; + + /* only return a finished session */ + sess = talloc_get_type(p, struct smbsrv_session); + if (sess && sess->session_info) { return sess; } + return NULL; } -/**************************************************************************** - Find a VUID assoicated with an in-progress session setup -****************************************************************************/ -struct smbsrv_session *smbsrv_session_find_sesssetup(struct smbsrv_connection *smb_conn, uint16_t vuid) +/* + * Find the session structure assoicated with a VUID + * (assoicated with an in-progress session setup) + */ +struct smbsrv_session *smbsrv_session_find_sesssetup(struct smbsrv_connection *smb_conn, uint64_t vuid) { - struct smbsrv_session *sess = idr_find(smb_conn->sessions.idtree_vuid, vuid); - if (sess && !sess->finished_sesssetup) { + void *p; + struct smbsrv_session *sess; + + if (vuid == 0) return NULL; + + if (vuid > smb_conn->sessions.idtree_limit) return NULL; + + p = idr_find(smb_conn->sessions.idtree_vuid, vuid); + if (!p) return NULL; + + /* only return an unfinished session */ + sess = talloc_get_type(p, struct smbsrv_session); + if (sess && !sess->session_info) { return sess; } return NULL; } -/**************************************************************************** -invalidate a session -****************************************************************************/ -static int smbsrv_session_destructor(void *p) +/* + * the session will be marked as valid for usage + * by attaching a auth_session_info to the session. + * + * session_info will be talloc_stealed + */ +NTSTATUS smbsrv_session_sesssetup_finished(struct smbsrv_session *sess, + struct auth_session_info *session_info) { - struct smbsrv_session *sess = talloc_get_type(p, struct smbsrv_session); - struct smbsrv_connection *smb_conn = sess->smb_conn; - - /* clear the vuid from the 'cache' on each connection, and - from the vuid 'owner' of connections */ - /* REWRITE: conn_clear_vuid_cache(smb, vuid); */ + /* this check is to catch programmer errors */ + if (!session_info) { + talloc_free(sess); + return NT_STATUS_ACCESS_DENIED; + } - smb_conn->sessions.num_validated_vuids--; + /* mark the session as successful authenticated */ + sess->session_info = talloc_steal(sess, session_info); - idr_remove(smb_conn->sessions.idtree_vuid, sess->vuid); + /* now fill in some statistics */ + sess->statistics.auth_time = timeval_current(); - DLIST_REMOVE(smb_conn->sessions.list, sess); - return 0; + return NT_STATUS_OK; } /**************************************************************************** -invalidate a uid +destroy a session structure ****************************************************************************/ -void smbsrv_invalidate_vuid(struct smbsrv_connection *smb_conn, uint16_t vuid) +static int smbsrv_session_destructor(void *p) { - struct smbsrv_session *sess = smbsrv_session_find(smb_conn, vuid); - talloc_free(sess); + struct smbsrv_session *sess = talloc_get_type(p, struct smbsrv_session); + struct smbsrv_connection *smb_conn = sess->smb_conn; + + idr_remove(smb_conn->sessions.idtree_vuid, sess->vuid); + DLIST_REMOVE(smb_conn->sessions.list, sess); + return 0; } -/** - * register that a valid login has been performed, establish 'session'. - * @param session_info The token returned from the authentication process (if the authentication has completed) - * (now 'owned' by register_vuid) - * - * @param smb_name The untranslated name of the user - * - * @return Newly allocated vuid, biased by an offset. (This allows us to - * tell random client vuid's (normally zero) from valid vuids.) - * +/* + * allocate a new session structure with a VUID. + * gensec_ctx is optional, but talloc_steal'ed when present */ - -struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_conn, - struct auth_session_info *session_info, - struct gensec_security *gensec_ctx) +struct smbsrv_session *smbsrv_session_new(struct smbsrv_connection *smb_conn, + struct gensec_security *gensec_ctx) { struct smbsrv_session *sess = NULL; int i; @@ -109,15 +142,11 @@ struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_con /* Ensure no vuid gets registered in share level security. */ if (smb_conn->config.security == SEC_SHARE) return NULL; - sess = talloc(smb_conn, struct smbsrv_session); - if (sess == NULL) { - DEBUG(0,("talloc(smb_conn->mem_ctx, struct smbsrv_session) failed\n")); - return sess; - } - - ZERO_STRUCTP(sess); + sess = talloc_zero(smb_conn, struct smbsrv_session); + if (!sess) return NULL; + sess->smb_conn = smb_conn; - i = idr_get_new_random(smb_conn->sessions.idtree_vuid, sess, UINT16_MAX); + i = idr_get_new_random(smb_conn->sessions.idtree_vuid, sess, smb_conn->sessions.idtree_limit); if (i == -1) { DEBUG(1,("ERROR! Out of connection structures\n")); talloc_free(sess); @@ -125,18 +154,14 @@ struct smbsrv_session *smbsrv_register_session(struct smbsrv_connection *smb_con } sess->vuid = i; - smb_conn->sessions.num_validated_vuids++; - /* use this to keep tabs on all our info from the authentication */ - sess->session_info = talloc_reference(sess, session_info); - - sess->gensec_ctx = talloc_reference(sess, gensec_ctx); - sess->smb_conn = smb_conn; - sess->connect_time = timeval_current(); + sess->gensec_ctx = talloc_steal(sess, gensec_ctx); DLIST_ADD(smb_conn->sessions.list, sess); - talloc_set_destructor(sess, smbsrv_session_destructor); + /* now fill in some statistics */ + sess->statistics.connect_time = timeval_current(); + return sess; } -- cgit From 316269a07523a421755158540d2f4e22fa312866 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 26 Mar 2006 11:32:27 +0000 Subject: r14739: keep the last request time for the smbsrv_connection, smbsrv_session and smbsrv_tcon for management tools metze (This used to be commit 2c87f210e9e68de42dc45ca6532f3f33f4b6ce95) --- source4/smb_server/session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 967c02bfc9..7274a7a716 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -47,7 +47,8 @@ NTSTATUS smbsrv_init_sessions(struct smbsrv_connection *smb_conn, uint64_t limit * Find the session structure assoicated with a VUID * (not one from an in-progress session setup) */ -struct smbsrv_session *smbsrv_session_find(struct smbsrv_connection *smb_conn, uint64_t vuid) +struct smbsrv_session *smbsrv_session_find(struct smbsrv_connection *smb_conn, + uint64_t vuid, struct timeval request_time) { void *p; struct smbsrv_session *sess; @@ -62,6 +63,7 @@ struct smbsrv_session *smbsrv_session_find(struct smbsrv_connection *smb_conn, u /* only return a finished session */ sess = talloc_get_type(p, struct smbsrv_session); if (sess && sess->session_info) { + sess->statistics.last_request_time = request_time; return sess; } -- cgit From 4c5a67fa35a7df9fd3c3f1080734170f37667e62 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 19 May 2006 14:25:15 +0000 Subject: r15715: add my copyright metze (This used to be commit a3799771c830a6ae952b0d9b45b8a01f7a6bf9c6) --- source4/smb_server/session.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 7274a7a716..50338ba16e 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -3,7 +3,8 @@ Password and authentication handling Copyright (C) Andrew Tridgell 1992-2005 Copyright (C) Andrew Bartlett 2005 - + Copyright (C) Stefan Metzmacher 2005-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 -- 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/session.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 50338ba16e..06c4f62904 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -122,9 +122,8 @@ NTSTATUS smbsrv_session_sesssetup_finished(struct smbsrv_session *sess, /**************************************************************************** destroy a session structure ****************************************************************************/ -static int smbsrv_session_destructor(void *p) +static int smbsrv_session_destructor(struct smbsrv_session *sess) { - struct smbsrv_session *sess = talloc_get_type(p, struct smbsrv_session); struct smbsrv_connection *smb_conn = sess->smb_conn; idr_remove(smb_conn->sessions.idtree_vuid, sess->vuid); -- 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/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index 06c4f62904..e95dc9e856 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -22,7 +22,7 @@ #include "includes.h" #include "smb_server/smb_server.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" /* -- cgit From d3e28ccd4824adce2feed9fe53cf2d4d393d607a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 20 May 2007 09:44:03 +0000 Subject: r23020: a better fix for the memory leak - this one doesn't stuff up spnego :) (This used to be commit 9a8da730a725fc9fc1a3e407273e688f44eadfe1) --- source4/smb_server/session.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index e95dc9e856..bd5660e481 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -136,6 +136,7 @@ static int smbsrv_session_destructor(struct smbsrv_session *sess) * gensec_ctx is optional, but talloc_steal'ed when present */ struct smbsrv_session *smbsrv_session_new(struct smbsrv_connection *smb_conn, + TALLOC_CTX *mem_ctx, struct gensec_security *gensec_ctx) { struct smbsrv_session *sess = NULL; @@ -144,7 +145,7 @@ struct smbsrv_session *smbsrv_session_new(struct smbsrv_connection *smb_conn, /* Ensure no vuid gets registered in share level security. */ if (smb_conn->config.security == SEC_SHARE) return NULL; - sess = talloc_zero(smb_conn, struct smbsrv_session); + sess = talloc_zero(mem_ctx, struct smbsrv_session); if (!sess) return NULL; sess->smb_conn = smb_conn; -- 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/session.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/smb_server/session.c') diff --git a/source4/smb_server/session.c b/source4/smb_server/session.c index bd5660e481..e7970eb7d5 100644 --- a/source4/smb_server/session.c +++ b/source4/smb_server/session.c @@ -7,7 +7,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, @@ -16,8 +16,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