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*64760Seric static char sccsid[] = "@(#)envelope.c 8.14 (Berkeley) 10/24/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 11264743Seric e->e_flags &= ~EF_QUEUERUN; 1139536Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1149536Seric { 1159536Seric if (bitset(QQUEUEUP, q->q_flags)) 1169536Seric queueit = TRUE; 11763839Seric if (!bitset(QDONTSEND, q->q_flags) && 11863839Seric bitset(QBADADDR, q->q_flags)) 11963839Seric { 12063839Seric if (q->q_owner == NULL && 12163839Seric strcmp(e->e_from.q_paddr, "<>") != 0) 12263839Seric (void) sendtolist(e->e_from.q_paddr, NULL, 12363839Seric &e->e_errorqueue, e); 12463839Seric } 1259536Seric } 1269536Seric 1279536Seric /* 12863753Seric ** See if the message timed out. 12963753Seric */ 13063753Seric 13163753Seric if (!queueit) 13263753Seric /* nothing to do */ ; 13363753Seric else if (curtime() > e->e_ctime + TimeOuts.to_q_return) 13463753Seric { 13563839Seric (void) sprintf(buf, "Cannot send message for %s", 13663839Seric pintvl(TimeOuts.to_q_return, FALSE)); 13763839Seric if (e->e_message != NULL) 13863839Seric free(e->e_message); 13963839Seric e->e_message = newstr(buf); 14063839Seric message(buf); 14163839Seric e->e_flags |= EF_CLRQUEUE; 14263839Seric saveit = TRUE; 14363787Seric fprintf(e->e_xfp, "Message could not be delivered for %s\n", 14463787Seric pintvl(TimeOuts.to_q_return, FALSE)); 14563787Seric fprintf(e->e_xfp, "Message will be deleted from queue\n"); 14663787Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 14763787Seric { 14863787Seric if (bitset(QQUEUEUP, q->q_flags)) 14963787Seric q->q_flags |= QBADADDR; 15063787Seric } 15163753Seric } 15263753Seric else if (TimeOuts.to_q_warning > 0 && 15363753Seric curtime() > e->e_ctime + TimeOuts.to_q_warning) 15463753Seric { 15563753Seric if (!bitset(EF_WARNING|EF_RESPONSE, e->e_flags) && 15663753Seric e->e_class >= 0 && 15763753Seric strcmp(e->e_from.q_paddr, "<>") != 0) 15863753Seric { 15963753Seric (void) sprintf(buf, 16063753Seric "warning: cannot send message for %s", 16163753Seric pintvl(TimeOuts.to_q_warning, FALSE)); 16263753Seric if (e->e_message != NULL) 16363753Seric free(e->e_message); 16463753Seric e->e_message = newstr(buf); 16563753Seric message(buf); 16663839Seric e->e_flags |= EF_WARNING; 16763839Seric saveit = TRUE; 16863753Seric } 16963753Seric fprintf(e->e_xfp, 17063753Seric "Warning: message still undelivered after %s\n", 17163753Seric pintvl(TimeOuts.to_q_warning, FALSE)); 17263753Seric fprintf(e->e_xfp, "Will keep trying until message is %s old\n", 17363753Seric pintvl(TimeOuts.to_q_return, FALSE)); 17463787Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 17563787Seric { 17663787Seric if (bitset(QQUEUEUP, q->q_flags)) 17763787Seric q->q_flags |= QREPORT; 17863787Seric } 17963753Seric } 18063753Seric 18163753Seric /* 1829536Seric ** Send back return receipts as requested. 1839536Seric */ 1849536Seric 1859536Seric if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags)) 1869536Seric { 18710844Seric auto ADDRESS *rlist = NULL; 1889536Seric 18964284Seric (void) sendtolist(e->e_receiptto, NULLADDR, &rlist, e); 19055012Seric (void) returntosender("Return receipt", rlist, FALSE, e); 1919536Seric } 1929536Seric 1939536Seric /* 1949536Seric ** Arrange to send error messages if there are fatal errors. 1959536Seric */ 1969536Seric 19763839Seric if (saveit && e->e_errormode != EM_QUIET) 1989536Seric savemail(e); 1999536Seric 2009536Seric /* 20163849Seric ** Arrange to send warning messages to postmaster as requested. 20263849Seric */ 20363849Seric 20463849Seric if (bitset(EF_PM_NOTIFY, e->e_flags) && PostMasterCopy != NULL && 20564363Seric !bitset(EF_RESPONSE, e->e_flags) && e->e_class >= 0) 20663849Seric { 20763849Seric auto ADDRESS *rlist = NULL; 20863849Seric 20964284Seric (void) sendtolist(PostMasterCopy, NULLADDR, &rlist, e); 21063849Seric (void) returntosender(e->e_message, rlist, FALSE, e); 21163849Seric } 21263849Seric 21363849Seric /* 2149536Seric ** Instantiate or deinstantiate the queue. 2159536Seric */ 2169536Seric 2179536Seric if ((!queueit && !bitset(EF_KEEPQUEUE, e->e_flags)) || 2189536Seric bitset(EF_CLRQUEUE, e->e_flags)) 2199536Seric { 22064307Seric if (tTd(50, 1)) 22164307Seric printf("\n===== Dropping [dq]f%s =====\n\n", e->e_id); 22223497Seric if (e->e_df != NULL) 22323497Seric xunlink(e->e_df); 2249536Seric xunlink(queuename(e, 'q')); 22563839Seric 22663839Seric #ifdef LOG 22763839Seric if (LogLevel > 10) 22863839Seric syslog(LOG_INFO, "%s: done", id); 22963839Seric #endif 2309536Seric } 2319536Seric else if (queueit || !bitset(EF_INQUEUE, e->e_flags)) 23210754Seric { 23310754Seric #ifdef QUEUE 23464307Seric queueup(e, bitset(EF_KEEPQUEUE, e->e_flags), FALSE); 23556795Seric #else /* QUEUE */ 23658151Seric syserr("554 dropenvelope: queueup"); 23756795Seric #endif /* QUEUE */ 23810754Seric } 2399536Seric 2409536Seric /* now unlock the job */ 24110196Seric closexscript(e); 2429536Seric unlockqueue(e); 2439536Seric 2449536Seric /* make sure that this envelope is marked unused */ 24524944Seric if (e->e_dfp != NULL) 24658680Seric (void) xfclose(e->e_dfp, "dropenvelope", e->e_df); 24710196Seric e->e_dfp = NULL; 24858680Seric e->e_id = e->e_df = NULL; 24964401Seric #ifdef XDEBUG 25064401Seric checkfd012("dropenvelope"); 25164401Seric #endif 2529536Seric } 2539536Seric /* 2549536Seric ** CLEARENVELOPE -- clear an envelope without unlocking 2559536Seric ** 2569536Seric ** This is normally used by a child process to get a clean 2579536Seric ** envelope without disturbing the parent. 2589536Seric ** 2599536Seric ** Parameters: 2609536Seric ** e -- the envelope to clear. 26125611Seric ** fullclear - if set, the current envelope is total 26225611Seric ** garbage and should be ignored; otherwise, 26325611Seric ** release any resources it may indicate. 2649536Seric ** 2659536Seric ** Returns: 2669536Seric ** none. 2679536Seric ** 2689536Seric ** Side Effects: 2699536Seric ** Closes files associated with the envelope. 2709536Seric ** Marks the envelope as unallocated. 2719536Seric */ 2729536Seric 27360494Seric void 27425611Seric clearenvelope(e, fullclear) 2759536Seric register ENVELOPE *e; 27625611Seric bool fullclear; 2779536Seric { 27825514Seric register HDR *bh; 27925514Seric register HDR **nhp; 28025514Seric extern ENVELOPE BlankEnvelope; 28125514Seric 28225611Seric if (!fullclear) 28325611Seric { 28425611Seric /* clear out any file information */ 28525611Seric if (e->e_xfp != NULL) 28658680Seric (void) xfclose(e->e_xfp, "clearenvelope xfp", e->e_id); 28725611Seric if (e->e_dfp != NULL) 28858680Seric (void) xfclose(e->e_dfp, "clearenvelope dfp", e->e_df); 28958680Seric e->e_xfp = e->e_dfp = NULL; 29025611Seric } 2919536Seric 29224961Seric /* now clear out the data */ 29324965Seric STRUCTCOPY(BlankEnvelope, *e); 29459698Seric if (Verbose) 29559698Seric e->e_sendmode = SM_DELIVER; 29625514Seric bh = BlankEnvelope.e_header; 29725514Seric nhp = &e->e_header; 29825514Seric while (bh != NULL) 29925514Seric { 30025514Seric *nhp = (HDR *) xalloc(sizeof *bh); 30125514Seric bcopy((char *) bh, (char *) *nhp, sizeof *bh); 30225514Seric bh = bh->h_link; 30325514Seric nhp = &(*nhp)->h_link; 30425514Seric } 3059536Seric } 3069536Seric /* 3079536Seric ** INITSYS -- initialize instantiation of system 3089536Seric ** 3099536Seric ** In Daemon mode, this is done in the child. 3109536Seric ** 3119536Seric ** Parameters: 3129536Seric ** none. 3139536Seric ** 3149536Seric ** Returns: 3159536Seric ** none. 3169536Seric ** 3179536Seric ** Side Effects: 3189536Seric ** Initializes the system macros, some global variables, 3199536Seric ** etc. In particular, the current time in various 3209536Seric ** forms is set. 3219536Seric */ 3229536Seric 32360494Seric void 32455012Seric initsys(e) 32555012Seric register ENVELOPE *e; 3269536Seric { 3279536Seric static char cbuf[5]; /* holds hop count */ 3289536Seric static char pbuf[10]; /* holds pid */ 32922963Smiriam #ifdef TTYNAME 33059304Seric static char ybuf[60]; /* holds tty id */ 3319536Seric register char *p; 33256795Seric #endif /* TTYNAME */ 3339536Seric extern char *ttyname(); 33460494Seric extern void settime(); 3359536Seric extern char Version[]; 3369536Seric 3379536Seric /* 3389536Seric ** Give this envelope a reality. 3399536Seric ** I.e., an id, a transcript, and a creation time. 3409536Seric */ 3419536Seric 34255012Seric openxscript(e); 34355012Seric e->e_ctime = curtime(); 3449536Seric 3459536Seric /* 3469536Seric ** Set OutChannel to something useful if stdout isn't it. 3479536Seric ** This arranges that any extra stuff the mailer produces 3489536Seric ** gets sent back to the user on error (because it is 3499536Seric ** tucked away in the transcript). 3509536Seric */ 3519536Seric 352*64760Seric if (OpMode == MD_DAEMON && bitset(EF_QUEUERUN, e->e_flags) && 35358737Seric e->e_xfp != NULL) 35455012Seric OutChannel = e->e_xfp; 3559536Seric 3569536Seric /* 3579536Seric ** Set up some basic system macros. 3589536Seric */ 3599536Seric 3609536Seric /* process id */ 3619536Seric (void) sprintf(pbuf, "%d", getpid()); 36255012Seric define('p', pbuf, e); 3639536Seric 3649536Seric /* hop count */ 36555012Seric (void) sprintf(cbuf, "%d", e->e_hopcount); 36655012Seric define('c', cbuf, e); 3679536Seric 3689536Seric /* time as integer, unix time, arpa time */ 36955012Seric settime(e); 3709536Seric 37117472Seric #ifdef TTYNAME 3729536Seric /* tty name */ 37355012Seric if (macvalue('y', e) == NULL) 3749536Seric { 3759536Seric p = ttyname(2); 3769536Seric if (p != NULL) 3779536Seric { 37856795Seric if (strrchr(p, '/') != NULL) 37956795Seric p = strrchr(p, '/') + 1; 3809536Seric (void) strcpy(ybuf, p); 38155012Seric define('y', ybuf, e); 3829536Seric } 3839536Seric } 38456795Seric #endif /* TTYNAME */ 3859536Seric } 3869536Seric /* 38711932Seric ** SETTIME -- set the current time. 38811932Seric ** 38911932Seric ** Parameters: 39011932Seric ** none. 39111932Seric ** 39211932Seric ** Returns: 39311932Seric ** none. 39411932Seric ** 39511932Seric ** Side Effects: 39611932Seric ** Sets the various time macros -- $a, $b, $d, $t. 39711932Seric */ 39811932Seric 39960494Seric void 40055012Seric settime(e) 40155012Seric register ENVELOPE *e; 40211932Seric { 40311932Seric register char *p; 40411932Seric auto time_t now; 40511932Seric static char tbuf[20]; /* holds "current" time */ 40611932Seric static char dbuf[30]; /* holds ctime(tbuf) */ 40711932Seric register struct tm *tm; 40811932Seric extern char *arpadate(); 40911932Seric extern struct tm *gmtime(); 41011932Seric 41111932Seric now = curtime(); 41211932Seric tm = gmtime(&now); 41357014Seric (void) sprintf(tbuf, "%04d%02d%02d%02d%02d", tm->tm_year + 1900, 41457014Seric tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min); 41555012Seric define('t', tbuf, e); 41611932Seric (void) strcpy(dbuf, ctime(&now)); 41758131Seric p = strchr(dbuf, '\n'); 41858131Seric if (p != NULL) 41958131Seric *p = '\0'; 42058131Seric define('d', dbuf, e); 42164086Seric p = arpadate(dbuf); 42264086Seric p = newstr(p); 42355012Seric if (macvalue('a', e) == NULL) 42455012Seric define('a', p, e); 42555012Seric define('b', p, e); 42611932Seric } 42711932Seric /* 4289536Seric ** OPENXSCRIPT -- Open transcript file 4299536Seric ** 4309536Seric ** Creates a transcript file for possible eventual mailing or 4319536Seric ** sending back. 4329536Seric ** 4339536Seric ** Parameters: 4349536Seric ** e -- the envelope to create the transcript in/for. 4359536Seric ** 4369536Seric ** Returns: 4379536Seric ** none 4389536Seric ** 4399536Seric ** Side Effects: 4409536Seric ** Creates the transcript file. 4419536Seric */ 4429536Seric 44358803Seric #ifndef O_APPEND 44458803Seric #define O_APPEND 0 44558803Seric #endif 44658803Seric 44760494Seric void 4489536Seric openxscript(e) 4499536Seric register ENVELOPE *e; 4509536Seric { 4519536Seric register char *p; 45240933Srick int fd; 4539536Seric 4549536Seric if (e->e_xfp != NULL) 4559536Seric return; 4569536Seric p = queuename(e, 'x'); 45758803Seric fd = open(p, O_WRONLY|O_CREAT|O_APPEND, 0644); 45840933Srick if (fd < 0) 45963753Seric { 46063753Seric syserr("Can't create transcript file %s", p); 46163753Seric fd = open("/dev/null", O_WRONLY, 0644); 46263753Seric if (fd < 0) 46363753Seric syserr("!Can't open /dev/null"); 46463753Seric } 46563753Seric e->e_xfp = fdopen(fd, "w"); 46664724Seric if (e->e_xfp == NULL) 46764724Seric { 46864724Seric syserr("!Can't create transcript stream %s", p); 46964724Seric } 47064743Seric if (tTd(46, 9)) 47164743Seric { 47264743Seric printf("openxscript(%s):\n ", p); 47364743Seric dumpfd(fileno(e->e_xfp), TRUE, FALSE); 47464743Seric } 4759536Seric } 4769536Seric /* 47710196Seric ** CLOSEXSCRIPT -- close the transcript file. 47810196Seric ** 47910196Seric ** Parameters: 48010196Seric ** e -- the envelope containing the transcript to close. 48110196Seric ** 48210196Seric ** Returns: 48310196Seric ** none. 48410196Seric ** 48510196Seric ** Side Effects: 48610196Seric ** none. 48710196Seric */ 48810196Seric 48960494Seric void 49010196Seric closexscript(e) 49110196Seric register ENVELOPE *e; 49210196Seric { 49310196Seric if (e->e_xfp == NULL) 49410196Seric return; 49558680Seric (void) xfclose(e->e_xfp, "closexscript", e->e_id); 49610196Seric e->e_xfp = NULL; 49710196Seric } 49810196Seric /* 4999536Seric ** SETSENDER -- set the person who this message is from 5009536Seric ** 5019536Seric ** Under certain circumstances allow the user to say who 5029536Seric ** s/he is (using -f or -r). These are: 5039536Seric ** 1. The user's uid is zero (root). 5049536Seric ** 2. The user's login name is in an approved list (typically 5059536Seric ** from a network server). 5069536Seric ** 3. The address the user is trying to claim has a 5079536Seric ** "!" character in it (since #2 doesn't do it for 5089536Seric ** us if we are dialing out for UUCP). 5099536Seric ** A better check to replace #3 would be if the 5109536Seric ** effective uid is "UUCP" -- this would require me 5119536Seric ** to rewrite getpwent to "grab" uucp as it went by, 5129536Seric ** make getname more nasty, do another passwd file 5139536Seric ** scan, or compile the UID of "UUCP" into the code, 5149536Seric ** all of which are reprehensible. 5159536Seric ** 5169536Seric ** Assuming all of these fail, we figure out something 5179536Seric ** ourselves. 5189536Seric ** 5199536Seric ** Parameters: 5209536Seric ** from -- the person we would like to believe this message 5219536Seric ** is from, as specified on the command line. 52253182Seric ** e -- the envelope in which we would like the sender set. 52358333Seric ** delimptr -- if non-NULL, set to the location of the 52458333Seric ** trailing delimiter. 52558704Seric ** internal -- set if this address is coming from an internal 52658704Seric ** source such as an owner alias. 5279536Seric ** 5289536Seric ** Returns: 52958704Seric ** none. 5309536Seric ** 5319536Seric ** Side Effects: 5329536Seric ** sets sendmail's notion of who the from person is. 5339536Seric */ 5349536Seric 53560494Seric void 53658704Seric setsender(from, e, delimptr, internal) 5379536Seric char *from; 53853182Seric register ENVELOPE *e; 53958333Seric char **delimptr; 54058704Seric bool internal; 5419536Seric { 5429536Seric register char **pvp; 5439536Seric char *realname = NULL; 54418665Seric register struct passwd *pw; 54558727Seric char delimchar; 54664147Seric char *bp; 54764147Seric char buf[MAXNAME + 2]; 54816913Seric char pvpbuf[PSBUFSIZE]; 54918665Seric extern struct passwd *getpwnam(); 5509536Seric extern char *FullName; 5519536Seric 5529536Seric if (tTd(45, 1)) 55314786Seric printf("setsender(%s)\n", from == NULL ? "" : from); 5549536Seric 5559536Seric /* 5569536Seric ** Figure out the real user executing us. 5579536Seric ** Username can return errno != 0 on non-errors. 5589536Seric */ 5599536Seric 56058737Seric if (bitset(EF_QUEUERUN, e->e_flags) || OpMode == MD_SMTP) 5619536Seric realname = from; 5629536Seric if (realname == NULL || realname[0] == '\0') 5639536Seric realname = username(); 5649536Seric 56559027Seric if (ConfigLevel < 2) 56659027Seric SuprErrs = TRUE; 56759027Seric 56858727Seric delimchar = internal ? '\0' : ' '; 56958333Seric if (from == NULL || 57064284Seric parseaddr(from, &e->e_from, RF_COPYALL|RF_SENDERADDR, 57164284Seric delimchar, delimptr, e) == NULL) 5729536Seric { 57321750Seric /* log garbage addresses for traceback */ 57455173Seric # ifdef LOG 57558020Seric if (from != NULL && LogLevel > 2) 57621750Seric { 57758951Seric char *p; 57858951Seric char ebuf[MAXNAME * 2 + 2]; 57955173Seric 58058951Seric p = macvalue('_', e); 58158951Seric if (p == NULL) 58258951Seric { 58358951Seric char *host = RealHostName; 58458951Seric if (host == NULL) 58558951Seric host = MyHostName; 58658951Seric (void) sprintf(ebuf, "%s@%s", realname, host); 58758951Seric p = ebuf; 58858951Seric } 58955173Seric syslog(LOG_NOTICE, 59058951Seric "from=%s unparseable, received from %s", 59158951Seric from, p); 59255173Seric } 59356795Seric # endif /* LOG */ 59457589Seric if (from != NULL) 59557589Seric SuprErrs = TRUE; 59657589Seric if (from == realname || 59764284Seric parseaddr(from = newstr(realname), &e->e_from, 59864284Seric RF_COPYALL|RF_SENDERADDR, ' ', NULL, e) == NULL) 59924944Seric { 60057589Seric SuprErrs = TRUE; 60164284Seric if (parseaddr("postmaster", &e->e_from, RF_COPYALL, 60264284Seric ' ', NULL, e) == NULL) 60358151Seric syserr("553 setsender: can't even parse postmaster!"); 60424944Seric } 6059536Seric } 6069536Seric else 6079536Seric FromFlag = TRUE; 60853182Seric e->e_from.q_flags |= QDONTSEND; 60957731Seric if (tTd(45, 5)) 61057731Seric { 61157731Seric printf("setsender: QDONTSEND "); 61257731Seric printaddr(&e->e_from, FALSE); 61357731Seric } 6149536Seric SuprErrs = FALSE; 6159536Seric 61653736Seric pvp = NULL; 61753736Seric if (e->e_from.q_mailer == LocalMailer) 6189536Seric { 61953736Seric # ifdef USERDB 62053736Seric register char *p; 62153736Seric extern char *udbsender(); 62253736Seric # endif 62317472Seric 62458704Seric if (!internal) 62558704Seric { 62658704Seric /* if the user has given fullname already, don't redefine */ 62758704Seric if (FullName == NULL) 62858704Seric FullName = macvalue('x', e); 62958704Seric if (FullName != NULL && FullName[0] == '\0') 63058704Seric FullName = NULL; 6319536Seric 63253736Seric # ifdef USERDB 63364284Seric p = udbsender(e->e_from.q_user); 63453736Seric 63558704Seric if (p != NULL) 63658704Seric { 63758704Seric /* 63858704Seric ** We have an alternate address for the sender 63958704Seric */ 64053736Seric 64158704Seric pvp = prescan(p, '\0', pvpbuf, NULL); 64258704Seric } 64358704Seric # endif /* USERDB */ 6449536Seric } 64553736Seric 64653736Seric if ((pw = getpwnam(e->e_from.q_user)) != NULL) 64753736Seric { 64853736Seric /* 64953736Seric ** Process passwd file entry. 65053736Seric */ 65153736Seric 65253736Seric 65353736Seric /* extract home directory */ 65453736Seric e->e_from.q_home = newstr(pw->pw_dir); 65553736Seric define('z', e->e_from.q_home, e); 65653736Seric 65753736Seric /* extract user and group id */ 65853736Seric e->e_from.q_uid = pw->pw_uid; 65953736Seric e->e_from.q_gid = pw->pw_gid; 66053736Seric 66153736Seric /* extract full name from passwd file */ 66253736Seric if (FullName == NULL && pw->pw_gecos != NULL && 66358704Seric strcmp(pw->pw_name, e->e_from.q_user) == 0 && 66458704Seric !internal) 66553736Seric { 66653736Seric buildfname(pw->pw_gecos, e->e_from.q_user, buf); 66753736Seric if (buf[0] != '\0') 66853736Seric FullName = newstr(buf); 66953736Seric } 67053736Seric } 67158704Seric if (FullName != NULL && !internal) 67253182Seric define('x', FullName, e); 6739536Seric } 67458704Seric else if (!internal) 67511625Seric { 67653182Seric if (e->e_from.q_home == NULL) 67753182Seric e->e_from.q_home = getenv("HOME"); 67863787Seric e->e_from.q_uid = RealUid; 67963787Seric e->e_from.q_gid = RealGid; 68011625Seric } 68111625Seric 6829536Seric /* 6839536Seric ** Rewrite the from person to dispose of possible implicit 6849536Seric ** links in the net. 6859536Seric */ 6869536Seric 6879536Seric if (pvp == NULL) 68858333Seric pvp = prescan(from, '\0', pvpbuf, NULL); 68953736Seric if (pvp == NULL) 6909536Seric { 69158403Seric /* don't need to give error -- prescan did that already */ 69236233Skarels # ifdef LOG 69358020Seric if (LogLevel > 2) 69436233Skarels syslog(LOG_NOTICE, "cannot prescan from (%s)", from); 69536233Skarels # endif 6969536Seric finis(); 6979536Seric } 69859084Seric (void) rewrite(pvp, 3, e); 69959084Seric (void) rewrite(pvp, 1, e); 70059084Seric (void) rewrite(pvp, 4, e); 70164147Seric bp = buf + 1; 70264147Seric cataddr(pvp, NULL, bp, sizeof buf - 2, '\0'); 70364147Seric if (*bp == '@') 70464147Seric { 70564147Seric /* heuristic: route-addr: add angle brackets */ 70664147Seric strcat(bp, ">"); 70764147Seric *--bp = '<'; 70864147Seric } 70964147Seric e->e_sender = newstr(bp); 71058704Seric define('f', e->e_sender, e); 7119536Seric 7129536Seric /* save the domain spec if this mailer wants it */ 71358704Seric if (!internal && e->e_from.q_mailer != NULL && 71453182Seric bitnset(M_CANONICAL, e->e_from.q_mailer->m_flags)) 7159536Seric { 7169536Seric extern char **copyplist(); 7179536Seric 7189536Seric while (*pvp != NULL && strcmp(*pvp, "@") != 0) 7199536Seric pvp++; 7209536Seric if (*pvp != NULL) 72153182Seric e->e_fromdomain = copyplist(pvp, TRUE); 7229536Seric } 7239536Seric } 724