diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/multipass-checkpassword.go	Sat Oct 24 21:32:03 2015 -0400
@@ -0,0 +1,50 @@
+package main
+
+import (
+	"bufio"
+	"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)
+	}
+	pass, err := reader.ReadString('\n')
+	if err != nil {
+		os.Exit(InternalError)
+	}
+	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)
+	err = os.Setenv("USER", user.HomeDir)
+	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{
+		"userdb_uid=" + user.Uid,
+		"userdb_gid=" + user.Gid,
+		"EXTRA=userdb_uid userdb_gid",
+	}
+	syscall.Exec(os.Args[1], os.Args[1:], environ)
+}