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/config.mk | 2 +- source4/smb_server/password.c | 142 ---------------------------------------- source4/smb_server/session.c | 139 +++++++++++++++++++++++++++++++++++++++ source4/smb_server/smb_server.h | 5 +- 4 files changed, 142 insertions(+), 146 deletions(-) delete mode 100644 source4/smb_server/password.c create mode 100644 source4/smb_server/session.c diff --git a/source4/smb_server/config.mk b/source4/smb_server/config.mk index 2521e8299e..70d2ea0926 100644 --- a/source4/smb_server/config.mk +++ b/source4/smb_server/config.mk @@ -9,7 +9,7 @@ ADD_OBJ_FILES = \ smb_server/conn.o \ smb_server/negprot.o \ smb_server/nttrans.o \ - smb_server/password.o \ + smb_server/session.o \ smb_server/reply.o \ smb_server/request.o \ smb_server/search.o \ diff --git a/source4/smb_server/password.c b/source4/smb_server/password.c deleted file mode 100644 index 1132a8ed9a..0000000000 --- a/source4/smb_server/password.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - 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; - - DLIST_REMOVE(smb_conn->sessions.session_list, sess); - - /* 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; - DLIST_ADD(smb_conn->sessions.session_list, sess); - - talloc_set_destructor(sess, smbsrv_session_destructor); - - return sess; -} 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; +} diff --git a/source4/smb_server/smb_server.h b/source4/smb_server/smb_server.h index 2f176d9c66..01222adc0c 100644 --- a/source4/smb_server/smb_server.h +++ b/source4/smb_server/smb_server.h @@ -218,12 +218,11 @@ struct smbsrv_connection { /* context associated with currently valid session setups */ struct { - /* this holds info on session vuids that are already validated for this VC */ - struct smbsrv_session *session_list; - int num_validated_vuids; /* an id tree used to allocate vuids */ + /* this holds info on session vuids that are already + * validated for this VC */ struct idr_context *idtree_vuid; } sessions; -- cgit