From ad19aa6331ab44516afa82434f125120172b3dda Mon Sep 17 00:00:00 2001 From: =?utf8?q?Matthias=20Dieter=20Walln=C3=B6fer?= Date: Wed, 23 Nov 2011 09:45:31 +0100 Subject: [PATCH] s4:libcli/finddcs_cldap.c - let "finddcs_cldap" work either with the IP address or the domain name This will be useful for a new "samba-tool domain info" command. Signed-off-by: Stefan Metzmacher --- source4/libcli/finddcs_cldap.c | 41 ++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/source4/libcli/finddcs_cldap.c b/source4/libcli/finddcs_cldap.c index a0f538df7c7..38e828fa987 100644 --- a/source4/libcli/finddcs_cldap.c +++ b/source4/libcli/finddcs_cldap.c @@ -60,7 +60,6 @@ static bool finddcs_cldap_ipaddress(struct finddcs_cldap_state *state, struct fi /* * find a list of DCs via DNS/CLDAP - * */ struct tevent_req *finddcs_cldap_send(TALLOC_CTX *mem_ctx, struct finddcs *io, @@ -78,9 +77,14 @@ struct tevent_req *finddcs_cldap_send(TALLOC_CTX *mem_ctx, state->req = req; state->ev = event_ctx; state->minimum_dc_flags = io->in.minimum_dc_flags; - state->domain_name = talloc_strdup(state, io->in.domain_name); - if (tevent_req_nomem(state->domain_name, req)) { - return tevent_req_post(req, event_ctx); + + if (io->in.domain_name) { + state->domain_name = talloc_strdup(state, io->in.domain_name); + if (tevent_req_nomem(state->domain_name, req)) { + return tevent_req_post(req, event_ctx); + } + } else { + state->domain_name = NULL; } if (io->in.domain_sid) { @@ -97,17 +101,26 @@ struct tevent_req *finddcs_cldap_send(TALLOC_CTX *mem_ctx, if (!finddcs_cldap_ipaddress(state, io)) { return tevent_req_post(req, event_ctx); } - } else if (strchr(state->domain_name, '.')) { - /* looks like a DNS name */ - DEBUG(4,("finddcs: searching for a DC by DNS domain %s\n", state->domain_name)); - if (!finddcs_cldap_srv_lookup(state, io, resolve_ctx, event_ctx)) { - return tevent_req_post(req, event_ctx); + } else if (io->in.domain_name) { + if (strchr(state->domain_name, '.')) { + /* looks like a DNS name */ + DEBUG(4,("finddcs: searching for a DC by DNS domain %s\n", state->domain_name)); + if (!finddcs_cldap_srv_lookup(state, io, resolve_ctx, + event_ctx)) { + return tevent_req_post(req, event_ctx); + } + } else { + DEBUG(4,("finddcs: searching for a DC by NBT lookup %s\n", state->domain_name)); + if (!finddcs_cldap_nbt_lookup(state, io, resolve_ctx, + event_ctx)) { + return tevent_req_post(req, event_ctx); + } } } else { - DEBUG(4,("finddcs: searching for a DC by NBT lookup %s\n", state->domain_name)); - if (!finddcs_cldap_nbt_lookup(state, io, resolve_ctx, event_ctx)) { - return tevent_req_post(req, event_ctx); - } + /* either we have the domain name or the IP address */ + tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER_MIX); + DEBUG(2,("finddcs: Please specify at least the domain name or the IP address! \n")); + return tevent_req_post(req, event_ctx); } return req; @@ -233,7 +246,7 @@ static void finddcs_cldap_next_server(struct finddcs_cldap_state *state) return; } - if (strchr(state->domain_name, '.')) { + if ((state->domain_name != NULL) && (strchr(state->domain_name, '.'))) { state->netlogon->in.realm = state->domain_name; } if (state->domain_sid) { -- 2.34.1