16 #include "wine/windef16.h"
25 #ifdef HAVE_SYS_FILE_H
26 # include <sys/file.h>
28 #include <sys/ioctl.h>
29 #ifdef HAVE_SYS_SOCKET_H
30 # include <sys/socket.h>
32 #ifdef HAVE_SYS_SOCKIO_H
33 # include <sys/sockio.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
42 #include "debugtools.h"
44 DEFAULT_DEBUG_CHANNEL(ole);
46 /***********************************************************************
50 * hinstDLL [I] handle to the DLL's instance
52 * lpvReserved [I] reserved, must be NULL
60 RPCRT4_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
63 case DLL_PROCESS_ATTACH:
66 case DLL_PROCESS_DETACH:
73 /*************************************************************************
74 * UuidCreate [RPCRT4.@]
76 * Creates a 128bit UUID.
77 * Implemented according the DCE specification for UUID generation.
78 * Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
79 * Copyright (C) 1996, 1997 Theodore Ts'o.
85 RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
87 static char has_init = 0;
88 static unsigned char a[6];
89 static int adjustment = 0;
90 static struct timeval last = {0, 0};
91 static UINT16 clock_seq;
93 unsigned long long clock_reg;
94 UINT clock_high, clock_low;
95 UINT16 temp_clock_seq, temp_clock_mid, temp_clock_hi_and_version;
98 struct ifreq ifr, *ifrp;
104 /* Have we already tried to get the MAC address? */
107 /* BSD 4.4 defines the size of an ifreq to be
108 * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
109 * However, under earlier systems, sa_len isn't present, so
110 * the size is just sizeof(struct ifreq)
112 #ifdef HAVE_SOCKADDR_SA_LEN
114 # define max(a,b) ((a) > (b) ? (a) : (b))
116 # define ifreq_size(i) max(sizeof(struct ifreq),\
117 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
119 # define ifreq_size(i) sizeof(struct ifreq)
120 # endif /* defined(HAVE_SOCKADDR_SA_LEN) */
122 sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
124 /* if we can't open a socket, just use random numbers */
125 /* set the multicast bit to prevent conflicts with real cards */
126 a[0] = (rand() & 0xff) | 0x80;
127 a[1] = rand() & 0xff;
128 a[2] = rand() & 0xff;
129 a[3] = rand() & 0xff;
130 a[4] = rand() & 0xff;
131 a[5] = rand() & 0xff;
133 memset(buf, 0, sizeof(buf));
134 ifc.ifc_len = sizeof(buf);
136 /* get the ifconf interface */
137 if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
139 /* no ifconf, so just use random numbers */
140 /* set the multicast bit to prevent conflicts with real cards */
141 a[0] = (rand() & 0xff) | 0x80;
142 a[1] = rand() & 0xff;
143 a[2] = rand() & 0xff;
144 a[3] = rand() & 0xff;
145 a[4] = rand() & 0xff;
146 a[5] = rand() & 0xff;
148 /* loop through the interfaces, looking for a valid one */
150 for (i = 0; i < n; i+= ifreq_size(ifr) ) {
151 ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
152 strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
153 /* try to get the address for this interface */
154 # ifdef SIOCGIFHWADDR
155 if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
157 memcpy(a, (unsigned char *)&ifr.ifr_hwaddr.sa_data, 6);
160 if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
162 memcpy(a, (unsigned char *) ifr.ifr_enaddr, 6);
164 /* XXX we don't have a way of getting the hardware address */
168 # endif /* SIOCGENADDR */
169 # endif /* SIOCGIFHWADDR */
170 /* make sure it's not blank */
171 if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
176 /* if we didn't find a valid address, make a random one */
177 /* once again, set multicast bit to avoid conflicts */
178 a[0] = (rand() & 0xff) | 0x80;
179 a[1] = rand() & 0xff;
180 a[2] = rand() & 0xff;
181 a[3] = rand() & 0xff;
182 a[4] = rand() & 0xff;
183 a[5] = rand() & 0xff;
190 /* no networking info, so generate a random address */
191 a[0] = (rand() & 0xff) | 0x80;
192 a[1] = rand() & 0xff;
193 a[2] = rand() & 0xff;
194 a[3] = rand() & 0xff;
195 a[4] = rand() & 0xff;
196 a[5] = rand() & 0xff;
197 #endif /* HAVE_NET_IF_H */
201 /* generate time element of GUID */
203 /* Assume that the gettimeofday() has microsecond granularity */
204 #define MAX_ADJUSTMENT 10
207 gettimeofday(&tv, 0);
208 if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
209 clock_seq = ((rand() & 0xff) << 8) + (rand() & 0xff);
214 if ((tv.tv_sec < last.tv_sec) ||
215 ((tv.tv_sec == last.tv_sec) &&
216 (tv.tv_usec < last.tv_usec))) {
217 clock_seq = (clock_seq+1) & 0x1FFF;
219 } else if ((tv.tv_sec == last.tv_sec) &&
220 (tv.tv_usec == last.tv_usec)) {
221 if (adjustment >= MAX_ADJUSTMENT)
227 clock_reg = tv.tv_usec*10 + adjustment;
228 clock_reg += ((unsigned long long) tv.tv_sec)*10000000;
229 clock_reg += (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
231 clock_high = clock_reg >> 32;
232 clock_low = clock_reg;
233 temp_clock_seq = clock_seq | 0x8000;
234 temp_clock_mid = (UINT16)clock_high;
235 temp_clock_hi_and_version = (clock_high >> 16) | 0x1000;
237 /* pack the information into the GUID structure */
239 ((unsigned char*)&Uuid->Data1)[3] = (unsigned char)clock_low;
241 ((unsigned char*)&Uuid->Data1)[2] = (unsigned char)clock_low;
243 ((unsigned char*)&Uuid->Data1)[1] = (unsigned char)clock_low;
245 ((unsigned char*)&Uuid->Data1)[0] = (unsigned char)clock_low;
247 ((unsigned char*)&Uuid->Data2)[1] = (unsigned char)temp_clock_mid;
248 temp_clock_mid >>= 8;
249 ((unsigned char*)&Uuid->Data2)[0] = (unsigned char)temp_clock_mid;
251 ((unsigned char*)&Uuid->Data3)[1] = (unsigned char)temp_clock_hi_and_version;
252 temp_clock_hi_and_version >>= 8;
253 ((unsigned char*)&Uuid->Data3)[0] = (unsigned char)temp_clock_hi_and_version;
255 ((unsigned char*)Uuid->Data4)[1] = (unsigned char)temp_clock_seq;
256 temp_clock_seq >>= 8;
257 ((unsigned char*)Uuid->Data4)[0] = (unsigned char)temp_clock_seq;
259 ((unsigned char*)Uuid->Data4)[2] = a[0];
260 ((unsigned char*)Uuid->Data4)[3] = a[1];
261 ((unsigned char*)Uuid->Data4)[4] = a[2];
262 ((unsigned char*)Uuid->Data4)[5] = a[3];
263 ((unsigned char*)Uuid->Data4)[6] = a[4];
264 ((unsigned char*)Uuid->Data4)[7] = a[5];
266 TRACE("%s\n", debugstr_guid(Uuid));
272 /*************************************************************************
273 * UuidCreateSequential [RPCRT4.@]
275 * Creates a 128bit UUID by calling UuidCreate.
276 * New API in Win 2000
279 RPC_STATUS WINAPI UuidCreateSequential(UUID *Uuid)
281 return UuidCreate (Uuid);
285 /*************************************************************************
286 * RpcStringFreeA [RPCRT4.@]
288 * Frees a character string allocated by the RPC run-time library.
292 * S_OK if successful.
294 RPC_STATUS WINAPI RpcStringFreeA(unsigned char** String)
296 HeapFree( GetProcessHeap(), 0, *String);
302 /*************************************************************************
303 * UuidHash [RPCRT4.@]
305 * Generates a hash value for a given UUID
308 unsigned short WINAPI UuidHash(UUID *uuid, RPC_STATUS *Status)
315 /*************************************************************************
316 * UuidToStringA [RPCRT4.@]
318 * Converts a UUID to a string.
320 * UUID format is 8 hex digits, followed by a hyphen then three groups of
321 * 4 hex digits each followed by a hyphen and then 12 hex digits
325 * S_OK if successful.
326 * S_OUT_OF_MEMORY if unsucessful.
328 RPC_STATUS WINAPI UuidToStringA(UUID *Uuid, unsigned char** StringUuid)
330 *StringUuid = HeapAlloc( GetProcessHeap(), 0, sizeof(char) * 37);
333 return RPC_S_OUT_OF_MEMORY;
335 sprintf(*StringUuid, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
336 Uuid->Data1, Uuid->Data2, Uuid->Data3,
337 Uuid->Data4[0], Uuid->Data4[1], Uuid->Data4[2],
338 Uuid->Data4[3], Uuid->Data4[4], Uuid->Data4[5],
339 Uuid->Data4[6], Uuid->Data4[7] );
344 /***********************************************************************
345 * NdrDllRegisterProxy (RPCRT4.@)
347 HRESULT WINAPI NdrDllRegisterProxy(
348 HMODULE hDll, /* [in] */
349 const ProxyFileInfo **pProxyFileList, /* [in] */
350 const CLSID *pclsid /* [in] */
353 FIXME("(%x,%p,%s), stub!\n",hDll,pProxyFileList,debugstr_guid(pclsid));
357 /***********************************************************************
358 * RpcServerUseProtseqEpA (RPCRT4.@)
361 RPC_STATUS WINAPI RpcServerUseProtseqEpA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor )
365 TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
367 /* This should provide the default behaviour */
368 policy.Length = sizeof( policy );
369 policy.EndpointFlags = 0;
372 return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
375 /***********************************************************************
376 * RpcServerUseProtseqEpW (RPCRT4.@)
378 RPC_STATUS WINAPI RpcServerUseProtseqEpW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor )
382 TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
384 /* This should provide the default behaviour */
385 policy.Length = sizeof( policy );
386 policy.EndpointFlags = 0;
389 return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
392 /***********************************************************************
393 * RpcServerUseProtseqEpExA (RPCRT4.@)
395 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor,
396 PRPC_POLICY lpPolicy )
398 FIXME( "(%s,%u,%s,%p,{%u,%lu,%lu}): stub\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor,
399 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
401 return RPC_S_PROTSEQ_NOT_SUPPORTED; /* We don't support anything at this point */
404 /***********************************************************************
405 * RpcServerUseProtseqEpExW (RPCRT4.@)
407 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor,
408 PRPC_POLICY lpPolicy )
410 FIXME( "(%s,%u,%s,%p,{%u,%lu,%lu}): stub\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ),
412 lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
414 return RPC_S_PROTSEQ_NOT_SUPPORTED; /* We don't support anything at this point */
417 /***********************************************************************
418 * RpcServerRegisterIf (RPCRT4.@)
420 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
422 /* FIXME: Dump UUID using UuidToStringA */
423 TRACE( "(%p,%p,%p)\n", IfSpec, MgrTypeUuid, MgrEpv );
425 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
428 /***********************************************************************
429 * RpcServerRegisterIfEx (RPCRT4.@)
431 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
432 UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
434 /* FIXME: Dump UUID using UuidToStringA */
435 TRACE( "(%p,%p,%p,%u,%u,%p)\n", IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, IfCallbackFn );
437 return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
440 /***********************************************************************
441 * RpcServerRegisterIf2 (RPCRT4.@)
443 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
444 UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
446 /* FIXME: Dump UUID using UuidToStringA */
447 FIXME( "(%p,%p,%p,%u,%u,%u,%p): stub\n", IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, MaxRpcSize, IfCallbackFn );
449 return RPC_S_UNKNOWN_IF; /* I guess this return code is as good as any failure */
453 /***********************************************************************
454 * RpcServerRegisterAuthInfoA (RPCRT4.@)
456 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( LPSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
459 FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
461 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
464 /***********************************************************************
465 * RpcServerRegisterAuthInfoW (RPCRT4.@)
467 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
470 FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
472 return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
475 /***********************************************************************
476 * RpcServerListen (RPCRT4.@)
478 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
480 FIXME( "(%u,%u,%u): stub\n", MinimumCallThreads, MaxCalls, DontWait );
482 return RPC_S_NO_PROTSEQS_REGISTERED; /* Since we don't allow registration this seems reasonable */
485 /***********************************************************************
486 * RpcStringBindingComposeA (RPCRT4.@)
488 RPC_STATUS WINAPI RpcStringBindingComposeA( LPSTR ObjUuid, LPSTR Protseq, LPSTR NetworkAddr, LPSTR Endpoint,
489 LPSTR Options, LPSTR* StringBinding )
491 FIXME( "(%s,%s,%s,%s,%s,%p): stub\n", ObjUuid, Protseq, NetworkAddr, Endpoint, Options, StringBinding );
492 *StringBinding = NULL;
494 return RPC_S_INVALID_STRING_UUID; /* Failure */
497 /***********************************************************************
498 * RpcStringBindingComposeW (RPCRT4.@)
500 RPC_STATUS WINAPI RpcStringBindingComposeW( LPWSTR ObjUuid, LPWSTR Protseq, LPWSTR NetworkAddr, LPWSTR Endpoint,
501 LPWSTR Options, LPWSTR* StringBinding )
503 FIXME( "(%s,%s,%s,%s,%s,%p): stub\n", debugstr_w( ObjUuid ), debugstr_w( Protseq ), debugstr_w( NetworkAddr ),
504 debugstr_w( Endpoint ), debugstr_w( Options ), StringBinding );
505 *StringBinding = NULL;
507 return RPC_S_INVALID_STRING_UUID; /* Failure */
510 /***********************************************************************
511 * RpcBindingFree (RPCRT4.@)
513 RPC_STATUS WINAPI RpcBindingFree(RPC_BINDING_HANDLE* Binding)
515 FIXME("(%p): stub\n", Binding);
518 /***********************************************************************
519 * RpcBindingFromStringBindingA (RPCRT4.@)
521 RPC_STATUS WINAPI RpcBindingFromStringBindingA( LPSTR StringBinding, RPC_BINDING_HANDLE* Binding )
523 FIXME( "(%s,%p): stub\n", StringBinding, Binding );
525 return RPC_S_INVALID_STRING_BINDING; /* As good as any failure code */
528 /***********************************************************************
529 * RpcBindingFromStringBindingW (RPCRT4.@)
531 RPC_STATUS WINAPI RpcBindingFromStringBindingW( LPWSTR StringBinding, RPC_BINDING_HANDLE* Binding )
533 FIXME( "(%s,%p): stub\n", debugstr_w( StringBinding ), Binding );
535 return RPC_S_INVALID_STRING_BINDING; /* As good as any failure code */
538 /***********************************************************************
539 * NdrDllCanUnloadNow (RPCRT4.@)
541 HRESULT WINAPI NdrDllCanUnloadNow(CStdPSFactoryBuffer *pPSFactoryBuffer)
543 FIXME("%p\n",pPSFactoryBuffer);
547 /***********************************************************************
548 * NdrDllGetClassObject (RPCRT4.@)
550 HRESULT WINAPI NdrDllGetClassObject(
551 REFCLSID rclsid, REFIID riid , LPVOID *ppv,
552 const ProxyFileInfo ** pProxyFileList,
553 const CLSID * pclsid,
554 CStdPSFactoryBuffer * pPSFactoryBuffer)
558 return RPC_S_UNKNOWN_IF;