Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

314 lines
8.3 KiB

  1. /* cmd.h - main include file for command.lib
  2. *
  3. * Modification History
  4. *
  5. * Sudeepb 17-Sep-1991 Created
  6. */
  7. /*
  8. #define WIN
  9. #define FLAT_32
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #define _WINDOWS
  14. #include <windows.h>
  15. */
  16. #ifdef DOS
  17. #define SIGNALS
  18. #endif
  19. #ifdef OS2_16
  20. #define OS2
  21. #define SIGNALS
  22. #endif
  23. #ifdef OS2_32
  24. #define OS2
  25. #define FLAT_32
  26. #endif
  27. #include <stdarg.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <malloc.h>
  32. #include <process.h>
  33. #ifdef WIN_16
  34. #define WIN
  35. #define API16
  36. #endif
  37. #ifdef WIN_32
  38. #define WIN
  39. #define FLAT_32
  40. #define TRUE_IF_WIN32 1
  41. #include <nt.h>
  42. #include <ntrtl.h>
  43. #include <nturtl.h>
  44. #else
  45. #define TRUE_IF_WIN32 0
  46. #endif
  47. #ifdef FLAT_32
  48. #ifndef i386
  49. #define ALIGN_32
  50. #else
  51. #define NOALIGN_32
  52. #endif
  53. #endif
  54. #ifdef WIN
  55. #define _WINDOWS
  56. #include <windows.h>
  57. #endif
  58. #ifdef SIGNALS
  59. #include <conio.h>
  60. #include <signal.h>
  61. #endif
  62. #ifdef OS2_32
  63. #include <excpt.h>
  64. #define XCPT_SIGNAL 0xC0010003
  65. #endif
  66. #include <vdmapi.h>
  67. #include "dpmtbls.h"
  68. #define COPY_STD_OUT 1
  69. #define COPY_STD_ERR 2
  70. #define CLOSE_ALL_HANDLES 1
  71. #define CLOSE_STD_OUT 2
  72. #define CLOSE_STD_ERR 4
  73. #define DEFAULT_REDIRECTION_SIZE 1024
  74. #define MAX_SHORTCUT_SIZE 128
  75. #define STDIN_BUF_SIZE 512
  76. /** Command Macros **/
  77. /** Command Basic Typedefs **/
  78. typedef VOID (*PFNSVC)(VOID);
  79. #pragma pack(1)
  80. typedef struct _PARAMBLOCK {
  81. USHORT SegEnv;
  82. USHORT OffCmdTail;
  83. USHORT SegCmdTail;
  84. ULONG pFCB1;
  85. ULONG pFCB2;
  86. } PARAMBLOCK,*PPARAMBLOCK;
  87. typedef struct _SCSINFO {
  88. CHAR SCS_ComSpec [64];
  89. CHAR SCS_CmdTail [128];
  90. PARAMBLOCK SCS_ParamBlock;
  91. CHAR SCS_ToSync;
  92. } SCSINFO, *PSCSINFO;
  93. typedef struct _STD_HANDLES {
  94. ULONG hStdErr;
  95. ULONG hStdOut;
  96. ULONG hStdIn;
  97. } STD_HANDLES, *PSTD_HANDLES;
  98. #define PIPE_INPUT_BUFFER_SIZE 512
  99. #define PIPE_OUTPUT_BUFFER_SIZE PIPE_INPUT_BUFFER_SIZE
  100. #define PIPE_INPUT_TIMEOUT 55
  101. #define PIPE_OUTPUT_TIMEOUT PIPE_INPUT_TIMEOUT
  102. typedef struct _PIPE_INPUT{
  103. struct _PIPE_INPUT *Next;
  104. HANDLE hFileRead;
  105. HANDLE hFileWrite;
  106. HANDLE hPipe;
  107. HANDLE hDataEvent;
  108. HANDLE hThread;
  109. CHAR *pFileName;
  110. DWORD BufferSize;
  111. BOOL fEOF;
  112. BOOL WaitData;
  113. BYTE *Buffer;
  114. CRITICAL_SECTION CriticalSection;
  115. } PIPE_INPUT, *PPIPE_INPUT;
  116. typedef struct _PIPE_OUTPUT {
  117. HANDLE hFile;
  118. HANDLE hPipe;
  119. HANDLE hExitEvent;
  120. CHAR *pFileName;
  121. DWORD BufferSize;
  122. BYTE *Buffer;
  123. } PIPE_OUTPUT, *PPIPE_OUTPUT;
  124. typedef struct _RedirComplete_Info {
  125. HANDLE ri_hStdErr;
  126. HANDLE ri_hStdOut;
  127. HANDLE ri_hStdIn;
  128. HANDLE ri_hStdErrFile;
  129. HANDLE ri_hStdOutFile;
  130. HANDLE ri_hStdInFile;
  131. HANDLE ri_hStdOutThread;
  132. HANDLE ri_hStdErrThread;
  133. PPIPE_INPUT ri_pPipeStdIn;
  134. PPIPE_OUTPUT ri_pPipeStdOut;
  135. PPIPE_OUTPUT ri_pPipeStdErr;
  136. } REDIRCOMPLETE_INFO, *PREDIRCOMPLETE_INFO;
  137. typedef struct _VDMENVBLK {
  138. DWORD cchEnv;
  139. DWORD cchRemain;
  140. CHAR *lpszzEnv;
  141. } VDMENVBLK, *PVDMENVBLK;
  142. #pragma pack()
  143. /** Command Function Prototypes */
  144. VOID cmdComSpec (VOID);
  145. VOID cmdGetEnv (VOID);
  146. VOID cmdGetNextCmd (VOID);
  147. VOID cmdGetNextCmdForSeparateWow (VOID);
  148. VOID cmdGetStdHandle (VOID);
  149. VOID cmdExec (VOID);
  150. VOID cmdExecComspec32 (VOID);
  151. VOID cmdExitVDM (VOID);
  152. VOID cmdReturnExitCode (VOID);
  153. VOID cmdSaveWorld (VOID);
  154. VOID cmdSetInfo (VOID);
  155. VOID cmdGetCurrentDir (VOID);
  156. VOID cmdSetDirectories (PCHAR,VDMINFO *);
  157. VOID CheckDotExeForWOW (LPSTR);
  158. BOOL cmdCheckCopyForRedirection (PREDIRCOMPLETE_INFO, BOOL);
  159. BOOL cmdCreateTempFile (PHANDLE,PCHAR *);
  160. VOID cmdCheckBinary (VOID);
  161. VOID cmdInitConsole (VOID);
  162. VOID nt_init_event_thread (VOID);
  163. VOID cmdExec32 (PCHAR,PCHAR);
  164. VOID cmdCreateProcess (PSTD_HANDLES pStdHandles);
  165. USHORT cmdMapCodePage (ULONG);
  166. VOID cmdCheckForPIF (PVDMINFO);
  167. VOID cmdGetConfigSys (VOID);
  168. VOID cmdGetAutoexecBat (VOID);
  169. VOID DeleteConfigFiles (VOID);
  170. VOID cmdGetKbdLayout (VOID);
  171. BOOL cmdXformEnvironment (PCHAR, PANSI_STRING);
  172. VOID cmdGetInitEnvironment (VOID);
  173. VOID cmdUpdateCurrentDirectories (BYTE);
  174. BOOL cmdCreateVDMEnvironment (PVDMENVBLK);
  175. DWORD cmdGetEnvironmentVariable (PVDMENVBLK, PCHAR, PCHAR, DWORD);
  176. BOOL cmdSetEnvironmentVariable (PVDMENVBLK, PCHAR, PCHAR);
  177. DWORD cmdExpandEnvironmentStrings (PVDMENVBLK, PCHAR, PCHAR, DWORD);
  178. PREDIRCOMPLETE_INFO cmdCheckStandardHandles (PVDMINFO,USHORT UNALIGNED *);
  179. VOID cmdGetStartInfo (VOID);
  180. BOOL cmdHandleStdinWithPipe (PREDIRCOMPLETE_INFO);
  181. BOOL cmdHandleStdOutErrWithPipe (PREDIRCOMPLETE_INFO, USHORT);
  182. LPSTR cmdSkipOverPathName (LPSTR);
  183. BOOL cmdPipeFileDataEOF (HANDLE, BOOL *);
  184. BOOL cmdPipeFileEOF (HANDLE);
  185. VOID cmdPipeInThread (LPVOID);
  186. VOID cmdPipeOutThread (LPVOID);
  187. VOID cmdSetWinTitle (VOID);
  188. BOOL cmdIllegalFunc(VOID);
  189. VOID cmdGetCursorPos(VOID);
  190. /** Command Externs **/
  191. extern USHORT nDrives;
  192. extern BOOL IsFirstVDMInSystem;
  193. extern BOOL VDMForWOW;
  194. extern CHAR lpszComSpec[];
  195. extern USHORT cbComSpec;
  196. extern BOOL IsFirstCall;
  197. extern BOOL IsRepeatCall;
  198. extern BOOL IsFirstWOWCheckBinary;
  199. extern BOOL IsFirstVDMInSystem;
  200. extern BOOL SaveWorldCreated;
  201. extern PCHAR pSCS_ToSync;
  202. extern BOOL fBlock;
  203. extern PCHAR pCommand32;
  204. extern PCHAR pEnv32;
  205. extern DWORD dwExitCode32;
  206. extern PSCSINFO pSCSInfo;
  207. extern HANDLE hFileStdOut;
  208. extern HANDLE hFileStdOutDup;
  209. extern HANDLE hFileStdErr;
  210. extern HANDLE hFileStdErrDup;
  211. extern VDMINFO VDMInfo;
  212. extern PSZ pszFileStdOut;
  213. extern PSZ pszFileStdErr;
  214. extern CHAR cmdHomeDirectory[];
  215. extern HANDLE SCS_hStdIn;
  216. extern HANDLE SCS_hStdOut;
  217. extern HANDLE SCS_hStdErr;
  218. extern CHAR chDefaultDrive;
  219. extern BOOL DontCheckDosBinaryType;
  220. extern WORD Exe32ActiveCount;
  221. extern BOOL fSoftpcRedirection;
  222. extern BOOL fSoftpcRedirectionOnShellOut;
  223. extern VOID nt_std_handle_notification (BOOL);
  224. extern VOID cmdPushExitInConsoleBuffer (VOID);
  225. // control handler state, defined in nt_event.h, nt_event.c
  226. extern ULONG CntrlHandlerState;
  227. #define CNTRL_SHELLCOUNT 0x0FFFF // The LOWORD is used for shell count
  228. #define CNTRL_PIFALLOWCLOSE 0x10000
  229. #define CNTRL_VDMBLOCKED 0x20000
  230. #define CNTRL_SYSTEMROOTCONSOLE 0x40000
  231. #define CNTRL_PUSHEXIT 0x80000
  232. // Temporary variable till we standardized on wowexec
  233. extern ULONG iWOWTaskId;
  234. extern CHAR comspec[];
  235. extern CHAR ShortCutInfo[];
  236. extern VOID nt_pif_callout (LPVOID);
  237. extern CHAR *lpszzInitEnvironment;
  238. extern WORD cchInitEnvironment;
  239. extern CHAR *lpszzCurrentDirectories;
  240. extern DWORD cchCurrentDirectories;
  241. extern BYTE * pIsDosBinary;
  242. extern WORD * pFDAccess;
  243. extern CHAR *lpszzcmdEnv16;
  244. extern BOOL DosEnvCreated;
  245. extern BOOL IsFirstVDM;
  246. extern VDMENVBLK cmdVDMEnvBlk;
  247. extern CHAR *lpszzVDMEnv32;
  248. extern DWORD cchVDMEnv32;
  249. extern UINT VdmExitCode;
  250. extern DWORD dwDosCompatFlags;
  251. extern PCMDLNPARMS pCmdLnParms;
  252. extern int cCmdLnParmStructs;
  253. extern PFAMILY_TABLE *pgDpmDosFamTbls;
  254. // application path name extention type.
  255. #define EXTENTION_STRING_LEN 4
  256. #define BAT_EXTENTION_STRING ".BAT"
  257. #define EXE_EXTENTION_STRING ".EXE"
  258. #define COM_EXTENTION_STRING ".COM"
  259. #ifdef DBCS // MUST fix for FE NT
  260. #define FIX_375051_NOW
  261. #endif
  262. #ifdef FIX_375051_NOW
  263. #define WOW32_strupr(psz) CharUpperA(psz)
  264. #else
  265. #define WOW32_strupr(psz) _strupr(psz)
  266. #endif