Source code of Windows XP (NT5)
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.

247 lines
6.1 KiB

  1. //
  2. // FILELIST.C
  3. //
  4. #include "sigverif.h"
  5. LPTSTR MyStrStr(LPTSTR lpString, LPTSTR lpSubString)
  6. {
  7. if (!lpString || !lpSubString) {
  8. return NULL;
  9. }
  10. //return (_tcsstr(lpString, lpSubString));
  11. return (StrStrI(lpString, lpSubString));
  12. }
  13. void InsertFileNodeIntoList(LPFILENODE lpFileNode)
  14. {
  15. LPFILENODE lpTempNode = g_App.lpFileList;
  16. LPFILENODE lpPrevNode = NULL;
  17. INT iRet;
  18. if (!lpFileNode)
  19. return;
  20. if (!g_App.lpFileList)
  21. {
  22. //
  23. // Initialize the global file lists
  24. //
  25. g_App.lpFileList = lpFileNode;
  26. g_App.lpFileLast = lpFileNode;
  27. }
  28. else
  29. {
  30. for(lpTempNode=g_App.lpFileList;lpTempNode;lpTempNode=lpTempNode->next)
  31. {
  32. //
  33. // Insert items sorted by directory and then filename
  34. //
  35. iRet = lstrcmp(lpTempNode->lpDirName, lpFileNode->lpDirName);
  36. if (iRet == 0)
  37. {
  38. //
  39. // If the directory names match, key off the filename
  40. //
  41. iRet = lstrcmp(lpTempNode->lpFileName, lpFileNode->lpFileName);
  42. }
  43. if (iRet >= 0)
  44. {
  45. if (!lpPrevNode)
  46. {
  47. //
  48. // Insert at the head of the list
  49. //
  50. lpFileNode->next = lpTempNode;
  51. g_App.lpFileList = lpFileNode;
  52. return;
  53. }
  54. else
  55. {
  56. //
  57. // Inserting between lpPrevNode and lpTempNode
  58. //
  59. lpFileNode->next = lpTempNode;
  60. lpPrevNode->next = lpFileNode;
  61. return;
  62. }
  63. }
  64. lpPrevNode = lpTempNode;
  65. }
  66. //
  67. // There were no matches, so insert this item at the end of the list
  68. //
  69. g_App.lpFileLast->next = lpFileNode;
  70. g_App.lpFileLast = lpFileNode;
  71. }
  72. }
  73. BOOL IsFileAlreadyInList(LPTSTR lpDirName, LPTSTR lpFileName)
  74. {
  75. LPFILENODE lpFileNode;
  76. CharLowerBuff(lpDirName, lstrlen(lpDirName));
  77. CharLowerBuff(lpFileName, lstrlen(lpFileName));
  78. for(lpFileNode=g_App.lpFileList;lpFileNode;lpFileNode=lpFileNode->next)
  79. {
  80. if (!lstrcmp(lpFileNode->lpFileName, lpFileName) && !lstrcmp(lpFileNode->lpDirName, lpDirName))
  81. {
  82. return TRUE;
  83. }
  84. }
  85. return FALSE;
  86. }
  87. // Free all the memory allocated in a single File Node.
  88. void DestroyFileNode(LPFILENODE lpFileNode)
  89. {
  90. if (!lpFileNode) {
  91. return;
  92. }
  93. if (lpFileNode->lpFileName) {
  94. FREE(lpFileNode->lpFileName);
  95. }
  96. if (lpFileNode->lpDirName) {
  97. FREE(lpFileNode->lpDirName);
  98. }
  99. if (lpFileNode->lpVersion) {
  100. FREE(lpFileNode->lpVersion);
  101. }
  102. if (lpFileNode->lpCatalog) {
  103. FREE(lpFileNode->lpCatalog);
  104. }
  105. if (lpFileNode->lpSignedBy) {
  106. FREE(lpFileNode->lpSignedBy);
  107. }
  108. if (lpFileNode->lpTypeName) {
  109. FREE(lpFileNode->lpTypeName);
  110. }
  111. if (lpFileNode) {
  112. FREE(lpFileNode);
  113. lpFileNode = NULL;
  114. }
  115. }
  116. // Free all the memory allocated in the g_App.lpFileList.
  117. void DestroyFileList(void)
  118. {
  119. LPFILENODE lpFileNode;
  120. while(g_App.lpFileList)
  121. {
  122. lpFileNode = g_App.lpFileList->next;
  123. DestroyFileNode(g_App.lpFileList);
  124. g_App.lpFileList = lpFileNode;
  125. }
  126. g_App.lpFileLast = NULL;
  127. g_App.dwFiles = 0;
  128. g_App.dwSigned = 0;
  129. g_App.dwUnsigned = 0;
  130. }
  131. LPFILENODE CreateFileNode(LPTSTR lpDirectory, LPTSTR lpFileName)
  132. {
  133. LPFILENODE lpFileNode;
  134. TCHAR szDirName[MAX_PATH];
  135. FILETIME ftLocalTime;
  136. WIN32_FILE_ATTRIBUTE_DATA faData;
  137. BOOL bRet;
  138. GetCurrentDirectory(MAX_PATH, szDirName);
  139. CharLowerBuff(szDirName, lstrlen(szDirName));
  140. lpFileNode = (LPFILENODE) MALLOC(sizeof(FILENODE));
  141. if (lpFileNode)
  142. {
  143. lpFileNode->lpFileName = (LPTSTR) MALLOC((lstrlen(lpFileName) + 1) * sizeof(TCHAR));
  144. if (!lpFileNode->lpFileName)
  145. {
  146. goto clean0;
  147. }
  148. lstrcpy(lpFileNode->lpFileName, lpFileName);
  149. CharLowerBuff(lpFileNode->lpFileName, lstrlen(lpFileNode->lpFileName));
  150. if (lpDirectory)
  151. {
  152. lpFileNode->lpDirName = (LPTSTR) MALLOC((lstrlen(lpDirectory) + 1) * sizeof(TCHAR));
  153. if (!lpFileNode->lpDirName)
  154. {
  155. goto clean0;
  156. }
  157. lstrcpy(lpFileNode->lpDirName, lpDirectory);
  158. CharLowerBuff(lpFileNode->lpDirName, lstrlen(lpFileNode->lpDirName));
  159. }
  160. else
  161. {
  162. lpFileNode->lpDirName = (LPTSTR) MALLOC((lstrlen(szDirName) + 1) * sizeof(TCHAR));
  163. if (!lpFileNode->lpDirName)
  164. {
  165. goto clean0;
  166. }
  167. lstrcpy(lpFileNode->lpDirName, szDirName);
  168. CharLowerBuff(lpFileNode->lpDirName, lstrlen(lpFileNode->lpDirName));
  169. }
  170. if (lpDirectory)
  171. SetCurrentDirectory(lpDirectory);
  172. ZeroMemory(&faData, sizeof(WIN32_FILE_ATTRIBUTE_DATA));
  173. bRet = GetFileAttributesEx(lpFileName, GetFileExInfoStandard, &faData);
  174. if (bRet)
  175. {
  176. // Store away the last access time for logging purposes.
  177. FileTimeToLocalFileTime(&faData.ftLastWriteTime, &ftLocalTime);
  178. FileTimeToSystemTime(&ftLocalTime, &lpFileNode->LastModified);
  179. }
  180. }
  181. if (lpDirectory)
  182. SetCurrentDirectory(szDirName);
  183. return lpFileNode;
  184. clean0:
  185. //
  186. // If we get here then we weren't able to allocate all of the memory needed
  187. // for this structure, so free up any memory we were able to allocate and
  188. // reutnr NULL.
  189. //
  190. if (lpFileNode)
  191. {
  192. if (lpFileNode->lpFileName)
  193. {
  194. FREE(lpFileNode->lpFileName);
  195. }
  196. if (lpFileNode->lpDirName)
  197. {
  198. FREE(lpFileNode->lpDirName);
  199. }
  200. FREE(lpFileNode);
  201. }
  202. return NULL;
  203. }