| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
SMB torture tester - winbind struct based protocol |
| 4 |
Copyright (C) Stefan Metzmacher 2007 |
| 5 |
Copyright (C) Michael Adam 2007 |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "includes.h" |
| 22 |
#include "torture/torture.h" |
| 23 |
#include "nsswitch/libwbclient/wbclient.h" |
| 24 |
#include "nsswitch/winbind_nss_config.h" |
| 25 |
#include "nsswitch/winbind_struct_protocol.h" |
| 26 |
#include "nsswitch/libwbclient/wbclient_internal.h" |
| 27 |
#include "libcli/security/security.h" |
| 28 |
#include "librpc/gen_ndr/netlogon.h" |
| 29 |
#include "param/param.h" |
| 30 |
#include "../libcli/auth/pam_errors.h" |
| 31 |
#include "torture/winbind/proto.h" |
| 32 |
#include "lib/util/string_wrappers.h" |
| 33 |
|
| 34 |
#define DO_STRUCT_REQ_REP_EXT(op,req,rep,expected,strict,warnaction,cmt) do { \ |
| 35 |
const char *__cmt = (cmt); \ |
| 36 |
wbcErr __wbc_status = WBC_ERR_UNKNOWN_FAILURE; \ |
| 37 |
NSS_STATUS __got, __expected = (expected); \ |
| 38 |
__wbc_status = wbcRequestResponse(NULL, op, req, rep); \ |
| 39 |
switch (__wbc_status) { \ |
| 40 |
case WBC_ERR_SUCCESS: \ |
| 41 |
__got = NSS_STATUS_SUCCESS; \ |
| 42 |
break; \ |
| 43 |
case WBC_ERR_WINBIND_NOT_AVAILABLE: \ |
| 44 |
__got = NSS_STATUS_UNAVAIL; \ |
| 45 |
break; \ |
| 46 |
case WBC_ERR_DOMAIN_NOT_FOUND: \ |
| 47 |
__got = NSS_STATUS_NOTFOUND; \ |
| 48 |
break; \ |
| 49 |
default: \ |
| 50 |
torture_result(torture, TORTURE_FAIL, \ |
| 51 |
__location__ ": " __STRING(op) \ |
| 52 |
" returned unmapped %s, expected nss %d%s%s", \ |
| 53 |
wbcErrorString(__wbc_status), __expected, \ |
| 54 |
(__cmt) ? ": " : "", \ |
| 55 |
(__cmt) ? (__cmt) : ""); \ |
| 56 |
return false; \ |
| 57 |
} \ |
| 58 |
if (__got != __expected) { \ |
| 59 |
if (strict) { \ |
| 60 |
torture_result(torture, TORTURE_FAIL, \ |
| 61 |
__location__ ": " __STRING(op) \ |
| 62 |
" returned %s, got %d , expected %d%s%s", \ |
| 63 |
wbcErrorString(__wbc_status), __got, __expected, \ |
| 64 |
(__cmt) ? ": " : "", \ |
| 65 |
(__cmt) ? (__cmt) : ""); \ |
| 66 |
return false; \ |
| 67 |
} else { \ |
| 68 |
torture_warning(torture, \ |
| 69 |
__location__ ": " __STRING(op) \ |
| 70 |
" returned %s, got %d , expected %d%s%s", \ |
| 71 |
wbcErrorString(__wbc_status), __got, __expected, \ |
| 72 |
(__cmt) ? ": " : "", \ |
| 73 |
(__cmt) ? (__cmt) : ""); \ |
| 74 |
warnaction; \ |
| 75 |
} \ |
| 76 |
} \ |
| 77 |
} while(0) |
| 78 |
|
| 79 |
#undef _STRUCT_NOOP |
| 80 |
#define _STRUCT_NOOP do {} while(0); |
| 81 |
#define DO_STRUCT_REQ_REP(op,req,rep) do { \ |
| 82 |
DO_STRUCT_REQ_REP_EXT(op,req,rep,NSS_STATUS_SUCCESS,true, _STRUCT_NOOP, NULL); \ |
| 83 |
} while (0) |
| 84 |
|
| 85 |
static bool torture_winbind_struct_interface_version(struct torture_context *torture) |
| 86 |
{ |
| 87 |
struct winbindd_request req; |
| 88 |
struct winbindd_response rep; |
| 89 |
|
| 90 |
ZERO_STRUCT(req); |
| 91 |
ZERO_STRUCT(rep); |
| 92 |
|
| 93 |
torture_comment(torture, "Running WINBINDD_INTERFACE_VERSION (struct based)\n"); |
| 94 |
|
| 95 |
DO_STRUCT_REQ_REP(WINBINDD_INTERFACE_VERSION, &req, &rep); |
| 96 |
|
| 97 |
torture_assert_int_equal(torture, |
| 98 |
rep.data.interface_version, |
| 99 |
WINBIND_INTERFACE_VERSION, |
| 100 |
"winbind server and client doesn't match"); |
| 101 |
|
| 102 |
return true; |
| 103 |
} |
| 104 |
|
| 105 |
static bool torture_winbind_struct_ping(struct torture_context *torture) |
| 106 |
{ |
| 107 |
struct timeval tv = timeval_current(); |
| 108 |
int timelimit = torture_setting_int(torture, "timelimit", 5); |
| 109 |
uint32_t total = 0; |
| 110 |
|
| 111 |
torture_comment(torture, |
| 112 |
"Running WINBINDD_PING (struct based) for %d seconds\n", |
| 113 |
timelimit); |
| 114 |
|
| 115 |
while (timeval_elapsed(&tv) < timelimit) { |
| 116 |
DO_STRUCT_REQ_REP(WINBINDD_PING, NULL, NULL); |
| 117 |
total++; |
| 118 |
} |
| 119 |
|
| 120 |
torture_comment(torture, |
| 121 |
"%u (%.1f/s) WINBINDD_PING (struct based)\n", |
| 122 |
total, total / timeval_elapsed(&tv)); |
| 123 |
|
| 124 |
return true; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
static char winbind_separator(struct torture_context *torture) |
| 129 |
{ |
| 130 |
struct winbindd_response rep; |
| 131 |
|
| 132 |
ZERO_STRUCT(rep); |
| 133 |
|
| 134 |
DO_STRUCT_REQ_REP(WINBINDD_INFO, NULL, &rep); |
| 135 |
|
| 136 |
return rep.data.info.winbind_separator; |
| 137 |
} |
| 138 |
|
| 139 |
static bool torture_winbind_struct_info(struct torture_context *torture) |
| 140 |
{ |
| 141 |
struct winbindd_response rep; |
| 142 |
const char *separator; |
| 143 |
|
| 144 |
ZERO_STRUCT(rep); |
| 145 |
|
| 146 |
torture_comment(torture, "Running WINBINDD_INFO (struct based)\n"); |
| 147 |
|
| 148 |
DO_STRUCT_REQ_REP(WINBINDD_INFO, NULL, &rep); |
| 149 |
|
| 150 |
separator = torture_setting_string(torture, |
| 151 |
"winbindd_separator", |
| 152 |
lpcfg_winbind_separator(torture->lp_ctx)); |
| 153 |
|
| 154 |
torture_assert_int_equal(torture, |
| 155 |
rep.data.info.winbind_separator, |
| 156 |
*separator, |
| 157 |
"winbind separator doesn't match"); |
| 158 |
|
| 159 |
torture_comment(torture, "Samba Version '%s'\n", |
| 160 |
rep.data.info.samba_version); |
| 161 |
|
| 162 |
return true; |
| 163 |
} |
| 164 |
|
| 165 |
static bool torture_winbind_struct_priv_pipe_dir(struct torture_context *torture) |
| 166 |
{ |
| 167 |
struct winbindd_response rep; |
| 168 |
const char *got_dir; |
| 169 |
|
| 170 |
ZERO_STRUCT(rep); |
| 171 |
|
| 172 |
torture_comment(torture, "Running WINBINDD_PRIV_PIPE_DIR (struct based)\n"); |
| 173 |
|
| 174 |
DO_STRUCT_REQ_REP(WINBINDD_PRIV_PIPE_DIR, NULL, &rep); |
| 175 |
|
| 176 |
got_dir = (const char *)rep.extra_data.data; |
| 177 |
|
| 178 |
torture_assert(torture, got_dir, "NULL WINBINDD_PRIV_PIPE_DIR\n"); |
| 179 |
|
| 180 |
SAFE_FREE(rep.extra_data.data); |
| 181 |
return true; |
| 182 |
} |
| 183 |
|
| 184 |
static bool torture_winbind_struct_netbios_name(struct torture_context *torture) |
| 185 |
{ |
| 186 |
struct winbindd_response rep; |
| 187 |
const char *expected; |
| 188 |
|
| 189 |
ZERO_STRUCT(rep); |
| 190 |
|
| 191 |
torture_comment(torture, "Running WINBINDD_NETBIOS_NAME (struct based)\n"); |
| 192 |
|
| 193 |
DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME, NULL, &rep); |
| 194 |
|
| 195 |
expected = torture_setting_string(torture, |
| 196 |
"winbindd_netbios_name", |
| 197 |
lpcfg_netbios_name(torture->lp_ctx)); |
| 198 |
expected = strupper_talloc(torture, expected); |
| 199 |
|
| 200 |
torture_assert_str_equal(torture, |
| 201 |
rep.data.netbios_name, expected, |
| 202 |
"winbindd's netbios name doesn't match"); |
| 203 |
|
| 204 |
return true; |
| 205 |
} |
| 206 |
|
| 207 |
static bool get_winbind_domain(struct torture_context *torture, char **domain) |
| 208 |
{ |
| 209 |
struct winbindd_response rep; |
| 210 |
|
| 211 |
ZERO_STRUCT(rep); |
| 212 |
|
| 213 |
DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_NAME, NULL, &rep); |
| 214 |
|
| 215 |
*domain = talloc_strdup(torture, rep.data.domain_name); |
| 216 |
torture_assert(torture, domain, "talloc error"); |
| 217 |
|
| 218 |
return true; |
| 219 |
} |
| 220 |
|
| 221 |
static bool torture_winbind_struct_domain_name(struct torture_context *torture) |
| 222 |
{ |
| 223 |
const char *expected; |
| 224 |
char *domain; |
| 225 |
|
| 226 |
torture_comment(torture, "Running WINBINDD_DOMAIN_NAME (struct based)\n"); |
| 227 |
|
| 228 |
expected = torture_setting_string(torture, |
| 229 |
"winbindd_netbios_domain", |
| 230 |
lpcfg_workgroup(torture->lp_ctx)); |
| 231 |
|
| 232 |
get_winbind_domain(torture, &domain); |
| 233 |
|
| 234 |
torture_assert_str_equal(torture, domain, expected, |
| 235 |
"winbindd's netbios domain doesn't match"); |
| 236 |
|
| 237 |
return true; |
| 238 |
} |
| 239 |
|
| 240 |
static bool torture_winbind_struct_check_machacc(struct torture_context *torture) |
| 241 |
{ |
| 242 |
bool ok; |
| 243 |
bool strict = torture_setting_bool(torture, "strict mode", false); |
| 244 |
struct winbindd_response rep; |
| 245 |
|
| 246 |
ZERO_STRUCT(rep); |
| 247 |
|
| 248 |
torture_comment(torture, "Running WINBINDD_CHECK_MACHACC (struct based)\n"); |
| 249 |
|
| 250 |
ok = true; |
| 251 |
DO_STRUCT_REQ_REP_EXT(WINBINDD_CHECK_MACHACC, NULL, &rep, |
| 252 |
NSS_STATUS_SUCCESS, strict, ok = false, |
| 253 |
"WINBINDD_CHECK_MACHACC"); |
| 254 |
|
| 255 |
if (!ok) { |
| 256 |
torture_assert(torture, |
| 257 |
strlen(rep.data.auth.nt_status_string)>0, |
| 258 |
"Failed with empty nt_status_string"); |
| 259 |
|
| 260 |
torture_warning(torture,"%s:%s:%s:%d\n", |
| 261 |
nt_errstr(NT_STATUS(rep.data.auth.nt_status)), |
| 262 |
rep.data.auth.nt_status_string, |
| 263 |
rep.data.auth.error_string, |
| 264 |
rep.data.auth.pam_error); |
| 265 |
return true; |
| 266 |
} |
| 267 |
|
| 268 |
torture_assert_ntstatus_ok(torture, |
| 269 |
NT_STATUS(rep.data.auth.nt_status), |
| 270 |
"WINBINDD_CHECK_MACHACC ok: nt_status"); |
| 271 |
|
| 272 |
torture_assert_str_equal(torture, |
| 273 |
rep.data.auth.nt_status_string, |
| 274 |
nt_errstr(NT_STATUS_OK), |
| 275 |
"WINBINDD_CHECK_MACHACC ok:nt_status_string"); |
| 276 |
|
| 277 |
torture_assert_str_equal(torture, |
| 278 |
rep.data.auth.error_string, |
| 279 |
get_friendly_nt_error_msg(NT_STATUS_OK), |
| 280 |
"WINBINDD_CHECK_MACHACC ok: error_string"); |
| 281 |
|
| 282 |
torture_assert_int_equal(torture, |
| 283 |
rep.data.auth.pam_error, |
| 284 |
nt_status_to_pam(NT_STATUS_OK), |
| 285 |
"WINBINDD_CHECK_MACHACC ok: pam_error"); |
| 286 |
|
| 287 |
return true; |
| 288 |
} |
| 289 |
|
| 290 |
struct torture_trust_domain { |
| 291 |
const char *netbios_name; |
| 292 |
const char *dns_name; |
| 293 |
struct dom_sid *sid; |
| 294 |
}; |
| 295 |
|
| 296 |
static bool get_trusted_domains(struct torture_context *torture, |
| 297 |
struct torture_trust_domain **_d) |
| 298 |
{ |
| 299 |
struct winbindd_request req; |
| 300 |
struct winbindd_response rep; |
| 301 |
struct torture_trust_domain *d = NULL; |
| 302 |
uint32_t dcount = 0; |
| 303 |
char *line = NULL; |
| 304 |
const char *extra_data; |
| 305 |
|
| 306 |
ZERO_STRUCT(req); |
| 307 |
ZERO_STRUCT(rep); |
| 308 |
|
| 309 |
DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep); |
| 310 |
|
| 311 |
extra_data = (char *)rep.extra_data.data; |
| 312 |
torture_assert(torture, extra_data != NULL, |
| 313 |
"Trust list was NULL: the list of trusted domain " |
| 314 |
"should be returned, with at least 2 entries " |
| 315 |
"(BUILTIN, and the local domain)"); |
| 316 |
|
| 317 |
while (next_token_talloc(torture, &extra_data, &line, "\n")) { |
| 318 |
char *p, *lp; |
| 319 |
|
| 320 |
d = talloc_realloc_zero(torture, |
| 321 |
d, |
| 322 |
struct torture_trust_domain, |
| 323 |
dcount + 2); |
| 324 |
|
| 325 |
lp = line; |
| 326 |
p = strchr(lp, '\\'); |
| 327 |
torture_assert(torture, p, "missing 1st '\\' in line"); |
| 328 |
*p = 0; |
| 329 |
d[dcount].netbios_name = talloc_strdup(d, lp); |
| 330 |
torture_assert(torture, strlen(d[dcount].netbios_name) > 0, |
| 331 |
"empty netbios_name"); |
| 332 |
|
| 333 |
lp = p+1; |
| 334 |
p = strchr(lp, '\\'); |
| 335 |
torture_assert(torture, p, "missing 2nd '\\' in line"); |
| 336 |
*p = 0; |
| 337 |
d[dcount].dns_name = talloc_strdup(d, lp); |
| 338 |
/* it's ok to have an empty dns_name */ |
| 339 |
|
| 340 |
lp = p+1; |
| 341 |
d[dcount].sid = dom_sid_parse_talloc(d, lp); |
| 342 |
torture_assert(torture, d[dcount].sid, |
| 343 |
"failed to parse sid"); |
| 344 |
|
| 345 |
dcount++; |
| 346 |
TALLOC_FREE(line); |
| 347 |
} |
| 348 |
SAFE_FREE(rep.extra_data.data); |
| 349 |
|
| 350 |
torture_assert(torture, dcount >= 2, |
| 351 |
"The list of trusted domain should contain 2 entries " |
| 352 |
"(BUILTIN, and the local domain)"); |
| 353 |
|
| 354 |
*_d = d; |
| 355 |
return true; |
| 356 |
} |
| 357 |
|
| 358 |
static bool torture_winbind_struct_list_trustdom(struct torture_context *torture) |
| 359 |
{ |
| 360 |
struct winbindd_request req; |
| 361 |
struct winbindd_response rep; |
| 362 |
char *list1; |
| 363 |
char *list2; |
| 364 |
bool ok; |
| 365 |
struct torture_trust_domain *listd = NULL; |
| 366 |
uint32_t i; |
| 367 |
|
| 368 |
torture_comment(torture, "Running WINBINDD_LIST_TRUSTDOM (struct based)\n"); |
| 369 |
|
| 370 |
ZERO_STRUCT(req); |
| 371 |
ZERO_STRUCT(rep); |
| 372 |
|
| 373 |
req.data.list_all_domains = false; |
| 374 |
|
| 375 |
DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep); |
| 376 |
|
| 377 |
list1 = (char *)rep.extra_data.data; |
| 378 |
|
| 379 |
torture_comment(torture, "%s\n", list1); |
| 380 |
|
| 381 |
ZERO_STRUCT(req); |
| 382 |
ZERO_STRUCT(rep); |
| 383 |
|
| 384 |
req.data.list_all_domains = true; |
| 385 |
|
| 386 |
DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep); |
| 387 |
|
| 388 |
list2 = (char *)rep.extra_data.data; |
| 389 |
|
| 390 |
/* |
| 391 |
* The list_all_domains parameter should be ignored |
| 392 |
*/ |
| 393 |
torture_assert_str_equal(torture, list2, list1, "list_all_domains not ignored"); |
| 394 |
|
| 395 |
SAFE_FREE(list1); |
| 396 |
SAFE_FREE(list2); |
| 397 |
|
| 398 |
ok = get_trusted_domains(torture, &listd); |
| 399 |
torture_assert(torture, ok, "failed to get trust list"); |
| 400 |
|
| 401 |
for (i=0; listd && listd[i].netbios_name; i++) { |
| 402 |
if (i == 0) { |
| 403 |
struct dom_sid *builtin_sid; |
| 404 |
|
| 405 |
builtin_sid = dom_sid_parse_talloc(torture, SID_BUILTIN); |
| 406 |
|
| 407 |
torture_assert_str_equal(torture, |
| 408 |
listd[i].netbios_name, |
| 409 |
NAME_BUILTIN, |
| 410 |
"first domain should be 'BUILTIN'"); |
| 411 |
|
| 412 |
torture_assert_str_equal(torture, |
| 413 |
listd[i].dns_name, |
| 414 |
"", |
| 415 |
"BUILTIN domain should not have a dns name"); |
| 416 |
|
| 417 |
ok = dom_sid_equal(builtin_sid, |
| 418 |
listd[i].sid); |
| 419 |
torture_assert(torture, ok, "BUILTIN domain should have S-1-5-32"); |
| 420 |
|
| 421 |
continue; |
| 422 |
} |
| 423 |
|
| 424 |
/* |
| 425 |
* TODO: verify the content of the 2nd and 3rd (in member server mode) |
| 426 |
* domain entries |
| 427 |
*/ |
| 428 |
} |
| 429 |
|
| 430 |
return true; |
| 431 |
} |
| 432 |
|
| 433 |
static bool torture_winbind_struct_domain_info(struct torture_context *torture) |
| 434 |
{ |
| 435 |
bool ok; |
| 436 |
struct torture_trust_domain *listd = NULL; |
| 437 |
uint32_t i; |
| 438 |
|
| 439 |
torture_comment(torture, "Running WINBINDD_DOMAIN_INFO (struct based)\n"); |
| 440 |
|
| 441 |
ok = get_trusted_domains(torture, &listd); |
| 442 |
torture_assert(torture, ok, "failed to get trust list"); |
| 443 |
|
| 444 |
for (i=0; listd && listd[i].netbios_name; i++) { |
| 445 |
torture_comment(torture, "LIST[%u] '%s' => '%s' [%s]\n", |
| 446 |
(unsigned)i, |
| 447 |
listd[i].netbios_name, |
| 448 |
listd[i].dns_name, |
| 449 |
dom_sid_string(torture, listd[i].sid)); |
| 450 |
} |
| 451 |
|
| 452 |
for (i=0; listd && listd[i].netbios_name; i++) { |
| 453 |
struct winbindd_request req; |
| 454 |
struct winbindd_response rep; |
| 455 |
struct dom_sid *sid; |
| 456 |
char *flagstr = talloc_strdup(torture," "); |
| 457 |
|
| 458 |
ZERO_STRUCT(req); |
| 459 |
ZERO_STRUCT(rep); |
| 460 |
|
| 461 |
fstrcpy(req.domain_name, listd[i].netbios_name); |
| 462 |
|
| 463 |
DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_INFO, &req, &rep); |
| 464 |
|
| 465 |
if (rep.data.domain_info.primary) { |
| 466 |
flagstr = talloc_strdup_append(flagstr, "PR "); |
| 467 |
} |
| 468 |
|
| 469 |
if (rep.data.domain_info.active_directory) { |
| 470 |
torture_assert(torture, |
| 471 |
strlen(rep.data.domain_info.alt_name)>0, |
| 472 |
"Active Directory without DNS name"); |
| 473 |
flagstr = talloc_strdup_append(flagstr, "AD "); |
| 474 |
} |
| 475 |
|
| 476 |
if (rep.data.domain_info.native_mode) { |
| 477 |
torture_assert(torture, |
| 478 |
rep.data.domain_info.active_directory, |
| 479 |
"Native-Mode, but no Active Directory"); |
| 480 |
flagstr = talloc_strdup_append(flagstr, "NA "); |
| 481 |
} |
| 482 |
|
| 483 |
torture_comment(torture, "DOMAIN[%u] '%s' => '%s' [%s] [%s]\n", |
| 484 |
(unsigned)i, |
| 485 |
rep.data.domain_info.name, |
| 486 |
rep.data.domain_info.alt_name, |
| 487 |
flagstr, |
| 488 |
rep.data.domain_info.sid); |
| 489 |
|
| 490 |
sid = dom_sid_parse_talloc(torture, rep.data.domain_info.sid); |
| 491 |
torture_assert(torture, sid, "Failed to parse SID"); |
| 492 |
|
| 493 |
ok = dom_sid_equal(listd[i].sid, sid); |
| 494 |
torture_assert(torture, ok, talloc_asprintf(torture, "SID's doesn't match [%s] != [%s]", |
| 495 |
dom_sid_string(torture, listd[i].sid), |
| 496 |
dom_sid_string(torture, sid))); |
| 497 |
|
| 498 |
torture_assert_str_equal(torture, |
| 499 |
rep.data.domain_info.name, |
| 500 |
listd[i].netbios_name, |
| 501 |
"Netbios domain name doesn't match"); |
| 502 |
|
| 503 |
torture_assert_str_equal(torture, |
| 504 |
rep.data.domain_info.alt_name, |
| 505 |
listd[i].dns_name, |
| 506 |
"DNS domain name doesn't match"); |
| 507 |
} |
| 508 |
|
| 509 |
return true; |
| 510 |
} |
| 511 |
|
| 512 |
static bool torture_winbind_struct_getdcname(struct torture_context *torture) |
| 513 |
{ |
| 514 |
bool ok; |
| 515 |
bool strict = torture_setting_bool(torture, "strict mode", false); |
| 516 |
const char *domain_name = torture_setting_string(torture, |
| 517 |
"winbindd_netbios_domain", |
| 518 |
lpcfg_workgroup(torture->lp_ctx)); |
| 519 |
struct torture_trust_domain *listd = NULL; |
| 520 |
uint32_t i, count = 0; |
| 521 |
|
| 522 |
torture_comment(torture, "Running WINBINDD_GETDCNAME (struct based)\n"); |
| 523 |
|
| 524 |
ok = get_trusted_domains(torture, &listd); |
| 525 |
torture_assert(torture, ok, "failed to get trust list"); |
| 526 |
|
| 527 |
for (i=0; listd && listd[i].netbios_name; i++) { |
| 528 |
struct winbindd_request req; |
| 529 |
struct winbindd_response rep; |
| 530 |
|
| 531 |
/* getdcname is not expected to work on "BUILTIN" or our own |
| 532 |
* domain */ |
| 533 |
if (strequal(listd[i].netbios_name, "BUILTIN") || |
| 534 |
strequal(listd[i].netbios_name, domain_name)) { |
| 535 |
continue; |
| 536 |
} |
| 537 |
|
| 538 |
ZERO_STRUCT(req); |
| 539 |
ZERO_STRUCT(rep); |
| 540 |
|
| 541 |
fstrcpy(req.domain_name, listd[i].netbios_name); |
| 542 |
|
| 543 |
ok = true; |
| 544 |
DO_STRUCT_REQ_REP_EXT(WINBINDD_GETDCNAME, &req, &rep, |
| 545 |
NSS_STATUS_SUCCESS, |
| 546 |
(i <2 || strict), ok = false, |
| 547 |
talloc_asprintf(torture, "DOMAIN '%s'", |
| 548 |
req.domain_name)); |
| 549 |
if (!ok) continue; |
| 550 |
|
| 551 |
/* TODO: check rep.data.dc_name; */ |
| 552 |
torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n", |
| 553 |
req.domain_name, rep.data.dc_name); |
| 554 |
count++; |
| 555 |
} |
| 556 |
|
| 557 |
if (strict) { |
| 558 |
torture_assert(torture, count > 0, |
| 559 |
"WiNBINDD_GETDCNAME was not tested"); |
| 560 |
} |
| 561 |
return true; |
| 562 |
} |
| 563 |
|
| 564 |
static bool torture_winbind_struct_dsgetdcname(struct torture_context *torture) |
| 565 |
{ |
| 566 |
bool ok; |
| 567 |
bool strict = torture_setting_bool(torture, "strict mode", false); |
| 568 |
struct torture_trust_domain *listd = NULL; |
| 569 |
uint32_t i; |
| 570 |
uint32_t count = 0; |
| 571 |
|
| 572 |
torture_comment(torture, "Running WINBINDD_DSGETDCNAME (struct based)\n"); |
| 573 |
|
| 574 |
ok = get_trusted_domains(torture, &listd); |
| 575 |
torture_assert(torture, ok, "failed to get trust list"); |
| 576 |
|
| 577 |
for (i=0; listd && listd[i].netbios_name; i++) { |
| 578 |
struct winbindd_request req; |
| 579 |
struct winbindd_response rep; |
| 580 |
|
| 581 |
ZERO_STRUCT(req); |
| 582 |
ZERO_STRUCT(rep); |
| 583 |
|
| 584 |
if (strlen(listd[i].dns_name) == 0) continue; |
| 585 |
|
| 586 |
/* |
| 587 |
* TODO: remove this and let winbindd give no dns name |
| 588 |
* for NT4 domains |
| 589 |
*/ |
| 590 |
if (strcmp(listd[i].dns_name, listd[i].netbios_name) == 0) { |
| 591 |
continue; |
| 592 |
} |
| 593 |
|
| 594 |
fstrcpy(req.domain_name, listd[i].dns_name); |
| 595 |
|
| 596 |
/* TODO: test more flag combinations */ |
| 597 |
req.flags = DS_DIRECTORY_SERVICE_REQUIRED; |
| 598 |
|
| 599 |
ok = true; |
| 600 |
DO_STRUCT_REQ_REP_EXT(WINBINDD_DSGETDCNAME, &req, &rep, |
| 601 |
NSS_STATUS_SUCCESS, |
| 602 |
strict, ok = false, |
| 603 |
talloc_asprintf(torture, "DOMAIN '%s'", |
| 604 |
req.domain_name)); |
| 605 |
if (!ok) continue; |
| 606 |
|
| 607 |
/* TODO: check rep.data.dc_name; */ |
| 608 |
torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n", |
| 609 |
req.domain_name, rep.data.dc_name); |
| 610 |
|
| 611 |
count++; |
| 612 |
} |
| 613 |
|
| 614 |
if (count == 0) { |
| 615 |
torture_warning(torture, "WINBINDD_DSGETDCNAME" |
| 616 |
" was not tested with %d non-AD domains", |
| 617 |
i); |
| 618 |
} |
| 619 |
|
| 620 |
if (strict) { |
| 621 |
torture_assert(torture, count > 0, |
| 622 |
"WiNBINDD_DSGETDCNAME was not tested"); |
| 623 |
} |
| 624 |
|
| 625 |
return true; |
| 626 |
} |
| 627 |
|
| 628 |
static bool get_user_list(struct torture_context *torture, char ***users) |
| 629 |
{ |
| 630 |
struct winbindd_request req; |
| 631 |
struct winbindd_response rep; |
| 632 |
char **u = NULL; |
| 633 |
uint32_t count; |
| 634 |
char *name = NULL; |
| 635 |
const char *extra_data; |
| 636 |
|
| 637 |
ZERO_STRUCT(req); |
| 638 |
ZERO_STRUCT(rep); |
| 639 |
|
| 640 |
DO_STRUCT_REQ_REP(WINBINDD_LIST_USERS, &req, &rep); |
| 641 |
|
| 642 |
extra_data = (char *)rep.extra_data.data; |
| 643 |
torture_assert(torture, extra_data, "NULL extra data"); |
| 644 |
|
| 645 |
for(count = 0; |
| 646 |
next_token_talloc(torture, &extra_data, &name, ","); |
| 647 |
count++) |
| 648 |
{ |
| 649 |
u = talloc_realloc_zero(torture, u, char *, count + 2); |
| 650 |
u[count] = talloc_move(u, &name); |
| 651 |
} |
| 652 |
|
| 653 |
SAFE_FREE(rep.extra_data.data); |
| 654 |
|
| 655 |
*users = u; |
| 656 |
return true; |
| 657 |
} |
| 658 |
|
| 659 |
static bool torture_winbind_struct_list_users(struct torture_context *torture) |
| 660 |
{ |
| 661 |
char **users; |
| 662 |
uint32_t count; |
| 663 |
bool ok; |
| 664 |
|
| 665 |
torture_comment(torture, "Running WINBINDD_LIST_USERS (struct based)\n"); |
| 666 |
|
| 667 |
ok = get_user_list(torture, &users); |
| 668 |
torture_assert(torture, ok, "failed to get user list"); |
| 669 |
|
| 670 |
for (count = 0; users[count]; count++) { } |
| 671 |
|
| 672 |
torture_comment(torture, "got %d users\n", count); |
| 673 |
|
| 674 |
return true; |
| 675 |
} |
| 676 |
|
| 677 |
static bool get_group_list(struct torture_context *torture, |
| 678 |
unsigned int *num_entries, |
| 679 |
char ***groups) |
| 680 |
{ |
| 681 |
struct winbindd_request req; |
| 682 |
struct winbindd_response rep; |
| 683 |
char **g = NULL; |
| 684 |
uint32_t count; |
| 685 |
char *name = NULL; |
| 686 |
const char *extra_data; |
| 687 |
|
| 688 |
ZERO_STRUCT(req); |
| 689 |
ZERO_STRUCT(rep); |
| 690 |
|
| 691 |
DO_STRUCT_REQ_REP(WINBINDD_LIST_GROUPS, &req, &rep); |
| 692 |
extra_data = (char *)rep.extra_data.data; |
| 693 |
|
| 694 |
*num_entries = rep.data.num_entries; |
| 695 |
|
| 696 |
if (*num_entries == 0) { |
| 697 |
torture_assert(torture, extra_data == NULL, |
| 698 |
"extra data is null for >0 reported entries\n"); |
| 699 |
*groups = NULL; |
| 700 |
return true; |
| 701 |
} |
| 702 |
|
| 703 |
torture_assert(torture, extra_data, "NULL extra data"); |
| 704 |
|
| 705 |
for(count = 0; |
| 706 |
next_token_talloc(torture, &extra_data, &name, ","); |
| 707 |
count++) |
| 708 |
{ |
| 709 |
g = talloc_realloc_zero(torture, g, char *, count + 2); |
| 710 |
g[count] = talloc_move(g, &name); |
| 711 |
} |
| 712 |
|
| 713 |
SAFE_FREE(rep.extra_data.data); |
| 714 |
|
| 715 |
torture_assert_int_equal(torture, *num_entries, count, |
| 716 |
"Wrong number of group entries reported."); |
| 717 |
|
| 718 |
*groups = g; |
| 719 |
return true; |
| 720 |
} |
| 721 |
|
| 722 |
static bool torture_winbind_struct_list_groups(struct torture_context *torture) |
| 723 |
{ |
| 724 |
char **groups; |
| 725 |
uint32_t count; |
| 726 |
bool ok; |
| 727 |
|
| 728 |
torture_comment(torture, "Running WINBINDD_LIST_GROUPS (struct based)\n"); |
| 729 |
|
| 730 |
ok = get_group_list(torture, &count, &groups); |
| 731 |
torture_assert(torture, ok, "failed to get group list"); |
| 732 |
|
| 733 |
torture_comment(torture, "got %d groups\n", count); |
| 734 |
|
| 735 |
return true; |
| 736 |
} |
| 737 |
|
| 738 |
static bool torture_winbind_struct_setpwent(struct torture_context *torture) |
| 739 |
{ |
| 740 |
struct winbindd_request req; |
| 741 |
struct winbindd_response rep; |
| 742 |
|
| 743 |
torture_comment(torture, "Running WINBINDD_SETPWENT (struct based)\n"); |
| 744 |
|
| 745 |
ZERO_STRUCT(req); |
| 746 |
ZERO_STRUCT(rep); |
| 747 |
|
| 748 |
DO_STRUCT_REQ_REP(WINBINDD_SETPWENT, &req, &rep); |
| 749 |
|
| 750 |
return true; |
| 751 |
} |
| 752 |
|
| 753 |
static bool torture_winbind_struct_getpwent(struct torture_context *torture) |
| 754 |
{ |
| 755 |
struct winbindd_request req; |
| 756 |
struct winbindd_response rep; |
| 757 |
struct winbindd_pw *pwent; |
| 758 |
|
| 759 |
torture_comment(torture, "Running WINBINDD_GETPWENT (struct based)\n"); |
| 760 |
|
| 761 |
torture_comment(torture, " - Running WINBINDD_SETPWENT first\n"); |
| 762 |
ZERO_STRUCT(req); |
| 763 |
ZERO_STRUCT(rep); |
| 764 |
DO_STRUCT_REQ_REP(WINBINDD_SETPWENT, &req, &rep); |
| 765 |
|
| 766 |
torture_comment(torture, " - Running WINBINDD_GETPWENT now\n"); |
| 767 |
ZERO_STRUCT(req); |
| 768 |
ZERO_STRUCT(rep); |
| 769 |
req.data.num_entries = 1; |
| 770 |
if (torture_setting_bool(torture, "samba3", false)) { |
| 771 |
DO_STRUCT_REQ_REP_EXT(WINBINDD_GETPWENT, &req, &rep, |
| 772 |
NSS_STATUS_SUCCESS, false, _STRUCT_NOOP, |
| 773 |
NULL); |
| 774 |
} else { |
| 775 |
DO_STRUCT_REQ_REP(WINBINDD_GETPWENT, &req, &rep); |
| 776 |
} |
| 777 |
pwent = (struct winbindd_pw *)rep.extra_data.data; |
| 778 |
if (!torture_setting_bool(torture, "samba3", false)) { |
| 779 |
torture_assert(torture, (pwent != NULL), "NULL pwent"); |
| 780 |
} |
| 781 |
if (pwent) { |
| 782 |
torture_comment(torture, "name: %s, uid: %d, gid: %d, shell: %s\n", |
| 783 |
pwent->pw_name, pwent->pw_uid, pwent->pw_gid, |
| 784 |
pwent->pw_shell); |
| 785 |
} |
| 786 |
|
| 787 |
return true; |
| 788 |
} |
| 789 |
|
| 790 |
static bool torture_winbind_struct_endpwent(struct torture_context *torture) |
| 791 |
{ |
| 792 |
struct winbindd_request req; |
| 793 |
struct winbindd_response rep; |
| 794 |
|
| 795 |
torture_comment(torture, "Running WINBINDD_ENDPWENT (struct based)\n"); |
| 796 |
|
| 797 |
ZERO_STRUCT(req); |
| 798 |
ZERO_STRUCT(rep); |
| 799 |
|
| 800 |
DO_STRUCT_REQ_REP(WINBINDD_ENDPWENT, &req, &rep); |
| 801 |
|
| 802 |
return true; |
| 803 |
} |
| 804 |
|
| 805 |
/* Copy of parse_domain_user from winbindd_util.c. Parse a string of the |
| 806 |
form DOMAIN/user into a domain and a user */ |
| 807 |
|
| 808 |
static bool parse_domain_user(struct torture_context *torture, |
| 809 |
const char *domuser, fstring domain, |
| 810 |
fstring user) |
| 811 |
{ |
| 812 |
char *p = strchr(domuser, winbind_separator(torture)); |
| 813 |
char *dom = NULL; |
| 814 |
|
| 815 |
if (!p) { |
| 816 |
/* Maybe it was a UPN? */ |
| 817 |
if ((p = strchr(domuser, '@')) != NULL) { |
| 818 |
fstrcpy(domain, ""); |
| 819 |
fstrcpy(user, domuser); |
| 820 |
return true; |
| 821 |
} |
| 822 |
|
| 823 |
fstrcpy(user, domuser); |
| 824 |
get_winbind_domain(torture, &dom); |
| 825 |
fstrcpy(domain, dom); |
| 826 |
return true; |
| 827 |
} |
| 828 |
|
| 829 |
fstrcpy(user, p+1); |
| 830 |
fstrcpy(domain, domuser); |
| 831 |
domain[PTR_DIFF(p, domuser)] = 0; |
| 832 |
|
| 833 |
return true; |
| 834 |
} |
| 835 |
|
| 836 |
static bool lookup_name_sid_list(struct torture_context *torture, char **list) |
| 837 |
{ |
| 838 |
uint32_t count; |
| 839 |
|
| 840 |
for (count = 0; list[count]; count++) { |
| 841 |
struct winbindd_request req; |
| 842 |
struct winbindd_response rep; |
| 843 |
char *sid; |
| 844 |
char *name; |
| 845 |
const char *domain_name = torture_setting_string(torture, |
| 846 |
"winbindd_domain_without_prefix", |
| 847 |
NULL); |
| 848 |
|
| 849 |
ZERO_STRUCT(req); |
| 850 |
ZERO_STRUCT(rep); |
| 851 |
|
| 852 |
parse_domain_user(torture, list[count], req.data.name.dom_name, |
| 853 |
req.data.name.name); |
| 854 |
|
| 855 |
DO_STRUCT_REQ_REP(WINBINDD_LOOKUPNAME, &req, &rep); |
| 856 |
|
| 857 |
sid = talloc_strdup(torture, rep.data.sid.sid); |
| 858 |
|
| 859 |
ZERO_STRUCT(req); |
| 860 |
ZERO_STRUCT(rep); |
| 861 |
|
| 862 |
fstrcpy(req.data.sid, sid); |
| 863 |
|
| 864 |
DO_STRUCT_REQ_REP(WINBINDD_LOOKUPSID, &req, &rep); |
| 865 |
|
| 866 |
if (domain_name != NULL && |
| 867 |
strequal(rep.data.name.dom_name, domain_name)) |
| 868 |
{ |
| 869 |
name = talloc_asprintf(torture, "%s", |
| 870 |
rep.data.name.name); |
| 871 |
} else { |
| 872 |
name = talloc_asprintf(torture, "%s%c%s", |
| 873 |
rep.data.name.dom_name, |
| 874 |
winbind_separator(torture), |
| 875 |
rep.data.name.name); |
| 876 |
} |
| 877 |
|
| 878 |
torture_assert_casestr_equal(torture, list[count], name, |
| 879 |
"LOOKUP_SID after LOOKUP_NAME != id"); |
| 880 |
|
| 881 |
#if 0 |
| 882 |
torture_comment(torture, " %s -> %s -> %s\n", list[count], |
| 883 |
sid, name); |
| 884 |
#endif |
| 885 |
|
| 886 |
talloc_free(sid); |
| 887 |
talloc_free(name); |
| 888 |
} |
| 889 |
|
| 890 |
return true; |
| 891 |
} |
| 892 |
|
| 893 |
static bool name_is_in_list(const char *name, char **list) |
| 894 |
{ |
| 895 |
uint32_t count; |
| 896 |
|
| 897 |
for (count = 0; list && list[count]; count++) { |
| 898 |
if (strequal(name, list[count])) { |
| 899 |
return true; |
| 900 |
} |
| 901 |
} |
| 902 |
return false; |
| 903 |
} |
| 904 |
|
| 905 |
static bool torture_winbind_struct_lookup_name_sid(struct torture_context *torture) |
| 906 |
{ |
| 907 |
struct winbindd_request req; |
| 908 |
struct winbindd_response rep; |
| 909 |
const char *invalid_sid = "S-0-0-7"; |
| 910 |
char *domain = NULL; |
| 911 |
const char *invalid_user = "no one"; |
| 912 |
char *invalid_name; |
| 913 |
bool strict = torture_setting_bool(torture, "strict mode", false); |
| 914 |
char **users; |
| 915 |
char **groups; |
| 916 |
uint32_t count, num_groups; |
| 917 |
bool ok; |
| 918 |
|
| 919 |
torture_comment(torture, "Running WINBINDD_LOOKUP_NAME_SID (struct based)\n"); |
| 920 |
|
| 921 |
ok = get_user_list(torture, &users); |
| 922 |
torture_assert(torture, ok, "failed to retrieve list of users"); |
| 923 |
lookup_name_sid_list(torture, users); |
| 924 |
|
| 925 |
ok = get_group_list(torture, &num_groups, &groups); |
| 926 |
torture_assert(torture, ok, "failed to retrieve list of groups"); |
| 927 |
if (num_groups > 0) { |
| 928 |
lookup_name_sid_list(torture, groups); |
| 929 |
} |
| 930 |
|
| 931 |
ZERO_STRUCT(req); |
| 932 |
ZERO_STRUCT(rep); |
| 933 |
|
| 934 |
fstrcpy(req.data.sid, invalid_sid); |
| 935 |
|
| 936 |
ok = true; |
| 937 |
DO_STRUCT_REQ_REP_EXT(WINBINDD_LOOKUPSID, &req, &rep, |
| 938 |
NSS_STATUS_NOTFOUND, |
| 939 |
strict, |
| 940 |
ok=false, |
| 941 |
talloc_asprintf(torture, |
| 942 |
"invalid sid %s was resolved", |
| 943 |
invalid_sid)); |
| 944 |
|
| 945 |
ZERO_STRUCT(req); |
| 946 |
ZERO_STRUCT(rep); |
| 947 |
|
| 948 |
/* try to find an invalid name... */ |
| 949 |
|
| 950 |
count = 0; |
| 951 |
get_winbind_domain(torture, &domain); |
| 952 |
do { |
| 953 |
count++; |
| 954 |
invalid_name = talloc_asprintf(torture, "%s/%s%u", |
| 955 |
domain, |
| 956 |
invalid_user, count); |
| 957 |
} while(name_is_in_list(invalid_name, users) || |
| 958 |
name_is_in_list(invalid_name, groups)); |
| 959 |
|
| 960 |
fstrcpy(req.data.name.dom_name, domain); |
| 961 |
fstrcpy(req.data.name.name, |
| 962 |
talloc_asprintf(torture, "%s%u", invalid_user, |
| 963 |
count)); |
| 964 |
|
| 965 |
ok = true; |
| 966 |
DO_STRUCT_REQ_REP_EXT(WINBINDD_LOOKUPNAME, &req, &rep, |
| 967 |
NSS_STATUS_NOTFOUND, |
| 968 |
strict, |
| 969 |
ok=false, |
| 970 |
talloc_asprintf(torture, |
| 971 |
"invalid name %s was resolved", |
| 972 |
invalid_name)); |
| 973 |
|
| 974 |
talloc_free(users); |
| 975 |
talloc_free(groups); |
| 976 |
|
| 977 |
return true; |
| 978 |
} |
| 979 |
|
| 980 |
static bool torture_winbind_struct_lookup_sids_invalid( |
| 981 |
struct torture_context *torture) |
| 982 |
{ |
| 983 |
struct winbindd_request req = {0}; |
| 984 |
struct winbindd_response rep = {0}; |
| 985 |
bool strict = torture_setting_bool(torture, "strict mode", false); |
| 986 |
bool ok; |
| 987 |
|
| 988 |
torture_comment(torture, |
| 989 |
"Running WINBINDD_LOOKUP_SIDS (struct based)\n"); |
| 990 |
|
| 991 |
ok = true; |
| 992 |
DO_STRUCT_REQ_REP_EXT(WINBINDD_LOOKUPSIDS, &req, &rep, |
| 993 |
NSS_STATUS_NOTFOUND, |
| 994 |
strict, |
| 995 |
ok=false, |
| 996 |
talloc_asprintf( |
| 997 |
torture, |
| 998 |
"invalid lookupsids succeeded")); |
| 999 |
|
| 1000 |
return ok; |
| 1001 |
} |
| 1002 |
|
| 1003 |
struct torture_suite *torture_winbind_struct_init(TALLOC_CTX *ctx) |
| 1004 |
{ |
| 1005 |
struct torture_suite *suite = torture_suite_create(ctx, "struct"); |
| 1006 |
|
| 1007 |
torture_suite_add_simple_test(suite, "interface_version", torture_winbind_struct_interface_version); |
| 1008 |
torture_suite_add_simple_test(suite, "ping", torture_winbind_struct_ping); |
| 1009 |
torture_suite_add_simple_test(suite, "info", torture_winbind_struct_info); |
| 1010 |
torture_suite_add_simple_test(suite, "priv_pipe_dir", torture_winbind_struct_priv_pipe_dir); |
| 1011 |
torture_suite_add_simple_test(suite, "netbios_name", torture_winbind_struct_netbios_name); |
| 1012 |
torture_suite_add_simple_test(suite, "domain_name", torture_winbind_struct_domain_name); |
| 1013 |
torture_suite_add_simple_test(suite, "check_machacc", torture_winbind_struct_check_machacc); |
| 1014 |
torture_suite_add_simple_test(suite, "list_trustdom", torture_winbind_struct_list_trustdom); |
| 1015 |
torture_suite_add_simple_test(suite, "domain_info", torture_winbind_struct_domain_info); |
| 1016 |
torture_suite_add_simple_test(suite, "getdcname", torture_winbind_struct_getdcname); |
| 1017 |
torture_suite_add_simple_test(suite, "dsgetdcname", torture_winbind_struct_dsgetdcname); |
| 1018 |
torture_suite_add_simple_test(suite, "list_users", torture_winbind_struct_list_users); |
| 1019 |
torture_suite_add_simple_test(suite, "list_groups", torture_winbind_struct_list_groups); |
| 1020 |
torture_suite_add_simple_test(suite, "setpwent", torture_winbind_struct_setpwent); |
| 1021 |
torture_suite_add_simple_test(suite, "getpwent", torture_winbind_struct_getpwent); |
| 1022 |
torture_suite_add_simple_test(suite, "endpwent", torture_winbind_struct_endpwent); |
| 1023 |
torture_suite_add_simple_test(suite, "lookup_name_sid", torture_winbind_struct_lookup_name_sid); |
| 1024 |
torture_suite_add_simple_test( |
| 1025 |
suite, |
| 1026 |
"lookup_sids_invalid", |
| 1027 |
torture_winbind_struct_lookup_sids_invalid); |
| 1028 |
|
| 1029 |
suite->description = talloc_strdup(suite, "WINBIND - struct based protocol tests"); |
| 1030 |
|
| 1031 |
return suite; |
| 1032 |
} |