Use DrawFrameControl instead of bitmaps in certain cases.
[wine] / dlls / rpcrt4 / rpcrt4_main.c
1 /*
2  *  RPCRT4
3  *
4  */
5
6 #include "config.h"
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <time.h>
12 #include <sys/time.h>
13 #include <unistd.h>
14
15 #include "windef.h"
16 #include "wine/windef16.h"
17 #include "winerror.h"
18 #include "winbase.h"
19 #include "rpc.h"
20
21 #ifdef HAVE_SYS_FILE_H
22 # include <sys/file.h>
23 #endif
24 #include <sys/ioctl.h>
25 #ifdef HAVE_SYS_SOCKET_H
26 # include <sys/socket.h>
27 #endif
28 #ifdef HAVE_SYS_SOCKIO_H
29 # include <sys/sockio.h>
30 #endif
31 #ifdef HAVE_NET_IF_H
32 # include <net/if.h>
33 #endif
34 #ifdef HAVE_NETINET_IN_H
35 # include <netinet/in.h>
36 #endif
37
38 #include "debugtools.h"
39
40 DEFAULT_DEBUG_CHANNEL(ole);
41
42 /***********************************************************************
43  * RPCRT4_LibMain
44  *
45  * PARAMS
46  *     hinstDLL    [I] handle to the DLL's instance
47  *     fdwReason   [I]
48  *     lpvReserved [I] reserved, must be NULL
49  *
50  * RETURNS
51  *     Success: TRUE
52  *     Failure: FALSE
53  */
54
55 BOOL WINAPI
56 RPCRT4_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
57 {
58     switch (fdwReason) {
59     case DLL_PROCESS_ATTACH:
60         break;
61
62     case DLL_PROCESS_DETACH:
63         break;      
64     }
65
66     return TRUE;
67 }
68
69 /*************************************************************************
70  *           UuidCreate   [RPCRT4.@]
71  *
72  * Creates a 128bit UUID.
73  * Implemented according the DCE specification for UUID generation.
74  * Code is based upon uuid library in e2fsprogs by Theodore Ts'o.
75  * Copyright (C) 1996, 1997 Theodore Ts'o.
76  *
77  * RETURNS
78  *
79  *  S_OK if successful.
80  */
81 RPC_STATUS WINAPI UuidCreate(UUID *Uuid)
82 {
83    static char has_init = 0;
84    unsigned char a[6];
85    static int                      adjustment = 0;
86    static struct timeval           last = {0, 0};
87    static UINT16                   clock_seq;
88    struct timeval                  tv;
89    unsigned long long              clock_reg;
90    UINT clock_high, clock_low;
91    UINT16 temp_clock_seq, temp_clock_mid, temp_clock_hi_and_version;
92 #ifdef HAVE_NET_IF_H
93    int             sd;
94    struct ifreq    ifr, *ifrp;
95    struct ifconf   ifc;
96    char buf[1024];
97    int             n, i;
98 #endif
99    
100    /* Have we already tried to get the MAC address? */
101    if (!has_init) {
102 #ifdef HAVE_NET_IF_H
103       /* BSD 4.4 defines the size of an ifreq to be
104        * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
105        * However, under earlier systems, sa_len isn't present, so
106        *  the size is just sizeof(struct ifreq)
107        */
108 #ifdef HAVE_SOCKADDR_SA_LEN
109 #  ifndef max
110 #   define max(a,b) ((a) > (b) ? (a) : (b))
111 #  endif
112 #  define ifreq_size(i) max(sizeof(struct ifreq),\
113 sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
114 # else
115 #  define ifreq_size(i) sizeof(struct ifreq)
116 # endif /* defined(HAVE_SOCKADDR_SA_LEN) */
117
118       sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
119       if (sd < 0) {
120          /* if we can't open a socket, just use random numbers */
121          /* set the multicast bit to prevent conflicts with real cards */
122          a[0] = (rand() & 0xff) | 0x80;
123          a[1] = rand() & 0xff;
124          a[2] = rand() & 0xff;
125          a[3] = rand() & 0xff;
126          a[4] = rand() & 0xff;
127          a[5] = rand() & 0xff;
128       } else {
129          memset(buf, 0, sizeof(buf));
130          ifc.ifc_len = sizeof(buf);
131          ifc.ifc_buf = buf;
132          /* get the ifconf interface */
133          if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
134             close(sd);
135             /* no ifconf, so just use random numbers */
136             /* set the multicast bit to prevent conflicts with real cards */
137             a[0] = (rand() & 0xff) | 0x80;
138             a[1] = rand() & 0xff;
139             a[2] = rand() & 0xff;
140             a[3] = rand() & 0xff;
141             a[4] = rand() & 0xff;
142             a[5] = rand() & 0xff;
143          } else {
144             /* loop through the interfaces, looking for a valid one */
145             n = ifc.ifc_len;
146             for (i = 0; i < n; i+= ifreq_size(ifr) ) {
147                ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
148                strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
149                /* try to get the address for this interface */
150 # ifdef SIOCGIFHWADDR
151                if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
152                    continue;
153                memcpy(a, (unsigned char *)&ifr.ifr_hwaddr.sa_data, 6);
154 # else
155 #  ifdef SIOCGENADDR
156                if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
157                    continue;
158                memcpy(a, (unsigned char *) ifr.ifr_enaddr, 6);
159 #  else
160                /* XXX we don't have a way of getting the hardware address */
161                close(sd);
162                a[0] = 0;
163                break;
164 #  endif /* SIOCGENADDR */
165 # endif /* SIOCGIFHWADDR */
166                /* make sure it's not blank */
167                if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
168                    continue;
169                                                                 
170                goto valid_address;
171             }
172             /* if we didn't find a valid address, make a random one */
173             /* once again, set multicast bit to avoid conflicts */
174             a[0] = (rand() & 0xff) | 0x80;
175             a[1] = rand() & 0xff;
176             a[2] = rand() & 0xff;
177             a[3] = rand() & 0xff;
178             a[4] = rand() & 0xff;
179             a[5] = rand() & 0xff;
180
181             valid_address:
182             close(sd);
183          }
184       }
185 #else
186       /* no networking info, so generate a random address */
187       a[0] = (rand() & 0xff) | 0x80;
188       a[1] = rand() & 0xff;
189       a[2] = rand() & 0xff;
190       a[3] = rand() & 0xff;
191       a[4] = rand() & 0xff;
192       a[5] = rand() & 0xff;
193 #endif /* HAVE_NET_IF_H */
194       has_init = 1;
195    }
196    
197    /* generate time element of GUID */
198    
199    /* Assume that the gettimeofday() has microsecond granularity */
200 #define MAX_ADJUSTMENT 10
201                      
202    try_again:
203    gettimeofday(&tv, 0);
204    if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
205       clock_seq = ((rand() & 0xff) << 8) + (rand() & 0xff);
206       clock_seq &= 0x1FFF;
207       last = tv;
208       last.tv_sec--;
209    }
210    if ((tv.tv_sec < last.tv_sec) ||
211        ((tv.tv_sec == last.tv_sec) &&
212         (tv.tv_usec < last.tv_usec))) {
213       clock_seq = (clock_seq+1) & 0x1FFF;
214       adjustment = 0;
215    } else if ((tv.tv_sec == last.tv_sec) &&
216               (tv.tv_usec == last.tv_usec)) {
217       if (adjustment >= MAX_ADJUSTMENT)
218           goto try_again;
219       adjustment++;
220    } else
221        adjustment = 0;
222    
223    clock_reg = tv.tv_usec*10 + adjustment;
224    clock_reg += ((unsigned long long) tv.tv_sec)*10000000;
225    clock_reg += (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
226    
227    clock_high = clock_reg >> 32;
228    clock_low = clock_reg;
229    temp_clock_seq = clock_seq | 0x8000;
230    temp_clock_mid = (UINT16)clock_high;
231    temp_clock_hi_and_version = (clock_high >> 16) | 0x1000;
232    
233    /* pack the information into the GUID structure */
234    
235    ((unsigned char*)&Uuid->Data1)[3] = (unsigned char)clock_low;
236    clock_low >>= 8;
237    ((unsigned char*)&Uuid->Data1)[2] = (unsigned char)clock_low;
238    clock_low >>= 8;
239    ((unsigned char*)&Uuid->Data1)[1] = (unsigned char)clock_low;
240    clock_low >>= 8;
241    ((unsigned char*)&Uuid->Data1)[0] = (unsigned char)clock_low;
242    
243    ((unsigned char*)&Uuid->Data2)[1] = (unsigned char)temp_clock_mid;
244    temp_clock_mid >>= 8;
245    ((unsigned char*)&Uuid->Data2)[0] = (unsigned char)temp_clock_mid;
246    
247    ((unsigned char*)&Uuid->Data3)[1] = (unsigned char)temp_clock_hi_and_version;
248    temp_clock_hi_and_version >>= 8;
249    ((unsigned char*)&Uuid->Data3)[0] = (unsigned char)temp_clock_hi_and_version;
250       
251    ((unsigned char*)Uuid->Data4)[1] = (unsigned char)temp_clock_seq;
252    temp_clock_seq >>= 8;
253    ((unsigned char*)Uuid->Data4)[0] = (unsigned char)temp_clock_seq;
254    
255    ((unsigned char*)Uuid->Data4)[2] = a[0];
256    ((unsigned char*)Uuid->Data4)[3] = a[1];
257    ((unsigned char*)Uuid->Data4)[4] = a[2];
258    ((unsigned char*)Uuid->Data4)[5] = a[3];
259    ((unsigned char*)Uuid->Data4)[6] = a[4];
260    ((unsigned char*)Uuid->Data4)[7] = a[5];
261    
262    TRACE("%s\n", debugstr_guid(Uuid));
263    
264    return RPC_S_OK;
265 }
266
267 /*************************************************************************
268  *           RpcStringFreeA   [RPCRT4.@]
269  *
270  * Frees a character string allocated by the RPC run-time library.
271  *
272  * RETURNS
273  *
274  *  S_OK if successful.
275  */
276 RPC_STATUS WINAPI RpcStringFreeA(unsigned char** String)
277 {
278   HeapFree( GetProcessHeap(), 0, *String);
279
280   return RPC_S_OK;
281 }
282
283
284 /*************************************************************************
285  *           UuidHash   [RPCRT4.@]
286  *
287  * Generates a hash value for a given UUID
288  *
289  */
290 unsigned short WINAPI UuidHash(UUID *uuid, RPC_STATUS *Status)
291 {
292   FIXME("stub:\n");
293   *Status = RPC_S_OK;
294   return 0xabcd;
295 }
296
297 /*************************************************************************
298  *           UuidToStringA   [RPCRT4.@]
299  *
300  * Converts a UUID to a string.
301  *
302  * UUID format is 8 hex digits, followed by a hyphen then three groups of
303  * 4 hex digits each followed by a hyphen and then 12 hex digits
304  *
305  * RETURNS
306  *
307  *  S_OK if successful.
308  *  S_OUT_OF_MEMORY if unsucessful.
309  */
310 RPC_STATUS WINAPI UuidToStringA(UUID *Uuid, unsigned char** StringUuid)
311 {
312   *StringUuid = HeapAlloc( GetProcessHeap(), 0, sizeof(char) * 37);
313
314   if(!(*StringUuid))
315     return RPC_S_OUT_OF_MEMORY;
316
317   sprintf(*StringUuid, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
318                  Uuid->Data1, Uuid->Data2, Uuid->Data3,
319                  Uuid->Data4[0], Uuid->Data4[1], Uuid->Data4[2],
320                  Uuid->Data4[3], Uuid->Data4[4], Uuid->Data4[5],
321                  Uuid->Data4[6], Uuid->Data4[7] );
322
323   return RPC_S_OK;
324 }
325
326 /***********************************************************************
327  *              NdrDllRegisterProxy (RPCRT4.@)
328  */
329 HRESULT WINAPI NdrDllRegisterProxy(
330   HMODULE hDll,          /* [in] */
331   void **pProxyFileList, /* [???] FIXME: const ProxyFileInfo ** */
332   const CLSID *pclsid    /* [in] */
333
334 {
335   FIXME("(%x,%p,%s), stub!\n",hDll,pProxyFileList,debugstr_guid(pclsid));
336   return S_OK;
337 }
338
339 /***********************************************************************
340  *              RpcServerUseProtseqEpA (RPCRT4.@)
341  */
342
343 RPC_STATUS WINAPI RpcServerUseProtseqEpA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor )
344 {
345   RPC_POLICY policy;
346   
347   TRACE( "(%s,%u,%s,%p)\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor );
348   
349   /* This should provide the default behaviour */
350   policy.Length        = sizeof( policy );
351   policy.EndpointFlags = 0;
352   policy.NICFlags      = 0;
353   
354   return RpcServerUseProtseqEpExA( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
355 }
356
357 /***********************************************************************
358  *              RpcServerUseProtseqEpW (RPCRT4.@)
359  */
360 RPC_STATUS WINAPI RpcServerUseProtseqEpW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor )
361 {
362   RPC_POLICY policy;
363   
364   TRACE( "(%s,%u,%s,%p)\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ), SecurityDescriptor );
365   
366   /* This should provide the default behaviour */
367   policy.Length        = sizeof( policy );
368   policy.EndpointFlags = 0;
369   policy.NICFlags      = 0;
370   
371   return RpcServerUseProtseqEpExW( Protseq, MaxCalls, Endpoint, SecurityDescriptor, &policy );
372 }
373
374 /***********************************************************************
375  *              RpcServerUseProtseqEpExA (RPCRT4.@)
376  */
377 RPC_STATUS WINAPI RpcServerUseProtseqEpExA( LPSTR Protseq, UINT MaxCalls, LPSTR Endpoint, LPVOID SecurityDescriptor,
378                           PRPC_POLICY lpPolicy )
379 {
380   FIXME( "(%s,%u,%s,%p,{%u,%lu,%lu}): stub\n", Protseq, MaxCalls, Endpoint, SecurityDescriptor,
381                                                lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
382   
383   return RPC_S_PROTSEQ_NOT_SUPPORTED; /* We don't support anything at this point */                       
384 }
385
386 /***********************************************************************
387  *              RpcServerUseProtseqEpExW (RPCRT4.@)
388  */
389 RPC_STATUS WINAPI RpcServerUseProtseqEpExW( LPWSTR Protseq, UINT MaxCalls, LPWSTR Endpoint, LPVOID SecurityDescriptor,
390                           PRPC_POLICY lpPolicy )
391 {
392   FIXME( "(%s,%u,%s,%p,{%u,%lu,%lu}): stub\n", debugstr_w( Protseq ), MaxCalls, debugstr_w( Endpoint ),
393                                                SecurityDescriptor,
394                                                lpPolicy->Length, lpPolicy->EndpointFlags, lpPolicy->NICFlags );
395   
396   return RPC_S_PROTSEQ_NOT_SUPPORTED; /* We don't support anything at this point */                       
397 }
398
399 /***********************************************************************
400  *              RpcServerRegisterIf (RPCRT4.@)
401  */
402 RPC_STATUS WINAPI RpcServerRegisterIf( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv )
403 {
404   /* FIXME: Dump UUID using UuidToStringA */
405   TRACE( "(%p,%p,%p)\n", IfSpec, MgrTypeUuid, MgrEpv );
406   
407   return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, (UINT)-1, NULL );
408 }
409
410 /***********************************************************************
411  *              RpcServerRegisterIfEx (RPCRT4.@)
412  */
413 RPC_STATUS WINAPI RpcServerRegisterIfEx( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
414                        UINT Flags, UINT MaxCalls, RPC_IF_CALLBACK_FN* IfCallbackFn )
415 {
416   /* FIXME: Dump UUID using UuidToStringA */
417   TRACE( "(%p,%p,%p,%u,%u,%p)\n", IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, IfCallbackFn );
418   
419   return RpcServerRegisterIf2( IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, (UINT)-1, IfCallbackFn );
420 }
421
422 /***********************************************************************
423  *              RpcServerRegisterIf2 (RPCRT4.@)
424  */
425 RPC_STATUS WINAPI RpcServerRegisterIf2( RPC_IF_HANDLE IfSpec, UUID* MgrTypeUuid, RPC_MGR_EPV* MgrEpv,
426                       UINT Flags, UINT MaxCalls, UINT MaxRpcSize, RPC_IF_CALLBACK_FN* IfCallbackFn )
427 {
428   /* FIXME: Dump UUID using UuidToStringA */
429   FIXME( "(%p,%p,%p,%u,%u,%u,%p): stub\n", IfSpec, MgrTypeUuid, MgrEpv, Flags, MaxCalls, MaxRpcSize, IfCallbackFn );
430   
431   return RPC_S_UNKNOWN_IF; /* I guess this return code is as good as any failure */
432 }
433
434
435 /***********************************************************************
436  *              RpcServerRegisterAuthInfoA (RPCRT4.@)
437  */
438 RPC_STATUS WINAPI RpcServerRegisterAuthInfoA( LPSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
439                             LPVOID Arg )
440 {
441   FIXME( "(%s,%lu,%p,%p): stub\n", ServerPrincName, AuthnSvc, GetKeyFn, Arg );
442   
443   return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
444 }
445
446 /***********************************************************************
447  *              RpcServerRegisterAuthInfoW (RPCRT4.@)
448  */
449 RPC_STATUS WINAPI RpcServerRegisterAuthInfoW( LPWSTR ServerPrincName, ULONG AuthnSvc, RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
450                             LPVOID Arg )
451 {
452   FIXME( "(%s,%lu,%p,%p): stub\n", debugstr_w( ServerPrincName ), AuthnSvc, GetKeyFn, Arg );
453   
454   return RPC_S_UNKNOWN_AUTHN_SERVICE; /* We don't know any authentication services */
455 }
456
457 /***********************************************************************
458  *              RpcServerListen (RPCRT4.@)
459  */
460 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
461 {
462   FIXME( "(%u,%u,%u): stub\n", MinimumCallThreads, MaxCalls, DontWait );
463   
464   return RPC_S_NO_PROTSEQS_REGISTERED; /* Since we don't allow registration this seems reasonable */
465 }
466
467 /***********************************************************************
468  *              RpcStringBindingComposeA (RPCRT4.@)
469  */
470 RPC_STATUS WINAPI RpcStringBindingComposeA( LPSTR ObjUuid, LPSTR Protseq, LPSTR NetworkAddr, LPSTR Endpoint,
471                           LPSTR Options, LPSTR* StringBinding )
472 {
473   FIXME( "(%s,%s,%s,%s,%s,%p): stub\n", ObjUuid, Protseq, NetworkAddr, Endpoint, Options, StringBinding );
474   *StringBinding = NULL;
475   
476   return RPC_S_INVALID_STRING_UUID; /* Failure */
477 }
478
479 /***********************************************************************
480  *              RpcStringBindingComposeW (RPCRT4.@)
481  */
482 RPC_STATUS WINAPI RpcStringBindingComposeW( LPWSTR ObjUuid, LPWSTR Protseq, LPWSTR NetworkAddr, LPWSTR Endpoint,
483                           LPWSTR Options, LPWSTR* StringBinding )
484 {
485   FIXME( "(%s,%s,%s,%s,%s,%p): stub\n", debugstr_w( ObjUuid ), debugstr_w( Protseq ), debugstr_w( NetworkAddr ),
486                                         debugstr_w( Endpoint ), debugstr_w( Options ), StringBinding );
487   *StringBinding = NULL;
488   
489   return RPC_S_INVALID_STRING_UUID; /* Failure */
490 }
491
492 /***********************************************************************
493  *              RpcBindingFromStringBindingA (RPCRT4.@)
494  */
495 RPC_STATUS WINAPI RpcBindingFromStringBindingA( LPSTR StringBinding, RPC_BINDING_HANDLE* Binding )
496 {
497   FIXME( "(%s,%p): stub\n", StringBinding, Binding );
498   
499   return RPC_S_INVALID_STRING_BINDING; /* As good as any failure code */
500 }
501   
502 /***********************************************************************
503  *              RpcBindingFromStringBindingW (RPCRT4.@)
504  */
505 RPC_STATUS WINAPI RpcBindingFromStringBindingW( LPWSTR StringBinding, RPC_BINDING_HANDLE* Binding )
506 {
507   FIXME( "(%s,%p): stub\n", debugstr_w( StringBinding ), Binding );
508
509   return RPC_S_INVALID_STRING_BINDING; /* As good as any failure code */
510 }