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); }
internal static SMBCommand GetQueryInformationResponse(SMBHeader header, QueryInformationRequest request, FileSystemShare share) { IFileSystem fileSystem = share.FileSystem; FileSystemEntry entry = fileSystem.GetEntry(request.FileName); if (entry == null) { header.Status = NTStatus.STATUS_OBJECT_PATH_INVALID; return(new ErrorResponse(CommandName.SMB_COM_QUERY_INFORMATION)); } QueryInformationResponse response = new QueryInformationResponse(); response.FileAttributes = InfoHelper.GetFileAttributes(entry); response.LastWriteTime = entry.LastWriteTime; response.FileSize = (uint)Math.Min(UInt32.MaxValue, entry.Size); return(response); }