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.

549 lines
15 KiB

  1. //-------------------------------------------------------------------
  2. //
  3. // FILE: special.cpp
  4. //
  5. // Summary; This file contians the dialogs for the MSDN version of
  6. // the control panel applet and setup entry points.
  7. //
  8. // History;
  9. // Jun-26-95 MikeMi Created
  10. //
  11. //-------------------------------------------------------------------
  12. #include <windows.h>
  13. #include "resource.h"
  14. #include "CLicReg.hpp"
  15. #include <stdlib.h>
  16. #include <htmlhelp.h>
  17. #include "liccpa.hpp"
  18. #include "PriDlgs.hpp"
  19. #include "SecDlgs.hpp"
  20. #include "Special.hpp"
  21. #include "sbs_res.h"
  22. SPECIALVERSIONINFO gSpecVerInfo;
  23. //-------------------------------------------------------------------
  24. //
  25. // Function: InitSpecialVersionInfo
  26. //
  27. // Summary: Initialize global data if liccpa is launched as
  28. // a special version (eg: restricted SAM, NFR, etc).
  29. //
  30. // Arguments: None.
  31. //
  32. // History: Oct-07-97 MarkBl Created
  33. //
  34. //-------------------------------------------------------------------
  35. void InitSpecialVersionInfo( void )
  36. {
  37. //
  38. // If the SPECIALVERSION manifest is defined, initialize the
  39. // global data from the specifc manifests defined for the special
  40. // version.
  41. //
  42. // TBD : These special versions should change to be detected at
  43. // runtime vs. building a special version of liccpa.
  44. //
  45. #ifdef SPECIALVERSION
  46. gSpecVerInfo.idsSpecVerWarning = IDS_SPECVER_WARNING;
  47. gSpecVerInfo.idsSpecVerText1 = IDS_SPECVER_TEXT1;
  48. gSpecVerInfo.idsSpecVerText2 = IDS_SPECVER_TEXT2;
  49. gSpecVerInfo.dwSpecialUsers = SPECIAL_USERS;
  50. gSpecVerInfo.lmSpecialMode = SPECIAL_MODE;
  51. #else
  52. ZeroMemory(&gSpecVerInfo, sizeof(gSpecVerInfo));
  53. #endif // SPECIALVERSION
  54. //
  55. // Special versions of liccpa detected at runtime.
  56. //
  57. // Currently, small business server only.
  58. //
  59. if (IsRestrictedSmallBusSrv())
  60. {
  61. gSpecVerInfo.dwSpecialUsers = GetSpecialUsers();
  62. //
  63. // Check for small business server NFR.
  64. //
  65. if (gSpecVerInfo.dwSpecialUsers == SAM_NFR_LICENSE_COUNT)
  66. {
  67. gSpecVerInfo.idsSpecVerWarning = IDS_SAMNFR_NOTAVAILABLE;
  68. gSpecVerInfo.idsSpecVerText1 = IDS_SAMNFR_TEXT1;
  69. gSpecVerInfo.idsSpecVerText2 = IDS_SAMNFR_TEXT2;
  70. gSpecVerInfo.lmSpecialMode = LICMODE_PERSERVER;
  71. }
  72. else
  73. {
  74. gSpecVerInfo.idsSpecVerWarning = IDS_SAM_NOTAVAILABLE;
  75. gSpecVerInfo.idsSpecVerText1 = IDS_SAM_TEXT1;
  76. gSpecVerInfo.idsSpecVerText2 = IDS_SAM_TEXT2;
  77. gSpecVerInfo.lmSpecialMode = LICMODE_PERSERVER;
  78. }
  79. }
  80. }
  81. //-------------------------------------------------------------------
  82. //
  83. // Function: RaiseNotAvailWarning
  84. //
  85. // Summary;
  86. // Raise the special not available with this version warning
  87. //
  88. // Arguments;
  89. // hwndDlg [in] - hwnd of control dialog
  90. //
  91. // History;
  92. // Jun-26-95 MikeMi Created
  93. //
  94. //-------------------------------------------------------------------
  95. void RaiseNotAvailWarning( HWND hwndCPL )
  96. {
  97. TCHAR pszText[LTEMPSTR_SIZE];
  98. TCHAR pszTitle[TEMPSTR_SIZE];
  99. HINSTANCE hSbsLib = NULL;
  100. if ( (gSpecVerInfo.idsSpecVerWarning == IDS_SAMNFR_NOTAVAILABLE)
  101. && (hSbsLib = LoadLibrary( SBS_RESOURCE_DLL )) )
  102. {
  103. LoadString( hSbsLib, SBS_License_Error, pszText, TEMPSTR_SIZE );
  104. }
  105. else
  106. {
  107. LoadString( g_hinst, gSpecVerInfo.idsSpecVerWarning, pszText,
  108. TEMPSTR_SIZE );
  109. }
  110. LoadString( g_hinst, IDS_CPATITLE, pszTitle, TEMPSTR_SIZE );
  111. MessageBox( hwndCPL, pszText, pszTitle, MB_ICONINFORMATION | MB_OK );
  112. }
  113. //-------------------------------------------------------------------
  114. void SetStaticWithService( HWND hwndDlg, UINT idcStatic, LPTSTR psService, UINT idsText )
  115. {
  116. WCHAR szText[LTEMPSTR_SIZE];
  117. WCHAR szTemp[LTEMPSTR_SIZE];
  118. LoadString( g_hinst, idsText, szTemp, LTEMPSTR_SIZE );
  119. wsprintf( szText, szTemp, psService );
  120. SetDlgItemText( hwndDlg, idcStatic, szText );
  121. }
  122. //-------------------------------------------------------------------
  123. void SetStaticUsers( HWND hwndDlg, UINT idcStatic, DWORD users, UINT idsText )
  124. {
  125. WCHAR szText[LTEMPSTR_SIZE];
  126. WCHAR szTemp[LTEMPSTR_SIZE];
  127. LoadString( g_hinst, idsText, szTemp, LTEMPSTR_SIZE );
  128. wsprintf( szText, szTemp, users );
  129. SetDlgItemText( hwndDlg, idcStatic, szText );
  130. }
  131. //-------------------------------------------------------------------
  132. //
  133. // Function: OnSpecialInitDialog
  134. //
  135. // Summary;
  136. // Handle the initialization of the Special only Setup Dialog
  137. //
  138. // Arguments;
  139. // hwndDlg [in] - the dialog to initialize
  140. // psdParams [in] - used for the displayname and service name
  141. //
  142. // Notes;
  143. //
  144. // History;
  145. // Dec-08-1994 MikeMi Created
  146. //
  147. //-------------------------------------------------------------------
  148. void OnSpecialInitDialog( HWND hwndDlg, PSETUPDLGPARAM psdParams )
  149. {
  150. HWND hwndOK = GetDlgItem( hwndDlg, IDOK );
  151. CLicRegLicense cLicKey;
  152. BOOL fNew;
  153. LONG lrt;
  154. INT nrt;
  155. lrt = cLicKey.Open( fNew, psdParams->pszComputer );
  156. nrt = AccessOk( NULL, lrt, FALSE );
  157. if (ERR_NONE == nrt)
  158. {
  159. CenterDialogToScreen( hwndDlg );
  160. SetStaticWithService( hwndDlg,
  161. IDC_STATICTITLE,
  162. psdParams->pszDisplayName,
  163. gSpecVerInfo.idsSpecVerText1 );
  164. if (IsRestrictedSmallBusSrv())
  165. {
  166. SetStaticUsers( hwndDlg,
  167. IDC_STATICINFO,
  168. gSpecVerInfo.dwSpecialUsers,
  169. gSpecVerInfo.idsSpecVerText2 );
  170. }
  171. else
  172. {
  173. SetStaticWithService( hwndDlg,
  174. IDC_STATICINFO,
  175. psdParams->pszDisplayName,
  176. gSpecVerInfo.idsSpecVerText2 );
  177. }
  178. // disable OK button at start!
  179. EnableWindow( hwndOK, FALSE );
  180. // if help is not defined, remove the button
  181. if (NULL == psdParams->pszHelpFile)
  182. {
  183. HWND hwndHelp = GetDlgItem( hwndDlg, IDC_BUTTONHELP );
  184. EnableWindow( hwndHelp, FALSE );
  185. ShowWindow( hwndHelp, SW_HIDE );
  186. }
  187. if (psdParams->fNoExit)
  188. {
  189. HWND hwndExit = GetDlgItem( hwndDlg, IDCANCEL );
  190. // remove the ExitSetup button
  191. EnableWindow( hwndExit, FALSE );
  192. ShowWindow( hwndExit, SW_HIDE );
  193. }
  194. }
  195. else
  196. {
  197. EndDialog( hwndDlg, nrt );
  198. }
  199. }
  200. //-------------------------------------------------------------------
  201. //
  202. // Function: OnSpecialSetupClose
  203. //
  204. // Summary;
  205. // Do work needed when the Setup Dialog is closed.
  206. // Save to Reg the Service entry.
  207. //
  208. // Arguments;
  209. // hwndDlg [in] - hwnd of dialog this close was requested on
  210. // fSave [in] - Save service to registry
  211. // psdParams [in] - used for the service name and displayname
  212. //
  213. // History;
  214. // Nov-30-94 MikeMi Created
  215. //
  216. //-------------------------------------------------------------------
  217. void OnSpecialSetupClose( HWND hwndDlg, BOOL fSave, PSETUPDLGPARAM psdParams )
  218. {
  219. int nrt = fSave;
  220. if (fSave)
  221. {
  222. CLicRegLicenseService cLicServKey;
  223. cLicServKey.SetService( psdParams->pszService );
  224. cLicServKey.Open( psdParams->pszComputer );
  225. // configure license rule of one change from PerServer to PerSeat
  226. //
  227. cLicServKey.SetChangeFlag( TRUE );
  228. cLicServKey.SetMode( gSpecVerInfo.lmSpecialMode );
  229. cLicServKey.SetUserLimit( gSpecVerInfo.dwSpecialUsers );
  230. cLicServKey.SetDisplayName( psdParams->pszDisplayName );
  231. cLicServKey.SetFamilyDisplayName( psdParams->pszFamilyDisplayName );
  232. cLicServKey.Close();
  233. }
  234. EndDialog( hwndDlg, nrt );
  235. }
  236. //-------------------------------------------------------------------
  237. //
  238. // Function: OnSpecialAgree
  239. //
  240. // Summary;
  241. // Handle the user interaction with the Agree Check box
  242. //
  243. // Arguments;
  244. // hwndDlg [in] - the dialog to initialize
  245. //
  246. // Return;
  247. // TRUE if succesful, otherwise false
  248. //
  249. // Notes;
  250. //
  251. // History;
  252. // Nov-11-1994 MikeMi Created
  253. //
  254. //-------------------------------------------------------------------
  255. void OnSpecialAgree( HWND hwndDlg )
  256. {
  257. HWND hwndOK = GetDlgItem( hwndDlg, IDOK );
  258. BOOL fChecked = !IsDlgButtonChecked( hwndDlg, IDC_AGREE );
  259. CheckDlgButton( hwndDlg, IDC_AGREE, fChecked );
  260. EnableWindow( hwndOK, fChecked );
  261. }
  262. //-------------------------------------------------------------------
  263. //
  264. // Function: dlgprocSPECIALSETUP
  265. //
  266. // Summary;
  267. // The dialog procedure for the special version Setup Dialog,
  268. // which will replace all others
  269. //
  270. // Arguments;
  271. // hwndDlg [in] - handle of Dialog window
  272. // uMsg [in] - message
  273. // lParam1 [in] - first message parameter
  274. // lParam2 [in] - second message parameter
  275. //
  276. // Return;
  277. // message dependant
  278. //
  279. // Notes;
  280. //
  281. // History;
  282. // Jun-26-1995 MikeMi Created
  283. //
  284. //-------------------------------------------------------------------
  285. INT_PTR CALLBACK dlgprocSPECIALSETUP( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  286. {
  287. BOOL frt = FALSE;
  288. static PSETUPDLGPARAM psdParams;
  289. switch (uMsg)
  290. {
  291. case WM_INITDIALOG:
  292. psdParams = (PSETUPDLGPARAM)lParam;
  293. OnSpecialInitDialog( hwndDlg, psdParams );
  294. frt = TRUE; // we use the default focus
  295. break;
  296. case WM_COMMAND:
  297. switch (HIWORD( wParam ))
  298. {
  299. case BN_CLICKED:
  300. switch (LOWORD( wParam ))
  301. {
  302. case IDOK:
  303. frt = TRUE; // use as save flag
  304. // intentional no break
  305. case IDCANCEL:
  306. OnSpecialSetupClose( hwndDlg, frt, psdParams );
  307. frt = FALSE;
  308. break;
  309. case IDC_BUTTONHELP:
  310. PostMessage( hwndDlg, PWM_HELP, 0, 0 );
  311. break;
  312. case IDC_AGREE:
  313. OnSpecialAgree( hwndDlg );
  314. break;
  315. default:
  316. break;
  317. }
  318. break;
  319. default:
  320. break;
  321. }
  322. break;
  323. default:
  324. if (PWM_HELP == uMsg)
  325. {
  326. ::HtmlHelp( hwndDlg,
  327. LICCPA_HTMLHELPFILE,
  328. HH_DISPLAY_TOPIC,
  329. 0);
  330. }
  331. break;
  332. }
  333. return( frt );
  334. }
  335. //-------------------------------------------------------------------
  336. //
  337. // Function: SpecialSetupDialog
  338. //
  339. // Summary;
  340. // Init and raises Per Seat only setup dialog.
  341. //
  342. // Arguments;
  343. // hwndDlg [in] - handle of Dialog window
  344. // dlgParem [in] - Setup params IDC_BUTTONHELP
  345. //
  346. // Return;
  347. // 1 - OK button was used to exit
  348. // 0 - Cancel button was used to exit
  349. // -1 - General Dialog error
  350. //
  351. // Notes;
  352. //
  353. // History;
  354. // Dec-05-1994 MikeMi Created
  355. //
  356. //-------------------------------------------------------------------
  357. INT_PTR SpecialSetupDialog( HWND hwndParent, SETUPDLGPARAM& dlgParam )
  358. {
  359. return( DialogBoxParam( g_hinst,
  360. MAKEINTRESOURCE(IDD_SPECIALSETUP),
  361. hwndParent,
  362. dlgprocSPECIALSETUP,
  363. (LPARAM)&dlgParam ) );
  364. }
  365. //-------------------------------------------------------------------
  366. //
  367. // Function: GetSpecialUsers
  368. //
  369. // Summary;
  370. // Gets the number of licensed users from the registry.
  371. //
  372. // Arguments;
  373. // none
  374. // Return;
  375. // The number of licensed users
  376. //
  377. // Notes;
  378. //
  379. // History;
  380. // Aug-18-97 GeorgeJe Created
  381. //
  382. //-------------------------------------------------------------------
  383. DWORD GetSpecialUsers( VOID )
  384. {
  385. LONG rVal;
  386. DWORD Disposition;
  387. HKEY hKey;
  388. DWORD Type;
  389. DWORD Size = sizeof(DWORD);
  390. DWORD Value;
  391. rVal = RegCreateKeyEx(
  392. HKEY_LOCAL_MACHINE,
  393. REGKEY_LICENSEINFO_SBS,
  394. 0,
  395. NULL,
  396. REG_OPTION_NON_VOLATILE,
  397. KEY_READ,
  398. NULL,
  399. &hKey,
  400. &Disposition
  401. );
  402. if (rVal != ERROR_SUCCESS) {
  403. return DEFAULT_SPECIAL_USERS;
  404. }
  405. rVal = RegQueryValueEx(
  406. hKey,
  407. REGVAL_CONCURRENT_LIMIT,
  408. 0,
  409. &Type,
  410. (LPBYTE) &Value,
  411. &Size
  412. );
  413. RegCloseKey( hKey );
  414. return (rVal == ERROR_SUCCESS ? Value : DEFAULT_SPECIAL_USERS);
  415. }
  416. const WCHAR wszProductOptions[] =
  417. L"System\\CurrentControlSet\\Control\\ProductOptions";
  418. const WCHAR wszProductSuite[] =
  419. L"ProductSuite";
  420. const WCHAR wszSBSRestricted[] =
  421. L"Small Business(Restricted)";
  422. BOOL IsRestrictedSmallBusSrv( void )
  423. /*++
  424. Routine Description:
  425. Check if this server is a Microsoft small business restricted server.
  426. Arguments:
  427. None.
  428. Return Values:
  429. TRUE -- This server is a restricted small business server.
  430. FALSE -- No such restriction.
  431. --*/
  432. {
  433. WCHAR wszBuffer[1024] = L"";
  434. DWORD cbBuffer = sizeof(wszBuffer);
  435. DWORD dwType;
  436. LPWSTR pwszSuite;
  437. HKEY hKey;
  438. BOOL bRet = FALSE;
  439. //
  440. // Check if this server is a Microsoft small business restricted server.
  441. // Do so by checking for the existence of the string
  442. // "Small Business(Restricted)"
  443. // in the MULTI_SZ "ProductSuite" value under
  444. // HKLM\CurrentCcntrolSet\Control\ProductOptions.
  445. //
  446. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  447. wszProductOptions,
  448. 0,
  449. KEY_READ,
  450. &hKey) == ERROR_SUCCESS)
  451. {
  452. if (RegQueryValueEx(hKey,
  453. wszProductSuite,
  454. NULL,
  455. &dwType,
  456. (LPBYTE)wszBuffer,
  457. &cbBuffer) == ERROR_SUCCESS)
  458. {
  459. if (dwType == REG_MULTI_SZ && *wszBuffer)
  460. {
  461. pwszSuite = wszBuffer;
  462. while (*pwszSuite)
  463. {
  464. if (lstrcmpi(pwszSuite, wszSBSRestricted) == 0)
  465. {
  466. bRet = TRUE;
  467. break;
  468. }
  469. pwszSuite += wcslen(pwszSuite) + 1;
  470. }
  471. }
  472. }
  473. RegCloseKey(hKey);
  474. }
  475. return bRet;
  476. }