/// <summary> /// Throws an exception when session context is null /// </summary> ///<param name="sessionContext">Context of the session</param> ///<exception cref="ArgumentNullException">Thrown when session context is null</exception> private void CheckIfSessionContextIsNull(SamrServerSessionContext sessionContext) { if (sessionContext == null) { throw new ArgumentNullException("sessionContext"); } }
/// <summary> /// Sends RPC response to the client /// </summary> /// <param name="sessionContext">The session context of the RPC response to send</param> /// <param name="messageToSend">The RPC response to send</param> /// <exception cref="ArgumentNullException">Thrown when sessionContext or messageToSend is null.</exception> public void SendRpcCallResponse(SamrServerSessionContext sessionContext, SamrResponseStub messageToSend) { CheckIfSessionContextIsNull(sessionContext); if (messageToSend == null) { throw new ArgumentNullException("messageToSend"); } rpceLayerServer.SendResponse(sessionContext.RpceLayerSessionContext, messageToSend.Encode(sessionContext)); }
/// <summary> /// Look up the Samr session context using the session context of RPCE /// </summary> /// <param name="rpceSessionContext">The RPCE layer session context</param> /// <param name="sessionContext">The corresponding Samr session context</param> /// <returns>Whether the rpce session is a new session</returns> internal bool LookupSessionContext(RpceServerSessionContext rpceSessionContext, out SamrServerSessionContext sessionContext) { lock (lockObj) { if (sessionContextMap.ContainsKey(rpceSessionContext)) { sessionContext = sessionContextMap[rpceSessionContext]; return(false); } else { sessionContext = new SamrServerSessionContext(); sessionContextMap[rpceSessionContext] = sessionContext; return(true); } } }
/// <summary> /// Look up the Samr session context using the session context of RPCE /// </summary> /// <param name="rpceSessionContext">The RPCE layer session context</param> /// <param name="sessionContext">The corresponding Samr session context</param> /// <returns>Whether the rpce session is a new session</returns> internal bool LookupSessionContext(RpceServerSessionContext rpceSessionContext, out SamrServerSessionContext sessionContext) { lock (lockObj) { if (sessionContextMap.ContainsKey(rpceSessionContext)) { sessionContext = sessionContextMap[rpceSessionContext]; return false; } else { sessionContext = new SamrServerSessionContext(); sessionContextMap[rpceSessionContext] = sessionContext; return true; } } }
/// <summary> /// Receives RPC calls from clients /// </summary> /// <param name="timeout">The maximum time waiting for RPC calls</param> /// <param name="sessionContext">The session context of the RPC call received</param> /// <returns>The input parameters of the RPC call received</returns> /// <exception cref="InvalidOperationException">Thrown when an invalid method is called, or /// an unexpected method is called</exception> public T ExpectRpcCall <T>(TimeSpan timeout, out SamrServerSessionContext sessionContext) where T : SamrRequestStub { RpceServerSessionContext rpceSessionContext; ushort opnum; byte[] requestStub = rpceLayerServer.ExpectCall(timeout, out rpceSessionContext, out opnum); if (!Enum.IsDefined(typeof(SamrMethodOpnums), (int)opnum)) { throw new InvalidOperationException("An invalid method is invoked"); } //If there isn't a corresponding Samr session context, it's a new session if (contextManager.LookupSessionContext(rpceSessionContext, out sessionContext)) { sessionContext.RpceLayerSessionContext = rpceSessionContext; } T t; if (typeof(T) == typeof(SamrRequestStub)) { t = (T)SamrUtility.CreateSamrRequestStub((SamrMethodOpnums)opnum); } else { t = Activator.CreateInstance <T>(); if ((ushort)t.Opnum != opnum) { throw new InvalidOperationException("An unexpected method call is received"); } } //Decode the request stub t.Decode(sessionContext, requestStub); //Update the session context sessionContext.UpdateSessionContextWithMessageReceived(t); return(t); }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { Unused = TypeMarshal.ToStruct<_RPC_UNICODE_STRING>(inParams[0]); UserId = inParams[1].ToUInt32(); EncryptedNtOwfPassword = TypeMarshal.ToStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[2]); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal override byte[] Encode(SamrServerSessionContext sessionContext) { Int3264[] paramList; SafeIntPtr pOutVersion = TypeMarshal.ToIntPtr(OutVersion); SafeIntPtr pOutRevisionInfo = TypeMarshal.ToIntPtr(OutRevisionInfo, OutVersion, null, null); SafeIntPtr pServerHandle = TypeMarshal.ToIntPtr(ServerHandle); paramList = new Int3264[] { IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pOutVersion, pOutRevisionInfo, pServerHandle, Status }; byte[] responseStub; try { responseStub = RpceStubEncoder.ToBytes( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, paramList); } finally { pOutVersion.Dispose(); pOutRevisionInfo.Dispose(); pServerHandle.Dispose(); } return responseStub; }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { ServerName = Marshal.PtrToStringAuto(inParams[0]); DesiredAccess = inParams[1].ToUInt32(); InVersion = inParams[2].ToUInt32(); InRevisionInfo = TypeMarshal.ToStruct<SAMPR_REVISION_INFO>(inParams[3], InVersion, null, null); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal override byte[] Encode(SamrServerSessionContext sessionContext) { Int3264[] paramList; SafeIntPtr pEnumerationContext = TypeMarshal.ToIntPtr<UInt32>(EnumerationContext); SafeIntPtr pBuffer = TypeMarshal.ToIntPtr<_SAMPR_ENUMERATION_BUFFER>(Buffer); IntPtr ppBuffer = Marshal.AllocHGlobal(IntPtr.Size); Marshal.WriteIntPtr(ppBuffer, pBuffer); SafeIntPtr pCountReturned = TypeMarshal.ToIntPtr<uint>(CountReturned); paramList = new Int3264[] { IntPtr.Zero, pEnumerationContext, IntPtr.Zero, ppBuffer, IntPtr.Zero, pCountReturned, Status }; byte[] responseStub; try { responseStub = RpceStubEncoder.ToBytes( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, paramList); } finally { pEnumerationContext.Dispose(); pBuffer.Dispose(); Marshal.FreeHGlobal(ppBuffer); pCountReturned.Dispose(); } return responseStub; }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { ServerHandle = inParams[0].ToIntPtr(); Name = TypeMarshal.ToStruct<_RPC_UNICODE_STRING>(inParams[1]); } }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { return; }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { ValidationType = (_PASSWORD_POLICY_VALIDATION_TYPE)inParams[0].ToInt32(); InputArg = TypeMarshal.ToStruct<_SAM_VALIDATE_INPUT_ARG>(inParams[1], ValidationType, null, null); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal override byte[] Encode(SamrServerSessionContext sessionContext) { Int3264[] paramList; SafeIntPtr pUserHandle = TypeMarshal.ToIntPtr(UserHandle); SafeIntPtr pGrantedAccess = TypeMarshal.ToIntPtr(GrantedAccess); SafeIntPtr pRelativeId = TypeMarshal.ToIntPtr(RelativeId); paramList = new Int3264[] { IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pUserHandle, pGrantedAccess, pRelativeId, Status }; byte[] responseStub; try { responseStub = RpceStubEncoder.ToBytes( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, paramList); } finally { pUserHandle.Dispose(); pGrantedAccess.Dispose(); pRelativeId.Dispose(); } return responseStub; }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { UserHandle = inParams[0].ToIntPtr(); LmPresent = (byte)inParams[1].ToInt32(); OldLmEncryptedWithNewLm = TypeMarshal.ToNullableStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[2]); NewLmEncryptedWithOldLm = TypeMarshal.ToNullableStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[3]); NtPresent = (byte)inParams[4].ToInt32(); OldNtEncryptedWithNewNt = TypeMarshal.ToNullableStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[5]); NewNtEncryptedWithOldNt = TypeMarshal.ToNullableStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[6]); NtCrossEncryptionPresent = (byte)inParams[7].ToInt32(); NewNtEncryptedWithNewLm = TypeMarshal.ToNullableStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[8]); LmCrossEncryptionPresent = (byte)inParams[9].ToInt32(); NewLmEncryptedWithNewNt = TypeMarshal.ToNullableStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[10]); } }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { IntPtr pServerName = inParams[0].ToIntPtr(); ServerName = Marshal.PtrToStringUni(pServerName); DesiredAccess = inParams[2].ToUInt32(); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal abstract byte[] Encode(SamrServerSessionContext sessionContext);
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal abstract void Decode(SamrServerSessionContext sessionContext, byte[] requestStub);
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { DomainHandle = inParams[0].ToIntPtr(); Count = inParams[1].ToUInt32(); RelativeIds = IntPtrUtility.PtrToArray<uint>(inParams[2], Count); } }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { DomainHandle = inParams[0].ToIntPtr(); EnumerationContext = TypeMarshal.ToNullableStruct<uint>(inParams[1]); PreferedMaximumLength = inParams[3].ToUInt32(); } }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { ObjectHandle = inParams[0].ToIntPtr(); SecurityInformation = (SamrQuerySecurityObject_SecurityInformation_Values)(inParams[1].ToInt32()); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal override byte[] Encode(SamrServerSessionContext sessionContext) { Int3264[] paramList; paramList = new Int3264[] { IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, Status }; byte[] responseStub = RpceStubEncoder.ToBytes( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, paramList); return responseStub; }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { DomainHandle = inParams[0].ToIntPtr(); DisplayInformationClass = (_DOMAIN_DISPLAY_INFORMATION)(inParams[1].ToInt32()); Index = inParams[2].ToUInt32(); EntryCount = inParams[3].ToUInt32(); PreferredMaximumLength = inParams[4].ToUInt32(); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal override byte[] Encode(SamrServerSessionContext sessionContext) { Int3264[] paramList; SafeIntPtr pSecurityDescriptor = TypeMarshal.ToIntPtr(SecurityDescriptor); IntPtr ppSecurityDescriptor = Marshal.AllocHGlobal(IntPtr.Size); Marshal.WriteIntPtr(ppSecurityDescriptor, pSecurityDescriptor); paramList = new Int3264[] { IntPtr.Zero, IntPtr.Zero, ppSecurityDescriptor, Status }; byte[] responseStub; try { responseStub = RpceStubEncoder.ToBytes( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, paramList); } finally { pSecurityDescriptor.Dispose(); Marshal.FreeHGlobal(ppSecurityDescriptor); } return responseStub; }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { //BindingHandle = inParams[0].ToIntPtr(); ServerName = TypeMarshal.ToStruct<_RPC_STRING>(inParams[0]); UserName = TypeMarshal.ToStruct<_RPC_STRING>(inParams[1]); NewPasswordEncryptedWithOldLm = TypeMarshal.ToStruct<_SAMPR_ENCRYPTED_USER_PASSWORD>(inParams[2]); OldLmOwfPasswordEncryptedWithNewLm = TypeMarshal.ToStruct<_ENCRYPTED_LM_OWF_PASSWORD>(inParams[3]); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal override byte[] Encode(SamrServerSessionContext sessionContext) { return null; }
/// <summary> /// Decodes the request stub, and fills the fields of the class /// </summary> /// <param name="sessionContext">The session context of the request received</param> /// <param name="requestStub">The request stub got from RPCE layer</param> internal override void Decode(SamrServerSessionContext sessionContext, byte[] requestStub) { using (RpceInt3264Collection inParams = RpceStubDecoder.ToParamList( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, requestStub)) { UserHandle = inParams[0].ToIntPtr(); UserInformationClass = (_USER_INFORMATION_CLASS)(inParams[1].ToInt32()); Buffer = TypeMarshal.ToStruct<_SAMPR_USER_INFO_BUFFER>(inParams[2].ToIntPtr(), UserInformationClass, null, null); } }
/// <summary> /// Encodes the response stub /// </summary> /// <param name="sessionContext">The session context of the response to send</param> /// <returns>The response stub</returns> internal override byte[] Encode(SamrServerSessionContext sessionContext) { Int3264[] paramList; SafeIntPtr pTotalAvailable = TypeMarshal.ToIntPtr(TotalAvailable); SafeIntPtr pTotalReturned = TypeMarshal.ToIntPtr(TotalReturned); SafeIntPtr pBuffer = TypeMarshal.ToIntPtr(Buffer, DisplayInformationClass, null, null); paramList = new Int3264[] { IntPtr.Zero, (int)DisplayInformationClass, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pTotalAvailable, pTotalReturned, pBuffer, Status }; byte[] responseStub; try { responseStub = RpceStubEncoder.ToBytes( RpceStubHelper.GetPlatform(), SamrRpcStubFormatString.TypeFormatString, new RpceStubExprEval[]{ new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002), new RpceStubExprEval(SamrRpcAdapter.samr_SAMPR_LOGON_HOURSExprEval_0003)}, SamrRpcStubFormatString.ProcFormatString, SamrRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum], false, paramList); } finally { pTotalAvailable.Dispose(); pTotalReturned.Dispose(); pBuffer.Dispose(); } return responseStub; }
/// <summary> /// Remove a session context from the context manager /// </summary> /// <param name="sessionContext">The session context to remove</param> /// <exception cref="ArgumentNullException">Thrown when sessionContext is null.</exception> public void RemoveSessionContext(SamrServerSessionContext sessionContext) { CheckIfSessionContextIsNull(sessionContext); contextManager.RemoveSessionContext(sessionContext.RpceLayerSessionContext); }