mirror of
https://github.com/samba-team/samba.git
synced 2025-11-05 04:23:51 +03:00
r8076: Put name resolution methods into libnet_context. This allows libnet based
application use methods of their own choice and makes it less dependent on smb.conf parameters. Use libnet_context in libnet_Lookup functions which is the way to pass default name resolution methods if caller doesn't want to bother with specifying them. rafal
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
b28d2e9639
commit
d0ea136356
@@ -24,13 +24,19 @@
|
||||
|
||||
struct libnet_context *libnet_context_init(struct event_context *ev)
|
||||
{
|
||||
/* default name resolution methods */
|
||||
const char *nr_methods[] = { "lmhosts", "wins", "host", "bcast", NULL };
|
||||
int nr_count = 0, nr_i;
|
||||
|
||||
struct libnet_context *ctx;
|
||||
|
||||
/* create brand new libnet context */
|
||||
ctx = talloc(NULL, struct libnet_context);
|
||||
if (!ctx) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* events */
|
||||
if (ev == NULL) {
|
||||
ev = event_context_init(ctx);
|
||||
if (ev == NULL) {
|
||||
@@ -40,6 +46,15 @@ struct libnet_context *libnet_context_init(struct event_context *ev)
|
||||
}
|
||||
ctx->event_ctx = ev;
|
||||
|
||||
/* count name resolution methods */
|
||||
while (nr_methods[nr_count]) nr_count++;
|
||||
|
||||
/* assign name resolution methods */
|
||||
ctx->name_res_methods = talloc_array(ctx, char*, nr_count+1);
|
||||
for (nr_i = 0; nr_i < nr_count; nr_i++) {
|
||||
ctx->name_res_methods[nr_i] = talloc_strdup(ctx, nr_methods[nr_i]);
|
||||
}
|
||||
ctx->name_res_methods[nr_count+1] = NULL;
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,16 @@ struct libnet_context {
|
||||
*/
|
||||
struct cli_credentials *cred;
|
||||
|
||||
/* dcerpc pipes */
|
||||
struct dcerpc_pipe *samr;
|
||||
/* pipe */
|
||||
struct dcerpc_pipe *pipe;
|
||||
|
||||
/* opened handles */
|
||||
struct policy_handle domain_handle;
|
||||
struct policy_handle user_handle;
|
||||
|
||||
/* name resolution methods */
|
||||
char **name_res_methods;
|
||||
|
||||
struct event_context *event_ctx;
|
||||
};
|
||||
|
||||
|
||||
@@ -45,10 +45,12 @@ struct lookup_state {
|
||||
* @param io arguments and result of the call
|
||||
*/
|
||||
|
||||
struct composite_context *libnet_Lookup_send(struct libnet_Lookup *io)
|
||||
struct composite_context *libnet_Lookup_send(struct libnet_context *ctx,
|
||||
struct libnet_Lookup *io)
|
||||
{
|
||||
struct composite_context *c;
|
||||
struct lookup_state *s;
|
||||
const char** methods;
|
||||
|
||||
if (!io) return NULL;
|
||||
|
||||
@@ -69,11 +71,18 @@ struct composite_context *libnet_Lookup_send(struct libnet_Lookup *io)
|
||||
s->hostname.scope = NULL;
|
||||
s->address = io->out.address;
|
||||
|
||||
/* name resolution methods */
|
||||
if (io->in.methods) {
|
||||
methods = io->in.methods;
|
||||
} else {
|
||||
methods = (const char**)ctx->name_res_methods;
|
||||
}
|
||||
|
||||
c->private = s;
|
||||
c->state = SMBCLI_REQUEST_SEND;
|
||||
|
||||
/* send resolve request */
|
||||
s->resolve_ctx = resolve_name_send(&s->hostname, c->event_ctx, io->in.methods);
|
||||
s->resolve_ctx = resolve_name_send(&s->hostname, c->event_ctx, methods);
|
||||
|
||||
return c;
|
||||
|
||||
@@ -113,9 +122,10 @@ NTSTATUS libnet_Lookup_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
|
||||
* @return nt status code of execution
|
||||
*/
|
||||
|
||||
NTSTATUS libnet_Lookup(TALLOC_CTX *mem_ctx, struct libnet_Lookup *io)
|
||||
NTSTATUS libnet_Lookup(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
|
||||
struct libnet_Lookup *io)
|
||||
{
|
||||
struct composite_context *c = libnet_Lookup_send(io);
|
||||
struct composite_context *c = libnet_Lookup_send(ctx, io);
|
||||
return libnet_Lookup_recv(c, mem_ctx, io);
|
||||
}
|
||||
|
||||
@@ -129,10 +139,11 @@ NTSTATUS libnet_Lookup(TALLOC_CTX *mem_ctx, struct libnet_Lookup *io)
|
||||
/**
|
||||
* Sends asynchronous LookupHost request
|
||||
*/
|
||||
struct composite_context* libnet_LookupHost_send(struct libnet_Lookup *io)
|
||||
struct composite_context* libnet_LookupHost_send(struct libnet_context *ctx,
|
||||
struct libnet_Lookup *io)
|
||||
{
|
||||
io->in.type = NBT_NAME_SERVER;
|
||||
return libnet_Lookup_send(io);
|
||||
return libnet_Lookup_send(ctx, io);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,9 +151,10 @@ struct composite_context* libnet_LookupHost_send(struct libnet_Lookup *io)
|
||||
/**
|
||||
* Synchronous version of LookupHost call
|
||||
*/
|
||||
NTSTATUS libnet_LookupHost(TALLOC_CTX *mem_ctx, struct libnet_Lookup *io)
|
||||
NTSTATUS libnet_LookupHost(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
|
||||
struct libnet_Lookup *io)
|
||||
{
|
||||
struct composite_context *c = libnet_LookupHost_send(io);
|
||||
struct composite_context *c = libnet_LookupHost_send(ctx, io);
|
||||
return libnet_Lookup_recv(c, mem_ctx, io);
|
||||
}
|
||||
|
||||
@@ -150,18 +162,20 @@ NTSTATUS libnet_LookupHost(TALLOC_CTX *mem_ctx, struct libnet_Lookup *io)
|
||||
/**
|
||||
* Sends asynchronous LookupPdc request
|
||||
*/
|
||||
struct composite_context* libnet_LookupPdc_send(struct libnet_Lookup *io)
|
||||
struct composite_context* libnet_LookupPdc_send(struct libnet_context *ctx,
|
||||
struct libnet_Lookup *io)
|
||||
{
|
||||
io->in.type = NBT_NAME_PDC;
|
||||
return libnet_Lookup_send(io);
|
||||
return libnet_Lookup_send(ctx, io);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Synchronous version of LookupPdc
|
||||
*/
|
||||
NTSTATUS libnet_LookupPdc(TALLOC_CTX *mem_ctx, struct libnet_Lookup *io)
|
||||
NTSTATUS libnet_LookupPdc(struct libnet_context *ctx, TALLOC_CTX *mem_ctx,
|
||||
struct libnet_Lookup *io)
|
||||
{
|
||||
struct composite_context *c = libnet_LookupPdc_send(io);
|
||||
struct composite_context *c = libnet_LookupPdc_send(ctx, io);
|
||||
return libnet_Lookup_recv(c, mem_ctx, io);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user