View | Details | Raw Unified | Return to bug 579
Collapse All | Expand All

(-)Mail-SpamAssassin-2.40-virgin-20020827/spamd/libspamc.c (-2 / +59 lines)
Lines 21-26 Link Here
21
#include <arpa/inet.h>
21
#include <arpa/inet.h>
22
#include "libspamc.h"
22
#include "libspamc.h"
23
23
24
static void send_user_prefs_file ();
25
24
/* RedHat 5.2 doesn't define Shutdown 2nd Parameter Constants */
26
/* RedHat 5.2 doesn't define Shutdown 2nd Parameter Constants */
25
/* KAM 12-4-01 */
27
/* KAM 12-4-01 */
26
#ifndef SHUT_RD
28
#ifndef SHUT_RD
Lines 85-90 Link Here
85
  char *msg_buf;
87
  char *msg_buf;
86
  /* Keep track of how much is stored in this buffer in case of failure later */
88
  /* Keep track of how much is stored in this buffer in case of failure later */
87
  int amount_read;
89
  int amount_read;
90
  FILE *user_prefs_file;
88
};
91
};
89
92
90
/* Dec 13 2001 jm: added safe full-read and full-write functions.  These
93
/* Dec 13 2001 jm: added safe full-read and full-write functions.  These
Lines 182-188 Link Here
182
    {
185
    {
183
      if(NULL != username)
186
      if(NULL != username)
184
      {
187
      {
185
	bytes2 = snprintf(header_buf,1024,"PROCESS %s\r\nUser: %s\r\nContent-length: %d\r\n\r\n",PROTOCOL_VERSION,username,bytes);
188
	bytes2 = snprintf(header_buf,1024,"PROCESS %s\r\nUser: %s\r\nContent-length: %d\r\n",PROTOCOL_VERSION,username,bytes);
186
      }
189
      }
187
      else
190
      else
188
      {
191
      {
Lines 191-196 Link Here
191
    }
194
    }
192
195
193
    full_write (out,header_buf,bytes2);
196
    full_write (out,header_buf,bytes2);
197
    if (ctx->user_prefs_file != NULL)
198
      send_user_prefs_file(out,username,ctx->user_prefs_file);
199
    full_write (out,"\r\n",2);
194
    full_write (out,ctx->msg_buf,bytes);
200
    full_write (out,ctx->msg_buf,bytes);
195
  }
201
  }
196
202
Lines 201-206 Link Here
201
  return ret;
207
  return ret;
202
}
208
}
203
209
210
static void send_user_prefs_file(int fd,char *username,FILE *up)
211
{
212
  char *home,linebuf[4096];
213
  int c,state=0,len=0;
214
215
  while((c=fgetc(up)) >= 0) {
216
    if((len+20) > 4095) {
217
      full_write(fd,linebuf,len);
218
      len=0;
219
    }
220
    /* Remove comments and unnecessary white space when sending prefs */
221
    switch (state) {
222
    case 0:
223
      /* In whitespace after newline (or start of file) */
224
      if (c=='#') {
225
        /* start of comment */
226
        state=2;
227
      } else if (c > ' ') {
228
        /* start of configuration directive */
229
        len+=sprintf(linebuf+len,"User-pref: %c",(char)c);
230
        state=1;
231
      }
232
      break;
233
    case 1:
234
      /* In configuration directive */
235
      if (c=='#') {
236
        /* comment at end of line */
237
        linebuf[len++] = '\r';
238
        linebuf[len++] = '\n';
239
        state=2;
240
      } else if (c=='\n') {
241
        /* End of line */
242
        linebuf[len++] = '\r';
243
        linebuf[len++] = '\n';
244
        state=0;
245
      } else {
246
        linebuf[len++] = (char)c;
247
      }
248
      break;
249
    case 2:
250
      /* In comment */
251
      if (c=='\n')
252
        state=0;
253
      break;
254
    }
255
  }
256
  fclose(up);
257
  full_write(fd,linebuf,len);
258
}
259
204
static int read_message(int in, int out, int max_size, struct spamc_context *ctx)
260
static int read_message(int in, int out, int max_size, struct spamc_context *ctx)
205
{
261
{
206
  size_t bytes;
262
  size_t bytes;
Lines 426-432 Link Here
426
}
482
}
427
483
428
int process_message(const char *hostname, int port, char *username, int max_size,
484
int process_message(const char *hostname, int port, char *username, int max_size,
429
        int in_fd, int out_fd, const int my_check_only, const int my_safe_fallback)
485
        int in_fd, int out_fd, const int my_check_only, const int my_safe_fallback, FILE *user_prefs_file)
430
{
486
{
431
  int exstatus;
487
  int exstatus;
432
  int mysock;
488
  int mysock;
Lines 443-448 Link Here
443
  ctx.amount_read = 0;
499
  ctx.amount_read = 0;
444
  ctx.check_only = my_check_only;
500
  ctx.check_only = my_check_only;
445
  ctx.safe_fallback = my_safe_fallback;
501
  ctx.safe_fallback = my_safe_fallback;
502
  ctx.user_prefs_file = user_prefs_file;
446
503
447
  /* first, try to mangle it directly into an addr.  This will work
504
  /* first, try to mangle it directly into an addr.  This will work
448
   * for numeric IP addresses, but not for hostnames...
505
   * for numeric IP addresses, but not for hostnames...
(-)Mail-SpamAssassin-2.40-virgin-20020827/spamd/libspamc.h (-1 / +2 lines)
Lines 17-23 Link Here
17
17
18
int process_message(const char *hostname, int port, char *username, 
18
int process_message(const char *hostname, int port, char *username, 
19
                    int max_size, int in_fd, int out_fd,
19
                    int max_size, int in_fd, int out_fd,
20
                    const int check_only, const int safe_fallback);
20
                    const int check_only, const int safe_fallback,
21
                    FILE *user_prefs_file);
21
22
22
#endif
23
#endif
23
24
(-)Mail-SpamAssassin-2.40-virgin-20020827/spamd/spamc.c (-2 / +17 lines)
Lines 34-39 Link Here
34
int SAFE_FALLBACK=-1; /* default to on now - CRH */
34
int SAFE_FALLBACK=-1; /* default to on now - CRH */
35
35
36
int CHECK_ONLY=0;
36
int CHECK_ONLY=0;
37
char *USER_PREFS_FILE=NULL;
37
38
38
39
39
void print_usage(void)
40
void print_usage(void)
Lines 53-59 Link Here
53
{
54
{
54
  int opt;
55
  int opt;
55
56
56
  while(-1 != (opt = getopt(argc,argv,"cd:fhp:t:s:u:")))
57
  while(-1 != (opt = getopt(argc,argv,"cd:fhj:p:t:s:u:")))
57
  {
58
  {
58
    switch(opt)
59
    switch(opt)
59
    {
60
    {
Lines 77-82 Link Here
77
	SAFE_FALLBACK = -1;
78
	SAFE_FALLBACK = -1;
78
	break;
79
	break;
79
      }
80
      }
81
    case 'j':
82
      {
83
        USER_PREFS_FILE = optarg;
84
        break;
85
      }
80
    case 'u':
86
    case 'u':
81
      {
87
      {
82
	*username = optarg;
88
	*username = optarg;
Lines 108-113 Link Here
108
  char *hostname = "127.0.0.1";
114
  char *hostname = "127.0.0.1";
109
  char *username = NULL;
115
  char *username = NULL;
110
  struct passwd *curr_user;
116
  struct passwd *curr_user;
117
  FILE *user_prefs_file=NULL;
111
118
112
  openlog ("spamc", LOG_CONS|LOG_PID, LOG_MAIL);
119
  openlog ("spamc", LOG_CONS|LOG_PID, LOG_MAIL);
113
  signal (SIGPIPE, SIG_IGN);
120
  signal (SIGPIPE, SIG_IGN);
Lines 124-129 Link Here
124
    username = curr_user->pw_name;
131
    username = curr_user->pw_name;
125
  }
132
  }
126
133
134
  if (USER_PREFS_FILE != NULL)
135
  if((user_prefs_file=fopen(USER_PREFS_FILE,"r"))==NULL) {
136
    perror("opening user prefs file");
137
    if(CHECK_ONLY) { printf("0/0\n"); return EX_NOTSPAM; } else { return EX_TEMPFAIL; }
138
  }
139
140
141
127
  return process_message(hostname, port, username, max_size, STDIN_FILENO,
142
  return process_message(hostname, port, username, max_size, STDIN_FILENO,
128
                STDOUT_FILENO, CHECK_ONLY, SAFE_FALLBACK);
143
                STDOUT_FILENO, CHECK_ONLY, SAFE_FALLBACK, user_prefs_file);
129
}
144
}
(-)Mail-SpamAssassin-2.40-virgin-20020827/spamd/spamd.raw (+13 lines)
Lines 67-72 Link Here
67
	'local!' => \$opt{'local'}, 'L' => \$opt{'local'},
67
	'local!' => \$opt{'local'}, 'L' => \$opt{'local'},
68
	'paranoid!' => \$opt{'paranoid'}, 'P' => \$opt{'paranoid'},
68
	'paranoid!' => \$opt{'paranoid'}, 'P' => \$opt{'paranoid'},
69
	'stop-at-threshold!' => \$opt{'stop-at-threshold'}, 'S' => \$opt{'stop-at-threshold'},
69
	'stop-at-threshold!' => \$opt{'stop-at-threshold'}, 'S' => \$opt{'stop-at-threshold'},
70
        'client-prefs!' => \$opt{'clientprefs'}, 'n' => \$opt{'clientprefs'}
71
70
72
71
        # will be stripped in future release
73
        # will be stripped in future release
72
	'add-from!' => sub { warn "The --add-from option has been removed\n" },
74
	'add-from!' => sub { warn "The --add-from option has been removed\n" },
Lines 317-322 Link Here
317
		    if (/^Content-length: ([0-9]*)\r\n/i) {
319
		    if (/^Content-length: ([0-9]*)\r\n/i) {
318
			$expected_length = $1;
320
			$expected_length = $1;
319
		    }
321
		    }
322
		    if ($opt{'clientprefs'}) {
323
			if (/^User-pref: (.*)\r\n/) {
324
			    $spamtest->{conf}->parse_scores_only($1);
325
			}
326
		    }
320
                }
327
                }
321
	    }
328
	    }
322
329
Lines 461-466 Link Here
461
		    if (/^Content-length: ([0-9]*)\r\n/i) {
468
		    if (/^Content-length: ([0-9]*)\r\n/i) {
462
			$expected_length = $1;
469
			$expected_length = $1;
463
		    }
470
		    }
471
		    if ($opt{'clientprefs'}) {
472
			if (/^User-pref: (.*)\r\n/) {
473
			    $spamtest->{conf}->parse_scores_only($1);
474
			}
475
		    }
464
                }
476
                }
465
	    }
477
	    }
466
478
Lines 851-856 Link Here
851
 -L, --local                        Use local tests only (no DNS)
863
 -L, --local                        Use local tests only (no DNS)
852
 -P, --paranoid                     Die upon user errors
864
 -P, --paranoid                     Die upon user errors
853
 -S, --stop-at-threshold            Stop tests after the threshold is reached
865
 -S, --stop-at-threshold            Stop tests after the threshold is reached
866
 -n, --client-prefs                 Accept user preferences from clients
854
867
855
868
856
=head1 OPTIONS
869
=head1 OPTIONS

Return to bug 579