ntoskrnl.exe: Add a helper function for accessing registers.
[wine.git] / dlls / adsldp / adsldp.c
blob4fc0de41eb449df8dc08469e967fac41af786294
1 /*
2 * Active Directory services LDAP Provider
4 * Copyright 2018 Dmitry Timoshkov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "initguid.h"
28 #include "objbase.h"
29 #include "rpcproxy.h"
30 #include "iads.h"
31 #define SECURITY_WIN32
32 #include "security.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(adsldp);
38 static HMODULE adsldp_hinst;
40 typedef struct
42 IADsADSystemInfo IADsADSystemInfo_iface;
43 LONG ref;
44 } AD_sysinfo;
46 static inline AD_sysinfo *impl_from_IADsADSystemInfo(IADsADSystemInfo *iface)
48 return CONTAINING_RECORD(iface, AD_sysinfo, IADsADSystemInfo_iface);
51 static HRESULT WINAPI sysinfo_QueryInterface(IADsADSystemInfo *iface, REFIID riid, void **obj)
53 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
55 if (!riid || !obj) return E_INVALIDARG;
57 if (IsEqualGUID(riid, &IID_IADsADSystemInfo) ||
58 IsEqualGUID(riid, &IID_IDispatch) ||
59 IsEqualGUID(riid, &IID_IUnknown))
61 IADsADSystemInfo_AddRef(iface);
62 *obj = iface;
63 return S_OK;
66 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
67 return E_NOINTERFACE;
70 static ULONG WINAPI sysinfo_AddRef(IADsADSystemInfo *iface)
72 AD_sysinfo *sysinfo = impl_from_IADsADSystemInfo(iface);
73 return InterlockedIncrement(&sysinfo->ref);
76 static ULONG WINAPI sysinfo_Release(IADsADSystemInfo *iface)
78 AD_sysinfo *sysinfo = impl_from_IADsADSystemInfo(iface);
79 LONG ref = InterlockedDecrement(&sysinfo->ref);
81 if (!ref)
83 TRACE("destroying %p\n", iface);
84 HeapFree(GetProcessHeap(), 0, sysinfo);
87 return ref;
90 static HRESULT WINAPI sysinfo_GetTypeInfoCount(IADsADSystemInfo *iface, UINT *count)
92 FIXME("%p,%p: stub\n", iface, count);
93 return E_NOTIMPL;
96 static HRESULT WINAPI sysinfo_GetTypeInfo(IADsADSystemInfo *iface, UINT index, LCID lcid, ITypeInfo **info)
98 FIXME("%p,%u,%#x,%p: stub\n", iface, index, lcid, info);
99 return E_NOTIMPL;
102 static HRESULT WINAPI sysinfo_GetIDsOfNames(IADsADSystemInfo *iface, REFIID riid, LPOLESTR *names,
103 UINT count, LCID lcid, DISPID *dispid)
105 FIXME("%p,%s,%p,%u,%u,%p: stub\n", iface, debugstr_guid(riid), names, count, lcid, dispid);
106 return E_NOTIMPL;
109 static HRESULT WINAPI sysinfo_Invoke(IADsADSystemInfo *iface, DISPID dispid, REFIID riid, LCID lcid, WORD flags,
110 DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *argerr)
112 FIXME("%p,%d,%s,%04x,%04x,%p,%p,%p,%p: stub\n", iface, dispid, debugstr_guid(riid), lcid, flags,
113 params, result, excepinfo, argerr);
114 return E_NOTIMPL;
117 static HRESULT WINAPI sysinfo_get_UserName(IADsADSystemInfo *iface, BSTR *retval)
119 FIXME("%p,%p: stub\n", iface, retval);
120 return E_NOTIMPL;
123 static HRESULT WINAPI sysinfo_get_ComputerName(IADsADSystemInfo *iface, BSTR *retval)
125 UINT size;
126 WCHAR *name;
128 TRACE("%p,%p\n", iface, retval);
130 size = 0;
131 GetComputerObjectNameW(NameFullyQualifiedDN, NULL, &size);
132 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
133 return HRESULT_FROM_WIN32(GetLastError());
135 name = SysAllocStringLen(NULL, size);
136 if (!name) return E_OUTOFMEMORY;
138 if (!GetComputerObjectNameW(NameFullyQualifiedDN, name, &size))
140 SysFreeString(name);
141 return HRESULT_FROM_WIN32(GetLastError());
144 *retval = name;
145 return S_OK;
148 static HRESULT WINAPI sysinfo_get_SiteName(IADsADSystemInfo *iface, BSTR *retval)
150 FIXME("%p,%p: stub\n", iface, retval);
151 return E_NOTIMPL;
154 static HRESULT WINAPI sysinfo_get_DomainShortName(IADsADSystemInfo *iface, BSTR *retval)
156 FIXME("%p,%p: stub\n", iface, retval);
157 return E_NOTIMPL;
160 static HRESULT WINAPI sysinfo_get_DomainDNSName(IADsADSystemInfo *iface, BSTR *retval)
162 FIXME("%p,%p: stub\n", iface, retval);
163 return E_NOTIMPL;
166 static HRESULT WINAPI sysinfo_get_ForestDNSName(IADsADSystemInfo *iface, BSTR *retval)
168 FIXME("%p,%p: stub\n", iface, retval);
169 return E_NOTIMPL;
172 static HRESULT WINAPI sysinfo_get_PDCRoleOwner(IADsADSystemInfo *iface, BSTR *retval)
174 FIXME("%p,%p: stub\n", iface, retval);
175 return E_NOTIMPL;
178 static HRESULT WINAPI sysinfo_get_SchemaRoleOwner(IADsADSystemInfo *iface, BSTR *retval)
180 FIXME("%p,%p: stub\n", iface, retval);
181 return E_NOTIMPL;
184 static HRESULT WINAPI sysinfo_get_IsNativeMode(IADsADSystemInfo *iface, VARIANT_BOOL *retval)
186 FIXME("%p,%p: stub\n", iface, retval);
187 return E_NOTIMPL;
190 static HRESULT WINAPI sysinfo_GetAnyDCName(IADsADSystemInfo *iface, BSTR *retval)
192 FIXME("%p,%p: stub\n", iface, retval);
193 return E_NOTIMPL;
196 static HRESULT WINAPI sysinfo_GetDCSiteName(IADsADSystemInfo *iface, BSTR server, BSTR *retval)
198 FIXME("%p,%s,%p: stub\n", iface, debugstr_w(server), retval);
199 return E_NOTIMPL;
202 static HRESULT WINAPI sysinfo_RefreshSchemaCache(IADsADSystemInfo *iface)
204 FIXME("%p: stub\n", iface);
205 return E_NOTIMPL;
208 static HRESULT WINAPI sysinfo_GetTrees(IADsADSystemInfo *iface, VARIANT *retval)
210 FIXME("%p,%p: stub\n", iface, retval);
211 return E_NOTIMPL;
214 static const IADsADSystemInfoVtbl IADsADSystemInfo_vtbl =
216 sysinfo_QueryInterface,
217 sysinfo_AddRef,
218 sysinfo_Release,
219 sysinfo_GetTypeInfoCount,
220 sysinfo_GetTypeInfo,
221 sysinfo_GetIDsOfNames,
222 sysinfo_Invoke,
223 sysinfo_get_UserName,
224 sysinfo_get_ComputerName,
225 sysinfo_get_SiteName,
226 sysinfo_get_DomainShortName,
227 sysinfo_get_DomainDNSName,
228 sysinfo_get_ForestDNSName,
229 sysinfo_get_PDCRoleOwner,
230 sysinfo_get_SchemaRoleOwner,
231 sysinfo_get_IsNativeMode,
232 sysinfo_GetAnyDCName,
233 sysinfo_GetDCSiteName,
234 sysinfo_RefreshSchemaCache,
235 sysinfo_GetTrees
238 static HRESULT ADSystemInfo_create(void **obj)
240 AD_sysinfo *sysinfo;
242 sysinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sysinfo));
243 if (!sysinfo) return E_OUTOFMEMORY;
245 sysinfo->IADsADSystemInfo_iface.lpVtbl = &IADsADSystemInfo_vtbl;
246 sysinfo->ref = 1;
247 *obj = &sysinfo->IADsADSystemInfo_iface;
249 TRACE("created %p\n", *obj);
251 return S_OK;
254 typedef struct
256 IClassFactory IClassFactory_iface;
257 HRESULT (*constructor)(void **);
258 } ADSystemInfo_factory;
260 static inline ADSystemInfo_factory *impl_from_IClassFactory(IClassFactory *iface)
262 return CONTAINING_RECORD(iface, ADSystemInfo_factory, IClassFactory_iface);
265 static HRESULT WINAPI factory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *obj)
267 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
269 if (!riid || !obj) return E_INVALIDARG;
271 if (IsEqualIID(riid, &IID_IUnknown) ||
272 IsEqualIID(riid, &IID_IClassFactory))
274 IClassFactory_AddRef(iface);
275 *obj = iface;
276 return S_OK;
279 *obj = NULL;
280 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
281 return E_NOINTERFACE;
284 static ULONG WINAPI factory_AddRef(IClassFactory *iface)
286 return 2;
289 static ULONG WINAPI factory_Release(IClassFactory *iface)
291 return 1;
294 static HRESULT WINAPI factory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **obj)
296 ADSystemInfo_factory *factory = impl_from_IClassFactory(iface);
297 IUnknown *unknown;
298 HRESULT hr;
300 TRACE("%p,%s,%p\n", outer, debugstr_guid(riid), obj);
302 if (!riid || !obj) return E_INVALIDARG;
304 *obj = NULL;
305 if (outer) return CLASS_E_NOAGGREGATION;
307 hr = factory->constructor((void **)&unknown);
308 if (hr == S_OK)
310 hr = IUnknown_QueryInterface(unknown, riid, obj);
311 IUnknown_Release(unknown);
313 return hr;
316 static HRESULT WINAPI factory_LockServer(IClassFactory *iface, BOOL lock)
318 FIXME("%p,%d: stub\n", iface, lock);
319 return S_OK;
322 static const struct IClassFactoryVtbl factory_vtbl =
324 factory_QueryInterface,
325 factory_AddRef,
326 factory_Release,
327 factory_CreateInstance,
328 factory_LockServer
331 static ADSystemInfo_factory ADSystemInfo_cf = { { &factory_vtbl }, ADSystemInfo_create };
333 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *obj)
335 TRACE("%s,%s,%p\n", debugstr_guid(clsid), debugstr_guid(iid), obj);
337 if (!clsid || !iid || !obj) return E_INVALIDARG;
339 *obj = NULL;
341 if (IsEqualGUID(clsid, &CLSID_ADSystemInfo))
342 return IClassFactory_QueryInterface(&ADSystemInfo_cf.IClassFactory_iface, iid, obj);
344 FIXME("class %s/%s is not implemented\n", debugstr_guid(clsid), debugstr_guid(iid));
345 return CLASS_E_CLASSNOTAVAILABLE;
348 HRESULT WINAPI DllCanUnloadNow(void)
350 return S_FALSE;
353 HRESULT WINAPI DllRegisterServer(void)
355 return __wine_register_resources(adsldp_hinst);
358 HRESULT WINAPI DllUnregisterServer(void)
360 return __wine_unregister_resources(adsldp_hinst);
363 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *reserved)
365 TRACE("%p,%u,%p\n", hinst, reason, reserved);
367 switch (reason)
369 case DLL_WINE_PREATTACH:
370 return FALSE; /* prefer native version */
372 case DLL_PROCESS_ATTACH:
373 adsldp_hinst = hinst;
374 DisableThreadLibraryCalls(hinst);
375 break;
378 return TRUE;