diff options
Diffstat (limited to 'mailutils')
-rw-r--r-- | mailutils/mail.c | 29 | ||||
-rw-r--r-- | mailutils/mail.h | 4 | ||||
-rw-r--r-- | mailutils/makemime.c | 2 | ||||
-rw-r--r-- | mailutils/sendmail.c | 58 |
4 files changed, 72 insertions, 21 deletions
diff --git a/mailutils/mail.c b/mailutils/mail.c index 7af7edd6c..6726654f7 100644 --- a/mailutils/mail.c +++ b/mailutils/mail.c | |||
@@ -107,7 +107,7 @@ static char* FAST_FUNC parse_url(char *url, char **user, char **pass) | |||
107 | } | 107 | } |
108 | */ | 108 | */ |
109 | 109 | ||
110 | void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol) | 110 | static void encode_n_base64(const char *fname, const char *text, size_t len) |
111 | { | 111 | { |
112 | enum { | 112 | enum { |
113 | SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */ | 113 | SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */ |
@@ -116,18 +116,12 @@ void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol) | |||
116 | #define src_buf text | 116 | #define src_buf text |
117 | char src[SRC_BUF_SIZE]; | 117 | char src[SRC_BUF_SIZE]; |
118 | FILE *fp = fp; | 118 | FILE *fp = fp; |
119 | ssize_t len = len; | ||
120 | char dst_buf[DST_BUF_SIZE + 1]; | 119 | char dst_buf[DST_BUF_SIZE + 1]; |
121 | 120 | ||
122 | if (fname) { | 121 | if (fname) { |
123 | fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : (FILE *)text; | 122 | fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : stdin; |
124 | src_buf = src; | 123 | src_buf = src; |
125 | } else if (text) { | 124 | } |
126 | // though we do not call uuencode(NULL, NULL) explicitly | ||
127 | // still we do not want to break things suddenly | ||
128 | len = strlen(text); | ||
129 | } else | ||
130 | return; | ||
131 | 125 | ||
132 | while (1) { | 126 | while (1) { |
133 | size_t size; | 127 | size_t size; |
@@ -145,7 +139,7 @@ void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol) | |||
145 | // encode the buffer we just read in | 139 | // encode the buffer we just read in |
146 | bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64); | 140 | bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64); |
147 | if (fname) { | 141 | if (fname) { |
148 | puts(eol); | 142 | puts(""); |
149 | } else { | 143 | } else { |
150 | src_buf += size; | 144 | src_buf += size; |
151 | len -= size; | 145 | len -= size; |
@@ -157,6 +151,21 @@ void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol) | |||
157 | #undef src_buf | 151 | #undef src_buf |
158 | } | 152 | } |
159 | 153 | ||
154 | void FAST_FUNC printstr_base64(const char *text) | ||
155 | { | ||
156 | encode_n_base64(NULL, text, strlen(text)); | ||
157 | } | ||
158 | |||
159 | void FAST_FUNC printbuf_base64(const char *text, unsigned len) | ||
160 | { | ||
161 | encode_n_base64(NULL, text, len); | ||
162 | } | ||
163 | |||
164 | void FAST_FUNC printfile_base64(const char *fname) | ||
165 | { | ||
166 | encode_n_base64(fname, NULL, 0); | ||
167 | } | ||
168 | |||
160 | /* | 169 | /* |
161 | * get username and password from a file descriptor | 170 | * get username and password from a file descriptor |
162 | */ | 171 | */ |
diff --git a/mailutils/mail.h b/mailutils/mail.h index fa0c5b378..b14228a4a 100644 --- a/mailutils/mail.h +++ b/mailutils/mail.h | |||
@@ -34,4 +34,6 @@ void get_cred_or_die(int fd) FAST_FUNC; | |||
34 | 34 | ||
35 | char *send_mail_command(const char *fmt, const char *param) FAST_FUNC; | 35 | char *send_mail_command(const char *fmt, const char *param) FAST_FUNC; |
36 | 36 | ||
37 | void encode_base64(char *fname, const char *text, const char *eol) FAST_FUNC; | 37 | void printbuf_base64(const char *buf, unsigned len) FAST_FUNC; |
38 | void printstr_base64(const char *buf) FAST_FUNC; | ||
39 | void printfile_base64(const char *fname) FAST_FUNC; | ||
diff --git a/mailutils/makemime.c b/mailutils/makemime.c index 577bcde39..7539d5134 100644 --- a/mailutils/makemime.c +++ b/mailutils/makemime.c | |||
@@ -234,7 +234,7 @@ int makemime_main(int argc UNUSED_PARAM, char **argv) | |||
234 | , G.opt_charset | 234 | , G.opt_charset |
235 | , bb_get_last_path_component_strip(*argv) | 235 | , bb_get_last_path_component_strip(*argv) |
236 | ); | 236 | ); |
237 | encode_base64(*argv++, (const char *)stdin, ""); | 237 | printfile_base64(*argv++); |
238 | } | 238 | } |
239 | 239 | ||
240 | // put multipart footer | 240 | // put multipart footer |
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index 0170f2870..32c50ba84 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c | |||
@@ -36,7 +36,9 @@ | |||
36 | //usage: "\n openssl s_client -quiet -tls1 -connect smtp.gmail.com:465" | 36 | //usage: "\n openssl s_client -quiet -tls1 -connect smtp.gmail.com:465" |
37 | //usage: "\n $SMTP_ANTISPAM_DELAY: seconds to wait after helper connect" | 37 | //usage: "\n $SMTP_ANTISPAM_DELAY: seconds to wait after helper connect" |
38 | //usage: "\n -S HOST[:PORT] Server (default $SMTPHOST or 127.0.0.1)" | 38 | //usage: "\n -S HOST[:PORT] Server (default $SMTPHOST or 127.0.0.1)" |
39 | //usage: "\n -amLOGIN Log in using AUTH LOGIN (-amCRAM-MD5 not supported)" | 39 | //usage: "\n -amLOGIN Log in using AUTH LOGIN" |
40 | //usage: "\n -amPLAIN or AUTH PLAIN" | ||
41 | //usage: "\n (-amCRAM-MD5 not supported)" | ||
40 | //usage: "\n -auUSER Username for AUTH" | 42 | //usage: "\n -auUSER Username for AUTH" |
41 | //usage: "\n -apPASS Password for AUTH" | 43 | //usage: "\n -apPASS Password for AUTH" |
42 | //usage: "\n" | 44 | //usage: "\n" |
@@ -248,6 +250,8 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
248 | OPT_S = 1 << 6, // specify connection string | 250 | OPT_S = 1 << 6, // specify connection string |
249 | OPT_a = 1 << 7, // authentication tokens | 251 | OPT_a = 1 << 7, // authentication tokens |
250 | OPT_v = 1 << 8, // verbosity | 252 | OPT_v = 1 << 8, // verbosity |
253 | //--- for -amMETHOD | ||
254 | OPT_am_plain = 1 << 9, // AUTH PLAIN | ||
251 | }; | 255 | }; |
252 | 256 | ||
253 | // init global variables | 257 | // init global variables |
@@ -286,9 +290,14 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
286 | G.user = xstrdup(a+1); | 290 | G.user = xstrdup(a+1); |
287 | if ('p' == a[0]) | 291 | if ('p' == a[0]) |
288 | G.pass = xstrdup(a+1); | 292 | G.pass = xstrdup(a+1); |
289 | // N.B. we support only AUTH LOGIN so far | 293 | if ('m' == a[0]) { |
290 | //if ('m' == a[0]) | 294 | if ((a[1] | 0x20) == 'p') // PLAIN |
291 | // G.method = xstrdup(a+1); | 295 | opts |= OPT_am_plain; |
296 | else if ((a[1] | 0x20) == 'l') // LOGIN | ||
297 | ; /* do nothing (this is the default) */ | ||
298 | else | ||
299 | bb_error_msg_and_die("unsupported AUTH method %s", a+1); | ||
300 | } | ||
292 | } | 301 | } |
293 | // N.B. list == NULL here | 302 | // N.B. list == NULL here |
294 | //bb_error_msg("OPT[%x] AU[%s], AP[%s], AM[%s], ARGV[%s]", opts, au, ap, am, *argv); | 303 | //bb_error_msg("OPT[%x] AU[%s], AP[%s], AM[%s], ARGV[%s]", opts, au, ap, am, *argv); |
@@ -348,13 +357,44 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
348 | 357 | ||
349 | // perform authentication | 358 | // perform authentication |
350 | if (opts & OPT_a) { | 359 | if (opts & OPT_a) { |
351 | smtp_check("AUTH LOGIN", 334); | 360 | // read credentials unless they are given via -a[up] options |
352 | // we must read credentials unless they are given via -a[up] options | ||
353 | if (!G.user || !G.pass) | 361 | if (!G.user || !G.pass) |
354 | get_cred_or_die(4); | 362 | get_cred_or_die(4); |
355 | encode_base64(NULL, G.user, NULL); | 363 | if (opts & OPT_am_plain) { |
356 | smtp_check("", 334); | 364 | // C: AUTH PLAIN |
357 | encode_base64(NULL, G.pass, NULL); | 365 | // S: 334 |
366 | // C: base64encoded(auth<NUL>user<NUL>pass) | ||
367 | // S: 235 2.7.0 Authentication successful | ||
368 | //Note: a shorter format is allowed: | ||
369 | // C: AUTH PLAIN base64encoded(auth<NUL>user<NUL>pass) | ||
370 | // S: 235 2.7.0 Authentication successful | ||
371 | smtp_check("AUTH PLAIN", 334); | ||
372 | { | ||
373 | unsigned user_len = strlen(G.user); | ||
374 | unsigned pass_len = strlen(G.pass); | ||
375 | unsigned sz = 1 + user_len + 1 + pass_len; | ||
376 | char plain_auth[sz + 1]; | ||
377 | // the format is: | ||
378 | // "authorization identity<NUL>username<NUL>password" | ||
379 | // authorization identity is empty. | ||
380 | plain_auth[0] = '\0'; | ||
381 | strcpy(stpcpy(plain_auth + 1, G.user) + 1, G.pass); | ||
382 | printbuf_base64(plain_auth, sz); | ||
383 | } | ||
384 | } else { | ||
385 | // C: AUTH LOGIN | ||
386 | // S: 334 VXNlcm5hbWU6 | ||
387 | // ^^^^^^^^^^^^ server says "Username:" | ||
388 | // C: base64encoded(user) | ||
389 | // S: 334 UGFzc3dvcmQ6 | ||
390 | // ^^^^^^^^^^^^ server says "Password:" | ||
391 | // C: base64encoded(pass) | ||
392 | // S: 235 2.7.0 Authentication successful | ||
393 | smtp_check("AUTH LOGIN", 334); | ||
394 | printstr_base64(G.user); | ||
395 | smtp_check("", 334); | ||
396 | printstr_base64(G.pass); | ||
397 | } | ||
358 | smtp_check("", 235); | 398 | smtp_check("", 235); |
359 | } | 399 | } |
360 | 400 | ||