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.

396 lines
12 KiB

  1. #include "convlog.h"
  2. #include "inetcom.h"
  3. #include "logtype.h"
  4. #include <winnlsp.h>
  5. //
  6. // Current output file
  7. //
  8. OUTFILESTATUS WebOutFile = {0};
  9. OUTFILESTATUS NoConvertOutFile = {0};
  10. //
  11. // Used for find first
  12. //
  13. WIN32_FIND_DATA FindData = {0};
  14. //
  15. // struct for holding command line args
  16. //
  17. BOOL DoDNSConversion = FALSE;
  18. BOOL SaveFTPEntries = FALSE;
  19. BOOL NoFormatConversion = FALSE;
  20. CHAR FTPSaveFile[MAX_PATH+1] = {0};
  21. CHAR NCSAGMTOffset[MAX_PATH+1] = {0};
  22. DWORD LogFileFormat = LOGFILE_INVALID;
  23. CHAR InputFileName[MAX_PATH+1] = {0};
  24. CHAR OutputDir[MAX_PATH+1] = {0};
  25. CHAR TempDir[MAX_PATH+1] = {0};
  26. DWORD nWebLineCount = 0;
  27. DATEFORMAT dwDateFormat = DateFormatUsa;
  28. BOOL bOnErrorContinue = FALSE;
  29. //
  30. // struct that holds log line items
  31. //
  32. INLOGLINE InLogLine = {0};
  33. int
  34. __cdecl
  35. main(
  36. int argc,
  37. char *argv[]
  38. )
  39. {
  40. FILE *fpInFile; //log File to open
  41. HANDLE hFile; //Handle for FindFirstFile
  42. //
  43. // Buffer to hold log line
  44. //
  45. CHAR szInBuf[MAX_LOG_RECORD_LEN+1];
  46. //
  47. // File mask to search for
  48. //
  49. CHAR szFileMask[MAX_PATH+1];
  50. CHAR szInfileName[MAX_PATH+1];
  51. CHAR szWorkingDir[MAX_PATH+1];
  52. int nTotalWebCount = 0;
  53. BOOL bWebFound = FALSE; //did we find a web line?
  54. BOOL bNoConvertFound = FALSE; //did we find any NoConvert lines?
  55. BOOL bRet; //used for testing returns
  56. DWORD dwErr; //used to hold error codes
  57. int nLineCount = 0; //number of lines read from input file
  58. int nTotalCount = 0;
  59. //int nCount = 0; Bug # 101690
  60. CHAR *pCh;
  61. DWORD dwFieldMask;
  62. BOOL fGetHeader;
  63. DWORD nLinesDumped = 0;
  64. DWORD dwGetLogLineResult;
  65. BOOL bContinue;
  66. DWORD dwCurrentLine;
  67. //
  68. // initialize data structure
  69. //
  70. setlocale(LC_ALL, ".ACP" );
  71. SetThreadUILanguage(0);
  72. WebOutFile.fpOutFile = NULL;
  73. NoConvertOutFile.fpOutFile = NULL;
  74. ZeroMemory(szInBuf, sizeof(szInBuf));
  75. strcpy(OutputDir, ".\\");
  76. switch ( ParseArgs(argc, argv) ) {
  77. case ILLEGAL_COMMAND_LINE:
  78. Usage(argv[0]);
  79. return 0;
  80. case OUT_DIR_NOT_OK:
  81. printfids(IDS_BAD_DIR, OutputDir);
  82. return 0;
  83. case ERROR_BAD_NONE:
  84. printfids(IDS_BAD_NONE_ERR);
  85. return 0;
  86. case COMMAND_LINE_OK:
  87. break;
  88. }
  89. if ( DoDNSConversion ) {
  90. INT serr;
  91. WSADATA wsaData;
  92. if (serr = WSAStartup(MAKEWORD(2,0), &wsaData) != 0) {
  93. printfids(IDS_WINSOCK_ERR, serr);
  94. DoDNSConversion = FALSE;
  95. }
  96. }
  97. if ( (LogFileFormat == LOGFILE_NCSA) && !DoDNSConversion ) {
  98. printfids(IDS_NO_CONVERSION_NEEDED);
  99. return(0);
  100. }
  101. if ( !InitDateStrings() ) {
  102. printfids(IDS_BAD_DATESTRINGS);
  103. }
  104. if (DoDNSConversion) {
  105. InitHashTable(2000);
  106. AddLocalMachineToCache( );
  107. }
  108. strcpy (szWorkingDir, InputFileName);
  109. // Bug # 101690
  110. //
  111. // for (nCount = strlen(szWorkingDir) -1; nCount >= 0; nCount--) {
  112. //
  113. // if ('\\' == szWorkingDir[nCount]) {
  114. // szWorkingDir[nCount+1] = '\0';
  115. // break;
  116. // }
  117. //
  118. // }
  119. // if (nCount < 0) {
  120. // strcpy (szWorkingDir, ".\\");
  121. // }
  122. //
  123. pCh = _mbsrchr(szWorkingDir, '\\');
  124. if (pCh != NULL) {
  125. *(pCh+1) = '\0';
  126. } else {
  127. strcpy (szWorkingDir, ".\\");
  128. }
  129. strcpy(szFileMask, InputFileName);
  130. hFile = FindFirstFile (szFileMask, &FindData);
  131. if (INVALID_HANDLE_VALUE == hFile) {
  132. printfids(IDS_FILE_NONE, szFileMask);
  133. return(0);
  134. }
  135. do {
  136. if (!(FILE_ATTRIBUTE_DIRECTORY & FindData.dwFileAttributes)) {
  137. strcpy(szInfileName, szWorkingDir);
  138. strcat(szInfileName, FindData.cFileName);
  139. fpInFile = fopen(szInfileName, "r");
  140. printfids(IDS_FILE_OPEN, FindData.cFileName);
  141. nLineCount = 0;
  142. dwCurrentLine = 0;
  143. {
  144. //
  145. // Do file conversion
  146. //
  147. strcpy (WebOutFile.szLastDate, NEW_DATETIME);
  148. strcpy (WebOutFile.szLastTime, NEW_DATETIME);
  149. bWebFound = FALSE;
  150. nWebLineCount = 0;
  151. nLinesDumped = 0;
  152. ExtendedFieldsDefined = FALSE;
  153. szGlobalDate[0] = '\0';
  154. }
  155. fGetHeader = TRUE;
  156. bContinue = TRUE;
  157. while ((bContinue) && (!feof(fpInFile)))
  158. {
  159. dwCurrentLine++;
  160. dwGetLogLineResult = GetLogLine( fpInFile, szInBuf, sizeof(szInBuf), &InLogLine);
  161. if (dwGetLogLineResult == GETLOG_SUCCESS)
  162. {
  163. nLineCount++;
  164. if (DoDNSConversion) {
  165. //
  166. //Getting machine names could take days, so put out status messages
  167. //
  168. switch (nLineCount) {
  169. case 25:
  170. case 50:
  171. case 100:
  172. case 250:
  173. case 500:
  174. printfids(IDS_LINES_PROC, FindData.cFileName, nLineCount);
  175. break;
  176. default:
  177. if ((nLineCount % 1000) == 0)
  178. printfids(IDS_LINES_PROC, FindData.cFileName, nLineCount);
  179. } //end switch
  180. }
  181. //
  182. // if NCSA and just DoDNS, do no convert
  183. //
  184. if ( NoFormatConversion ||
  185. (_strnicmp(
  186. InLogLine.szService,
  187. "W3SVC",
  188. strlen("W3SVC")) != 0) ) {
  189. if ( NoFormatConversion || SaveFTPEntries ) {
  190. ProcessNoConvertLine(
  191. &InLogLine,
  192. FindData.cFileName,
  193. szInBuf,
  194. &NoConvertOutFile,
  195. &bNoConvertFound);
  196. } else {
  197. nLinesDumped++;
  198. }
  199. } else {
  200. bWebFound = TRUE;
  201. if (ProcessWebLine(
  202. &InLogLine,
  203. FindData.cFileName,
  204. &WebOutFile)) {
  205. nWebLineCount++;
  206. }
  207. }
  208. } //end if LogLineProcessed
  209. else
  210. {
  211. if (dwGetLogLineResult != GETLOG_ERROR)
  212. {
  213. nLineCount++;
  214. }
  215. switch (dwGetLogLineResult) {
  216. case GETLOG_ERROR_PARSE_NCSA:
  217. printfids(IDS_FILE_NOT_NCSA,dwCurrentLine);
  218. break;
  219. case GETLOG_ERROR_PARSE_MSINET:
  220. printfids(IDS_FILE_NOT_MSINET,dwCurrentLine);
  221. break;
  222. case GETLOG_ERROR_PARSE_EXTENDED:
  223. printfids(IDS_BAD_EXTENDED_FORMAT,dwCurrentLine);
  224. break;
  225. default:
  226. break;
  227. }
  228. if (!bOnErrorContinue)
  229. {
  230. bContinue = FALSE;
  231. }
  232. }
  233. } //end while !eof
  234. nTotalCount += nLineCount;
  235. if (fpInFile) {
  236. fclose(fpInFile);
  237. }
  238. if (bWebFound) {
  239. if (WebOutFile.fpOutFile != NULL ) {
  240. fclose(WebOutFile.fpOutFile);
  241. WebOutFile.fpOutFile = NULL;
  242. }
  243. bRet = MoveFileEx(
  244. WebOutFile.szTmpFileName,
  245. WebOutFile.szOutFileName,
  246. MOVEFILE_COPY_ALLOWED);
  247. if (!bRet) {
  248. dwErr = GetLastError();
  249. switch (dwErr) {
  250. case ERROR_FILE_EXISTS:
  251. case ERROR_ALREADY_EXISTS:
  252. CombineFiles(WebOutFile.szTmpFileName, WebOutFile.szOutFileName);
  253. break;
  254. case ERROR_PATH_NOT_FOUND:
  255. break;
  256. default:
  257. printfids(IDS_FILE_ERR, dwErr);
  258. return 1;
  259. }
  260. }
  261. }
  262. if (bNoConvertFound) {
  263. bNoConvertFound = FALSE;
  264. if (NoConvertOutFile.fpOutFile != NULL) {
  265. fclose(NoConvertOutFile.fpOutFile);
  266. NoConvertOutFile.fpOutFile = NULL;
  267. }
  268. bRet = MoveFileEx(
  269. NoConvertOutFile.szTmpFileName,
  270. NoConvertOutFile.szOutFileName,
  271. MOVEFILE_COPY_ALLOWED);
  272. if (!bRet) {
  273. dwErr = GetLastError();
  274. switch (dwErr) {
  275. case ERROR_FILE_EXISTS:
  276. case ERROR_ALREADY_EXISTS:
  277. CombineFiles(NoConvertOutFile.szTmpFileName, NoConvertOutFile.szOutFileName);
  278. break;
  279. case ERROR_PATH_NOT_FOUND:
  280. break;
  281. default:
  282. printfids(IDS_FILE_ERR, dwErr);
  283. exit (1);
  284. break;
  285. }
  286. }
  287. }
  288. nTotalWebCount += nWebLineCount;
  289. printfids( IDS_LINES, FindData.cFileName, nLineCount);
  290. printfids (IDS_WEB_LINES, nWebLineCount);
  291. if ( nLinesDumped > 0 ) {
  292. printfids( IDS_DUMP_LINES, nLinesDumped );
  293. nLinesDumped = 0;
  294. }
  295. }
  296. } while (FindNextFile (hFile, &FindData));
  297. FindClose(hFile);
  298. printfids (IDS_TOTALS);
  299. printfids (IDS_TOT_LINES, nTotalCount);
  300. printfids (IDS_TOT_WEB_LINES, nTotalWebCount);
  301. #if DBG
  302. PrintCacheTotals();
  303. #endif
  304. return (0);
  305. }