You are viewing a plain text version of this content. The canonical link for it is here.
Posted to win32-msi-cvs@httpd.apache.org by wr...@apache.org on 2001/02/28 05:25:53 UTC

cvs commit: httpd-win32-msi/src real_features.c real_features.dsp real_features.mak

wrowe       01/02/27 20:25:53

  Modified:    src      real_features.c real_features.dsp real_features.mak
  Log:
    This rather nice little validation for potentially nasty characters
    or empty values of the ServerName, DomainName or AdminEmail fields
    successfully validates the data, but these problems remain:
  
    1. The corrected field doesn't display the new value (trimmed white
       space or truncated string at the invalid character.)  Until the
       user moves off and back onto the dialog they won't see the change.
  
    2. The error message is _not_ displayed.
  
  Revision  Changes    Path
  1.3       +128 -0    httpd-win32-msi/src/real_features.c
  
  Index: real_features.c
  ===================================================================
  RCS file: /home/cvs/httpd-win32-msi/src/real_features.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- real_features.c	2001/02/13 19:50:41	1.2
  +++ real_features.c	2001/02/28 04:25:53	1.3
  @@ -60,10 +60,32 @@
   #include <windows.h>
   #include <stdio.h>
   #include <tchar.h>
  +#include <ctype.h>
   #include "MsiQuery.h"
   
   #define MAXHOSTNAMELEN 255
   
  +static UINT warn_user(MSIHANDLE hInstall, UINT errcode, const char *szPass)
  +{
  +    /* Set up the Message string (with [n] entries, where [1] is the first
  +     * numeric error number.  The record entry 0 of NULL tells .msi to get
  +     * the error message from the error table.  The remaining arguments are
  +     * substituted by number, e.g. [2] is our szPass string.
  +     *
  +     * Only give the user the opportunity to click Ok, or Cancel the install.
  +     */
  +    MSIHANDLE hrec = MsiCreateRecord(3);
  +    int rv;
  +    MsiRecordSetString(hrec, 0, NULL);
  +    MsiRecordSetInteger(hrec, 1, errcode);
  +    MsiRecordSetString(hrec, 2, szPass);
  +    rv = MsiProcessMessage(hInstall, INSTALLMESSAGE_WARNING
  +                                   + MB_OKCANCEL, hrec);
  +    MsiCloseHandle(hrec);
  +    return rv == IDOK ? ERROR_SUCCESS : ERROR_INSTALL_USEREXIT;
  +}
  +
  +
   UINT __declspec(dllexport) __stdcall ResolveServerName(MSIHANDLE hInstall) 
   {
       char str[MAXHOSTNAMELEN + 7]; /* Allow for admin@ */
  @@ -127,5 +149,111 @@
       }
   
       WSACleanup();    
  +    return ERROR_SUCCESS;
  +}
  +
  +
  +/* Return the first unrecognized character and truncate the
  + * string after the last good character. 
  + */
  +static char test_bad_ch(char *str)
  +{
  +    while (*str) {
  +        if (!isprint(*str) || strchr("|*()[]:;<>?$%&#'`\"", *str)) {
  +            char ch = *str;
  +            *str = '\0';
  +            return ch;
  +        }
  +        ++str;
  +    }
  +    return 0;
  +}
  +
  +
  +char *trim_white_space(char *dstr, const char *str)
  +{
  +    char *pch = dstr;
  +    while (isspace(*str)) 
  +        ++str;
  +    while (*str) 
  +        *(pch++) = *(str++);
  +    while (pch >= dstr && isspace(*(--pch))) {
  +        ;
  +    }
  +    *(pch + 1) = '\0';        
  +    return dstr;
  +}
  +
  +
  +UINT __declspec(dllexport) __stdcall ValidateServerName(MSIHANDLE hInstall) 
  +{
  +    char dstr[MAXHOSTNAMELEN + 1];
  +    char str[MAXHOSTNAMELEN + 1];
  +    char ch[2] = "\0\0";
  +    char *pch;
  +    size_t len;
  +
  +    /* Validate that we resolved WinSock2
  +     */
  +    *str = '\0';  len = sizeof(str) - 1;
  +    MsiGetPropertyA(hInstall, "RESOLVED_WINSOCK2", str, &len);
  +    if (strcmp(str, "1")) {
  +        /* Nowhere interesting to go... just leave them in the top field 
  +         * and let them contemplate the warning message for a while till
  +         * they get a clue and Cancel the install.
  +         */
  +        MsiSetPropertyA(hInstall, "FIELDINVALID", "SERVERDOMAIN");
  +        return warn_user(hInstall, 20001, ch);
  +    }
  +
  +    /* Validate the Domain name is not blank & does not contain bad characters
  +     */
  +    *str = '\0';  len = sizeof(str) - 1;
  +    MsiGetPropertyA(hInstall, "SERVERDOMAIN", str, &len);
  +    ch[0] = test_bad_ch(pch = trim_white_space(dstr, str));
  +    if (strcmp(dstr, str))
  +        MsiSetPropertyA(hInstall, "SERVERDOMAIN", dstr);
  +    if (ch[0] || !strlen(dstr)) {
  +        if (ch[0] && !isprint(ch[0]))
  +            ch[0] = '?';
  +        MsiSetPropertyA(hInstall, "FIELDINVALID", "SERVERDOMAIN");
  +        return warn_user(hInstall, ch[0] ? 20012 : 20011, ch);
  +    }
  +
  +    /* Validate the Server name is not blank & does not contain bad characters
  +     */
  +    *str = '\0';  len = sizeof(str) - 1;
  +    MsiGetPropertyA(hInstall, "SERVERNAME",   str, &len);
  +    ch[0] = test_bad_ch(pch = trim_white_space(dstr, str));
  +    if (strcmp(dstr, str))
  +        MsiSetPropertyA(hInstall, "SERVERNAME", dstr);
  +    if (ch[0] || !strlen(dstr)) {
  +        if (ch[0] && !isprint(ch[0]))
  +            ch[0] = '?';
  +        MsiSetPropertyA(hInstall, "FIELDINVALID", "SERVERNAME");
  +        return warn_user(hInstall, ch[0] ? 20022 : 20021, ch);
  +    }
  +
  +    /* Validate the Email addr is not blank & does not contain bad characters
  +     */
  +    *str = '\0';  len = sizeof(str) - 1;
  +    MsiGetPropertyA(hInstall, "SERVERADMIN",  str, &len);
  +    ch[0] = test_bad_ch(pch = trim_white_space(dstr, str));
  +    if (strcmp(dstr, str))
  +        MsiSetPropertyA(hInstall, "SERVERADMIN", dstr);
  +    if (ch[0] || !strlen(dstr)) {
  +        if (ch[0] && !isprint(ch[0]))
  +            ch[0] = '?';
  +        MsiSetPropertyA(hInstall, "FIELDINVALID", "SERVERADMIN");
  +        return warn_user(hInstall, ch[0] ? 20032 : 20031, ch);
  +    }
  +    /* Validate the Email addr contains the appropriate '@' sign
  +     */
  +    if (!strchr(dstr, '@'))
  +        return warn_user(hInstall, 20033, ch);;
  +
  +    /* Reset to assure we can leave the Server Information panel
  +     */
  +    MsiSetPropertyA(hInstall, "FIELDINVALID", "");
       return ERROR_SUCCESS;
   }
  
  
  
  1.2       +2 -2      httpd-win32-msi/src/real_features.dsp
  
  Index: real_features.dsp
  ===================================================================
  RCS file: /home/cvs/httpd-win32-msi/src/real_features.dsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- real_features.dsp	2001/02/12 22:51:37	1.1
  +++ real_features.dsp	2001/02/28 04:25:53	1.2
  @@ -54,7 +54,7 @@
   # ADD BSC32 /nologo
   LINK32=link.exe
   # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
  -# ADD LINK32 kernel32.lib msi.lib user32.lib wsock32.lib /nologo /subsystem:windows /dll /machine:I386 /export:ResolveServerName
  +# ADD LINK32 kernel32.lib msi.lib user32.lib wsock32.lib /nologo /subsystem:windows /dll /machine:I386 /export:ResolveServerName /export:ValidateServerName
   # SUBTRACT LINK32 /pdb:none
   
   !ELSEIF  "$(CFG)" == "real_features - Win32 Debug"
  @@ -82,7 +82,7 @@
   # ADD BSC32 /nologo
   LINK32=link.exe
   # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
  -# ADD LINK32 kernel32.lib msi.lib user32.lib wsock32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept /export:ResolveServerName
  +# ADD LINK32 kernel32.lib msi.lib user32.lib wsock32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept /export:ResolveServerName /export:ValidateServerName
   # SUBTRACT LINK32 /pdb:none
   
   !ENDIF 
  
  
  
  1.2       +26 -58    httpd-win32-msi/src/real_features.mak
  
  Index: real_features.mak
  ===================================================================
  RCS file: /home/cvs/httpd-win32-msi/src/real_features.mak,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- real_features.mak	2001/02/12 22:51:37	1.1
  +++ real_features.mak	2001/02/28 04:25:53	1.2
  @@ -28,6 +28,10 @@
   NULL=nul
   !ENDIF 
   
  +CPP=cl.exe
  +MTL=midl.exe
  +RSC=rc.exe
  +
   !IF  "$(CFG)" == "real_features - Win32 Release"
   
   OUTDIR=.
  @@ -56,45 +60,11 @@
   "$(INTDIR)" :
       if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)"
   
  -CPP=cl.exe
   CPP_PROJ=/nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\
    /Fp"$(INTDIR)\real_features.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 
   CPP_OBJS=.\Release/
   CPP_SBRS=.
  -
  -.c{$(CPP_OBJS)}.obj::
  -   $(CPP) @<<
  -   $(CPP_PROJ) $< 
  -<<
  -
  -.cpp{$(CPP_OBJS)}.obj::
  -   $(CPP) @<<
  -   $(CPP_PROJ) $< 
  -<<
  -
  -.cxx{$(CPP_OBJS)}.obj::
  -   $(CPP) @<<
  -   $(CPP_PROJ) $< 
  -<<
  -
  -.c{$(CPP_SBRS)}.sbr::
  -   $(CPP) @<<
  -   $(CPP_PROJ) $< 
  -<<
  -
  -.cpp{$(CPP_SBRS)}.sbr::
  -   $(CPP) @<<
  -   $(CPP_PROJ) $< 
  -<<
  -
  -.cxx{$(CPP_SBRS)}.sbr::
  -   $(CPP) @<<
  -   $(CPP_PROJ) $< 
  -<<
  -
  -MTL=midl.exe
   MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 
  -RSC=rc.exe
   BSC32=bscmake.exe
   BSC32_FLAGS=/nologo /o"$(OUTDIR)\real_features.bsc" 
   BSC32_SBRS= \
  @@ -103,7 +73,8 @@
   LINK32_FLAGS=kernel32.lib msi.lib user32.lib wsock32.lib /nologo\
    /subsystem:windows /dll /incremental:no /pdb:"$(OUTDIR)\real_features.pdb"\
    /machine:I386 /out:"$(OUTDIR)\real_features.dll"\
  - /implib:"$(OUTDIR)\real_features.lib" /export:ResolveServerName 
  + /implib:"$(OUTDIR)\real_features.lib" /export:ResolveServerName\
  + /export:ValidateServerName 
   LINK32_OBJS= \
   	"$(INTDIR)\real_features.obj"
   
  @@ -143,11 +114,30 @@
   "$(INTDIR)" :
       if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)"
   
  -CPP=cl.exe
   CPP_PROJ=/nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS"\
    /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 
   CPP_OBJS=.\Debug/
   CPP_SBRS=.
  +MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 
  +BSC32=bscmake.exe
  +BSC32_FLAGS=/nologo /o"$(OUTDIR)\real_features.bsc" 
  +BSC32_SBRS= \
  +	
  +LINK32=link.exe
  +LINK32_FLAGS=kernel32.lib msi.lib user32.lib wsock32.lib /nologo\
  + /subsystem:windows /dll /incremental:yes /pdb:"$(OUTDIR)\real_features.pdb"\
  + /debug /machine:I386 /out:"$(OUTDIR)\real_features.dll"\
  + /implib:"$(OUTDIR)\real_features.lib" /pdbtype:sept /export:ResolveServerName\
  + /export:ValidateServerName 
  +LINK32_OBJS= \
  +	"$(INTDIR)\real_features.obj"
  +
  +"$(OUTDIR)\real_features.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
  +    $(LINK32) @<<
  +  $(LINK32_FLAGS) $(LINK32_OBJS)
  +<<
  +
  +!ENDIF 
   
   .c{$(CPP_OBJS)}.obj::
      $(CPP) @<<
  @@ -178,28 +168,6 @@
      $(CPP) @<<
      $(CPP_PROJ) $< 
   <<
  -
  -MTL=midl.exe
  -MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 
  -RSC=rc.exe
  -BSC32=bscmake.exe
  -BSC32_FLAGS=/nologo /o"$(OUTDIR)\real_features.bsc" 
  -BSC32_SBRS= \
  -	
  -LINK32=link.exe
  -LINK32_FLAGS=kernel32.lib msi.lib user32.lib wsock32.lib /nologo\
  - /subsystem:windows /dll /incremental:yes /pdb:"$(OUTDIR)\real_features.pdb"\
  - /debug /machine:I386 /out:"$(OUTDIR)\real_features.dll"\
  - /implib:"$(OUTDIR)\real_features.lib" /pdbtype:sept /export:ResolveServerName 
  -LINK32_OBJS= \
  -	"$(INTDIR)\real_features.obj"
  -
  -"$(OUTDIR)\real_features.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
  -    $(LINK32) @<<
  -  $(LINK32_FLAGS) $(LINK32_OBJS)
  -<<
  -
  -!ENDIF 
   
   
   !IF "$(CFG)" == "real_features - Win32 Release" || "$(CFG)" ==\