Mercurial > go > multipass
comparison cmds/multipass-checkpassword/checkpassword.go @ 17:342f63116bfd
Move commands to canonical Go locations, so go install works.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Fri, 30 Oct 2015 00:18:13 -0400 |
| parents | multipass-checkpassword.go@4db389f948c9 |
| children |
comparison
equal
deleted
inserted
replaced
| 16:bfc035bd5132 | 17:342f63116bfd |
|---|---|
| 1 package main | |
| 2 | |
| 3 import ( | |
| 4 "bufio" | |
| 5 "os" | |
| 6 "os/user" | |
| 7 "syscall" | |
| 8 | |
| 9 "pfish.zone/go/multipass/file" | |
| 10 ) | |
| 11 | |
| 12 const ( | |
| 13 InternalError = 111 | |
| 14 Failed = 1 | |
| 15 ) | |
| 16 | |
| 17 func main() { | |
| 18 infile := os.NewFile(3, "") | |
| 19 reader := bufio.NewReader(infile) | |
| 20 username, err := reader.ReadString(0) | |
| 21 if err != nil { | |
| 22 os.Exit(InternalError) | |
| 23 } | |
| 24 username = username[:len(username)-1] | |
| 25 pass, err := reader.ReadString(0) | |
| 26 if err != nil { | |
| 27 os.Exit(InternalError) | |
| 28 } | |
| 29 pass = pass[:len(pass)-1] | |
| 30 infile.Close() | |
| 31 passfile, err := file.ForUser(username) | |
| 32 if err != nil { | |
| 33 os.Exit(Failed) | |
| 34 } | |
| 35 success, _ := passfile.Authenticate(pass) | |
| 36 if !success { | |
| 37 os.Exit(Failed) | |
| 38 } | |
| 39 user, err := user.Lookup(username) | |
| 40 if err != nil { | |
| 41 os.Exit(Failed) | |
| 42 } | |
| 43 os.Setenv("USER", user.Username) | |
| 44 os.Setenv("HOME", user.HomeDir) | |
| 45 os.Setenv("userdb_uid", user.Uid) | |
| 46 os.Setenv("userdb_gid", user.Gid) | |
| 47 os.Setenv("EXTRA", "userdb_uid userdb_gid") | |
| 48 syscall.Exec(os.Args[1], os.Args[1:], os.Environ()) | |
| 49 } |
