2004-08-13 07:10:46 +00:00
/*
2020-08-03 21:48:41 +02:00
Unix SMB / CIFS Implementation .
2004-08-13 07:10:46 +00:00
LDAP protocol helper functions for SAMBA
Copyright ( C ) Stefan Metzmacher 2004
Copyright ( C ) Simo Sorce 2004
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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2004-08-13 07:10:46 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-08-13 07:10:46 +00:00
*/
2004-08-12 08:00:45 +00:00
# include "includes.h"
2008-04-02 04:53:27 +02:00
# include "libcli/ldap/ldap_client.h"
2008-04-27 14:02:46 +01:00
# include "torture/smbtorture.h"
2006-06-17 02:20:39 +00:00
# include "torture/ldap/proto.h"
2004-08-12 08:00:45 +00:00
2004-08-12 22:25:01 +00:00
NTSTATUS torture_ldap_bind ( struct ldap_connection * conn , const char * userdn , const char * password )
{
2005-06-16 05:39:40 +00:00
NTSTATUS status ;
2004-08-12 22:25:01 +00:00
2005-06-16 05:39:40 +00:00
status = ldap_bind_simple ( conn , userdn , password ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Failed to bind with provided credentials - %s \n " ,
nt_errstr ( status ) ) ;
2004-08-12 22:25:01 +00:00
}
2005-06-16 05:39:40 +00:00
return status ;
2004-08-13 05:26:38 +00:00
}
2008-04-02 04:53:27 +02:00
NTSTATUS torture_ldap_bind_sasl ( struct ldap_connection * conn ,
2007-12-08 23:32:43 +01:00
struct cli_credentials * creds ,
struct loadparm_context * lp_ctx )
2004-08-13 05:26:38 +00:00
{
2005-06-16 05:39:40 +00:00
NTSTATUS status ;
2004-08-13 05:26:38 +00:00
2007-12-08 23:32:43 +01:00
status = ldap_bind_sasl ( conn , creds , lp_ctx ) ;
2005-06-16 05:39:40 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Failed sasl bind with provided credentials - %s \n " ,
nt_errstr ( status ) ) ;
2004-08-12 22:25:01 +00:00
}
2005-06-16 05:39:40 +00:00
return status ;
2004-08-12 22:25:01 +00:00
}
2004-08-12 08:00:45 +00:00
/* open a ldap connection to a server */
2008-04-02 04:53:27 +02:00
NTSTATUS torture_ldap_connection ( struct torture_context * tctx ,
2007-12-10 04:33:16 +01:00
struct ldap_connection * * conn ,
const char * url )
2004-08-12 08:00:45 +00:00
{
2005-06-16 05:39:40 +00:00
NTSTATUS status ;
2004-08-12 08:00:45 +00:00
if ( ! url ) {
printf ( " You must specify a url string \n " ) ;
return NT_STATUS_INVALID_PARAMETER ;
}
2008-04-21 17:58:23 -04:00
* conn = ldap4_new_connection ( tctx , tctx - > lp_ctx , tctx - > ev ) ;
2005-06-16 05:39:40 +00:00
status = ldap_connect ( * conn , url ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " Failed to connect to ldap server '%s' - %s \n " ,
url , nt_errstr ( status ) ) ;
2004-08-12 08:00:45 +00:00
}
2005-06-16 05:39:40 +00:00
return status ;
2005-05-11 14:38:13 +00:00
}
2004-08-12 08:00:45 +00:00
/* close an ldap connection to a server */
NTSTATUS torture_ldap_close ( struct ldap_connection * conn )
{
2010-09-27 08:14:54 +02:00
struct ldap_message * msg ;
struct ldap_request * req ;
NTSTATUS status ;
2013-09-18 15:29:38 -07:00
printf ( " Closing the connection... \n " ) ;
2010-09-27 08:14:54 +02:00
msg = new_ldap_message ( conn ) ;
if ( ! msg ) {
talloc_free ( conn ) ;
return NT_STATUS_NO_MEMORY ;
}
2013-09-18 15:29:38 -07:00
printf ( " Try a UnbindRequest \n " ) ;
2010-09-27 08:14:54 +02:00
msg - > type = LDAP_TAG_UnbindRequest ;
req = ldap_request_send ( conn , msg ) ;
if ( ! req ) {
talloc_free ( conn ) ;
return NT_STATUS_NO_MEMORY ;
}
status = ldap_request_wait ( req ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
printf ( " error in ldap unbind request - %s \n " , nt_errstr ( status ) ) ;
talloc_free ( conn ) ;
return status ;
}
2005-06-16 05:39:40 +00:00
talloc_free ( conn ) ;
2004-08-12 08:00:45 +00:00
return NT_STATUS_OK ;
}
2006-06-17 02:20:39 +00:00
2017-04-20 12:24:43 -07:00
NTSTATUS torture_ldap_init ( TALLOC_CTX * ctx )
2006-06-17 02:20:39 +00:00
{
2017-04-24 14:41:26 -07:00
struct torture_suite * suite = torture_suite_create ( ctx , " ldap " ) ;
2010-12-11 03:26:31 +01:00
torture_suite_add_simple_test ( suite , " bench-cldap " , torture_bench_cldap ) ;
torture_suite_add_simple_test ( suite , " basic " , torture_ldap_basic ) ;
torture_suite_add_simple_test ( suite , " sort " , torture_ldap_sort ) ;
torture_suite_add_simple_test ( suite , " cldap " , torture_cldap ) ;
2013-10-28 14:21:20 +01:00
torture_suite_add_simple_test ( suite , " netlogon-udp " , torture_netlogon_udp ) ;
torture_suite_add_simple_test ( suite , " netlogon-tcp " , torture_netlogon_tcp ) ;
2010-12-11 03:26:31 +01:00
torture_suite_add_simple_test ( suite , " schema " , torture_ldap_schema ) ;
torture_suite_add_simple_test ( suite , " uptodatevector " , torture_ldap_uptodatevector ) ;
torture_suite_add_simple_test ( suite , " nested-search " , test_ldap_nested_search ) ;
2006-10-16 13:06:41 +00:00
2007-02-20 14:39:13 +00:00
suite - > description = talloc_strdup ( suite , " LDAP and CLDAP tests " ) ;
2006-10-16 13:06:41 +00:00
2017-04-24 14:41:26 -07:00
torture_register_suite ( ctx , suite ) ;
2006-06-17 02:20:39 +00:00
return NT_STATUS_OK ;
}