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) {
}
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;
}
-
* @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;
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;
* @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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}