httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TOKI...@aol.com
Subject WIN32 CGI - USC CODE - 3 OF 4
Date Mon, 25 Jan 1999 17:36:59 GMT

WIN32 PROBLEM: EXECUTABLE AND CGI 'SCRIPT' HANDLING LOGIC

RELATES TO: Some currently open Apache WIN32 CGI PR REPORTS

A good example of a possible BETTER way to look at/for
WIN32 executables 'on-the-fly'...

More detailed ( and flexible ) than current Apache code.

Comes from:

Expect 5 for Tcl 8.0 and Tk 8.0 project at

USC ( Berkman!... Berkmeister!... Berk-o-rama!... the Berk. )

http://bmrc.berkely.edu/ftp/pub/winnt/tcltk/expect/expect-patch-snap13tosnap14

Reachable via any search engine using keyword IMAGE_DOS_HEADER.

Excerpt from source file: diff -u expect-5.21/CHANGES.NT

-static DWORD
-ExpApplicationType(originalName, fullPath)
-    const TCHAR *originalName;	/* Name of the application to find. */
-    TCHAR fullPath[MAX_PATH];	/* Filled with complete path to 
-				 * application. */
-{
-    DWORD applType;
-    int i;
-    HANDLE hFile;
-    PTCHAR ext;
-    TCHAR buf[2];
-    DWORD read;
-    IMAGE_DOS_HEADER header;
-    static TCHAR extensions[][5] = {TEXT(""), TEXT(".com"), TEXT(".exe"),
-				    TEXT(".bat"), TEXT(".cmd")};
-
-    /* Look for the program as an external program.  First try the name
-     * as it is, then try adding .com, .exe, and .bat, in that order, to
-     * the name, looking for an executable.
-     *
-     * Using the raw SearchPath() procedure doesn't do quite what is 
-     * necessary.  If the name of the executable already contains a '.' 
-     * character, it will not try appending the specified extension when
-     * searching (in other words, SearchPath will not find the program 
-     * "a.b.exe" if the arguments specified "a.b" and ".exe").   
-     * So, first look for the file as it is named.  Then manually append 
-     * the extensions, looking for a match.  
-     */
-
-    applType = EXP_APPL_NONE;
-    for (i = 0; i < (int) (sizeof(extensions) / sizeof(extensions[0])); i++)
{
-	lstrcpyn(fullPath, originalName, MAX_PATH - 5);
-        lstrcat(fullPath, extensions[i]);
-	
-	{
-	    DWORD x;
-	    WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), fullPath,
-		lstrlen(fullPath), &x, NULL);
-	    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), TEXT("\n"), 1, &x,NULL);
-	}
-	if (SearchPath(NULL, fullPath, NULL, MAX_PATH, fullPath, NULL) == 0) {
-	    continue;
-	}
-
-	/*
-	 * Ignore matches on directories or data files, return if identified
-	 * a known type.
-	 */
-
-	if (GetFileAttributes(fullPath) & FILE_ATTRIBUTE_DIRECTORY) {
-	    continue;
-	}
-
-	ext = lstrrchr(fullPath, '.');
-	if ((ext != NULL) && (lstrcmpi(ext, TEXT(".bat")) == 0)) {
-	    applType = EXP_APPL_DOS;
-	    break;
-	}
-
-	hFile = CreateFile(fullPath, GENERIC_READ, FILE_SHARE_READ, NULL, 
-		OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-	if (hFile == INVALID_HANDLE_VALUE) {
-	    continue;
-	}
-
-	header.e_magic = 0;
-	ReadFile(hFile, (void *) &header, sizeof(header), &read, NULL);
-	if (header.e_magic != IMAGE_DOS_SIGNATURE) {
-	    /* 
-	     * Doesn't have the magic number for relocatable executables.  If 
-	     * filename ends with .com, assume it's a DOS application anyhow.
-	     * Note that we didn't make this assumption at first, because some
-	     * supposed .com files are really 32-bit executables with all the
-	     * magic numbers and everything.  
-	     */
-
-	    CloseHandle(hFile);
-	    if ((ext != NULL) && (lstrcmpi(ext, TEXT(".com")) == 0)) {
-		applType = EXP_APPL_DOS;
-		break;
-	    }
-	    continue;
-	}
-	if (header.e_lfarlc != sizeof(header)) {
-	    /* 
-	     * All Windows 3.X and Win32 and some DOS programs have this value
-	     * set here.  If it doesn't, assume that since it already had the 
-	     * other magic number it was a DOS application.
-	     */
-
-	    CloseHandle(hFile);
-	    applType = EXP_APPL_DOS;
-	    break;
-	}
-
-	/* 
-	 * The DWORD at header.e_lfanew points to yet another magic number.
-	 */
-
-	buf[0] = '\0';
-	SetFilePointer(hFile, header.e_lfanew, NULL, FILE_BEGIN);
-	ReadFile(hFile, (void *) buf, 2, &read, NULL);
-	CloseHandle(hFile);
-
-	if ((buf[0] == 'L') && (buf[1] == 'E')) {
-	    applType = EXP_APPL_DOS;
-	} else if ((buf[0] == 'N') && (buf[1] == 'E')) {
-	    applType = EXP_APPL_WIN3X;
-	} else if ((buf[0] == 'P') && (buf[1] == 'E')) {
-	    applType = EXP_APPL_WIN32;
-	} else {
-	    continue;
-	}
-	break;
-    }
-
-    if (applType == EXP_APPL_NONE) {
-	return EXP_APPL_NONE;
-    }
-
-    if ((applType == EXP_APPL_DOS) || (applType == EXP_APPL_WIN3X)) {
-	/* 
-	 * Replace long path name of executable with short path name for 
-	 * 16-bit applications.  Otherwise the application may not be able
-	 * to correctly parse its own command line to separate off the 
-	 * application name from the arguments.
-	 */
-
-	GetShortPathName(fullPath, fullPath, MAX_PATH);
-    }
-    return applType;
-}
-#endif /* XXX */
-    

Mime
View raw message