2 Unix SMB/CIFS mplementation.
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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.
25 #include "libcli/cldap/cldap.h"
26 #include "libcli/ldap/ldap.h"
27 #include "lib/events/events.h"
29 #define CHECK_STATUS(status, correct) do { \
30 if (!NT_STATUS_EQUAL(status, correct)) { \
31 printf("(%s) Incorrect status %s - should be %s\n", \
32 __location__, nt_errstr(status), nt_errstr(correct)); \
39 test netlogon operations
41 static BOOL test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
43 struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
45 struct cldap_netlogon search;
46 union nbt_cldap_netlogon n1;
51 search.in.dest_address = dest;
52 search.in.realm = lp_realm();
53 search.in.host = lp_netbios_name();
54 search.in.user = NULL;
55 search.in.domain_guid = NULL;
56 search.in.domain_sid = NULL;
57 search.in.acct_control = -1;
59 printf("Scanning for netlogon levels\n");
61 search.in.version = i;
62 printf("Trying netlogon level %d\n", i);
63 status = cldap_netlogon(cldap, mem_ctx, &search);
64 CHECK_STATUS(status, NT_STATUS_OK);
66 NDR_PRINT_UNION_DEBUG(nbt_cldap_netlogon, i & 0xF,
67 &search.out.netlogon);
71 search.in.version = 6;
72 status = cldap_netlogon(cldap, mem_ctx, &search);
73 CHECK_STATUS(status, NT_STATUS_OK);
74 n1 = search.out.netlogon;
76 printf("Trying with User=Administrator\n");
78 search.in.user = "Administrator";
79 status = cldap_netlogon(cldap, mem_ctx, &search);
80 CHECK_STATUS(status, NT_STATUS_OK);
82 printf("Trying with a GUID\n");
83 search.in.realm = NULL;
84 search.in.domain_guid = GUID_string(mem_ctx, &n1.logon4.domain_uuid);
85 status = cldap_netlogon(cldap, mem_ctx, &search);
86 CHECK_STATUS(status, NT_STATUS_OK);
88 printf("Trying with a incorrect GUID\n");
90 search.in.user = NULL;
91 search.in.domain_guid = GUID_string(mem_ctx, &guid);
92 status = cldap_netlogon(cldap, mem_ctx, &search);
93 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
95 printf("Trying with a incorrect domain and correct guid\n");
96 search.in.realm = "test.example.com";
97 search.in.domain_guid = GUID_string(mem_ctx, &n1.logon4.domain_uuid);
98 status = cldap_netlogon(cldap, mem_ctx, &search);
99 CHECK_STATUS(status, NT_STATUS_OK);
101 printf("Trying with a incorrect domain and incorrect guid\n");
102 search.in.realm = "test.example.com";
103 search.in.domain_guid = GUID_string(mem_ctx, &guid);
104 status = cldap_netlogon(cldap, mem_ctx, &search);
105 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
107 printf("Trying with a AAC\n");
108 search.in.acct_control = 0x180;
109 search.in.realm = lp_realm();
110 status = cldap_netlogon(cldap, mem_ctx, &search);
111 CHECK_STATUS(status, NT_STATUS_OK);
113 printf("Trying with a bad AAC\n");
114 search.in.acct_control = 0xFF00FF00;
115 search.in.realm = lp_realm();
116 status = cldap_netlogon(cldap, mem_ctx, &search);
117 CHECK_STATUS(status, NT_STATUS_OK);
119 printf("Trying with a user only\n");
120 search.in.acct_control = -1;
121 search.in.user = "Administrator";
122 search.in.realm = NULL;
123 search.in.domain_guid = NULL;
124 status = cldap_netlogon(cldap, mem_ctx, &search);
125 CHECK_STATUS(status, NT_STATUS_OK);
127 printf("Trying without any attributes\n");
128 search.in.user = NULL;
129 search.in.host = NULL;
130 status = cldap_netlogon(cldap, mem_ctx, &search);
131 CHECK_STATUS(status, NT_STATUS_OK);
137 BOOL torture_cldap(void)
141 const char *host = lp_parm_string(-1, "torture", "host");
143 mem_ctx = talloc_init("torture_cldap");
145 ret &= test_cldap_netlogon(mem_ctx, host);
147 talloc_free(mem_ctx);