9 extern void krb5_stdcc_shutdown();
12 #include "gssapi/generic/gssapi_err_generic.h"
13 #include "gssapi/krb5/gssapi_err_krb5.h"
18 * #defines for MIT-specific time-based timebombs and/or version
19 * server for the Kerberos DLL.
23 #define TIMEBOMB 865141200 /* 1-Jun-97 */
24 #define TIMEBOMB_PRODUCT "SAPGUI"
25 #define TIMEBOMB_WARN 15
26 #define TIMEBOMB_INFO " Please see the web page at:\nhttp://web.mit.edu/reeng/www/saphelp for more information"
27 #define TIMEBOMB_ERROR KRB5_APPL_EXPIRED
31 #define TIMEBOMB 865141200 /* 1-Jun-97 */
32 #define TIMEBOMB_PRODUCT "Kerberos V5"
33 #define TIMEBOMB_WARN 15
34 #define TIMEBOMB_INFO " Please see the web page at:\nhttp://web.mit.edu/reeng/www/saphelp for more information"
35 #define TIMEBOMB_ERROR KRB5_LIB_EXPIRED
39 * #defines for using MIT's version server DLL
42 #define APP_TITLE "KRB5-SAP"
43 #define APP_VER "3.0f"
44 #define APP_INI "krb5sap.ini"
45 #define VERSERV_ERROR KRB5_APPL_EXPIRED
56 * This function will get the version resource information from the
57 * application using the DLL. This allows us to Version Serve
58 * arbitrary third party applications. If there is an error, or we
59 * decide that we should not version check the calling application
60 * then VSflag will be FALSE when the function returns.
62 * The buffers passed into this function must be at least
63 * APPVERINFO_SIZE bytes long.
66 #define APPVERINFO_SIZE 256
68 void GetCallingAppVerInfo( char *AppTitle, char *AppVer, char *AppIni,
71 char CallerFilename[_MAX_PATH];
73 DWORD hVersionInfoID, size;
74 GLOBALHANDLE hVersionInfo;
82 char locAppIni[_MAX_PATH];
87 /* first we need to get the calling module's filename */
92 retval = GetModuleFileName((HMODULE)wStackSeg, CallerFilename,
96 * Note: this may only work for single threaded applications,
97 * we'll live and learn ...
99 retval = GetModuleFileName( NULL, CallerFilename, _MAX_PATH);
107 size = GetFileVersionInfoSize( CallerFilename, &hVersionInfoID);
111 * hey , I bet we don't have a version resource, let's
115 /* let's see what we have? (1813 means no resource) */
116 size = GetLastError(); /* WIN32 only */
122 hVersionInfo = GlobalAlloc(GHND, size);
123 lpVersionInfo = GlobalLock(hVersionInfo);
125 retval = GetFileVersionInfo( CallerFilename, hVersionInfoID, size,
128 retval = VerQueryValue(lpVersionInfo, "\\VarFileInfo\\Translation",
129 (LPSTR *)&lpLangInfo, &dumint);
131 "\\StringFileInfo\\%04x%04x\\",
132 LOWORD(*lpLangInfo), HIWORD(*lpLangInfo));
134 cp = szVerQ + lstrlen(szVerQ);
136 lstrcpy(cp, "ProductName");
139 /* try a localAppTitle and then a strcpy 4/2/97 */
144 retval = VerQueryValue(lpVersionInfo, szVerQ, &locAppTitle,
147 lstrcpy(cp, "ProductVersion");
150 retval = VerQueryValue(lpVersionInfo, szVerQ, &locAppVer,
153 if (!locAppTitle || !locAppVer) {
154 /* Punt, we don't have the right version resource records */
160 * We don't have a way to determine that INI file of the
161 * application at the moment so let's just use krb5.ini
163 strncpy( locAppIni, KERBEROS_INI, sizeof(locAppIni) - 1 );
164 locAppIni[ sizeof(locAppIni) - 1 ] = '\0';
166 strncpy( AppTitle, locAppTitle, APPVERINFO_SIZE);
167 AppTitle[APPVERINFO_SIZE - 1] = '\0';
168 strncpy( AppVer, locAppVer, APPVERINFO_SIZE);
169 AppVer[APPVERINFO_SIZE - 1] = '\0';
170 strncpy( AppIni, locAppIni, APPVERINFO_SIZE);
171 AppIni[APPVERINFO_SIZE - 1] = '\0';
174 * We also need to determine if we want to suppress version
175 * checking of this application. Does the tail of the
176 * AppTitle end in a "-v" ?
178 revAppTitle = _strrev( _strdup(AppTitle));
179 if( revAppTitle[0] == 'v' || revAppTitle[0] == 'V' &&
180 revAppTitle[1] == '-' ) {
188 * Use the version server to give us some control on distribution and usage
189 * We're going to test track as well
191 static int CallVersionServer(app_title, app_version, app_ini, code_cover)
200 SetCursor(LoadCursor(NULL, IDC_WAIT));
203 * We should be able to pass in code_cover below, but things
204 * are breaking under Windows 16 for no good reason.
206 vrequest = VSFormRequest((LPSTR) app_title, (LPSTR) app_version,
208 NULL /* code_cover */, NULL,
211 SetCursor(LoadCursor(NULL, IDC_ARROW));
213 * If the user presses cancel when registering the test
214 * tracker, we'll let them continue.
216 if (ReqStatus(vrequest) == V_E_CANCEL) {
217 VSDestroyRequest(vrequest);
220 vstatus = VSProcessRequest(vrequest);
222 * Only complain periodically, if the test tracker isn't
225 if (v_complain(vstatus, app_ini)) {
226 WinVSReportRequest(vrequest, NULL,
227 "Version Server Status Report");
229 if (vstatus == V_REQUIRED) {
230 SetCursor(LoadCursor(NULL, IDC_WAIT));
231 VSDestroyRequest(vrequest);
234 VSDestroyRequest(vrequest);
240 static krb5_error_code do_timebomb()
244 static first_time = 1;
246 timeleft = TIMEBOMB - time(0);
249 sprintf(buf, "Your version of %s has expired.\n",
251 buf[sizeof(buf) - 1] = '\0';
252 strncat(buf, "Please upgrade it.", sizeof(buf) - 1 - strlen(buf));
254 strncat(buf, TIMEBOMB_INFO, sizeof(buf) - 1 - strlen(buf));
256 MessageBox(NULL, buf, "", MB_OK);
259 return TIMEBOMB_ERROR;
261 timeleft = timeleft / ((long) 60*60*24);
262 if (timeleft < TIMEBOMB_WARN) {
264 sprintf(buf, "Your version of %s will expire in %ld days.\n",
265 TIMEBOMB_PRODUCT, timeleft);
266 strncat(buf, "Please upgrade it soon.", sizeof(buf) - 1 - strlen(buf));
268 strncat(buf, TIMEBOMB_INFO, sizeof(buf) - 1 - strlen(buf));
270 MessageBox(NULL, buf, "", MB_OK);
279 * This was originally called from LibMain; unfortunately, Windows 3.1
280 * doesn't allow you to make messaging calls from LibMain. So, we now
281 * do the timebomb/version server stuff from krb5_init_context().
283 krb5_error_code krb5_vercheck()
285 static int verchecked = 0;
289 krb5_error_code retval = do_timebomb();
295 /* Check library ? */
296 if (CallVersionServer(APP_TITLE, APP_VER, APP_INI, NULL))
297 return KRB5_LIB_EXPIRED;
301 if (CallVersionServer(APP_TITLE, APP_VER, APP_INI, NULL))
302 return VERSERV_ERROR;
304 char AppTitle[APPVERINFO_SIZE];
305 char AppVer[APPVERINFO_SIZE];
306 char AppIni[APPVERINFO_SIZE];
309 GetCallingAppVerInfo( AppTitle, AppVer, AppIni, &VSflag);
312 if (CallVersionServer(AppTitle, AppVer, AppIni, NULL))
313 return KRB5_APPL_EXPIRED;
324 static HINSTANCE hlibinstance;
326 HINSTANCE get_lib_instance()
331 #define DLL_STARTUP 0
332 #define DLL_SHUTDOWN 1
343 krb5_stdcc_shutdown();
347 #if defined(ENABLE_THREADS) && defined(SUPPORTLIB)
348 case DLL_THREAD_DETACH:
349 krb5int_thread_detach_hook();
360 profile_library_initializer__auxinit();
361 cryptoint_initialize_library__auxinit();
362 krb5int_lib_init__auxinit();
366 cryptoint_cleanup_library();
367 profile_library_finalizer();
373 gssint_mechglue_init__auxinit();
376 gssint_mechglue_fini();
382 com_err_initialize__auxinit();
388 #elif defined PROFILELIB
391 profile_library_initializer__auxinit();
394 profile_library_finalizer();
397 #elif defined SUPPORTLIB
400 krb5int_thread_support_init__auxinit();
403 krb5int_thread_support_fini();
407 # error "Don't know the init/fini functions for this library."
415 BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
419 case DLL_PROCESS_ATTACH:
420 hlibinstance = (HINSTANCE) hModule;
421 if (control(DLL_STARTUP))
425 case DLL_THREAD_ATTACH:
428 case DLL_THREAD_DETACH:
429 if (control(DLL_THREAD_DETACH))
433 case DLL_PROCESS_DETACH:
434 if (control(DLL_SHUTDOWN))
442 return TRUE; // successful DLL_PROCESS_ATTACH
448 LibMain (hInst, wDataSeg, cbHeap, CmdLine)
454 hlibinstance = hInst;
455 if (control(DLL_STARTUP))
461 int CALLBACK __export
465 if (control(DLL_SHUTDOWN))