Ejemplo n.º 1
0
        internal LdapControl[] BuildControlArray(DirectoryControlCollection controls, bool serverControl)
        {
            int count = 0;
            LdapControl[] managedControls = null;

            if (controls != null && controls.Count != 0)
            {
                ArrayList controlList = new ArrayList();
                foreach (DirectoryControl col in controls)
                {
                    if (serverControl == true)
                    {
                        if (col.ServerSide)
                            controlList.Add(col);
                    }
                    else
                    {
                        if (!col.ServerSide)
                            controlList.Add(col);
                    }
                }
                if (controlList.Count != 0)
                {
                    count = controlList.Count;

                    managedControls = new LdapControl[count];

                    for (int i = 0; i < count; i++)
                    {
                        managedControls[i] = new LdapControl();
                        // get the control type
                        managedControls[i].ldctl_oid = Marshal.StringToHGlobalUni(((DirectoryControl)controlList[i]).Type);
                        //get the control cricality
                        managedControls[i].ldctl_iscritical = ((DirectoryControl)controlList[i]).IsCritical;
                        // get the control value
                        DirectoryControl tempControl = (DirectoryControl)controlList[i];
                        byte[] byteControlValue = tempControl.GetValue();
                        if (byteControlValue == null || byteControlValue.Length == 0)
                        {
                            // treat the control value as null
                            managedControls[i].ldctl_value = new berval();
                            managedControls[i].ldctl_value.bv_len = 0;
                            managedControls[i].ldctl_value.bv_val = (IntPtr)0;
                        }
                        else
                        {
                            managedControls[i].ldctl_value = new berval();
                            managedControls[i].ldctl_value.bv_len = byteControlValue.Length;
                            managedControls[i].ldctl_value.bv_val = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * managedControls[i].ldctl_value.bv_len);
                            Marshal.Copy(byteControlValue, 0, managedControls[i].ldctl_value.bv_val, managedControls[i].ldctl_value.bv_len);
                        }
                    }
                }
            }

            return managedControls;
        }
Ejemplo n.º 2
0
        private DirectoryControl ConstructControl(IntPtr controlPtr)
        {
            LdapControl control = new LdapControl();
            Marshal.PtrToStructure(controlPtr, control);

            Debug.Assert(control.ldctl_oid != (IntPtr)0);
            string controlType = Marshal.PtrToStringUni(control.ldctl_oid);

            byte[] bytes = new byte[control.ldctl_value.bv_len];
            Marshal.Copy(control.ldctl_value.bv_val, bytes, 0, control.ldctl_value.bv_len);

            bool criticality = control.ldctl_iscritical;

            return new DirectoryControl(controlType, bytes, criticality, true);
        }
Ejemplo n.º 3
0
        public override byte[] GetValue()
        {
            IntPtr intPtr;
            byte   num;
            IntPtr intPtr1 = (IntPtr)0;
            int    num1    = Marshal.SizeOf(typeof(SortKey));
            IntPtr intPtr2 = Utility.AllocHGlobalIntPtrArray((int)this.keys.Length + 1);

            try
            {
                int i = 0;
                for (i = 0; i < (int)this.keys.Length; i++)
                {
                    IntPtr intPtr3 = Marshal.AllocHGlobal(num1);
                    Marshal.StructureToPtr(this.keys[i], intPtr3, false);
                    intPtr = (IntPtr)((long)intPtr2 + (long)(Marshal.SizeOf(typeof(IntPtr)) * i));
                    Marshal.WriteIntPtr(intPtr, intPtr3);
                }
                intPtr = (IntPtr)((long)intPtr2 + (long)(Marshal.SizeOf(typeof(IntPtr)) * i));
                Marshal.WriteIntPtr(intPtr, (IntPtr)0);
                bool             isCritical = base.IsCritical;
                ConnectionHandle handle     = UtilityHandle.GetHandle();
                IntPtr           intPtr4    = intPtr2;
                if (isCritical)
                {
                    num = 1;
                }
                else
                {
                    num = 0;
                }
                int num2 = Wldap32.ldap_create_sort_control(handle, intPtr4, num, ref intPtr1);
                if (num2 == 0)
                {
                    LdapControl ldapControl = new LdapControl();
                    Marshal.PtrToStructure(intPtr1, ldapControl);
                    berval ldctlValue = ldapControl.ldctl_value;
                    this.directoryControlValue = null;
                    if (ldctlValue != null)
                    {
                        this.directoryControlValue = new byte[ldctlValue.bv_len];
                        Marshal.Copy(ldctlValue.bv_val, this.directoryControlValue, 0, ldctlValue.bv_len);
                    }
                }
                else
                {
                    if (!Utility.IsLdapError((LdapError)num2))
                    {
                        throw new LdapException(num2);
                    }
                    else
                    {
                        string str = LdapErrorMappings.MapResultCode(num2);
                        throw new LdapException(num2, str);
                    }
                }
            }
            finally
            {
                if (intPtr1 != (IntPtr)0)
                {
                    Wldap32.ldap_control_free(intPtr1);
                }
                if (intPtr2 != (IntPtr)0)
                {
                    for (int j = 0; j < (int)this.keys.Length; j++)
                    {
                        IntPtr intPtr5 = Marshal.ReadIntPtr(intPtr2, Marshal.SizeOf(typeof(IntPtr)) * j);
                        if (intPtr5 != (IntPtr)0)
                        {
                            IntPtr intPtr6 = Marshal.ReadIntPtr(intPtr5);
                            if (intPtr6 != (IntPtr)0)
                            {
                                Marshal.FreeHGlobal(intPtr6);
                            }
                            intPtr6 = Marshal.ReadIntPtr(intPtr5, Marshal.SizeOf(typeof(IntPtr)));
                            if (intPtr6 != (IntPtr)0)
                            {
                                Marshal.FreeHGlobal(intPtr6);
                            }
                            Marshal.FreeHGlobal(intPtr5);
                        }
                    }
                    Marshal.FreeHGlobal(intPtr2);
                }
            }
            return(base.GetValue());
        }
Ejemplo n.º 4
0
        public override byte[] GetValue()
        {
            IntPtr control    = (IntPtr)0;
            int    structSize = Marshal.SizeOf(typeof(SortKey));
            int    keyCount   = _keys.Length;
            IntPtr memHandle  = Utility.AllocHGlobalIntPtrArray(keyCount + 1);

            try
            {
                IntPtr tempPtr = (IntPtr)0;
                IntPtr sortPtr = (IntPtr)0;
                int    i       = 0;
                for (i = 0; i < keyCount; i++)
                {
                    sortPtr = Marshal.AllocHGlobal(structSize);
                    Marshal.StructureToPtr(_keys[i], sortPtr, false);
                    tempPtr = (IntPtr)((long)memHandle + Marshal.SizeOf(typeof(IntPtr)) * i);
                    Marshal.WriteIntPtr(tempPtr, sortPtr);
                }
                tempPtr = (IntPtr)((long)memHandle + Marshal.SizeOf(typeof(IntPtr)) * i);
                Marshal.WriteIntPtr(tempPtr, (IntPtr)0);

                bool critical = IsCritical;
                int  error    = Wldap32.ldap_create_sort_control(UtilityHandle.GetHandle(), memHandle, critical ? (byte)1 : (byte)0, ref control);

                if (error != 0)
                {
                    if (Utility.IsLdapError((LdapError)error))
                    {
                        string errorMessage = LdapErrorMappings.MapResultCode(error);
                        throw new LdapException(error, errorMessage);
                    }
                    else
                    {
                        throw new LdapException(error);
                    }
                }

                LdapControl managedControl = new LdapControl();
                Marshal.PtrToStructure(control, managedControl);
                berval value = managedControl.ldctl_value;
                // reinitialize the value
                directoryControlValue = null;
                if (value != null)
                {
                    directoryControlValue = new byte[value.bv_len];
                    Marshal.Copy(value.bv_val, directoryControlValue, 0, value.bv_len);
                }
            }
            finally
            {
                if (control != (IntPtr)0)
                {
                    Wldap32.ldap_control_free(control);
                }

                if (memHandle != (IntPtr)0)
                {
                    //release the memory from the heap
                    for (int i = 0; i < keyCount; i++)
                    {
                        IntPtr tempPtr = Marshal.ReadIntPtr(memHandle, Marshal.SizeOf(typeof(IntPtr)) * i);
                        if (tempPtr != (IntPtr)0)
                        {
                            // free the marshalled name
                            IntPtr ptr = Marshal.ReadIntPtr(tempPtr);
                            if (ptr != (IntPtr)0)
                            {
                                Marshal.FreeHGlobal(ptr);
                            }
                            // free the marshalled rule
                            ptr = Marshal.ReadIntPtr(tempPtr, Marshal.SizeOf(typeof(IntPtr)));
                            if (ptr != (IntPtr)0)
                            {
                                Marshal.FreeHGlobal(ptr);
                            }

                            Marshal.FreeHGlobal(tempPtr);
                        }
                    }
                    Marshal.FreeHGlobal(memHandle);
                }
            }

            return(base.GetValue());
        }
Ejemplo n.º 5
0
		internal LdapControl[] BuildControlArray(DirectoryControlCollection controls, bool serverControl)
		{
			LdapControl[] ldapControl = null;
			if (controls != null && controls.Count != 0)
			{
				ArrayList arrayLists = new ArrayList();
				foreach (DirectoryControl control in controls)
				{
					if (!serverControl)
					{
						if (control.ServerSide)
						{
							continue;
						}
						arrayLists.Add(control);
					}
					else
					{
						if (!control.ServerSide)
						{
							continue;
						}
						arrayLists.Add(control);
					}
				}
				if (arrayLists.Count != 0)
				{
					int count = arrayLists.Count;
					ldapControl = new LdapControl[count];
					for (int i = 0; i < count; i++)
					{
						ldapControl[i] = new LdapControl();
						ldapControl[i].ldctl_oid = Marshal.StringToHGlobalUni(((DirectoryControl)arrayLists[i]).Type);
						ldapControl[i].ldctl_iscritical = ((DirectoryControl)arrayLists[i]).IsCritical;
						DirectoryControl item = (DirectoryControl)arrayLists[i];
						byte[] value = item.GetValue();
						if (value == null || (int)value.Length == 0)
						{
							ldapControl[i].ldctl_value = new berval();
							ldapControl[i].ldctl_value.bv_len = 0;
							ldapControl[i].ldctl_value.bv_val = (IntPtr)0;
						}
						else
						{
							ldapControl[i].ldctl_value = new berval();
							ldapControl[i].ldctl_value.bv_len = (int)value.Length;
							ldapControl[i].ldctl_value.bv_val = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * ldapControl[i].ldctl_value.bv_len);
							Marshal.Copy(value, 0, ldapControl[i].ldctl_value.bv_val, ldapControl[i].ldctl_value.bv_len);
						}
					}
				}
			}
			return ldapControl;
		}
Ejemplo n.º 6
0
		private DirectoryControl ConstructControl(IntPtr controlPtr)
		{
			LdapControl ldapControl = new LdapControl();
			Marshal.PtrToStructure(controlPtr, ldapControl);
			string stringUni = Marshal.PtrToStringUni(ldapControl.ldctl_oid);
			byte[] numArray = new byte[ldapControl.ldctl_value.bv_len];
			Marshal.Copy(ldapControl.ldctl_value.bv_val, numArray, 0, ldapControl.ldctl_value.bv_len);
			bool ldctlIscritical = ldapControl.ldctl_iscritical;
			return new DirectoryControl(stringUni, numArray, ldctlIscritical, true);
		}
        public override byte[] GetValue()
        {
            IntPtr zero   = IntPtr.Zero;
            int    cb     = Marshal.SizeOf(typeof(SortKey));
            int    length = this.keys.Length;
            IntPtr keys   = Marshal.AllocHGlobal((int)(Marshal.SizeOf(typeof(IntPtr)) * (length + 1)));

            try
            {
                IntPtr ptr   = IntPtr.Zero;
                IntPtr ptr4  = IntPtr.Zero;
                int    index = 0;
                index = 0;
                while (index < length)
                {
                    ptr4 = Marshal.AllocHGlobal(cb);
                    Marshal.StructureToPtr(this.keys[index], ptr4, false);
                    ptr = (IntPtr)(((long)keys) + (Marshal.SizeOf(typeof(IntPtr)) * index));
                    Marshal.WriteIntPtr(ptr, ptr4);
                    index++;
                }
                ptr = (IntPtr)(((long)keys) + (Marshal.SizeOf(typeof(IntPtr)) * index));
                Marshal.WriteIntPtr(ptr, IntPtr.Zero);
                bool isCritical = base.IsCritical;
                int  errorCode  = Wldap32.ldap_create_sort_control(UtilityHandle.GetHandle(), keys, isCritical ? ((byte)1) : ((byte)0), ref zero);
                if (errorCode != 0)
                {
                    if (Utility.IsLdapError((LdapError)errorCode))
                    {
                        string message = LdapErrorMappings.MapResultCode(errorCode);
                        throw new LdapException(errorCode, message);
                    }
                    throw new LdapException(errorCode);
                }
                LdapControl structure = new LdapControl();
                Marshal.PtrToStructure(zero, structure);
                berval berval = structure.ldctl_value;
                base.directoryControlValue = null;
                if (berval != null)
                {
                    base.directoryControlValue = new byte[berval.bv_len];
                    Marshal.Copy(berval.bv_val, base.directoryControlValue, 0, berval.bv_len);
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Wldap32.ldap_control_free(zero);
                }
                if (keys != IntPtr.Zero)
                {
                    for (int i = 0; i < length; i++)
                    {
                        IntPtr ptr5 = Marshal.ReadIntPtr(keys, Marshal.SizeOf(typeof(IntPtr)) * i);
                        if (ptr5 != IntPtr.Zero)
                        {
                            IntPtr hglobal = Marshal.ReadIntPtr(ptr5);
                            if (hglobal != IntPtr.Zero)
                            {
                                Marshal.FreeHGlobal(hglobal);
                            }
                            hglobal = Marshal.ReadIntPtr(ptr5, Marshal.SizeOf(typeof(IntPtr)));
                            if (hglobal != IntPtr.Zero)
                            {
                                Marshal.FreeHGlobal(hglobal);
                            }
                            Marshal.FreeHGlobal(ptr5);
                        }
                    }
                    Marshal.FreeHGlobal(keys);
                }
            }
            return(base.GetValue());
        }
Ejemplo n.º 8
0
        public override byte[] GetValue()
        {
            IntPtr control = (IntPtr)0;
            int structSize = Marshal.SizeOf(typeof(SortKey));
            int keyCount = _keys.Length;
            IntPtr memHandle = Utility.AllocHGlobalIntPtrArray(keyCount + 1);

            try
            {
                IntPtr tempPtr = (IntPtr)0;
                IntPtr sortPtr = (IntPtr)0;
                int i = 0;
                for (i = 0; i < keyCount; i++)
                {
                    sortPtr = Marshal.AllocHGlobal(structSize);
                    Marshal.StructureToPtr(_keys[i], sortPtr, false);
                    tempPtr = (IntPtr)((long)memHandle + Marshal.SizeOf(typeof(IntPtr)) * i);
                    Marshal.WriteIntPtr(tempPtr, sortPtr);
                }
                tempPtr = (IntPtr)((long)memHandle + Marshal.SizeOf(typeof(IntPtr)) * i);
                Marshal.WriteIntPtr(tempPtr, (IntPtr)0);

                bool critical = IsCritical;
                int error = Wldap32.ldap_create_sort_control(UtilityHandle.GetHandle(), memHandle, critical ? (byte)1 : (byte)0, ref control);

                if (error != 0)
                {
                    if (Utility.IsLdapError((LdapError)error))
                    {
                        string errorMessage = LdapErrorMappings.MapResultCode(error);
                        throw new LdapException(error, errorMessage);
                    }
                    else
                        throw new LdapException(error);
                }

                LdapControl managedControl = new LdapControl();
                Marshal.PtrToStructure(control, managedControl);
                berval value = managedControl.ldctl_value;
                // reinitialize the value
                directoryControlValue = null;
                if (value != null)
                {
                    directoryControlValue = new byte[value.bv_len];
                    Marshal.Copy(value.bv_val, directoryControlValue, 0, value.bv_len);
                }
            }
            finally
            {
                if (control != (IntPtr)0)
                    Wldap32.ldap_control_free(control);

                if (memHandle != (IntPtr)0)
                {
                    //release the memory from the heap
                    for (int i = 0; i < keyCount; i++)
                    {
                        IntPtr tempPtr = Marshal.ReadIntPtr(memHandle, Marshal.SizeOf(typeof(IntPtr)) * i);
                        if (tempPtr != (IntPtr)0)
                        {
                            // free the marshalled name
                            IntPtr ptr = Marshal.ReadIntPtr(tempPtr);
                            if (ptr != (IntPtr)0)
                                Marshal.FreeHGlobal(ptr);
                            // free the marshalled rule
                            ptr = Marshal.ReadIntPtr(tempPtr, Marshal.SizeOf(typeof(IntPtr)));
                            if (ptr != (IntPtr)0)
                                Marshal.FreeHGlobal(ptr);

                            Marshal.FreeHGlobal(tempPtr);
                        }
                    }
                    Marshal.FreeHGlobal(memHandle);
                }
            }

            return base.GetValue();
        }
Ejemplo n.º 9
0
		public override byte[] GetValue()
		{
			IntPtr intPtr;
			byte num;
			IntPtr intPtr1 = (IntPtr)0;
			int num1 = Marshal.SizeOf(typeof(SortKey));
			IntPtr intPtr2 = Utility.AllocHGlobalIntPtrArray((int)this.keys.Length + 1);
			try
			{
				int i = 0;
				for (i = 0; i < (int)this.keys.Length; i++)
				{
					IntPtr intPtr3 = Marshal.AllocHGlobal(num1);
					Marshal.StructureToPtr(this.keys[i], intPtr3, false);
					intPtr = (IntPtr)((long)intPtr2 + (long)(Marshal.SizeOf(typeof(IntPtr)) * i));
					Marshal.WriteIntPtr(intPtr, intPtr3);
				}
				intPtr = (IntPtr)((long)intPtr2 + (long)(Marshal.SizeOf(typeof(IntPtr)) * i));
				Marshal.WriteIntPtr(intPtr, (IntPtr)0);
				bool isCritical = base.IsCritical;
				ConnectionHandle handle = UtilityHandle.GetHandle();
				IntPtr intPtr4 = intPtr2;
				if (isCritical)
				{
					num = 1;
				}
				else
				{
					num = 0;
				}
				int num2 = Wldap32.ldap_create_sort_control(handle, intPtr4, num, ref intPtr1);
				if (num2 == 0)
				{
					LdapControl ldapControl = new LdapControl();
					Marshal.PtrToStructure(intPtr1, ldapControl);
					berval ldctlValue = ldapControl.ldctl_value;
					this.directoryControlValue = null;
					if (ldctlValue != null)
					{
						this.directoryControlValue = new byte[ldctlValue.bv_len];
						Marshal.Copy(ldctlValue.bv_val, this.directoryControlValue, 0, ldctlValue.bv_len);
					}
				}
				else
				{
					if (!Utility.IsLdapError((LdapError)num2))
					{
						throw new LdapException(num2);
					}
					else
					{
						string str = LdapErrorMappings.MapResultCode(num2);
						throw new LdapException(num2, str);
					}
				}
			}
			finally
			{
				if (intPtr1 != (IntPtr)0)
				{
					Wldap32.ldap_control_free(intPtr1);
				}
				if (intPtr2 != (IntPtr)0)
				{
					for (int j = 0; j < (int)this.keys.Length; j++)
					{
						IntPtr intPtr5 = Marshal.ReadIntPtr(intPtr2, Marshal.SizeOf(typeof(IntPtr)) * j);
						if (intPtr5 != (IntPtr)0)
						{
							IntPtr intPtr6 = Marshal.ReadIntPtr(intPtr5);
							if (intPtr6 != (IntPtr)0)
							{
								Marshal.FreeHGlobal(intPtr6);
							}
							intPtr6 = Marshal.ReadIntPtr(intPtr5, Marshal.SizeOf(typeof(IntPtr)));
							if (intPtr6 != (IntPtr)0)
							{
								Marshal.FreeHGlobal(intPtr6);
							}
							Marshal.FreeHGlobal(intPtr5);
						}
					}
					Marshal.FreeHGlobal(intPtr2);
				}
			}
			return base.GetValue();
		}
 private DirectoryControl ConstructControl(IntPtr controlPtr)
 {
     LdapControl structure = new LdapControl();
     Marshal.PtrToStructure(controlPtr, structure);
     string type = Marshal.PtrToStringUni(structure.ldctl_oid);
     byte[] destination = new byte[structure.ldctl_value.bv_len];
     Marshal.Copy(structure.ldctl_value.bv_val, destination, 0, structure.ldctl_value.bv_len);
     return new DirectoryControl(type, destination, structure.ldctl_iscritical, true);
 }
 internal LdapControl[] BuildControlArray(DirectoryControlCollection controls, bool serverControl)
 {
     int count = 0;
     LdapControl[] controlArray = null;
     if ((controls != null) && (controls.Count != 0))
     {
         ArrayList list = new ArrayList();
         foreach (DirectoryControl control in controls)
         {
             if (serverControl)
             {
                 if (control.ServerSide)
                 {
                     list.Add(control);
                 }
             }
             else if (!control.ServerSide)
             {
                 list.Add(control);
             }
         }
         if (list.Count == 0)
         {
             return controlArray;
         }
         count = list.Count;
         controlArray = new LdapControl[count];
         for (int i = 0; i < count; i++)
         {
             controlArray[i] = new LdapControl();
             controlArray[i].ldctl_oid = Marshal.StringToHGlobalUni(((DirectoryControl) list[i]).Type);
             controlArray[i].ldctl_iscritical = ((DirectoryControl) list[i]).IsCritical;
             byte[] source = ((DirectoryControl) list[i]).GetValue();
             if ((source == null) || (source.Length == 0))
             {
                 controlArray[i].ldctl_value = new berval();
                 controlArray[i].ldctl_value.bv_len = 0;
                 controlArray[i].ldctl_value.bv_val = IntPtr.Zero;
             }
             else
             {
                 controlArray[i].ldctl_value = new berval();
                 controlArray[i].ldctl_value.bv_len = source.Length;
                 controlArray[i].ldctl_value.bv_val = Marshal.AllocHGlobal((int) (Marshal.SizeOf(typeof(byte)) * controlArray[i].ldctl_value.bv_len));
                 Marshal.Copy(source, 0, controlArray[i].ldctl_value.bv_val, controlArray[i].ldctl_value.bv_len);
             }
         }
     }
     return controlArray;
 }