smtpd.h revision 1.81
1/* $OpenBSD: smtpd.h,v 1.81 2009/03/03 23:23:52 gilles Exp $ */ 2 3/* 4 * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> 5 * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20#define CONF_FILE "/etc/mail/smtpd.conf" 21#define MAX_LISTEN 16 22#define PROC_COUNT 9 23#define READ_BUF_SIZE 32768 24#define MAX_NAME_SIZE 64 25 26#define MAX_HOPS_COUNT 100 27 28/* sizes include the tailing '\0' */ 29#define MAX_LINE_SIZE 1024 30#define MAX_LOCALPART_SIZE 65 31#define MAX_DOMAINPART_SIZE MAXHOSTNAMELEN 32#define MAX_ID_SIZE 64 33 34/* return and forward path size */ 35#define MAX_PATH_SIZE 256 36 37/* makemap mapped value text length */ 38#define MAX_MAKEMAP_SIZE 256 39 40/*#define SMTPD_CONNECT_TIMEOUT (60)*/ 41#define SMTPD_CONNECT_TIMEOUT (10) 42#define SMTPD_QUEUE_INTERVAL (15 * 60) 43#define SMTPD_QUEUE_MAXINTERVAL (4 * 60 * 60) 44#define SMTPD_QUEUE_EXPIRY (4 * 24 * 60 * 60) 45#define SMTPD_USER "_smtpd" 46#define SMTPD_SOCKET "/var/run/smtpd.sock" 47#define SMTPD_BANNER "220 %s ESMTP OpenSMTPD" 48#define SMTPD_SESSION_TIMEOUT 300 49#define SMTPD_BACKLOG 5 50 51#define PATH_MAILLOCAL "/usr/libexec/mail.local" 52 53#define DIRHASH_BUCKETS 4096 54 55#define PATH_SPOOL "/var/spool/smtpd" 56 57#define PATH_ENQUEUE "/enqueue" 58#define PATH_INCOMING "/incoming" 59#define PATH_QUEUE "/queue" 60#define PATH_PURGE "/purge" 61 62#define PATH_MESSAGE "/message" 63#define PATH_ENVELOPES "/envelopes" 64 65#define PATH_RUNQUEUE "/runqueue" 66#define PATH_RUNQUEUEHIGH "/runqueue-high" 67#define PATH_RUNQUEUELOW "/runqueue-low" 68 69/* number of MX records to lookup */ 70#define MXARRAYSIZE 5 71 72/* rfc5321 limits */ 73#define SMTP_TEXTLINE_MAX 1000 74#define SMTP_CMDLINE_MAX 512 75#define SMTP_ANYLINE_MAX SMTP_TEXTLINE_MAX 76 77#define F_STARTTLS 0x01 78#define F_SSMTP 0x02 79#define F_AUTH 0x04 80#define F_SSL (F_SSMTP|F_STARTTLS) 81 82 83struct netaddr { 84 struct sockaddr_storage ss; 85 int bits; 86}; 87 88struct relayhost { 89 u_int8_t flags; 90 char hostname[MAXHOSTNAMELEN]; 91 u_int16_t port; 92}; 93 94struct mxhost { 95 u_int8_t flags; 96 struct sockaddr_storage ss; 97}; 98 99/* buffer specific headers */ 100struct buf { 101 TAILQ_ENTRY(buf) entry; 102 u_char *buf; 103 size_t size; 104 size_t max; 105 size_t wpos; 106 size_t rpos; 107 int fd; 108}; 109 110struct msgbuf { 111 TAILQ_HEAD(, buf) bufs; 112 u_int32_t queued; 113 int fd; 114}; 115 116struct buf_read { 117 u_char buf[READ_BUF_SIZE]; 118 u_char *rptr; 119 size_t wpos; 120}; 121 122struct imsg_fd { 123 TAILQ_ENTRY(imsg_fd) entry; 124 int fd; 125 u_int32_t id; 126}; 127 128struct imsgbuf { 129 TAILQ_HEAD(, imsg_fd) fds; 130 struct buf_read r; 131 struct msgbuf w; 132 struct event ev; 133 void (*handler)(int, short, void *); 134 int fd; 135 pid_t pid; 136 short events; 137 void *data; 138 u_int32_t id; 139}; 140 141struct imsg_hdr { 142 u_int16_t type; 143 u_int16_t len; 144 u_int32_t peerid; 145 pid_t pid; 146}; 147 148struct imsg { 149 struct imsg_hdr hdr; 150 u_int32_t id; 151 void *data; 152}; 153 154enum imsg_type { 155 IMSG_NONE, 156 IMSG_CTL_OK, /* answer to smtpctl requests */ 157 IMSG_CTL_FAIL, 158 IMSG_CTL_SHUTDOWN, 159 IMSG_CONF_START, 160 IMSG_CONF_SSL, 161 IMSG_CONF_SSL_CERT, 162 IMSG_CONF_SSL_KEY, 163 IMSG_CONF_LISTENER, 164 IMSG_CONF_MAP, 165 IMSG_CONF_RULE, 166 IMSG_CONF_CONDITION, 167 IMSG_CONF_OPTION, 168 IMSG_CONF_END, 169 IMSG_CONF_RELOAD, 170 IMSG_LKA_MAIL, 171 IMSG_LKA_RCPT, 172 IMSG_LKA_MX, 173 IMSG_LKA_HOST, 174 IMSG_MDA_MAILBOX_FILE, 175 IMSG_MDA_MESSAGE_FILE, 176 IMSG_MFA_RCPT, 177 IMSG_MFA_MAIL, 178 179 IMSG_QUEUE_CREATE_MESSAGE, 180 IMSG_QUEUE_SUBMIT_ENVELOPE, 181 IMSG_QUEUE_COMMIT_ENVELOPES, 182 IMSG_QUEUE_REMOVE_MESSAGE, 183 IMSG_QUEUE_COMMIT_MESSAGE, 184 IMSG_QUEUE_TEMPFAIL, 185 IMSG_QUEUE_STATS, 186 187 IMSG_QUEUE_REMOVE_SUBMISSION, 188 IMSG_QUEUE_MESSAGE_UPDATE, 189 IMSG_QUEUE_MESSAGE_FD, 190 IMSG_QUEUE_MESSAGE_FILE, 191 192 IMSG_RUNNER_UPDATE_ENVELOPE, 193 IMSG_RUNNER_STATS, 194 IMSG_RUNNER_SCHEDULE, 195 196 IMSG_BATCH_CREATE, 197 IMSG_BATCH_APPEND, 198 IMSG_BATCH_CLOSE, 199 200 IMSG_PARENT_FORWARD_OPEN, 201 IMSG_PARENT_MAILBOX_OPEN, 202 IMSG_PARENT_MESSAGE_OPEN, 203 IMSG_PARENT_MAILBOX_RENAME, 204 IMSG_PARENT_STATS, 205 206 IMSG_PARENT_AUTHENTICATE, 207 IMSG_PARENT_SEND_CONFIG, 208 209 IMSG_MDA_PAUSE, 210 IMSG_MTA_PAUSE, 211 IMSG_SMTP_PAUSE, 212 IMSG_SMTP_STATS, 213 214 IMSG_MDA_RESUME, 215 IMSG_MTA_RESUME, 216 IMSG_SMTP_RESUME, 217 218 IMSG_STATS 219}; 220 221#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) 222#define MAX_IMSGSIZE 16384 223 224enum blockmodes { 225 BM_NORMAL, 226 BM_NONBLOCK 227}; 228 229struct ctl_conn { 230 TAILQ_ENTRY(ctl_conn) entry; 231 u_int8_t flags; 232#define CTL_CONN_NOTIFY 0x01 233 struct imsgbuf ibuf; 234}; 235TAILQ_HEAD(ctl_connlist, ctl_conn); 236 237typedef u_int32_t objid_t; 238 239struct ctl_id { 240 objid_t id; 241 char name[MAX_NAME_SIZE]; 242}; 243 244enum smtp_proc_type { 245 PROC_PARENT = 0, 246 PROC_SMTP, 247 PROC_MFA, 248 PROC_LKA, 249 PROC_QUEUE, 250 PROC_MDA, 251 PROC_MTA, 252 PROC_CONTROL, 253 PROC_RUNNER, 254} smtpd_process; 255 256struct peer { 257 enum smtp_proc_type id; 258 void (*cb)(int, short, void *); 259}; 260 261enum map_type { 262 T_SINGLE, 263 T_LIST, 264 T_HASH 265}; 266 267enum map_src { 268 S_NONE, 269 S_DYN, 270 S_DNS, 271 S_FILE, 272 S_DB, 273 S_EXT 274}; 275 276enum mapel_type { 277 ME_STRING, 278 ME_NET, 279 ME_NETMASK 280}; 281 282struct mapel { 283 TAILQ_ENTRY(mapel) me_entry; 284 union mapel_data { 285 char med_string[MAX_LINE_SIZE]; 286 struct netaddr med_addr; 287 } me_key; 288 union mapel_data me_val; 289}; 290 291struct map { 292 TAILQ_ENTRY(map) m_entry; 293#define F_USED 0x01 294#define F_DYNAMIC 0x02 295 u_int8_t m_flags; 296 char m_name[MAX_LINE_SIZE]; 297 objid_t m_id; 298 enum map_type m_type; 299 enum mapel_type m_eltype; 300 enum map_src m_src; 301 char m_config[MAXPATHLEN]; 302 TAILQ_HEAD(mapel_list, mapel) m_contents; 303}; 304 305enum cond_type { 306 C_ALL, 307 C_NET, 308 C_DOM 309}; 310 311struct cond { 312 TAILQ_ENTRY(cond) c_entry; 313 objid_t c_map; 314 enum cond_type c_type; 315 struct map *c_match; 316}; 317 318enum opt_type { 319 O_RWUSER, /* rewrite user */ 320 O_RWDOMAIN, /* rewrite domain */ 321}; 322 323struct opt { 324 TAILQ_ENTRY(opt) o_entry; 325 enum opt_type o_type; 326}; 327 328enum action_type { 329 A_RELAY, 330 A_RELAYVIA, 331 A_MAILDIR, 332 A_MBOX, 333 A_FILENAME, 334 A_EXT 335}; 336#define IS_MAILBOX(x) ((x) == A_MAILDIR || (x) == A_MBOX || (x) == A_FILENAME) 337#define IS_RELAY(x) ((x) == A_RELAY || (x) == A_RELAYVIA) 338#define IS_EXT(x) ((x) == A_EXT) 339 340struct rule { 341 TAILQ_ENTRY(rule) r_entry; 342 int r_accept; 343 struct map *r_sources; 344 TAILQ_HEAD(condlist, cond) r_conditions; 345 enum action_type r_action; 346 union rule_dest { 347 char path[MAXPATHLEN]; 348 struct relayhost relayhost; 349#define MAXCOMMANDLEN 256 350 char command[MAXCOMMANDLEN]; 351 } r_value; 352 TAILQ_HEAD(optlist, opt) r_options; 353}; 354 355enum path_flags { 356 F_ALIAS = 0x1, 357 F_VIRTUAL = 0x2, 358 F_EXPANDED = 0x4, 359 F_NOFORWARD = 0x8, 360 F_FORWARDED = 0x10, 361 F_ACCOUNT = 0x20, 362}; 363 364struct path { 365 TAILQ_ENTRY(path) entry; 366 struct rule rule; 367 enum path_flags flags; 368 u_int8_t forwardcnt; 369 char user[MAX_LOCALPART_SIZE]; 370 char domain[MAX_DOMAINPART_SIZE]; 371 char pw_name[MAXLOGNAME]; 372 union path_data { 373 char filename[MAXPATHLEN]; 374 char filter[MAXPATHLEN]; 375 } u; 376}; 377 378enum alias_type { 379 ALIAS_USERNAME, 380 ALIAS_FILENAME, 381 ALIAS_FILTER, 382 ALIAS_INCLUDE, 383 ALIAS_ADDRESS, 384 ALIAS_TEXT 385}; 386 387struct alias { 388 TAILQ_ENTRY(alias) entry; 389 enum alias_type type; 390 union alias_data { 391 char username[MAXLOGNAME]; 392 char filename[MAXPATHLEN]; 393 char filter[MAXPATHLEN]; 394 char text[MAX_MAKEMAP_SIZE]; 395 struct path path; 396 } u; 397}; 398TAILQ_HEAD(aliaseslist, alias); 399 400enum message_type { 401 T_MDA_MESSAGE = 0x1, 402 T_MTA_MESSAGE = 0x2, 403 T_DAEMON_MESSAGE = 0x4 404}; 405 406enum message_status { 407 S_MESSAGE_LOCKFAILURE = 0x1, 408 S_MESSAGE_PERMFAILURE = 0x2, 409 S_MESSAGE_TEMPFAILURE = 0x4, 410 S_MESSAGE_REJECTED = 0x8, 411 S_MESSAGE_ACCEPTED = 0x10, 412 S_MESSAGE_RETRY = 0x20, 413 S_MESSAGE_EDNS = 0x40, 414 S_MESSAGE_ECONNECT = 0x80 415}; 416 417enum message_flags { 418 F_MESSAGE_RESOLVED = 0x1, 419 F_MESSAGE_SCHEDULED = 0x2, 420 F_MESSAGE_PROCESSING = 0x4, 421 F_MESSAGE_AUTHENTICATED = 0x8, 422 F_MESSAGE_ENQUEUED = 0x10, 423 F_MESSAGE_FORCESCHEDULE = 0x20 424}; 425 426struct message { 427 SPLAY_ENTRY(message) nodes; 428 TAILQ_ENTRY(message) entry; 429 430 enum message_type type; 431 432 u_int64_t id; 433 u_int64_t session_id; 434 u_int64_t batch_id; 435 436 char message_id[MAX_ID_SIZE]; 437 char message_uid[MAX_ID_SIZE]; 438 439 char session_helo[MAXHOSTNAMELEN]; 440 char session_hostname[MAXHOSTNAMELEN]; 441 char session_errorline[MAX_LINE_SIZE]; 442 struct sockaddr_storage session_ss; 443 struct path session_rcpt; 444 445 struct path sender; 446 struct path recipient; 447 TAILQ_HEAD(pathlist,path) recipients; 448 449 u_int16_t rcptcount; 450 451 time_t creation; 452 time_t lasttry; 453 u_int8_t retry; 454 enum message_flags flags; 455 enum message_status status; 456 FILE *datafp; 457 int mboxfd; 458 int messagefd; 459}; 460 461enum batch_status { 462 S_BATCH_PERMFAILURE = 0x1, 463 S_BATCH_TEMPFAILURE = 0x2, 464 S_BATCH_REJECTED = 0x4, 465 S_BATCH_ACCEPTED = 0x8, 466 S_BATCH_RETRY = 0x10, 467 S_BATCH_EDNS = 0x20, 468 S_BATCH_ECONNECT = 0x40 469}; 470 471enum batch_type { 472 T_MDA_BATCH = 0x1, 473 T_MTA_BATCH = 0x2, 474 T_DAEMON_BATCH = 0x4 475}; 476 477enum batch_flags { 478 F_BATCH_COMPLETE = 0x1, 479 F_BATCH_RESOLVED = 0x2, 480 F_BATCH_SCHEDULED = 0x4, 481 F_BATCH_EXPIRED = 0x8, 482}; 483 484struct mdaproc { 485 SPLAY_ENTRY(mdaproc) mdaproc_nodes; 486 487 pid_t pid; 488}; 489 490struct batch { 491 SPLAY_ENTRY(batch) b_nodes; 492 493 u_int64_t id; 494 u_int64_t session_id; 495 enum batch_type type; 496 enum batch_flags flags; 497 498 struct rule rule; 499 500 struct smtpd *env; 501 502 char message_id[MAX_ID_SIZE]; 503 char hostname[MAXHOSTNAMELEN]; 504 char errorline[MAX_LINE_SIZE]; 505 506 char session_helo[MAXHOSTNAMELEN]; 507 char session_hostname[MAXHOSTNAMELEN]; 508 struct sockaddr_storage session_ss; 509 510 int8_t getaddrinfo_error; 511 struct mxhost mxarray[MXARRAYSIZE*2]; 512 u_int8_t mx_cnt; 513 u_int8_t mx_off; 514 515 time_t creation; 516 time_t lasttry; 517 u_int8_t retry; 518 519 struct session *sessionp; 520 521 struct message message; 522 struct message *messagep; 523 FILE *messagefp; 524 TAILQ_HEAD(messagelist, message) messages; 525 526 enum batch_status status; 527}; 528 529enum session_state { 530 S_INIT = 0, 531 S_GREETED, 532 S_TLS, 533 S_AUTH_INIT, 534 S_AUTH_USERNAME, 535 S_AUTH_PASSWORD, 536 S_AUTH_FINALIZE, 537 S_HELO, 538 S_MAILREQUEST, 539 S_MAIL, 540 S_RCPTREQUEST, 541 S_RCPT, 542 S_DATAREQUEST, 543 S_DATA, 544 S_DATACONTENT, 545 S_DONE, 546 S_QUIT 547}; 548#define IS_AUTH(x) ((x) == S_AUTH_INIT || (x) == S_AUTH_USERNAME || (x) == S_AUTH_PASSWORD || (x) == S_AUTH_FINALIZE) 549 550struct ssl { 551 SPLAY_ENTRY(ssl) ssl_nodes; 552 char ssl_name[PATH_MAX]; 553 char *ssl_cert; 554 off_t ssl_cert_len; 555 char *ssl_key; 556 off_t ssl_key_len; 557}; 558 559struct listener { 560 u_int8_t flags; 561 int fd; 562 struct sockaddr_storage ss; 563 in_port_t port; 564 struct timeval timeout; 565 struct event ev; 566 struct smtpd *env; 567 char ssl_cert_name[PATH_MAX]; 568 struct ssl *ssl; 569 void *ssl_ctx; 570 TAILQ_ENTRY(listener) entry; 571}; 572 573struct session_auth_req { 574 u_int64_t session_id; 575 char buffer[MAX_LINE_SIZE]; 576}; 577 578struct session_auth_reply { 579 u_int64_t session_id; 580 u_int8_t value; 581}; 582 583enum session_flags { 584 F_EHLO = 0x1, 585 F_QUIT = 0x2, 586 F_8BITMIME = 0x4, 587 F_SECURE = 0x8, 588 F_AUTHENTICATED = 0x10, 589 F_PEERHASTLS = 0x20, 590 F_EVLOCKED = 0x40 591}; 592 593struct session { 594 SPLAY_ENTRY(session) s_nodes; 595 u_int64_t s_id; 596 597 enum session_flags s_flags; 598 enum session_state s_state; 599 time_t s_tm; 600 int s_fd; 601 struct sockaddr_storage s_ss; 602 char s_hostname[MAXHOSTNAMELEN]; 603 struct event s_ev; 604 struct bufferevent *s_bev; 605 struct listener *s_l; 606 struct smtpd *s_env; 607 void *s_ssl; 608 u_char *s_buf; 609 int s_buflen; 610 struct timeval s_tv; 611 struct message s_msg; 612 613 struct session_auth_req s_auth; 614 615 struct mxhost *mxarray; 616 u_int8_t mx_cnt; 617 u_int8_t mx_off; 618 619 struct batch *batch; 620 621}; 622 623struct forward_req { 624 u_int64_t id; 625 char pw_name[MAXLOGNAME]; 626}; 627 628enum lkasession_flags { 629 F_ERROR = 0x1 630}; 631 632struct lkasession { 633 SPLAY_ENTRY(lkasession) nodes; 634 u_int64_t id; 635 636 struct path path; 637 struct aliaseslist aliaseslist; 638 u_int8_t iterations; 639 u_int32_t pending; 640 enum lkasession_flags flags; 641 struct message message; 642}; 643 644struct smtpd { 645#define SMTPD_OPT_VERBOSE 0x00000001 646#define SMTPD_OPT_NOACTION 0x00000002 647 u_int32_t sc_opts; 648#define SMTPD_CONFIGURING 0x00000001 649#define SMTPD_EXITING 0x00000002 650#define SMTPD_MDA_PAUSED 0x00000004 651#define SMTPD_MTA_PAUSED 0x00000008 652#define SMTPD_SMTP_PAUSED 0x00000010 653 u_int32_t sc_flags; 654 struct timeval sc_qintval; 655 u_int32_t sc_maxconn; 656 struct event sc_ev; 657 int *sc_pipes[PROC_COUNT] 658 [PROC_COUNT]; 659 struct imsgbuf *sc_ibufs[PROC_COUNT]; 660 int sc_instances[PROC_COUNT]; 661 int sc_instance; 662 struct passwd *sc_pw; 663 char sc_hostname[MAXHOSTNAMELEN]; 664 TAILQ_HEAD(listenerlist, listener) sc_listeners; 665 TAILQ_HEAD(maplist, map) *sc_maps; 666 TAILQ_HEAD(rulelist, rule) *sc_rules; 667 SPLAY_HEAD(sessiontree, session) sc_sessions; 668 SPLAY_HEAD(msgtree, message) sc_messages; 669 SPLAY_HEAD(ssltree, ssl) sc_ssl; 670 671 SPLAY_HEAD(batchtree, batch) batch_queue; 672 SPLAY_HEAD(mdaproctree, mdaproc) mdaproc_queue; 673 SPLAY_HEAD(lkatree, lkasession) lka_sessions; 674}; 675 676struct s_parent { 677 time_t start; 678}; 679 680struct s_queue { 681 size_t inserts_local; 682 size_t inserts_remote; 683}; 684 685struct s_runner { 686 size_t active; 687}; 688 689struct s_smtp { 690 size_t sessions; 691 size_t sessions_active; 692 693 size_t ssmtp; 694 size_t ssmtp_active; 695 696 size_t starttls; 697 size_t starttls_active; 698 699 size_t aborted; 700}; 701 702struct stats { 703 int fd; 704 union u_stats { 705 struct s_parent parent; 706 struct s_queue queue; 707 struct s_runner runner; 708 struct s_smtp smtp; 709 } u; 710}; 711 712struct sched { 713 int fd; 714 char mid[MAX_ID_SIZE]; 715 int ret; 716}; 717 718struct submit_status { 719 u_int64_t id; 720 int code; 721 union submit_path { 722 struct path path; 723 char msgid[MAX_ID_SIZE]; 724 char errormsg[MAX_LINE_SIZE]; 725 } u; 726 enum message_flags flags; 727 struct sockaddr_storage ss; 728 struct message msg; 729}; 730 731struct message_recipient { 732 u_int64_t id; 733 struct sockaddr_storage ss; 734 enum message_flags flags; 735 struct path path; 736 struct message msg; 737}; 738 739 740/* aliases.c */ 741int aliases_exist(struct smtpd *, char *); 742int aliases_get(struct smtpd *, struct aliaseslist *, char *); 743int aliases_virtual_exist(struct smtpd *, struct path *); 744int aliases_virtual_get(struct smtpd *, struct aliaseslist *, struct path *); 745int alias_parse(struct alias *, char *); 746 747 748/* log.c */ 749void log_init(int); 750void log_warn(const char *, ...) 751 __attribute__ ((format (printf, 1, 2))); 752void log_warnx(const char *, ...) 753 __attribute__ ((format (printf, 1, 2))); 754void log_info(const char *, ...) 755 __attribute__ ((format (printf, 1, 2))); 756void log_debug(const char *, ...) 757 __attribute__ ((format (printf, 1, 2))); 758__dead void fatal(const char *); 759__dead void fatalx(const char *); 760 761 762/* buffer.c */ 763struct buf *buf_open(size_t); 764struct buf *buf_dynamic(size_t, size_t); 765int buf_add(struct buf *, void *, size_t); 766void *buf_reserve(struct buf *, size_t); 767int buf_close(struct msgbuf *, struct buf *); 768void buf_free(struct buf *); 769void msgbuf_init(struct msgbuf *); 770void msgbuf_clear(struct msgbuf *); 771int msgbuf_write(struct msgbuf *); 772 773 774/* dns.c */ 775int getmxbyname(char *, char ***); 776 777 778/* forward.c */ 779int forwards_get(int, struct aliaseslist *); 780 781 782/* imsg.c */ 783void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *)); 784ssize_t imsg_read(struct imsgbuf *); 785ssize_t imsg_get(struct imsgbuf *, struct imsg *); 786int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t, 787 int, void *, u_int16_t); 788int imsg_composev(struct imsgbuf *, enum imsg_type, u_int32_t, 789 pid_t, int, const struct iovec *, int); 790int imsg_compose_fds(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t, 791 void *, u_int16_t, int, ...); 792struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t, 793 u_int16_t); 794int imsg_add(struct buf *, void *, u_int16_t); 795int imsg_append(struct imsgbuf *, struct buf *); 796int imsg_close(struct imsgbuf *, struct buf *); 797void imsg_free(struct imsg *); 798void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */ 799int imsg_get_fd(struct imsgbuf *, struct imsg *); 800int imsg_flush(struct imsgbuf *); 801void imsg_clear(struct imsgbuf *); 802 803/* lka.c */ 804pid_t lka(struct smtpd *); 805int lkasession_cmp(struct lkasession *, struct lkasession *); 806SPLAY_PROTOTYPE(lkatree, lkasession, nodes, lkasession_cmp); 807 808/* mfa.c */ 809pid_t mfa(struct smtpd *); 810int msg_cmp(struct message *, struct message *); 811SPLAY_PROTOTYPE(msgtree, message, nodes, msg_cmp); 812 813/* queue.c */ 814pid_t queue(struct smtpd *); 815u_int64_t queue_generate_id(void); 816int queue_remove_batch_message(struct smtpd *, struct batch *, 817 struct message *); 818int queue_load_envelope(struct message *, char *); 819int queue_update_envelope(struct message *); 820int queue_remove_envelope(struct message *); 821int batch_cmp(struct batch *, struct batch *); 822struct batch *batch_by_id(struct smtpd *, u_int64_t); 823struct message *message_by_id(struct smtpd *, struct batch *, u_int64_t); 824u_int16_t queue_hash(char *); 825 826/* queue_shared.c */ 827int queue_create_layout_message(char *, char *); 828void queue_delete_layout_message(char *, char *); 829int queue_record_layout_envelope(char *, struct message *); 830int queue_remove_layout_envelope(char *, struct message *); 831int queue_commit_layout_message(char *, struct message *); 832int queue_open_layout_messagefile(char *, struct message *); 833int enqueue_create_layout(char *); 834void enqueue_delete_message(char *); 835int enqueue_record_envelope(struct message *); 836int enqueue_remove_envelope(struct message *); 837int enqueue_commit_message(struct message *); 838int enqueue_open_messagefile(struct message *); 839int queue_create_incoming_layout(char *); 840void queue_delete_incoming_message(char *); 841int queue_record_incoming_envelope(struct message *); 842int queue_remove_incoming_envelope(struct message *); 843int queue_commit_incoming_message(struct message *); 844int queue_open_incoming_message_file(struct message *); 845int queue_open_message_file(char *msgid); 846void queue_message_update(struct message *); 847void queue_delete_message(char *); 848struct qwalk *qwalk_new(char *); 849int qwalk(struct qwalk *, char *); 850void qwalk_close(struct qwalk *); 851void show_queue(char *, int); 852 853u_int16_t queue_hash(char *); 854 855/* mda.c */ 856pid_t mda(struct smtpd *); 857int mdaproc_cmp(struct mdaproc *, struct mdaproc *); 858SPLAY_PROTOTYPE(mdaproctree, mdaproc, mdaproc_nodes, mdaproc_cmp); 859 860/* mta.c */ 861pid_t mta(struct smtpd *); 862 863/* control.c */ 864pid_t control(struct smtpd *); 865void session_socket_blockmode(int, enum blockmodes); 866 867/* runner.c */ 868pid_t runner(struct smtpd *); 869SPLAY_PROTOTYPE(batchtree, batch, b_nodes, batch_cmp); 870 871 872/* smtp.c */ 873pid_t smtp(struct smtpd *); 874void smtp_listener_setup(struct smtpd *, struct listener *); 875 876/* smtp_session.c */ 877void session_init(struct listener *, struct session *); 878int session_cmp(struct session *, struct session *); 879void session_pickup(struct session *, struct submit_status *); 880void session_destroy(struct session *); 881void session_respond(struct session *, char *, ...) 882 __attribute__ ((format (printf, 2, 3))); 883 884SPLAY_PROTOTYPE(sessiontree, session, s_nodes, session_cmp); 885 886/* store.c */ 887int store_write_header(struct batch *, struct message *, FILE *, int); 888int store_write_message(struct batch *, struct message *); 889int store_write_daemon(struct batch *, struct message *); 890int store_message(struct batch *, struct message *, 891 int (*)(struct batch *, struct message *)); 892 893/* config.c */ 894#define PURGE_LISTENERS 0x01 895#define PURGE_MAPS 0x02 896#define PURGE_RULES 0x04 897#define PURGE_SSL 0x08 898#define PURGE_EVERYTHING 0xff 899void purge_config(struct smtpd *, u_int8_t); 900void unconfigure(struct smtpd *); 901void configure(struct smtpd *); 902void init_peers(struct smtpd *); 903void config_pipes(struct smtpd *, struct peer *, u_int); 904void config_peers(struct smtpd *, struct peer *, u_int); 905 906/* parse.y */ 907int parse_config(struct smtpd *, const char *, int); 908int cmdline_symset(char *); 909 910/* ssl.c */ 911void ssl_init(void); 912void ssl_transaction(struct session *); 913 914void ssl_session_init(struct session *); 915void ssl_session_destroy(struct session *); 916int ssl_load_certfile(struct smtpd *, const char *); 917void ssl_setup(struct smtpd *, struct listener *); 918int ssl_cmp(struct ssl *, struct ssl *); 919SPLAY_PROTOTYPE(ssltree, ssl, ssl_nodes, ssl_cmp); 920 921/* ssl_privsep.c */ 922int ssl_ctx_use_private_key(void *, char *, off_t); 923int ssl_ctx_use_certificate_chain(void *, char *, off_t); 924 925/* smtpd.c */ 926struct map *map_find(struct smtpd *, objid_t); 927struct map *map_findbyname(struct smtpd *, const char *); 928 929/* util.c */ 930int bsnprintf(char *, size_t, const char *, ...) 931 __attribute__ ((format (printf, 3, 4))); 932int safe_fclose(FILE *); 933struct passwd *safe_getpwnam(const char *); 934struct passwd *safe_getpwuid(uid_t); 935int hostname_match(char *, char *); 936int recipient_to_path(struct path *, char *); 937int valid_localpart(char *); 938int valid_domainpart(char *); 939char *ss_to_text(struct sockaddr_storage *); 940int valid_message_id(char *); 941int valid_message_uid(char *); 942int secure_file(int, char *, struct passwd *); 943