57 lines
1017 B
Go
57 lines
1017 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"database/sql"
|
|
_ "github.com/lib/pq"
|
|
|
|
libpassword "dev.sum7.eu/sum7/warehost/lib/password"
|
|
)
|
|
|
|
var (
|
|
configFile string
|
|
username string
|
|
password string
|
|
execCmd string
|
|
config *Config
|
|
db *sql.DB
|
|
err error
|
|
)
|
|
|
|
func main() {
|
|
configFile = os.Args[1]
|
|
execCmd = os.Args[2]
|
|
|
|
pipe := os.NewFile(uintptr(3), "/dev/fd/3")
|
|
defer pipe.Close()
|
|
in := bufio.NewReader(pipe)
|
|
data, _ := in.ReadBytes(0)
|
|
username = string(data[:len(data)-1])
|
|
data, _ = in.ReadBytes(0)
|
|
password = string(data[:len(data)-1])
|
|
|
|
config = ReadConfigFile(configFile)
|
|
|
|
db, err = sql.Open("postgres", config.Database)
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
defer db.Close()
|
|
|
|
var realPassword string
|
|
err = db.QueryRow("select password from login where mail = $1", username).Scan(&realPassword)
|
|
if err != nil {
|
|
os.Exit(1)
|
|
}
|
|
|
|
output, _ := libpassword.Validate(realPassword, password)
|
|
if output {
|
|
exec.Command("bash", "-c", execCmd).Run()
|
|
} else {
|
|
os.Exit(1)
|
|
}
|
|
}
|