-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DirectoryRequest.cs
332 lines (264 loc) · 9.53 KB
/
DirectoryRequest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Specialized;
using System.ComponentModel;
namespace System.DirectoryServices.Protocols
{
public abstract class DirectoryRequest : DirectoryOperation
{
internal DirectoryRequest()
{
}
public string RequestId
{
get => _directoryRequestID;
set => _directoryRequestID = value;
}
public DirectoryControlCollection Controls { get; } = new DirectoryControlCollection();
}
public class DeleteRequest : DirectoryRequest
{
public DeleteRequest() { }
public DeleteRequest(string distinguishedName)
{
DistinguishedName = distinguishedName;
}
public string DistinguishedName { get; set; }
}
public class AddRequest : DirectoryRequest
{
public AddRequest() { }
public AddRequest(string distinguishedName, params DirectoryAttribute[] attributes) : this()
{
DistinguishedName = distinguishedName;
if (attributes != null)
{
for (int i = 0; i < attributes.Length; i++)
{
Attributes.Add(attributes[i]);
}
}
}
public AddRequest(string distinguishedName, string objectClass) : this()
{
ArgumentNullException.ThrowIfNull(objectClass);
DistinguishedName = distinguishedName;
var objClassAttr = new DirectoryAttribute()
{
Name = nameof(objectClass)
};
objClassAttr.Add(objectClass);
Attributes.Add(objClassAttr);
}
public string DistinguishedName { get; set; }
public DirectoryAttributeCollection Attributes { get; } = new DirectoryAttributeCollection();
}
public class ModifyRequest : DirectoryRequest
{
public ModifyRequest() { }
public ModifyRequest(string distinguishedName, params DirectoryAttributeModification[] modifications) : this()
{
DistinguishedName = distinguishedName;
Modifications.AddRange(modifications);
}
public ModifyRequest(string distinguishedName, DirectoryAttributeOperation operation, string attributeName, params object[] values) : this()
{
ArgumentNullException.ThrowIfNull(attributeName);
DistinguishedName = distinguishedName;
var mod = new DirectoryAttributeModification()
{
Operation = operation,
Name = attributeName
};
if (values != null)
{
for (int i = 0; i < values.Length; i++)
{
mod.Add(values[i]);
}
}
Modifications.Add(mod);
}
public string DistinguishedName { get; set; }
public DirectoryAttributeModificationCollection Modifications { get; } = new DirectoryAttributeModificationCollection();
}
public class CompareRequest : DirectoryRequest
{
public CompareRequest() { }
public CompareRequest(string distinguishedName, string attributeName, string value)
{
CompareRequestHelper(distinguishedName, attributeName, value);
}
public CompareRequest(string distinguishedName, string attributeName, byte[] value)
{
CompareRequestHelper(distinguishedName, attributeName, value);
}
public CompareRequest(string distinguishedName, string attributeName, Uri value)
{
CompareRequestHelper(distinguishedName, attributeName, value);
}
public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
{
ArgumentNullException.ThrowIfNull(assertion);
if (assertion.Count != 1)
{
throw new ArgumentException(SR.WrongNumValuesCompare);
}
CompareRequestHelper(distinguishedName, assertion.Name, assertion[0]);
}
private void CompareRequestHelper(string distinguishedName, string attributeName, object value)
{
ArgumentNullException.ThrowIfNull(attributeName);
ArgumentNullException.ThrowIfNull(value);
DistinguishedName = distinguishedName;
Assertion.Name = attributeName;
Assertion.Add(value);
}
public string DistinguishedName { get; set; }
public DirectoryAttribute Assertion { get; } = new DirectoryAttribute();
}
public class ModifyDNRequest : DirectoryRequest
{
public ModifyDNRequest() { }
public ModifyDNRequest(string distinguishedName, string newParentDistinguishedName, string newName)
{
DistinguishedName = distinguishedName;
NewParentDistinguishedName = newParentDistinguishedName;
NewName = newName;
}
public string DistinguishedName { get; set; }
public string NewParentDistinguishedName { get; set; }
public string NewName { get; set; }
public bool DeleteOldRdn { get; set; } = true;
}
public class ExtendedRequest : DirectoryRequest
{
private byte[] _requestValue;
public ExtendedRequest() { }
public ExtendedRequest(string requestName)
{
RequestName = requestName;
}
public ExtendedRequest(string requestName, byte[] requestValue) : this(requestName)
{
_requestValue = requestValue;
}
public string RequestName { get; set; }
public byte[] RequestValue
{
get
{
if (_requestValue == null)
{
return Array.Empty<byte>();
}
byte[] tempValue = new byte[_requestValue.Length];
for (int i = 0; i < _requestValue.Length; i++)
{
tempValue[i] = _requestValue[i];
}
return tempValue;
}
set => _requestValue = value;
}
}
public class SearchRequest : DirectoryRequest
{
public SearchRequest() { }
public SearchRequest(string distinguishedName, string ldapFilter, SearchScope searchScope, params string[] attributeList) : this()
{
DistinguishedName = distinguishedName;
if (attributeList != null)
{
for (int i = 0; i < attributeList.Length; i++)
{
Attributes.Add(attributeList[i]);
}
}
Scope = searchScope;
Filter = ldapFilter;
}
public string DistinguishedName { get; set; }
public StringCollection Attributes { get; } = new StringCollection();
public object Filter
{
get => _directoryFilter;
set
{
if (value != null && !(value is string))
{
throw new ArgumentException(SR.ValidFilterType, nameof(value));
}
_directoryFilter = value;
}
}
public SearchScope Scope
{
get => _directoryScope;
set
{
if (value < SearchScope.Base || value > SearchScope.Subtree)
{
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(SearchScope));
}
_directoryScope = value;
}
}
public DereferenceAlias Aliases
{
get => _directoryRefAlias;
set
{
if (value < DereferenceAlias.Never || value > DereferenceAlias.Always)
{
throw new InvalidEnumArgumentException(nameof(value), (int)value, typeof(DereferenceAlias));
}
_directoryRefAlias = value;
}
}
public int SizeLimit
{
get => _directorySizeLimit;
set
{
if (value < 0)
{
throw new ArgumentException(SR.NoNegativeSizeLimit, nameof(value));
}
_directorySizeLimit = value;
}
}
public TimeSpan TimeLimit
{
get => _directoryTimeLimit;
set
{
if (value < TimeSpan.Zero)
{
throw new ArgumentException(SR.NoNegativeTimeLimit, nameof(value));
}
// Prevent integer overflow.
if (value.TotalSeconds > int.MaxValue)
{
throw new ArgumentException(SR.TimespanExceedMax, nameof(value));
}
_directoryTimeLimit = value;
}
}
public bool TypesOnly { get; set; }
private object _directoryFilter;
private SearchScope _directoryScope = SearchScope.Subtree;
private DereferenceAlias _directoryRefAlias = DereferenceAlias.Never;
private int _directorySizeLimit;
private TimeSpan _directoryTimeLimit = new TimeSpan(0);
}
}
namespace System.DirectoryServices.Protocols
{
public class DsmlAuthRequest : DirectoryRequest
{
public DsmlAuthRequest() => Principal = string.Empty;
public DsmlAuthRequest(string principal) => Principal = principal;
public string Principal { get; set; }
}
}