File: spamtrap.c

package info (click to toggle)
postfix-policyd 1.82-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 520 kB
  • ctags: 220
  • sloc: ansic: 3,875; sql: 270; sh: 252; makefile: 127
file content (102 lines) | stat: -rw-r--r-- 3,325 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "policyd.h"


/*
 *
 *
 *                           Policy Daemon
 *
 *  policy daemon is used in conjuction with postfix to combat spam.
 *
 *  Copyright (C) 2004 Cami Sardinha (cami@mweb.co.za)
 *
 *
 *  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  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
 *
 *
 *
 */


/*
 * function: spamtrap_check
 *  purpose: check if there is a delivery attempt to a spamtrap
 *   return: 1=yes, 0=no
 */
int
spamtrap_check(unsigned int fd)
{
  
  if(DEBUG > 0)
    logmessage("DEBUG: fd: %d checking spamtrap\n", fd);

  /* reset value */
  mysql_optarray[fd][0] = 0;
    
  /* build up & execute query */
  snprintf(mysqlquery_array[fd], 512,
    "SELECT _active FROM spamtrap WHERE _rcpt='%s' AND _active=1", triplet_array[fd][2]);
  if(db_optquery(fd) == -1) return(db_failure(fd, "spamtrap"));

  /* we have a delivery attempt to a spamtrap */
  if(mysql_optarray[fd][0] == 1)
  {
    int expire=0;
    if(DEBUG > 0)
      logmessage("DEBUG: fd: %d spamtrap found: %s from: %s\n", fd, 
        triplet_array[fd][2],   /* rcpt */
        host_array[fd][2]);     /* host */

    /* never auto expire blacklist? */
    if(SPAMTRAP_AUTO_EXPIRE > 0)
      expire=timenow+SPAMTRAP_AUTO_EXPIRE;

    /* blacklist netblock /24 */
    if(BLACKLIST_NETBLOCK==1)
    {
      /* build up query */
      snprintf(mysqlquery_array[fd], 512,
        "INSERT DELAYED INTO blacklist (_blacklist,_description,_expire) VALUES ('%s','# spamtrap delivery: (%s)',%d)",
       host_array[fd][3], triplet_array[fd][2], expire);
    } else { /* blacklist host ip */
      /* build up query */
      snprintf(mysqlquery_array[fd], 512,
        "INSERT DELAYED INTO blacklist (_blacklist,_description,_expire) VALUES ('%s','# spamtrap delivery: (%s)',%d)",
      host_array[fd][2], triplet_array[fd][2], expire);
    }
    /* execute query */
    if(db_doquery(fd) == -1) return(db_failure(fd, "spamtrap"));
    
    logmessage("rcpt=%lu, spamtrap=new, host=%s (%s), from=%s, to=%s, size=%s, expire=%d\n",
      rcpt_count,                       /* recipient count      */
      host_array[fd][2],                /* host                 */
      host_array[fd][0],                /* hostname             */
      triplet_array[fd][1],             /* from                 */
      triplet_array[fd][2],             /* rcpt                 */
      triplet_array[fd][3],             /* size                 */
      expire                            /* expiry               */
    );

    return (1);
  }

  if(DEBUG > 0)
    logmessage("DEBUG: fd: %d spamtrap not found: %s\n", fd, triplet_array[fd][2]);

  /* no delivery attempted to spamtrap */
  return (0);
}
 
/* EOF */