*/
#include "includes.h"
+#include "libads/sitename_cache.h"
+#include "../librpc/gen_ndr/ndr_netlogon.h"
+#include "libads/cldap.h"
+#include "libads/dns.h"
+#include "libsmb/clidgram.h"
-#define DSGETDCNAME_FMT "DSGETDCNAME/DOMAIN/%s"
/* 15 minutes */
#define DSGETDCNAME_CACHE_TTL 60*15
struct ip_service_name {
struct sockaddr_storage ss;
- unsigned port;
const char *hostname;
};
return NULL;
}
- return talloc_asprintf_strupper_m(mem_ctx, DSGETDCNAME_FMT, domain);
+ return talloc_asprintf_strupper_m(mem_ctx, "DSGETDCNAME/DOMAIN/%s",
+ domain);
}
/****************************************************************
r->sockaddr.sockaddr_family = 2; /* AF_INET */
r->sockaddr.pdc_ip = talloc_strdup(mem_ctx, addr);
- ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, r,
+ ndr_err = ndr_push_struct_blob(&blob, mem_ctx, r,
(ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
return ndr_map_error2ntstatus(ndr_err);
}
- if (r->domain) {
- status = dsgetdcname_cache_store(mem_ctx, r->domain, &blob);
+ if (r->domain_name) {
+ status = dsgetdcname_cache_store(mem_ctx, r->domain_name, &blob);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
if (r->client_site) {
- sitename_store(r->domain, r->client_site);
+ sitename_store(r->domain_name, r->client_site);
}
}
if (r->dns_domain) {
return NT_STATUS_NOT_FOUND;
}
- info = TALLOC_ZERO_P(mem_ctx, struct netr_DsRGetDCNameInfo);
+ info = talloc_zero(mem_ctx, struct netr_DsRGetDCNameInfo);
if (!info) {
return NT_STATUS_NO_MEMORY;
}
- ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, &r,
+ ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
(ndr_pull_flags_fn_t)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX);
data_blob_free(&blob);
dclist = TALLOC_ZERO_ARRAY(mem_ctx, struct ip_service_name, count);
if (!dclist) {
+ SAFE_FREE(iplist);
return NT_STATUS_NO_MEMORY;
}
&iplist[i].ss);
r->ss = iplist[i].ss;
- r->port = iplist[i].port;
r->hostname = talloc_strdup(mem_ctx, addr);
if (!r->hostname) {
+ SAFE_FREE(iplist);
return NT_STATUS_NO_MEMORY;
}
*returned_dclist = dclist;
*returned_count = count;
+ SAFE_FREE(iplist);
return NT_STATUS_OK;
}
struct ip_service_name *r = &dclist[count];
- r->port = dcs[i].port;
r->hostname = dcs[i].hostname;
/* If we don't have an IP list for a name, lookup it up */
i++;
j = 0;
} else {
- /* use the IP addresses from the SRV sresponse */
+ /* use the IP addresses from the SRV response */
if (j >= dcs[i].num_ips) {
i++;
/* make sure it is a valid IP. I considered checking the
* negative connection cache, but this is the wrong place for
- * it. Maybe only as a hac. After think about it, if all of
- * the IP addresses retuend from DNS are dead, what hope does a
+ * it. Maybe only as a hack. After think about it, if all of
+ * the IP addresses returned from DNS are dead, what hope does a
* netbios name lookup have? The standard reason for falling
* back to netbios lookups is that our DNS server doesn't know
* anything about the DC's -- jerry */
- if (!is_zero_addr((struct sockaddr *)(void *)&r->ss)) {
+ if (!is_zero_addr(&r->ss)) {
count++;
continue;
}
{
struct netr_DsRGetDCNameInfo *info;
- info = TALLOC_ZERO_P(mem_ctx, struct netr_DsRGetDCNameInfo);
+ info = talloc_zero(mem_ctx, struct netr_DsRGetDCNameInfo);
NT_STATUS_HAVE_NO_MEMORY(info);
if (dc_unc) {
map_dc_and_domain_names(flags,
r->pdc_name,
- r->domain,
+ r->domain_name,
r->pdc_dns_name,
r->dns_domain,
&dc_flags,
for (i=0; i<num_dcs; i++) {
+
DEBUG(10,("LDAP ping to %s\n", dclist[i].hostname));
- if (ads_cldap_netlogon(mem_ctx, dclist[i].hostname,
+ if (ads_cldap_netlogon(mem_ctx, &dclist[i].ss,
domain_name,
nt_version,
&r))
/****************************************************************
****************************************************************/
-static struct event_context *ev_context(void)
-{
- static struct event_context *ctx;
-
- if (!ctx && !(ctx = event_context_init(NULL))) {
- smb_panic("Could not init event context");
- }
- return ctx;
-}
-
-/****************************************************************
-****************************************************************/
-
-static struct messaging_context *msg_context(TALLOC_CTX *mem_ctx)
-{
- static struct messaging_context *ctx;
-
- if (!ctx && !(ctx = messaging_init(mem_ctx, server_id_self(),
- ev_context()))) {
- smb_panic("Could not init messaging context");
- }
- return ctx;
-}
-
/****************************************************************
****************************************************************/
NETLOGON_NT_VERSION_5 |
NETLOGON_NT_VERSION_5EX_WITH_IP;
- if (!msg_ctx) {
- msg_ctx = msg_context(mem_ctx);
+ if (msg_ctx == NULL) {
+ return NT_STATUS_INVALID_PARAMETER;
}
if (flags & DS_PDC_REQUIRED) {
DEBUG(10,("process_dc_netbios\n"));
for (i=0; i<num_dcs; i++) {
+ uint16_t val;
+
+ generate_random_buffer((uint8_t *)&val, 2);
ip_list.ss = dclist[i].ss;
ip_list.port = 0;
return NT_STATUS_UNSUCCESSFUL;
}
- if (send_getdc_request(mem_ctx, msg_ctx,
- &dclist[i].ss, domain_name,
- NULL, nt_version))
- {
- int k;
- smb_msleep(300);
- for (k=0; k<5; k++) {
- if (receive_getdc_response(mem_ctx,
- &dclist[i].ss,
- domain_name,
- &nt_version,
- &dc_name,
- &r)) {
- store_cache = true;
- namecache_store(dc_name, NBT_NAME_SERVER, 1, &ip_list);
- goto make_reply;
- }
- smb_msleep(1500);
- }
+ status = nbt_getdc(msg_ctx, &dclist[i].ss, domain_name,
+ NULL, nt_version,
+ mem_ctx, &nt_version, &dc_name, &r);
+ if (NT_STATUS_IS_OK(status)) {
+ store_cache = true;
+ namecache_store(dc_name, NBT_NAME_SERVER, 1, &ip_list);
+ goto make_reply;
}
if (name_status_find(domain_name,
{
struct NETLOGON_SAM_LOGON_RESPONSE_NT40 logon1;
- r = TALLOC_ZERO_P(mem_ctx, struct netlogon_samlogon_response);
+ r = talloc_zero(mem_ctx, struct netlogon_samlogon_response);
NT_STATUS_HAVE_NO_MEMORY(r);
ZERO_STRUCT(logon1);
nt_version = NETLOGON_NT_VERSION_1;
logon1.nt_version = nt_version;
- logon1.server = tmp_dc_name;
- logon1.domain = talloc_strdup_upper(mem_ctx, domain_name);
- NT_STATUS_HAVE_NO_MEMORY(logon1.domain);
+ logon1.pdc_name = tmp_dc_name;
+ logon1.domain_name = talloc_strdup_upper(mem_ctx, domain_name);
+ NT_STATUS_HAVE_NO_MEMORY(logon1.domain_name);
r->data.nt4 = logon1;
r->ntver = nt_version;