2000-07-15 21:53:50 +02:00
|
|
|
/*
|
|
|
|
* RPCRT4
|
|
|
|
*
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2000 Huw D M Davies for CodeWeavers
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* WINE RPC TODO's (and a few TODONT's)
|
|
|
|
*
|
2003-09-11 03:05:19 +02:00
|
|
|
* - Ove's decreasingly incomplete widl is an IDL compiler for wine. For widl
|
|
|
|
* to be wine's only IDL compiler, a fair bit of work remains to be done.
|
|
|
|
* until then we have used some midl-generated stuff. (What?)
|
|
|
|
* widl currently doesn't generate stub/proxy files required by wine's (O)RPC
|
|
|
|
* capabilities -- nor does it make those lovely format strings :(
|
|
|
|
* The MS MIDL compiler does some really esoteric stuff. Of course Ove has
|
|
|
|
* started with the less esoteric stuff. There are also lots of nice
|
|
|
|
* comments in there if you want to flex your bison and help build this monster.
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
2002-12-02 22:17:04 +01:00
|
|
|
* - RPC has a quite featureful error handling mechanism; basically none of this is
|
2003-09-11 03:05:19 +02:00
|
|
|
* implemented right now. We also have deficiencies on the compiler side, where
|
|
|
|
* wine's __TRY / __EXCEPT / __FINALLY macros are not even used for RpcTryExcept & co,
|
|
|
|
* due to syntactic differences! (we can fix it with widl by using __TRY)
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - There are several different memory allocation schemes for MSRPC.
|
|
|
|
* I don't even understand what they all are yet, much less have them
|
|
|
|
* properly implemented. Surely we are supposed to be doing something with
|
|
|
|
* the user-provided allocation/deallocation functions, but so far,
|
|
|
|
* I don't think we are doing this...
|
|
|
|
*
|
|
|
|
* - MSRPC provides impersonation capabilities which currently are not possible
|
|
|
|
* to implement in wine. At the very least we should implement the authorization
|
2003-09-11 03:05:19 +02:00
|
|
|
* API's & gracefully ignore the irrelevant stuff (to an extent we already do).
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - Some transports are not yet implemented. The existing transport implementations
|
2003-09-11 03:05:19 +02:00
|
|
|
* are incomplete and may be bug-infested.
|
2002-12-02 22:17:04 +01:00
|
|
|
*
|
|
|
|
* - The various transports that we do support ought to be supported in a more
|
2003-09-11 03:05:19 +02:00
|
|
|
* object-oriented manner, as in DCE's RPC implementation, instead of cluttering
|
2002-10-25 21:03:43 +02:00
|
|
|
* up the code with conditionals like we do now.
|
|
|
|
*
|
2003-09-11 03:05:19 +02:00
|
|
|
* - Data marshalling: So far, only the beginnings of a full implementation
|
2002-11-06 22:58:21 +01:00
|
|
|
* exist in wine. NDR protocol itself is documented, but the MS API's to
|
2003-09-11 03:05:19 +02:00
|
|
|
* convert data-types in memory into NDR are not. This is challenging work,
|
|
|
|
* and has supposedly been "at the top of Greg's queue" for several months now.
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - ORPC is RPC for OLE; once we have a working RPC framework, we can
|
|
|
|
* use it to implement out-of-process OLE client/server communications.
|
2005-06-30 20:19:33 +02:00
|
|
|
* ATM there is maybe a disconnect between the marshalling in the OLE DLLs
|
2003-09-11 03:05:19 +02:00
|
|
|
* and the marshalling going on here [TODO: well, is there or not?]
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - In-source API Documentation, at least for those functions which we have
|
2003-09-11 03:05:19 +02:00
|
|
|
* implemented, but preferably for everything we can document, would be nice,
|
|
|
|
* since some of this stuff is quite obscure.
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
2003-09-11 03:05:19 +02:00
|
|
|
* - Name services... [TODO: what about them]
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
2002-11-06 22:58:21 +01:00
|
|
|
* - Protocol Towers: Totally unimplemented.... I think.
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - Context Handle Rundown: whatever that is.
|
|
|
|
*
|
|
|
|
* - Nested RPC's: Totally unimplemented.
|
|
|
|
*
|
|
|
|
* - Statistics: we are supposed to be keeping various counters. we aren't.
|
|
|
|
*
|
2003-09-11 03:05:19 +02:00
|
|
|
* - Async RPC: Unimplemented.
|
2002-11-06 22:58:21 +01:00
|
|
|
*
|
2003-09-11 03:05:19 +02:00
|
|
|
* - XML/http RPC: Somewhere there's an XML fiend that wants to do this! Betcha
|
|
|
|
* we could use these as a transport for RPC's across computers without a
|
|
|
|
* permissions and/or licensing crisis.
|
|
|
|
*
|
|
|
|
* - The NT "ports" API, aka LPC. Greg claims this is on his radar. Might (or
|
|
|
|
* might not) enable users to get some kind of meaningful result out of
|
|
|
|
* NT-based native rpcrt4's. Commonly-used transport for self-to-self RPC's.
|
|
|
|
*
|
|
|
|
* - ...? More stuff I haven't thought of. If you think of more RPC todo's
|
|
|
|
* drop me an e-mail <gmturner007@ameritech.net> or send a patch to the
|
|
|
|
* wine-patches mailing list.
|
2000-07-15 21:53:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-10-24 03:37:22 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winbase.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
#include "winuser.h"
|
2007-11-12 21:10:19 +01:00
|
|
|
#include "winnt.h"
|
|
|
|
#include "winternl.h"
|
2004-04-28 03:04:49 +02:00
|
|
|
#include "iptypes.h"
|
|
|
|
#include "iphlpapi.h"
|
2002-10-04 00:51:49 +02:00
|
|
|
#include "wine/unicode.h"
|
2000-07-15 21:53:50 +02:00
|
|
|
#include "rpc.h"
|
|
|
|
|
2002-01-29 19:16:39 +01:00
|
|
|
#include "ole2.h"
|
|
|
|
#include "rpcndr.h"
|
|
|
|
#include "rpcproxy.h"
|
|
|
|
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
#include "rpc_binding.h"
|
2002-12-02 22:17:04 +01:00
|
|
|
#include "rpcss_np_client.h"
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-07-15 21:53:50 +02:00
|
|
|
|
2005-03-14 11:11:04 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(rpc);
|
2000-07-15 21:53:50 +02:00
|
|
|
|
2002-10-04 00:51:49 +02:00
|
|
|
static UUID uuid_nil;
|
2002-12-02 22:17:04 +01:00
|
|
|
static HANDLE master_mutex;
|
|
|
|
|
|
|
|
HANDLE RPCRT4_GetMasterMutex(void)
|
|
|
|
{
|
|
|
|
return master_mutex;
|
|
|
|
}
|
2002-10-04 00:51:49 +02:00
|
|
|
|
2004-04-28 03:04:49 +02:00
|
|
|
static CRITICAL_SECTION uuid_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &uuid_cs,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": uuid_cs") }
|
2004-04-28 03:04:49 +02:00
|
|
|
};
|
|
|
|
static CRITICAL_SECTION uuid_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2007-11-12 21:10:19 +01:00
|
|
|
static CRITICAL_SECTION threaddata_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG threaddata_cs_debug =
|
|
|
|
{
|
2007-11-13 19:58:51 +01:00
|
|
|
0, 0, &threaddata_cs,
|
2007-11-12 21:10:19 +01:00
|
|
|
{ &threaddata_cs_debug.ProcessLocksList, &threaddata_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": threaddata_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION threaddata_cs = { &threaddata_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
struct list threaddata_list = LIST_INIT(threaddata_list);
|
|
|
|
|
|
|
|
struct threaddata
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
CRITICAL_SECTION cs;
|
|
|
|
DWORD thread_id;
|
|
|
|
RpcConnection *connection;
|
|
|
|
};
|
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
/***********************************************************************
|
2002-11-05 00:53:41 +01:00
|
|
|
* DllMain
|
2000-07-15 21:53:50 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
2000-07-16 17:44:22 +02:00
|
|
|
* hinstDLL [I] handle to the DLL's instance
|
2000-07-15 21:53:50 +02:00
|
|
|
* fdwReason [I]
|
2000-07-16 17:44:22 +02:00
|
|
|
* lpvReserved [I] reserved, must be NULL
|
2000-07-15 21:53:50 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
2000-07-15 21:53:50 +02:00
|
|
|
{
|
2007-11-12 21:10:19 +01:00
|
|
|
struct threaddata *tdata;
|
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
switch (fdwReason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2002-12-02 22:17:04 +01:00
|
|
|
master_mutex = CreateMutexA( NULL, FALSE, RPCSS_MASTER_MUTEX_NAME);
|
|
|
|
if (!master_mutex)
|
|
|
|
ERR("Failed to create master mutex\n");
|
|
|
|
break;
|
2000-07-15 21:53:50 +02:00
|
|
|
|
2007-11-12 21:10:19 +01:00
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
tdata = NtCurrentTeb()->ReservedForNtRpc;
|
|
|
|
if (tdata)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&threaddata_cs);
|
|
|
|
list_remove(&tdata->entry);
|
|
|
|
LeaveCriticalSection(&threaddata_cs);
|
|
|
|
|
|
|
|
DeleteCriticalSection(&tdata->cs);
|
|
|
|
if (tdata->connection)
|
|
|
|
ERR("tdata->connection should be NULL but is still set to %p\n", tdata);
|
|
|
|
HeapFree(GetProcessHeap(), 0, tdata);
|
|
|
|
}
|
2007-12-08 18:14:30 +01:00
|
|
|
break;
|
2007-11-12 21:10:19 +01:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
2002-12-02 22:17:04 +01:00
|
|
|
CloseHandle(master_mutex);
|
2003-01-15 00:43:41 +01:00
|
|
|
master_mutex = NULL;
|
2002-12-02 22:17:04 +01:00
|
|
|
break;
|
2000-07-15 21:53:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* RpcStringFreeA [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Frees a character string allocated by the RPC run-time library.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* S_OK if successful.
|
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS WINAPI RpcStringFreeA(RPC_CSTR* String)
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, *String);
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* RpcStringFreeW [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Frees a character string allocated by the RPC run-time library.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* S_OK if successful.
|
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS WINAPI RpcStringFreeW(RPC_WSTR* String)
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, *String);
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-31 04:22:27 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* RpcRaiseException [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Raises an exception.
|
|
|
|
*/
|
|
|
|
void WINAPI RpcRaiseException(RPC_STATUS exception)
|
|
|
|
{
|
|
|
|
/* FIXME: translate exception? */
|
|
|
|
RaiseException(exception, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2002-10-04 00:51:49 +02:00
|
|
|
/*************************************************************************
|
2002-10-10 20:55:24 +02:00
|
|
|
* UuidCompare [RPCRT4.@]
|
|
|
|
*
|
2002-10-04 00:51:49 +02:00
|
|
|
* PARAMS
|
|
|
|
* UUID *Uuid1 [I] Uuid to compare
|
|
|
|
* UUID *Uuid2 [I] Uuid to compare
|
|
|
|
* RPC_STATUS *Status [O] returns RPC_S_OK
|
2002-10-10 20:55:24 +02:00
|
|
|
*
|
2002-10-04 00:51:49 +02:00
|
|
|
* RETURNS
|
2004-04-28 03:04:49 +02:00
|
|
|
* -1 if Uuid1 is less than Uuid2
|
2002-10-10 20:55:24 +02:00
|
|
|
* 0 if Uuid1 and Uuid2 are equal
|
|
|
|
* 1 if Uuid1 is greater than Uuid2
|
2002-10-04 00:51:49 +02:00
|
|
|
*/
|
2002-10-10 20:55:24 +02:00
|
|
|
int WINAPI UuidCompare(UUID *Uuid1, UUID *Uuid2, RPC_STATUS *Status)
|
2002-10-04 00:51:49 +02:00
|
|
|
{
|
2004-04-28 03:04:49 +02:00
|
|
|
int i;
|
|
|
|
|
2002-10-07 23:52:55 +02:00
|
|
|
TRACE("(%s,%s)\n", debugstr_guid(Uuid1), debugstr_guid(Uuid2));
|
2004-04-28 03:04:49 +02:00
|
|
|
|
2002-10-04 00:51:49 +02:00
|
|
|
*Status = RPC_S_OK;
|
2004-04-28 03:04:49 +02:00
|
|
|
|
2002-10-07 23:52:55 +02:00
|
|
|
if (!Uuid1) Uuid1 = &uuid_nil;
|
|
|
|
if (!Uuid2) Uuid2 = &uuid_nil;
|
2004-04-28 03:04:49 +02:00
|
|
|
|
2002-10-10 20:55:24 +02:00
|
|
|
if (Uuid1 == Uuid2) return 0;
|
2004-04-28 03:04:49 +02:00
|
|
|
|
|
|
|
if (Uuid1->Data1 != Uuid2->Data1)
|
|
|
|
return Uuid1->Data1 < Uuid2->Data1 ? -1 : 1;
|
|
|
|
|
|
|
|
if (Uuid1->Data2 != Uuid2->Data2)
|
|
|
|
return Uuid1->Data2 < Uuid2->Data2 ? -1 : 1;
|
|
|
|
|
|
|
|
if (Uuid1->Data3 != Uuid2->Data3)
|
|
|
|
return Uuid1->Data3 < Uuid2->Data3 ? -1 : 1;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (Uuid1->Data4[i] < Uuid2->Data4[i])
|
|
|
|
return -1;
|
|
|
|
if (Uuid1->Data4[i] > Uuid2->Data4[i])
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2002-10-07 23:52:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2002-10-10 20:55:24 +02:00
|
|
|
* UuidEqual [RPCRT4.@]
|
2002-10-07 23:52:55 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* UUID *Uuid1 [I] Uuid to compare
|
|
|
|
* UUID *Uuid2 [I] Uuid to compare
|
|
|
|
* RPC_STATUS *Status [O] returns RPC_S_OK
|
2002-10-10 20:55:24 +02:00
|
|
|
*
|
2002-10-07 23:52:55 +02:00
|
|
|
* RETURNS
|
2002-10-10 20:55:24 +02:00
|
|
|
* TRUE/FALSE
|
2002-10-07 23:52:55 +02:00
|
|
|
*/
|
2002-10-10 20:55:24 +02:00
|
|
|
int WINAPI UuidEqual(UUID *Uuid1, UUID *Uuid2, RPC_STATUS *Status)
|
2002-10-07 23:52:55 +02:00
|
|
|
{
|
|
|
|
TRACE("(%s,%s)\n", debugstr_guid(Uuid1), debugstr_guid(Uuid2));
|
2002-10-10 20:55:24 +02:00
|
|
|
return !UuidCompare(Uuid1, Uuid2, Status);
|
2002-10-04 00:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* UuidIsNil [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* UUID *Uuid [I] Uuid to compare
|
|
|
|
* RPC_STATUS *Status [O] retuns RPC_S_OK
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE/FALSE
|
|
|
|
*/
|
2004-04-28 03:04:49 +02:00
|
|
|
int WINAPI UuidIsNil(UUID *Uuid, RPC_STATUS *Status)
|
2002-10-04 00:51:49 +02:00
|
|
|
{
|
2004-04-28 03:04:49 +02:00
|
|
|
TRACE("(%s)\n", debugstr_guid(Uuid));
|
|
|
|
if (!Uuid) return TRUE;
|
|
|
|
return !UuidCompare(Uuid, &uuid_nil, Status);
|
2002-10-04 00:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* UuidCreateNil [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* UUID *Uuid [O] returns a nil UUID
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* RPC_S_OK
|
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI UuidCreateNil(UUID *Uuid)
|
|
|
|
{
|
|
|
|
*Uuid = uuid_nil;
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-28 03:04:49 +02:00
|
|
|
/* Number of 100ns ticks per clock tick. To be safe, assume that the clock
|
|
|
|
resolution is at least 1000 * 100 * (1/1000000) = 1/10 of a second */
|
|
|
|
#define TICKS_PER_CLOCK_TICK 1000
|
|
|
|
#define SECSPERDAY 86400
|
|
|
|
#define TICKSPERSEC 10000000
|
|
|
|
/* UUID system time starts at October 15, 1582 */
|
|
|
|
#define SECS_15_OCT_1582_TO_1601 ((17 + 30 + 31 + 365 * 18 + 5) * SECSPERDAY)
|
|
|
|
#define TICKS_15_OCT_1582_TO_1601 ((ULONGLONG)SECS_15_OCT_1582_TO_1601 * TICKSPERSEC)
|
|
|
|
|
|
|
|
static void RPC_UuidGetSystemTime(ULONGLONG *time)
|
|
|
|
{
|
|
|
|
FILETIME ft;
|
|
|
|
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
|
|
|
|
*time = ((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
|
|
|
|
*time += TICKS_15_OCT_1582_TO_1601;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assume that a hardware address is at least 6 bytes long */
|
|
|
|
#define ADDRESS_BYTES_NEEDED 6
|
|
|
|
|
|
|
|
static RPC_STATUS RPC_UuidGetNodeAddress(BYTE *address)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
DWORD status = RPC_S_OK;
|
|
|
|
|
|
|
|
ULONG buflen = sizeof(IP_ADAPTER_INFO);
|
2005-03-24 22:01:35 +01:00
|
|
|
PIP_ADAPTER_INFO adapter = HeapAlloc(GetProcessHeap(), 0, buflen);
|
2004-04-28 03:04:49 +02:00
|
|
|
|
|
|
|
if (GetAdaptersInfo(adapter, &buflen) == ERROR_BUFFER_OVERFLOW) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, adapter);
|
2005-03-24 22:01:35 +01:00
|
|
|
adapter = HeapAlloc(GetProcessHeap(), 0, buflen);
|
2004-04-28 03:04:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetAdaptersInfo(adapter, &buflen) == NO_ERROR) {
|
|
|
|
for (i = 0; i < ADDRESS_BYTES_NEEDED; i++) {
|
|
|
|
address[i] = adapter->Address[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* We can't get a hardware address, just use random numbers.
|
|
|
|
Set the multicast bit to prevent conflicts with real cards. */
|
|
|
|
else {
|
|
|
|
for (i = 0; i < ADDRESS_BYTES_NEEDED; i++) {
|
|
|
|
address[i] = rand() & 0xff;
|
|
|
|
}
|
|
|
|
|
2005-03-14 11:53:57 +01:00
|
|
|
address[0] |= 0x01;
|
2004-04-28 03:04:49 +02:00
|
|
|
status = RPC_S_UUID_LOCAL_ONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, adapter);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
/*************************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* UuidCreate [RPCRT4.@]
|
2000-07-15 21:53:50 +02:00
|
|
|
*
|
|
|
|
* Creates a 128bit UUID.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
2004-04-28 03:04:49 +02:00
|
|
|
* RPC_S_OK if successful.
|
|
|
|
* RPC_S_UUID_LOCAL_ONLY if UUID is only locally unique.
|
|
|
|
*
|
|
|
|
* FIXME: No compensation for changes across reloading
|
|
|
|
* this dll or across reboots (e.g. clock going
|
|
|
|
* backwards and swapped network cards). The RFC
|
|
|
|
* suggests using NVRAM for storing persistent
|
|
|
|
* values.
|
2000-07-15 21:53:50 +02:00
|
|
|
*/
|
2000-07-25 19:45:14 +02:00
|
|
|
RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
|
2000-07-15 21:53:50 +02:00
|
|
|
{
|
2004-04-28 03:04:49 +02:00
|
|
|
static int initialised, count;
|
|
|
|
|
|
|
|
ULONGLONG time;
|
|
|
|
static ULONGLONG timelast;
|
|
|
|
static WORD sequence;
|
|
|
|
|
|
|
|
static DWORD status;
|
|
|
|
static BYTE address[MAX_ADAPTER_ADDRESS_LENGTH];
|
|
|
|
|
|
|
|
EnterCriticalSection(&uuid_cs);
|
|
|
|
|
|
|
|
if (!initialised) {
|
|
|
|
RPC_UuidGetSystemTime(&timelast);
|
|
|
|
count = TICKS_PER_CLOCK_TICK;
|
|
|
|
|
|
|
|
sequence = ((rand() & 0xff) << 8) + (rand() & 0xff);
|
|
|
|
sequence &= 0x1fff;
|
|
|
|
|
|
|
|
status = RPC_UuidGetNodeAddress(address);
|
|
|
|
initialised = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generate time element of the UUID. Account for going faster
|
|
|
|
than our clock as well as the clock going backwards. */
|
|
|
|
while (1) {
|
|
|
|
RPC_UuidGetSystemTime(&time);
|
|
|
|
if (time > timelast) {
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (time < timelast) {
|
|
|
|
sequence = (sequence + 1) & 0x1fff;
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count < TICKS_PER_CLOCK_TICK) {
|
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
timelast = time;
|
|
|
|
time += count;
|
|
|
|
|
|
|
|
/* Pack the information into the UUID structure. */
|
|
|
|
|
|
|
|
Uuid->Data1 = (unsigned long)(time & 0xffffffff);
|
|
|
|
Uuid->Data2 = (unsigned short)((time >> 32) & 0xffff);
|
|
|
|
Uuid->Data3 = (unsigned short)((time >> 48) & 0x0fff);
|
|
|
|
|
|
|
|
/* This is a version 1 UUID */
|
|
|
|
Uuid->Data3 |= (1 << 12);
|
|
|
|
|
|
|
|
Uuid->Data4[0] = sequence & 0xff;
|
|
|
|
Uuid->Data4[1] = (sequence & 0x3f00) >> 8;
|
|
|
|
Uuid->Data4[1] |= 0x80;
|
|
|
|
|
|
|
|
Uuid->Data4[2] = address[0];
|
|
|
|
Uuid->Data4[3] = address[1];
|
|
|
|
Uuid->Data4[4] = address[2];
|
|
|
|
Uuid->Data4[5] = address[3];
|
|
|
|
Uuid->Data4[6] = address[4];
|
|
|
|
Uuid->Data4[7] = address[5];
|
|
|
|
|
|
|
|
LeaveCriticalSection(&uuid_cs);
|
2000-10-24 03:37:22 +02:00
|
|
|
|
2004-04-28 03:04:49 +02:00
|
|
|
TRACE("%s\n", debugstr_guid(Uuid));
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2002-01-06 20:08:47 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* UuidCreateSequential [RPCRT4.@]
|
|
|
|
*
|
2004-04-28 03:04:49 +02:00
|
|
|
* Creates a 128bit UUID.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* RPC_S_OK if successful.
|
|
|
|
* RPC_S_UUID_LOCAL_ONLY if UUID is only locally unique.
|
|
|
|
*
|
2002-01-06 20:08:47 +01:00
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI UuidCreateSequential(UUID *Uuid)
|
|
|
|
{
|
2004-04-28 03:04:49 +02:00
|
|
|
return UuidCreate(Uuid);
|
2002-01-06 20:08:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-24 03:37:22 +02:00
|
|
|
/*************************************************************************
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
* UuidHash [RPCRT4.@]
|
2000-10-24 03:37:22 +02:00
|
|
|
*
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
* Generates a hash value for a given UUID
|
2000-10-24 03:37:22 +02:00
|
|
|
*
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
* Code based on FreeDCE implementation
|
2000-10-24 03:37:22 +02:00
|
|
|
*
|
|
|
|
*/
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
unsigned short WINAPI UuidHash(UUID *uuid, RPC_STATUS *Status)
|
2000-10-24 03:37:22 +02:00
|
|
|
{
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
BYTE *data = (BYTE*)uuid;
|
|
|
|
short c0 = 0, c1 = 0, x, y;
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2000-10-24 03:37:22 +02:00
|
|
|
|
2002-11-06 22:58:21 +01:00
|
|
|
if (!uuid) data = (BYTE*)(uuid = &uuid_nil);
|
|
|
|
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
TRACE("(%s)\n", debugstr_guid(uuid));
|
2000-10-24 03:37:22 +02:00
|
|
|
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
for (i=0; i<sizeof(UUID); i++) {
|
|
|
|
c0 += data[i];
|
|
|
|
c1 += c0;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = -c1 % 255;
|
|
|
|
if (x < 0) x += 255;
|
|
|
|
|
|
|
|
y = (c1 - c0) % 255;
|
|
|
|
if (y < 0) y += 255;
|
2001-09-07 17:25:51 +02:00
|
|
|
|
|
|
|
*Status = RPC_S_OK;
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
return y*256 + x;
|
2001-09-07 17:25:51 +02:00
|
|
|
}
|
|
|
|
|
2000-10-24 03:37:22 +02:00
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* UuidToStringA [RPCRT4.@]
|
2000-10-24 03:37:22 +02:00
|
|
|
*
|
|
|
|
* Converts a UUID to a string.
|
|
|
|
*
|
|
|
|
* UUID format is 8 hex digits, followed by a hyphen then three groups of
|
|
|
|
* 4 hex digits each followed by a hyphen and then 12 hex digits
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* S_OK if successful.
|
2006-09-07 20:01:50 +02:00
|
|
|
* S_OUT_OF_MEMORY if unsuccessful.
|
2000-10-24 03:37:22 +02:00
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS WINAPI UuidToStringA(UUID *Uuid, RPC_CSTR* StringUuid)
|
2000-10-24 03:37:22 +02:00
|
|
|
{
|
|
|
|
*StringUuid = HeapAlloc( GetProcessHeap(), 0, sizeof(char) * 37);
|
|
|
|
|
|
|
|
if(!(*StringUuid))
|
2001-07-11 22:19:06 +02:00
|
|
|
return RPC_S_OUT_OF_MEMORY;
|
2000-10-24 03:37:22 +02:00
|
|
|
|
2002-11-06 22:58:21 +01:00
|
|
|
if (!Uuid) Uuid = &uuid_nil;
|
|
|
|
|
2006-11-09 23:04:48 +01:00
|
|
|
sprintf( (char*)*StringUuid, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
2000-10-24 03:37:22 +02:00
|
|
|
Uuid->Data1, Uuid->Data2, Uuid->Data3,
|
|
|
|
Uuid->Data4[0], Uuid->Data4[1], Uuid->Data4[2],
|
|
|
|
Uuid->Data4[3], Uuid->Data4[4], Uuid->Data4[5],
|
|
|
|
Uuid->Data4[6], Uuid->Data4[7] );
|
|
|
|
|
2001-07-11 22:19:06 +02:00
|
|
|
return RPC_S_OK;
|
2000-10-24 03:37:22 +02:00
|
|
|
}
|
2000-11-15 23:11:50 +01:00
|
|
|
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
/*************************************************************************
|
|
|
|
* UuidToStringW [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Converts a UUID to a string.
|
|
|
|
*
|
|
|
|
* S_OK if successful.
|
2006-09-07 20:01:50 +02:00
|
|
|
* S_OUT_OF_MEMORY if unsuccessful.
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS WINAPI UuidToStringW(UUID *Uuid, RPC_WSTR* StringUuid)
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
{
|
|
|
|
char buf[37];
|
|
|
|
|
2002-11-06 22:58:21 +01:00
|
|
|
if (!Uuid) Uuid = &uuid_nil;
|
|
|
|
|
2006-11-09 23:04:48 +01:00
|
|
|
sprintf(buf, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
Implemented RpcBindingInqObject, RpcBindingSetObject,
RpcBindingVectorFree, RpcBindingToStringBindingA/W,
RpcBindingFromStringBindingA/W, RpcStringBindingParseA/W,
I_RpcBindingSetAsync, RpcStringBindingComposeA/W, RpcBindingFree,
RPCStringFreeW, UUIDHash, UuidToStringW, and associated junk.
2002-10-07 23:49:49 +02:00
|
|
|
Uuid->Data1, Uuid->Data2, Uuid->Data3,
|
|
|
|
Uuid->Data4[0], Uuid->Data4[1], Uuid->Data4[2],
|
|
|
|
Uuid->Data4[3], Uuid->Data4[4], Uuid->Data4[5],
|
|
|
|
Uuid->Data4[6], Uuid->Data4[7] );
|
|
|
|
|
|
|
|
*StringUuid = RPCRT4_strdupAtoW(buf);
|
|
|
|
|
|
|
|
if(!(*StringUuid))
|
|
|
|
return RPC_S_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
2002-10-04 02:20:56 +02:00
|
|
|
|
|
|
|
static const BYTE hex2bin[] =
|
|
|
|
{
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
|
|
|
|
0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
|
|
|
|
0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
|
|
|
|
0,10,11,12,13,14,15 /* 0x60 */
|
|
|
|
};
|
|
|
|
|
2002-06-13 23:50:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* UuidFromStringA (RPCRT4.@)
|
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS WINAPI UuidFromStringA(RPC_CSTR s, UUID *uuid)
|
2002-06-13 23:50:12 +02:00
|
|
|
{
|
2002-10-04 02:20:56 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!s) return UuidCreateNil( uuid );
|
|
|
|
|
2005-08-30 10:56:35 +02:00
|
|
|
if (strlen((char*)s) != 36) return RPC_S_INVALID_STRING_UUID;
|
2002-10-04 02:20:56 +02:00
|
|
|
|
|
|
|
if ((s[8]!='-') || (s[13]!='-') || (s[18]!='-') || (s[23]!='-'))
|
|
|
|
return RPC_S_INVALID_STRING_UUID;
|
|
|
|
|
|
|
|
for (i=0; i<36; i++)
|
|
|
|
{
|
|
|
|
if ((i == 8)||(i == 13)||(i == 18)||(i == 23)) continue;
|
|
|
|
if (s[i] > 'f' || (!hex2bin[s[i]] && s[i] != '0')) return RPC_S_INVALID_STRING_UUID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* in form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */
|
|
|
|
|
|
|
|
uuid->Data1 = (hex2bin[s[0]] << 28 | hex2bin[s[1]] << 24 | hex2bin[s[2]] << 20 | hex2bin[s[3]] << 16 |
|
|
|
|
hex2bin[s[4]] << 12 | hex2bin[s[5]] << 8 | hex2bin[s[6]] << 4 | hex2bin[s[7]]);
|
|
|
|
uuid->Data2 = hex2bin[s[9]] << 12 | hex2bin[s[10]] << 8 | hex2bin[s[11]] << 4 | hex2bin[s[12]];
|
|
|
|
uuid->Data3 = hex2bin[s[14]] << 12 | hex2bin[s[15]] << 8 | hex2bin[s[16]] << 4 | hex2bin[s[17]];
|
|
|
|
|
|
|
|
/* these are just sequential bytes */
|
|
|
|
uuid->Data4[0] = hex2bin[s[19]] << 4 | hex2bin[s[20]];
|
|
|
|
uuid->Data4[1] = hex2bin[s[21]] << 4 | hex2bin[s[22]];
|
|
|
|
uuid->Data4[2] = hex2bin[s[24]] << 4 | hex2bin[s[25]];
|
|
|
|
uuid->Data4[3] = hex2bin[s[26]] << 4 | hex2bin[s[27]];
|
|
|
|
uuid->Data4[4] = hex2bin[s[28]] << 4 | hex2bin[s[29]];
|
|
|
|
uuid->Data4[5] = hex2bin[s[30]] << 4 | hex2bin[s[31]];
|
|
|
|
uuid->Data4[6] = hex2bin[s[32]] << 4 | hex2bin[s[33]];
|
|
|
|
uuid->Data4[7] = hex2bin[s[34]] << 4 | hex2bin[s[35]];
|
|
|
|
return RPC_S_OK;
|
2002-06-13 23:50:12 +02:00
|
|
|
}
|
|
|
|
|
2002-10-04 02:20:56 +02:00
|
|
|
|
2002-06-13 23:50:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* UuidFromStringW (RPCRT4.@)
|
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS WINAPI UuidFromStringW(RPC_WSTR s, UUID *uuid)
|
2002-06-13 23:50:12 +02:00
|
|
|
{
|
2002-10-04 02:20:56 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!s) return UuidCreateNil( uuid );
|
|
|
|
|
|
|
|
if (strlenW(s) != 36) return RPC_S_INVALID_STRING_UUID;
|
|
|
|
|
|
|
|
if ((s[8]!='-') || (s[13]!='-') || (s[18]!='-') || (s[23]!='-'))
|
|
|
|
return RPC_S_INVALID_STRING_UUID;
|
|
|
|
|
|
|
|
for (i=0; i<36; i++)
|
|
|
|
{
|
|
|
|
if ((i == 8)||(i == 13)||(i == 18)||(i == 23)) continue;
|
|
|
|
if (s[i] > 'f' || (!hex2bin[s[i]] && s[i] != '0')) return RPC_S_INVALID_STRING_UUID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* in form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */
|
|
|
|
|
|
|
|
uuid->Data1 = (hex2bin[s[0]] << 28 | hex2bin[s[1]] << 24 | hex2bin[s[2]] << 20 | hex2bin[s[3]] << 16 |
|
|
|
|
hex2bin[s[4]] << 12 | hex2bin[s[5]] << 8 | hex2bin[s[6]] << 4 | hex2bin[s[7]]);
|
|
|
|
uuid->Data2 = hex2bin[s[9]] << 12 | hex2bin[s[10]] << 8 | hex2bin[s[11]] << 4 | hex2bin[s[12]];
|
|
|
|
uuid->Data3 = hex2bin[s[14]] << 12 | hex2bin[s[15]] << 8 | hex2bin[s[16]] << 4 | hex2bin[s[17]];
|
|
|
|
|
|
|
|
/* these are just sequential bytes */
|
|
|
|
uuid->Data4[0] = hex2bin[s[19]] << 4 | hex2bin[s[20]];
|
|
|
|
uuid->Data4[1] = hex2bin[s[21]] << 4 | hex2bin[s[22]];
|
|
|
|
uuid->Data4[2] = hex2bin[s[24]] << 4 | hex2bin[s[25]];
|
|
|
|
uuid->Data4[3] = hex2bin[s[26]] << 4 | hex2bin[s[27]];
|
|
|
|
uuid->Data4[4] = hex2bin[s[28]] << 4 | hex2bin[s[29]];
|
|
|
|
uuid->Data4[5] = hex2bin[s[30]] << 4 | hex2bin[s[31]];
|
|
|
|
uuid->Data4[6] = hex2bin[s[32]] << 4 | hex2bin[s[33]];
|
|
|
|
uuid->Data4[7] = hex2bin[s[34]] << 4 | hex2bin[s[35]];
|
|
|
|
return RPC_S_OK;
|
2002-06-13 23:50:12 +02:00
|
|
|
}
|
|
|
|
|
2002-05-20 00:22:52 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (RPCRT4.@)
|
|
|
|
*/
|
|
|
|
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllRegisterServer( void )
|
2002-05-20 00:22:52 +02:00
|
|
|
{
|
2002-12-02 22:17:04 +01:00
|
|
|
FIXME( "(): stub\n" );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-24 22:18:25 +01:00
|
|
|
static BOOL RPCRT4_StartRPCSS(void)
|
|
|
|
{
|
2002-12-02 22:17:04 +01:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA si;
|
|
|
|
static char cmd[6];
|
|
|
|
BOOL rslt;
|
|
|
|
|
|
|
|
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
|
|
|
|
ZeroMemory(&si, sizeof(STARTUPINFOA));
|
|
|
|
si.cb = sizeof(STARTUPINFOA);
|
|
|
|
|
|
|
|
/* apparently it's not OK to use a constant string below */
|
|
|
|
CopyMemory(cmd, "rpcss", 6);
|
|
|
|
|
|
|
|
/* FIXME: will this do the right thing when run as a test? */
|
|
|
|
rslt = CreateProcessA(
|
|
|
|
NULL, /* executable */
|
|
|
|
cmd, /* command line */
|
|
|
|
NULL, /* process security attributes */
|
|
|
|
NULL, /* primary thread security attributes */
|
|
|
|
FALSE, /* inherit handles */
|
|
|
|
0, /* creation flags */
|
|
|
|
NULL, /* use parent's environment */
|
|
|
|
NULL, /* use parent's current directory */
|
|
|
|
&si, /* STARTUPINFO pointer */
|
|
|
|
&pi /* PROCESS_INFORMATION */
|
|
|
|
);
|
|
|
|
|
|
|
|
if (rslt) {
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rslt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RPCRT4_RPCSSOnDemandCall (internal)
|
|
|
|
*
|
|
|
|
* Attempts to send a message to the RPCSS process
|
|
|
|
* on the local machine, invoking it if necessary.
|
|
|
|
* For remote RPCSS calls, use.... your imagination.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* msg [I] pointer to the RPCSS message
|
|
|
|
* vardata_payload [I] pointer vardata portion of the RPCSS message
|
|
|
|
* reply [O] pointer to reply structure
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful
|
|
|
|
* FALSE otherwise
|
|
|
|
*/
|
|
|
|
BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPCSS_NP_REPLY reply)
|
|
|
|
{
|
|
|
|
HANDLE client_handle;
|
2007-03-08 15:29:50 +01:00
|
|
|
BOOL ret;
|
2002-12-02 22:17:04 +01:00
|
|
|
int i, j = 0;
|
|
|
|
|
|
|
|
TRACE("(msg == %p, vardata_payload == %p, reply == %p)\n", msg, vardata_payload, reply);
|
|
|
|
|
|
|
|
client_handle = RPCRT4_RpcssNPConnect();
|
|
|
|
|
2007-03-08 15:29:50 +01:00
|
|
|
while (INVALID_HANDLE_VALUE == client_handle) {
|
2002-12-02 22:17:04 +01:00
|
|
|
/* start the RPCSS process */
|
|
|
|
if (!RPCRT4_StartRPCSS()) {
|
|
|
|
ERR("Unable to start RPCSS process.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* wait for a connection (w/ periodic polling) */
|
|
|
|
for (i = 0; i < 60; i++) {
|
|
|
|
Sleep(200);
|
|
|
|
client_handle = RPCRT4_RpcssNPConnect();
|
2007-03-08 15:29:50 +01:00
|
|
|
if (INVALID_HANDLE_VALUE != client_handle) break;
|
2002-12-02 22:17:04 +01:00
|
|
|
}
|
|
|
|
/* we are only willing to try twice */
|
|
|
|
if (j++ >= 1) break;
|
|
|
|
}
|
|
|
|
|
2007-03-08 15:29:50 +01:00
|
|
|
if (INVALID_HANDLE_VALUE == client_handle) {
|
2002-12-02 22:17:04 +01:00
|
|
|
/* no dice! */
|
|
|
|
ERR("Unable to connect to RPCSS process!\n");
|
|
|
|
SetLastError(RPC_E_SERVER_DIED_DNE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* great, we're connected. now send the message */
|
2007-03-08 15:29:50 +01:00
|
|
|
ret = TRUE;
|
2002-12-02 22:17:04 +01:00
|
|
|
if (!RPCRT4_SendReceiveNPMsg(client_handle, msg, vardata_payload, reply)) {
|
|
|
|
ERR("Something is amiss: RPC_SendReceive failed.\n");
|
2007-03-08 15:29:50 +01:00
|
|
|
ret = FALSE;
|
2002-12-02 22:17:04 +01:00
|
|
|
}
|
2007-03-08 15:29:50 +01:00
|
|
|
CloseHandle(client_handle);
|
2002-12-02 22:17:04 +01:00
|
|
|
|
2007-03-08 15:29:50 +01:00
|
|
|
return ret;
|
2002-05-20 00:22:52 +02:00
|
|
|
}
|
2004-12-23 12:29:54 +01:00
|
|
|
|
2005-04-20 17:18:42 +02:00
|
|
|
#define MAX_RPC_ERROR_TEXT 256
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* DceErrorInqTextW (rpcrt4.@)
|
2004-12-23 12:29:54 +01:00
|
|
|
*
|
|
|
|
* Notes
|
|
|
|
* 1. On passing a NULL pointer the code does bomb out.
|
|
|
|
* 2. The size of the required buffer is not defined in the documentation.
|
|
|
|
* It appears to be 256.
|
|
|
|
* 3. The function is defined to return RPC_S_INVALID_ARG but I don't know
|
|
|
|
* of any value for which it does.
|
|
|
|
* 4. The MSDN documentation currently declares that the second argument is
|
|
|
|
* unsigned char *, even for the W version. I don't believe it.
|
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS RPC_ENTRY DceErrorInqTextW (RPC_STATUS e, RPC_WSTR buffer)
|
2004-12-23 12:29:54 +01:00
|
|
|
{
|
|
|
|
DWORD count;
|
|
|
|
count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL, e, 0, buffer, MAX_RPC_ERROR_TEXT, NULL);
|
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL, RPC_S_NOT_RPC_ERROR, 0, buffer, MAX_RPC_ERROR_TEXT, NULL);
|
|
|
|
if (!count)
|
|
|
|
{
|
2006-10-05 11:11:03 +02:00
|
|
|
ERR ("Failed to translate error\n");
|
2004-12-23 12:29:54 +01:00
|
|
|
return RPC_S_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-20 17:18:42 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* DceErrorInqTextA (rpcrt4.@)
|
|
|
|
*/
|
2006-10-13 02:19:15 +02:00
|
|
|
RPC_STATUS RPC_ENTRY DceErrorInqTextA (RPC_STATUS e, RPC_CSTR buffer)
|
2004-12-23 12:29:54 +01:00
|
|
|
{
|
|
|
|
RPC_STATUS status;
|
|
|
|
WCHAR bufferW [MAX_RPC_ERROR_TEXT];
|
|
|
|
if ((status = DceErrorInqTextW (e, bufferW)) == RPC_S_OK)
|
|
|
|
{
|
2005-08-30 10:56:35 +02:00
|
|
|
if (!WideCharToMultiByte(CP_ACP, 0, bufferW, -1, (LPSTR)buffer, MAX_RPC_ERROR_TEXT,
|
2004-12-23 12:29:54 +01:00
|
|
|
NULL, NULL))
|
|
|
|
{
|
2006-10-05 11:11:03 +02:00
|
|
|
ERR ("Failed to translate error\n");
|
2004-12-23 12:29:54 +01:00
|
|
|
status = RPC_S_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
2006-06-01 21:24:52 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* I_RpcAllocate (rpcrt4.@)
|
|
|
|
*/
|
|
|
|
void * WINAPI I_RpcAllocate(unsigned int Size)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* I_RpcFree (rpcrt4.@)
|
|
|
|
*/
|
|
|
|
void WINAPI I_RpcFree(void *Object)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, Object);
|
|
|
|
}
|
2006-07-13 14:06:44 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* I_RpcMapWin32Status (rpcrt4.@)
|
|
|
|
*/
|
2007-11-13 20:50:35 +01:00
|
|
|
LONG WINAPI I_RpcMapWin32Status(RPC_STATUS status)
|
2006-07-13 14:06:44 +02:00
|
|
|
{
|
|
|
|
FIXME("(%ld): stub\n", status);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-06 16:54:59 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RpcErrorStartEnumeration (rpcrt4.@)
|
|
|
|
*/
|
|
|
|
RPC_STATUS RPC_ENTRY RpcErrorStartEnumeration(void** EnumHandle)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", EnumHandle);
|
|
|
|
return RPC_S_ENTRY_NOT_FOUND;
|
|
|
|
}
|
2007-11-06 16:55:06 +01:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RpcMgmtSetCancelTimeout (rpcrt4.@)
|
|
|
|
*/
|
|
|
|
RPC_STATUS RPC_ENTRY RpcMgmtSetCancelTimeout(LONG Timeout)
|
|
|
|
{
|
|
|
|
FIXME("(%d): stub\n", Timeout);
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-12 21:10:19 +01:00
|
|
|
void RPCRT4_SetThreadCurrentConnection(RpcConnection *Connection)
|
|
|
|
{
|
|
|
|
struct threaddata *tdata = NtCurrentTeb()->ReservedForNtRpc;
|
|
|
|
if (!tdata)
|
|
|
|
{
|
|
|
|
tdata = HeapAlloc(GetProcessHeap(), 0, sizeof(*tdata));
|
|
|
|
if (!tdata) return;
|
|
|
|
|
|
|
|
InitializeCriticalSection(&tdata->cs);
|
|
|
|
tdata->thread_id = GetCurrentThreadId();
|
|
|
|
tdata->connection = Connection;
|
|
|
|
|
|
|
|
EnterCriticalSection(&threaddata_cs);
|
|
|
|
list_add_tail(&threaddata_list, &tdata->entry);
|
|
|
|
LeaveCriticalSection(&threaddata_cs);
|
|
|
|
|
|
|
|
NtCurrentTeb()->ReservedForNtRpc = tdata;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EnterCriticalSection(&tdata->cs);
|
|
|
|
tdata->connection = Connection;
|
|
|
|
LeaveCriticalSection(&tdata->cs);
|
|
|
|
}
|
|
|
|
|
2007-11-06 16:55:06 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* RpcCancelThread (rpcrt4.@)
|
|
|
|
*/
|
2007-11-13 20:50:35 +01:00
|
|
|
RPC_STATUS RPC_ENTRY RpcCancelThread(void* ThreadHandle)
|
2007-11-06 16:55:06 +01:00
|
|
|
{
|
2007-11-12 21:10:19 +01:00
|
|
|
DWORD target_tid;
|
|
|
|
struct threaddata *tdata;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", ThreadHandle);
|
|
|
|
|
|
|
|
target_tid = GetThreadId(ThreadHandle);
|
|
|
|
if (!target_tid)
|
|
|
|
return RPC_S_INVALID_ARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&threaddata_cs);
|
|
|
|
LIST_FOR_EACH_ENTRY(tdata, &threaddata_list, struct threaddata, entry)
|
|
|
|
if (tdata->thread_id == target_tid)
|
|
|
|
{
|
2007-11-18 16:51:03 +01:00
|
|
|
EnterCriticalSection(&tdata->cs);
|
|
|
|
if (tdata->connection) rpcrt4_conn_cancel_call(tdata->connection);
|
|
|
|
LeaveCriticalSection(&tdata->cs);
|
2007-11-12 21:10:19 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&threaddata_cs);
|
|
|
|
|
2007-11-06 16:55:06 +01:00
|
|
|
return RPC_S_OK;
|
|
|
|
}
|