|
5 | 5 | // Licensed under the Non-Profit OSL. See LICENSE file in the project root for full license information.
|
6 | 6 | //
|
7 | 7 | using System;
|
8 |
| -using System.Collections.Generic; |
9 | 8 | using System.Diagnostics;
|
10 | 9 | using System.Net;
|
11 |
| -using System.Text; |
| 10 | +using System.Security.Principal; |
12 | 11 |
|
13 | 12 | namespace PingCastle.ADWS
|
14 | 13 | {
|
15 |
| - public abstract class ADConnection : IADConnection |
16 |
| - { |
| 14 | + public abstract class ADConnection : IADConnection |
| 15 | + { |
17 | 16 |
|
18 |
| - public abstract void Enumerate(string distinguishedName, string filter, string[] properties, WorkOnReturnedObjectByADWS callback, string scope); |
19 |
| - public abstract void EstablishConnection(); |
| 17 | + public abstract void Enumerate(string distinguishedName, string filter, string[] properties, WorkOnReturnedObjectByADWS callback, string scope); |
| 18 | + public abstract void EstablishConnection(); |
20 | 19 |
|
21 |
| - public string Server { get; set; } |
| 20 | + public string Server { get; set; } |
22 | 21 |
|
23 |
| - public int Port { get; set; } |
| 22 | + public int Port { get; set; } |
24 | 23 |
|
25 |
| - public NetworkCredential Credential { get; set; } |
| 24 | + public NetworkCredential Credential { get; set; } |
26 | 25 |
|
27 |
| - protected abstract ADDomainInfo GetDomainInfoInternal(); |
28 |
| - protected ADDomainInfo domainInfo; |
| 26 | + protected abstract ADDomainInfo GetDomainInfoInternal(); |
| 27 | + protected ADDomainInfo domainInfo; |
29 | 28 |
|
30 |
| - public ADDomainInfo GetDomainInfo() |
31 |
| - { |
32 |
| - if (domainInfo == null) |
33 |
| - domainInfo = GetDomainInfoInternal(); |
34 |
| - return domainInfo; |
35 |
| - } |
| 29 | + public ADDomainInfo GetDomainInfo() |
| 30 | + { |
| 31 | + if (domainInfo == null) |
| 32 | + domainInfo = GetDomainInfoInternal(); |
| 33 | + return domainInfo; |
| 34 | + } |
36 | 35 |
|
37 |
| - public static string EscapeLDAP(string input) |
38 |
| - { |
39 |
| - string strTemp = input.Replace("\\", "\\5c"); |
40 |
| - strTemp = strTemp.Replace("(", "\\28"); |
41 |
| - strTemp = strTemp.Replace("|", "\\7c"); |
42 |
| - strTemp = strTemp.Replace("<", "\\3c"); |
43 |
| - strTemp = strTemp.Replace("/", "\\2f"); |
44 |
| - strTemp = strTemp.Replace(")", "\\29"); |
45 |
| - strTemp = strTemp.Replace("=", "\\3d"); |
46 |
| - strTemp = strTemp.Replace("~", "\\7e"); |
47 |
| - strTemp = strTemp.Replace("&", "\\26"); |
48 |
| - strTemp = strTemp.Replace(">", "\\3e"); |
49 |
| - strTemp = strTemp.Replace("*", "\\2a"); |
50 |
| - return strTemp; |
51 |
| - } |
| 36 | + public static string EscapeLDAP(string input) |
| 37 | + { |
| 38 | + string strTemp = input.Replace("\\", "\\5c"); |
| 39 | + strTemp = strTemp.Replace("(", "\\28"); |
| 40 | + strTemp = strTemp.Replace("|", "\\7c"); |
| 41 | + strTemp = strTemp.Replace("<", "\\3c"); |
| 42 | + strTemp = strTemp.Replace("/", "\\2f"); |
| 43 | + strTemp = strTemp.Replace(")", "\\29"); |
| 44 | + strTemp = strTemp.Replace("=", "\\3d"); |
| 45 | + strTemp = strTemp.Replace("~", "\\7e"); |
| 46 | + strTemp = strTemp.Replace("&", "\\26"); |
| 47 | + strTemp = strTemp.Replace(">", "\\3e"); |
| 48 | + strTemp = strTemp.Replace("*", "\\2a"); |
| 49 | + return strTemp; |
| 50 | + } |
52 | 51 |
|
53 |
| - public static string EncodeSidToString(string sid) |
54 |
| - { |
55 |
| - try |
56 |
| - { |
57 |
| - var realsid = new System.Security.Principal.SecurityIdentifier(sid); |
58 |
| - var bytesid = new byte[realsid.BinaryLength]; |
59 |
| - realsid.GetBinaryForm(bytesid, 0); |
60 |
| - return "\\" + BitConverter.ToString(bytesid).Replace("-", "\\"); |
61 |
| - } |
62 |
| - catch (ArgumentException) |
63 |
| - { |
64 |
| - Trace.WriteLine("Unable to encode " + sid); |
65 |
| - throw; |
66 |
| - } |
67 |
| - } |
68 |
| - } |
| 52 | + public static string EncodeSidToString(string sid) |
| 53 | + { |
| 54 | + try |
| 55 | + { |
| 56 | + var realsid = new System.Security.Principal.SecurityIdentifier(sid); |
| 57 | + var bytesid = new byte[realsid.BinaryLength]; |
| 58 | + realsid.GetBinaryForm(bytesid, 0); |
| 59 | + return "\\" + BitConverter.ToString(bytesid).Replace("-", "\\"); |
| 60 | + } |
| 61 | + catch (ArgumentException) |
| 62 | + { |
| 63 | + Trace.WriteLine("Unable to encode " + sid); |
| 64 | + throw; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public abstract string ConvertSIDToName(string sidstring, out string referencedDomain); |
| 69 | + |
| 70 | + public abstract SecurityIdentifier ConvertNameToSID(string nameToResolve); |
| 71 | + |
| 72 | + public abstract IFileConnection FileConnection {get;} |
| 73 | + |
| 74 | + } |
69 | 75 | }
|
0 commit comments