2 * ReactOS Access Control List Editor
3 * Copyright (C) 2004 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>
36 LengthOfStrResource(IN HINSTANCE hInst
,
48 /* There are always blocks of 16 strings */
49 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
51 /* Find the string table block */
52 if((hrSrc
= FindResourceW(hInst
, lpName
, (LPWSTR
)RT_STRING
)) &&
53 (hRes
= LoadResource(hInst
, hrSrc
)) &&
54 (lpStr
= LockResource(hRes
)))
58 /* Find the string we're looking for */
59 uID
&= 0xF; /* position in the block, same as % 16 */
60 for(x
= 0; x
< uID
; x
++)
62 lpStr
+= (*lpStr
) + 1;
65 /* Found the string */
72 AllocAndLoadString(OUT LPWSTR
*lpTarget
,
78 ln
= LengthOfStrResource(hInst
,
82 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
84 if((*lpTarget
) != NULL
)
87 if(!(Ret
= LoadStringW(hInst
, uID
, *lpTarget
, ln
)))
89 LocalFree((HLOCAL
)(*lpTarget
));
98 LoadAndFormatString(IN HINSTANCE hInstance
,
100 OUT LPWSTR
*lpTarget
,
107 if(AllocAndLoadString(&lpFormat
,
111 va_start(lArgs
, lpTarget
);
112 /* let's use FormatMessage to format it because it has the ability to allocate
113 memory automatically */
114 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
123 LocalFree((HLOCAL
)lpFormat
);
130 OpenLSAPolicyHandle(IN LPWSTR SystemName
,
131 IN ACCESS_MASK DesiredAccess
,
132 OUT PLSA_HANDLE PolicyHandle
)
134 LSA_OBJECT_ATTRIBUTES LsaObjectAttributes
;
135 LSA_UNICODE_STRING LsaSystemName
, *psn
;
138 ZeroMemory(&LsaObjectAttributes
, sizeof(LSA_OBJECT_ATTRIBUTES
));
140 if (SystemName
!= NULL
)
142 LsaSystemName
.Buffer
= SystemName
;
143 LsaSystemName
.Length
= wcslen(SystemName
) * sizeof(WCHAR
);
144 LsaSystemName
.MaximumLength
= LsaSystemName
.Length
+ sizeof(WCHAR
);
145 psn
= &LsaSystemName
;
152 Status
= LsaOpenPolicy(psn
,
153 &LsaObjectAttributes
,
156 if (!NT_SUCCESS(Status
))
158 SetLastError(LsaNtStatusToWinError(Status
));
166 ListViewGetSelectedItemData(IN HWND hwnd
)
170 Index
= ListView_GetNextItem(hwnd
,
177 li
.mask
= LVIF_PARAM
;
181 if (ListView_GetItem(hwnd
,
192 ListViewSelectItem(IN HWND hwnd
,
197 li
.mask
= LVIF_STATE
;
200 li
.state
= LVIS_SELECTED
;
201 li
.stateMask
= LVIS_SELECTED
;
203 return ListView_SetItem(hwnd
,
208 InitializeObjectPicker(IN PCWSTR ServerName
,
209 IN PSI_OBJECT_INFO ObjectInfo
,
210 IN PCWSTR Attributes
[],
211 OUT IDsObjectPicker
**pDsObjectPicker
)
215 *pDsObjectPicker
= NULL
;
217 hRet
= CoCreateInstance(&CLSID_DsObjectPicker
,
219 CLSCTX_INPROC_SERVER
,
220 &IID_IDsObjectPicker
,
221 (LPVOID
*)pDsObjectPicker
);
224 DSOP_INIT_INFO InitInfo
;
226 DSOP_SCOPE_INIT_INFO Scopes
[] =
229 sizeof(DSOP_SCOPE_INIT_INFO
),
230 DSOP_SCOPE_TYPE_TARGET_COMPUTER
,
231 DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS
| DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS
|
232 DSOP_SCOPE_FLAG_STARTING_SCOPE
,
239 DSOP_DOWNLEVEL_FILTER_USERS
| DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS
|
240 DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS
| DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS
248 InitInfo
.cbSize
= sizeof(InitInfo
);
249 InitInfo
.pwzTargetComputer
= ServerName
;
250 InitInfo
.cDsScopeInfos
= sizeof(Scopes
) / sizeof(Scopes
[0]);
251 InitInfo
.aDsScopeInfos
= Scopes
;
252 InitInfo
.flOptions
= DSOP_FLAG_MULTISELECT
| DSOP_SCOPE_TYPE_TARGET_COMPUTER
;
253 InitInfo
.cAttributesToFetch
= sizeof(Attributes
) / sizeof(Attributes
[0]);
254 InitInfo
.apwzAttributeNames
= Attributes
;
256 for (i
= 0; i
< InitInfo
.cDsScopeInfos
; i
++)
258 if ((ObjectInfo
->dwFlags
& SI_SERVER_IS_DC
) &&
259 (InitInfo
.aDsScopeInfos
[i
].flType
& DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
))
261 /* only set the domain controller string if we know the target
262 computer is a domain controller and the scope type is an
263 up-level domain to which the target computer is joined */
264 InitInfo
.aDsScopeInfos
[i
].pwzDcName
= InitInfo
.pwzTargetComputer
;
268 hRet
= (*pDsObjectPicker
)->lpVtbl
->Initialize(*pDsObjectPicker
,
273 /* delete the object picker in case initialization failed! */
274 (*pDsObjectPicker
)->lpVtbl
->Release(*pDsObjectPicker
);