Skip to content

Commit 21d2e85

Browse files
authored
Merge pull request #2 from jrwren/001-fixes
docs & fix missing errcheck
2 parents d79ceb5 + 0379fc3 commit 21d2e85

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright © 2020 Jay R. Wren
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sadv.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
Package sadv provides a saslauthd client for authenticating a user via
3+
password. In most cases the path, service, realm, and clientAddr args to
4+
SASLauthdVerifyPassword can be empty string and the retval can be ignored.
5+
For Example:
6+
7+
import (
8+
"log"
9+
10+
"github.com/jrwren/sadv"
11+
)
12+
func main() {
13+
retval, err := sadv.SASLauthdVerifyPassword("", user, password, "", "", "")
14+
if err != nil {
15+
log.Println("auth failed")
16+
17+
}
18+
log.Println("auth succeeded")
19+
}
20+
21+
The entire package is in a single file and ~ 120lines. Feel free to copy and
22+
paste the impl into your code rather than importing with go get.
23+
*/
124
package sadv
225

326
import (
@@ -9,9 +32,13 @@ import (
932
)
1033

1134
// SASLauthdVerifyPassword connects to saslauthd socket at path and
12-
// autneticates. If the return value is not an error, then authentication
35+
// authenticates. If the return value is not an error, then authentication
1336
// was successful. The string response is the response from saslauthd. It is
1437
// usually not needed but can be useful for debugging purposes.
38+
// If the path is empty and environment variable PATH_SASLAUTHD_RUNDIR is set
39+
// then the mux socket file in that directory is used. Otherwise a default of
40+
// "/var/run/saslauthd/mux" is used.
41+
// If the service is empty then a default of imap is used.
1542
func SASLauthdVerifyPassword(path, user, password, service, realm,
1643
clientAddr string) (string, error) {
1744
if service == "" {
@@ -57,6 +84,9 @@ func SASLauthdVerifyPassword(path, user, password, service, realm,
5784
}
5885
defer c.Close()
5986
n, err := c.Write(query.Bytes())
87+
if err != nil {
88+
return "", err
89+
}
6090
if n != query.Len() {
6191
return "", io.ErrShortWrite
6292
}

0 commit comments

Comments
 (0)