From: Art Cancro Date: Mon, 29 Nov 2021 00:47:20 +0000 (-0500) Subject: Another win for short circuit evaluation X-Git-Tag: v941~4 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=c85fbae2cd83bf0c8434f409ff3a4a9e694d03fc Another win for short circuit evaluation --- diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index fa8b731d4..2a4b84642 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -681,26 +681,28 @@ void smtp_rcpt(void) { return; // no need to free_recipients(valid) } // because it hasn't been allocated yet + // This is a *preliminary* call to validate_recipients() to evaluate one recipient. valid = validate_recipients( (char *)ChrPtr(SMTP->OneRcpt), smtp_get_Recipients(), (SMTP->is_lmtp)? POST_LMTP: (CC->logged_in)? POST_LOGGED_IN: POST_EXTERNAL ); + + // Any type of error thrown by validate_recipients() will make the SMTP transaction fail at this point. if (valid->num_error != 0) { cprintf("550 %s\r\n", valid->errormsg); free_recipients(valid); return; } - if (valid->num_internet > 0) { - if (CC->logged_in) { - if (CtdlCheckInternetMailPermission(&CC->user)==0) { - cprintf("551 <%s> - you do not have permission to send Internet mail\r\n", - ChrPtr(SMTP->OneRcpt)); - free_recipients(valid); - return; - } - } + if ( + (valid->num_internet > 0) // If it's outbound Internet mail... + && (CC->logged_in) // ...and we're a logged-in user... + && (CtdlCheckInternetMailPermission(&CC->user)==0) // ...who does not have Internet mail rights... + ) { + cprintf("551 <%s> - you do not have permission to send Internet mail\r\n", ChrPtr(SMTP->OneRcpt)); + free_recipients(valid); + return; } if (valid->num_internet > 0) {