summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/hackers.go
blob: 446351d705e350561686a16639dbd1bc1dcd0363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package hackers_git

import (
	"inotify"
	"nslcd_proto"
	"nslcd_proto/util"
	"nslcd_systemd"
	"sd_daemon/logger"
	"sd_daemon/lsb"
	"sync"
)

type user struct {
	passwd nslcd_proto.Passwd
	groups []string
}

type Config struct {
	Pam_password_prohibit_message string
	Yamldir                       string
}

type Hackers struct {
	util.NullBackend
	Cfg     Config
	lock    sync.RWMutex

	users  map[int32]user
	groups map[string]map[string]bool

	in_fd      *inotify.Inotify
	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{}
var _ nslcd_proto.Backend = &Hackers{}

func (o *Hackers) Init() error {
	err := o.Reload()
	if err != nil {
		logger.Err("Could not initialize hackers.git: %v", err)
		return err
	}
	go func() {
		defer lsb.Recover()
		o.worker()
	}()
	return nil
}

func (o *Hackers) Close() {
	logger.Info("Closing hackers.git session")
	o.lock.Lock()
	defer o.lock.Unlock()
	o.close()
}

func (o *Hackers) Reload() error {
	logger.Info("Loading hackers.git session")
	o.lock.Lock()
	defer o.lock.Unlock()

	return o.reload()
}

func (o *Hackers) name2uid(name string) int32 {
	for uid, data := range o.users {
		if data.passwd.Name == name {
			return uid
		}
	}
	return -1
}