diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-06-17 14:35:35 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-06-17 14:35:35 -0400 |
commit | 0e0907734c12eb0b70659be15ffd8c161402e6db (patch) | |
tree | 220fb5efa58a6ad3539c5d7fcc53c5c66fa29ee6 /src/parabola_hackers/password.go | |
parent | c191af11616a3306b8e0a3650b6972eb61d2aba1 (diff) |
move things src/parabola_hackers{/nslcd_backend,}
Diffstat (limited to 'src/parabola_hackers/password.go')
-rw-r--r-- | src/parabola_hackers/password.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/parabola_hackers/password.go b/src/parabola_hackers/password.go new file mode 100644 index 0000000..4ea345f --- /dev/null +++ b/src/parabola_hackers/password.go @@ -0,0 +1,63 @@ +// Copyright 2015-2016 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. +// +// 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 parabola_hackers + +import ( + "io/ioutil" + "lukeshu.com/git/go/libgnulinux.git/crypt" + "fmt" + "os" + "strings" +) + +/* Note that the password hash value should be one of: + <empty> - no password set, allow login without password + ! - used to prevent logins + x - "valid" encrypted password that does not match any valid password + often used to indicate that the password is defined elsewhere + other - encrypted password, in crypt(3) format */ + +func LoadUserPassword(filename string) (hash string, err error) { + file, err := os.Open(filename) + if err != nil { + return + } + contents, err := ioutil.ReadAll(file) + if err != nil { + return + } + lines := strings.Split(string(contents), "\n") + switch len(lines) { + case 1: + hash = lines[0] + case 2: + if lines[1] == "" { + hash = lines[0] + } else { + err = fmt.Errorf("Invalid password format in file: %q", filename) + } + default: + err = fmt.Errorf("Invalid password format in file (number of lines): %q", filename) + return + } + if hash != "!" && !crypt.SaltOk(hash) { + hash = "!" + err = fmt.Errorf("Invalid password format in file (invalid salt): %q", filename) + return + } + return +} |