1 /* NFSv4.1 client for Windows
2 * Copyright © 2012 The Regents of the University of Michigan
4 * Olga Kornievskaia <aglo@umich.edu>
5 * Casey Bodley <cbodley@umich.edu>
7 * This library is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or (at
10 * your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * without any warranty; without even the implied warranty of merchantability
14 * or fitness for a particular purpose. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 static DWORD dwTlsIndex
;
36 extern void multithread_init(void);
39 tirpc_report(LPTSTR lpszMsg
)
43 LPCWSTR lpszStrings
[2];
45 // Use event logging to log the error.
47 hEventSource
= RegisterEventSource(NULL
,
51 swprintf_s(chMsg
, sizeof(chMsg
), L
"tirpc report: %d", GetLastError());
53 _snwprintf(chMsg
, sizeof(chMsg
) / sizeof(WCHAR
), L
"tirpc report: %d", GetLastError());
55 lpszStrings
[0] = (LPCWSTR
)chMsg
;
56 lpszStrings
[1] = lpszMsg
;
58 if (hEventSource
!= NULL
) {
59 ReportEvent(hEventSource
, // handle of event source
60 EVENTLOG_WARNING_TYPE
, // event type
63 NULL
, // current user's SID
64 2, // strings in lpszStrings
65 0, // no bytes of raw data
66 lpszStrings
, // array of error strings
69 (VOID
) DeregisterEventSource(hEventSource
);
73 void tirpc_criticalsection_init(void) {
77 BOOL
winsock_init(void)
80 err
= WSAStartup(MAKEWORD( 3, 3 ), &WSAData
); // XXX THIS SHOULD BE FAILING!!!!!!!!!!!!!!!!!
83 tirpc_report(L
"WSAStartup failed!\n");
90 BOOL
winsock_fini(void)
96 BOOL WINAPI DllMain
/*tirpc_main*/(HINSTANCE hinstDLL
, // DLL module handle
97 DWORD fdwReason
, // reason called
98 LPVOID lpvReserved
) // reserved
106 // Deal with Thread Local Storage initialization!!
109 // The DLL is loading due to process
110 // initialization or a call to LoadLibrary.
111 case DLL_PROCESS_ATTACH
:
113 // Initialize socket library
114 if (winsock_init() == FALSE
)
117 // Initialize CriticalSections
118 tirpc_criticalsection_init();
120 // Allocate a TLS index.
121 if ((dwTlsIndex
= TlsAlloc()) == TLS_OUT_OF_INDEXES
)
124 // No break: Initialize the index for first thread.
126 // The attached process creates a new thread.
127 case DLL_THREAD_ATTACH
:
129 // Initialize the TLS index for this thread
130 lpvData
= (LPVOID
) LocalAlloc(LPTR
, 256);
132 fIgnore
= TlsSetValue(dwTlsIndex
, lpvData
);
136 // The thread of the attached process terminates.
137 case DLL_THREAD_DETACH
:
139 // Release the allocated memory for this thread.
140 lpvData
= TlsGetValue(dwTlsIndex
);
142 LocalFree((HLOCAL
) lpvData
);
146 // DLL unload due to process termination or FreeLibrary.
147 case DLL_PROCESS_DETACH
:
149 // Release the allocated memory for this thread.
150 lpvData
= TlsGetValue(dwTlsIndex
);
152 LocalFree((HLOCAL
) lpvData
);
154 // Release the TLS index.
157 // Clean up winsock stuff
172 if (init
== 0 || --init
> 0)
179 void wintirpc_debug(char *fmt
, ...)
184 static int triedToOpen
= 0;
185 static FILE *dbgFile
= NULL
;
189 va_start(vargs
, fmt
);
192 vsprintf(buffer
, fmt
, vargs
);
193 OutputDebugStringA(buffer
);
195 if (dbgFile
== NULL
&& triedToOpen
== 0) {
197 dbgFile
= fopen("c:\\etc\\rpcsec_gss_debug.txt", "w");
199 if (dbgFile
!= NULL
) {
200 vfprintf(dbgFile
, fmt
, vargs
);