From c191af11616a3306b8e0a3650b6972eb61d2aba1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 17 Jun 2016 11:49:22 -0400 Subject: rearrange the go packages a bit --- src/nshd/hackers_git/hackers.go | 116 ---------------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 src/nshd/hackers_git/hackers.go (limited to 'src/nshd/hackers_git/hackers.go') diff --git a/src/nshd/hackers_git/hackers.go b/src/nshd/hackers_git/hackers.go deleted file mode 100644 index b9a0b9a..0000000 --- a/src/nshd/hackers_git/hackers.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2015-2016 Luke Shumaker . -// -// 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. -// -// 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 -// . - -// Package hackers_git is an nslcd_server Backend that speaks to -// hackers.git. -package hackers_git - -import ( - "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" - "sync" -) - -type user struct { - passwd nslcd_proto.Passwd - groups []string -} - -type config struct { - Pam_password_prohibit_message string -} - -type Hackers struct { - nslcd_server.NilBackend - lock sync.RWMutex - - CfgFilename string - YamlCat string - - cfg config - users map[int32]user - groups map[string]map[string]bool -} - -var _ nslcd_systemd.Backend = &Hackers{} -var _ nslcd_server.Backend = &Hackers{} - -func (o *Hackers) Init() error { - logger.Debug("hackers.git: CfgFilename = %v", o.CfgFilename) - logger.Debug("hackers.git: YamlCat = %v", o.YamlCat) - 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.users = make(map[int32]user, 0) - o.groups = make(map[string]map[string]bool) -} - -func (o *Hackers) Reload() error { - logger.Info("hackers.git: Loading session") - o.lock.Lock() - defer o.lock.Unlock() - - var err error - o.cfg, err = parse_config(o.CfgFilename) - if err != nil { - return err - } - logger.Info("hackers.git: pam_password_prohibit_message: %#v", o.cfg.Pam_password_prohibit_message) - - logger.Debug("hackers.git: Parsing user data") - o.users, err = parse_users(o.YamlCat) - if err != nil { - return err - } - - o.groups = make(map[string]map[string]bool) - for _, user := range o.users { - for _, groupname := range user.groups { - o.add_user_to_group(user.passwd.Name, groupname) - } - } - return nil -} - -func (o *Hackers) name2uid(name string) int32 { - for uid, data := range o.users { - if data.passwd.Name == name { - return uid - } - } - 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 -} -- cgit v1.2.3-54-g00ecf