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.

273 lines
5.8 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <io.h>
  6. #include <fcntl.h>
  7. #include <dos.h>
  8. #include <sys/stat.h>
  9. #include <fdi.h>
  10. char dest_dir[MAX_PATH];
  11. /*
  12. * Memory allocation function
  13. */
  14. FNALLOC(fdi_mem_alloc)
  15. {
  16. return malloc(cb);
  17. }
  18. /*
  19. * Memory free function
  20. */
  21. FNFREE(fdi_mem_free)
  22. {
  23. free(pv);
  24. }
  25. FNOPEN(fdi_file_open)
  26. {
  27. return _open(pszFile, oflag, pmode);
  28. }
  29. FNREAD(fdi_file_read)
  30. {
  31. return _read((int)hf, pv, cb);
  32. }
  33. FNWRITE(fdi_file_write)
  34. {
  35. return _write((int)hf, pv, cb);
  36. }
  37. FNCLOSE(fdi_file_close)
  38. {
  39. return _close((int)hf);
  40. }
  41. FNSEEK(fdi_file_seek)
  42. {
  43. return _lseek((int)hf, dist, seektype);
  44. }
  45. FNFDINOTIFY(fdi_notification_function)
  46. {
  47. switch (fdint)
  48. {
  49. case fdintCABINET_INFO: // general information about the cabinet
  50. #ifdef MSMGEN_TEST
  51. printf(
  52. "fdintCABINET_INFO\n"
  53. " next cabinet = %s\n"
  54. " next disk = %s\n"
  55. " cabinet path = %s\n"
  56. " cabinet set ID = %d\n"
  57. " cabinet # in set = %d (zero based)\n"
  58. "\n",
  59. pfdin->psz1,
  60. pfdin->psz2,
  61. pfdin->psz3,
  62. pfdin->setID,
  63. pfdin->iCabinet
  64. );
  65. #endif
  66. return 0;
  67. case fdintPARTIAL_FILE: // first file in cabinet is continuation
  68. printf(
  69. "fdintPARTIAL_FILE\n"
  70. " name of continued file = %s\n"
  71. " name of cabinet where file starts = %s\n"
  72. " name of disk where file starts = %s\n",
  73. pfdin->psz1,
  74. pfdin->psz2,
  75. pfdin->psz3
  76. );
  77. return 0;
  78. case fdintCOPY_FILE: // file to be copied
  79. {
  80. INT_PTR handle;
  81. char destination[MAX_PATH];
  82. #ifdef MSMGEN_TEST
  83. printf(
  84. "fdintCOPY_FILE\n"
  85. " file name in cabinet = %s\n"
  86. " uncompressed file size = %d\n",
  87. pfdin->psz1,
  88. pfdin->cb
  89. );
  90. #endif
  91. sprintf(
  92. destination,
  93. "%s%s",
  94. dest_dir,
  95. pfdin->psz1
  96. );
  97. handle = fdi_file_open(
  98. destination,
  99. _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
  100. _S_IREAD | _S_IWRITE
  101. );
  102. return handle;
  103. }
  104. case fdintCLOSE_FILE_INFO: // close the file, set relevant info
  105. {
  106. HANDLE handle;
  107. char destination[256];
  108. printf(
  109. "fdintCLOSE_FILE_INFO\n"
  110. " file name in cabinet = %s\n"
  111. "\n",
  112. pfdin->psz1
  113. );
  114. sprintf(
  115. destination,
  116. "%s%s",
  117. dest_dir,
  118. pfdin->psz1
  119. );
  120. fdi_file_close(pfdin->hf);
  121. /*
  122. * Set date/time
  123. *
  124. * Need Win32 type handle for to set date/time
  125. */
  126. handle = CreateFile(
  127. destination,
  128. GENERIC_READ | GENERIC_WRITE,
  129. FILE_SHARE_READ,
  130. NULL,
  131. OPEN_EXISTING,
  132. FILE_ATTRIBUTE_NORMAL,
  133. NULL
  134. );
  135. if (handle != INVALID_HANDLE_VALUE)
  136. {
  137. FILETIME datetime;
  138. if (TRUE == DosDateTimeToFileTime(
  139. pfdin->date,
  140. pfdin->time,
  141. &datetime))
  142. {
  143. FILETIME local_filetime;
  144. if (TRUE == LocalFileTimeToFileTime(
  145. &datetime,
  146. &local_filetime))
  147. {
  148. (void) SetFileTime(
  149. handle,
  150. &local_filetime,
  151. NULL,
  152. &local_filetime
  153. );
  154. }
  155. }
  156. CloseHandle(handle);
  157. }
  158. /*
  159. * Mask out attribute bits other than readonly,
  160. * hidden, system, and archive, since the other
  161. * attribute bits are reserved for use by
  162. * the cabinet format.
  163. */
  164. (void) SetFileAttributes(
  165. destination,
  166. pfdin->attribs
  167. );
  168. if (!SUCCEEDED(AddFileToCabinetA(destination, strlen(destination), //"%Temp%\\msm_temp_cabinet_dir\\a.manifest.12213232312312312
  169. pfdin->psz1, strlen(pfdin->psz1)))) // a.manifest.12213232312312312
  170. {
  171. return -1; // abort
  172. }
  173. return TRUE;
  174. }
  175. case fdintNEXT_CABINET: // file continued to next cabinet
  176. printf(
  177. "fdintNEXT_CABINET\n"
  178. " name of next cabinet where file continued = %s\n"
  179. " name of next disk where file continued = %s\n"
  180. " cabinet path name = %s\n"
  181. "\n",
  182. pfdin->psz1,
  183. pfdin->psz2,
  184. pfdin->psz3
  185. );
  186. return 0;
  187. }
  188. return 0;
  189. }
  190. char *return_fdi_error_string(INT err)
  191. {
  192. switch (err)
  193. {
  194. case FDIERROR_NONE:
  195. return "No error";
  196. case FDIERROR_CABINET_NOT_FOUND:
  197. return "Cabinet not found";
  198. case FDIERROR_NOT_A_CABINET:
  199. return "Not a cabinet";
  200. case FDIERROR_UNKNOWN_CABINET_VERSION:
  201. return "Unknown cabinet version";
  202. case FDIERROR_CORRUPT_CABINET:
  203. return "Corrupt cabinet";
  204. case FDIERROR_ALLOC_FAIL:
  205. return "Memory allocation failed";
  206. case FDIERROR_BAD_COMPR_TYPE:
  207. return "Unknown compression type";
  208. case FDIERROR_MDI_FAIL:
  209. return "Failure decompressing data";
  210. case FDIERROR_TARGET_FILE:
  211. return "Failure writing to target file";
  212. case FDIERROR_RESERVE_MISMATCH:
  213. return "Cabinets in set have different RESERVE sizes";
  214. case FDIERROR_WRONG_CABINET:
  215. return "Cabinet returned on fdintNEXT_CABINET is incorrect";
  216. case FDIERROR_USER_ABORT:
  217. return "User aborted";
  218. default:
  219. return "Unknown error";
  220. }
  221. }