Skip to content

Commit

Permalink
Merge pull request #207 from sonroyaalmerol/server-nfs
Browse files Browse the repository at this point in the history
add syslogs
  • Loading branch information
sonroyaalmerol authored Feb 25, 2025
2 parents ff1b57f + ceaaf82 commit bf9c209
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/agent/vssfs/vssfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

securejoin "github.com/cyphar/filepath-securejoin"
"github.com/sonroyaalmerol/pbs-plus/internal/arpc"
"github.com/sonroyaalmerol/pbs-plus/internal/syslog"
"github.com/sonroyaalmerol/pbs-plus/internal/utils"
"golang.org/x/sys/windows"
)
Expand Down Expand Up @@ -78,6 +79,7 @@ func (s *VSSFSServer) handleFsStat(_ arpc.Request) (arpc.Response, error) {
nil,
)
if err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}

Expand All @@ -100,6 +102,7 @@ func (s *VSSFSServer) handleOpenFile(req arpc.Request) (arpc.Response, error) {
Perm int `json:"perm"`
}
if err := json.Unmarshal(req.Payload, &params); err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 400, Message: "invalid request"}, nil
}

Expand All @@ -110,10 +113,12 @@ func (s *VSSFSServer) handleOpenFile(req arpc.Request) (arpc.Response, error) {

fullPath, err := securejoin.SecureJoin(s.rootDir, filepath.Clean(params.Path))
if err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}
pathPtr, err := windows.UTF16PtrFromString(fullPath)
if err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}

Expand Down Expand Up @@ -164,22 +169,26 @@ func (s *VSSFSServer) handleStat(req arpc.Request) (arpc.Response, error) {
Path string `json:"path"`
}
if err := json.Unmarshal(req.Payload, &params); err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 400, Message: "invalid request"}, nil
}

fullPath, err := securejoin.SecureJoin(s.rootDir, filepath.Clean(params.Path))
if err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}

pathPtr, err := windows.UTF16PtrFromString(fullPath)
if err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}

var fileInfo windows.Win32FileAttributeData
err = windows.GetFileAttributesEx(pathPtr, windows.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&fileInfo)))
if err != nil {
syslog.L.Error(err.Error())
return s.mapWindowsErrorToResponse(err), nil
}

Expand All @@ -194,24 +203,28 @@ func (s *VSSFSServer) handleReadDir(req arpc.Request) (arpc.Response, error) {
Path string `json:"path"`
}
if err := json.Unmarshal(req.Payload, &params); err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 400, Message: "invalid request"}, nil
}

fullPath, err := securejoin.SecureJoin(s.rootDir, filepath.Clean(params.Path))
if err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}

pattern := filepath.Join(fullPath, "*")

patternPtr, err := windows.UTF16PtrFromString(pattern)
if err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}

var findData windows.Win32finddata
handle, err := windows.FindFirstFile(patternPtr, &findData)
if err != nil {
syslog.L.Error(err.Error())
return s.mapWindowsErrorToResponse(err), nil
}
defer windows.FindClose(handle)
Expand All @@ -231,6 +244,7 @@ func (s *VSSFSServer) handleReadDir(req arpc.Request) (arpc.Response, error) {
if err == windows.ERROR_NO_MORE_FILES {
break // No more files
}
syslog.L.Error(err.Error())
return s.mapWindowsErrorToResponse(err), nil
}
}
Expand All @@ -247,6 +261,7 @@ func (s *VSSFSServer) handleRead(req arpc.Request) (arpc.Response, error) {
Length int `json:"length"`
}
if err := json.Unmarshal(req.Payload, &params); err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 400, Message: "invalid request"}, nil
}

Expand All @@ -270,6 +285,7 @@ func (s *VSSFSServer) handleRead(req arpc.Request) (arpc.Response, error) {

if err != nil {
if err != windows.ERROR_HANDLE_EOF {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}
isEOF = true
Expand All @@ -291,6 +307,7 @@ func (s *VSSFSServer) handleReadAt(req arpc.Request) (arpc.Response, error) {
Length int `json:"length"`
}
if err := json.Unmarshal(req.Payload, &params); err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 400, Message: "invalid request"}, nil
}

Expand Down Expand Up @@ -318,6 +335,7 @@ func (s *VSSFSServer) handleReadAt(req arpc.Request) (arpc.Response, error) {

if err != nil {
if err != windows.ERROR_HANDLE_EOF {
syslog.L.Error(err.Error())
return arpc.Response{Status: 500, Message: err.Error()}, nil
}
isEOF = true
Expand All @@ -337,6 +355,7 @@ func (s *VSSFSServer) handleClose(req arpc.Request) (arpc.Response, error) {
HandleID uint64 `json:"handleID"`
}
if err := json.Unmarshal(req.Payload, &params); err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 400, Message: "invalid request"}, nil
}

Expand Down Expand Up @@ -364,6 +383,7 @@ func (s *VSSFSServer) handleFstat(req arpc.Request) (arpc.Response, error) {
HandleID uint64 `json:"handleID"`
}
if err := json.Unmarshal(req.Payload, &params); err != nil {
syslog.L.Error(err.Error())
return arpc.Response{Status: 400, Message: "invalid request"}, nil
}

Expand All @@ -377,6 +397,7 @@ func (s *VSSFSServer) handleFstat(req arpc.Request) (arpc.Response, error) {

var fileInfo windows.ByHandleFileInformation
if err := windows.GetFileInformationByHandle(handle.handle, &fileInfo); err != nil {
syslog.L.Error(err.Error())
return s.mapWindowsErrorToResponse(err), nil
}

Expand Down

0 comments on commit bf9c209

Please sign in to comment.