svn commit: samba r8076 - in branches/SAMBA_4_0/source/libnet: .

mimir at samba.org mimir at samba.org
Sat Jul 2 14:32:49 GMT 2005


Author: mimir
Date: 2005-07-02 14:32:49 +0000 (Sat, 02 Jul 2005)
New Revision: 8076

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8076

Log:
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


Modified:
   branches/SAMBA_4_0/source/libnet/libnet.c
   branches/SAMBA_4_0/source/libnet/libnet.h
   branches/SAMBA_4_0/source/libnet/libnet_lookup.c


Changeset:
Modified: branches/SAMBA_4_0/source/libnet/libnet.c
===================================================================
--- branches/SAMBA_4_0/source/libnet/libnet.c	2005-07-02 14:28:15 UTC (rev 8075)
+++ branches/SAMBA_4_0/source/libnet/libnet.c	2005-07-02 14:32:49 UTC (rev 8076)
@@ -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 @@
 	}
 	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;
 }
-

Modified: branches/SAMBA_4_0/source/libnet/libnet.h
===================================================================
--- branches/SAMBA_4_0/source/libnet/libnet.h	2005-07-02 14:28:15 UTC (rev 8075)
+++ branches/SAMBA_4_0/source/libnet/libnet.h	2005-07-02 14:32:49 UTC (rev 8076)
@@ -25,13 +25,16 @@
 	 */
 	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;
 };
 

Modified: branches/SAMBA_4_0/source/libnet/libnet_lookup.c
===================================================================
--- branches/SAMBA_4_0/source/libnet/libnet_lookup.c	2005-07-02 14:28:15 UTC (rev 8075)
+++ branches/SAMBA_4_0/source/libnet/libnet_lookup.c	2005-07-02 14:32:49 UTC (rev 8076)
@@ -45,10 +45,12 @@
  * @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 @@
 	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 @@
  * @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 @@
 /**
  * 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 @@
 /**
  * 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 @@
 /**
  * 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);
 }



More information about the samba-cvs mailing list