ReactOS 0.4.15-dev-7958-gcd0bb1a
misc.c
Go to the documentation of this file.
1/*
2 * ReactOS Access Control List Editor
3 * Copyright (C) 2004-2005 ReactOS Team
4 *
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.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19/*
20 * PROJECT: ReactOS Access Control List Editor
21 * FILE: lib/aclui/misc.c
22 * PURPOSE: Access Control List Editor
23 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
24 *
25 * UPDATE HISTORY:
26 * 07/01/2005 Created
27 */
28
29#include "precomp.h"
30
31#define NDEBUG
32#include <debug.h>
33
35{
36 L"ObjectSid",
37};
38
39static INT
41 IN UINT uID)
42{
43 HRSRC hrSrc;
44 HGLOBAL hRes;
45 LPWSTR lpName, lpStr;
46
47 if (hInst == NULL)
48 {
49 return -1;
50 }
51
52 /* There are always blocks of 16 strings */
53 lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
54
55 /* Find the string table block */
56 if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
57 (hRes = LoadResource(hInst, hrSrc)) &&
58 (lpStr = LockResource(hRes)))
59 {
60 UINT x;
61
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++)
65 {
66 lpStr += (*lpStr) + 1;
67 }
68
69 /* Found the string */
70 return (int)(*lpStr);
71 }
72 return -1;
73}
74
75static INT
78 IN UINT uID)
79{
80 INT ln;
81
83 uID);
84 if (ln++ > 0)
85 {
86 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
87 ln * sizeof(WCHAR));
88 if ((*lpTarget) != NULL)
89 {
90 INT Ret;
91 if (!(Ret = LoadStringW(hInst, uID, *lpTarget, ln)))
92 {
93 LocalFree((HLOCAL)(*lpTarget));
94 }
95 return Ret;
96 }
97 }
98 return 0;
99}
100
101DWORD
103 IN UINT uID,
104 OUT LPWSTR *lpTarget,
105 ...)
106{
107 DWORD Ret = 0;
109 va_list lArgs;
110
112 hInstance,
113 uID) > 0)
114 {
115 va_start(lArgs, lpTarget);
116 /* let's use FormatMessage to format it because it has the ability to allocate
117 memory automatically */
119 lpFormat,
120 0,
121 0,
122 (LPWSTR)lpTarget,
123 0,
124 &lArgs);
125 va_end(lArgs);
126
128 }
129
130 return Ret;
131}
132
133LPARAM
135{
136 int Index;
137
139 -1,
141 if (Index != -1)
142 {
143 LVITEM li;
144
145 li.mask = LVIF_PARAM;
146 li.iItem = Index;
147 li.iSubItem = 0;
148
150 &li))
151 {
152 return li.lParam;
153 }
154 }
155
156 return 0;
157}
158
159BOOL
161 IN INT Index)
162{
163 LVITEM li;
164
165 li.mask = LVIF_STATE;
166 li.iItem = Index;
167 li.iSubItem = 0;
168 li.state = LVIS_SELECTED;
169 li.stateMask = LVIS_SELECTED;
170
171 return ListView_SetItem(hwnd,
172 &li);
173}
174
177 IN PSI_OBJECT_INFO ObjectInfo,
178 OUT IDsObjectPicker **pDsObjectPicker)
179{
180 HRESULT hRet;
181
182 *pDsObjectPicker = NULL;
183
184 hRet = CoCreateInstance(&CLSID_DsObjectPicker,
185 NULL,
186 CLSCTX_INPROC_SERVER,
187 &IID_IDsObjectPicker,
188 (LPVOID*)pDsObjectPicker);
189 if (SUCCEEDED(hRet))
190 {
191 DSOP_INIT_INFO InitInfo;
192 UINT i;
193 static DSOP_SCOPE_INIT_INFO Scopes[] =
194 {
195 {
196 sizeof(DSOP_SCOPE_INIT_INFO),
200 {
201 {
202 0,
203 0,
204 0
205 },
208 },
209 NULL,
210 NULL,
211 S_OK
212 },
213 };
214
215 InitInfo.cbSize = sizeof(InitInfo);
216 InitInfo.pwzTargetComputer = ServerName;
217 InitInfo.cDsScopeInfos = sizeof(Scopes) / sizeof(Scopes[0]);
218 InitInfo.aDsScopeInfos = Scopes;
222
223 for (i = 0; i < InitInfo.cDsScopeInfos; i++)
224 {
225 if ((ObjectInfo->dwFlags & SI_SERVER_IS_DC) &&
227 {
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;
232 }
233 }
234
235 hRet = (*pDsObjectPicker)->lpVtbl->Initialize(*pDsObjectPicker,
236 &InitInfo);
237
238 if (FAILED(hRet))
239 {
240 /* delete the object picker in case initialization failed! */
241 (*pDsObjectPicker)->lpVtbl->Release(*pDsObjectPicker);
242 }
243 }
244
245 return hRet;
246}
247
249InvokeObjectPickerDialog(IN IDsObjectPicker *pDsObjectPicker,
251 IN POBJPICK_SELECTED_SID SelectedSidCallback,
253{
254 IDataObject *pdo = NULL;
255 HRESULT hRet;
256
257 hRet = pDsObjectPicker->lpVtbl->InvokeDialog(pDsObjectPicker,
259 &pdo);
260 if (hRet == S_OK)
261 {
262 STGMEDIUM stm;
263 FORMATETC fe;
264
266 fe.ptd = NULL;
267 fe.dwAspect = DVASPECT_CONTENT;
268 fe.lindex = -1;
269 fe.tymed = TYMED_HGLOBAL;
270
271 hRet = pdo->lpVtbl->GetData(pdo,
272 &fe,
273 &stm);
274 if (SUCCEEDED(hRet))
275 {
276 PDS_SELECTION_LIST SelectionList = (PDS_SELECTION_LIST)GlobalLock(stm.hGlobal);
277 if (SelectionList != NULL)
278 {
279 LPVARIANT vSid;
280 PSID pSid;
281 UINT i;
282 BOOL contLoop = TRUE;
283
284 for (i = 0; i < SelectionList->cItems && contLoop; i++)
285 {
286 vSid = SelectionList->aDsSelection[i].pvarFetchedAttributes;
287
288 if (vSid != NULL && V_VT(vSid) == (VT_ARRAY | VT_UI1))
289 {
290 hRet = SafeArrayAccessData(V_ARRAY(vSid),
291 (void **)&pSid);
292 if (FAILED(hRet))
293 {
294 break;
295 }
296
297 if (pSid != NULL)
298 {
299 contLoop = SelectedSidCallback(pDsObjectPicker,
301 pSid,
302 Context);
303 }
304
306 }
307 }
308
309 GlobalUnlock(stm.hGlobal);
310
311 if (SUCCEEDED(hRet))
312 {
313 /* return S_OK instead of possible other success codes if
314 everything went well */
315 hRet = S_OK;
316 }
317 }
318 else
319 {
320 /* unable to translate the selection pointer handle, indicate
321 failure */
322 hRet = E_FAIL;
323 }
324
325 ReleaseStgMedium(&stm);
326 }
327
328 pdo->lpVtbl->Release(pdo);
329 }
330
331 return hRet;
332}
333
334VOID
335FreeObjectPicker(IN IDsObjectPicker *pDsObjectPicker)
336{
337 pDsObjectPicker->lpVtbl->Release(pDsObjectPicker);
338}
#define SI_SERVER_IS_DC
Definition: accctrl.h:126
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
DWORD LoadAndFormatString(IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
Definition: misc.c:85
HINSTANCE hInstance
Definition: charmap.c:19
static HWND hwndParent
Definition: cryptui.c:300
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
HRESULT InitializeObjectPicker(IN PCWSTR ServerName, IN PSI_OBJECT_INFO ObjectInfo, OUT IDsObjectPicker **pDsObjectPicker)
Definition: misc.c:176
static PCWSTR ObjectPickerAttributes[]
Definition: misc.c:34
BOOL ListViewSelectItem(IN HWND hwnd, IN INT Index)
Definition: misc.c:160
HRESULT InvokeObjectPickerDialog(IN IDsObjectPicker *pDsObjectPicker, IN HWND hwndParent OPTIONAL, IN POBJPICK_SELECTED_SID SelectedSidCallback, IN PVOID Context OPTIONAL)
Definition: misc.c:249
VOID FreeObjectPicker(IN IDsObjectPicker *pDsObjectPicker)
Definition: misc.c:335
LPARAM ListViewGetSelectedItemData(IN HWND hwnd)
Definition: misc.c:134
BOOL(* POBJPICK_SELECTED_SID)(IN IDsObjectPicker *pDsObjectPicker, IN HWND hwndParent OPTIONAL, IN PSID pSid, IN PVOID Context OPTIONAL)
Definition: precomp.h:100
@ VT_ARRAY
Definition: compat.h:2341
@ VT_UI1
Definition: compat.h:2311
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
HRESULT WINAPI SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Definition: safearray.c:1137
HRESULT WINAPI SafeArrayUnaccessData(SAFEARRAY *psa)
Definition: safearray.c:1168
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
ULONG Release()
nsrefcnt Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static PSID pSid
Definition: security.c:74
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define DSOP_SCOPE_FLAG_STARTING_SCOPE
Definition: objsel.h:80
#define DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS
Definition: objsel.h:86
#define DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS
Definition: objsel.h:52
#define DSOP_FLAG_MULTISELECT
Definition: objsel.h:104
#define DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS
Definition: objsel.h:87
#define DSOP_SCOPE_TYPE_TARGET_COMPUTER
Definition: objsel.h:121
struct _DS_SELECTION_LIST * PDS_SELECTION_LIST
#define DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS
Definition: objsel.h:68
#define DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN
Definition: objsel.h:122
#define DSOP_DOWNLEVEL_FILTER_USERS
Definition: objsel.h:51
struct _DSOP_SCOPE_INIT_INFO DSOP_SCOPE_INIT_INFO
#define CFSTR_DSOP_DS_SELECTION_LIST
Definition: objsel.h:27
#define DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS
Definition: objsel.h:53
#define V_ARRAY(A)
Definition: oleauto.h:222
#define V_VT(A)
Definition: oleauto.h:211
#define RT_STRING
Definition: pedump.c:368
#define LVIF_STATE
Definition: commctrl.h:2312
#define LVNI_SELECTED
Definition: commctrl.h:2424
#define ListView_GetNextItem(hwnd, i, flags)
Definition: commctrl.h:2434
#define LVIS_SELECTED
Definition: commctrl.h:2319
#define LVITEM
Definition: commctrl.h:2375
#define LVIF_PARAM
Definition: commctrl.h:2311
#define ListView_SetItem(hwnd, pitem)
Definition: commctrl.h:2401
#define ListView_GetItem(hwnd, pitem)
Definition: commctrl.h:2394
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
ULONG cAttributesToFetch
Definition: objsel.h:114
ULONG cbSize
Definition: objsel.h:109
PCWSTR * apwzAttributeNames
Definition: objsel.h:115
PDSOP_SCOPE_INIT_INFO aDsScopeInfos
Definition: objsel.h:112
ULONG cDsScopeInfos
Definition: objsel.h:111
PCWSTR pwzTargetComputer
Definition: objsel.h:110
ULONG flOptions
Definition: objsel.h:113
DS_SELECTION aDsSelection[ANYSIZE_ARRAY]
Definition: objsel.h:146
VARIANT * pvarFetchedAttributes
Definition: objsel.h:138
LPCWSTR lpFormat
Definition: trayclock.cpp:32
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_In_ WDFCOLLECTION _In_ ULONG Index
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define LMEM_FIXED
Definition: winbase.h:368
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define RegisterClipboardFormat
Definition: winuser.h:5838
#define MAKEINTRESOURCE
Definition: winuser.h:591
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184