/// <summary> /// The SamrCreateAliasInDomain method creates an alias. /// Opnum: 14 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="AccountName"> /// The value to use as the name of the alias. Details on /// how this value maps to the data model are provided /// later in this section. /// </param> /// <param name="DesiredAccess"> /// The access requested on the AliasHandle on output. See /// section for a listing of possible values. /// </param> /// <param name="AliasHandle"> /// An RPC context handle, as specified in section. /// </param> /// <param name="RelativeId"> /// The RID of the newly created alias. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrCreateAliasInDomain(System.IntPtr DomainHandle, _RPC_UNICODE_STRING AccountName, uint DesiredAccess, out System.IntPtr AliasHandle, out System.UInt32 RelativeId) { return rpc.SamrCreateAliasInDomain(DomainHandle, AccountName, DesiredAccess, out AliasHandle, out RelativeId); }
/// <summary> /// The SamrCreateUserInDomain method creates a user. Opnum /// : 12 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="Name"> /// The value to use as the name of the user. See the message /// processing shown later in this section for details /// on how this value maps to the data model. /// </param> /// <param name="DesiredAccess"> /// The access requested on the UserHandle on output. See /// section for a listing of possible values. /// </param> /// <param name="UserHandle"> /// An RPC context handle, as specified in section. /// </param> /// <param name="RelativeId"> /// The RID of the newly created user. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrCreateUserInDomain(System.IntPtr DomainHandle, _RPC_UNICODE_STRING Name, uint DesiredAccess, out System.IntPtr UserHandle, out System.UInt32 RelativeId) { return rpc.SamrCreateUserInDomain(DomainHandle, Name, DesiredAccess, out UserHandle, out RelativeId); }
/// <summary> /// The SamrSetDSRMPassword method sets a local recovery /// password. Opnum: 66 /// </summary> /// <param name="BindingHandle"> /// An RPC binding handle parameter, as specified in [C706-Ch2Intro]. /// </param> /// <param name="Unused"> /// A string value. This value is not used in the protocol /// and is ignored by the server. /// </param> /// <param name="UserId"> /// A RID of a user account. See the message processing /// later in this section for details on restrictions on /// this value. /// </param> /// <param name="EncryptedNtOwfPassword"> /// The NT hash of the new password (as presented by the /// client) encrypted according to the specification of /// ENCRYPTED_NT_OWF_PASSWORD, where the key is the User ID. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrSetDSRMPassword(System.IntPtr BindingHandle, _RPC_UNICODE_STRING Unused, uint UserId, _ENCRYPTED_LM_OWF_PASSWORD EncryptedNtOwfPassword) { return rpc.SamrSetDSRMPassword(BindingHandle, Unused, UserId, EncryptedNtOwfPassword); }
/// <summary> /// The SamrUnicodeChangePasswordUser2 method changes a /// user account's password. Opnum: 55 /// </summary> /// <param name="BindingHandle"> /// An RPC binding handle parameter as specified in [C706-Ch2Intro]. /// </param> /// <param name="ServerName"> /// A null-terminated string containing the NETBIOS name /// of the server; this parameter MAY servers ignore the /// ServerName parameter. be ignored by the server. /// </param> /// <param name="UserName"> /// The name of the user. See the message processing later /// in this section for details on how this value is used /// as a database key to locate the account that is the /// target of this password change operation. /// </param> /// <param name="NewPasswordEncryptedWithOldNt"> /// A clear text password encrypted according to the specification /// of SAMPR_ENCRYPTED_USER_PASSWORD, where the key is /// the NT hash of the existing password for the target /// user (as presented by the client in the OldNtOwfPasswordEncryptedWithNewNt /// parameter). /// </param> /// <param name="OldNtOwfPasswordEncryptedWithNewNt"> /// The NT hash of the target user's existing password (as /// presented by the client) encrypted according to the /// specification of ENCRYPTED_LM_OWF_PASSWORD, where the /// key is the NT hash of the clear text password obtained /// from decrypting NewPasswordEncryptedWithOldNt. /// </param> /// <param name="LmPresent"> /// If this parameter is zero, NewPasswordEncryptedWithOldLm /// and OldLmOwfPasswordEncryptedWithOldLm MUST be ignored; /// otherwise these fields MUST be processed. /// </param> /// <param name="NewPasswordEncryptedWithOldLm"> /// A clear text password encrypted according to the specification /// of SAMPR_ENCRYPTED_USER_PASSWORD, where the key is /// the LM hash of the existing password for the target /// user (as presented by the client). /// </param> /// <param name="OldLmOwfPasswordEncryptedWithNewNt"> /// The LM hash the target user's existing password (as /// presented by the client) encrypted according to the /// specification of ENCRYPTED_LM_OWF_PASSWORD, where the /// key is the NT hash of the clear text password obtained /// from decrypting NewPasswordEncryptedWithOldNt. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrUnicodeChangePasswordUser2(System.IntPtr BindingHandle, _RPC_UNICODE_STRING ServerName, _RPC_UNICODE_STRING UserName, _SAMPR_ENCRYPTED_USER_PASSWORD NewPasswordEncryptedWithOldNt, _ENCRYPTED_LM_OWF_PASSWORD OldNtOwfPasswordEncryptedWithNewNt, byte LmPresent, _SAMPR_ENCRYPTED_USER_PASSWORD NewPasswordEncryptedWithOldLm, _ENCRYPTED_LM_OWF_PASSWORD OldLmOwfPasswordEncryptedWithNewNt) { return rpc.SamrUnicodeChangePasswordUser2(BindingHandle, ServerName, UserName, NewPasswordEncryptedWithOldNt, OldNtOwfPasswordEncryptedWithNewNt, LmPresent, NewPasswordEncryptedWithOldLm, OldLmOwfPasswordEncryptedWithNewNt); }
/// <summary> /// The SamrLookupDomainInSamServer method obtains the SID /// of a domain object, given the object's name. Opnum /// : 5 /// </summary> /// <param name="ServerHandle"> /// An RPC context handle, as specified in section , representing /// a server object. /// </param> /// <param name="Name"> /// A UTF-16 encoded string. /// </param> /// <param name="DomainId"> /// A SID value of a domain that matches the Name passed /// in. The match must be exact (no wildcards are permitted). /// See message processing later in this section for more /// details. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrLookupDomainInSamServer(System.IntPtr ServerHandle, _RPC_UNICODE_STRING Name, out _RPC_SID? DomainId) { return rpc.SamrLookupDomainInSamServer(ServerHandle, Name, out DomainId); }
/// <summary> /// The SamrLookupNamesInDomain method translates a set /// of account names into a set of RIDs. Opnum: 17 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="Count"> /// The number of elements in Names. The maximum value of /// 1,000 is chosen to limit the amount of memory that /// the client can force the server to allocate. /// </param> /// <param name="Names"> /// An array of strings that are to be mapped to RIDs. /// </param> /// <param name="RelativeIds"> /// An array of RIDs of accounts that correspond to the /// elements in Names. /// </param> /// <param name="Use"> /// An array of SID_NAME_USE enumeration values that describe /// the type of account for each entry in RelativeIds. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrLookupNamesInDomain(System.IntPtr DomainHandle, uint Count, //[Length("Count")] [Size("1000")] _RPC_UNICODE_STRING[] Names, out _SAMPR_ULONG_ARRAY RelativeIds, out _SAMPR_ULONG_ARRAY Use) { return rpc.SamrLookupNamesInDomain(DomainHandle, Count, Names, out RelativeIds, out Use); }
/// <summary> /// The SamrCreateAliasInDomain method creates an alias. /// Opnum: 14 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="AccountName"> /// The value to use as the name of the alias. Details on /// how this value maps to the data model are provided /// later in this section. /// </param> /// <param name="DesiredAccess"> /// The access requested on the AliasHandle on output. See /// section for a listing of possible values. /// </param> /// <param name="AliasHandle"> /// An RPC context handle, as specified in section. /// </param> /// <param name="RelativeId"> /// The RID of the newly created alias. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrCreateAliasInDomain( IntPtr DomainHandle, _RPC_UNICODE_STRING AccountName, uint DesiredAccess, out IntPtr AliasHandle, out uint RelativeId) { const ushort opnum = 14; Int3264[] paramList; int retVal = 0; SafeIntPtr pAccountName = TypeMarshal.ToIntPtr(AccountName); paramList = new Int3264[] { DomainHandle, pAccountName, DesiredAccess, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero }; try { using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum)) { AliasHandle = Marshal.ReadIntPtr(outParamList[3]); RelativeId = TypeMarshal.ToStruct<uint>(outParamList[4]); retVal = outParamList[5].ToInt32(); } } finally { pAccountName.Dispose(); } return retVal; }
/// <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> /// The SamrLookupDomainInSamServer method obtains the SID /// of a domain object, given the object's name. Opnum /// : 5 /// </summary> /// <param name="ServerHandle"> /// An RPC context handle, as specified in section , representing /// a server object. /// </param> /// <param name="Name"> /// A UTF-16 encoded string. /// </param> /// <param name="DomainId"> /// A SID value of a domain that matches the Name passed /// in. The match must be exact (no wildcards are permitted). /// See message processing later in this section for more /// details. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrLookupDomainInSamServer(IntPtr ServerHandle, _RPC_UNICODE_STRING Name, out _RPC_SID? DomainId) { const ushort opnum = 5; Int3264[] paramList; int retVal = 0; SafeIntPtr pName = TypeMarshal.ToIntPtr(Name); paramList = new Int3264[] { ServerHandle, pName, IntPtr.Zero, IntPtr.Zero }; try { using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum)) { DomainId = TypeMarshal.ToNullableStruct<_RPC_SID>(Marshal.ReadIntPtr(outParamList[2])); retVal = outParamList[3].ToInt32(); } } finally { pName.Dispose(); } return retVal; }
/// <summary> /// The SamrLookupNamesInDomain method translates a set /// of account names into a set of RIDs. Opnum: 17 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="Count"> /// The number of elements in Names. The maximum value of /// 1,000 is chosen to limit the amount of memory that /// the client can force the server to allocate. /// </param> /// <param name="Names"> /// An array of strings that are to be mapped to RIDs. /// </param> /// <param name="RelativeIds"> /// An array of RIDs of accounts that correspond to the /// elements in Names. /// </param> /// <param name="Use"> /// An array of SID_NAME_USE enumeration values that describe /// the type of account for each entry in RelativeIds. /// </param> /// <exception cref="ArgumentNullException"> /// thrown when the pNames is null. /// </exception> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrLookupNamesInDomain( IntPtr DomainHandle, uint Count, _RPC_UNICODE_STRING[] Names, out _SAMPR_ULONG_ARRAY RelativeIds, out _SAMPR_ULONG_ARRAY Use) { const ushort opnum = 17; Int3264[] paramList; int retVal = 0; if (Names == null) { throw new ArgumentNullException("Names"); } SafeIntPtr pNames = TypeMarshal.ToIntPtr(Names); paramList = new Int3264[] { DomainHandle, Count, Marshal.ReadIntPtr(pNames), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero }; try { using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum)) { RelativeIds = TypeMarshal.ToStruct<_SAMPR_ULONG_ARRAY>(outParamList[3]); Use = TypeMarshal.ToStruct<_SAMPR_ULONG_ARRAY>(outParamList[4]); retVal = outParamList[5].ToInt32(); } } finally { pNames.Dispose(); } return retVal; }
/// <summary> /// The SamrGetDisplayEnumerationIndex2 method obtains an /// index into an account-namesorted list of accounts, /// such that the index is the position in the list of /// the accounts whose account name best matches a client-provided /// string. Opnum: 49 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="DisplayInformationClass"> /// An enumeration indicating which set of objects to return /// an index into (for a subsequent SamrQueryDisplayInformation3 /// method call). /// </param> /// <param name="Prefix"> /// A string matched against the account name to find a /// starting point for an enumeration. The Prefix parameter /// enables the client to obtain a listing of an account /// from SamrQueryDisplayInformation3 such that the accounts /// are returned in alphabetical order with respect to /// their account name, starting with the account name /// that most closely matches Prefix. See details later /// in this section. /// </param> /// <param name="Index"> /// A value to use as input to SamrQueryDisplayInformation3 /// in order to control the accounts that are returned /// from that method. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrGetDisplayEnumerationIndex2( IntPtr DomainHandle, _DOMAIN_DISPLAY_INFORMATION DisplayInformationClass, _RPC_UNICODE_STRING Prefix, out uint Index) { const ushort opnum = 49; Int3264[] paramList; int retVal = 0; SafeIntPtr pPrefix = TypeMarshal.ToIntPtr(Prefix); paramList = new Int3264[] { DomainHandle, (int)DisplayInformationClass, pPrefix, IntPtr.Zero, IntPtr.Zero }; try { using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum)) { Index = TypeMarshal.ToStruct<uint>(outParamList[3]); retVal = outParamList[4].ToInt32(); } } finally { pPrefix.Dispose(); } return retVal; }
/// <summary> /// Read string from PRC_UNICODE_STRING, null terminating char is not included. /// </summary> /// <param name="s"> /// A PRC_UNICODE_STRING structure. /// Return value is null if Length and MaximumLength is 0 and Buffer is NULL.</param> /// <returns>The string in the structure.</returns> /// <exception cref="ArgumentException"> /// Thrown when s is invalid. /// </exception> public static string ToString(_RPC_UNICODE_STRING s) { if (s.Length == 0 && s.MaximumLength == 0 && s.Buffer == null) { return null; } if (s.Buffer.Length * sizeof(ushort) < s.Length) { throw new ArgumentException("RPC_UNICODE_STRING is invalid.", "s"); } byte[] buf = new byte[s.Length]; Buffer.BlockCopy(s.Buffer, 0, buf, 0, buf.Length); return Encoding.Unicode.GetString(buf); }
/// <summary> /// Create an instance of PRC_UNICODE_STRING. /// </summary> /// <param name="s"> /// A string. /// If it's null, Length and maximumLength is 0, Buffer is NULL. /// </param> /// <returns>Created RPC_UNICODE_STRING structure.</returns> public static _RPC_UNICODE_STRING ToRpcUnicodeString(string s) { _RPC_UNICODE_STRING rpcUnicodeString = new _RPC_UNICODE_STRING(); if (s == null) { rpcUnicodeString.Length = 0; rpcUnicodeString.MaximumLength = 0; rpcUnicodeString.Buffer = null; } else { byte[] buf = Encoding.Unicode.GetBytes(s); rpcUnicodeString.Length = (ushort)buf.Length; rpcUnicodeString.MaximumLength = (ushort)buf.Length; rpcUnicodeString.Buffer = new ushort[buf.Length / sizeof(ushort)]; Buffer.BlockCopy(buf, 0, rpcUnicodeString.Buffer, 0, buf.Length); } return rpcUnicodeString; }
/// <summary> /// The SamrGetDisplayEnumerationIndex2 method obtains an /// index into an account-namesorted list of accounts, /// such that the index is the position in the list of /// the accounts whose account name best matches a client-provided /// string. Opnum: 49 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="DisplayInformationClass"> /// An enumeration indicating which set of objects to return /// an index into (for a subsequent SamrQueryDisplayInformation3 /// method call). /// </param> /// <param name="Prefix"> /// A string matched against the account name to find a /// starting point for an enumeration. The Prefix parameter /// enables the client to obtain a listing of an account /// from SamrQueryDisplayInformation3 such that the accounts /// are returned in alphabetical order with respect to /// their account name, starting with the account name /// that most closely matches Prefix. See details later /// in this section. /// </param> /// <param name="Index"> /// A value to use as input to SamrQueryDisplayInformation3 /// in order to control the accounts that are returned /// from that method. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrGetDisplayEnumerationIndex2(System.IntPtr DomainHandle, _DOMAIN_DISPLAY_INFORMATION DisplayInformationClass, _RPC_UNICODE_STRING Prefix, out System.UInt32 Index) { return rpc.SamrGetDisplayEnumerationIndex2(DomainHandle, DisplayInformationClass, Prefix, out Index); }
/// <summary> /// The SamrCreateUser2InDomain method creates a user. Opnum /// : 50 /// </summary> /// <param name="DomainHandle"> /// An RPC context handle, as specified in section , representing /// a domain object. /// </param> /// <param name="Name"> /// The value to use as the name of the user. See the message /// processing shown later in this section for details /// on how this value maps to the data model. /// </param> /// <param name="AccountType"> /// A 32-bit value indicating the type of account to create. /// See the message processing shown later in this section /// for possible values. /// </param> /// <param name="DesiredAccess"> /// The access requested on the UserHandle on output. See /// section for a listing of possible values. /// </param> /// <param name="UserHandle"> /// An RPC context handle, as specified in section. /// </param> /// <param name="GrantedAccess"> /// The access granted on UserHandle. /// </param> /// <param name="RelativeId"> /// The RID of the newly created user. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrCreateUser2InDomain( IntPtr DomainHandle, _RPC_UNICODE_STRING? Name, uint AccountType, uint DesiredAccess, out IntPtr UserHandle, out uint GrantedAccess, out uint RelativeId) { const ushort opnum = 50; Int3264[] paramList; int retVal = 0; SafeIntPtr pName = TypeMarshal.ToIntPtr(Name); paramList = new Int3264[] { DomainHandle, pName, AccountType, DesiredAccess, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero }; try { using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum)) { UserHandle = Marshal.ReadIntPtr(outParamList[4]); GrantedAccess = TypeMarshal.ToStruct<uint>(outParamList[5]); RelativeId = TypeMarshal.ToStruct<uint>(outParamList[6]); retVal = outParamList[7].ToInt32(); } } finally { pName.Dispose(); } return retVal; }
/// <summary> /// The SamrGetDomainPasswordInformation method obtains /// select password policy information (without authenticating /// to the server). Opnum: 56 /// </summary> /// <param name="BindingHandle"> /// An RPC binding handle parameter, as specified in [C706-Ch2Intro]. /// </param> /// <param name="Unused"> /// A string value that is unused by the protocol. It is /// ignored by the server. The client MAY clients set this /// value to be the NULL-terminated NETBIOS name of the /// server. set any value. /// </param> /// <param name="PasswordInformation"> /// Password policy information from the account domain. /// </param> /// <returns> /// status of the function call, for example: 0 indicates STATUS_SUCCESS /// </returns> public int SamrGetDomainPasswordInformation(System.IntPtr BindingHandle, _RPC_UNICODE_STRING Unused, out _USER_DOMAIN_PASSWORD_INFORMATION PasswordInformation) { return rpc.SamrGetDomainPasswordInformation(BindingHandle, Unused, out PasswordInformation); }
/// <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]); } }