2 * ReactOS Access Control List Editor
3 * Copyright (C) 2004-2005 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * PROJECT: ReactOS Access Control List Editor
22 * FILE: lib/aclui/misc.c
23 * PURPOSE: Access Control List Editor
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
34 static PCWSTR ObjectPickerAttributes
[] =
40 LengthOfStrResource(IN HINSTANCE hInst
,
52 /* There are always blocks of 16 strings */
53 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
55 /* Find the string table block */
56 if ((hrSrc
= FindResourceW(hInst
, lpName
, (LPWSTR
)RT_STRING
)) &&
57 (hRes
= LoadResource(hInst
, hrSrc
)) &&
58 (lpStr
= LockResource(hRes
)))
62 /* Find the string we're looking for */
63 uID
&= 0xF; /* position in the block, same as % 16 */
64 for (x
= 0; x
< uID
; x
++)
66 lpStr
+= (*lpStr
) + 1;
69 /* Found the string */
76 AllocAndLoadString(OUT LPWSTR
*lpTarget
,
82 ln
= LengthOfStrResource(hInst
,
86 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
88 if ((*lpTarget
) != NULL
)
91 if (!(Ret
= LoadStringW(hInst
, uID
, *lpTarget
, ln
)))
93 LocalFree((HLOCAL
)(*lpTarget
));
102 LoadAndFormatString(IN HINSTANCE hInstance
,
104 OUT LPWSTR
*lpTarget
,
111 if (AllocAndLoadString(&lpFormat
,
115 va_start(lArgs
, lpTarget
);
116 /* let's use FormatMessage to format it because it has the ability to allocate
117 memory automatically */
118 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
127 LocalFree((HLOCAL
)lpFormat
);
134 ListViewGetSelectedItemData(IN HWND hwnd
)
138 Index
= ListView_GetNextItem(hwnd
,
145 li
.mask
= LVIF_PARAM
;
149 if (ListView_GetItem(hwnd
,
160 ListViewSelectItem(IN HWND hwnd
,
165 li
.mask
= LVIF_STATE
;
168 li
.state
= LVIS_SELECTED
;
169 li
.stateMask
= LVIS_SELECTED
;
171 return ListView_SetItem(hwnd
,
176 InitializeObjectPicker(IN PCWSTR ServerName
,
177 IN PSI_OBJECT_INFO ObjectInfo
,
178 OUT IDsObjectPicker
**pDsObjectPicker
)
182 *pDsObjectPicker
= NULL
;
184 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
186 CLSCTX_INPROC_SERVER
,
187 &IID_IDsObjectPicker
,
188 (LPVOID
*)pDsObjectPicker
);
191 DSOP_INIT_INFO InitInfo
;
193 static DSOP_SCOPE_INIT_INFO Scopes
[] =
196 sizeof(DSOP_SCOPE_INIT_INFO
),
197 DSOP_SCOPE_TYPE_TARGET_COMPUTER
,
198 DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS
| DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS
|
199 DSOP_SCOPE_FLAG_STARTING_SCOPE
,
206 DSOP_DOWNLEVEL_FILTER_USERS
| DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS
|
207 DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS
| DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS
215 InitInfo
.cbSize
= sizeof(InitInfo
);
216 InitInfo
.pwzTargetComputer
= ServerName
;
217 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
218 InitInfo
.aDsScopeInfos
= Scopes
;
219 InitInfo
.flOptions
= DSOP_FLAG_MULTISELECT
;
220 InitInfo
.cAttributesToFetch
= sizeof(ObjectPickerAttributes
) / sizeof(ObjectPickerAttributes
[0]);
221 InitInfo
.apwzAttributeNames
= ObjectPickerAttributes
;
223 for (i
= 0; i
< InitInfo
.cDsScopeInfos
; i
++)
225 if ((ObjectInfo
->dwFlags
& SI_SERVER_IS_DC
) &&
226 (InitInfo
.aDsScopeInfos
[i
].flType
& DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
))
228 /* only set the domain controller string if we know the target
229 computer is a domain controller and the scope type is an
230 up-level domain to which the target computer is joined */
231 InitInfo
.aDsScopeInfos
[i
].pwzDcName
= InitInfo
.pwzTargetComputer
;
235 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
240 /* delete the object picker in case initialization failed! */
241 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);
249 InvokeObjectPickerDialog(IN IDsObjectPicker
*pDsObjectPicker
,
250 IN HWND hwndParent OPTIONAL
,
251 IN POBJPICK_SELECTED_SID SelectedSidCallback
,
252 IN PVOID Context OPTIONAL
)
254 IDataObject
*pdo
= NULL
;
257 hRet
= pDsObjectPicker
->lpVtbl
->InvokeDialog(pDsObjectPicker
,
265 fe
.cfFormat
= (WORD
)RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST
);
267 fe
.dwAspect
= DVASPECT_CONTENT
;
269 fe
.tymed
= TYMED_HGLOBAL
;
271 hRet
= pdo
->lpVtbl
->GetData(pdo
,
276 PDS_SELECTION_LIST SelectionList
= (PDS_SELECTION_LIST
)GlobalLock(stm
.hGlobal
);
277 if (SelectionList
!= NULL
)
282 BOOL contLoop
= TRUE
;
284 for (i
= 0; i
< SelectionList
->cItems
&& contLoop
; i
++)
286 vSid
= SelectionList
->aDsSelection
[i
].pvarFetchedAttributes
;
288 if (vSid
!= NULL
&& V_VT(vSid
) == (VT_ARRAY
| VT_UI1
))
290 hRet
= SafeArrayAccessData(V_ARRAY(vSid
),
299 contLoop
= SelectedSidCallback(pDsObjectPicker
,
305 SafeArrayUnaccessData(V_ARRAY(vSid
));
309 GlobalUnlock(stm
.hGlobal
);
313 /* return S_OK instead of possible other success codes if
314 everything went well */
320 /* unable to translate the selection pointer handle, indicate
325 ReleaseStgMedium(&stm
);
328 pdo
->lpVtbl
->Release(pdo
);
335 FreeObjectPicker(IN IDsObjectPicker
*pDsObjectPicker
)
337 pDsObjectPicker
->lpVtbl
->Release(pDsObjectPicker
);