Example #1
0
        private RPC_CALL_ATTRIBUTES_V2 GetCallInfo()
        {
            if (_callAttrs.Version != 0)
                return _callAttrs;
            var attrs = new RPC_CALL_ATTRIBUTES_V2
                {
                    Version = 2,
                    Flags = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_NO_AUTH_REQUIRED
                };
            RPC_STATUS err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs);

            if (err == RPC_STATUS.RPC_S_INVALID_ARG) //may not support v2 on early edditions of XP/SP3
            {
                attrs.Version = 1;
                err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs);
            }

            if (err == RPC_STATUS.RPC_S_OK)
            {
                _callAttrs = attrs;
                _isAuthenticated = false;
                attrs.Flags = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_IS_CLIENT_LOCAL |
                              RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_NO_AUTH_REQUIRED;
                if ((err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                {
                    _callAttrs.IsClientLocal = attrs.IsClientLocal;

                    if (_callAttrs.ProtocolSequence == RpcProtoseqType.LRPC)
                    {
                        attrs.Flags = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_CLIENT_PID;
                        if ((err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                            _callAttrs.ClientPID = attrs.ClientPID;
                    }
                }

                if (_callAttrs.ProtocolSequence != RpcProtoseqType.LRPC)
                {
                    using (Ptr<byte[]> callerAddress = new Ptr<byte[]>(new byte[1024]))
                    {
                        var localAddress = new RPC_CALL_LOCAL_ADDRESS_V1();
                        localAddress.Version = 1;
                        localAddress.Buffer = callerAddress.Handle;
                        localAddress.BufferSize = 1024;
                        localAddress.AddressFormat = RpcLocalAddressFormat.Invalid;
                        _callAttrs = attrs;

                        using (var callerAddressv1 = new Ptr<RPC_CALL_LOCAL_ADDRESS_V1>(localAddress))
                        {
                            attrs.CallLocalAddress = callerAddressv1.Handle;
                            attrs.Flags = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_CALL_LOCAL_ADDRESS |
                                          RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_NO_AUTH_REQUIRED;
                            if ((err = NativeMethods. RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                            {
                                _clientAddress = new byte[callerAddressv1.Data.BufferSize];
                                Array.Copy(callerAddress.Data, _clientAddress, _clientAddress.Length);
                            }
                        }
                    }
                }

                using (Ptr<byte[]> clientPrincipal = new Ptr<byte[]>(new byte[1024]))
                {
                    attrs.ClientPrincipalName = clientPrincipal.Handle;
                    attrs.ClientPrincipalNameBufferLength = 1024;
                    attrs.Flags = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_CLIENT_PRINCIPAL_NAME;
                    if ((err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                    {
                        _clientPrincipalName = Marshal.PtrToStringUni(clientPrincipal.Handle);

                        if (!String.IsNullOrEmpty(_clientPrincipalName))
                        {
                            _isAuthenticated = true;
                            //On Windows XP this only returns a value on LRPC so we know they are local
                            if (attrs.Version == 1)
                                _callAttrs.IsClientLocal = RpcCallClientLocality.Local;
                        }
                    }
                }
            }
            else
                RpcTrace.Warning("RpcServerInqCallAttributes error {0} = {1}", err, new RpcException(err).Message);

            return _callAttrs;
        }
Example #2
0
 public static extern RPC_STATUS RpcServerInqCallAttributes(IntPtr binding,
                                                            [In, Out] ref RPC_CALL_ATTRIBUTES_V2 attributes);
Example #3
0
        private RPC_CALL_ATTRIBUTES_V2 GetCallInfo()
        {
            if (_callAttrs.Version != 0)
            {
                return(_callAttrs);
            }
            var attrs = new RPC_CALL_ATTRIBUTES_V2
            {
                Version = 2,
                Flags   = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_NO_AUTH_REQUIRED
            };
            RPC_STATUS err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs);

            if (err == RPC_STATUS.RPC_S_INVALID_ARG) //may not support v2 on early edditions of XP/SP3
            {
                attrs.Version = 1;
                err           = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs);
            }

            if (err == RPC_STATUS.RPC_S_OK)
            {
                _callAttrs       = attrs;
                _isAuthenticated = false;
                attrs.Flags      = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_IS_CLIENT_LOCAL |
                                   RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_NO_AUTH_REQUIRED;
                if ((err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                {
                    _callAttrs.IsClientLocal = attrs.IsClientLocal;

                    if (_callAttrs.ProtocolSequence == RpcProtoseqType.LRPC)
                    {
                        attrs.Flags = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_CLIENT_PID;
                        if ((err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                        {
                            _callAttrs.ClientPID = attrs.ClientPID;
                        }
                    }
                }

                if (_callAttrs.ProtocolSequence != RpcProtoseqType.LRPC)
                {
                    using (Ptr <byte[]> callerAddress = new Ptr <byte[]>(new byte[1024]))
                    {
                        var localAddress = new RPC_CALL_LOCAL_ADDRESS_V1();
                        localAddress.Version       = 1;
                        localAddress.Buffer        = callerAddress.Handle;
                        localAddress.BufferSize    = 1024;
                        localAddress.AddressFormat = RpcLocalAddressFormat.Invalid;
                        _callAttrs = attrs;

                        using (var callerAddressv1 = new Ptr <RPC_CALL_LOCAL_ADDRESS_V1>(localAddress))
                        {
                            attrs.CallLocalAddress = callerAddressv1.Handle;
                            attrs.Flags            = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_CALL_LOCAL_ADDRESS |
                                                     RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_NO_AUTH_REQUIRED;
                            if ((err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                            {
                                _clientAddress = new byte[callerAddressv1.Data.BufferSize];
                                Array.Copy(callerAddress.Data, _clientAddress, _clientAddress.Length);
                            }
                        }
                    }
                }

                using (Ptr <byte[]> clientPrincipal = new Ptr <byte[]>(new byte[1024]))
                {
                    attrs.ClientPrincipalName             = clientPrincipal.Handle;
                    attrs.ClientPrincipalNameBufferLength = 1024;
                    attrs.Flags = RPC_CALL_ATTRIBUTES_FLAGS.RPC_QUERY_CLIENT_PRINCIPAL_NAME;
                    if ((err = NativeMethods.RpcServerInqCallAttributes(_clientHandle, ref attrs)) == RPC_STATUS.RPC_S_OK)
                    {
                        _clientPrincipalName = Marshal.PtrToStringUni(clientPrincipal.Handle);

                        if (!String.IsNullOrEmpty(_clientPrincipalName))
                        {
                            _isAuthenticated = true;
                            //On Windows XP this only returns a value on LRPC so we know they are local
                            if (attrs.Version == 1)
                            {
                                _callAttrs.IsClientLocal = RpcCallClientLocality.Local;
                            }
                        }
                    }
                }
            }
            else
            {
                RpcTrace.Warning("RpcServerInqCallAttributes error {0} = {1}", err, new RpcException(err).Message);
            }


            return(_callAttrs);
        }