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.

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