From 5fd34611ee99d409c7e127bac162eb2fe37e46b7 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 17 Jun 2016 14:46:57 -0400 Subject: clean up --- src/cmd-nshd/main.go.in | 5 +- .../nslcd_backend/check_password.go | 23 --------- src/parabola_hackers/nslcd_backend/db_config.go | 3 +- src/parabola_hackers/nslcd_backend/db_group.go | 3 +- src/parabola_hackers/nslcd_backend/db_pam.go | 12 +++-- src/parabola_hackers/nslcd_backend/db_passwd.go | 5 +- src/parabola_hackers/nslcd_backend/db_shadow.go | 5 +- src/parabola_hackers/nslcd_backend/gid.go | 37 -------------- src/parabola_hackers/nslcd_backend/hackers.go | 7 +-- .../nslcd_backend/hackers_parse.go | 38 -------------- src/parabola_hackers/nslcd_backend/util.go | 58 ++++++++++++++++++++++ src/parabola_hackers/password.go | 5 +- 12 files changed, 87 insertions(+), 114 deletions(-) delete mode 100644 src/parabola_hackers/nslcd_backend/check_password.go delete mode 100644 src/parabola_hackers/nslcd_backend/gid.go delete mode 100644 src/parabola_hackers/nslcd_backend/hackers_parse.go create mode 100644 src/parabola_hackers/nslcd_backend/util.go (limited to 'src') diff --git a/src/cmd-nshd/main.go.in b/src/cmd-nshd/main.go.in index f24707e..b8c3e71 100644 --- a/src/cmd-nshd/main.go.in +++ b/src/cmd-nshd/main.go.in @@ -18,9 +18,10 @@ package main import ( - "lukeshu.com/git/go/libnslcd.git/systemd" - hackers_nslcd_backend "parabola_hackers/nslcd_backend" "os" + hackers_nslcd_backend "parabola_hackers/nslcd_backend" + + nslcd_systemd "lukeshu.com/git/go/libnslcd.git/systemd" ) func main() { diff --git a/src/parabola_hackers/nslcd_backend/check_password.go b/src/parabola_hackers/nslcd_backend/check_password.go deleted file mode 100644 index 1458b6f..0000000 --- a/src/parabola_hackers/nslcd_backend/check_password.go +++ /dev/null @@ -1,23 +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_nslcd_backend - -import "lukeshu.com/git/go/libgnulinux.git/crypt" - -func check_password(password string, hash string) bool { - return crypt.Crypt(password, hash) == hash -} diff --git a/src/parabola_hackers/nslcd_backend/db_config.go b/src/parabola_hackers/nslcd_backend/db_config.go index 934498d..e78643b 100644 --- a/src/parabola_hackers/nslcd_backend/db_config.go +++ b/src/parabola_hackers/nslcd_backend/db_config.go @@ -17,8 +17,9 @@ package hackers_nslcd_backend import ( - p "lukeshu.com/git/go/libnslcd.git/proto" s "syscall" + + p "lukeshu.com/git/go/libnslcd.git/proto" ) func (o *Hackers) Config_Get(cred s.Ucred, req p.Request_Config_Get) <-chan p.Config { diff --git a/src/parabola_hackers/nslcd_backend/db_group.go b/src/parabola_hackers/nslcd_backend/db_group.go index b6b0704..18e54b1 100644 --- a/src/parabola_hackers/nslcd_backend/db_group.go +++ b/src/parabola_hackers/nslcd_backend/db_group.go @@ -17,9 +17,10 @@ package hackers_nslcd_backend import ( - p "lukeshu.com/git/go/libnslcd.git/proto" "parabola_hackers" s "syscall" + + p "lukeshu.com/git/go/libnslcd.git/proto" ) func (o *Hackers) groupByName(name string, users bool) p.Group { diff --git a/src/parabola_hackers/nslcd_backend/db_pam.go b/src/parabola_hackers/nslcd_backend/db_pam.go index 19d4c79..303a66c 100644 --- a/src/parabola_hackers/nslcd_backend/db_pam.go +++ b/src/parabola_hackers/nslcd_backend/db_pam.go @@ -1,4 +1,4 @@ -// Copyright 2015 Luke Shumaker . +// 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 @@ -17,11 +17,17 @@ package hackers_nslcd_backend import ( - p "lukeshu.com/git/go/libnslcd.git/proto" "parabola_hackers" s "syscall" + + "lukeshu.com/git/go/libgnulinux.git/crypt" + p "lukeshu.com/git/go/libnslcd.git/proto" ) +func checkPassword(password string, hash string) bool { + return crypt.Crypt(password, hash) == hash +} + func (o *Hackers) PAM_Authentication(cred s.Ucred, req p.Request_PAM_Authentication) <-chan p.PAM_Authentication { o.lock.RLock() ret := make(chan p.PAM_Authentication) @@ -41,7 +47,7 @@ func (o *Hackers) PAM_Authentication(cred s.Ucred, req p.Request_PAM_Authenticat AuthorizationResult: p.NSLCD_PAM_AUTH_ERR, AuthorizationError: "", } - if check_password(req.Password, user.Passwd.PwHash) { + if checkPassword(req.Password, user.Passwd.PwHash) { obj.AuthenticationResult = p.NSLCD_PAM_SUCCESS obj.AuthorizationResult = obj.AuthenticationResult obj.UserName = user.Passwd.Name diff --git a/src/parabola_hackers/nslcd_backend/db_passwd.go b/src/parabola_hackers/nslcd_backend/db_passwd.go index b11f6af..3f32ddd 100644 --- a/src/parabola_hackers/nslcd_backend/db_passwd.go +++ b/src/parabola_hackers/nslcd_backend/db_passwd.go @@ -1,4 +1,4 @@ -// Copyright 2015 Luke Shumaker . +// 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 @@ -17,8 +17,9 @@ package hackers_nslcd_backend import ( - p "lukeshu.com/git/go/libnslcd.git/proto" s "syscall" + + p "lukeshu.com/git/go/libnslcd.git/proto" ) /* Note that the output password hash value should be one of: diff --git a/src/parabola_hackers/nslcd_backend/db_shadow.go b/src/parabola_hackers/nslcd_backend/db_shadow.go index 6166cd9..abfff28 100644 --- a/src/parabola_hackers/nslcd_backend/db_shadow.go +++ b/src/parabola_hackers/nslcd_backend/db_shadow.go @@ -1,4 +1,4 @@ -// Copyright 2015 Luke Shumaker . +// 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 @@ -17,8 +17,9 @@ package hackers_nslcd_backend import ( - p "lukeshu.com/git/go/libnslcd.git/proto" s "syscall" + + p "lukeshu.com/git/go/libnslcd.git/proto" ) func (o *Hackers) Shadow_ByName(cred s.Ucred, req p.Request_Shadow_ByName) <-chan p.Shadow { diff --git a/src/parabola_hackers/nslcd_backend/gid.go b/src/parabola_hackers/nslcd_backend/gid.go deleted file mode 100644 index eabdbd7..0000000 --- a/src/parabola_hackers/nslcd_backend/gid.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015 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_nslcd_backend - -import "lukeshu.com/git/go/libgnulinux.git/getgr" - -func name2gid(name string) int32 { - gr, err := getgr.ByName(name) - if gr == nil || err != nil { - return -1 - } else { - return int32(gr.Gid) - } -} - -func gid2name(gid int32) (string, bool) { - gr, err := getgr.ByGid(gid) - if gr == nil || err != nil { - return "", false - } else { - return gr.Name, true - } -} diff --git a/src/parabola_hackers/nslcd_backend/hackers.go b/src/parabola_hackers/nslcd_backend/hackers.go index 50d392b..f7d56e3 100644 --- a/src/parabola_hackers/nslcd_backend/hackers.go +++ b/src/parabola_hackers/nslcd_backend/hackers.go @@ -19,11 +19,12 @@ package hackers_nslcd_backend import ( - "lukeshu.com/git/go/libnslcd.git/proto/server" - "lukeshu.com/git/go/libnslcd.git/systemd" - "lukeshu.com/git/go/libsystemd.git/sd_daemon/logger" "parabola_hackers" "sync" + + nslcd_server "lukeshu.com/git/go/libnslcd.git/proto/server" + nslcd_systemd "lukeshu.com/git/go/libnslcd.git/systemd" + "lukeshu.com/git/go/libsystemd.git/sd_daemon/logger" ) type config struct { diff --git a/src/parabola_hackers/nslcd_backend/hackers_parse.go b/src/parabola_hackers/nslcd_backend/hackers_parse.go deleted file mode 100644 index e6d31c8..0000000 --- a/src/parabola_hackers/nslcd_backend/hackers_parse.go +++ /dev/null @@ -1,38 +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_nslcd_backend - -import ( - yaml "gopkg.in/yaml.v2" - "io/ioutil" - "os" -) - -var usersGid = name2gid("users") - -func parse_config(filename string) (cfg config, err error) { - file, err := os.Open(filename) - if err != nil { - return - } - contents, err := ioutil.ReadAll(file) - if err != nil { - return - } - err = yaml.Unmarshal(contents, &cfg) - return -} diff --git a/src/parabola_hackers/nslcd_backend/util.go b/src/parabola_hackers/nslcd_backend/util.go new file mode 100644 index 0000000..4fb28f3 --- /dev/null +++ b/src/parabola_hackers/nslcd_backend/util.go @@ -0,0 +1,58 @@ +// 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_nslcd_backend + +import ( + "io/ioutil" + "os" + + yaml "gopkg.in/yaml.v2" + "lukeshu.com/git/go/libgnulinux.git/getgr" +) + +func name2gid(name string) int32 { + gr, err := getgr.ByName(name) + if gr == nil || err != nil { + return -1 + } else { + return int32(gr.Gid) + } +} + +func gid2name(gid int32) (string, bool) { + gr, err := getgr.ByGid(gid) + if gr == nil || err != nil { + return "", false + } else { + return gr.Name, true + } +} + +var usersGid = name2gid("users") + +func parse_config(filename string) (cfg config, err error) { + file, err := os.Open(filename) + if err != nil { + return + } + contents, err := ioutil.ReadAll(file) + if err != nil { + return + } + err = yaml.Unmarshal(contents, &cfg) + return +} diff --git a/src/parabola_hackers/password.go b/src/parabola_hackers/password.go index 4ea345f..957de1f 100644 --- a/src/parabola_hackers/password.go +++ b/src/parabola_hackers/password.go @@ -17,11 +17,12 @@ package parabola_hackers import ( - "io/ioutil" - "lukeshu.com/git/go/libgnulinux.git/crypt" "fmt" + "io/ioutil" "os" "strings" + + "lukeshu.com/git/go/libgnulinux.git/crypt" ) /* Note that the password hash value should be one of: -- cgit v1.2.2