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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
/* Distributed Checksum Clearinghouse
*
* common threaded client definitions
*
* Copyright (c) 2005 by Rhyolite Software
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE
* BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*
* Rhyolite Software DCC 1.2.74-1.20 $Revision$
*/
#ifndef CLNT_DEFS_H
#define CLNT_DEFS_H
#include "dcc_ck.h"
#include "dcc_xhdr.h"
#include "dcc_heap_debug.h"
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#else
#include <sys/pthread.h>
#endif
#ifndef DCC_WIN32
#include <sys/un.h>
#include <sys/resource.h>
#include <arpa/inet.h>
#endif
/* what to do about checksums whose counts say "spam" */
typedef enum {
CMN_REJECT = 0, /* tell sendmail to reject spam */
CMN_DISCARD, /* discard spam */
CMN_IGNORE, /* ignore spam reports */
} CMN_ACTION;
extern CMN_ACTION action;
typedef enum {
SETHDR, ADDHDR, NOHDR
} CHGHDR;
extern CHGHDR chghdr;
typedef struct {
char rcode[sizeof("5yz")];
char xcode[sizeof("1.23.45")];
# define REPLY_BUF 200
char pat[REPLY_BUF];
u_char is_pat;
} REPLY;
extern REPLY rej_reply;
extern REPLY grey_reply;
extern REPLY temp_reply;
#define DCC_XCODE "5.7.1"
#define DCC_RCODE "550"
#define GREY_XCODE "4.2.1"
#define GREY_RCODE "452"
typedef struct {
int msgs; /* total messages */
int tgts; /* total addressees */
int tgts_discarded; /* discarded for this many addressess */
int tgts_rejected;
int tgts_embargoed;
int msgs_embargoed;
int msgs_spam;
time_t msg_prev, msg_next;
} TOTALS;
extern TOTALS totals;
/* This is a wild guess of open files hidden in libraries and elsewhere.
* Some systems such as Solaris seem to have an amazing number of them
* Each whitelist context can involve two open files. */
#define EXTRA_FILES (32 + NUM_CWFS*2)
/* per-recipient state */
typedef struct rcpt_st {
struct rcpt_st *fwd;
struct cmn_work *cwp;
int user_log_fd;
off_t log_pos_to; /* env_To line in main log file */
off_t log_pos_white;
DCC_CKS_WTGTS wtgts;
DCC_ASK_GREY_RESULT grey_result;
u_int embargo_num;
u_int flags;
# define RCPT_ST_NO_CLNT_ADDR 0x01 /* no SMTP client address */
# define RCPT_ST_DCC_OFF 0x0002 /* no DCC check */
# define RCPT_ST_GREY_OFF 0x0004 /* greylisting off */
# define RCPT_ST_GREY_LOG_OFF 0x08 /* log greylist embargos */
# define RCPT_ST_LOG_ALL 0x0010
# define RCPT_ST_DNSBL_ON 0x0020 /* check DNS blacklists */
# define RCPT_ST_WHITE 0x0040 /* msg is whitelisted */
# define RCPT_ST_BLACK 0x0080 /* msg is blacklisted */
# define RCPT_ST_GREY_END 0x0100 /* end of greylist embargo */
# define RCPT_ST_GREY_WHITE 0x0200 /* whitelisted for greylisting */
# define RCTP_MAXNAME 257 /* sendmail MAXNAME limit */
char env_to[RCTP_MAXNAME]; /* env_to */
char user[RCTP_MAXNAME]; /* mailbox */
DCC_SUM env_to_sum;
DCC_SUM msg_sum;
DCC_SUM triple_sum;
DCC_PATH dir; /* recipient's whitelist and logdir */
DCC_PATH user_log_nm;
} RCPT_ST;
/* per message state common to threaded DCC clients */
typedef struct cmn_work {
DCC_CLNT_CTXT *dcc_ctxt;
struct work *wp;
u_int dcc_ctxt_sn;
CMN_ACTION action;
u_int xhdr_len;
char xhdr[sizeof(DCC_XHDR_START)+sizeof(DCC_BRAND)+1];
char clnt_name[MAXHOSTNAMELEN]; /* SMTP client */
char clnt_str[INET6_ADDRSTRLEN+1];
struct in6_addr clnt_addr;
char helo[DCC_HELO_MAX];
# define WORK_ID_LEN 24
char id[WORK_ID_LEN];
char reply_buf[REPLY_BUF+WORK_ID_LEN+INET6_ADDRSTRLEN];
DCC_EMSG emsg;
DCC_PATH log_nm; /* log file for this message */
int num_rcpts;
# define MAX_RCPTS 1024
RCPT_ST *rcpt_st_first, *rcpt_st_last;
off_t log_pos_to_first; /* first env_To line in log file */
off_t log_pos_to_end; /* end of env_To lines in log file */
off_t log_pos_white_first; /* first white-list result */
off_t log_pos_white_last; /* last white-list result */
int log_fd; /* -1=none */
int log_fd2; /* -1=none -2=stop trying */
DCC_HEADER_BUF header;
#define CMN_WORK_ZERO reply_ptr /* here down cleared for each msg */
char *reply_ptr;
REPLY reply;
DCC_TGTS tgts, white_tgts, reject_tgts, deliver_tgts;
DCC_TGTS early_grey_tgts; /* report to DCC if embargoed */
DCC_TGTS late_grey_tgts; /* don't report to DCC if delivered */
#if MAX_LOG_SIZE > 0
int log_size;
#endif
DCC_GOT_CKS cks;
DCC_CKS_WTGTS wtgts;
u_int rcpt_st_flags; /* common values for rcpt_st->flags */
u_int honor; /* DCC_HONOR_SRVR_ISSPAM etc. */
} CMN_WORK;
extern u_char grey_on;
extern u_char grey_query_only;
extern u_int dcc_ctxt_sn; /* change X-DCC header server name */
extern RCPT_ST *rcpt_st_free;
extern u_char dcc_query_only;
extern u_char try_extra_hard; /* 1=don't quit if DCC server dead */
extern u_char to_white_only;
extern const char *mapfile_nm;
extern const char *main_white_nm;
extern void parse_userdirs(const char *);
extern u_char get_user_dir(RCPT_ST *, const char *, int, const char *, int);
extern void parse_reply(REPLY *, u_char,
const char *, const char *, const char *);
extern void parse_reply_arg(const char *);
extern void make_reply(CMN_WORK *, REPLY *);
extern void finish_replies(void);
extern void lock_work(void);
extern void unlock_work(void);
extern void cmn_init(DCC_EMSG);
extern void cmn_create(CMN_WORK *);
extern void cmn_clear(CMN_WORK *, struct work *);
extern void rcpts_create(int);
extern void rcpts_free(CMN_WORK *, u_char);
extern RCPT_ST *rcpt_st_alloc(CMN_WORK *, u_char);
extern u_char log_start(CMN_WORK *);
extern void log_stop(CMN_WORK *);
extern void log_write(CMN_WORK *, const void *, u_int);
#define LOG_CMN_CAPTION(cwp, s) log_write(cwp, s, sizeof(s)-1)
#define LOG_CMN_EOL(cwp) LOG_CMN_CAPTION(cwp, "\n")
#define LOG_CAPTION(wp, s) LOG_CMN_CAPTION(&(wp)->cw, s)
#define LOG_EOL(wp) LOG_CAPTION(wp, "\n")
extern void log_print(CMN_WORK *, const char *, ...) PATTRIB(2,3);
extern off_t log_lseek(CMN_WORK *, int);
extern void cmn_error_msg(CMN_WORK *, const char *, ...) PATTRIB(2,3);
extern void cmn_trace_msg(CMN_WORK *, const char *, ...) PATTRIB(2,3);
extern u_char ck_dcc_ctxt(CMN_WORK *);
extern u_char ask_grey_predict(CMN_WORK *, RCPT_ST *, u_char);
extern void cmn_ask_white(CMN_WORK *, u_char);
extern int cmn_ask_dcc(CMN_WORK *, u_char);
#define USER_LOG_CAPTION(rcpt_st, s) user_log_write((rcpt_st), (s), sizeof(s)-1)
#define USER_LOG_EOL(rcpt_st) USER_LOG_CAPTION((rcpt_st), "\n")
extern u_char user_log_write(RCPT_ST *, const void *, u_int);
extern void users_process(CMN_WORK *);
typedef enum {
USER_REJECT_RCPT, /* this recipient only */
USER_REJECT_ALL, /* all recipients */
USER_REJECT_GREY, /* greylist embargo */
} USER_REJECT_TYPE;
extern void user_reject(CMN_WORK *, RCPT_ST *, USER_REJECT_TYPE type);
extern void totals_init(void);
extern void totals_msg(void);
#endif /* CLNT_DEFS_H */
|