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.

293 lines
10 KiB

  1. #ifndef __AWFILE_H__
  2. #define __AWFILE_H__
  3. #include <ifaxos.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #ifndef IFAX11
  8. #define AWFS_BLACKBOX 1 // turn on the blackbox option
  9. #endif
  10. #define AWFS_SEEK_BEG 0
  11. #define AWFS_SEEK_CUR 1
  12. #define AWFS_SEEK_END 2
  13. #define AWFS_BADREAD ((WORD)0xffff)
  14. #define AWFS_BADWRITE ((WORD)0xffff)
  15. #define AWFS_BADSEEK ((DWORD)0xffffffff)
  16. #define AWFS_ROOT_DIR "c:\\awfiles"
  17. #ifdef AWFS_BLACKBOX
  18. #define AWFS_READ 0 /* Read mode */
  19. #define AWFS_WRITE 1 /* Write mode */
  20. #define AWFS_BACKDOORWRITE 254 /* Internal use only */
  21. #ifndef __AWFILE2_H__
  22. /* None of the first 4 bytes of this structure can never legally be 0, so you
  23. can use this fact to mark an hSecureFile as unused. */
  24. typedef struct hSecureFile
  25. {
  26. BYTE data[12];
  27. }
  28. hSecureFile, FAR *LPhSecureFile;
  29. typedef struct hOpenSecureFile
  30. {
  31. BYTE data[10];
  32. }
  33. hOpenSecureFile, FAR *LPhOpenSecureFile;
  34. #endif
  35. #else /* ------ IFAX11: NOT BLACKBOX ANY MORE ------ */
  36. #define AWFS_TEMP_PATTERN "c:\\awfiles\\T*.*"
  37. #define AWFS_ALL_PATTERN "c:\\awfiles\\*.*"
  38. #define AWFS_REF_COUNT "c:\\awfiles\\refcount.awf"
  39. #define AWSF ((DWORD)'A'+((DWORD)'W'<<8)+((DWORD)'S'<<16)+((DWORD)'F'<<24))
  40. #define AWFS_MAX_PATH 42 // C:\8.3\8.3\8.3 ==> 6 + 3 * 12 = 42
  41. #define AWFS_BAD_ENCODER 0
  42. /* ------- wFileInfo, used in SecCreateFile() ---------- */
  43. #define AWFS_MASK_JOBINFO ((WORD) 0x0FF0)
  44. #define AWFS_GENERIC ((WORD) 0x0000)
  45. #define AWFS_RECVTOPC ((WORD) 0x0010)
  46. #define AWFS_SCANTOPC ((WORD) 0x0020)
  47. #define AWFS_SENDFROMPC ((WORD) 0x0030)
  48. #define AWFS_PRINTFROMPC ((WORD) 0x0040)
  49. #define AWFS_SCANTOTWAIN ((WORD) 0x0050)
  50. #define AWFS_RECV ((WORD) 0x0060) // don't care where awfile is
  51. #define AWFS_SEND ((WORD) 0x0070) // don't care where awfile is
  52. #define AWFS_SCAN ((WORD) 0x0080) // don't care where awfile is
  53. #define AWFS_PRINT ((WORD) 0x0090) // don't care where awfile is
  54. #define AWFS_MASK_SCRATCH ((WORD) 0x0003)
  55. #define AWFS_PERSISTENT ((WORD) 0x0000)
  56. #define AWFS_SCRATCH ((WORD) 0x0001)
  57. #define AWFS_MASK_DRIVE ((WORD) 0x7000)
  58. #define AWFS_DONTCARE ((WORD) 0x0000)
  59. #define AWFS_REMOTE ((WORD) 0x1000)
  60. #define AWFS_LOCAL ((WORD) 0x2000)
  61. #define AWFS_PREFERLOCAL ((WORD) 0x3000)
  62. #define AWFS_PREFERREMOTE ((WORD) 0x4000)
  63. #define AWFS_USER_ATTACH (AWFS_GENERIC|AWFS_PERSISTENT) // user attachment
  64. /* -------- mode, used in SecOpenFile() --------- */
  65. #define AWFS_MASK_ACCESSMODE ((WORD) 0x000F)
  66. #define AWFS_READ ((WORD) 0)
  67. #define AWFS_WRITE ((WORD) 1)
  68. // #define AWFS_BACKDOORWRITE ((WORD) 2) /* Internal use only */
  69. // now it is only a hack
  70. #define AWFS_BACKDOORWRITE 254 /* Internal use only */ // a hack for awsec.dll
  71. #define AWFS_MASK_PREFETCH ((WORD) 0x00F0)
  72. // we can specify the max num of active buffers when prefetch will be turned off
  73. #define AWFS_DEFAULT_PREFETCH ((WORD) 0x0030) // three buffers can be prefetched at most
  74. #define AWFS_MASK_BUFSIZE ((WORD) 0xFF00) // in units of 256 Bytes
  75. #define AWFS_DEFAULT_BUFSIZE ((WORD) 0x1000) // 4 KB is default
  76. #define AWFS_MAX_BUFSIZE ((WORD) 0x4000) // 16 KB is max, please
  77. #define AWFS_NORM_READ (AWFS_READ|AWFS_DEFAULT_PREFETCH|AWFS_DEFAULT_BUFSIZE)
  78. #define AWFS_NORM_WRITE (AWFS_WRITE|AWFS_DEFAULT_BUFSIZE)
  79. /* -------- data structures ------------- */
  80. typedef struct tag_hSecureFile
  81. { // simplify naming and provide job information
  82. // must be 12 bytes for backward compatibility
  83. DWORD dwEncoder; // encoding file name, non-zero
  84. WORD wFileInfo; // file info passed in while calling SecCreateFile()
  85. WORD wRemote; // 0 for local file; non-zero for remote file
  86. char szExt[4]; // customized extension if szExt[0] != '\0'
  87. }
  88. hSecureFile, FAR *LPhSecureFile;
  89. typedef struct tag_OpenHandle
  90. {
  91. // the following from hSecureFile
  92. hSecureFile hsf;
  93. // the following are from original hOpenSecureFile
  94. WORD wHdrSize; // Size of header, 0 means closed file handle
  95. DWORD dwHandle; // Open file handle (4 bytes)
  96. WORD wMode; // READ or WRITE or READ_WRITE, used in _lopen()
  97. ULONG ulOffset; // Current physical position in the file
  98. // the following are for remote awfile client
  99. LPVOID lpRfsOpen; // for remote file system information
  100. // hands off, internal use only
  101. struct tag_OpenHandle FAR * next;
  102. struct tag_OpenHandle FAR * alloc_next;
  103. }
  104. OPENHANDLE, FAR * LPOPENHANDLE;
  105. typedef struct tag_hOpenSecureFile
  106. { // maintain more information associated with handle
  107. // must be 10 bytes for backward compatibility
  108. LPOPENHANDLE lpOpenHandle; // pointer to the internal info of file handle
  109. BYTE unused[6]; // to keep the same size for backward compatibility
  110. }
  111. hOpenSecureFile, FAR *LPhOpenSecureFile;
  112. typedef struct tag_hSecureHeader
  113. { // drop encryption
  114. // previously, 266 bytes, 256 bytes of them are for security key.
  115. DWORD magic; // Should be AWSF
  116. WORD size; // Size of header
  117. hSecureFile hsf;
  118. }
  119. hSecureHeader, FAR *LPhSecureHeader;
  120. // for hhsos.dll
  121. typedef struct tag_FILELINK
  122. {
  123. DWORD dwHash; // awfile.dll does not care
  124. hSecureFile hFile;
  125. WORD wRefCount;
  126. struct tag_FILELINK FAR * lpNext;
  127. }
  128. FILELINK, FAR * LPFILELINK;
  129. // for remote awfile
  130. typedef struct tag_FILECOUNT
  131. {
  132. hSecureFile hsf;
  133. WORD wRefCount;
  134. }
  135. FILECOUNT, FAR * LPFILECOUNT;
  136. #endif // end of IFAX11
  137. // No secure file handles will have the first 4 bytes as 0
  138. #define IsValidSecureFile(hsec) (*((LPDWORD)&(hsec)) != 0)
  139. #ifdef IFAX11
  140. /* Last error maintenance */
  141. void WINAPI SecSetLastError ( DWORD dwErr );
  142. DWORD WINAPI SecGetLastError ( void );
  143. /* Construct the path name of this awfile. cb is the size of the buffer
  144. to hold the path name. The size of the buffer is recommended to be
  145. AWFS_MAX_PATH.
  146. Return NO_ERROR if this operation is successful.
  147. Return ERROR_NOT_SUFFICIENT_MEMORY if the buffer is too small.
  148. Return ERROR_INVALID_PARAMETER if either pointer is null. */
  149. WORD WINAPI SecGetPath ( hSecureFile FAR * lphsf, LPSTR lpszPath, UINT cb );
  150. WORD WINAPI SetGetRootDir ( LPSTR lpszPath, UINT cb );
  151. /* Construct the encoder of the given awfile file name (not path name). */
  152. DWORD WINAPI SecExtractEncoderFromFileName ( LPSTR lpszFileName );
  153. #endif
  154. /* Creates a new file in the secur file system, and fills in hsec to point to
  155. the new file. Space for hsec must be allocated by the caller. Returns 0
  156. for success, non-zero on failure. The file is not open when the function
  157. returns. If temp is non-zero, file will be erased when machine is next
  158. rebooted as part of cleanup. */
  159. #ifdef AWFS_BLACKBOX
  160. WORD WINAPI SecCreateFile(hSecureFile FAR *hsec, WORD temp);
  161. #else
  162. WORD WINAPI SecCreateFile(hSecureFile FAR *hsec, WORD wFileInfo);
  163. WORD WINAPI SecCreateFileEx (hSecureFile FAR * lphsec, WORD wFileInfo, LPSTR lpszExt );
  164. #endif
  165. /* Deletes a file from the secure file system. Returns 0 for success, non-zero
  166. for failure. Doesn't actually remove file until reference count is 0 */
  167. WORD WINAPI SecDeleteFile(hSecureFile FAR *hsec);
  168. /* Increments reference count on a secure file, such that it will take one more
  169. delete call to remove the file than before. Returns 0 for success, non-zero
  170. for failure. */
  171. WORD WINAPI SecIncFileRefCount(hSecureFile FAR *hsec);
  172. #ifdef IFAX11
  173. WORD WINAPI SecAdjustRefCount ( hSecureFile FAR * lphsf, short sAdjust );
  174. #endif
  175. /* Opens a secure file for reading or writing. Mode must be AWFS_READ or
  176. AWFS_WRITE. Returns 0 for success, non-zero on failure. Fills in hopense
  177. with a secure file handle on success. Space for hopensec must be allocated
  178. by the caller. Opening the file for write should happen only once. Once
  179. the file has been closed from writing, it should never be opened for writing
  180. again. A file can be opened for reading multiple times. The file should
  181. be created with SecCreateFile before it is opened for writing. */
  182. WORD WINAPI SecOpenFile(hSecureFile FAR *hsec,
  183. hOpenSecureFile FAR *hopensec, WORD mode);
  184. /* Closes a secure file which has been opened by SecOpenFile. Returns 0 for
  185. success, non-zero for failure. */
  186. WORD WINAPI SecCloseFile(hOpenSecureFile FAR *hopensec);
  187. /* Flushes a secure file which has been opened by SecOpenFile. Returns 0 for
  188. success, non-zero for failure. */
  189. WORD WINAPI SecFlushFile(hOpenSecureFile FAR *hopensec);
  190. /* Flushes all reference counts to disk. Returns 0 for success, non-zero for
  191. failure. */
  192. WORD WINAPI SecFlushCache(void);
  193. /* Reads from a secure file. This will read up to bufsize bytes from the file
  194. into buf. Buf should, therefore, be at least bufsize bytes big. The
  195. hopensec should be obtained from calling SecOpenFile with mode equal to
  196. AWFS_READ. The number of bytes read is returned, with 0 meaning end of
  197. file, and AWFS_BADREAD meaning a read error occurred. */
  198. WORD WINAPI SecReadFile(hOpenSecureFile FAR *hopensec, LPVOID buf,
  199. WORD bufsize);
  200. /* Writes to a secure file. hopensec should be obtained from SecOpenFile with
  201. the mode set to AWFS_WRITE. bufsize bytes are written from buf. The number
  202. of bytes written is returned on success. AWFS_BADWRITE is returned on
  203. failure. The buffer passed in will be returned intact, but will be modified
  204. along the way, so it cannot be a shared copy of a buffer */
  205. WORD WINAPI SecWriteFile(hOpenSecureFile FAR *hopensec, LPVOID buf,
  206. WORD bufsize);
  207. /* Seeks to position pos in hOpenSecFile for either writing or reading. Type
  208. can be AWFS_SEEK_BEG for seeking to pos bytes from the start of the file,
  209. AWFS_SEEK_CUR for seeking to pos bytes from the current position, and
  210. AWFS_SEEK_END for pos bytes from the end of the file. SecSeekFile returns
  211. the new position in bytes from the beginning of the file, or AWFS_BADSEEK.*/
  212. DWORD WINAPI SecSeekFile(hOpenSecureFile FAR *hopensec, long pos,
  213. WORD type);
  214. /* Private MAPI API's */
  215. typedef WORD CALLBACK RefCallback(hSecureFile FAR *lphSecFile);
  216. void WINAPI SecReinitRefCount(RefCallback *lpfnRefCB);
  217. BOOL WINAPI RegisterSecFile(hSecureFile FAR *lphSecFile); // unexported
  218. BOOL WINAPI UnRegisterSecFile(hSecureFile FAR *lphSecFile); // unexported
  219. #ifdef IFAX11
  220. void WINAPI SecResetRefCount ( LPFILELINK lpFileLink );
  221. #endif
  222. #ifdef __cplusplus
  223. } /* extern "C" */
  224. #endif
  225. #endif /* __AWFILE_H__ */