Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit 5c2e28a

Browse files
authored
Merge pull request decke#7 from JonathonReinhart/allow-empty-auth-email
Allow email field to be empty in allowedUsers file to accept any sending address
2 parents 9040a45 + f33105f commit 5c2e28a

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

auth.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func AuthReady() bool {
2828
return (filename != "")
2929
}
3030

31+
// Returns bcrypt-hash, email
32+
// email can be empty in which case it is not checked
3133
func AuthFetch(username string) (string, string, error) {
3234
if !AuthReady() {
3335
return "", "", errors.New("Authentication file not specified. Call LoadFile() first")
@@ -43,13 +45,22 @@ func AuthFetch(username string) (string, string, error) {
4345
for scanner.Scan() {
4446
parts := strings.Fields(scanner.Text())
4547

46-
if len(parts) != 3 {
48+
if len(parts) < 2 || len(parts) > 3 {
4749
continue
4850
}
4951

50-
if strings.ToLower(username) == strings.ToLower(parts[0]) {
51-
return parts[1], parts[2], nil
52+
if strings.ToLower(username) != strings.ToLower(parts[0]) {
53+
continue
5254
}
55+
56+
hash := parts[1]
57+
email := ""
58+
59+
if len(parts) >= 3 {
60+
email = parts[2]
61+
}
62+
63+
return hash, email, nil
5364
}
5465

5566
return "", "", errors.New("User not found")

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func senderChecker(peer smtpd.Peer, addr string) error {
4444
return smtpd.Error{Code: 451, Message: "Bad sender address"}
4545
}
4646

47-
if strings.ToLower(addr) != strings.ToLower(email) {
47+
if email != "" && strings.ToLower(addr) != strings.ToLower(email) {
4848
return smtpd.Error{Code: 451, Message: "Bad sender address"}
4949
}
5050
}

smtprelay.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
; File which contains username and password used for
3939
; authentication before they can send mail.
40-
; File format: username bcrypt-hash email
40+
; File format: username bcrypt-hash [email]
4141
;allowed_users =
4242

4343
; Relay all mails to this SMTP server

0 commit comments

Comments
 (0)