sftp_server

package module
v1.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 18 Imported by: 0

README

Pterodactyl SFTP Server

This package serves as a SFTP server to run alongside the Pterodactyl Daemon. Previous versions of this software included a standalone mode, however this repository now serves to provide API level access to the Wings Daemon for SFTP access.

License

Copyright (c) 2019 Dane Everitt <dane@daneeveritt.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Index

Constants

View Source
const (
	PermissionFileRead   = "file.read"
	PermissionFileCreate = "file.create"
	PermissionFileUpdate = "file.update"
	PermissionFileDelete = "file.delete"
)
View Source
const (
	// Extends the default SFTP server to return a quota exceeded error to the client.
	//
	// @see https://tools.ietf.org/id/draft-ietf-secsh-filexfer-13.txt
	ErrSshQuotaExceeded = fxerr(15)
)

Variables

This section is empty.

Functions

func IsInvalidCredentialsError

func IsInvalidCredentialsError(err error) bool

func New

func New(c *Server) error

Create a new server configuration instance.

Types

type AuthenticationRequest

type AuthenticationRequest struct {
	User          string `json:"username"`
	Pass          string `json:"password"`
	IP            string `json:"ip"`
	SessionID     []byte `json:"session_id"`
	ClientVersion []byte `json:"client_version"`
}

type AuthenticationResponse

type AuthenticationResponse struct {
	Server      string   `json:"server"`
	Token       string   `json:"token"`
	Permissions []string `json:"permissions"`
}

type FileSystem

type FileSystem struct {
	UUID        string
	Permissions []string
	ReadOnly    bool
	User        SftpUser
	Cache       *cache.Cache

	PathValidator func(fs FileSystem, p string) (string, error)
	HasDiskSpace  func(fs FileSystem) bool
	// contains filtered or unexported fields
}

func (FileSystem) Filecmd

func (fs FileSystem) Filecmd(request *sftp.Request) error

Filecmd hander for basic SFTP system calls related to files, but not anything to do with reading or writing to those files.

func (FileSystem) Filelist

func (fs FileSystem) Filelist(request *sftp.Request) (sftp.ListerAt, error)

Filelist is the handler for SFTP filesystem list calls. This will handle calls to list the contents of a directory as well as perform file/folder stat calls.

func (FileSystem) Fileread

func (fs FileSystem) Fileread(request *sftp.Request) (io.ReaderAt, error)

Fileread creates a reader for a file on the system and returns the reader back.

func (FileSystem) Filewrite

func (fs FileSystem) Filewrite(request *sftp.Request) (io.WriterAt, error)

Filewrite handles the write actions for a file on the system.

type InvalidCredentialsError

type InvalidCredentialsError struct {
}

func (InvalidCredentialsError) Error

func (ice InvalidCredentialsError) Error() string

type ListerAt

type ListerAt []os.FileInfo

func (ListerAt) ListAt

func (l ListerAt) ListAt(f []os.FileInfo, offset int64) (int, error)

Returns the number of entries copied and an io.EOF error if we made it to the end of the file list. Take a look at the pkg/sftp godoc for more information about how this function should work.

type Server

type Server struct {
	Settings Settings
	User     SftpUser

	PathValidator      func(fs FileSystem, p string) (string, error)
	DiskSpaceValidator func(fs FileSystem) bool

	// Validator function that is called when a user connects to the server. This should
	// check against whatever system is desired to confirm if the given username and password
	// combination is valid. If so, should return an authentication response.
	CredentialValidator func(r AuthenticationRequest) (*AuthenticationResponse, error)
	// contains filtered or unexported fields
}

func (Server) AcceptInboundConnection

func (c Server) AcceptInboundConnection(conn net.Conn, config *ssh.ServerConfig)

Handles an inbound connection to the instance and determines if we should serve the request or not.

func (*Server) ConfigureLogger

func (c *Server) ConfigureLogger(cb func() *zap.SugaredLogger)

Allows configuration of a custom logger.

func (*Server) Initialize added in v1.1.5

func (c *Server) Initialize() error

Initialize the SFTP server and add a persistent listener to handle inbound SFTP connections.

type Settings

type Settings struct {
	BasePath    string
	ReadOnly    bool
	BindPort    int
	BindAddress string
}

type SftpUser

type SftpUser struct {
	Uid int
	Gid int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL