예제 #1
0
        /// <summary>
        /// update context on sending RPCE CO BindAck PDU.
        /// </summary>
        /// <param name="bindAckPdu">BindAck PDU to send.</param>
        internal void UpdateContextOnSendingBindAckPdu(RpceCoBindAckPdu bindAckPdu)
        {
            this.MaxTransmitFragmentSize = bindAckPdu.max_xmit_frag;
            this.MaxReceiveFragmentSize  = bindAckPdu.max_recv_frag;
            this.AssociateGroupId        = bindAckPdu.assoc_group_id;
            if (bindAckPdu.sec_addr.port_spec != null)
            {
                this.SecondaryAddress
                    = Encoding.ASCII.GetString(bindAckPdu.sec_addr.port_spec);
            }

            if (bindAckPdu.p_result_list.p_results != null)
            {
                this.NdrVersion = RpceNdrVersion.None;
                for (int i = 0; i < bindAckPdu.p_result_list.p_results.Length; i++)
                {
                    p_result_t p_result = bindAckPdu.p_result_list.p_results[i];

                    if (p_result.result == p_cont_def_result_t.acceptance)
                    {
                        if (p_result.transfer_syntax.if_uuid == RpceUtility.NDR_INTERFACE_UUID
                            &&
                            p_result.transfer_syntax.if_vers_major == RpceUtility.NDR_INTERFACE_MAJOR_VERSION
                            &&
                            p_result.transfer_syntax.if_vers_minor == RpceUtility.NDR_INTERFACE_MINOR_VERSION)
                        {
                            this.NdrVersion |= RpceNdrVersion.NDR;
                        }
                        else if (p_result.transfer_syntax.if_uuid == RpceUtility.NDR64_INTERFACE_UUID
                                 &&
                                 p_result.transfer_syntax.if_vers_major == RpceUtility.NDR64_INTERFACE_MAJOR_VERSION
                                 &&
                                 p_result.transfer_syntax.if_vers_minor == RpceUtility.NDR64_INTERFACE_MINOR_VERSION)
                        {
                            this.NdrVersion |= RpceNdrVersion.NDR64;
                        }
                    }
                    else if (p_result.result == p_cont_def_result_t.negotiate_ack)
                    {
                        byte[] bitmask = BitConverter.GetBytes((ushort)p_result.reason);
                        this.BindTimeFeatureNegotiationBitmask = (RpceBindTimeFeatureNegotiationBitmask)bitmask[0];
                        if ((this.BindTimeFeatureNegotiationBitmask
                             & RpceBindTimeFeatureNegotiationBitmask.KeepConnectionOnOrphanSupported_Resp)
                            != 0)
                        {
                            this.BindTimeFeatureNegotiationBitmask
                                |= RpceBindTimeFeatureNegotiationBitmask.KeepConnectionOnOrphanSupported;
                        }
                    }
                }

                foreach (KeyValuePair <ushort, RpceNdrVersion> item in this.PresentationContextsTable)
                {
                    if ((this.NdrVersion & item.Value) == item.Value)
                    {
                        this.ContextIdentifier = item.Key;
                        break;
                    }
                }
            }
        }
        public RpceCoBindAckPdu CreateCoBindAckPdu(
            RpceServerSessionContext sessionContext)
        {
            if (sessionContext == null)
            {
                throw new ArgumentNullException("sessionContext");
            }

            RpceCoBindAckPdu bindAckPdu = new RpceCoBindAckPdu(sessionContext);

            float serverRpcVersion
                = (float)sessionContext.ServerContext.RpcVersionMajor
                + (float)sessionContext.ServerContext.RpcVersionMinor / 10.0f;
            float proposedRpcVersion
                = (float)sessionContext.RpcVersionMajor
                + (float)sessionContext.RpcVersionMinor / 10.0f;
            float rpcVersion = Math.Min(serverRpcVersion, proposedRpcVersion);

            bindAckPdu.rpc_vers = (byte)Math.Truncate(rpcVersion);
            bindAckPdu.rpc_vers_minor = (byte)((rpcVersion - Math.Truncate(rpcVersion)) * 10.0f);
            bindAckPdu.PTYPE = RpcePacketType.BindAck;
            bindAckPdu.pfc_flags = RpceUtility.GeneratePfcFlags(sessionContext, RpcePacketType.BindAck);
            bindAckPdu.packed_drep.dataRepFormat = sessionContext.PackedDataRepresentationFormat;
            bindAckPdu.packed_drep.reserved = 0;
            bindAckPdu.call_id = sessionContext.CurrentCallId;

            bindAckPdu.max_xmit_frag = sessionContext.MaxTransmitFragmentSize;
            bindAckPdu.max_recv_frag = sessionContext.MaxReceiveFragmentSize;
            bindAckPdu.assoc_group_id = sessionContext.AssociateGroupId;
            if (sessionContext.SecondaryAddress == null)
            {
                bindAckPdu.sec_addr.port_spec = new byte[0];
            }
            else
            {
                bindAckPdu.sec_addr.port_spec = Encoding.ASCII.GetBytes(sessionContext.SecondaryAddress);
            }
            bindAckPdu.sec_addr.length = (ushort)bindAckPdu.sec_addr.port_spec.Length;

            int sizeOfSecAddr = bindAckPdu.sec_addr.length + Marshal.SizeOf(bindAckPdu.sec_addr.length);
            bindAckPdu.pad2 = new byte[RpceUtility.Align(sizeOfSecAddr, 4) - sizeOfSecAddr];

            RpceNdrVersion ndrVersion = sessionContext.ServerContext.NdrVersion;
            List<p_result_t> presentationResultList = new List<p_result_t>();
            for (int i = 0; i < sessionContext.PresentationContextsTable.Count; i++)
            {
                p_result_t pResult = new p_result_t();
                RpceNdrVersion proposedNdrVersion = sessionContext.PresentationContextsTable.Values[i];
                if ((proposedNdrVersion & ndrVersion) != 0)
                {
                    pResult.result = p_cont_def_result_t.acceptance;
                    // donot accept any more NDR version.
                    ndrVersion = RpceNdrVersion.None;
                }
                else
                {
                    pResult.result = p_cont_def_result_t.provider_rejection;
                }
                pResult.reason = p_provider_reason_t.reason_not_specified;
                if (proposedNdrVersion == RpceNdrVersion.NDR)
                {
                    pResult.transfer_syntax.if_uuid = RpceUtility.NDR_INTERFACE_UUID;
                    pResult.transfer_syntax.if_vers_major = RpceUtility.NDR_INTERFACE_MAJOR_VERSION;
                    pResult.transfer_syntax.if_vers_minor = RpceUtility.NDR_INTERFACE_MINOR_VERSION;
                }
                else if (proposedNdrVersion == RpceNdrVersion.NDR64)
                {
                    pResult.transfer_syntax.if_uuid = RpceUtility.NDR64_INTERFACE_UUID;
                    pResult.transfer_syntax.if_vers_major = RpceUtility.NDR64_INTERFACE_MAJOR_VERSION;
                    pResult.transfer_syntax.if_vers_minor = RpceUtility.NDR64_INTERFACE_MINOR_VERSION;
                }
                presentationResultList.Add(pResult);
            }
            if (sessionContext.BindTimeFeatureNegotiationBitmask != RpceBindTimeFeatureNegotiationBitmask.None)
            {
                RpceBindTimeFeatureNegotiationBitmask bindTimeFeatureNegotiationBitmask
                    = sessionContext.BindTimeFeatureNegotiationBitmask;
                if ((bindTimeFeatureNegotiationBitmask
                    & RpceBindTimeFeatureNegotiationBitmask.KeepConnectionOnOrphanSupported)
                    != 0)
                {
                    bindTimeFeatureNegotiationBitmask
                        |= RpceBindTimeFeatureNegotiationBitmask.KeepConnectionOnOrphanSupported_Resp;
                }
                bindTimeFeatureNegotiationBitmask
                    &= (sessionContext.ServerContext.SupportsSecurityContextMultiplexing
                        ? RpceBindTimeFeatureNegotiationBitmask.SecurityContextMultiplexingSupported
                        : RpceBindTimeFeatureNegotiationBitmask.None)
                        |
                       (sessionContext.ServerContext.SupportsKeepConnectionOnOrphan
                        ? RpceBindTimeFeatureNegotiationBitmask.KeepConnectionOnOrphanSupported_Resp
                        : RpceBindTimeFeatureNegotiationBitmask.None);

                p_result_t pResult = new p_result_t();
                pResult.result = p_cont_def_result_t.negotiate_ack;
                pResult.reason = (p_provider_reason_t)bindTimeFeatureNegotiationBitmask;
                presentationResultList.Add(pResult);
            }

            bindAckPdu.p_result_list.n_results = (byte)presentationResultList.Count;
            bindAckPdu.p_result_list.p_results = presentationResultList.ToArray();

            bindAckPdu.AppendAuthenticationVerifier();
            bindAckPdu.SetLength();

            return bindAckPdu;
        }