1 /* $Id: agent_shared.h,v 1.35 2011/07/11 21:27:15 sbajic Exp $ */
2 
3 /*
4  DSPAM
5  COPYRIGHT (C) 2002-2012 DSPAM PROJECT
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Affero General Public License as
9  published by the Free Software Foundation, either version 3 of the
10  License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU Affero General Public License for more details.
16 
17  You should have received a copy of the GNU Affero General Public License
18  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 
20 */
21 
22 #include <sys/types.h>
23 #ifndef _WIN32
24 #include <pwd.h>
25 #endif
26 #include "buffer.h"
27 
28 #ifdef HAVE_CONFIG_H
29 #include <auto-config.h>
30 #endif
31 #include "libdspam.h"
32 
33 #ifndef _AGENT_SHARED_H
34 #  define _AGENT_SHARED_H
35 
36 extern char *__pw_name;
37 extern uid_t __pw_uid;
38 
39 #define STATUS( ... )   snprintf(ATX->status, sizeof(ATX->status), __VA_ARGS__);
40 
41 #define SYNTAX "Syntax: dspam [--help|--version|[--client|--daemon [--nofork]] [--debug] --mode=[toe|tum|teft|notrain|unlearn] --user [user1 user2 ... userN] [--feature=[no,wh,tb=N]] [--class=[spam|innocent]] [--source=[error|corpus|inoculation]] [--profile=[PROFILE]] [--deliver=[spam,[innocent|nonspam],summary,stdout]] [--process|--classify] [--stdout] [--mail-from=sender-address] [--rcpt-to recipient-address(es)] [--signature=DSPAM-Signature] [passthru-arguments]]"
42 
43 #define         SIGNATURE_BEGIN		"!DSPAM:"
44 #define         SIGNATURE_END		"!"
45 #define         LOOSE_SIGNATURE_BEGIN	"X-DSPAM-Signature:"
46 #define         SIGNATURE_DELIMITER	": "
47 
48 /* AGENT_CTX: Agent context. Defines the behavior of the agent */
49 
50 typedef struct {
51   int operating_mode;			/* Processing Mode       IN DSM_ */
52   int fork;				/* Fork daemon:          IN 1:0  */
53   int client_mode;			/* Client Mode:          IN 1:0  */
54   int training_mode;			/* Training Mode         IN DST_ */
55   int classification;			/* Classification        IN DSR_ */
56   int source;				/* Classification Source IN DSS_ */
57   int spam_action;			/* Action on Spam        IN DSA_ */
58 #ifdef TRUSTED_USER_SECURITY
59   int trusted;				/* Trusted User?         IN      */
60 #endif
61   int feature;				/* Feature Overridden?   IN      */
62   int train_pristine;			/* Train Pristine?       IN      */
63   int tokenizer;			/* Tokenizer             IN      */
64   void *dbh;				/* Database Handle       IN      */
65   u_int64_t flags;			/* Flags DAF_            IN      */
66   int training_buffer;			/* Sedation Level 0-10   IN      */
67   char *recipient;			/* Current Recipient             */
68   char mailer_args[256];		/* Delivery Args         IN      */
69   char spam_args[256];			/* Quarantine Args       IN      */
70   char managed_group[256];		/* Managed Groupname     IN      */
71   char profile[32];			/* Storage Profile       IN      */
72   char signature[128];			/* Signature Serial      IN/OUT  */
73   char mailfrom[256];			/* For LMTP or SMTP              */
74   struct nt *users;			/* Destination Users     IN      */
75   struct nt *inoc_users;		/* Inoculate list        OUT     */
76   struct nt *classify_users;		/* Classify list         OUT     */
77   struct nt *recipients;		/* Recipients            IN      */
78   struct nt *results;			/* Process Results       OUT     */
79   struct _ds_spam_signature SIG;	/* Signature object      OUT     */
80   int learned;                  	/* Message learned?      OUT     */
81   FILE *sockfd;				/* Socket FD if not STDOUT       */
82   int sockfd_output;			/* Output sent to sockfd?        */
83   char client_args[1024];		/* Args for client connection    */
84   double timestart;
85   agent_pref_t PTX;
86 
87   char status[256];
88 #ifdef DEBUG
89   char debug_args[1024];
90 #endif
91 #ifndef _WIN32
92 #ifdef TRUSTED_USER_SECURITY
93   struct passwd *p;
94 #if defined(_REENTRANT) && defined(HAVE_GETPWUID_R)
95   struct passwd pwbuf;
96 #endif
97 #endif
98 #endif
99 } AGENT_CTX;
100 
101 int process_features	(AGENT_CTX *ATX, const char *features);
102 int process_mode	(AGENT_CTX *ATX, const char *mode);
103 int check_configuration (AGENT_CTX *ATX);
104 int apply_defaults      (AGENT_CTX *ATX);
105 int process_arguments   (AGENT_CTX *ATX, int argc, char **argv);
106 int initialize_atx      (AGENT_CTX *ATX);
107 int process_parseto	(AGENT_CTX *ATX, const char *buf);
108 buffer *read_stdin	(AGENT_CTX *ATX);
109 
110 int init_pwent_cache(void);
111 
112 #ifndef MIN
113 #   define MAX(a,b)  ((a)>(b)?(a):(b))
114 #   define MIN(a,b)  ((a)<(b)?(a):(b))
115 #endif /* !MIN */
116 
117 /*
118  * Agent context flag (DAF)
119  * Do not confuse with libdspam's classification context flags (DSF)
120  *
121  */
122 
123 #define DAF_STDOUT		0x01
124 #define DAF_DELIVER_SPAM	0x02
125 #define DAF_DELIVER_INNOCENT	0x04
126 #define DAF_WHITELIST		0x08
127 #define DAF_GLOBAL		0x10
128 #define DAF_INOCULATE		0x20
129 #define DAF_NOISE		0x40
130 #define DAF_MERGED		0x80
131 #define DAF_SUMMARY		0x100
132 #define DAF_UNLEARN		0x200
133 #define DAF_FIXED_TR_MODE	0x400
134 
135 #define DAZ_WORD		0x01
136 #define DAZ_CHAIN		0x02
137 #define DAZ_SBPH		0x03
138 #define DAZ_OSB			0x04
139 
140 #endif /* _AGENT_SHARED_H */
141