Пример #1
0
        /// <summary>
        /// SWN client invoke WitnessrGetInterfaceList method to retrieve information about the interfaces to which witness client connections can be made.
        /// </summary>
        /// <param name="InterfaceList">A pointer to a PWITNESS_INTERFACE_LIST, as specified in section 2.2.1.9.</param>
        /// <returns>Return zero if success, otherwise return nonzero.</returns>
        public int WitnessrGetInterfaceList(out WITNESS_INTERFACE_LIST InterfaceList)
        {
            Int3264[] paramList;
            int       retVal = 0;

            paramList = new Int3264[] {
                IntPtr.Zero, //out param
                IntPtr.Zero  //return value
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SWN_OPNUM.WitnessrGetInterfaceList))
            {
                WITNESS_INTERFACE_LIST_RPC rpcList  = TypeMarshal.ToStruct <WITNESS_INTERFACE_LIST_RPC>(Marshal.ReadIntPtr(outParamList[0]));
                WITNESS_INTERFACE_INFO[]   infoList = new WITNESS_INTERFACE_INFO[rpcList.NumberOfInterfaces];
                int sizeInByte = Marshal.SizeOf(typeof(WITNESS_INTERFACE_INFO));
                for (int i = 0; i < rpcList.NumberOfInterfaces; i++)
                {
                    IntPtr pInfo = IntPtrUtility.Add(rpcList.InterfaceInfo, i * sizeInByte);
                    infoList[i] = (WITNESS_INTERFACE_INFO)Marshal.PtrToStructure(pInfo, typeof(WITNESS_INTERFACE_INFO));
                }

                InterfaceList = new WITNESS_INTERFACE_LIST();
                InterfaceList.NumberOfInterfaces = rpcList.NumberOfInterfaces;
                InterfaceList.InterfaceInfo      = infoList;

                retVal = outParamList[paramList.Length - 1].ToInt32();
            }
            return(retVal);
        }
        /// <summary>
        /// The NetrShareGetInfo method retrieves information about a particular shared resource on the server from the ShareList.
        /// </summary>
        /// <param name="ServerName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param>
        /// <param name="NetName">The name of the share to return information for.</param>
        /// <param name="Level">Specifies the information level of the data. This parameter MUST be one of the following values.</param>
        /// <param name="InfoStruct">Its contents are determined by the value of the Level parameter, as shown in the preceding table.</param>
        /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns>
        public uint NetrShareGetInfo(string ServerName, string NetName, SHARE_ENUM_STRUCT_LEVEL Level, out SHARE_INFO?InfoStruct)
        {
            /*
             * NET_API_STATUS NetrShareGetInfo(
             * [in, string, unique] SRVSVC_HANDLE ServerName,
             * [in, string] WCHAR* NetName,
             * [in] DWORD Level,
             * [out, switch_is(Level)] LPSHARE_INFO InfoStruct
             * );
             */
            Int3264[] paramList;
            uint      retVal = 0;

            InfoStruct = null;
            using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName), pNetName = Marshal.StringToHGlobalUni(NetName))
            {
                paramList = new Int3264[] {
                    pServerName,
                    pNetName,
                    (uint)Level,
                    IntPtr.Zero, // out value
                    IntPtr.Zero  // return value
                };
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareGetInfo))
                {
                    retVal = outParamList[paramList.Length - 1].ToUInt32();
                    if (retVal == (uint)Win32ErrorCode_32.ERROR_SUCCESS)
                    {
                        InfoStruct = TypeMarshal.ToStruct <SHARE_INFO>(outParamList[3], Level, null, null);
                    }
                }
            }
            return(retVal);
        }
Пример #3
0
        /// <summary>
        /// SWN client invoke WitnessrRegister to register for resource state change notifications of a NetName and IPAddress.
        /// </summary>
        /// <param name="Version">The version of the Witness protocol currently in use by the client.</param>
        /// <param name="NetName">Specifies a null-terminated string that specifies the name of the resource for which the client requires notifications.</param>
        /// <param name="IpAddr">Specifies a null-terminated string that specifies the IP address to which the client application connection is established.</param>
        /// <param name="ClientName">Specifies a null-terminated string that is used to identify the Witness client.</param>
        /// <param name="pContext">A context handle to identifies the client on the server. </param>
        /// <returns>Return zero if success, otherwise return nonzero.</returns>
        public int WitnessrRegister(SwnVersion Version, string NetName, string IpAddr, string ClientName, out IntPtr pContext)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pNetName    = Marshal.StringToHGlobalUni(NetName);
            SafeIntPtr pIpAddr     = Marshal.StringToHGlobalUni(IpAddr);
            SafeIntPtr pClientName = Marshal.StringToHGlobalUni(ClientName);

            paramList = new Int3264[] {
                IntPtr.Zero,//out param
                (uint)Version,
                pNetName,
                pIpAddr,
                pClientName,
                IntPtr.Zero //return value
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SWN_OPNUM.WitnessrRegister))
                {
                    pContext = Marshal.ReadIntPtr(outParamList[0]);
                    retVal   = outParamList[paramList.Length - 1].ToInt32();
                }
            }
            finally
            {
                pNetName.Dispose();
                pIpAddr.Dispose();
                pClientName.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        /// This call waits until all the shadowcopy preparation is done on the file server.
        /// It is used to avoid the long preparation time on file server break the
        /// 60 seconds freeze/thaw window on the application server
        /// It must be called between the last AddToShadowCopySet and CommitShadowCopySet
        /// </summary>
        /// <param name="ShadowCopySetId">The GUID of shadow copy set</param>
        /// <param name="TimeOutInMilliseconds">The maximum total time in milliseconds for which the server MUST wait for the expose operation.</param>
        /// <returns></returns>
        public int PrepareShadowCopySet(
            Guid ShadowCopySetId,
            uint TimeOutInMilliseconds
            )
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);

            paramList = new Int3264[] {
                pShadowCopySetId,
                TimeOutInMilliseconds,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.PrepareShadowCopySet))
                {
                    retVal = outParamList[2].ToInt32();
                }
            }
            finally
            {
                pShadowCopySetId.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        /// The IsPathSupported method is invoked by client to query if a given share is supported by the server
        /// for shadow copy operations.
        /// </summary>
        /// <param name="ShareName">The full path of the share in UNC format.</param>
        /// <param name="SupportedByThisProvider">On output, a Boolean, when set to TRUE, indicates that shadow
        /// copies of this share are supported by the server.</param>
        /// <param name="OwnerMachineName">On output, the name of the server machine to which the client MUST
        /// connect to create shadow copies of the specified ShareName.</param>
        /// <returns></returns>
        public int IsPathSupported(
            string ShareName,
            out bool SupportedByThisProvider,
            out string OwnerMachineName)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShareName,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.IsPathSupported))
                {
                    SupportedByThisProvider = TypeMarshal.ToStruct <bool>(outParamList[1]);//(Marshal.ReadInt32(outParamList[1]) == 1);
                    OwnerMachineName        = Marshal.PtrToStringUni(Marshal.ReadIntPtr(outParamList[2]));
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pShareName.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        /// The DeleteShareMapping method deletes the mapping of a share’s shadow copy from a shadow copy set.
        /// </summary>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set.</param>
        /// <param name="ShadowCopyId">The GUID of the shadow copy associated with the share.</param>
        /// <param name="ShareName">The name of the share for which the share mapping is to be deleted.</param>
        /// <returns></returns>
        public int DeleteShareMapping(
            Guid ShadowCopySetId,
            Guid ShadowCopyId,
            string ShareName)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);
            SafeIntPtr pShadowCopyId    = TypeMarshal.ToIntPtr(ShadowCopyId);
            SafeIntPtr pShareName       = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShadowCopySetId,
                pShadowCopyId,
                pShareName,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.DeleteShareMapping))
                {
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pShadowCopySetId.Dispose();
                pShadowCopyId.Dispose();
                pShareName.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        /// The IsPathShadowCopied method is invoked by the client to query if any shadow copy for a share already exists.
        /// </summary>
        /// <param name="ShareName">The full path of the share in UNC format.</param>
        /// <param name="ShadowCopyPresent">On output, a Boolean, when set to TRUE, indicates that shadow
        /// copies of this share are supported by the server.</param>
        /// <param name="ShadowCopyCompatibility">On output, this indicates whether certain I/O operations on the object
        /// store containing the shadow copy are disabled. This MUST be zero or a combination of the values
        /// as specified in section 2.2.2.2.</param>
        /// <returns></returns>
        public int IsPathShadowCopied(
            string ShareName,
            out bool ShadowCopyPresent,
            out long ShadowCopyCompatibility)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShareName,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.IsPathShadowCopied))
                {
                    retVal                  = outParamList[paramList.Length - 1].ToInt32();
                    ShadowCopyPresent       = TypeMarshal.ToStruct <bool>(outParamList[1]);
                    ShadowCopyCompatibility = Marshal.ReadInt32(outParamList[2]);
                    retVal                  = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pShareName.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        /// The AbortShadowCopySet method is invoked by the client to delete a given shadow copy set on the server.
        /// </summary>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set to which ShareName is to be added.</param>
        /// <returns></returns>
        public int AbortShadowCopySet(Guid ShadowCopySetId)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);

            paramList = new Int3264[] {
                pShadowCopySetId,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.AbortShadowCopySet))
                {
                    retVal = outParamList[1].ToInt32();
                }
            }
            finally
            {
                pShadowCopySetId.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        /// The StartShadowCopySet method is called by the client to initiate a new shadow copy set for shadow copy creation.
        /// </summary>
        /// <param name="pShadowCopySetId">On output, the GUID of the shadow copy set that must be created by server.</param>
        /// <returns></returns>
        public int StartShadowCopySet(
            Guid clientShadowCopySetId,
            out Guid pShadowCopySetId)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pClientShadowCopySetId = TypeMarshal.ToIntPtr(clientShadowCopySetId);

            paramList = new Int3264[] {
                pClientShadowCopySetId,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.StartShadowCopySet))
                {
                    pShadowCopySetId = TypeMarshal.ToStruct <Guid>(outParamList[1]);
                    retVal           = outParamList[2].ToInt32();
                }
            }
            finally
            {
                pClientShadowCopySetId.Dispose();
            }

            return(retVal);
        }
        /// <summary>
        ///  The IDL_DSAExecuteScript method executes a maintenance script.
        ///  Opnum: 1
        /// </summary>
        /// <param name="hRpc">
        ///  The RPC binding handle, as specified in [C706].
        /// </param>
        /// <param name="dwInVersion">
        ///  The version of the request message.
        /// </param>
        /// <param name="pmsgIn">
        ///  A pointer to the request message.
        /// </param>
        /// <param name="pdwOutVersion">
        ///  A pointer to the version of the response message.
        /// </param>
        /// <param name="pmsgOut">
        ///  A pointer to the response message.
        /// </param>
        public uint IDL_DSAExecuteScript(
            IntPtr hRpc,
            uint dwInVersion,
            //[Switch("dwInVersion")]
            DSA_MSG_EXECUTE_SCRIPT_REQ?pmsgIn,
            out uint?pdwOutVersion,
            //[Switch("*pdwOutVersion")]
            out DSA_MSG_EXECUTE_SCRIPT_REPLY?pmsgOut)
        {
            const ushort opnum = 1;

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

            SafeIntPtr ptrMsgIn = TypeMarshal.ToIntPtr(pmsgIn, dwInVersion, null, null);

            paramList = new Int3264[]
            {
                dwInVersion,
                ptrMsgIn,
                IntPtr.Zero,
                IntPtr.Zero,
                0//retVal
            };

            requestStub = RpceStubEncoder.ToBytes(
                RpceStubHelper.GetPlatform(),
                DrsrRpcStubFormatString.TypeFormatString,
                null,
                DrsrRpcStubFormatString.ProcFormatString,
                DrsrRpcStubFormatString.Dsaop_ProcFormatStringOffsetTable[opnum],
                true,
                paramList);

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

            using (RpceInt3264Collection outParamList = RpceStubDecoder.ToParamList(
                       RpceStubHelper.GetPlatform(),
                       DrsrRpcStubFormatString.TypeFormatString,
                       null,
                       DrsrRpcStubFormatString.ProcFormatString,
                       DrsrRpcStubFormatString.Dsaop_ProcFormatStringOffsetTable[opnum],
                       true,
                       responseStub,
                       rpceClientTransport.Context.PackedDataRepresentationFormat,
                       paramList))
            {
                pdwOutVersion = TypeMarshal.ToNullableStruct <uint>(outParamList[2]);
                pmsgOut       = TypeMarshal.ToNullableStruct <DSA_MSG_EXECUTE_SCRIPT_REPLY>(
                    outParamList[3], pdwOutVersion, null, null);
                retVal = outParamList[4].ToUInt32();
            }

            ptrMsgIn.Dispose();

            return(retVal);
        }
Пример #11
0
        /// <summary>
        /// SWN client invoke WitnessrAsyncNotify method to post a message on the server; this message is completed when there are no longer any notifications which are required to be communicated with the client.
        /// </summary>
        /// <param name="pContext">A context handle to identifies the client on the server.</param>
        /// <returns>The identifier of this async call.</returns>
        public uint WitnessrAsyncNotify(IntPtr pContext)
        {
            Int3264[] paramList;

            paramList = new Int3264[] {
                pContext,
                IntPtr.Zero, //out param
                IntPtr.Zero  //return value
            };

            return(RpceAsyncCall(paramList, (ushort)SWN_OPNUM.WitnessrAsyncNotify));
        }
        /// <summary>
        /// The GetShareMapping method is invoked by the client to get the shadow copy information on a given
        /// file share on the server.
        /// </summary>
        /// <param name="ShadowCopyId">The GUID of the shadow copy associated with the share.</param>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set.</param>
        /// <param name="ShareName">The name of the share in UNC format.</param>
        /// <param name="Level">The format of this data depends on the value of the level parameter.</param>
        /// <param name="ShareMapping">On output, a FSSAGENT_SHARE_MAPPING structure, as specified in section 2.2.3.1.</param>
        /// <returns></returns>
        public int GetShareMapping(
            Guid ShadowCopyId,
            Guid ShadowCopySetId,
            string ShareName,
            uint Level,
            out FSSAGENT_SHARE_MAPPING ShareMapping)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pShadowCopyId    = TypeMarshal.ToIntPtr(ShadowCopyId);
            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);
            SafeIntPtr pShareName       = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShadowCopyId,
                pShadowCopySetId,
                pShareName,
                Level,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.GetShareMapping))
                {
                    retVal       = outParamList[5].ToInt32();
                    ShareMapping = new FSSAGENT_SHARE_MAPPING();
                    if ((FsrvpErrorCode)retVal == FsrvpErrorCode.FSRVP_SUCCESS)
                    {
                        ShareMapping.ShareMapping1       = TypeMarshal.ToStruct <FSSAGENT_SHARE_MAPPING_1>(Marshal.ReadIntPtr(outParamList[4]));
                        ShareMapping.ShareMapping1IsNull = false;
                    }
                    else
                    {
                        ShareMapping.ShareMapping1IsNull = true;
                    }
                }
            }
            finally
            {
                pShadowCopyId.Dispose();
                pShadowCopySetId.Dispose();
                pShareName.Dispose();
            }

            return(retVal);
        }
Пример #13
0
        /// <summary>
        /// The NetrShareEnum method retrieves information about each shared resource on a server.
        /// </summary>
        /// <param name="serverName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param>
        /// <param name="infoStruct">A SHARE_ENUM_STRUCT structure. The SHARE_ENUM_STRUCT structure has a Level member
        /// that specifies the type of structure to return in the ShareInfo member.</param>
        /// <param name="PreferedMaximumLength">Specifies the preferred maximum length, in bytes, of the returned data.
        /// If the specified value is MAX_PREFERRED_LENGTH, the method MUST attempt to return all entries.</param>
        /// <param name="TotalEntries">The total number of entries that could have been enumerated if the buffer had been big enough to hold all the entries.</param>
        /// <param name="ResumeHandle">A pointer to a value that contains a handle, which is used to continue an existing share search in ShareList.
        /// handle MUST be zero on the first call and remain unchanged for subsequent calls. If the ResumeHandle parameter is NULL, no resume handle MUST be stored.
        /// If this parameter is not NULL and the method returns ERROR_MORE_DATA, this parameter receives a nonzero value that can be passed in subsequent
        /// calls to this method to continue with the enumeration in ShareList. If this parameter is NULL or points to 0x00000000, the enumeration starts from the beginning of the ShareList.
        /// </param>
        /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns>
        public uint NetrShareEnum(
            string serverName,
            ref SHARE_ENUM_STRUCT infoStruct,
            uint PreferedMaximumLength,
            out uint?TotalEntries,
            ref uint?ResumeHandle)
        {
            /*  NET_API_STATUS NetrShareEnum(
             *    [in, string, unique] SRVSVC_HANDLE ServerName,
             *    [in, out] LPSHARE_ENUM_STRUCT InfoStruct,
             *    [in] DWORD PreferedMaximumLength,
             *    [out] DWORD* TotalEntries,
             *    [in, out, unique] DWORD* ResumeHandle
             *  );
             */

            Int3264[] paramList;
            TotalEntries = 0;
            uint retVal = 0;

            using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(serverName),
                   pInfoStruct = TypeMarshal.ToIntPtr(infoStruct),
                   pResumeHandle = TypeMarshal.ToIntPtr(ResumeHandle))
            {
                paramList = new Int3264[] {
                    pServerName,
                    pInfoStruct,
                    PreferedMaximumLength,
                    IntPtr.Zero, // out value
                    pResumeHandle,
                    IntPtr.Zero  // return value
                };

                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareEnum))
                {
                    retVal = outParamList[paramList.Length - 1].ToUInt32();
                    if (retVal == (uint)Win32ErrorCode_32.ERROR_SUCCESS)
                    {
                        infoStruct   = TypeMarshal.ToStruct <SHARE_ENUM_STRUCT>(outParamList[1].ToIntPtr());
                        TotalEntries = TypeMarshal.ToNullableStruct <uint>(outParamList[3]);
                        ResumeHandle = TypeMarshal.ToNullableStruct <uint>(outParamList[4]);
                    }
                }
            }
            return(retVal);
        }
Пример #14
0
        /// <summary>
        /// SWN client invoke WitnessrUnRegister to unregister for notifications from the server.
        /// </summary>
        /// <param name="pContext">A context handle to identifies the client on the server.</param>
        /// <returns>Return zero if success, otherwise return nonzero.</returns>
        public int WitnessrUnRegister(IntPtr pContext)
        {
            Int3264[] paramList;
            int       retVal = 0;

            paramList = new Int3264[] {
                pContext,
                IntPtr.Zero //return value
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SWN_OPNUM.WitnessrUnRegister))
            {
                retVal = outParamList[paramList.Length - 1].ToInt32();
            }

            return(retVal);
        }
        /// <summary>
        /// The SetContext method sets the context for subsequent shadow copy-related operations.
        /// </summary>
        /// <param name="Context">The context to be used for the shadow copy operations.</param>
        /// <returns>It MUST be zero or a combination of the CONTEXT_VALUES as specified in section 2.2.2.2.</returns>
        public int SetContext(ulong Context)
        {
            Int3264[] paramList;
            int       retVal = 0;

            paramList = new Int3264[] {
                Context,
                IntPtr.Zero
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.SetContext))
            {
                retVal = outParamList[1].ToInt32();
            }

            return(retVal);
        }
        /// <summary>
        /// Get the Server supported version range.
        /// Windows Server 8 compatiable Agent should return both
        /// as FSSAGENT_RPC_VERSION_1
        /// </summary>
        /// <param name="MinVersion">The minor version.</param>
        /// <param name="MaxVersion">The maximum version.</param>
        /// <returns></returns>
        public int GetSupportedVersion(out uint MinVersion, out uint MaxVersion)
        {
            Int3264[] paramList;
            int       retVal = 0;

            paramList = new Int3264[] {
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.GetSupportedVersion))
            {
                MinVersion = (uint)Marshal.ReadInt32(outParamList[0]);
                MaxVersion = (uint)Marshal.ReadInt32(outParamList[1]);
                retVal     = outParamList[2].ToInt32();
            }

            return(retVal);
        }
Пример #17
0
        /// <summary>
        /// The NetrShareSetInfo method sets the parameters of a shared resource in a ShareList.
        /// </summary>
        /// <param name="ServerName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param>
        /// <param name="NetName">The name of the share to return information for.</param>
        /// <param name="Level">Specifies the information level of the data. This parameter MUST be one of the following values.</param>
        /// <param name="InfoStruct">Its contents are determined by the value of the Level parameter, as shown in the preceding table.
        /// This parameter MUST NOT contain a null value. </param>
        /// <param name="ParmErr">An integer value that receives the index of the first member of the share information
        /// structure that caused the ERROR_INVALID_PARAMETER error, if it occurs</param>
        /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns>
        public uint NetrShareSetInfo(string ServerName, string NetName, SHARE_ENUM_STRUCT_LEVEL Level, SHARE_INFO InfoStruct, ref uint?ParmErr)
        {
            /*
             * NET_API_STATUS NetrShareSetInfo(
             *  [in, string, unique] SRVSVC_HANDLE ServerName,
             *  [in, string] WCHAR* NetName,
             *  [in] DWORD Level,
             *  [in, switch_is(Level)] LPSHARE_INFO ShareInfo,
             *  [in, out, unique] DWORD* ParmErr
             * );
             */

            Int3264[] paramList;
            uint      retVal = 0;

            using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName),
                   pNetName = Marshal.StringToHGlobalUni(NetName),
                   pShareInfo = TypeMarshal.ToIntPtr(InfoStruct, Level, null, null),
                   pParmErr = TypeMarshal.ToIntPtr(ParmErr))
            {
                paramList = new Int3264[] {
                    pServerName,
                    pNetName,
                    (uint)Level,
                    pShareInfo, // out value
                    pParmErr,
                    IntPtr.Zero // return value
                };
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareSetInfo))
                {
                    retVal = outParamList[paramList.Length - 1].ToUInt32();
                    if (retVal == (uint)Win32ErrorCode_32.ERROR_INVALID_PARAMETER)
                    {
                        ParmErr = TypeMarshal.ToNullableStruct <uint>(outParamList[4]);
                    }
                }
            }
            return(retVal);
        }
        /// <summary>
        /// The AddToShadowCopySet method adds a share to an existing shadow copy set.
        /// </summary>
        /// <param name="ClientShadowCopyId">The GUID of the client. This MUST be set to NULL.</param>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set to which ShareName is to be added.</param>
        /// <param name="ShareName">The name of the share in UNC format for which a shadow copy is required.</param>
        /// <param name="pShadowCopyId">On output, the GUID of the shadow copy associated to the share.</param>
        /// <returns></returns>
        public int AddToShadowCopySet(
            Guid ClientShadowCopyId,
            Guid ShadowCopySetId,
            string ShareName,
            out Guid pShadowCopyId)
        {
            Int3264[] paramList;
            int       retVal = 0;

            SafeIntPtr pClientShadowCopyId = TypeMarshal.ToIntPtr(ClientShadowCopyId);
            SafeIntPtr pShadowCopySetId    = TypeMarshal.ToIntPtr(ShadowCopySetId);
            SafeIntPtr pShareName          = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pClientShadowCopyId,
                pShadowCopySetId,
                pShareName,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.AddToShadowCopySet))
                {
                    pShadowCopyId = TypeMarshal.ToStruct <Guid>(outParamList[3]);
                    retVal        = outParamList[4].ToInt32();
                }
            }
            finally
            {
                pClientShadowCopyId.Dispose();
                pShadowCopySetId.Dispose();
                pShareName.Dispose();
            }

            return(retVal);
        }
Пример #19
0
        private Int3264 NdrUnmarshalRoutines(
            Int3264 arg,
            int typeFormatStringOffset,
            RpceFormatCharType formatChar)
        {
            Int3264 retVal = 0;

            switch ((RpceFormatCharType)((int)formatChar & FORMAT_CHAR_ROUTINE_BITMASK))
            {
            case RpceFormatCharType.FC_ZERO:
                throw new InvalidOperationException("Bad format char: FC_ZERO.");

            case RpceFormatCharType.FC_BYTE:
            case RpceFormatCharType.FC_CHAR:
            case RpceFormatCharType.FC_SMALL:
            case RpceFormatCharType.FC_USMALL:
                retVal = (int)NdrByteUnmarshal();
                break;

            case RpceFormatCharType.FC_WCHAR:
            case RpceFormatCharType.FC_SHORT:
            case RpceFormatCharType.FC_USHORT:
                retVal = (int)NdrInt16Unmarshal();
                break;

            case RpceFormatCharType.FC_LONG:
            case RpceFormatCharType.FC_ULONG:
            case RpceFormatCharType.FC_FLOAT:
                retVal = NdrInt32Unmarshal();
                break;

            case RpceFormatCharType.FC_HYPER:
            case RpceFormatCharType.FC_DOUBLE:
                retVal = NdrInt64Unmarshal();
                break;

            case RpceFormatCharType.FC_ENUM16:
                retVal = (int)NdrInt16Unmarshal();
                break;

            case RpceFormatCharType.FC_ENUM32:
                retVal = NdrInt32Unmarshal();
                break;

            case RpceFormatCharType.FC_ERROR_STATUS_T:
                retVal = NdrInt32Unmarshal();
                break;

            case RpceFormatCharType.FC_RP:
            case RpceFormatCharType.FC_UP:
            case RpceFormatCharType.FC_OP:
            case RpceFormatCharType.FC_FP:
                retVal = NdrPointerUnmarshall(typeFormatStringOffset);
                break;

            case RpceFormatCharType.FC_STRUCT:
            case RpceFormatCharType.FC_PSTRUCT:
                retVal = NdrSimpleStructUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_CSTRUCT:
            case RpceFormatCharType.FC_CPSTRUCT:
                retVal = NdrConformantStructUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_CVSTRUCT:
                retVal = NdrConformantVaryingStructUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_BOGUS_STRUCT:
            case (RpceFormatCharType)((int)
                                      RpceFormatCharType.FC_FORCED_BOGUS_STRUCT & FORMAT_CHAR_ROUTINE_BITMASK):
                retVal = NdrComplexStructUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_CARRAY:
                retVal = NdrConformantArrayUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_CVARRAY:
                retVal = NdrConformantVaryingArrayUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_SMFARRAY:
            case RpceFormatCharType.FC_LGFARRAY:
                retVal = NdrFixedArrayUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_SMVARRAY:
            case RpceFormatCharType.FC_LGVARRAY:
                retVal = NdrVaryingArrayUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_BOGUS_ARRAY:
                retVal = NdrComplexArrayUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_C_CSTRING:
            case RpceFormatCharType.FC_C_BSTRING:
            case RpceFormatCharType.FC_C_SSTRING:
            case RpceFormatCharType.FC_C_WSTRING:
                retVal = NdrConformantStringUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_CSTRING:
            case RpceFormatCharType.FC_BSTRING:
            case RpceFormatCharType.FC_SSTRING:
            case RpceFormatCharType.FC_WSTRING:
                retVal = NdrNonConformantStringUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_ENCAPSULATED_UNION:
                retVal = NdrEncapsulatedUnionUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_NON_ENCAPSULATED_UNION:
                retVal = NdrNonEncapsulatedUnionUnmarshall(typeFormatStringOffset, 0);
                break;

            case RpceFormatCharType.FC_BYTE_COUNT_POINTER:
                retVal = NdrByteCountPointerUnmarshall(typeFormatStringOffset, arg.ToIntPtr(), 0);
                break;

            case RpceFormatCharType.FC_IP:
                retVal = NdrPointerUnmarshall(typeFormatStringOffset);
                break;

            case RpceFormatCharType.FC_BIND_CONTEXT:
                retVal = NdrContextHandleUnmarshall(arg, typeFormatStringOffset);
                break;

            case (RpceFormatCharType)((int)RpceFormatCharType.FC_SUPPLEMENT & FORMAT_CHAR_ROUTINE_BITMASK):
                retVal = NdrSupplementUnmarshall(arg, typeFormatStringOffset, 0);
                break;

            case (RpceFormatCharType)((int)RpceFormatCharType.FC_RANGE & FORMAT_CHAR_ROUTINE_BITMASK):
                retVal = NdrRangeUnmarshall(typeFormatStringOffset);
                break;

            case (RpceFormatCharType)((int)RpceFormatCharType.FC_INT3264 & FORMAT_CHAR_ROUTINE_BITMASK):
            case (RpceFormatCharType)((int)RpceFormatCharType.FC_UINT3264 & FORMAT_CHAR_ROUTINE_BITMASK):
                if (IntPtr.Size == sizeof(int))
                {
                    retVal = NdrInt32Unmarshal();
                }
                else if (IntPtr.Size == sizeof(long))
                {
                    retVal = NdrInt64Unmarshal();
                }
                else
                {
                    throw new InvalidOperationException("Unsupported platform.");
                }
                break;

            case (RpceFormatCharType)0x0f:     // Ignore
                break;

            case RpceFormatCharType.FC_TRANSMIT_AS:
            case RpceFormatCharType.FC_REPRESENT_AS:
            case (RpceFormatCharType)((int)
                                      RpceFormatCharType.FC_TRANSMIT_AS_PTR & FORMAT_CHAR_ROUTINE_BITMASK):
            case (RpceFormatCharType)((int)
                                      RpceFormatCharType.FC_REPRESENT_AS_PTR & FORMAT_CHAR_ROUTINE_BITMASK):
            case (RpceFormatCharType)((int)RpceFormatCharType.FC_USER_MARSHAL & FORMAT_CHAR_ROUTINE_BITMASK):
            case (RpceFormatCharType)((int)RpceFormatCharType.FC_PIPE & FORMAT_CHAR_ROUTINE_BITMASK):
            case (RpceFormatCharType)((int)RpceFormatCharType.FC_CSARRAY & FORMAT_CHAR_ROUTINE_BITMASK):
            case (RpceFormatCharType)((int)RpceFormatCharType.FC_CS_TAG & FORMAT_CHAR_ROUTINE_BITMASK):
                throw new NotSupportedException(
                          "transmit_as, represent_as, user_marshal, pipe and csarray are not supported.");

            default:
                throw new InvalidOperationException(
                          string.Format("Unsupported type format char {0}.", formatChar));
            }

            return(retVal);
        }
        /// <summary>
        /// The AbortShadowCopySet method is invoked by the client to delete a given shadow copy set on the server.
        /// </summary>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set to which ShareName is to be added.</param>
        /// <returns></returns>
        public int AbortShadowCopySet(Guid ShadowCopySetId)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);

            paramList = new Int3264[] {
                pShadowCopySetId,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.AbortShadowCopySet))
                {
                    retVal = outParamList[1].ToInt32();
                }
            }
            finally
            {
                pShadowCopySetId.Dispose();
            }

            return retVal;
        }
        /// <summary>
        /// The SetContext method sets the context for subsequent shadow copy-related operations.
        /// </summary>
        /// <param name="Context">The context to be used for the shadow copy operations.</param>
        /// <returns>It MUST be zero or a combination of the CONTEXT_VALUES as specified in section 2.2.2.2.</returns>
        public int SetContext(ulong Context)
        {
            Int3264[] paramList;
            int retVal = 0;

            paramList = new Int3264[] {
                Context,
                IntPtr.Zero
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.SetContext))
            {
                retVal = outParamList[1].ToInt32();
            }

            return retVal;
        }
        /// <summary>
        /// This call waits until all the shadowcopy preparation is done on the file server.
        /// It is used to avoid the long preparation time on file server break the
        /// 60 seconds freeze/thaw window on the application server
        /// It must be called between the last AddToShadowCopySet and CommitShadowCopySet
        /// </summary>
        /// <param name="ShadowCopySetId">The GUID of shadow copy set</param>
        /// <param name="TimeOutInMilliseconds">The maximum total time in milliseconds for which the server MUST wait for the expose operation.</param>
        /// <returns></returns>
        public int PrepareShadowCopySet(
            Guid ShadowCopySetId,
            uint TimeOutInMilliseconds
            )
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);

            paramList = new Int3264[]{
                pShadowCopySetId,
                TimeOutInMilliseconds,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.PrepareShadowCopySet))
                {
                    retVal = outParamList[2].ToInt32();
                }
            }
            finally
            {
                pShadowCopySetId.Dispose();
            }

            return retVal;
        }
        /// <summary>
        /// The IsPathShadowCopied method is invoked by the client to query if any shadow copy for a share already exists.
        /// </summary>
        /// <param name="ShareName">The full path of the share in UNC format.</param>
        /// <param name="ShadowCopyPresent">On output, a Boolean, when set to TRUE, indicates that shadow
        /// copies of this share are supported by the server.</param>
        /// <param name="ShadowCopyCompatibility">On output, this indicates whether certain I/O operations on the object
        /// store containing the shadow copy are disabled. This MUST be zero or a combination of the values 
        /// as specified in section 2.2.2.2.</param>
        /// <returns></returns>
        public int IsPathShadowCopied(
            string ShareName,
            out bool ShadowCopyPresent,
            out long ShadowCopyCompatibility)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShareName,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.IsPathShadowCopied))
                {
                    retVal = outParamList[paramList.Length - 1].ToInt32();
                    ShadowCopyPresent = TypeMarshal.ToStruct<bool>(outParamList[1]);
                    ShadowCopyCompatibility = Marshal.ReadInt32(outParamList[2]);
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pShareName.Dispose();
            }

            return retVal;
        }
        /// <summary>
        /// The GetShareMapping method is invoked by the client to get the shadow copy information on a given
        /// file share on the server.
        /// </summary>
        /// <param name="ShadowCopyId">The GUID of the shadow copy associated with the share.</param>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set.</param>
        /// <param name="ShareName">The name of the share in UNC format.</param>
        /// <param name="Level">The format of this data depends on the value of the level parameter.</param>
        /// <param name="ShareMapping">On output, a FSSAGENT_SHARE_MAPPING structure, as specified in section 2.2.3.1.</param>
        /// <returns></returns>
        public int GetShareMapping(
            Guid ShadowCopyId,
            Guid ShadowCopySetId,
            string ShareName,
            uint Level,
            out FSSAGENT_SHARE_MAPPING ShareMapping)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pShadowCopyId = TypeMarshal.ToIntPtr(ShadowCopyId);
            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);
            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShadowCopyId,
                pShadowCopySetId,
                pShareName,
                Level,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.GetShareMapping))
                {
                    retVal = outParamList[5].ToInt32();
                    ShareMapping = new FSSAGENT_SHARE_MAPPING();
                    if ((FsrvpErrorCode)retVal == FsrvpErrorCode.FSRVP_SUCCESS)
                    {
                        ShareMapping.ShareMapping1 = TypeMarshal.ToStruct<FSSAGENT_SHARE_MAPPING_1>(Marshal.ReadIntPtr(outParamList[4]));
                        ShareMapping.ShareMapping1IsNull = false;
                    }
                    else
                    {
                        ShareMapping.ShareMapping1IsNull = true;
                    }
                }
            }
            finally
            {
                pShadowCopyId.Dispose();
                pShadowCopySetId.Dispose();
                pShareName.Dispose();
            }

            return retVal;
        }
        /// <summary>
        /// The AddToShadowCopySet method adds a share to an existing shadow copy set.
        /// </summary>
        /// <param name="ClientShadowCopyId">The GUID of the client. This MUST be set to NULL.</param>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set to which ShareName is to be added.</param>
        /// <param name="ShareName">The name of the share in UNC format for which a shadow copy is required.</param>
        /// <param name="pShadowCopyId">On output, the GUID of the shadow copy associated to the share.</param>
        /// <returns></returns>
        public int AddToShadowCopySet(
            Guid ClientShadowCopyId,
            Guid ShadowCopySetId,
            string ShareName,
            out Guid pShadowCopyId)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pClientShadowCopyId = TypeMarshal.ToIntPtr(ClientShadowCopyId);
            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);
            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[]{
                pClientShadowCopyId,
                pShadowCopySetId,
                pShareName,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.AddToShadowCopySet))
                {
                    pShadowCopyId = TypeMarshal.ToStruct<Guid>(outParamList[3]);
                    retVal = outParamList[4].ToInt32();
                }
            }
            finally
            {
                pClientShadowCopyId.Dispose();
                pShadowCopySetId.Dispose();
                pShareName.Dispose();
            }

            return retVal;
        }
        /// <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,
            [Indirect()] _RPC_UNICODE_STRING ServerName,
            [Indirect()] _RPC_UNICODE_STRING UserName,
            [Indirect()] _SAMPR_ENCRYPTED_USER_PASSWORD NewPasswordEncryptedWithOldNt,
            [Indirect()] _ENCRYPTED_LM_OWF_PASSWORD OldNtOwfPasswordEncryptedWithNewNt,
            byte LmPresent,
            [Indirect()] _SAMPR_ENCRYPTED_USER_PASSWORD NewPasswordEncryptedWithOldLm,
            [Indirect()] _ENCRYPTED_LM_OWF_PASSWORD OldLmOwfPasswordEncryptedWithNewNt)
        {
            const ushort opnum = 55;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pServerName = TypeMarshal.ToIntPtr(ServerName);
            SafeIntPtr pUserName = TypeMarshal.ToIntPtr(UserName);
            SafeIntPtr pNewPasswordEncryptedWithOldNt = TypeMarshal.ToIntPtr(NewPasswordEncryptedWithOldNt);
            SafeIntPtr pOldNtOwfPasswordEncryptedWithNewNt = TypeMarshal.ToIntPtr(OldNtOwfPasswordEncryptedWithNewNt);
            SafeIntPtr pNewPasswordEncryptedWithOldLm = TypeMarshal.ToIntPtr(NewPasswordEncryptedWithOldLm);
            SafeIntPtr pOldLmOwfPasswordEncryptedWithNewNt = TypeMarshal.ToIntPtr(OldLmOwfPasswordEncryptedWithNewNt);

            paramList = new Int3264[] {
                pServerName,
                pUserName,
                pNewPasswordEncryptedWithOldNt,
                pOldNtOwfPasswordEncryptedWithNewNt,
                (uint)LmPresent,
                pNewPasswordEncryptedWithOldLm,
                pOldLmOwfPasswordEncryptedWithNewNt,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[7].ToInt32();
                }
            }
            finally
            {
                pServerName.Dispose();
                pUserName.Dispose();
                pNewPasswordEncryptedWithOldNt.Dispose();
                pOldNtOwfPasswordEncryptedWithNewNt.Dispose();
                pNewPasswordEncryptedWithOldLm.Dispose();
                pOldLmOwfPasswordEncryptedWithNewNt.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrSetSecurityObject method sets the access control
        ///  on a server, domain, user, group, or alias object.
        ///  Opnum: 2 
        /// </summary>
        /// <param name="ObjectHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a server, domain, user, group, or alias object.
        /// </param>
        /// <param name="SecurityInformation">
        ///  A bit field that indicates the fields of SecurityDescriptor
        ///  that are requested to be set. The SECURITY_INFORMATION
        ///  type is defined in [MS-DTYP] section. The following
        ///  bits are valid; all other bits MUST be zero on send
        ///  and ignored on receipt.
        /// </param>
        /// <param name="SecurityDescriptor">
        ///  A security descriptor expressing access that is specific
        ///  to the ObjectHandle.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrSetSecurityObject(
            IntPtr ObjectHandle,
            SecurityInformation_Values SecurityInformation,
            _SAMPR_SR_SECURITY_DESCRIPTOR? SecurityDescriptor)
        {
            const ushort opnum = 2;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pSecurityDescriptor = TypeMarshal.ToIntPtr(SecurityDescriptor);

            paramList = new Int3264[] {
                ObjectHandle,
                (uint)SecurityInformation,
                pSecurityDescriptor,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pSecurityDescriptor.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrSetMemberAttributesOfGroup method sets the attributes
        ///  of a member relationship. Opnum: 26 
        /// </summary>
        /// <param name="GroupHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a group object.
        /// </param>
        /// <param name="MemberId">
        ///  A RID that represents a member of a group (which is
        ///  a user or machine account).
        /// </param>
        /// <param name="Attributes">
        ///  The characteristics of the membership relationship.
        ///  For legal values, see section.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrSetMemberAttributesOfGroup(IntPtr GroupHandle, uint MemberId, uint Attributes)
        {
            const ushort opnum = 26;
            Int3264[] paramList;
            int retVal = 0;

            paramList = new Int3264[] {
                GroupHandle,
                MemberId,
                Attributes,
                IntPtr.Zero
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
            {
                retVal = outParamList[3].ToInt32();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrSetInformationUser2 method updates attributes
        ///  on a user object. Opnum: 58 
        /// </summary>
        /// <param name="UserHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a user object.
        /// </param>
        /// <param name="UserInformationClass">
        ///  An enumeration indicating which attributes to update.
        ///  See section  for a listing of possible values.
        /// </param>
        /// <param name="Buffer">
        ///  The requested attributes and values to update. See section
        ///   for structure details.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrSetInformationUser2(
            System.IntPtr UserHandle,
            _USER_INFORMATION_CLASS UserInformationClass,
            [Switch("UserInformationClass")] _SAMPR_USER_INFO_BUFFER Buffer)
        {
            const ushort opnum = 58;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pBuffer = TypeMarshal.ToIntPtr(Buffer, UserInformationClass, null, null);

            paramList = new Int3264[] {
                UserHandle,
                (int)UserInformationClass,
                pBuffer,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pBuffer.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrSetInformationGroup method updates attributes
        ///  on a group object. Opnum: 21 
        /// </summary>
        /// <param name="GroupHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a group object.
        /// </param>
        /// <param name="GroupInformationClass">
        ///  An enumeration indicating which attributes to update.
        ///  See section  for a listing of possible values.
        /// </param>
        /// <param name="Buffer">
        ///  The requested attributes and values to update. See section
        ///   for structure details.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrSetInformationGroup(
            IntPtr GroupHandle,
            _GROUP_INFORMATION_CLASS GroupInformationClass,
            _SAMPR_GROUP_INFO_BUFFER Buffer)
        {
            const ushort opnum = 21;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pBuffer = TypeMarshal.ToIntPtr(Buffer, GroupInformationClass, null, null);

            paramList = new Int3264[] {
                GroupHandle,
                (int)GroupInformationClass,
                pBuffer,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pBuffer.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrSetInformationDomain method updates attributes
        ///  on a domain object. Opnum: 9 
        /// </summary>
        /// <param name="DomainHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a domain object.
        /// </param>
        /// <param name="DomainInformationClass">
        ///  An enumeration indicating which attributes to update.
        ///  See section  for a list of possible values.
        /// </param>
        /// <param name="DomainInformation">
        ///  The requested attributes and values to update. See section
        ///   for structure details.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrSetInformationDomain(
            IntPtr DomainHandle,
            _DOMAIN_INFORMATION_CLASS DomainInformationClass,
            _SAMPR_DOMAIN_INFO_BUFFER DomainInformation)
        {
            const ushort opnum = 9;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pDomainInformation = TypeMarshal.ToIntPtr(
                DomainInformation,
                DomainInformationClass,
                null,
                null);

            paramList = new Int3264[] {
                DomainHandle,
                (int)DomainInformationClass,
                pDomainInformation,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pDomainInformation.Dispose();
            }

            return retVal;
        }
        /// <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,
            [Indirect()] _RPC_UNICODE_STRING Unused,
            uint UserId,
            [Indirect()] _ENCRYPTED_LM_OWF_PASSWORD EncryptedNtOwfPassword)
        {
            const ushort opnum = 66;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pUnused = TypeMarshal.ToIntPtr(Unused);
            SafeIntPtr pEncryptedNtOwfPassword = TypeMarshal.ToIntPtr(EncryptedNtOwfPassword);

            paramList = new Int3264[] {
                pUnused,
                UserId,
                pEncryptedNtOwfPassword,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pUnused.Dispose();
                pEncryptedNtOwfPassword.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrRemoveMemberFromGroup method removes a member
        ///  from a group. Opnum: 24 
        /// </summary>
        /// <param name="GroupHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a group object.
        /// </param>
        /// <param name="MemberId">
        ///  A RID representing an account to remove from the group's
        ///  membership list.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrRemoveMemberFromGroup(IntPtr GroupHandle, uint MemberId)
        {
            const ushort opnum = 24;
            Int3264[] paramList;
            int retVal = 0;

            paramList = new Int3264[] {
                GroupHandle,
                MemberId,
                IntPtr.Zero
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
            {
                retVal = outParamList[2].ToInt32();
            }

            return retVal;
        }
        /// <summary>
        /// The DeleteShareMapping method deletes the mapping of a share’s shadow copy from a shadow copy set.
        /// </summary>
        /// <param name="ShadowCopySetId">The GUID of the shadow copy set.</param>
        /// <param name="ShadowCopyId">The GUID of the shadow copy associated with the share.</param>
        /// <param name="ShareName">The name of the share for which the share mapping is to be deleted.</param>
        /// <returns></returns>
        public int DeleteShareMapping(
            Guid ShadowCopySetId,
            Guid ShadowCopyId,
            string ShareName)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pShadowCopySetId = TypeMarshal.ToIntPtr(ShadowCopySetId);
            SafeIntPtr pShadowCopyId = TypeMarshal.ToIntPtr(ShadowCopyId);
            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShadowCopySetId,
                pShadowCopyId,
                pShareName,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.DeleteShareMapping))
                {
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pShadowCopySetId.Dispose();
                pShadowCopyId.Dispose();
                pShareName.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrValidatePassword method validates an application
        ///  password against the locally stored policy. Opnum :
        ///  67 
        /// </summary>
        /// <param name="Handle">
        ///  An RPC binding handle parameter, as specified in [C706-Ch2Intro].
        /// </param>
        /// <param name="ValidationType">
        ///  The password policy validation requested.
        /// </param>
        /// <param name="InputArg">
        ///  The password-related material to validate.
        /// </param>
        /// <param name="OutputArg">
        ///  The result of the validation.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrValidatePassword(
            System.IntPtr Handle,
            _PASSWORD_POLICY_VALIDATION_TYPE ValidationType,
            _SAM_VALIDATE_INPUT_ARG InputArg,
            out _SAM_VALIDATE_OUTPUT_ARG? OutputArg)
        {
            const ushort opnum = 67;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pInputArg = TypeMarshal.ToIntPtr(InputArg, ValidationType, null, null);

            paramList = new Int3264[] {
                (int)ValidationType,
                pInputArg,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    OutputArg = TypeMarshal.ToNullableStruct<_SAM_VALIDATE_OUTPUT_ARG>(
                        Marshal.ReadIntPtr(outParamList[2]), ValidationType, null, null);
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pInputArg.Dispose();
            }

            return retVal;
        }
        /// <summary>
        /// Get the Server supported version range.  
        /// Windows Server 8 compatiable Agent should return both  
        /// as FSSAGENT_RPC_VERSION_1
        /// </summary>
        /// <param name="MinVersion">The minor version.</param>
        /// <param name="MaxVersion">The maximum version.</param>
        /// <returns></returns>
        public int GetSupportedVersion(out uint MinVersion, out uint MaxVersion)
        {
            Int3264[] paramList;
            int retVal = 0;

            paramList = new Int3264[] {
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.GetSupportedVersion))
            {
                MinVersion = (uint)Marshal.ReadInt32(outParamList[0]);
                MaxVersion = (uint)Marshal.ReadInt32(outParamList[1]);
                retVal = outParamList[2].ToInt32();
            }

            return retVal;
        }
        /// <summary>
        /// The common part of all the Samr Rpc methods
        /// </summary>
        /// <param name="paramList">input param list to decode</param>
        /// <param name="opnum">opnum of the current Samr Rpc method</param>
        /// <returns>the decoded parameter list</returns>
        private RpceInt3264Collection RpceCall(Int3264[] paramList, ushort opnum)
        {
            byte[] requestStub;
            byte[] responseStub;

            requestStub = RpceStubEncoder.ToBytes(
              RpceStubHelper.GetPlatform(),
                    SamrRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] {
                        new RpceStubExprEval(samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000),
                        new RpceStubExprEval(samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001),
                        new RpceStubExprEval(samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002),
                        new RpceStubExprEval(samr_SAMPR_LOGON_HOURSExprEval_0003) },
                    SamrRpcStubFormatString.ProcFormatString,
                    SamrRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    paramList);

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

            RpceInt3264Collection outParamList = RpceStubDecoder.ToParamList(
              RpceStubHelper.GetPlatform(),
                    SamrRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] {
                        new RpceStubExprEval(samr_SAMPR_USER_LOGON_INFORMATIONExprEval_0000),
                        new RpceStubExprEval(samr_SAMPR_USER_LOGON_HOURS_INFORMATIONExprEval_0001),
                        new RpceStubExprEval(samr_SAMPR_USER_ACCOUNT_INFORMATIONExprEval_0002),
                        new RpceStubExprEval(samr_SAMPR_LOGON_HOURSExprEval_0003) },
                    SamrRpcStubFormatString.ProcFormatString,
                    SamrRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    responseStub,
                    paramList);

            return outParamList;
        }
        /// <summary>
        /// The IsPathSupported method is invoked by client to query if a given share is supported by the server 
        /// for shadow copy operations.
        /// </summary>
        /// <param name="ShareName">The full path of the share in UNC format.</param>
        /// <param name="SupportedByThisProvider">On output, a Boolean, when set to TRUE, indicates that shadow
        /// copies of this share are supported by the server.</param>
        /// <param name="OwnerMachineName">On output, the name of the server machine to which the client MUST 
        /// connect to create shadow copies of the specified ShareName.</param>
        /// <returns></returns>
        public int IsPathSupported(
            string ShareName,
            out bool SupportedByThisProvider,
            out string OwnerMachineName)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pShareName = Marshal.StringToHGlobalUni(ShareName);

            paramList = new Int3264[] {
                pShareName,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.IsPathSupported))
                {
                    SupportedByThisProvider = TypeMarshal.ToStruct<bool>(outParamList[1]);//(Marshal.ReadInt32(outParamList[1]) == 1);
                    OwnerMachineName = Marshal.PtrToStringUni(Marshal.ReadIntPtr(outParamList[2]));
                    retVal = outParamList[3].ToInt32();
                }
            }
            finally
            {
                pShareName.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrChangePasswordUser method changes the password
        ///  of a user object. Opnum: 38 
        /// </summary>
        /// <param name="UserHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a user object.
        /// </param>
        /// <param name="LmPresent">
        ///  If this parameter is zero, the LmOldEncryptedWithLmNew
        ///  and LmNewEncryptedWithLmOld fields MUST be ignored
        ///  by the server; otherwise these fields MUST be processed.
        /// </param>
        /// <param name="OldLmEncryptedWithNewLm">
        ///  The LM 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 LM hash of the new password for the target
        ///  user (as presented by the client in the LmNewEncryptedWithLmOld
        ///  parameter).
        /// </param>
        /// <param name="NewLmEncryptedWithOldLm">
        ///  The LM hash of the target user's new password (as presented
        ///  by the client) encrypted according to the specification
        ///  of ENCRYPTED_LM_OWF_PASSWORD, where the key is the
        ///  LM hash of the existing password for the target user
        ///  (as presented by the client in the LmOldEncryptedWithLmNew
        ///  parameter).
        /// </param>
        /// <param name="NtPresent">
        ///  If this parameter is zero, NtOldEncryptedWithNtNew and
        ///  NtNewEncryptedWithNtOld MUST be ignored by the server;
        ///  otherwise these fields MUST be processed. 
        /// </param>
        /// <param name="OldNtEncryptedWithNewNt">
        ///  The NT hash of the target user's existing password (as
        ///  presented by the client) encrypted according to the
        ///  specification of  ENCRYPTED_NT_OWF_PASSWORD, where
        ///  the key is the NT hash of the new password for the
        ///  target user (as presented by the client).
        /// </param>
        /// <param name="NewNtEncryptedWithOldNt">
        ///  The NT hash of the target user's new password (as presented
        ///  by the client) encrypted according to the specification
        ///  of ENCRYPTED_NT_OWF_PASSWORD, where the key is the
        ///  NT hash of the existing password for the target user
        ///  (as presented by the client).
        /// </param>
        /// <param name="NtCrossEncryptionPresent">
        ///  If this parameter is zero, NtNewEncryptedWithLmNew MUST
        ///  be ignored; otherwise, this field MUST be processed.
        /// </param>
        /// <param name="NewNtEncryptedWithNewLm">
        ///  The NT hash of the target user's new password (as presented
        ///  by the client) encrypted according to the specification
        ///  of ENCRYPTED_NT_OWF_PASSWORD, where the key is the
        ///  LM hash of the new password for the target user (as
        ///  presented by the client).
        /// </param>
        /// <param name="LmCrossEncryptionPresent">
        ///  If this parameter is zero, LmNewEncryptedWithNtNew MUST
        ///  be ignored; otherwise, this field MUST be processed.
        /// </param>
        /// <param name="NewLmEncryptedWithNewNt">
        ///  The LM hash of the target user's new 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 new password for the target user (as
        ///  presented by the client).
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrChangePasswordUser(
            IntPtr UserHandle,
            byte LmPresent,
            _ENCRYPTED_LM_OWF_PASSWORD? OldLmEncryptedWithNewLm,
            _ENCRYPTED_LM_OWF_PASSWORD? NewLmEncryptedWithOldLm,
            byte NtPresent,
            _ENCRYPTED_LM_OWF_PASSWORD? OldNtEncryptedWithNewNt,
            _ENCRYPTED_LM_OWF_PASSWORD? NewNtEncryptedWithOldNt,
            byte NtCrossEncryptionPresent,
            _ENCRYPTED_LM_OWF_PASSWORD? NewNtEncryptedWithNewLm,
            byte LmCrossEncryptionPresent,
            _ENCRYPTED_LM_OWF_PASSWORD? NewLmEncryptedWithNewNt)
        {
            const ushort opnum = 38;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pOldLmEncryptedWithNewLm = TypeMarshal.ToIntPtr(OldLmEncryptedWithNewLm);
            SafeIntPtr pNewLmEncryptedWithOldLm = TypeMarshal.ToIntPtr(NewLmEncryptedWithOldLm);
            SafeIntPtr pOldNtEncryptedWithNewNt = TypeMarshal.ToIntPtr(OldNtEncryptedWithNewNt);
            SafeIntPtr pNewNtEncryptedWithOldNt = TypeMarshal.ToIntPtr(NewNtEncryptedWithOldNt);
            SafeIntPtr pNewNtEncryptedWithNewLm = TypeMarshal.ToIntPtr(NewNtEncryptedWithNewLm);
            SafeIntPtr pNewLmEncryptedWithNewNt = TypeMarshal.ToIntPtr(NewLmEncryptedWithNewNt);

            paramList = new Int3264[] {
                UserHandle,
                (uint)LmPresent,
                pOldLmEncryptedWithNewLm,
                pNewLmEncryptedWithOldLm,
                (uint)NtPresent,
                pOldNtEncryptedWithNewNt,
                pNewNtEncryptedWithOldNt,
                (uint)NtCrossEncryptionPresent,
                pNewNtEncryptedWithNewLm,
                (uint)LmCrossEncryptionPresent,
                pNewLmEncryptedWithNewNt,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[11].ToInt32();
                }
            }
            finally
            {
                pNewLmEncryptedWithNewNt.Dispose();
                pNewLmEncryptedWithOldLm.Dispose();
                pNewNtEncryptedWithNewLm.Dispose();
                pNewNtEncryptedWithOldNt.Dispose();
                pOldLmEncryptedWithNewLm.Dispose();
                pOldNtEncryptedWithNewNt.Dispose();
            }

            return retVal;
        }
        /// <summary>
        /// The common part of all the FSRVP methods
        /// </summary>
        /// <param name="paramList">input param list to decode</param>
        /// <param name="opnum">opnum of the current FSRVP method</param>
        /// <returns>the decoded paramlist</returns>
        public RpceInt3264Collection RpceCall(Int3264[] paramList, ushort opnum)
        {
            byte[] requestStub;
            byte[] responseStub;
            RpceInt3264Collection outParamList = null;

            requestStub = RpceStubEncoder.ToBytes(
                    RpceStubHelper.GetPlatform(),
                    FsrvpStubFormatString.TypeFormatString,
                    null,
                    FsrvpStubFormatString.ProcFormatString,
                    FsrvpStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    paramList);

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

            outParamList = RpceStubDecoder.ToParamList(
                    RpceStubHelper.GetPlatform(),
                    FsrvpStubFormatString.TypeFormatString,
                    null,
                    FsrvpStubFormatString.ProcFormatString,
                    FsrvpStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    responseStub,
                    paramList);

            return outParamList;
        }
        /// <summary>
        ///  The SamrCloseHandle method closes (that is, releases
        ///  server-side resources used by) any context handle obtained
        ///  from this RPC interface. Opnum: 1 
        /// </summary>
        /// <param name="SamHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  any context handle returned from this interface.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrCloseHandle(ref IntPtr SamHandle)
        {
            const ushort opnum = 1;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr ppSamHandle = TypeMarshal.ToIntPtr(SamHandle);

            paramList = new Int3264[] {
                ppSamHandle,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    SamHandle = Marshal.ReadIntPtr(outParamList[0]);
                    retVal = outParamList[1].ToInt32();
                }
            }
            finally
            {
                ppSamHandle.Dispose();
            }

            return retVal;
        }
        /// <summary>
        /// The StartShadowCopySet method is called by the client to initiate a new shadow copy set for shadow copy creation.
        /// </summary>
        /// <param name="pShadowCopySetId">On output, the GUID of the shadow copy set that must be created by server.</param>
        /// <returns></returns>
        public int StartShadowCopySet(
            Guid clientShadowCopySetId,
            out Guid pShadowCopySetId)
        {
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pClientShadowCopySetId = TypeMarshal.ToIntPtr(clientShadowCopySetId);

            paramList = new Int3264[] {
                pClientShadowCopySetId,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)FSRVP_OPNUM.StartShadowCopySet))
                {
                    pShadowCopySetId = TypeMarshal.ToStruct<Guid>(outParamList[1]);
                    retVal = outParamList[2].ToInt32();
                }
            }
            finally
            {
                pClientShadowCopySetId.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrConnect4 method obtains a handle to a server
        ///  object. Opnum: 62 
        /// </summary>
        /// <param name="ServerName">
        ///  The null-terminated NETBIOS name of the server; this
        ///  parameter MAYServerName is ignored on receipt.  be
        ///  ignored on receipt.
        /// </param>
        /// <param name="ServerHandle">
        ///  An RPC context handle, as specified in section.
        /// </param>
        /// <param name="ClientRevision">
        ///  Indicates the revision (for this protocol) of the client.
        ///  See the Revision field of SAMPR_REVISION_INFO_V1 for
        ///  possible values.
        /// </param>
        /// <param name="DesiredAccess">
        ///  An ACCESS_MASK that indicates the access requested for
        ///  ServerHandle on output. See section  for a listing
        ///  of possible values.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrConnect4(
            string ServerName,
            out System.IntPtr ServerHandle,
            uint ClientRevision,
            uint DesiredAccess)
        {
            const ushort opnum = 62;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName);

            paramList = new Int3264[] {
                pServerName,
                IntPtr.Zero,
                ClientRevision,
                DesiredAccess,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    ServerHandle = Marshal.ReadIntPtr(outParamList[1]);
                    retVal = outParamList[4].ToInt32();
                }
            }
            finally
            {
                pServerName.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrRemoveMemberFromForeignDomain method removes
        ///  a member from all aliases. Opnum: 45 
        /// </summary>
        /// <param name="DomainHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  a domain object.
        /// </param>
        /// <param name="MemberSid">
        ///  The SID to remove from the membership.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrRemoveMemberFromForeignDomain(IntPtr DomainHandle, _RPC_SID? MemberSid)
        {
            const ushort opnum = 45;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pMemberSid = TypeMarshal.ToIntPtr(MemberSid);

            paramList = new Int3264[] {
                DomainHandle,
                pMemberSid,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[2].ToInt32();
                }
            }
            finally
            {
                pMemberSid.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrConnect5 method obtains a handle to a server
        ///  object. Opnum: 64 
        /// </summary>
        /// <param name="ServerName">
        ///  The null-terminated NETBIOS name of the server; this
        ///  parameter MAYServerName is ignored on receipt.  be
        ///  ignored on receipt.
        /// </param>
        /// <param name="DesiredAccess">
        ///  An ACCESS_MASK that indicates the access requested for
        ///  ServerHandle on output. For a listing of possible values,
        ///  see section.
        /// </param>
        /// <param name="InVersion">
        ///  Indicates which field of the InRevisionInfo union is
        ///  used.
        /// </param>
        /// <param name="InRevisionInfo">
        ///  Revision information. For details, see the definition
        ///  of the SAMPR_REVISION_INFO_V1 structure, which is contained
        ///  in the SAMPR_REVISION_INFO union.
        /// </param>
        /// <param name="OutVersion">
        ///  Indicates which field of the OutRevisionInfo union is
        ///  used.
        /// </param>
        /// <param name="OutRevisionInfo">
        ///  Revision information. For details, see the definition
        ///  of the SAMPR_REVISION_INFO_V1 structure, which is contained
        ///  in the SAMPR_REVISION_INFO union.
        /// </param>
        /// <param name="ServerHandle">
        ///  An RPC context handle, as specified in section.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrConnect5(
            [String()] string ServerName,
            uint DesiredAccess,
            uint InVersion,
            [Switch("InVersion")] SAMPR_REVISION_INFO InRevisionInfo,
            out System.UInt32 OutVersion,
            [Switch("*OutVersion")] out SAMPR_REVISION_INFO OutRevisionInfo,
            out System.IntPtr ServerHandle)
        {
            const ushort opnum = 64;
            Int3264[] paramList;
            int retVal = 0;

            SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName);
            SafeIntPtr pInRevisionInfo = TypeMarshal.ToIntPtr(InRevisionInfo, InVersion, null, null);

            paramList = new Int3264[] {
                pServerName,
                DesiredAccess,
                InVersion,
                pInRevisionInfo,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    OutVersion = TypeMarshal.ToStruct<uint>(outParamList[4]);
                    OutRevisionInfo = TypeMarshal.ToStruct<SAMPR_REVISION_INFO>(
                        outParamList[5], OutVersion, null, null);
                    ServerHandle = Marshal.ReadIntPtr(outParamList[6]);
                    retVal = outParamList[7].ToInt32();
                }
            }
            finally
            {
                pServerName.Dispose();
                pInRevisionInfo.Dispose();
            }

            return retVal;
        }
        /// <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>
        ///  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 SamrAddMultipleMembersToAlias method adds multiple
        ///  members to an alias. Opnum: 52 
        /// </summary>
        /// <param name="AliasHandle">
        ///  An RPC context handle, as specified in section , representing
        ///  an alias object.
        /// </param>
        /// <param name="MembersBuffer">
        ///  A structure containing a list of SIDs to add as members
        ///  to the alias.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrAddMultipleMembersToAlias(IntPtr AliasHandle, _SAMPR_PSID_ARRAY? MembersBuffer)
        {
            const ushort opnum = 52;
            Int3264[] paramList;
            int retVal = 0;
            SafeIntPtr pMembersBuffer = TypeMarshal.ToIntPtr(MembersBuffer);

            paramList = new Int3264[] {
                AliasHandle,
                pMembersBuffer,
                IntPtr.Zero
            };

            try
            {
                using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
                {
                    retVal = outParamList[2].ToInt32();
                }
            }
            finally
            {
                pMembersBuffer.Dispose();
            }

            return retVal;
        }
        /// <summary>
        ///  The SamrRidToSid method obtains the SID of an account,
        ///  given a RID. Opnum: 65 
        /// </summary>
        /// <param name="ObjectHandle">
        ///  An RPC context handle, as specified in section. The
        ///  message processing shown later in this section contains
        ///  details on which types of ObjectHandle are accepted
        ///  by the server.
        /// </param>
        /// <param name="Rid">
        ///  A RID of an account.
        /// </param>
        /// <param name="Sid">
        ///  The SID of the account referenced by Rid.
        /// </param>
        /// <returns>
        /// status of the function call, for example: 0 indicates STATUS_SUCCESS
        /// </returns>
        public int SamrRidToSid(System.IntPtr ObjectHandle, uint Rid, out _RPC_SID? Sid)
        {
            const ushort opnum = 65;
            Int3264[] paramList;
            int retVal = 0;

            paramList = new Int3264[] {
                ObjectHandle,
                Rid,
                IntPtr.Zero,
                IntPtr.Zero
            };

            using (RpceInt3264Collection outParamList = RpceCall(paramList, opnum))
            {
                Sid = TypeMarshal.ToNullableStruct<_RPC_SID>(Marshal.ReadIntPtr(outParamList[2]));
                retVal = outParamList[3].ToInt32();
            }

            return retVal;
        }