/* * Copyright (C), 2000-2005 by the monit project group. * All Rights Reserved. * * 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 2 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, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_SOCKET_H #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif #ifdef HAVE_ARPA_INET_H #include #endif #include "protocol.h" /** * A simple Postfix SMTP access policy delegation protocol test * * To not affect real traffic, we send the following request with * fixed virtual triplet values to the server: * request=smtpd_access_policy * protocol_state=RCPT * protocol_name=SMTP * sender=monit@foo.tld * recipient=monit@foo.tld * client_address=1.2.3.4 * and check that the server replies with some action. * * @author Martin Pala, * * @version \$Id: postfix_policy.c,v 1.1 2005/08/04 14:52:16 martinp Exp $ * * @file */ int check_postfix_policy(Socket_T s) { char buf[STRLEN]; ASSERT(s); if(socket_print(s, "request=smtpd_access_policy\n" "protocol_state=RCPT\n" "protocol_name=SMTP\n" "sender=monit@foo.tld\n" "recipient=monit@foo.tld\n" "client_address=1.2.3.4\n" "\n") < 0) { log("POSTFIX-POLICY: error sending data -- %s\n", STRERROR); return FALSE; } if(! socket_readln(s, buf, sizeof(buf))) { log("POSTFIX-POLICY: error receiving data -- %s\n", STRERROR); return FALSE; } Util_chomp(buf); if( (strlen(buf) <= 7) || strncasecmp(buf, "action=", 7) ) { log("POSTFIX-POLICY error: %s\n", (buf && *buf)?buf:"no action returned"); return FALSE; } return TRUE; }