2002-08-19 07:17:03 +04:00
/*
Samba Unix / Linux SMB client library
net ads cldap functions
Copyright ( C ) 2001 Andrew Tridgell ( tridge @ samba . org )
2003-02-28 06:35:45 +03:00
Copyright ( C ) 2003 Jim McDonough ( jmcd @ us . ibm . com )
2008-05-07 17:49:09 +04:00
Copyright ( C ) 2008 Guenther Deschner ( gd @ samba . org )
2009-02-24 21:05:33 +03:00
Copyright ( C ) 2009 Stefan Metzmacher ( metze @ samba . org )
2002-08-19 07:17:03 +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
2002-08-19 07:17:03 +04:00
( at your option ) any later version .
2008-12-25 16:29:39 +03:00
2002-08-19 07:17:03 +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 .
2008-12-25 16:29:39 +03:00
2002-08-19 07:17:03 +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/>.
2002-08-19 07:17:03 +04:00
*/
# include "includes.h"
2009-02-24 21:05:33 +03:00
# include "../libcli/cldap/cldap.h"
# include "../lib/tsocket/tsocket.h"
2010-05-18 21:40:31 +04:00
# include "libads/cldap.h"
2002-08-19 19:30:26 +04:00
2006-05-12 19:17:35 +04:00
/*******************************************************************
do a cldap netlogon query . Always 389 / udp
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-04-21 21:47:13 +04:00
bool ads_cldap_netlogon ( TALLOC_CTX * mem_ctx ,
2011-04-26 11:03:32 +04:00
struct sockaddr_storage * ss ,
2008-04-21 21:47:13 +04:00
const char * realm ,
2008-09-24 00:21:52 +04:00
uint32_t nt_version ,
2009-02-24 21:05:33 +03:00
struct netlogon_samlogon_response * * _reply )
2002-08-19 19:30:26 +04:00
{
2009-02-24 21:05:33 +03:00
struct cldap_socket * cldap ;
struct cldap_netlogon io ;
struct netlogon_samlogon_response * reply ;
NTSTATUS status ;
2009-06-09 02:21:48 +04:00
char addrstr [ INET6_ADDRSTRLEN ] ;
2009-02-24 21:05:33 +03:00
const char * dest_str ;
2002-08-19 19:30:26 +04:00
int ret ;
2009-02-24 21:05:33 +03:00
struct tsocket_address * dest_addr ;
2002-08-19 19:30:26 +04:00
2011-04-26 11:03:32 +04:00
dest_str = print_sockaddr ( addrstr , sizeof ( addrstr ) , ss ) ;
2002-08-19 07:17:03 +04:00
2009-06-09 02:21:48 +04:00
ret = tsocket_address_inet_from_strings ( mem_ctx , " ip " ,
2009-02-24 21:05:33 +03:00
dest_str , LDAP_PORT ,
& dest_addr ) ;
2002-08-19 19:30:26 +04:00
if ( ret ! = 0 ) {
2009-02-24 21:05:33 +03:00
status = map_nt_error_from_unix ( errno ) ;
DEBUG ( 2 , ( " Failed to create cldap tsocket_address for %s - %s \n " ,
dest_str , nt_errstr ( status ) ) ) ;
return false ;
}
/*
* as we use a connected udp socket
*/
status = cldap_socket_init ( mem_ctx , NULL , NULL , dest_addr , & cldap ) ;
TALLOC_FREE ( dest_addr ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 2 , ( " Failed to create cldap socket to %s: %s \n " ,
dest_str , nt_errstr ( status ) ) ) ;
return false ;
2002-08-19 19:30:26 +04:00
}
2002-08-19 19:59:14 +04:00
2009-02-24 21:05:33 +03:00
reply = talloc ( cldap , struct netlogon_samlogon_response ) ;
if ( ! reply ) {
goto failed ;
2002-08-23 02:50:57 +04:00
}
2009-02-24 21:05:33 +03:00
/*
* as we use a connected socket , so we don ' t need to specify the
* destination
*/
io . in . dest_address = NULL ;
io . in . dest_port = 0 ;
io . in . realm = realm ;
io . in . host = NULL ;
io . in . user = NULL ;
io . in . domain_guid = NULL ;
io . in . domain_sid = NULL ;
io . in . acct_control = 0 ;
io . in . version = nt_version ;
io . in . map_response = false ;
2010-05-10 02:42:06 +04:00
status = cldap_netlogon ( cldap , reply , & io ) ;
2009-02-24 21:05:33 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 2 , ( " cldap_netlogon() failed: %s \n " , nt_errstr ( status ) ) ) ;
goto failed ;
}
* reply = io . out . netlogon ;
* _reply = talloc_move ( mem_ctx , & reply ) ;
TALLOC_FREE ( cldap ) ;
return true ;
failed :
TALLOC_FREE ( cldap ) ;
return false ;
2002-08-19 07:17:03 +04:00
}
2008-05-07 17:49:09 +04:00
/*******************************************************************
do a cldap netlogon query . Always 389 / udp
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool ads_cldap_netlogon_5 ( TALLOC_CTX * mem_ctx ,
2011-04-26 11:03:32 +04:00
struct sockaddr_storage * ss ,
2008-05-07 17:49:09 +04:00
const char * realm ,
2008-09-24 00:21:52 +04:00
struct NETLOGON_SAM_LOGON_RESPONSE_EX * reply5 )
2008-05-07 17:49:09 +04:00
{
2008-09-23 23:08:25 +04:00
uint32_t nt_version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX ;
2008-09-24 00:21:52 +04:00
struct netlogon_samlogon_response * reply = NULL ;
2008-05-07 17:49:09 +04:00
bool ret ;
2011-04-26 11:03:32 +04:00
ret = ads_cldap_netlogon ( mem_ctx , ss , realm , nt_version , & reply ) ;
2008-05-07 17:49:09 +04:00
if ( ! ret ) {
return false ;
}
2008-09-24 00:21:52 +04:00
if ( reply - > ntver ! = NETLOGON_NT_VERSION_5EX ) {
DEBUG ( 0 , ( " ads_cldap_netlogon_5: nt_version mismatch: 0x%08x \n " ,
reply - > ntver ) ) ;
2008-05-07 17:49:09 +04:00
return false ;
}
2008-10-02 10:09:25 +04:00
* reply5 = reply - > data . nt5_ex ;
2008-05-07 23:31:59 +04:00
return true ;
}