2 Unix SMB/CIFS implementation.
4 endpoint server for the epmapper pipe
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "rpc_server/common/common.h"
26 typedef uint32_t error_status_t;
28 /* handle types for this module */
29 enum handle_types {HTYPE_LOOKUP};
31 /* a endpoint combined with an interface description */
32 struct dcesrv_ep_iface {
34 struct dcesrv_ep_description ep_description;
40 simple routine to compare a GUID string to a GUID structure
42 static int guid_cmp(TALLOC_CTX *mem_ctx, const struct GUID *guid, const char *uuid_str)
44 const char *s = GUID_string(mem_ctx, guid);
45 if (!s || strcasecmp(s, uuid_str)) {
54 static BOOL fill_protocol_tower(TALLOC_CTX *mem_ctx, struct epm_towers *twr,
55 struct dcesrv_ep_iface *e)
58 twr->floors = talloc_array_p(mem_ctx, struct epm_floor, 5);
63 twr->floors[0].lhs.protocol = EPM_PROTOCOL_UUID;
64 GUID_from_string(e->uuid, &twr->floors[0].lhs.info.uuid.uuid);
65 twr->floors[0].lhs.info.uuid.version = e->if_version;
66 twr->floors[0].rhs.rhs_data = data_blob_talloc_zero(mem_ctx, 2);
68 /* encoded with NDR ... */
69 twr->floors[1].lhs.protocol = EPM_PROTOCOL_UUID;
70 GUID_from_string(NDR_GUID, &twr->floors[1].lhs.info.uuid.uuid);
71 twr->floors[1].lhs.info.uuid.version = NDR_GUID_VERSION;
72 twr->floors[1].rhs.rhs_data = data_blob_talloc_zero(mem_ctx, 2);
74 /* on an RPC connection ... */
75 twr->floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
76 twr->floors[2].lhs.info.lhs_data = data_blob(NULL, 0);
77 twr->floors[2].rhs.rhs_data = data_blob_talloc_zero(mem_ctx, 2);
79 switch (e->ep_description.type) {
81 /* on a SMB pipe ... */
82 twr->floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
83 twr->floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
84 twr->floors[3].rhs.rhs_data.data = talloc_asprintf(mem_ctx, "\\PIPE\\%s",
85 e->ep_description.info.smb_pipe);
86 twr->floors[3].rhs.rhs_data.length = strlen(twr->floors[3].rhs.rhs_data.data)+1;
88 /* on an NetBIOS link ... */
89 twr->floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
90 twr->floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
91 twr->floors[4].rhs.rhs_data.data = talloc_asprintf(mem_ctx, "\\\\%s",
93 twr->floors[4].rhs.rhs_data.length = strlen(twr->floors[4].rhs.rhs_data.data)+1;
97 /* on a TCP connection ... */
98 twr->floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
99 twr->floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
100 twr->floors[3].rhs.rhs_data = data_blob_talloc(mem_ctx, NULL, 2);
101 RSSVAL(twr->floors[3].rhs.rhs_data.data, 0, e->ep_description.info.tcp_port);
103 /* on an IP link ... */
104 twr->floors[4].lhs.protocol = EPM_PROTOCOL_IP;
105 twr->floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
106 twr->floors[4].rhs.rhs_data = data_blob_talloc_zero(mem_ctx, 4);
107 /* TODO: we should fill in our IP address here as a hint to the
117 build a list of all interfaces handled by all endpoint servers
119 static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
120 struct dcesrv_endpoint *endpoint_list,
121 struct dcesrv_ep_iface **eps)
123 struct dcesrv_endpoint *d;
128 for (d=endpoint_list; d; d=d->next) {
129 struct dcesrv_if_list *iface;
131 for (iface=d->interface_list;iface;iface=iface->next) {
132 (*eps) = talloc_realloc_p(mem_ctx,
134 struct dcesrv_ep_iface,
139 (*eps)[total].name = iface->iface.ndr->name;
140 (*eps)[total].uuid = iface->iface.ndr->uuid;
141 (*eps)[total].if_version = iface->iface.ndr->if_version;
142 (*eps)[total].ep_description = d->ep_description;
151 static error_status_t epm_Insert(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
152 struct epm_Insert *r)
154 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
157 static error_status_t epm_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
158 struct epm_Delete *r)
160 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
165 implement epm_Lookup. This call is used to enumerate the interfaces
166 available on a rpc server
168 static error_status_t epm_Lookup(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
169 struct epm_Lookup *r)
171 struct dcesrv_handle *h;
174 struct dcesrv_ep_iface *e;
179 h = dcesrv_handle_fetch(dce_call->conn, r->in.entry_handle, HTYPE_LOOKUP);
180 DCESRV_CHECK_HANDLE(h);
185 /* this is the first call - fill the list. Subsequent calls
186 will feed from this list, stored in the handle */
187 eps = talloc_p(h, struct rpc_eps);
189 return EPMAPPER_STATUS_NO_MEMORY;
193 eps->count = build_ep_list(h, dce_call->conn->dce_ctx->endpoint_list, &eps->e);
196 /* return the next N elements */
197 num_ents = r->in.max_ents;
198 if (num_ents > eps->count) {
199 num_ents = eps->count;
202 *r->out.entry_handle = h->wire_handle;
203 r->out.num_ents = num_ents;
206 r->out.entries = NULL;
207 ZERO_STRUCTP(r->out.entry_handle);
208 dcesrv_handle_destroy(dce_call->conn, h);
209 return EPMAPPER_STATUS_NO_MORE_ENTRIES;
212 r->out.entries = talloc_array_p(mem_ctx, struct epm_entry_t, num_ents);
213 if (!r->out.entries) {
214 return EPMAPPER_STATUS_NO_MEMORY;
217 for (i=0;i<num_ents;i++) {
218 ZERO_STRUCT(r->out.entries[i].object);
219 r->out.entries[i].annotation = eps->e[i].name;
220 r->out.entries[i].tower = talloc_p(mem_ctx, struct epm_twr_t);
221 if (!r->out.entries[i].tower) {
222 return EPMAPPER_STATUS_NO_MEMORY;
225 if (!fill_protocol_tower(mem_ctx, &r->out.entries[i].tower->towers, &eps->e[i])) {
226 return EPMAPPER_STATUS_NO_MEMORY;
230 eps->count -= num_ents;
233 return EPMAPPER_STATUS_OK;
238 implement epm_Map. This is used to find the specific endpoint to talk to given
239 a generic protocol tower
241 static error_status_t epm_Map(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
246 struct dcesrv_ep_iface *eps;
247 struct epm_floor *floors;
249 count = build_ep_list(mem_ctx, dce_call->conn->dce_ctx->endpoint_list, &eps);
251 ZERO_STRUCT(*r->out.entry_handle);
252 r->out.num_towers = 1;
253 r->out.towers = talloc_p(mem_ctx, struct epm_twr_p_t);
254 if (!r->out.towers) {
255 return EPMAPPER_STATUS_NO_MEMORY;
257 r->out.towers->twr = talloc_p(mem_ctx, struct epm_twr_t);
258 if (!r->out.towers->twr) {
259 return EPMAPPER_STATUS_NO_MEMORY;
262 if (!r->in.map_tower || r->in.max_towers == 0 ||
263 r->in.map_tower->towers.num_floors != 5) {
267 floors = r->in.map_tower->towers.floors;
269 if (floors[0].lhs.protocol != EPM_PROTOCOL_UUID ||
270 floors[1].lhs.protocol != EPM_PROTOCOL_UUID ||
271 guid_cmp(mem_ctx, &floors[1].lhs.info.uuid.uuid, NDR_GUID) != 0 ||
272 floors[1].lhs.info.uuid.version != NDR_GUID_VERSION ||
273 floors[2].lhs.protocol != EPM_PROTOCOL_NCACN) {
277 for (i=0;i<count;i++) {
278 if (guid_cmp(mem_ctx, &floors[0].lhs.info.uuid.uuid, eps[i].uuid) != 0 ||
279 floors[0].lhs.info.uuid.version != eps[i].if_version) {
282 switch (eps[i].ep_description.type) {
284 if (floors[3].lhs.protocol != EPM_PROTOCOL_SMB ||
285 floors[4].lhs.protocol != EPM_PROTOCOL_NETBIOS) {
290 if (floors[3].lhs.protocol != EPM_PROTOCOL_TCP ||
291 floors[4].lhs.protocol != EPM_PROTOCOL_IP) {
296 fill_protocol_tower(mem_ctx, &r->out.towers->twr->towers, &eps[i]);
297 r->out.towers->twr->tower_length = 0;
298 return EPMAPPER_STATUS_OK;
303 r->out.num_towers = 0;
304 r->out.towers->twr = NULL;
306 return EPMAPPER_STATUS_NO_MORE_ENTRIES;
309 static error_status_t epm_LookupHandleFree(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
310 struct epm_LookupHandleFree *r)
312 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
315 static error_status_t epm_InqObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
316 struct epm_InqObject *r)
318 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
321 static error_status_t epm_MgmtDelete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
322 struct epm_MgmtDelete *r)
324 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
327 static error_status_t epm_MapAuth(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
328 struct epm_MapAuth *r)
330 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
333 /* include the generated boilerplate */
334 #include "librpc/gen_ndr/ndr_epmapper_s.c"