예제 #1
0
        public NTStatus GetFileInformation(out FileInformation result, object handle, FileInformationClass informationClass)
        {
            result = null;
            if (m_client.InfoLevelPassthrough)
            {
                int maxOutputLength = 4096;
                Transaction2QueryFileInformationRequest subcommand = new Transaction2QueryFileInformationRequest();
                subcommand.FID = (ushort)handle;
                subcommand.FileInformationClass = informationClass;

                Transaction2Request request = new Transaction2Request();
                request.Setup               = subcommand.GetSetup();
                request.TransParameters     = subcommand.GetParameters(m_client.Unicode);
                request.TransData           = subcommand.GetData(m_client.Unicode);
                request.TotalDataCount      = (ushort)request.TransData.Length;
                request.TotalParameterCount = (ushort)request.TransParameters.Length;
                request.MaxParameterCount   = Transaction2QueryFileInformationResponse.ParametersLength;
                request.MaxDataCount        = (ushort)maxOutputLength;

                TrySendMessage(request);
                SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
                if (reply != null)
                {
                    if (reply.Header.Status == NTStatus.STATUS_SUCCESS && reply.Commands[0] is Transaction2Response)
                    {
                        Transaction2Response response = (Transaction2Response)reply.Commands[0];
                        Transaction2QueryFileInformationResponse subcommandResponse = new Transaction2QueryFileInformationResponse(response.TransParameters, response.TransData, reply.Header.UnicodeFlag);
                        if (informationClass == FileInformationClass.FileAllInformation)
                        {
                            // Windows implementations return SMB_QUERY_FILE_ALL_INFO when a client specifies native NT passthrough level "FileAllInformation".
                            QueryInformation queryFileAllInfo = subcommandResponse.GetQueryInformation(QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO);
                            result = QueryInformationHelper.ToFileInformation(queryFileAllInfo);
                        }
                        else
                        {
                            result = subcommandResponse.GetFileInformation(informationClass);
                        }
                    }
                    return(reply.Header.Status);
                }
                return(NTStatus.STATUS_INVALID_SMB);
            }
            else
            {
                QueryInformationLevel informationLevel = QueryInformationHelper.ToFileInformationLevel(informationClass);
                QueryInformation      queryInformation;
                NTStatus status = GetFileInformation(out queryInformation, handle, informationLevel);
                if (status == NTStatus.STATUS_SUCCESS)
                {
                    result = QueryInformationHelper.ToFileInformation(queryInformation);
                }
                return(status);
            }
        }
예제 #2
0
        public void GetFileInformation(out FileInformation result, NtHandle handle, FileInformationClass informationClass)
        {
            if (m_client.InfoLevelPassthrough)
            {
                int maxOutputLength = 4096;
                Transaction2QueryFileInformationRequest subcommand = new Transaction2QueryFileInformationRequest
                {
                    FID = ((Smb1Handle)handle).FID,
                    FileInformationClass = informationClass
                };

                Transaction2Request request = new Transaction2Request
                {
                    Setup           = subcommand.GetSetup(),
                    TransParameters = subcommand.GetParameters(m_client.Unicode),
                    TransData       = subcommand.GetData(m_client.Unicode)
                };
                request.TotalDataCount      = (ushort)request.TransData.Length;
                request.TotalParameterCount = (ushort)request.TransParameters.Length;
                request.MaxParameterCount   = Transaction2QueryFileInformationResponse.ParametersLength;
                request.MaxDataCount        = (ushort)maxOutputLength;

                TrySendMessage(request);
                SMB1Message reply = m_client.WaitForMessage(CommandName.SMB_COM_TRANSACTION2);
                reply.IsSuccessElseThrow();
                if (!(reply.Commands[0] is Transaction2Response transaction2Response))
                {
                    throw new NtStatusException(reply.Header.Status);
                }

                Transaction2QueryFileInformationResponse subcommandResponse = new Transaction2QueryFileInformationResponse(transaction2Response.TransParameters, transaction2Response.TransData);
                if (informationClass == FileInformationClass.FileAllInformation)
                {
                    // Windows implementations return SMB_QUERY_FILE_ALL_INFO when a client specifies native NT passthrough level "FileAllInformation".
                    QueryInformation queryFileAllInfo = subcommandResponse.GetQueryInformation(QueryInformationLevel.SMB_QUERY_FILE_ALL_INFO);
                    result = QueryInformationHelper.ToFileInformation(queryFileAllInfo);
                }
                else
                {
                    result = subcommandResponse.GetFileInformation(informationClass);
                }
                reply.IsSuccessElseThrow();
                return;
            }

            QueryInformationLevel informationLevel = QueryInformationHelper.ToFileInformationLevel(informationClass);

            GetFileInformation(out QueryInformation? queryInformation, handle, informationLevel);
            result = QueryInformationHelper.ToFileInformation(queryInformation);
        }