summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/hackers.go
blob: 5b57a630b9619c994065f7805c1789cb38f17477 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>.
//
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// The GNU General Public License's references to "object code" and
// "executables" are to be interpreted to also include the output of
// any document formatting or typesetting system, including
// intermediate and printed output.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this manual; if not, see
// <http://www.gnu.org/licenses/>.

// Package hackers_git is an nslcd_server Backend that speaks to
// hackers.git.
package hackers_git

import (
	"inotify"
	"inotify/inutil"
	"nslcd/proto"
	"nslcd/proto/server"
	"nslcd/systemd"
	"sd_daemon/logger"
	"sync"
)

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

type Config struct {
	Pam_password_prohibit_message string
	Yamldir                       string
}

type Hackers struct {
	nslcd_server.NilBackend
	Cfg     Config
	lock    sync.RWMutex
	workers sync.WaitGroup

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

	in_fd      *inutil.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{}
var _ nslcd_server.Backend = &Hackers{}

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

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

func (o *Hackers) Reload() error {
	logger.Info("hackers.git: Loading 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
}