From bd3991ac970c1b0856e2e8525fe683c0b1596ea1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Apr 2008 00:04:25 +0200 Subject: dsgetdcname: add very basic flat name support. Guenther (This used to be commit bb72d0b71e2a85d50e7bd893670c3eec69717580) --- source3/libsmb/dsgetdcname.c | 177 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 168 insertions(+), 9 deletions(-) diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c index 7834632806..874a7749b7 100644 --- a/source3/libsmb/dsgetdcname.c +++ b/source3/libsmb/dsgetdcname.c @@ -391,15 +391,60 @@ static NTSTATUS discover_dc_netbios(TALLOC_CTX *mem_ctx, const char *domain_name, uint32_t flags, struct ip_service_name **returned_dclist, - int *return_count) + 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; } - /* FIXME: code here */ + if (flags & DS_PDC_REQUIRED) { + name_type = NBT_NAME_PDC; + } - return NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND; + 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; iss = 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; } /**************************************************************** @@ -688,16 +733,130 @@ static NTSTATUS process_dc_dns(TALLOC_CTX *mem_ctx, /**************************************************************** ****************************************************************/ +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; +} + +/**************************************************************** +****************************************************************/ + static NTSTATUS process_dc_netbios(TALLOC_CTX *mem_ctx, const char *domain_name, uint32_t flags, - struct ip_service_name **dclist, + struct ip_service_name *dclist, int num_dcs, struct netr_DsRGetDCNameInfo **info) { - /* FIXME: code here */ + struct sockaddr_storage ss; + struct ip_service ip_list; + enum nbt_name_type name_type = NBT_NAME_LOGON; + + int i; + const char *dc_hostname, *dc_domain_name; + const char *dc_address; + uint32_t dc_address_type; + uint32_t dc_flags = 0; + const char *dc_name = NULL; + fstring tmp_dc_name; + struct messaging_context *msg_ctx = msg_context(mem_ctx); + + if (flags & DS_PDC_REQUIRED) { + name_type = NBT_NAME_PDC; + } + + DEBUG(10,("process_dc_netbios\n")); + + for (i=0; i