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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - actually do things right
35 #include "wine/debug.h"
37 #include "rpc_binding.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
41 /* The "real" RPC portmapper endpoints that I know of are:
45 * ncacn_np: \\pipe\epmapper (?)
48 * If the user's machine ran a DCE RPC daemon, it would
49 * probably be possible to connect to it, but there are many
50 * reasons not to, like:
51 * - the user probably does *not* run one, and probably
52 * shouldn't be forced to run one just for local COM
53 * - very few Unix systems use DCE RPC... if they run a RPC
54 * daemon at all, it's usually Sun RPC
55 * - DCE RPC registrations are persistent and saved on disk,
56 * while MS-RPC registrations are documented as non-persistent
57 * and stored only in RAM, and auto-destroyed when the process
58 * dies (something DCE RPC can't do)
60 * Of course, if the user *did* want to run a DCE RPC daemon anyway,
61 * there would be interoperability advantages, like the possibility
62 * of running a fully functional DCOM server using Wine...
65 /***********************************************************************
66 * RpcEpRegisterA (RPCRT4.@)
68 RPC_STATUS WINAPI
RpcEpRegisterA( RPC_IF_HANDLE IfSpec
, PRPC_BINDING_VECTOR BindingVector
,
69 PUUID_VECTOR UuidVector
, LPSTR Annotation
)
73 char *vardata_payload
, *vp
;
74 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
76 RPC_STATUS rslt
= RPC_S_OK
;
78 TRACE("(%p,%p,%p,%s)\n", IfSpec
, BindingVector
, UuidVector
, debugstr_a(Annotation
));
79 TRACE(" ifid=%s\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
));
80 for (c
=0; c
<BindingVector
->Count
; c
++) {
81 RpcBinding
* bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
82 TRACE(" protseq[%ld]=%s\n", c
, debugstr_a(bind
->Protseq
));
83 TRACE(" endpoint[%ld]=%s\n", c
, debugstr_a(bind
->Endpoint
));
86 for (c
=0; c
<UuidVector
->Count
; c
++)
87 TRACE(" obj[%ld]=%s\n", c
, debugstr_guid(UuidVector
->Uuid
[c
]));
90 /* FIXME: Do something with annotation. */
92 /* construct the message to rpcss */
93 msg
.message_type
= RPCSS_NP_MESSAGE_TYPEID_REGISTEREPMSG
;
94 msg
.message
.registerepmsg
.iface
= If
->InterfaceId
;
95 msg
.message
.registerepmsg
.no_replace
= 0;
97 msg
.message
.registerepmsg
.object_count
= (UuidVector
) ? UuidVector
->Count
: 0;
98 msg
.message
.registerepmsg
.binding_count
= BindingVector
->Count
;
100 /* calculate vardata payload size */
101 msg
.vardata_payload_size
= msg
.message
.registerepmsg
.object_count
* sizeof(UUID
);
102 for (c
=0; c
< msg
.message
.registerepmsg
.binding_count
; c
++) {
103 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
104 msg
.vardata_payload_size
+= strlen(bind
->Protseq
) + 1;
105 msg
.vardata_payload_size
+= strlen(bind
->Endpoint
) + 1;
108 /* allocate the payload buffer */
109 vp
= vardata_payload
= LocalAlloc(LPTR
, msg
.vardata_payload_size
);
110 if (!vardata_payload
)
111 return RPC_S_OUT_OF_MEMORY
;
113 /* populate the payload data */
114 for (c
=0; c
< msg
.message
.registerepmsg
.object_count
; c
++) {
115 CopyMemory(vp
, UuidVector
->Uuid
[c
], sizeof(UUID
));
119 for (c
=0; c
< msg
.message
.registerepmsg
.binding_count
; c
++) {
120 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
121 unsigned long pslen
= strlen(bind
->Protseq
) + 1, eplen
= strlen(bind
->Endpoint
) + 1;
122 CopyMemory(vp
, bind
->Protseq
, pslen
);
124 CopyMemory(vp
, bind
->Endpoint
, eplen
);
128 /* send our request */
129 if (!RPCRT4_RPCSSOnDemandCall(&msg
, vardata_payload
, &reply
))
130 rslt
= RPC_S_OUT_OF_MEMORY
;
132 /* free the payload buffer */
133 LocalFree(vardata_payload
);
138 /***********************************************************************
139 * RpcEpUnregister (RPCRT4.@)
141 RPC_STATUS WINAPI
RpcEpUnregister( RPC_IF_HANDLE IfSpec
, PRPC_BINDING_VECTOR BindingVector
,
142 PUUID_VECTOR UuidVector
)
144 RPCSS_NP_MESSAGE msg
;
145 RPCSS_NP_REPLY reply
;
146 char *vardata_payload
, *vp
;
147 PRPC_SERVER_INTERFACE If
= (PRPC_SERVER_INTERFACE
)IfSpec
;
149 RPC_STATUS rslt
= RPC_S_OK
;
151 TRACE("(%p,%p,%p)\n", IfSpec
, BindingVector
, UuidVector
);
152 TRACE(" ifid=%s\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
));
153 for (c
=0; c
<BindingVector
->Count
; c
++) {
154 RpcBinding
* bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
155 TRACE(" protseq[%ld]=%s\n", c
, debugstr_a(bind
->Protseq
));
156 TRACE(" endpoint[%ld]=%s\n", c
, debugstr_a(bind
->Endpoint
));
159 for (c
=0; c
<UuidVector
->Count
; c
++)
160 TRACE(" obj[%ld]=%s\n", c
, debugstr_guid(UuidVector
->Uuid
[c
]));
163 /* construct the message to rpcss */
164 msg
.message_type
= RPCSS_NP_MESSAGE_TYPEID_UNREGISTEREPMSG
;
165 msg
.message
.unregisterepmsg
.iface
= If
->InterfaceId
;
167 msg
.message
.unregisterepmsg
.object_count
= (UuidVector
) ? UuidVector
->Count
: 0;
168 msg
.message
.unregisterepmsg
.binding_count
= BindingVector
->Count
;
170 /* calculate vardata payload size */
171 msg
.vardata_payload_size
= msg
.message
.unregisterepmsg
.object_count
* sizeof(UUID
);
172 for (c
=0; c
< msg
.message
.unregisterepmsg
.binding_count
; c
++) {
173 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
174 msg
.vardata_payload_size
+= strlen(bind
->Protseq
) + 1;
175 msg
.vardata_payload_size
+= strlen(bind
->Endpoint
) + 1;
178 /* allocate the payload buffer */
179 vp
= vardata_payload
= LocalAlloc(LPTR
, msg
.vardata_payload_size
);
180 if (!vardata_payload
)
181 return RPC_S_OUT_OF_MEMORY
;
183 /* populate the payload data */
184 for (c
=0; c
< msg
.message
.unregisterepmsg
.object_count
; c
++) {
185 CopyMemory(vp
, UuidVector
->Uuid
[c
], sizeof(UUID
));
189 for (c
=0; c
< msg
.message
.unregisterepmsg
.binding_count
; c
++) {
190 RpcBinding
*bind
= (RpcBinding
*)(BindingVector
->BindingH
[c
]);
191 unsigned long pslen
= strlen(bind
->Protseq
) + 1, eplen
= strlen(bind
->Endpoint
) + 1;
192 CopyMemory(vp
, bind
->Protseq
, pslen
);
194 CopyMemory(vp
, bind
->Endpoint
, eplen
);
198 /* send our request */
199 if (!RPCRT4_RPCSSOnDemandCall(&msg
, vardata_payload
, &reply
))
200 rslt
= RPC_S_OUT_OF_MEMORY
;
202 /* free the payload buffer */
203 LocalFree(vardata_payload
);
208 /***********************************************************************
209 * RpcEpResolveBinding (RPCRT4.@)
211 RPC_STATUS WINAPI
RpcEpResolveBinding( RPC_BINDING_HANDLE Binding
, RPC_IF_HANDLE IfSpec
)
213 RPCSS_NP_MESSAGE msg
;
214 RPCSS_NP_REPLY reply
;
215 PRPC_CLIENT_INTERFACE If
= (PRPC_CLIENT_INTERFACE
)IfSpec
;
216 RpcBinding
* bind
= (RpcBinding
*)Binding
;
218 TRACE("(%p,%p)\n", Binding
, IfSpec
);
219 TRACE(" protseq=%s\n", debugstr_a(bind
->Protseq
));
220 TRACE(" obj=%s\n", debugstr_guid(&bind
->ObjectUuid
));
221 TRACE(" ifid=%s\n", debugstr_guid(&If
->InterfaceId
.SyntaxGUID
));
223 /* FIXME: totally untested */
225 /* just return for fully bound handles */
226 if (bind
->Endpoint
&& (bind
->Endpoint
[0] != '\0'))
229 /* construct the message to rpcss */
230 msg
.message_type
= RPCSS_NP_MESSAGE_TYPEID_RESOLVEEPMSG
;
231 msg
.message
.resolveepmsg
.iface
= If
->InterfaceId
;
232 msg
.message
.resolveepmsg
.object
= bind
->ObjectUuid
;
234 msg
.vardata_payload_size
= strlen(bind
->Protseq
) + 1;
236 /* send the message */
237 if (!RPCRT4_RPCSSOnDemandCall(&msg
, bind
->Protseq
, &reply
))
238 return RPC_S_OUT_OF_MEMORY
;
240 /* empty-string result means not registered */
241 if (reply
.as_string
[0] == '\0')
242 return EPT_S_NOT_REGISTERED
;
244 /* otherwise we fully bind the handle & return RPC_S_OK */
245 return RPCRT4_ResolveBinding(Binding
, reply
.as_string
);