source: vendor/current/source4/libcli/resolve/lmhosts.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 3.6 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 broadcast name resolution module
5
6 Copyright (C) Andrew Tridgell 1994-1998,2005
7 Copyright (C) Jeremy Allison 2007
8 Copyright (C) Jelmer Vernooij 2007
9 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009-2014
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "includes.h"
25#include "libcli/composite/composite.h"
26#include "libcli/resolve/resolve.h"
27#include "lib/socket/socket.h"
28#include "system/network.h"
29#include "lib/socket/netif.h"
30#include "param/param.h"
31#include "lib/util/util_net.h"
32#include "libcli/nbt/libnbt.h"
33#include "dynconfig.h"
34
35struct resolve_lmhosts_state {
36 struct socket_address **addrs;
37 char **names;
38};
39
40/**
41 broadcast name resolution method - async send
42 */
43/*
44 general name resolution - async send
45 */
46struct composite_context *resolve_name_lmhosts_send(TALLOC_CTX *mem_ctx,
47 struct tevent_context *event_ctx,
48 void *userdata, uint32_t flags,
49 uint16_t port,
50 struct nbt_name *name)
51{
52 struct composite_context *c;
53 struct resolve_lmhosts_state *state;
54 struct sockaddr_storage *resolved_iplist;
55 int resolved_count, i;
56
57 if (event_ctx == NULL) {
58 return NULL;
59 }
60
61 c = composite_create(mem_ctx, event_ctx);
62 if (c == NULL) return NULL;
63
64 if (composite_nomem(c->event_ctx, c)) return c;
65
66 state = talloc_zero(c, struct resolve_lmhosts_state);
67 if (composite_nomem(state, c)) return c;
68 c->private_data = state;
69
70 c->status = resolve_lmhosts_file_as_sockaddr(dyn_LMHOSTSFILE, name->name, name->type,
71 state, &resolved_iplist, &resolved_count);
72 if (!composite_is_ok(c)) return c;
73
74 for (i=0; i < resolved_count; i++) {
75 state->addrs = talloc_realloc(state, state->addrs, struct socket_address *, i+2);
76 if (composite_nomem(state->addrs, c)) return c;
77
78 set_sockaddr_port((struct sockaddr *)&resolved_iplist[i], port);
79
80 state->addrs[i] = socket_address_from_sockaddr(state->addrs, (struct sockaddr *)&resolved_iplist[i], sizeof(resolved_iplist[i]));
81 if (composite_nomem(state->addrs[i], c)) return c;
82
83 state->addrs[i+1] = NULL;
84
85
86 state->names = talloc_realloc(state, state->names, char *, i+2);
87 if (composite_nomem(state->addrs, c)) return c;
88
89 state->names[i] = talloc_strdup(state->names, name->name);
90 if (composite_nomem(state->names[i], c)) return c;
91
92 state->names[i+1] = NULL;
93
94 i++;
95 }
96
97 composite_done(c);
98 return c;
99}
100
101/*
102 general name resolution method - recv side
103 */
104NTSTATUS resolve_name_lmhosts_recv(struct composite_context *c,
105 TALLOC_CTX *mem_ctx,
106 struct socket_address ***addrs,
107 char ***names)
108{
109 NTSTATUS status;
110
111 status = composite_wait(c);
112
113 if (NT_STATUS_IS_OK(status)) {
114 struct resolve_lmhosts_state *state = talloc_get_type(c->private_data, struct resolve_lmhosts_state);
115 *addrs = talloc_steal(mem_ctx, state->addrs);
116 if (names) {
117 *names = talloc_steal(mem_ctx, state->names);
118 }
119 }
120
121 talloc_free(c);
122 return status;
123}
124
125
126bool resolve_context_add_lmhosts_method(struct resolve_context *ctx)
127{
128 return resolve_context_add_method(ctx, resolve_name_lmhosts_send, resolve_name_lmhosts_recv, NULL);
129}
Note: See TracBrowser for help on using the repository browser.