Mercurial > go > multipass
view multipass-checkpassword.go @ 2:a4fa4f28b472
Actually shave off last character of password description.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 24 Oct 2015 22:34:07 -0400 |
parents | faf4aad86fc9 |
children | ec4ded022025 |
line wrap: on
line source
package main import ( "bufio" "fmt" "os" "os/user" "syscall" "pfish.zone/go/multipass/file" ) const ( InternalError = 111 Failed = 1 ) func main() { infile = os.NewFile(3, "") reader := bufio.NewReader(os.Stdin) username, err := reader.ReadString('\n') if err != nil { os.Exit(InternalError) } username = username[:len(username)-1] pass, err := reader.ReadString('\n') if err != nil { os.Exit(InternalError) } pass = pass[:len(pass)-1] infile.Close() passfile, err := file.ForUser(username) if err != nil { os.Exit(Failed) } success, _ := passfile.Authenticate(pass) if !success { os.Exit(Failed) } user, err := user.Lookup(username) if err != nil { os.Exit(Failed) } os.Setenv("userdb_uid", user.Uid) os.Setenv("userdb_gid", user.Gid) os.Setenv("EXTRA", "userdb_uid userdb_gid") environ := []string{ "USER=" + user.Username "userdb_uid=" + user.Uid, "userdb_gid=" + user.Gid, "HOME=" + user.HomeDir, "EXTRA=userdb_uid userdb_gid", } syscall.Exec(os.Args[1], os.Args[1:], environ) }