forked from drew/smtprelay
Add localAuthRequired() helper function
This just makes the configuration state a little more obvious.
This commit is contained in:
@@ -43,6 +43,10 @@ var (
|
|||||||
versionInfo = flag.Bool("version", false, "Show version information")
|
versionInfo = flag.Bool("version", false, "Show version information")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func localAuthRequired() bool {
|
||||||
|
return *allowedUsers != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func setupAllowedNetworks() {
|
func setupAllowedNetworks() {
|
||||||
for _, netstr := range splitstr(*allowedNetsStr, ' ') {
|
for _, netstr := range splitstr(*allowedNetsStr, ' ') {
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -81,7 +81,7 @@ func addrAllowed(addr string, allowedAddrs []string) bool {
|
|||||||
|
|
||||||
func senderChecker(peer smtpd.Peer, addr string) error {
|
func senderChecker(peer smtpd.Peer, addr string) error {
|
||||||
// check sender address from auth file if user is authenticated
|
// check sender address from auth file if user is authenticated
|
||||||
if *allowedUsers != "" && peer.Username != "" {
|
if localAuthRequired() && peer.Username != "" {
|
||||||
user, err := AuthFetch(peer.Username)
|
user, err := AuthFetch(peer.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Shouldn't happen: authChecker already validated username+password
|
// Shouldn't happen: authChecker already validated username+password
|
||||||
@@ -276,7 +276,7 @@ func main() {
|
|||||||
Debug("starting smtprelay")
|
Debug("starting smtprelay")
|
||||||
|
|
||||||
// Load allowed users file
|
// Load allowed users file
|
||||||
if *allowedUsers != "" {
|
if localAuthRequired() {
|
||||||
err := AuthLoadFile(*allowedUsers)
|
err := AuthLoadFile(*allowedUsers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithField("file", *allowedUsers).
|
log.WithField("file", *allowedUsers).
|
||||||
@@ -300,7 +300,7 @@ func main() {
|
|||||||
Handler: mailHandler,
|
Handler: mailHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
if *allowedUsers != "" {
|
if localAuthRequired() {
|
||||||
server.Authenticator = authChecker
|
server.Authenticator = authChecker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user