unix_util

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswordWithHashedPassword

func ComparePasswordWithHashedPassword(candidatePassword string, hashedPassword string) (bool, error)

* Compares the provided password with the one stored in the shadow passwords table (generally /etc/shadow)

func Crypt

func Crypt(clearPassword, setting string) (string, error)

* Wrapper around libc's crypt function * Similarly to the original function, the setting string * can also be a fully hashed password, crypt() will only * look at the three first components.

func GetEGid

func GetEGid() int32

func GetEUid

func GetEUid() int32

func GetGid

func GetGid() int32

func GetUid

func GetUid() int32

func NewUnixSocketPath

func NewUnixSocketPath() (string, error)

func PasswordAuthAvailable

func PasswordAuthAvailable() bool

func StartWithAttrsAndPty

func StartWithAttrsAndPty(c *exec.Cmd, sz *ptylib.Winsize, attrs *syscall.SysProcAttr, pty *os.File, tty *os.File) error

copied and adapted from github.com/creack/pty StartWithAttrs assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, and c.Stderr, calls c.Start, and returns the File of the tty's corresponding pty.

This will resize the pty to the specified size before starting the command if a size is provided. The `attrs` parameter overrides the one set in c.SysProcAttr.

This should generally not be needed. Used in some edge cases where it is needed to create a pty without a controlling terminal.

func StartWithSizeAndPty

func StartWithSizeAndPty(cmd *exec.Cmd, ws *ptylib.Winsize, pty *os.File, tty *os.File) error

adapted from github.com/creack/pty StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, and c.Stderr, calls c.Start, and returns the File of the tty's corresponding pty.

This will resize the pty to the specified size before starting the command. Starts the process in a new session and sets the controlling terminal.

func UserPasswordAuthentication

func UserPasswordAuthentication(username, password string) (bool, error)

* Returns a boolean stating whether the user is correctly authenticated on this * server. May return a UserNotFound error when the user does not exist.

Types

type ShadowEntry

type ShadowEntry struct {
	Username string
	Password string
}

func Getspnam

func Getspnam(name string) (*ShadowEntry, error)

* Wrapper around libshadow's getspnam function * copied from https://stackoverflow.com/questions/38790092/call-a-c-function-from-go

type User

type User struct {
	Username string
	Uid      uint64
	Gid      uint64
	Dir      string
	Shell    string
}

func GetUser

func GetUser(username string) (*User, error)

func (*User) CreateCommand

func (u *User) CreateCommand(addEnv string, stdout, stderr io.Writer, stdin io.Reader, loginShell bool, command string, args ...string) (*exec.Cmd, io.Reader, io.Reader, io.Writer, error)

func (*User) CreateCommandPipeOutput

func (u *User) CreateCommandPipeOutput(addEnv string, loginShell bool, command string, args ...string) (*exec.Cmd, io.Reader, io.Reader, io.Writer, error)

Jump to

Keyboard shortcuts

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