2005-12-19 09:56:45 +03:00
/*
Unix SMB / CIFS implementation .
auth functions
Copyright ( C ) Simo Sorce 2005
Copyright ( C ) Andrew Tridgell 2005
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
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-12-19 09:56:45 +03:00
( 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
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-12-19 09:56:45 +03:00
*/
# include "includes.h"
# include "auth/auth.h"
2007-01-04 12:47:49 +03:00
/*
It ' s allowed to pass NULL as session_info ,
when the caller doesn ' t need a session_info
*/
2006-07-31 18:05:08 +04:00
_PUBLIC_ NTSTATUS authenticate_username_pw ( TALLOC_CTX * mem_ctx ,
2008-12-29 22:24:57 +03:00
struct tevent_context * ev ,
2011-05-03 04:40:33 +04:00
struct imessaging_context * msg ,
2007-12-02 19:56:09 +03:00
struct loadparm_context * lp_ctx ,
2006-07-31 18:05:08 +04:00
const char * nt4_domain ,
const char * nt4_username ,
const char * password ,
2010-11-05 01:00:13 +03:00
const uint32_t logon_parameters ,
2006-07-31 18:05:08 +04:00
struct auth_session_info * * session_info )
2005-12-19 09:56:45 +03:00
{
2011-05-07 10:14:06 +04:00
struct auth4_context * auth_context ;
2005-12-19 09:56:45 +03:00
struct auth_usersupplied_info * user_info ;
2011-02-08 08:53:13 +03:00
struct auth_user_info_dc * user_info_dc ;
2005-12-19 09:56:45 +03:00
NTSTATUS nt_status ;
TALLOC_CTX * tmp_ctx = talloc_new ( mem_ctx ) ;
if ( ! tmp_ctx ) {
return NT_STATUS_NO_MEMORY ;
}
2007-07-03 12:05:55 +04:00
nt_status = auth_context_create ( tmp_ctx ,
2006-07-31 18:05:08 +04:00
ev , msg ,
2007-12-02 19:56:09 +03:00
lp_ctx ,
2006-07-31 18:05:08 +04:00
& auth_context ) ;
2005-12-19 09:56:45 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
talloc_free ( tmp_ctx ) ;
return nt_status ;
}
2010-05-04 10:44:08 +04:00
user_info = talloc_zero ( tmp_ctx , struct auth_usersupplied_info ) ;
2005-12-19 09:56:45 +03:00
if ( ! user_info ) {
talloc_free ( tmp_ctx ) ;
return NT_STATUS_NO_MEMORY ;
}
2007-10-07 02:16:19 +04:00
user_info - > mapped_state = true ;
2005-12-19 09:56:45 +03:00
user_info - > client . account_name = nt4_username ;
user_info - > mapped . account_name = nt4_username ;
user_info - > client . domain_name = nt4_domain ;
user_info - > mapped . domain_name = nt4_domain ;
user_info - > workstation_name = NULL ;
user_info - > remote_host = NULL ;
user_info - > password_state = AUTH_PASSWORD_PLAIN ;
user_info - > password . plaintext = talloc_strdup ( user_info , password ) ;
user_info - > flags = USER_INFO_CASE_INSENSITIVE_USERNAME |
USER_INFO_DONT_CHECK_UNIX_ACCOUNT ;
2010-11-05 01:00:13 +03:00
user_info - > logon_parameters = logon_parameters |
MSV1_0_CLEARTEXT_PASSWORD_ALLOWED |
MSV1_0_CLEARTEXT_PASSWORD_SUPPLIED ;
2005-12-19 09:56:45 +03:00
2011-02-08 08:53:13 +03:00
nt_status = auth_check_password ( auth_context , tmp_ctx , user_info , & user_info_dc ) ;
2005-12-19 09:56:45 +03:00
if ( ! NT_STATUS_IS_OK ( nt_status ) ) {
talloc_free ( tmp_ctx ) ;
return nt_status ;
}
2007-01-04 12:47:49 +03:00
if ( session_info ) {
2010-04-19 09:51:57 +04:00
uint32_t flags = AUTH_SESSION_INFO_DEFAULT_GROUPS ;
2011-02-08 08:53:13 +03:00
if ( user_info_dc - > info - > authenticated ) {
2010-04-19 09:51:57 +04:00
flags | = AUTH_SESSION_INFO_AUTHENTICATED ;
}
2012-02-04 10:49:49 +04:00
nt_status = auth_context - > generate_session_info ( auth_context ,
tmp_ctx ,
2011-02-08 08:53:13 +03:00
user_info_dc ,
2012-01-30 14:49:33 +04:00
nt4_username ,
2010-04-19 09:51:57 +04:00
flags ,
session_info ) ;
2005-12-19 09:56:45 +03:00
2007-01-04 12:47:49 +03:00
if ( NT_STATUS_IS_OK ( nt_status ) ) {
talloc_steal ( mem_ctx , * session_info ) ;
}
2005-12-19 09:56:45 +03:00
}
2007-01-04 12:47:49 +03:00
talloc_free ( tmp_ctx ) ;
2005-12-19 09:56:45 +03:00
return nt_status ;
}