/// <summary>
        /// Extract domain names from _DOMAIN_NAME_BUFFER.
        /// </summary>
        /// <param name="buffer">A struct of _DOMAIN_NAME_BUFFER.</param>
        /// <returns>A string collection what contains domain names in the buffer.</returns>
        public static ReadOnlyCollection<string> ExtractDomainNames(_DOMAIN_NAME_BUFFER buffer)
        {
            List<string> nameList = new List<string>();

            if (buffer.DomainNames != null)
            {
                //The Unicode string buffer that contains the list of trusted domains,
                //in MULTI-SZ format. MULTI-SZ format is a UTF-16 string composed of one or more substrings.
                //Each substring is separated from adjacent substrings by the UTF-16 null character, 0x0000.
                //After the final substring, the MULTI-SZ format string is terminated by two UTF-16 null characters.
                //For example, if there are three trusted domains, DOMAIN1, DOMAIN2, and DOMAIN3,
                //the DomainNames string buffer would have the following form:
                //DOMAIN1<null>DOMAIN2<null>DOMAIN3<null><null>
                foreach (string name in Encoding.Unicode.GetString(buffer.DomainNames).Split('\0'))
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        nameList.Add(name);
                    }
                }
            }

            return nameList.AsReadOnly();
        }
        /// <summary>
        ///  The NetrEnumerateTrustedDomains method returns a set
        ///  of trusted domain names. Opnum: 19 
        /// </summary>
        /// <param name="ServerName">
        ///  The custom RPC binding handle, as specified in section
        ///  .
        /// </param>
        /// <param name="DomainNameBuffer">
        ///  A pointer to a DOMAIN_NAME_BUFFER structure, as specified
        ///  in section , that contains a list of trusted domain
        ///  names. The format of domain names contained in the
        ///  buffer is specified in section.
        /// </param>
        public NtStatus NetrEnumerateTrustedDomains(
            string ServerName,
            out _DOMAIN_NAME_BUFFER? DomainNameBuffer)
        {
            const ushort opnum = 19;

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

            SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName);

            paramList = new Int3264[] {
                pServerName,
                IntPtr.Zero,
                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 pDomainNameBuffer = outParamList[1];
                DomainNameBuffer = TypeMarshal.ToNullableStruct<_DOMAIN_NAME_BUFFER>(pDomainNameBuffer);

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

            pServerName.Dispose();

            return (NtStatus)retVal;
        }
Ejemplo n.º 3
0
 /// <summary>
 ///  The NetrEnumerateTrustedDomains method returns a set
 ///  of trusted domain names. Opnum: 19 
 /// </summary>
 /// <param name="serverName">
 ///  The custom RPC binding handle.
 /// </param>
 /// <param name="domainNameBuffer">
 ///  A pointer to a DOMAIN_NAME_BUFFER structure, 
 ///  that contains a list of trusted domain
 ///  names.
 /// </param>
 /// <returns>
 /// The method returns 0x00000000 on success; 
 /// otherwise, it returns a nonzero error code.
 /// </returns>
 public NtStatus NetrEnumerateTrustedDomains(
     string serverName,
     out _DOMAIN_NAME_BUFFER? domainNameBuffer)
 {
     return rpc.NetrEnumerateTrustedDomains(
         serverName,
         out domainNameBuffer);
 }