2000-07-15 21:53:50 +02:00
|
|
|
/*
|
|
|
|
* RPCRT4
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright 2000 Huw D M Davies for Codeweavers
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* WINE RPC TODO's (and a few TODONT's)
|
|
|
|
*
|
|
|
|
* - widl is like MIDL for wine. For wine to be a useful RPC platform, quite
|
|
|
|
* a bit of work needs to be done here. widl currently doesn't generate stubs
|
|
|
|
* for RPC invocation -- it will need to; this is tricky because the MIDL compiler
|
|
|
|
* does some really wierd stuff. Then again, we don't neccesarily have to
|
2002-12-02 22:17:04 +01:00
|
|
|
* make widl work like MIDL, so it could be worse. Lately Ove has been working on
|
|
|
|
* some widl enhancements.
|
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
|
|
|
|
* implemented right now.
|
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
|
|
|
|
* API's & gracefully ignore the irrelevant stuff (to a small extent we already do).
|
|
|
|
*
|
|
|
|
* - Some transports are not yet implemented. The existing transport implementations
|
2002-12-02 22:17:04 +01:00
|
|
|
* are incomplete and many seem to be buggy
|
|
|
|
*
|
|
|
|
* - The various transports that we do support ought to be supported in a more
|
2002-10-25 21:03:43 +02:00
|
|
|
* object-oriented manner, like in DCE's RPC implementation, instead of cluttering
|
|
|
|
* up the code with conditionals like we do now.
|
|
|
|
*
|
|
|
|
* - Data marshalling: So far, only the very beginnings of an implementation
|
2002-11-06 22:58:21 +01:00
|
|
|
* exist in wine. NDR protocol itself is documented, but the MS API's to
|
2002-12-02 22:17:04 +01:00
|
|
|
* convert data-types in memory into NDR are not. This is a bit of a challenge,
|
|
|
|
* but it is at the top of Greg's queue and should be improving soon.
|
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.
|
|
|
|
* ATM there is a 100% disconnect between the marshalling in the OLE DLL's
|
|
|
|
* and the marshalling going on here. This is a good thing, since marshalling
|
|
|
|
* doesn't work yet. But once it does, obviously there will be the opportunity
|
|
|
|
* to implement out-of-process OLE using wine's rpcrt4 or some derivative.
|
2002-12-02 22:17:04 +01:00
|
|
|
* This may require some collaboration between the RPC workers and the OLE
|
|
|
|
* workers, of course.
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - In-source API Documentation, at least for those functions which we have
|
|
|
|
* implemented, but preferably for everything we can document, would be nice.
|
|
|
|
* Some stuff is undocumented by Microsoft and we are guessing how to implement
|
|
|
|
* (in these cases we should document the behavior we implemented, or, if there
|
|
|
|
* is no implementation, at least hazard some kind of guess, and put a few
|
2002-12-02 22:17:04 +01:00
|
|
|
* question marks after it ;) ).
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - Stubs. Lots of stuff is defined in Microsoft's headers, including undocumented
|
|
|
|
* stuff. So let's make a stub-farm and populate it with as many rpcrt4 api's as
|
|
|
|
* we can stand, so people don't get unimplemented function exceptions.
|
|
|
|
*
|
|
|
|
* - Name services: this part hasn't even been started.
|
|
|
|
*
|
2002-12-02 22:17:04 +01:00
|
|
|
* - Concurrency: right now I have not tested more than one request at a time;
|
2002-10-25 21:03:43 +02:00
|
|
|
* we are supposed to be able to do this, and to queue requests which exceed the
|
2002-12-02 22:17:04 +01:00
|
|
|
* concurrency limit.
|
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.
|
|
|
|
*
|
2002-12-02 22:17:04 +01:00
|
|
|
* - Connectionless RPC: unimplemented (DNE in win9x so not a top priority)
|
2002-11-06 22:58:21 +01:00
|
|
|
*
|
|
|
|
* - XML RPC: Dunno if microsoft does it... but we'd might as well just for kicks.
|
2002-10-25 21:03:43 +02:00
|
|
|
*
|
|
|
|
* - ...? 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 wine-patches.
|
2000-07-15 21:53:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2000-10-24 03:37:22 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2000-10-24 03:37:22 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winbase.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"
|
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
#ifdef HAVE_SYS_FILE_H
|
|
|
|
# include <sys/file.h>
|
|
|
|
#endif
|
2002-05-15 01:18:23 +02:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
2000-07-15 21:53:50 +02:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKIO_H
|
|
|
|
# include <sys/sockio.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NET_IF_H
|
|
|
|
# include <net/if.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
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
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2002-12-24 01:26:55 +01:00
|
|
|
RPC_STATUS WINAPI RpcStringFreeA(unsigned char** 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.
|
|
|
|
*/
|
2002-12-24 01:26:55 +01:00
|
|
|
RPC_STATUS WINAPI RpcStringFreeW(unsigned short** 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;
|
|
|
|
}
|
|
|
|
|
2002-10-04 00:51:49 +02:00
|
|
|
/*************************************************************************
|
2002-10-10 20:55:24 +02:00
|
|
|
* UuidCompare [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* (an educated-guess implementation)
|
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
|
2002-10-10 20:55:24 +02:00
|
|
|
* -1 if Uuid1 is less than Uuid2
|
|
|
|
* 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
|
|
|
{
|
2002-10-07 23:52:55 +02:00
|
|
|
TRACE("(%s,%s)\n", debugstr_guid(Uuid1), debugstr_guid(Uuid2));
|
2002-10-04 00:51:49 +02:00
|
|
|
*Status = RPC_S_OK;
|
2002-10-07 23:52:55 +02:00
|
|
|
if (!Uuid1) Uuid1 = &uuid_nil;
|
|
|
|
if (!Uuid2) Uuid2 = &uuid_nil;
|
2002-10-10 20:55:24 +02:00
|
|
|
if (Uuid1 == Uuid2) return 0;
|
|
|
|
return memcmp(Uuid1, Uuid2, sizeof(UUID));
|
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
|
|
|
|
*/
|
|
|
|
int WINAPI UuidIsNil(UUID *uuid, RPC_STATUS *Status)
|
|
|
|
{
|
|
|
|
TRACE("(%s)\n", debugstr_guid(uuid));
|
|
|
|
*Status = RPC_S_OK;
|
|
|
|
if (!uuid) return TRUE;
|
|
|
|
return !memcmp(uuid, &uuid_nil, sizeof(UUID));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* Implemented according the DCE specification for UUID generation.
|
|
|
|
* Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
|
|
|
|
* Copyright (C) 1996, 1997 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* S_OK if successful.
|
|
|
|
*/
|
2000-07-25 19:45:14 +02:00
|
|
|
RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
|
2000-07-15 21:53:50 +02:00
|
|
|
{
|
|
|
|
static char has_init = 0;
|
2002-01-06 20:08:47 +01:00
|
|
|
static unsigned char a[6];
|
2000-07-15 21:53:50 +02:00
|
|
|
static int adjustment = 0;
|
|
|
|
static struct timeval last = {0, 0};
|
2002-10-04 00:51:49 +02:00
|
|
|
static WORD clock_seq;
|
2000-07-15 21:53:50 +02:00
|
|
|
struct timeval tv;
|
|
|
|
unsigned long long clock_reg;
|
2002-10-04 00:51:49 +02:00
|
|
|
DWORD clock_high, clock_low;
|
|
|
|
WORD temp_clock_seq, temp_clock_mid, temp_clock_hi_and_version;
|
2000-07-15 21:53:50 +02:00
|
|
|
#ifdef HAVE_NET_IF_H
|
|
|
|
int sd;
|
|
|
|
struct ifreq ifr, *ifrp;
|
|
|
|
struct ifconf ifc;
|
|
|
|
char buf[1024];
|
|
|
|
int n, i;
|
|
|
|
#endif
|
2002-01-06 20:08:47 +01:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
/* Have we already tried to get the MAC address? */
|
|
|
|
if (!has_init) {
|
|
|
|
#ifdef HAVE_NET_IF_H
|
|
|
|
/* BSD 4.4 defines the size of an ifreq to be
|
|
|
|
* max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
|
|
|
|
* However, under earlier systems, sa_len isn't present, so
|
|
|
|
* the size is just sizeof(struct ifreq)
|
|
|
|
*/
|
2001-07-09 00:30:50 +02:00
|
|
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
2000-07-15 21:53:50 +02:00
|
|
|
# ifndef max
|
|
|
|
# define max(a,b) ((a) > (b) ? (a) : (b))
|
|
|
|
# endif
|
|
|
|
# define ifreq_size(i) max(sizeof(struct ifreq),\
|
|
|
|
sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
|
|
|
|
# else
|
|
|
|
# define ifreq_size(i) sizeof(struct ifreq)
|
2001-07-09 00:30:50 +02:00
|
|
|
# endif /* defined(HAVE_SOCKADDR_SA_LEN) */
|
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
|
|
|
if (sd < 0) {
|
|
|
|
/* if we can't open a socket, just use random numbers */
|
|
|
|
/* set the multicast bit to prevent conflicts with real cards */
|
|
|
|
a[0] = (rand() & 0xff) | 0x80;
|
|
|
|
a[1] = rand() & 0xff;
|
|
|
|
a[2] = rand() & 0xff;
|
|
|
|
a[3] = rand() & 0xff;
|
|
|
|
a[4] = rand() & 0xff;
|
|
|
|
a[5] = rand() & 0xff;
|
|
|
|
} else {
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
ifc.ifc_len = sizeof(buf);
|
|
|
|
ifc.ifc_buf = buf;
|
|
|
|
/* get the ifconf interface */
|
|
|
|
if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
|
|
|
|
close(sd);
|
|
|
|
/* no ifconf, so just use random numbers */
|
|
|
|
/* set the multicast bit to prevent conflicts with real cards */
|
|
|
|
a[0] = (rand() & 0xff) | 0x80;
|
|
|
|
a[1] = rand() & 0xff;
|
|
|
|
a[2] = rand() & 0xff;
|
|
|
|
a[3] = rand() & 0xff;
|
|
|
|
a[4] = rand() & 0xff;
|
|
|
|
a[5] = rand() & 0xff;
|
|
|
|
} else {
|
|
|
|
/* loop through the interfaces, looking for a valid one */
|
|
|
|
n = ifc.ifc_len;
|
2001-07-09 00:30:50 +02:00
|
|
|
for (i = 0; i < n; i+= ifreq_size(ifr) ) {
|
2000-07-15 21:53:50 +02:00
|
|
|
ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
|
|
|
|
strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
|
|
|
|
/* try to get the address for this interface */
|
|
|
|
# ifdef SIOCGIFHWADDR
|
|
|
|
if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
|
|
|
|
continue;
|
|
|
|
memcpy(a, (unsigned char *)&ifr.ifr_hwaddr.sa_data, 6);
|
|
|
|
# else
|
|
|
|
# ifdef SIOCGENADDR
|
|
|
|
if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
|
|
|
|
continue;
|
|
|
|
memcpy(a, (unsigned char *) ifr.ifr_enaddr, 6);
|
|
|
|
# else
|
|
|
|
/* XXX we don't have a way of getting the hardware address */
|
|
|
|
close(sd);
|
|
|
|
a[0] = 0;
|
|
|
|
break;
|
|
|
|
# endif /* SIOCGENADDR */
|
|
|
|
# endif /* SIOCGIFHWADDR */
|
|
|
|
/* make sure it's not blank */
|
|
|
|
if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
|
|
|
|
continue;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
goto valid_address;
|
|
|
|
}
|
|
|
|
/* if we didn't find a valid address, make a random one */
|
|
|
|
/* once again, set multicast bit to avoid conflicts */
|
|
|
|
a[0] = (rand() & 0xff) | 0x80;
|
|
|
|
a[1] = rand() & 0xff;
|
|
|
|
a[2] = rand() & 0xff;
|
|
|
|
a[3] = rand() & 0xff;
|
|
|
|
a[4] = rand() & 0xff;
|
|
|
|
a[5] = rand() & 0xff;
|
|
|
|
|
|
|
|
valid_address:
|
|
|
|
close(sd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* no networking info, so generate a random address */
|
|
|
|
a[0] = (rand() & 0xff) | 0x80;
|
|
|
|
a[1] = rand() & 0xff;
|
|
|
|
a[2] = rand() & 0xff;
|
|
|
|
a[3] = rand() & 0xff;
|
|
|
|
a[4] = rand() & 0xff;
|
|
|
|
a[5] = rand() & 0xff;
|
|
|
|
#endif /* HAVE_NET_IF_H */
|
|
|
|
has_init = 1;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
/* generate time element of GUID */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
/* Assume that the gettimeofday() has microsecond granularity */
|
|
|
|
#define MAX_ADJUSTMENT 10
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
try_again:
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
|
|
|
|
clock_seq = ((rand() & 0xff) << 8) + (rand() & 0xff);
|
|
|
|
clock_seq &= 0x1FFF;
|
|
|
|
last = tv;
|
|
|
|
last.tv_sec--;
|
|
|
|
}
|
|
|
|
if ((tv.tv_sec < last.tv_sec) ||
|
|
|
|
((tv.tv_sec == last.tv_sec) &&
|
|
|
|
(tv.tv_usec < last.tv_usec))) {
|
|
|
|
clock_seq = (clock_seq+1) & 0x1FFF;
|
|
|
|
adjustment = 0;
|
|
|
|
} else if ((tv.tv_sec == last.tv_sec) &&
|
|
|
|
(tv.tv_usec == last.tv_usec)) {
|
|
|
|
if (adjustment >= MAX_ADJUSTMENT)
|
|
|
|
goto try_again;
|
|
|
|
adjustment++;
|
|
|
|
} else
|
|
|
|
adjustment = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
clock_reg = tv.tv_usec*10 + adjustment;
|
|
|
|
clock_reg += ((unsigned long long) tv.tv_sec)*10000000;
|
|
|
|
clock_reg += (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
clock_high = clock_reg >> 32;
|
|
|
|
clock_low = clock_reg;
|
|
|
|
temp_clock_seq = clock_seq | 0x8000;
|
2002-10-04 00:51:49 +02:00
|
|
|
temp_clock_mid = (WORD)clock_high;
|
2000-07-15 21:53:50 +02:00
|
|
|
temp_clock_hi_and_version = (clock_high >> 16) | 0x1000;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
/* pack the information into the GUID structure */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
((unsigned char*)&Uuid->Data1)[3] = (unsigned char)clock_low;
|
|
|
|
clock_low >>= 8;
|
|
|
|
((unsigned char*)&Uuid->Data1)[2] = (unsigned char)clock_low;
|
|
|
|
clock_low >>= 8;
|
|
|
|
((unsigned char*)&Uuid->Data1)[1] = (unsigned char)clock_low;
|
|
|
|
clock_low >>= 8;
|
|
|
|
((unsigned char*)&Uuid->Data1)[0] = (unsigned char)clock_low;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
((unsigned char*)&Uuid->Data2)[1] = (unsigned char)temp_clock_mid;
|
|
|
|
temp_clock_mid >>= 8;
|
|
|
|
((unsigned char*)&Uuid->Data2)[0] = (unsigned char)temp_clock_mid;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
((unsigned char*)&Uuid->Data3)[1] = (unsigned char)temp_clock_hi_and_version;
|
|
|
|
temp_clock_hi_and_version >>= 8;
|
|
|
|
((unsigned char*)&Uuid->Data3)[0] = (unsigned char)temp_clock_hi_and_version;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
((unsigned char*)Uuid->Data4)[1] = (unsigned char)temp_clock_seq;
|
|
|
|
temp_clock_seq >>= 8;
|
|
|
|
((unsigned char*)Uuid->Data4)[0] = (unsigned char)temp_clock_seq;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-07-15 21:53:50 +02:00
|
|
|
((unsigned char*)Uuid->Data4)[2] = a[0];
|
|
|
|
((unsigned char*)Uuid->Data4)[3] = a[1];
|
|
|
|
((unsigned char*)Uuid->Data4)[4] = a[2];
|
|
|
|
((unsigned char*)Uuid->Data4)[5] = a[3];
|
|
|
|
((unsigned char*)Uuid->Data4)[6] = a[4];
|
|
|
|
((unsigned char*)Uuid->Data4)[7] = a[5];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-05-09 19:31:31 +02:00
|
|
|
TRACE("%s\n", debugstr_guid(Uuid));
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-07-11 22:19:06 +02:00
|
|
|
return RPC_S_OK;
|
2000-07-15 21:53:50 +02:00
|
|
|
}
|
2000-10-24 03:37:22 +02:00
|
|
|
|
2002-01-06 20:08:47 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* UuidCreateSequential [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Creates a 128bit UUID by calling UuidCreate.
|
|
|
|
* New API in Win 2000
|
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI UuidCreateSequential(UUID *Uuid)
|
|
|
|
{
|
|
|
|
return UuidCreate (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
|
|
|
* 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;
|
|
|
|
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.
|
|
|
|
* S_OUT_OF_MEMORY if unsucessful.
|
|
|
|
*/
|
2002-12-24 01:26:55 +01:00
|
|
|
RPC_STATUS WINAPI UuidToStringA(UUID *Uuid, unsigned char** 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;
|
|
|
|
|
2002-01-06 20:08:47 +01:00
|
|
|
sprintf(*StringUuid, "%08lx-%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.
|
|
|
|
* S_OUT_OF_MEMORY if unsucessful.
|
|
|
|
*/
|
2002-12-24 01:26:55 +01:00
|
|
|
RPC_STATUS WINAPI UuidToStringW(UUID *Uuid, unsigned short** 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;
|
|
|
|
|
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
|
|
|
sprintf(buf, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
|
|
|
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.@)
|
|
|
|
*/
|
2002-12-24 01:26:55 +01:00
|
|
|
RPC_STATUS WINAPI UuidFromStringA(unsigned char* str, UUID *uuid)
|
2002-06-13 23:50:12 +02:00
|
|
|
{
|
2002-10-04 02:20:56 +02:00
|
|
|
BYTE *s = (BYTE *)str;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!s) return UuidCreateNil( uuid );
|
|
|
|
|
|
|
|
if (strlen(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-10-04 02:20:56 +02:00
|
|
|
|
2002-06-13 23:50:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* UuidFromStringW (RPCRT4.@)
|
|
|
|
*/
|
2002-12-24 01:26:55 +01:00
|
|
|
RPC_STATUS WINAPI UuidFromStringW(unsigned short* 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.@)
|
|
|
|
*/
|
|
|
|
|
|
|
|
HRESULT WINAPI RPCRT4_DllRegisterServer( void )
|
|
|
|
{
|
2002-12-02 22:17:04 +01:00
|
|
|
FIXME( "(): stub\n" );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL RPCRT4_StartRPCSS(void)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
int i, j = 0;
|
|
|
|
|
|
|
|
TRACE("(msg == %p, vardata_payload == %p, reply == %p)\n", msg, vardata_payload, reply);
|
|
|
|
|
|
|
|
client_handle = RPCRT4_RpcssNPConnect();
|
|
|
|
|
|
|
|
while (!client_handle) {
|
|
|
|
/* 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();
|
|
|
|
if (client_handle) break;
|
|
|
|
}
|
|
|
|
/* we are only willing to try twice */
|
|
|
|
if (j++ >= 1) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!client_handle) {
|
|
|
|
/* 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 */
|
|
|
|
if (!RPCRT4_SendReceiveNPMsg(client_handle, msg, vardata_payload, reply)) {
|
|
|
|
ERR("Something is amiss: RPC_SendReceive failed.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2002-05-20 00:22:52 +02:00
|
|
|
}
|