1 /* 2 * Copyright (c) 1983 Eric P. Allman 3 * Copyright (c) 1988, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * %sccs.include.redist.c% 7 */ 8 9 #ifndef lint 10 static char sccsid[] = "@(#)envelope.c 8.54 (Berkeley) 03/21/95"; 11 #endif /* not lint */ 12 13 #include "sendmail.h" 14 #include <pwd.h> 15 16 /* 17 ** NEWENVELOPE -- allocate a new envelope 18 ** 19 ** Supports inheritance. 20 ** 21 ** Parameters: 22 ** e -- the new envelope to fill in. 23 ** parent -- the envelope to be the parent of e. 24 ** 25 ** Returns: 26 ** e. 27 ** 28 ** Side Effects: 29 ** none. 30 */ 31 32 ENVELOPE * 33 newenvelope(e, parent) 34 register ENVELOPE *e; 35 register ENVELOPE *parent; 36 { 37 extern putheader(), putbody(); 38 extern ENVELOPE BlankEnvelope; 39 40 if (e == parent && e->e_parent != NULL) 41 parent = e->e_parent; 42 clearenvelope(e, TRUE); 43 if (e == CurEnv) 44 bcopy((char *) &NullAddress, (char *) &e->e_from, sizeof e->e_from); 45 else 46 bcopy((char *) &CurEnv->e_from, (char *) &e->e_from, sizeof e->e_from); 47 e->e_parent = parent; 48 e->e_ctime = curtime(); 49 if (parent != NULL) 50 e->e_msgpriority = parent->e_msgsize; 51 e->e_puthdr = putheader; 52 e->e_putbody = putbody; 53 if (CurEnv->e_xfp != NULL) 54 (void) fflush(CurEnv->e_xfp); 55 56 return (e); 57 } 58 /* 59 ** DROPENVELOPE -- deallocate an envelope. 60 ** 61 ** Parameters: 62 ** e -- the envelope to deallocate. 63 ** 64 ** Returns: 65 ** none. 66 ** 67 ** Side Effects: 68 ** housekeeping necessary to dispose of an envelope. 69 ** Unlocks this queue file. 70 */ 71 72 void 73 dropenvelope(e) 74 register ENVELOPE *e; 75 { 76 bool queueit = FALSE; 77 bool failure_return = FALSE; 78 bool success_return = FALSE; 79 register ADDRESS *q; 80 char *id = e->e_id; 81 char buf[MAXLINE]; 82 83 if (tTd(50, 1)) 84 { 85 printf("dropenvelope %x: id=", e); 86 xputs(e->e_id); 87 printf(", flags=0x%x\n", e->e_flags); 88 if (tTd(50, 10)) 89 { 90 printf("sendq="); 91 printaddr(e->e_sendqueue, TRUE); 92 } 93 } 94 95 /* we must have an id to remove disk files */ 96 if (id == NULL) 97 return; 98 99 #ifdef LOG 100 if (LogLevel > 4 && bitset(EF_LOGSENDER, e->e_flags)) 101 logsender(e, NULL); 102 if (LogLevel > 84) 103 syslog(LOG_DEBUG, "dropenvelope, id=%s, flags=0x%x, pid=%d", 104 id, e->e_flags, getpid()); 105 #endif /* LOG */ 106 e->e_flags &= ~EF_LOGSENDER; 107 108 /* post statistics */ 109 poststats(StatFile); 110 111 /* 112 ** Extract state information from dregs of send list. 113 */ 114 115 e->e_flags &= ~EF_QUEUERUN; 116 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 117 { 118 if (bitset(QQUEUEUP, q->q_flags)) 119 queueit = TRUE; 120 121 /* see if a notification is needed */ 122 if (bitset(QBADADDR, q->q_flags) && 123 bitset(QPINGONFAILURE, q->q_flags)) 124 { 125 failure_return = TRUE; 126 if (q->q_owner == NULL && !emptyaddr(&e->e_from)) 127 (void) sendtolist(e->e_from.q_paddr, NULL, 128 &e->e_errorqueue, 0, e); 129 } 130 else if (bitset(QSENT, q->q_flags) && 131 bitnset(M_LOCALMAILER, q->q_mailer->m_flags) && 132 bitset(QPINGONSUCCESS, q->q_flags)) 133 { 134 success_return = TRUE; 135 } 136 else if (bitset(QRELAYED, q->q_flags)) 137 { 138 success_return = TRUE; 139 } 140 else 141 { 142 continue; 143 } 144 } 145 146 if (e->e_class < 0) 147 e->e_flags |= EF_NO_BODY_RETN; 148 149 /* 150 ** See if the message timed out. 151 */ 152 153 if (!queueit) 154 /* nothing to do */ ; 155 else if (curtime() > e->e_ctime + TimeOuts.to_q_return[e->e_timeoutclass]) 156 { 157 (void) sprintf(buf, "Cannot send message for %s", 158 pintvl(TimeOuts.to_q_return[e->e_timeoutclass], FALSE)); 159 if (e->e_message != NULL) 160 free(e->e_message); 161 e->e_message = newstr(buf); 162 message(buf); 163 e->e_flags |= EF_CLRQUEUE; 164 failure_return = TRUE; 165 fprintf(e->e_xfp, "Message could not be delivered for %s\n", 166 pintvl(TimeOuts.to_q_return[e->e_timeoutclass], FALSE)); 167 fprintf(e->e_xfp, "Message will be deleted from queue\n"); 168 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 169 { 170 if (bitset(QQUEUEUP, q->q_flags)) 171 q->q_flags |= QBADADDR; 172 } 173 } 174 else if (TimeOuts.to_q_warning[e->e_timeoutclass] > 0 && 175 curtime() > e->e_ctime + TimeOuts.to_q_warning[e->e_timeoutclass]) 176 { 177 bool delay_return = FALSE; 178 179 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 180 { 181 if (bitset(QQUEUEUP, q->q_flags) && 182 bitset(QPINGONDELAY, q->q_flags)) 183 { 184 q->q_flags |= QREPORT; 185 delay_return = TRUE; 186 } 187 } 188 if (delay_return && 189 !bitset(EF_WARNING|EF_RESPONSE, e->e_flags) && 190 e->e_class >= 0 && 191 strcmp(e->e_from.q_paddr, "<>") != 0 && 192 strncasecmp(e->e_from.q_paddr, "owner-", 6) != 0 && 193 (strlen(e->e_from.q_paddr) <= 8 || 194 strcasecmp(&e->e_from.q_paddr[strlen(e->e_from.q_paddr) - 8], "-request") != 0)) 195 { 196 (void) sprintf(buf, 197 "Warning: cannot send message for %s", 198 pintvl(TimeOuts.to_q_warning[e->e_timeoutclass], FALSE)); 199 if (e->e_message != NULL) 200 free(e->e_message); 201 e->e_message = newstr(buf); 202 message(buf); 203 e->e_flags |= EF_WARNING; 204 failure_return = TRUE; 205 } 206 fprintf(e->e_xfp, 207 "Warning: message still undelivered after %s\n", 208 pintvl(TimeOuts.to_q_warning[e->e_timeoutclass], FALSE)); 209 fprintf(e->e_xfp, "Will keep trying until message is %s old\n", 210 pintvl(TimeOuts.to_q_return[e->e_timeoutclass], FALSE)); 211 } 212 213 if (tTd(50, 2)) 214 printf("failure_return=%d success_return=%d queueit=%d\n", 215 failure_return, success_return, queueit); 216 217 /* 218 ** If we had some fatal error, but no addresses are marked as 219 ** bad, mark them _all_ as bad. 220 */ 221 222 if (bitset(EF_FATALERRS, e->e_flags) && !failure_return) 223 { 224 failure_return = TRUE; 225 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 226 { 227 if (!bitset(QDONTSEND, q->q_flags)) 228 q->q_flags |= QBADADDR; 229 } 230 } 231 232 /* 233 ** Send back return receipts as requested. 234 */ 235 236 /* 237 if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags) 238 && !bitset(PRIV_NORECEIPTS, PrivacyFlags)) 239 */ 240 if (e->e_receiptto == NULL) 241 e->e_receiptto = e->e_from.q_paddr; 242 if (success_return && !failure_return && 243 !bitset(PRIV_NORECEIPTS, PrivacyFlags) && 244 strcmp(e->e_receiptto, "<>") != 0) 245 { 246 auto ADDRESS *rlist = NULL; 247 248 e->e_flags |= EF_SENDRECEIPT; 249 (void) sendtolist(e->e_receiptto, NULLADDR, &rlist, 0, e); 250 (void) returntosender("Return receipt", rlist, FALSE, e); 251 } 252 e->e_flags &= ~EF_SENDRECEIPT; 253 254 /* 255 ** Arrange to send error messages if there are fatal errors. 256 */ 257 258 if (failure_return && e->e_errormode != EM_QUIET) 259 savemail(e, !bitset(EF_NO_BODY_RETN, e->e_flags)); 260 261 /* 262 ** Arrange to send warning messages to postmaster as requested. 263 */ 264 265 if (bitset(EF_PM_NOTIFY, e->e_flags) && PostMasterCopy != NULL && 266 !bitset(EF_RESPONSE, e->e_flags) && e->e_class >= 0) 267 { 268 auto ADDRESS *rlist = NULL; 269 270 (void) sendtolist(PostMasterCopy, NULLADDR, &rlist, 0, e); 271 (void) returntosender(e->e_message, rlist, FALSE, e); 272 } 273 274 /* 275 ** Instantiate or deinstantiate the queue. 276 */ 277 278 if ((!queueit && !bitset(EF_KEEPQUEUE, e->e_flags)) || 279 bitset(EF_CLRQUEUE, e->e_flags)) 280 { 281 if (tTd(50, 1)) 282 printf("\n===== Dropping [dq]f%s (queueit=%d, e_flags=%x) =====\n\n", 283 e->e_id, queueit, e->e_flags); 284 xunlink(queuename(e, 'd')); 285 xunlink(queuename(e, 'q')); 286 287 #ifdef LOG 288 if (LogLevel > 10) 289 syslog(LOG_INFO, "%s: done", id); 290 #endif 291 } 292 else if (queueit || !bitset(EF_INQUEUE, e->e_flags)) 293 { 294 #ifdef QUEUE 295 queueup(e, bitset(EF_KEEPQUEUE, e->e_flags), FALSE); 296 #else /* QUEUE */ 297 syserr("554 dropenvelope: queueup"); 298 #endif /* QUEUE */ 299 } 300 301 /* now unlock the job */ 302 closexscript(e); 303 unlockqueue(e); 304 305 /* make sure that this envelope is marked unused */ 306 if (e->e_dfp != NULL) 307 (void) xfclose(e->e_dfp, "dropenvelope df", e->e_id); 308 e->e_dfp = NULL; 309 e->e_id = NULL; 310 e->e_flags &= ~EF_HAS_DF; 311 } 312 /* 313 ** CLEARENVELOPE -- clear an envelope without unlocking 314 ** 315 ** This is normally used by a child process to get a clean 316 ** envelope without disturbing the parent. 317 ** 318 ** Parameters: 319 ** e -- the envelope to clear. 320 ** fullclear - if set, the current envelope is total 321 ** garbage and should be ignored; otherwise, 322 ** release any resources it may indicate. 323 ** 324 ** Returns: 325 ** none. 326 ** 327 ** Side Effects: 328 ** Closes files associated with the envelope. 329 ** Marks the envelope as unallocated. 330 */ 331 332 void 333 clearenvelope(e, fullclear) 334 register ENVELOPE *e; 335 bool fullclear; 336 { 337 register HDR *bh; 338 register HDR **nhp; 339 extern ENVELOPE BlankEnvelope; 340 341 if (!fullclear) 342 { 343 /* clear out any file information */ 344 if (e->e_xfp != NULL) 345 (void) xfclose(e->e_xfp, "clearenvelope xfp", e->e_id); 346 if (e->e_dfp != NULL) 347 (void) xfclose(e->e_dfp, "clearenvelope dfp", e->e_id); 348 e->e_xfp = e->e_dfp = NULL; 349 } 350 351 /* now clear out the data */ 352 STRUCTCOPY(BlankEnvelope, *e); 353 if (Verbose) 354 e->e_sendmode = SM_DELIVER; 355 bh = BlankEnvelope.e_header; 356 nhp = &e->e_header; 357 while (bh != NULL) 358 { 359 *nhp = (HDR *) xalloc(sizeof *bh); 360 bcopy((char *) bh, (char *) *nhp, sizeof *bh); 361 bh = bh->h_link; 362 nhp = &(*nhp)->h_link; 363 } 364 } 365 /* 366 ** INITSYS -- initialize instantiation of system 367 ** 368 ** In Daemon mode, this is done in the child. 369 ** 370 ** Parameters: 371 ** none. 372 ** 373 ** Returns: 374 ** none. 375 ** 376 ** Side Effects: 377 ** Initializes the system macros, some global variables, 378 ** etc. In particular, the current time in various 379 ** forms is set. 380 */ 381 382 void 383 initsys(e) 384 register ENVELOPE *e; 385 { 386 char cbuf[5]; /* holds hop count */ 387 char pbuf[10]; /* holds pid */ 388 #ifdef TTYNAME 389 static char ybuf[60]; /* holds tty id */ 390 register char *p; 391 #endif /* TTYNAME */ 392 extern char *ttyname(); 393 extern void settime(); 394 extern char Version[]; 395 396 /* 397 ** Give this envelope a reality. 398 ** I.e., an id, a transcript, and a creation time. 399 */ 400 401 openxscript(e); 402 e->e_ctime = curtime(); 403 404 /* 405 ** Set OutChannel to something useful if stdout isn't it. 406 ** This arranges that any extra stuff the mailer produces 407 ** gets sent back to the user on error (because it is 408 ** tucked away in the transcript). 409 */ 410 411 if (OpMode == MD_DAEMON && bitset(EF_QUEUERUN, e->e_flags) && 412 e->e_xfp != NULL) 413 OutChannel = e->e_xfp; 414 415 /* 416 ** Set up some basic system macros. 417 */ 418 419 /* process id */ 420 (void) sprintf(pbuf, "%d", getpid()); 421 define('p', newstr(pbuf), e); 422 423 /* hop count */ 424 (void) sprintf(cbuf, "%d", e->e_hopcount); 425 define('c', newstr(cbuf), e); 426 427 /* time as integer, unix time, arpa time */ 428 settime(e); 429 430 #ifdef TTYNAME 431 /* tty name */ 432 if (macvalue('y', e) == NULL) 433 { 434 p = ttyname(2); 435 if (p != NULL) 436 { 437 if (strrchr(p, '/') != NULL) 438 p = strrchr(p, '/') + 1; 439 (void) strcpy(ybuf, p); 440 define('y', ybuf, e); 441 } 442 } 443 #endif /* TTYNAME */ 444 } 445 /* 446 ** SETTIME -- set the current time. 447 ** 448 ** Parameters: 449 ** none. 450 ** 451 ** Returns: 452 ** none. 453 ** 454 ** Side Effects: 455 ** Sets the various time macros -- $a, $b, $d, $t. 456 */ 457 458 void 459 settime(e) 460 register ENVELOPE *e; 461 { 462 register char *p; 463 auto time_t now; 464 char tbuf[20]; /* holds "current" time */ 465 char dbuf[30]; /* holds ctime(tbuf) */ 466 register struct tm *tm; 467 extern char *arpadate(); 468 extern struct tm *gmtime(); 469 470 now = curtime(); 471 tm = gmtime(&now); 472 (void) sprintf(tbuf, "%04d%02d%02d%02d%02d", tm->tm_year + 1900, 473 tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min); 474 define('t', newstr(tbuf), e); 475 (void) strcpy(dbuf, ctime(&now)); 476 p = strchr(dbuf, '\n'); 477 if (p != NULL) 478 *p = '\0'; 479 define('d', newstr(dbuf), e); 480 p = arpadate(dbuf); 481 p = newstr(p); 482 if (macvalue('a', e) == NULL) 483 define('a', p, e); 484 define('b', p, e); 485 } 486 /* 487 ** OPENXSCRIPT -- Open transcript file 488 ** 489 ** Creates a transcript file for possible eventual mailing or 490 ** sending back. 491 ** 492 ** Parameters: 493 ** e -- the envelope to create the transcript in/for. 494 ** 495 ** Returns: 496 ** none 497 ** 498 ** Side Effects: 499 ** Creates the transcript file. 500 */ 501 502 #ifndef O_APPEND 503 #define O_APPEND 0 504 #endif 505 506 void 507 openxscript(e) 508 register ENVELOPE *e; 509 { 510 register char *p; 511 int fd; 512 513 if (e->e_xfp != NULL) 514 return; 515 p = queuename(e, 'x'); 516 fd = open(p, O_WRONLY|O_CREAT|O_APPEND, 0644); 517 if (fd < 0) 518 { 519 syserr("Can't create transcript file %s", p); 520 fd = open("/dev/null", O_WRONLY, 0644); 521 if (fd < 0) 522 syserr("!Can't open /dev/null"); 523 } 524 e->e_xfp = fdopen(fd, "a"); 525 if (e->e_xfp == NULL) 526 syserr("!Can't create transcript stream %s", p); 527 #ifdef HASSETVBUF 528 setvbuf(e->e_xfp, NULL, _IOLBF, 0); 529 #else 530 setlinebuf(e->e_xfp); 531 #endif 532 if (tTd(46, 9)) 533 { 534 printf("openxscript(%s):\n ", p); 535 dumpfd(fileno(e->e_xfp), TRUE, FALSE); 536 } 537 } 538 /* 539 ** CLOSEXSCRIPT -- close the transcript file. 540 ** 541 ** Parameters: 542 ** e -- the envelope containing the transcript to close. 543 ** 544 ** Returns: 545 ** none. 546 ** 547 ** Side Effects: 548 ** none. 549 */ 550 551 void 552 closexscript(e) 553 register ENVELOPE *e; 554 { 555 if (e->e_xfp == NULL) 556 return; 557 (void) xfclose(e->e_xfp, "closexscript", e->e_id); 558 e->e_xfp = NULL; 559 } 560 /* 561 ** SETSENDER -- set the person who this message is from 562 ** 563 ** Under certain circumstances allow the user to say who 564 ** s/he is (using -f or -r). These are: 565 ** 1. The user's uid is zero (root). 566 ** 2. The user's login name is in an approved list (typically 567 ** from a network server). 568 ** 3. The address the user is trying to claim has a 569 ** "!" character in it (since #2 doesn't do it for 570 ** us if we are dialing out for UUCP). 571 ** A better check to replace #3 would be if the 572 ** effective uid is "UUCP" -- this would require me 573 ** to rewrite getpwent to "grab" uucp as it went by, 574 ** make getname more nasty, do another passwd file 575 ** scan, or compile the UID of "UUCP" into the code, 576 ** all of which are reprehensible. 577 ** 578 ** Assuming all of these fail, we figure out something 579 ** ourselves. 580 ** 581 ** Parameters: 582 ** from -- the person we would like to believe this message 583 ** is from, as specified on the command line. 584 ** e -- the envelope in which we would like the sender set. 585 ** delimptr -- if non-NULL, set to the location of the 586 ** trailing delimiter. 587 ** internal -- set if this address is coming from an internal 588 ** source such as an owner alias. 589 ** 590 ** Returns: 591 ** none. 592 ** 593 ** Side Effects: 594 ** sets sendmail's notion of who the from person is. 595 */ 596 597 void 598 setsender(from, e, delimptr, internal) 599 char *from; 600 register ENVELOPE *e; 601 char **delimptr; 602 bool internal; 603 { 604 register char **pvp; 605 char *realname = NULL; 606 register struct passwd *pw; 607 char delimchar; 608 char *bp; 609 char buf[MAXNAME + 2]; 610 char pvpbuf[PSBUFSIZE]; 611 extern struct passwd *getpwnam(); 612 extern char *FullName; 613 614 if (tTd(45, 1)) 615 printf("setsender(%s)\n", from == NULL ? "" : from); 616 617 /* 618 ** Figure out the real user executing us. 619 ** Username can return errno != 0 on non-errors. 620 */ 621 622 if (bitset(EF_QUEUERUN, e->e_flags) || OpMode == MD_SMTP || 623 OpMode == MD_ARPAFTP || OpMode == MD_DAEMON) 624 realname = from; 625 if (realname == NULL || realname[0] == '\0') 626 realname = username(); 627 628 if (ConfigLevel < 2) 629 SuprErrs = TRUE; 630 631 delimchar = internal ? '\0' : ' '; 632 e->e_from.q_flags = QBADADDR; 633 if (from == NULL || 634 parseaddr(from, &e->e_from, RF_COPYALL|RF_SENDERADDR, 635 delimchar, delimptr, e) == NULL || 636 bitset(QBADADDR, e->e_from.q_flags) || 637 e->e_from.q_mailer == ProgMailer || 638 e->e_from.q_mailer == FileMailer || 639 e->e_from.q_mailer == InclMailer) 640 { 641 /* log garbage addresses for traceback */ 642 # ifdef LOG 643 if (from != NULL && LogLevel > 2) 644 { 645 char *p; 646 char ebuf[MAXNAME * 2 + 2]; 647 648 p = macvalue('_', e); 649 if (p == NULL) 650 { 651 char *host = RealHostName; 652 if (host == NULL) 653 host = MyHostName; 654 (void) sprintf(ebuf, "%s@%s", realname, host); 655 p = ebuf; 656 } 657 syslog(LOG_NOTICE, 658 "setsender: %s: invalid or unparseable, received from %s", 659 shortenstring(from, 83), p); 660 } 661 # endif /* LOG */ 662 if (from != NULL) 663 { 664 if (!bitset(QBADADDR, e->e_from.q_flags)) 665 { 666 /* it was a bogus mailer in the from addr */ 667 usrerr("553 Invalid sender address"); 668 } 669 SuprErrs = TRUE; 670 } 671 if (from == realname || 672 parseaddr(from = newstr(realname), &e->e_from, 673 RF_COPYALL|RF_SENDERADDR, ' ', NULL, e) == NULL) 674 { 675 char nbuf[100]; 676 677 SuprErrs = TRUE; 678 expand("\201n", nbuf, sizeof nbuf, e); 679 if (parseaddr(from = newstr(nbuf), &e->e_from, 680 RF_COPYALL, ' ', NULL, e) == NULL && 681 parseaddr(from = "postmaster", &e->e_from, 682 RF_COPYALL, ' ', NULL, e) == NULL) 683 syserr("553 setsender: can't even parse postmaster!"); 684 } 685 } 686 else 687 FromFlag = TRUE; 688 e->e_from.q_flags |= QDONTSEND; 689 if (tTd(45, 5)) 690 { 691 printf("setsender: QDONTSEND "); 692 printaddr(&e->e_from, FALSE); 693 } 694 SuprErrs = FALSE; 695 696 # ifdef USERDB 697 if (bitnset(M_CHECKUDB, e->e_from.q_mailer->m_flags)) 698 { 699 register char *p; 700 extern char *udbsender(); 701 702 p = udbsender(e->e_from.q_user); 703 if (p != NULL) 704 from = p; 705 } 706 # endif /* USERDB */ 707 708 if (bitnset(M_HASPWENT, e->e_from.q_mailer->m_flags)) 709 { 710 if (!internal) 711 { 712 /* if the user already given fullname don't redefine */ 713 if (FullName == NULL) 714 FullName = macvalue('x', e); 715 if (FullName != NULL && FullName[0] == '\0') 716 FullName = NULL; 717 } 718 719 if ((pw = getpwnam(e->e_from.q_user)) != NULL) 720 { 721 /* 722 ** Process passwd file entry. 723 */ 724 725 /* extract home directory */ 726 if (strcmp(pw->pw_dir, "/") == 0) 727 e->e_from.q_home = newstr(""); 728 else 729 e->e_from.q_home = newstr(pw->pw_dir); 730 define('z', e->e_from.q_home, e); 731 732 /* extract user and group id */ 733 e->e_from.q_uid = pw->pw_uid; 734 e->e_from.q_gid = pw->pw_gid; 735 e->e_from.q_flags |= QGOODUID; 736 737 /* extract full name from passwd file */ 738 if (FullName == NULL && pw->pw_gecos != NULL && 739 strcmp(pw->pw_name, e->e_from.q_user) == 0 && 740 !internal) 741 { 742 buildfname(pw->pw_gecos, e->e_from.q_user, buf); 743 if (buf[0] != '\0') 744 FullName = newstr(buf); 745 } 746 } 747 if (FullName != NULL && !internal) 748 define('x', FullName, e); 749 } 750 else if (!internal && OpMode != MD_DAEMON) 751 { 752 if (e->e_from.q_home == NULL) 753 { 754 e->e_from.q_home = getenv("HOME"); 755 if (e->e_from.q_home != NULL && 756 strcmp(e->e_from.q_home, "/") == 0) 757 e->e_from.q_home++; 758 } 759 e->e_from.q_uid = RealUid; 760 e->e_from.q_gid = RealGid; 761 e->e_from.q_flags |= QGOODUID; 762 } 763 764 /* 765 ** Rewrite the from person to dispose of possible implicit 766 ** links in the net. 767 */ 768 769 pvp = prescan(from, delimchar, pvpbuf, sizeof pvpbuf, NULL); 770 if (pvp == NULL) 771 { 772 /* don't need to give error -- prescan did that already */ 773 # ifdef LOG 774 if (LogLevel > 2) 775 syslog(LOG_NOTICE, "cannot prescan from (%s)", from); 776 # endif 777 finis(); 778 } 779 /* 780 (void) rewrite(pvp, 3, 0, e); 781 (void) rewrite(pvp, 1, 0, e); 782 (void) rewrite(pvp, 4, 0, e); 783 */ 784 bp = buf + 1; 785 cataddr(pvp, NULL, bp, sizeof buf - 2, '\0'); 786 if (*bp == '@' && !bitnset(M_NOBRACKET, e->e_from.q_mailer->m_flags)) 787 { 788 /* heuristic: route-addr: add angle brackets */ 789 strcat(bp, ">"); 790 *--bp = '<'; 791 } 792 e->e_sender = newstr(bp); 793 define('f', e->e_sender, e); 794 795 /* save the domain spec if this mailer wants it */ 796 if (e->e_from.q_mailer != NULL && 797 bitnset(M_CANONICAL, e->e_from.q_mailer->m_flags)) 798 { 799 extern char **copyplist(); 800 801 while (*pvp != NULL && strcmp(*pvp, "@") != 0) 802 pvp++; 803 if (*pvp != NULL) 804 e->e_fromdomain = copyplist(pvp, TRUE); 805 } 806 } 807