1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s4:libcli/replace: add some RESOLVE_NAME_FLAG* flags

metze
This commit is contained in:
Stefan Metzmacher 2008-12-17 16:55:44 +01:00
parent 9f8dfb0a52
commit a60159c873
4 changed files with 43 additions and 18 deletions

View File

@ -40,9 +40,7 @@
#include "heimdal/lib/roken/resolve.h"
struct dns_ex_state {
bool do_getaddrinfo;
bool do_fallback;
bool do_srv;
uint32_t flags;
uint16_t port;
struct nbt_name name;
@ -88,15 +86,16 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd)
char *addrs;
bool first;
uint32_t i;
bool do_srv = (state->flags & RESOLVE_NAME_FLAG_DNS_SRV);
/* this is the blocking call we are going to lots of trouble
to avoid in the parent */
reply = dns_lookup(state->name.name, state->do_srv?"SRV":"A");
reply = dns_lookup(state->name.name, do_srv?"SRV":"A");
if (!reply) {
goto done;
}
if (state->do_srv) {
if (do_srv) {
dns_srv_order(reply);
}
@ -107,7 +106,7 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd)
continue;
}
if (state->do_srv) {
if (do_srv) {
/* we are only interested in SRV records */
if (rr->type != T_SRV) {
continue;
@ -162,7 +161,7 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd)
continue;
}
if (state->do_srv) {
if (do_srv) {
/* we are only interested in SRV records */
if (rr->type != T_SRV) {
continue;
@ -230,13 +229,22 @@ static void run_child_dns_lookup(struct dns_ex_state *state, int fd)
}
first = true;
for (i=0; i < count; i++) {
uint16_t port;
if (!addrs_rr[i]) {
continue;
}
if (srv_rr[i] &&
(state->flags & RESOLVE_NAME_FLAG_OVERWRITE_PORT)) {
port = srv_rr[i]->u.srv->port;
} else {
port = state->port;
}
addrs = talloc_asprintf_append_buffer(addrs, "%s%s:%u/%s",
first?"":",",
inet_ntoa(*addrs_rr[i]->u.a),
state->port,
port,
addrs_rr[i]->domain);
if (!addrs) {
goto done;
@ -429,9 +437,7 @@ struct composite_context *resolve_name_dns_ex_send(TALLOC_CTX *mem_ctx,
uint32_t flags,
uint16_t port,
struct nbt_name *name,
bool do_getaddrinfo,
bool do_fallback,
bool do_srv)
bool do_fallback)
{
struct composite_context *c;
struct dns_ex_state *state;
@ -441,7 +447,10 @@ struct composite_context *resolve_name_dns_ex_send(TALLOC_CTX *mem_ctx,
c = composite_create(mem_ctx, event_ctx);
if (c == NULL) return NULL;
if (composite_nomem(c->event_ctx, c)) return c;
if (flags & RESOLVE_NAME_FLAG_FORCE_NBT) {
composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND);
return c;
}
state = talloc_zero(c, struct dns_ex_state);
if (composite_nomem(state, c)) return c;
@ -457,9 +466,7 @@ struct composite_context *resolve_name_dns_ex_send(TALLOC_CTX *mem_ctx,
return c;
}
state->do_getaddrinfo = do_getaddrinfo;
state->do_fallback = do_fallback;
state->do_srv = do_srv;
state->flags = flags;
state->port = port;
@ -484,10 +491,10 @@ struct composite_context *resolve_name_dns_ex_send(TALLOC_CTX *mem_ctx,
if (state->child == 0) {
close(fd[0]);
if (state->do_getaddrinfo) {
run_child_getaddrinfo(state, fd[1]);
} else {
if (state->flags & RESOLVE_NAME_FLAG_FORCE_DNS) {
run_child_dns_lookup(state, fd[1]);
} else {
run_child_getaddrinfo(state, fd[1]);
}
_exit(0);
}

View File

@ -39,7 +39,7 @@ struct composite_context *resolve_name_host_send(TALLOC_CTX *mem_ctx,
struct nbt_name *name)
{
return resolve_name_dns_ex_send(mem_ctx, event_ctx, NULL, flags,
port, name, true, true, false);
port, name, true);
}
/*

View File

@ -125,7 +125,15 @@ struct composite_context *resolve_name_nbtlist_send(TALLOC_CTX *mem_ctx,
c = composite_create(mem_ctx, event_ctx);
if (c == NULL) return NULL;
if (composite_nomem(c->event_ctx, c)) return c;
if (flags & RESOLVE_NAME_FLAG_FORCE_DNS) {
composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND);
return c;
}
if (strlen(name->name) > 15) {
composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND);
return c;
}
state = talloc(c, struct nbtlist_state);
if (composite_nomem(state, c)) return c;

View File

@ -26,6 +26,16 @@ struct socket_address;
struct event_context;
#include "../libcli/nbt/libnbt.h"
/* force that only NBT name resolution is used */
#define RESOLVE_NAME_FLAG_FORCE_NBT 0x00000001
/* force that only DNS name resolution is used */
#define RESOLVE_NAME_FLAG_FORCE_DNS 0x00000002
/* tell the dns resolver to do a DNS SRV lookup */
#define RESOLVE_NAME_FLAG_DNS_SRV 0x00000004
/* allow the resolver to overwrite the given port, e.g. for DNS SRV */
#define RESOLVE_NAME_FLAG_OVERWRITE_PORT 0x00000008
typedef struct composite_context *(*resolve_name_send_fn)(TALLOC_CTX *mem_ctx,
struct event_context *,
void *privdata,