comparison mp-checkpassword/checkpassword.go @ 19:58fe867c9ecf

Reorganize commands to more standard go layout. - Unify multipass user commands under one 'multipass' binary - Move multipass checkpassword command to mp-checkpassword.
author Paul Fisher <paul@pfish.zone>
date Sun, 01 Nov 2015 12:42:02 -0500
parents cmds/multipass-checkpassword/checkpassword.go@342f63116bfd
children
comparison
equal deleted inserted replaced
18:00d30c67b56d 19:58fe867c9ecf
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 }