Lines Matching +full:triple +full:- +full:channel

2  * Copyright (c) 1998-2010, 2012-2014,2021-2024 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
20 SM_RCSID("@(#)$Id: srvrsmtp.c,v 8.1016 2013-11-22 20:51:56 ca Exp $")
71 #define SRV_REQ_SEC 0x00000800 /* require security - equiv to AuthOptions=p */
79 #define SRV_BARE_LF_421 0x00020000 /* bare LF - drop connection */
80 #define SRV_BARE_CR_421 0x00040000 /* bare CR - drop connection */
86 #define STOP_ATTACK ((time_t) -1)
112 auth_user_len = SM_MIN(len, MAX_AUTH_USER_LEN-1); \
166 ? n_badrcpts - 1 : n_badrcpts); \
167 macdefine(&e->e_macro, A_TEMP, macid("{nbadrcpts}"), buf); \
175 ** ADDR_IS_ASCII -- check whether a string (address) is ASCII
178 ** str -- a string
181 ** TRUE iff str is non-NULL and points to only ASCII
194 ** STR_IS_PRINT -- check whether a string is printable ASCII
197 ** str -- a string
200 ** TRUE iff str is non-NULL and points to only printable ASCII
221 if (!e->e_smtputf8) \
234 ** PARSE_ESMTP_ARGS -- parse ESMTP arguments (for MAIL, RCPT)
237 ** e -- the envelope
238 ** addr_st -- address (RCPT only)
239 ** p -- read buffer
240 ** delimptr -- current position in read buffer
241 ** which -- MAIL/RCPT
242 ** args -- arguments (output)
243 ** esmtp_args -- function to process a single ESMTP argument
278 while ((isascii(*p) && isalnum(*p)) || *p == '-')
306 if (argno >= MAXSMTPARGS - 1)
318 ** ADDRCPT -- Add a rcpt to sendq list
321 ** rcpt -- rcpt [i]
322 ** sendq -- a pointer to the head of a queue to put
324 ** e -- the envelope in which to add these recipients.
343 oldto = e->e_to;
350 macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), "e b");
356 a->q_flags &= ~Q_PINGFLAGS;
357 a->q_flags |= QINTBCC;
358 a->q_owner = "<>";
365 e->e_to = oldto;
366 macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), NULL);
371 a != NULL ? a->q_flags : 0);
377 ** ADDBCC -- Maybe create a copy of an e-mail
380 ** a -- current RCPT
381 ** e -- the envelope.
405 nobcc = rscheck("bcc", a->q_paddr, NULL, e, RSF_ADDR, 12, NULL, NOQID,
412 (void) addrcpt(newrcpt, &e->e_sendqueue, e);
421 ** RCPTMODS -- Perform rcpt modifications if requested
424 ** rcpt -- current RCPT
425 ** e -- the envelope.
445 sm_dprintf("rcptmods: rcpt=%s, flags=%s\n", rcpt->q_paddr, fl);
453 rcpt->q_flags &= ~Q_PINGFLAGS;
454 rcpt->q_flags |= QINTBCC;
455 rcpt->q_owner = "<>";
459 rcpt->q_flags &= ~Q_PINGFLAGS;
460 rcpt->q_owner = "<>";
464 rcpt->q_flags |= QDYNMAILER;
469 sm_syslog(LOG_INFO, e->e_id,
471 rcpt->q_paddr, fl);
477 macdefine(&e->e_macro, A_PERM, macid("{rcpt_flags}"), NULL);
487 ** SEP_ARGS -- separate address and argument string for MAIL/RCPT command
490 ** args -- arguments (converted to and from internal format)
491 ** orig -- string after command (original data)
492 ** id -- envelope id (for logging only)
493 ** addr -- for logging only: address (original data)
521 q = orig + (lo - lr);
522 if (!(q > orig && *--q == ' '))
530 for (; q > orig && *q == ' '; q--)
536 ** CHANNEL_READBLE -- determine if data is readable from the SMTP channel
539 ** channel -- connect channel for reading
540 ** timeout -- how long to pause for data in milliseconds
548 channel_readable(channel, timeout) in channel_readable() argument
549 SM_FILE_T *channel; in channel_readable()
556 /* check if data is on the channel during the pause */
558 if ((eoftest = sm_io_getc(channel, timeout)) != SM_IO_EOF)
561 sm_io_ungetc(channel, SM_TIME_DEFAULT, eoftest);
569 ** SMTP -- run the SMTP protocol.
572 ** nullserver -- if non-NULL, rejection message for
574 ** d_flags -- daemon flags
575 ** e -- the envelope.
581 ** Reads commands from the input channel and processes them.
599 #define CMDMAIL 1 /* mail -- designate sender */
600 #define CMDRCPT 2 /* rcpt -- designate recipient */
601 #define CMDDATA 3 /* data -- send message text */
602 #define CMDRSET 4 /* rset -- reset state */
603 #define CMDVRFY 5 /* vrfy -- verify address */
604 #define CMDEXPN 6 /* expn -- expand address */
605 #define CMDNOOP 7 /* noop -- do nothing */
606 #define CMDQUIT 8 /* quit -- close connection and die */
607 #define CMDHELO 9 /* helo -- be polite */
608 #define CMDHELP 10 /* help -- give usage info */
609 #define CMDEHLO 11 /* ehlo -- extended helo (RFC 1425) */
610 #define CMDETRN 12 /* etrn -- flush queue */
612 # define CMDAUTH 13 /* auth -- SASL authenticate */
615 # define CMDSTLS 14 /* STARTTLS -- start TLS session */
617 /* non-standard commands */
618 #define CMDVERB 17 /* verb -- go into verbose mode */
623 /* debugging-only commands, only enabled if SMTPDEBUG is defined */
624 #define CMDDBGQSHOW 24 /* showq -- show send queue */
625 #define CMDDBGDEBUG 25 /* debug -- set debug mode */
664 static char *CurSmtpClient; /* who's at the other end of channel */
709 "@(#)$Debug: leak_smtp - trace memory leaks during SMTP processing $");
745 sm_syslog(LOG_INFO, e->e_id, \
756 e->e_sendqueue = NULL; \
763 sm_syslog(LOG_INFO, e->e_id, \
769 || strncmp(response, "421-", 4) == 0) \
776 e->e_sendqueue = NULL; \
786 sm_syslog(LOG_INFO, e->e_id, \
796 sm_syslog(LOG_INFO, e->e_id, \
799 e->e_flags |= EF_DISCARD; \
806 sm_syslog(LOG_INFO, e->e_id, \
837 macdefine(&e->e_macro, A_PERM, \
841 e->e_sendqueue = NULL; \
842 e->e_flags |= EF_CLRQUEUE; \
846 e->e_id, bitset(EF_LOGSENDER, e->e_flags), LogLevel);\
847 if (LogLevel > 4 && bitset(EF_LOGSENDER, e->e_flags)) \
849 e->e_flags &= ~EF_LOGSENDER; \
855 sm_rpool_free(e->e_rpool); \
858 e->e_features = features; \
862 e->e_flags |= EF_DISCARD; \
867 e->e_quarmsg = NULL; \
868 macdefine(&e->e_macro, A_PERM, \
873 e->e_quarmsg = sm_rpool_strdup_x(e->e_rpool, \
875 macdefine(&e->e_macro, A_PERM, macid("{quarantine}"), \
876 e->e_quarmsg); \
895 sm_syslog(LOG_INFO, e->e_id, \
920 (e->e_smtputf8 \
1071 e->e_rpool = sm_rpool_new_x(NULL);
1072 e->e_macro.mac_rpool = e->e_rpool;
1085 smtp.sm_discard = bitset(EF_DISCARD, e->e_flags);
1088 /* auto-flush output when reading input */
1167 e->e_features = features;
1186 /* use no realm -> realm is set to hostname by SASL lib */
1339 sm_syslog(LOG_INFO, e->e_id,
1348 sm_syslog(LOG_INFO, e->e_id,
1356 sm_syslog(LOG_INFO, e->e_id,
1364 e->e_sendqueue = NULL;
1372 !bitset(EF_DISCARD, e->e_flags))
1389 sm_syslog(LOG_INFO, e->e_id,
1416 sm_syslog(LOG_INFO, e->e_id,
1431 e->e_sendqueue = NULL;
1438 sm_syslog(LOG_INFO, e->e_id,
1454 sm_syslog(LOG_INFO, e->e_id,
1465 sm_syslog(LOG_INFO, e->e_id,
1475 sm_syslog(LOG_INFO, e->e_id,
1485 e->e_sendqueue = NULL;
1533 sm_syslog(LOG_INFO, e->e_id,
1534 "rejecting commands from %s [%s] due to pre-greeting traffic after %d seconds",
1537 (int) tp->tv_sec +
1538 (tp->tv_usec >= 500000 ? 1 : 0)
1550 sm_syslog(LOG_ERR, e->e_id,
1584 "%s-%%.*s ESMTP%%s", greetcode);
1585 message(cmdbuf, (int) (id - inp), inp, id);
1593 (void) sm_strlcpyn(cmdbuf, sizeof(cmdbuf), 2, greetcode, "-%s");
1608 if (e->e_quarmsg == NULL)
1611 smtp.sm_quarmsg = newstr(e->e_quarmsg);
1630 e->e_flags &= ~(EF_VRFYONLY|EF_GLOBALERRS);
1636 e->e_to = NULL;
1676 message("421 4.4.1 %s Lost input channel from %s",
1679 sm_syslog(LOG_NOTICE, e->e_id,
1680 "lost input channel from %s to %s after %s",
1682 (c == NULL || c->cmd_name == NULL) ? "startup" : c->cmd_name);
1688 if (bitset(EF_CLRQUEUE, e->e_flags))
1689 e->e_sendqueue = NULL;
1708 sm_syslog(LOG_INFO, e->e_id,
1737 sm_syslog(LOG_INFO, e->e_id,
1939 sm_syslog(LOG_WARNING, e->e_id,
1971 sm_syslog(LOG_WARNING, e->e_id, \
1993 if (e->e_xfp != NULL)
1994 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
1998 sm_syslog(LOG_INFO, e->e_id, "<-- %s", inp);
2006 cmd < &cmdbuf[sizeof(cmdbuf) - 2])
2014 for (c = CmdTab; c->cmd_name != NULL; c++)
2016 if (SM_STRCASEEQ(c->cmd_name, cmdbuf))
2023 /* check whether a "non-null" command has been used */
2024 switch (c->cmd_code)
2044 if (e->e_id == NULL)
2061 switch (c->cmd_code)
2089 e->e_sendqueue = NULL;
2112 switch (c->cmd_code)
2135 sm_syslog(LOG_INFO, e->e_id,
2156 *(q - 1) = '\0';
2178 ** Unlike a zero-length client answer to a
2179 ** 334 reply, a zero- length initial response
2198 in = sm_rpool_malloc(e->e_rpool, strlen(q));
2208 sm_syslog(LOG_WARNING, e->e_id,
2266 sm_syslog(LOG_WARNING, e->e_id,
2312 sm_syslog(LOG_INFO, e->e_id,
2448 e->e_sendqueue = NULL;
2563 case CMDHELO: /* hello -- introduce yourself */
2566 if (c->cmd_code == CMDEHLO)
2577 /* avoid denial-of-service */
2593 sm_syslog(LOG_INFO, e->e_id,
2629 sm_syslog(LOG_INFO, CurEnv->e_id,
2657 if (strchr("[].-_#:", *q) == NULL)
2670 sm_syslog(LOG_INFO, CurEnv->e_id,
2685 !bitset(EF_DISCARD, e->e_flags))
2695 sm_syslog(LOG_INFO, e->e_id,
2704 sm_syslog(LOG_INFO, e->e_id,
2713 sm_syslog(LOG_INFO, e->e_id,
2717 && strncmp(response, "421-", 4) != 0)
2728 sm_syslog(LOG_INFO, e->e_id,
2744 e->e_sendqueue = NULL;
2757 e->e_quarmsg != NULL)
2758 smtp.sm_quarmsg = newstr(e->e_quarmsg);
2764 if (c->cmd_code != CMDEHLO)
2771 message("250-%s Hello %s, %s",
2788 message("250-ENHANCEDSTATUSCODES");
2791 message("250-PIPELINING");
2795 message("250-EXPN");
2797 message("250-VERB");
2800 message("250-8BITMIME");
2803 message("250-SIZE %ld", MaxMessageSize);
2805 message("250-SIZE");
2808 message("250-DSN");
2812 message("250-SMTPUTF8");
2815 message("250-ETRN");
2818 message("250-AUTH %s", mechlist);
2822 message("250-STARTTLS");
2825 message("250-DELIVERBY %ld",
2828 message("250-DELIVERBY");
2830 /* < 0: no deliver-by */
2835 case CMDMAIL: /* mail -- designate sender */
2866 sm_syslog(LOG_INFO, e->e_id,
2907 macdefine(&e->e_macro, A_PERM, 'r', protocol);
2908 macdefine(&e->e_macro, A_PERM, 's', sendinghost);
2914 macdefine(&e->e_macro, A_PERM, macid("{ntries}"), "0");
2915 macdefine(&e->e_macro, A_PERM, macid("{nrcpts}"), "0");
2916 macdefine(&e->e_macro, A_PERM, macid("{nbadrcpts}"),
2918 e->e_flags |= EF_CLRQUEUE;
2952 len = sizeof(iaddr) - (delimptr - iaddr);
2954 sep_args(delimptr, origp, e->e_id, p);
2961 e->e_flags |= EF_LOGSENDER;
2963 /* put resulting triple from parseaddr() into macros */
2964 if (e->e_from.q_mailer != NULL)
2965 macdefine(&e->e_macro, A_PERM,
2967 e->e_from.q_mailer->m_name);
2969 macdefine(&e->e_macro, A_PERM,
2971 if (e->e_from.q_host != NULL)
2972 macdefine(&e->e_macro, A_PERM,
2974 e->e_from.q_host);
2976 macdefine(&e->e_macro, A_PERM,
2978 if (e->e_from.q_user != NULL)
2979 macdefine(&e->e_macro, A_PERM,
2981 e->e_from.q_user);
2983 macdefine(&e->e_macro, A_PERM,
2992 e->e_from.q_mailer->m_flags) ||
2993 strcmp(e->e_from.q_user, RealUserName) != 0))
2995 auth_warning(e, "%s owned process doing -bs",
3000 e->e_flags &= ~EF_7BITBODY;
3003 e->e_msgsize = 0;
3011 if (e->e_smtputf8)
3014 macdefine(&e->e_macro, A_PERM, 'r', protocol);
3019 CHECK_UTF8_ADDR(e->e_from.q_paddr, q);
3030 if (e->e_auth_param == NULL)
3033 e->e_auth_param = macvalue(macid("{auth_authen}"),
3035 if (e->e_auth_param == NULL)
3036 e->e_auth_param = "<>";
3048 macdefine(&e->e_macro, A_PERM,
3052 macdefine(&e->e_macro, A_TEMP, macid("{mail_from}"),
3053 e->e_from.q_paddr);
3057 NULL, e->e_id, NULL, NULL) != EX_OK ||
3060 macdefine(&e->e_macro, A_PERM,
3064 (e->e_msgsize > MaxMessageSize ||
3065 e->e_msgsize < 0))
3081 !enoughdiskspace(e->e_msgsize, e)
3083 && !filesys_free(e->e_msgsize)
3101 !bitset(EF_DISCARD, e->e_flags))
3130 e->e_flags &= ~EF_PM_NOTIFY;
3134 case CMDRCPT: /* rcpt -- designate recipient */
3136 macdefine(&e->e_macro, A_PERM,
3138 macdefine(&e->e_macro, A_PERM,
3140 macdefine(&e->e_macro, A_PERM,
3146 smtp.sm_e_nrcpts_orig = e->e_nrcpts;
3157 ? n_badrcpts - 1 : n_badrcpts;
3167 sm_syslog(LOG_INFO, e->e_id,
3174 e->e_sendqueue = NULL;
3184 sm_syslog(LOG_INFO, e->e_id,
3228 if (!SM_IS_INTERACTIVE(e->e_sendmode)
3230 && (NotFirstDelivery || SM_DM_ONE != e->e_sendmode)
3233 e->e_flags |= EF_VRFYONLY;
3246 !bitset(EF_DISCARD, e->e_flags) &&
3249 e->e_flags |= EF_VRFYONLY;
3257 macdefine(&e->e_macro, A_PERM,
3268 macdefine(&e->e_macro, A_PERM,
3278 CHECK_UTF8_ADDR(a->q_paddr, q);
3290 len = sizeof(iaddr) - (delimptr - iaddr);
3292 sep_args(delimptr, origp, e->e_id, p);
3296 /* put resulting triple from parseaddr() into macros */
3297 if (a->q_mailer != NULL)
3298 macdefine(&e->e_macro, A_PERM,
3300 a->q_mailer->m_name);
3302 macdefine(&e->e_macro, A_PERM,
3304 if (a->q_host != NULL)
3305 macdefine(&e->e_macro, A_PERM,
3306 macid("{rcpt_host}"), a->q_host);
3308 macdefine(&e->e_macro, A_PERM,
3310 if (a->q_user != NULL)
3311 macdefine(&e->e_macro, A_PERM,
3312 macid("{rcpt_addr}"), a->q_user);
3314 macdefine(&e->e_macro, A_PERM,
3320 addr = sm_rpool_strdup_x(e->e_rpool, p);
3344 macdefine(&e->e_macro, A_PERM,
3348 NULL, e->e_id, p_addr_st, NULL) != EX_OK ||
3351 macdefine(&e->e_macro, A_PERM,
3355 if (bitset(EF_DISCARD, e->e_flags))
3356 a->q_state = QS_VERIFIED;
3365 a = recipient(a, &e->e_sendqueue, 0, e);
3372 if(!(Errors > 0) && QS_IS_BADADDR(a->q_state))
3374 /* punt -- should keep message in ADDRESS.... */
3381 !bitset(EF_DISCARD, e->e_flags))
3389 macdefine(&e->e_macro, A_PERM,
3393 a->q_status != NULL &&
3394 a->q_rstatus != NULL)
3396 macdefine(&e->e_macro, A_PERM,
3398 a->q_status);
3399 macdefine(&e->e_macro, A_PERM,
3401 a->q_rstatus);
3406 macdefine(&e->e_macro,
3411 macdefine(&e->e_macro,
3426 e->e_to = a->q_paddr;
3427 if (!(Errors > 0) && !QS_IS_BADADDR(a->q_state))
3432 QS_IS_QUEUEUP(a->q_state) ?
3442 macdefine(&e->e_macro, A_PERM,
3444 macdefine(&e->e_macro, A_PERM,
3446 macdefine(&e->e_macro, A_PERM,
3448 macdefine(&e->e_macro, A_PERM,
3460 e->e_flags &= ~(EF_FATALERRS|EF_PM_NOTIFY);
3465 !bitset(EF_DISCARD, e->e_flags) &&
3471 macdefine(&e->e_macro, A_PERM,
3476 macdefine(&e->e_macro, A_PERM,
3479 else if (a != NULL && a->q_status != NULL)
3480 macdefine(&e->e_macro, A_PERM,
3482 a->q_status);
3485 macdefine(&e->e_macro, A_PERM,
3488 else if (a != NULL && a->q_rstatus != NULL)
3489 macdefine(&e->e_macro, A_PERM,
3491 a->q_rstatus);
3497 macdefine(&e->e_macro, A_PERM,
3499 macdefine(&e->e_macro, A_PERM,
3501 macdefine(&e->e_macro, A_PERM,
3508 (void) removefromlist(addr, &e->e_sendqueue, e);
3510 if (smtp.sm_e_nrcpts_orig < e->e_nrcpts)
3511 e->e_nrcpts = smtp.sm_e_nrcpts_orig;
3518 case CMDDATA: /* data -- text of mail */
3525 case CMDRSET: /* rset -- reset state */
3533 case CMDVRFY: /* vrfy -- verify address */
3534 case CMDEXPN: /* expn -- expand address */
3535 vrfy = c->cmd_code == CMDVRFY;
3540 sm_syslog(LOG_INFO, e->e_id,
3561 sm_syslog(LOG_INFO, e->e_id,
3577 sm_syslog(LOG_INFO, e->e_id, "%s: %s",
3585 e->e_flags |= EF_VRFYONLY;
3606 t = wt - (curtime() - previous);
3618 if (!QS_IS_UNDELIVERED(vrfyqueue->q_state))
3620 vrfyqueue = vrfyqueue->q_next;
3626 while ((a = a->q_next) != NULL &&
3627 (!QS_IS_UNDELIVERED(a->q_state)))
3645 case CMDETRN: /* etrn -- force queue flush */
3656 sm_syslog(LOG_INFO, e->e_id,
3665 sm_syslog(LOG_INFO, e->e_id,
3679 /* crude way to avoid denial-of-service attacks */
3699 sm_syslog(LOG_INFO, e->e_id,
3718 Queue[i]->qg_nextrun = (time_t) -1;
3719 Queue[qgrp]->qg_nextrun = 0;
3720 ok = run_work_group(Queue[qgrp]->qg_wgrp,
3730 *--id = '@';
3738 new->queue_match = id;
3739 new->queue_negate = false;
3740 new->queue_next = NULL;
3749 case CMDHELP: /* help -- give user info */
3767 e->e_sendqueue = NULL; \
3774 case CMDNOOP: /* noop -- do nothing */
3782 case CMDQUIT: /* quit -- leave mail */
3792 e->e_sendqueue = NULL;
3822 e->e_id,
3823 bitset(EF_LOGSENDER, e->e_flags),
3825 if (LogLevel > 4 && bitset(EF_LOGSENDER, e->e_flags))
3827 e->e_flags &= ~EF_LOGSENDER;
3844 sm_syslog(LOG_INFO, e->e_id,
3865 (void) sm_io_fprintf(out, SM_TIME_DEFAULT, "----------------------\n");
3867 sm_debug_level(&SmHeapCheck) - 1);
3902 printaddr(smioout, e->e_sendqueue, true);
3907 tTsetup(tTdvect, sizeof(tTdvect), "0-99.1");
3919 sm_syslog(LOG_CRIT, e->e_id,
3921 c->cmd_name, CurSmtpClient,
3934 e->e_sendqueue = NULL;
3941 !bitset(EF_DISCARD, e->e_flags))
3947 sm_syslog(LOG_INFO, e->e_id,
3978 syserr("500 5.5.0 smtp: unknown code %d", c->cmd_code);
3996 ** SMTP_DATA -- implement the SMTP DATA command.
3999 ** smtp -- status of SMTP connection.
4000 ** e -- envelope.
4001 ** check_stuffing -- check for transaction stuffing.
4030 if (!smtp->sm_gotmail)
4035 else if (smtp->sm_nrcpts <= 0)
4045 sm_syslog(LOG_INFO, e->e_id,
4052 (void) sm_snprintf(buf, sizeof(buf), "%u", smtp->sm_nrcpts);
4055 e->e_id, NULL, NULL) != EX_OK)
4059 if (smtp->sm_milterlist && smtp->sm_milterize &&
4060 !bitset(EF_DISCARD, e->e_flags))
4072 sm_syslog(LOG_INFO, e->e_id,
4079 (void) extenhsc(response + 4, ' ', e->e_enhsc);
4085 || strncmp(response, "421-", 4) == 0)
4087 e->e_sendqueue = NULL;
4095 sm_syslog(LOG_INFO, e->e_id,
4100 (void) sm_strlcpy(e->e_enhsc, "5.7.1",
4101 sizeof(e->e_enhsc));
4108 sm_syslog(LOG_INFO, e->e_id,
4110 e->e_flags |= EF_DISCARD;
4116 sm_syslog(LOG_INFO, e->e_id,
4122 (void) extenhsc(MSG_TEMPFAIL + 4, ' ', e->e_enhsc);
4131 sm_syslog(LOG_INFO, e->e_id,
4137 e->e_sendqueue = NULL;
4147 if (smtp->sm_discard)
4148 e->e_flags |= EF_DISCARD;
4150 /* check to see if we need to re-expand aliases */
4151 /* also reset QS_BADADDR on already-diagnosted addrs */
4153 for (a = e->e_sendqueue; a != NULL; a = a->q_next)
4155 if (QS_IS_VERIFIED(a->q_state) &&
4156 !bitset(EF_DISCARD, e->e_flags))
4158 /* need to re-expand aliases */
4161 if (QS_IS_BADADDR(a->q_state))
4164 a->q_state = QS_DONTSEND;
4173 | (bitset(SRV_BARE_LF_421, e->e_features) ? SMTPMODE_LF_421 : 0)
4174 | (bitset(SRV_BARE_CR_421, e->e_features) ? SMTPMODE_CR_421 : 0)
4175 | (bitset(SRV_BARE_LF_SP, e->e_features) ? SMTPMODE_LF_SP : 0)
4176 | (bitset(SRV_BARE_CR_SP, e->e_features) ? SMTPMODE_CR_SP : 0)
4177 | (bitset(SRV_REQ_CRLF, e->e_features) ? SMTPMODE_CRLF : 0),
4181 (void) sm_snprintf(buf, sizeof(buf), "%ld", PRT_NONNEGL(e->e_msgsize));
4182 macdefine(&e->e_macro, A_TEMP, macid("{msg_size}"), buf);
4186 3, NULL, e->e_id, NULL, NULL);
4190 if (smtp->sm_milterlist && smtp->sm_milterize &&
4192 !bitset(EF_DISCARD, e->e_flags))
4202 sm_syslog(LOG_INFO, e->e_id,
4208 (void) extenhsc(response + 4, ' ', e->e_enhsc);
4213 || strncmp(response, "421-", 4) == 0)
4220 sm_syslog(LOG_INFO, e->e_id,
4227 sm_syslog(LOG_INFO, e->e_id,
4230 e->e_flags |= EF_DISCARD;
4235 sm_syslog(LOG_INFO, e->e_id,
4240 (void) extenhsc(MSG_TEMPFAIL + 4, ' ', e->e_enhsc);
4248 sm_syslog(LOG_INFO, e->e_id,
4261 (void) sm_snprintf(buf, sizeof(buf), "%ld", PRT_NONNEGL(e->e_msgsize));
4262 macdefine(&e->e_macro, A_TEMP, macid("{msg_size}"), buf);
4265 if (smtp->sm_milterlist && smtp->sm_milterize)
4269 sm_syslog(LOG_INFO, e->e_id, "Milter accept: message");
4286 df = e->e_dfp;
4300 st.st_size = -1;
4336 e->e_dfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, dfname,
4338 if (e->e_dfp == NULL)
4349 if (e->e_quarmsg != NULL)
4354 ** set EF_DISCARD, don't queueup the message --
4359 if (bitset(EF_DISCARD, e->e_flags))
4363 if (!(aborting || bitset(EF_DISCARD, e->e_flags)) &&
4364 (QueueMode == QM_QUARANTINE || e->e_quarmsg == NULL) &&
4366 aborting = bitset(EF_FATALERRS, e->e_flags);
4373 logundelrcpts(e, e->e_message, 8, false);
4380 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
4381 q->q_flags &= ~Q_PINGFLAGS;
4399 e->e_message = NULL;
4409 ** Truncate our transcript -- the mail has gotten
4421 (void) sm_io_setinfo(e->e_xfp, SM_BF_TRUNCATE, NULL);
4422 id = e->e_id;
4430 if (SM_PROXY_REQ == e->e_sendmode)
4433 if (e->e_sibling == NULL && e->e_nrcpts == 1
4434 && smtp->sm_nrcpts == 1
4435 && (a = e->e_sendqueue) != NULL && a->q_next == NULL)
4437 a->q_flags &= ~(QPINGONFAILURE|QPINGONSUCCESS|
4439 e->e_errormode = EM_QUIET;
4440 e->e_sendmode = SM_PROXY;
4446 a = e->e_sendqueue;
4448 e->e_sendmode, e, e->e_sibling, e->e_nrcpts,
4449 smtp->sm_nrcpts, a,
4450 (a == NULL) ? (void *)0 : a->q_next);
4454 e->e_sendmode = SM_DELIVER;
4456 sm_syslog(LOG_DEBUG, e->e_id,
4463 if (SM_TRIGGER == e->e_sendmode)
4466 for (ee = e; ee != NULL; ee = ee->e_sibling)
4469 ee->e_flags &= ~EF_CLRQUEUE;
4472 ee->e_errormode = EM_MAIL;
4480 if (IS_SM_TRIGGER(ee->e_sendmode))
4493 if (SM_DM_ONE == e->e_sendmode)
4498 e->e_sendmode = SM_QUEUE;
4509 ee->e_to = NULL;
4513 oldid = CurEnv->e_id;
4514 CurEnv->e_id = id;
4517 a = e->e_sendqueue;
4521 e->e_sendmode, e, e->e_sibling, e->e_nrcpts, e->e_message, a,
4522 (a == NULL) ? (void *)0 : a->q_next,
4523 (a == NULL) ? -1 : a->q_state, SmtpError, e->e_rcode,
4524 e->e_renhsc, e->e_text);
4527 if (SM_PROXY == e->e_sendmode && a->q_state != QS_SENT &&
4528 a->q_state != QS_VERIFIED) /* discarded! */
4535 #define NN_MSG(e) (((e)->e_message != NULL) ? (e)->e_message : "")
4536 m = e->e_message;
4539 sizeof(SM_MSG_DEFERRED) - 1) == 0)
4540 m += sizeof(SM_MSG_DEFERRED) - 1;
4546 SmtpError, e->e_rcode, e->e_renhsc,
4551 if (e->e_rcode != 0 && (replycode[0] == '\0' ||
4552 replycode[0] == DIG2CHAR(REPLYTYPE(e->e_rcode))))
4554 replycode[0] = DIG2CHAR(REPLYTYPE(e->e_rcode));
4555 replycode[1] = DIG2CHAR(REPLYCLASS(e->e_rcode));
4556 replycode[2] = DIG2CHAR(REPLYMINOR(e->e_rcode));
4558 if (e->e_renhsc[0] == replycode[0])
4559 sm_strlcpy(enhsc, e->e_renhsc, sizeof(enhsc));
4563 if (e->e_text != NULL)
4565 (void) strreplnonprt(e->e_text, '_');
4566 errtext = e->e_text;
4576 else if (QS_IS_TEMPFAIL(a->q_state))
4610 CurEnv->e_id = oldid;
4618 for (ee = e; ee != NULL; ee = ee->e_sibling)
4621 if (SM_TRIGGER == ee->e_sendmode)
4623 sm_syslog(LOG_DEBUG, ee->e_id,
4624 "smtp: doublequeue, mode=%c", ee->e_sendmode);
4625 ee->e_sendmode = SM_DELIVER;
4630 SM_CLOSE_FP(ee->e_dfp);
4634 if (WILL_BE_QUEUED(ee->e_sendmode))
4636 if (shouldqueue(ee->e_msgpriority, ee->e_ctime))
4638 ee->e_sendmode = SM_QUEUE;
4642 ee->e_quarmsg != NULL)
4644 ee->e_sendmode = SM_QUEUE;
4651 SM_CLOSE_FP(ee->e_dfp);
4665 sm_syslog(LOG_DEBUG, e->e_id, "smtp: doublequeue=send");
4674 e->e_id, bitset(EF_LOGSENDER, e->e_flags), LogLevel);
4675 if (LogLevel > 4 && bitset(EF_LOGSENDER, e->e_flags))
4677 e->e_flags &= ~EF_LOGSENDER;
4680 smtp->sm_gotmail = false;
4687 if (aborting || bitset(EF_DISCARD, e->e_flags))
4691 for (ee = e; ee != NULL; ee = ee->e_sibling)
4695 ee->e_quarmsg != NULL)
4700 if (WILL_BE_QUEUED(ee->e_sendmode))
4706 features = e->e_features;
4707 sm_rpool_free(e->e_rpool);
4709 e->e_flags = BlankEnvelope.e_flags;
4710 e->e_features = features;
4713 if (smtp->sm_quarmsg == NULL)
4715 e->e_quarmsg = NULL;
4716 macdefine(&e->e_macro, A_PERM, macid("{quarantine}"), "");
4720 e->e_quarmsg = sm_rpool_strdup_x(e->e_rpool, smtp->sm_quarmsg);
4721 macdefine(&e->e_macro, A_PERM,
4722 macid("{quarantine}"), e->e_quarmsg);
4727 ** LOGUNDELRCPTS -- log undelivered (or all) recipients.
4730 ** e -- envelope.
4731 ** msg -- message for Stat=
4732 ** level -- log level.
4733 ** all -- log all recipients.
4755 macdefine(&e->e_macro, A_PERM, 'h', NULL);
4758 for (a = e->e_sendqueue; a != NULL; a = a->q_next)
4760 if (!QS_IS_UNDELIVERED(a->q_state) && !all)
4762 e->e_to = a->q_paddr;
4765 (a->q_status == NULL && e->e_enhsc[0] != '\0')
4766 ? e->e_enhsc :
4770 (NULL == a->q_status) ? e->e_status :
4772 a->q_status,
4775 e->e_to = NULL;
4778 ** CHECKSMTPATTACK -- check for denial-of-service attack by repetition
4781 ** pcounter -- pointer to a counter for this command.
4782 ** maxcount -- maximum value for this counter before we
4784 ** waitnow -- sleep now (in this routine)?
4785 ** cname -- command name for logging.
4786 ** e -- the current envelope.
4815 sm_syslog(LOG_INFO, e->e_id,
4819 shift = *pcounter - maxcount;
4829 s -= *pcounter / maxcount;
4842 ** SETUP_SMTPD_IO -- setup I/O fd correctly for the SMTP server
4881 if (inmode == -1) in setup_smtpd_io()
4890 if (outmode == -1) in setup_smtpd_io()
4900 fcntl(inchfd, F_SETFL, inmode | O_NONBLOCK) == -1) in setup_smtpd_io()
4903 if (outmode != -1 && bitset(O_NONBLOCK, outmode)) in setup_smtpd_io()
4918 ** SKIPWORD -- skip a fixed word.
4921 ** p -- place to start looking.
4922 ** w -- word to skip.
4970 ** RESET_MAIL_ESMTP_ARGS -- reset ESMTP arguments for MAIL
4973 ** e -- the envelope.
4986 e->e_flags &= ~EF_7BITBODY;
4987 e->e_bodytype = NULL;
4990 e->e_envid = NULL;
4991 macdefine(&e->e_macro, A_PERM, macid("{dsn_envid}"), NULL);
4994 e->e_flags &= ~(EF_RET_PARAM|EF_NO_BODY_RETN);
4995 macdefine(&e->e_macro, A_TEMP, macid("{dsn_ret}"), NULL);
4999 macdefine(&e->e_macro, A_TEMP, macid("{auth_author}"), NULL);
5000 e->e_auth_param = "";
5008 e->e_deliver_by = 0;
5009 e->e_dlvr_flag = 0;
5013 ** MAIL_ESMTP_ARGS -- process ESMTP arguments from MAIL line
5016 ** a -- address (unused, for compatibility with rcpt_esmtp_args)
5017 ** kp -- the parameter key.
5018 ** vp -- the value of that parameter.
5019 ** e -- the envelope.
5039 macdefine(&e->e_macro, A_TEMP, macid("{msg_size}"), vp);
5041 e->e_msgsize = strtol(vp, (char **) NULL, 10);
5042 if (e->e_msgsize == LONG_MAX && errno == ERANGE)
5047 if (e->e_msgsize < 0)
5063 e->e_flags |= EF_7BITBODY;
5070 e->e_bodytype = sm_rpool_strdup_x(e->e_rpool, vp);
5074 if (!bitset(SRV_OFFER_DSN, e->e_features))
5089 if (e->e_envid != NULL)
5094 e->e_envid = sm_rpool_strdup_x(e->e_rpool, vp);
5095 macdefine(&e->e_macro, A_PERM,
5096 macid("{dsn_envid}"), e->e_envid);
5100 if (!bitset(SRV_OFFER_DSN, e->e_features))
5110 if (bitset(EF_RET_PARAM, e->e_flags))
5115 e->e_flags |= EF_RET_PARAM;
5117 e->e_flags |= EF_NO_BODY_RETN;
5124 macdefine(&e->e_macro, A_TEMP, macid("{dsn_ret}"), vp);
5141 if (e->e_auth_param != NULL)
5147 len = q - vp + 1;
5160 macdefine(&e->e_macro, A_TEMP, macid("{auth_author}"),
5178 q = e->e_auth_param;
5184 e->e_auth_param = "<>";
5194 e->e_auth_param = sm_rpool_strdup_x(e->e_rpool,
5223 e->e_deliver_by = strtol(vp, &s, 10);
5224 if (e->e_deliver_by == LONG_MIN ||
5225 e->e_deliver_by == LONG_MAX ||
5226 e->e_deliver_by > 999999999l ||
5227 e->e_deliver_by < -999999999l)
5238 e->e_dlvr_flag = 0;
5244 e->e_dlvr_flag = DLVR_NOTIFY;
5247 e->e_dlvr_flag = DLVR_RETURN;
5248 if (e->e_deliver_by <= 0)
5253 if (DeliverByMin > 0 && e->e_deliver_by > 0 &&
5254 e->e_deliver_by < DeliverByMin)
5257 e->e_deliver_by, (long) DeliverByMin);
5262 usrerr("501 5.5.2 illegal by-mode '%c'", PRTCHAR(*s));
5270 e->e_dlvr_flag |= DLVR_TRACE;
5275 usrerr("501 5.5.2 illegal by-trace '%c'", PRTCHAR(*s));
5284 if (!bitset(SRV_OFFER_EAI, e->e_features))
5289 e->e_smtputf8 = true;
5301 ** RCPT_ESMTP_ARGS -- process ESMTP arguments from RCPT line
5304 ** a -- the address corresponding to the To: parameter.
5305 ** kp -- the parameter key.
5306 ** vp -- the value of that parameter.
5307 ** e -- the envelope.
5324 if (!bitset(SRV_OFFER_DSN, e->e_features))
5334 a->q_flags &= ~(QPINGONSUCCESS|QPINGONFAILURE|QPINGONDELAY);
5335 a->q_flags |= QHASNOTIFY;
5336 macdefine(&e->e_macro, A_TEMP, macid("{dsn_notify}"), vp);
5348 a->q_flags |= QPINGONSUCCESS;
5350 a->q_flags |= QPINGONFAILURE;
5352 a->q_flags |= QPINGONDELAY;
5367 if (!bitset(SRV_OFFER_DSN, e->e_features))
5377 if (a->q_orcpt != NULL)
5390 if (SM_STRCASEEQ(vp, "utf-8"))
5397 usrerr("501 5.5.4 Syntax error in UTF-8 ORCPT parameter value");
5403 utf-8-enc-addr = utf-8-addr-xtext / utf-8-addr-unitext / utf-8-address
5416 a->q_orcpt = sm_rpool_strdup_x(e->e_rpool, vp);
5426 ** PRINTVRFYADDR -- print an entry in the verify queue
5429 ** a -- the address to print.
5430 ** last -- set if this is the last one.
5431 ** vrfy -- set if this is a VRFY command.
5449 if (vrfy && a->q_mailer != NULL &&
5450 !bitnset(M_VRFY250, a->q_mailer->m_flags))
5454 fmtbuf[3] = last ? ' ' : '-';
5455 (void) sm_strlcpy(&fmtbuf[4], "2.1.5 ", sizeof(fmtbuf) - 4);
5456 if (a->q_fullname == NULL)
5458 if ((a->q_mailer == NULL ||
5459 a->q_mailer->m_addrtype == NULL ||
5460 SM_STRCASEEQ(a->q_mailer->m_addrtype, "rfc822")) &&
5461 strchr(a->q_user, '@') == NULL)
5463 sizeof(fmtbuf) - OFFF);
5466 sizeof(fmtbuf) - OFFF);
5467 message(fmtbuf, a->q_user, MyHostName);
5471 if ((a->q_mailer == NULL ||
5472 a->q_mailer->m_addrtype == NULL ||
5473 SM_STRCASEEQ(a->q_mailer->m_addrtype, "rfc822")) &&
5474 strchr(a->q_user, '@') == NULL)
5476 sizeof(fmtbuf) - OFFF);
5479 sizeof(fmtbuf) - OFFF);
5480 message(fmtbuf, a->q_fullname, a->q_user, MyHostName);
5486 ** SASLMECHS -- get list of possible AUTH mechanisms
5489 ** conn -- SASL connection info.
5490 ** mechlist -- output parameter for list of mechanisms.
5541 ** PROXY_POLICY -- define proxy policy for AUTH
5544 ** conn -- unused.
5545 ** context -- unused.
5546 ** requested_user -- authorization identity.
5547 ** rlen -- authorization identity length.
5548 ** auth_identity -- authentication identity.
5549 ** alen -- authentication identity length.
5550 ** def_realm -- default user realm.
5551 ** urlen -- user realm length.
5552 ** propctx -- unused.
5586 ** PROXY_POLICY -- define proxy policy for AUTH
5589 ** context -- unused.
5590 ** auth_identity -- authentication identity.
5591 ** requested_user -- authorization identity.
5592 ** user -- allowed user (output).
5593 ** errstr -- possible error string (output).
5617 ** INITSRVTLS -- initialize server side TLS
5620 ** tls_ok -- should tls initialization be done?
5645 ** SRVFEATURES -- get features for SMTP server
5648 ** e -- envelope (should be session context).
5649 ** clientname -- name of client.
5650 ** features -- default features for this invocation.
5736 sm_syslog(LOG_WARNING, e->e_id,
5750 ** - _flag itself is set by default
5752 ** - _flag2 is only "effective" if _flag is not set,
5777 sm_syslog(LOG_WARNING, e->e_id,
5789 ** HELP -- implement the HELP command.
5792 ** topic -- the topic we want help for.
5793 ** e -- envelope.
5818 static int foundvers = -1;
5831 message("502 5.3.0 Sendmail %s -- HELP not implemented",
5878 message("214-2.0.0 This is Sendmail version %s", Version);
5882 p = buf + strlen(buf) - 1;
5889 int lbs = sizeof(buf) - (p - buf);
5897 message("214-2.0.0 %s", p);
5910 sm_syslog(LOG_WARNING, e->e_id,
5924 ** RESET_SASLCONN -- reset SASL connection data
5927 ** conn -- SASL connection context
5928 ** hostname -- host name
5959 /* use no realm -> realm is set to hostname by SASL lib */ in reset_saslconn()
6007 ** GET_SASL_USER -- extract user part from SASL reply
6010 ** val -- sasl reply (may contain NUL)
6011 ** len -- length of val
6012 ** auth_type -- auth_type (can be NULL)
6013 ** user -- output buffer for extract user
6014 ** user_len -- length of output buffer (user)
6020 ** (non-printable) characters, but the returned value (user)
6045 # define DIGMD5U_L (sizeof(DIGMD5U) - 1)
6046 if (SM_STRCASEEQ(auth_type, "digest-md5") &&
6054 len -= DIGMD5U_L;
6072 else if (SM_STRCASEEQ(auth_type, "cram-md5"))
6094 ** UTF8NUL = %x00 ; UTF-8 encoded NUL character
6096 ** draft-murchison-sasl-login: it's just username by its own
6127 u = len - 1;