This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
#include "lib/messaging/messaging.h"
#include "lib/messaging/irpc.h"
#include "libcli/resolve/resolve.h"
-#include "libcli/finddcs.h"
+#include "libcli/libcli.h"
+#include "libcli/finddc.h"
#include "libcli/security/security.h"
#include "librpc/gen_ndr/lsa.h"
#include "librpc/gen_ndr/ndr_lsa_c.h"
+#include "param/param.h"
+
struct lookup_state {
struct nbt_name hostname;
const char *address;
struct composite_context *c;
struct lookup_state *s;
struct composite_context *cresolve_req;
- const char** methods;
+ struct resolve_context *resolve_ctx;
/* allocate context and state structures */
c = composite_create(ctx, ctx->event_ctx);
s->hostname.scope = NULL;
/* name resolution methods */
- if (io->in.methods) {
- methods = io->in.methods;
+ if (io->in.resolve_ctx) {
+ resolve_ctx = io->in.resolve_ctx;
} else {
- methods = ctx->name_res_methods;
+ resolve_ctx = ctx->resolve_ctx;
}
/* send resolve request */
- cresolve_req = resolve_name_send(&s->hostname, c->event_ctx, methods);
+ cresolve_req = resolve_name_send(resolve_ctx, s, &s->hostname, c->event_ctx);
if (composite_nomem(cresolve_req, c)) return c;
composite_continue(c, cresolve_req, continue_name_resolved, c);
if (NT_STATUS_IS_OK(status)) {
s = talloc_get_type(c->private_data, struct lookup_state);
- io->out.address = str_list_make(mem_ctx, s->address, NULL);
+ io->out.address = (const char **)str_list_make_single(mem_ctx, s->address);
NT_STATUS_HAVE_NO_MEMORY(io->out.address);
}
/**
* Sends asynchronous LookupDCs request
*/
-struct composite_context* libnet_LookupDCs_send(struct libnet_context *ctx,
- TALLOC_CTX *mem_ctx,
- struct libnet_LookupDCs *io)
+struct tevent_req *libnet_LookupDCs_send(struct libnet_context *ctx,
+ TALLOC_CTX *mem_ctx,
+ struct libnet_LookupDCs *io)
{
- struct composite_context *c;
- struct messaging_context *msg_ctx = messaging_client_init(mem_ctx, ctx->event_ctx);
+ struct tevent_req *req;
+ struct finddcs finddcs_io;
- c = finddcs_send(mem_ctx, io->in.domain_name, io->in.name_type,
- NULL, ctx->name_res_methods, ctx->event_ctx, msg_ctx);
- return c;
+ ZERO_STRUCT(finddcs_io);
+ finddcs_io.in.domain_name = lpcfg_realm(ctx->lp_ctx);
+ if (strcmp(finddcs_io.in.domain_name, "") == 0) {
+ finddcs_io.in.domain_name = lpcfg_workgroup(ctx->lp_ctx);
+ }
+ finddcs_io.in.minimum_dc_flags = NBT_SERVER_LDAP | NBT_SERVER_DS | NBT_SERVER_WRITABLE;
+
+
+ req = finddcs_cldap_send(mem_ctx, &finddcs_io, ctx->resolve_ctx, ctx->event_ctx);
+ return req;
}
/**
* @return nt status code of execution
*/
-NTSTATUS libnet_LookupDCs_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
+NTSTATUS libnet_LookupDCs_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
struct libnet_LookupDCs *io)
{
NTSTATUS status;
- status = finddcs_recv(c, mem_ctx, &io->out.num_dcs, &io->out.dcs);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ struct finddcs finddcs_io;
+ status = finddcs_cldap_recv(req, mem_ctx, &finddcs_io);
+ talloc_free(req);
+ io->out.num_dcs = 1;
+ io->out.dcs = talloc(mem_ctx, struct nbt_dc_name);
+ NT_STATUS_HAVE_NO_MEMORY(io->out.dcs);
+ io->out.dcs[0].address = finddcs_io.out.address;
+ io->out.dcs[0].name = finddcs_io.out.netlogon.data.nt5_ex.pdc_dns_name;
return status;
}
NTSTATUS libnet_LookupDCs(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
struct libnet_LookupDCs *io)
{
- struct composite_context *c = libnet_LookupDCs_send(ctx, mem_ctx, io);
- return libnet_LookupDCs_recv(c, mem_ctx, io);
+ struct tevent_req *req = libnet_LookupDCs_send(ctx, mem_ctx, io);
+ return libnet_LookupDCs_recv(req, mem_ctx, io);
}
struct composite_context *c,
struct lookup_name_state *s);
static void continue_lookup_name(struct composite_context *ctx);
-static void continue_name_found(struct rpc_request *req);
+static void continue_name_found(struct tevent_req *subreq);
struct composite_context* libnet_LookupName_send(struct libnet_context *ctx,
{
struct composite_context *c;
struct lookup_name_state *s;
- struct rpc_request *lookup_req;
- BOOL prereq_met = False;
+ struct tevent_req *subreq;
+ bool prereq_met = false;
c = composite_create(mem_ctx, ctx->event_ctx);
if (c == NULL) return NULL;
if (!prepare_lookup_params(ctx, c, s)) return c;
- lookup_req = dcerpc_lsa_LookupNames_send(ctx->lsa.pipe, c, &s->lookup);
- if (composite_nomem(lookup_req, c)) return c;
+ subreq = dcerpc_lsa_LookupNames_r_send(s, c->event_ctx,
+ ctx->lsa.pipe->binding_handle,
+ &s->lookup);
+ if (composite_nomem(subreq, c)) return c;
- composite_continue_rpc(c, lookup_req, continue_name_found, c);
+ tevent_req_set_callback(subreq, continue_name_found, c);
return c;
}
s->lookup.in.count = &s->count;
s->lookup.out.count = &s->count;
s->lookup.out.sids = &s->sids;
+ s->lookup.out.domains = talloc_zero(ctx, struct lsa_RefDomainList *);
+ if (composite_nomem(s->lookup.out.domains, c)) return false;
return true;
}
{
struct composite_context *c;
struct lookup_name_state *s;
- struct rpc_request *lookup_req;
+ struct tevent_req *subreq;
c = talloc_get_type(ctx->async.private_data, struct composite_context);
s = talloc_get_type(c->private_data, struct lookup_name_state);
if (!prepare_lookup_params(s->ctx, c, s)) return;
- lookup_req = dcerpc_lsa_LookupNames_send(s->ctx->lsa.pipe, c, &s->lookup);
- if (composite_nomem(lookup_req, c)) return;
+ subreq = dcerpc_lsa_LookupNames_r_send(s, c->event_ctx,
+ s->ctx->lsa.pipe->binding_handle,
+ &s->lookup);
+ if (composite_nomem(subreq, c)) return;
- composite_continue_rpc(c, lookup_req, continue_name_found, c);
+ tevent_req_set_callback(subreq, continue_name_found, c);
}
-static void continue_name_found(struct rpc_request *req)
+static void continue_name_found(struct tevent_req *subreq)
{
struct composite_context *c;
struct lookup_name_state *s;
- c = talloc_get_type(req->async.private, struct composite_context);
+ c = tevent_req_callback_data(subreq, struct composite_context);
s = talloc_get_type(c->private_data, struct lookup_name_state);
- c->status = dcerpc_ndr_request_recv(req);
+ c->status = dcerpc_lsa_LookupNames_r_recv(subreq, s);
+ TALLOC_FREE(subreq);
if (!composite_is_ok(c)) return;
c->status = s->lookup.out.result;
io->out.sidstr = NULL;
if (*s->lookup.out.count > 0) {
- struct lsa_RefDomainList *domains = s->lookup.out.domains;
+ struct lsa_RefDomainList *domains = *s->lookup.out.domains;
struct lsa_TransSidArray *sids = s->lookup.out.sids;
if (domains == NULL || sids == NULL) {