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 "librpc/gen_ndr/ndr_nbt.h"
27 #include "torture/torture.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)); \
37 NDR_PRINT_UNION_DEBUG(nbt_cldap_netlogon, \
38 search.in.version & 0xF, \
39 &search.out.netlogon); \
44 test netlogon operations
46 static BOOL test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
48 struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
50 struct cldap_netlogon search, empty_search;
51 union nbt_cldap_netlogon n1;
57 search.in.dest_address = dest;
58 search.in.acct_control = -1;
59 search.in.version = 6;
61 empty_search = search;
63 printf("Trying without any attributes\n");
64 search = empty_search;
65 status = cldap_netlogon(cldap, mem_ctx, &search);
66 CHECK_STATUS(status, NT_STATUS_OK);
68 n1 = search.out.netlogon;
70 search.in.user = "Administrator";
71 search.in.realm = n1.logon5.dns_domain;
72 search.in.host = "__cldap_torture__";
74 printf("Scanning for netlogon levels\n");
76 search.in.version = i;
77 printf("Trying netlogon level %d\n", i);
78 status = cldap_netlogon(cldap, mem_ctx, &search);
79 CHECK_STATUS(status, NT_STATUS_OK);
82 printf("Scanning for netlogon level bits\n");
84 search.in.version = (1<<i);
85 printf("Trying netlogon level 0x%x\n", i);
86 status = cldap_netlogon(cldap, mem_ctx, &search);
87 CHECK_STATUS(status, NT_STATUS_OK);
90 search.in.version = 6;
91 status = cldap_netlogon(cldap, mem_ctx, &search);
92 CHECK_STATUS(status, NT_STATUS_OK);
94 printf("Trying with User=NULL\n");
96 search.in.user = NULL;
97 status = cldap_netlogon(cldap, mem_ctx, &search);
98 CHECK_STATUS(status, NT_STATUS_OK);
100 printf("Trying with User=Administrator\n");
102 search.in.user = "Administrator";
103 status = cldap_netlogon(cldap, mem_ctx, &search);
104 CHECK_STATUS(status, NT_STATUS_OK);
106 printf("Trying with a GUID\n");
107 search.in.realm = NULL;
108 search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
109 status = cldap_netlogon(cldap, mem_ctx, &search);
110 CHECK_STATUS(status, NT_STATUS_OK);
112 printf("Trying with a incorrect GUID\n");
113 guid = GUID_random();
114 search.in.user = NULL;
115 search.in.domain_guid = GUID_string(mem_ctx, &guid);
116 status = cldap_netlogon(cldap, mem_ctx, &search);
117 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
119 printf("Trying with a AAC\n");
120 search.in.acct_control = 0x180;
121 search.in.realm = n1.logon5.dns_domain;
122 status = cldap_netlogon(cldap, mem_ctx, &search);
123 CHECK_STATUS(status, NT_STATUS_OK);
125 printf("Trying with a bad AAC\n");
126 search.in.acct_control = 0xFF00FF00;
127 search.in.realm = n1.logon5.dns_domain;
128 status = cldap_netlogon(cldap, mem_ctx, &search);
129 CHECK_STATUS(status, NT_STATUS_OK);
131 printf("Trying with a user only\n");
132 search = empty_search;
133 search.in.user = "Administrator";
134 status = cldap_netlogon(cldap, mem_ctx, &search);
135 CHECK_STATUS(status, NT_STATUS_OK);
137 printf("Trying with just a bad username\n");
138 search.in.user = "___no_such_user___";
139 status = cldap_netlogon(cldap, mem_ctx, &search);
140 CHECK_STATUS(status, NT_STATUS_OK);
142 printf("Trying with just a bad domain\n");
143 search = empty_search;
144 search.in.realm = "___no_such_domain___";
145 status = cldap_netlogon(cldap, mem_ctx, &search);
146 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
148 printf("Trying with a incorrect domain and correct guid\n");
149 search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
150 status = cldap_netlogon(cldap, mem_ctx, &search);
151 CHECK_STATUS(status, NT_STATUS_OK);
153 printf("Trying with a incorrect domain and incorrect guid\n");
154 search.in.domain_guid = GUID_string(mem_ctx, &guid);
155 status = cldap_netlogon(cldap, mem_ctx, &search);
156 CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
158 printf("Trying with a incorrect GUID and correct domain\n");
159 search.in.domain_guid = GUID_string(mem_ctx, &guid);
160 search.in.realm = n1.logon5.dns_domain;
161 status = cldap_netlogon(cldap, mem_ctx, &search);
162 CHECK_STATUS(status, NT_STATUS_OK);
168 BOOL torture_cldap(struct torture_context *torture)
172 const char *host = lp_parm_string(-1, "torture", "host");
174 mem_ctx = talloc_init("torture_cldap");
176 ret &= test_cldap_netlogon(mem_ctx, host);
178 talloc_free(mem_ctx);