internal static extern int RpcMgmtEpEltInqNext(
     SafeRpcInquiryHandle InquiryContext,
     [Out] RPC_IF_ID IfId,
     out SafeRpcBindingHandle Binding,
     [Out] UUID ObjectUuid,
     out SafeRpcStringHandle Annotation
     );
Пример #2
0
 internal RpcEndpoint(RPC_IF_ID if_id, UUID uuid, SafeRpcStringHandle annotation, SafeRpcBindingHandle binding, bool registered)
 {
     InterfaceId      = if_id.Uuid;
     InterfaceVersion = new Version(if_id.VersMajor, if_id.VersMinor);
     ObjectUuid       = uuid.Uuid;
     Annotation       = annotation?.ToString() ?? string.Empty;
     BindingString    = binding.ToString();
     ProtocolSequence = binding.Protseq;
     NetworkAddress   = binding.NetworkAddr;
     Endpoint         = binding.Endpoint;
     NetworkOptions   = binding.NetworkOptions;
     if (ProtocolSequence.Equals("ncalrpc", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(Endpoint))
     {
         if (Endpoint.Contains(@"\"))
         {
             EndpointPath = Endpoint;
         }
         else
         {
             EndpointPath = $@"\RPC Control\{Endpoint}";
         }
     }
     else if (ProtocolSequence.Equals("ncacn_np", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(Endpoint))
     {
         EndpointPath = $@"\??{Endpoint}";
     }
     else
     {
         EndpointPath = string.Empty;
     }
     Registered = registered;
 }
Пример #3
0
 internal static extern int RpcMgmtEpEltInqBegin(
     SafeRpcBindingHandle EpBinding,
     RpcEndpointInquiryFlag InquiryType,
     RPC_IF_ID IfId,
     RpcEndPointVersionOption VersOption,
     UUID ObjectUuid,
     out SafeRpcInquiryHandle InquiryContext
     );
Пример #4
0
        /// <summary>
        /// Query for endpoints registered on the local system for an RPC endpoint ignoring the version.
        /// </summary>
        /// <param name="interface_id">Interface UUID to lookup.</param>
        /// <returns>The list of registered RPC endpoints.</returns>
        public static IEnumerable <RpcEndpoint> QueryEndpoints(Guid interface_id)
        {
            RPC_IF_ID if_id = new RPC_IF_ID()
            {
                Uuid = interface_id
            };

            return(QueryEndpoints(SafeRpcBindingHandle.Null, RpcEndpointInquiryFlag.Interface, if_id, RpcEndPointVersionOption.All, null));
        }
Пример #5
0
        /// <summary>
        /// Query for endpoints registered on the local system for an RPC endpoint ignoring the version.
        /// </summary>
        /// <param name="search_binding">The binding string for the server to search on. If null or empty will search localhost.</param>
        /// <param name="interface_id">Interface UUID to lookup.</param>
        /// <returns>The list of registered RPC endpoints.</returns>
        public static IEnumerable <RpcEndpoint> QueryEndpoints(string search_binding, Guid interface_id)
        {
            RPC_IF_ID if_id = new RPC_IF_ID()
            {
                Uuid = interface_id
            };

            return(QueryEndpoints(search_binding, RpcEndpointInquiryFlag.Interface, if_id, RpcEndPointVersionOption.All, null));
        }
Пример #6
0
        /// <summary>
        /// Query for endpoints registered on the local system for an RPC endpoint.
        /// </summary>
        /// <param name="interface_id">Interface UUID to lookup.</param>
        /// <param name="interface_version">Interface version lookup.</param>
        /// <returns>The list of registered RPC endpoints.</returns>
        public static IEnumerable <RpcEndpoint> QueryEndpoints(Guid interface_id, Version interface_version)
        {
            RPC_IF_ID if_id = new RPC_IF_ID()
            {
                Uuid      = interface_id,
                VersMajor = (ushort)interface_version.Major,
                VersMinor = (ushort)interface_version.Minor
            };

            return(QueryEndpoints(SafeRpcBindingHandle.Null, RpcEndpointInquiryFlag.Interface, if_id, RpcEndPointVersionOption.Exact, null));
        }
Пример #7
0
        /// <summary>
        /// Query for endpoints registered on the local system for an RPC endpoint via ALPC.
        /// </summary>
        /// <param name="interface_id">Interface UUID to lookup.</param>
        /// <param name="interface_version">Interface version lookup.</param>
        /// <returns>The list of registered RPC endpoints.</returns>
        public static IEnumerable <RpcEndpoint> QueryAlpcEndpoints(Guid interface_id, Version interface_version)
        {
            RPC_IF_ID if_id = new RPC_IF_ID()
            {
                Uuid      = interface_id,
                VersMajor = (ushort)interface_version.Major,
                VersMinor = (ushort)interface_version.Minor
            };

            return(QueryEndpoints(SafeRpcBindingHandle.Null, RpcEndpointInquiryFlag.Interface, if_id,
                                  RpcEndPointVersionOption.Exact, null).Where(e => e.ProtocolSequence.Equals("ncalrpc", StringComparison.OrdinalIgnoreCase)));
        }
Пример #8
0
        private static IEnumerable <RpcEndpoint> QueryEndpoints(string search_binding, RpcEndpointInquiryFlag inquiry_flag, RPC_IF_ID if_id_search, RpcEndPointVersionOption version, UUID uuid_search, bool throw_on_error = true)
        {
            using (SafeRpcBindingHandle search_handle = string.IsNullOrEmpty(search_binding) ? SafeRpcBindingHandle.Null : SafeRpcBindingHandle.Create(search_binding))
            {
                int status = Win32NativeMethods.RpcMgmtEpEltInqBegin(search_handle,
                                                                     inquiry_flag,
                                                                     if_id_search, version, uuid_search, out SafeRpcInquiryHandle inquiry);
                if (status != 0)
                {
                    if (throw_on_error)
                    {
                        throw new SafeWin32Exception(status);
                    }
                    yield break;
                }

                using (inquiry)
                {
                    while (true)
                    {
                        RPC_IF_ID if_id = new RPC_IF_ID();
                        UUID      uuid  = new UUID();
                        status = Win32NativeMethods.RpcMgmtEpEltInqNext(inquiry, if_id, out SafeRpcBindingHandle binding, uuid, out SafeRpcStringHandle annotation);
                        if (status != 0)
                        {
                            if (status != 1772 && throw_on_error)
                            {
                                throw new SafeWin32Exception(status);
                            }
                            break;
                        }
                        try
                        {
                            yield return(new RpcEndpoint(if_id, uuid, annotation, binding, true));
                        }
                        finally
                        {
                            binding.Dispose();
                            annotation.Dispose();
                        }
                    }
                }
            }
        }
Пример #9
0
        private static IEnumerable <RpcEndpoint> QueryEndpoints(SafeRpcBindingHandle search_binding, RpcEndpointInquiryFlag inquiry_flag, RPC_IF_ID if_id_search, RpcEndPointVersionOption version, UUID uuid_search)
        {
            using (search_binding)
            {
                int status = Win32NativeMethods.RpcMgmtEpEltInqBegin(search_binding,
                                                                     inquiry_flag,
                                                                     if_id_search, version, uuid_search, out SafeRpcInquiryHandle inquiry);
                if (status != 0)
                {
                    throw new SafeWin32Exception(status);
                }

                using (inquiry)
                {
                    while (true)
                    {
                        RPC_IF_ID if_id = new RPC_IF_ID();
                        UUID      uuid  = new UUID();
                        status = Win32NativeMethods.RpcMgmtEpEltInqNext(inquiry, if_id, out SafeRpcBindingHandle binding, uuid, out SafeRpcStringHandle annotation);
                        if (status != 0)
                        {
                            if (status == 1772)
                            {
                                break;
                            }
                            throw new SafeWin32Exception(status);
                        }
                        try
                        {
                            yield return(new RpcEndpoint(if_id, uuid, annotation, binding));
                        }
                        finally
                        {
                            binding.Dispose();
                            annotation.Dispose();
                        }
                    }
                }
            }
        }
Пример #10
0
        internal RpcEndpoint(RPC_IF_ID if_id, UUID uuid, SafeRpcStringHandle annotation, SafeRpcBindingHandle binding)
        {
            InterfaceId      = if_id.Uuid;
            InterfaceVersion = new Version(if_id.VersMajor, if_id.VersMinor);
            ObjectUuid       = uuid.Uuid;
            Annotation       = annotation.ToString();
            BindingString    = binding.ToString();
            var cracked = new CrackedBindingString(BindingString);

            Protseq        = cracked.Protseq;
            NetworkAddr    = cracked.NetworkAddr;
            Endpoint       = cracked.Endpoint;
            NetworkOptions = cracked.NetworkOptions;
            if (Protseq.Equals("ncalrpc", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(Endpoint))
            {
                AlpcPortName = $@"\RPC Control\{Endpoint}";
            }
            else
            {
                AlpcPortName = string.Empty;
            }
        }
 internal RpcEndpoint(RPC_IF_ID if_id, UUID uuid, SafeRpcStringHandle annotation, SafeRpcBindingHandle binding, bool registered)
     : this(if_id.Uuid, new Version(if_id.VersMajor, if_id.VersMinor), annotation?.ToString(), binding.ToString(), registered)
 {
 }
Пример #12
0
        private static RpcEndpoint CreateEndpoint(SafeRpcBindingHandle binding_handle, RPC_IF_ID if_id)
        {
            var endpoints = QueryEndpoints(binding_handle, RpcEndpointInquiryFlag.Interface,
                                           if_id, RpcEndPointVersionOption.Exact, null, false).ToArray();
            RpcEndpoint ret = endpoints.Where(ep => ep.BindingString.Equals(binding_handle.ToString(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            return(ret ?? new RpcEndpoint(if_id, new UUID(), null, binding_handle, false));
        }