summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/hackers.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/nshd/hackers_git/hackers.go')
-rw-r--r--src/nshd/hackers_git/hackers.go50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/nshd/hackers_git/hackers.go b/src/nshd/hackers_git/hackers.go
index 2e9edc1..b72698f 100644
--- a/src/nshd/hackers_git/hackers.go
+++ b/src/nshd/hackers_git/hackers.go
@@ -24,11 +24,11 @@
package hackers_git
import (
- "lukeshu.com/git/go/libgnulinux.git/inotify"
"lukeshu.com/git/go/libnslcd.git/proto"
"lukeshu.com/git/go/libnslcd.git/proto/server"
"lukeshu.com/git/go/libnslcd.git/systemd"
"lukeshu.com/git/go/libsystemd.git/sd_daemon/logger"
+ "path/filepath"
"sync"
)
@@ -44,18 +44,11 @@ type Config struct {
type Hackers struct {
nslcd_server.NilBackend
- Cfg Config
- lock sync.RWMutex
- workers sync.WaitGroup
+ Cfg Config
+ lock sync.RWMutex
users map[int32]user
groups map[string]map[string]bool
-
- in_fd *inotify.Watcher
- in_wd_home inotify.Wd
- in_wd_yaml inotify.Wd
- in_uid2wd map[int32]inotify.Wd
- in_wd2uid map[inotify.Wd]int32
}
var _ nslcd_systemd.Backend = &Hackers{}
@@ -74,7 +67,9 @@ func (o *Hackers) Close() {
logger.Info("hackers.git: Closing session")
o.lock.Lock()
defer o.lock.Unlock()
- o.close()
+
+ o.users = make(map[int32]user, 0)
+ o.groups = make(map[string]map[string]bool)
}
func (o *Hackers) Reload() error {
@@ -82,7 +77,29 @@ func (o *Hackers) Reload() error {
o.lock.Lock()
defer o.lock.Unlock()
- return o.reload()
+ filenames, err := filepath.Glob(o.Cfg.Yamldir + "/*.yml")
+ if err != nil {
+ return err
+ }
+ o.users = make(map[int32]user, len(filenames))
+ o.groups = make(map[string]map[string]bool)
+ for _, filename := range filenames {
+ logger.Debug("hackers.git: Loading YAML file: %s", filename)
+
+ user, err := parse_user_yaml(filename)
+ if err != nil {
+ logger.Warning("hackers.git: -> File ignored: %v", err)
+ continue
+ }
+ for _, groupname := range user.groups {
+ o.add_user_to_group(user.passwd.Name, groupname)
+ }
+ user.passwd.PwHash = parse_user_password(user.passwd.HomeDir + "/.password")
+ o.users[user.passwd.UID] = user
+ logger.Debug("hackers.git: -> User %d(%s) added", user.passwd.UID, user.passwd.Name)
+ }
+
+ return nil
}
func (o *Hackers) name2uid(name string) int32 {
@@ -93,3 +110,12 @@ func (o *Hackers) name2uid(name string) int32 {
}
return -1
}
+
+func (o *Hackers) add_user_to_group(username string, groupname string) {
+ group, found := o.groups[groupname]
+ if !found {
+ group = make(map[string]bool)
+ o.groups[groupname] = group
+ }
+ group[username] = true
+}