예제 #1
0
        public DirectoryEntry(string sLDAPPath)
        {
            this.sLDAPPath = sLDAPPath;
            propertyCollection = null;
            nativeObject = null;
            sName = null;
            children = null;
            objectSecurity = null;
            guid = Guid.Empty;
            parent = null;
            objectClassType = null;

            SDSUtils.CrackPath(sLDAPPath, out sProtocol, out sServer, out sCNs, out sDCs);

            /*if (sProtocol != null) Console.WriteLine("sProtocol is " + sProtocol);
            if (sServer != null) Console.WriteLine("sServer is " + sServer);
            if (sCNs != null) Console.WriteLine("sCNs is " + sCNs);
            if (sDCs != null) Console.WriteLine("sDCs is " + sDCs); */

            string[] rootDNcom;

            if (sServer != null)
            {
                rootDNcom = sServer.Split('.');

                rootDN = "";

                foreach (string str in rootDNcom)
                {
                    string temp = string.Concat("dc=", str, ",");
                    rootDN = string.Concat(rootDN, temp);
                }

                rootDN = rootDN.Substring(0, rootDN.Length - 1);
            }
            //beacuse rootDN is nothing but collection of all DC's from DN
            if (sDCs != null)
                rootDN = sDCs;

            baseDn = "";

            //sCNs = RootDSE, Configuration, Schema, Domain
            if (sCNs != null && sDCs == null)
            {
                if (sCNs.Equals("RootDSE", StringComparison.InvariantCultureIgnoreCase))
                    baseDn = "";
                else if (sCNs.Equals("Configuration", StringComparison.InvariantCultureIgnoreCase))
                    baseDn = string.Concat("CN=Configuration,", rootDN);
                else if (sCNs.Equals("Schema", StringComparison.InvariantCultureIgnoreCase))
                    baseDn = string.Concat("CN=Schema,", rootDN);
                else if (sCNs.Equals("Domain", StringComparison.InvariantCultureIgnoreCase) ||
                 sCNs.Equals("", StringComparison.InvariantCultureIgnoreCase) ||
                 sCNs.StartsWith("<"))
                {
                    if (rootDN != null)
                        baseDn = rootDN;
                }
                else baseDn = string.Concat(sCNs, ",", rootDN);

            }

            if (sCNs != null && sDCs != null)
                baseDn = string.Concat(sCNs, ",", sDCs);

            if (sCNs == null && sDCs != null)
                baseDn = sDCs;

            if (sCNs == null && sDCs == null)
                baseDn = rootDN;

            //assign sName value using the dN of this node
            if (baseDn.Equals("", StringComparison.InvariantCultureIgnoreCase))
                sName = "RootDSE";
            else
                sName = baseDn;
        }
예제 #2
0
		internal ADPropertyValueCollection ConvertFromRaw(string propertyName, ADPropertyValueCollection propertyValues)
		{
			string str = null;
			int num = 0;
			ADPropertyValueCollection aDPropertyValueCollection;
			byte[] bytes;
			this.Init();
			if (propertyValues.Count != 0)
			{
				ADObjectSearcher.ContainsRangeRetrievalTag(propertyName, out str, out num);
				ADAttributeSyntax propertyType = this._adSchema.GetPropertyType(str);
				ADAttributeSyntax aDAttributeSyntax = propertyType;
				switch (aDAttributeSyntax)
				{
					case ADAttributeSyntax.DirectoryString:
					case ADAttributeSyntax.DN:
					{
						aDPropertyValueCollection = propertyValues;
						break;
					}
					case ADAttributeSyntax.OctetString:
					{
						aDPropertyValueCollection = propertyValues;
						break;
					}
					case ADAttributeSyntax.SecurityDescriptor:
					{
						aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
						IEnumerator enumerator = propertyValues.GetEnumerator();
						try
						{
							while (enumerator.MoveNext())
							{
								byte[] current = (byte[])enumerator.Current;
								ActiveDirectorySecurity activeDirectorySecurity = new ActiveDirectorySecurity();
								activeDirectorySecurity.SetSecurityDescriptorBinaryForm(current);
								aDPropertyValueCollection.Add(activeDirectorySecurity);
							}
							break;
						}
						finally
						{
							IDisposable disposable = enumerator as IDisposable;
							if (disposable != null)
							{
								disposable.Dispose();
							}
						}
					}
					case ADAttributeSyntax.Int:
					case ADAttributeSyntax.Enumeration:
					{
						aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
						IEnumerator enumerator1 = propertyValues.GetEnumerator();
						try
						{
							while (enumerator1.MoveNext())
							{
								string current1 = (string)enumerator1.Current;
								aDPropertyValueCollection.Add(int.Parse(current1, NumberFormatInfo.InvariantInfo));
							}
							break;
						}
						finally
						{
							IDisposable disposable1 = enumerator1 as IDisposable;
							if (disposable1 != null)
							{
								disposable1.Dispose();
							}
						}
					}
					case ADAttributeSyntax.Int64:
					{
						aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
						IEnumerator enumerator2 = propertyValues.GetEnumerator();
						try
						{
							while (enumerator2.MoveNext())
							{
								string str1 = (string)enumerator2.Current;
								aDPropertyValueCollection.Add(long.Parse(str1, NumberFormatInfo.InvariantInfo));
							}
							break;
						}
						finally
						{
							IDisposable disposable2 = enumerator2 as IDisposable;
							if (disposable2 != null)
							{
								disposable2.Dispose();
							}
						}
					}
					case ADAttributeSyntax.Bool:
					{
						aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
						IEnumerator enumerator3 = propertyValues.GetEnumerator();
						try
						{
							while (enumerator3.MoveNext())
							{
								string current2 = (string)enumerator3.Current;
								if (string.Compare(current2, "TRUE", StringComparison.OrdinalIgnoreCase) != 0)
								{
									aDPropertyValueCollection.Add(false);
								}
								else
								{
									aDPropertyValueCollection.Add(true);
								}
							}
							break;
						}
						finally
						{
							IDisposable disposable3 = enumerator3 as IDisposable;
							if (disposable3 != null)
							{
								disposable3.Dispose();
							}
						}
					}
					case ADAttributeSyntax.Oid:
					case ADAttributeSyntax.DNWithBinary:
					case ADAttributeSyntax.DNWithString:
					case ADAttributeSyntax.IA5String:
					case ADAttributeSyntax.PrintableString:
					{
						aDPropertyValueCollection = propertyValues;
						break;
					}
					case ADAttributeSyntax.GeneralizedTime:
					case ADAttributeSyntax.UtcTime:
					{
						aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
						IEnumerator enumerator4 = propertyValues.GetEnumerator();
						try
						{
							while (enumerator4.MoveNext())
							{
								string str2 = (string)enumerator4.Current;
								aDPropertyValueCollection.Add(ADTypeConverter.ParseDateTimeValue(str2, propertyType));
							}
							break;
						}
						finally
						{
							IDisposable disposable4 = enumerator4 as IDisposable;
							if (disposable4 != null)
							{
								disposable4.Dispose();
							}
						}
					}
					case ADAttributeSyntax.Sid:
					{
						aDPropertyValueCollection = new ADPropertyValueCollection(propertyValues.Count);
						IEnumerator enumerator5 = propertyValues.GetEnumerator();
						try
						{
							while (enumerator5.MoveNext())
							{
								object obj = enumerator5.Current;
								if (obj as string == null)
								{
									bytes = (byte[])obj;
								}
								else
								{
									bytes = ADTypeConverter._encoder.GetBytes((string)obj);
								}
								aDPropertyValueCollection.Add(new SecurityIdentifier(bytes, 0));
							}
							break;
						}
						finally
						{
							IDisposable disposable5 = enumerator5 as IDisposable;
							if (disposable5 != null)
							{
								disposable5.Dispose();
							}
						}
					}
					default:
					{
						aDPropertyValueCollection = propertyValues;
						break;
					}
				}
				return aDPropertyValueCollection;
			}
			else
			{
				return null;
			}
		}
예제 #3
0
		internal ADPropertyValueCollection ConvertFromRaw(DirectoryAttribute property)
		{
			string str = null;
			int num = 0;
			this.Init();
			if (property == null || property.Count == 0)
			{
				return null;
			}
			else
			{
				ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection();
				ADObjectSearcher.ContainsRangeRetrievalTag(property.Name, out str, out num);
				ADAttributeSyntax propertyType = this._adSchema.GetPropertyType(str);
				string[] values = null;
				byte[][] numArray = null;
				ADAttributeSyntax aDAttributeSyntax = propertyType;
				switch (aDAttributeSyntax)
				{
					case ADAttributeSyntax.DirectoryString:
					case ADAttributeSyntax.DN:
					{
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
						break;
					}
					case ADAttributeSyntax.OctetString:
					{
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(byte[])));
						break;
					}
					case ADAttributeSyntax.SecurityDescriptor:
					{
						numArray = (byte[][])property.GetValues(typeof(byte[]));
						byte[][] numArray1 = numArray;
						for (int i = 0; i < (int)numArray1.Length; i++)
						{
							byte[] numArray2 = numArray1[i];
							ActiveDirectorySecurity activeDirectorySecurity = new ActiveDirectorySecurity();
							activeDirectorySecurity.SetSecurityDescriptorBinaryForm(numArray2);
							aDPropertyValueCollection.Add(activeDirectorySecurity);
						}
						break;
					}
					case ADAttributeSyntax.Int:
					case ADAttributeSyntax.Enumeration:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays = values;
						for (int j = 0; j < (int)strArrays.Length; j++)
						{
							string str1 = strArrays[j];
							aDPropertyValueCollection.Add(int.Parse(str1, NumberFormatInfo.InvariantInfo));
						}
						break;
					}
					case ADAttributeSyntax.Int64:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays1 = values;
						for (int k = 0; k < (int)strArrays1.Length; k++)
						{
							string str2 = strArrays1[k];
							aDPropertyValueCollection.Add(long.Parse(str2, NumberFormatInfo.InvariantInfo));
						}
						break;
					}
					case ADAttributeSyntax.Bool:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays2 = values;
						for (int l = 0; l < (int)strArrays2.Length; l++)
						{
							string str3 = strArrays2[l];
							if (string.Compare(str3, "TRUE", StringComparison.OrdinalIgnoreCase) != 0)
							{
								aDPropertyValueCollection.Add(false);
							}
							else
							{
								aDPropertyValueCollection.Add(true);
							}
						}
						break;
					}
					case ADAttributeSyntax.Oid:
					case ADAttributeSyntax.DNWithBinary:
					case ADAttributeSyntax.DNWithString:
					case ADAttributeSyntax.IA5String:
					case ADAttributeSyntax.PrintableString:
					{
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
						break;
					}
					case ADAttributeSyntax.GeneralizedTime:
					case ADAttributeSyntax.UtcTime:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays3 = values;
						for (int m = 0; m < (int)strArrays3.Length; m++)
						{
							string str4 = strArrays3[m];
							aDPropertyValueCollection.Add(ADTypeConverter.ParseDateTimeValue(str4, propertyType));
						}
						break;
					}
					case ADAttributeSyntax.Sid:
					{
						numArray = (byte[][])property.GetValues(typeof(byte[]));
						byte[][] numArray3 = numArray;
						for (int n = 0; n < (int)numArray3.Length; n++)
						{
							byte[] numArray4 = numArray3[n];
							aDPropertyValueCollection.Add(new SecurityIdentifier(numArray4, 0));
						}
						break;
					}
					default:
					{
						if (aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
						{
							aDPropertyValueCollection.AddRange(property.GetValues(typeof(byte[])));
							break;
						}
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
						break;
					}
				}
				return aDPropertyValueCollection;
			}
		}
예제 #4
0
파일: ADProvider.cs 프로젝트: nickchal/pash
		private void WriteADObjectSecurityDescriptor(ADObject adObj, ActiveDirectorySecurity ads, ADProviderCommonParameters parameters, ADDriveInfo extendedDriveInfo)
		{
			if (this.GetFormatType(parameters, extendedDriveInfo) != ADPathFormat.Canonical)
			{
				this.WriteSecurityDescriptorObjectWithAbsolutePath(ads, adObj.DistinguishedName);
				return;
			}
			else
			{
				if (!adObj.Contains("canonicalName"))
				{
					base.WriteError(ADUtilities.GetErrorRecord(new ADException(string.Format(StringResources.ADProviderUnableToReadProperty, "canonicalName", adObj.DistinguishedName)), "ADProvider:WriteADObjectSecurityDescriptor:UnableToReadCanonicalName", adObj.DistinguishedName));
					this.Trace(DebugLogLevel.Error, string.Format("Leaving WriteADObjectSecurityDescriptor: Unable to read canonical name for object {0}.", adObj.DistinguishedName));
					return;
				}
				else
				{
					string value = (string)adObj["canonicalName"].Value;
					this.WriteSecurityDescriptorObjectWithAbsolutePath(ads, value);
					return;
				}
			}
		}
예제 #5
0
        protected static void ScanACLForChangePasswordRight(
                                        ActiveDirectorySecurity adsSecurity,
                                        out bool denySelfFound,
                                        out bool denyWorldFound,
                                        out bool allowSelfFound,
                                        out bool allowWorldFound)
        {
            denySelfFound = false;
            denyWorldFound = false;
            allowSelfFound = false;
            allowWorldFound = false;

            MACLPrinc.SecurityIdentifier trustee;

            foreach (ActiveDirectoryAccessRule rule in adsSecurity.GetAccessRules(true, true, typeof(MACLPrinc.SecurityIdentifier)))
            {
                trustee = (MACLPrinc.SecurityIdentifier)rule.IdentityReference;
                string sidSddl = trustee.Value;

                if (rule.ObjectType == s_changePasswordGuid)
                {
                    if (rule.AccessControlType == AccessControlType.Deny)
                    {
                        if (sidSddl == SelfSddl)
                        {
                            denySelfFound = true;
                        }
                        else if (sidSddl == WorldSddl)
                        {
                            denyWorldFound = true;
                        }
                    }
                    else if (rule.AccessControlType == AccessControlType.Allow)
                    {
                        if (sidSddl == SelfSddl)
                        {
                            allowSelfFound = true;
                        }
                        else if (sidSddl == WorldSddl)
                        {
                            allowWorldFound = true;
                        }
                    }
                }
            }
        }
예제 #6
0
        public DirectoryEntry(string sLDAPPath)
        {
            this.sLDAPPath     = sLDAPPath;
            propertyCollection = null;
            nativeObject       = null;
            sName           = null;
            children        = null;
            objectSecurity  = null;
            guid            = Guid.Empty;
            parent          = null;
            objectClassType = null;

            SDSUtils.CrackPath(sLDAPPath, out sProtocol, out sServer, out sCNs, out sDCs);

            /*if (sProtocol != null) Console.WriteLine("sProtocol is " + sProtocol);
             * if (sServer != null) Console.WriteLine("sServer is " + sServer);
             * if (sCNs != null) Console.WriteLine("sCNs is " + sCNs);
             * if (sDCs != null) Console.WriteLine("sDCs is " + sDCs); */

            string[] rootDNcom;

            if (sServer != null)
            {
                rootDNcom = sServer.Split('.');

                rootDN = "";

                foreach (string str in rootDNcom)
                {
                    string temp = string.Concat("dc=", str, ",");
                    rootDN = string.Concat(rootDN, temp);
                }

                rootDN = rootDN.Substring(0, rootDN.Length - 1);
            }
            //beacuse rootDN is nothing but collection of all DC's from DN
            if (sDCs != null)
            {
                rootDN = sDCs;
            }

            baseDn = "";

            //sCNs = RootDSE, Configuration, Schema, Domain
            if (sCNs != null && sDCs == null)
            {
                if (sCNs.Equals("RootDSE", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = "";
                }
                else if (sCNs.Equals("Configuration", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = string.Concat("CN=Configuration,", rootDN);
                }
                else if (sCNs.Equals("Schema", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = string.Concat("CN=Schema,", rootDN);
                }
                else if (sCNs.Equals("Domain", StringComparison.InvariantCultureIgnoreCase) ||
                         sCNs.Equals("", StringComparison.InvariantCultureIgnoreCase) ||
                         sCNs.StartsWith("<"))
                {
                    if (rootDN != null)
                    {
                        baseDn = rootDN;
                    }
                }
                else
                {
                    baseDn = string.Concat(sCNs, ",", rootDN);
                }
            }

            if (sCNs != null && sDCs != null)
            {
                baseDn = string.Concat(sCNs, ",", sDCs);
            }

            if (sCNs == null && sDCs != null)
            {
                baseDn = sDCs;
            }

            if (sCNs == null && sDCs == null)
            {
                baseDn = rootDN;
            }

            //assign sName value using the dN of this node
            if (baseDn.Equals("", StringComparison.InvariantCultureIgnoreCase))
            {
                sName = "RootDSE";
            }
            else
            {
                sName = baseDn;
            }
        }