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; }
static BOOL rpc_dc_name(const char *domain, fstring srv_name, struct in_addr *ip_out) { struct ip_service *ip_list = NULL; struct in_addr dc_ip, exclude_ip; int count, i; NTSTATUS result; zero_ip(&exclude_ip); /* get a list of all domain controllers */ if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, NULL, &ip_list, &count, False))) { DEBUG(3, ("Could not look up dc's for domain %s\n", domain)); return False; } /* Remove the entry we've already failed with (should be the PDC). */ for (i = 0; i < count; i++) { if (is_zero_ip(ip_list[i].ip)) continue; if (name_status_find(domain, 0x1c, 0x20, ip_list[i].ip, srv_name)) { result = check_negative_conn_cache( domain, srv_name ); if ( NT_STATUS_IS_OK(result) ) { dc_ip = ip_list[i].ip; goto done; } } } SAFE_FREE(ip_list); /* No-one to talk to )-: */ return False; /* Boo-hoo */ done: /* We have the netbios name and IP address of a domain controller. Ideally we should sent a SAMLOGON request to determine whether the DC is alive and kicking. If we can catch a dead DC before performing a cli_connect() we can avoid a 30-second timeout. */ DEBUG(3, ("rpc_dc_name: Returning DC %s (%s) for domain %s\n", srv_name, inet_ntoa(dc_ip), domain)); *ip_out = dc_ip; SAFE_FREE(ip_list); return True; }
static bool rpc_dc_name(const char *domain, fstring srv_name, struct sockaddr_storage *ss_out) { struct ip_service *ip_list = NULL; struct sockaddr_storage dc_ss; int count, i; NTSTATUS result; char addr[INET6_ADDRSTRLEN]; /* get a list of all domain controllers */ if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, NULL, &ip_list, &count, False))) { DEBUG(3, ("Could not look up dc's for domain %s\n", domain)); return False; } /* Remove the entry we've already failed with (should be the PDC). */ for (i = 0; i < count; i++) { if (is_zero_addr((struct sockaddr *)&ip_list[i].ss)) continue; if (name_status_find(domain, 0x1c, 0x20, &ip_list[i].ss, srv_name)) { result = check_negative_conn_cache( domain, srv_name ); if ( NT_STATUS_IS_OK(result) ) { dc_ss = ip_list[i].ss; goto done; } } } SAFE_FREE(ip_list); /* No-one to talk to )-: */ return False; /* Boo-hoo */ done: /* We have the netbios name and IP address of a domain controller. Ideally we should sent a SAMLOGON request to determine whether the DC is alive and kicking. If we can catch a dead DC before performing a cli_connect() we can avoid a 30-second timeout. */ print_sockaddr(addr, sizeof(addr), &dc_ss); DEBUG(3, ("rpc_dc_name: Returning DC %s (%s) for domain %s\n", srv_name, addr, domain)); *ss_out = dc_ss; SAFE_FREE(ip_list); return True; }
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; }
static int get_ldap_sequence_number( const char* domain, uint32 *seq) { int ret = -1; int i, port = LDAP_PORT; struct ip_service *ip_list = NULL; int count; if ( !get_sorted_dc_list(domain, &ip_list, &count, False) ) { DEBUG(3, ("Could not look up dc's for domain %s\n", domain)); return False; } /* Finally return first DC that we can contact */ for (i = 0; i < count; i++) { fstring ipstr; /* since the is an LDAP lookup, default to the LDAP_PORT is not set */ port = (ip_list[i].port!= PORT_NONE) ? ip_list[i].port : LDAP_PORT; fstrcpy( ipstr, inet_ntoa(ip_list[i].ip) ); if (is_zero_ip(ip_list[i].ip)) continue; if ( (ret = get_ldap_seq( ipstr, port, seq)) == 0 ) goto done; /* add to failed connection cache */ add_failed_connection_entry( domain, ipstr, NT_STATUS_UNSUCCESSFUL ); } done: if ( ret == 0 ) { DEBUG(3, ("get_ldap_sequence_number: Retrieved sequence number for Domain (%s) from DC (%s:%d)\n", domain, inet_ntoa(ip_list[i].ip), port)); } SAFE_FREE(ip_list); return ret; }