r8076: Put name resolution methods into libnet_context. This allows libnet based
authorRafal Szczesniak <mimir@samba.org>
Sat, 2 Jul 2005 14:32:49 +0000 (14:32 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:19:05 +0000 (13:19 -0500)
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 used to be commit d0ea136356bcb9c6c01120d8683b71e8689d5e5b)

source4/libnet/libnet.c
source4/libnet/libnet.h
source4/libnet/libnet_lookup.c

index 5d66005a27a599f93de11b50434c01bb78d86deb..963e8244974b5ae7f0c9293049c3d26164a06e62 100644 (file)
 
 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;
 }
-
index 470c98dca955f1f0440ea7d3ccc388f250819973..18dc37662851af56dc8ff27f8422899ae2d8055b 100644 (file)
@@ -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;
 };
 
index 8892ae0e491a92e4808be652089f9218cf5e2bbc..ba806e4e445208b755a76fa490398ca9d0a2874e 100644 (file)
@@ -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);
 }