2 Unix SMB/CIFS implementation.
4 endpoint server for the epmapper pipe
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Jelmer Vernooij 2004
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "librpc/gen_ndr/ndr_epmapper.h"
26 #include "rpc_server/dcerpc_server.h"
27 #include "rpc_server/common/common.h"
29 typedef uint32_t error_status_t;
31 /* handle types for this module */
32 enum handle_types {HTYPE_LOOKUP};
34 /* a endpoint combined with an interface description */
35 struct dcesrv_ep_iface {
37 struct dcerpc_binding ep_description;
41 simple routine to compare a GUID string to a GUID structure
43 static int guid_cmp(TALLOC_CTX *mem_ctx, const struct GUID *guid, const char *uuid_str)
45 const char *s = GUID_string(mem_ctx, guid);
46 if (!s || strcasecmp(s, uuid_str)) {
53 build a list of all interfaces handled by all endpoint servers
55 static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
56 struct dcesrv_endpoint *endpoint_list,
57 struct dcesrv_ep_iface **eps)
59 struct dcesrv_endpoint *d;
64 for (d=endpoint_list; d; d=d->next) {
65 struct dcesrv_if_list *iface;
67 for (iface=d->interface_list;iface;iface=iface->next) {
68 (*eps) = talloc_realloc_p(mem_ctx,
70 struct dcesrv_ep_iface,
75 (*eps)[total].name = iface->iface.ndr->name;
76 (*eps)[total].ep_description = d->ep_description;
77 GUID_from_string(iface->iface.ndr->uuid,
78 &(*eps)[total].ep_description.object);
79 (*eps)[total].ep_description.object_version =
80 iface->iface.ndr->if_version;
89 static error_status_t epm_Insert(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
92 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
95 static error_status_t epm_Delete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
98 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
103 implement epm_Lookup. This call is used to enumerate the interfaces
104 available on a rpc server
106 static error_status_t epm_Lookup(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
107 struct epm_Lookup *r)
109 struct dcesrv_handle *h;
112 struct dcesrv_ep_iface *e;
118 h = dcesrv_handle_fetch(dce_call->conn, r->in.entry_handle, HTYPE_LOOKUP);
119 DCESRV_CHECK_HANDLE(h);
124 /* this is the first call - fill the list. Subsequent calls
125 will feed from this list, stored in the handle */
126 eps = talloc_p(h, struct rpc_eps);
128 return EPMAPPER_STATUS_NO_MEMORY;
132 eps->count = build_ep_list(h, dce_call->conn->dce_ctx->endpoint_list, &eps->e);
135 /* return the next N elements */
136 num_ents = r->in.max_ents;
137 if (num_ents > eps->count) {
138 num_ents = eps->count;
141 *r->out.entry_handle = h->wire_handle;
142 r->out.num_ents = num_ents;
145 r->out.entries = NULL;
146 ZERO_STRUCTP(r->out.entry_handle);
147 dcesrv_handle_destroy(dce_call->conn, h);
148 return EPMAPPER_STATUS_NO_MORE_ENTRIES;
151 r->out.entries = talloc_array_p(mem_ctx, struct epm_entry_t, num_ents);
152 if (!r->out.entries) {
153 return EPMAPPER_STATUS_NO_MEMORY;
156 for (i=0;i<num_ents;i++) {
157 ZERO_STRUCT(r->out.entries[i].object);
158 r->out.entries[i].annotation = eps->e[i].name;
159 r->out.entries[i].tower = talloc_p(mem_ctx, struct epm_twr_t);
160 if (!r->out.entries[i].tower) {
161 return EPMAPPER_STATUS_NO_MEMORY;
164 status = dcerpc_binding_build_tower(mem_ctx, &eps->e[i].ep_description, &r->out.entries[i].tower->tower);
165 if (NT_STATUS_IS_ERR(status)) {
166 return EPMAPPER_STATUS_NO_MEMORY;
170 eps->count -= num_ents;
173 return EPMAPPER_STATUS_OK;
178 implement epm_Map. This is used to find the specific endpoint to talk to given
179 a generic protocol tower
181 static error_status_t epm_Map(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
186 struct dcesrv_ep_iface *eps;
187 struct epm_floor *floors;
188 enum dcerpc_transport_t transport;
191 count = build_ep_list(mem_ctx, dce_call->conn->dce_ctx->endpoint_list, &eps);
193 ZERO_STRUCT(*r->out.entry_handle);
194 r->out.num_towers = 1;
195 r->out.towers = talloc_p(mem_ctx, struct epm_twr_p_t);
196 if (!r->out.towers) {
197 return EPMAPPER_STATUS_NO_MEMORY;
199 r->out.towers->twr = talloc_p(mem_ctx, struct epm_twr_t);
200 if (!r->out.towers->twr) {
201 return EPMAPPER_STATUS_NO_MEMORY;
204 if (!r->in.map_tower || r->in.max_towers == 0 ||
205 r->in.map_tower->tower.num_floors < 3) {
209 floors = r->in.map_tower->tower.floors;
211 if (floors[0].lhs.protocol != EPM_PROTOCOL_UUID ||
212 floors[1].lhs.protocol != EPM_PROTOCOL_UUID ||
213 guid_cmp(mem_ctx, &floors[1].lhs.info.uuid.uuid, NDR_GUID) != 0 ||
214 floors[1].lhs.info.uuid.version != NDR_GUID_VERSION) {
218 transport = dcerpc_transport_by_tower(&r->in.map_tower->tower);
220 if (transport == -1) {
221 DEBUG(1, ("Client requested unknown transport with levels: "));
222 for (i = 2; i < r->in.map_tower->tower.num_floors; i++) {
223 DEBUG(1, ("%d, ", r->in.map_tower->tower.floors[i].lhs.protocol));
228 for (i=0;i<count;i++) {
230 if (!GUID_equal(&floors[0].lhs.info.uuid.uuid, &eps[i].ep_description.object) ||
231 floors[0].lhs.info.uuid.version != eps[i].ep_description.object_version) {
235 if (transport != eps[i].ep_description.transport) {
239 status = dcerpc_binding_build_tower(mem_ctx,
240 &eps[i].ep_description,
243 if (NT_STATUS_IS_ERR(status)) {
244 return EPMAPPER_STATUS_NO_MEMORY;
246 r->out.towers->twr->tower = t;
247 r->out.towers->twr->tower_length = 0;
248 return EPMAPPER_STATUS_OK;
253 r->out.num_towers = 0;
254 r->out.towers->twr = NULL;
256 return EPMAPPER_STATUS_NO_MORE_ENTRIES;
259 static error_status_t epm_LookupHandleFree(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
260 struct epm_LookupHandleFree *r)
262 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
265 static error_status_t epm_InqObject(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
266 struct epm_InqObject *r)
268 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
271 static error_status_t epm_MgmtDelete(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
272 struct epm_MgmtDelete *r)
274 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
277 static error_status_t epm_MapAuth(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
278 struct epm_MapAuth *r)
280 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
283 /* include the generated boilerplate */
284 #include "librpc/gen_ndr/ndr_epmapper_s.c"