コード例 #1
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;
        }
コード例 #2
0
        private RpceInt3264Collection RpceCall(Int3264[] paramList, ushort opnum)
        {
            byte[] requestStub;
            byte[] responseStub;
            RpceInt3264Collection outParamList = null;

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

            RpceClientTransport.Call(opnum, requestStub, RpceTimeout, out responseStub);

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

            return outParamList;
        }
コード例 #3
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;
        }
コード例 #4
0
 /// <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;
 }
コード例 #5
0
        /// <summary>
        /// The common method of all the SWN async calls
        /// </summary>
        /// <param name="paramList">input param list to decode</param>
        /// <param name="opnum">opnum of the current SWN calls</param>
        /// <returns>The identifier of this async call.</returns>
        private uint RpceAsyncCall(Int3264[] paramList, ushort opnum)
        {
            byte[] requestStub;
            uint callId;

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

            rpceClientTransport.SendRequest(opnum, requestStub, out callId);

            RpceResponseFormat format = new RpceResponseFormat();
            format.opnum = opnum;
            format.paramList = paramList;

            lock (responseLock)
            {
                responseFormat.Add(callId, format);
            }

            return callId;
        }
コード例 #6
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;
        }
コード例 #7
0
        /// <summary>
        /// SWN client invoke WitnessrRegisterEx 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="ShareName">Specifies a null-terminated string that specifies the name of the share 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="Flags">Specifies the type of Witness registration.</param>
        /// <param name="KeepAliveTimout">Specifies the maximum number of milliseconds for any notification response from the server.</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 WitnessrRegisterEx(SwnVersion Version, string NetName, string ShareName, string IpAddr, string ClientName, WitnessrRegisterExFlagsValue Flags, uint KeepAliveTimout, out IntPtr pContext)
        {
            Int3264[] paramList;
            int retVal = 0;

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

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

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

            return retVal;
        }
コード例 #8
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;
        }
コード例 #9
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);
        }