static NTSTATUS discover_dc_netbios(TALLOC_CTX *mem_ctx, const char *domain_name, uint32_t flags, struct ip_service_name **returned_dclist, int *returned_count) { NTSTATUS status; enum nbt_name_type name_type = NBT_NAME_LOGON; struct ip_service *iplist; int i; struct ip_service_name *dclist = NULL; int count; *returned_dclist = NULL; *returned_count = 0; if (lp_disable_netbios()) { return NT_STATUS_NOT_SUPPORTED; } if (flags & DS_PDC_REQUIRED) { name_type = NBT_NAME_PDC; } status = internal_resolve_name(domain_name, name_type, NULL, &iplist, &count, "lmhosts wins bcast"); if (!NT_STATUS_IS_OK(status)) { DEBUG(10,("discover_dc_netbios: failed to find DC\n")); return status; } dclist = TALLOC_ZERO_ARRAY(mem_ctx, struct ip_service_name, count); if (!dclist) { return NT_STATUS_NO_MEMORY; } for (i=0; i<count; i++) { char addr[INET6_ADDRSTRLEN]; struct ip_service_name *r = &dclist[i]; print_sockaddr(addr, sizeof(addr), &iplist[i].ss); r->ss = iplist[i].ss; r->port = iplist[i].port; r->hostname = talloc_strdup(mem_ctx, addr); if (!r->hostname) { return NT_STATUS_NO_MEMORY; } } *returned_dclist = dclist; *returned_count = count; return NT_STATUS_OK; }
static NTSTATUS dsgetdcname_rediscover(TALLOC_CTX *mem_ctx, struct messaging_context *msg_ctx, const char *domain_name, const struct GUID *domain_guid, uint32_t flags, const char *site_name, struct netr_DsRGetDCNameInfo **info) { NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND; struct ip_service_name *dclist = NULL; int num_dcs; DEBUG(10,("dsgetdcname_rediscover\n")); if (flags & DS_IS_FLAT_NAME) { if (lp_disable_netbios()) { return NT_STATUS_NOT_SUPPORTED; } status = discover_dc_netbios(mem_ctx, domain_name, flags, &dclist, &num_dcs); NT_STATUS_NOT_OK_RETURN(status); return process_dc_netbios(mem_ctx, msg_ctx, domain_name, flags, dclist, num_dcs, info); } if (flags & DS_IS_DNS_NAME) { status = discover_dc_dns(mem_ctx, domain_name, domain_guid, flags, site_name, &dclist, &num_dcs); NT_STATUS_NOT_OK_RETURN(status); return process_dc_dns(mem_ctx, domain_name, flags, dclist, num_dcs, info); } status = discover_dc_dns(mem_ctx, domain_name, domain_guid, flags, site_name, &dclist, &num_dcs); if (NT_STATUS_IS_OK(status) && num_dcs != 0) { status = process_dc_dns(mem_ctx, domain_name, flags, dclist, num_dcs, info); if (NT_STATUS_IS_OK(status)) { return status; } } if (lp_disable_netbios()) { return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND; } status = discover_dc_netbios(mem_ctx, domain_name, flags, &dclist, &num_dcs); NT_STATUS_NOT_OK_RETURN(status); return process_dc_netbios(mem_ctx, msg_ctx, domain_name, flags, dclist, num_dcs, info); }