internal static SMB1Command GetQueryInformationResponse(SMB1Header header, QueryInformationRequest request, ISMBShare share, SMB1ConnectionState state)
        {
            SMB1Session session = state.GetSession(header.UID);
            string      path    = request.FileName;

            if (!path.StartsWith(@"\"))
            {
                path = @"\" + path;
            }

            if (share is FileSystemShare)
            {
                if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, path))
                {
                    state.LogToServer(Severity.Verbose, "Query Information on '{0}{1}' failed. User '{2}' was denied access.", share.Name, path, session.UserName);
                    header.Status = NTStatus.STATUS_ACCESS_DENIED;
                    return(new ErrorResponse(request.CommandName));
                }
            }

            FileNetworkOpenInformation fileInfo;

            header.Status = SMB1FileStoreHelper.QueryInformation(out fileInfo, share.FileStore, path, session.SecurityContext);
            if (header.Status != NTStatus.STATUS_SUCCESS)
            {
                return(new ErrorResponse(request.CommandName));
            }

            QueryInformationResponse response = new QueryInformationResponse();

            response.FileAttributes = SMB1FileStoreHelper.GetFileAttributes(fileInfo.FileAttributes);
            response.LastWriteTime  = fileInfo.LastWriteTime;
            response.FileSize       = (uint)Math.Min(UInt32.MaxValue, fileInfo.EndOfFile);
            return(response);
        }
Exemple #2
0
        private static OpenAndXResponse CreateResponseFromFileInfo(FileNetworkOpenInformation fileInfo, ushort fileID, OpenResult openResult)
        {
            OpenAndXResponse response = new OpenAndXResponse();

            response.FID                    = fileID;
            response.FileAttrs              = SMB1FileStoreHelper.GetFileAttributes(fileInfo.FileAttributes);
            response.LastWriteTime          = fileInfo.LastWriteTime;
            response.FileDataSize           = (uint)Math.Min(UInt32.MaxValue, fileInfo.EndOfFile);
            response.AccessRights           = AccessRights.SMB_DA_ACCESS_READ;
            response.ResourceType           = ResourceType.FileTypeDisk;
            response.OpenResults.OpenResult = openResult;
            return(response);
        }
Exemple #3
0
        private static OpenAndXResponseExtended CreateResponseExtendedFromFileInfo(FileNetworkOpenInformation fileInfo, ushort fileID, OpenResult openResult)
        {
            OpenAndXResponseExtended response = new OpenAndXResponseExtended();

            response.FID                    = fileID;
            response.FileAttrs              = SMB1FileStoreHelper.GetFileAttributes(fileInfo.FileAttributes);
            response.LastWriteTime          = fileInfo.LastWriteTime;
            response.FileDataSize           = (uint)Math.Min(UInt32.MaxValue, fileInfo.EndOfFile);
            response.AccessRights           = AccessRights.SMB_DA_ACCESS_READ;
            response.ResourceType           = ResourceType.FileTypeDisk;
            response.OpenResults.OpenResult = openResult;
            response.MaximalAccessRights    = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA | FileAccessMask.FILE_APPEND_DATA |
                                                           FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
                                                           FileAccessMask.FILE_EXECUTE |
                                                           FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
                                              AccessMask.DELETE | AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.WRITE_OWNER | AccessMask.SYNCHRONIZE;
            response.GuestMaximalAccessRights = (AccessMask)(FileAccessMask.FILE_READ_DATA | FileAccessMask.FILE_WRITE_DATA |
                                                             FileAccessMask.FILE_READ_EA | FileAccessMask.FILE_WRITE_EA |
                                                             FileAccessMask.FILE_READ_ATTRIBUTES | FileAccessMask.FILE_WRITE_ATTRIBUTES) |
                                                AccessMask.READ_CONTROL | AccessMask.SYNCHRONIZE;
            return(response);
        }