122704Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 362525Sbostic * Copyright (c) 1988, 1993 462525Sbostic * The Regents of the University of California. All rights reserved. 533729Sbostic * 642826Sbostic * %sccs.include.redist.c% 733729Sbostic */ 822704Sdist 922704Sdist #ifndef lint 10*64724Seric static char sccsid[] = "@(#)envelope.c 8.12 (Berkeley) 10/16/93"; 1133729Sbostic #endif /* not lint */ 1222704Sdist 1358332Seric #include "sendmail.h" 1436928Sbostic #include <sys/time.h> 159536Seric #include <pwd.h> 169536Seric 179536Seric /* 189536Seric ** NEWENVELOPE -- allocate a new envelope 199536Seric ** 209536Seric ** Supports inheritance. 219536Seric ** 229536Seric ** Parameters: 239536Seric ** e -- the new envelope to fill in. 2458179Seric ** parent -- the envelope to be the parent of e. 259536Seric ** 269536Seric ** Returns: 279536Seric ** e. 289536Seric ** 299536Seric ** Side Effects: 309536Seric ** none. 319536Seric */ 329536Seric 339536Seric ENVELOPE * 3458179Seric newenvelope(e, parent) 359536Seric register ENVELOPE *e; 3658179Seric register ENVELOPE *parent; 379536Seric { 389536Seric extern putheader(), putbody(); 3925611Seric extern ENVELOPE BlankEnvelope; 409536Seric 4158179Seric if (e == parent && e->e_parent != NULL) 429536Seric parent = e->e_parent; 4325611Seric clearenvelope(e, TRUE); 4424944Seric if (e == CurEnv) 4524944Seric bcopy((char *) &NullAddress, (char *) &e->e_from, sizeof e->e_from); 4624944Seric else 4724944Seric bcopy((char *) &CurEnv->e_from, (char *) &e->e_from, sizeof e->e_from); 489536Seric e->e_parent = parent; 499536Seric e->e_ctime = curtime(); 5056215Seric if (parent != NULL) 5156215Seric e->e_msgpriority = parent->e_msgsize; 529536Seric e->e_puthdr = putheader; 539536Seric e->e_putbody = putbody; 549536Seric if (CurEnv->e_xfp != NULL) 559536Seric (void) fflush(CurEnv->e_xfp); 569536Seric 579536Seric return (e); 589536Seric } 599536Seric /* 609536Seric ** DROPENVELOPE -- deallocate an envelope. 619536Seric ** 629536Seric ** Parameters: 639536Seric ** e -- the envelope to deallocate. 649536Seric ** 659536Seric ** Returns: 669536Seric ** none. 679536Seric ** 689536Seric ** Side Effects: 699536Seric ** housekeeping necessary to dispose of an envelope. 709536Seric ** Unlocks this queue file. 719536Seric */ 729536Seric 7360494Seric void 749536Seric dropenvelope(e) 759536Seric register ENVELOPE *e; 769536Seric { 779536Seric bool queueit = FALSE; 7863839Seric bool saveit = bitset(EF_FATALERRS, e->e_flags); 799536Seric register ADDRESS *q; 8057943Seric char *id = e->e_id; 8163753Seric char buf[MAXLINE]; 829536Seric 839536Seric if (tTd(50, 1)) 849536Seric { 8558680Seric printf("dropenvelope %x: id=", e); 869536Seric xputs(e->e_id); 8758680Seric printf(", flags=%o\n", e->e_flags); 8863753Seric if (tTd(50, 10)) 8963753Seric { 9063753Seric printf("sendq="); 9163753Seric printaddr(e->e_sendqueue, TRUE); 9263753Seric } 939536Seric } 9457943Seric 9558680Seric /* we must have an id to remove disk files */ 9657943Seric if (id == NULL) 9758680Seric return; 9857943Seric 999536Seric #ifdef LOG 10058020Seric if (LogLevel > 84) 1019536Seric syslog(LOG_DEBUG, "dropenvelope, id=%s, flags=%o, pid=%d", 10257943Seric id, e->e_flags, getpid()); 10356795Seric #endif /* LOG */ 1049536Seric 10563753Seric /* post statistics */ 10663753Seric poststats(StatFile); 10763753Seric 1089536Seric /* 1099536Seric ** Extract state information from dregs of send list. 1109536Seric */ 1119536Seric 1129536Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1139536Seric { 1149536Seric if (bitset(QQUEUEUP, q->q_flags)) 1159536Seric queueit = TRUE; 11663839Seric if (!bitset(QDONTSEND, q->q_flags) && 11763839Seric bitset(QBADADDR, q->q_flags)) 11863839Seric { 11963839Seric if (q->q_owner == NULL && 12063839Seric strcmp(e->e_from.q_paddr, "<>") != 0) 12163839Seric (void) sendtolist(e->e_from.q_paddr, NULL, 12263839Seric &e->e_errorqueue, e); 12363839Seric } 1249536Seric } 1259536Seric 1269536Seric /* 12763753Seric ** See if the message timed out. 12863753Seric */ 12963753Seric 13063753Seric if (!queueit) 13163753Seric /* nothing to do */ ; 13263753Seric else if (curtime() > e->e_ctime + TimeOuts.to_q_return) 13363753Seric { 13463839Seric (void) sprintf(buf, "Cannot send message for %s", 13563839Seric pintvl(TimeOuts.to_q_return, FALSE)); 13663839Seric if (e->e_message != NULL) 13763839Seric free(e->e_message); 13863839Seric e->e_message = newstr(buf); 13963839Seric message(buf); 14063839Seric e->e_flags |= EF_CLRQUEUE; 14163839Seric saveit = TRUE; 14263787Seric fprintf(e->e_xfp, "Message could not be delivered for %s\n", 14363787Seric pintvl(TimeOuts.to_q_return, FALSE)); 14463787Seric fprintf(e->e_xfp, "Message will be deleted from queue\n"); 14563787Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 14663787Seric { 14763787Seric if (bitset(QQUEUEUP, q->q_flags)) 14863787Seric q->q_flags |= QBADADDR; 14963787Seric } 15063753Seric } 15163753Seric else if (TimeOuts.to_q_warning > 0 && 15263753Seric curtime() > e->e_ctime + TimeOuts.to_q_warning) 15363753Seric { 15463753Seric if (!bitset(EF_WARNING|EF_RESPONSE, e->e_flags) && 15563753Seric e->e_class >= 0 && 15663753Seric strcmp(e->e_from.q_paddr, "<>") != 0) 15763753Seric { 15863753Seric (void) sprintf(buf, 15963753Seric "warning: cannot send message for %s", 16063753Seric pintvl(TimeOuts.to_q_warning, FALSE)); 16163753Seric if (e->e_message != NULL) 16263753Seric free(e->e_message); 16363753Seric e->e_message = newstr(buf); 16463753Seric message(buf); 16563839Seric e->e_flags |= EF_WARNING; 16663839Seric saveit = TRUE; 16763753Seric } 16863753Seric fprintf(e->e_xfp, 16963753Seric "Warning: message still undelivered after %s\n", 17063753Seric pintvl(TimeOuts.to_q_warning, FALSE)); 17163753Seric fprintf(e->e_xfp, "Will keep trying until message is %s old\n", 17263753Seric pintvl(TimeOuts.to_q_return, FALSE)); 17363787Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 17463787Seric { 17563787Seric if (bitset(QQUEUEUP, q->q_flags)) 17663787Seric q->q_flags |= QREPORT; 17763787Seric } 17863753Seric } 17963753Seric 18063753Seric /* 1819536Seric ** Send back return receipts as requested. 1829536Seric */ 1839536Seric 1849536Seric if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags)) 1859536Seric { 18610844Seric auto ADDRESS *rlist = NULL; 1879536Seric 18864284Seric (void) sendtolist(e->e_receiptto, NULLADDR, &rlist, e); 18955012Seric (void) returntosender("Return receipt", rlist, FALSE, e); 1909536Seric } 1919536Seric 1929536Seric /* 1939536Seric ** Arrange to send error messages if there are fatal errors. 1949536Seric */ 1959536Seric 19663839Seric if (saveit && e->e_errormode != EM_QUIET) 1979536Seric savemail(e); 1989536Seric 1999536Seric /* 20063849Seric ** Arrange to send warning messages to postmaster as requested. 20163849Seric */ 20263849Seric 20363849Seric if (bitset(EF_PM_NOTIFY, e->e_flags) && PostMasterCopy != NULL && 20464363Seric !bitset(EF_RESPONSE, e->e_flags) && e->e_class >= 0) 20563849Seric { 20663849Seric auto ADDRESS *rlist = NULL; 20763849Seric 20864284Seric (void) sendtolist(PostMasterCopy, NULLADDR, &rlist, e); 20963849Seric (void) returntosender(e->e_message, rlist, FALSE, e); 21063849Seric } 21163849Seric 21263849Seric /* 2139536Seric ** Instantiate or deinstantiate the queue. 2149536Seric */ 2159536Seric 2169536Seric if ((!queueit && !bitset(EF_KEEPQUEUE, e->e_flags)) || 2179536Seric bitset(EF_CLRQUEUE, e->e_flags)) 2189536Seric { 21964307Seric if (tTd(50, 1)) 22064307Seric printf("\n===== Dropping [dq]f%s =====\n\n", e->e_id); 22123497Seric if (e->e_df != NULL) 22223497Seric xunlink(e->e_df); 2239536Seric xunlink(queuename(e, 'q')); 22463839Seric 22563839Seric #ifdef LOG 22663839Seric if (LogLevel > 10) 22763839Seric syslog(LOG_INFO, "%s: done", id); 22863839Seric #endif 2299536Seric } 2309536Seric else if (queueit || !bitset(EF_INQUEUE, e->e_flags)) 23110754Seric { 23210754Seric #ifdef QUEUE 23364307Seric queueup(e, bitset(EF_KEEPQUEUE, e->e_flags), FALSE); 23456795Seric #else /* QUEUE */ 23558151Seric syserr("554 dropenvelope: queueup"); 23656795Seric #endif /* QUEUE */ 23710754Seric } 2389536Seric 2399536Seric /* now unlock the job */ 24010196Seric closexscript(e); 2419536Seric unlockqueue(e); 2429536Seric 2439536Seric /* make sure that this envelope is marked unused */ 24424944Seric if (e->e_dfp != NULL) 24558680Seric (void) xfclose(e->e_dfp, "dropenvelope", e->e_df); 24610196Seric e->e_dfp = NULL; 24758680Seric e->e_id = e->e_df = NULL; 24864401Seric #ifdef XDEBUG 24964401Seric checkfd012("dropenvelope"); 25064401Seric #endif 2519536Seric } 2529536Seric /* 2539536Seric ** CLEARENVELOPE -- clear an envelope without unlocking 2549536Seric ** 2559536Seric ** This is normally used by a child process to get a clean 2569536Seric ** envelope without disturbing the parent. 2579536Seric ** 2589536Seric ** Parameters: 2599536Seric ** e -- the envelope to clear. 26025611Seric ** fullclear - if set, the current envelope is total 26125611Seric ** garbage and should be ignored; otherwise, 26225611Seric ** release any resources it may indicate. 2639536Seric ** 2649536Seric ** Returns: 2659536Seric ** none. 2669536Seric ** 2679536Seric ** Side Effects: 2689536Seric ** Closes files associated with the envelope. 2699536Seric ** Marks the envelope as unallocated. 2709536Seric */ 2719536Seric 27260494Seric void 27325611Seric clearenvelope(e, fullclear) 2749536Seric register ENVELOPE *e; 27525611Seric bool fullclear; 2769536Seric { 27725514Seric register HDR *bh; 27825514Seric register HDR **nhp; 27925514Seric extern ENVELOPE BlankEnvelope; 28025514Seric 28125611Seric if (!fullclear) 28225611Seric { 28325611Seric /* clear out any file information */ 28425611Seric if (e->e_xfp != NULL) 28558680Seric (void) xfclose(e->e_xfp, "clearenvelope xfp", e->e_id); 28625611Seric if (e->e_dfp != NULL) 28758680Seric (void) xfclose(e->e_dfp, "clearenvelope dfp", e->e_df); 28858680Seric e->e_xfp = e->e_dfp = NULL; 28925611Seric } 2909536Seric 29124961Seric /* now clear out the data */ 29224965Seric STRUCTCOPY(BlankEnvelope, *e); 29359698Seric if (Verbose) 29459698Seric e->e_sendmode = SM_DELIVER; 29525514Seric bh = BlankEnvelope.e_header; 29625514Seric nhp = &e->e_header; 29725514Seric while (bh != NULL) 29825514Seric { 29925514Seric *nhp = (HDR *) xalloc(sizeof *bh); 30025514Seric bcopy((char *) bh, (char *) *nhp, sizeof *bh); 30125514Seric bh = bh->h_link; 30225514Seric nhp = &(*nhp)->h_link; 30325514Seric } 3049536Seric } 3059536Seric /* 3069536Seric ** INITSYS -- initialize instantiation of system 3079536Seric ** 3089536Seric ** In Daemon mode, this is done in the child. 3099536Seric ** 3109536Seric ** Parameters: 3119536Seric ** none. 3129536Seric ** 3139536Seric ** Returns: 3149536Seric ** none. 3159536Seric ** 3169536Seric ** Side Effects: 3179536Seric ** Initializes the system macros, some global variables, 3189536Seric ** etc. In particular, the current time in various 3199536Seric ** forms is set. 3209536Seric */ 3219536Seric 32260494Seric void 32355012Seric initsys(e) 32455012Seric register ENVELOPE *e; 3259536Seric { 3269536Seric static char cbuf[5]; /* holds hop count */ 3279536Seric static char pbuf[10]; /* holds pid */ 32822963Smiriam #ifdef TTYNAME 32959304Seric static char ybuf[60]; /* holds tty id */ 3309536Seric register char *p; 33156795Seric #endif /* TTYNAME */ 3329536Seric extern char *ttyname(); 33360494Seric extern void settime(); 3349536Seric extern char Version[]; 3359536Seric 3369536Seric /* 3379536Seric ** Give this envelope a reality. 3389536Seric ** I.e., an id, a transcript, and a creation time. 3399536Seric */ 3409536Seric 34155012Seric openxscript(e); 34255012Seric e->e_ctime = curtime(); 3439536Seric 3449536Seric /* 3459536Seric ** Set OutChannel to something useful if stdout isn't it. 3469536Seric ** This arranges that any extra stuff the mailer produces 3479536Seric ** gets sent back to the user on error (because it is 3489536Seric ** tucked away in the transcript). 3499536Seric */ 3509536Seric 35158737Seric if (OpMode == MD_DAEMON && !bitset(EF_QUEUERUN, e->e_flags) && 35258737Seric e->e_xfp != NULL) 35355012Seric OutChannel = e->e_xfp; 3549536Seric 3559536Seric /* 3569536Seric ** Set up some basic system macros. 3579536Seric */ 3589536Seric 3599536Seric /* process id */ 3609536Seric (void) sprintf(pbuf, "%d", getpid()); 36155012Seric define('p', pbuf, e); 3629536Seric 3639536Seric /* hop count */ 36455012Seric (void) sprintf(cbuf, "%d", e->e_hopcount); 36555012Seric define('c', cbuf, e); 3669536Seric 3679536Seric /* time as integer, unix time, arpa time */ 36855012Seric settime(e); 3699536Seric 37017472Seric #ifdef TTYNAME 3719536Seric /* tty name */ 37255012Seric if (macvalue('y', e) == NULL) 3739536Seric { 3749536Seric p = ttyname(2); 3759536Seric if (p != NULL) 3769536Seric { 37756795Seric if (strrchr(p, '/') != NULL) 37856795Seric p = strrchr(p, '/') + 1; 3799536Seric (void) strcpy(ybuf, p); 38055012Seric define('y', ybuf, e); 3819536Seric } 3829536Seric } 38356795Seric #endif /* TTYNAME */ 3849536Seric } 3859536Seric /* 38611932Seric ** SETTIME -- set the current time. 38711932Seric ** 38811932Seric ** Parameters: 38911932Seric ** none. 39011932Seric ** 39111932Seric ** Returns: 39211932Seric ** none. 39311932Seric ** 39411932Seric ** Side Effects: 39511932Seric ** Sets the various time macros -- $a, $b, $d, $t. 39611932Seric */ 39711932Seric 39860494Seric void 39955012Seric settime(e) 40055012Seric register ENVELOPE *e; 40111932Seric { 40211932Seric register char *p; 40311932Seric auto time_t now; 40411932Seric static char tbuf[20]; /* holds "current" time */ 40511932Seric static char dbuf[30]; /* holds ctime(tbuf) */ 40611932Seric register struct tm *tm; 40711932Seric extern char *arpadate(); 40811932Seric extern struct tm *gmtime(); 40911932Seric 41011932Seric now = curtime(); 41111932Seric tm = gmtime(&now); 41257014Seric (void) sprintf(tbuf, "%04d%02d%02d%02d%02d", tm->tm_year + 1900, 41357014Seric tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min); 41455012Seric define('t', tbuf, e); 41511932Seric (void) strcpy(dbuf, ctime(&now)); 41658131Seric p = strchr(dbuf, '\n'); 41758131Seric if (p != NULL) 41858131Seric *p = '\0'; 41958131Seric define('d', dbuf, e); 42064086Seric p = arpadate(dbuf); 42164086Seric p = newstr(p); 42255012Seric if (macvalue('a', e) == NULL) 42355012Seric define('a', p, e); 42455012Seric define('b', p, e); 42511932Seric } 42611932Seric /* 4279536Seric ** OPENXSCRIPT -- Open transcript file 4289536Seric ** 4299536Seric ** Creates a transcript file for possible eventual mailing or 4309536Seric ** sending back. 4319536Seric ** 4329536Seric ** Parameters: 4339536Seric ** e -- the envelope to create the transcript in/for. 4349536Seric ** 4359536Seric ** Returns: 4369536Seric ** none 4379536Seric ** 4389536Seric ** Side Effects: 4399536Seric ** Creates the transcript file. 4409536Seric */ 4419536Seric 44258803Seric #ifndef O_APPEND 44358803Seric #define O_APPEND 0 44458803Seric #endif 44558803Seric 44660494Seric void 4479536Seric openxscript(e) 4489536Seric register ENVELOPE *e; 4499536Seric { 4509536Seric register char *p; 45140933Srick int fd; 4529536Seric 4539536Seric if (e->e_xfp != NULL) 4549536Seric return; 4559536Seric p = queuename(e, 'x'); 45658803Seric fd = open(p, O_WRONLY|O_CREAT|O_APPEND, 0644); 45740933Srick if (fd < 0) 45863753Seric { 45963753Seric syserr("Can't create transcript file %s", p); 46063753Seric fd = open("/dev/null", O_WRONLY, 0644); 46163753Seric if (fd < 0) 46263753Seric syserr("!Can't open /dev/null"); 46363753Seric } 46463753Seric e->e_xfp = fdopen(fd, "w"); 465*64724Seric if (e->e_xfp == NULL) 466*64724Seric { 467*64724Seric syserr("!Can't create transcript stream %s", p); 468*64724Seric } 4699536Seric } 4709536Seric /* 47110196Seric ** CLOSEXSCRIPT -- close the transcript file. 47210196Seric ** 47310196Seric ** Parameters: 47410196Seric ** e -- the envelope containing the transcript to close. 47510196Seric ** 47610196Seric ** Returns: 47710196Seric ** none. 47810196Seric ** 47910196Seric ** Side Effects: 48010196Seric ** none. 48110196Seric */ 48210196Seric 48360494Seric void 48410196Seric closexscript(e) 48510196Seric register ENVELOPE *e; 48610196Seric { 48710196Seric if (e->e_xfp == NULL) 48810196Seric return; 48958680Seric (void) xfclose(e->e_xfp, "closexscript", e->e_id); 49010196Seric e->e_xfp = NULL; 49110196Seric } 49210196Seric /* 4939536Seric ** SETSENDER -- set the person who this message is from 4949536Seric ** 4959536Seric ** Under certain circumstances allow the user to say who 4969536Seric ** s/he is (using -f or -r). These are: 4979536Seric ** 1. The user's uid is zero (root). 4989536Seric ** 2. The user's login name is in an approved list (typically 4999536Seric ** from a network server). 5009536Seric ** 3. The address the user is trying to claim has a 5019536Seric ** "!" character in it (since #2 doesn't do it for 5029536Seric ** us if we are dialing out for UUCP). 5039536Seric ** A better check to replace #3 would be if the 5049536Seric ** effective uid is "UUCP" -- this would require me 5059536Seric ** to rewrite getpwent to "grab" uucp as it went by, 5069536Seric ** make getname more nasty, do another passwd file 5079536Seric ** scan, or compile the UID of "UUCP" into the code, 5089536Seric ** all of which are reprehensible. 5099536Seric ** 5109536Seric ** Assuming all of these fail, we figure out something 5119536Seric ** ourselves. 5129536Seric ** 5139536Seric ** Parameters: 5149536Seric ** from -- the person we would like to believe this message 5159536Seric ** is from, as specified on the command line. 51653182Seric ** e -- the envelope in which we would like the sender set. 51758333Seric ** delimptr -- if non-NULL, set to the location of the 51858333Seric ** trailing delimiter. 51958704Seric ** internal -- set if this address is coming from an internal 52058704Seric ** source such as an owner alias. 5219536Seric ** 5229536Seric ** Returns: 52358704Seric ** none. 5249536Seric ** 5259536Seric ** Side Effects: 5269536Seric ** sets sendmail's notion of who the from person is. 5279536Seric */ 5289536Seric 52960494Seric void 53058704Seric setsender(from, e, delimptr, internal) 5319536Seric char *from; 53253182Seric register ENVELOPE *e; 53358333Seric char **delimptr; 53458704Seric bool internal; 5359536Seric { 5369536Seric register char **pvp; 5379536Seric char *realname = NULL; 53818665Seric register struct passwd *pw; 53958727Seric char delimchar; 54064147Seric char *bp; 54164147Seric char buf[MAXNAME + 2]; 54216913Seric char pvpbuf[PSBUFSIZE]; 54318665Seric extern struct passwd *getpwnam(); 5449536Seric extern char *FullName; 5459536Seric 5469536Seric if (tTd(45, 1)) 54714786Seric printf("setsender(%s)\n", from == NULL ? "" : from); 5489536Seric 5499536Seric /* 5509536Seric ** Figure out the real user executing us. 5519536Seric ** Username can return errno != 0 on non-errors. 5529536Seric */ 5539536Seric 55458737Seric if (bitset(EF_QUEUERUN, e->e_flags) || OpMode == MD_SMTP) 5559536Seric realname = from; 5569536Seric if (realname == NULL || realname[0] == '\0') 5579536Seric realname = username(); 5589536Seric 55959027Seric if (ConfigLevel < 2) 56059027Seric SuprErrs = TRUE; 56159027Seric 56258727Seric delimchar = internal ? '\0' : ' '; 56358333Seric if (from == NULL || 56464284Seric parseaddr(from, &e->e_from, RF_COPYALL|RF_SENDERADDR, 56564284Seric delimchar, delimptr, e) == NULL) 5669536Seric { 56721750Seric /* log garbage addresses for traceback */ 56855173Seric # ifdef LOG 56958020Seric if (from != NULL && LogLevel > 2) 57021750Seric { 57158951Seric char *p; 57258951Seric char ebuf[MAXNAME * 2 + 2]; 57355173Seric 57458951Seric p = macvalue('_', e); 57558951Seric if (p == NULL) 57658951Seric { 57758951Seric char *host = RealHostName; 57858951Seric if (host == NULL) 57958951Seric host = MyHostName; 58058951Seric (void) sprintf(ebuf, "%s@%s", realname, host); 58158951Seric p = ebuf; 58258951Seric } 58355173Seric syslog(LOG_NOTICE, 58458951Seric "from=%s unparseable, received from %s", 58558951Seric from, p); 58655173Seric } 58756795Seric # endif /* LOG */ 58857589Seric if (from != NULL) 58957589Seric SuprErrs = TRUE; 59057589Seric if (from == realname || 59164284Seric parseaddr(from = newstr(realname), &e->e_from, 59264284Seric RF_COPYALL|RF_SENDERADDR, ' ', NULL, e) == NULL) 59324944Seric { 59457589Seric SuprErrs = TRUE; 59564284Seric if (parseaddr("postmaster", &e->e_from, RF_COPYALL, 59664284Seric ' ', NULL, e) == NULL) 59758151Seric syserr("553 setsender: can't even parse postmaster!"); 59824944Seric } 5999536Seric } 6009536Seric else 6019536Seric FromFlag = TRUE; 60253182Seric e->e_from.q_flags |= QDONTSEND; 60357731Seric if (tTd(45, 5)) 60457731Seric { 60557731Seric printf("setsender: QDONTSEND "); 60657731Seric printaddr(&e->e_from, FALSE); 60757731Seric } 6089536Seric SuprErrs = FALSE; 6099536Seric 61053736Seric pvp = NULL; 61153736Seric if (e->e_from.q_mailer == LocalMailer) 6129536Seric { 61353736Seric # ifdef USERDB 61453736Seric register char *p; 61553736Seric extern char *udbsender(); 61653736Seric # endif 61717472Seric 61858704Seric if (!internal) 61958704Seric { 62058704Seric /* if the user has given fullname already, don't redefine */ 62158704Seric if (FullName == NULL) 62258704Seric FullName = macvalue('x', e); 62358704Seric if (FullName != NULL && FullName[0] == '\0') 62458704Seric FullName = NULL; 6259536Seric 62653736Seric # ifdef USERDB 62764284Seric p = udbsender(e->e_from.q_user); 62853736Seric 62958704Seric if (p != NULL) 63058704Seric { 63158704Seric /* 63258704Seric ** We have an alternate address for the sender 63358704Seric */ 63453736Seric 63558704Seric pvp = prescan(p, '\0', pvpbuf, NULL); 63658704Seric } 63758704Seric # endif /* USERDB */ 6389536Seric } 63953736Seric 64053736Seric if ((pw = getpwnam(e->e_from.q_user)) != NULL) 64153736Seric { 64253736Seric /* 64353736Seric ** Process passwd file entry. 64453736Seric */ 64553736Seric 64653736Seric 64753736Seric /* extract home directory */ 64853736Seric e->e_from.q_home = newstr(pw->pw_dir); 64953736Seric define('z', e->e_from.q_home, e); 65053736Seric 65153736Seric /* extract user and group id */ 65253736Seric e->e_from.q_uid = pw->pw_uid; 65353736Seric e->e_from.q_gid = pw->pw_gid; 65453736Seric 65553736Seric /* extract full name from passwd file */ 65653736Seric if (FullName == NULL && pw->pw_gecos != NULL && 65758704Seric strcmp(pw->pw_name, e->e_from.q_user) == 0 && 65858704Seric !internal) 65953736Seric { 66053736Seric buildfname(pw->pw_gecos, e->e_from.q_user, buf); 66153736Seric if (buf[0] != '\0') 66253736Seric FullName = newstr(buf); 66353736Seric } 66453736Seric } 66558704Seric if (FullName != NULL && !internal) 66653182Seric define('x', FullName, e); 6679536Seric } 66858704Seric else if (!internal) 66911625Seric { 67053182Seric if (e->e_from.q_home == NULL) 67153182Seric e->e_from.q_home = getenv("HOME"); 67263787Seric e->e_from.q_uid = RealUid; 67363787Seric e->e_from.q_gid = RealGid; 67411625Seric } 67511625Seric 6769536Seric /* 6779536Seric ** Rewrite the from person to dispose of possible implicit 6789536Seric ** links in the net. 6799536Seric */ 6809536Seric 6819536Seric if (pvp == NULL) 68258333Seric pvp = prescan(from, '\0', pvpbuf, NULL); 68353736Seric if (pvp == NULL) 6849536Seric { 68558403Seric /* don't need to give error -- prescan did that already */ 68636233Skarels # ifdef LOG 68758020Seric if (LogLevel > 2) 68836233Skarels syslog(LOG_NOTICE, "cannot prescan from (%s)", from); 68936233Skarels # endif 6909536Seric finis(); 6919536Seric } 69259084Seric (void) rewrite(pvp, 3, e); 69359084Seric (void) rewrite(pvp, 1, e); 69459084Seric (void) rewrite(pvp, 4, e); 69564147Seric bp = buf + 1; 69664147Seric cataddr(pvp, NULL, bp, sizeof buf - 2, '\0'); 69764147Seric if (*bp == '@') 69864147Seric { 69964147Seric /* heuristic: route-addr: add angle brackets */ 70064147Seric strcat(bp, ">"); 70164147Seric *--bp = '<'; 70264147Seric } 70364147Seric e->e_sender = newstr(bp); 70458704Seric define('f', e->e_sender, e); 7059536Seric 7069536Seric /* save the domain spec if this mailer wants it */ 70758704Seric if (!internal && e->e_from.q_mailer != NULL && 70853182Seric bitnset(M_CANONICAL, e->e_from.q_mailer->m_flags)) 7099536Seric { 7109536Seric extern char **copyplist(); 7119536Seric 7129536Seric while (*pvp != NULL && strcmp(*pvp, "@") != 0) 7139536Seric pvp++; 7149536Seric if (*pvp != NULL) 71553182Seric e->e_fromdomain = copyplist(pvp, TRUE); 7169536Seric } 7179536Seric } 718