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