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[] = "@(#)deliver.c 8.60 (Berkeley) 01/06/94"; 11 #endif /* not lint */ 12 13 #include "sendmail.h" 14 #include <netdb.h> 15 #include <errno.h> 16 #ifdef NAMED_BIND 17 #include <arpa/nameser.h> 18 #include <resolv.h> 19 20 extern int h_errno; 21 #endif 22 23 extern char SmtpError[]; 24 25 /* 26 ** SENDALL -- actually send all the messages. 27 ** 28 ** Parameters: 29 ** e -- the envelope to send. 30 ** mode -- the delivery mode to use. If SM_DEFAULT, use 31 ** the current e->e_sendmode. 32 ** 33 ** Returns: 34 ** none. 35 ** 36 ** Side Effects: 37 ** Scans the send lists and sends everything it finds. 38 ** Delivers any appropriate error messages. 39 ** If we are running in a non-interactive mode, takes the 40 ** appropriate action. 41 */ 42 43 sendall(e, mode) 44 ENVELOPE *e; 45 char mode; 46 { 47 register ADDRESS *q; 48 char *owner; 49 int otherowners; 50 register ENVELOPE *ee; 51 ENVELOPE *splitenv = NULL; 52 bool announcequeueup; 53 54 /* 55 ** If we have had global, fatal errors, don't bother sending 56 ** the message at all if we are in SMTP mode. Local errors 57 ** (e.g., a single address failing) will still cause the other 58 ** addresses to be sent. 59 */ 60 61 if (bitset(EF_FATALERRS, e->e_flags) && OpMode == MD_SMTP) 62 { 63 e->e_flags |= EF_CLRQUEUE; 64 return; 65 } 66 67 /* determine actual delivery mode */ 68 CurrentLA = getla(); 69 if (mode == SM_DEFAULT) 70 { 71 mode = e->e_sendmode; 72 if (mode != SM_VERIFY && 73 shouldqueue(e->e_msgpriority, e->e_ctime)) 74 mode = SM_QUEUE; 75 announcequeueup = mode == SM_QUEUE; 76 } 77 else 78 announcequeueup = FALSE; 79 80 if (tTd(13, 1)) 81 { 82 printf("\n===== SENDALL: mode %c, id %s, e_from ", 83 mode, e->e_id); 84 printaddr(&e->e_from, FALSE); 85 printf("sendqueue:\n"); 86 printaddr(e->e_sendqueue, TRUE); 87 } 88 89 /* 90 ** Do any preprocessing necessary for the mode we are running. 91 ** Check to make sure the hop count is reasonable. 92 ** Delete sends to the sender in mailing lists. 93 */ 94 95 CurEnv = e; 96 97 if (e->e_hopcount > MaxHopCount) 98 { 99 errno = 0; 100 syserr("554 too many hops %d (%d max): from %s via %s, to %s", 101 e->e_hopcount, MaxHopCount, e->e_from.q_paddr, 102 RealHostName, e->e_sendqueue->q_paddr); 103 return; 104 } 105 106 /* 107 ** Do sender deletion. 108 ** 109 ** If the sender has the QQUEUEUP flag set, skip this. 110 ** This can happen if the name server is hosed when you 111 ** are trying to send mail. The result is that the sender 112 ** is instantiated in the queue as a recipient. 113 */ 114 115 if (!bitset(EF_METOO, e->e_flags) && 116 !bitset(QQUEUEUP, e->e_from.q_flags)) 117 { 118 if (tTd(13, 5)) 119 { 120 printf("sendall: QDONTSEND "); 121 printaddr(&e->e_from, FALSE); 122 } 123 e->e_from.q_flags |= QDONTSEND; 124 (void) recipient(&e->e_from, &e->e_sendqueue, e); 125 } 126 127 /* 128 ** Handle alias owners. 129 ** 130 ** We scan up the q_alias chain looking for owners. 131 ** We discard owners that are the same as the return path. 132 */ 133 134 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 135 { 136 register struct address *a; 137 138 for (a = q; a != NULL && a->q_owner == NULL; a = a->q_alias) 139 continue; 140 if (a != NULL) 141 q->q_owner = a->q_owner; 142 143 if (q->q_owner != NULL && 144 !bitset(QDONTSEND, q->q_flags) && 145 strcmp(q->q_owner, e->e_from.q_paddr) == 0) 146 q->q_owner = NULL; 147 } 148 149 owner = ""; 150 otherowners = 1; 151 while (owner != NULL && otherowners > 0) 152 { 153 owner = NULL; 154 otherowners = 0; 155 156 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 157 { 158 if (bitset(QDONTSEND, q->q_flags)) 159 continue; 160 161 if (q->q_owner != NULL) 162 { 163 if (owner == NULL) 164 owner = q->q_owner; 165 else if (owner != q->q_owner) 166 { 167 if (strcmp(owner, q->q_owner) == 0) 168 { 169 /* make future comparisons cheap */ 170 q->q_owner = owner; 171 } 172 else 173 { 174 otherowners++; 175 } 176 owner = q->q_owner; 177 } 178 } 179 else 180 { 181 otherowners++; 182 } 183 } 184 185 if (owner != NULL && otherowners > 0) 186 { 187 extern HDR *copyheader(); 188 extern ADDRESS *copyqueue(); 189 190 /* 191 ** Split this envelope into two. 192 */ 193 194 ee = (ENVELOPE *) xalloc(sizeof(ENVELOPE)); 195 *ee = *e; 196 ee->e_id = NULL; 197 (void) queuename(ee, '\0'); 198 199 if (tTd(13, 1)) 200 printf("sendall: split %s into %s\n", 201 e->e_id, ee->e_id); 202 203 ee->e_header = copyheader(e->e_header); 204 ee->e_sendqueue = copyqueue(e->e_sendqueue); 205 ee->e_errorqueue = copyqueue(e->e_errorqueue); 206 ee->e_flags = e->e_flags & ~(EF_INQUEUE|EF_CLRQUEUE|EF_FATALERRS); 207 setsender(owner, ee, NULL, TRUE); 208 if (tTd(13, 5)) 209 { 210 printf("sendall(split): QDONTSEND "); 211 printaddr(&ee->e_from, FALSE); 212 } 213 ee->e_from.q_flags |= QDONTSEND; 214 ee->e_dfp = NULL; 215 ee->e_xfp = NULL; 216 ee->e_df = NULL; 217 ee->e_errormode = EM_MAIL; 218 ee->e_sibling = splitenv; 219 splitenv = ee; 220 221 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 222 if (q->q_owner == owner) 223 q->q_flags |= QDONTSEND; 224 for (q = ee->e_sendqueue; q != NULL; q = q->q_next) 225 if (q->q_owner != owner) 226 q->q_flags |= QDONTSEND; 227 228 if (e->e_df != NULL && mode != SM_VERIFY) 229 { 230 ee->e_dfp = NULL; 231 ee->e_df = queuename(ee, 'd'); 232 ee->e_df = newstr(ee->e_df); 233 if (link(e->e_df, ee->e_df) < 0) 234 { 235 syserr("sendall: link(%s, %s)", 236 e->e_df, ee->e_df); 237 } 238 } 239 240 if (mode != SM_VERIFY) 241 openxscript(ee); 242 #ifdef LOG 243 if (LogLevel > 4) 244 syslog(LOG_INFO, "%s: clone %s", 245 ee->e_id, e->e_id); 246 #endif 247 } 248 } 249 250 if (owner != NULL) 251 { 252 setsender(owner, e, NULL, TRUE); 253 if (tTd(13, 5)) 254 { 255 printf("sendall(owner): QDONTSEND "); 256 printaddr(&e->e_from, FALSE); 257 } 258 e->e_from.q_flags |= QDONTSEND; 259 e->e_errormode = EM_MAIL; 260 } 261 262 # ifdef QUEUE 263 if ((mode == SM_QUEUE || mode == SM_FORK || 264 (mode != SM_VERIFY && SuperSafe)) && 265 !bitset(EF_INQUEUE, e->e_flags)) 266 { 267 /* be sure everything is instantiated in the queue */ 268 queueup(e, TRUE, announcequeueup); 269 for (ee = splitenv; ee != NULL; ee = ee->e_sibling) 270 queueup(ee, TRUE, announcequeueup); 271 } 272 #endif /* QUEUE */ 273 274 if (splitenv != NULL) 275 { 276 if (tTd(13, 1)) 277 { 278 printf("\nsendall: Split queue; remaining queue:\n"); 279 printaddr(e->e_sendqueue, TRUE); 280 } 281 282 for (ee = splitenv; ee != NULL; ee = ee->e_sibling) 283 { 284 CurEnv = ee; 285 sendenvelope(ee, mode); 286 } 287 288 CurEnv = e; 289 } 290 sendenvelope(e, mode); 291 292 for (; splitenv != NULL; splitenv = splitenv->e_sibling) 293 dropenvelope(splitenv); 294 } 295 296 sendenvelope(e, mode) 297 register ENVELOPE *e; 298 char mode; 299 { 300 bool oldverbose; 301 int pid; 302 register ADDRESS *q; 303 char *qf; 304 char *id; 305 306 /* 307 ** If we have had global, fatal errors, don't bother sending 308 ** the message at all if we are in SMTP mode. Local errors 309 ** (e.g., a single address failing) will still cause the other 310 ** addresses to be sent. 311 */ 312 313 if (bitset(EF_FATALERRS, e->e_flags) && OpMode == MD_SMTP) 314 { 315 e->e_flags |= EF_CLRQUEUE; 316 return; 317 } 318 319 oldverbose = Verbose; 320 switch (mode) 321 { 322 case SM_VERIFY: 323 Verbose = TRUE; 324 break; 325 326 case SM_QUEUE: 327 queueonly: 328 e->e_flags |= EF_INQUEUE|EF_KEEPQUEUE; 329 return; 330 331 case SM_FORK: 332 if (e->e_xfp != NULL) 333 (void) fflush(e->e_xfp); 334 335 # ifndef HASFLOCK 336 /* 337 ** Since fcntl locking has the interesting semantic that 338 ** the lock is owned by a process, not by an open file 339 ** descriptor, we have to flush this to the queue, and 340 ** then restart from scratch in the child. 341 */ 342 343 /* save id for future use */ 344 id = e->e_id; 345 346 /* now drop the envelope in the parent */ 347 e->e_flags |= EF_INQUEUE|EF_KEEPQUEUE; 348 dropenvelope(e); 349 350 /* and reacquire in the child */ 351 (void) dowork(id, TRUE, FALSE, e); 352 353 return; 354 355 # else /* HASFLOCK */ 356 357 pid = fork(); 358 if (pid < 0) 359 { 360 goto queueonly; 361 } 362 else if (pid > 0) 363 { 364 /* be sure we leave the temp files to our child */ 365 /* can't call unlockqueue to avoid unlink of xfp */ 366 if (e->e_lockfp != NULL) 367 (void) xfclose(e->e_lockfp, "sendenvelope", "lockfp"); 368 e->e_lockfp = NULL; 369 370 /* close any random open files in the envelope */ 371 closexscript(e); 372 if (e->e_dfp != NULL) 373 (void) xfclose(e->e_dfp, "sendenvelope", e->e_df); 374 e->e_dfp = NULL; 375 e->e_id = e->e_df = NULL; 376 return; 377 } 378 379 /* double fork to avoid zombies */ 380 if (fork() > 0) 381 exit(EX_OK); 382 383 /* be sure we are immune from the terminal */ 384 disconnect(1, e); 385 386 /* 387 ** Close any cached connections. 388 ** 389 ** We don't send the QUIT protocol because the parent 390 ** still knows about the connection. 391 ** 392 ** This should only happen when delivering an error 393 ** message. 394 */ 395 396 mci_flush(FALSE, NULL); 397 398 # endif /* HASFLOCK */ 399 400 break; 401 } 402 403 /* 404 ** Run through the list and send everything. 405 ** 406 ** Set EF_GLOBALERRS so that error messages during delivery 407 ** result in returned mail. 408 */ 409 410 e->e_nsent = 0; 411 e->e_flags |= EF_GLOBALERRS; 412 413 /* now run through the queue */ 414 for (q = e->e_sendqueue; q != NULL; q = q->q_next) 415 { 416 #ifdef XDEBUG 417 char wbuf[MAXNAME + 20]; 418 419 (void) sprintf(wbuf, "sendall(%s)", q->q_paddr); 420 checkfd012(wbuf); 421 #endif 422 if (mode == SM_VERIFY) 423 { 424 e->e_to = q->q_paddr; 425 if (!bitset(QDONTSEND|QBADADDR, q->q_flags)) 426 { 427 if (q->q_host != NULL && q->q_host[0] != '\0') 428 message("deliverable: mailer %s, host %s, user %s", 429 q->q_mailer->m_name, 430 q->q_host, 431 q->q_user); 432 else 433 message("deliverable: mailer %s, user %s", 434 q->q_mailer->m_name, 435 q->q_user); 436 } 437 } 438 else if (!bitset(QDONTSEND|QBADADDR, q->q_flags)) 439 { 440 # ifdef QUEUE 441 /* 442 ** Checkpoint the send list every few addresses 443 */ 444 445 if (e->e_nsent >= CheckpointInterval) 446 { 447 queueup(e, TRUE, FALSE); 448 e->e_nsent = 0; 449 } 450 # endif /* QUEUE */ 451 (void) deliver(e, q); 452 } 453 } 454 Verbose = oldverbose; 455 456 #ifdef XDEBUG 457 checkfd012("end of sendenvelope"); 458 #endif 459 460 if (mode == SM_FORK) 461 finis(); 462 } 463 /* 464 ** DOFORK -- do a fork, retrying a couple of times on failure. 465 ** 466 ** This MUST be a macro, since after a vfork we are running 467 ** two processes on the same stack!!! 468 ** 469 ** Parameters: 470 ** none. 471 ** 472 ** Returns: 473 ** From a macro??? You've got to be kidding! 474 ** 475 ** Side Effects: 476 ** Modifies the ==> LOCAL <== variable 'pid', leaving: 477 ** pid of child in parent, zero in child. 478 ** -1 on unrecoverable error. 479 ** 480 ** Notes: 481 ** I'm awfully sorry this looks so awful. That's 482 ** vfork for you..... 483 */ 484 485 # define NFORKTRIES 5 486 487 # ifndef FORK 488 # define FORK fork 489 # endif 490 491 # define DOFORK(fORKfN) \ 492 {\ 493 register int i;\ 494 \ 495 for (i = NFORKTRIES; --i >= 0; )\ 496 {\ 497 pid = fORKfN();\ 498 if (pid >= 0)\ 499 break;\ 500 if (i > 0)\ 501 sleep((unsigned) NFORKTRIES - i);\ 502 }\ 503 } 504 /* 505 ** DOFORK -- simple fork interface to DOFORK. 506 ** 507 ** Parameters: 508 ** none. 509 ** 510 ** Returns: 511 ** pid of child in parent. 512 ** zero in child. 513 ** -1 on error. 514 ** 515 ** Side Effects: 516 ** returns twice, once in parent and once in child. 517 */ 518 519 dofork() 520 { 521 register int pid; 522 523 DOFORK(fork); 524 return (pid); 525 } 526 /* 527 ** DELIVER -- Deliver a message to a list of addresses. 528 ** 529 ** This routine delivers to everyone on the same host as the 530 ** user on the head of the list. It is clever about mailers 531 ** that don't handle multiple users. It is NOT guaranteed 532 ** that it will deliver to all these addresses however -- so 533 ** deliver should be called once for each address on the 534 ** list. 535 ** 536 ** Parameters: 537 ** e -- the envelope to deliver. 538 ** firstto -- head of the address list to deliver to. 539 ** 540 ** Returns: 541 ** zero -- successfully delivered. 542 ** else -- some failure, see ExitStat for more info. 543 ** 544 ** Side Effects: 545 ** The standard input is passed off to someone. 546 */ 547 548 deliver(e, firstto) 549 register ENVELOPE *e; 550 ADDRESS *firstto; 551 { 552 char *host; /* host being sent to */ 553 char *user; /* user being sent to */ 554 char **pvp; 555 register char **mvp; 556 register char *p; 557 register MAILER *m; /* mailer for this recipient */ 558 ADDRESS *ctladdr; 559 register MCI *mci; 560 register ADDRESS *to = firstto; 561 bool clever = FALSE; /* running user smtp to this mailer */ 562 ADDRESS *tochain = NULL; /* chain of users in this mailer call */ 563 int rcode; /* response code */ 564 char *firstsig; /* signature of firstto */ 565 int pid; 566 char *curhost; 567 int mpvect[2]; 568 int rpvect[2]; 569 char *pv[MAXPV+1]; 570 char tobuf[TOBUFSIZE]; /* text line of to people */ 571 char buf[MAXNAME]; 572 char rpathbuf[MAXNAME]; /* translated return path */ 573 extern int checkcompat(); 574 575 errno = 0; 576 if (bitset(QDONTSEND|QBADADDR|QQUEUEUP, to->q_flags)) 577 return (0); 578 579 #ifdef NAMED_BIND 580 /* unless interactive, try twice, over a minute */ 581 if (OpMode == MD_DAEMON || OpMode == MD_SMTP) { 582 _res.retrans = 30; 583 _res.retry = 2; 584 } 585 #endif 586 587 m = to->q_mailer; 588 host = to->q_host; 589 CurEnv = e; /* just in case */ 590 e->e_statmsg = NULL; 591 SmtpError[0] = '\0'; 592 593 if (tTd(10, 1)) 594 printf("\n--deliver, mailer=%d, host=`%s', first user=`%s'\n", 595 m->m_mno, host, to->q_user); 596 if (tTd(10, 100)) 597 printopenfds(FALSE); 598 599 /* 600 ** If this mailer is expensive, and if we don't want to make 601 ** connections now, just mark these addresses and return. 602 ** This is useful if we want to batch connections to 603 ** reduce load. This will cause the messages to be 604 ** queued up, and a daemon will come along to send the 605 ** messages later. 606 ** This should be on a per-mailer basis. 607 */ 608 609 if (NoConnect && bitnset(M_EXPENSIVE, m->m_flags) && !Verbose) 610 { 611 for (; to != NULL; to = to->q_next) 612 { 613 if (bitset(QDONTSEND|QBADADDR|QQUEUEUP, to->q_flags) || 614 to->q_mailer != m) 615 continue; 616 to->q_flags |= QQUEUEUP; 617 e->e_to = to->q_paddr; 618 message("queued"); 619 if (LogLevel > 8) 620 logdelivery(m, NULL, "queued", NULL, e); 621 } 622 e->e_to = NULL; 623 return (0); 624 } 625 626 /* 627 ** Do initial argv setup. 628 ** Insert the mailer name. Notice that $x expansion is 629 ** NOT done on the mailer name. Then, if the mailer has 630 ** a picky -f flag, we insert it as appropriate. This 631 ** code does not check for 'pv' overflow; this places a 632 ** manifest lower limit of 4 for MAXPV. 633 ** The from address rewrite is expected to make 634 ** the address relative to the other end. 635 */ 636 637 /* rewrite from address, using rewriting rules */ 638 rcode = EX_OK; 639 (void) strcpy(rpathbuf, remotename(e->e_from.q_paddr, m, 640 RF_SENDERADDR|RF_CANONICAL, 641 &rcode, e)); 642 define('g', rpathbuf, e); /* translated return path */ 643 define('h', host, e); /* to host */ 644 Errors = 0; 645 pvp = pv; 646 *pvp++ = m->m_argv[0]; 647 648 /* insert -f or -r flag as appropriate */ 649 if (FromFlag && (bitnset(M_FOPT, m->m_flags) || bitnset(M_ROPT, m->m_flags))) 650 { 651 if (bitnset(M_FOPT, m->m_flags)) 652 *pvp++ = "-f"; 653 else 654 *pvp++ = "-r"; 655 *pvp++ = newstr(rpathbuf); 656 } 657 658 /* 659 ** Append the other fixed parts of the argv. These run 660 ** up to the first entry containing "$u". There can only 661 ** be one of these, and there are only a few more slots 662 ** in the pv after it. 663 */ 664 665 for (mvp = m->m_argv; (p = *++mvp) != NULL; ) 666 { 667 /* can't use strchr here because of sign extension problems */ 668 while (*p != '\0') 669 { 670 if ((*p++ & 0377) == MACROEXPAND) 671 { 672 if (*p == 'u') 673 break; 674 } 675 } 676 677 if (*p != '\0') 678 break; 679 680 /* this entry is safe -- go ahead and process it */ 681 expand(*mvp, buf, &buf[sizeof buf - 1], e); 682 *pvp++ = newstr(buf); 683 if (pvp >= &pv[MAXPV - 3]) 684 { 685 syserr("554 Too many parameters to %s before $u", pv[0]); 686 return (-1); 687 } 688 } 689 690 /* 691 ** If we have no substitution for the user name in the argument 692 ** list, we know that we must supply the names otherwise -- and 693 ** SMTP is the answer!! 694 */ 695 696 if (*mvp == NULL) 697 { 698 /* running SMTP */ 699 # ifdef SMTP 700 clever = TRUE; 701 *pvp = NULL; 702 # else /* SMTP */ 703 /* oops! we don't implement SMTP */ 704 syserr("554 SMTP style mailer not implemented"); 705 return (EX_SOFTWARE); 706 # endif /* SMTP */ 707 } 708 709 /* 710 ** At this point *mvp points to the argument with $u. We 711 ** run through our address list and append all the addresses 712 ** we can. If we run out of space, do not fret! We can 713 ** always send another copy later. 714 */ 715 716 tobuf[0] = '\0'; 717 e->e_to = tobuf; 718 ctladdr = NULL; 719 firstsig = hostsignature(firstto->q_mailer, firstto->q_host, e); 720 for (; to != NULL; to = to->q_next) 721 { 722 /* avoid sending multiple recipients to dumb mailers */ 723 if (tobuf[0] != '\0' && !bitnset(M_MUSER, m->m_flags)) 724 break; 725 726 /* if already sent or not for this host, don't send */ 727 if (bitset(QDONTSEND|QBADADDR|QQUEUEUP, to->q_flags) || 728 to->q_mailer != firstto->q_mailer || 729 strcmp(hostsignature(to->q_mailer, to->q_host, e), firstsig) != 0) 730 continue; 731 732 /* avoid overflowing tobuf */ 733 if (sizeof tobuf < (strlen(to->q_paddr) + strlen(tobuf) + 2)) 734 break; 735 736 if (tTd(10, 1)) 737 { 738 printf("\nsend to "); 739 printaddr(to, FALSE); 740 } 741 742 /* compute effective uid/gid when sending */ 743 /* XXX perhaps this should be to->q_mailer != LocalMailer ?? */ 744 /* XXX perhaps it should be a mailer flag? */ 745 if (to->q_mailer == ProgMailer || to->q_mailer == FileMailer) 746 ctladdr = getctladdr(to); 747 748 user = to->q_user; 749 e->e_to = to->q_paddr; 750 if (tTd(10, 5)) 751 { 752 printf("deliver: QDONTSEND "); 753 printaddr(to, FALSE); 754 } 755 to->q_flags |= QDONTSEND; 756 757 /* 758 ** Check to see that these people are allowed to 759 ** talk to each other. 760 */ 761 762 if (m->m_maxsize != 0 && e->e_msgsize > m->m_maxsize) 763 { 764 NoReturn = TRUE; 765 usrerr("552 Message is too large; %ld bytes max", m->m_maxsize); 766 giveresponse(EX_UNAVAILABLE, m, NULL, ctladdr, e); 767 continue; 768 } 769 rcode = checkcompat(to, e); 770 if (rcode != EX_OK) 771 { 772 markfailure(e, to, rcode); 773 giveresponse(rcode, m, NULL, ctladdr, e); 774 continue; 775 } 776 777 /* 778 ** Strip quote bits from names if the mailer is dumb 779 ** about them. 780 */ 781 782 if (bitnset(M_STRIPQ, m->m_flags)) 783 { 784 stripquotes(user); 785 stripquotes(host); 786 } 787 788 /* hack attack -- delivermail compatibility */ 789 if (m == ProgMailer && *user == '|') 790 user++; 791 792 /* 793 ** If an error message has already been given, don't 794 ** bother to send to this address. 795 ** 796 ** >>>>>>>>>> This clause assumes that the local mailer 797 ** >> NOTE >> cannot do any further aliasing; that 798 ** >>>>>>>>>> function is subsumed by sendmail. 799 */ 800 801 if (bitset(QBADADDR|QQUEUEUP, to->q_flags)) 802 continue; 803 804 /* save statistics.... */ 805 markstats(e, to); 806 807 /* 808 ** See if this user name is "special". 809 ** If the user name has a slash in it, assume that this 810 ** is a file -- send it off without further ado. Note 811 ** that this type of addresses is not processed along 812 ** with the others, so we fudge on the To person. 813 */ 814 815 if (m == FileMailer) 816 { 817 rcode = mailfile(user, ctladdr, e); 818 giveresponse(rcode, m, NULL, ctladdr, e); 819 if (rcode == EX_OK) 820 to->q_flags |= QSENT; 821 continue; 822 } 823 824 /* 825 ** Address is verified -- add this user to mailer 826 ** argv, and add it to the print list of recipients. 827 */ 828 829 /* link together the chain of recipients */ 830 to->q_tchain = tochain; 831 tochain = to; 832 833 /* create list of users for error messages */ 834 (void) strcat(tobuf, ","); 835 (void) strcat(tobuf, to->q_paddr); 836 define('u', user, e); /* to user */ 837 p = to->q_home; 838 if (p == NULL && ctladdr != NULL) 839 p = ctladdr->q_home; 840 define('z', p, e); /* user's home */ 841 842 /* 843 ** Expand out this user into argument list. 844 */ 845 846 if (!clever) 847 { 848 expand(*mvp, buf, &buf[sizeof buf - 1], e); 849 *pvp++ = newstr(buf); 850 if (pvp >= &pv[MAXPV - 2]) 851 { 852 /* allow some space for trailing parms */ 853 break; 854 } 855 } 856 } 857 858 /* see if any addresses still exist */ 859 if (tobuf[0] == '\0') 860 { 861 define('g', (char *) NULL, e); 862 return (0); 863 } 864 865 /* print out messages as full list */ 866 e->e_to = tobuf + 1; 867 868 /* 869 ** Fill out any parameters after the $u parameter. 870 */ 871 872 while (!clever && *++mvp != NULL) 873 { 874 expand(*mvp, buf, &buf[sizeof buf - 1], e); 875 *pvp++ = newstr(buf); 876 if (pvp >= &pv[MAXPV]) 877 syserr("554 deliver: pv overflow after $u for %s", pv[0]); 878 } 879 *pvp++ = NULL; 880 881 /* 882 ** Call the mailer. 883 ** The argument vector gets built, pipes 884 ** are created as necessary, and we fork & exec as 885 ** appropriate. 886 ** If we are running SMTP, we just need to clean up. 887 */ 888 889 /*XXX this seems a bit wierd */ 890 if (ctladdr == NULL && bitset(QGOODUID, e->e_from.q_flags)) 891 ctladdr = &e->e_from; 892 893 #ifdef NAMED_BIND 894 if (ConfigLevel < 2) 895 _res.options &= ~(RES_DEFNAMES | RES_DNSRCH); /* XXX */ 896 #endif 897 898 if (tTd(11, 1)) 899 { 900 printf("openmailer:"); 901 printav(pv); 902 } 903 errno = 0; 904 905 CurHostName = m->m_mailer; 906 907 /* 908 ** Deal with the special case of mail handled through an IPC 909 ** connection. 910 ** In this case we don't actually fork. We must be 911 ** running SMTP for this to work. We will return a 912 ** zero pid to indicate that we are running IPC. 913 ** We also handle a debug version that just talks to stdin/out. 914 */ 915 916 curhost = NULL; 917 SmtpPhase = NULL; 918 mci = NULL; 919 920 #ifdef XDEBUG 921 { 922 char wbuf[MAXLINE]; 923 924 /* make absolutely certain 0, 1, and 2 are in use */ 925 sprintf(wbuf, "%s... openmailer(%s)", e->e_to, m->m_name); 926 checkfd012(wbuf); 927 } 928 #endif 929 930 /* check for Local Person Communication -- not for mortals!!! */ 931 if (strcmp(m->m_mailer, "[LPC]") == 0) 932 { 933 mci = (MCI *) xalloc(sizeof *mci); 934 bzero((char *) mci, sizeof *mci); 935 mci->mci_in = stdin; 936 mci->mci_out = stdout; 937 mci->mci_state = clever ? MCIS_OPENING : MCIS_OPEN; 938 mci->mci_mailer = m; 939 } 940 else if (strcmp(m->m_mailer, "[IPC]") == 0 || 941 strcmp(m->m_mailer, "[TCP]") == 0) 942 { 943 #ifdef DAEMON 944 register int i; 945 register u_short port; 946 947 if (pv[0] == NULL || pv[1] == NULL || pv[1][0] == '\0') 948 { 949 syserr("null host name for %s mailer", m->m_mailer); 950 rcode = EX_CONFIG; 951 goto give_up; 952 } 953 954 CurHostName = pv[1]; 955 curhost = hostsignature(m, pv[1], e); 956 957 if (curhost == NULL || curhost[0] == '\0') 958 { 959 syserr("null host signature for %s", pv[1]); 960 rcode = EX_OSERR; 961 goto give_up; 962 } 963 964 if (!clever) 965 { 966 syserr("554 non-clever IPC"); 967 rcode = EX_CONFIG; 968 goto give_up; 969 } 970 if (pv[2] != NULL) 971 port = atoi(pv[2]); 972 else 973 port = 0; 974 tryhost: 975 while (*curhost != '\0') 976 { 977 register char *p; 978 static char hostbuf[MAXNAME]; 979 980 /* pull the next host from the signature */ 981 p = strchr(curhost, ':'); 982 if (p == NULL) 983 p = &curhost[strlen(curhost)]; 984 if (p == curhost) 985 { 986 syserr("deliver: null host name in signature"); 987 curhost++; 988 continue; 989 } 990 strncpy(hostbuf, curhost, p - curhost); 991 hostbuf[p - curhost] = '\0'; 992 if (*p != '\0') 993 p++; 994 curhost = p; 995 996 /* see if we already know that this host is fried */ 997 CurHostName = hostbuf; 998 mci = mci_get(hostbuf, m); 999 if (mci->mci_state != MCIS_CLOSED) 1000 { 1001 if (tTd(11, 1)) 1002 { 1003 printf("openmailer: "); 1004 mci_dump(mci, FALSE); 1005 } 1006 CurHostName = mci->mci_host; 1007 break; 1008 } 1009 mci->mci_mailer = m; 1010 if (mci->mci_exitstat != EX_OK) 1011 continue; 1012 1013 /* try the connection */ 1014 setproctitle("%s %s: %s", e->e_id, hostbuf, "user open"); 1015 message("Connecting to %s (%s)...", 1016 hostbuf, m->m_name); 1017 i = makeconnection(hostbuf, port, mci, 1018 bitnset(M_SECURE_PORT, m->m_flags)); 1019 mci->mci_exitstat = i; 1020 mci->mci_errno = errno; 1021 #ifdef NAMED_BIND 1022 mci->mci_herrno = h_errno; 1023 #endif 1024 if (i == EX_OK) 1025 { 1026 mci->mci_state = MCIS_OPENING; 1027 mci_cache(mci); 1028 if (TrafficLogFile != NULL) 1029 fprintf(TrafficLogFile, "%05d == CONNECT %s\n", 1030 getpid(), hostbuf); 1031 break; 1032 } 1033 else if (tTd(11, 1)) 1034 printf("openmailer: makeconnection => stat=%d, errno=%d\n", 1035 i, errno); 1036 1037 /* enter status of this host */ 1038 setstat(i); 1039 1040 /* should print some message here for -v mode */ 1041 } 1042 if (mci == NULL) 1043 { 1044 syserr("deliver: no host name"); 1045 rcode = EX_OSERR; 1046 goto give_up; 1047 } 1048 mci->mci_pid = 0; 1049 #else /* no DAEMON */ 1050 syserr("554 openmailer: no IPC"); 1051 if (tTd(11, 1)) 1052 printf("openmailer: NULL\n"); 1053 rcode = EX_UNAVAILABLE; 1054 goto give_up; 1055 #endif /* DAEMON */ 1056 } 1057 else 1058 { 1059 if (TrafficLogFile != NULL) 1060 { 1061 char **av; 1062 1063 fprintf(TrafficLogFile, "%05d === EXEC", getpid()); 1064 for (av = pv; *av != NULL; av++) 1065 fprintf(TrafficLogFile, " %s", *av); 1066 fprintf(TrafficLogFile, "\n"); 1067 } 1068 1069 /* create a pipe to shove the mail through */ 1070 if (pipe(mpvect) < 0) 1071 { 1072 syserr("%s... openmailer(%s): pipe (to mailer)", 1073 e->e_to, m->m_name); 1074 if (tTd(11, 1)) 1075 printf("openmailer: NULL\n"); 1076 rcode = EX_OSERR; 1077 goto give_up; 1078 } 1079 1080 /* if this mailer speaks smtp, create a return pipe */ 1081 if (clever && pipe(rpvect) < 0) 1082 { 1083 syserr("%s... openmailer(%s): pipe (from mailer)", 1084 e->e_to, m->m_name); 1085 (void) close(mpvect[0]); 1086 (void) close(mpvect[1]); 1087 if (tTd(11, 1)) 1088 printf("openmailer: NULL\n"); 1089 rcode = EX_OSERR; 1090 goto give_up; 1091 } 1092 1093 /* 1094 ** Actually fork the mailer process. 1095 ** DOFORK is clever about retrying. 1096 ** 1097 ** Dispose of SIGCHLD signal catchers that may be laying 1098 ** around so that endmail will get it. 1099 */ 1100 1101 if (e->e_xfp != NULL) 1102 (void) fflush(e->e_xfp); /* for debugging */ 1103 (void) fflush(stdout); 1104 # ifdef SIGCHLD 1105 (void) setsignal(SIGCHLD, SIG_DFL); 1106 # endif /* SIGCHLD */ 1107 DOFORK(FORK); 1108 /* pid is set by DOFORK */ 1109 if (pid < 0) 1110 { 1111 /* failure */ 1112 syserr("%s... openmailer(%s): cannot fork", 1113 e->e_to, m->m_name); 1114 (void) close(mpvect[0]); 1115 (void) close(mpvect[1]); 1116 if (clever) 1117 { 1118 (void) close(rpvect[0]); 1119 (void) close(rpvect[1]); 1120 } 1121 if (tTd(11, 1)) 1122 printf("openmailer: NULL\n"); 1123 rcode = EX_OSERR; 1124 goto give_up; 1125 } 1126 else if (pid == 0) 1127 { 1128 int i; 1129 int saveerrno; 1130 char **ep; 1131 char *env[MAXUSERENVIRON]; 1132 extern char **environ; 1133 extern int DtableSize; 1134 1135 /* child -- set up input & exec mailer */ 1136 (void) setsignal(SIGINT, SIG_IGN); 1137 (void) setsignal(SIGHUP, SIG_IGN); 1138 (void) setsignal(SIGTERM, SIG_DFL); 1139 1140 /* reset user and group */ 1141 if (!bitnset(M_RESTR, m->m_flags)) 1142 { 1143 if (ctladdr == NULL || ctladdr->q_uid == 0) 1144 { 1145 (void) initgroups(DefUser, DefGid); 1146 (void) setgid(DefGid); 1147 (void) setuid(DefUid); 1148 } 1149 else 1150 { 1151 (void) initgroups(ctladdr->q_ruser? 1152 ctladdr->q_ruser: ctladdr->q_user, 1153 ctladdr->q_gid); 1154 (void) setgid(ctladdr->q_gid); 1155 (void) setuid(ctladdr->q_uid); 1156 } 1157 } 1158 1159 if (tTd(11, 2)) 1160 printf("openmailer: running as r/euid=%d/%d\n", 1161 getuid(), geteuid()); 1162 1163 /* move into some "safe" directory */ 1164 if (m->m_execdir != NULL) 1165 { 1166 char *p, *q; 1167 char buf[MAXLINE]; 1168 1169 for (p = m->m_execdir; p != NULL; p = q) 1170 { 1171 q = strchr(p, ':'); 1172 if (q != NULL) 1173 *q = '\0'; 1174 expand(p, buf, &buf[sizeof buf] - 1, e); 1175 if (q != NULL) 1176 *q++ = ':'; 1177 if (tTd(11, 20)) 1178 printf("openmailer: trydir %s\n", 1179 buf); 1180 if (buf[0] != '\0' && chdir(buf) >= 0) 1181 break; 1182 } 1183 } 1184 1185 /* arrange to filter std & diag output of command */ 1186 if (clever) 1187 { 1188 (void) close(rpvect[0]); 1189 if (dup2(rpvect[1], STDOUT_FILENO) < 0) 1190 { 1191 syserr("%s... openmailer(%s): cannot dup pipe %d for stdout", 1192 e->e_to, m->m_name, rpvect[1]); 1193 _exit(EX_OSERR); 1194 } 1195 (void) close(rpvect[1]); 1196 } 1197 else if (OpMode == MD_SMTP || HoldErrs) 1198 { 1199 /* put mailer output in transcript */ 1200 if (dup2(fileno(e->e_xfp), STDOUT_FILENO) < 0) 1201 { 1202 syserr("%s... openmailer(%s): cannot dup xscript %d for stdout", 1203 e->e_to, m->m_name, 1204 fileno(e->e_xfp)); 1205 _exit(EX_OSERR); 1206 } 1207 } 1208 if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) 1209 { 1210 syserr("%s... openmailer(%s): cannot dup stdout for stderr", 1211 e->e_to, m->m_name); 1212 _exit(EX_OSERR); 1213 } 1214 1215 /* arrange to get standard input */ 1216 (void) close(mpvect[1]); 1217 if (dup2(mpvect[0], STDIN_FILENO) < 0) 1218 { 1219 syserr("%s... openmailer(%s): cannot dup pipe %d for stdin", 1220 e->e_to, m->m_name, mpvect[0]); 1221 _exit(EX_OSERR); 1222 } 1223 (void) close(mpvect[0]); 1224 1225 /* arrange for all the files to be closed */ 1226 for (i = 3; i < DtableSize; i++) 1227 { 1228 register int j; 1229 1230 if ((j = fcntl(i, F_GETFD, 0)) != -1) 1231 (void) fcntl(i, F_SETFD, j | 1); 1232 } 1233 1234 /* set up the mailer environment */ 1235 i = 0; 1236 env[i++] = "AGENT=sendmail"; 1237 for (ep = environ; *ep != NULL; ep++) 1238 { 1239 if (strncmp(*ep, "TZ=", 3) == 0) 1240 env[i++] = *ep; 1241 } 1242 env[i++] = NULL; 1243 1244 /* try to execute the mailer */ 1245 execve(m->m_mailer, pv, env); 1246 saveerrno = errno; 1247 syserr("Cannot exec %s", m->m_mailer); 1248 if (m == LocalMailer || transienterror(saveerrno)) 1249 _exit(EX_OSERR); 1250 _exit(EX_UNAVAILABLE); 1251 } 1252 1253 /* 1254 ** Set up return value. 1255 */ 1256 1257 mci = (MCI *) xalloc(sizeof *mci); 1258 bzero((char *) mci, sizeof *mci); 1259 mci->mci_mailer = m; 1260 mci->mci_state = clever ? MCIS_OPENING : MCIS_OPEN; 1261 mci->mci_pid = pid; 1262 (void) close(mpvect[0]); 1263 mci->mci_out = fdopen(mpvect[1], "w"); 1264 if (mci->mci_out == NULL) 1265 { 1266 syserr("deliver: cannot create mailer output channel, fd=%d", 1267 mpvect[1]); 1268 (void) close(mpvect[1]); 1269 if (clever) 1270 { 1271 (void) close(rpvect[0]); 1272 (void) close(rpvect[1]); 1273 } 1274 rcode = EX_OSERR; 1275 goto give_up; 1276 } 1277 if (clever) 1278 { 1279 (void) close(rpvect[1]); 1280 mci->mci_in = fdopen(rpvect[0], "r"); 1281 if (mci->mci_in == NULL) 1282 { 1283 syserr("deliver: cannot create mailer input channel, fd=%d", 1284 mpvect[1]); 1285 (void) close(rpvect[0]); 1286 fclose(mci->mci_out); 1287 mci->mci_out = NULL; 1288 rcode = EX_OSERR; 1289 goto give_up; 1290 } 1291 } 1292 else 1293 { 1294 mci->mci_flags |= MCIF_TEMP; 1295 mci->mci_in = NULL; 1296 } 1297 } 1298 1299 /* 1300 ** If we are in SMTP opening state, send initial protocol. 1301 */ 1302 1303 if (clever && mci->mci_state != MCIS_CLOSED) 1304 { 1305 smtpinit(m, mci, e); 1306 } 1307 if (tTd(11, 1)) 1308 { 1309 printf("openmailer: "); 1310 mci_dump(mci, FALSE); 1311 } 1312 1313 if (mci->mci_state != MCIS_OPEN) 1314 { 1315 /* couldn't open the mailer */ 1316 rcode = mci->mci_exitstat; 1317 errno = mci->mci_errno; 1318 #ifdef NAMED_BIND 1319 h_errno = mci->mci_herrno; 1320 #endif 1321 if (rcode == EX_OK) 1322 { 1323 /* shouldn't happen */ 1324 syserr("554 deliver: rcode=%d, mci_state=%d, sig=%s", 1325 rcode, mci->mci_state, firstsig); 1326 rcode = EX_SOFTWARE; 1327 } 1328 else if (rcode == EX_TEMPFAIL && curhost != NULL && *curhost != '\0') 1329 { 1330 /* try next MX site */ 1331 goto tryhost; 1332 } 1333 } 1334 else if (!clever) 1335 { 1336 /* 1337 ** Format and send message. 1338 */ 1339 1340 putfromline(mci->mci_out, m, e); 1341 (*e->e_puthdr)(mci->mci_out, m, e); 1342 putline("\n", mci->mci_out, m); 1343 (*e->e_putbody)(mci->mci_out, m, e, NULL); 1344 1345 /* get the exit status */ 1346 rcode = endmailer(mci, e, pv); 1347 } 1348 else 1349 #ifdef SMTP 1350 { 1351 /* 1352 ** Send the MAIL FROM: protocol 1353 */ 1354 1355 rcode = smtpmailfrom(m, mci, e); 1356 if (rcode == EX_OK) 1357 { 1358 register char *t = tobuf; 1359 register int i; 1360 1361 /* send the recipient list */ 1362 tobuf[0] = '\0'; 1363 for (to = tochain; to != NULL; to = to->q_tchain) 1364 { 1365 e->e_to = to->q_paddr; 1366 if ((i = smtprcpt(to, m, mci, e)) != EX_OK) 1367 { 1368 markfailure(e, to, i); 1369 giveresponse(i, m, mci, ctladdr, e); 1370 } 1371 else 1372 { 1373 *t++ = ','; 1374 for (p = to->q_paddr; *p; *t++ = *p++) 1375 continue; 1376 *t = '\0'; 1377 } 1378 } 1379 1380 /* now send the data */ 1381 if (tobuf[0] == '\0') 1382 { 1383 rcode = EX_OK; 1384 e->e_to = NULL; 1385 if (bitset(MCIF_CACHED, mci->mci_flags)) 1386 smtprset(m, mci, e); 1387 } 1388 else 1389 { 1390 e->e_to = tobuf + 1; 1391 rcode = smtpdata(m, mci, e); 1392 } 1393 1394 /* now close the connection */ 1395 if (!bitset(MCIF_CACHED, mci->mci_flags)) 1396 smtpquit(m, mci, e); 1397 } 1398 if (rcode != EX_OK && curhost != NULL && *curhost != '\0') 1399 { 1400 /* try next MX site */ 1401 goto tryhost; 1402 } 1403 } 1404 #else /* not SMTP */ 1405 { 1406 syserr("554 deliver: need SMTP compiled to use clever mailer"); 1407 rcode = EX_CONFIG; 1408 goto give_up; 1409 } 1410 #endif /* SMTP */ 1411 #ifdef NAMED_BIND 1412 if (ConfigLevel < 2) 1413 _res.options |= RES_DEFNAMES | RES_DNSRCH; /* XXX */ 1414 #endif 1415 1416 /* arrange a return receipt if requested */ 1417 if (rcode == EX_OK && e->e_receiptto != NULL && 1418 bitnset(M_LOCALMAILER, m->m_flags)) 1419 { 1420 e->e_flags |= EF_SENDRECEIPT; 1421 /* do we want to send back more info? */ 1422 } 1423 1424 /* 1425 ** Do final status disposal. 1426 ** We check for something in tobuf for the SMTP case. 1427 ** If we got a temporary failure, arrange to queue the 1428 ** addressees. 1429 */ 1430 1431 give_up: 1432 if (tobuf[0] != '\0') 1433 giveresponse(rcode, m, mci, ctladdr, e); 1434 for (to = tochain; to != NULL; to = to->q_tchain) 1435 { 1436 if (rcode != EX_OK) 1437 markfailure(e, to, rcode); 1438 else 1439 { 1440 to->q_flags |= QSENT; 1441 e->e_nsent++; 1442 if (e->e_receiptto != NULL && 1443 bitnset(M_LOCALMAILER, m->m_flags)) 1444 { 1445 fprintf(e->e_xfp, "%s... Successfully delivered\n", 1446 to->q_paddr); 1447 } 1448 } 1449 } 1450 1451 /* 1452 ** Restore state and return. 1453 */ 1454 1455 #ifdef XDEBUG 1456 { 1457 char wbuf[MAXLINE]; 1458 1459 /* make absolutely certain 0, 1, and 2 are in use */ 1460 sprintf(wbuf, "%s... end of deliver(%s)", 1461 e->e_to == NULL ? "NO-TO-LIST" : e->e_to, 1462 m->m_name); 1463 checkfd012(wbuf); 1464 } 1465 #endif 1466 1467 errno = 0; 1468 define('g', (char *) NULL, e); 1469 return (rcode); 1470 } 1471 /* 1472 ** MARKFAILURE -- mark a failure on a specific address. 1473 ** 1474 ** Parameters: 1475 ** e -- the envelope we are sending. 1476 ** q -- the address to mark. 1477 ** rcode -- the code signifying the particular failure. 1478 ** 1479 ** Returns: 1480 ** none. 1481 ** 1482 ** Side Effects: 1483 ** marks the address (and possibly the envelope) with the 1484 ** failure so that an error will be returned or 1485 ** the message will be queued, as appropriate. 1486 */ 1487 1488 markfailure(e, q, rcode) 1489 register ENVELOPE *e; 1490 register ADDRESS *q; 1491 int rcode; 1492 { 1493 char buf[MAXLINE]; 1494 1495 switch (rcode) 1496 { 1497 case EX_OK: 1498 break; 1499 1500 case EX_TEMPFAIL: 1501 case EX_IOERR: 1502 case EX_OSERR: 1503 q->q_flags |= QQUEUEUP; 1504 break; 1505 1506 default: 1507 q->q_flags |= QBADADDR; 1508 break; 1509 } 1510 } 1511 /* 1512 ** ENDMAILER -- Wait for mailer to terminate. 1513 ** 1514 ** We should never get fatal errors (e.g., segmentation 1515 ** violation), so we report those specially. For other 1516 ** errors, we choose a status message (into statmsg), 1517 ** and if it represents an error, we print it. 1518 ** 1519 ** Parameters: 1520 ** pid -- pid of mailer. 1521 ** e -- the current envelope. 1522 ** pv -- the parameter vector that invoked the mailer 1523 ** (for error messages). 1524 ** 1525 ** Returns: 1526 ** exit code of mailer. 1527 ** 1528 ** Side Effects: 1529 ** none. 1530 */ 1531 1532 endmailer(mci, e, pv) 1533 register MCI *mci; 1534 register ENVELOPE *e; 1535 char **pv; 1536 { 1537 int st; 1538 1539 /* close any connections */ 1540 if (mci->mci_in != NULL) 1541 (void) xfclose(mci->mci_in, mci->mci_mailer->m_name, "mci_in"); 1542 if (mci->mci_out != NULL) 1543 (void) xfclose(mci->mci_out, mci->mci_mailer->m_name, "mci_out"); 1544 mci->mci_in = mci->mci_out = NULL; 1545 mci->mci_state = MCIS_CLOSED; 1546 1547 /* in the IPC case there is nothing to wait for */ 1548 if (mci->mci_pid == 0) 1549 return (EX_OK); 1550 1551 /* wait for the mailer process to die and collect status */ 1552 st = waitfor(mci->mci_pid); 1553 if (st == -1) 1554 { 1555 syserr("endmailer %s: wait", pv[0]); 1556 return (EX_SOFTWARE); 1557 } 1558 1559 if (WIFEXITED(st)) 1560 { 1561 /* normal death -- return status */ 1562 return (WEXITSTATUS(st)); 1563 } 1564 1565 /* it died a horrid death */ 1566 syserr("451 mailer %s died with signal %o", 1567 mci->mci_mailer->m_name, st); 1568 1569 /* log the arguments */ 1570 if (pv != NULL && e->e_xfp != NULL) 1571 { 1572 register char **av; 1573 1574 fprintf(e->e_xfp, "Arguments:"); 1575 for (av = pv; *av != NULL; av++) 1576 fprintf(e->e_xfp, " %s", *av); 1577 fprintf(e->e_xfp, "\n"); 1578 } 1579 1580 ExitStat = EX_TEMPFAIL; 1581 return (EX_TEMPFAIL); 1582 } 1583 /* 1584 ** GIVERESPONSE -- Interpret an error response from a mailer 1585 ** 1586 ** Parameters: 1587 ** stat -- the status code from the mailer (high byte 1588 ** only; core dumps must have been taken care of 1589 ** already). 1590 ** m -- the mailer info for this mailer. 1591 ** mci -- the mailer connection info -- can be NULL if the 1592 ** response is given before the connection is made. 1593 ** ctladdr -- the controlling address for the recipient 1594 ** address(es). 1595 ** e -- the current envelope. 1596 ** 1597 ** Returns: 1598 ** none. 1599 ** 1600 ** Side Effects: 1601 ** Errors may be incremented. 1602 ** ExitStat may be set. 1603 */ 1604 1605 giveresponse(stat, m, mci, ctladdr, e) 1606 int stat; 1607 register MAILER *m; 1608 register MCI *mci; 1609 ADDRESS *ctladdr; 1610 ENVELOPE *e; 1611 { 1612 register const char *statmsg; 1613 extern char *SysExMsg[]; 1614 register int i; 1615 extern int N_SysEx; 1616 char buf[MAXLINE]; 1617 1618 /* 1619 ** Compute status message from code. 1620 */ 1621 1622 i = stat - EX__BASE; 1623 if (stat == 0) 1624 { 1625 statmsg = "250 Sent"; 1626 if (e->e_statmsg != NULL) 1627 { 1628 (void) sprintf(buf, "%s (%s)", statmsg, e->e_statmsg); 1629 statmsg = buf; 1630 } 1631 } 1632 else if (i < 0 || i > N_SysEx) 1633 { 1634 (void) sprintf(buf, "554 unknown mailer error %d", stat); 1635 stat = EX_UNAVAILABLE; 1636 statmsg = buf; 1637 } 1638 else if (stat == EX_TEMPFAIL) 1639 { 1640 (void) strcpy(buf, SysExMsg[i] + 1); 1641 #ifdef NAMED_BIND 1642 if (h_errno == TRY_AGAIN) 1643 statmsg = errstring(h_errno+E_DNSBASE); 1644 else 1645 #endif 1646 { 1647 if (errno != 0) 1648 statmsg = errstring(errno); 1649 else 1650 { 1651 #ifdef SMTP 1652 statmsg = SmtpError; 1653 #else /* SMTP */ 1654 statmsg = NULL; 1655 #endif /* SMTP */ 1656 } 1657 } 1658 if (statmsg != NULL && statmsg[0] != '\0') 1659 { 1660 (void) strcat(buf, ": "); 1661 (void) strcat(buf, statmsg); 1662 } 1663 statmsg = buf; 1664 } 1665 #ifdef NAMED_BIND 1666 else if (stat == EX_NOHOST && h_errno != 0) 1667 { 1668 statmsg = errstring(h_errno + E_DNSBASE); 1669 (void) sprintf(buf, "%s (%s)", SysExMsg[i], statmsg); 1670 statmsg = buf; 1671 } 1672 #endif 1673 else 1674 { 1675 statmsg = SysExMsg[i]; 1676 if (*statmsg++ == ':') 1677 { 1678 (void) sprintf(buf, "%s: %s", statmsg, errstring(errno)); 1679 statmsg = buf; 1680 } 1681 } 1682 1683 /* 1684 ** Print the message as appropriate 1685 */ 1686 1687 if (stat == EX_OK || stat == EX_TEMPFAIL) 1688 { 1689 extern char MsgBuf[]; 1690 1691 message(&statmsg[4], errstring(errno)); 1692 if (stat == EX_TEMPFAIL && e->e_xfp != NULL) 1693 fprintf(e->e_xfp, "%s\n", &MsgBuf[4]); 1694 } 1695 else 1696 { 1697 Errors++; 1698 usrerr(statmsg, errstring(errno)); 1699 } 1700 1701 /* 1702 ** Final cleanup. 1703 ** Log a record of the transaction. Compute the new 1704 ** ExitStat -- if we already had an error, stick with 1705 ** that. 1706 */ 1707 1708 if (LogLevel > ((stat == EX_TEMPFAIL) ? 8 : (stat == EX_OK) ? 7 : 6)) 1709 logdelivery(m, mci, &statmsg[4], ctladdr, e); 1710 1711 if (stat != EX_TEMPFAIL) 1712 setstat(stat); 1713 if (stat != EX_OK && (stat != EX_TEMPFAIL || e->e_message == NULL)) 1714 { 1715 if (e->e_message != NULL) 1716 free(e->e_message); 1717 e->e_message = newstr(&statmsg[4]); 1718 } 1719 errno = 0; 1720 #ifdef NAMED_BIND 1721 h_errno = 0; 1722 #endif 1723 } 1724 /* 1725 ** LOGDELIVERY -- log the delivery in the system log 1726 ** 1727 ** Care is taken to avoid logging lines that are too long, because 1728 ** some versions of syslog have an unfortunate proclivity for core 1729 ** dumping. This is a hack, to be sure, that is at best empirical. 1730 ** 1731 ** Parameters: 1732 ** m -- the mailer info. Can be NULL for initial queue. 1733 ** mci -- the mailer connection info -- can be NULL if the 1734 ** log is occuring when no connection is active. 1735 ** stat -- the message to print for the status. 1736 ** ctladdr -- the controlling address for the to list. 1737 ** e -- the current envelope. 1738 ** 1739 ** Returns: 1740 ** none 1741 ** 1742 ** Side Effects: 1743 ** none 1744 */ 1745 1746 logdelivery(m, mci, stat, ctladdr, e) 1747 MAILER *m; 1748 register MCI *mci; 1749 char *stat; 1750 ADDRESS *ctladdr; 1751 register ENVELOPE *e; 1752 { 1753 # ifdef LOG 1754 register char *bp; 1755 register char *p; 1756 int l; 1757 char buf[512]; 1758 1759 # if (SYSLOG_BUFSIZE) >= 256 1760 bp = buf; 1761 if (ctladdr != NULL) 1762 { 1763 strcpy(bp, ", ctladdr="); 1764 strcat(bp, shortenstring(ctladdr->q_paddr, 83)); 1765 bp += strlen(bp); 1766 if (bitset(QGOODUID, ctladdr->q_flags)) 1767 { 1768 (void) sprintf(bp, " (%d/%d)", 1769 ctladdr->q_uid, ctladdr->q_gid); 1770 bp += strlen(bp); 1771 } 1772 } 1773 1774 (void) sprintf(bp, ", delay=%s", pintvl(curtime() - e->e_ctime, TRUE)); 1775 bp += strlen(bp); 1776 1777 if (m != NULL) 1778 { 1779 (void) strcpy(bp, ", mailer="); 1780 (void) strcat(bp, m->m_name); 1781 bp += strlen(bp); 1782 } 1783 1784 if (mci != NULL && mci->mci_host != NULL) 1785 { 1786 # ifdef DAEMON 1787 extern SOCKADDR CurHostAddr; 1788 # endif 1789 1790 (void) strcpy(bp, ", relay="); 1791 (void) strcat(bp, mci->mci_host); 1792 1793 # ifdef DAEMON 1794 (void) strcat(bp, " ("); 1795 (void) strcat(bp, anynet_ntoa(&CurHostAddr)); 1796 (void) strcat(bp, ")"); 1797 # endif 1798 } 1799 else 1800 { 1801 char *p = macvalue('h', e); 1802 1803 if (p != NULL && p[0] != '\0') 1804 { 1805 (void) strcpy(bp, ", relay="); 1806 (void) strcat(bp, p); 1807 } 1808 } 1809 bp += strlen(bp); 1810 1811 #define STATLEN (((SYSLOG_BUFSIZE) - 100) / 4) 1812 #if (STATLEN) < 63 1813 # undef STATLEN 1814 # define STATLEN 63 1815 #endif 1816 #if (STATLEN) > 203 1817 # undef STATLEN 1818 # define STATLEN 203 1819 #endif 1820 1821 if ((bp - buf) > (sizeof buf - ((STATLEN) + 20))) 1822 { 1823 /* desperation move -- truncate data */ 1824 bp = buf + sizeof buf - ((STATLEN) + 17); 1825 strcpy(bp, "..."); 1826 bp += 3; 1827 } 1828 1829 (void) strcpy(bp, ", stat="); 1830 bp += strlen(bp); 1831 1832 (void) strcpy(bp, shortenstring(stat, (STATLEN))); 1833 1834 l = SYSLOG_BUFSIZE - 100 - strlen(buf); 1835 p = e->e_to; 1836 while (strlen(p) >= l) 1837 { 1838 register char *q = strchr(p + l, ','); 1839 1840 if (q == NULL) 1841 break; 1842 syslog(LOG_INFO, "%s: to=%.*s [more]%s", 1843 e->e_id, ++q - p, p, buf); 1844 p = q; 1845 } 1846 syslog(LOG_INFO, "%s: to=%s%s", e->e_id, p, buf); 1847 1848 # else /* we have a very short log buffer size */ 1849 1850 l = SYSLOG_BUFSIZE - 40; 1851 p = e->e_to; 1852 while (strlen(p) >= l) 1853 { 1854 register char *q = strchr(p + l, ','); 1855 1856 if (q == NULL) 1857 break; 1858 syslog(LOG_INFO, "%s: to=%.*s [more]", 1859 e->e_id, ++q - p, p); 1860 p = q; 1861 } 1862 syslog(LOG_INFO, "%s: to=%s", e->e_id, p); 1863 1864 if (ctladdr != NULL) 1865 { 1866 bp = buf; 1867 strcpy(buf, "ctladdr="); 1868 bp += strlen(buf); 1869 strcpy(bp, shortenstring(ctladdr->q_paddr, 83)); 1870 bp += strlen(buf); 1871 if (bitset(QGOODUID, ctladdr->q_flags)) 1872 { 1873 (void) sprintf(bp, " (%d/%d)", 1874 ctladdr->q_uid, ctladdr->q_gid); 1875 bp += strlen(bp); 1876 } 1877 syslog(LOG_INFO, "%s: %s", e->e_id, buf); 1878 } 1879 syslog(LOG_INFO, "%s: delay=%s", 1880 e->e_id, pintvl(curtime() - e->e_ctime, TRUE)); 1881 1882 if (m != NULL) 1883 syslog(LOG_INFO, "%s: mailer=%s", e->e_id, m->m_name); 1884 1885 if (mci != NULL && mci->mci_host != NULL) 1886 { 1887 # ifdef DAEMON 1888 extern SOCKADDR CurHostAddr; 1889 # endif 1890 1891 (void) strcpy(buf, mci->mci_host); 1892 1893 # ifdef DAEMON 1894 (void) strcat(buf, " ("); 1895 (void) strcat(buf, anynet_ntoa(&CurHostAddr)); 1896 (void) strcat(buf, ")"); 1897 # endif 1898 syslog(LOG_INFO, "%s: relay=%s", e->e_id, buf); 1899 } 1900 else 1901 { 1902 char *p = macvalue('h', e); 1903 1904 if (p != NULL && p[0] != '\0') 1905 syslog(LOG_INFO, "%s: relay=%s", e->e_id, p); 1906 } 1907 1908 syslog(LOG_INFO, "%s: stat=%s", e->e_id, shortenstring(stat, 63)); 1909 # endif /* short log buffer */ 1910 # endif /* LOG */ 1911 } 1912 /* 1913 ** PUTFROMLINE -- output a UNIX-style from line (or whatever) 1914 ** 1915 ** This can be made an arbitrary message separator by changing $l 1916 ** 1917 ** One of the ugliest hacks seen by human eyes is contained herein: 1918 ** UUCP wants those stupid "remote from <host>" lines. Why oh why 1919 ** does a well-meaning programmer such as myself have to deal with 1920 ** this kind of antique garbage???? 1921 ** 1922 ** Parameters: 1923 ** fp -- the file to output to. 1924 ** m -- the mailer describing this entry. 1925 ** 1926 ** Returns: 1927 ** none 1928 ** 1929 ** Side Effects: 1930 ** outputs some text to fp. 1931 */ 1932 1933 putfromline(fp, m, e) 1934 register FILE *fp; 1935 register MAILER *m; 1936 ENVELOPE *e; 1937 { 1938 char *template = "\201l\n"; 1939 char buf[MAXLINE]; 1940 1941 if (bitnset(M_NHDR, m->m_flags)) 1942 return; 1943 1944 # ifdef UGLYUUCP 1945 if (bitnset(M_UGLYUUCP, m->m_flags)) 1946 { 1947 char *bang; 1948 char xbuf[MAXLINE]; 1949 1950 expand("\201g", buf, &buf[sizeof buf - 1], e); 1951 bang = strchr(buf, '!'); 1952 if (bang == NULL) 1953 { 1954 errno = 0; 1955 syserr("554 No ! in UUCP From address! (%s given)", buf); 1956 } 1957 else 1958 { 1959 *bang++ = '\0'; 1960 (void) sprintf(xbuf, "From %s \201d remote from %s\n", bang, buf); 1961 template = xbuf; 1962 } 1963 } 1964 # endif /* UGLYUUCP */ 1965 expand(template, buf, &buf[sizeof buf - 1], e); 1966 putline(buf, fp, m); 1967 } 1968 /* 1969 ** PUTBODY -- put the body of a message. 1970 ** 1971 ** Parameters: 1972 ** fp -- file to output onto. 1973 ** m -- a mailer descriptor to control output format. 1974 ** e -- the envelope to put out. 1975 ** separator -- if non-NULL, a message separator that must 1976 ** not be permitted in the resulting message. 1977 ** 1978 ** Returns: 1979 ** none. 1980 ** 1981 ** Side Effects: 1982 ** The message is written onto fp. 1983 */ 1984 1985 putbody(fp, m, e, separator) 1986 FILE *fp; 1987 MAILER *m; 1988 register ENVELOPE *e; 1989 char *separator; 1990 { 1991 char buf[MAXLINE]; 1992 1993 /* 1994 ** Output the body of the message 1995 */ 1996 1997 if (e->e_dfp == NULL) 1998 { 1999 if (e->e_df != NULL) 2000 { 2001 e->e_dfp = fopen(e->e_df, "r"); 2002 if (e->e_dfp == NULL) 2003 syserr("putbody: Cannot open %s for %s from %s", 2004 e->e_df, e->e_to, e->e_from.q_paddr); 2005 } 2006 else 2007 putline("<<< No Message Collected >>>", fp, m); 2008 } 2009 if (e->e_dfp != NULL) 2010 { 2011 rewind(e->e_dfp); 2012 while (!ferror(fp) && fgets(buf, sizeof buf, e->e_dfp) != NULL) 2013 { 2014 if (buf[0] == 'F' && bitnset(M_ESCFROM, m->m_flags) && 2015 strncmp(buf, "From ", 5) == 0) 2016 (void) putc('>', fp); 2017 if (buf[0] == '-' && buf[1] == '-' && separator != NULL) 2018 { 2019 /* possible separator */ 2020 int sl = strlen(separator); 2021 2022 if (strncmp(&buf[2], separator, sl) == 0) 2023 (void) putc(' ', fp); 2024 } 2025 putline(buf, fp, m); 2026 } 2027 2028 if (ferror(e->e_dfp)) 2029 { 2030 syserr("putbody: %s: read error", e->e_df); 2031 ExitStat = EX_IOERR; 2032 } 2033 } 2034 2035 /* some mailers want extra blank line at end of message */ 2036 if (bitnset(M_BLANKEND, m->m_flags) && buf[0] != '\0' && buf[0] != '\n') 2037 putline("", fp, m); 2038 2039 (void) fflush(fp); 2040 if (ferror(fp) && errno != EPIPE) 2041 { 2042 syserr("putbody: write error"); 2043 ExitStat = EX_IOERR; 2044 } 2045 errno = 0; 2046 } 2047 /* 2048 ** MAILFILE -- Send a message to a file. 2049 ** 2050 ** If the file has the setuid/setgid bits set, but NO execute 2051 ** bits, sendmail will try to become the owner of that file 2052 ** rather than the real user. Obviously, this only works if 2053 ** sendmail runs as root. 2054 ** 2055 ** This could be done as a subordinate mailer, except that it 2056 ** is used implicitly to save messages in ~/dead.letter. We 2057 ** view this as being sufficiently important as to include it 2058 ** here. For example, if the system is dying, we shouldn't have 2059 ** to create another process plus some pipes to save the message. 2060 ** 2061 ** Parameters: 2062 ** filename -- the name of the file to send to. 2063 ** ctladdr -- the controlling address header -- includes 2064 ** the userid/groupid to be when sending. 2065 ** 2066 ** Returns: 2067 ** The exit code associated with the operation. 2068 ** 2069 ** Side Effects: 2070 ** none. 2071 */ 2072 2073 mailfile(filename, ctladdr, e) 2074 char *filename; 2075 ADDRESS *ctladdr; 2076 register ENVELOPE *e; 2077 { 2078 register FILE *f; 2079 register int pid; 2080 int mode; 2081 2082 if (tTd(11, 1)) 2083 { 2084 printf("mailfile %s\n ctladdr=", filename); 2085 printaddr(ctladdr, FALSE); 2086 } 2087 2088 if (e->e_xfp != NULL) 2089 fflush(e->e_xfp); 2090 2091 /* 2092 ** Fork so we can change permissions here. 2093 ** Note that we MUST use fork, not vfork, because of 2094 ** the complications of calling subroutines, etc. 2095 */ 2096 2097 DOFORK(fork); 2098 2099 if (pid < 0) 2100 return (EX_OSERR); 2101 else if (pid == 0) 2102 { 2103 /* child -- actually write to file */ 2104 struct stat stb; 2105 2106 (void) setsignal(SIGINT, SIG_DFL); 2107 (void) setsignal(SIGHUP, SIG_DFL); 2108 (void) setsignal(SIGTERM, SIG_DFL); 2109 (void) umask(OldUmask); 2110 2111 if (stat(filename, &stb) < 0) 2112 stb.st_mode = FileMode; 2113 mode = stb.st_mode; 2114 2115 /* limit the errors to those actually caused in the child */ 2116 errno = 0; 2117 ExitStat = EX_OK; 2118 2119 if (bitset(0111, stb.st_mode)) 2120 exit(EX_CANTCREAT); 2121 if (ctladdr != NULL) 2122 { 2123 /* ignore setuid and setgid bits */ 2124 mode &= ~(S_ISGID|S_ISUID); 2125 } 2126 2127 /* we have to open the dfile BEFORE setuid */ 2128 if (e->e_dfp == NULL && e->e_df != NULL) 2129 { 2130 e->e_dfp = fopen(e->e_df, "r"); 2131 if (e->e_dfp == NULL) 2132 { 2133 syserr("mailfile: Cannot open %s for %s from %s", 2134 e->e_df, e->e_to, e->e_from.q_paddr); 2135 } 2136 } 2137 2138 if (!bitset(S_ISGID, mode) || setgid(stb.st_gid) < 0) 2139 { 2140 if (ctladdr == NULL || ctladdr->q_uid == 0) 2141 { 2142 (void) initgroups(DefUser, DefGid); 2143 } 2144 else 2145 { 2146 (void) initgroups(ctladdr->q_ruser ? 2147 ctladdr->q_ruser : ctladdr->q_user, 2148 ctladdr->q_gid); 2149 } 2150 } 2151 if (!bitset(S_ISUID, mode) || setuid(stb.st_uid) < 0) 2152 { 2153 if (ctladdr == NULL || ctladdr->q_uid == 0) 2154 (void) setuid(DefUid); 2155 else 2156 (void) setuid(ctladdr->q_uid); 2157 } 2158 FileName = filename; 2159 LineNumber = 0; 2160 f = dfopen(filename, O_WRONLY|O_CREAT|O_APPEND, FileMode); 2161 if (f == NULL) 2162 { 2163 message("554 cannot open: %s", errstring(errno)); 2164 exit(EX_CANTCREAT); 2165 } 2166 2167 putfromline(f, FileMailer, e); 2168 (*e->e_puthdr)(f, FileMailer, e); 2169 putline("\n", f, FileMailer); 2170 (*e->e_putbody)(f, FileMailer, e, NULL); 2171 putline("\n", f, FileMailer); 2172 if (ferror(f)) 2173 { 2174 message("451 I/O error: %s", errstring(errno)); 2175 setstat(EX_IOERR); 2176 } 2177 (void) xfclose(f, "mailfile", filename); 2178 (void) fflush(stdout); 2179 2180 /* reset ISUID & ISGID bits for paranoid systems */ 2181 (void) chmod(filename, (int) stb.st_mode); 2182 exit(ExitStat); 2183 /*NOTREACHED*/ 2184 } 2185 else 2186 { 2187 /* parent -- wait for exit status */ 2188 int st; 2189 2190 st = waitfor(pid); 2191 if (WIFEXITED(st)) 2192 return (WEXITSTATUS(st)); 2193 else 2194 { 2195 syserr("child died on signal %d", st); 2196 return (EX_UNAVAILABLE); 2197 } 2198 /*NOTREACHED*/ 2199 } 2200 } 2201 /* 2202 ** HOSTSIGNATURE -- return the "signature" for a host. 2203 ** 2204 ** The signature describes how we are going to send this -- it 2205 ** can be just the hostname (for non-Internet hosts) or can be 2206 ** an ordered list of MX hosts. 2207 ** 2208 ** Parameters: 2209 ** m -- the mailer describing this host. 2210 ** host -- the host name. 2211 ** e -- the current envelope. 2212 ** 2213 ** Returns: 2214 ** The signature for this host. 2215 ** 2216 ** Side Effects: 2217 ** Can tweak the symbol table. 2218 */ 2219 2220 char * 2221 hostsignature(m, host, e) 2222 register MAILER *m; 2223 char *host; 2224 ENVELOPE *e; 2225 { 2226 register char *p; 2227 register STAB *s; 2228 int i; 2229 int len; 2230 #ifdef NAMED_BIND 2231 int nmx; 2232 auto int rcode; 2233 char *hp; 2234 char *endp; 2235 int oldoptions; 2236 char *mxhosts[MAXMXHOSTS + 1]; 2237 #endif 2238 2239 /* 2240 ** Check to see if this uses IPC -- if not, it can't have MX records. 2241 */ 2242 2243 p = m->m_mailer; 2244 if (strcmp(p, "[IPC]") != 0 && strcmp(p, "[TCP]") != 0) 2245 { 2246 /* just an ordinary mailer */ 2247 return host; 2248 } 2249 2250 /* 2251 ** Look it up in the symbol table. 2252 */ 2253 2254 s = stab(host, ST_HOSTSIG, ST_ENTER); 2255 if (s->s_hostsig != NULL) 2256 return s->s_hostsig; 2257 2258 /* 2259 ** Not already there -- create a signature. 2260 */ 2261 2262 #ifdef NAMED_BIND 2263 if (ConfigLevel < 2) 2264 { 2265 oldoptions = _res.options; 2266 _res.options &= ~(RES_DEFNAMES | RES_DNSRCH); /* XXX */ 2267 } 2268 2269 for (hp = host; hp != NULL; hp = endp) 2270 { 2271 endp = strchr(hp, ':'); 2272 if (endp != NULL) 2273 *endp = '\0'; 2274 2275 nmx = getmxrr(hp, mxhosts, TRUE, &rcode); 2276 2277 if (nmx <= 0) 2278 { 2279 register MCI *mci; 2280 2281 /* update the connection info for this host */ 2282 mci = mci_get(hp, m); 2283 mci->mci_exitstat = rcode; 2284 mci->mci_errno = errno; 2285 #ifdef NAMED_BIND 2286 mci->mci_herrno = h_errno; 2287 #endif 2288 2289 /* and return the original host name as the signature */ 2290 nmx = 1; 2291 mxhosts[0] = hp; 2292 } 2293 2294 len = 0; 2295 for (i = 0; i < nmx; i++) 2296 { 2297 len += strlen(mxhosts[i]) + 1; 2298 } 2299 if (s->s_hostsig != NULL) 2300 len += strlen(s->s_hostsig) + 1; 2301 p = xalloc(len); 2302 if (s->s_hostsig != NULL) 2303 { 2304 (void) strcpy(p, s->s_hostsig); 2305 free(s->s_hostsig); 2306 s->s_hostsig = p; 2307 p += strlen(p); 2308 *p++ = ':'; 2309 } 2310 else 2311 s->s_hostsig = p; 2312 for (i = 0; i < nmx; i++) 2313 { 2314 if (i != 0) 2315 *p++ = ':'; 2316 strcpy(p, mxhosts[i]); 2317 p += strlen(p); 2318 } 2319 if (endp != NULL) 2320 *endp++ = ':'; 2321 } 2322 makelower(s->s_hostsig); 2323 if (ConfigLevel < 2) 2324 _res.options = oldoptions; 2325 #else 2326 /* not using BIND -- the signature is just the host name */ 2327 s->s_hostsig = host; 2328 #endif 2329 if (tTd(17, 1)) 2330 printf("hostsignature(%s) = %s\n", host, s->s_hostsig); 2331 return s->s_hostsig; 2332 } 2333