2000-12-13 13:19:03 +00:00
|
|
|
/*
|
2019-07-10 13:00:47 +00:00
|
|
|
* Copyright (c) 1995-2019 Peter Simons <simons@cryp.to>
|
2010-02-24 16:01:14 +00:00
|
|
|
* Copyright (c) 2000-2001 Cable & Wireless GmbH
|
|
|
|
|
* Copyright (c) 1999-2000 CyberSolutions GmbH
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
|
* version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
|
* details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2000-12-13 15:35:14 +00:00
|
|
|
|
2013-02-09 19:13:50 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
2000-12-13 15:35:14 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include "petidomo.h"
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
/* Returncodes have the following meaning: '-1' == Error, '0' ==
|
|
|
|
|
Proceed, '1' == Mail has been taken care of. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
handleACL(struct Mail * MailStruct, const char * listname, int operation, char * parameter)
|
|
|
|
|
{
|
|
|
|
|
const struct PD_Config * MasterConfig;
|
2001-01-06 10:11:58 +00:00
|
|
|
const struct List_Config * ListConfig = NULL;
|
2000-12-13 13:19:03 +00:00
|
|
|
FILE * fh;
|
|
|
|
|
char * buffer;
|
|
|
|
|
char envelope[1024];
|
|
|
|
|
char owner[1024];
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
assert(MailStruct != NULL);
|
|
|
|
|
|
|
|
|
|
MasterConfig = getMasterConfig();
|
|
|
|
|
if (listname != NULL) {
|
2010-02-24 16:24:28 +00:00
|
|
|
ListConfig = getListConfig(listname);
|
|
|
|
|
sprintf(envelope, "%s-owner@%s", listname, ListConfig->fqdn);
|
|
|
|
|
sprintf(owner, "%s-owner@%s", listname, ListConfig->fqdn);
|
2000-12-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-02-24 16:24:28 +00:00
|
|
|
sprintf(envelope, "petidomo-manager@%s", MasterConfig->fqdn);
|
|
|
|
|
sprintf(owner, "petidomo-manager@%s", MasterConfig->fqdn);
|
2000-12-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check for authorization. */
|
|
|
|
|
|
|
|
|
|
switch(operation) {
|
|
|
|
|
case ACL_NONE:
|
2010-02-24 16:24:28 +00:00
|
|
|
break;
|
2000-12-13 13:19:03 +00:00
|
|
|
case ACL_PASS:
|
2010-02-24 16:24:28 +00:00
|
|
|
break;
|
2001-01-16 10:49:08 +00:00
|
|
|
case ACL_APPROVE:
|
2010-02-24 16:24:28 +00:00
|
|
|
MailStruct->Approve = MasterConfig->master_password;
|
|
|
|
|
break;
|
2000-12-13 13:19:03 +00:00
|
|
|
case ACL_DROP:
|
2010-02-24 16:24:28 +00:00
|
|
|
return 1;
|
2000-12-13 13:19:03 +00:00
|
|
|
case ACL_REJECTWITH:
|
2010-02-24 16:24:28 +00:00
|
|
|
assert(parameter != NULL);
|
2000-12-13 13:19:03 +00:00
|
|
|
case ACL_REJECT:
|
2010-02-24 16:24:28 +00:00
|
|
|
fh = vOpenMailer(envelope, owner, (MailStruct->Reply_To) ?
|
|
|
|
|
(MailStruct->Reply_To) : (MailStruct->From), NULL);
|
|
|
|
|
if (fh == NULL) {
|
|
|
|
|
syslog(LOG_ERR, "Failed to open mailer for redirection.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fprintf(fh, "From: %s (Petidomo Mailing List Server)\n", owner);
|
|
|
|
|
fprintf(fh, "To: %s\n", (MailStruct->Reply_To) ?
|
|
|
|
|
(MailStruct->Reply_To) : (MailStruct->From));
|
|
|
|
|
fprintf(fh, "Cc: %s\n", owner);
|
|
|
|
|
if (listname != NULL)
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: BOUNCE %s@%s: Rejected due to ACL\n", listname, ListConfig->fqdn);
|
|
|
|
|
else
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: BOUNCE: Rejected due to ACL\n");
|
|
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", owner);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
if (operation == ACL_REJECTWITH && (buffer = loadfile(parameter)) != NULL) {
|
|
|
|
|
fprintf(fh, "%s\n", buffer);
|
|
|
|
|
free(buffer);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2001-01-06 11:05:08 +00:00
|
|
|
if (listname != NULL)
|
|
|
|
|
fprintf(fh, "The following posting was rejected by Petidomo, due to\n"
|
|
|
|
|
"the access control list (ACL) rules for list `%s@%s'.\n", listname, ListConfig->fqdn);
|
2010-02-24 16:24:28 +00:00
|
|
|
else
|
2001-01-06 11:05:08 +00:00
|
|
|
fprintf(fh, "The following posting was rejected by Petidomo, due to\n" \
|
|
|
|
|
"the global access control list (ACL) rules.\n\n");
|
|
|
|
|
}
|
2010-02-24 16:24:28 +00:00
|
|
|
fprintf(fh, "%s\n", MailStruct->Header);
|
|
|
|
|
fprintf(fh, "%s", MailStruct->Body);
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
return 1;
|
2000-12-13 13:19:03 +00:00
|
|
|
case ACL_REDIRECT:
|
2010-02-24 16:24:28 +00:00
|
|
|
assert(parameter != NULL);
|
|
|
|
|
syslog(LOG_INFO, "Mail is redirected to \"%s\" due to access control.", parameter);
|
|
|
|
|
fh = vOpenMailer(MailStruct->Envelope, parameter, NULL);
|
|
|
|
|
if (fh == NULL) {
|
|
|
|
|
syslog(LOG_ERR, "Failed to open mailer for redirection.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fprintf(fh, "%s\n", MailStruct->Header);
|
|
|
|
|
fprintf(fh, "%s", MailStruct->Body);
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
return 1;
|
2000-12-13 13:19:03 +00:00
|
|
|
case ACL_FORWARD:
|
2010-02-24 16:24:28 +00:00
|
|
|
assert(parameter != NULL);
|
|
|
|
|
syslog(LOG_INFO, "Mail is forwarded to \"%s\" due to access control.", parameter);
|
|
|
|
|
fh = vOpenMailer(envelope, parameter, NULL);
|
|
|
|
|
if (fh == NULL) {
|
|
|
|
|
syslog(LOG_ERR, "Failed to open mailer for redirection.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fprintf(fh, "From: %s (Petidomo Mailing List Server)\n", owner);
|
|
|
|
|
fprintf(fh, "To: %s\n", parameter);
|
|
|
|
|
if (listname != NULL)
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: BOUNCE %s@%s: Forwarded due to ACL\n", listname, ListConfig->fqdn);
|
2001-01-06 11:05:08 +00:00
|
|
|
else
|
2010-02-24 16:24:28 +00:00
|
|
|
fprintf(fh, "Subject: Petidomo: BOUNCE: Forwarded due to ACL\n");
|
|
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", owner);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
if (listname != NULL)
|
|
|
|
|
fprintf(fh, "The following posting was forwarded to you by Petidomo, due to\n"
|
|
|
|
|
"the access control list (ACL) rules for list `%s@%s'.\n", listname, ListConfig->fqdn);
|
|
|
|
|
else
|
|
|
|
|
fprintf(fh, "The following posting was forwarded to you by Petidomo, due to\n" \
|
|
|
|
|
"the global access control list (ACL) rules.\n");
|
2001-01-06 11:05:08 +00:00
|
|
|
fprintf(fh, "If you approve this posting, pipe this mail through `petidomo-approve'.\n"
|
|
|
|
|
"If you do not approve this posting, just do nothing.\n\n");
|
2010-02-24 16:24:28 +00:00
|
|
|
fprintf(fh, "%s\n", MailStruct->Header);
|
|
|
|
|
fprintf(fh, "%s", MailStruct->Body);
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
return 1;
|
2000-12-13 13:19:03 +00:00
|
|
|
case ACL_FILTER:
|
2010-02-24 16:24:28 +00:00
|
|
|
assert(parameter != NULL);
|
|
|
|
|
syslog(LOG_INFO, "Mail is filtered through \"%s\" due to access control.",
|
|
|
|
|
parameter);
|
|
|
|
|
rc = MailFilter(MailStruct, parameter);
|
|
|
|
|
if (rc != 0) {
|
|
|
|
|
syslog(LOG_ERR, "Mail filter \"%s\" returned error code %d.", parameter, rc);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2000-12-13 13:19:03 +00:00
|
|
|
default:
|
2010-02-24 16:24:28 +00:00
|
|
|
syslog(LOG_CRIT, "Internal error: Unexpected return code %d from checkACL()",
|
|
|
|
|
operation);
|
|
|
|
|
return -1;
|
2000-12-13 13:19:03 +00:00
|
|
|
}
|
2010-02-24 16:09:53 +00:00
|
|
|
free(parameter);
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|