helpers

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAccountInGroup

func AddAccountInGroup(groupName string, account string, membershipType string) (err error)

AddAccountInGroup adds an account in a group's membership group

func AddGroup

func AddGroup(groupname string, ownerAccount string) (err error)

AddGroup creates a new group on the system

func AddUser

func AddUser(homedir, username, shellPath string) (err error)

AddUser creates a new user on the system

func ArchiveHomeSkelleton

func ArchiveHomeSkelleton(homedir, suffix string) (err error)

ArchiveHomeSkelleton moves user home to home.bak

func BcryptPbkdfKey

func BcryptPbkdfKey(password, salt []byte, rounds, keyLen int) ([]byte, error)

Bcrypt_pbkdfKey derives a key from the password, salt and rounds count, returning a []byte of length keyLen that can be used as cryptographic key.

func ChmodFile

func ChmodFile(filePath, owner, permissions string) (err error)

func CreateHomeSkeleton

func CreateHomeSkeleton(homedir string, username string, homeType string) (err error)

CreateHomeSkeleton creates user home

func DecryptFile

func DecryptFile(filepathIn, filepathOut, decryptionKey string) (err error)

func DeleteAccount

func DeleteAccount(username, archiveSuffix string) (err error)

DeleteAccount deletes a group from the system

func DeleteGroup

func DeleteGroup(groupname, archiveSuffix string) (err error)

DeleteGroup deletes a group from the system

func EncryptFile

func EncryptFile(filepathIn, filepathOut, replicationEncryptionKey string) (err error)

func FillUserAuthorizedKeysFile

func FillUserAuthorizedKeysFile(sshdir string, username string, pk string) (err error)

FillUserAuthorizedKeysFile creates the .ssh directory, put the public key in the authorized_keys file and chmods everything

func GenerateNewEgressGroupKey

func GenerateNewEgressGroupKey(algo string, size string, passphrase string, groupname string) (privateKey, publicKey, privateKeyFilePath, publicKeyFilePath, filesOwner string, err error)

func GenerateNewEgressKey

func GenerateNewEgressKey(algo string, size string, passphrase string, username string) (privateKey, publicKey, privateKeyFilePath, publicKeyFilePath, filesOwner string, err error)

func GetEtcGroupFilePath

func GetEtcGroupFilePath() string

GetEtcGroupFilePath returns /etc/group or an other specifically set filepath

func GetEtcPasswdFilePath

func GetEtcPasswdFilePath() string

GetEtcPasswdFilePath returns /etc/passwd or an other specifically set filepath

func GetGroupSudoersTemplateOwners

func GetGroupSudoersTemplateOwners(binaryPath, sbUser string) (str string)

func GetHostname

func GetHostname() (hostname string, err error)

func GetRandomStrings

func GetRandomStrings(quantity int, length int) (rdm []string)

GetRandomStrings returns x random strings of y characters

func GetScpScript

func GetScpScript(user, host, port string) (str string)

GetScpScript returns the user's SCP script

func GetSystemGroups

func GetSystemGroups() (groups [][]string, err error)

GetSystemGroups returns the content of /etc/group

func GetSystemUsers

func GetSystemUsers() (groups [][]string, err error)

GetSystemGroups returns the content of /etc/passwd

func GetSystemdServiceFile

func GetSystemdServiceFile(binaryPath, sbHomeDirectory string) (str string)

func GetTOTPFile

func GetTOTPFile(secret string, emergencyCodes []string) (str string)

GetTOTPFile returns the user's TOTP file

func MarshalPrivateKey

func MarshalPrivateKey(key crypto.PrivateKey, comment string) (*pem.Block, error)

MarshalPrivateKey returns a PEM block with the private key serialized in the OpenSSH format.

func MarshalPrivateKeyWithPassphrase

func MarshalPrivateKeyWithPassphrase(key crypto.PrivateKey, comment string, passphrase []byte) (*pem.Block, error)

MarshalPrivateKeyWithPassphrase returns an encrypted PEM block with the private key serialized in the OpenSSH format.

func ParseArguments

func ParseArguments(clArgs []string) (c string, ca []string, ba map[string]bool, rest []string, err error)

ParseArguments parses the os.Args arguments

func ParseArgumentsNew

func ParseArgumentsNew(clArgs []string) (c string, ca []string, rest []string, err error)

ParseArguments parses the os.Args arguments

func ParseCommandLine

func ParseCommandLine(cmd string) ([]string, error)

ParseCommandLine parses the string passed to us by SSH to an array of args

func RegroupCommandArguments

func RegroupCommandArguments(clArgs []string) (args []string)

func RemoveAccountFromGroup

func RemoveAccountFromGroup(groupName string, account string, membershipType string) (err error)

RemoveAccountFromGroup adds an account in a group's membership group

func RemoveHostKey

func RemoveHostKey(username, knownHostsFilePath, hostkey string) (err error)

func SetEtcGroupFilePath

func SetEtcGroupFilePath(path string)

SetEtcGroupFilePath sets a specific filepath to oveerride /etc/group (mainly for tests purposes)

func SetEtcPasswdFilePath

func SetEtcPasswdFilePath(path string)

SetEtcPasswdFilePath sets a specific filepath to oveerride /etc/passwd (mainly for tests purposes)

func WriteGroupPrivateKey

func WriteGroupPrivateKey(privateKey, privateKeyFile, owner string) (err error)

func WritePrivateKey

func WritePrivateKey(privateKey, privateKeyFile, owner string) (err error)

func WritePublicKey

func WritePublicKey(publicKey, publicKeyFile, owner string) (err error)

func WriteSelfPrivateKey

func WriteSelfPrivateKey(privateKey, privateKeyFile, owner string) (err error)

func WriteSelfPublicKey

func WriteSelfPublicKey(publicKey, publicKeyFile, owner string) (err error)

Types

type Helper

type Helper struct {
	Header      string
	Usage       string
	Description string
	Aliases     []string
}

Helper describes the basic properties of a sb Helper type

type PublicKey

type PublicKey struct {
	PublicKey ssh.PublicKey
	Comment   string
	Options   []string
	Rest      []byte
}

PublicKey describes the basic properties of a sb PublicKey type

func CheckStringPK

func CheckStringPK(arg string, keys []PublicKey) (pk *PublicKey, err error)

CheckStringPK checks if the provided public key is valid and not already present in the optional keys slice

func (*PublicKey) Equals

func (k *PublicKey) Equals(key ssh.PublicKey) bool

Equals returns true if the helpers.PublicKey matches the ssh.PublicKey

func (*PublicKey) String

func (k *PublicKey) String() string

type SSHDConfigParser

type SSHDConfigParser struct {
	// contains filtered or unexported fields
}

func ParseSSHDConfig

func ParseSSHDConfig(content io.Reader) (p *SSHDConfigParser, err error)

func ParseSSHDConfigFile

func ParseSSHDConfigFile(path string) (p *SSHDConfigParser, err error)

func (*SSHDConfigParser) Dump

func (p *SSHDConfigParser) Dump() (content string)

func (*SSHDConfigParser) GetParam

func (p *SSHDConfigParser) GetParam(key string) (value string)

func (*SSHDConfigParser) SetParam

func (p *SSHDConfigParser) SetParam(key, value string)

func (*SSHDConfigParser) WriteToFile

func (p *SSHDConfigParser) WriteToFile(path string) (err error)

type SSHKeyPair

type SSHKeyPair struct {
	PublicKey          *PublicKey
	PrivateKeyFilepath string
}

SSHKeyPair describes an SSH key pair

type SSHSession

type SSHSession struct {
	UniqID    string
	StartDate time.Time
	EndDate   time.Time
	UserFrom  string
	IPFrom    string
	PortFrom  string
	HostFrom  string
	HostTo    string
	PortTo    string
	UserTo    string
	Allowed   bool
}

SSHSession represents an SSH session

func (*SSHSession) String

func (s *SSHSession) String() (str string)

Jump to

Keyboard shortcuts

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