Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/activeds/pathname.c
8721 views
1
/*
2
* Copyright 2020 Dmitry Timoshkov
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
#include <stdarg.h>
20
21
#define COBJMACROS
22
23
#include "windef.h"
24
#include "winbase.h"
25
#include "iads.h"
26
#include "adserr.h"
27
28
#include "wine/debug.h"
29
30
WINE_DEFAULT_DEBUG_CHANNEL(activeds);
31
32
typedef struct
33
{
34
IADsPathname IADsPathname_iface;
35
LONG ref;
36
BSTR provider, server, dn;
37
} ADsPathname;
38
39
static inline ADsPathname *impl_from_IADsPathname(IADsPathname *iface)
40
{
41
return CONTAINING_RECORD(iface, ADsPathname, IADsPathname_iface);
42
}
43
44
static HRESULT WINAPI path_QueryInterface(IADsPathname *iface, REFIID riid, void **obj)
45
{
46
TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
47
48
if (!riid || !obj) return E_INVALIDARG;
49
50
if (IsEqualGUID(riid, &IID_IUnknown) ||
51
IsEqualGUID(riid, &IID_IDispatch) ||
52
IsEqualGUID(riid, &IID_IADsPathname))
53
{
54
IADsPathname_AddRef(iface);
55
*obj = iface;
56
return S_OK;
57
}
58
59
FIXME("interface %s is not implemented\n", debugstr_guid(riid));
60
return E_NOINTERFACE;
61
}
62
63
static ULONG WINAPI path_AddRef(IADsPathname *iface)
64
{
65
ADsPathname *path = impl_from_IADsPathname(iface);
66
return InterlockedIncrement(&path->ref);
67
}
68
69
static ULONG WINAPI path_Release(IADsPathname *iface)
70
{
71
ADsPathname *path = impl_from_IADsPathname(iface);
72
LONG ref = InterlockedDecrement(&path->ref);
73
74
if (!ref)
75
{
76
TRACE("destroying %p\n", iface);
77
SysFreeString(path->provider);
78
SysFreeString(path->server);
79
SysFreeString(path->dn);
80
free(path);
81
}
82
83
return ref;
84
}
85
86
static HRESULT WINAPI path_GetTypeInfoCount(IADsPathname *iface, UINT *count)
87
{
88
FIXME("%p,%p: stub\n", iface, count);
89
return E_NOTIMPL;
90
}
91
92
static HRESULT WINAPI path_GetTypeInfo(IADsPathname *iface, UINT index, LCID lcid, ITypeInfo **info)
93
{
94
FIXME("%p,%u,%#lx,%p: stub\n", iface, index, lcid, info);
95
return E_NOTIMPL;
96
}
97
98
static HRESULT WINAPI path_GetIDsOfNames(IADsPathname *iface, REFIID riid, LPOLESTR *names,
99
UINT count, LCID lcid, DISPID *dispid)
100
{
101
FIXME("%p,%s,%p,%u,%lu,%p: stub\n", iface, debugstr_guid(riid), names, count, lcid, dispid);
102
return E_NOTIMPL;
103
}
104
105
static HRESULT WINAPI path_Invoke(IADsPathname *iface, DISPID dispid, REFIID riid, LCID lcid, WORD flags,
106
DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *argerr)
107
{
108
FIXME("%p,%ld,%s,%04lx,%04x,%p,%p,%p,%p: stub\n", iface, dispid, debugstr_guid(riid), lcid, flags,
109
params, result, excepinfo, argerr);
110
return E_NOTIMPL;
111
}
112
113
static HRESULT parse_path(BSTR path, BSTR *provider, BSTR *server, BSTR *dn)
114
{
115
WCHAR *p, *p_server;
116
int server_len;
117
118
*provider = NULL;
119
*server = NULL;
120
*dn = NULL;
121
122
if (wcsnicmp(path, L"LDAP:", 5) != 0)
123
return E_ADS_BAD_PATHNAME;
124
125
*provider = SysAllocStringLen(path, 4);
126
if (!*provider) return E_OUTOFMEMORY;
127
128
p = path + 5;
129
if (!*p) return S_OK;
130
131
if (*p++ != '/' || *p++ != '/' || !*p)
132
{
133
SysFreeString(*provider);
134
return E_ADS_BAD_PATHNAME;
135
}
136
137
p_server = p;
138
server_len = 0;
139
while (*p && *p != '/')
140
{
141
p++;
142
server_len++;
143
}
144
if (server_len == 0)
145
{
146
SysFreeString(*provider);
147
return E_ADS_BAD_PATHNAME;
148
}
149
150
*server = SysAllocStringLen(p_server, server_len);
151
if (!*server)
152
{
153
SysFreeString(*provider);
154
return E_OUTOFMEMORY;
155
}
156
157
if (!*p) return S_OK;
158
159
if (*p++ != '/' || !*p)
160
{
161
SysFreeString(*provider);
162
SysFreeString(*server);
163
return E_ADS_BAD_PATHNAME;
164
}
165
166
*dn = SysAllocString(p);
167
if (!*dn)
168
{
169
SysFreeString(*provider);
170
SysFreeString(*server);
171
return E_OUTOFMEMORY;
172
}
173
174
return S_OK;
175
}
176
177
static HRESULT WINAPI path_Set(IADsPathname *iface, BSTR adspath, LONG type)
178
{
179
ADsPathname *path = impl_from_IADsPathname(iface);
180
HRESULT hr;
181
BSTR provider, server, dn;
182
183
TRACE("%p,%s,%ld\n", iface, debugstr_w(adspath), type);
184
185
if (!adspath) return E_INVALIDARG;
186
187
if (type == ADS_SETTYPE_PROVIDER)
188
{
189
SysFreeString(path->provider);
190
path->provider = SysAllocString(adspath);
191
return path->provider ? S_OK : E_OUTOFMEMORY;
192
}
193
194
if (type == ADS_SETTYPE_SERVER)
195
{
196
SysFreeString(path->server);
197
path->server = SysAllocString(adspath);
198
return path->server ? S_OK : E_OUTOFMEMORY;
199
}
200
201
if (type == ADS_SETTYPE_DN)
202
{
203
SysFreeString(path->dn);
204
path->dn = SysAllocString(adspath);
205
return path->dn ? S_OK : E_OUTOFMEMORY;
206
}
207
208
if (type != ADS_SETTYPE_FULL)
209
{
210
FIXME("type %ld not implemented\n", type);
211
return E_INVALIDARG;
212
}
213
214
hr = parse_path(adspath, &provider, &server, &dn);
215
if (hr == S_OK)
216
{
217
SysFreeString(path->provider);
218
SysFreeString(path->server);
219
SysFreeString(path->dn);
220
221
path->provider = provider;
222
path->server = server;
223
path->dn = dn;
224
}
225
return hr;
226
}
227
228
static HRESULT WINAPI path_SetDisplayType(IADsPathname *iface, LONG type)
229
{
230
FIXME("%p,%ld: stub\n", iface, type);
231
return E_NOTIMPL;
232
}
233
234
static HRESULT WINAPI path_Retrieve(IADsPathname *iface, LONG type, BSTR *adspath)
235
{
236
ADsPathname *path = impl_from_IADsPathname(iface);
237
int len;
238
239
TRACE("%p,%ld,%p\n", iface, type, adspath);
240
241
if (!adspath) return E_INVALIDARG;
242
243
switch (type)
244
{
245
default:
246
FIXME("type %ld not implemented\n", type);
247
/* fall through */
248
249
case ADS_FORMAT_X500:
250
len = wcslen(path->provider) + 3;
251
if (path->server) len += wcslen(path->server) + 1;
252
if (path->dn) len += wcslen(path->dn);
253
254
*adspath = SysAllocStringLen(NULL, len);
255
if (!*adspath) break;
256
257
wcscpy(*adspath, path->provider);
258
wcscat(*adspath, L"://");
259
if (path->server)
260
{
261
wcscat(*adspath, path->server);
262
wcscat(*adspath, L"/");
263
}
264
if (path->dn) wcscat(*adspath, path->dn);
265
break;
266
267
case ADS_FORMAT_PROVIDER:
268
*adspath = SysAllocString(path->provider);
269
break;
270
271
case ADS_FORMAT_SERVER:
272
*adspath = path->provider ? SysAllocString(path->server) : SysAllocStringLen(NULL, 0);
273
break;
274
275
case ADS_FORMAT_X500_DN:
276
*adspath = path->dn ? SysAllocString(path->dn) : SysAllocStringLen(NULL, 0);
277
break;
278
279
case ADS_FORMAT_LEAF:
280
if (!path->dn)
281
*adspath = SysAllocStringLen(NULL, 0);
282
else
283
{
284
WCHAR *p = wcschr(path->dn, ',');
285
*adspath = p ? SysAllocStringLen(path->dn, p - path->dn) : SysAllocString(path->dn);
286
}
287
break;
288
}
289
290
TRACE("=> %s\n", debugstr_w(*adspath));
291
return *adspath ? S_OK : E_OUTOFMEMORY;
292
}
293
294
static HRESULT WINAPI path_GetNumElements(IADsPathname *iface, LONG *count)
295
{
296
ADsPathname *path = impl_from_IADsPathname(iface);
297
WCHAR *p;
298
299
TRACE("%p,%p\n", iface, count);
300
301
if (!count) return E_INVALIDARG;
302
303
*count = 0;
304
305
p = path->dn;
306
while (p)
307
{
308
*count += 1;
309
p = wcschr(p, ',');
310
if (p) p++;
311
}
312
313
return S_OK;
314
}
315
316
static HRESULT WINAPI path_GetElement(IADsPathname *iface, LONG index, BSTR *element)
317
{
318
ADsPathname *path = impl_from_IADsPathname(iface);
319
HRESULT hr;
320
WCHAR *p, *end;
321
LONG count;
322
323
TRACE("%p,%ld,%p\n", iface, index, element);
324
325
if (!element) return E_INVALIDARG;
326
327
count = 0;
328
hr = HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
329
330
p = path->dn;
331
while (p)
332
{
333
end = wcschr(p, ',');
334
335
if (index == count)
336
{
337
*element = end ? SysAllocStringLen(p, end - p) : SysAllocString(p);
338
hr = *element ? S_OK : E_OUTOFMEMORY;
339
break;
340
}
341
342
p = end ? end + 1 : NULL;
343
count++;
344
}
345
346
return hr;
347
}
348
349
static HRESULT WINAPI path_AddLeafElement(IADsPathname *iface, BSTR element)
350
{
351
FIXME("%p,%s: stub\n", iface, debugstr_w(element));
352
return E_NOTIMPL;
353
}
354
355
static HRESULT WINAPI path_RemoveLeafElement(IADsPathname *iface)
356
{
357
FIXME("%p: stub\n", iface);
358
return E_NOTIMPL;
359
}
360
361
static HRESULT WINAPI path_CopyPath(IADsPathname *iface, IDispatch **path)
362
{
363
FIXME("%p,%p: stub\n", iface, path);
364
return E_NOTIMPL;
365
}
366
367
static HRESULT WINAPI path_GetEscapedElement(IADsPathname *iface, LONG reserved, BSTR element, BSTR *str)
368
{
369
FIXME("%p,%ld,%s,%p: stub\n", iface, reserved, debugstr_w(element), str);
370
return E_NOTIMPL;
371
}
372
373
static HRESULT WINAPI path_get_EscapedMode(IADsPathname *iface, LONG *mode)
374
{
375
FIXME("%p,%p: stub\n", iface, mode);
376
return E_NOTIMPL;
377
}
378
379
static HRESULT WINAPI path_put_EscapedMode(IADsPathname *iface, LONG mode)
380
{
381
FIXME("%p,%ld: stub\n", iface, mode);
382
return E_NOTIMPL;
383
}
384
385
static const IADsPathnameVtbl IADsPathname_vtbl =
386
{
387
path_QueryInterface,
388
path_AddRef,
389
path_Release,
390
path_GetTypeInfoCount,
391
path_GetTypeInfo,
392
path_GetIDsOfNames,
393
path_Invoke,
394
path_Set,
395
path_SetDisplayType,
396
path_Retrieve,
397
path_GetNumElements,
398
path_GetElement,
399
path_AddLeafElement,
400
path_RemoveLeafElement,
401
path_CopyPath,
402
path_GetEscapedElement,
403
path_get_EscapedMode,
404
path_put_EscapedMode
405
};
406
407
static HRESULT Pathname_create(REFIID riid, void **obj)
408
{
409
ADsPathname *path;
410
HRESULT hr;
411
412
path = malloc(sizeof(*path));
413
if (!path) return E_OUTOFMEMORY;
414
415
path->IADsPathname_iface.lpVtbl = &IADsPathname_vtbl;
416
path->ref = 1;
417
path->provider = SysAllocString(L"LDAP");
418
path->server = NULL;
419
path->dn = NULL;
420
421
hr = IADsPathname_QueryInterface(&path->IADsPathname_iface, riid, obj);
422
IADsPathname_Release(&path->IADsPathname_iface);
423
424
return hr;
425
}
426
427
HRESULT ADsDNWithBinary_create(REFIID riid, void **obj);
428
429
static const struct class_info
430
{
431
const CLSID *clsid;
432
HRESULT (*constructor)(REFIID, void **);
433
} class_info[] =
434
{
435
{ &CLSID_Pathname, Pathname_create },
436
{ &CLSID_DNWithBinary, ADsDNWithBinary_create }
437
};
438
439
typedef struct
440
{
441
IClassFactory IClassFactory_iface;
442
LONG ref;
443
const struct class_info *info;
444
} class_factory;
445
446
static inline class_factory *impl_from_IClassFactory(IClassFactory *iface)
447
{
448
return CONTAINING_RECORD(iface, class_factory, IClassFactory_iface);
449
}
450
451
static HRESULT WINAPI factory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *obj)
452
{
453
TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
454
455
if (!riid || !obj) return E_INVALIDARG;
456
457
if (IsEqualIID(riid, &IID_IUnknown) ||
458
IsEqualIID(riid, &IID_IClassFactory))
459
{
460
IClassFactory_AddRef(iface);
461
*obj = iface;
462
return S_OK;
463
}
464
465
*obj = NULL;
466
FIXME("interface %s is not implemented\n", debugstr_guid(riid));
467
return E_NOINTERFACE;
468
}
469
470
static ULONG WINAPI factory_AddRef(IClassFactory *iface)
471
{
472
class_factory *factory = impl_from_IClassFactory(iface);
473
ULONG ref = InterlockedIncrement(&factory->ref);
474
475
TRACE("(%p) ref %lu\n", iface, ref);
476
477
return ref;
478
}
479
480
static ULONG WINAPI factory_Release(IClassFactory *iface)
481
{
482
class_factory *factory = impl_from_IClassFactory(iface);
483
ULONG ref = InterlockedDecrement(&factory->ref);
484
485
TRACE("(%p) ref %lu\n", iface, ref);
486
487
if (!ref)
488
free(factory);
489
490
return ref;
491
}
492
493
static HRESULT WINAPI factory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **obj)
494
{
495
class_factory *factory = impl_from_IClassFactory(iface);
496
497
TRACE("%p,%s,%p\n", outer, debugstr_guid(riid), obj);
498
499
if (!riid || !obj) return E_INVALIDARG;
500
501
*obj = NULL;
502
if (outer) return CLASS_E_NOAGGREGATION;
503
504
return factory->info->constructor(riid, obj);
505
}
506
507
static HRESULT WINAPI factory_LockServer(IClassFactory *iface, BOOL lock)
508
{
509
FIXME("%p,%d: stub\n", iface, lock);
510
return S_OK;
511
}
512
513
static const struct IClassFactoryVtbl factory_vtbl =
514
{
515
factory_QueryInterface,
516
factory_AddRef,
517
factory_Release,
518
factory_CreateInstance,
519
factory_LockServer
520
};
521
522
static HRESULT factory_constructor(const struct class_info *info, REFIID riid, void **obj)
523
{
524
class_factory *factory;
525
HRESULT hr;
526
527
factory = malloc(sizeof(*factory));
528
if (!factory) return E_OUTOFMEMORY;
529
530
factory->IClassFactory_iface.lpVtbl = &factory_vtbl;
531
factory->ref = 1;
532
factory->info = info;
533
534
hr = IClassFactory_QueryInterface(&factory->IClassFactory_iface, riid, obj);
535
IClassFactory_Release(&factory->IClassFactory_iface);
536
537
return hr;
538
}
539
540
HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *obj)
541
{
542
int i;
543
544
TRACE("%s,%s,%p\n", debugstr_guid(clsid), debugstr_guid(iid), obj);
545
546
if (!clsid || !iid || !obj) return E_INVALIDARG;
547
548
*obj = NULL;
549
550
for (i = 0; i < ARRAY_SIZE(class_info); i++)
551
{
552
if (IsEqualCLSID(class_info[i].clsid, clsid))
553
return factory_constructor(&class_info[i], iid, obj);
554
}
555
556
FIXME("class %s/%s is not implemented\n", debugstr_guid(clsid), debugstr_guid(iid));
557
return CLASS_E_CLASSNOTAVAILABLE;
558
}
559
560