| 6 |
details. |
details. |
| 7 |
|
|
| 8 |
Process remailer messages |
Process remailer messages |
| 9 |
$Id: rem.c,v 1.34 2003/03/31 17:40:53 weaselp Exp $ */ |
$Id: rem.c,v 1.35 2003/04/09 10:36:34 weaselp Exp $ */ |
| 10 |
|
|
| 11 |
|
|
| 12 |
#include "mix3.h" |
#include "mix3.h" |
| 34 |
#define REQUESTKEY 200 |
#define REQUESTKEY 200 |
| 35 |
#define REQUESTCONF 201 |
#define REQUESTCONF 201 |
| 36 |
#define REQUESTOPKEY 202 |
#define REQUESTOPKEY 202 |
| 37 |
|
#define REQUESTOTHER 203 |
| 38 |
#define BLOCKREQUEST 666 |
#define BLOCKREQUEST 666 |
| 39 |
#define DISABLED 99 |
#define DISABLED 99 |
| 40 |
|
|
| 41 |
#define CPUNKMSG 1 |
#define CPUNKMSG 1 |
| 42 |
#define MIXMSG 2 |
#define MIXMSG 2 |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
/** \brief get replies for additional information requests |
| 46 |
|
* |
| 47 |
|
* \param reply The buffer to store the reply in |
| 48 |
|
* \param file The file or name of information a user requested |
| 49 |
|
* \returns 0 on success; -1 if a ressource has a valid name |
| 50 |
|
* but doesn't exist; 1 if the ressource name isn't valid. |
| 51 |
|
* |
| 52 |
|
* This function returns additional information that a |
| 53 |
|
* user may have requested. One obvious example is help files |
| 54 |
|
* in different languages. We don't want to hack the source every |
| 55 |
|
* time we or somebody else adds a new language. |
| 56 |
|
* |
| 57 |
|
* Therefore we add a new directory where the operator may |
| 58 |
|
* just create new files (say "remailer-help-de"). If a user |
| 59 |
|
* requests that using this (file|ressource) name in the |
| 60 |
|
* subject line we respond by sending it. |
| 61 |
|
* |
| 62 |
|
* Perhaps we should build something that returns an index of |
| 63 |
|
* available files (FIXME if done). |
| 64 |
|
* |
| 65 |
|
* A ressource name needs to start with the string "remailer-" |
| 66 |
|
* and must only consist of alphanumerical characters and dashes. |
| 67 |
|
* Checking is done by this function and an error returned |
| 68 |
|
* if this is violated. |
| 69 |
|
*/ |
| 70 |
|
int get_otherrequests_reply(BUFFER *reply, BUFFER *filename) |
| 71 |
|
{ |
| 72 |
|
FILE *f = NULL; |
| 73 |
|
char c; |
| 74 |
|
int err; |
| 75 |
|
BUFFER *path; |
| 76 |
|
|
| 77 |
|
path = buf_new(); |
| 78 |
|
|
| 79 |
|
assert(filename); |
| 80 |
|
assert(reply); |
| 81 |
|
|
| 82 |
|
buf_rewind(filename); |
| 83 |
|
err = bufileft(filename, "remailer-"); |
| 84 |
|
if (! err) { |
| 85 |
|
err = 1; |
| 86 |
|
goto end; |
| 87 |
|
}; |
| 88 |
|
|
| 89 |
|
while ((c = buf_getc(filename)) != -1) { |
| 90 |
|
int ok = (c >= 'A' && c <= 'Z') || |
| 91 |
|
(c >= 'a' && c <= 'z') || |
| 92 |
|
(c >= '0' && c <= '9') || |
| 93 |
|
c == '-'; |
| 94 |
|
if (!ok) { |
| 95 |
|
err = 1; |
| 96 |
|
goto end; |
| 97 |
|
}; |
| 98 |
|
}; |
| 99 |
|
buf_rewind(filename); |
| 100 |
|
|
| 101 |
|
buf_appends(path, REQUESTDIR); |
| 102 |
|
buf_appends(path, "/"); |
| 103 |
|
buf_cat(path, filename); |
| 104 |
|
|
| 105 |
|
f = mix_openfile(path->data, "r"); |
| 106 |
|
if (f == NULL) { |
| 107 |
|
err = -1; |
| 108 |
|
goto end; |
| 109 |
|
}; |
| 110 |
|
|
| 111 |
|
buf_read(reply, f); |
| 112 |
|
err = 0; |
| 113 |
|
end: |
| 114 |
|
if (f) |
| 115 |
|
fclose(f); |
| 116 |
|
buf_free(path); |
| 117 |
|
return (err); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
int mix_decrypt(BUFFER *message) |
int mix_decrypt(BUFFER *message) |
| 121 |
{ |
{ |
| 122 |
int type = 0; |
int type = 0; |
| 123 |
BUFFER *field, *content; |
BUFFER *field, *content; |
| 124 |
BUFFER *to, *subject, *replyto, *reply; |
BUFFER *to, *subject, *replyto, *reply; |
| 125 |
|
BUFFER *otherrequest; |
| 126 |
FILE *f; |
FILE *f; |
| 127 |
BUFFER *block; |
BUFFER *block; |
| 128 |
int err = 0; |
int err = 0; |
| 136 |
reply = buf_new(); |
reply = buf_new(); |
| 137 |
block = buf_new(); |
block = buf_new(); |
| 138 |
subject = buf_new(); |
subject = buf_new(); |
| 139 |
|
otherrequest = buf_new(); |
| 140 |
buf_sets(subject, "Subject: Re: your mail"); |
buf_sets(subject, "Subject: Re: your mail"); |
| 141 |
|
|
| 142 |
buf_rewind(message); |
buf_rewind(message); |
| 185 |
type = REQUESTOPKEY; |
type = REQUESTOPKEY; |
| 186 |
else if (bufieq(content, "remailer-conf")) |
else if (bufieq(content, "remailer-conf")) |
| 187 |
type = REQUESTCONF; |
type = REQUESTCONF; |
| 188 |
else if (bufileft(content, "destination-block")) |
else if (bufileft(content, "remailer-")) { |
| 189 |
|
type = REQUESTOTHER; |
| 190 |
|
buf_set(otherrequest, content); |
| 191 |
|
} else if (bufileft(content, "destination-block")) |
| 192 |
type = BLOCKREQUEST; |
type = BLOCKREQUEST; |
| 193 |
else { |
else { |
| 194 |
buf_sets(subject, "Subject: "); |
buf_sets(subject, "Subject: "); |
| 241 |
if (err == 0) |
if (err == 0) |
| 242 |
err = sendmail(reply, REMAILERNAME, replyto); |
err = sendmail(reply, REMAILERNAME, replyto); |
| 243 |
break; |
break; |
| 244 |
|
case REQUESTOTHER: |
| 245 |
|
err = get_otherrequests_reply(reply, otherrequest); |
| 246 |
|
if (err == 0) |
| 247 |
|
err = sendmail(reply, REMAILERNAME, replyto); |
| 248 |
|
break; |
| 249 |
case CPUNKMSG: |
case CPUNKMSG: |
| 250 |
err = t1_decrypt(message); |
err = t1_decrypt(message); |
| 251 |
if (err != 0) { |
if (err != 0) { |
| 309 |
buf_free(reply); |
buf_free(reply); |
| 310 |
buf_free(block); |
buf_free(block); |
| 311 |
buf_free(subject); |
buf_free(subject); |
| 312 |
|
buf_free(otherrequest); |
| 313 |
return (err); |
return (err); |
| 314 |
} |
} |
| 315 |
|
|