4 * Copyright 2000 Huw D M Davies for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * WINE RPC TODO's (and a few TODONT's)
22 * - Ove's decreasingly incomplete widl is an IDL compiler for wine. For widl
23 * to be wine's only IDL compiler, a fair bit of work remains to be done.
24 * until then we have used some midl-generated stuff. (What?)
25 * widl currently doesn't generate stub/proxy files required by wine's (O)RPC
26 * capabilities -- nor does it make those lovely format strings :(
27 * The MS MIDL compiler does some really esoteric stuff. Of course Ove has
28 * started with the less esoteric stuff. There are also lots of nice
29 * comments in there if you want to flex your bison and help build this monster.
31 * - RPC has a quite featureful error handling mechanism; basically none of this is
32 * implemented right now. We also have deficiencies on the compiler side, where
33 * wine's __TRY / __EXCEPT / __FINALLY macros are not even used for RpcTryExcept & co,
34 * due to syntactic differences! (we can fix it with widl by using __TRY)
36 * - There are several different memory allocation schemes for MSRPC.
37 * I don't even understand what they all are yet, much less have them
38 * properly implemented. Surely we are supposed to be doing something with
39 * the user-provided allocation/deallocation functions, but so far,
40 * I don't think we are doing this...
42 * - MSRPC provides impersonation capabilities which currently are not possible
43 * to implement in wine. At the very least we should implement the authorization
44 * API's & gracefully ignore the irrelevant stuff (to an extent we already do).
46 * - Some transports are not yet implemented. The existing transport implementations
47 * are incomplete and may be bug-infested.
49 * - The various transports that we do support ought to be supported in a more
50 * object-oriented manner, as in DCE's RPC implementation, instead of cluttering
51 * up the code with conditionals like we do now.
53 * - Data marshalling: So far, only the beginnings of a full implementation
54 * exist in wine. NDR protocol itself is documented, but the MS API's to
55 * convert data-types in memory into NDR are not. This is challenging work,
56 * and has supposedly been "at the top of Greg's queue" for several months now.
58 * - ORPC is RPC for OLE; once we have a working RPC framework, we can
59 * use it to implement out-of-process OLE client/server communications.
60 * ATM there is maybe a disconnect between the marshalling in the OLE DLLs
61 * and the marshalling going on here [TODO: well, is there or not?]
63 * - In-source API Documentation, at least for those functions which we have
64 * implemented, but preferably for everything we can document, would be nice,
65 * since some of this stuff is quite obscure.
67 * - Name services... [TODO: what about them]
69 * - Protocol Towers: Totally unimplemented.... I think.
71 * - Context Handle Rundown: whatever that is.
73 * - Nested RPC's: Totally unimplemented.
75 * - Statistics: we are supposed to be keeping various counters. we aren't.
77 * - Async RPC: Unimplemented.
79 * - XML/http RPC: Somewhere there's an XML fiend that wants to do this! Betcha
80 * we could use these as a transport for RPC's across computers without a
81 * permissions and/or licensing crisis.
83 * - The NT "ports" API, aka LPC. Greg claims this is on his radar. Might (or
84 * might not) enable users to get some kind of meaningful result out of
85 * NT-based native rpcrt4's. Commonly-used transport for self-to-self RPC's.
87 * - ...? More stuff I haven't thought of. If you think of more RPC todo's
88 * drop me an e-mail <gmturner007@ameritech.net> or send a patch to the
89 * wine-patches mailing list.
100 #include "winerror.h"
104 #include "iphlpapi.h"
105 #include "wine/unicode.h"
110 #include "rpcproxy.h"
112 #include "rpc_binding.h"
113 #include "rpcss_np_client.h"
115 #include "wine/debug.h"
117 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
119 static UUID uuid_nil
;
120 static HANDLE master_mutex
;
122 HANDLE
RPCRT4_GetMasterMutex(void)
127 static CRITICAL_SECTION uuid_cs
;
128 static CRITICAL_SECTION_DEBUG critsect_debug
=
131 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
132 0, 0, { (DWORD_PTR
)(__FILE__
": uuid_cs") }
134 static CRITICAL_SECTION uuid_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
136 /***********************************************************************
140 * hinstDLL [I] handle to the DLL's instance
142 * lpvReserved [I] reserved, must be NULL
149 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
152 case DLL_PROCESS_ATTACH
:
153 DisableThreadLibraryCalls(hinstDLL
);
154 master_mutex
= CreateMutexA( NULL
, FALSE
, RPCSS_MASTER_MUTEX_NAME
);
157 case DLL_PROCESS_DETACH
:
158 CloseHandle(master_mutex
);
166 /*************************************************************************
167 * RpcStringFreeA [RPCRT4.@]
169 * Frees a character string allocated by the RPC run-time library.
173 * S_OK if successful.
175 RPC_STATUS WINAPI
RpcStringFreeA(unsigned char** String
)
177 HeapFree( GetProcessHeap(), 0, *String
);
182 /*************************************************************************
183 * RpcStringFreeW [RPCRT4.@]
185 * Frees a character string allocated by the RPC run-time library.
189 * S_OK if successful.
191 RPC_STATUS WINAPI
RpcStringFreeW(unsigned short** String
)
193 HeapFree( GetProcessHeap(), 0, *String
);
198 /*************************************************************************
199 * RpcRaiseException [RPCRT4.@]
201 * Raises an exception.
203 void WINAPI
RpcRaiseException(RPC_STATUS exception
)
205 /* FIXME: translate exception? */
206 RaiseException(exception
, 0, 0, NULL
);
209 /*************************************************************************
210 * UuidCompare [RPCRT4.@]
213 * UUID *Uuid1 [I] Uuid to compare
214 * UUID *Uuid2 [I] Uuid to compare
215 * RPC_STATUS *Status [O] returns RPC_S_OK
218 * -1 if Uuid1 is less than Uuid2
219 * 0 if Uuid1 and Uuid2 are equal
220 * 1 if Uuid1 is greater than Uuid2
222 int WINAPI
UuidCompare(UUID
*Uuid1
, UUID
*Uuid2
, RPC_STATUS
*Status
)
226 TRACE("(%s,%s)\n", debugstr_guid(Uuid1
), debugstr_guid(Uuid2
));
230 if (!Uuid1
) Uuid1
= &uuid_nil
;
231 if (!Uuid2
) Uuid2
= &uuid_nil
;
233 if (Uuid1
== Uuid2
) return 0;
235 if (Uuid1
->Data1
!= Uuid2
->Data1
)
236 return Uuid1
->Data1
< Uuid2
->Data1
? -1 : 1;
238 if (Uuid1
->Data2
!= Uuid2
->Data2
)
239 return Uuid1
->Data2
< Uuid2
->Data2
? -1 : 1;
241 if (Uuid1
->Data3
!= Uuid2
->Data3
)
242 return Uuid1
->Data3
< Uuid2
->Data3
? -1 : 1;
244 for (i
= 0; i
< 8; i
++) {
245 if (Uuid1
->Data4
[i
] < Uuid2
->Data4
[i
])
247 if (Uuid1
->Data4
[i
] > Uuid2
->Data4
[i
])
254 /*************************************************************************
255 * UuidEqual [RPCRT4.@]
258 * UUID *Uuid1 [I] Uuid to compare
259 * UUID *Uuid2 [I] Uuid to compare
260 * RPC_STATUS *Status [O] returns RPC_S_OK
265 int WINAPI
UuidEqual(UUID
*Uuid1
, UUID
*Uuid2
, RPC_STATUS
*Status
)
267 TRACE("(%s,%s)\n", debugstr_guid(Uuid1
), debugstr_guid(Uuid2
));
268 return !UuidCompare(Uuid1
, Uuid2
, Status
);
271 /*************************************************************************
272 * UuidIsNil [RPCRT4.@]
275 * UUID *Uuid [I] Uuid to compare
276 * RPC_STATUS *Status [O] retuns RPC_S_OK
281 int WINAPI
UuidIsNil(UUID
*Uuid
, RPC_STATUS
*Status
)
283 TRACE("(%s)\n", debugstr_guid(Uuid
));
284 if (!Uuid
) return TRUE
;
285 return !UuidCompare(Uuid
, &uuid_nil
, Status
);
288 /*************************************************************************
289 * UuidCreateNil [RPCRT4.@]
292 * UUID *Uuid [O] returns a nil UUID
297 RPC_STATUS WINAPI
UuidCreateNil(UUID
*Uuid
)
303 /* Number of 100ns ticks per clock tick. To be safe, assume that the clock
304 resolution is at least 1000 * 100 * (1/1000000) = 1/10 of a second */
305 #define TICKS_PER_CLOCK_TICK 1000
306 #define SECSPERDAY 86400
307 #define TICKSPERSEC 10000000
308 /* UUID system time starts at October 15, 1582 */
309 #define SECS_15_OCT_1582_TO_1601 ((17 + 30 + 31 + 365 * 18 + 5) * SECSPERDAY)
310 #define TICKS_15_OCT_1582_TO_1601 ((ULONGLONG)SECS_15_OCT_1582_TO_1601 * TICKSPERSEC)
312 static void RPC_UuidGetSystemTime(ULONGLONG
*time
)
316 GetSystemTimeAsFileTime(&ft
);
318 *time
= ((ULONGLONG
)ft
.dwHighDateTime
<< 32) | ft
.dwLowDateTime
;
319 *time
+= TICKS_15_OCT_1582_TO_1601
;
322 typedef DWORD
WINAPI (*LPGETADAPTERSINFO
)(PIP_ADAPTER_INFO pAdapterInfo
, PULONG pOutBufLen
);
324 /* Assume that a hardware address is at least 6 bytes long */
325 #define ADDRESS_BYTES_NEEDED 6
327 static RPC_STATUS
RPC_UuidGetNodeAddress(BYTE
*address
)
330 DWORD status
= RPC_S_OK
;
332 ULONG buflen
= sizeof(IP_ADAPTER_INFO
);
333 PIP_ADAPTER_INFO adapter
= HeapAlloc(GetProcessHeap(), 0, buflen
);
335 LPGETADAPTERSINFO pGetAdaptersInfo
;
337 hIpHlpApi
= LoadLibrary("iphlpapi.dll");
340 pGetAdaptersInfo
= (LPGETADAPTERSINFO
)GetProcAddress(hIpHlpApi
, "GetAdaptersInfo");
341 if (pGetAdaptersInfo
)
343 if (pGetAdaptersInfo(adapter
, &buflen
) == ERROR_BUFFER_OVERFLOW
) {
344 HeapFree(GetProcessHeap(), 0, adapter
);
345 adapter
= HeapAlloc(GetProcessHeap(), 0, buflen
);
348 if (pGetAdaptersInfo(adapter
, &buflen
) == NO_ERROR
) {
349 for (i
= 0; i
< ADDRESS_BYTES_NEEDED
; i
++) {
350 address
[i
] = adapter
->Address
[i
];
359 /* Free the Library */
360 FreeLibrary(hIpHlpApi
);
365 /* We can't get a hardware address, just use random numbers.
366 Set the multicast bit to prevent conflicts with real cards. */
367 for (i
= 0; i
< ADDRESS_BYTES_NEEDED
; i
++) {
368 address
[i
] = rand() & 0xff;
371 status
= RPC_S_UUID_LOCAL_ONLY
;
374 HeapFree(GetProcessHeap(), 0, adapter
);
378 /*************************************************************************
379 * UuidCreate [RPCRT4.@]
381 * Creates a 128bit UUID.
385 * RPC_S_OK if successful.
386 * RPC_S_UUID_LOCAL_ONLY if UUID is only locally unique.
388 * FIXME: No compensation for changes across reloading
389 * this dll or across reboots (e.g. clock going
390 * backwards and swapped network cards). The RFC
391 * suggests using NVRAM for storing persistent
394 RPC_STATUS WINAPI
UuidCreate(UUID
*Uuid
)
396 static int initialised
, count
;
399 static ULONGLONG timelast
;
400 static WORD sequence
;
403 static BYTE address
[MAX_ADAPTER_ADDRESS_LENGTH
];
405 EnterCriticalSection(&uuid_cs
);
408 RPC_UuidGetSystemTime(&timelast
);
409 count
= TICKS_PER_CLOCK_TICK
;
411 sequence
= ((rand() & 0xff) << 8) + (rand() & 0xff);
414 status
= RPC_UuidGetNodeAddress(address
);
418 /* Generate time element of the UUID. Account for going faster
419 than our clock as well as the clock going backwards. */
421 RPC_UuidGetSystemTime(&time
);
422 if (time
> timelast
) {
426 if (time
< timelast
) {
427 sequence
= (sequence
+ 1) & 0x1fff;
431 if (count
< TICKS_PER_CLOCK_TICK
) {
440 /* Pack the information into the UUID structure. */
442 Uuid
->Data1
= (unsigned long)(time
& 0xffffffff);
443 Uuid
->Data2
= (unsigned short)((time
>> 32) & 0xffff);
444 Uuid
->Data3
= (unsigned short)((time
>> 48) & 0x0fff);
446 /* This is a version 1 UUID */
447 Uuid
->Data3
|= (1 << 12);
449 Uuid
->Data4
[0] = sequence
& 0xff;
450 Uuid
->Data4
[1] = (sequence
& 0x3f00) >> 8;
451 Uuid
->Data4
[1] |= 0x80;
453 Uuid
->Data4
[2] = address
[0];
454 Uuid
->Data4
[3] = address
[1];
455 Uuid
->Data4
[4] = address
[2];
456 Uuid
->Data4
[5] = address
[3];
457 Uuid
->Data4
[6] = address
[4];
458 Uuid
->Data4
[7] = address
[5];
460 LeaveCriticalSection(&uuid_cs
);
462 TRACE("%s\n", debugstr_guid(Uuid
));
467 /*************************************************************************
468 * UuidCreateSequential [RPCRT4.@]
470 * Creates a 128bit UUID.
474 * RPC_S_OK if successful.
475 * RPC_S_UUID_LOCAL_ONLY if UUID is only locally unique.
478 RPC_STATUS WINAPI
UuidCreateSequential(UUID
*Uuid
)
480 return UuidCreate(Uuid
);
484 /*************************************************************************
485 * UuidHash [RPCRT4.@]
487 * Generates a hash value for a given UUID
489 * Code based on FreeDCE implementation
492 unsigned short WINAPI
UuidHash(UUID
*uuid
, RPC_STATUS
*Status
)
494 BYTE
*data
= (BYTE
*)uuid
;
495 short c0
= 0, c1
= 0, x
, y
;
498 if (!uuid
) data
= (BYTE
*)(uuid
= &uuid_nil
);
500 TRACE("(%s)\n", debugstr_guid(uuid
));
502 for (i
=0; i
<sizeof(UUID
); i
++) {
517 /*************************************************************************
518 * UuidToStringA [RPCRT4.@]
520 * Converts a UUID to a string.
522 * UUID format is 8 hex digits, followed by a hyphen then three groups of
523 * 4 hex digits each followed by a hyphen and then 12 hex digits
527 * S_OK if successful.
528 * S_OUT_OF_MEMORY if unsucessful.
530 RPC_STATUS WINAPI
UuidToStringA(UUID
*Uuid
, unsigned char** StringUuid
)
532 *StringUuid
= HeapAlloc( GetProcessHeap(), 0, sizeof(char) * 37);
535 return RPC_S_OUT_OF_MEMORY
;
537 if (!Uuid
) Uuid
= &uuid_nil
;
539 sprintf( (char*)*StringUuid
, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
540 Uuid
->Data1
, Uuid
->Data2
, Uuid
->Data3
,
541 Uuid
->Data4
[0], Uuid
->Data4
[1], Uuid
->Data4
[2],
542 Uuid
->Data4
[3], Uuid
->Data4
[4], Uuid
->Data4
[5],
543 Uuid
->Data4
[6], Uuid
->Data4
[7] );
548 /*************************************************************************
549 * UuidToStringW [RPCRT4.@]
551 * Converts a UUID to a string.
553 * S_OK if successful.
554 * S_OUT_OF_MEMORY if unsucessful.
556 RPC_STATUS WINAPI
UuidToStringW(UUID
*Uuid
, unsigned short** StringUuid
)
560 if (!Uuid
) Uuid
= &uuid_nil
;
562 sprintf(buf
, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
563 Uuid
->Data1
, Uuid
->Data2
, Uuid
->Data3
,
564 Uuid
->Data4
[0], Uuid
->Data4
[1], Uuid
->Data4
[2],
565 Uuid
->Data4
[3], Uuid
->Data4
[4], Uuid
->Data4
[5],
566 Uuid
->Data4
[6], Uuid
->Data4
[7] );
568 *StringUuid
= RPCRT4_strdupAtoW(buf
);
571 return RPC_S_OUT_OF_MEMORY
;
576 static const BYTE hex2bin
[] =
578 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
579 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
580 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
581 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
582 0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
583 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
584 0,10,11,12,13,14,15 /* 0x60 */
587 /***********************************************************************
588 * UuidFromStringA (RPCRT4.@)
590 RPC_STATUS WINAPI
UuidFromStringA(unsigned char* s
, UUID
*uuid
)
594 if (!s
) return UuidCreateNil( uuid
);
596 if (strlen((char*)s
) != 36) return RPC_S_INVALID_STRING_UUID
;
598 if ((s
[8]!='-') || (s
[13]!='-') || (s
[18]!='-') || (s
[23]!='-'))
599 return RPC_S_INVALID_STRING_UUID
;
603 if ((i
== 8)||(i
== 13)||(i
== 18)||(i
== 23)) continue;
604 if (s
[i
] > 'f' || (!hex2bin
[s
[i
]] && s
[i
] != '0')) return RPC_S_INVALID_STRING_UUID
;
607 /* in form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */
609 uuid
->Data1
= (hex2bin
[s
[0]] << 28 | hex2bin
[s
[1]] << 24 | hex2bin
[s
[2]] << 20 | hex2bin
[s
[3]] << 16 |
610 hex2bin
[s
[4]] << 12 | hex2bin
[s
[5]] << 8 | hex2bin
[s
[6]] << 4 | hex2bin
[s
[7]]);
611 uuid
->Data2
= hex2bin
[s
[9]] << 12 | hex2bin
[s
[10]] << 8 | hex2bin
[s
[11]] << 4 | hex2bin
[s
[12]];
612 uuid
->Data3
= hex2bin
[s
[14]] << 12 | hex2bin
[s
[15]] << 8 | hex2bin
[s
[16]] << 4 | hex2bin
[s
[17]];
614 /* these are just sequential bytes */
615 uuid
->Data4
[0] = hex2bin
[s
[19]] << 4 | hex2bin
[s
[20]];
616 uuid
->Data4
[1] = hex2bin
[s
[21]] << 4 | hex2bin
[s
[22]];
617 uuid
->Data4
[2] = hex2bin
[s
[24]] << 4 | hex2bin
[s
[25]];
618 uuid
->Data4
[3] = hex2bin
[s
[26]] << 4 | hex2bin
[s
[27]];
619 uuid
->Data4
[4] = hex2bin
[s
[28]] << 4 | hex2bin
[s
[29]];
620 uuid
->Data4
[5] = hex2bin
[s
[30]] << 4 | hex2bin
[s
[31]];
621 uuid
->Data4
[6] = hex2bin
[s
[32]] << 4 | hex2bin
[s
[33]];
622 uuid
->Data4
[7] = hex2bin
[s
[34]] << 4 | hex2bin
[s
[35]];
627 /***********************************************************************
628 * UuidFromStringW (RPCRT4.@)
630 RPC_STATUS WINAPI
UuidFromStringW(unsigned short* s
, UUID
*uuid
)
634 if (!s
) return UuidCreateNil( uuid
);
636 if (strlenW(s
) != 36) return RPC_S_INVALID_STRING_UUID
;
638 if ((s
[8]!='-') || (s
[13]!='-') || (s
[18]!='-') || (s
[23]!='-'))
639 return RPC_S_INVALID_STRING_UUID
;
643 if ((i
== 8)||(i
== 13)||(i
== 18)||(i
== 23)) continue;
644 if (s
[i
] > 'f' || (!hex2bin
[s
[i
]] && s
[i
] != '0')) return RPC_S_INVALID_STRING_UUID
;
647 /* in form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */
649 uuid
->Data1
= (hex2bin
[s
[0]] << 28 | hex2bin
[s
[1]] << 24 | hex2bin
[s
[2]] << 20 | hex2bin
[s
[3]] << 16 |
650 hex2bin
[s
[4]] << 12 | hex2bin
[s
[5]] << 8 | hex2bin
[s
[6]] << 4 | hex2bin
[s
[7]]);
651 uuid
->Data2
= hex2bin
[s
[9]] << 12 | hex2bin
[s
[10]] << 8 | hex2bin
[s
[11]] << 4 | hex2bin
[s
[12]];
652 uuid
->Data3
= hex2bin
[s
[14]] << 12 | hex2bin
[s
[15]] << 8 | hex2bin
[s
[16]] << 4 | hex2bin
[s
[17]];
654 /* these are just sequential bytes */
655 uuid
->Data4
[0] = hex2bin
[s
[19]] << 4 | hex2bin
[s
[20]];
656 uuid
->Data4
[1] = hex2bin
[s
[21]] << 4 | hex2bin
[s
[22]];
657 uuid
->Data4
[2] = hex2bin
[s
[24]] << 4 | hex2bin
[s
[25]];
658 uuid
->Data4
[3] = hex2bin
[s
[26]] << 4 | hex2bin
[s
[27]];
659 uuid
->Data4
[4] = hex2bin
[s
[28]] << 4 | hex2bin
[s
[29]];
660 uuid
->Data4
[5] = hex2bin
[s
[30]] << 4 | hex2bin
[s
[31]];
661 uuid
->Data4
[6] = hex2bin
[s
[32]] << 4 | hex2bin
[s
[33]];
662 uuid
->Data4
[7] = hex2bin
[s
[34]] << 4 | hex2bin
[s
[35]];
666 /***********************************************************************
667 * DllRegisterServer (RPCRT4.@)
670 HRESULT WINAPI
DllRegisterServer( void )
672 FIXME( "(): stub\n" );
676 BOOL
RPCRT4_StartRPCSS(void)
678 PROCESS_INFORMATION pi
;
683 ZeroMemory(&pi
, sizeof(PROCESS_INFORMATION
));
684 ZeroMemory(&si
, sizeof(STARTUPINFOA
));
685 si
.cb
= sizeof(STARTUPINFOA
);
687 /* apparently it's not OK to use a constant string below */
688 CopyMemory(cmd
, "rpcss", 6);
690 /* FIXME: will this do the right thing when run as a test? */
691 rslt
= CreateProcessA(
692 NULL
, /* executable */
693 cmd
, /* command line */
694 NULL
, /* process security attributes */
695 NULL
, /* primary thread security attributes */
696 FALSE
, /* inherit handles */
697 0, /* creation flags */
698 NULL
, /* use parent's environment */
699 NULL
, /* use parent's current directory */
700 &si
, /* STARTUPINFO pointer */
701 &pi
/* PROCESS_INFORMATION */
705 CloseHandle(pi
.hProcess
);
706 CloseHandle(pi
.hThread
);
712 /***********************************************************************
713 * RPCRT4_RPCSSOnDemandCall (internal)
715 * Attempts to send a message to the RPCSS process
716 * on the local machine, invoking it if necessary.
717 * For remote RPCSS calls, use.... your imagination.
720 * msg [I] pointer to the RPCSS message
721 * vardata_payload [I] pointer vardata portion of the RPCSS message
722 * reply [O] pointer to reply structure
728 BOOL
RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg
, char *vardata_payload
, PRPCSS_NP_REPLY reply
)
730 HANDLE client_handle
;
733 TRACE("(msg == %p, vardata_payload == %p, reply == %p)\n", msg
, vardata_payload
, reply
);
735 client_handle
= RPCRT4_RpcssNPConnect();
737 while (!client_handle
) {
738 /* start the RPCSS process */
739 if (!RPCRT4_StartRPCSS()) {
740 ERR("Unable to start RPCSS process.\n");
743 /* wait for a connection (w/ periodic polling) */
744 for (i
= 0; i
< 60; i
++) {
746 client_handle
= RPCRT4_RpcssNPConnect();
747 if (client_handle
) break;
749 /* we are only willing to try twice */
753 if (!client_handle
) {
755 ERR("Unable to connect to RPCSS process!\n");
756 SetLastError(RPC_E_SERVER_DIED_DNE
);
760 /* great, we're connected. now send the message */
761 if (!RPCRT4_SendReceiveNPMsg(client_handle
, msg
, vardata_payload
, reply
)) {
762 ERR("Something is amiss: RPC_SendReceive failed.\n");
769 #define MAX_RPC_ERROR_TEXT 256
771 /******************************************************************************
772 * DceErrorInqTextW (rpcrt4.@)
775 * 1. On passing a NULL pointer the code does bomb out.
776 * 2. The size of the required buffer is not defined in the documentation.
777 * It appears to be 256.
778 * 3. The function is defined to return RPC_S_INVALID_ARG but I don't know
779 * of any value for which it does.
780 * 4. The MSDN documentation currently declares that the second argument is
781 * unsigned char *, even for the W version. I don't believe it.
783 RPC_STATUS RPC_ENTRY
DceErrorInqTextW (RPC_STATUS e
, unsigned short *buffer
)
786 count
= FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM
|
787 FORMAT_MESSAGE_IGNORE_INSERTS
,
788 NULL
, e
, 0, buffer
, MAX_RPC_ERROR_TEXT
, NULL
);
791 count
= FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM
|
792 FORMAT_MESSAGE_IGNORE_INSERTS
,
793 NULL
, RPC_S_NOT_RPC_ERROR
, 0, buffer
, MAX_RPC_ERROR_TEXT
, NULL
);
796 ERR ("Failed to translate error");
797 return RPC_S_INVALID_ARG
;
803 /******************************************************************************
804 * DceErrorInqTextA (rpcrt4.@)
806 RPC_STATUS RPC_ENTRY
DceErrorInqTextA (RPC_STATUS e
, unsigned char *buffer
)
809 WCHAR bufferW
[MAX_RPC_ERROR_TEXT
];
810 if ((status
= DceErrorInqTextW (e
, bufferW
)) == RPC_S_OK
)
812 if (!WideCharToMultiByte(CP_ACP
, 0, bufferW
, -1, (LPSTR
)buffer
, MAX_RPC_ERROR_TEXT
,
815 ERR ("Failed to translate error");
816 status
= RPC_S_INVALID_ARG
;