24cbc184add1637991d329c04cf001f6e89685eb
[samba.git] / source / 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
44         for (i=0;i<256;i++) {
45                 search.in.version = i;
46                 printf("Trying netlogon level %d\n", i);
47                 status = cldap_netlogon(cldap, mem_ctx, &search);
48                 if (!NT_STATUS_IS_OK(status)) {
49                         printf("netlogon[%d] failed - %s\n", i, nt_errstr(status));
50                 } else {
51                         NDR_PRINT_UNION_DEBUG(nbt_cldap_netlogon, i & 0xF, 
52                                               &search.out.netlogon);
53                 }
54         }
55
56         printf("cldap_search gave %s\n", nt_errstr(status));
57
58         return True;    
59 }
60
61 BOOL torture_cldap(void)
62 {
63         TALLOC_CTX *mem_ctx;
64         BOOL ret = True;
65         const char *host = lp_parm_string(-1, "torture", "host");
66
67         mem_ctx = talloc_init("torture_cldap");
68
69         ret &= test_cldap_netlogon(mem_ctx, host);
70
71         talloc_free(mem_ctx);
72
73         return ret;
74 }
75