LCOV - code coverage report
Current view: top level - source4/torture/ldap - common.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 42 59 71.2 %
Date: 2024-02-28 12:06:22 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS Implementation.
       3             :    LDAP protocol helper functions for SAMBA
       4             :    
       5             :    Copyright (C) Stefan Metzmacher 2004
       6             :    Copyright (C) Simo Sorce 2004
       7             :     
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             :    
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "libcli/ldap/ldap_client.h"
      25             : #include "torture/smbtorture.h"
      26             : #include "torture/ldap/proto.h"
      27             : 
      28           2 : NTSTATUS torture_ldap_bind(struct ldap_connection *conn, const char *userdn, const char *password)
      29             : {
      30           0 :         NTSTATUS status;
      31             : 
      32           2 :         status = ldap_bind_simple(conn, userdn, password);
      33           2 :         if (!NT_STATUS_IS_OK(status)) {
      34           1 :                 printf("Failed to bind with provided credentials - %s\n", 
      35             :                        nt_errstr(status));
      36             :         }
      37             : 
      38           2 :         return status;
      39             : }
      40             : 
      41           1 : NTSTATUS torture_ldap_bind_sasl(struct ldap_connection *conn, 
      42             :                                 struct cli_credentials *creds, 
      43             :                                 struct loadparm_context *lp_ctx)
      44             : {
      45           0 :         NTSTATUS status;
      46             : 
      47           1 :         status = ldap_bind_sasl(conn, creds, lp_ctx);
      48           1 :         if (!NT_STATUS_IS_OK(status)) {
      49           0 :                 printf("Failed sasl bind with provided credentials - %s\n", 
      50             :                        nt_errstr(status));
      51             :         }
      52             :  
      53           1 :         return status;
      54             : }
      55             : 
      56             : /* open a ldap connection to a server */
      57           2 : NTSTATUS torture_ldap_connection(struct torture_context *tctx, 
      58             :                                           struct ldap_connection **conn, 
      59             :                                           const char *url)
      60             : {
      61           0 :         NTSTATUS status;
      62             : 
      63           2 :         if (!url) {
      64           0 :                 printf("You must specify a url string\n");
      65           0 :                 return NT_STATUS_INVALID_PARAMETER;
      66             :         }
      67             : 
      68           2 :         *conn = ldap4_new_connection(tctx, tctx->lp_ctx, tctx->ev);
      69             : 
      70           2 :         status = ldap_connect(*conn, url);
      71           2 :         if (!NT_STATUS_IS_OK(status)) {
      72           0 :                 printf("Failed to connect to ldap server '%s' - %s\n",
      73             :                        url, nt_errstr(status));
      74             :         }
      75             : 
      76           2 :         return status;
      77             : }
      78             : 
      79             : /* close an ldap connection to a server */
      80           1 : NTSTATUS torture_ldap_close(struct ldap_connection *conn)
      81             : {
      82           0 :         struct ldap_message *msg;
      83           0 :         struct ldap_request *req;
      84           0 :         NTSTATUS status;
      85             : 
      86           1 :         printf("Closing the connection...\n");
      87             : 
      88           1 :         msg = new_ldap_message(conn);
      89           1 :         if (!msg) {
      90           0 :                 talloc_free(conn);
      91           0 :                 return NT_STATUS_NO_MEMORY;
      92             :         }
      93             : 
      94           1 :         printf(" Try a UnbindRequest\n");
      95             : 
      96           1 :         msg->type = LDAP_TAG_UnbindRequest;
      97             : 
      98           1 :         req = ldap_request_send(conn, msg);
      99           1 :         if (!req) {
     100           0 :                 talloc_free(conn);
     101           0 :                 return NT_STATUS_NO_MEMORY;
     102             :         }
     103             : 
     104           1 :         status = ldap_request_wait(req);
     105           1 :         if (!NT_STATUS_IS_OK(status)) {
     106           0 :                 printf("error in ldap unbind request - %s\n", nt_errstr(status));
     107           0 :                 talloc_free(conn);
     108           0 :                 return status;
     109             :         }
     110             : 
     111           1 :         talloc_free(conn);
     112           1 :         return NT_STATUS_OK;
     113             : }
     114             : 
     115        2379 : NTSTATUS torture_ldap_init(TALLOC_CTX *ctx)
     116             : {
     117        2379 :         struct torture_suite *suite = torture_suite_create(ctx, "ldap");
     118        2379 :         torture_suite_add_simple_test(suite, "bench-cldap", torture_bench_cldap);
     119        2379 :         torture_suite_add_simple_test(suite, "basic", torture_ldap_basic);
     120        2379 :         torture_suite_add_simple_test(suite, "sort", torture_ldap_sort);
     121        2379 :         torture_suite_add_simple_test(suite, "cldap", torture_cldap);
     122        2379 :         torture_suite_add_simple_test(suite, "netlogon-udp", torture_netlogon_udp);
     123        2379 :         torture_suite_add_simple_test(suite, "netlogon-tcp", torture_netlogon_tcp);
     124        2379 :         torture_suite_add_simple_test(suite, "schema", torture_ldap_schema);
     125        2379 :         torture_suite_add_simple_test(suite, "uptodatevector", torture_ldap_uptodatevector);
     126        2379 :         torture_suite_add_simple_test(suite, "nested-search", test_ldap_nested_search);
     127        2379 :         torture_suite_add_simple_test(
     128             :                 suite, "session-expiry", torture_ldap_session_expiry);
     129             : 
     130        2379 :         suite->description = talloc_strdup(suite, "LDAP and CLDAP tests");
     131             : 
     132        2379 :         torture_register_suite(ctx, suite);
     133             : 
     134        2379 :         return NT_STATUS_OK;
     135             : }

Generated by: LCOV version 1.14