milter.c (147078) | milter.c (157001) |
---|---|
1/* 2 * Copyright (c) 1999-2005 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 5 * By using this file, you agree to the terms and conditions set 6 * forth in the LICENSE file which can be found at the top level of 7 * the sendmail distribution. 8 * 9 */ 10 11#include <sendmail.h> 12 | 1/* 2 * Copyright (c) 1999-2005 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 5 * By using this file, you agree to the terms and conditions set 6 * forth in the LICENSE file which can be found at the top level of 7 * the sendmail distribution. 8 * 9 */ 10 11#include <sendmail.h> 12 |
13SM_RCSID("@(#)$Id: milter.c,v 8.229 2005/03/02 02:32:34 ca Exp $") | 13SM_RCSID("@(#)$Id: milter.c,v 8.232 2005/08/05 21:49:04 ca Exp $") |
14 15#if MILTER 16# include <libmilter/mfapi.h> 17# include <libmilter/mfdef.h> 18 19# include <errno.h> | 14 15#if MILTER 16# include <libmilter/mfapi.h> 17# include <libmilter/mfdef.h> 18 19# include <errno.h> |
20# include <sys/time.h> | 20# include <sm/time.h> |
21# include <sys/uio.h> 22 23# if NETINET || NETINET6 24# include <arpa/inet.h> 25# if _FFR_MILTER_NAGLE 26# include <netinet/tcp.h> 27# endif /* _FFR_MILTER_NAGLE */ 28# endif /* NETINET || NETINET6 */ --- 1928 unchanged lines hidden (view full) --- 1957 case SMFIC_EOH: 1958 skipflag = SMFIP_NOEOH; 1959 action = "eoh"; 1960 defresponse = "550 5.7.1 Command rejected"; 1961 break; 1962 1963#if SMFI_VERSION > 2 1964 case SMFIC_UNKNOWN: | 21# include <sys/uio.h> 22 23# if NETINET || NETINET6 24# include <arpa/inet.h> 25# if _FFR_MILTER_NAGLE 26# include <netinet/tcp.h> 27# endif /* _FFR_MILTER_NAGLE */ 28# endif /* NETINET || NETINET6 */ --- 1928 unchanged lines hidden (view full) --- 1957 case SMFIC_EOH: 1958 skipflag = SMFIP_NOEOH; 1959 action = "eoh"; 1960 defresponse = "550 5.7.1 Command rejected"; 1961 break; 1962 1963#if SMFI_VERSION > 2 1964 case SMFIC_UNKNOWN: |
1965 skipflag = SMFIP_NOUNKNOWN; |
|
1965 action = "unknown"; 1966 defresponse = "550 5.7.1 Command rejected"; 1967 break; 1968#endif /* SMFI_VERSION > 2 */ 1969 | 1966 action = "unknown"; 1967 defresponse = "550 5.7.1 Command rejected"; 1968 break; 1969#endif /* SMFI_VERSION > 2 */ 1970 |
1971#if SMFI_VERSION > 3 1972 case SMFIC_DATA: 1973 skipflag = SMFIP_NODATA; 1974 action = "data"; 1975 defresponse = "550 5.7.1 Command rejected"; 1976 break; 1977#endif /* SMFI_VERSION > 3 */ 1978 |
|
1970 case SMFIC_BODYEOB: 1971 case SMFIC_OPTNEG: 1972 case SMFIC_MACRO: 1973 case SMFIC_ABORT: 1974 case SMFIC_QUIT: 1975 /* NOTE: not handled by milter_send_command() */ 1976 /* FALLTHROUGH */ 1977 --- 201 unchanged lines hidden (view full) --- 2179milter_negotiate(m, e) 2180 struct milter *m; 2181 ENVELOPE *e; 2182{ 2183 char rcmd; 2184 mi_int32 fvers; 2185 mi_int32 fflags; 2186 mi_int32 pflags; | 1979 case SMFIC_BODYEOB: 1980 case SMFIC_OPTNEG: 1981 case SMFIC_MACRO: 1982 case SMFIC_ABORT: 1983 case SMFIC_QUIT: 1984 /* NOTE: not handled by milter_send_command() */ 1985 /* FALLTHROUGH */ 1986 --- 201 unchanged lines hidden (view full) --- 2188milter_negotiate(m, e) 2189 struct milter *m; 2190 ENVELOPE *e; 2191{ 2192 char rcmd; 2193 mi_int32 fvers; 2194 mi_int32 fflags; 2195 mi_int32 pflags; |
2187 char *response; | 2196 mi_int32 curr_prot; |
2188 ssize_t rlen; | 2197 ssize_t rlen; |
2198 char *response; |
|
2189 char data[MILTER_OPTLEN]; 2190 2191 /* sanity check */ 2192 if (m->mf_sock < 0 || m->mf_state != SMFS_OPEN) 2193 { 2194 if (MilterLogLevel > 0) 2195 sm_syslog(LOG_ERR, e->e_id, 2196 "Milter (%s): negotiate, impossible state", 2197 m->mf_name); 2198 milter_error(m, e); 2199 return -1; 2200 } 2201 2202 fvers = htonl(SMFI_VERSION); 2203 fflags = htonl(SMFI_CURR_ACTS); | 2199 char data[MILTER_OPTLEN]; 2200 2201 /* sanity check */ 2202 if (m->mf_sock < 0 || m->mf_state != SMFS_OPEN) 2203 { 2204 if (MilterLogLevel > 0) 2205 sm_syslog(LOG_ERR, e->e_id, 2206 "Milter (%s): negotiate, impossible state", 2207 m->mf_name); 2208 milter_error(m, e); 2209 return -1; 2210 } 2211 2212 fvers = htonl(SMFI_VERSION); 2213 fflags = htonl(SMFI_CURR_ACTS); |
2204 pflags = htonl(SMFI_CURR_PROT); | 2214 curr_prot = SMFI_V2_PROT 2215#if _FFR_MILTER_NOHDR_RESP 2216 | SMFIP_NOHREPL 2217#endif /* _FFR_MILTER_NOHDR_RESP */ 2218#if SMFI_VERSION >= 3 2219 | SMFIP_NOUNKNOWN 2220# if SMFI_VERSION >= 4 2221 | SMFIP_NODATA 2222# endif /* SMFI_VERSION >= 4 */ 2223#endif /* SMFI_VERSION >= 3 */ 2224 ; 2225 pflags = htonl(curr_prot); |
2205 (void) memcpy(data, (char *) &fvers, MILTER_LEN_BYTES); 2206 (void) memcpy(data + MILTER_LEN_BYTES, 2207 (char *) &fflags, MILTER_LEN_BYTES); 2208 (void) memcpy(data + (MILTER_LEN_BYTES * 2), 2209 (char *) &pflags, MILTER_LEN_BYTES); 2210 (void) milter_write(m, SMFIC_OPTNEG, data, sizeof data, 2211 m->mf_timeout[SMFTO_WRITE], e); 2212 --- 92 unchanged lines hidden (view full) --- 2305 "Milter (%s): negotiate: filter abilities 0x%x != MTA milter abilities 0x%lx", 2306 m->mf_name, m->mf_fflags, 2307 (unsigned long) SMFI_CURR_ACTS); 2308 milter_error(m, e); 2309 return -1; 2310 } 2311 2312 /* check for protocol feature mismatch */ | 2226 (void) memcpy(data, (char *) &fvers, MILTER_LEN_BYTES); 2227 (void) memcpy(data + MILTER_LEN_BYTES, 2228 (char *) &fflags, MILTER_LEN_BYTES); 2229 (void) memcpy(data + (MILTER_LEN_BYTES * 2), 2230 (char *) &pflags, MILTER_LEN_BYTES); 2231 (void) milter_write(m, SMFIC_OPTNEG, data, sizeof data, 2232 m->mf_timeout[SMFTO_WRITE], e); 2233 --- 92 unchanged lines hidden (view full) --- 2326 "Milter (%s): negotiate: filter abilities 0x%x != MTA milter abilities 0x%lx", 2327 m->mf_name, m->mf_fflags, 2328 (unsigned long) SMFI_CURR_ACTS); 2329 milter_error(m, e); 2330 return -1; 2331 } 2332 2333 /* check for protocol feature mismatch */ |
2313 if ((m->mf_pflags & SMFI_CURR_PROT) != m->mf_pflags) | 2334 if ((m->mf_pflags & curr_prot) != m->mf_pflags) |
2314 { 2315 if (tTd(64, 5)) 2316 sm_dprintf("milter_negotiate(%s): protocol abilities 0x%x != MTA milter abilities 0x%lx\n", 2317 m->mf_name, m->mf_pflags, | 2335 { 2336 if (tTd(64, 5)) 2337 sm_dprintf("milter_negotiate(%s): protocol abilities 0x%x != MTA milter abilities 0x%lx\n", 2338 m->mf_name, m->mf_pflags, |
2318 (unsigned long) SMFI_CURR_PROT); | 2339 (unsigned long) curr_prot); |
2319 if (MilterLogLevel > 0) 2320 sm_syslog(LOG_ERR, e->e_id, 2321 "Milter (%s): negotiate: protocol abilities 0x%x != MTA milter abilities 0x%lx", 2322 m->mf_name, m->mf_pflags, | 2340 if (MilterLogLevel > 0) 2341 sm_syslog(LOG_ERR, e->e_id, 2342 "Milter (%s): negotiate: protocol abilities 0x%x != MTA milter abilities 0x%lx", 2343 m->mf_name, m->mf_pflags, |
2323 (unsigned long) SMFI_CURR_PROT); | 2344 (unsigned long) curr_prot); |
2324 milter_error(m, e); 2325 return -1; 2326 } 2327 | 2345 milter_error(m, e); 2346 return -1; 2347 } 2348 |
2349 if (m->mf_fvers <= 2) 2350 m->mf_pflags |= SMFIP_NOUNKNOWN; 2351 if (m->mf_fvers <= 3) 2352 m->mf_pflags |= SMFIP_NODATA; 2353 |
|
2328 if (tTd(64, 5)) 2329 sm_dprintf("milter_negotiate(%s): version %u, fflags 0x%x, pflags 0x%x\n", 2330 m->mf_name, m->mf_fvers, m->mf_fflags, m->mf_pflags); 2331 return 0; 2332} 2333/* 2334** MILTER_PER_CONNECTION_CHECK -- checks on per-connection commands 2335** --- 348 unchanged lines hidden (view full) --- 2684** Parameters: 2685** response -- encoded form of header/value. 2686** rlen -- length of response. 2687** e -- current envelope. 2688** 2689** Returns: 2690** none 2691** | 2354 if (tTd(64, 5)) 2355 sm_dprintf("milter_negotiate(%s): version %u, fflags 0x%x, pflags 0x%x\n", 2356 m->mf_name, m->mf_fvers, m->mf_fflags, m->mf_pflags); 2357 return 0; 2358} 2359/* 2360** MILTER_PER_CONNECTION_CHECK -- checks on per-connection commands 2361** --- 348 unchanged lines hidden (view full) --- 2710** Parameters: 2711** response -- encoded form of header/value. 2712** rlen -- length of response. 2713** e -- current envelope. 2714** 2715** Returns: 2716** none 2717** |
2692** Notes: 2693** Unlike milter_addheader(), this does not attempt to determine 2694** if the header already exists in the envelope, even a 2695** deleted version. It just blindly inserts. | 2718** Notes: 2719** Unlike milter_addheader(), this does not attempt to determine 2720** if the header already exists in the envelope, even a 2721** deleted version. It just blindly inserts. |
2696*/ 2697 2698static void 2699milter_insheader(response, rlen, e) 2700 char *response; 2701 ssize_t rlen; 2702 ENVELOPE *e; 2703{ --- 43 unchanged lines hidden (view full) --- 2747 2748 /* add to e_msgsize */ 2749 e->e_msgsize += strlen(response) + 2 + strlen(val); 2750 2751 if (tTd(64, 10)) 2752 sm_dprintf("Insert (%d) %s: %s\n", idx, response, val); 2753 if (MilterLogLevel > 8) 2754 sm_syslog(LOG_INFO, e->e_id, | 2722*/ 2723 2724static void 2725milter_insheader(response, rlen, e) 2726 char *response; 2727 ssize_t rlen; 2728 ENVELOPE *e; 2729{ --- 43 unchanged lines hidden (view full) --- 2773 2774 /* add to e_msgsize */ 2775 e->e_msgsize += strlen(response) + 2 + strlen(val); 2776 2777 if (tTd(64, 10)) 2778 sm_dprintf("Insert (%d) %s: %s\n", idx, response, val); 2779 if (MilterLogLevel > 8) 2780 sm_syslog(LOG_INFO, e->e_id, |
2755 "Milter insert (%d): header: %s: %s", | 2781 "Milter insert (%d): header: %s: %s", |
2756 idx, field, val); 2757 insheader(idx, newstr(field), val, H_USER, e); 2758} 2759/* 2760** MILTER_CHANGEHEADER -- Change the supplied header in the message 2761** 2762** Parameters: 2763** response -- encoded form of header/index/value. --- 1381 unchanged lines hidden --- | 2782 idx, field, val); 2783 insheader(idx, newstr(field), val, H_USER, e); 2784} 2785/* 2786** MILTER_CHANGEHEADER -- Change the supplied header in the message 2787** 2788** Parameters: 2789** response -- encoded form of header/index/value. --- 1381 unchanged lines hidden --- |