4 * Copyright 2008 Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. Furthermore if you modify this software you must label
20 * your software as modified software and not distribute it in such a
21 * fashion that it might be confused with the original M.I.T. software.
22 * M.I.T. makes no representations about the suitability of
23 * this software for any purpose. It is provided "as is" without express
24 * or implied warranty.
32 #include "cci_debugging.h"
36 CcOsLock Init::s_lock;
37 DWORD Init::s_refcount = 0;
38 DWORD Init::s_error = ERROR_INVALID_HANDLE;
39 bool Init::s_init = false;
40 Init::InitInfo Init::s_info = { 0 };
41 HINSTANCE Init::s_hRpcDll = 0;
56 // This function will not do automatic initialization.
57 CcAutoLock AL(s_lock);
59 memset(&info, 0, sizeof(info));
60 return s_error ? s_error : ERROR_INVALID_HANDLE;
69 CcAutoLock AL(s_lock);
70 cci_debug_printf("%s s_init:%d", __FUNCTION__, s_init);
78 BOOL isSupportedVersion = FALSE;
79 memset(&s_info, 0, sizeof(s_info));
80 memset(&osvi, 0, sizeof(osvi));
81 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
83 status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
86 switch(osvi.dwPlatformId) {
87 case VER_PLATFORM_WIN32_WINDOWS:
89 isSupportedVersion = TRUE;
91 case VER_PLATFORM_WIN32_NT:
93 isSupportedVersion = TRUE;
95 case VER_PLATFORM_WIN32s:
101 if (!isSupportedVersion) {
102 cci_debug_printf("%s Trying to run on an unsupported version of Windows", __FUNCTION__);
107 if (!status) {status = !s_info.isNT;}
109 if (!status) {status = !(s_hRpcDll = LoadLibrary(TEXT("rpcrt4.dll")));}
112 s_info.fRpcBindingSetAuthInfoEx = (FP_RpcBindingSetAuthInfoEx)
113 GetProcAddress(s_hRpcDll, TEXT(FN_RpcBindingSetAuthInfoEx));
114 if (!s_info.fRpcBindingSetAuthInfoEx) {
115 cci_debug_printf(" Running on NT but could not find RpcBindinSetAuthInfoEx");
121 s_info.fRpcServerRegisterIfEx = (FP_RpcServerRegisterIfEx)
122 GetProcAddress(s_hRpcDll, TEXT(FN_RpcServerRegisterIfEx));
123 if (!s_info.fRpcServerRegisterIfEx) {
124 cci_debug_printf(" Running on NT but could not find RpcServerRegisterIfEx");
130 status = SecureClient::Attach();
132 cci_debug_printf(" SecureClient::Attach() failed (%u)", status);
137 memset(&s_info, 0, sizeof(s_info));
139 FreeLibrary(s_hRpcDll);
142 cci_debug_printf(" Init::Attach() failed (%u)", status);
156 CcAutoLock AL(s_lock);
158 if (s_refcount) return 0;
159 if (!s_init) return 0;
162 FreeLibrary(s_hRpcDll);
165 error = SecureClient::Detach();
166 memset(&s_info, 0, sizeof(s_info));
170 cci_debug_printf(" Init::Detach() had an error (%u)", error);
182 cci_debug_printf(" Running on Windows NT using secure mode");
184 cci_debug_printf(" Running insecurely on non-NT Windows");