all repos — flounder @ cf1bc7f98c8988285623ff592f6ee14861c12afd

A small site builder for the Gemini protocol

Add remove command
alex wennerberg alex@alexwennerberg.com
Fri, 26 Feb 2021 21:30:51 -0800
commit

cf1bc7f98c8988285623ff592f6ee14861c12afd

parent

521d6b600460a4d4ebb271b50e003c9d9d8218b5

1 files changed, 12 insertions(+), 1 deletions(-)

jump to
M sftp.gosftp.go

@@ -74,8 +74,19 @@ }

return nil, fmt.Errorf("Invalid command") } -func (c *Connection) Filecmd(request *sftp.Request) error { +func (conn *Connection) Filecmd(request *sftp.Request) error { // remove, rename, setstat? find out + fullpath := path.Join(c.FilesDirectory, filepath.Clean(request.Filepath)) + userDir := getUserDirectory(conn.User) // NOTE -- not cross platform + writePerms := strings.HasPrefix(fullpath, userDir) + switch request.Method { + case "Remove": + if writePerms { + os.Remove(fullpath) + } else { + return fmt.Errorf("Unauthorized") + } + } return nil }