4 * Copyright 2002 Greg Turner
5 * Copyright 2001 Ove Kåven, TransGaming Technologies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * - actually do things right
35 #include "wine/debug.h"
37 #include "rpc_binding.h"
38 #include "epm_towers.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
42 /* The "real" RPC portmapper endpoints that I know of are:
46 * ncacn_np: \\pipe\epmapper (?)
49 * If the user's machine ran a DCE RPC daemon, it would
50 * probably be possible to connect to it, but there are many
51 * reasons not to, like:
52 * - the user probably does *not* run one, and probably
53 * shouldn't be forced to run one just for local COM
54 * - very few Unix systems use DCE RPC... if they run a RPC
55 * daemon at all, it's usually Sun RPC
56 * - DCE RPC registrations are persistent and saved on disk,
57 * while MS-RPC registrations are documented as non-persistent
58 * and stored only in RAM, and auto-destroyed when the process
59 * dies (something DCE RPC can't do)
61 * Of course, if the user *did* want to run a DCE RPC daemon anyway,
62 * there would be interoperability advantages, like the possibility
63 * of running a fully functional DCOM server using Wine...
66 /***********************************************************************
67 * RpcEpRegisterA (RPCRT4.@)
69 RPC_STATUS WINAPI
RpcEpRegisterA( RPC_IF_HANDLE IfSpec
, RPC_BINDING_VECTOR
*BindingVector
,
70 UUID_VECTOR
*UuidVector
, RPC_CSTR Annotation
)
74 char *vardata_payload
, *vp
;
75 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
77 RPC_STATUS rslt
= RPC_S_OK
;
79 TRACE("(%p,%p,%p,%s)\n", IfSpec
, BindingVector
, UuidVector
, debugstr_a((char*)Annotation
));
80 TRACE(" ifid=%s\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
));
81 for (c
=0; c
<BindingVector
->Count
; c
++) {
82 RpcBinding
* bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
83 TRACE(" protseq[%ld]=%s\n", c
, debugstr_a(bind
->Protseq
));
84 TRACE(" endpoint[%ld]=%s\n", c
, debugstr_a(bind
->Endpoint
));
87 for (c
=0; c
<UuidVector
->Count
; c
++)
88 TRACE(" obj[%ld]=%s\n", c
, debugstr_guid(UuidVector
->Uuid
[c
]));
91 /* FIXME: Do something with annotation. */
93 /* construct the message to rpcss */
94 msg
.message_type
= RPCSS_NP_MESSAGE_TYPEID_REGISTEREPMSG
;
95 msg
.message
.registerepmsg
.iface
= If
->InterfaceId
;
96 msg
.message
.registerepmsg
.no_replace
= 0;
98 msg
.message
.registerepmsg
.object_count
= (UuidVector
) ? UuidVector
->Count
: 0;
99 msg
.message
.registerepmsg
.binding_count
= BindingVector
->Count
;
101 /* calculate vardata payload size */
102 msg
.vardata_payload_size
= msg
.message
.registerepmsg
.object_count
* sizeof(UUID
);
103 for (c
=0; c
< msg
.message
.registerepmsg
.binding_count
; c
++) {
104 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
105 msg
.vardata_payload_size
+= strlen(bind
->Protseq
) + 1;
106 msg
.vardata_payload_size
+= strlen(bind
->Endpoint
) + 1;
109 /* allocate the payload buffer */
110 vp
= vardata_payload
= LocalAlloc(LPTR
, msg
.vardata_payload_size
);
111 if (!vardata_payload
)
112 return RPC_S_OUT_OF_MEMORY
;
114 /* populate the payload data */
115 for (c
=0; c
< msg
.message
.registerepmsg
.object_count
; c
++) {
116 CopyMemory(vp
, UuidVector
->Uuid
[c
], sizeof(UUID
));
120 for (c
=0; c
< msg
.message
.registerepmsg
.binding_count
; c
++) {
121 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
122 unsigned long pslen
= strlen(bind
->Protseq
) + 1, eplen
= strlen(bind
->Endpoint
) + 1;
123 CopyMemory(vp
, bind
->Protseq
, pslen
);
125 CopyMemory(vp
, bind
->Endpoint
, eplen
);
129 /* send our request */
130 if (!RPCRT4_RPCSSOnDemandCall(&msg
, vardata_payload
, &reply
))
131 rslt
= RPC_S_OUT_OF_MEMORY
;
133 /* free the payload buffer */
134 LocalFree(vardata_payload
);
139 /***********************************************************************
140 * RpcEpUnregister (RPCRT4.@)
142 RPC_STATUS WINAPI
RpcEpUnregister( RPC_IF_HANDLE IfSpec
, RPC_BINDING_VECTOR
*BindingVector
,
143 UUID_VECTOR
*UuidVector
)
145 RPCSS_NP_MESSAGE msg
;
146 RPCSS_NP_REPLY reply
;
147 char *vardata_payload
, *vp
;
148 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
150 RPC_STATUS rslt
= RPC_S_OK
;
152 TRACE("(%p,%p,%p)\n", IfSpec
, BindingVector
, UuidVector
);
153 TRACE(" ifid=%s\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
));
154 for (c
=0; c
<BindingVector
->Count
; c
++) {
155 RpcBinding
* bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
156 TRACE(" protseq[%ld]=%s\n", c
, debugstr_a(bind
->Protseq
));
157 TRACE(" endpoint[%ld]=%s\n", c
, debugstr_a(bind
->Endpoint
));
160 for (c
=0; c
<UuidVector
->Count
; c
++)
161 TRACE(" obj[%ld]=%s\n", c
, debugstr_guid(UuidVector
->Uuid
[c
]));
164 /* construct the message to rpcss */
165 msg
.message_type
= RPCSS_NP_MESSAGE_TYPEID_UNREGISTEREPMSG
;
166 msg
.message
.unregisterepmsg
.iface
= If
->InterfaceId
;
168 msg
.message
.unregisterepmsg
.object_count
= (UuidVector
) ? UuidVector
->Count
: 0;
169 msg
.message
.unregisterepmsg
.binding_count
= BindingVector
->Count
;
171 /* calculate vardata payload size */
172 msg
.vardata_payload_size
= msg
.message
.unregisterepmsg
.object_count
* sizeof(UUID
);
173 for (c
=0; c
< msg
.message
.unregisterepmsg
.binding_count
; c
++) {
174 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
175 msg
.vardata_payload_size
+= strlen(bind
->Protseq
) + 1;
176 msg
.vardata_payload_size
+= strlen(bind
->Endpoint
) + 1;
179 /* allocate the payload buffer */
180 vp
= vardata_payload
= LocalAlloc(LPTR
, msg
.vardata_payload_size
);
181 if (!vardata_payload
)
182 return RPC_S_OUT_OF_MEMORY
;
184 /* populate the payload data */
185 for (c
=0; c
< msg
.message
.unregisterepmsg
.object_count
; c
++) {
186 CopyMemory(vp
, UuidVector
->Uuid
[c
], sizeof(UUID
));
190 for (c
=0; c
< msg
.message
.unregisterepmsg
.binding_count
; c
++) {
191 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
192 unsigned long pslen
= strlen(bind
->Protseq
) + 1, eplen
= strlen(bind
->Endpoint
) + 1;
193 CopyMemory(vp
, bind
->Protseq
, pslen
);
195 CopyMemory(vp
, bind
->Endpoint
, eplen
);
199 /* send our request */
200 if (!RPCRT4_RPCSSOnDemandCall(&msg
, vardata_payload
, &reply
))
201 rslt
= RPC_S_OUT_OF_MEMORY
;
203 /* free the payload buffer */
204 LocalFree(vardata_payload
);
209 /***********************************************************************
210 * RpcEpResolveBinding (RPCRT4.@)
212 RPC_STATUS WINAPI
RpcEpResolveBinding( RPC_BINDING_HANDLE Binding
, RPC_IF_HANDLE IfSpec
)
214 RPCSS_NP_MESSAGE msg
;
215 RPCSS_NP_REPLY reply
;
216 PRPC_CLIENT_INTERFACE If
= (PRPC_CLIENT_INTERFACE
)IfSpec
;
217 RpcBinding
* bind
= (RpcBinding
*)Binding
;
219 TRACE("(%p,%p)\n", Binding
, IfSpec
);
220 TRACE(" protseq=%s\n", debugstr_a(bind
->Protseq
));
221 TRACE(" obj=%s\n", debugstr_guid(&bind
->ObjectUuid
));
222 TRACE(" ifid=%s\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
));
224 /* FIXME: totally untested */
226 /* just return for fully bound handles */
227 if (bind
->Endpoint
&& (bind
->Endpoint
[0] != '\0'))
230 /* construct the message to rpcss */
231 msg
.message_type
= RPCSS_NP_MESSAGE_TYPEID_RESOLVEEPMSG
;
232 msg
.message
.resolveepmsg
.iface
= If
->InterfaceId
;
233 msg
.message
.resolveepmsg
.object
= bind
->ObjectUuid
;
235 msg
.vardata_payload_size
= strlen(bind
->Protseq
) + 1;
237 /* send the message */
238 if (!RPCRT4_RPCSSOnDemandCall(&msg
, bind
->Protseq
, &reply
))
239 return RPC_S_OUT_OF_MEMORY
;
241 /* empty-string result means not registered */
242 if (reply
.as_string
[0] == '\0')
243 return EPT_S_NOT_REGISTERED
;
245 /* otherwise we fully bind the handle & return RPC_S_OK */
246 return RPCRT4_ResolveBinding(Binding
, reply
.as_string
);
249 typedef unsigned int unsigned32
;
252 unsigned32 tower_length
;
253 /* [size_is] */ BYTE tower_octet_string
[ 1 ];
256 /***********************************************************************
257 * TowerExplode (RPCRT4.@)
259 RPC_STATUS WINAPI
TowerExplode(
260 const twr_t
*tower
, PRPC_SYNTAX_IDENTIFIER object
, PRPC_SYNTAX_IDENTIFIER syntax
,
261 char **protseq
, char **endpoint
, char **address
)
265 const unsigned char *p
;
267 const twr_uuid_floor_t
*object_floor
;
268 const twr_uuid_floor_t
*syntax_floor
;
270 TRACE("(%p, %p, %p, %p, %p, %p)\n", tower
, object
, syntax
, protseq
,
280 tower_size
= tower
->tower_length
;
282 if (tower_size
< sizeof(u_int16
))
283 return EPT_S_NOT_REGISTERED
;
285 p
= &tower
->tower_octet_string
[0];
287 floor_count
= *(const u_int16
*)p
;
288 p
+= sizeof(u_int16
);
289 tower_size
-= sizeof(u_int16
);
290 TRACE("floor_count: %d\n", floor_count
);
291 /* FIXME: should we do something with the floor count? at the moment we don't */
293 if (tower_size
< sizeof(*object_floor
) + sizeof(*syntax_floor
))
294 return EPT_S_NOT_REGISTERED
;
296 object_floor
= (const twr_uuid_floor_t
*)p
;
297 p
+= sizeof(*object_floor
);
298 tower_size
-= sizeof(*object_floor
);
299 syntax_floor
= (const twr_uuid_floor_t
*)p
;
300 p
+= sizeof(*syntax_floor
);
301 tower_size
-= sizeof(*syntax_floor
);
303 if ((object_floor
->count_lhs
!= sizeof(object_floor
->protid
) +
304 sizeof(object_floor
->uuid
) + sizeof(object_floor
->major_version
)) ||
305 (object_floor
->protid
!= EPM_PROTOCOL_UUID
) ||
306 (object_floor
->count_rhs
!= sizeof(object_floor
->minor_version
)))
307 return EPT_S_NOT_REGISTERED
;
309 if ((syntax_floor
->count_lhs
!= sizeof(syntax_floor
->protid
) +
310 sizeof(syntax_floor
->uuid
) + sizeof(syntax_floor
->major_version
)) ||
311 (syntax_floor
->protid
!= EPM_PROTOCOL_UUID
) ||
312 (syntax_floor
->count_rhs
!= sizeof(syntax_floor
->minor_version
)))
313 return EPT_S_NOT_REGISTERED
;
315 status
= RpcTransport_ParseTopOfTower(p
, tower_size
, protseq
, address
, endpoint
);
316 if ((status
== RPC_S_OK
) && syntax
&& object
)
318 syntax
->SyntaxGUID
= syntax_floor
->uuid
;
319 syntax
->SyntaxVersion
.MajorVersion
= syntax_floor
->major_version
;
320 syntax
->SyntaxVersion
.MinorVersion
= syntax_floor
->minor_version
;
321 object
->SyntaxGUID
= object_floor
->uuid
;
322 object
->SyntaxVersion
.MajorVersion
= object_floor
->major_version
;
323 object
->SyntaxVersion
.MinorVersion
= object_floor
->minor_version
;
328 /***********************************************************************
329 * TowerConstruct (RPCRT4.@)
331 RPC_STATUS WINAPI
TowerConstruct(
332 const RPC_SYNTAX_IDENTIFIER
*object
, const RPC_SYNTAX_IDENTIFIER
*syntax
,
333 const char *protseq
, const char *endpoint
, const char *address
,
339 twr_uuid_floor_t
*object_floor
;
340 twr_uuid_floor_t
*syntax_floor
;
342 TRACE("(%p, %p, %s, %s, %s, %p)\n", object
, syntax
, debugstr_a(protseq
),
343 debugstr_a(endpoint
), debugstr_a(address
), tower
);
347 status
= RpcTransport_GetTopOfTower(NULL
, &tower_size
, protseq
, address
, endpoint
);
349 if (status
!= RPC_S_OK
)
352 tower_size
+= sizeof(u_int16
) + sizeof(*object_floor
) + sizeof(*syntax_floor
);
353 *tower
= I_RpcAllocate(FIELD_OFFSET(twr_t
, tower_octet_string
[tower_size
]));
355 return RPC_S_OUT_OF_RESOURCES
;
357 (*tower
)->tower_length
= tower_size
;
358 p
= &(*tower
)->tower_octet_string
[0];
359 *(u_int16
*)p
= 5; /* number of floors */
360 p
+= sizeof(u_int16
);
361 object_floor
= (twr_uuid_floor_t
*)p
;
362 p
+= sizeof(*object_floor
);
363 syntax_floor
= (twr_uuid_floor_t
*)p
;
364 p
+= sizeof(*syntax_floor
);
366 object_floor
->count_lhs
= sizeof(object_floor
->protid
) + sizeof(object_floor
->uuid
) +
367 sizeof(object_floor
->major_version
);
368 object_floor
->protid
= EPM_PROTOCOL_UUID
;
369 object_floor
->count_rhs
= sizeof(object_floor
->minor_version
);
370 object_floor
->uuid
= object
->SyntaxGUID
;
371 object_floor
->major_version
= object
->SyntaxVersion
.MajorVersion
;
372 object_floor
->minor_version
= object
->SyntaxVersion
.MinorVersion
;
374 syntax_floor
->count_lhs
= sizeof(syntax_floor
->protid
) + sizeof(syntax_floor
->uuid
) +
375 sizeof(syntax_floor
->major_version
);
376 syntax_floor
->protid
= EPM_PROTOCOL_UUID
;
377 syntax_floor
->count_rhs
= sizeof(syntax_floor
->minor_version
);
378 syntax_floor
->uuid
= syntax
->SyntaxGUID
;
379 syntax_floor
->major_version
= syntax
->SyntaxVersion
.MajorVersion
;
380 syntax_floor
->minor_version
= syntax
->SyntaxVersion
.MinorVersion
;
382 status
= RpcTransport_GetTopOfTower(p
, &tower_size
, protseq
, address
, endpoint
);
383 if (status
!= RPC_S_OK
)