/[pkg-mixmaster]/trunk/Mix/Src/rem1.c
ViewVC logotype

Diff of /trunk/Mix/Src/rem1.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 91 by rabbi, Wed Jul 10 01:58:49 2002 UTC revision 497 by weaselp, Tue Apr 29 12:03:32 2003 UTC
# Line 6  Line 6 
6     details.     details.
7    
8     Process Cypherpunk remailer messages     Process Cypherpunk remailer messages
9     $Id: rem1.c,v 1.5 2002/07/10 01:58:49 rabbi Exp $ */     $Id: rem1.c,v 1.9 2003/04/29 12:03:32 weaselp Exp $ */
10    
11    
12  #include "mix3.h"  #include "mix3.h"
13  #include <ctype.h>  #include <ctype.h>
14  #include <time.h>  #include <time.h>
15  #include <string.h>  #include <string.h>
16    #include <assert.h>
17    #include <stdlib.h>
18    
19  static int t1msg(BUFFER *in, int hdr);  static int t1msg(BUFFER *in, int hdr);
20    
# Line 72  void t1_esub(BUFFER *esub, BUFFER *subje Line 74  void t1_esub(BUFFER *esub, BUFFER *subje
74    buf_free(iv);    buf_free(iv);
75    buf_free(out);    buf_free(out);
76  }  }
77  #endif  #endif /* USE_IDEA */
78    
79  #define N(X) (isdigit(X) ? (X)-'0' : 0)  #define N(X) (isdigit(X) ? (X)-'0' : 0)
80    
# Line 88  static int readnum(BUFFER *b, int f) Line 90  static int readnum(BUFFER *b, int f)
90    return (num);    return (num);
91  }  }
92    
93    static int readdate(BUFFER *b)
94    {
95      int num = -1;
96    
97      if (b->length > 0)
98        num = parsedate(b->data);
99      return (num);
100    }
101    
102    static int reached_maxcount(BUFFER *md, int maxcount)
103    {
104      FILE *f;
105      char temp[LINELEN];
106      int count = 0;
107      int err = 0;
108      long then;
109      time_t now = time(NULL);
110    
111      assert(md->length > 0);
112    
113      encode(md, 0);
114    
115      f = mix_openfile(PGPMAXCOUNT, "a+"); /* create file if it does not exist */
116      fseek(f,0,SEEK_SET);
117      if (f == NULL) {
118        errlog(ERRORMSG, "Can't open %s!\n", PGPMAXCOUNT);
119        return (-1);
120      }
121      lock(f);
122      while (fgets(temp, sizeof(temp), f) != NULL)
123        if (sscanf(temp, "%ld", &then) &&
124            (then >= now - SECONDSPERDAY) &&
125            strstr (temp, md->data))
126          count++;
127    
128      if (count > maxcount)
129        err = 1;
130      else
131        fprintf(f, "%ld %s\n", (long) time(NULL), md->data);
132    
133      unlock(f);
134      fclose(f);
135      return (err);
136    }
137    
138  static int t1msg(BUFFER *in, int hdr)  static int t1msg(BUFFER *in, int hdr)
139       /* hdr = 1: mail header, hdr = 2: pasted header, hdr = 0: ignore */       /* hdr = 1: mail header, hdr = 2: pasted header, hdr = 0: ignore */
140  {  {
# Line 95  static int t1msg(BUFFER *in, int hdr) Line 142  static int t1msg(BUFFER *in, int hdr)
142    BUFFER *cutmarks, *to, *newsgroups, *ek, *ekdes, *ekcast, *esub, *subject;    BUFFER *cutmarks, *to, *newsgroups, *ek, *ekdes, *ekcast, *esub, *subject;
143    BUFFER *temp, *header, *out;    BUFFER *temp, *header, *out;
144    BUFFER *test, *testto, *remixto;    BUFFER *test, *testto, *remixto;
145      BUFFER *digest;
146    int err = 0;    int err = 0;
147    int encrypted = 0;    int encrypted = 0;
148    int type = -1;    int type = -1;
149    int latent = 0;    int latent = 0;
150    int remix = 0, repgp = 0;    int remix = 0, repgp = 0;
151    int inflate = 0;    int inflate = 0;
152      int maxsize = -1;
153      int maxcount = -1;
154      int maxdate = -2; /* -2 not used, -1 parse error */
155    
156    field = buf_new();    field = buf_new();
157    content = buf_new();    content = buf_new();
# Line 119  static int t1msg(BUFFER *in, int hdr) Line 170  static int t1msg(BUFFER *in, int hdr)
170    out = buf_new();    out = buf_new();
171    test = buf_new();    test = buf_new();
172    testto = buf_new();    testto = buf_new();
173      digest = buf_new();
174    
175    if (REMIX == 1)    if (REMIX == 1)
176      remix = 2;      remix = 2;
# Line 218  header: Line 270  header:
270          buf_appendc(remixto, ',');          buf_appendc(remixto, ',');
271          buf_cat(remixto, temp);          buf_cat(remixto, temp);
272        }        }
273      }      } else if (bufieq(field, "max-size") || bufieq(field, "maxsize"))
274          maxsize = readnum(content, 1024);
275        else if (bufieq(field, "max-count") || bufieq(field, "maxcount"))
276          maxcount = readnum(content, 1);
277        else if (bufieq(field, "max-date") || bufieq(field, "maxdate"))
278          maxdate = readdate(content);
279  #if USE_NSUB  #if USE_NSUB
280      else if (bufieq(field, "subject"))      else if (bufieq(field, "subject"))
281        buf_set(subject, content);        buf_set(subject, content);
282  #endif  #endif /* USE_NSUB */
283    }    }
284    
285    if (cutmarks->length > 0) {    if (cutmarks->length > 0) {
# Line 253  header: Line 310  header:
310      err = pgp_dearmor(in, temp);      err = pgp_dearmor(in, temp);
311      if (err == 0) {      if (err == 0) {
312        BUFFER *pass;        BUFFER *pass;
313          digest_sha1(temp, digest);
314    
315        pass = buf_new();        pass = buf_new();
316        buf_sets(pass, PASS_PHRASE);        buf_sets(pass, PASSPHRASE);
317        err = pgp_decrypt(temp, pass, NULL, NULL, NULL);        err = pgp_decrypt(temp, pass, NULL, NULL, NULL);
318        buf_free(pass);        buf_free(pass);
319      }      }
# Line 271  header: Line 329  header:
329        hdr = 0;        hdr = 0;
330        goto header;        goto header;
331      }      }
332  #endif  #endif /* USE_PGP */
333      if (testto->length == 0)      if (testto->length == 0)
334        errlog(ERRORMSG, "Can't decrypt PGP message.\n");        errlog(ERRORMSG, "Can't decrypt PGP message.\n");
335      buf_appends(test, "Can't decrypt PGP message.\n");      buf_appends(test, "Can't decrypt PGP message.\n");
# Line 281  header: Line 339  header:
339  #if 0  #if 0
340    if (err == -1)    if (err == -1)
341      goto end;      goto end;
342  #endif  #endif /* 0 */
343    
344    if (isline(line, HDRMARK) && (hdr == 0 || hdr == 1)) {    if (isline(line, HDRMARK) && (hdr == 0 || hdr == 1)) {
345      buf_getline(in, NULL);      buf_getline(in, NULL);
# Line 307  header: Line 365  header:
365      err = -2;      err = -2;
366      goto end;      goto end;
367    }    }
368      if (maxdate == -1) {
369        if (testto->length == 0)
370          errlog(LOG, "Could not parse Max-Date: header.\n");
371        buf_appends(test, "Could not parse Max-Date: header.\n");
372        err = -2;
373        goto end;
374      } else if (maxdate >= 0 && maxdate <= time(NULL)) {
375        if (testto->length == 0)
376          errlog(LOG, "Message is expired.\n");
377        buf_appends(test, "Message is expired.\n");
378        err = -2;
379        goto end;
380      }
381      if (maxsize >= 0 && in->length >= maxsize) {
382        if (testto->length == 0)
383          errlog(LOG, "Message Size exceeds Max-Size.\n");
384        buf_appends(test, "Message Size exceeds Max-Size.\n");
385        err = -2;
386        goto end;
387      }
388      if (maxcount >= 0) {
389        if (digest->length == 0) {
390          if (testto->length == 0)
391            errlog(LOG, "Max-Count yet not encrypted.\n");
392          buf_appends(test, "Max-Count yet not encrypted.\n");
393          err = -2;
394          goto end;
395        }
396        if (reached_maxcount(digest, maxcount)) {
397          if (testto->length == 0)
398            errlog(LOG, "Max-Count reached - discarding message.\n");
399          buf_appends(test, "Max-Count reached - discarding message.\n");
400          err = -2;
401          goto end;
402        }
403      }
404    
405    if (type == MSG_POST && subject->length == 0)    if (type == MSG_POST && subject->length == 0)
406      buf_sets(subject, "(no subject)");      buf_sets(subject, "(no subject)");
407    
# Line 320  header: Line 415  header:
415  #ifdef USE_IDEA  #ifdef USE_IDEA
416      if (esub->length > 0)      if (esub->length > 0)
417        t1_esub(esub, subject);        t1_esub(esub, subject);
418  #endif  #endif /* USE_IDEA */
419      buf_appendf(out, "Subject: %b\n", subject);      buf_appendf(out, "Subject: %b\n", subject);
420    }    }
421    buf_cat(out, header);    buf_cat(out, header);
# Line 328  header: Line 423  header:
423    
424  #if 0  #if 0
425    inflate -= in->length;    inflate -= in->length;
426  #endif  #endif /* 0 */
427    if (inflate > 0) {    if (inflate > 0) {
428      buf_setrnd(temp, inflate * 3 / 4);      buf_setrnd(temp, inflate * 3 / 4);
429      encode(temp, 64);      encode(temp, 64);
# Line 373  header: Line 468  header:
468      buf_appends(out, EKMARK);      buf_appends(out, EKMARK);
469      buf_nl(out);      buf_nl(out);
470      buf_cat(out, temp);      buf_cat(out, temp);
471  #else  #else /* end of USE_PGP */
472      err = -1;      err = -1;
473  #endif  #endif /* Else if not USE_PGP */
474    }    }
475    
476    if (type == -1) {    if (type == -1) {
# Line 449  end: Line 544  end:
544        remix = 0;        remix = 0;
545      if (remix && remixto->length == 0)      if (remix && remixto->length == 0)
546        buf_set(remixto, to);        buf_set(remixto, to);
547      if (remix && !repgp)      if (remix && !repgp && remixto->length != 0)
548        err = mix_encrypt(type, out, remixto->data, 1, line);        err = mix_encrypt(type, out, remixto->data, 1, line);
549      if (err != 0) {      if (err != 0) {
550        if (remix == 1 && !repgp)        if (remix == 1 && !repgp)
# Line 482  end: Line 577  end:
577    buf_free(header);    buf_free(header);
578    buf_free(test);    buf_free(test);
579    buf_free(testto);    buf_free(testto);
580      buf_free(digest);
581    return (err);    return (err);
582  }  }

Legend:
Removed from v.91  
changed lines
  Added in v.497

  ViewVC Help
Powered by ViewVC 1.1.5