Esempio n. 1
0
        public static List <string> ListShares(INtFileStore namedPipeShare, ShareType?shareType)
        {
            NamedPipeHelper.BindPipe(namedPipeShare, ServerService.ServicePipeName, ServerService.ServiceInterfaceGuid, ServerService.ServiceVersion, out NtHandle? pipeHandle, out int maxTransmitFragmentSize).IsSuccessElseThrow();

            NetrShareEnumRequest shareEnumRequest = new NetrShareEnumRequest
            {
                InfoStruct = new ShareEnum
                {
                    Level = 1,
                    Info  = new ShareInfo1Container()
                },
                PreferedMaximumLength = uint.MaxValue,
                ServerName            = "*"
            };

            byte[]     data       = shareEnumRequest.GetBytes();
            RequestPDU requestPdu = new RequestPDU
            {
                Flags = PacketFlags.FirstFragment | PacketFlags.LastFragment,
                DataRepresentation =
                {
                    CharacterFormat             = CharacterFormat.ASCII,
                    ByteOrder                   = ByteOrder.LittleEndian,
                    FloatingPointRepresentation = FloatingPointRepresentation.IEEE
                },
                OpNum          = (ushort)ServerServiceOpName.NetrShareEnum,
                Data           = data,
                AllocationHint = (uint)data.Length
            };

            byte[] input = requestPdu.GetBytes();
            namedPipeShare.DeviceIOControl(pipeHandle, (uint)IoControlCode.FSCTL_PIPE_TRANSCEIVE, input, out byte[]? output, maxTransmitFragmentSize);

            if (!(RPCPDU.GetPDU(output, 0) is ResponsePDU responsePdu))
            {
                throw new NtStatusException(NTStatus.STATUS_NOT_SUPPORTED);
            }

            byte[] responseData = responsePdu.Data;
            while ((responsePdu.Flags & PacketFlags.LastFragment) == 0)
            {
                namedPipeShare.ReadFile(out output, pipeHandle, 0, maxTransmitFragmentSize);

                if (!(RPCPDU.GetPDU(output, 0) is ResponsePDU responsePdu2))
                {
                    throw new NtStatusException(NTStatus.STATUS_NOT_SUPPORTED);
                }
                responseData = ByteUtils.Concatenate(responseData, responsePdu2.Data);
            }
            namedPipeShare.CloseFile(pipeHandle);
            NetrShareEnumResponse shareEnumResponse = new NetrShareEnumResponse(responseData);

            if (shareEnumResponse.InfoStruct.Info is ShareInfo1Container shareInfo1 && shareInfo1.Entries != null)
            {
                return((from entry in shareInfo1.Entries where !shareType.HasValue || shareType.Value == entry.ShareType.ShareType select entry.NetName.Value).ToList());
            }

            throw new NtStatusException(shareEnumResponse.Result == Win32Error.ERROR_ACCESS_DENIED ? NTStatus.STATUS_ACCESS_DENIED : NTStatus.STATUS_NOT_SUPPORTED);
        }
Esempio n. 2
0
        public static FileNetworkOpenInformation?GetNetworkOpenInformation(INtFileStore fileStore, string path, SecurityContext securityContext)
        {
            fileStore.CreateFile(out NtHandle handle, out _, path, (AccessMask)FileAccessMask.FILE_READ_ATTRIBUTES, 0, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, 0, securityContext);

            fileStore.GetFileInformation(out FileInformation? fileInfo, handle, FileInformationClass.FileNetworkOpenInformation);
            fileStore.CloseFile(handle);
            return((FileNetworkOpenInformation?)fileInfo);
        }
Esempio n. 3
0
        public void TestCancel()
        {
            m_fileStore.CreateFile(out NtHandle handle, out FileStatus fileStatus, TestDirName, AccessMask.GENERIC_ALL, FileAttributes.Directory, ShareAccess.Read, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);

            m_fileStore.NotifyChange(out object ioRequest, handle, NotifyChangeFilter.FileName | NotifyChangeFilter.LastWrite | NotifyChangeFilter.DirName, false, 8192, OnNotifyChangeCompleted, null);
            //Assert.True(status == NTStatus.STATUS_PENDING);

            Thread.Sleep(1);
            m_fileStore.Cancel(ioRequest);
            m_fileStore.CloseFile(handle);
            while (m_notifyChangeStatus == null)
            {
                Thread.Sleep(1);
            }
            Assert.True(m_notifyChangeStatus.Value == NTStatus.STATUS_CANCELLED);
        }
Esempio n. 4
0
 public NTFileStoreTests(INtFileStore fileStore)
 {
     m_fileStore = fileStore;
     m_fileStore.CreateFile(out NtHandle handle, out _, TestDirName, AccessMask.GENERIC_ALL, FileAttributes.Directory, ShareAccess.Read, CreateDisposition.FILE_OPEN_IF, CreateOptions.FILE_DIRECTORY_FILE, null);
     m_fileStore.CloseFile(handle);
 }