Gregory Rudolph
4 years ago
5 changed files with 93 additions and 1 deletions
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
module github.com/Rudi9719/pgplockd |
||||
|
||||
go 1.16 |
||||
|
||||
require github.com/coreos/go-systemd/v22 v22.1.0 |
@ -0,0 +1,4 @@
@@ -0,0 +1,4 @@
|
||||
github.com/coreos/go-systemd/v22 v22.1.0 h1:kq/SbG2BCKLkDKkjQf5OWwKWUKj1lgs3lFI4PxnR5lg= |
||||
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= |
||||
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME= |
||||
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= |
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io/ioutil" |
||||
"os/user" |
||||
"time" |
||||
|
||||
"github.com/coreos/go-systemd/v22/journal" |
||||
"github.com/coreos/go-systemd/v22/login1" |
||||
) |
||||
|
||||
var ( |
||||
conn login1.Conn |
||||
sess login1.Session |
||||
keyID string |
||||
unlock = false |
||||
) |
||||
|
||||
func main() { |
||||
if !journal.Enabled() { |
||||
return |
||||
} |
||||
journal.Print(journal.PriAlert, "Starting pamlockd") |
||||
setUp() |
||||
go timeOutLoop() |
||||
|
||||
fmt.Printf("%+v\n%+v\n", sess, keyID) |
||||
|
||||
} |
||||
|
||||
func timeOutLoop() { |
||||
//TODO: Implement an actual check for unlock status
|
||||
for { |
||||
time.Sleep(30 * time.Second) |
||||
if !unlock { |
||||
journal.Print(journal.PriInfo, "Timeout reached waiting for unlock. Locking session!") |
||||
conn.LockSession(sess.ID) |
||||
} |
||||
time.Sleep(5 * time.Minute) |
||||
} |
||||
} |
||||
|
||||
func setUp() { |
||||
journal.Print(journal.PriInfo, "Opening new connection to logind.") |
||||
conn, err := login1.New() |
||||
if err != nil { |
||||
journal.Print(journal.PriCrit, "Unable to open login1 connection: %+v\n", err) |
||||
return |
||||
} |
||||
journal.Print(journal.PriInfo, "Getting current user.") |
||||
usr, err := user.Current() |
||||
if err != nil { |
||||
journal.Print(journal.PriCrit, "Unable to determine current user: %+v\n", err) |
||||
return |
||||
} |
||||
|
||||
journal.Print(journal.PriInfo, "Getting current session from Active Sessions.") |
||||
dop, err := conn.GetActiveSession() |
||||
sessions, err := conn.ListSessions() |
||||
for _, v := range sessions { |
||||
if v.Path == dop { |
||||
sess = v |
||||
} |
||||
} |
||||
content, err := ioutil.ReadFile(fmt.Sprintf("%+v/.pgplockd", usr.HomeDir)) |
||||
if err != nil { |
||||
journal.Print(journal.PriCrit, "Unable to read ~/.pgplockd config: %+v\n", err) |
||||
return |
||||
} |
||||
keyID = string(content) |
||||
} |
Binary file not shown.
Loading…
Reference in new issue