r6694: a simple CLDAP torture test
[samba.git] / source4 / torture / ldap / cldap.c
1 /* 
2    Unix SMB/CIFS mplementation.
3
4    test CLDAP operations
5    
6    Copyright (C) Andrew Tridgell 2005
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21    
22 */
23
24 #include "includes.h"
25 #include "libcli/cldap/cldap.h"
26 #include "libcli/ldap/ldap.h"
27 #include "lib/events/events.h"
28
29
30 /*
31   test netlogon operations
32 */
33 static BOOL test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
34 {
35         struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
36         NTSTATUS status;
37         struct cldap_netlogon search;
38         int i;
39
40         search.in.dest_address  = dest;
41         search.in.realm   = lp_realm();
42         search.in.host    = lp_netbios_name();
43         search.in.version = 6;
44         status = cldap_netlogon(cldap, mem_ctx, &search);
45
46         if (!NT_STATUS_IS_OK(status)) {
47                 printf("netlogon failed - %s\n", nt_errstr(status));
48         } else {
49                 NDR_PRINT_DEBUG(nbt_cldap_netlogon, &search.out.netlogon);
50         }
51
52         for (i=0;i<20;i++) {
53                 search.in.version = i;
54                 status = cldap_netlogon(cldap, mem_ctx, &search);
55                 if (!NT_STATUS_IS_OK(status)) {
56                         printf("netlogon[%d] failed - %s\n", i, nt_errstr(status));
57                 } else {
58                         NDR_PRINT_DEBUG(nbt_cldap_netlogon, &search.out.netlogon);
59                 }
60         }
61
62         printf("cldap_search gave %s\n", nt_errstr(status));
63
64         return True;    
65 }
66
67 BOOL torture_cldap(void)
68 {
69         TALLOC_CTX *mem_ctx;
70         BOOL ret = True;
71         const char *host = lp_parm_string(-1, "torture", "host");
72
73         mem_ctx = talloc_init("torture_cldap");
74
75         ret &= test_cldap_netlogon(mem_ctx, host);
76
77         talloc_free(mem_ctx);
78
79         return ret;
80 }
81