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.

339 lines
8.0 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. #include "admincfg.h"
  6. #include "grouppri.h"
  7. #ifdef INCL_GROUP_SUPPORT
  8. GROUPPRIENTRY * pGroupPriEntryFirst = NULL; // head of linked list
  9. INT_PTR CALLBACK GroupPriorityDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  10. LPARAM lParam);
  11. extern HIMAGELIST hImageListSmall;
  12. VOID EnableDlgButtons(HWND hDlg);
  13. GROUPPRIENTRY * FindGroupPriEntry(TCHAR * pszGroupName)
  14. {
  15. GROUPPRIENTRY * pGroupPriEntry = pGroupPriEntryFirst;
  16. while (pGroupPriEntry) {
  17. if (!lstrcmpi(pszGroupName,pGroupPriEntry->pszGroupName))
  18. return pGroupPriEntry;
  19. pGroupPriEntry = pGroupPriEntry->pNext;
  20. }
  21. return NULL;
  22. }
  23. BOOL AddGroupPriEntry(TCHAR * pszGroupName)
  24. {
  25. GROUPPRIENTRY * pGroupPriEntryNew;
  26. if (FindGroupPriEntry(pszGroupName))
  27. return TRUE; // already in list
  28. pGroupPriEntryNew = (GROUPPRIENTRY * ) GlobalAlloc(GPTR,sizeof(GROUPPRIENTRY)
  29. + ((lstrlen(pszGroupName) + 1) * sizeof(TCHAR)));
  30. if (!pGroupPriEntryNew)
  31. return FALSE; // out of memory
  32. pGroupPriEntryNew->pNext = NULL;
  33. pGroupPriEntryNew->pszGroupName = ((LPBYTE) pGroupPriEntryNew)
  34. + sizeof(GROUPPRIENTRY);
  35. lstrcpy(pGroupPriEntryNew->pszGroupName,pszGroupName);
  36. if (!pGroupPriEntryFirst) {
  37. pGroupPriEntryFirst = pGroupPriEntryNew;
  38. pGroupPriEntryNew->pPrev = NULL;
  39. } else {
  40. // attach to end of linked list
  41. GROUPPRIENTRY * pGroupPriEntryLast = pGroupPriEntryFirst;
  42. while (pGroupPriEntryLast->pNext)
  43. pGroupPriEntryLast=pGroupPriEntryLast->pNext;
  44. pGroupPriEntryLast->pNext = pGroupPriEntryNew;
  45. pGroupPriEntryNew->pPrev = pGroupPriEntryLast;
  46. }
  47. return TRUE;
  48. }
  49. BOOL RemoveGroupPriEntry(TCHAR * pszGroupName)
  50. {
  51. GROUPPRIENTRY * pGroupPriEntry;
  52. if (!(pGroupPriEntry=FindGroupPriEntry(pszGroupName)))
  53. return FALSE;
  54. // fix up linked list
  55. if (pGroupPriEntry == pGroupPriEntryFirst)
  56. pGroupPriEntryFirst = pGroupPriEntry->pNext;
  57. if (pGroupPriEntry->pPrev)
  58. (pGroupPriEntry->pPrev)->pNext = pGroupPriEntry->pNext;
  59. if (pGroupPriEntry->pNext)
  60. (pGroupPriEntry->pNext)->pPrev = pGroupPriEntry->pPrev;
  61. GlobalFree(pGroupPriEntry);
  62. return TRUE;
  63. }
  64. VOID FreeGroupPriorityList( VOID )
  65. {
  66. GROUPPRIENTRY * pGroupPriEntry=pGroupPriEntryFirst,* pGroupPriEntryNext;
  67. while (pGroupPriEntry) {
  68. pGroupPriEntryNext = pGroupPriEntry->pNext;
  69. GlobalFree(pGroupPriEntry);
  70. pGroupPriEntry = pGroupPriEntryNext;
  71. }
  72. pGroupPriEntryFirst = NULL;
  73. }
  74. UINT LoadGroupPriorityList(HKEY hkeyPriority,HKEY hkeyGroup)
  75. {
  76. TCHAR szValueName[10],szGroupName[USERNAMELEN+1];
  77. UINT uGroupIndex=1,uErr = ERROR_SUCCESS;
  78. DWORD dwSize;
  79. FreeGroupPriorityList();
  80. while (uErr == ERROR_SUCCESS) {
  81. wsprintf(szValueName,TEXT("%lu"),uGroupIndex);
  82. dwSize = ARRAYSIZE(szGroupName) * sizeof(TCHAR);
  83. uErr = RegQueryValueEx(hkeyPriority,szValueName,NULL,NULL,szGroupName,
  84. &dwSize);
  85. if (uErr == ERROR_SUCCESS) {
  86. HKEY hkeyTmp;
  87. // as sanity check: only add group priority entry if we find an
  88. // entry for group in policy file
  89. if (RegOpenKey(hkeyGroup,szGroupName,&hkeyTmp) == ERROR_SUCCESS) {
  90. RegCloseKey(hkeyTmp);
  91. if (!AddGroupPriEntry(szGroupName))
  92. return ERROR_NOT_ENOUGH_MEMORY;
  93. }
  94. }
  95. uGroupIndex++;
  96. }
  97. return ERROR_SUCCESS;
  98. }
  99. UINT SaveGroupPriorityList(HKEY hKey)
  100. {
  101. GROUPPRIENTRY * pGroupPriEntry = pGroupPriEntryFirst;
  102. UINT uRet;
  103. DWORD cbValueName;
  104. TCHAR szValueName[MAX_PATH+1];
  105. UINT uGroupIndex=1;
  106. // erase all values for this key, first off
  107. while (TRUE) {
  108. cbValueName=ARRAYSIZE(szValueName);
  109. uRet=RegEnumValue(hKey,0,szValueName,&cbValueName,NULL,
  110. NULL,NULL,NULL);
  111. // stop if we're out of items
  112. if (uRet != ERROR_SUCCESS && uRet != ERROR_MORE_DATA)
  113. break;
  114. RegDeleteValue(hKey,szValueName);
  115. }
  116. uRet = ERROR_SUCCESS;
  117. while (pGroupPriEntry) {
  118. wsprintf(szValueName,TEXT("%lu"),uGroupIndex);
  119. uRet = RegSetValueEx(hKey,szValueName,0,REG_SZ,pGroupPriEntry->pszGroupName,
  120. ((lstrlen(pGroupPriEntry->pszGroupName)+1) * sizeof(TCHAR)));
  121. if (uRet != ERROR_SUCCESS) {
  122. return uRet;
  123. }
  124. uGroupIndex++;
  125. pGroupPriEntry = pGroupPriEntry->pNext;
  126. }
  127. return uRet;
  128. }
  129. BOOL OnGroupPriority(HWND hWnd)
  130. {
  131. return (BOOL)DialogBox(ghInst,MAKEINTRESOURCE(DLG_GROUPPRIORITY),hWnd,
  132. GroupPriorityDlgProc);
  133. }
  134. BOOL InitGroupPriorityDlg(HWND hDlg)
  135. {
  136. GROUPPRIENTRY * pGroupPriEntry = pGroupPriEntryFirst;
  137. LV_ITEM lvi;
  138. HWND hwndList = GetDlgItem(hDlg,IDD_GROUPORDER);
  139. LV_COLUMN lvc;
  140. lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  141. lvc.fmt = LVCFMT_LEFT;
  142. lvc.cx = 150;
  143. lvc.pszText = (LPTSTR) szNull;
  144. lvc.cchTextMax = 1;
  145. lvc.iSubItem = 0;
  146. ListView_InsertColumn(hwndList,0,&lvc);
  147. SetWindowLong(hwndList,GWL_EXSTYLE,WS_EX_CLIENTEDGE);
  148. SetScrollRange(hwndList,SB_VERT,0,100,TRUE);
  149. SetScrollRange(hwndList,SB_VERT,0,0,TRUE);
  150. ListView_SetImageList(hwndList,hImageListSmall,LVSIL_SMALL);
  151. lvi.iItem =lvi.iSubItem=0;
  152. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  153. lvi.iImage = IMG_USERS;
  154. // insert members of group list into listbox in current priority order
  155. while (pGroupPriEntry) {
  156. lvi.pszText = pGroupPriEntry->pszGroupName;
  157. lvi.cchTextMax = lstrlen(lvi.pszText) + 1;
  158. lvi.lParam = (LPARAM) pGroupPriEntry; // save pointer to node in lparam
  159. ListView_InsertItem(hwndList,&lvi);
  160. lvi.iItem ++;
  161. pGroupPriEntry = pGroupPriEntry->pNext;
  162. }
  163. EnableDlgButtons(hDlg);
  164. return TRUE;
  165. }
  166. VOID EnableDlgButtons(HWND hDlg)
  167. {
  168. HWND hwndList = GetDlgItem(hDlg,IDD_GROUPORDER);
  169. int nItem;
  170. BOOL fMoveUpOK=FALSE,fMoveDownOK=FALSE;
  171. // if item is selected, enable up/down buttons appropriately
  172. nItem=ListView_GetNextItem(hwndList,-1,LVNI_SELECTED);
  173. if (nItem >=0) {
  174. if (nItem > 0)
  175. fMoveUpOK = TRUE;
  176. if (nItem < ListView_GetItemCount(hwndList) -1)
  177. fMoveDownOK = TRUE;
  178. }
  179. EnableDlgItem(hDlg,IDD_MOVEUP,fMoveUpOK);
  180. EnableDlgItem(hDlg,IDD_MOVEDOWN,fMoveDownOK);
  181. }
  182. VOID MoveGroupItem(HWND hDlg,int iDelta)
  183. {
  184. HWND hwndList = GetDlgItem(hDlg,IDD_GROUPORDER);
  185. LV_ITEM lvi;
  186. TCHAR szText[MAX_PATH+1];
  187. lvi.iItem=ListView_GetNextItem(hwndList,-1,LVNI_SELECTED);
  188. if (lvi.iItem <0)
  189. return;
  190. lvi.iSubItem = 0;
  191. lvi.mask = LVIF_ALL;
  192. lvi.pszText = szText;
  193. lvi.cchTextMax = ARRAYSIZE(szText)+1;
  194. if (ListView_GetItem(hwndList,&lvi)) {
  195. ListView_DeleteItem(hwndList,lvi.iItem);
  196. lvi.iItem += iDelta;
  197. lvi.state = LVIS_SELECTED;
  198. lvi.stateMask = LVIS_SELECTED;
  199. ListView_InsertItem(hwndList,&lvi);
  200. }
  201. SetFocus(hwndList);
  202. }
  203. BOOL ProcessGroupPriorityDlg(HWND hDlg)
  204. {
  205. HWND hwndList = GetDlgItem(hDlg,IDD_GROUPORDER);
  206. int iMax = ListView_GetItemCount(hwndList),iItem;
  207. GROUPPRIENTRY * pGroupPriEntry;
  208. GROUPPRIENTRY * pGroupPriEntryLast;
  209. // relink the list in the order the entries now appear in the listbox
  210. for (iItem = 0;iItem < iMax;iItem ++) {
  211. pGroupPriEntry = (GROUPPRIENTRY *)
  212. IntToPtr(ListView_GetItemParm(hwndList,iItem));
  213. if (iItem == 0) {
  214. pGroupPriEntryFirst=pGroupPriEntryLast = pGroupPriEntry;
  215. pGroupPriEntry->pPrev = pGroupPriEntry->pNext = NULL;
  216. } else {
  217. pGroupPriEntryLast->pNext = pGroupPriEntry;
  218. pGroupPriEntry->pPrev = pGroupPriEntryLast;
  219. pGroupPriEntry->pNext = NULL;
  220. pGroupPriEntryLast = pGroupPriEntry;
  221. }
  222. }
  223. dwAppState |= AS_FILEDIRTY;
  224. return TRUE;
  225. }
  226. INT_PTR CALLBACK GroupPriorityDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  227. LPARAM lParam)
  228. {
  229. switch (uMsg) {
  230. case WM_INITDIALOG:
  231. InitGroupPriorityDlg(hDlg);
  232. break;
  233. case WM_COMMAND:
  234. switch (wParam) {
  235. case IDOK:
  236. if (ProcessGroupPriorityDlg(hDlg))
  237. EndDialog(hDlg,TRUE);
  238. return TRUE;
  239. break;
  240. case IDCANCEL:
  241. EndDialog(hDlg,FALSE);
  242. return TRUE;
  243. break;
  244. case IDD_MOVEUP:
  245. MoveGroupItem(hDlg,-1);
  246. break;
  247. case IDD_MOVEDOWN:
  248. MoveGroupItem(hDlg,1);
  249. break;
  250. }
  251. break;
  252. case WM_NOTIFY:
  253. if ( ((LPNMHDR) lParam)->hwndFrom == GetDlgItem(hDlg,IDD_GROUPORDER))
  254. EnableDlgButtons(hDlg);
  255. break;
  256. default:
  257. return FALSE;
  258. }
  259. return FALSE;
  260. }
  261. #endif // INCL_GROUP_SUPPORT