netstat: Initial implementation.
[wine] / dlls / msident / msident.c
1 /*
2  * Copyright 2012 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20
21 #include "windows.h"
22 #include "initguid.h"
23 #include "msident.h"
24 #include "rpcproxy.h"
25
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(msident);
29
30 static inline void *heap_alloc(size_t len)
31 {
32     return HeapAlloc(GetProcessHeap(), 0, len);
33 }
34
35 static inline BOOL heap_free(void *mem)
36 {
37     return HeapFree(GetProcessHeap(), 0, mem);
38 }
39
40 static HINSTANCE msident_instance;
41
42 typedef struct {
43     IEnumUserIdentity IEnumUserIdentity_iface;
44     LONG ref;
45 } EnumUserIdentity;
46
47 static inline EnumUserIdentity *impl_from_IEnumUserIdentity(IEnumUserIdentity *iface)
48 {
49     return CONTAINING_RECORD(iface, EnumUserIdentity, IEnumUserIdentity_iface);
50 }
51
52 static HRESULT WINAPI EnumUserIdentity_QueryInterface(IEnumUserIdentity *iface, REFIID riid, void **ppv)
53 {
54     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
55
56     if(IsEqualGUID(&IID_IUnknown, riid)) {
57         TRACE("(IID_IUnknown %p)\n", ppv);
58         *ppv = &This->IEnumUserIdentity_iface;
59     }else if(IsEqualGUID(&IID_IEnumUserIdentity, riid)) {
60         TRACE("(IID_IEnumUserIdentity %p)\n", ppv);
61         *ppv = &This->IEnumUserIdentity_iface;
62     }else {
63         WARN("(%s %p)\n", debugstr_guid(riid), ppv);
64         *ppv = NULL;
65         return E_NOINTERFACE;
66     }
67
68     IUnknown_AddRef((IUnknown*)*ppv);
69     return S_OK;
70 }
71
72 static ULONG WINAPI EnumUserIdentity_AddRef(IEnumUserIdentity *iface)
73 {
74     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
75     LONG ref = InterlockedIncrement(&This->ref);
76
77     TRACE("(%p) ref=%d\n", This, ref);
78
79     return ref;
80 }
81
82 static ULONG WINAPI EnumUserIdentity_Release(IEnumUserIdentity *iface)
83 {
84     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
85     LONG ref = InterlockedDecrement(&This->ref);
86
87     TRACE("(%p) ref=%d\n", This, ref);
88
89     if(!ref)
90         heap_free(This);
91
92     return ref;
93 }
94
95 static HRESULT WINAPI EnumUserIdentity_Next(IEnumUserIdentity *iface, ULONG celt, IUnknown **rgelt, ULONG *pceltFetched)
96 {
97     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
98     FIXME("(%p)->(%u %p %p)\n", This, celt, rgelt, pceltFetched);
99     return E_NOTIMPL;
100 }
101
102 static HRESULT WINAPI EnumUserIdentity_Skip(IEnumUserIdentity *iface, ULONG celt)
103 {
104     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
105     FIXME("(%p)->(%u)\n", This, celt);
106     return E_NOTIMPL;
107 }
108
109 static HRESULT WINAPI EnumUserIdentity_Reset(IEnumUserIdentity *iface)
110 {
111     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
112     FIXME("(%p)->()\n", This);
113     return E_NOTIMPL;
114 }
115
116 static HRESULT WINAPI EnumUserIdentity_Clone(IEnumUserIdentity *iface, IEnumUserIdentity **ppenum)
117 {
118     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
119     FIXME("(%p)->(%p)\n", This, ppenum);
120     return E_NOTIMPL;
121 }
122
123 static HRESULT WINAPI EnumUserIdentity_GetCount(IEnumUserIdentity *iface, ULONG *pnCount)
124 {
125     EnumUserIdentity *This = impl_from_IEnumUserIdentity(iface);
126
127     FIXME("(%p)->(%p)\n", This, pnCount);
128
129     *pnCount = 0;
130     return S_OK;
131 }
132
133 static const IEnumUserIdentityVtbl EnumUserIdentityVtbl = {
134     EnumUserIdentity_QueryInterface,
135     EnumUserIdentity_AddRef,
136     EnumUserIdentity_Release,
137     EnumUserIdentity_Next,
138     EnumUserIdentity_Skip,
139     EnumUserIdentity_Reset,
140     EnumUserIdentity_Clone,
141     EnumUserIdentity_GetCount
142 };
143
144 static HRESULT WINAPI UserIdentityManager_QueryInterface(IUserIdentityManager *iface, REFIID riid, void **ppv)
145 {
146     if(IsEqualGUID(&IID_IUnknown, riid)) {
147         TRACE("(IID_IUnknown %p)\n", ppv);
148         *ppv = iface;
149     }else if(IsEqualGUID(&IID_IUserIdentityManager, riid)) {
150         TRACE("(IID_IUserIdentityManager %p)\n", ppv);
151         *ppv = iface;
152     }else {
153         WARN("(%s %p)\n", debugstr_guid(riid), ppv);
154         *ppv = NULL;
155         return E_NOINTERFACE;
156     }
157
158     IUnknown_AddRef((IUnknown*)*ppv);
159     return S_OK;
160 }
161
162 static ULONG WINAPI UserIdentityManager_AddRef(IUserIdentityManager *iface)
163 {
164     TRACE("\n");
165     return 2;
166 }
167
168 static ULONG WINAPI UserIdentityManager_Release(IUserIdentityManager *iface)
169 {
170     TRACE("\n");
171     return 1;
172 }
173
174 static HRESULT WINAPI UserIdentityManager_EnumIdentities(IUserIdentityManager *iface, IEnumUserIdentity **ppEnumUser)
175 {
176     EnumUserIdentity *ret;
177
178     TRACE("(%p)\n", ppEnumUser);
179
180     ret = heap_alloc(sizeof(*ret));
181     if(!ret)
182         return E_OUTOFMEMORY;
183
184     ret->IEnumUserIdentity_iface.lpVtbl = &EnumUserIdentityVtbl;
185     ret->ref = 1;
186
187     *ppEnumUser = &ret->IEnumUserIdentity_iface;
188     return S_OK;
189 }
190
191 static HRESULT WINAPI UserIdentityManager_ManageIdentities(IUserIdentityManager *iface, HWND hwndParent, DWORD dwFlags)
192 {
193     FIXME("(%p %x)\n", hwndParent, dwFlags);
194     return E_NOTIMPL;
195 }
196
197 static HRESULT WINAPI UserIdentityManager_Logon(IUserIdentityManager *iface, HWND hwndParent,
198         DWORD dwFlags, IUserIdentity **ppIdentity)
199 {
200     FIXME("(%p %x %p)\n", hwndParent, dwFlags, ppIdentity);
201     return E_USER_CANCELLED;
202 }
203
204 static HRESULT WINAPI UserIdentityManager_Logoff(IUserIdentityManager *iface, HWND hwndParent)
205 {
206     FIXME("(%p)\n", hwndParent);
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI UserIdentityManager_GetIdentityByCookie(IUserIdentityManager *iface, GUID *uidCookie,
211         IUserIdentity **ppIdentity)
212 {
213     FIXME("(%p %p)\n", uidCookie, ppIdentity);
214     return E_NOTIMPL;
215 }
216
217 static const IUserIdentityManagerVtbl UserIdentityManagerVtbl = {
218     UserIdentityManager_QueryInterface,
219     UserIdentityManager_AddRef,
220     UserIdentityManager_Release,
221     UserIdentityManager_EnumIdentities,
222     UserIdentityManager_ManageIdentities,
223     UserIdentityManager_Logon,
224     UserIdentityManager_Logoff,
225     UserIdentityManager_GetIdentityByCookie
226 };
227
228 static IUserIdentityManager UserIdentityManager = { &UserIdentityManagerVtbl };
229
230 static HRESULT WINAPI UserIdentityManager_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
231 {
232     TRACE("\n");
233
234     return IUserIdentityManager_QueryInterface(&UserIdentityManager, riid, ppv);
235 }
236
237 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
238 {
239     *ppv = NULL;
240
241     if(IsEqualGUID(&IID_IUnknown, riid)) {
242         TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
243         *ppv = iface;
244     }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
245         TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
246         *ppv = iface;
247     }
248
249     if(*ppv) {
250         IUnknown_AddRef((IUnknown*)*ppv);
251         return S_OK;
252     }
253
254     FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
255     return E_NOINTERFACE;
256 }
257
258 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
259 {
260     TRACE("(%p)\n", iface);
261     return 2;
262 }
263
264 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
265 {
266     TRACE("(%p)\n", iface);
267     return 1;
268 }
269
270 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
271 {
272     TRACE("(%p)->(%x)\n", iface, fLock);
273     return S_OK;
274 }
275
276 static const IClassFactoryVtbl UserIdentityManagerCFVtbl = {
277     ClassFactory_QueryInterface,
278     ClassFactory_AddRef,
279     ClassFactory_Release,
280     UserIdentityManager_CreateInstance,
281     ClassFactory_LockServer
282 };
283
284 static IClassFactory UserIdentityManagerCF = { &UserIdentityManagerCFVtbl };
285
286 /******************************************************************
287  *              DllMain (msident.@)
288  */
289 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
290 {
291     TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
292
293     switch(fdwReason)
294     {
295     case DLL_WINE_PREATTACH:
296         return FALSE;  /* prefer native version */
297     case DLL_PROCESS_ATTACH:
298         msident_instance = hInstDLL;
299         DisableThreadLibraryCalls(hInstDLL);
300         break;
301     }
302
303     return TRUE;
304 }
305
306 /***********************************************************************
307  *              DllGetClassObject       (msident.@)
308  */
309 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
310 {
311     if(IsEqualGUID(&CLSID_UserIdentityManager, rclsid)) {
312         TRACE("CLSID_UserIdentityManager\n");
313         return IClassFactory_QueryInterface(&UserIdentityManagerCF, riid, ppv);
314     }
315
316     FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
317     return CLASS_E_CLASSNOTAVAILABLE;
318 }
319
320 /***********************************************************************
321  *          DllCanUnloadNow (msident.@)
322  */
323 HRESULT WINAPI DllCanUnloadNow(void)
324 {
325     return S_FALSE;
326 }
327
328 /***********************************************************************
329  *          DllRegisterServer (msident.@)
330  */
331 HRESULT WINAPI DllRegisterServer(void)
332 {
333     TRACE("()\n");
334     return __wine_register_resources(msident_instance);
335 }
336
337 /***********************************************************************
338  *          DllUnregisterServer (msident.@)
339  */
340 HRESULT WINAPI DllUnregisterServer(void)
341 {
342     TRACE("()\n");
343     return __wine_unregister_resources(msident_instance);
344 }