2007-08-21 06:04:24 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1996-05-04 11:50:46 +04:00
Password and authentication handling
1998-01-22 16:27:43 +03:00
Copyright ( C ) Andrew Tridgell 1992 - 1998
2007-08-21 06:04:24 +04:00
Copyright ( C ) Jeremy Allison 2007.
1996-05-04 11:50:46 +04: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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1996-05-04 11:50:46 +04:00
( at your option ) any later version .
2007-08-21 06:04:24 +04:00
1996-05-04 11:50:46 +04:00
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 .
2007-08-21 06:04:24 +04:00
1996-05-04 11:50:46 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1996-05-04 11:50:46 +04:00
*/
# include "includes.h"
/* users from session setup */
2004-04-15 02:35:28 +04:00
static char * session_userlist = NULL ;
2007-02-03 01:02:42 +03:00
/* workgroup from session setup. */
static char * session_workgroup = NULL ;
1996-05-04 11:50:46 +04:00
1999-12-13 16:27:58 +03:00
/* this holds info on user ids that are already validated for this VC */
2000-11-29 01:17:44 +03:00
static user_struct * validated_users ;
static int next_vuid = VUID_OFFSET ;
static int num_validated_vuids ;
1999-12-13 16:27:58 +03:00
2007-08-21 05:43:22 +04:00
enum server_allocated_state { SERVER_ALLOCATED_REQUIRED_YES ,
SERVER_ALLOCATED_REQUIRED_NO ,
SERVER_ALLOCATED_REQUIRED_ANY } ;
2003-07-17 22:55:40 +04:00
2007-08-21 05:43:22 +04:00
static user_struct * get_valid_user_struct_internal ( uint16 vuid ,
enum server_allocated_state server_allocated )
1999-12-13 16:27:58 +03:00
{
2000-11-29 01:17:44 +03:00
user_struct * usp ;
int count = 0 ;
if ( vuid = = UID_FIELD_INVALID )
return NULL ;
for ( usp = validated_users ; usp ; usp = usp - > next , count + + ) {
2007-08-21 05:43:22 +04:00
if ( vuid = = usp - > vuid ) {
switch ( server_allocated ) {
case SERVER_ALLOCATED_REQUIRED_YES :
if ( usp - > server_info = = NULL ) {
continue ;
}
break ;
case SERVER_ALLOCATED_REQUIRED_NO :
if ( usp - > server_info ! = NULL ) {
continue ;
}
case SERVER_ALLOCATED_REQUIRED_ANY :
break ;
}
2005-07-14 18:39:27 +04:00
if ( count > 10 ) {
DLIST_PROMOTE ( validated_users , usp ) ;
}
return usp ;
}
}
return NULL ;
}
/****************************************************************************
2007-08-21 05:43:22 +04:00
Check if a uid has been validated , and return an pointer to the user_struct
if it has . NULL if not . vuid is biased by an offset . This allows us to
tell random client vuid ' s ( normally zero ) from valid vuids .
2005-07-14 18:39:27 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-08-21 05:43:22 +04:00
user_struct * get_valid_user_struct ( uint16 vuid )
2005-07-14 18:39:27 +04:00
{
2007-08-21 06:04:24 +04:00
return get_valid_user_struct_internal ( vuid ,
SERVER_ALLOCATED_REQUIRED_YES ) ;
2007-08-21 05:43:22 +04:00
}
2005-07-14 18:39:27 +04:00
2007-10-19 04:40:25 +04:00
bool is_partial_auth_vuid ( uint16 vuid )
2007-08-21 05:43:22 +04:00
{
2008-12-29 23:01:13 +03:00
return ( get_partial_auth_user_struct ( vuid ) ! = NULL ) ;
2007-08-21 05:43:22 +04:00
}
2000-11-29 01:17:44 +03:00
2007-08-21 05:43:22 +04:00
/****************************************************************************
Get the user struct of a partial NTLMSSP login
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
user_struct * get_partial_auth_user_struct ( uint16 vuid )
{
return get_valid_user_struct_internal ( vuid ,
SERVER_ALLOCATED_REQUIRED_NO ) ;
1999-12-13 16:27:58 +03:00
}
/****************************************************************************
2003-07-17 22:55:40 +04:00
Invalidate a uid .
1999-12-13 16:27:58 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-17 22:55:40 +04:00
1999-12-13 16:27:58 +03:00
void invalidate_vuid ( uint16 vuid )
{
2007-08-21 05:43:22 +04:00
user_struct * vuser = NULL ;
vuser = get_valid_user_struct_internal ( vuid ,
SERVER_ALLOCATED_REQUIRED_ANY ) ;
if ( vuser = = NULL ) {
2000-06-09 22:45:31 +04:00
return ;
2007-08-21 05:43:22 +04:00
}
2001-11-09 01:19:01 +03:00
session_yield ( vuser ) ;
2003-02-24 05:35:54 +03:00
2008-02-15 05:06:16 +03:00
if ( vuser - > auth_ntlmssp_state ) {
auth_ntlmssp_end ( & vuser - > auth_ntlmssp_state ) ;
}
2000-11-29 01:17:44 +03:00
DLIST_REMOVE ( validated_users , vuser ) ;
2000-06-09 07:30:54 +04:00
2002-09-25 19:19:00 +04:00
/* clear the vuid from the 'cache' on each connection, and
from the vuid ' owner ' of connections */
2008-06-14 18:59:07 +04:00
conn_clear_vuid_caches ( vuid ) ;
2002-09-25 19:19:00 +04:00
2007-04-02 07:46:13 +04:00
TALLOC_FREE ( vuser ) ;
2000-11-29 01:17:44 +03:00
num_validated_vuids - - ;
1999-12-13 16:27:58 +03:00
}
2001-04-18 20:41:04 +04:00
/****************************************************************************
2003-07-17 22:55:40 +04:00
Invalidate all vuid entries for this process .
2001-04-18 20:41:04 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-17 22:55:40 +04:00
2001-04-18 20:41:04 +04:00
void invalidate_all_vuids ( void )
{
2008-12-29 21:50:39 +03:00
while ( validated_users ! = NULL ) {
invalidate_vuid ( validated_users - > vuid ) ;
2001-04-18 20:41:04 +04:00
}
}
2007-08-21 05:43:22 +04:00
/****************************************************
Create a new partial auth user struct .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-08-02 06:11:55 +04:00
2007-08-21 05:43:22 +04:00
int register_initial_vuid ( void )
1999-12-13 16:27:58 +03:00
{
2007-04-02 07:46:13 +04:00
user_struct * vuser ;
2000-11-29 01:17:44 +03:00
2006-05-14 03:05:53 +04:00
/* Paranoia check. */
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
if ( lp_security ( ) = = SEC_SHARE ) {
2007-08-21 05:43:22 +04:00
smb_panic ( " register_initial_vuid: "
" Tried to register uid in security=share " ) ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
}
2000-11-29 01:17:44 +03:00
/* Limit allowed vuids to 16bits - VUID_OFFSET. */
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
if ( num_validated_vuids > = 0xFFFF - VUID_OFFSET ) {
2000-11-29 01:17:44 +03:00
return UID_FIELD_INVALID ;
Changes all over the shop, but all towards:
- NTLM2 support in the server
- KEY_EXCH support in the server
- variable length session keys.
In detail:
- NTLM2 is an extension of NTLMv1, that is compatible with existing
domain controllers (unlike NTLMv2, which requires a DC upgrade).
* This is known as 'NTLMv2 session security' *
(This is not yet implemented on the RPC pipes however, so there may
well still be issues for PDC setups, particuarly around password
changes. We do not fully understand the sign/seal implications of
NTLM2 on RPC pipes.)
This requires modifications to our authentication subsystem, as we
must handle the 'challege' input into the challenge-response algorithm
being changed. This also needs to be turned off for
'security=server', which does not support this.
- KEY_EXCH is another 'security' mechanism, whereby the session key
actually used by the server is sent by the client, rather than being
the shared-secret directly or indirectly.
- As both these methods change the session key, the auth subsystem
needed to be changed, to 'override' session keys provided by the
backend.
- There has also been a major overhaul of the NTLMSSP subsystem, to merge the 'client' and 'server' functions, so they both operate on a single structure. This should help the SPNEGO implementation.
- The 'names blob' in NTLMSSP is always in unicode - never in ascii.
Don't make an ascii version ever.
- The other big change is to allow variable length session keys. We
have always assumed that session keys are 16 bytes long - and padded
to this length if shorter. However, Kerberos session keys are 8 bytes
long, when the krb5 login uses DES.
* This fix allows SMB signging on machines not yet running MIT KRB5 1.3.1. *
- Add better DEBUG() messages to ntlm_auth, warning administrators of
misconfigurations that prevent access to the privileged pipe. This
should help reduce some of the 'it just doesn't work' issues.
- Fix data_blob_talloc() to behave the same way data_blob() does when
passed a NULL data pointer. (just allocate)
REMEMBER to make clean after this commit - I have changed plenty of data structures...
(This used to be commit f3bbc87b0dac63426cda6fac7a295d3aad810ecc)
2003-11-22 16:19:38 +03:00
}
2000-11-29 01:17:44 +03:00
2007-08-21 05:43:22 +04:00
if ( ( vuser = talloc_zero ( NULL , user_struct ) ) = = NULL ) {
DEBUG ( 0 , ( " register_initial_vuid: "
" Failed to talloc users struct! \n " ) ) ;
2000-11-29 01:17:44 +03:00
return UID_FIELD_INVALID ;
}
2007-08-21 05:43:22 +04:00
/* Allocate a free vuid. Yes this is a linear search... */
while ( get_valid_user_struct_internal ( next_vuid ,
SERVER_ALLOCATED_REQUIRED_ANY ) ! = NULL ) {
2000-11-29 01:17:44 +03:00
next_vuid + + ;
/* Check for vuid wrap. */
2007-08-21 05:43:22 +04:00
if ( next_vuid = = UID_FIELD_INVALID ) {
2000-11-29 01:17:44 +03:00
next_vuid = VUID_OFFSET ;
2007-08-21 05:43:22 +04:00
}
2000-11-29 01:17:44 +03:00
}
2007-08-21 05:43:22 +04:00
DEBUG ( 10 , ( " register_initial_vuid: allocated vuid = %u \n " ,
( unsigned int ) next_vuid ) ) ;
2000-11-29 01:17:44 +03:00
vuser - > vuid = next_vuid ;
2002-09-25 19:19:00 +04:00
2007-08-21 05:43:22 +04:00
/*
* This happens in an unfinished NTLMSSP session setup . We
* need to allocate a vuid between the first and second calls
* to NTLMSSP .
*/
next_vuid + + ;
num_validated_vuids + + ;
DLIST_ADD ( validated_users , vuser ) ;
return vuser - > vuid ;
}
2008-04-29 15:23:47 +04:00
static int register_homes_share ( const char * username )
{
int result ;
struct passwd * pwd ;
result = lp_servicenumber ( username ) ;
if ( result ! = - 1 ) {
DEBUG ( 3 , ( " Using static (or previously created) service for "
" user '%s'; path = '%s' \n " , username ,
lp_pathname ( result ) ) ) ;
return result ;
}
pwd = getpwnam_alloc ( talloc_tos ( ) , username ) ;
if ( ( pwd = = NULL ) | | ( pwd - > pw_dir [ 0 ] = = ' \0 ' ) ) {
DEBUG ( 3 , ( " No home directory defined for user '%s' \n " ,
username ) ) ;
TALLOC_FREE ( pwd ) ;
return - 1 ;
}
DEBUG ( 3 , ( " Adding homes service for user '%s' using home directory: "
" '%s' \n " , username , pwd - > pw_dir ) ) ;
result = add_home_service ( username , username , pwd - > pw_dir ) ;
TALLOC_FREE ( pwd ) ;
return result ;
}
2007-08-21 05:43:22 +04:00
/**
* register that a valid login has been performed , establish ' session ' .
* @ param server_info The token returned from the authentication process .
* ( now ' owned ' by register_existing_vuid )
*
* @ param session_key The User session key for the login session ( now also
* ' owned ' by register_existing_vuid )
*
* @ param respose_blob The NT challenge - response , if available . ( May be
* freed after this call )
*
* @ 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 . )
*
*/
int register_existing_vuid ( uint16 vuid ,
auth_serversupplied_info * server_info ,
DATA_BLOB response_blob ,
const char * smb_name )
{
2008-04-30 19:42:39 +04:00
fstring tmp ;
user_struct * vuser ;
vuser = get_partial_auth_user_struct ( vuid ) ;
2007-08-21 05:43:22 +04:00
if ( ! vuser ) {
goto fail ;
2005-07-14 18:39:27 +04:00
}
2007-08-21 05:43:22 +04:00
/* Use this to keep tabs on all our info from the authentication */
2008-04-30 19:42:39 +04:00
vuser - > server_info = talloc_move ( vuser , & server_info ) ;
2003-02-24 05:35:54 +03:00
/* This is a potentially untrusted username */
2008-04-30 19:42:39 +04:00
alpha_strcpy ( tmp , smb_name , " . _-$ " , sizeof ( tmp ) ) ;
2003-02-24 05:35:54 +03:00
2008-04-30 19:42:39 +04:00
vuser - > server_info - > sanitized_username = talloc_strdup (
2008-05-06 17:41:20 +04:00
vuser - > server_info , tmp ) ;
2001-10-31 13:46:25 +03:00
2007-08-21 05:43:22 +04:00
DEBUG ( 10 , ( " register_existing_vuid: (%u,%u) %s %s %s guest=%d \n " ,
2008-06-19 18:54:12 +04:00
( unsigned int ) vuser - > server_info - > utok . uid ,
( unsigned int ) vuser - > server_info - > utok . gid ,
2008-04-30 19:42:39 +04:00
vuser - > server_info - > unix_name ,
vuser - > server_info - > sanitized_username ,
pdb_get_domain ( vuser - > server_info - > sam_account ) ,
vuser - > server_info - > guest ) ) ;
2001-10-31 13:46:25 +03:00
2007-08-21 05:43:22 +04:00
DEBUG ( 3 , ( " register_existing_vuid: User name: %s \t "
2008-04-30 19:42:39 +04:00
" Real name: %s \n " , vuser - > server_info - > unix_name ,
pdb_get_fullname ( vuser - > server_info - > sam_account ) ) ) ;
2000-11-29 01:17:44 +03:00
2008-04-30 19:42:39 +04:00
if ( ! vuser - > server_info - > ptok ) {
2007-08-21 05:43:22 +04:00
DEBUG ( 1 , ( " register_existing_vuid: server_info does not "
" contain a user_token - cannot continue \n " ) ) ;
goto fail ;
2002-09-25 19:19:00 +04:00
}
2000-11-29 01:17:44 +03:00
2007-08-21 05:43:22 +04:00
DEBUG ( 3 , ( " register_existing_vuid: UNIX uid %d is UNIX user %s, "
2008-06-19 18:54:12 +04:00
" and will be vuid %u \n " , ( int ) vuser - > server_info - > utok . uid ,
2008-04-30 19:42:39 +04:00
vuser - > server_info - > unix_name , vuser - > vuid ) ) ;
2001-08-17 11:47:10 +04:00
2001-11-09 01:19:01 +03:00
if ( ! session_claim ( vuser ) ) {
2007-08-21 05:43:22 +04:00
DEBUG ( 1 , ( " register_existing_vuid: Failed to claim session "
" for vuid=%d \n " ,
vuser - > vuid ) ) ;
goto fail ;
2000-11-29 01:17:44 +03:00
}
1999-12-13 16:27:58 +03:00
2007-08-21 05:43:22 +04:00
/* Register a home dir service for this user if
( a ) This is not a guest connection ,
( b ) we have a home directory defined
( c ) there s not an existing static share by that name
If a share exists by this name ( autoloaded or not ) reuse it . */
2004-08-27 00:47:58 +04:00
vuser - > homes_snum = - 1 ;
2008-04-29 15:23:47 +04:00
2008-04-29 15:45:58 +04:00
if ( ! vuser - > server_info - > guest ) {
2008-04-29 15:23:47 +04:00
vuser - > homes_snum = register_homes_share (
2008-04-30 19:42:39 +04:00
vuser - > server_info - > unix_name ) ;
2007-08-21 05:43:22 +04:00
}
2008-04-29 15:45:58 +04:00
if ( srv_is_signing_negotiated ( ) & & ! vuser - > server_info - > guest & &
2007-08-21 05:43:22 +04:00
! srv_signing_started ( ) ) {
2006-02-04 01:19:41 +03:00
/* Try and turn on server signing on the first non-guest
* sessionsetup . */
2008-04-30 16:26:16 +04:00
srv_set_signing ( vuser - > server_info - > user_session_key , response_blob ) ;
2003-07-17 22:55:40 +04:00
}
2007-08-21 05:43:22 +04:00
2004-03-20 01:06:54 +03:00
/* fill in the current_user_info struct */
2008-04-30 19:42:39 +04:00
set_current_user_info (
vuser - > server_info - > sanitized_username ,
vuser - > server_info - > unix_name ,
pdb_get_fullname ( vuser - > server_info - > sam_account ) ,
pdb_get_domain ( vuser - > server_info - > sam_account ) ) ;
2007-08-21 05:43:22 +04:00
return vuser - > vuid ;
2004-03-20 01:06:54 +03:00
2007-08-21 05:43:22 +04:00
fail :
2003-07-17 22:55:40 +04:00
2007-08-21 05:43:22 +04:00
if ( vuser ) {
invalidate_vuid ( vuid ) ;
}
return UID_FIELD_INVALID ;
1999-12-13 16:27:58 +03:00
}
1996-05-04 11:50:46 +04:00
/****************************************************************************
2003-07-17 22:55:40 +04:00
Add a name to the session users list .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-17 22:55:40 +04:00
2002-08-17 19:27:10 +04:00
void add_session_user ( const char * user )
1996-05-04 11:50:46 +04:00
{
2007-12-09 21:03:49 +03:00
struct passwd * pw ;
char * tmp ;
2002-09-25 19:19:00 +04:00
2007-12-09 21:03:49 +03:00
pw = Get_Pwnam_alloc ( talloc_tos ( ) , user ) ;
1996-05-04 11:50:46 +04:00
2007-12-09 21:03:49 +03:00
if ( pw = = NULL ) {
2004-04-15 02:35:28 +04:00
return ;
2007-12-09 21:03:49 +03:00
}
2004-04-15 02:35:28 +04:00
2007-12-09 21:03:49 +03:00
if ( session_userlist = = NULL ) {
session_userlist = SMB_STRDUP ( pw - > pw_name ) ;
goto done ;
}
2004-04-15 02:35:28 +04:00
2007-12-09 21:03:49 +03:00
if ( in_list ( pw - > pw_name , session_userlist , False ) ) {
goto done ;
}
2004-04-15 02:35:28 +04:00
2007-12-09 21:03:49 +03:00
if ( strlen ( session_userlist ) > 128 * 1024 ) {
DEBUG ( 3 , ( " add_session_user: session userlist already "
" too large. \n " ) ) ;
goto done ;
}
if ( asprintf ( & tmp , " %s %s " , session_userlist , pw - > pw_name ) = = - 1 ) {
DEBUG ( 3 , ( " asprintf failed \n " ) ) ;
goto done ;
1996-05-04 11:50:46 +04:00
}
2004-04-15 02:35:28 +04:00
2007-12-09 21:03:49 +03:00
SAFE_FREE ( session_userlist ) ;
session_userlist = tmp ;
done :
TALLOC_FREE ( pw ) ;
1996-05-04 11:50:46 +04:00
}
2007-02-03 01:02:42 +03:00
/****************************************************************************
In security = share mode we need to store the client workgroup , as that ' s
what Vista uses for the NTLMv2 calculation .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void add_session_workgroup ( const char * workgroup )
{
if ( session_workgroup ) {
SAFE_FREE ( session_workgroup ) ;
}
session_workgroup = smb_xstrdup ( workgroup ) ;
}
/****************************************************************************
In security = share mode we need to return the client workgroup , as that ' s
what Vista uses for the NTLMv2 calculation .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
const char * get_session_workgroup ( void )
{
return session_workgroup ;
}
2006-02-13 20:08:25 +03:00
/****************************************************************************
Check if a user is in a netgroup user list . If at first we don ' t succeed ,
try lower case .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool user_in_netgroup ( const char * user , const char * ngname )
2006-02-13 20:08:25 +03:00
{
# ifdef HAVE_NETGROUP
static char * mydomain = NULL ;
fstring lowercase_user ;
if ( mydomain = = NULL )
yp_get_default_domain ( & mydomain ) ;
if ( mydomain = = NULL ) {
2007-08-21 06:04:24 +04:00
DEBUG ( 5 , ( " Unable to get default yp domain, "
" let's try without specifying it \n " ) ) ;
2006-02-13 20:08:25 +03:00
}
DEBUG ( 5 , ( " looking for user %s of domain %s in netgroup %s \n " ,
2006-08-05 02:18:02 +04:00
user , mydomain ? mydomain : " (ANY) " , ngname ) ) ;
2006-02-13 20:08:25 +03:00
if ( innetgr ( ngname , NULL , user , mydomain ) ) {
DEBUG ( 5 , ( " user_in_netgroup: Found \n " ) ) ;
return ( True ) ;
} else {
/*
* Ok , innetgr is case sensitive . Try once more with lowercase
* just in case . Attempt to fix # 703. JRA .
*/
fstrcpy ( lowercase_user , user ) ;
strlower_m ( lowercase_user ) ;
2007-08-21 06:04:24 +04:00
2006-02-13 20:08:25 +03:00
DEBUG ( 5 , ( " looking for user %s of domain %s in netgroup %s \n " ,
2006-08-05 02:18:02 +04:00
lowercase_user , mydomain ? mydomain : " (ANY) " , ngname ) ) ;
2006-02-13 20:08:25 +03:00
if ( innetgr ( ngname , NULL , lowercase_user , mydomain ) ) {
DEBUG ( 5 , ( " user_in_netgroup: Found \n " ) ) ;
return ( True ) ;
}
}
# endif /* HAVE_NETGROUP */
return False ;
}
/****************************************************************************
Check if a user is in a user list - can check combinations of UNIX
and netgroup lists .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-10-19 04:40:25 +04:00
bool user_in_list ( const char * user , const char * * list )
2006-02-13 20:08:25 +03:00
{
if ( ! list | | ! * list )
return False ;
DEBUG ( 10 , ( " user_in_list: checking user %s in list \n " , user ) ) ;
while ( * list ) {
DEBUG ( 10 , ( " user_in_list: checking user |%s| against |%s| \n " ,
user , * list ) ) ;
/*
* Check raw username .
*/
if ( strequal ( user , * list ) )
return ( True ) ;
/*
* Now check to see if any combination
* of UNIX and netgroups has been specified .
*/
if ( * * list = = ' @ ' ) {
/*
* Old behaviour . Check netgroup list
* followed by UNIX list .
*/
if ( user_in_netgroup ( user , * list + 1 ) )
return True ;
if ( user_in_group ( user , * list + 1 ) )
return True ;
} else if ( * * list = = ' + ' ) {
if ( ( * ( * list + 1 ) ) = = ' & ' ) {
/*
* Search UNIX list followed by netgroup .
*/
if ( user_in_group ( user , * list + 2 ) )
return True ;
if ( user_in_netgroup ( user , * list + 2 ) )
return True ;
} else {
/*
* Just search UNIX list .
*/
if ( user_in_group ( user , * list + 1 ) )
return True ;
}
} else if ( * * list = = ' & ' ) {
if ( * ( * list + 1 ) = = ' + ' ) {
/*
* Search netgroup list followed by UNIX list .
*/
if ( user_in_netgroup ( user , * list + 2 ) )
return True ;
if ( user_in_group ( user , * list + 2 ) )
return True ;
} else {
/*
* Just search netgroup list .
*/
if ( user_in_netgroup ( user , * list + 1 ) )
return True ;
}
}
2007-08-21 06:04:24 +04:00
2006-02-13 20:08:25 +03:00
list + + ;
}
return ( False ) ;
}
1999-12-13 16:27:58 +03:00
/****************************************************************************
2003-07-17 22:55:40 +04:00
Check if a username is valid .
1999-12-13 16:27:58 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-17 22:55:40 +04:00
2007-10-19 04:40:25 +04:00
static bool user_ok ( const char * user , int snum )
1999-12-13 16:27:58 +03:00
{
2001-07-25 00:02:48 +04:00
char * * valid , * * invalid ;
2007-10-19 04:40:25 +04:00
bool ret ;
1999-12-13 16:27:58 +03:00
2001-07-25 00:02:48 +04:00
valid = invalid = NULL ;
ret = True ;
1999-12-13 16:27:58 +03:00
2001-07-25 00:02:48 +04:00
if ( lp_invalid_users ( snum ) ) {
2008-10-12 02:56:56 +04:00
invalid = str_list_copy ( talloc_tos ( ) , lp_invalid_users ( snum ) ) ;
2005-12-17 19:31:04 +03:00
if ( invalid & &
str_list_substitute ( invalid , " %S " , lp_servicename ( snum ) ) ) {
2006-07-11 22:01:26 +04:00
/* This is used in sec=share only, so no current user
* around to pass to str_list_sub_basic ( ) */
if ( invalid & & str_list_sub_basic ( invalid , " " , " " ) ) {
2005-12-17 19:31:04 +03:00
ret = ! user_in_list ( user ,
2006-02-04 01:19:41 +03:00
( const char * * ) invalid ) ;
2003-09-26 23:28:20 +04:00
}
2001-07-25 00:02:48 +04:00
}
1999-12-13 16:27:58 +03:00
}
2008-02-04 23:05:41 +03:00
TALLOC_FREE ( invalid ) ;
2001-07-25 00:02:48 +04:00
if ( ret & & lp_valid_users ( snum ) ) {
2008-10-12 02:56:56 +04:00
valid = str_list_copy ( talloc_tos ( ) , lp_valid_users ( snum ) ) ;
2005-12-17 19:31:04 +03:00
if ( valid & &
str_list_substitute ( valid , " %S " , lp_servicename ( snum ) ) ) {
2006-07-11 22:01:26 +04:00
/* This is used in sec=share only, so no current user
* around to pass to str_list_sub_basic ( ) */
if ( valid & & str_list_sub_basic ( valid , " " , " " ) ) {
2006-02-04 01:19:41 +03:00
ret = user_in_list ( user , ( const char * * ) valid ) ;
2003-09-26 23:28:20 +04:00
}
2001-07-25 00:02:48 +04:00
}
}
2008-02-04 23:05:41 +03:00
TALLOC_FREE ( valid ) ;
1999-12-13 16:27:58 +03:00
if ( ret & & lp_onlyuser ( snum ) ) {
2008-11-07 05:53:00 +03:00
char * * user_list = str_list_make_v3 (
2008-02-04 22:57:35 +03:00
talloc_tos ( ) , lp_username ( snum ) , NULL ) ;
2005-12-17 19:31:04 +03:00
if ( user_list & &
str_list_substitute ( user_list , " %S " ,
lp_servicename ( snum ) ) ) {
2006-02-04 01:19:41 +03:00
ret = user_in_list ( user , ( const char * * ) user_list ) ;
2001-07-25 00:02:48 +04:00
}
2008-02-04 22:57:35 +03:00
TALLOC_FREE ( user_list ) ;
1999-12-13 16:27:58 +03:00
}
return ( ret ) ;
}
1996-05-04 11:50:46 +04:00
/****************************************************************************
2003-07-17 22:55:40 +04:00
Validate a group username entry . Return the username or NULL .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2003-07-17 22:55:40 +04:00
2001-10-31 13:46:25 +03:00
static char * validate_group ( char * group , DATA_BLOB password , int snum )
1996-05-04 11:50:46 +04:00
{
1999-12-13 16:27:58 +03:00
# ifdef HAVE_NETGROUP
{
char * host , * user , * domain ;
setnetgrent ( group ) ;
while ( getnetgrent ( & host , & user , & domain ) ) {
if ( user ) {
2006-02-04 01:19:41 +03:00
if ( user_ok ( user , snum ) & &
2001-10-31 13:46:25 +03:00
password_ok ( user , password ) ) {
1999-12-13 16:27:58 +03:00
endnetgrent ( ) ;
return ( user ) ;
}
}
}
endnetgrent ( ) ;
1996-05-04 11:50:46 +04:00
}
# endif
2007-08-21 06:04:24 +04:00
1999-12-13 16:27:58 +03:00
# ifdef HAVE_GETGRENT
1996-05-04 11:50:46 +04:00
{
1999-12-13 16:27:58 +03:00
struct group * gptr ;
setgrent ( ) ;
while ( ( gptr = ( struct group * ) getgrent ( ) ) ) {
2000-01-04 04:01:27 +03:00
if ( strequal ( gptr - > gr_name , group ) )
break ;
}
/*
* As user_ok can recurse doing a getgrent ( ) , we must
2007-11-13 23:51:31 +03:00
* copy the member list onto the heap before
2000-01-04 04:01:27 +03:00
* use . Bug pointed out by leon @ eatworms . swmed . edu .
*/
if ( gptr ) {
2007-11-13 23:51:31 +03:00
char * member_list = NULL ;
size_t list_len = 0 ;
2000-01-04 04:01:27 +03:00
char * member ;
int i ;
2007-11-13 23:51:31 +03:00
for ( i = 0 ; gptr - > gr_mem & & gptr - > gr_mem [ i ] ; i + + ) {
list_len + = strlen ( gptr - > gr_mem [ i ] ) + 1 ;
}
list_len + + ;
2007-11-16 02:34:37 +03:00
member_list = ( char * ) SMB_MALLOC ( list_len ) ;
2007-11-13 23:51:31 +03:00
if ( ! member_list ) {
endgrent ( ) ;
return NULL ;
}
2000-01-04 04:01:27 +03:00
* member_list = ' \0 ' ;
member = member_list ;
for ( i = 0 ; gptr - > gr_mem & & gptr - > gr_mem [ i ] ; i + + ) {
2006-02-04 01:19:41 +03:00
size_t member_len = strlen ( gptr - > gr_mem [ i ] ) + 1 ;
2007-11-13 23:51:31 +03:00
DEBUG ( 10 , ( " validate_group: = gr_mem = "
" %s \n " , gptr - > gr_mem [ i ] ) ) ;
safe_strcpy ( member , gptr - > gr_mem [ i ] ,
list_len - ( member - member_list ) ) ;
member + = member_len ;
2000-01-04 04:01:27 +03:00
}
endgrent ( ) ;
member = member_list ;
while ( * member ) {
2007-11-13 23:51:31 +03:00
if ( user_ok ( member , snum ) & &
password_ok ( member , password ) ) {
char * name = talloc_strdup ( talloc_tos ( ) ,
member ) ;
SAFE_FREE ( member_list ) ;
return name ;
1999-12-13 16:27:58 +03:00
}
2000-01-04 04:01:27 +03:00
2006-02-04 01:19:41 +03:00
DEBUG ( 10 , ( " validate_group = member = %s \n " ,
member ) ) ;
2000-01-04 04:01:27 +03:00
member + = strlen ( member ) + 1 ;
1999-12-13 16:27:58 +03:00
}
2007-11-13 23:51:31 +03:00
SAFE_FREE ( member_list ) ;
2000-01-04 04:01:27 +03:00
} else {
endgrent ( ) ;
return NULL ;
1999-12-13 16:27:58 +03:00
}
1996-05-04 11:50:46 +04:00
}
# endif
1999-12-13 16:27:58 +03:00
return ( NULL ) ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
2001-06-22 04:57:59 +04:00
Check for authority to login to a service with a given username / password .
Note this is * NOT * used when logging on using sessionsetup_and_X .
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-06-22 04:57:59 +04:00
2007-10-19 04:40:25 +04:00
bool authorise_login ( int snum , fstring user , DATA_BLOB password ,
bool * guest )
1996-05-04 11:50:46 +04:00
{
2007-10-19 04:40:25 +04:00
bool ok = False ;
2007-08-21 06:04:24 +04:00
2004-10-11 04:32:31 +04:00
# ifdef DEBUG_PASSWORD
2005-12-18 16:54:53 +03:00
DEBUG ( 100 , ( " authorise_login: checking authorisation on "
" user=%s pass=%s \n " , user , password . data ) ) ;
1996-05-04 11:50:46 +04:00
# endif
2001-06-22 04:57:59 +04:00
* guest = False ;
2007-08-21 06:04:24 +04:00
2001-06-22 04:57:59 +04:00
/* there are several possibilities:
1 ) login as the given user with given password
2007-08-21 06:04:24 +04:00
2 ) login as a previously registered username with the given
2005-12-18 16:54:53 +03:00
password
2001-06-22 04:57:59 +04:00
3 ) login as a session list username with the given password
4 ) login as a previously validated user / password pair
5 ) login as the " user = " user with given password
2007-08-21 06:04:24 +04:00
6 ) login as the " user = " user with no password
2005-12-18 16:54:53 +03:00
( guest connection )
2001-06-22 04:57:59 +04:00
7 ) login as guest user with no password
if the service is guest_only then steps 1 to 5 are skipped
*/
2002-07-15 14:35:28 +04:00
/* now check the list of session users */
if ( ! ok ) {
char * auser ;
2004-05-05 06:58:43 +04:00
char * user_list = NULL ;
2008-01-23 13:04:10 +03:00
char * saveptr ;
2004-05-05 06:58:43 +04:00
if ( session_userlist )
2004-12-07 21:25:53 +03:00
user_list = SMB_STRDUP ( session_userlist ) ;
2004-05-06 19:29:02 +04:00
else
2004-12-07 21:25:53 +03:00
user_list = SMB_STRDUP ( " " ) ;
2004-05-05 06:58:43 +04:00
2002-07-15 14:35:28 +04:00
if ( ! user_list )
return ( False ) ;
2007-08-21 06:04:24 +04:00
2008-01-23 13:04:10 +03:00
for ( auser = strtok_r ( user_list , LIST_SEP , & saveptr ) ;
! ok & & auser ;
auser = strtok_r ( NULL , LIST_SEP , & saveptr ) ) {
2002-07-15 14:35:28 +04:00
fstring user2 ;
fstrcpy ( user2 , auser ) ;
2006-02-04 01:19:41 +03:00
if ( ! user_ok ( user2 , snum ) )
2002-07-15 14:35:28 +04:00
continue ;
2007-08-21 06:04:24 +04:00
2002-07-15 14:35:28 +04:00
if ( password_ok ( user2 , password ) ) {
2001-06-22 04:57:59 +04:00
ok = True ;
2002-07-15 14:35:28 +04:00
fstrcpy ( user , user2 ) ;
2005-12-18 16:54:53 +03:00
DEBUG ( 3 , ( " authorise_login: ACCEPTED: session "
" list username (%s) and given "
" password ok \n " , user ) ) ;
2001-06-22 04:57:59 +04:00
}
}
2005-12-18 16:54:53 +03:00
2002-07-15 14:35:28 +04:00
SAFE_FREE ( user_list ) ;
}
2007-08-21 06:04:24 +04:00
2002-07-15 14:35:28 +04:00
/* check the user= fields and the given password */
if ( ! ok & & lp_username ( snum ) ) {
2007-11-13 23:51:31 +03:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
2002-07-15 14:35:28 +04:00
char * auser ;
2007-11-13 23:51:31 +03:00
char * user_list = talloc_strdup ( ctx , lp_username ( snum ) ) ;
2008-01-23 13:04:10 +03:00
char * saveptr ;
2007-11-13 23:51:31 +03:00
if ( ! user_list ) {
goto check_guest ;
}
2007-08-21 06:04:24 +04:00
2007-11-13 23:51:31 +03:00
user_list = talloc_string_sub ( ctx ,
user_list ,
" %S " ,
lp_servicename ( snum ) ) ;
if ( ! user_list ) {
goto check_guest ;
}
2007-08-21 06:04:24 +04:00
2008-01-23 13:04:10 +03:00
for ( auser = strtok_r ( user_list , LIST_SEP , & saveptr ) ;
auser & & ! ok ;
auser = strtok_r ( NULL , LIST_SEP , & saveptr ) ) {
2002-07-15 14:35:28 +04:00
if ( * auser = = ' @ ' ) {
auser = validate_group ( auser + 1 , password , snum ) ;
if ( auser ) {
ok = True ;
fstrcpy ( user , auser ) ;
2005-12-18 16:54:53 +03:00
DEBUG ( 3 , ( " authorise_login: ACCEPTED: "
" group username and given "
" password ok (%s) \n " , user ) ) ;
2002-07-15 14:35:28 +04:00
}
} else {
2001-06-22 04:57:59 +04:00
fstring user2 ;
fstrcpy ( user2 , auser ) ;
2006-02-04 01:19:41 +03:00
if ( user_ok ( user2 , snum ) & &
2005-12-18 16:54:53 +03:00
password_ok ( user2 , password ) ) {
2001-06-22 04:57:59 +04:00
ok = True ;
fstrcpy ( user , user2 ) ;
2005-12-18 16:54:53 +03:00
DEBUG ( 3 , ( " authorise_login: ACCEPTED: "
" user list username and "
" given password ok (%s) \n " ,
user ) ) ;
2001-06-22 04:57:59 +04:00
}
}
}
2002-07-15 14:35:28 +04:00
}
2001-06-22 04:57:59 +04:00
2007-11-13 23:51:31 +03:00
check_guest :
2001-06-22 04:57:59 +04:00
/* check for a normal guest connection */
if ( ! ok & & GUEST_OK ( snum ) ) {
2007-12-19 17:02:59 +03:00
struct passwd * guest_pw ;
2001-06-22 04:57:59 +04:00
fstring guestname ;
2003-04-23 17:27:35 +04:00
fstrcpy ( guestname , lp_guestaccount ( ) ) ;
2007-12-19 17:02:59 +03:00
guest_pw = Get_Pwnam_alloc ( talloc_tos ( ) , guestname ) ;
if ( guest_pw ! = NULL ) {
2001-06-22 04:57:59 +04:00
fstrcpy ( user , guestname ) ;
ok = True ;
2005-12-18 16:54:53 +03:00
DEBUG ( 3 , ( " authorise_login: ACCEPTED: guest account "
" and guest ok (%s) \n " , user ) ) ;
2001-06-22 04:57:59 +04:00
} else {
2005-12-18 16:54:53 +03:00
DEBUG ( 0 , ( " authorise_login: Invalid guest account "
" %s?? \n " , guestname ) ) ;
2001-06-22 04:57:59 +04:00
}
2007-12-19 17:02:59 +03:00
TALLOC_FREE ( guest_pw ) ;
2001-06-22 04:57:59 +04:00
* guest = True ;
1996-05-04 11:50:46 +04:00
}
2006-02-04 01:19:41 +03:00
if ( ok & & ! user_ok ( user , snum ) ) {
2001-06-22 04:57:59 +04:00
DEBUG ( 0 , ( " authorise_login: rejected invalid user %s \n " , user ) ) ;
ok = False ;
}
1996-05-04 11:50:46 +04:00
2001-06-22 04:57:59 +04:00
return ( ok ) ;
1996-05-04 11:50:46 +04:00
}