Пример #1
0
static int net_lookup_dc(int argc, const char **argv)
{
	struct ip_service *ip_list;
	struct in_addr addr;
	char *pdc_str = NULL;
	const char *domain=opt_target_workgroup;
	char *sitename = NULL;
	int count, i;

	if (argc > 0)
		domain=argv[0];

	/* first get PDC */
	if (!get_pdc_ip(domain, &addr))
		return -1;

	asprintf(&pdc_str, "%s", inet_ntoa(addr));
	d_printf("%s\n", pdc_str);

	sitename = sitename_fetch(domain);
	if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, sitename, &ip_list, &count, False))) {
		SAFE_FREE(pdc_str);
		SAFE_FREE(sitename);
		return 0;
	}
	SAFE_FREE(sitename);
	for (i=0;i<count;i++) {
		char *dc_str = inet_ntoa(ip_list[i].ip);
		if (!strequal(pdc_str, dc_str))
			d_printf("%s\n", dc_str);
	}
	SAFE_FREE(pdc_str);
	return 0;
}
Пример #2
0
NTSTATUS dsgetdcname(TALLOC_CTX *mem_ctx,
		     struct messaging_context *msg_ctx,
		     const char *domain_name,
		     const struct GUID *domain_guid,
		     const char *site_name,
		     uint32_t flags,
		     struct netr_DsRGetDCNameInfo **info)
{
	NTSTATUS status;
	const char *query_site = NULL;
	char *ptr_to_free = NULL;
	bool retry_query_with_null = false;

	if ((site_name == NULL) || (site_name[0] == '\0')) {
		ptr_to_free = sitename_fetch(mem_ctx, domain_name);
		if (ptr_to_free != NULL) {
			retry_query_with_null = true;
		}
		query_site = ptr_to_free;
	} else {
		query_site = site_name;
	}

	status = dsgetdcname_internal(mem_ctx,
				msg_ctx,
				domain_name,
				domain_guid,
				query_site,
				flags,
				info);

	TALLOC_FREE(ptr_to_free);

	if (!NT_STATUS_EQUAL(status, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND)) {
		return status;
	}

	/* Should we try again with site_name == NULL ? */
	if (retry_query_with_null) {
		status = dsgetdcname_internal(mem_ctx,
					msg_ctx,
					domain_name,
					domain_guid,
					NULL,
					flags,
					info);
	}

	return status;
}
Пример #3
0
static int net_lookup_dc(struct net_context *c, int argc, const char **argv)
{
	struct ip_service *ip_list;
	struct sockaddr_storage ss;
	char *pdc_str = NULL;
	const char *domain = NULL;
	char *sitename = NULL;
	int count, i;
	char addr[INET6_ADDRSTRLEN];
	bool sec_ads = (lp_security() == SEC_ADS);

	if (sec_ads) {
		domain = lp_realm();
	} else {
		domain = c->opt_target_workgroup;
	}

	if (argc > 0)
		domain=argv[0];

	/* first get PDC */
	if (!get_pdc_ip(domain, &ss))
		return -1;

	print_sockaddr(addr, sizeof(addr), &ss);
	if (asprintf(&pdc_str, "%s", addr) == -1) {
		return -1;
	}
	d_printf("%s\n", pdc_str);

	sitename = sitename_fetch(talloc_tos(), domain);
	if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, sitename,
					&ip_list, &count, sec_ads))) {
		SAFE_FREE(pdc_str);
		TALLOC_FREE(sitename);
		return 0;
	}
	TALLOC_FREE(sitename);
	for (i=0;i<count;i++) {
		print_sockaddr(addr, sizeof(addr), &ip_list[i].ss);
		if (!strequal(pdc_str, addr))
			d_printf("%s\n", addr);
	}
	SAFE_FREE(pdc_str);
	return 0;
}
Пример #4
0
NTSTATUS dsgetdcname(TALLOC_CTX *mem_ctx,
		     struct messaging_context *msg_ctx,
		     const char *domain_name,
		     struct GUID *domain_guid,
		     const char *site_name,
		     uint32_t flags,
		     struct netr_DsRGetDCNameInfo **info)
{
	NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
	struct netr_DsRGetDCNameInfo *myinfo = NULL;
	char *query_site = NULL;
	bool first = true;
	struct netr_DsRGetDCNameInfo *first_info = NULL;

	DEBUG(10,("dsgetdcname: domain_name: %s, "
		  "domain_guid: %s, site_name: %s, flags: 0x%08x\n",
		  domain_name,
		  domain_guid ? GUID_string(mem_ctx, domain_guid) : "(null)",
		  site_name, flags));

	*info = NULL;

	if (!check_allowed_required_flags(flags, site_name)) {
		DEBUG(0,("invalid flags specified\n"));
		return NT_STATUS_INVALID_PARAMETER;
	}

	if (!site_name) {
		query_site = sitename_fetch(domain_name);
	} else {
		query_site = SMB_STRDUP(site_name);
	}

	if (flags & DS_FORCE_REDISCOVERY) {
		goto rediscover;
	}

	status = dsgetdcname_cached(mem_ctx, msg_ctx, domain_name, domain_guid,
				    flags, query_site, &myinfo);
	if (NT_STATUS_IS_OK(status)) {
		goto done;
	}

	if (flags & DS_BACKGROUND_ONLY) {
		goto done;
	}

 rediscover:
	status = dsgetdcname_rediscover(mem_ctx, msg_ctx, domain_name,
					domain_guid, flags, query_site,
					&myinfo);

 done:
	SAFE_FREE(query_site);

	if (!NT_STATUS_IS_OK(status)) {
		if (!first) {
			*info = first_info;
			return NT_STATUS_OK;
		}
		return status;
	}

	if (!first) {
		TALLOC_FREE(first_info);
	} else if (!is_closest_site(myinfo)) {
		first = false;
		first_info = myinfo;
		/* TODO: may use the next_closest_site here */
		query_site = SMB_STRDUP(myinfo->client_site_name);
		goto rediscover;
	}

	*info = myinfo;
	return NT_STATUS_OK;
}
Пример #5
0
static int net_lookup_ldap(struct net_context *c, int argc, const char **argv)
{
#ifdef HAVE_ADS
	const char *domain;
	struct sockaddr_storage ss;
	struct dns_rr_srv *dcs = NULL;
	int numdcs = 0;
	char *sitename;
	TALLOC_CTX *ctx;
	NTSTATUS status;
	int ret;
	char h_name[MAX_DNS_NAME_LENGTH];

	if (argc > 0)
		domain = argv[0];
	else
		domain = c->opt_target_workgroup;

	if ( (ctx = talloc_init("net_lookup_ldap")) == NULL ) {
		d_fprintf(stderr,"net_lookup_ldap: talloc_init() %s!\n",
			  _("failed"));
		return -1;
	}

	sitename = sitename_fetch(ctx, domain);

	DEBUG(9, ("Lookup up ldap for domain %s\n", domain));

	status = ads_dns_query_dcs(ctx,
				   domain,
				   sitename,
				   &dcs,
				   &numdcs);
	if ( NT_STATUS_IS_OK(status) && numdcs ) {
		print_ldap_srvlist(dcs, numdcs);
		TALLOC_FREE( ctx );
		return 0;
	}

     	DEBUG(9, ("Looking up PDC for domain %s\n", domain));
	if (!get_pdc_ip(domain, &ss)) {
		TALLOC_FREE( ctx );
		return -1;
	}

	ret = sys_getnameinfo((struct sockaddr *)&ss,
			sizeof(struct sockaddr_storage),
			h_name, sizeof(h_name),
			NULL, 0,
			NI_NAMEREQD);

	if (ret) {
		TALLOC_FREE( ctx );
		return -1;
	}

	DEBUG(9, ("Found PDC with DNS name %s\n", h_name));
	domain = strchr(h_name, '.');
	if (!domain) {
		TALLOC_FREE( ctx );
		return -1;
	}
	domain++;

	DEBUG(9, ("Looking up ldap for domain %s\n", domain));

	status = ads_dns_query_dcs(ctx,
				   domain,
				   sitename,
				   &dcs,
				   &numdcs);
	if ( NT_STATUS_IS_OK(status) && numdcs ) {
		print_ldap_srvlist(dcs, numdcs);
		TALLOC_FREE( ctx );
		return 0;
	}

	TALLOC_FREE( ctx );

	return -1;
#endif
	DEBUG(1,("No ADS support\n"));
	return -1;
}
Пример #6
0
static BOOL ads_dc_name(const char *domain,
			const char *realm,
			struct in_addr *dc_ip,
			fstring srv_name)
{
#if 1 /* AVM */
	return False;
#else 
	ADS_STRUCT *ads;
	char *sitename;
	int i;

	if (!realm && strequal(domain, lp_workgroup())) {
		realm = lp_realm();
	}

	sitename = sitename_fetch(realm);

	/* Try this 3 times then give up. */
	for( i =0 ; i < 3; i++) {
		ads = ads_init(realm, domain, NULL);
		if (!ads) {
			SAFE_FREE(sitename);
			return False;
		}

		DEBUG(4,("ads_dc_name: domain=%s\n", domain));

#ifdef HAVE_ADS
		/* we don't need to bind, just connect */
		ads->auth.flags |= ADS_AUTH_NO_BIND;
		ads_connect(ads);
#endif

		if (!ads->config.realm) {
			SAFE_FREE(sitename);
			ads_destroy(&ads);
			return False;
		}

		/* Now we've found a server, see if our sitename
		   has changed. If so, we need to re-do the DNS query
		   to ensure we only find servers in our site. */

		if (stored_sitename_changed(realm, sitename)) {
			SAFE_FREE(sitename);
			sitename = sitename_fetch(realm);
			ads_destroy(&ads);
			/* Ensure we don't cache the DC we just connected to. */
			namecache_delete(realm, 0x1C);
			namecache_delete(domain, 0x1C);
			continue;
		}

#ifdef HAVE_KRB5
		if (is_our_primary_domain(domain) && (ads->config.flags & ADS_KDC)) {
			if (ads_closest_dc(ads)) {
				/* We're going to use this KDC for this realm/domain.
				   If we are using sites, then force the krb5 libs
				   to use this KDC. */

				create_local_private_krb5_conf_for_domain(realm,
									domain,
									sitename,
									ads->ldap_ip);
			} else {
				/* use an off site KDC */
				create_local_private_krb5_conf_for_domain(realm,
									domain,
									NULL,
									ads->ldap_ip);
			}
		}
#endif
		break;
	}

	if (i == 3) {
		DEBUG(1,("ads_dc_name: sitename (now \"%s\") keeps changing ???\n",
			sitename ? sitename : ""));
		SAFE_FREE(sitename);
		return False;
	}

	SAFE_FREE(sitename);

	fstrcpy(srv_name, ads->config.ldap_server_name);
	strupper_m(srv_name);
	*dc_ip = ads->ldap_ip;
	ads_destroy(&ads);
	
	DEBUG(4,("ads_dc_name: using server='%s' IP=%s\n",
		 srv_name, inet_ntoa(*dc_ip)));
	
	return True;
#endif /* AVM */
}
Пример #7
0
static int net_lookup_ldap(int argc, const char **argv)
{
#ifdef HAVE_ADS
	const char *domain;
	struct in_addr addr;
	struct hostent *hostent;
	struct dns_rr_srv *dcs = NULL;
	int numdcs = 0;
	char *sitename;
	TALLOC_CTX *ctx;
	NTSTATUS status;

	if (argc > 0)
		domain = argv[0];
	else
		domain = opt_target_workgroup;

	sitename = sitename_fetch(domain);

	if ( (ctx = talloc_init("net_lookup_ldap")) == NULL ) {
		d_fprintf(stderr, "net_lookup_ldap: talloc_inti() failed!\n");
		SAFE_FREE(sitename);
		return -1;
	}

	DEBUG(9, ("Lookup up ldap for domain %s\n", domain));

	status = ads_dns_query_dcs( ctx, domain, sitename, &dcs, &numdcs );
	if ( NT_STATUS_IS_OK(status) && numdcs ) {
		print_ldap_srvlist(dcs, numdcs);
		TALLOC_FREE( ctx );
		SAFE_FREE(sitename);
		return 0;
	}

     	DEBUG(9, ("Looking up DC for domain %s\n", domain));
	if (!get_pdc_ip(domain, &addr)) {
		TALLOC_FREE( ctx );
		SAFE_FREE(sitename);
		return -1;
	}

	hostent = gethostbyaddr((char *) &addr.s_addr, sizeof(addr.s_addr),
				AF_INET);
	if (!hostent) {
		TALLOC_FREE( ctx );
		SAFE_FREE(sitename);
		return -1;
	}

	DEBUG(9, ("Found DC with DNS name %s\n", hostent->h_name));
	domain = strchr(hostent->h_name, '.');
	if (!domain) {
		TALLOC_FREE( ctx );
		SAFE_FREE(sitename);
		return -1;
	}
	domain++;

	DEBUG(9, ("Looking up ldap for domain %s\n", domain));

	status = ads_dns_query_dcs( ctx, domain, sitename, &dcs, &numdcs );
	if ( NT_STATUS_IS_OK(status) && numdcs ) {
		print_ldap_srvlist(dcs, numdcs);
		TALLOC_FREE( ctx );
		SAFE_FREE(sitename);
		return 0;
	}

	TALLOC_FREE( ctx );
	SAFE_FREE(sitename);

	return -1;
#endif
	DEBUG(1,("No ADS support\n"));
	return -1;
}