msg_file_close.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package smb
  2. func init() {
  3. commandRequestMap[CommandClose] = func() DataI {
  4. return &CloseRequest{}
  5. }
  6. }
  7. //CommandClose
  8. type CloseRequest struct {
  9. Header
  10. StructureSize uint16
  11. Flags uint16
  12. Reserved uint32
  13. FileId GUID
  14. }
  15. const SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB = 0x0001
  16. type CloseResponse struct {
  17. Header
  18. StructureSize uint16
  19. Flags uint16
  20. Reserved uint32
  21. CreationTime uint64
  22. LastAccessTime uint64
  23. LastWriteTime uint64
  24. ChangeTime uint64
  25. AllocationSize uint64
  26. EndofFile uint64
  27. FileAttributes uint32
  28. }
  29. func (data *CloseRequest) ServerAction(ctx *DataCtx) (interface{}, error) {
  30. data.Header.Flags = SMB2_FLAGS_RESPONSE
  31. if data.StructureSize != 24 {
  32. return ERR(data.Header, STATUS_INVALID_PARAMETER)
  33. }
  34. fileid := ctx.FileID(data.FileId)
  35. webfile, ok := ctx.session.openedFiles[fileid]
  36. if !ok {
  37. return ERR(data.Header, STATUS_FILE_CLOSED)
  38. }
  39. data.Header.Status = StatusOk
  40. resp := &CloseResponse{
  41. Header: data.Header,
  42. StructureSize: 0x003c,
  43. }
  44. if data.Flags&SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB == SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB {
  45. fi, err := webfile.Stat()
  46. if err == nil {
  47. mtime := timeToFiletime(fi.ModTime())
  48. resp.CreationTime = mtime
  49. resp.LastWriteTime = mtime
  50. resp.ChangeTime = mtime
  51. resp.LastAccessTime = 0 // timeToFiletime(statAccessTime(fi))
  52. resp.Flags = 1
  53. }
  54. }
  55. delete(ctx.session.openedFiles, fileid)
  56. if webfile != nil {
  57. webfile.Close()
  58. }
  59. if ctx.closeAction != nil {
  60. ctx.closeAction()
  61. ctx.closeAction = nil
  62. }
  63. ctx.latestFileId = NilGUID
  64. return resp, nil
  65. }