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