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"
27 #define CHECK_STATUS(status, correct) do { \
28 if (!NT_STATUS_EQUAL(status, correct)) { \
29 printf("(%s) Incorrect status %s - should be %s\n", \
30 __location__, nt_errstr(status), nt_errstr(correct)); \
35 NDR_PRINT_UNION_DEBUG(nbt_cldap_netlogon, \
36 search.in.version & 0xF, \
37 &search.out.netlogon); \
42 test netlogon operations
44 static BOOL test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
46 struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
48 struct cldap_netlogon search, empty_search;
49 union nbt_cldap_netlogon n1;
55 search.in.dest_address = dest;
56 search.in.acct_control = -1;
57 search.in.version = 6;
59 empty_search = search;
61 printf("Trying without any attributes\n");
62 search = empty_search;
63 status = cldap_netlogon(cldap, mem_ctx, &search);
64 CHECK_STATUS(status, NT_STATUS_OK);
66 n1 = search.out.netlogon;
68 search.in.user = "Administrator";
69 search.in.realm = n1.logon5.dns_domain;
70 search.in.host = "__cldap_torture__";
72 printf("Scanning for netlogon levels\n");
74 search.in.version = i;
75 printf("Trying netlogon level %d\n", i);
76 status = cldap_netlogon(cldap, mem_ctx, &search);
77 CHECK_STATUS(status, NT_STATUS_OK);
80 printf("Scanning for netlogon level bits\n");
82 search.in.version = (1<<i);
83 printf("Trying netlogon level 0x%x\n", i);
84 status = cldap_netlogon(cldap, mem_ctx, &search);
85 CHECK_STATUS(status, NT_STATUS_OK);
88 search.in.version = 6;
89 status = cldap_netlogon(cldap, mem_ctx, &search);
90 CHECK_STATUS(status, NT_STATUS_OK);
92 printf("Trying with User=Administrator\n");
94 search.in.user = "Administrator";
95 status = cldap_netlogon(cldap, mem_ctx, &search);
96 CHECK_STATUS(status, NT_STATUS_OK);
98 printf("Trying with a GUID\n");
99 search.in.realm = NULL;
100 search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
101 status = cldap_netlogon(cldap, mem_ctx, &search);
102 CHECK_STATUS(status, NT_STATUS_OK);
104 printf("Trying with a incorrect GUID\n");
105 guid = GUID_random();
106 search.in.user = NULL;
107 search.in.domain_guid = GUID_string(mem_ctx, &guid);
108 status = cldap_netlogon(cldap, mem_ctx, &search);
109 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
111 printf("Trying with a AAC\n");
112 search.in.acct_control = 0x180;
113 search.in.realm = n1.logon5.dns_domain;
114 status = cldap_netlogon(cldap, mem_ctx, &search);
115 CHECK_STATUS(status, NT_STATUS_OK);
117 printf("Trying with a bad AAC\n");
118 search.in.acct_control = 0xFF00FF00;
119 search.in.realm = n1.logon5.dns_domain;
120 status = cldap_netlogon(cldap, mem_ctx, &search);
121 CHECK_STATUS(status, NT_STATUS_OK);
123 printf("Trying with a user only\n");
124 search = empty_search;
125 search.in.user = "Administrator";
126 status = cldap_netlogon(cldap, mem_ctx, &search);
127 CHECK_STATUS(status, NT_STATUS_OK);
129 printf("Trying with just a bad username\n");
130 search.in.user = "___no_such_user___";
131 status = cldap_netlogon(cldap, mem_ctx, &search);
132 CHECK_STATUS(status, NT_STATUS_OK);
134 printf("Trying with just a bad domain\n");
135 search = empty_search;
136 search.in.realm = "___no_such_domain___";
137 status = cldap_netlogon(cldap, mem_ctx, &search);
138 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
140 printf("Trying with a incorrect domain and correct guid\n");
141 search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
142 status = cldap_netlogon(cldap, mem_ctx, &search);
143 CHECK_STATUS(status, NT_STATUS_OK);
145 printf("Trying with a incorrect domain and incorrect guid\n");
146 search.in.domain_guid = GUID_string(mem_ctx, &guid);
147 status = cldap_netlogon(cldap, mem_ctx, &search);
148 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
150 printf("Trying with a incorrect GUID and correct domain\n");
151 search.in.domain_guid = GUID_string(mem_ctx, &guid);
152 search.in.realm = n1.logon5.dns_domain;
153 status = cldap_netlogon(cldap, mem_ctx, &search);
154 CHECK_STATUS(status, NT_STATUS_OK);
160 BOOL torture_cldap(void)
164 const char *host = lp_parm_string(-1, "torture", "host");
166 mem_ctx = talloc_init("torture_cldap");
168 ret &= test_cldap_netlogon(mem_ctx, host);
170 talloc_free(mem_ctx);