static int net_lookup_ldap(int argc, const char **argv) { #ifdef HAVE_LDAP char *srvlist; const char *domain; int rc; struct in_addr addr; struct hostent *hostent; if (argc > 0) domain = argv[0]; else domain = opt_target_workgroup; DEBUG(9, ("Lookup up ldap for domain %s\n", domain)); rc = ldap_domain2hostlist(domain, &srvlist); if ((rc == LDAP_SUCCESS) && srvlist) { print_ldap_srvlist(srvlist); return 0; } DEBUG(9, ("Looking up DC for domain %s\n", domain)); if (!get_pdc_ip(domain, &addr)) return -1; hostent = gethostbyaddr((char *) &addr.s_addr, sizeof(addr.s_addr), AF_INET); if (!hostent) return -1; DEBUG(9, ("Found DC with DNS name %s\n", hostent->h_name)); domain = strchr(hostent->h_name, '.'); if (!domain) return -1; domain++; DEBUG(9, ("Looking up ldap for domain %s\n", domain)); rc = ldap_domain2hostlist(domain, &srvlist); if ((rc == LDAP_SUCCESS) && srvlist) { print_ldap_srvlist(srvlist); return 0; } return -1; #endif DEBUG(1,("No LDAP support\n")); return -1; }
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; }
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; }