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.

356 lines
9.0 KiB

  1. /**------------------------------------------------------------------
  2. class.c
  3. ------------------------------------------------------------------**/
  4. //
  5. // Includes
  6. //
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <wtypes.h>
  11. #include <cfgmgr32.h>
  12. #include "cmtest.h"
  13. //
  14. // Private Prototypes
  15. //
  16. BOOL
  17. FillClassListBox(
  18. HWND hDlg
  19. );
  20. BOOL
  21. GetSelectedClass(
  22. HWND hDlg,
  23. LPTSTR szClassGuid
  24. );
  25. REGSAM
  26. GetAccessMask(
  27. HWND hDlg
  28. );
  29. //
  30. // Globals
  31. //
  32. extern HINSTANCE hInst;
  33. extern TCHAR szDebug[MAX_PATH];
  34. extern TCHAR szAppName[MAX_PATH];
  35. extern HMACHINE hMachine;
  36. /**----------------------------------------------------------------------**/
  37. INT_PTR CALLBACK
  38. ClassDlgProc(
  39. HWND hDlg,
  40. UINT message,
  41. WPARAM wParam,
  42. LPARAM lParam
  43. )
  44. {
  45. CONFIGRET Status;
  46. ULONG Size;
  47. LONG Index;
  48. TCHAR szClassGuid[MAX_GUID_STRING_LEN];
  49. TCHAR szClassName[MAX_CLASS_NAME_LEN];
  50. switch (message) {
  51. case WM_INITDIALOG:
  52. if (!FillClassListBox(hDlg)) {
  53. EndDialog(hDlg, FALSE);
  54. }
  55. return TRUE;
  56. case WM_COMMAND:
  57. switch(LOWORD(wParam)) {
  58. case IDOK:
  59. EndDialog(hDlg, TRUE);
  60. return TRUE;
  61. case ID_LB_CLASSES:
  62. if (HIWORD(wParam) != LBN_DBLCLK) {
  63. break;
  64. }
  65. // if DBLCK, fall through to getting the classname
  66. case ID_BT_CLASSNAME:
  67. /*
  68. if (!GetSelectedClass(hDlg, szClassName)) {
  69. break;
  70. }
  71. Size = MAX_CLASS_NAME_LEN;
  72. Status = CM_Get_Class_Name_Ex(
  73. &ClassGuid, szClassName, &Size, 0, hMachine);
  74. if (Status != CR_SUCCESS) {
  75. wsprintf(szDebug,
  76. TEXT("CM_Get_Class_Name failed (%xh)"), Status);
  77. MessageBox(hDlg, szDebug, szAppName, MB_OK);
  78. EndDialog(hDlg, FALSE);
  79. }
  80. SetDlgItemText(hDlg, ID_ST_CLASSNAME, szClassName);
  81. */
  82. break;
  83. case ID_BT_CLASSKEY:
  84. if (!GetSelectedClass(hDlg, szClassName)) {
  85. break;
  86. }
  87. DialogBoxParam(hInst, MAKEINTRESOURCE(CLASSKEY_DIALOG), hDlg,
  88. ClassKeyDlgProc, (LPARAM)(LPCTSTR)szClassName);
  89. break;
  90. default:
  91. break;
  92. }
  93. }
  94. return FALSE;
  95. } // ClassDlgProc
  96. /**----------------------------------------------------------------------**/
  97. BOOL CALLBACK
  98. ClassKeyDlgProc(
  99. HWND hDlg,
  100. UINT message,
  101. WPARAM wParam,
  102. LPARAM lParam
  103. )
  104. {
  105. CONFIGRET Status;
  106. REGSAM rsAccess;
  107. ULONG ulDisp, ulSize;
  108. TCHAR szClassGuid[MAX_PATH];
  109. TCHAR szValueName[MAX_PATH];
  110. TCHAR szValueData[MAX_PATH];
  111. LONG RegStatus;
  112. HKEY hKey;
  113. GUID ClassGuid;
  114. switch (message) {
  115. case WM_INITDIALOG:
  116. SetDlgItemText(hDlg, ID_ST_CLASSGUID, (LPCTSTR)lParam);
  117. return TRUE;
  118. case WM_COMMAND:
  119. switch(LOWORD(wParam)) {
  120. case IDOK:
  121. EndDialog(hDlg, TRUE);
  122. return TRUE;
  123. case ID_BT_QUERYVALUE:
  124. GetDlgItemText(hDlg, ID_ST_CLASSGUID, szClassGuid, MAX_PATH);
  125. rsAccess = GetAccessMask(hDlg);
  126. if (IsDlgButtonChecked(hDlg, ID_CHK_CREATE)) {
  127. ulDisp = RegDisposition_OpenAlways;
  128. }
  129. else {
  130. ulDisp = RegDisposition_OpenExisting;
  131. }
  132. Status = CM_Open_Class_Key_Ex(
  133. &ClassGuid, NULL, rsAccess, ulDisp, &hKey, 0, hMachine);
  134. if (Status != CR_SUCCESS) {
  135. wsprintf(szDebug,
  136. TEXT("CM_Open_Class_Key failed (%xh)"), Status);
  137. MessageBox(hDlg, szDebug, szAppName, MB_OK);
  138. EndDialog(hDlg, FALSE);
  139. }
  140. GetDlgItemText(hDlg, ID_ED_VALUENAME, szValueName, MAX_PATH);
  141. RegStatus = RegQueryValueEx(hKey, szValueName, NULL, NULL,
  142. (LPBYTE)szValueData, &ulSize);
  143. if (RegStatus == ERROR_SUCCESS) {
  144. SetDlgItemText(hDlg, ID_ED_VALUEDATA, szValueData);
  145. }
  146. else {
  147. MessageBeep(0);
  148. }
  149. RegCloseKey(hKey);
  150. break;
  151. case ID_BT_SETVALUE:
  152. GetDlgItemText(hDlg, ID_ST_CLASSGUID, szClassGuid, MAX_PATH);
  153. rsAccess = GetAccessMask(hDlg);
  154. if (IsDlgButtonChecked(hDlg, ID_CHK_CREATE)) {
  155. ulDisp = RegDisposition_OpenAlways;
  156. }
  157. else {
  158. ulDisp = RegDisposition_OpenExisting;
  159. }
  160. Status = CM_Open_Class_Key_Ex(
  161. &ClassGuid, NULL, rsAccess, ulDisp, &hKey, 0, hMachine);
  162. if (Status != CR_SUCCESS) {
  163. wsprintf(szDebug,
  164. TEXT("CM_Open_Class_Key failed (%xh)"), Status);
  165. MessageBox(hDlg, szDebug, szAppName, MB_OK);
  166. EndDialog(hDlg, FALSE);
  167. }
  168. GetDlgItemText(hDlg, ID_ED_VALUENAME, szValueName, MAX_PATH);
  169. GetDlgItemText(hDlg, ID_ED_VALUEDATA, szValueData, MAX_PATH);
  170. RegStatus = RegSetValueEx(hKey, szValueName, 0, REG_SZ,
  171. (LPBYTE)szValueData,
  172. (lstrlen(szValueData)+1) * sizeof(TCHAR));
  173. if (RegStatus != ERROR_SUCCESS) {
  174. MessageBeep(0);
  175. }
  176. RegCloseKey(hKey);
  177. break;
  178. default:
  179. break;
  180. }
  181. }
  182. return FALSE;
  183. } // ClassKeyDlgProc
  184. /**----------------------------------------------------------------------**/
  185. BOOL
  186. FillClassListBox(
  187. HWND hDlg
  188. )
  189. {
  190. CONFIGRET Status;
  191. ULONG ulIndex, Size;
  192. GUID ClassGuid;
  193. TCHAR szClassGuid[MAX_CLASS_NAME_LEN];
  194. SendDlgItemMessage(
  195. hDlg, ID_LB_CLASSES, LB_RESETCONTENT, 0, 0);
  196. SendDlgItemMessage(
  197. hDlg, ID_LB_CLASSES, LB_ADDSTRING, 0,
  198. (LPARAM)(LPCTSTR)TEXT("(Root)"));
  199. ulIndex = 0;
  200. Status = CR_SUCCESS;
  201. while (Status == CR_SUCCESS) {
  202. Status = CM_Enumerate_Classes_Ex(
  203. ulIndex, &ClassGuid, 0, hMachine);
  204. if (Status == CR_NO_SUCH_VALUE) {
  205. // no more classes, break out of the look
  206. break;
  207. }
  208. if (Status != CR_SUCCESS) {
  209. wsprintf(szDebug, TEXT("CM_Enumerate_Classes failed (%xh)"), Status);
  210. MessageBox(hDlg, szDebug, szAppName, MB_OK);
  211. return FALSE;
  212. }
  213. Size = MAX_CLASS_NAME_LEN;
  214. Status = CM_Get_Class_Name_Ex(
  215. &ClassGuid, szClassGuid, &Size, 0, hMachine);
  216. if (Status != CR_SUCCESS) {
  217. wsprintf(szDebug, TEXT("CM_Get_Class_Name failed (%xh)"), Status);
  218. MessageBox(hDlg, szDebug, szAppName, MB_OK);
  219. return FALSE;
  220. }
  221. SendDlgItemMessage(
  222. hDlg, ID_LB_CLASSES, LB_ADDSTRING, 0,
  223. (LPARAM)(LPCTSTR)szClassGuid);
  224. ulIndex++;
  225. }
  226. return TRUE;
  227. } // FillClassListBox
  228. /**----------------------------------------------------------------------**/
  229. BOOL
  230. GetSelectedClass(
  231. HWND hDlg,
  232. LPTSTR szClassName
  233. )
  234. {
  235. LONG Index;
  236. Index = SendDlgItemMessage(
  237. hDlg, ID_LB_CLASSES, LB_GETCURSEL, 0, 0);
  238. if (Index == LB_ERR || Index == 0) {
  239. MessageBeep(0);
  240. return FALSE;
  241. }
  242. SendDlgItemMessage(
  243. hDlg, ID_LB_CLASSES, LB_GETTEXT, (WPARAM)Index,
  244. (LPARAM)(LPCTSTR)szClassName);
  245. if (lstrcmpi(szClassName, TEXT("Root")) == 0) {
  246. *szClassName = '\0'; // if Root selected, then no class specified
  247. }
  248. return TRUE;
  249. } // GetSeletectedClass
  250. /**----------------------------------------------------------------------**/
  251. REGSAM
  252. GetAccessMask(
  253. HWND hDlg
  254. )
  255. {
  256. REGSAM rsAccess = 0;
  257. if (IsDlgButtonChecked(hDlg, ID_CHK_ALL_ACCESS)) {
  258. rsAccess |= KEY_ALL_ACCESS;
  259. }
  260. if (IsDlgButtonChecked(hDlg, ID_CHK_CREATE_LINK)) {
  261. rsAccess |= KEY_CREATE_LINK;
  262. }
  263. if (IsDlgButtonChecked(hDlg, ID_CHK_CREATE_SUB_KEY)) {
  264. rsAccess |= KEY_CREATE_SUB_KEY;
  265. }
  266. if (IsDlgButtonChecked(hDlg, ID_CHK_ENUMERATE_SUB_KEYS)) {
  267. rsAccess |= KEY_ENUMERATE_SUB_KEYS;
  268. }
  269. if (IsDlgButtonChecked(hDlg, ID_CHK_EXECUTE)) {
  270. rsAccess |= KEY_EXECUTE;
  271. }
  272. if (IsDlgButtonChecked(hDlg, ID_CHK_NOTIFY)) {
  273. rsAccess |= KEY_NOTIFY;
  274. }
  275. if (IsDlgButtonChecked(hDlg, ID_CHK_QUERY_VALUE)) {
  276. rsAccess |= KEY_QUERY_VALUE;
  277. }
  278. if (IsDlgButtonChecked(hDlg, ID_CHK_READ)) {
  279. rsAccess |= KEY_READ;
  280. }
  281. if (IsDlgButtonChecked(hDlg, ID_CHK_SET_VALUE)) {
  282. rsAccess |= KEY_SET_VALUE;
  283. }
  284. if (IsDlgButtonChecked(hDlg, ID_CHK_WRITE)) {
  285. rsAccess |= KEY_WRITE;
  286. }
  287. return rsAccess;
  288. } // GetAccessMask