Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ const (
IPMatchDisabled
)

// SiteHandler defines how a SITE command works
type SiteHandler = func(string, MainDriver, ClientDriver) (int, string)

// Settings defines all the server settings
//
//nolint:maligned
Expand All @@ -265,7 +268,9 @@ type Settings struct {
DisableSTAT bool // Disable Server STATUS, STAT on files and directories will still work
DisableSYST bool // Disable SYST
EnableCOMB bool // Enable COMB support
DefaultTransferType TransferType // Transfer type to use if the client don't send the TYPE command
DefaultTransferType TransferType // Transfer type to use if the client don't send the TYPE
// SiteHandlers defines custom SITE command handlers (Optional)
SiteHandlers map[string]SiteHandler
// ActiveConnectionsCheck defines the security requirements for active connections
ActiveConnectionsCheck DataConnectionRequirement
// PasvConnectionsCheck defines the security requirements for passive connections
Expand Down
36 changes: 23 additions & 13 deletions handle_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,29 @@ func (c *clientHandler) handleSITE(param string) error {
params = ""
}

switch cmd {
case "CHMOD":
c.handleCHMOD(params)
case "CHOWN":
c.handleCHOWN(params)
case "SYMLINK":
c.handleSYMLINK(params)
case "MKDIR":
c.handleMKDIR(params)
case "RMDIR":
c.handleRMDIR(params)
default:
c.writeMessage(StatusSyntaxErrorNotRecognised, "Unknown SITE subcommand: "+cmd)
var handler SiteHandler
handlerMap := c.server.settings.SiteHandlers
if handlerMap != nil {
handler, _ = handlerMap[cmd]
}
if handler == nil {
switch cmd {
case "CHMOD":
c.handleCHMOD(params)
case "CHOWN":
c.handleCHOWN(params)
case "SYMLINK":
c.handleSYMLINK(params)
case "MKDIR":
c.handleMKDIR(params)
case "RMDIR":
c.handleRMDIR(params)
default:
c.writeMessage(StatusSyntaxErrorNotRecognised, "Unknown SITE subcommand: "+cmd)
}
} else {
errCode, msg := handler(params, c.server.driver, c.driver)
c.writeMessage(errCode, msg)
}

return nil
Expand Down