Exemplo n.º 1
0
        protected override int SendRequest(SafeHandle handle, DirectoryRequest request, IntPtr serverControlArray, IntPtr clientControlArray, ref int messageId)
        {
            if (request is CompareRequest compareRequest)
            {
                if (string.IsNullOrEmpty(compareRequest.DistinguishedName) ||
                    string.IsNullOrEmpty(compareRequest.Assertion?.Name) ||
                    compareRequest.Assertion.GetRawValues().Count != 1
                    )
                {
                    throw new LdapException(new LdapExceptionData("Wrong assertion"));
                }

                var value       = compareRequest.Assertion.GetRawValues().Single();
                var stringValue = value as string;
                var berValuePtr = IntPtr.Zero;
                if (value is byte[] binaryValue && binaryValue.Length != 0)
                {
                    berValuePtr = MarshalUtils.ByteArrayToBerValue(binaryValue);
                }

                var result = Native.Compare(handle, compareRequest.DistinguishedName, compareRequest.Assertion.Name, stringValue, berValuePtr, serverControlArray, clientControlArray, ref messageId);
                MarshalUtils.BerValFree(berValuePtr);
                return(result);
            }

            return(0);
        }
Exemplo n.º 2
0
        public override int SendRequest(SafeHandle handle, DirectoryRequest request, ref int messageId)
        {
            if (request is ExtendedRequest extendedRequest)
            {
                var name        = extendedRequest.RequestName;
                var val         = extendedRequest.RequestValue;
                var berValuePtr = IntPtr.Zero;

                if (val != null && val.Length != 0)
                {
                    berValuePtr = MarshalUtils.ByteArrayToBerValue(val);
                }

                var result = Native.ldap_extended_operation(handle, name, berValuePtr, IntPtr.Zero, IntPtr.Zero,
                                                            ref messageId);
                MarshalUtils.BerValFree(berValuePtr);
                return(result);
            }

            return(0);
        }
Exemplo n.º 3
0
        private static int EncodingBerValHelper(BerSafeHandle berElement, byte[] value, char fmt)
        {
            int rc;
            var valPtr = IntPtr.Zero;

            try
            {
                if (value == null)
                {
                    value = new byte[0];
                }
                valPtr = MarshalUtils.ByteArrayToBerValue(value);
                rc     = LdapNative.Instance.ber_printf_berarray(berElement, new string(fmt, 1), valPtr);
            }
            finally
            {
                if (valPtr != IntPtr.Zero)
                {
                    MarshalUtils.BerValFree(valPtr);
                }
            }
            return(rc);
        }