1 /* $NetBSD: local.c,v 1.1.1.3 2013/01/02 18:59:01 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* local 8 6 /* SUMMARY 7 /* Postfix local mail delivery 8 /* SYNOPSIS 9 /* \fBlocal\fR [generic Postfix daemon options] 10 /* DESCRIPTION 11 /* The \fBlocal\fR(8) daemon processes delivery requests from the 12 /* Postfix queue manager to deliver mail to local recipients. 13 /* Each delivery request specifies a queue file, a sender address, 14 /* a domain or host to deliver to, and one or more recipients. 15 /* This program expects to be run from the \fBmaster\fR(8) process 16 /* manager. 17 /* 18 /* The \fBlocal\fR(8) daemon updates queue files and marks recipients 19 /* as finished, or it informs the queue manager that delivery should 20 /* be tried again at a later time. Delivery status reports are sent 21 /* to the \fBbounce\fR(8), \fBdefer\fR(8) or \fBtrace\fR(8) daemon as 22 /* appropriate. 23 /* CASE FOLDING 24 /* .ad 25 /* .fi 26 /* All delivery decisions are made using the bare recipient 27 /* name (i.e. the address localpart), folded to lower case. 28 /* See also under ADDRESS EXTENSION below for a few exceptions. 29 /* SYSTEM-WIDE AND USER-LEVEL ALIASING 30 /* .ad 31 /* .fi 32 /* The system administrator can set up one or more system-wide 33 /* \fBsendmail\fR-style alias databases. 34 /* Users can have \fBsendmail\fR-style ~/.\fBforward\fR files. 35 /* Mail for \fIname\fR is delivered to the alias \fIname\fR, to 36 /* destinations in ~\fIname\fR/.\fBforward\fR, to the mailbox owned 37 /* by the user \fIname\fR, or it is sent back as undeliverable. 38 /* 39 /* The system administrator can specify a comma/space separated list 40 /* of ~\fR/.\fBforward\fR like files through the \fBforward_path\fR 41 /* configuration parameter. Upon delivery, the local delivery agent 42 /* tries each pathname in the list until a file is found. 43 /* 44 /* Delivery via ~/.\fBforward\fR files is done with the privileges 45 /* of the recipient. 46 /* Thus, ~/.\fBforward\fR like files must be readable by the 47 /* recipient, and their parent directory needs to have "execute" 48 /* permission for the recipient. 49 /* 50 /* The \fBforward_path\fR parameter is subject to interpolation of 51 /* \fB$user\fR (recipient username), \fB$home\fR (recipient home 52 /* directory), \fB$shell\fR (recipient shell), \fB$recipient\fR 53 /* (complete recipient address), \fB$extension\fR (recipient address 54 /* extension), \fB$domain\fR (recipient domain), \fB$local\fR 55 /* (entire recipient address localpart) and 56 /* \fB$recipient_delimiter.\fR The forms \fI${name?value}\fR and 57 /* \fI${name:value}\fR expand conditionally to \fIvalue\fR when 58 /* \fI$name\fR is (is not) defined. 59 /* Characters that may have special meaning to the shell or file system 60 /* are replaced by underscores. The list of acceptable characters 61 /* is specified with the \fBforward_expansion_filter\fR configuration 62 /* parameter. 63 /* 64 /* An alias or ~/.\fBforward\fR file may list any combination of external 65 /* commands, destination file names, \fB:include:\fR directives, or 66 /* mail addresses. 67 /* See \fBaliases\fR(5) for a precise description. Each line in a 68 /* user's .\fBforward\fR file has the same syntax as the right-hand part 69 /* of an alias. 70 /* 71 /* When an address is found in its own alias expansion, delivery is 72 /* made to the user instead. When a user is listed in the user's own 73 /* ~/.\fBforward\fR file, delivery is made to the user's mailbox instead. 74 /* An empty ~/.\fBforward\fR file means do not forward mail. 75 /* 76 /* In order to prevent the mail system from using up unreasonable 77 /* amounts of memory, input records read from \fB:include:\fR or from 78 /* ~/.\fBforward\fR files are broken up into chunks of length 79 /* \fBline_length_limit\fR. 80 /* 81 /* While expanding aliases, ~/.\fBforward\fR files, and so on, the 82 /* program attempts to avoid duplicate deliveries. The 83 /* \fBduplicate_filter_limit\fR configuration parameter limits the 84 /* number of remembered recipients. 85 /* MAIL FORWARDING 86 /* .ad 87 /* .fi 88 /* For the sake of reliability, forwarded mail is re-submitted as 89 /* a new message, so that each recipient has a separate on-file 90 /* delivery status record. 91 /* 92 /* In order to stop mail forwarding loops early, the software adds an 93 /* optional 94 /* \fBDelivered-To:\fR header with the final envelope recipient address. If 95 /* mail arrives for a recipient that is already listed in a 96 /* \fBDelivered-To:\fR header, the message is bounced. 97 /* MAILBOX DELIVERY 98 /* .ad 99 /* .fi 100 /* The default per-user mailbox is a file in the UNIX mail spool 101 /* directory (\fB/var/mail/\fIuser\fR or \fB/var/spool/mail/\fIuser\fR); 102 /* the location can be specified with the \fBmail_spool_directory\fR 103 /* configuration parameter. Specify a name ending in \fB/\fR for 104 /* \fBqmail\fR-compatible \fBmaildir\fR delivery. 105 /* 106 /* Alternatively, the per-user mailbox can be a file in the user's home 107 /* directory with a name specified via the \fBhome_mailbox\fR 108 /* configuration parameter. Specify a relative path name. Specify a name 109 /* ending in \fB/\fR for \fBqmail\fR-compatible \fBmaildir\fR delivery. 110 /* 111 /* Mailbox delivery can be delegated to an external command specified 112 /* with the \fBmailbox_command_maps\fR and \fBmailbox_command\fR 113 /* configuration parameters. The command 114 /* executes with the privileges of the recipient user (exceptions: 115 /* secondary groups are not enabled; in case of delivery as root, 116 /* the command executes with the privileges of \fBdefault_privs\fR). 117 /* 118 /* Mailbox delivery can be delegated to alternative message transports 119 /* specified in the \fBmaster.cf\fR file. 120 /* The \fBmailbox_transport_maps\fR and \fBmailbox_transport\fR 121 /* configuration parameters specify an optional 122 /* message transport that is to be used for all local recipients, 123 /* regardless of whether they are found in the UNIX passwd database. 124 /* The \fBfallback_transport_maps\fR and 125 /* \fBfallback_transport\fR parameters specify an optional 126 /* message transport 127 /* for recipients that are not found in the aliases(5) or UNIX 128 /* passwd database. 129 /* 130 /* In the case of UNIX-style mailbox delivery, 131 /* the \fBlocal\fR(8) daemon prepends a "\fBFrom \fIsender time_stamp\fR" 132 /* envelope header to each message, prepends an 133 /* \fBX-Original-To:\fR header with the recipient address as given to 134 /* Postfix, prepends an 135 /* optional \fBDelivered-To:\fR header 136 /* with the final envelope recipient address, prepends a \fBReturn-Path:\fR 137 /* header with the envelope sender address, prepends a \fB>\fR character 138 /* to lines beginning with "\fBFrom \fR", and appends an empty line. 139 /* The mailbox is locked for exclusive access while delivery is in 140 /* progress. In case of problems, an attempt is made to truncate the 141 /* mailbox to its original length. 142 /* 143 /* In the case of \fBmaildir\fR delivery, the local daemon prepends 144 /* an optional 145 /* \fBDelivered-To:\fR header with the final envelope recipient address, 146 /* prepends an 147 /* \fBX-Original-To:\fR header with the recipient address as given to 148 /* Postfix, 149 /* and prepends a \fBReturn-Path:\fR header with the envelope sender 150 /* address. 151 /* EXTERNAL COMMAND DELIVERY 152 /* .ad 153 /* .fi 154 /* The \fBallow_mail_to_commands\fR configuration parameter restricts 155 /* delivery to external commands. The default setting (\fBalias, 156 /* forward\fR) forbids command destinations in \fB:include:\fR files. 157 /* 158 /* Optionally, the process working directory is changed to the path 159 /* specified with \fBcommand_execution_directory\fR (Postfix 2.2 and 160 /* later). Failure to change directory causes mail to be deferred. 161 /* 162 /* The \fBcommand_execution_directory\fR parameter value is subject 163 /* to interpolation of \fB$user\fR (recipient username), 164 /* \fB$home\fR (recipient home directory), \fB$shell\fR 165 /* (recipient shell), \fB$recipient\fR (complete recipient 166 /* address), \fB$extension\fR (recipient address extension), 167 /* \fB$domain\fR (recipient domain), \fB$local\fR (entire 168 /* recipient address localpart) and \fB$recipient_delimiter.\fR 169 /* The forms \fI${name?value}\fR and \fI${name:value}\fR expand 170 /* conditionally to \fIvalue\fR when \fI$name\fR is (is not) 171 /* defined. Characters that may have special meaning to the 172 /* shell or file system are replaced by underscores. The list 173 /* of acceptable characters is specified with the 174 /* \fBexecution_directory_expansion_filter\fR configuration 175 /* parameter. 176 /* 177 /* The command is executed directly where possible. Assistance by the 178 /* shell (\fB/bin/sh\fR on UNIX systems) is used only when the command 179 /* contains shell magic characters, or when the command invokes a shell 180 /* built-in command. 181 /* 182 /* A limited amount of command output (standard output and standard 183 /* error) is captured for inclusion with non-delivery status reports. 184 /* A command is forcibly terminated if it does not complete within 185 /* \fBcommand_time_limit\fR seconds. Command exit status codes are 186 /* expected to follow the conventions defined in <\fBsysexits.h\fR>. 187 /* Exit status 0 means normal successful completion. 188 /* 189 /* Postfix version 2.3 and later support RFC 3463-style enhanced 190 /* status codes. If a command terminates with a non-zero exit 191 /* status, and the command output begins with an enhanced 192 /* status code, this status code takes precedence over the 193 /* non-zero exit status. 194 /* 195 /* A limited amount of message context is exported via environment 196 /* variables. Characters that may have special meaning to the shell 197 /* are replaced by underscores. The list of acceptable characters 198 /* is specified with the \fBcommand_expansion_filter\fR configuration 199 /* parameter. 200 /* .IP \fBSHELL\fR 201 /* The recipient user's login shell. 202 /* .IP \fBHOME\fR 203 /* The recipient user's home directory. 204 /* .IP \fBUSER\fR 205 /* The bare recipient name. 206 /* .IP \fBEXTENSION\fR 207 /* The optional recipient address extension. 208 /* .IP \fBDOMAIN\fR 209 /* The recipient address domain part. 210 /* .IP \fBLOGNAME\fR 211 /* The bare recipient name. 212 /* .IP \fBLOCAL\fR 213 /* The entire recipient address localpart (text to the left of the 214 /* rightmost @ character). 215 /* .IP \fBORIGINAL_RECIPIENT\fR 216 /* The entire recipient address, before any address rewriting 217 /* or aliasing (Postfix 2.5 and later). 218 /* .IP \fBRECIPIENT\fR 219 /* The entire recipient address. 220 /* .IP \fBSENDER\fR 221 /* The entire sender address. 222 /* .PP 223 /* Additional remote client information is made available via 224 /* the following environment variables: 225 /* .IP \fBCLIENT_ADDRESS\fR 226 /* Remote client network address. Available as of Postfix 2.2. 227 /* .IP \fBCLIENT_HELO\fR 228 /* Remote client EHLO command parameter. Available as of Postfix 2.2. 229 /* .IP \fBCLIENT_HOSTNAME\fR 230 /* Remote client hostname. Available as of Postfix 2.2. 231 /* .IP \fBCLIENT_PROTOCOL\fR 232 /* Remote client protocol. Available as of Postfix 2.2. 233 /* .IP \fBSASL_METHOD\fR 234 /* SASL authentication method specified in the 235 /* remote client AUTH command. Available as of Postfix 2.2. 236 /* .IP \fBSASL_SENDER\fR 237 /* SASL sender address specified in the remote client MAIL 238 /* FROM command. Available as of Postfix 2.2. 239 /* .IP \fBSASL_USERNAME\fR 240 /* SASL username specified in the remote client AUTH command. 241 /* Available as of Postfix 2.2. 242 /* .PP 243 /* The \fBPATH\fR environment variable is always reset to a 244 /* system-dependent default path, and environment variables 245 /* whose names are blessed by the \fBexport_environment\fR 246 /* configuration parameter are exported unchanged. 247 /* 248 /* The current working directory is the mail queue directory. 249 /* 250 /* The \fBlocal\fR(8) daemon prepends a "\fBFrom \fIsender time_stamp\fR" 251 /* envelope header to each message, prepends an 252 /* \fBX-Original-To:\fR header with the recipient address as given to 253 /* Postfix, prepends an 254 /* optional \fBDelivered-To:\fR 255 /* header with the final recipient envelope address, prepends a 256 /* \fBReturn-Path:\fR header with the sender envelope address, 257 /* and appends no empty line. 258 /* EXTERNAL FILE DELIVERY 259 /* .ad 260 /* .fi 261 /* The delivery format depends on the destination filename syntax. 262 /* The default is to use UNIX-style mailbox format. Specify a name 263 /* ending in \fB/\fR for \fBqmail\fR-compatible \fBmaildir\fR delivery. 264 /* 265 /* The \fBallow_mail_to_files\fR configuration parameter restricts 266 /* delivery to external files. The default setting (\fBalias, 267 /* forward\fR) forbids file destinations in \fB:include:\fR files. 268 /* 269 /* In the case of UNIX-style mailbox delivery, 270 /* the \fBlocal\fR(8) daemon prepends a "\fBFrom \fIsender time_stamp\fR" 271 /* envelope header to each message, prepends an 272 /* \fBX-Original-To:\fR header with the recipient address as given to 273 /* Postfix, prepends an 274 /* optional \fBDelivered-To:\fR 275 /* header with the final recipient envelope address, prepends a \fB>\fR 276 /* character to lines beginning with "\fBFrom \fR", and appends an 277 /* empty line. 278 /* The envelope sender address is available in the \fBReturn-Path:\fR 279 /* header. 280 /* When the destination is a regular file, it is locked for exclusive 281 /* access while delivery is in progress. In case of problems, an attempt 282 /* is made to truncate a regular file to its original length. 283 /* 284 /* In the case of \fBmaildir\fR delivery, the local daemon prepends 285 /* an optional 286 /* \fBDelivered-To:\fR header with the final envelope recipient address, 287 /* and prepends an 288 /* \fBX-Original-To:\fR header with the recipient address as given to 289 /* Postfix. 290 /* The envelope sender address is available in the \fBReturn-Path:\fR 291 /* header. 292 /* ADDRESS EXTENSION 293 /* .ad 294 /* .fi 295 /* The optional \fBrecipient_delimiter\fR configuration parameter 296 /* specifies how to separate address extensions from local recipient 297 /* names. 298 /* 299 /* For example, with "\fBrecipient_delimiter = +\fR", mail for 300 /* \fIname\fR+\fIfoo\fR is delivered to the alias \fIname\fR+\fIfoo\fR 301 /* or to the alias \fIname\fR, to the destinations listed in 302 /* ~\fIname\fR/.\fBforward\fR+\fIfoo\fR or in ~\fIname\fR/.\fBforward\fR, 303 /* to the mailbox owned by the user \fIname\fR, or it is sent back as 304 /* undeliverable. 305 /* DELIVERY RIGHTS 306 /* .ad 307 /* .fi 308 /* Deliveries to external files and external commands are made with 309 /* the rights of the receiving user on whose behalf the delivery is made. 310 /* In the absence of a user context, the \fBlocal\fR(8) daemon uses the 311 /* owner rights of the \fB:include:\fR file or alias database. 312 /* When those files are owned by the superuser, delivery is made with 313 /* the rights specified with the \fBdefault_privs\fR configuration 314 /* parameter. 315 /* STANDARDS 316 /* RFC 822 (ARPA Internet Text Messages) 317 /* RFC 3463 (Enhanced status codes) 318 /* DIAGNOSTICS 319 /* Problems and transactions are logged to \fBsyslogd\fR(8). 320 /* Corrupted message files are marked so that the queue 321 /* manager can move them to the \fBcorrupt\fR queue afterwards. 322 /* 323 /* Depending on the setting of the \fBnotify_classes\fR parameter, 324 /* the postmaster is notified of bounces and of other trouble. 325 /* SECURITY 326 /* .ad 327 /* .fi 328 /* The \fBlocal\fR(8) delivery agent needs a dual personality 329 /* 1) to access the private Postfix queue and IPC mechanisms, 330 /* 2) to impersonate the recipient and deliver to recipient-specified 331 /* files or commands. It is therefore security sensitive. 332 /* 333 /* The \fBlocal\fR(8) delivery agent disallows regular expression 334 /* substitution of $1 etc. in \fBalias_maps\fR, because that 335 /* would open a security hole. 336 /* 337 /* The \fBlocal\fR(8) delivery agent will silently ignore 338 /* requests to use the \fBproxymap\fR(8) server within 339 /* \fBalias_maps\fR. Instead it will open the table directly. 340 /* Before Postfix version 2.2, the \fBlocal\fR(8) delivery 341 /* agent will terminate with a fatal error. 342 /* BUGS 343 /* For security reasons, the message delivery status of external commands 344 /* or of external files is never checkpointed to file. As a result, 345 /* the program may occasionally deliver more than once to a command or 346 /* external file. Better safe than sorry. 347 /* 348 /* Mutually-recursive aliases or ~/.\fBforward\fR files are not detected 349 /* early. The resulting mail forwarding loop is broken by the use of the 350 /* \fBDelivered-To:\fR message header. 351 /* CONFIGURATION PARAMETERS 352 /* .ad 353 /* .fi 354 /* Changes to \fBmain.cf\fR are picked up automatically, as \fBlocal\fR(8) 355 /* processes run for only a limited amount of time. Use the command 356 /* "\fBpostfix reload\fR" to speed up a change. 357 /* 358 /* The text below provides only a parameter summary. See 359 /* \fBpostconf\fR(5) for more details including examples. 360 /* COMPATIBILITY CONTROLS 361 /* .ad 362 /* .fi 363 /* .IP "\fBbiff (yes)\fR" 364 /* Whether or not to use the local biff service. 365 /* .IP "\fBexpand_owner_alias (no)\fR" 366 /* When delivering to an alias "aliasname" that has an "owner-aliasname" 367 /* companion alias, set the envelope sender address to the expansion 368 /* of the "owner-aliasname" alias. 369 /* .IP "\fBowner_request_special (yes)\fR" 370 /* Give special treatment to owner-listname and listname-request 371 /* address localparts: don't split such addresses when the 372 /* recipient_delimiter is set to "-". 373 /* .IP "\fBsun_mailtool_compatibility (no)\fR" 374 /* Obsolete SUN mailtool compatibility feature. 375 /* .PP 376 /* Available in Postfix version 2.3 and later: 377 /* .IP "\fBfrozen_delivered_to (yes)\fR" 378 /* Update the \fBlocal\fR(8) delivery agent's idea of the Delivered-To: 379 /* address (see prepend_delivered_header) only once, at the start of 380 /* a delivery attempt; do not update the Delivered-To: address while 381 /* expanding aliases or .forward files. 382 /* .PP 383 /* Available in Postfix version 2.5.3 and later: 384 /* .IP "\fBstrict_mailbox_ownership (yes)\fR" 385 /* Defer delivery when a mailbox file is not owned by its recipient. 386 /* .IP "\fBreset_owner_alias (no)\fR" 387 /* Reset the \fBlocal\fR(8) delivery agent's idea of the owner-alias 388 /* attribute, when delivering mail to a child alias that does not have 389 /* its own owner alias. 390 /* DELIVERY METHOD CONTROLS 391 /* .ad 392 /* .fi 393 /* The precedence of \fBlocal\fR(8) delivery methods from high to low is: 394 /* aliases, .forward files, mailbox_transport_maps, 395 /* mailbox_transport, mailbox_command_maps, mailbox_command, 396 /* home_mailbox, mail_spool_directory, fallback_transport_maps, 397 /* fallback_transport, and luser_relay. 398 /* .IP "\fBalias_maps (see 'postconf -d' output)\fR" 399 /* The alias databases that are used for \fBlocal\fR(8) delivery. 400 /* .IP "\fBforward_path (see 'postconf -d' output)\fR" 401 /* The \fBlocal\fR(8) delivery agent search list for finding a .forward 402 /* file with user-specified delivery methods. 403 /* .IP "\fBmailbox_transport_maps (empty)\fR" 404 /* Optional lookup tables with per-recipient message delivery 405 /* transports to use for \fBlocal\fR(8) mailbox delivery, whether or not the 406 /* recipients are found in the UNIX passwd database. 407 /* .IP "\fBmailbox_transport (empty)\fR" 408 /* Optional message delivery transport that the \fBlocal\fR(8) delivery 409 /* agent should use for mailbox delivery to all local recipients, 410 /* whether or not they are found in the UNIX passwd database. 411 /* .IP "\fBmailbox_command_maps (empty)\fR" 412 /* Optional lookup tables with per-recipient external commands to use 413 /* for \fBlocal\fR(8) mailbox delivery. 414 /* .IP "\fBmailbox_command (empty)\fR" 415 /* Optional external command that the \fBlocal\fR(8) delivery agent should 416 /* use for mailbox delivery. 417 /* .IP "\fBhome_mailbox (empty)\fR" 418 /* Optional pathname of a mailbox file relative to a \fBlocal\fR(8) user's 419 /* home directory. 420 /* .IP "\fBmail_spool_directory (see 'postconf -d' output)\fR" 421 /* The directory where \fBlocal\fR(8) UNIX-style mailboxes are kept. 422 /* .IP "\fBfallback_transport_maps (empty)\fR" 423 /* Optional lookup tables with per-recipient message delivery 424 /* transports for recipients that the \fBlocal\fR(8) delivery agent could 425 /* not find in the \fBaliases\fR(5) or UNIX password database. 426 /* .IP "\fBfallback_transport (empty)\fR" 427 /* Optional message delivery transport that the \fBlocal\fR(8) delivery 428 /* agent should use for names that are not found in the \fBaliases\fR(5) 429 /* or UNIX password database. 430 /* .IP "\fBluser_relay (empty)\fR" 431 /* Optional catch-all destination for unknown \fBlocal\fR(8) recipients. 432 /* .PP 433 /* Available in Postfix version 2.2 and later: 434 /* .IP "\fBcommand_execution_directory (empty)\fR" 435 /* The \fBlocal\fR(8) delivery agent working directory for delivery to 436 /* external command. 437 /* MAILBOX LOCKING CONTROLS 438 /* .ad 439 /* .fi 440 /* .IP "\fBdeliver_lock_attempts (20)\fR" 441 /* The maximal number of attempts to acquire an exclusive lock on a 442 /* mailbox file or \fBbounce\fR(8) logfile. 443 /* .IP "\fBdeliver_lock_delay (1s)\fR" 444 /* The time between attempts to acquire an exclusive lock on a mailbox 445 /* file or \fBbounce\fR(8) logfile. 446 /* .IP "\fBstale_lock_time (500s)\fR" 447 /* The time after which a stale exclusive mailbox lockfile is removed. 448 /* .IP "\fBmailbox_delivery_lock (see 'postconf -d' output)\fR" 449 /* How to lock a UNIX-style \fBlocal\fR(8) mailbox before attempting delivery. 450 /* RESOURCE AND RATE CONTROLS 451 /* .ad 452 /* .fi 453 /* .IP "\fBcommand_time_limit (1000s)\fR" 454 /* Time limit for delivery to external commands. 455 /* .IP "\fBduplicate_filter_limit (1000)\fR" 456 /* The maximal number of addresses remembered by the address 457 /* duplicate filter for \fBaliases\fR(5) or \fBvirtual\fR(5) alias expansion, or 458 /* for \fBshowq\fR(8) queue displays. 459 /* .IP "\fBlocal_destination_concurrency_limit (2)\fR" 460 /* The maximal number of parallel deliveries via the local mail 461 /* delivery transport to the same recipient (when 462 /* "local_destination_recipient_limit = 1") or the maximal number of 463 /* parallel deliveries to the same local domain (when 464 /* "local_destination_recipient_limit > 1"). 465 /* .IP "\fBlocal_destination_recipient_limit (1)\fR" 466 /* The maximal number of recipients per message delivery via the 467 /* local mail delivery transport. 468 /* .IP "\fBmailbox_size_limit (51200000)\fR" 469 /* The maximal size of any \fBlocal\fR(8) individual mailbox or maildir 470 /* file, or zero (no limit). 471 /* SECURITY CONTROLS 472 /* .ad 473 /* .fi 474 /* .IP "\fBallow_mail_to_commands (alias, forward)\fR" 475 /* Restrict \fBlocal\fR(8) mail delivery to external commands. 476 /* .IP "\fBallow_mail_to_files (alias, forward)\fR" 477 /* Restrict \fBlocal\fR(8) mail delivery to external files. 478 /* .IP "\fBcommand_expansion_filter (see 'postconf -d' output)\fR" 479 /* Restrict the characters that the \fBlocal\fR(8) delivery agent allows in 480 /* $name expansions of $mailbox_command and $command_execution_directory. 481 /* .IP "\fBdefault_privs (nobody)\fR" 482 /* The default rights used by the \fBlocal\fR(8) delivery agent for delivery 483 /* to external file or command. 484 /* .IP "\fBforward_expansion_filter (see 'postconf -d' output)\fR" 485 /* Restrict the characters that the \fBlocal\fR(8) delivery agent allows in 486 /* $name expansions of $forward_path. 487 /* .PP 488 /* Available in Postfix version 2.2 and later: 489 /* .IP "\fBexecution_directory_expansion_filter (see 'postconf -d' output)\fR" 490 /* Restrict the characters that the \fBlocal\fR(8) delivery agent allows 491 /* in $name expansions of $command_execution_directory. 492 /* .PP 493 /* Available in Postfix version 2.5.3 and later: 494 /* .IP "\fBstrict_mailbox_ownership (yes)\fR" 495 /* Defer delivery when a mailbox file is not owned by its recipient. 496 /* MISCELLANEOUS CONTROLS 497 /* .ad 498 /* .fi 499 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR" 500 /* The default location of the Postfix main.cf and master.cf 501 /* configuration files. 502 /* .IP "\fBdaemon_timeout (18000s)\fR" 503 /* How much time a Postfix daemon process may take to handle a 504 /* request before it is terminated by a built-in watchdog timer. 505 /* .IP "\fBdelay_logging_resolution_limit (2)\fR" 506 /* The maximal number of digits after the decimal point when logging 507 /* sub-second delay values. 508 /* .IP "\fBexport_environment (see 'postconf -d' output)\fR" 509 /* The list of environment variables that a Postfix process will export 510 /* to non-Postfix processes. 511 /* .IP "\fBipc_timeout (3600s)\fR" 512 /* The time limit for sending or receiving information over an internal 513 /* communication channel. 514 /* .IP "\fBlocal_command_shell (empty)\fR" 515 /* Optional shell program for \fBlocal\fR(8) delivery to non-Postfix command. 516 /* .IP "\fBmax_idle (100s)\fR" 517 /* The maximum amount of time that an idle Postfix daemon process waits 518 /* for an incoming connection before terminating voluntarily. 519 /* .IP "\fBmax_use (100)\fR" 520 /* The maximal number of incoming connections that a Postfix daemon 521 /* process will service before terminating voluntarily. 522 /* .IP "\fBprepend_delivered_header (command, file, forward)\fR" 523 /* The message delivery contexts where the Postfix \fBlocal\fR(8) delivery 524 /* agent prepends a Delivered-To: message header with the address 525 /* that the mail was delivered to. 526 /* .IP "\fBprocess_id (read-only)\fR" 527 /* The process ID of a Postfix command or daemon process. 528 /* .IP "\fBprocess_name (read-only)\fR" 529 /* The process name of a Postfix command or daemon process. 530 /* .IP "\fBpropagate_unmatched_extensions (canonical, virtual)\fR" 531 /* What address lookup tables copy an address extension from the lookup 532 /* key to the lookup result. 533 /* .IP "\fBqueue_directory (see 'postconf -d' output)\fR" 534 /* The location of the Postfix top-level queue directory. 535 /* .IP "\fBrecipient_delimiter (empty)\fR" 536 /* The separator between user names and address extensions (user+foo). 537 /* .IP "\fBrequire_home_directory (no)\fR" 538 /* Require that a \fBlocal\fR(8) recipient's home directory exists 539 /* before mail delivery is attempted. 540 /* .IP "\fBsyslog_facility (mail)\fR" 541 /* The syslog facility of Postfix logging. 542 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR" 543 /* The mail system name that is prepended to the process name in syslog 544 /* records, so that "smtpd" becomes, for example, "postfix/smtpd". 545 /* FILES 546 /* The following are examples; details differ between systems. 547 /* $HOME/.forward, per-user aliasing 548 /* /etc/aliases, system-wide alias database 549 /* /var/spool/mail, system mailboxes 550 /* SEE ALSO 551 /* qmgr(8), queue manager 552 /* bounce(8), delivery status reports 553 /* newaliases(1), create/update alias database 554 /* postalias(1), create/update alias database 555 /* aliases(5), format of alias database 556 /* postconf(5), configuration parameters 557 /* master(5), generic daemon options 558 /* syslogd(8), system logging 559 /* LICENSE 560 /* .ad 561 /* .fi 562 /* The Secure Mailer license must be distributed with this software. 563 /* HISTORY 564 /* .ad 565 /* .fi 566 /* The \fBDelivered-To:\fR message header appears in the \fBqmail\fR 567 /* system by Daniel Bernstein. 568 /* 569 /* The \fImaildir\fR structure appears in the \fBqmail\fR system 570 /* by Daniel Bernstein. 571 /* AUTHOR(S) 572 /* Wietse Venema 573 /* IBM T.J. Watson Research 574 /* P.O. Box 704 575 /* Yorktown Heights, NY 10598, USA 576 /*--*/ 577 578 /* System library. */ 579 580 #include <sys_defs.h> 581 #include <unistd.h> 582 #include <stdlib.h> 583 #include <string.h> 584 #include <fcntl.h> 585 #ifdef USE_PATHS_H 586 #include <paths.h> 587 #endif 588 589 /* Utility library. */ 590 591 #include <msg.h> 592 #include <mymalloc.h> 593 #include <htable.h> 594 #include <vstring.h> 595 #include <vstream.h> 596 #include <iostuff.h> 597 #include <name_mask.h> 598 #include <set_eugid.h> 599 #include <dict.h> 600 601 /* Global library. */ 602 603 #include <recipient_list.h> 604 #include <deliver_request.h> 605 #include <deliver_completed.h> 606 #include <mail_params.h> 607 #include <mail_addr.h> 608 #include <mail_conf.h> 609 #include <been_here.h> 610 #include <mail_params.h> 611 #include <mail_version.h> 612 #include <ext_prop.h> 613 #include <maps.h> 614 #include <flush_clnt.h> 615 616 /* Single server skeleton. */ 617 618 #include <mail_server.h> 619 620 /* Application-specific. */ 621 622 #include "local.h" 623 624 /* 625 * Tunable parameters. 626 */ 627 char *var_allow_commands; 628 char *var_allow_files; 629 char *var_alias_maps; 630 int var_dup_filter_limit; 631 int var_command_maxtime; /* You can now leave this here. */ 632 char *var_home_mailbox; 633 char *var_mailbox_command; 634 char *var_mailbox_cmd_maps; 635 char *var_rcpt_fdelim; 636 char *var_local_cmd_shell; 637 char *var_luser_relay; 638 int var_biff; 639 char *var_mail_spool_dir; 640 char *var_mailbox_transport; 641 char *var_mbox_transp_maps; 642 char *var_fallback_transport; 643 char *var_fbck_transp_maps; 644 char *var_exec_directory; 645 char *var_exec_exp_filter; 646 char *var_forward_path; 647 char *var_cmd_exp_filter; 648 char *var_fwd_exp_filter; 649 char *var_prop_extension; 650 int var_exp_own_alias; 651 char *var_deliver_hdr; 652 int var_stat_home_dir; 653 int var_mailtool_compat; 654 char *var_mailbox_lock; 655 long var_mailbox_limit; 656 bool var_frozen_delivered; 657 bool var_reset_owner_attr; 658 bool var_strict_mbox_owner; 659 660 int local_cmd_deliver_mask; 661 int local_file_deliver_mask; 662 int local_ext_prop_mask; 663 int local_deliver_hdr_mask; 664 int local_mbox_lock_mask; 665 MAPS *alias_maps; 666 667 /* local_deliver - deliver message with extreme prejudice */ 668 669 static int local_deliver(DELIVER_REQUEST *rqst, char *service) 670 { 671 const char *myname = "local_deliver"; 672 RECIPIENT *rcpt_end = rqst->rcpt_list.info + rqst->rcpt_list.len; 673 RECIPIENT *rcpt; 674 int rcpt_stat; 675 int msg_stat; 676 LOCAL_STATE state; 677 USER_ATTR usr_attr; 678 679 if (msg_verbose) 680 msg_info("local_deliver: %s from %s", rqst->queue_id, rqst->sender); 681 682 /* 683 * Initialize the delivery attributes that are not recipient specific. 684 * While messages are being delivered and while aliases or forward files 685 * are being expanded, this attribute list is being changed constantly. 686 * For this reason, the list is passed on by value (except when it is 687 * being initialized :-), so that there is no need to undo attribute 688 * changes made by lower-level routines. The alias/include/forward 689 * expansion attribute list is part of a tree with self and parent 690 * references (see the EXPAND_ATTR definitions). The user-specific 691 * attributes are security sensitive, and are therefore kept separate. 692 * All this results in a noticeable level of clumsiness, but passing 693 * things around by value gives good protection against accidental change 694 * by subroutines. 695 */ 696 state.level = 0; 697 deliver_attr_init(&state.msg_attr); 698 state.msg_attr.queue_name = rqst->queue_name; 699 state.msg_attr.queue_id = rqst->queue_id; 700 state.msg_attr.fp = rqst->fp; 701 state.msg_attr.offset = rqst->data_offset; 702 state.msg_attr.encoding = rqst->encoding; 703 state.msg_attr.sender = rqst->sender; 704 state.msg_attr.dsn_envid = rqst->dsn_envid; 705 state.msg_attr.dsn_ret = rqst->dsn_ret; 706 state.msg_attr.relay = service; 707 state.msg_attr.msg_stats = rqst->msg_stats; 708 state.msg_attr.request = rqst; 709 RESET_OWNER_ATTR(state.msg_attr, state.level); 710 RESET_USER_ATTR(usr_attr, state.level); 711 state.loop_info = delivered_hdr_init(rqst->fp, rqst->data_offset, 712 FOLD_ADDR_ALL); 713 state.request = rqst; 714 715 /* 716 * Iterate over each recipient named in the delivery request. When the 717 * mail delivery status for a given recipient is definite (i.e. bounced 718 * or delivered), update the message queue file and cross off the 719 * recipient. Update the per-message delivery status. 720 */ 721 for (msg_stat = 0, rcpt = rqst->rcpt_list.info; rcpt < rcpt_end; rcpt++) { 722 state.dup_filter = been_here_init(var_dup_filter_limit, BH_FLAG_FOLD); 723 forward_init(); 724 state.msg_attr.rcpt = *rcpt; 725 rcpt_stat = deliver_recipient(state, usr_attr); 726 rcpt_stat |= forward_finish(rqst, state.msg_attr, rcpt_stat); 727 if (rcpt_stat == 0 && (rqst->flags & DEL_REQ_FLAG_SUCCESS)) 728 deliver_completed(state.msg_attr.fp, rcpt->offset); 729 been_here_free(state.dup_filter); 730 msg_stat |= rcpt_stat; 731 } 732 733 /* 734 * Clean up. 735 */ 736 delivered_hdr_free(state.loop_info); 737 deliver_attr_free(&state.msg_attr); 738 739 return (msg_stat); 740 } 741 742 /* local_service - perform service for client */ 743 744 static void local_service(VSTREAM *stream, char *service, char **argv) 745 { 746 DELIVER_REQUEST *request; 747 int status; 748 749 /* 750 * Sanity check. This service takes no command-line arguments. 751 */ 752 if (argv[0]) 753 msg_fatal("unexpected command-line argument: %s", argv[0]); 754 755 /* 756 * This routine runs whenever a client connects to the UNIX-domain socket 757 * that is dedicated to local mail delivery service. What we see below is 758 * a little protocol to (1) tell the client that we are ready, (2) read a 759 * delivery request from the client, and (3) report the completion status 760 * of that request. 761 */ 762 if ((request = deliver_request_read(stream)) != 0) { 763 status = local_deliver(request, service); 764 deliver_request_done(stream, request, status); 765 } 766 } 767 768 /* local_mask_init - initialize delivery restrictions */ 769 770 static void local_mask_init(void) 771 { 772 static const NAME_MASK file_mask[] = { 773 "alias", EXPAND_TYPE_ALIAS, 774 "forward", EXPAND_TYPE_FWD, 775 "include", EXPAND_TYPE_INCL, 776 0, 777 }; 778 static const NAME_MASK command_mask[] = { 779 "alias", EXPAND_TYPE_ALIAS, 780 "forward", EXPAND_TYPE_FWD, 781 "include", EXPAND_TYPE_INCL, 782 0, 783 }; 784 static const NAME_MASK deliver_mask[] = { 785 "command", DELIVER_HDR_CMD, 786 "file", DELIVER_HDR_FILE, 787 "forward", DELIVER_HDR_FWD, 788 0, 789 }; 790 791 local_file_deliver_mask = name_mask(VAR_ALLOW_FILES, file_mask, 792 var_allow_files); 793 local_cmd_deliver_mask = name_mask(VAR_ALLOW_COMMANDS, command_mask, 794 var_allow_commands); 795 local_ext_prop_mask = 796 ext_prop_mask(VAR_PROP_EXTENSION, var_prop_extension); 797 local_deliver_hdr_mask = name_mask(VAR_DELIVER_HDR, deliver_mask, 798 var_deliver_hdr); 799 local_mbox_lock_mask = mbox_lock_mask(var_mailbox_lock); 800 if (var_mailtool_compat) { 801 msg_warn("%s: deprecated parameter, use \"%s = dotlock\" instead", 802 VAR_MAILTOOL_COMPAT, VAR_MAILBOX_LOCK); 803 local_mbox_lock_mask &= MBOX_DOT_LOCK; 804 } 805 if (local_mbox_lock_mask == 0) 806 msg_fatal("parameter %s specifies no applicable mailbox locking method", 807 VAR_MAILBOX_LOCK); 808 } 809 810 /* pre_accept - see if tables have changed */ 811 812 static void pre_accept(char *unused_name, char **unused_argv) 813 { 814 const char *table; 815 816 if ((table = dict_changed_name()) != 0) { 817 msg_info("table %s has changed -- restarting", table); 818 exit(0); 819 } 820 } 821 822 /* post_init - post-jail initialization */ 823 824 static void post_init(char *unused_name, char **unused_argv) 825 { 826 827 /* 828 * Drop privileges most of the time, and set up delivery restrictions. 829 */ 830 set_eugid(var_owner_uid, var_owner_gid); 831 local_mask_init(); 832 } 833 834 /* pre_init - pre-jail initialization */ 835 836 static void pre_init(char *unused_name, char **unused_argv) 837 { 838 839 /* 840 * Reset the file size limit from the message size limit to the mailbox 841 * size limit. XXX This still isn't accurate because the file size limit 842 * also affects delivery to command. 843 * 844 * A file size limit protects the machine against runaway software errors. 845 * It is not suitable to enforce mail quota, because users can get around 846 * mail quota by delivering to /file/name or to |command. 847 * 848 * We can't have mailbox size limit smaller than the message size limit, 849 * because that prohibits the delivery agent from updating the queue 850 * file. 851 */ 852 if (var_mailbox_limit) { 853 if (var_mailbox_limit < var_message_limit || var_message_limit == 0) 854 msg_fatal("main.cf configuration error: %s is smaller than %s", 855 VAR_MAILBOX_LIMIT, VAR_MESSAGE_LIMIT); 856 set_file_limit(var_mailbox_limit); 857 } 858 alias_maps = maps_create("aliases", var_alias_maps, 859 DICT_FLAG_LOCK | DICT_FLAG_PARANOID 860 | DICT_FLAG_FOLD_FIX); 861 862 flush_init(); 863 } 864 865 MAIL_VERSION_STAMP_DECLARE; 866 867 /* main - pass control to the single-threaded skeleton */ 868 869 int main(int argc, char **argv) 870 { 871 static const CONFIG_TIME_TABLE time_table[] = { 872 VAR_COMMAND_MAXTIME, DEF_COMMAND_MAXTIME, &var_command_maxtime, 1, 0, 873 0, 874 }; 875 static const CONFIG_INT_TABLE int_table[] = { 876 VAR_DUP_FILTER_LIMIT, DEF_DUP_FILTER_LIMIT, &var_dup_filter_limit, 0, 0, 877 0, 878 }; 879 static const CONFIG_LONG_TABLE long_table[] = { 880 VAR_MAILBOX_LIMIT, DEF_MAILBOX_LIMIT, &var_mailbox_limit, 0, 0, 881 0, 882 }; 883 static const CONFIG_STR_TABLE str_table[] = { 884 VAR_ALIAS_MAPS, DEF_ALIAS_MAPS, &var_alias_maps, 0, 0, 885 VAR_HOME_MAILBOX, DEF_HOME_MAILBOX, &var_home_mailbox, 0, 0, 886 VAR_ALLOW_COMMANDS, DEF_ALLOW_COMMANDS, &var_allow_commands, 0, 0, 887 VAR_ALLOW_FILES, DEF_ALLOW_FILES, &var_allow_files, 0, 0, 888 VAR_LOCAL_CMD_SHELL, DEF_LOCAL_CMD_SHELL, &var_local_cmd_shell, 0, 0, 889 VAR_MAIL_SPOOL_DIR, DEF_MAIL_SPOOL_DIR, &var_mail_spool_dir, 0, 0, 890 VAR_MAILBOX_TRANSP, DEF_MAILBOX_TRANSP, &var_mailbox_transport, 0, 0, 891 VAR_MBOX_TRANSP_MAPS, DEF_MBOX_TRANSP_MAPS, &var_mbox_transp_maps, 0, 0, 892 VAR_FALLBACK_TRANSP, DEF_FALLBACK_TRANSP, &var_fallback_transport, 0, 0, 893 VAR_FBCK_TRANSP_MAPS, DEF_FBCK_TRANSP_MAPS, &var_fbck_transp_maps, 0, 0, 894 VAR_CMD_EXP_FILTER, DEF_CMD_EXP_FILTER, &var_cmd_exp_filter, 1, 0, 895 VAR_FWD_EXP_FILTER, DEF_FWD_EXP_FILTER, &var_fwd_exp_filter, 1, 0, 896 VAR_EXEC_EXP_FILTER, DEF_EXEC_EXP_FILTER, &var_exec_exp_filter, 1, 0, 897 VAR_PROP_EXTENSION, DEF_PROP_EXTENSION, &var_prop_extension, 0, 0, 898 VAR_DELIVER_HDR, DEF_DELIVER_HDR, &var_deliver_hdr, 0, 0, 899 VAR_MAILBOX_LOCK, DEF_MAILBOX_LOCK, &var_mailbox_lock, 1, 0, 900 VAR_MAILBOX_CMD_MAPS, DEF_MAILBOX_CMD_MAPS, &var_mailbox_cmd_maps, 0, 0, 901 0, 902 }; 903 static const CONFIG_BOOL_TABLE bool_table[] = { 904 VAR_BIFF, DEF_BIFF, &var_biff, 905 VAR_EXP_OWN_ALIAS, DEF_EXP_OWN_ALIAS, &var_exp_own_alias, 906 VAR_STAT_HOME_DIR, DEF_STAT_HOME_DIR, &var_stat_home_dir, 907 VAR_MAILTOOL_COMPAT, DEF_MAILTOOL_COMPAT, &var_mailtool_compat, 908 VAR_FROZEN_DELIVERED, DEF_FROZEN_DELIVERED, &var_frozen_delivered, 909 VAR_RESET_OWNER_ATTR, DEF_RESET_OWNER_ATTR, &var_reset_owner_attr, 910 VAR_STRICT_MBOX_OWNER, DEF_STRICT_MBOX_OWNER, &var_strict_mbox_owner, 911 0, 912 }; 913 914 /* Suppress $name expansion upon loading. */ 915 static const CONFIG_RAW_TABLE raw_table[] = { 916 VAR_EXEC_DIRECTORY, DEF_EXEC_DIRECTORY, &var_exec_directory, 0, 0, 917 VAR_FORWARD_PATH, DEF_FORWARD_PATH, &var_forward_path, 0, 0, 918 VAR_MAILBOX_COMMAND, DEF_MAILBOX_COMMAND, &var_mailbox_command, 0, 0, 919 VAR_LUSER_RELAY, DEF_LUSER_RELAY, &var_luser_relay, 0, 0, 920 0, 921 }; 922 923 /* 924 * Fingerprint executables and core dumps. 925 */ 926 MAIL_VERSION_STAMP_ALLOCATE; 927 928 single_server_main(argc, argv, local_service, 929 MAIL_SERVER_INT_TABLE, int_table, 930 MAIL_SERVER_LONG_TABLE, long_table, 931 MAIL_SERVER_STR_TABLE, str_table, 932 MAIL_SERVER_RAW_TABLE, raw_table, 933 MAIL_SERVER_BOOL_TABLE, bool_table, 934 MAIL_SERVER_TIME_TABLE, time_table, 935 MAIL_SERVER_PRE_INIT, pre_init, 936 MAIL_SERVER_POST_INIT, post_init, 937 MAIL_SERVER_PRE_ACCEPT, pre_accept, 938 MAIL_SERVER_PRIVILEGED, 939 0); 940 } 941