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*64401Seric static char sccsid[] = "@(#)envelope.c 8.11 (Berkeley) 09/04/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; 248*64401Seric #ifdef XDEBUG 249*64401Seric checkfd012("dropenvelope"); 250*64401Seric #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"); 4659536Seric } 4669536Seric /* 46710196Seric ** CLOSEXSCRIPT -- close the transcript file. 46810196Seric ** 46910196Seric ** Parameters: 47010196Seric ** e -- the envelope containing the transcript to close. 47110196Seric ** 47210196Seric ** Returns: 47310196Seric ** none. 47410196Seric ** 47510196Seric ** Side Effects: 47610196Seric ** none. 47710196Seric */ 47810196Seric 47960494Seric void 48010196Seric closexscript(e) 48110196Seric register ENVELOPE *e; 48210196Seric { 48310196Seric if (e->e_xfp == NULL) 48410196Seric return; 48558680Seric (void) xfclose(e->e_xfp, "closexscript", e->e_id); 48610196Seric e->e_xfp = NULL; 48710196Seric } 48810196Seric /* 4899536Seric ** SETSENDER -- set the person who this message is from 4909536Seric ** 4919536Seric ** Under certain circumstances allow the user to say who 4929536Seric ** s/he is (using -f or -r). These are: 4939536Seric ** 1. The user's uid is zero (root). 4949536Seric ** 2. The user's login name is in an approved list (typically 4959536Seric ** from a network server). 4969536Seric ** 3. The address the user is trying to claim has a 4979536Seric ** "!" character in it (since #2 doesn't do it for 4989536Seric ** us if we are dialing out for UUCP). 4999536Seric ** A better check to replace #3 would be if the 5009536Seric ** effective uid is "UUCP" -- this would require me 5019536Seric ** to rewrite getpwent to "grab" uucp as it went by, 5029536Seric ** make getname more nasty, do another passwd file 5039536Seric ** scan, or compile the UID of "UUCP" into the code, 5049536Seric ** all of which are reprehensible. 5059536Seric ** 5069536Seric ** Assuming all of these fail, we figure out something 5079536Seric ** ourselves. 5089536Seric ** 5099536Seric ** Parameters: 5109536Seric ** from -- the person we would like to believe this message 5119536Seric ** is from, as specified on the command line. 51253182Seric ** e -- the envelope in which we would like the sender set. 51358333Seric ** delimptr -- if non-NULL, set to the location of the 51458333Seric ** trailing delimiter. 51558704Seric ** internal -- set if this address is coming from an internal 51658704Seric ** source such as an owner alias. 5179536Seric ** 5189536Seric ** Returns: 51958704Seric ** none. 5209536Seric ** 5219536Seric ** Side Effects: 5229536Seric ** sets sendmail's notion of who the from person is. 5239536Seric */ 5249536Seric 52560494Seric void 52658704Seric setsender(from, e, delimptr, internal) 5279536Seric char *from; 52853182Seric register ENVELOPE *e; 52958333Seric char **delimptr; 53058704Seric bool internal; 5319536Seric { 5329536Seric register char **pvp; 5339536Seric char *realname = NULL; 53418665Seric register struct passwd *pw; 53558727Seric char delimchar; 53664147Seric char *bp; 53764147Seric char buf[MAXNAME + 2]; 53816913Seric char pvpbuf[PSBUFSIZE]; 53918665Seric extern struct passwd *getpwnam(); 5409536Seric extern char *FullName; 5419536Seric 5429536Seric if (tTd(45, 1)) 54314786Seric printf("setsender(%s)\n", from == NULL ? "" : from); 5449536Seric 5459536Seric /* 5469536Seric ** Figure out the real user executing us. 5479536Seric ** Username can return errno != 0 on non-errors. 5489536Seric */ 5499536Seric 55058737Seric if (bitset(EF_QUEUERUN, e->e_flags) || OpMode == MD_SMTP) 5519536Seric realname = from; 5529536Seric if (realname == NULL || realname[0] == '\0') 5539536Seric realname = username(); 5549536Seric 55559027Seric if (ConfigLevel < 2) 55659027Seric SuprErrs = TRUE; 55759027Seric 55858727Seric delimchar = internal ? '\0' : ' '; 55958333Seric if (from == NULL || 56064284Seric parseaddr(from, &e->e_from, RF_COPYALL|RF_SENDERADDR, 56164284Seric delimchar, delimptr, e) == NULL) 5629536Seric { 56321750Seric /* log garbage addresses for traceback */ 56455173Seric # ifdef LOG 56558020Seric if (from != NULL && LogLevel > 2) 56621750Seric { 56758951Seric char *p; 56858951Seric char ebuf[MAXNAME * 2 + 2]; 56955173Seric 57058951Seric p = macvalue('_', e); 57158951Seric if (p == NULL) 57258951Seric { 57358951Seric char *host = RealHostName; 57458951Seric if (host == NULL) 57558951Seric host = MyHostName; 57658951Seric (void) sprintf(ebuf, "%s@%s", realname, host); 57758951Seric p = ebuf; 57858951Seric } 57955173Seric syslog(LOG_NOTICE, 58058951Seric "from=%s unparseable, received from %s", 58158951Seric from, p); 58255173Seric } 58356795Seric # endif /* LOG */ 58457589Seric if (from != NULL) 58557589Seric SuprErrs = TRUE; 58657589Seric if (from == realname || 58764284Seric parseaddr(from = newstr(realname), &e->e_from, 58864284Seric RF_COPYALL|RF_SENDERADDR, ' ', NULL, e) == NULL) 58924944Seric { 59057589Seric SuprErrs = TRUE; 59164284Seric if (parseaddr("postmaster", &e->e_from, RF_COPYALL, 59264284Seric ' ', NULL, e) == NULL) 59358151Seric syserr("553 setsender: can't even parse postmaster!"); 59424944Seric } 5959536Seric } 5969536Seric else 5979536Seric FromFlag = TRUE; 59853182Seric e->e_from.q_flags |= QDONTSEND; 59957731Seric if (tTd(45, 5)) 60057731Seric { 60157731Seric printf("setsender: QDONTSEND "); 60257731Seric printaddr(&e->e_from, FALSE); 60357731Seric } 6049536Seric SuprErrs = FALSE; 6059536Seric 60653736Seric pvp = NULL; 60753736Seric if (e->e_from.q_mailer == LocalMailer) 6089536Seric { 60953736Seric # ifdef USERDB 61053736Seric register char *p; 61153736Seric extern char *udbsender(); 61253736Seric # endif 61317472Seric 61458704Seric if (!internal) 61558704Seric { 61658704Seric /* if the user has given fullname already, don't redefine */ 61758704Seric if (FullName == NULL) 61858704Seric FullName = macvalue('x', e); 61958704Seric if (FullName != NULL && FullName[0] == '\0') 62058704Seric FullName = NULL; 6219536Seric 62253736Seric # ifdef USERDB 62364284Seric p = udbsender(e->e_from.q_user); 62453736Seric 62558704Seric if (p != NULL) 62658704Seric { 62758704Seric /* 62858704Seric ** We have an alternate address for the sender 62958704Seric */ 63053736Seric 63158704Seric pvp = prescan(p, '\0', pvpbuf, NULL); 63258704Seric } 63358704Seric # endif /* USERDB */ 6349536Seric } 63553736Seric 63653736Seric if ((pw = getpwnam(e->e_from.q_user)) != NULL) 63753736Seric { 63853736Seric /* 63953736Seric ** Process passwd file entry. 64053736Seric */ 64153736Seric 64253736Seric 64353736Seric /* extract home directory */ 64453736Seric e->e_from.q_home = newstr(pw->pw_dir); 64553736Seric define('z', e->e_from.q_home, e); 64653736Seric 64753736Seric /* extract user and group id */ 64853736Seric e->e_from.q_uid = pw->pw_uid; 64953736Seric e->e_from.q_gid = pw->pw_gid; 65053736Seric 65153736Seric /* extract full name from passwd file */ 65253736Seric if (FullName == NULL && pw->pw_gecos != NULL && 65358704Seric strcmp(pw->pw_name, e->e_from.q_user) == 0 && 65458704Seric !internal) 65553736Seric { 65653736Seric buildfname(pw->pw_gecos, e->e_from.q_user, buf); 65753736Seric if (buf[0] != '\0') 65853736Seric FullName = newstr(buf); 65953736Seric } 66053736Seric } 66158704Seric if (FullName != NULL && !internal) 66253182Seric define('x', FullName, e); 6639536Seric } 66458704Seric else if (!internal) 66511625Seric { 66653182Seric if (e->e_from.q_home == NULL) 66753182Seric e->e_from.q_home = getenv("HOME"); 66863787Seric e->e_from.q_uid = RealUid; 66963787Seric e->e_from.q_gid = RealGid; 67011625Seric } 67111625Seric 6729536Seric /* 6739536Seric ** Rewrite the from person to dispose of possible implicit 6749536Seric ** links in the net. 6759536Seric */ 6769536Seric 6779536Seric if (pvp == NULL) 67858333Seric pvp = prescan(from, '\0', pvpbuf, NULL); 67953736Seric if (pvp == NULL) 6809536Seric { 68158403Seric /* don't need to give error -- prescan did that already */ 68236233Skarels # ifdef LOG 68358020Seric if (LogLevel > 2) 68436233Skarels syslog(LOG_NOTICE, "cannot prescan from (%s)", from); 68536233Skarels # endif 6869536Seric finis(); 6879536Seric } 68859084Seric (void) rewrite(pvp, 3, e); 68959084Seric (void) rewrite(pvp, 1, e); 69059084Seric (void) rewrite(pvp, 4, e); 69164147Seric bp = buf + 1; 69264147Seric cataddr(pvp, NULL, bp, sizeof buf - 2, '\0'); 69364147Seric if (*bp == '@') 69464147Seric { 69564147Seric /* heuristic: route-addr: add angle brackets */ 69664147Seric strcat(bp, ">"); 69764147Seric *--bp = '<'; 69864147Seric } 69964147Seric e->e_sender = newstr(bp); 70058704Seric define('f', e->e_sender, e); 7019536Seric 7029536Seric /* save the domain spec if this mailer wants it */ 70358704Seric if (!internal && e->e_from.q_mailer != NULL && 70453182Seric bitnset(M_CANONICAL, e->e_from.q_mailer->m_flags)) 7059536Seric { 7069536Seric extern char **copyplist(); 7079536Seric 7089536Seric while (*pvp != NULL && strcmp(*pvp, "@") != 0) 7099536Seric pvp++; 7109536Seric if (*pvp != NULL) 71153182Seric e->e_fromdomain = copyplist(pvp, TRUE); 7129536Seric } 7139536Seric } 714