2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
Password and authentication handling
Copyright ( C ) Andrew Tridgell 1992 - 1998
2005-04-10 07:39:51 +00:00
Copyright ( C ) Andrew Bartlett < abartlet @ samba . org > 2005
2003-08-13 01:53:07 +00:00
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 0213 9 , USA .
*/
# include "includes.h"
2004-11-02 07:18:24 +00:00
# include "smb_server/smb_server.h"
2003-08-13 01:53:07 +00:00
/****************************************************************************
2005-04-10 07:39:51 +00:00
init the tcon structures
2003-08-13 01:53:07 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-04-10 07:39:51 +00:00
void smbsrv_vuid_init ( struct smbsrv_connection * smb_conn )
2003-08-13 01:53:07 +00:00
{
2005-04-10 07:39:51 +00:00
smb_conn - > sessions . idtree_vuid = idr_init ( smb_conn ) ;
}
2003-08-13 01:53:07 +00:00
2005-04-10 07:39:51 +00:00
/****************************************************************************
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 ;
2003-08-13 01:53:07 +00:00
}
return NULL ;
}
/****************************************************************************
2005-04-10 07:39:51 +00:00
Find a VUID assoicated with an in - progress session setup
2003-08-13 01:53:07 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-04-10 07:39:51 +00:00
struct smbsrv_session * smbsrv_session_find_sesssetup ( struct smbsrv_connection * smb_conn , uint16_t vuid )
2003-08-13 01:53:07 +00:00
{
2005-04-10 07:39:51 +00:00
struct smbsrv_session * sess = idr_find ( smb_conn - > sessions . idtree_vuid , vuid ) ;
if ( sess & & ! sess - > finished_sesssetup ) {
return sess ;
}
return NULL ;
}
2003-08-13 01:53:07 +00:00
2005-04-10 07:39:51 +00:00
/****************************************************************************
invalidate a session
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int smbsrv_session_destructor ( void * p )
{
struct smbsrv_session * sess = p ;
struct smbsrv_connection * smb_conn = sess - > smb_conn ;
2004-05-02 08:45:00 +00:00
2003-08-13 01:53:07 +00:00
/* clear the vuid from the 'cache' on each connection, and
from the vuid ' owner ' of connections */
/* REWRITE: conn_clear_vuid_cache(smb, vuid); */
2004-07-14 12:44:31 +00:00
smb_conn - > sessions . num_validated_vuids - - ;
2005-04-10 07:39:51 +00:00
idr_remove ( smb_conn - > sessions . idtree_vuid , sess - > vuid ) ;
return 0 ;
2003-08-13 01:53:07 +00:00
}
/****************************************************************************
2005-04-10 07:39:51 +00:00
invalidate a uid
2003-08-13 01:53:07 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-04-10 07:39:51 +00:00
void smbsrv_invalidate_vuid ( struct smbsrv_connection * smb_conn , uint16_t vuid )
2003-08-13 01:53:07 +00:00
{
2005-04-10 07:39:51 +00:00
struct smbsrv_session * sess = smbsrv_session_find ( smb_conn , vuid ) ;
talloc_free ( sess ) ;
2003-08-13 01:53:07 +00:00
}
/**
* register that a valid login has been performed , establish ' session ' .
2004-08-11 16:16:28 +00:00
* @ param session_info The token returned from the authentication process ( if the authentication has completed )
2003-08-13 01:53:07 +00:00
* ( now ' owned ' by register_vuid )
*
2004-05-02 08:45:00 +00:00
* @ param smb_name The untranslated name of the user
*
2003-08-13 01:53:07 +00:00
* @ return Newly allocated vuid , biased by an offset . ( This allows us to
* tell random client vuid ' s ( normally zero ) from valid vuids . )
*
*/
2005-04-10 07:39:51 +00:00
struct smbsrv_session * smbsrv_register_session ( struct smbsrv_connection * smb_conn ,
struct auth_session_info * session_info ,
struct gensec_security * gensec_ctx )
2003-08-13 01:53:07 +00:00
{
2004-07-14 12:44:31 +00:00
struct smbsrv_session * sess = NULL ;
2005-04-10 07:39:51 +00:00
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 ;
2003-08-13 01:53:07 +00:00
2005-01-27 07:08:20 +00:00
sess = talloc ( smb_conn , struct smbsrv_session ) ;
2005-04-10 07:39:51 +00:00
if ( sess = = NULL ) {
2005-01-27 07:08:20 +00:00
DEBUG ( 0 , ( " talloc(smb_conn->mem_ctx, struct smbsrv_session) failed \n " ) ) ;
2005-04-10 07:39:51 +00:00
return sess ;
2004-07-14 12:44:31 +00:00
}
2003-08-13 01:53:07 +00:00
2004-07-14 12:44:31 +00:00
ZERO_STRUCTP ( sess ) ;
2003-08-13 01:53:07 +00:00
2005-06-17 06:36:13 +00:00
i = idr_get_new_random ( smb_conn - > sessions . idtree_vuid , sess , UINT16_MAX ) ;
2005-04-10 07:39:51 +00:00
if ( i = = - 1 ) {
DEBUG ( 1 , ( " ERROR! Out of connection structures \n " ) ) ;
talloc_free ( sess ) ;
return NULL ;
2003-08-13 01:53:07 +00:00
}
2005-04-10 07:39:51 +00:00
sess - > vuid = i ;
2003-08-13 01:53:07 +00:00
2004-07-14 12:44:31 +00:00
smb_conn - > sessions . num_validated_vuids + + ;
2003-08-13 01:53:07 +00:00
/* use this to keep tabs on all our info from the authentication */
2005-04-10 07:39:51 +00:00
sess - > session_info = talloc_reference ( sess , session_info ) ;
sess - > gensec_ctx = talloc_reference ( sess , gensec_ctx ) ;
2004-07-14 12:44:31 +00:00
sess - > smb_conn = smb_conn ;
2005-04-10 07:39:51 +00:00
talloc_set_destructor ( sess , smbsrv_session_destructor ) ;
return sess ;
2003-08-13 01:53:07 +00:00
}