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.

283 lines
5.9 KiB

  1. /* Copyright (c) 1992-2001, Microsoft Corporation, all rights reserved
  2. **
  3. ** pcache.h
  4. ** Remote Access Phonebook - Win9x Password cache (PWL) decrypter
  5. ** Private header
  6. **
  7. ** Portions of this code have been ported from:
  8. ** Win9x\proj\net\user\src\WNET\PCACHE
  9. **
  10. ** Whistler bug: 208318 Win9x Upg: Username and Password for DUN connectoid not
  11. ** migrated from Win9x to Whistler
  12. **
  13. ** 06/24/92 gregj
  14. ** 03/06/01 Jeff Sigman
  15. */
  16. #ifndef _PCACHE_H_
  17. #define _PCACHE_H_
  18. //----------------------------------------------------------------------------
  19. // Constants
  20. //----------------------------------------------------------------------------
  21. #define IERR_PCACHE_BASE 7200
  22. #define IERR_BadSig (IERR_PCACHE_BASE + 1)
  23. #define IERR_CacheEntryNotFound (IERR_PCACHE_BASE + 4)
  24. #define IERR_IncorrectUsername (IERR_PCACHE_BASE + 6)
  25. #define IERR_CacheCorrupt (IERR_PCACHE_BASE + 7)
  26. #define PLAINTEXT_SIGNATURE 0x4E464DB0
  27. #define NEW_PLAINTEXT_SIGNATURE 0x968582E3
  28. #define PCE_END_MARKER 0x8000
  29. #define BUCKET_COUNT 16
  30. #define RAS_MaxPortName MAX_PATH
  31. #define MAX_ENTRY_SIZE 250 // so total file size < 64K
  32. #define PCE_MISC 0x06 // entry is for some other resource
  33. #define MAX_PHONENUMBER_SIZE 128
  34. #define MAX_CALLBACKNUMBER_SIZE MAX_PHONENUMBER_SIZE
  35. #define DLPARAMS_MASK_USERNAME 0x00000001
  36. #define DLPARAMS_MASK_PASSWORD 0x00000002
  37. #define DLPARAMS_MASK_DOMAIN 0x00000004
  38. #define DLPARAMS_MASK_OLDSTYLE 0x80000000
  39. #define S_RESOURCEMASK2 "*Rna\\%s\\%s"
  40. #define S_SRCHPWL "*.PWL"
  41. #define S_PWLDIR "\\Pwls"
  42. //----------------------------------------------------------------------------
  43. // Datatypes
  44. //----------------------------------------------------------------------------
  45. typedef struct
  46. {
  47. USHORT cbResource;
  48. USHORT cbPassword;
  49. UCHAR iEntry;
  50. UCHAR nType;
  51. USHORT dchResource;
  52. USHORT dchPassword;
  53. }
  54. CACHE_ENTRY_INFO;
  55. typedef struct
  56. {
  57. USHORT cbEntry;
  58. USHORT cbResource;
  59. USHORT cbPassword;
  60. UCHAR iEntry;
  61. UCHAR nType;
  62. CHAR abResource[ 1 ];
  63. }
  64. PASSWORD_CACHE_ENTRY;
  65. typedef struct
  66. {
  67. CHAR abRandomPadding[ 16 ];
  68. CHAR abAuthenticationHash[ 16 ];
  69. USHORT aibBuckets[ BUCKET_COUNT + 1 ];
  70. }
  71. NEW_ENCRYPTED_HEADER;
  72. typedef struct
  73. {
  74. USHORT cbBlob;
  75. }
  76. KEYBLOB;
  77. typedef struct
  78. {
  79. ULONG ulSig;
  80. ULONG ulSerial;
  81. USHORT cMRUEntries;
  82. UCHAR aiOrder[ 255 ];
  83. UCHAR aiBucket[ 255 ];
  84. DWORD cbHeader;
  85. DWORD adwBucketSalts[ BUCKET_COUNT + 1 ];
  86. KEYBLOB keyBlobs;
  87. }
  88. NEW_PLAINTEXT_HEADER;
  89. typedef struct _RAS_DIALPARAMS {
  90. DWORD DP_Uid;
  91. WCHAR DP_PhoneNumber[MAX_PHONENUMBER_SIZE + 1];
  92. WCHAR DP_CallbackNumber[MAX_CALLBACKNUMBER_SIZE + 1];
  93. WCHAR DP_UserName[UNLEN + 1];
  94. WCHAR DP_Password[PWLEN + 1];
  95. WCHAR DP_Domain[DNLEN + 1];
  96. DWORD DP_SubEntry;
  97. } RAS_DIALPARAMS, *PRAS_DIALPARAMS;
  98. //----------------------------------------------------------------------------
  99. // Macros
  100. //----------------------------------------------------------------------------
  101. #define FIELDOFFSET(type,field) (((CHAR*)&(((type*)NULL)->field))-((CHAR*)NULL))
  102. #define BREAK_ON_DWERR(_e) if ((_e)) break;
  103. #define NEXT_PCE(pce) ((PASSWORD_CACHE_ENTRY*)(((CHAR*)(pce))+(pce)->cbEntry))
  104. #undef min
  105. #define min(a,b) ((a)<(b)?(a):(b))
  106. //----------------------------------------------------------------------------
  107. // Prototypes
  108. //----------------------------------------------------------------------------
  109. DWORD (* g_SetEntryDialParams) (
  110. IN PWCHAR pszSid,
  111. IN DWORD dwUID,
  112. IN DWORD dwSetMask,
  113. IN DWORD dwClearMask,
  114. IN PRAS_DIALPARAMS lpRasDialParams
  115. );
  116. UINT
  117. HashName (
  118. const CHAR* pbResource,
  119. WORD cbResource
  120. );
  121. VOID
  122. Encrypt (
  123. CHAR *pbSource,
  124. WORD cbSource,
  125. CHAR *pbDest
  126. );
  127. VOID
  128. Decrypt (
  129. CHAR *pbSource,
  130. WORD cbSource
  131. );
  132. VOID
  133. ENCRYPTER (
  134. const CHAR* pszUsername,
  135. const CHAR* pszPassword,
  136. UINT iBucket,
  137. DWORD dwSalt
  138. );
  139. DWORD
  140. ReadData (
  141. WORD ibSeek,
  142. PVOID pbBuffer,
  143. WORD cbBuffer
  144. );
  145. VOID
  146. AssembleFindCacheName (
  147. CHAR* pszWindir,
  148. CHAR* pszResult
  149. );
  150. DWORD
  151. OpenCacheFile (
  152. VOID
  153. );
  154. DWORD
  155. ReadAndDecrypt (
  156. WORD ibSeek,
  157. PVOID pbBuffer,
  158. WORD cbBuffer
  159. );
  160. INT
  161. CompareCacheNames (
  162. const CHAR* pbRes1,
  163. WORD cbRes1,
  164. const CHAR* pbRes2,
  165. WORD cbRes2
  166. );
  167. DWORD
  168. LoadEncryptedHeader (
  169. VOID
  170. );
  171. DWORD
  172. LoadPlaintextHeader (
  173. VOID
  174. );
  175. DWORD
  176. LookupEntry (
  177. const CHAR* pbResource,
  178. WORD cbResource,
  179. UCHAR nType,
  180. PASSWORD_CACHE_ENTRY** ppce
  181. );
  182. DWORD
  183. ValidateEncryptedHeader (
  184. VOID
  185. );
  186. DWORD
  187. FindPWLResource (
  188. const CHAR* pbResource,
  189. WORD cbResource,
  190. CHAR* pbBuffer,
  191. WORD cbBuffer,
  192. UCHAR nType
  193. );
  194. DWORD
  195. FindNewestFile (
  196. IN OUT CHAR* SourceName
  197. );
  198. VOID
  199. DeleteAllPwls (
  200. VOID
  201. );
  202. BOOL
  203. StrCpyAFromWUsingAnsiEncoding(
  204. LPSTR pszDst,
  205. LPCWSTR pszSrc,
  206. DWORD dwDstChars
  207. );
  208. BOOL
  209. StrCpyWFromAUsingAnsiEncoding(
  210. WCHAR* pszDst,
  211. LPCSTR pszSrc,
  212. DWORD dwDstChars
  213. );
  214. VOID
  215. CopyAndTruncate (
  216. LPSTR lpszDest,
  217. LPCSTR lpszSrc,
  218. UINT cbDest,
  219. BOOL flag
  220. );
  221. DWORD
  222. OpenPWL (
  223. CHAR* Username,
  224. CHAR* Password,
  225. BOOL flag
  226. );
  227. DWORD
  228. FindPWLString (
  229. IN CHAR* EntryName,
  230. IN CHAR* ConnUser,
  231. IN OUT CHAR* Output
  232. );
  233. BOOL
  234. MigrateEntryCreds (
  235. IN OUT PRAS_DIALPARAMS prdp,
  236. IN PCTSTR pszEntryName,
  237. IN PCTSTR pszUserName,
  238. IN PDWORD pdwFlag
  239. );
  240. #endif // _PCACHE_H_