All checks were successful
Test / Create distribution (push) Successful in 34s
Test / Hakurei (push) Successful in 3m13s
Test / Hpkg (push) Successful in 4m5s
Test / Sandbox (race detector) (push) Successful in 4m28s
Test / Hakurei (race detector) (push) Successful in 5m23s
Test / Sandbox (push) Successful in 1m25s
Test / Flake checks (push) Successful in 1m33s
This simulates params to shim and this is the last step before params to shim is merged. Signed-off-by: Ophestra <cat@gensokyo.uk>
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"hakurei.app/container/fhs"
|
|
"hakurei.app/hst"
|
|
)
|
|
|
|
func init() { gob.Register(spAccountOp{}) }
|
|
|
|
// spAccountOp sets up user account emulation inside the container.
|
|
type spAccountOp struct{}
|
|
|
|
func (s spAccountOp) toSystem(state *outcomeStateSys, _ *hst.Config) error {
|
|
const fallbackUsername = "chronos"
|
|
|
|
// do checks here to fail before fork/exec
|
|
if state.Container == nil || state.Container.Home == nil || state.Container.Shell == nil {
|
|
// unreachable
|
|
return syscall.ENOTRECOVERABLE
|
|
}
|
|
if state.Container.Username == "" {
|
|
state.Container.Username = fallbackUsername
|
|
} else if !isValidUsername(state.Container.Username) {
|
|
return newWithMessage(fmt.Sprintf("invalid user name %q", state.Container.Username))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s spAccountOp) toContainer(state *outcomeStateParams) error {
|
|
state.params.Dir = state.Container.Home
|
|
state.env["HOME"] = state.Container.Home.String()
|
|
state.env["USER"] = state.Container.Username
|
|
state.env["SHELL"] = state.Container.Shell.String()
|
|
|
|
state.params.
|
|
Place(fhs.AbsEtc.Append("passwd"),
|
|
[]byte(state.Container.Username+":x:"+
|
|
state.mapuid.String()+":"+
|
|
state.mapgid.String()+
|
|
":Hakurei:"+
|
|
state.Container.Home.String()+":"+
|
|
state.Container.Shell.String()+"\n")).
|
|
Place(fhs.AbsEtc.Append("group"),
|
|
[]byte("hakurei:x:"+state.mapgid.String()+":\n"))
|
|
|
|
return nil
|
|
}
|