comparison multipass-checkpassword.go @ 0:c18bc7b9d1d9

Basic binaries. checkpassword doesn't yet work.
author Paul Fisher <paul@pfish.zone>
date Sat, 24 Oct 2015 21:32:03 -0400
parents
children faf4aad86fc9
comparison
equal deleted inserted replaced
-1:000000000000 0:c18bc7b9d1d9
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(os.Stdin)
20 username, err := reader.ReadString('\n')
21 if err != nil {
22 os.Exit(InternalError)
23 }
24 pass, err := reader.ReadString('\n')
25 if err != nil {
26 os.Exit(InternalError)
27 }
28 passfile, err := file.ForUser(username)
29 if err != nil {
30 os.Exit(Failed)
31 }
32 success, _ := passfile.Authenticate(pass)
33 if !success {
34 os.Exit(Failed)
35 }
36 user, err := user.Lookup(username)
37 err = os.Setenv("USER", user.HomeDir)
38 if err != nil {
39 os.Exit(Failed)
40 }
41 os.Setenv("userdb_uid", user.Uid)
42 os.Setenv("userdb_gid", user.Gid)
43 os.Setenv("EXTRA", "userdb_uid userdb_gid")
44 environ := []string{
45 "userdb_uid=" + user.Uid,
46 "userdb_gid=" + user.Gid,
47 "EXTRA=userdb_uid userdb_gid",
48 }
49 syscall.Exec(os.Args[1], os.Args[1:], environ)
50 }