password expires today
[ghsmtp.git] / smtp.cpp
blob071812832735cfc14e62da9aee517a564d36715e
1 #include <gflags/gflags.h>
2 namespace gflags {
5 // These need to be at least the length of any string it's trying to match.
6 DEFINE_uint64(cmd_bfr_size, 4 * 1024, "command parser buffer size");
7 DEFINE_uint64(data_bfr_size, 64 * 1024, "data parser buffer size");
9 DEFINE_uint64(max_xfer_size, 64 * 1024, "maximum BDAT transfer size");
11 #include <fstream>
13 #include "Session.hpp"
14 #include "esc.hpp"
15 #include "fs.hpp"
16 #include "iobuffer.hpp"
17 #include "osutil.hpp"
19 #include <cstdlib>
20 #include <memory>
22 #include <signal.h>
24 #include <tao/pegtl.hpp>
25 #include <tao/pegtl/contrib/abnf.hpp>
27 using namespace tao::pegtl;
28 using namespace tao::pegtl::abnf;
30 namespace RFC5321 {
32 struct Ctx {
33 Session session;
35 std::string mb_loc;
36 std::string mb_dom;
38 std::pair<std::string, std::string> param;
39 std::unordered_map<std::string, std::string> parameters;
41 std::streamsize chunk_size;
43 Ctx(fs::path config_path, std::function<void(void)> read_hook)
44 : session(config_path, read_hook)
49 // clang-format off
51 struct UTF8_tail : range<'\x80', '\xBF'> {};
53 struct UTF8_1 : range<'\x00', '\x7F'> {};
55 struct UTF8_2 : seq<range<'\xC2', '\xDF'>, UTF8_tail> {};
57 struct UTF8_3 : sor<seq<one<'\xE0'>, range<'\xA0', '\xBF'>, UTF8_tail>,
58 seq<range<'\xE1', '\xEC'>, rep<2, UTF8_tail>>,
59 seq<one<'\xED'>, range<'\x80', '\x9F'>, UTF8_tail>,
60 seq<range<'\xEE', '\xEF'>, rep<2, UTF8_tail>>> {};
62 struct UTF8_4 : sor<seq<one<'\xF0'>, range<'\x90', '\xBF'>, rep<2, UTF8_tail>>,
63 seq<range<'\xF1', '\xF3'>, rep<3, UTF8_tail>>,
64 seq<one<'\xF4'>, range<'\x80', '\x8F'>, rep<2, UTF8_tail>>> {};
66 struct UTF8_non_ascii : sor<UTF8_2, UTF8_3, UTF8_4> {};
68 struct quoted_pair : seq<one<'\\'>, sor<VCHAR, WSP>> {};
70 using dot = one<'.'>;
71 using colon = one<':'>;
72 using dash = one<'-'>;
74 struct u_let_dig : sor<ALPHA, DIGIT, UTF8_non_ascii> {};
76 struct u_ldh_tail : star<sor<seq<plus<one<'-'>>, u_let_dig>, u_let_dig>> {};
78 struct u_label : seq<u_let_dig, u_ldh_tail> {};
80 struct let_dig : sor<ALPHA, DIGIT> {};
82 struct ldh_tail : star<sor<seq<plus<one<'-'>>, let_dig>, let_dig>> {};
84 struct ldh_str : seq<let_dig, ldh_tail> {};
86 // struct label : seq<let_dig, opt<ldh_str>> {};
88 struct sub_domain : u_label {};
90 struct domain : list_tail<sub_domain, dot> {};
92 struct dec_octet : sor<seq<string<'2','5'>, range<'0','5'>>,
93 seq<one<'2'>, range<'0','4'>, DIGIT>,
94 seq<range<'0', '1'>, rep<2, DIGIT>>,
95 rep_min_max<1, 2, DIGIT>> {};
97 struct IPv4_address_literal
98 : seq<dec_octet, dot, dec_octet, dot, dec_octet, dot, dec_octet> {};
100 struct h16 : rep_min_max<1, 4, HEXDIG> {};
102 struct ls32 : sor<seq<h16, colon, h16>, IPv4_address_literal> {};
104 struct dcolon : two<':'> {};
106 struct IPv6address : sor<seq< rep<6, h16, colon>, ls32>,
107 seq< dcolon, rep<5, h16, colon>, ls32>,
108 seq<opt<h16 >, dcolon, rep<4, h16, colon>, ls32>,
109 seq<opt<h16, opt< colon, h16>>, dcolon, rep<3, h16, colon>, ls32>,
110 seq<opt<h16, rep_opt<2, colon, h16>>, dcolon, rep<2, h16, colon>, ls32>,
111 seq<opt<h16, rep_opt<3, colon, h16>>, dcolon, h16, colon, ls32>,
112 seq<opt<h16, rep_opt<4, colon, h16>>, dcolon, ls32>,
113 seq<opt<h16, rep_opt<5, colon, h16>>, dcolon, h16>,
114 seq<opt<h16, rep_opt<6, colon, h16>>, dcolon >> {};
116 struct IPv6_address_literal : seq<TAO_PEGTL_ISTRING("IPv6:"), IPv6address> {};
118 struct dcontent : ranges<33, 90, 94, 126> {};
120 struct standardized_tag : ldh_str {};
122 struct general_address_literal : seq<standardized_tag, colon, plus<dcontent>> {};
124 // See rfc 5321 Section 4.1.3
125 struct address_literal : seq<one<'['>,
126 sor<IPv4_address_literal,
127 IPv6_address_literal,
128 general_address_literal>,
129 one<']'>> {};
131 struct at_domain : seq<one<'@'>, domain> {};
133 struct a_d_l : list<at_domain, one<','>> {};
135 // The qtextSMTP rule explained: it's ASCII...
136 // excluding all the control chars below SPACE
137 // 34 '"' the double quote
138 // 92 '\\' the back slash
139 // DEL
140 // So including:
141 // 32-33: ' ' and '!'
142 // 35-91: "#$%&'()*+,-./" 0-9 ":;<=>?@" A-Z '['
143 // 93-126: "]^_`" a-z "{|}~"
145 struct qtextSMTP : sor<ranges<32, 33, 35, 91, 93, 126>, UTF8_non_ascii> {};
147 struct graphic : range<32, 126> {};
149 struct quoted_pairSMTP : seq<one<'\\'>, graphic> {};
151 struct qcontentSMTP : sor<qtextSMTP, quoted_pairSMTP> {};
153 struct quoted_string : seq<one<'"'>, star<qcontentSMTP>, one<'"'>> {};
155 // excluded from atext are the “specials”: "()<>[]:;@\\,."
157 struct atext : sor<ALPHA, DIGIT,
158 one<'!', '#',
159 '$', '%',
160 '&', '\'',
161 '*', '+',
162 '-', '/',
163 '=', '?',
164 '^', '_',
165 '`', '{',
166 '|', '}',
167 '~'>,
168 UTF8_non_ascii> {};
170 struct atom : plus<atext> {};
172 struct dot_string : list<atom, dot> {};
174 struct local_part : sor<dot_string, quoted_string> {};
176 struct non_local_part : sor<domain, address_literal> {};
178 struct mailbox : seq<local_part, one<'@'>, non_local_part> {};
180 struct path : seq<one<'<'>, seq<opt<seq<a_d_l, colon>>, mailbox, one<'>'>>> {};
182 struct bounce_path : TAO_PEGTL_ISTRING("<>") {};
184 struct reverse_path : sor<path, bounce_path> {};
186 struct magic_postmaster : TAO_PEGTL_ISTRING("<Postmaster>") {};
188 struct forward_path : sor<path, magic_postmaster> {};
190 struct esmtp_keyword : seq<sor<ALPHA, DIGIT>, star<sor<ALPHA, DIGIT, dash>>> {};
192 struct esmtp_value : plus<sor<range<33, 60>, range<62, 126>, UTF8_non_ascii>> {};
194 struct esmtp_param : seq<esmtp_keyword, opt<seq<one<'='>, esmtp_value>>> {};
196 struct mail_parameters : list<esmtp_param, SP> {};
198 struct rcpt_parameters : list<esmtp_param, SP> {};
200 struct string : sor<quoted_string, atom> {};
202 struct helo : seq<TAO_PEGTL_ISTRING("HELO"),
204 sor<domain, address_literal>,
205 CRLF> {};
207 struct ehlo : seq<TAO_PEGTL_ISTRING("EHLO"),
209 sor<domain, address_literal>,
210 CRLF> {};
212 struct mail_from : seq<TAO_PEGTL_ISTRING("MAIL"),
213 TAO_PEGTL_ISTRING(" FROM:"),
214 opt<SP>, // common enough error, we'll allow it
215 reverse_path,
216 opt<seq<SP, mail_parameters>>,
217 CRLF> {};
219 struct rcpt_to : seq<TAO_PEGTL_ISTRING("RCPT"),
220 TAO_PEGTL_ISTRING(" TO:"),
221 opt<SP>, // common error
222 forward_path,
223 opt<seq<SP, rcpt_parameters>>,
224 CRLF> {};
226 struct chunk_size : plus<DIGIT> {};
228 struct last : TAO_PEGTL_ISTRING("LAST") {};
230 struct bdat : seq<TAO_PEGTL_ISTRING("BDAT"), SP, chunk_size, CRLF> {};
232 struct bdat_last : seq<TAO_PEGTL_ISTRING("BDAT"), SP, chunk_size, SP, last, CRLF> {};
234 struct data : seq<TAO_PEGTL_ISTRING("DATA"), CRLF> {};
236 struct data_end : seq<dot, CRLF> {};
238 struct data_blank : CRLF {};
240 // Rules for strict RFC adherence:
242 // RFC 5321 text line length section 4.5.3.1.6.
243 struct data_dot
244 : seq<one<'.'>, rep_min_max<1, 998, not_one<'\r', '\n'>>, CRLF> {};
246 struct data_plain : seq<rep_min_max<1, 998, not_one<'\r', '\n'>>, CRLF> {};
248 // But let's accept real-world crud, up to a point...
250 struct anything_else : seq<star<not_one<'\n'>>, one<'\n'>> {};
252 // This particular crud will trigger an error return with the "no bare
253 // LF" message.
255 struct not_data_end : seq<dot, LF> {};
257 struct data_line : sor<at<data_end>,
258 seq<sor<data_blank,
259 data_dot,
260 data_plain,
261 not_data_end,
262 anything_else>,
263 discard>> {};
265 struct data_grammar : until<data_end, data_line> {};
267 struct rset : seq<TAO_PEGTL_ISTRING("RSET"), CRLF> {};
269 struct noop : seq<TAO_PEGTL_ISTRING("NOOP"), opt<seq<SP, string>>, CRLF> {};
271 struct vrfy : seq<TAO_PEGTL_ISTRING("VRFY"), opt<seq<SP, string>>, CRLF> {};
273 struct help : seq<TAO_PEGTL_ISTRING("HELP"), opt<seq<SP, string>>, CRLF> {};
275 struct starttls
276 : seq<TAO_PEGTL_ISTRING("STAR"), TAO_PEGTL_ISTRING("TTLS"), CRLF> {};
278 struct quit : seq<TAO_PEGTL_ISTRING("QUIT"), CRLF> {};
280 // Anti-AUTH support
282 // base64-char = ALPHA / DIGIT / "+" / "/"
283 // ;; Case-sensitive
285 struct base64_char : sor<ALPHA, DIGIT, one<'+', '/'>> {};
287 // base64-terminal = (2base64-char "==") / (3base64-char "=")
289 struct base64_terminal : sor<seq<rep<2, base64_char>, TAO_PEGTL_ISTRING("==")>,
290 seq<rep<3, base64_char>, one<'='>>
291 > {};
293 // base64 = base64-terminal /
294 // ( 1*(4base64-char) [base64-terminal] )
296 struct base64 : sor<base64_terminal,
297 seq<plus<rep<4, base64_char>>,
298 opt<base64_terminal>>
299 > {};
301 // initial-response= base64 / "="
303 struct initial_response : sor<base64, one<'='>> {};
305 // cancel-response = "*"
307 struct cancel_response : one<'*'> {};
309 struct UPPER_ALPHA : range<'A', 'Z'> {};
311 using HYPHEN = one<'-'>;
312 using UNDERSCORE = one<'_'>;
314 struct mech_char : sor<UPPER_ALPHA, DIGIT, HYPHEN, UNDERSCORE> {};
315 struct sasl_mech : rep_min_max<1, 20, mech_char> {};
317 // auth-command = "AUTH" SP sasl-mech [SP initial-response]
318 // *(CRLF [base64]) [CRLF cancel-response]
319 // CRLF
320 // ;; <sasl-mech> is defined in RFC 4422
322 struct auth : seq<TAO_PEGTL_ISTRING("AUTH"), SP, sasl_mech,
323 opt<seq<SP, initial_response>>,
324 // star<CRLF, opt<base64>>,
325 // opt<seq<CRLF, cancel_response>>,
326 CRLF> {};
327 // bad commands:
329 struct bogus_cmd_short : seq<rep_min_max<0, 3, not_one<'\r', '\n'>>, CRLF> {};
330 struct bogus_cmd_long : seq<rep_min_max<4, 1000, not_one<'\r', '\n'>>, CRLF> {};
332 // commands in size order
334 struct any_cmd : seq<sor<bogus_cmd_short,
335 data,
336 quit,
337 rset,
338 noop,
339 vrfy,
340 help,
341 helo,
342 ehlo,
343 bdat,
344 bdat_last,
345 starttls,
346 rcpt_to,
347 mail_from,
348 auth,
349 bogus_cmd_long,
350 anything_else>,
351 discard> {};
353 struct grammar : plus<any_cmd> {};
355 // clang-format on
357 template <typename Rule>
358 struct action : nothing<Rule> {
361 template <typename Rule>
362 struct data_action : nothing<Rule> {
365 template <>
366 struct action<esmtp_keyword> {
367 template <typename Input>
368 static void apply(Input const& in, Ctx& ctx)
370 ctx.param.first = in.string();
374 template <>
375 struct action<bogus_cmd_short> {
376 template <typename Input>
377 static void apply(Input const& in, Ctx& ctx)
379 LOG(INFO) << "bogus_cmd_short";
380 ctx.session.cmd_unrecognized(in.string());
384 template <>
385 struct action<bogus_cmd_long> {
386 template <typename Input>
387 static void apply(Input const& in, Ctx& ctx)
389 LOG(INFO) << "bogus_cmd_long";
390 ctx.session.cmd_unrecognized(in.string());
394 template <>
395 struct action<anything_else> {
396 template <typename Input>
397 static void apply(Input const& in, Ctx& ctx)
399 LOG(INFO) << "anything_else";
400 ctx.session.cmd_unrecognized(in.string());
404 template <>
405 struct action<esmtp_value> {
406 template <typename Input>
407 static void apply(Input const& in, Ctx& ctx)
409 ctx.param.second = in.string();
413 template <>
414 struct action<esmtp_param> {
415 template <typename Input>
416 static void apply(Input const& in, Ctx& ctx)
418 ctx.parameters.insert(ctx.param);
419 ctx.param.first.clear();
420 ctx.param.second.clear();
424 template <>
425 struct action<local_part> {
426 template <typename Input>
427 static void apply(Input const& in, Ctx& ctx)
429 ctx.mb_loc = in.string();
430 // RFC 5321, section 4.5.3.1.1.
431 if (ctx.mb_loc.length() > 64) {
432 LOG(WARNING) << "local part too long " << ctx.mb_loc;
437 template <>
438 struct action<non_local_part> {
439 template <typename Input>
440 static void apply(Input const& in, Ctx& ctx)
442 ctx.mb_dom = in.string();
443 // RFC 5321, section 4.5.3.1.2.
444 if (ctx.mb_dom.length() > 255) {
445 LOG(WARNING) << "domain name or number too long " << ctx.mb_dom;
450 template <>
451 struct action<magic_postmaster> {
452 static void apply0(Ctx& ctx)
454 ctx.mb_loc = std::string{"Postmaster"};
455 ctx.mb_dom.clear();
459 template <>
460 struct action<helo> {
461 template <typename Input>
462 static void apply(Input const& in, Ctx& ctx)
464 auto const b = begin(in) + 5; // +5 for the length of "HELO "
465 auto const e = std::find(b, end(in) - 2, ' '); // -2 for the CRLF
466 ctx.session.helo(std::string_view(b, e - b));
470 template <>
471 struct action<ehlo> {
472 template <typename Input>
473 static void apply(Input const& in, Ctx& ctx)
475 auto const b = begin(in) + 5; // +5 for the length of "EHLO "
476 auto const e = std::find(b, end(in) - 2, ' '); // -2 for the CRLF
477 ctx.session.ehlo(std::string_view(b, e - b));
481 template <>
482 struct action<mail_from> {
483 static void apply0(Ctx& ctx)
485 ctx.session.mail_from(Mailbox{ctx.mb_loc, ctx.mb_dom}, ctx.parameters);
486 ctx.mb_loc.clear();
487 ctx.mb_dom.clear();
488 ctx.parameters.clear();
492 template <>
493 struct action<rcpt_to> {
494 static void apply0(Ctx& ctx)
496 ctx.session.rcpt_to(Mailbox{ctx.mb_loc, ctx.mb_dom}, ctx.parameters);
497 ctx.mb_loc.clear();
498 ctx.mb_dom.clear();
499 ctx.parameters.clear();
503 template <>
504 struct action<chunk_size> {
505 template <typename Input>
506 static void apply(Input const& in, Ctx& ctx)
508 ctx.chunk_size = std::strtoull(in.string().c_str(), nullptr, 10);
512 void bdat_act(Ctx& ctx, bool last)
514 auto status_returned = false;
516 if (!ctx.session.bdat_start(ctx.chunk_size))
517 status_returned = true;
519 auto to_xfer = ctx.chunk_size;
521 auto const bfr_size{std::min(to_xfer, std::streamsize(FLAGS_max_xfer_size))};
522 iobuffer<char> bfr(bfr_size);
524 while (to_xfer) {
525 auto const xfer_sz{std::min(to_xfer, bfr_size)};
527 ctx.session.in().read(bfr.data(), xfer_sz);
528 if (!ctx.session.in()) {
529 LOG(ERROR) << "attempt to read " << xfer_sz << " octets but only got "
530 << ctx.session.in().gcount();
531 if (ctx.session.maxed_out()) {
532 LOG(ERROR) << "input maxed out";
533 if (!status_returned)
534 ctx.session.bdat_size_error();
536 else if (ctx.session.timed_out()) {
537 LOG(ERROR) << "input timed out";
538 if (!status_returned)
539 ctx.session.bdat_io_error();
541 else if (ctx.session.in().eof()) {
542 LOG(ERROR) << "EOF in BDAT";
543 if (!status_returned)
544 ctx.session.bdat_io_error();
546 else {
547 LOG(ERROR) << "I/O error in BDAT";
548 if (!status_returned)
549 ctx.session.bdat_io_error();
551 return;
553 if (!ctx.session.msg_write(bfr.data(), xfer_sz)) {
554 if (!status_returned)
555 ctx.session.bdat_size_error();
556 status_returned = true;
559 to_xfer -= xfer_sz;
562 if (!status_returned) {
563 ctx.session.bdat_done(ctx.chunk_size, last);
567 template <>
568 struct action<bdat> {
569 static void apply0(Ctx& ctx)
571 bdat_act(ctx, false);
575 template <>
576 struct action<bdat_last> {
577 static void apply0(Ctx& ctx)
579 bdat_act(ctx, true);
583 template <>
584 struct data_action<data_end> {
585 static void apply0(Ctx& ctx) { ctx.session.data_done(); }
588 template <>
589 struct data_action<data_blank> {
590 static void apply0(Ctx& ctx)
592 constexpr char CRLF[]{'\r', '\n'};
593 ctx.session.msg_write(CRLF, sizeof(CRLF));
597 template <>
598 struct data_action<data_plain> {
599 template <typename Input>
600 static void apply(Input const& in, Ctx& ctx)
602 auto const len{end(in) - begin(in)};
603 ctx.session.msg_write(begin(in), len);
607 template <>
608 struct data_action<data_dot> {
609 template <typename Input>
610 static void apply(Input const& in, Ctx& ctx)
612 auto const len{end(in) - begin(in) - 1};
613 ctx.session.msg_write(begin(in) + 1, len);
617 template <>
618 struct data_action<not_data_end> {
619 static void apply0(Ctx& ctx) __attribute__((noreturn))
621 ctx.session.bare_lf();
625 template <>
626 struct data_action<anything_else> {
627 template <typename Input>
628 static void apply(Input const& in, Ctx& ctx)
630 LOG(WARNING) << "garbage in data stream: \"" << esc(in.string()) << "\"";
631 auto const len{end(in) - begin(in)};
632 if (len)
633 ctx.session.msg_write(begin(in), len);
634 if (len > 1000) {
635 LOG(WARNING) << "line too long at " << len << " octets";
640 template <>
641 struct action<data> {
642 template <typename Input>
643 static void apply(Input const& in, Ctx& ctx)
645 if (ctx.session.data_start()) {
646 auto din = istream_input<eol::crlf, 1>(ctx.session.in(),
647 FLAGS_data_bfr_size, "data");
648 try {
649 if (!parse_nested<RFC5321::data_grammar, RFC5321::data_action>(in, din,
650 ctx)) {
651 ctx.session.log_stats();
652 if (!(ctx.session.maxed_out() || ctx.session.timed_out())) {
653 ctx.session.error("bad DATA syntax");
656 return;
658 catch (parse_error const& e) {
659 LOG(WARNING) << e.what();
660 ctx.session.error("unable to parse DATA stream");
662 catch (std::exception const& e) {
663 LOG(WARNING) << e.what();
664 ctx.session.error("unknown problem in DATA stream");
670 template <>
671 struct action<rset> {
672 static void apply0(Ctx& ctx) { ctx.session.rset(); }
675 template <typename Input>
676 std::string_view get_string_view(Input const& in)
678 auto const b = begin(in) + 4;
679 auto const len = end(in) - b;
680 auto str = std::string_view(b, len);
681 if (str.front() == ' ')
682 str.remove_prefix(1);
683 return str;
686 template <>
687 struct action<noop> {
688 template <typename Input>
689 static void apply(Input const& in, Ctx& ctx)
691 auto const str = get_string_view(in);
692 ctx.session.noop(str);
696 template <>
697 struct action<vrfy> {
698 template <typename Input>
699 static void apply(Input const& in, Ctx& ctx)
701 auto const str = get_string_view(in);
702 ctx.session.vrfy(str);
706 template <>
707 struct action<help> {
708 template <typename Input>
709 static void apply(Input const& in, Ctx& ctx)
711 auto const str = get_string_view(in);
712 ctx.session.help(str);
716 template <>
717 struct action<starttls> {
718 static void apply0(Ctx& ctx) { ctx.session.starttls(); }
721 template <>
722 struct action<quit> {
723 static void apply0(Ctx& ctx) __attribute__((noreturn)) { ctx.session.quit(); }
726 template <>
727 struct action<auth> {
728 static void apply0(Ctx& ctx) __attribute__((noreturn)) { ctx.session.auth(); }
730 } // namespace RFC5321
732 void timeout(int signum) __attribute__((noreturn));
733 void timeout(int signum)
735 const char errmsg[] = "421 4.4.2 time-out\r\n";
736 write(STDOUT_FILENO, errmsg, sizeof errmsg - 1);
737 _Exit(1);
740 int main(int argc, char* argv[])
742 std::ios::sync_with_stdio(false);
744 { // Need to work with either namespace.
745 using namespace gflags;
746 using namespace google;
747 ParseCommandLineFlags(&argc, &argv, true);
750 // Set timeout signal handler to limit total run time.
751 struct sigaction sact {
753 PCHECK(sigemptyset(&sact.sa_mask) == 0);
754 sact.sa_flags = 0;
755 sact.sa_handler = timeout;
756 PCHECK(sigaction(SIGALRM, &sact, nullptr) == 0);
758 auto const log_dir{getenv("GOOGLE_LOG_DIR")};
759 if (log_dir) {
760 error_code ec;
761 fs::create_directories(log_dir, ec);
764 google::InitGoogleLogging(argv[0]);
766 std::unique_ptr<RFC5321::Ctx> ctx;
768 // Don't wait for STARTTLS to fail if no cert.
769 auto const config_path = osutil::get_config_dir();
770 auto const certs = osutil::list_directory(config_path, Config::cert_fn_re);
771 CHECK_GE(certs.size(), 1) << "no certs found";
773 auto const read_hook{[&ctx]() { ctx->session.flush(); }};
774 ctx = std::make_unique<RFC5321::Ctx>(config_path, read_hook);
776 ctx->session.greeting();
778 istream_input<eol::crlf, 1> in{ctx->session.in(), FLAGS_cmd_bfr_size,
779 "session"};
781 int ret = 0;
782 try {
783 ret = !parse<RFC5321::grammar, RFC5321::action>(in, *ctx);
785 catch (std::exception const& e) {
786 LOG(WARNING) << e.what();
789 if (ctx->session.maxed_out()) {
790 ctx->session.max_out();
792 else if (ctx->session.timed_out()) {
793 ctx->session.time_out();
795 // else {
796 // ctx->session.error("session end without QUIT command from client");
797 // }
799 return ret;