/// <summary>
        /// When an RODC receives either the NetrServerAuthenticate3 method or the 
        /// NetrLogonGetDomainInfo method with updates requested, it invokes this method 
        /// on a normal (writable) DC to update to a client's computer account object in 
        /// Active Directory.
        /// </summary>
        /// <param name="PrimaryName">
        /// The custom RPC binding handle, as specified in section 3.5.5.1.
        /// </param>
        /// <param name="ChainedFromServerName">
        /// The null-terminated Unicode string that contains the name of the read-only 
        /// DC that issues the request.
        /// </param>
        /// <param name="ChainedForClientName">
        /// The null-terminated Unicode string that contains the name of the client 
        /// computer that called NetrServerAuthenticate3 or NetrLogonGetDomainInfo on 
        /// the RODC.
        /// </param>
        /// <param name="Authenticator">
        /// A pointer to a NETLOGON_AUTHENTICATOR structure that contains the client 
        /// authenticator.
        /// </param>
        /// <param name="ReturnAuthenticator">
        /// A pointer to a NETLOGON_AUTHENTICATOR structure that contains the server 
        /// return authenticator.
        /// </param>
        /// <param name="dwInVersion">
        /// One of the NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES union types selected based on 
        /// the value of the pmsgIn field. The value MUST be 1.
        /// </param>
        /// <param name="pmsgIn">
        /// A pointer to an NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES_V1 structure that contains 
        /// the values to update on the client's computer account object in Active 
        /// Directory on the normal (writable) DC.
        /// </param>
        /// <param name="pdwOutVersion">
        /// A pointer to one of the NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES union types selected 
        /// based on the value of the pmsgIn field. The value MUST be 1.
        /// </param>
        /// <param name="pmsgOut">
        /// A pointer to an NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1 structure that contains 
        /// information on the client workstation and the writable domain controller. For 
        /// how it is populated by the server, see below.
        /// </param>
        public NtStatus NetrChainSetClientAttributes(
            string PrimaryName,
            string ChainedFromServerName,
            string ChainedForClientName,
            _NETLOGON_AUTHENTICATOR? Authenticator,
            ref _NETLOGON_AUTHENTICATOR? ReturnAuthenticator,
            uint dwInVersion,
            NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES? pmsgIn,
            ref uint? pdwOutVersion,
            ref NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES? pmsgOut)
        {
            NtStatus status = rpc.NetrChainSetClientAttributes(
                PrimaryName,
                ChainedFromServerName,
                ChainedForClientName,
                Authenticator,
                ref ReturnAuthenticator,
                dwInVersion,
                pmsgIn,
                ref pdwOutVersion,
                ref pmsgOut);

            context.ConnectionStatus = status;
            return status;
        }
        /// <summary>
        /// When an RODC receives either the NetrServerAuthenticate3 method or the 
        /// NetrLogonGetDomainInfo method with updates requested, it invokes this method 
        /// on a normal (writable) DC to update to a client's computer account object in 
        /// Active Directory.
        /// </summary>
        /// <param name="PrimaryName">
        /// The custom RPC binding handle, as specified in section 3.5.5.1.
        /// </param>
        /// <param name="ChainedFromServerName">
        /// The null-terminated Unicode string that contains the name of the read-only 
        /// DC that issues the request.
        /// </param>
        /// <param name="ChainedForClientName">
        /// The null-terminated Unicode string that contains the name of the client 
        /// computer that called NetrServerAuthenticate3 or NetrLogonGetDomainInfo on 
        /// the RODC.
        /// </param>
        /// <param name="Authenticator">
        /// A pointer to a NETLOGON_AUTHENTICATOR structure that contains the client 
        /// authenticator.
        /// </param>
        /// <param name="ReturnAuthenticator">
        /// A pointer to a NETLOGON_AUTHENTICATOR structure that contains the server 
        /// return authenticator.
        /// </param>
        /// <param name="dwInVersion">
        /// One of the NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES union types selected based on 
        /// the value of the pmsgIn field. The value MUST be 1.
        /// </param>
        /// <param name="pmsgIn">
        /// A pointer to an NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES_V1 structure that contains 
        /// the values to update on the client's computer account object in Active 
        /// Directory on the normal (writable) DC.
        /// </param>
        /// <param name="pdwOutVersion">
        /// A pointer to one of the NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES union types selected 
        /// based on the value of the pmsgIn field. The value MUST be 1.
        /// </param>
        /// <param name="pmsgOut">
        /// A pointer to an NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1 structure that contains 
        /// information on the client workstation and the writable domain controller. For 
        /// how it is populated by the server, see below.
        /// </param>
        public NtStatus NetrChainSetClientAttributes(
            string PrimaryName,
            string ChainedFromServerName,
            string ChainedForClientName,
            _NETLOGON_AUTHENTICATOR? Authenticator,
            ref _NETLOGON_AUTHENTICATOR? ReturnAuthenticator,
            uint dwInVersion,
            NL_IN_CHAIN_SET_CLIENT_ATTRIBUTES? pmsgIn,
            ref uint? pdwOutVersion,
            ref NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES? pmsgOut)
        {
            const ushort opnum = 49;

            byte[] requestStub;
            byte[] responseStub;
            Int3264[] paramList;
            int retVal;

            SafeIntPtr pPrimaryName = Marshal.StringToHGlobalUni(PrimaryName);
            SafeIntPtr pChainedFromServerName = Marshal.StringToHGlobalUni(ChainedFromServerName);
            SafeIntPtr pChainedForClientName = Marshal.StringToHGlobalUni(ChainedForClientName);
            SafeIntPtr pAuthenticator = TypeMarshal.ToIntPtr(Authenticator);
            SafeIntPtr pReturnAuthenticatorIn = TypeMarshal.ToIntPtr(ReturnAuthenticator);
            SafeIntPtr ppMsgIn = TypeMarshal.ToIntPtr(pmsgIn, dwInVersion, null, null);
            SafeIntPtr ppdwOutVersion = TypeMarshal.ToIntPtr(pdwOutVersion);
            SafeIntPtr ppMsgOutIn = TypeMarshal.ToIntPtr(pmsgOut, pdwOutVersion.Value, null, null);

            paramList = new Int3264[] {
                pPrimaryName,
                pChainedFromServerName,
                pChainedForClientName,
                pAuthenticator,
                pReturnAuthenticatorIn,
                dwInVersion,
                ppMsgIn,
                ppdwOutVersion,
                ppMsgOutIn,
                0 // retVal
            };

            requestStub = RpceStubEncoder.ToBytes(
                     RpceStubHelper.GetPlatform(),
                    NrpcRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] { new RpceStubExprEval(logon__NETLOGON_DELTA_USERExprEval_0000) },
                    NrpcRpcStubFormatString.ProcFormatString,
                    NrpcRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    paramList);

            rpceClientTransport.Call(opnum, requestStub, rpceTimeout, out responseStub);

            using (RpceInt3264Collection outParamList = RpceStubDecoder.ToParamList(
                     RpceStubHelper.GetPlatform(),
                    NrpcRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] { new RpceStubExprEval(logon__NETLOGON_DELTA_USERExprEval_0000) },
                    NrpcRpcStubFormatString.ProcFormatString,
                    NrpcRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    responseStub,
                    paramList))
            {
                IntPtr pReturnAuthenticatorOut = outParamList[4];
                ReturnAuthenticator = TypeMarshal.ToNullableStruct<_NETLOGON_AUTHENTICATOR>(pReturnAuthenticatorOut);

                pdwOutVersion = TypeMarshal.ToNullableStruct<uint>(outParamList[7]);

                IntPtr ppMsgOutOut = outParamList[8];
                pmsgOut = TypeMarshal.ToNullableStruct<NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES>(
                    ppMsgOutOut,
                    pdwOutVersion.Value,
                    null,
                    null);

                retVal = outParamList[9].ToInt32();
            }

            pPrimaryName.Dispose();
            pChainedFromServerName.Dispose();
            pChainedForClientName.Dispose();
            pAuthenticator.Dispose();
            pReturnAuthenticatorIn.Dispose();
            ppMsgIn.Dispose();
            ppdwOutVersion.Dispose();
            ppMsgOutIn.Dispose();

            return (NtStatus)retVal;
        }
        public NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES CreateNlOutChainSetClientAttributes(
            string hubName,
            string oldDnsHostName,
            uint? supportedEncTypes)
        {
            NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES nlOutChainSetClientAttributes = new NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES();

            nlOutChainSetClientAttributes.V1 = new _NL_OUT_CHAIN_SET_CLIENT_ATTRIBUTES_V1();
            nlOutChainSetClientAttributes.V1.HubName = hubName;
            if (oldDnsHostName != null)
            {
                nlOutChainSetClientAttributes.V1.OldDnsHostName = new string[1];
                nlOutChainSetClientAttributes.V1.OldDnsHostName[0] = oldDnsHostName;
            }
            if (supportedEncTypes != null)
            {
                nlOutChainSetClientAttributes.V1.SupportedEncTypes = new uint[1];
                nlOutChainSetClientAttributes.V1.SupportedEncTypes[0] = supportedEncTypes.Value;
            }

            return nlOutChainSetClientAttributes;
        }