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.

426 lines
9.5 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: defpol.cpp
  6. //
  7. // Contents: Default policy module
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "pch.cpp"
  13. #include "tlspol.h"
  14. #include "policy.h"
  15. //---------------------------------------------------------------
  16. //
  17. // Default Policy Module Function.
  18. //
  19. //---------------------------------------------------------------
  20. POLICYSTATUS WINAPI
  21. PMInitialize(
  22. DWORD dwLicenseServerVersion, // HIWORD is major, LOWORD is minor
  23. LPCTSTR pszCompanyName,
  24. LPCTSTR pszProductCode,
  25. PDWORD pdwNumProduct,
  26. PPMSUPPORTEDPRODUCT* ppszProduct,
  27. PDWORD pdwErrCode
  28. )
  29. /*++
  30. --*/
  31. {
  32. *pdwNumProduct = 0;
  33. *ppszProduct = NULL;
  34. *pdwErrCode = ERROR_SUCCESS;
  35. return POLICY_SUCCESS;
  36. }
  37. //-------------------------------------------------------
  38. POLICYSTATUS WINAPI
  39. PMReturnLicense(
  40. PMHANDLE hClient,
  41. ULARGE_INTEGER* pLicenseSerialNumber,
  42. PPMLICENSETOBERETURN pLicenseTobeReturn,
  43. PDWORD pdwLicenseStatus,
  44. PDWORD pdwErrCode
  45. )
  46. /*++
  47. ++*/
  48. {
  49. //
  50. // default return license is always delete old license
  51. // and return license to license pack
  52. //
  53. *pdwLicenseStatus = LICENSE_RETURN_DELETE;
  54. *pdwErrCode = ERROR_SUCCESS;
  55. return POLICY_SUCCESS;
  56. }
  57. //--------------------------------------------------------------
  58. POLICYSTATUS WINAPI
  59. PMInitializeProduct(
  60. LPCTSTR pszCompanyName,
  61. LPCTSTR pszCHCode,
  62. LPCTSTR pszTLSCode,
  63. PDWORD pdwErrCode
  64. )
  65. /*++
  66. ++*/
  67. {
  68. //
  69. // Initialize internal data here
  70. //
  71. *pdwErrCode = ERROR_SUCCESS;
  72. return POLICY_SUCCESS;
  73. }
  74. //--------------------------------------------------------------
  75. POLICYSTATUS WINAPI
  76. PMUnloadProduct(
  77. LPCTSTR pszCompanyName,
  78. LPCTSTR pszCHCode,
  79. LPCTSTR pszTLSCode,
  80. PDWORD pdwErrCode
  81. )
  82. /*++
  83. ++*/
  84. {
  85. //
  86. // Free all internal data here
  87. //
  88. *pdwErrCode = ERROR_SUCCESS;
  89. return POLICY_SUCCESS;
  90. }
  91. //--------------------------------------------------------------
  92. void WINAPI
  93. PMTerminate()
  94. /*++
  95. ++*/
  96. {
  97. //
  98. // Free internal data here
  99. //
  100. return;
  101. }
  102. //--------------------------------------------------------------
  103. POLICYSTATUS
  104. ProcessLicenseRequest(
  105. PMHANDLE client,
  106. PPMLICENSEREQUEST pbRequest,
  107. PPMLICENSEREQUEST* pbAdjustedRequest,
  108. PDWORD pdwErrCode
  109. )
  110. /*++
  111. ++*/
  112. {
  113. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  114. *pbAdjustedRequest = pbRequest;
  115. if(pbRequest->dwLicenseType != LICENSETYPE_LICENSE)
  116. {
  117. dwStatus = POLICY_NOT_SUPPORTED;
  118. *pdwErrCode = TLS_E_NOCONCURRENT;
  119. }
  120. return dwStatus;
  121. }
  122. //--------------------------------------------------------------
  123. POLICYSTATUS
  124. ProcessAllocateRequest(
  125. PMHANDLE client,
  126. DWORD dwSuggestType,
  127. PDWORD pdwKeyPackType,
  128. PDWORD pdwErrCode
  129. )
  130. /*++
  131. Default sequence is always FREE/RETAIL/OPEN/SELECT/TEMPORARY
  132. ++*/
  133. {
  134. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  135. switch(dwSuggestType)
  136. {
  137. case LSKEYPACKTYPE_UNKNOWN:
  138. *pdwKeyPackType = LSKEYPACKTYPE_FREE;
  139. break;
  140. case LSKEYPACKTYPE_FREE:
  141. *pdwKeyPackType = LSKEYPACKTYPE_RETAIL;
  142. break;
  143. case LSKEYPACKTYPE_RETAIL:
  144. *pdwKeyPackType = LSKEYPACKTYPE_OPEN;
  145. break;
  146. case LSKEYPACKTYPE_OPEN:
  147. *pdwKeyPackType = LSKEYPACKTYPE_SELECT;
  148. break;
  149. case LSKEYPACKTYPE_SELECT:
  150. //
  151. // No more keypack to look for, instruct license
  152. // server to terminate.
  153. //
  154. *pdwKeyPackType = LSKEYPACKTYPE_UNKNOWN;
  155. break;
  156. default:
  157. //
  158. // Instruct License Server to terminate request
  159. //
  160. *pdwKeyPackType = LSKEYPACKTYPE_UNKNOWN;
  161. }
  162. *pdwErrCode = ERROR_SUCCESS;
  163. return dwStatus;
  164. }
  165. //-------------------------------------------------------------
  166. POLICYSTATUS
  167. ProcessGenLicenses(
  168. PMHANDLE client,
  169. PPMGENERATELICENSE pGenLicense,
  170. PPMCERTEXTENSION *pCertExtension,
  171. PDWORD pdwErrCode
  172. )
  173. /*++
  174. ++*/
  175. {
  176. // No policy extension to return.
  177. *pCertExtension = NULL;
  178. *pdwErrCode = ERROR_SUCCESS;
  179. return POLICY_SUCCESS;
  180. }
  181. //--------------------------------------------------------------
  182. POLICYSTATUS
  183. ProcessComplete(
  184. PMHANDLE client,
  185. DWORD dwErrCode,
  186. PDWORD pdwRetCode
  187. )
  188. /*++
  189. ++*/
  190. {
  191. *pdwRetCode = ERROR_SUCCESS;
  192. return POLICY_SUCCESS;
  193. }
  194. //--------------------------------------------------------------
  195. POLICYSTATUS WINAPI
  196. PMLicenseRequest(
  197. PMHANDLE client,
  198. DWORD dwProgressCode,
  199. PVOID pbProgressData,
  200. PVOID* pbNewProgressData,
  201. PDWORD pdwErrCode
  202. )
  203. /*++
  204. ++*/
  205. {
  206. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  207. switch( dwProgressCode )
  208. {
  209. case REQUEST_NEW:
  210. //
  211. // License Server ask to fine tune the request.
  212. //
  213. dwStatus = ProcessLicenseRequest(
  214. client,
  215. (PPMLICENSEREQUEST) pbProgressData,
  216. (PPMLICENSEREQUEST *) pbNewProgressData,
  217. pdwErrCode
  218. );
  219. break;
  220. case REQUEST_KEYPACKTYPE:
  221. //
  222. // License Server ask for the license pack type
  223. //
  224. dwStatus = ProcessAllocateRequest(
  225. client,
  226. #ifdef _WIN64
  227. PtrToUlong(pbProgressData),
  228. #else
  229. (DWORD) pbProgressData,
  230. #endif
  231. (PDWORD) pbNewProgressData,
  232. pdwErrCode
  233. );
  234. break;
  235. case REQUEST_TEMPORARY:
  236. //
  237. // License Server ask if temporary license should be issued
  238. //
  239. *(BOOL *)pbNewProgressData = TRUE;
  240. *pdwErrCode = ERROR_SUCCESS;
  241. break;
  242. case REQUEST_GENLICENSE:
  243. //
  244. // License Server ask for certificate extension
  245. //
  246. dwStatus = ProcessGenLicenses(
  247. client,
  248. (PPMGENERATELICENSE) pbProgressData,
  249. (PPMCERTEXTENSION *) pbNewProgressData,
  250. pdwErrCode
  251. );
  252. break;
  253. case REQUEST_COMPLETE:
  254. //
  255. // Request complete
  256. //
  257. dwStatus = ProcessComplete(
  258. client,
  259. #ifdef _WIN64
  260. PtrToUlong(pbNewProgressData),
  261. #else
  262. (DWORD) pbNewProgressData,
  263. #endif
  264. pdwErrCode
  265. );
  266. break;
  267. case REQUEST_KEYPACKDESC:
  268. if(pbNewProgressData != NULL)
  269. {
  270. *pbNewProgressData = NULL;
  271. }
  272. // FALL THRU
  273. default:
  274. *pdwErrCode = ERROR_SUCCESS;
  275. dwStatus = POLICY_SUCCESS;
  276. }
  277. return dwStatus;
  278. }
  279. //------------------------------------------------------------------------
  280. POLICYSTATUS
  281. ProcessUpgradeRequest(
  282. PMHANDLE hClient,
  283. PPMUPGRADEREQUEST pUpgrade,
  284. PPMLICENSEREQUEST* pbAdjustedRequest,
  285. PDWORD pdwRetCode
  286. )
  287. /*++
  288. ++*/
  289. {
  290. *pdwRetCode = ERROR_SUCCESS;
  291. *pbAdjustedRequest = pUpgrade->pUpgradeRequest;
  292. return POLICY_SUCCESS;
  293. }
  294. //------------------------------------------------------------------------
  295. POLICYSTATUS WINAPI
  296. PMLicenseUpgrade(
  297. PMHANDLE hClient,
  298. DWORD dwProgressCode,
  299. PVOID pbProgressData,
  300. PVOID *ppbReturnData,
  301. PDWORD pdwRetCode
  302. )
  303. /*++
  304. ++*/
  305. {
  306. POLICYSTATUS dwStatus = POLICY_SUCCESS;
  307. switch(dwProgressCode)
  308. {
  309. case REQUEST_UPGRADE:
  310. dwStatus = ProcessUpgradeRequest(
  311. hClient,
  312. (PPMUPGRADEREQUEST) pbProgressData,
  313. (PPMLICENSEREQUEST *) ppbReturnData,
  314. pdwRetCode
  315. );
  316. break;
  317. case REQUEST_COMPLETE:
  318. dwStatus = ProcessComplete(
  319. hClient,
  320. #ifdef _WIN64
  321. PtrToUlong(pbProgressData),
  322. #else
  323. (DWORD) (pbProgressData),
  324. #endif
  325. pdwRetCode
  326. );
  327. break;
  328. default:
  329. //assert(FALSE);
  330. *pdwRetCode = ERROR_SUCCESS;
  331. dwStatus = POLICY_SUCCESS;
  332. }
  333. return dwStatus;
  334. }
  335. //------------------------------------------------------------------------
  336. POLICYSTATUS WINAPI
  337. PMRegisterLicensePack(
  338. PMHANDLE hClient,
  339. DWORD dwProgressCode,
  340. PVOID pbProgressData,
  341. PVOID pbProgressReturnData,
  342. PDWORD pdwRetCode
  343. )
  344. /*++
  345. Not supported.
  346. --*/
  347. {
  348. *pdwRetCode = ERROR_INVALID_FUNCTION;
  349. return POLICY_NOT_SUPPORTED;
  350. }