Skip to content

Commit

Permalink
Merge pull request #338 from michaelkrieger/michaelkrieger-patch-1
Browse files Browse the repository at this point in the history
Adds config setting which can limit alias destinations to local domains ( Thanks @michaelkrieger ). See also #338
  • Loading branch information
DavidGoodwin committed Jan 11, 2024
2 parents 78bf7b7 + eda637d commit ca4a4da
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
16 changes: 7 additions & 9 deletions config.inc.php
Expand Up @@ -538,6 +538,11 @@ function x_struct_admin_modify($struct) {
// address is legal by performing a name server look-up.
$CONF['emailcheck_resolve_domain']='YES';

// When creating mailboxes or aliases, check that the domain-part of the
// address is local and managed by postfixadmin, preventing remote domains
// from being the destination for an alias
$CONF['emailcheck_localaliasonly']='NO';

// Use TOTP for logging into Postfixadmin, can be overridden for listed
// IPs to allow access by software that provide their own checking.
// Exceptions can be of user, domain or global scope.
Expand All @@ -548,21 +553,14 @@ function x_struct_admin_modify($struct) {
// password in another system. These passwords can not access Postfixadmin.
$CONF['app_passwords'] = 'NO';

//
//
// OpenDKIM stuff
//
//

// OpenDKIM stuff
// Enable the dkim database component
$CONF['dkim'] = 'NO';

// Allow regular admins to add/edit/remove dkim entries
$CONF['dkim_all_admins'] = 'NO';

//
// End OpenDKIM stuff
//


// Optional:
// Analyze alias gotos and display a colored block in the first column
Expand Down
27 changes: 27 additions & 0 deletions functions.inc.php
Expand Up @@ -303,6 +303,33 @@ function check_domain($domain)
return '';
}

/**
* Checks if a domain is local
* @param string $domain
* @return string empty if the domain is valid, otherwise string with the errormessage
*/
function check_localaliasonly($domain) {
// If emailcheck_localaliasonly is set to 'YES', disallow aliases to remote servers (but allow aliases on this server)
if (Config::bool('emailcheck_localaliasonly')) {
// get the domain part of the e-mail
list(/*NULL*/, $domain) = explode('@', $domain);

// get all domains managed on this system by postfixadmin
$domains = list_domains();

// Only allow local domains to be alias destinations
if (in_array($domain, $domains)) {
return '';
} else {
// FIXME: Add transaltions
return sprintf("You may only make aliases to domains hosted on this server. %s is a remote domain name.", htmlentities($domain));
}
} else {
return '';
}

}

/**
* Get password expiration value for a domain
* @param string $domain - a string that may be a domain
Expand Down
8 changes: 8 additions & 0 deletions model/AliasHandler.php
Expand Up @@ -412,12 +412,20 @@ protected function _validate_goto($field, $val)
if ($domain_check != '') {
$errors[] = "$singlegoto: $domain_check";
}
$localaliasonly_check = check_localaliasonly($domain);
if ($localaliasonly_check != '') {
$errors[] = "$singlegoto: $localaliasonly_check";
}
} else {
$email_check = check_email($singlegoto);
// preg_match -> allows for redirect to a local system account.
if ($email_check != '' && !preg_match('/^[a-z0-9]+$/', $singlegoto)) {
$errors[] = "$singlegoto: $email_check";
}
$localaliasonly_check = check_localaliasonly($singlegoto);
if ($localaliasonly_check != '') {
$errors[] = "$singlegoto: $localaliasonly_check";
}
}
if ($this->called_by != "MailboxHandler" && $this->id == $singlegoto) {
// The MailboxHandler needs to create an alias that points to itself (for the mailbox)
Expand Down

0 comments on commit ca4a4da

Please sign in to comment.