mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-26 00:12:32 -07:00
Merge pull request #7 from JonathonReinhart/allow-empty-auth-email
Allow email field to be empty in allowedUsers file to accept any sending address
This commit is contained in:
17
auth.go
17
auth.go
@@ -28,6 +28,8 @@ func AuthReady() bool {
|
|||||||
return (filename != "")
|
return (filename != "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns bcrypt-hash, email
|
||||||
|
// email can be empty in which case it is not checked
|
||||||
func AuthFetch(username string) (string, string, error) {
|
func AuthFetch(username string) (string, string, error) {
|
||||||
if !AuthReady() {
|
if !AuthReady() {
|
||||||
return "", "", errors.New("Authentication file not specified. Call LoadFile() first")
|
return "", "", errors.New("Authentication file not specified. Call LoadFile() first")
|
||||||
@@ -43,13 +45,22 @@ func AuthFetch(username string) (string, string, error) {
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
parts := strings.Fields(scanner.Text())
|
parts := strings.Fields(scanner.Text())
|
||||||
|
|
||||||
if len(parts) != 3 {
|
if len(parts) < 2 || len(parts) > 3 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower(username) == strings.ToLower(parts[0]) {
|
if strings.ToLower(username) != strings.ToLower(parts[0]) {
|
||||||
return parts[1], parts[2], nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash := parts[1]
|
||||||
|
email := ""
|
||||||
|
|
||||||
|
if len(parts) >= 3 {
|
||||||
|
email = parts[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash, email, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", "", errors.New("User not found")
|
return "", "", errors.New("User not found")
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -44,7 +44,7 @@ func senderChecker(peer smtpd.Peer, addr string) error {
|
|||||||
return smtpd.Error{Code: 451, Message: "Bad sender address"}
|
return smtpd.Error{Code: 451, Message: "Bad sender address"}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower(addr) != strings.ToLower(email) {
|
if email != "" && strings.ToLower(addr) != strings.ToLower(email) {
|
||||||
return smtpd.Error{Code: 451, Message: "Bad sender address"}
|
return smtpd.Error{Code: 451, Message: "Bad sender address"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
; File which contains username and password used for
|
; File which contains username and password used for
|
||||||
; authentication before they can send mail.
|
; authentication before they can send mail.
|
||||||
; File format: username bcrypt-hash email
|
; File format: username bcrypt-hash [email]
|
||||||
;allowed_users =
|
;allowed_users =
|
||||||
|
|
||||||
; Relay all mails to this SMTP server
|
; Relay all mails to this SMTP server
|
||||||
|
|||||||
Reference in New Issue
Block a user