19536Seric #include <pwd.h> 213587Swnj #include <sys/time.h> 39536Seric #include "sendmail.h" 49536Seric #include <sys/stat.h> 59536Seric 6*16913Seric SCCSID(@(#)envelope.c 4.7 08/11/84); 79536Seric 89536Seric /* 99536Seric ** NEWENVELOPE -- allocate a new envelope 109536Seric ** 119536Seric ** Supports inheritance. 129536Seric ** 139536Seric ** Parameters: 149536Seric ** e -- the new envelope to fill in. 159536Seric ** 169536Seric ** Returns: 179536Seric ** e. 189536Seric ** 199536Seric ** Side Effects: 209536Seric ** none. 219536Seric */ 229536Seric 239536Seric ENVELOPE * 249536Seric newenvelope(e) 259536Seric register ENVELOPE *e; 269536Seric { 279536Seric register HDR *bh; 289536Seric register HDR **nhp; 299536Seric register ENVELOPE *parent; 309536Seric extern putheader(), putbody(); 319536Seric extern ENVELOPE BlankEnvelope; 329536Seric 339536Seric parent = CurEnv; 349536Seric if (e == CurEnv) 359536Seric parent = e->e_parent; 3616888Seric bzero((char *) e, sizeof *e); 3716888Seric bcopy((char *) &CurEnv->e_from, (char *) &e->e_from, sizeof e->e_from); 389536Seric e->e_parent = parent; 399536Seric e->e_ctime = curtime(); 409536Seric e->e_puthdr = putheader; 419536Seric e->e_putbody = putbody; 429536Seric bh = BlankEnvelope.e_header; 439536Seric nhp = &e->e_header; 449536Seric while (bh != NULL) 459536Seric { 469536Seric *nhp = (HDR *) xalloc(sizeof *bh); 4716888Seric bcopy((char *) bh, (char *) *nhp, sizeof *bh); 489536Seric bh = bh->h_link; 499536Seric nhp = &(*nhp)->h_link; 509536Seric } 519536Seric if (CurEnv->e_xfp != NULL) 529536Seric (void) fflush(CurEnv->e_xfp); 539536Seric 549536Seric return (e); 559536Seric } 569536Seric /* 579536Seric ** DROPENVELOPE -- deallocate an envelope. 589536Seric ** 599536Seric ** Parameters: 609536Seric ** e -- the envelope to deallocate. 619536Seric ** 629536Seric ** Returns: 639536Seric ** none. 649536Seric ** 659536Seric ** Side Effects: 669536Seric ** housekeeping necessary to dispose of an envelope. 679536Seric ** Unlocks this queue file. 689536Seric */ 699536Seric 709536Seric dropenvelope(e) 719536Seric register ENVELOPE *e; 729536Seric { 739536Seric bool queueit = FALSE; 749536Seric register ADDRESS *q; 759536Seric 769536Seric #ifdef DEBUG 779536Seric if (tTd(50, 1)) 789536Seric { 799536Seric printf("dropenvelope %x id=", e); 809536Seric xputs(e->e_id); 819536Seric printf(" flags=%o\n", e->e_flags); 829536Seric } 839536Seric #endif DEBUG 849536Seric #ifdef LOG 859536Seric if (LogLevel > 10) 869536Seric syslog(LOG_DEBUG, "dropenvelope, id=%s, flags=%o, pid=%d", 879536Seric e->e_id == NULL ? "(none)" : e->e_id, 889536Seric e->e_flags, getpid()); 899536Seric #endif LOG 909536Seric 919536Seric /* we must have an id to remove disk files */ 929536Seric if (e->e_id == NULL) 939536Seric return; 949536Seric 959536Seric /* 969536Seric ** Extract state information from dregs of send list. 979536Seric */ 989536Seric 999536Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1009536Seric { 1019536Seric if (bitset(QQUEUEUP, q->q_flags)) 1029536Seric queueit = TRUE; 1039536Seric } 1049536Seric 1059536Seric /* 1069536Seric ** Send back return receipts as requested. 1079536Seric */ 1089536Seric 1099536Seric if (e->e_receiptto != NULL && bitset(EF_SENDRECEIPT, e->e_flags)) 1109536Seric { 11110844Seric auto ADDRESS *rlist = NULL; 1129536Seric 1139621Seric sendtolist(CurEnv->e_receiptto, (ADDRESS *) NULL, &rlist); 1149536Seric (void) returntosender("Return receipt", rlist, FALSE); 1159536Seric } 1169536Seric 1179536Seric /* 1189536Seric ** Arrange to send error messages if there are fatal errors. 1199536Seric */ 1209536Seric 12110754Seric if (bitset(EF_FATALERRS|EF_TIMEOUT, e->e_flags) && ErrorMode != EM_QUIET) 1229536Seric savemail(e); 1239536Seric 1249536Seric /* 1259536Seric ** Instantiate or deinstantiate the queue. 1269536Seric */ 1279536Seric 1289536Seric if ((!queueit && !bitset(EF_KEEPQUEUE, e->e_flags)) || 1299536Seric bitset(EF_CLRQUEUE, e->e_flags)) 1309536Seric { 1319536Seric if (e->e_dfp != NULL) 1329536Seric (void) fclose(e->e_dfp); 1339536Seric if (e->e_df != NULL) 1349536Seric xunlink(e->e_df); 1359536Seric xunlink(queuename(e, 'q')); 1369536Seric } 1379536Seric else if (queueit || !bitset(EF_INQUEUE, e->e_flags)) 13810754Seric { 13910754Seric #ifdef QUEUE 1409536Seric queueup(e, FALSE, FALSE); 14110754Seric #else QUEUE 14210754Seric syserr("dropenvelope: queueup"); 14310754Seric #endif QUEUE 14410754Seric } 1459536Seric 1469536Seric /* now unlock the job */ 14710196Seric closexscript(e); 1489536Seric unlockqueue(e); 1499536Seric 1509536Seric /* make sure that this envelope is marked unused */ 1519536Seric e->e_id = e->e_df = NULL; 15210196Seric e->e_dfp = NULL; 1539536Seric } 1549536Seric /* 1559536Seric ** CLEARENVELOPE -- clear an envelope without unlocking 1569536Seric ** 1579536Seric ** This is normally used by a child process to get a clean 1589536Seric ** envelope without disturbing the parent. 1599536Seric ** 1609536Seric ** Parameters: 1619536Seric ** e -- the envelope to clear. 1629536Seric ** 1639536Seric ** Returns: 1649536Seric ** none. 1659536Seric ** 1669536Seric ** Side Effects: 1679536Seric ** Closes files associated with the envelope. 1689536Seric ** Marks the envelope as unallocated. 1699536Seric */ 1709536Seric 1719536Seric clearenvelope(e) 1729536Seric register ENVELOPE *e; 1739536Seric { 1749536Seric /* clear out any file information */ 1759536Seric if (e->e_xfp != NULL) 1769536Seric (void) fclose(e->e_xfp); 1779536Seric if (e->e_dfp != NULL) 1789536Seric (void) fclose(e->e_dfp); 1799536Seric e->e_xfp = e->e_dfp = NULL; 1809536Seric 1819536Seric /* now expunge names of objects */ 1829536Seric e->e_df = e->e_id = NULL; 1839536Seric 1849536Seric /* and the flags which are now meaningless */ 1859536Seric e->e_flags = 0; 1869536Seric } 1879536Seric /* 1889536Seric ** UNLOCKQUEUE -- unlock the queue entry for a specified envelope 1899536Seric ** 1909536Seric ** Parameters: 1919536Seric ** e -- the envelope to unlock. 1929536Seric ** 1939536Seric ** Returns: 1949536Seric ** none 1959536Seric ** 1969536Seric ** Side Effects: 1979536Seric ** unlocks the queue for `e'. 1989536Seric */ 1999536Seric 2009536Seric unlockqueue(e) 2019536Seric ENVELOPE *e; 2029536Seric { 2039536Seric /* remove the transcript */ 2049536Seric #ifdef DEBUG 20510196Seric # ifdef LOG 20610196Seric if (LogLevel > 19) 20710196Seric syslog(LOG_DEBUG, "%s: unlock", e->e_id); 20810196Seric # endif LOG 2099536Seric if (!tTd(51, 4)) 2109536Seric #endif DEBUG 2119536Seric xunlink(queuename(e, 'x')); 2129536Seric 21310754Seric # ifdef QUEUE 2149536Seric /* last but not least, remove the lock */ 2159536Seric xunlink(queuename(e, 'l')); 21610754Seric # endif QUEUE 2179536Seric } 2189536Seric /* 2199536Seric ** INITSYS -- initialize instantiation of system 2209536Seric ** 2219536Seric ** In Daemon mode, this is done in the child. 2229536Seric ** 2239536Seric ** Parameters: 2249536Seric ** none. 2259536Seric ** 2269536Seric ** Returns: 2279536Seric ** none. 2289536Seric ** 2299536Seric ** Side Effects: 2309536Seric ** Initializes the system macros, some global variables, 2319536Seric ** etc. In particular, the current time in various 2329536Seric ** forms is set. 2339536Seric */ 2349536Seric 2359536Seric initsys() 2369536Seric { 2379536Seric static char cbuf[5]; /* holds hop count */ 2389536Seric static char pbuf[10]; /* holds pid */ 2399536Seric static char ybuf[10]; /* holds tty id */ 2409536Seric register char *p; 2419536Seric extern char *ttyname(); 2429536Seric extern char *macvalue(); 2439536Seric extern char Version[]; 2449536Seric 2459536Seric /* 2469536Seric ** Give this envelope a reality. 2479536Seric ** I.e., an id, a transcript, and a creation time. 2489536Seric */ 2499536Seric 2509536Seric openxscript(CurEnv); 2519536Seric CurEnv->e_ctime = curtime(); 2529536Seric 2539536Seric /* 2549536Seric ** Set OutChannel to something useful if stdout isn't it. 2559536Seric ** This arranges that any extra stuff the mailer produces 2569536Seric ** gets sent back to the user on error (because it is 2579536Seric ** tucked away in the transcript). 2589536Seric */ 2599536Seric 2609536Seric if (OpMode == MD_DAEMON && QueueRun) 2619536Seric OutChannel = CurEnv->e_xfp; 2629536Seric 2639536Seric /* 2649536Seric ** Set up some basic system macros. 2659536Seric */ 2669536Seric 2679536Seric /* process id */ 2689536Seric (void) sprintf(pbuf, "%d", getpid()); 2699536Seric define('p', pbuf, CurEnv); 2709536Seric 2719536Seric /* hop count */ 2729536Seric (void) sprintf(cbuf, "%d", CurEnv->e_hopcount); 2739536Seric define('c', cbuf, CurEnv); 2749536Seric 2759536Seric /* time as integer, unix time, arpa time */ 27611932Seric settime(); 2779536Seric 2789536Seric /* tty name */ 2799536Seric if (macvalue('y', CurEnv) == NULL) 2809536Seric { 2819536Seric p = ttyname(2); 2829536Seric if (p != NULL) 2839536Seric { 2849536Seric if (rindex(p, '/') != NULL) 2859536Seric p = rindex(p, '/') + 1; 2869536Seric (void) strcpy(ybuf, p); 2879536Seric define('y', ybuf, CurEnv); 2889536Seric } 2899536Seric } 2909536Seric } 2919536Seric /* 29211932Seric ** SETTIME -- set the current time. 29311932Seric ** 29411932Seric ** Parameters: 29511932Seric ** none. 29611932Seric ** 29711932Seric ** Returns: 29811932Seric ** none. 29911932Seric ** 30011932Seric ** Side Effects: 30111932Seric ** Sets the various time macros -- $a, $b, $d, $t. 30211932Seric */ 30311932Seric 30411932Seric settime() 30511932Seric { 30611932Seric register char *p; 30711932Seric auto time_t now; 30811932Seric static char tbuf[20]; /* holds "current" time */ 30911932Seric static char dbuf[30]; /* holds ctime(tbuf) */ 31011932Seric register struct tm *tm; 31111932Seric extern char *arpadate(); 31211932Seric extern struct tm *gmtime(); 31311932Seric extern char *macvalue(); 31411932Seric 31511932Seric now = curtime(); 31611932Seric tm = gmtime(&now); 31711932Seric (void) sprintf(tbuf, "%02d%02d%02d%02d%02d", tm->tm_year, tm->tm_mon+1, 31811932Seric tm->tm_mday, tm->tm_hour, tm->tm_min); 31911932Seric define('t', tbuf, CurEnv); 32011932Seric (void) strcpy(dbuf, ctime(&now)); 32111932Seric *index(dbuf, '\n') = '\0'; 32211932Seric if (macvalue('d', CurEnv) == NULL) 32311932Seric define('d', dbuf, CurEnv); 32411932Seric p = newstr(arpadate(dbuf)); 32511932Seric if (macvalue('a', CurEnv) == NULL) 32611932Seric define('a', p, CurEnv); 32711932Seric define('b', p, CurEnv); 32811932Seric } 32911932Seric /* 3309536Seric ** QUEUENAME -- build a file name in the queue directory for this envelope. 3319536Seric ** 3329536Seric ** Assigns an id code if one does not already exist. 3339536Seric ** This code is very careful to avoid trashing existing files 3349536Seric ** under any circumstances. 3359536Seric ** We first create an nf file that is only used when 3369536Seric ** assigning an id. This file is always empty, so that 3379536Seric ** we can never accidently truncate an lf file. 3389536Seric ** 3399536Seric ** Parameters: 3409536Seric ** e -- envelope to build it in/from. 3419536Seric ** type -- the file type, used as the first character 3429536Seric ** of the file name. 3439536Seric ** 3449536Seric ** Returns: 3459536Seric ** a pointer to the new file name (in a static buffer). 3469536Seric ** 3479536Seric ** Side Effects: 3489536Seric ** Will create the lf and qf files if no id code is 3499536Seric ** already assigned. This will cause the envelope 3509536Seric ** to be modified. 3519536Seric */ 3529536Seric 3539536Seric char * 3549536Seric queuename(e, type) 3559536Seric register ENVELOPE *e; 3569536Seric char type; 3579536Seric { 3589536Seric static char buf[MAXNAME]; 3599536Seric static int pid = -1; 3609536Seric char c1 = 'A'; 3619536Seric char c2 = 'A'; 3629536Seric 3639536Seric if (e->e_id == NULL) 3649536Seric { 3659536Seric char qf[20]; 3669536Seric char lf[20]; 3679536Seric char nf[20]; 3689536Seric 3699536Seric /* find a unique id */ 3709536Seric if (pid != getpid()) 3719536Seric { 3729536Seric /* new process -- start back at "AA" */ 3739536Seric pid = getpid(); 3749536Seric c1 = 'A'; 3759536Seric c2 = 'A' - 1; 3769536Seric } 3779536Seric (void) sprintf(qf, "qfAA%05d", pid); 3789536Seric strcpy(lf, qf); 3799536Seric lf[0] = 'l'; 3809536Seric strcpy(nf, qf); 3819536Seric nf[0] = 'n'; 3829536Seric 3839536Seric while (c1 < '~' || c2 < 'Z') 3849536Seric { 3859536Seric int i; 3869536Seric 3879536Seric if (c2 >= 'Z') 3889536Seric { 3899536Seric c1++; 3909536Seric c2 = 'A' - 1; 3919536Seric } 3929536Seric qf[2] = lf[2] = nf[2] = c1; 3939536Seric qf[3] = lf[3] = nf[3] = ++c2; 3949536Seric # ifdef DEBUG 3959536Seric if (tTd(7, 20)) 3969536Seric printf("queuename: trying \"%s\"\n", nf); 3979536Seric # endif DEBUG 39810754Seric # ifdef QUEUE 3999536Seric if (access(lf, 0) >= 0 || access(qf, 0) >= 0) 4009536Seric continue; 4019536Seric errno = 0; 4029536Seric i = creat(nf, FileMode); 4039536Seric if (i < 0) 4049536Seric { 4059536Seric (void) unlink(nf); /* kernel bug */ 4069536Seric continue; 4079536Seric } 4089536Seric (void) close(i); 4099536Seric i = link(nf, lf); 4109536Seric (void) unlink(nf); 4119536Seric if (i < 0) 4129536Seric continue; 4139536Seric if (link(lf, qf) >= 0) 4149536Seric break; 4159536Seric (void) unlink(lf); 41610754Seric # else QUEUE 41710754Seric if (close(creat(qf, FileMode)) < 0) 41810754Seric continue; 41910754Seric # endif QUEUE 4209536Seric } 4219536Seric if (c1 >= '~' && c2 >= 'Z') 4229536Seric { 4239536Seric syserr("queuename: Cannot create \"%s\" in \"%s\"", 4249536Seric lf, QueueDir); 4259536Seric exit(EX_OSERR); 4269536Seric } 4279536Seric e->e_id = newstr(&qf[2]); 4289536Seric define('i', e->e_id, e); 4299536Seric # ifdef DEBUG 4309536Seric if (tTd(7, 1)) 4319536Seric printf("queuename: assigned id %s, env=%x\n", e->e_id, e); 43210196Seric # ifdef LOG 43310196Seric if (LogLevel > 16) 43410196Seric syslog(LOG_DEBUG, "%s: assigned id", e->e_id); 43510196Seric # endif LOG 4369536Seric # endif DEBUG 4379536Seric } 4389536Seric 4399536Seric if (type == '\0') 4409536Seric return (NULL); 4419536Seric (void) sprintf(buf, "%cf%s", type, e->e_id); 4429536Seric # ifdef DEBUG 4439536Seric if (tTd(7, 2)) 4449536Seric printf("queuename: %s\n", buf); 4459536Seric # endif DEBUG 4469536Seric return (buf); 4479536Seric } 4489536Seric /* 4499536Seric ** OPENXSCRIPT -- Open transcript file 4509536Seric ** 4519536Seric ** Creates a transcript file for possible eventual mailing or 4529536Seric ** sending back. 4539536Seric ** 4549536Seric ** Parameters: 4559536Seric ** e -- the envelope to create the transcript in/for. 4569536Seric ** 4579536Seric ** Returns: 4589536Seric ** none 4599536Seric ** 4609536Seric ** Side Effects: 4619536Seric ** Creates the transcript file. 4629536Seric */ 4639536Seric 4649536Seric openxscript(e) 4659536Seric register ENVELOPE *e; 4669536Seric { 4679536Seric register char *p; 4689536Seric 46910196Seric # ifdef LOG 47010196Seric if (LogLevel > 19) 47110196Seric syslog(LOG_DEBUG, "%s: openx%s", e->e_id, e->e_xfp == NULL ? "" : " (no)"); 47210196Seric # endif LOG 4739536Seric if (e->e_xfp != NULL) 4749536Seric return; 4759536Seric p = queuename(e, 'x'); 4769536Seric e->e_xfp = fopen(p, "w"); 4779536Seric if (e->e_xfp == NULL) 4789536Seric syserr("Can't create %s", p); 4799536Seric else 4809536Seric (void) chmod(p, 0644); 4819536Seric } 4829536Seric /* 48310196Seric ** CLOSEXSCRIPT -- close the transcript file. 48410196Seric ** 48510196Seric ** Parameters: 48610196Seric ** e -- the envelope containing the transcript to close. 48710196Seric ** 48810196Seric ** Returns: 48910196Seric ** none. 49010196Seric ** 49110196Seric ** Side Effects: 49210196Seric ** none. 49310196Seric */ 49410196Seric 49510196Seric closexscript(e) 49610196Seric register ENVELOPE *e; 49710196Seric { 49810196Seric if (e->e_xfp == NULL) 49910196Seric return; 50010196Seric (void) fclose(e->e_xfp); 50110196Seric e->e_xfp = NULL; 50210196Seric } 50310196Seric /* 5049536Seric ** SETSENDER -- set the person who this message is from 5059536Seric ** 5069536Seric ** Under certain circumstances allow the user to say who 5079536Seric ** s/he is (using -f or -r). These are: 5089536Seric ** 1. The user's uid is zero (root). 5099536Seric ** 2. The user's login name is in an approved list (typically 5109536Seric ** from a network server). 5119536Seric ** 3. The address the user is trying to claim has a 5129536Seric ** "!" character in it (since #2 doesn't do it for 5139536Seric ** us if we are dialing out for UUCP). 5149536Seric ** A better check to replace #3 would be if the 5159536Seric ** effective uid is "UUCP" -- this would require me 5169536Seric ** to rewrite getpwent to "grab" uucp as it went by, 5179536Seric ** make getname more nasty, do another passwd file 5189536Seric ** scan, or compile the UID of "UUCP" into the code, 5199536Seric ** all of which are reprehensible. 5209536Seric ** 5219536Seric ** Assuming all of these fail, we figure out something 5229536Seric ** ourselves. 5239536Seric ** 5249536Seric ** Parameters: 5259536Seric ** from -- the person we would like to believe this message 5269536Seric ** is from, as specified on the command line. 5279536Seric ** 5289536Seric ** Returns: 5299536Seric ** none. 5309536Seric ** 5319536Seric ** Side Effects: 5329536Seric ** sets sendmail's notion of who the from person is. 5339536Seric */ 5349536Seric 5359536Seric setsender(from) 5369536Seric char *from; 5379536Seric { 5389536Seric register char **pvp; 5399536Seric register struct passwd *pw = NULL; 5409536Seric char *realname = NULL; 5419536Seric char buf[MAXNAME]; 542*16913Seric char pvpbuf[PSBUFSIZE]; 5439536Seric extern char *macvalue(); 5449536Seric extern char **prescan(); 5459536Seric extern bool safefile(); 5469536Seric extern char *FullName; 5479536Seric 5489536Seric # ifdef DEBUG 5499536Seric if (tTd(45, 1)) 55014786Seric printf("setsender(%s)\n", from == NULL ? "" : from); 5519536Seric # endif DEBUG 5529536Seric 5539536Seric /* 5549536Seric ** Figure out the real user executing us. 5559536Seric ** Username can return errno != 0 on non-errors. 5569536Seric */ 5579536Seric 5589536Seric if (QueueRun || OpMode == MD_SMTP || OpMode == MD_ARPAFTP) 5599536Seric realname = from; 5609536Seric if (realname == NULL || realname[0] == '\0') 5619536Seric { 5629536Seric extern char *username(); 5639536Seric 5649536Seric realname = username(); 5659536Seric errno = 0; 5669536Seric } 5679536Seric if (realname == NULL || realname[0] == '\0') 5689536Seric { 5699536Seric extern struct passwd *getpwuid(); 5709536Seric 5719536Seric pw = getpwuid(getruid()); 5729536Seric if (pw != NULL) 5739536Seric realname = pw->pw_name; 5749536Seric } 5759536Seric if (realname == NULL || realname[0] == '\0') 5769536Seric { 5779536Seric syserr("Who are you?"); 5789536Seric realname = "root"; 5799536Seric } 5809536Seric 5819536Seric /* 5829536Seric ** Determine if this real person is allowed to alias themselves. 5839536Seric */ 5849536Seric 5859536Seric if (from != NULL) 5869536Seric { 5879536Seric extern bool trusteduser(); 5889536Seric 5899536Seric if (!trusteduser(realname) && 5909536Seric # ifdef DEBUG 5919536Seric (!tTd(1, 9) || getuid() != geteuid()) && 5929536Seric # endif DEBUG 5939536Seric index(from, '!') == NULL && getuid() != 0) 5949536Seric { 5959536Seric /* network sends -r regardless (why why why?) */ 5969536Seric /* syserr("%s, you cannot use the -f flag", realname); */ 5979536Seric from = NULL; 5989536Seric } 59911615Seric else if (strcmp(from, realname) != 0) 60011615Seric pw = NULL; 6019536Seric } 6029536Seric 6039536Seric SuprErrs = TRUE; 60411447Seric if (from == NULL || parseaddr(from, &CurEnv->e_from, 1, '\0') == NULL) 6059536Seric { 6069536Seric from = newstr(realname); 60711447Seric (void) parseaddr(from, &CurEnv->e_from, 1, '\0'); 6089536Seric } 6099536Seric else 6109536Seric FromFlag = TRUE; 6119536Seric CurEnv->e_from.q_flags |= QDONTSEND; 61216162Seric loweraddr(&CurEnv->e_from); 6139536Seric SuprErrs = FALSE; 6149536Seric 6159536Seric if (pw == NULL && CurEnv->e_from.q_mailer == LocalMailer) 6169536Seric { 6179536Seric extern struct passwd *getpwnam(); 6189536Seric 6199536Seric pw = getpwnam(CurEnv->e_from.q_user); 6209536Seric } 6219536Seric 6229536Seric /* 6239536Seric ** Process passwd file entry. 6249536Seric */ 6259536Seric 6269536Seric if (pw != NULL) 6279536Seric { 6289536Seric /* extract home directory */ 6299536Seric CurEnv->e_from.q_home = newstr(pw->pw_dir); 63016481Seric define('z', CurEnv->e_from.q_home, CurEnv); 6319536Seric 63211625Seric /* extract user and group id */ 63311625Seric CurEnv->e_from.q_uid = pw->pw_uid; 63411625Seric CurEnv->e_from.q_gid = pw->pw_gid; 63511625Seric 6369536Seric /* if the user has given fullname already, don't redefine */ 6379536Seric if (FullName == NULL) 6389536Seric FullName = macvalue('x', CurEnv); 63911932Seric if (FullName != NULL && FullName[0] == '\0') 6409536Seric FullName = NULL; 6419536Seric 6429536Seric /* extract full name from passwd file */ 6439582Seric if (FullName == NULL && pw->pw_gecos != NULL && 6449582Seric strcmp(pw->pw_name, CurEnv->e_from.q_user) == 0) 6459536Seric { 6469536Seric buildfname(pw->pw_gecos, CurEnv->e_from.q_user, buf); 6479536Seric if (buf[0] != '\0') 6489536Seric FullName = newstr(buf); 6499536Seric } 6509536Seric if (FullName != NULL) 6519536Seric define('x', FullName, CurEnv); 6529536Seric } 65311625Seric else 65411625Seric { 6559536Seric #ifndef V6 65611625Seric if (CurEnv->e_from.q_home == NULL) 65711625Seric CurEnv->e_from.q_home = getenv("HOME"); 6589536Seric #endif V6 65911625Seric CurEnv->e_from.q_uid = getuid(); 66011625Seric CurEnv->e_from.q_gid = getgid(); 66111625Seric } 66211625Seric 6639536Seric if (CurEnv->e_from.q_uid != 0) 6649536Seric { 6659536Seric DefUid = CurEnv->e_from.q_uid; 6669536Seric DefGid = CurEnv->e_from.q_gid; 6679536Seric } 6689536Seric 6699536Seric /* 6709536Seric ** Rewrite the from person to dispose of possible implicit 6719536Seric ** links in the net. 6729536Seric */ 6739536Seric 674*16913Seric pvp = prescan(from, '\0', pvpbuf); 6759536Seric if (pvp == NULL) 6769536Seric { 6779536Seric syserr("cannot prescan from (%s)", from); 6789536Seric finis(); 6799536Seric } 6809536Seric rewrite(pvp, 3); 6819536Seric rewrite(pvp, 1); 68211286Seric rewrite(pvp, 4); 6839536Seric cataddr(pvp, buf, sizeof buf); 6849536Seric define('f', newstr(buf), CurEnv); 6859536Seric 6869536Seric /* save the domain spec if this mailer wants it */ 68710690Seric if (bitnset(M_CANONICAL, CurEnv->e_from.q_mailer->m_flags)) 6889536Seric { 6899536Seric extern char **copyplist(); 6909536Seric 6919536Seric while (*pvp != NULL && strcmp(*pvp, "@") != 0) 6929536Seric pvp++; 6939536Seric if (*pvp != NULL) 6949536Seric CurEnv->e_fromdomain = copyplist(pvp, TRUE); 6959536Seric } 6969536Seric } 6979536Seric /* 6989536Seric ** TRUSTEDUSER -- tell us if this user is to be trusted. 6999536Seric ** 7009536Seric ** Parameters: 7019536Seric ** user -- the user to be checked. 7029536Seric ** 7039536Seric ** Returns: 7049536Seric ** TRUE if the user is in an approved list. 7059536Seric ** FALSE otherwise. 7069536Seric ** 7079536Seric ** Side Effects: 7089536Seric ** none. 7099536Seric */ 7109536Seric 7119536Seric bool 7129536Seric trusteduser(user) 7139536Seric char *user; 7149536Seric { 7159536Seric register char **ulist; 7169536Seric extern char *TrustedUsers[]; 7179536Seric 7189536Seric for (ulist = TrustedUsers; *ulist != NULL; ulist++) 7199536Seric if (strcmp(*ulist, user) == 0) 7209536Seric return (TRUE); 7219536Seric return (FALSE); 7229536Seric } 723