[5283] | 1 | /* $Id: clfix.c,v 1.3 2001-03-02 12:48:41 bird Exp $
|
---|
[4292] | 2 | *
|
---|
| 3 | * A wrapper program for cl.exe fix will try fix some of the problems
|
---|
| 4 | * we have seen.
|
---|
| 5 | *
|
---|
| 6 | * syntax: clfix.exe <cl> [cl arguments]
|
---|
| 7 | *
|
---|
| 8 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 9 | *
|
---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 11 | *
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | /*******************************************************************************
|
---|
| 15 | * Defined Constants And Macros *
|
---|
| 16 | *******************************************************************************/
|
---|
| 17 | #define INCL_BASE
|
---|
| 18 |
|
---|
| 19 | /*******************************************************************************
|
---|
| 20 | * Header Files *
|
---|
| 21 | *******************************************************************************/
|
---|
| 22 | #include <os2.h>
|
---|
| 23 | #include <string.h>
|
---|
[4580] | 24 | #include <stdio.h>
|
---|
[4292] | 25 |
|
---|
| 26 |
|
---|
| 27 | int main(int argc, char **argv)
|
---|
| 28 | {
|
---|
| 29 | static char szArgBuffer[32768];
|
---|
[5283] | 30 | static char szzEnv[4096];
|
---|
| 31 | char * pszEnv = &szzEnv[0];
|
---|
[4292] | 32 | RESULTCODES resc;
|
---|
| 33 | int argi;
|
---|
| 34 | char * psz;
|
---|
[4580] | 35 | HFILE hFile;
|
---|
| 36 | APIRET rc;
|
---|
[4292] | 37 |
|
---|
[5283] | 38 |
|
---|
[4292] | 39 | /*
|
---|
| 40 | * Check that we have cl.exe at least passed in.
|
---|
| 41 | */
|
---|
| 42 | if (argc < 2)
|
---|
| 43 | {
|
---|
| 44 | PSZ psz =
|
---|
| 45 | "A wrapper program for cl.exe fix will try fix some of the problems\r\n"
|
---|
| 46 | "we have seen.\r\n"
|
---|
| 47 | "\r\n"
|
---|
| 48 | " syntax: clfix.exe <drive:fullpath\\cl.exe> [cl arguments]\r\n";
|
---|
| 49 | ULONG cch = strlen(psz);
|
---|
| 50 | DosWrite(0, psz, cch, &cch);
|
---|
| 51 | return -1;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[5283] | 54 | /*
|
---|
| 55 | * Blow away extra libpaths.
|
---|
| 56 | */
|
---|
| 57 | DosSetExtLIBPATH("", BEGIN_LIBPATH);
|
---|
| 58 | DosSetExtLIBPATH("", END_LIBPATH);
|
---|
[4292] | 59 |
|
---|
[5283] | 60 |
|
---|
[4292] | 61 | /*
|
---|
| 62 | * First argument
|
---|
| 63 | */
|
---|
| 64 | psz = strcpy(szArgBuffer, argv[1]);
|
---|
| 65 | psz += strlen(psz);
|
---|
| 66 | psz++;
|
---|
| 67 |
|
---|
| 68 |
|
---|
[5283] | 69 | /*
|
---|
| 70 | * The other arguments.
|
---|
| 71 | * The -I arguments are put into the environment variable INCLUDE.
|
---|
| 72 | */
|
---|
| 73 | strcpy(pszEnv, "INCLUDE=");
|
---|
| 74 | pszEnv += strlen(pszEnv);
|
---|
[4292] | 75 | if (argc > 2)
|
---|
| 76 | {
|
---|
| 77 | argi = 2;
|
---|
| 78 | while (argi < argc)
|
---|
| 79 | {
|
---|
[5283] | 80 | if ( (argv[argi][0] == '-' || argv[argi][0] == '/')
|
---|
| 81 | && (argv[argi][1] == 'I' || argv[argi][1] == 'i'))
|
---|
| 82 | {
|
---|
| 83 | strcpy(pszEnv, &argv[argi][2]);
|
---|
| 84 | pszEnv += strlen(pszEnv);
|
---|
| 85 | *pszEnv++ = ';';
|
---|
| 86 | argi++;
|
---|
| 87 | }
|
---|
| 88 | else
|
---|
| 89 | {
|
---|
| 90 | strcpy(psz, argv[argi]);
|
---|
| 91 | psz += strlen(psz);
|
---|
| 92 | *psz++ = ' ';
|
---|
| 93 | argi++;
|
---|
| 94 | }
|
---|
[4292] | 95 | }
|
---|
| 96 | psz[-1] = '\0';
|
---|
| 97 | }
|
---|
| 98 | *psz = '\0';
|
---|
| 99 |
|
---|
[5283] | 100 | printf("exe: %s\n", szArgBuffer);
|
---|
| 101 | printf("arg: %s\n", szArgBuffer + strlen(szArgBuffer)+1);
|
---|
| 102 | printf("env: %s\n", szzEnv);
|
---|
[4292] | 103 |
|
---|
| 104 | /*
|
---|
[4580] | 105 | * Set max filehandles
|
---|
| 106 | * ú Is this inherited?
|
---|
| 107 | * - Probably not. So we'll have exploit handle inheritance
|
---|
| 108 | * to fix this.
|
---|
[4292] | 109 | */
|
---|
| 110 | DosSetMaxFH(100);
|
---|
| 111 |
|
---|
[4580] | 112 | /*
|
---|
| 113 | * Let us open a high handle number which makes the
|
---|
| 114 | * child process to inherit the maximum number of open files.
|
---|
| 115 | */
|
---|
| 116 | hFile = 99; /* suggest handle number. */
|
---|
| 117 | rc = DosDupHandle(1, &hFile);
|
---|
| 118 | if (rc)
|
---|
| 119 | printf("clfix: DosDupHandle failed with rc=%d\n\n", rc);
|
---|
[5283] | 120 |
|
---|
[4292] | 121 |
|
---|
| 122 | /*
|
---|
| 123 | * Execute argument without any environment.
|
---|
| 124 | * Some of the internal errors which has occured might be caused by long variables or
|
---|
| 125 | * generally a big environment block. We'll send in an empty environment block and hope
|
---|
| 126 | * this will solve the problems.
|
---|
| 127 | */
|
---|
[5283] | 128 | if (DosExecPgm(NULL, 0, EXEC_SYNC, szArgBuffer, &szzEnv[0], &resc, szArgBuffer) != NO_ERROR)
|
---|
[4292] | 129 | {
|
---|
| 130 | /*complain*/
|
---|
| 131 | return -1;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | /*
|
---|
| 136 | * return result code from cl.exe.
|
---|
| 137 | */
|
---|
| 138 | return resc.codeResult;
|
---|
| 139 | }
|
---|
| 140 |
|
---|