From b0c22b91e53f448758517da1b14337cfe16e2976 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Tue, 29 Apr 1997 10:44:10 +0000 Subject: [PATCH] win_glue.c: Add code to get the version resource from the calling application and use that to call the Version server. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10078 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/ChangeLog | 6 ++ src/lib/Makefile.in | 20 ++++--- src/lib/win_glue.c | 143 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 159 insertions(+), 10 deletions(-) diff --git a/src/lib/ChangeLog b/src/lib/ChangeLog index c4693b496..150ef916e 100644 --- a/src/lib/ChangeLog +++ b/src/lib/ChangeLog @@ -1,3 +1,9 @@ +Tue Apr 29 06:22:03 1997 Theodore Ts'o + + * win_glue.c (CallVersionServer): Add code to get the version + resource from the calling application and use that to call + the Version server. + Fri Mar 28 01:51:09 1997 Theodore Y. Ts'o * gssapi16.def, gssapi32.def: Added the V2 calls diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in index 9c281fd15..f8a5b4141 100644 --- a/src/lib/Makefile.in +++ b/src/lib/Makefile.in @@ -31,6 +31,12 @@ KLIBS = krb5\krb5.lib crypto\crypto.lib \ GLIBS = gssapi\gssapi.lib K4LIBS = krb4\krb4.lib +##WIN16##VERLIBS=..\mit\windows\lib\vswin.lib c:\msvc\lib\ver.lib +##WIN32##VERLIBS=..\mit\windows\lib\vsnt.lib \ +##WIN32## "c:\program files\devstudio\vc\lib\version.lib" +##MIT##MITLIBS= $(VERLIBS) +##MIT##MITFLAGS=-I..\mit\windows\include /DVERSERV=1 + ##WIN16##CDEF = comerr16.def ##WIN32##CDEF = comerr32.def ##WIN16##KDEF = krb5_16.def @@ -62,22 +68,22 @@ $(CLIB): $(CLIBS) $(WLIB) $(CDEF) no_glue.obj $(KLIB): $(KLIBS) $(CLIB) $(WLIB) $(KDEF) k5_glue.obj $(KRB5RC) ##WIN16## link /co /seg:400 /noe /nod /nol \ ##WIN16## k5_glue, $*.dll, $*.map, \ -##WIN16## $(KLIBS) $(CLIB) $(WINLIBS), $(KDEF) +##WIN16## $(MITLIBS) $(KLIBS) $(CLIB) $(WINLIBS), $(KDEF) ##WIN16## rc /nologo /p /k $(CPPFLAGS) -D_MSDOS -DRES_ONLY \ ##WIN16## $(KRB5RC) $*.dll ##WIN16## implib /nologo $@ $*.dll ##WIN32## link $(WINDLLFLAGS) /def:$(KDEF) /out:$*.dll \ -##WIN32## k5_glue.obj $(KRB5RC) $(KLIBS) $(CLIB) $(WINLIBS) \ -##WIN32## advapi32.lib gdi32.lib +##WIN32## k5_glue.obj $(KRB5RC) $(MITLIBS) $(KLIBS) $(CLIB) \ +##WIN32## $(WINLIBS) advapi32.lib gdi32.lib $(GLIB): $(GLIBS) $(KLIB) $(CLIB) $(GDEF) gss_glue.obj ##WIN16## link /co /seg:400 /noe /nod /nol \ ##WIN16## gss_glue, $*.dll, $*.map, \ -##WIN16## $(GLIBS) $(KLIB) $(CLIB) $(WINLIBS), $(GDEF) +##WIN16## $(MITLIBS) $(GLIBS) $(KLIB) $(CLIB) $(WINLIBS), $(GDEF) ##WIN16## rc /nologo /p /k $*.dll ##WIN16## implib /nologo $@ $*.dll ##WIN32## link $(WINDLLFLAGS) /def:$(GDEF) /out:$*.dll \ -##WIN32## gss_glue.obj $(GLIBS) $(KLIB) $(CLIB) $(WINLIBS) +##WIN32## gss_glue.obj $(MITLIBS) $(GLIBS) $(KLIB) $(CLIB) $(WINLIBS) $(K4LIB): $(K4LIBS) $(KLIB) $(CLIB) $(K4DEF) k4_glue.obj ##WIN16## link /co /seg:400 /noe /nod /nol \ @@ -89,11 +95,11 @@ $(K4LIB): $(K4LIBS) $(KLIB) $(CLIB) $(K4DEF) k4_glue.obj ##WIN32## k4_glue.obj $(K4LIBS) $(KLIB) $(CLIB) $(WINLIBS) k5_glue.obj: win_glue.c - $(CC) $(CFLAGS) /c /DKRB5=1 /Fo$@ $** + $(CC) $(CFLAGS) $(MITFLAGS) /c /DKRB5=1 /Fo$@ $** k4_glue.obj: win_glue.c $(CC) $(CFLAGS) /c /DKRB4=1 /Fo$@ $** gss_glue.obj: win_glue.c - $(CC) $(CFLAGS) /c /DGSSAPI=1 /Fo$@ $** + $(CC) $(CFLAGS) $(MITFLAGS) /c /DGSSAPI=1 /Fo$@ $** no_glue.obj: win_glue.c $(CC) $(CFLAGS) /c /Fo$@ $** diff --git a/src/lib/win_glue.c b/src/lib/win_glue.c index c9d4971bb..bd1eae642 100644 --- a/src/lib/win_glue.c +++ b/src/lib/win_glue.c @@ -79,10 +79,125 @@ #ifdef VERSERV #define WINDOWS +#include #include #include +/* + * This function will get the version resource information from the + * application using the DLL. This allows us to Version Serve + * arbitrary third party applications. If there is an error, or we + * decide that we should not version check the calling application + * then VSflag will be FALSE when the function returns. + */ + +void GetCallingAppVerInfo( char *AppTitle, char *AppVer, char *AppIni, + BOOL *VSflag) +{ + char CallerFilename[_MAX_PATH]; + LONG FAR *lpLangInfo; + DWORD hVersionInfoID, size; + GLOBALHANDLE hVersionInfo; + LPSTR lpVersionInfo; + int dumint, retval; + char *cp; + char *revAppTitle; + char szVerQ[90]; + LPBYTE locAppTitle; + LPBYTE locAppVer; + char locAppIni[_MAX_PATH]; +#ifndef _WIN32 + WORD wStackSeg; +#endif /* !_WIN32 */ + + /* first we need to get the calling module's filename */ +#ifndef _WIN32 + _asm { + mov wStackSeg, ss + }; + retval = GetModuleFileName((HMODULE)wStackSeg, CallerFilename, + _MAX_PATH); +#else + /* + * Note: this may only work for single threaded applications, + * we'll live and learn ... + */ + retval = GetModuleFileName( NULL, CallerFilename, _MAX_PATH); +#endif + + if ( retval == 0 ) { + VSflag = FALSE; + return; + } + + size = GetFileVersionInfoSize( CallerFilename, &hVersionInfoID); + + if( size == 0 ) { + /* + * hey , I bet we don't have a version resource, let's + * punt + */ +#if 0 + /* let's see what we have? (1813 means no resource) */ + size = GetLastError(); /* WIN32 only */ +#endif + *VSflag = FALSE; + return; + } + + hVersionInfo = GlobalAlloc(GHND, size); + lpVersionInfo = GlobalLock(hVersionInfo); + + retval = GetFileVersionInfo( CallerFilename, hVersionInfoID, size, + lpVersionInfo); + + retval = VerQueryValue(lpVersionInfo, "\\VarFileInfo\\Translation", + (LPSTR FAR *)&lpLangInfo, &dumint); + wsprintf(szVerQ, + "\\StringFileInfo\\%04x%04x\\", + LOWORD(*lpLangInfo), HIWORD(*lpLangInfo)); + + cp = szVerQ + lstrlen(szVerQ); + + lstrcpy(cp, "ProductName"); + + + /* try a localAppTitle and then a strcpy 4/2/97 */ + + retval = VerQueryValue(lpVersionInfo, szVerQ, &locAppTitle, + &dumint); + + lstrcpy(cp, "ProductVersion"); + + + retval = VerQueryValue(lpVersionInfo, szVerQ, &locAppVer, + &dumint); + + /* + * We don't have a way to determine that INI file of the + * application at the moment so let's just use krb5.ini + */ + strcpy( locAppIni, KERBEROS_INI ); + + strcpy( AppTitle, locAppTitle); + strcpy( AppVer, locAppVer); + strcpy( AppIni, locAppIni); + + /* + * We also need to determine if we want to suppress version + * checking of this application. Does the tail of the + * AppTitle end in a "-v" ? + */ + revAppTitle = _strrev( _strdup(AppTitle)); + if( revAppTitle[0] == 'v' || revAppTitle[0] == 'V' && + revAppTitle[1] == '-' ) { + VSflag = FALSE; + } + return; +} + + /* * Use the version server to give us some control on distribution and usage * We're going to test track as well @@ -98,8 +213,14 @@ static int CallVersionServer(app_title, app_version, app_ini, code_cover) SetCursor(LoadCursor(NULL, IDC_WAIT)); - vrequest = VSFormRequest(app_title, app_version, app_ini, - code_cover, NULL, V_CHECK_AND_LOG); + /* + * We should be able to pass in code_cover below, but things + * are breaking under Windows 16 for no good reason. + */ + vrequest = VSFormRequest((LPSTR) app_title, (LPSTR) app_version, + (LPSTR) app_ini, + NULL /* code_cover */, NULL, + V_CHECK_AND_LOG); SetCursor(LoadCursor(NULL, IDC_ARROW)); /* @@ -180,8 +301,24 @@ krb5_error_code krb5_vercheck() return retval; #endif #ifdef VERSERV +#if 0 + /* Check library ? */ if (CallVersionServer(APP_TITLE, APP_VER, APP_INI, NULL)) - return VERSERV_ERROR; + return KRB5_LIB_EXPIRED; +#endif + { + char AppTitle[256]; + char AppVer[256]; + char AppIni[256]; + BOOL VSflag=TRUE; + + GetCallingAppVerInfo( AppTitle, AppVer, AppIni, &VSflag); + + if (VSflag) { + if (CallVersionServer(AppTitle, AppVer, AppIni, NULL)) + return KRB5_APPL_EXPIRED; + } + } #endif return 0; } -- 2.26.2