smtpd.h revision 1.631
1/* $OpenBSD: smtpd.h,v 1.631 2019/08/10 16:07:02 gilles Exp $ */ 2 3/* 4 * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> 5 * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> 6 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21#ifndef nitems 22#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 23#endif 24 25#include <netinet/in.h> 26#include <netdb.h> 27#include <event.h> 28 29#include "smtpd-defines.h" 30#include "smtpd-api.h" 31#include "ioev.h" 32 33#define CHECK_IMSG_DATA_SIZE(imsg, expected_sz) do { \ 34 if ((imsg)->hdr.len - IMSG_HEADER_SIZE != (expected_sz)) \ 35 fatalx("smtpd: imsg %d: data size expected %zd got %zd",\ 36 (imsg)->hdr.type, \ 37 (expected_sz), (imsg)->hdr.len - IMSG_HEADER_SIZE); \ 38} while (0) 39 40#define CONF_FILE "/etc/mail/smtpd.conf" 41#define MAILNAME_FILE "/etc/mail/mailname" 42#define CA_FILE "/etc/ssl/cert.pem" 43 44#define PROC_COUNT 7 45 46#define MAX_HOPS_COUNT 100 47#define DEFAULT_MAX_BODY_SIZE (35*1024*1024) 48 49#define EXPAND_BUFFER 1024 50 51#define SMTPD_QUEUE_EXPIRY (4 * 24 * 60 * 60) 52#define SMTPD_SOCKET "/var/run/smtpd.sock" 53#define SMTPD_NAME "OpenSMTPD" 54#define SMTPD_VERSION "6.6.0" 55#define SMTPD_SESSION_TIMEOUT 300 56#define SMTPD_BACKLOG 5 57 58#define PATH_SMTPCTL "/usr/sbin/smtpctl" 59 60#define PATH_OFFLINE "/offline" 61#define PATH_PURGE "/purge" 62#define PATH_TEMPORARY "/temporary" 63 64#define PATH_LIBEXEC "/usr/local/libexec/smtpd" 65 66 67/* 68 * RFC 5322 defines these characters as valid, some of them are 69 * potentially dangerous and need to be escaped. 70 */ 71#define MAILADDR_ALLOWED "!#$%&'*/?^`{|}~+-=_" 72#define MAILADDR_ESCAPE "!#$%&'*/?^`{|}~" 73 74 75#define F_STARTTLS 0x01 76#define F_SMTPS 0x02 77#define F_SSL (F_STARTTLS | F_SMTPS) 78#define F_AUTH 0x08 79#define F_STARTTLS_REQUIRE 0x20 80#define F_AUTH_REQUIRE 0x40 81#define F_MASK_SOURCE 0x100 82#define F_TLS_VERIFY 0x200 83#define F_EXT_DSN 0x400 84#define F_RECEIVEDAUTH 0x800 85#define F_MASQUERADE 0x1000 86#define F_FILTERED 0x2000 87#define F_PROXY 0x4000 88 89#define RELAY_TLS_OPPORTUNISTIC 0 90#define RELAY_TLS_STARTTLS 1 91#define RELAY_TLS_SMTPS 2 92#define RELAY_TLS_NO 3 93 94#define RELAY_AUTH 0x08 95#define RELAY_LMTP 0x80 96#define RELAY_TLS_VERIFY 0x200 97 98#define MTA_EXT_DSN 0x400 99 100 101#define P_NEWALIASES 0 102#define P_MAKEMAP 1 103 104#define CERT_ERROR -1 105#define CERT_OK 0 106#define CERT_NOCA 1 107#define CERT_NOCERT 2 108#define CERT_INVALID 3 109 110struct userinfo { 111 char username[SMTPD_VUSERNAME_SIZE]; 112 char directory[PATH_MAX]; 113 uid_t uid; 114 gid_t gid; 115}; 116 117struct netaddr { 118 struct sockaddr_storage ss; 119 int bits; 120}; 121 122struct relayhost { 123 uint16_t flags; 124 int tls; 125 char hostname[HOST_NAME_MAX+1]; 126 uint16_t port; 127 char authlabel[PATH_MAX]; 128}; 129 130struct credentials { 131 char username[LINE_MAX]; 132 char password[LINE_MAX]; 133}; 134 135struct destination { 136 char name[HOST_NAME_MAX+1]; 137}; 138 139struct source { 140 struct sockaddr_storage addr; 141}; 142 143struct addrname { 144 struct sockaddr_storage addr; 145 char name[HOST_NAME_MAX+1]; 146}; 147 148union lookup { 149 struct expand *expand; 150 struct credentials creds; 151 struct netaddr netaddr; 152 struct source source; 153 struct destination domain; 154 struct userinfo userinfo; 155 struct mailaddr mailaddr; 156 struct addrname addrname; 157 struct maddrmap *maddrmap; 158 char relayhost[LINE_MAX]; 159}; 160 161/* 162 * Bump IMSG_VERSION whenever a change is made to enum imsg_type. 163 * This will ensure that we can never use a wrong version of smtpctl with smtpd. 164 */ 165#define IMSG_VERSION 16 166 167enum imsg_type { 168 IMSG_NONE, 169 170 IMSG_CTL_OK, 171 IMSG_CTL_FAIL, 172 173 IMSG_CTL_GET_DIGEST, 174 IMSG_CTL_GET_STATS, 175 IMSG_CTL_LIST_MESSAGES, 176 IMSG_CTL_LIST_ENVELOPES, 177 IMSG_CTL_MTA_SHOW_HOSTS, 178 IMSG_CTL_MTA_SHOW_RELAYS, 179 IMSG_CTL_MTA_SHOW_ROUTES, 180 IMSG_CTL_MTA_SHOW_HOSTSTATS, 181 IMSG_CTL_MTA_BLOCK, 182 IMSG_CTL_MTA_UNBLOCK, 183 IMSG_CTL_MTA_SHOW_BLOCK, 184 IMSG_CTL_PAUSE_EVP, 185 IMSG_CTL_PAUSE_MDA, 186 IMSG_CTL_PAUSE_MTA, 187 IMSG_CTL_PAUSE_SMTP, 188 IMSG_CTL_PROFILE, 189 IMSG_CTL_PROFILE_DISABLE, 190 IMSG_CTL_PROFILE_ENABLE, 191 IMSG_CTL_RESUME_EVP, 192 IMSG_CTL_RESUME_MDA, 193 IMSG_CTL_RESUME_MTA, 194 IMSG_CTL_RESUME_SMTP, 195 IMSG_CTL_RESUME_ROUTE, 196 IMSG_CTL_REMOVE, 197 IMSG_CTL_SCHEDULE, 198 IMSG_CTL_SHOW_STATUS, 199 IMSG_CTL_TRACE_DISABLE, 200 IMSG_CTL_TRACE_ENABLE, 201 IMSG_CTL_UPDATE_TABLE, 202 IMSG_CTL_VERBOSE, 203 IMSG_CTL_DISCOVER_EVPID, 204 IMSG_CTL_DISCOVER_MSGID, 205 206 IMSG_CTL_SMTP_SESSION, 207 208 IMSG_GETADDRINFO, 209 IMSG_GETADDRINFO_END, 210 IMSG_GETNAMEINFO, 211 IMSG_RES_QUERY, 212 213 IMSG_CERT_INIT, 214 IMSG_CERT_CERTIFICATE, 215 IMSG_CERT_VERIFY, 216 217 IMSG_SETUP_KEY, 218 IMSG_SETUP_PEER, 219 IMSG_SETUP_DONE, 220 221 IMSG_CONF_START, 222 IMSG_CONF_END, 223 224 IMSG_STAT_INCREMENT, 225 IMSG_STAT_DECREMENT, 226 IMSG_STAT_SET, 227 228 IMSG_LKA_AUTHENTICATE, 229 IMSG_LKA_OPEN_FORWARD, 230 IMSG_LKA_ENVELOPE_SUBMIT, 231 IMSG_LKA_ENVELOPE_COMMIT, 232 233 IMSG_QUEUE_DELIVER, 234 IMSG_QUEUE_DELIVERY_OK, 235 IMSG_QUEUE_DELIVERY_TEMPFAIL, 236 IMSG_QUEUE_DELIVERY_PERMFAIL, 237 IMSG_QUEUE_DELIVERY_LOOP, 238 IMSG_QUEUE_DISCOVER_EVPID, 239 IMSG_QUEUE_DISCOVER_MSGID, 240 IMSG_QUEUE_ENVELOPE_ACK, 241 IMSG_QUEUE_ENVELOPE_COMMIT, 242 IMSG_QUEUE_ENVELOPE_REMOVE, 243 IMSG_QUEUE_ENVELOPE_SCHEDULE, 244 IMSG_QUEUE_ENVELOPE_SUBMIT, 245 IMSG_QUEUE_HOLDQ_HOLD, 246 IMSG_QUEUE_HOLDQ_RELEASE, 247 IMSG_QUEUE_MESSAGE_COMMIT, 248 IMSG_QUEUE_MESSAGE_ROLLBACK, 249 IMSG_QUEUE_SMTP_SESSION, 250 IMSG_QUEUE_TRANSFER, 251 252 IMSG_MDA_DELIVERY_OK, 253 IMSG_MDA_DELIVERY_TEMPFAIL, 254 IMSG_MDA_DELIVERY_PERMFAIL, 255 IMSG_MDA_DELIVERY_LOOP, 256 IMSG_MDA_DELIVERY_HOLD, 257 IMSG_MDA_DONE, 258 IMSG_MDA_FORK, 259 IMSG_MDA_HOLDQ_RELEASE, 260 IMSG_MDA_LOOKUP_USERINFO, 261 IMSG_MDA_KILL, 262 IMSG_MDA_OPEN_MESSAGE, 263 264 IMSG_MTA_DELIVERY_OK, 265 IMSG_MTA_DELIVERY_TEMPFAIL, 266 IMSG_MTA_DELIVERY_PERMFAIL, 267 IMSG_MTA_DELIVERY_LOOP, 268 IMSG_MTA_DELIVERY_HOLD, 269 IMSG_MTA_DNS_HOST, 270 IMSG_MTA_DNS_HOST_END, 271 IMSG_MTA_DNS_MX, 272 IMSG_MTA_DNS_MX_PREFERENCE, 273 IMSG_MTA_HOLDQ_RELEASE, 274 IMSG_MTA_LOOKUP_CREDENTIALS, 275 IMSG_MTA_LOOKUP_SOURCE, 276 IMSG_MTA_LOOKUP_HELO, 277 IMSG_MTA_LOOKUP_SMARTHOST, 278 IMSG_MTA_OPEN_MESSAGE, 279 IMSG_MTA_SCHEDULE, 280 281 IMSG_SCHED_ENVELOPE_BOUNCE, 282 IMSG_SCHED_ENVELOPE_DELIVER, 283 IMSG_SCHED_ENVELOPE_EXPIRE, 284 IMSG_SCHED_ENVELOPE_INJECT, 285 IMSG_SCHED_ENVELOPE_REMOVE, 286 IMSG_SCHED_ENVELOPE_TRANSFER, 287 288 IMSG_SMTP_AUTHENTICATE, 289 IMSG_SMTP_MESSAGE_COMMIT, 290 IMSG_SMTP_MESSAGE_CREATE, 291 IMSG_SMTP_MESSAGE_ROLLBACK, 292 IMSG_SMTP_MESSAGE_OPEN, 293 IMSG_SMTP_CHECK_SENDER, 294 IMSG_SMTP_EXPAND_RCPT, 295 IMSG_SMTP_LOOKUP_HELO, 296 297 IMSG_SMTP_REQ_CONNECT, 298 IMSG_SMTP_REQ_HELO, 299 IMSG_SMTP_REQ_MAIL, 300 IMSG_SMTP_REQ_RCPT, 301 IMSG_SMTP_REQ_DATA, 302 IMSG_SMTP_REQ_EOM, 303 IMSG_SMTP_EVENT_RSET, 304 IMSG_SMTP_EVENT_COMMIT, 305 IMSG_SMTP_EVENT_ROLLBACK, 306 IMSG_SMTP_EVENT_DISCONNECT, 307 308 IMSG_LKA_PROCESSOR_FORK, 309 IMSG_LKA_PROCESSOR_ERRFD, 310 311 IMSG_REPORT_SMTP_LINK_CONNECT, 312 IMSG_REPORT_SMTP_LINK_DISCONNECT, 313 IMSG_REPORT_SMTP_LINK_IDENTIFY, 314 IMSG_REPORT_SMTP_LINK_TLS, 315 IMSG_REPORT_SMTP_LINK_AUTH, 316 IMSG_REPORT_SMTP_TX_RESET, 317 IMSG_REPORT_SMTP_TX_BEGIN, 318 IMSG_REPORT_SMTP_TX_MAIL, 319 IMSG_REPORT_SMTP_TX_RCPT, 320 IMSG_REPORT_SMTP_TX_ENVELOPE, 321 IMSG_REPORT_SMTP_TX_DATA, 322 IMSG_REPORT_SMTP_TX_COMMIT, 323 IMSG_REPORT_SMTP_TX_ROLLBACK, 324 IMSG_REPORT_SMTP_PROTOCOL_CLIENT, 325 IMSG_REPORT_SMTP_PROTOCOL_SERVER, 326 IMSG_REPORT_SMTP_FILTER_RESPONSE, 327 IMSG_REPORT_SMTP_TIMEOUT, 328 329 IMSG_FILTER_SMTP_BEGIN, 330 IMSG_FILTER_SMTP_END, 331 IMSG_FILTER_SMTP_PROTOCOL, 332 IMSG_FILTER_SMTP_DATA_BEGIN, 333 IMSG_FILTER_SMTP_DATA_END, 334 335 IMSG_CA_RSA_PRIVENC, 336 IMSG_CA_RSA_PRIVDEC, 337 IMSG_CA_ECDSA_SIGN, 338}; 339 340enum smtp_proc_type { 341 PROC_PARENT = 0, 342 PROC_LKA, 343 PROC_QUEUE, 344 PROC_CONTROL, 345 PROC_SCHEDULER, 346 PROC_PONY, 347 PROC_CA, 348 PROC_PROCESSOR, 349 PROC_CLIENT, 350}; 351 352enum table_type { 353 T_NONE = 0, 354 T_DYNAMIC = 0x01, /* table with external source */ 355 T_LIST = 0x02, /* table holding a list */ 356 T_HASH = 0x04, /* table holding a hash table */ 357}; 358 359struct table { 360 char t_name[LINE_MAX]; 361 enum table_type t_type; 362 char t_config[PATH_MAX]; 363 364 void *t_handle; 365 struct table_backend *t_backend; 366}; 367 368struct table_backend { 369 const char *name; 370 const unsigned int services; 371 int (*config)(struct table *); 372 int (*add)(struct table *, const char *, const char *); 373 void (*dump)(struct table *); 374 int (*open)(struct table *); 375 int (*update)(struct table *); 376 void (*close)(struct table *); 377 int (*lookup)(struct table *, enum table_service, const char *, char **); 378 int (*fetch)(struct table *, enum table_service, char **); 379}; 380 381 382enum bounce_type { 383 B_FAILED, 384 B_DELAYED, 385 B_DELIVERED 386}; 387 388enum dsn_ret { 389 DSN_RETFULL = 1, 390 DSN_RETHDRS 391}; 392 393struct delivery_bounce { 394 enum bounce_type type; 395 time_t delay; 396 time_t ttl; 397 enum dsn_ret dsn_ret; 398 int mta_without_dsn; 399}; 400 401enum expand_type { 402 EXPAND_INVALID, 403 EXPAND_USERNAME, 404 EXPAND_FILENAME, 405 EXPAND_FILTER, 406 EXPAND_INCLUDE, 407 EXPAND_ADDRESS, 408 EXPAND_ERROR, 409}; 410 411enum filter_phase { 412 FILTER_CONNECT, 413 FILTER_HELO, 414 FILTER_EHLO, 415 FILTER_STARTTLS, 416 FILTER_AUTH, 417 FILTER_MAIL_FROM, 418 FILTER_RCPT_TO, 419 FILTER_DATA, 420 FILTER_DATA_LINE, 421 FILTER_RSET, 422 FILTER_QUIT, 423 FILTER_NOOP, 424 FILTER_HELP, 425 FILTER_WIZ, 426 FILTER_COMMIT, 427 FILTER_PHASES_COUNT /* must be last */ 428}; 429 430struct expandnode { 431 RB_ENTRY(expandnode) entry; 432 TAILQ_ENTRY(expandnode) tq_entry; 433 enum expand_type type; 434 int sameuser; 435 int realuser; 436 int forwarded; 437 struct rule *rule; 438 struct expandnode *parent; 439 unsigned int depth; 440 union { 441 /* 442 * user field handles both expansion user and system user 443 * so we MUST make it large enough to fit a mailaddr user 444 */ 445 char user[SMTPD_MAXLOCALPARTSIZE]; 446 char buffer[EXPAND_BUFFER]; 447 struct mailaddr mailaddr; 448 } u; 449 char subaddress[SMTPD_SUBADDRESS_SIZE]; 450}; 451 452struct expand { 453 RB_HEAD(expandtree, expandnode) tree; 454 TAILQ_HEAD(xnodes, expandnode) *queue; 455 size_t nb_nodes; 456 struct rule *rule; 457 struct expandnode *parent; 458}; 459 460struct maddrnode { 461 TAILQ_ENTRY(maddrnode) entries; 462 struct mailaddr mailaddr; 463}; 464 465struct maddrmap { 466 TAILQ_HEAD(xmaddr, maddrnode) queue; 467}; 468 469#define DSN_SUCCESS 0x01 470#define DSN_FAILURE 0x02 471#define DSN_DELAY 0x04 472#define DSN_NEVER 0x08 473 474#define DSN_ENVID_LEN 100 475 476#define SMTPD_ENVELOPE_VERSION 3 477struct envelope { 478 TAILQ_ENTRY(envelope) entry; 479 480 char dispatcher[HOST_NAME_MAX+1]; 481 482 char tag[SMTPD_TAG_SIZE]; 483 484 uint32_t version; 485 uint64_t id; 486 enum envelope_flags flags; 487 488 char smtpname[HOST_NAME_MAX+1]; 489 char helo[HOST_NAME_MAX+1]; 490 char hostname[HOST_NAME_MAX+1]; 491 char errorline[LINE_MAX]; 492 struct sockaddr_storage ss; 493 494 struct mailaddr sender; 495 struct mailaddr rcpt; 496 struct mailaddr dest; 497 498 char mda_user[SMTPD_VUSERNAME_SIZE]; 499 char mda_subaddress[SMTPD_SUBADDRESS_SIZE]; 500 char mda_exec[LINE_MAX]; 501 502 enum delivery_type type; 503 union { 504 struct delivery_bounce bounce; 505 } agent; 506 507 uint16_t retry; 508 time_t creation; 509 time_t ttl; 510 time_t lasttry; 511 time_t nexttry; 512 time_t lastbounce; 513 514 struct mailaddr dsn_orcpt; 515 char dsn_envid[DSN_ENVID_LEN+1]; 516 uint8_t dsn_notify; 517 enum dsn_ret dsn_ret; 518 519 uint8_t esc_class; 520 uint8_t esc_code; 521}; 522 523struct listener { 524 uint16_t flags; 525 int fd; 526 struct sockaddr_storage ss; 527 in_port_t port; 528 struct timeval timeout; 529 struct event ev; 530 char filter_name[PATH_MAX]; 531 char pki_name[PATH_MAX]; 532 char ca_name[PATH_MAX]; 533 char tag[SMTPD_TAG_SIZE]; 534 char authtable[LINE_MAX]; 535 char hostname[HOST_NAME_MAX+1]; 536 char hostnametable[PATH_MAX]; 537 char sendertable[PATH_MAX]; 538 539 TAILQ_ENTRY(listener) entry; 540 541 int local; /* there must be a better way */ 542}; 543 544struct smtpd { 545 char sc_conffile[PATH_MAX]; 546 size_t sc_maxsize; 547 548#define SMTPD_OPT_VERBOSE 0x00000001 549#define SMTPD_OPT_NOACTION 0x00000002 550 uint32_t sc_opts; 551 552#define SMTPD_EXITING 0x00000001 /* unused */ 553#define SMTPD_MDA_PAUSED 0x00000002 554#define SMTPD_MTA_PAUSED 0x00000004 555#define SMTPD_SMTP_PAUSED 0x00000008 556#define SMTPD_MDA_BUSY 0x00000010 557#define SMTPD_MTA_BUSY 0x00000020 558#define SMTPD_BOUNCE_BUSY 0x00000040 559#define SMTPD_SMTP_DISABLED 0x00000080 560 uint32_t sc_flags; 561 562#define QUEUE_COMPRESSION 0x00000001 563#define QUEUE_ENCRYPTION 0x00000002 564#define QUEUE_EVPCACHE 0x00000004 565 uint32_t sc_queue_flags; 566 char *sc_queue_key; 567 size_t sc_queue_evpcache_size; 568 569 size_t sc_session_max_rcpt; 570 size_t sc_session_max_mails; 571 572 struct dict *sc_mda_wrappers; 573 size_t sc_mda_max_session; 574 size_t sc_mda_max_user_session; 575 size_t sc_mda_task_hiwat; 576 size_t sc_mda_task_lowat; 577 size_t sc_mda_task_release; 578 579 size_t sc_mta_max_deferred; 580 581 size_t sc_scheduler_max_inflight; 582 size_t sc_scheduler_max_evp_batch_size; 583 size_t sc_scheduler_max_msg_batch_size; 584 size_t sc_scheduler_max_schedule; 585 586 struct dict *sc_processors_dict; 587 588 int sc_ttl; 589#define MAX_BOUNCE_WARN 4 590 time_t sc_bounce_warn[MAX_BOUNCE_WARN]; 591 char sc_hostname[HOST_NAME_MAX+1]; 592 struct stat_backend *sc_stat; 593 struct compress_backend *sc_comp; 594 595 time_t sc_uptime; 596 597 /* This is a listener for a local socket used by smtp_enqueue(). */ 598 struct listener *sc_sock_listener; 599 600 TAILQ_HEAD(listenerlist, listener) *sc_listeners; 601 602 TAILQ_HEAD(rulelist, rule) *sc_rules; 603 604 605 struct dict *sc_filters_dict; 606 struct dict *sc_dispatchers; 607 struct dispatcher *sc_dispatcher_bounce; 608 609 struct dict *sc_ca_dict; 610 struct dict *sc_pki_dict; 611 struct dict *sc_ssl_dict; 612 613 struct dict *sc_tables_dict; /* keyed lookup */ 614 615 struct dict *sc_limits_dict; 616 617 char *sc_tls_ciphers; 618 619 char *sc_subaddressing_delim; 620}; 621 622#define TRACE_DEBUG 0x0001 623#define TRACE_IMSG 0x0002 624#define TRACE_IO 0x0004 625#define TRACE_SMTP 0x0008 626#define TRACE_FILTERS 0x0010 627#define TRACE_MTA 0x0020 628#define TRACE_BOUNCE 0x0040 629#define TRACE_SCHEDULER 0x0080 630#define TRACE_LOOKUP 0x0100 631#define TRACE_STAT 0x0200 632#define TRACE_RULES 0x0400 633#define TRACE_MPROC 0x0800 634#define TRACE_EXPAND 0x1000 635#define TRACE_TABLES 0x2000 636#define TRACE_QUEUE 0x4000 637 638#define PROFILE_TOSTAT 0x0001 639#define PROFILE_IMSG 0x0002 640#define PROFILE_QUEUE 0x0004 641 642struct forward_req { 643 uint64_t id; 644 uint8_t status; 645 646 char user[SMTPD_VUSERNAME_SIZE]; 647 uid_t uid; 648 gid_t gid; 649 char directory[PATH_MAX]; 650}; 651 652struct deliver { 653 char dispatcher[EXPAND_BUFFER]; 654 655 struct mailaddr sender; 656 struct mailaddr rcpt; 657 struct mailaddr dest; 658 659 char mda_subaddress[SMTPD_SUBADDRESS_SIZE]; 660 char mda_exec[LINE_MAX]; 661 662 struct userinfo userinfo; 663}; 664 665struct mta_host { 666 SPLAY_ENTRY(mta_host) entry; 667 struct sockaddr *sa; 668 char *ptrname; 669 int refcount; 670 size_t nconn; 671 time_t lastconn; 672 time_t lastptrquery; 673 674#define HOST_IGNORE 0x01 675 int flags; 676}; 677 678struct mta_mx { 679 TAILQ_ENTRY(mta_mx) entry; 680 struct mta_host *host; 681 int preference; 682}; 683 684struct mta_domain { 685 SPLAY_ENTRY(mta_domain) entry; 686 char *name; 687 int as_host; 688 TAILQ_HEAD(, mta_mx) mxs; 689 int mxstatus; 690 int refcount; 691 size_t nconn; 692 time_t lastconn; 693 time_t lastmxquery; 694}; 695 696struct mta_source { 697 SPLAY_ENTRY(mta_source) entry; 698 struct sockaddr *sa; 699 int refcount; 700 size_t nconn; 701 time_t lastconn; 702}; 703 704struct mta_connector { 705 struct mta_source *source; 706 struct mta_relay *relay; 707 708#define CONNECTOR_ERROR_FAMILY 0x0001 709#define CONNECTOR_ERROR_SOURCE 0x0002 710#define CONNECTOR_ERROR_MX 0x0004 711#define CONNECTOR_ERROR_ROUTE_NET 0x0008 712#define CONNECTOR_ERROR_ROUTE_SMTP 0x0010 713#define CONNECTOR_ERROR_ROUTE 0x0018 714#define CONNECTOR_ERROR_BLOCKED 0x0020 715#define CONNECTOR_ERROR 0x00ff 716 717#define CONNECTOR_LIMIT_HOST 0x0100 718#define CONNECTOR_LIMIT_ROUTE 0x0200 719#define CONNECTOR_LIMIT_SOURCE 0x0400 720#define CONNECTOR_LIMIT_RELAY 0x0800 721#define CONNECTOR_LIMIT_CONN 0x1000 722#define CONNECTOR_LIMIT_DOMAIN 0x2000 723#define CONNECTOR_LIMIT 0xff00 724 725#define CONNECTOR_NEW 0x10000 726#define CONNECTOR_WAIT 0x20000 727 int flags; 728 729 int refcount; 730 size_t nconn; 731 time_t lastconn; 732}; 733 734struct mta_route { 735 SPLAY_ENTRY(mta_route) entry; 736 uint64_t id; 737 struct mta_source *src; 738 struct mta_host *dst; 739#define ROUTE_NEW 0x01 740#define ROUTE_RUNQ 0x02 741#define ROUTE_KEEPALIVE 0x04 742#define ROUTE_DISABLED 0xf0 743#define ROUTE_DISABLED_NET 0x10 744#define ROUTE_DISABLED_SMTP 0x20 745 int flags; 746 int nerror; 747 int penalty; 748 int refcount; 749 size_t nconn; 750 time_t lastconn; 751 time_t lastdisc; 752 time_t lastpenalty; 753}; 754 755struct mta_limits { 756 size_t maxconn_per_host; 757 size_t maxconn_per_route; 758 size_t maxconn_per_source; 759 size_t maxconn_per_connector; 760 size_t maxconn_per_relay; 761 size_t maxconn_per_domain; 762 763 time_t conndelay_host; 764 time_t conndelay_route; 765 time_t conndelay_source; 766 time_t conndelay_connector; 767 time_t conndelay_relay; 768 time_t conndelay_domain; 769 770 time_t discdelay_route; 771 772 size_t max_mail_per_session; 773 time_t sessdelay_transaction; 774 time_t sessdelay_keepalive; 775 776 size_t max_failures_per_session; 777 778 int family; 779 780 int task_hiwat; 781 int task_lowat; 782 int task_release; 783}; 784 785struct mta_relay { 786 SPLAY_ENTRY(mta_relay) entry; 787 uint64_t id; 788 789 struct dispatcher *dispatcher; 790 struct mta_domain *domain; 791 struct mta_limits *limits; 792 int tls; 793 int flags; 794 char *backupname; 795 int backuppref; 796 char *sourcetable; 797 uint16_t port; 798 char *pki_name; 799 char *ca_name; 800 char *authtable; 801 char *authlabel; 802 char *helotable; 803 char *heloname; 804 char *secret; 805 806 int state; 807 size_t ntask; 808 TAILQ_HEAD(, mta_task) tasks; 809 810 struct tree connectors; 811 size_t sourceloop; 812 time_t lastsource; 813 time_t nextsource; 814 815 int fail; 816 char *failstr; 817 818#define RELAY_WAIT_MX 0x01 819#define RELAY_WAIT_PREFERENCE 0x02 820#define RELAY_WAIT_SECRET 0x04 821#define RELAY_WAIT_LIMITS 0x08 822#define RELAY_WAIT_SOURCE 0x10 823#define RELAY_WAIT_CONNECTOR 0x20 824#define RELAY_WAIT_SMARTHOST 0x40 825#define RELAY_WAITMASK 0x7f 826 int status; 827 828 int refcount; 829 size_t nconn; 830 size_t nconn_ready; 831 time_t lastconn; 832}; 833 834struct mta_envelope { 835 TAILQ_ENTRY(mta_envelope) entry; 836 uint64_t id; 837 uint64_t session; 838 time_t creation; 839 char *smtpname; 840 char *dest; 841 char *rcpt; 842 struct mta_task *task; 843 int delivery; 844 845 int ext; 846 char *dsn_orcpt; 847 char dsn_envid[DSN_ENVID_LEN+1]; 848 uint8_t dsn_notify; 849 enum dsn_ret dsn_ret; 850 851 char status[LINE_MAX]; 852}; 853 854struct mta_task { 855 TAILQ_ENTRY(mta_task) entry; 856 struct mta_relay *relay; 857 uint32_t msgid; 858 TAILQ_HEAD(, mta_envelope) envelopes; 859 char *sender; 860}; 861 862struct passwd; 863 864struct queue_backend { 865 int (*init)(struct passwd *, int, const char *); 866}; 867 868struct compress_backend { 869 size_t (*compress_chunk)(void *, size_t, void *, size_t); 870 size_t (*uncompress_chunk)(void *, size_t, void *, size_t); 871 int (*compress_file)(FILE *, FILE *); 872 int (*uncompress_file)(FILE *, FILE *); 873}; 874 875/* auth structures */ 876enum auth_type { 877 AUTH_BSD, 878 AUTH_PWD, 879}; 880 881struct auth_backend { 882 int (*authenticate)(char *, char *); 883}; 884 885struct scheduler_backend { 886 int (*init)(const char *); 887 888 int (*insert)(struct scheduler_info *); 889 size_t (*commit)(uint32_t); 890 size_t (*rollback)(uint32_t); 891 892 int (*update)(struct scheduler_info *); 893 int (*delete)(uint64_t); 894 int (*hold)(uint64_t, uint64_t); 895 int (*release)(int, uint64_t, int); 896 897 int (*batch)(int, int*, size_t*, uint64_t*, int*); 898 899 size_t (*messages)(uint32_t, uint32_t *, size_t); 900 size_t (*envelopes)(uint64_t, struct evpstate *, size_t); 901 int (*schedule)(uint64_t); 902 int (*remove)(uint64_t); 903 int (*suspend)(uint64_t); 904 int (*resume)(uint64_t); 905 int (*query)(uint64_t); 906}; 907 908enum stat_type { 909 STAT_COUNTER, 910 STAT_TIMESTAMP, 911 STAT_TIMEVAL, 912 STAT_TIMESPEC, 913}; 914 915struct stat_value { 916 enum stat_type type; 917 union stat_v { 918 size_t counter; 919 time_t timestamp; 920 struct timeval tv; 921 struct timespec ts; 922 } u; 923}; 924 925#define STAT_KEY_SIZE 1024 926struct stat_kv { 927 void *iter; 928 char key[STAT_KEY_SIZE]; 929 struct stat_value val; 930}; 931 932struct stat_backend { 933 void (*init)(void); 934 void (*close)(void); 935 void (*increment)(const char *, size_t); 936 void (*decrement)(const char *, size_t); 937 void (*set)(const char *, const struct stat_value *); 938 int (*iter)(void **, char **, struct stat_value *); 939}; 940 941struct stat_digest { 942 time_t startup; 943 time_t timestamp; 944 945 size_t clt_connect; 946 size_t clt_disconnect; 947 948 size_t evp_enqueued; 949 size_t evp_dequeued; 950 951 size_t evp_expired; 952 size_t evp_removed; 953 size_t evp_bounce; 954 955 size_t dlv_ok; 956 size_t dlv_permfail; 957 size_t dlv_tempfail; 958 size_t dlv_loop; 959}; 960 961 962struct mproc { 963 pid_t pid; 964 char *name; 965 int proc; 966 void (*handler)(struct mproc *, struct imsg *); 967 struct imsgbuf imsgbuf; 968 969 char *m_buf; 970 size_t m_alloc; 971 size_t m_pos; 972 uint32_t m_type; 973 uint32_t m_peerid; 974 pid_t m_pid; 975 int m_fd; 976 977 int enable; 978 short events; 979 struct event ev; 980 void *data; 981}; 982 983struct msg { 984 const uint8_t *pos; 985 const uint8_t *end; 986}; 987 988extern enum smtp_proc_type smtpd_process; 989 990extern int tracing; 991extern int foreground_log; 992extern int profiling; 993 994extern struct mproc *p_control; 995extern struct mproc *p_parent; 996extern struct mproc *p_lka; 997extern struct mproc *p_queue; 998extern struct mproc *p_scheduler; 999extern struct mproc *p_pony; 1000extern struct mproc *p_ca; 1001 1002extern struct smtpd *env; 1003extern void (*imsg_callback)(struct mproc *, struct imsg *); 1004 1005/* inter-process structures */ 1006 1007struct bounce_req_msg { 1008 uint64_t evpid; 1009 time_t timestamp; 1010 struct delivery_bounce bounce; 1011}; 1012 1013enum dns_error { 1014 DNS_OK = 0, 1015 DNS_RETRY, 1016 DNS_EINVAL, 1017 DNS_ENONAME, 1018 DNS_ENOTFOUND, 1019}; 1020 1021enum lka_resp_status { 1022 LKA_OK, 1023 LKA_TEMPFAIL, 1024 LKA_PERMFAIL 1025}; 1026 1027struct processor { 1028 const char *command; 1029 const char *user; 1030 const char *group; 1031 const char *chroot; 1032 int errfd; 1033}; 1034 1035enum filter_type { 1036 FILTER_TYPE_BUILTIN, 1037 FILTER_TYPE_PROC, 1038 FILTER_TYPE_CHAIN, 1039}; 1040 1041struct filter_config { 1042 char *name; 1043 enum filter_type filter_type; 1044 enum filter_phase phase; 1045 char *reject; 1046 char *disconnect; 1047 char *rewrite; 1048 char *proc; 1049 1050 const char **chain; 1051 size_t chain_size; 1052 struct dict chain_procs; 1053 1054 int8_t not_fcrdns; 1055 int8_t fcrdns; 1056 1057 int8_t not_rdns; 1058 int8_t rdns; 1059 1060 int8_t not_rdns_table; 1061 struct table *rdns_table; 1062 1063 int8_t not_rdns_regex; 1064 struct table *rdns_regex; 1065 1066 int8_t not_src_table; 1067 struct table *src_table; 1068 1069 int8_t not_src_regex; 1070 struct table *src_regex; 1071 1072 int8_t not_helo_table; 1073 struct table *helo_table; 1074 1075 int8_t not_helo_regex; 1076 struct table *helo_regex; 1077 1078 int8_t not_mail_from_table; 1079 struct table *mail_from_table; 1080 1081 int8_t not_mail_from_regex; 1082 struct table *mail_from_regex; 1083 1084 int8_t not_rcpt_to_table; 1085 struct table *rcpt_to_table; 1086 1087 int8_t not_rcpt_to_regex; 1088 struct table *rcpt_to_regex; 1089 1090}; 1091 1092enum filter_status { 1093 FILTER_PROCEED, 1094 FILTER_REWRITE, 1095 FILTER_REJECT, 1096 FILTER_DISCONNECT, 1097}; 1098 1099enum ca_resp_status { 1100 CA_OK, 1101 CA_FAIL 1102}; 1103 1104enum mda_resp_status { 1105 MDA_OK, 1106 MDA_TEMPFAIL, 1107 MDA_PERMFAIL 1108}; 1109 1110struct msg_walkinfo { 1111 struct event ev; 1112 uint32_t msgid; 1113 uint32_t peerid; 1114 size_t n_evp; 1115 void *data; 1116 int done; 1117}; 1118 1119 1120enum dispatcher_type { 1121 DISPATCHER_LOCAL, 1122 DISPATCHER_REMOTE, 1123 DISPATCHER_BOUNCE, 1124}; 1125 1126struct dispatcher_local { 1127 uint8_t requires_root; /* only for MBOX */ 1128 1129 uint8_t expand_only; 1130 uint8_t forward_only; 1131 1132 char *mda_wrapper; 1133 char *command; 1134 1135 char *table_alias; 1136 char *table_virtual; 1137 char *table_userbase; 1138 1139 char *user; 1140}; 1141 1142struct dispatcher_remote { 1143 char *helo; 1144 char *helo_source; 1145 1146 char *source; 1147 1148 char *ca; 1149 char *pki; 1150 1151 char *mail_from; 1152 1153 char *smarthost; 1154 char *auth; 1155 int tls_required; 1156 int tls_noverify; 1157 1158 int backup; 1159 char *backupmx; 1160}; 1161 1162struct dispatcher_bounce { 1163}; 1164 1165struct dispatcher { 1166 enum dispatcher_type type; 1167 union dispatcher_agent { 1168 struct dispatcher_local local; 1169 struct dispatcher_remote remote; 1170 struct dispatcher_bounce bounce; 1171 } u; 1172 1173 time_t ttl; 1174}; 1175 1176struct rule { 1177 TAILQ_ENTRY(rule) r_entry; 1178 1179 uint8_t reject; 1180 1181 int8_t flag_tag; 1182 int8_t flag_from; 1183 int8_t flag_for; 1184 int8_t flag_from_rdns; 1185 int8_t flag_from_socket; 1186 1187 int8_t flag_tag_regex; 1188 int8_t flag_from_regex; 1189 int8_t flag_for_regex; 1190 1191 int8_t flag_smtp_helo; 1192 int8_t flag_smtp_starttls; 1193 int8_t flag_smtp_auth; 1194 int8_t flag_smtp_mail_from; 1195 int8_t flag_smtp_rcpt_to; 1196 1197 int8_t flag_smtp_helo_regex; 1198 int8_t flag_smtp_starttls_regex; 1199 int8_t flag_smtp_auth_regex; 1200 int8_t flag_smtp_mail_from_regex; 1201 int8_t flag_smtp_rcpt_to_regex; 1202 1203 1204 char *table_tag; 1205 char *table_from; 1206 char *table_for; 1207 1208 char *table_smtp_helo; 1209 char *table_smtp_auth; 1210 char *table_smtp_mail_from; 1211 char *table_smtp_rcpt_to; 1212 1213 char *dispatcher; 1214}; 1215 1216 1217/* aliases.c */ 1218int aliases_get(struct expand *, const char *); 1219int aliases_virtual_get(struct expand *, const struct mailaddr *); 1220int alias_parse(struct expandnode *, const char *); 1221 1222 1223/* auth.c */ 1224struct auth_backend *auth_backend_lookup(enum auth_type); 1225 1226 1227/* bounce.c */ 1228void bounce_add(uint64_t); 1229void bounce_fd(int); 1230 1231 1232/* ca.c */ 1233int ca(void); 1234int ca_X509_verify(void *, void *, const char *, const char *, const char **); 1235void ca_imsg(struct mproc *, struct imsg *); 1236void ca_init(void); 1237void ca_engine_init(void); 1238 1239 1240/* cert.c */ 1241int cert_init(const char *, int, 1242 void (*)(void *, int, const char *, const void *, size_t), void *); 1243int cert_verify(const void *, const char *, int, void (*)(void *, int), void *); 1244void cert_dispatch_request(struct mproc *, struct imsg *); 1245void cert_dispatch_result(struct mproc *, struct imsg *); 1246 1247 1248/* compress_backend.c */ 1249struct compress_backend *compress_backend_lookup(const char *); 1250size_t compress_chunk(void *, size_t, void *, size_t); 1251size_t uncompress_chunk(void *, size_t, void *, size_t); 1252int compress_file(FILE *, FILE *); 1253int uncompress_file(FILE *, FILE *); 1254 1255/* config.c */ 1256#define PURGE_LISTENERS 0x01 1257#define PURGE_TABLES 0x02 1258#define PURGE_RULES 0x04 1259#define PURGE_PKI 0x08 1260#define PURGE_PKI_KEYS 0x10 1261#define PURGE_DISPATCHERS 0x20 1262#define PURGE_EVERYTHING 0xff 1263struct smtpd *config_default(void); 1264void purge_config(uint8_t); 1265void config_process(enum smtp_proc_type); 1266void config_peer(enum smtp_proc_type); 1267 1268 1269/* control.c */ 1270int control(void); 1271int control_create_socket(void); 1272 1273 1274/* crypto.c */ 1275int crypto_setup(const char *, size_t); 1276int crypto_encrypt_file(FILE *, FILE *); 1277int crypto_decrypt_file(FILE *, FILE *); 1278size_t crypto_encrypt_buffer(const char *, size_t, char *, size_t); 1279size_t crypto_decrypt_buffer(const char *, size_t, char *, size_t); 1280 1281 1282/* dns.c */ 1283void dns_imsg(struct mproc *, struct imsg *); 1284 1285 1286/* enqueue.c */ 1287int enqueue(int, char **, FILE *); 1288 1289 1290/* envelope.c */ 1291void envelope_set_errormsg(struct envelope *, char *, ...); 1292void envelope_set_esc_class(struct envelope *, enum enhanced_status_class); 1293void envelope_set_esc_code(struct envelope *, enum enhanced_status_code); 1294int envelope_load_buffer(struct envelope *, const char *, size_t); 1295int envelope_dump_buffer(const struct envelope *, char *, size_t); 1296 1297 1298/* expand.c */ 1299int expand_cmp(struct expandnode *, struct expandnode *); 1300void expand_insert(struct expand *, struct expandnode *); 1301struct expandnode *expand_lookup(struct expand *, struct expandnode *); 1302void expand_clear(struct expand *); 1303void expand_free(struct expand *); 1304int expand_line(struct expand *, const char *, int); 1305int expand_to_text(struct expand *, char *, size_t); 1306RB_PROTOTYPE(expandtree, expandnode, nodes, expand_cmp); 1307 1308 1309/* forward.c */ 1310int forwards_get(int, struct expand *); 1311 1312 1313/* limit.c */ 1314void limit_mta_set_defaults(struct mta_limits *); 1315int limit_mta_set(struct mta_limits *, const char*, int64_t); 1316 1317 1318/* lka.c */ 1319int lka(void); 1320 1321 1322/* lka_proc.c */ 1323int lka_proc_ready(void); 1324void lka_proc_forked(const char *, int); 1325void lka_proc_errfd(const char *, int); 1326struct io *lka_proc_get_io(const char *); 1327 1328 1329/* lka_report.c */ 1330void lka_report_init(void); 1331void lka_report_register_hook(const char *, const char *); 1332void lka_report_smtp_link_connect(const char *, struct timeval *, uint64_t, const char *, int, 1333 const struct sockaddr_storage *, const struct sockaddr_storage *); 1334void lka_report_smtp_link_disconnect(const char *, struct timeval *, uint64_t); 1335void lka_report_smtp_link_identify(const char *, struct timeval *, uint64_t, const char *, const char *); 1336void lka_report_smtp_link_tls(const char *, struct timeval *, uint64_t, const char *); 1337void lka_report_smtp_link_auth(const char *, struct timeval *, uint64_t, const char *, const char *); 1338void lka_report_smtp_tx_reset(const char *, struct timeval *, uint64_t, uint32_t); 1339void lka_report_smtp_tx_begin(const char *, struct timeval *, uint64_t, uint32_t); 1340void lka_report_smtp_tx_mail(const char *, struct timeval *, uint64_t, uint32_t, const char *, int); 1341void lka_report_smtp_tx_rcpt(const char *, struct timeval *, uint64_t, uint32_t, const char *, int); 1342void lka_report_smtp_tx_envelope(const char *, struct timeval *, uint64_t, uint32_t, uint64_t); 1343void lka_report_smtp_tx_commit(const char *, struct timeval *, uint64_t, uint32_t, size_t); 1344void lka_report_smtp_tx_data(const char *, struct timeval *, uint64_t, uint32_t, int); 1345void lka_report_smtp_tx_rollback(const char *, struct timeval *, uint64_t, uint32_t); 1346void lka_report_smtp_protocol_client(const char *, struct timeval *, uint64_t, const char *); 1347void lka_report_smtp_protocol_server(const char *, struct timeval *, uint64_t, const char *); 1348void lka_report_smtp_filter_response(const char *, struct timeval *, uint64_t, 1349 int, int, const char *); 1350void lka_report_smtp_timeout(const char *, struct timeval *, uint64_t); 1351 1352 1353/* lka_filter.c */ 1354void lka_filter_init(void); 1355void lka_filter_register_hook(const char *, const char *); 1356void lka_filter_ready(void); 1357int lka_filter_proc_in_session(uint64_t, const char *); 1358void lka_filter_begin(uint64_t, const char *, const struct sockaddr_storage *, const struct sockaddr_storage *, const char *, int); 1359void lka_filter_end(uint64_t); 1360void lka_filter_protocol(uint64_t, enum filter_phase, const char *); 1361void lka_filter_data_begin(uint64_t); 1362void lka_filter_data_end(uint64_t); 1363int lka_filter_response(uint64_t, const char *, const char *); 1364 1365 1366/* lka_session.c */ 1367void lka_session(uint64_t, struct envelope *); 1368void lka_session_forward_reply(struct forward_req *, int); 1369 1370 1371/* log.c */ 1372void vlog(int, const char *, va_list); 1373void logit(int, const char *, ...) __attribute__((format (printf, 2, 3))); 1374 1375 1376/* mda.c */ 1377void mda_postfork(void); 1378void mda_postprivdrop(void); 1379void mda_imsg(struct mproc *, struct imsg *); 1380 1381 1382/* mda_unpriv.c */ 1383void mda_unpriv(struct dispatcher *, struct deliver *, const char *, const char *); 1384 1385 1386/* mda_variables.c */ 1387ssize_t mda_expand_format(char *, size_t, const struct deliver *, 1388 const struct userinfo *, const char *); 1389 1390 1391/* makemap.c */ 1392int makemap(int, int, char **); 1393 1394 1395/* mailaddr.c */ 1396int mailaddr_line(struct maddrmap *, const char *); 1397void maddrmap_init(struct maddrmap *); 1398void maddrmap_insert(struct maddrmap *, struct maddrnode *); 1399void maddrmap_free(struct maddrmap *); 1400 1401 1402/* mproc.c */ 1403int mproc_fork(struct mproc *, const char*, char **); 1404void mproc_init(struct mproc *, int); 1405void mproc_clear(struct mproc *); 1406void mproc_enable(struct mproc *); 1407void mproc_disable(struct mproc *); 1408void mproc_event_add(struct mproc *); 1409void m_compose(struct mproc *, uint32_t, uint32_t, pid_t, int, void *, size_t); 1410void m_composev(struct mproc *, uint32_t, uint32_t, pid_t, int, 1411 const struct iovec *, int); 1412void m_forward(struct mproc *, struct imsg *); 1413void m_create(struct mproc *, uint32_t, uint32_t, pid_t, int); 1414void m_add(struct mproc *, const void *, size_t); 1415void m_add_int(struct mproc *, int); 1416void m_add_u32(struct mproc *, uint32_t); 1417void m_add_size(struct mproc *, size_t); 1418void m_add_time(struct mproc *, time_t); 1419void m_add_timeval(struct mproc *, struct timeval *tv); 1420void m_add_string(struct mproc *, const char *); 1421void m_add_data(struct mproc *, const void *, size_t); 1422void m_add_evpid(struct mproc *, uint64_t); 1423void m_add_msgid(struct mproc *, uint32_t); 1424void m_add_id(struct mproc *, uint64_t); 1425void m_add_sockaddr(struct mproc *, const struct sockaddr *); 1426void m_add_mailaddr(struct mproc *, const struct mailaddr *); 1427void m_add_envelope(struct mproc *, const struct envelope *); 1428void m_add_params(struct mproc *, struct dict *); 1429void m_close(struct mproc *); 1430void m_flush(struct mproc *); 1431 1432void m_msg(struct msg *, struct imsg *); 1433int m_is_eom(struct msg *); 1434void m_end(struct msg *); 1435void m_get_int(struct msg *, int *); 1436void m_get_size(struct msg *, size_t *); 1437void m_get_u32(struct msg *, uint32_t *); 1438void m_get_time(struct msg *, time_t *); 1439void m_get_timeval(struct msg *, struct timeval *); 1440void m_get_string(struct msg *, const char **); 1441void m_get_data(struct msg *, const void **, size_t *); 1442void m_get_evpid(struct msg *, uint64_t *); 1443void m_get_msgid(struct msg *, uint32_t *); 1444void m_get_id(struct msg *, uint64_t *); 1445void m_get_sockaddr(struct msg *, struct sockaddr *); 1446void m_get_mailaddr(struct msg *, struct mailaddr *); 1447void m_get_envelope(struct msg *, struct envelope *); 1448void m_get_params(struct msg *, struct dict *); 1449void m_clear_params(struct dict *); 1450 1451 1452/* mta.c */ 1453void mta_postfork(void); 1454void mta_postprivdrop(void); 1455void mta_imsg(struct mproc *, struct imsg *); 1456void mta_route_ok(struct mta_relay *, struct mta_route *); 1457void mta_route_error(struct mta_relay *, struct mta_route *); 1458void mta_route_down(struct mta_relay *, struct mta_route *); 1459void mta_route_collect(struct mta_relay *, struct mta_route *); 1460void mta_source_error(struct mta_relay *, struct mta_route *, const char *); 1461void mta_delivery_log(struct mta_envelope *, const char *, const char *, int, const char *); 1462void mta_delivery_notify(struct mta_envelope *); 1463struct mta_task *mta_route_next_task(struct mta_relay *, struct mta_route *); 1464const char *mta_host_to_text(struct mta_host *); 1465const char *mta_relay_to_text(struct mta_relay *); 1466 1467 1468/* mta_session.c */ 1469void mta_session(struct mta_relay *, struct mta_route *); 1470void mta_session_imsg(struct mproc *, struct imsg *); 1471 1472 1473/* parse.y */ 1474int parse_config(struct smtpd *, const char *, int); 1475int cmdline_symset(char *); 1476 1477 1478/* queue.c */ 1479int queue(void); 1480 1481 1482/* queue_backend.c */ 1483uint32_t queue_generate_msgid(void); 1484uint64_t queue_generate_evpid(uint32_t); 1485int queue_init(const char *, int); 1486int queue_close(void); 1487int queue_message_create(uint32_t *); 1488int queue_message_delete(uint32_t); 1489int queue_message_commit(uint32_t); 1490int queue_message_fd_r(uint32_t); 1491int queue_message_fd_rw(uint32_t); 1492int queue_envelope_create(struct envelope *); 1493int queue_envelope_delete(uint64_t); 1494int queue_envelope_load(uint64_t, struct envelope *); 1495int queue_envelope_update(struct envelope *); 1496int queue_envelope_walk(struct envelope *); 1497int queue_message_walk(struct envelope *, uint32_t, int *, void **); 1498 1499 1500/* report_smtp.c */ 1501void report_smtp_link_connect(const char *, uint64_t, const char *, int, 1502 const struct sockaddr_storage *, const struct sockaddr_storage *); 1503void report_smtp_link_disconnect(const char *, uint64_t); 1504void report_smtp_link_identify(const char *, uint64_t, const char *, const char *); 1505void report_smtp_link_tls(const char *, uint64_t, const char *); 1506void report_smtp_link_auth(const char *, uint64_t, const char *, const char *); 1507void report_smtp_tx_reset(const char *, uint64_t, uint32_t); 1508void report_smtp_tx_begin(const char *, uint64_t, uint32_t); 1509void report_smtp_tx_mail(const char *, uint64_t, uint32_t, const char *, int); 1510void report_smtp_tx_rcpt(const char *, uint64_t, uint32_t, const char *, int); 1511void report_smtp_tx_envelope(const char *, uint64_t, uint32_t, uint64_t); 1512void report_smtp_tx_data(const char *, uint64_t, uint32_t, int); 1513void report_smtp_tx_commit(const char *, uint64_t, uint32_t, size_t); 1514void report_smtp_tx_rollback(const char *, uint64_t, uint32_t); 1515void report_smtp_protocol_client(const char *, uint64_t, const char *); 1516void report_smtp_protocol_server(const char *, uint64_t, const char *); 1517void report_smtp_filter_response(const char *, uint64_t, int, int, const char *); 1518void report_smtp_timeout(const char *, uint64_t); 1519 1520 1521/* ruleset.c */ 1522struct rule *ruleset_match(const struct envelope *); 1523 1524 1525/* scheduler.c */ 1526int scheduler(void); 1527 1528 1529/* scheduler_bakend.c */ 1530struct scheduler_backend *scheduler_backend_lookup(const char *); 1531void scheduler_info(struct scheduler_info *, struct envelope *); 1532 1533 1534/* pony.c */ 1535int pony(void); 1536void pony_imsg(struct mproc *, struct imsg *); 1537 1538 1539/* resolver.c */ 1540void resolver_getaddrinfo(const char *, const char *, const struct addrinfo *, 1541 void(*)(void *, int, struct addrinfo*), void *); 1542void resolver_getnameinfo(const struct sockaddr *, int, 1543 void(*)(void *, int, const char *, const char *), void *); 1544void resolver_res_query(const char *, int, int, 1545 void (*cb)(void *, int, int, int, const void *, int), void *); 1546void resolver_dispatch_request(struct mproc *, struct imsg *); 1547void resolver_dispatch_result(struct mproc *, struct imsg *); 1548 1549 1550/* smtp.c */ 1551void smtp_postfork(void); 1552void smtp_postprivdrop(void); 1553void smtp_imsg(struct mproc *, struct imsg *); 1554void smtp_configure(void); 1555void smtp_collect(void); 1556 1557 1558/* smtp_session.c */ 1559int smtp_session(struct listener *, int, const struct sockaddr_storage *, 1560 const char *, struct io *); 1561void smtp_session_imsg(struct mproc *, struct imsg *); 1562 1563 1564/* smtpf_session.c */ 1565int smtpf_session(struct listener *, int, const struct sockaddr_storage *, 1566 const char *); 1567void smtpf_session_imsg(struct mproc *, struct imsg *); 1568 1569 1570/* smtpd.c */ 1571void imsg_dispatch(struct mproc *, struct imsg *); 1572const char *proc_name(enum smtp_proc_type); 1573const char *proc_title(enum smtp_proc_type); 1574const char *imsg_to_str(int); 1575void log_imsg(int, int, struct imsg *); 1576int fork_proc_backend(const char *, const char *, const char *); 1577 1578 1579/* ssl_smtpd.c */ 1580void *ssl_mta_init(void *, char *, off_t, const char *); 1581void *ssl_smtp_init(void *, int); 1582 1583 1584/* stat_backend.c */ 1585struct stat_backend *stat_backend_lookup(const char *); 1586void stat_increment(const char *, size_t); 1587void stat_decrement(const char *, size_t); 1588void stat_set(const char *, const struct stat_value *); 1589struct stat_value *stat_counter(size_t); 1590struct stat_value *stat_timestamp(time_t); 1591struct stat_value *stat_timeval(struct timeval *); 1592struct stat_value *stat_timespec(struct timespec *); 1593 1594 1595/* table.c */ 1596struct table *table_find(struct smtpd *, const char *); 1597struct table *table_create(struct smtpd *, const char *, const char *, 1598 const char *); 1599int table_config(struct table *); 1600int table_open(struct table *); 1601int table_update(struct table *); 1602void table_close(struct table *); 1603void table_dump(struct table *); 1604int table_check_use(struct table *, uint32_t, uint32_t); 1605int table_check_type(struct table *, uint32_t); 1606int table_check_service(struct table *, uint32_t); 1607int table_match(struct table *, enum table_service, const char *); 1608int table_lookup(struct table *, enum table_service, const char *, 1609 union lookup *); 1610int table_fetch(struct table *, enum table_service, union lookup *); 1611void table_destroy(struct smtpd *, struct table *); 1612void table_add(struct table *, const char *, const char *); 1613int table_domain_match(const char *, const char *); 1614int table_netaddr_match(const char *, const char *); 1615int table_mailaddr_match(const char *, const char *); 1616int table_regex_match(const char *, const char *); 1617void table_open_all(struct smtpd *); 1618void table_dump_all(struct smtpd *); 1619void table_close_all(struct smtpd *); 1620 1621 1622/* to.c */ 1623int email_to_mailaddr(struct mailaddr *, char *); 1624int text_to_netaddr(struct netaddr *, const char *); 1625int text_to_mailaddr(struct mailaddr *, const char *); 1626int text_to_relayhost(struct relayhost *, const char *); 1627int text_to_userinfo(struct userinfo *, const char *); 1628int text_to_credentials(struct credentials *, const char *); 1629int text_to_expandnode(struct expandnode *, const char *); 1630uint64_t text_to_evpid(const char *); 1631uint32_t text_to_msgid(const char *); 1632const char *sa_to_text(const struct sockaddr *); 1633const char *ss_to_text(const struct sockaddr_storage *); 1634const char *time_to_text(time_t); 1635const char *duration_to_text(time_t); 1636const char *rule_to_text(struct rule *); 1637const char *sockaddr_to_text(struct sockaddr *); 1638const char *mailaddr_to_text(const struct mailaddr *); 1639const char *expandnode_to_text(struct expandnode *); 1640 1641 1642/* util.c */ 1643typedef struct arglist arglist; 1644struct arglist { 1645 char **list; 1646 uint num; 1647 uint nalloc; 1648}; 1649void addargs(arglist *, char *, ...) 1650 __attribute__((format(printf, 2, 3))); 1651int bsnprintf(char *, size_t, const char *, ...) 1652 __attribute__((format (printf, 3, 4))); 1653int mkdirs(char *, mode_t); 1654int safe_fclose(FILE *); 1655int hostname_match(const char *, const char *); 1656int mailaddr_match(const struct mailaddr *, const struct mailaddr *); 1657int valid_localpart(const char *); 1658int valid_domainpart(const char *); 1659int valid_smtp_response(const char *); 1660int secure_file(int, char *, char *, uid_t, int); 1661int lowercase(char *, const char *, size_t); 1662void xlowercase(char *, const char *, size_t); 1663int uppercase(char *, const char *, size_t); 1664uint64_t generate_uid(void); 1665int availdesc(void); 1666int ckdir(const char *, mode_t, uid_t, gid_t, int); 1667int rmtree(char *, int); 1668int mvpurge(char *, char *); 1669int mktmpfile(void); 1670const char *parse_smtp_response(char *, size_t, char **, int *); 1671int xasprintf(char **, const char *, ...); 1672void *xmalloc(size_t); 1673void *xcalloc(size_t, size_t); 1674char *xstrdup(const char *); 1675void *xmemdup(const void *, size_t); 1676char *strip(char *); 1677int io_xprint(struct io *, const char *); 1678int io_xprintf(struct io *, const char *, ...); 1679void log_envelope(const struct envelope *, const char *, const char *, 1680 const char *); 1681int session_socket_error(int); 1682int getmailname(char *, size_t); 1683int base64_encode(unsigned char const *, size_t, char *, size_t); 1684int base64_decode(char const *, unsigned char *, size_t); 1685 1686void log_trace_verbose(int); 1687void log_trace(int, const char *, ...) 1688 __attribute__((format (printf, 2, 3))); 1689 1690/* waitq.c */ 1691int waitq_wait(void *, void (*)(void *, void *, void *), void *); 1692void waitq_run(void *, void *); 1693 1694 1695/* runq.c */ 1696struct runq; 1697 1698int runq_init(struct runq **, void (*)(struct runq *, void *)); 1699int runq_schedule(struct runq *, time_t, void *); 1700int runq_schedule_at(struct runq *, time_t, void *); 1701int runq_cancel(struct runq *, void *); 1702int runq_pending(struct runq *, void *, time_t *); 1703