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 workers sync.WaitGroup users map[int32]user in_fd *inotify.Inotify in_wd_home inotify.Cint in_wd_yaml inotify.Cint in_uid2wd map[int32]inotify.Cint in_wd2uid map[inotify.Cint]int32 } var _ nslcd_systemd.Backend = &Hackers{} var _ nslcd_proto.Backend = &Hackers{} func NewHackers(config Config) *Hackers { o := Hackers{ cfg: config, } err := o.Reload() if err != nil { logger.Err("Could not initialize hackers.git: %v", err) return nil } o.workers.Add(1) go func() { defer lsb.Recover() defer o.workers.Done() o.worker() }() return &o } func (o *Hackers) Close() { defer o.workers.Wait() 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 }