122708Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822708Sdist 933731Sbostic # include "sendmail.h" 1022708Sdist 1133731Sbostic #ifndef lint 1233731Sbostic #ifdef QUEUE 13*58050Seric static char sccsid[] = "@(#)queue.c 6.12 (Berkeley) 02/18/93 (with queueing)"; 1433731Sbostic #else 15*58050Seric static char sccsid[] = "@(#)queue.c 6.12 (Berkeley) 02/18/93 (without queueing)"; 1633731Sbostic #endif 1733731Sbostic #endif /* not lint */ 1833731Sbostic 194632Seric # include <sys/stat.h> 2013707Ssam # include <sys/dir.h> 2157948Seric # include <sys/file.h> 224634Seric # include <signal.h> 234632Seric # include <errno.h> 2440973Sbostic # include <pwd.h> 2551937Seric # include <fcntl.h> 2657977Seric # ifndef MAXNAMLEN 2757736Seric # include <dirent.h> 2857736Seric # endif 294632Seric 3033731Sbostic # ifdef QUEUE 314632Seric 324632Seric /* 339377Seric ** Work queue. 349377Seric */ 359377Seric 369377Seric struct work 379377Seric { 389377Seric char *w_name; /* name of control file */ 399377Seric long w_pri; /* priority of message, see below */ 4025013Seric time_t w_ctime; /* creation time of message */ 419377Seric struct work *w_next; /* next in queue */ 429377Seric }; 439377Seric 449377Seric typedef struct work WORK; 459377Seric 469377Seric WORK *WorkQ; /* queue of things to be done */ 479377Seric /* 484632Seric ** QUEUEUP -- queue a message up for future transmission. 494632Seric ** 504632Seric ** Parameters: 516980Seric ** e -- the envelope to queue up. 526999Seric ** queueall -- if TRUE, queue all addresses, rather than 536999Seric ** just those with the QQUEUEUP flag set. 549377Seric ** announce -- if TRUE, tell when you are queueing up. 554632Seric ** 564632Seric ** Returns: 5751920Seric ** none. 584632Seric ** 594632Seric ** Side Effects: 609377Seric ** The current request are saved in a control file. 6151920Seric ** The queue file is left locked. 624632Seric */ 634632Seric 649377Seric queueup(e, queueall, announce) 656980Seric register ENVELOPE *e; 666999Seric bool queueall; 679377Seric bool announce; 684632Seric { 697812Seric char *qf; 707812Seric register FILE *tfp; 714632Seric register HDR *h; 725007Seric register ADDRESS *q; 7351920Seric int fd; 7451920Seric int i; 7551920Seric bool newid; 7653400Seric register char *p; 7710173Seric MAILER nullmailer; 7854974Seric ADDRESS *lastctladdr; 7954975Seric static ADDRESS *nullctladdr = NULL; 8051920Seric char buf[MAXLINE], tf[MAXLINE]; 8153400Seric extern char *macvalue(); 8254974Seric extern ADDRESS *getctladdr(); 834632Seric 845037Seric /* 8554975Seric ** If we don't have nullctladdr, create one 8654975Seric */ 8754975Seric 8854975Seric if (nullctladdr == NULL) 8954975Seric { 9054975Seric nullctladdr = (ADDRESS *) xalloc(sizeof *nullctladdr); 9154975Seric bzero((char *) nullctladdr, sizeof nullctladdr); 9254975Seric } 9354975Seric 9454975Seric /* 9517477Seric ** Create control file. 965037Seric */ 974632Seric 9851920Seric newid = (e->e_id == NULL); 9951920Seric strcpy(tf, queuename(e, 't')); 10051920Seric tfp = e->e_lockfp; 10151920Seric if (tfp == NULL) 10251920Seric newid = FALSE; 10351920Seric if (newid) 10451835Seric { 10551920Seric tfp = e->e_lockfp; 10651920Seric } 10751920Seric else 10851920Seric { 10951920Seric /* get a locked tf file */ 11051920Seric for (i = 100; --i >= 0; ) 11151835Seric { 11251937Seric # ifdef LOCKF 11351937Seric struct flock lfd; 11451937Seric # endif 11551937Seric 11651920Seric fd = open(tf, O_CREAT|O_WRONLY|O_EXCL, FileMode); 11751920Seric if (fd < 0) 11851835Seric { 11951920Seric if (errno == EEXIST) 12051920Seric continue; 12151920Seric syserr("queueup: cannot create temp file %s", tf); 12251920Seric return; 12341636Srick } 12451835Seric # ifdef LOCKF 12551937Seric lfd.l_type = F_WRLCK; 12651937Seric lfd.l_whence = lfd.l_start = lfd.l_len = 0; 12751937Seric if (fcntl(fd, F_SETLK, &lfd) >= 0) 12851920Seric break; 12951920Seric if (errno != EACCES && errno != EAGAIN) 13051920Seric syserr("cannot lockf(%s)", tf); 13151835Seric # else 13251920Seric if (flock(fd, LOCK_EX|LOCK_NB) >= 0) 13351920Seric break; 13451920Seric if (errno != EWOULDBLOCK) 13551920Seric syserr("cannot flock(%s)", tf); 13651835Seric # endif 13751920Seric close(fd); 13841636Srick } 13941636Srick 14051920Seric tfp = fdopen(fd, "w"); 14151920Seric } 1424632Seric 1437677Seric if (tTd(40, 1)) 14417468Seric printf("queueing %s\n", e->e_id); 1454632Seric 1464632Seric /* 1476980Seric ** If there is no data file yet, create one. 1486980Seric */ 1496980Seric 1506980Seric if (e->e_df == NULL) 1516980Seric { 1526980Seric register FILE *dfp; 1539389Seric extern putbody(); 1546980Seric 1557812Seric e->e_df = newstr(queuename(e, 'd')); 15640934Srick fd = open(e->e_df, O_WRONLY|O_CREAT, FileMode); 15740934Srick if (fd < 0) 1586980Seric { 1596980Seric syserr("queueup: cannot create %s", e->e_df); 16051920Seric if (!newid) 16151920Seric (void) fclose(tfp); 16251920Seric return; 1636980Seric } 16440934Srick dfp = fdopen(fd, "w"); 16510173Seric (*e->e_putbody)(dfp, ProgMailer, e); 1667009Seric (void) fclose(dfp); 1679389Seric e->e_putbody = putbody; 1686980Seric } 1696980Seric 1706980Seric /* 1714632Seric ** Output future work requests. 17225687Seric ** Priority and creation time should be first, since 17325687Seric ** they are required by orderq. 1744632Seric */ 1754632Seric 1769377Seric /* output message priority */ 1779377Seric fprintf(tfp, "P%ld\n", e->e_msgpriority); 1789377Seric 1799630Seric /* output creation time */ 1809630Seric fprintf(tfp, "T%ld\n", e->e_ctime); 1819630Seric 1824632Seric /* output name of data file */ 1837812Seric fprintf(tfp, "D%s\n", e->e_df); 1844632Seric 18510108Seric /* message from envelope, if it exists */ 18610108Seric if (e->e_message != NULL) 18710108Seric fprintf(tfp, "M%s\n", e->e_message); 18810108Seric 18953400Seric /* $r and $s macro values */ 19053400Seric if ((p = macvalue('r', e)) != NULL) 19153400Seric fprintf(tfp, "$r%s\n", p); 19253400Seric if ((p = macvalue('s', e)) != NULL) 19353400Seric fprintf(tfp, "$s%s\n", p); 19453400Seric 1954632Seric /* output name of sender */ 1967812Seric fprintf(tfp, "S%s\n", e->e_from.q_paddr); 1974632Seric 19855360Seric /* output list of error recipients */ 19955360Seric lastctladdr = NULL; 20055360Seric for (q = e->e_errorqueue; q != NULL; q = q->q_next) 20155360Seric { 20255360Seric if (!bitset(QDONTSEND, q->q_flags)) 20355360Seric { 20455360Seric ADDRESS *ctladdr; 20555360Seric 20655360Seric ctladdr = getctladdr(q); 20755360Seric if (ctladdr == NULL && q->q_alias != NULL) 20855360Seric ctladdr = nullctladdr; 20955360Seric if (ctladdr != lastctladdr) 21055360Seric { 21155360Seric printctladdr(ctladdr, tfp); 21255360Seric lastctladdr = ctladdr; 21355360Seric } 21455360Seric fprintf(tfp, "E%s\n", q->q_paddr); 21555360Seric } 21655360Seric } 21755360Seric 2184632Seric /* output list of recipient addresses */ 2196980Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 2204632Seric { 22147284Seric if (queueall ? !bitset(QDONTSEND|QSENT, q->q_flags) : 2227763Seric bitset(QQUEUEUP, q->q_flags)) 2238245Seric { 22454974Seric ADDRESS *ctladdr; 22540973Sbostic 22654975Seric ctladdr = getctladdr(q); 22754975Seric if (ctladdr == NULL && q->q_alias != NULL) 22854975Seric ctladdr = nullctladdr; 22954975Seric if (ctladdr != lastctladdr) 23054974Seric { 23154974Seric printctladdr(ctladdr, tfp); 23254974Seric lastctladdr = ctladdr; 23354974Seric } 2347812Seric fprintf(tfp, "R%s\n", q->q_paddr); 2359377Seric if (announce) 2369377Seric { 2379377Seric e->e_to = q->q_paddr; 2389377Seric message(Arpa_Info, "queued"); 23958020Seric if (LogLevel > 8) 24054967Seric logdelivery("queued", e); 2419377Seric e->e_to = NULL; 2429377Seric } 2439387Seric if (tTd(40, 1)) 2449387Seric { 2459387Seric printf("queueing "); 2469387Seric printaddr(q, FALSE); 2479387Seric } 2488245Seric } 2494632Seric } 2504632Seric 2519377Seric /* 2529377Seric ** Output headers for this message. 2539377Seric ** Expand macros completely here. Queue run will deal with 2549377Seric ** everything as absolute headers. 2559377Seric ** All headers that must be relative to the recipient 2569377Seric ** can be cracked later. 25710173Seric ** We set up a "null mailer" -- i.e., a mailer that will have 25810173Seric ** no effect on the addresses as they are output. 2599377Seric */ 2609377Seric 26110686Seric bzero((char *) &nullmailer, sizeof nullmailer); 26258020Seric nullmailer.m_re_rwset = nullmailer.m_rh_rwset = 26358020Seric nullmailer.m_se_rwset = nullmailer.m_sh_rwset = -1; 26410349Seric nullmailer.m_eol = "\n"; 26510173Seric 266*58050Seric define('g', "\201f", e); 2676980Seric for (h = e->e_header; h != NULL; h = h->h_link) 2684632Seric { 26910686Seric extern bool bitzerop(); 27010686Seric 27112015Seric /* don't output null headers */ 2724632Seric if (h->h_value == NULL || h->h_value[0] == '\0') 2734632Seric continue; 27412015Seric 27512015Seric /* don't output resent headers on non-resent messages */ 27612015Seric if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags)) 27712015Seric continue; 27812015Seric 27912015Seric /* output this header */ 2807812Seric fprintf(tfp, "H"); 28112015Seric 28212015Seric /* if conditional, output the set of conditions */ 28310686Seric if (!bitzerop(h->h_mflags) && bitset(H_CHECK|H_ACHECK, h->h_flags)) 28410686Seric { 28510686Seric int j; 28610686Seric 28723098Seric (void) putc('?', tfp); 28810686Seric for (j = '\0'; j <= '\177'; j++) 28910686Seric if (bitnset(j, h->h_mflags)) 29023098Seric (void) putc(j, tfp); 29123098Seric (void) putc('?', tfp); 29210686Seric } 29312015Seric 29412015Seric /* output the header: expand macros, convert addresses */ 2957763Seric if (bitset(H_DEFAULT, h->h_flags)) 2967763Seric { 2977763Seric (void) expand(h->h_value, buf, &buf[sizeof buf], e); 2988236Seric fprintf(tfp, "%s: %s\n", h->h_field, buf); 2997763Seric } 3008245Seric else if (bitset(H_FROM|H_RCPT, h->h_flags)) 3019348Seric { 30255012Seric commaize(h, h->h_value, tfp, 30355012Seric bitset(EF_OLDSTYLE, e->e_flags), 30455012Seric &nullmailer, e); 3059348Seric } 3067763Seric else 3078245Seric fprintf(tfp, "%s: %s\n", h->h_field, h->h_value); 3084632Seric } 3094632Seric 3104632Seric /* 3114632Seric ** Clean up. 3124632Seric */ 3134632Seric 31451920Seric if (!newid) 31551920Seric { 31651920Seric qf = queuename(e, 'q'); 31751920Seric if (rename(tf, qf) < 0) 31851920Seric syserr("cannot rename(%s, %s), df=%s", tf, qf, e->e_df); 31951920Seric if (e->e_lockfp != NULL) 32051920Seric (void) fclose(e->e_lockfp); 32151920Seric e->e_lockfp = tfp; 32251920Seric } 32351920Seric else 32451920Seric qf = tf; 32541636Srick errno = 0; 3267391Seric 3277677Seric # ifdef LOG 3287677Seric /* save log info */ 32958020Seric if (LogLevel > 79) 3307878Seric syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df); 33156795Seric # endif /* LOG */ 33240934Srick fflush(tfp); 33351920Seric return; 3344632Seric } 33554974Seric 33654974Seric printctladdr(a, tfp) 33754974Seric ADDRESS *a; 33854974Seric FILE *tfp; 33954974Seric { 34054974Seric char *u; 34154974Seric struct passwd *pw; 34254974Seric extern struct passwd *getpwuid(); 34354974Seric 34454974Seric if (a == NULL) 34554974Seric { 34654974Seric fprintf(tfp, "C\n"); 34754974Seric return; 34854974Seric } 34954974Seric if (a->q_uid == 0 || (pw = getpwuid(a->q_uid)) == NULL) 35054974Seric u = DefUser; 35154974Seric else 35254974Seric u = pw->pw_name; 35354974Seric fprintf(tfp, "C%s\n", u); 35454974Seric } 35554974Seric 3564632Seric /* 3574632Seric ** RUNQUEUE -- run the jobs in the queue. 3584632Seric ** 3594632Seric ** Gets the stuff out of the queue in some presumably logical 3604632Seric ** order and processes them. 3614632Seric ** 3624632Seric ** Parameters: 36324941Seric ** forkflag -- TRUE if the queue scanning should be done in 36424941Seric ** a child process. We double-fork so it is not our 36524941Seric ** child and we don't have to clean up after it. 3664632Seric ** 3674632Seric ** Returns: 3684632Seric ** none. 3694632Seric ** 3704632Seric ** Side Effects: 3714632Seric ** runs things in the mail queue. 3724632Seric */ 3734632Seric 37455360Seric ENVELOPE QueueEnvelope; /* the queue run envelope */ 37555360Seric 37655360Seric runqueue(forkflag) 3774639Seric bool forkflag; 3784632Seric { 37924953Seric extern bool shouldqueue(); 38055360Seric register ENVELOPE *e; 38155360Seric extern ENVELOPE BlankEnvelope; 38255360Seric extern ENVELOPE *newenvelope(); 38324953Seric 3847466Seric /* 38524953Seric ** If no work will ever be selected, don't even bother reading 38624953Seric ** the queue. 38724953Seric */ 38824953Seric 38951920Seric CurrentLA = getla(); /* get load average */ 39040934Srick 39157438Seric if (shouldqueue(-100000000L, curtime())) 39224953Seric { 39324953Seric if (Verbose) 39424953Seric printf("Skipping queue run -- load average too high\n"); 39555360Seric return; 39624953Seric } 39724953Seric 39824953Seric /* 3997466Seric ** See if we want to go off and do other useful work. 4007466Seric */ 4014639Seric 4024639Seric if (forkflag) 4034639Seric { 4047943Seric int pid; 4057943Seric 4067943Seric pid = dofork(); 4077943Seric if (pid != 0) 4084639Seric { 40946928Sbostic extern void reapchild(); 41025184Seric 4117943Seric /* parent -- pick up intermediate zombie */ 41225184Seric #ifndef SIGCHLD 4139377Seric (void) waitfor(pid); 41456795Seric #else /* SIGCHLD */ 41525184Seric (void) signal(SIGCHLD, reapchild); 41656795Seric #endif /* SIGCHLD */ 4177690Seric if (QueueIntvl != 0) 4189348Seric (void) setevent(QueueIntvl, runqueue, TRUE); 4194639Seric return; 4204639Seric } 4217943Seric /* child -- double fork */ 42225184Seric #ifndef SIGCHLD 4237943Seric if (fork() != 0) 4247943Seric exit(EX_OK); 42556795Seric #else /* SIGCHLD */ 42625184Seric (void) signal(SIGCHLD, SIG_DFL); 42756795Seric #endif /* SIGCHLD */ 4284639Seric } 42924941Seric 43040934Srick setproctitle("running queue: %s", QueueDir); 43157731Seric ForceMail = TRUE; 43224941Seric 4337876Seric # ifdef LOG 43458020Seric if (LogLevel > 69) 43555360Seric syslog(LOG_DEBUG, "runqueue %s, pid=%d, forkflag=%d", 43655360Seric QueueDir, getpid(), forkflag); 43756795Seric # endif /* LOG */ 4384639Seric 4397466Seric /* 44010205Seric ** Release any resources used by the daemon code. 44110205Seric */ 44210205Seric 44310205Seric # ifdef DAEMON 44410205Seric clrdaemon(); 44556795Seric # endif /* DAEMON */ 44610205Seric 44710205Seric /* 44855360Seric ** Create ourselves an envelope 44955360Seric */ 45055360Seric 45155360Seric CurEnv = &QueueEnvelope; 45255360Seric e = newenvelope(&QueueEnvelope); 45355360Seric e->e_flags = BlankEnvelope.e_flags; 45455360Seric 45555360Seric /* 45627175Seric ** Make sure the alias database is open. 45727175Seric */ 45827175Seric 45955012Seric initaliases(AliasFile, FALSE, e); 46027175Seric 46127175Seric /* 4627466Seric ** Start making passes through the queue. 4637466Seric ** First, read and sort the entire queue. 4647466Seric ** Then, process the work in that order. 4657466Seric ** But if you take too long, start over. 4667466Seric */ 4677466Seric 4687943Seric /* order the existing work requests */ 46924954Seric (void) orderq(FALSE); 4707690Seric 4717943Seric /* process them once at a time */ 4727943Seric while (WorkQ != NULL) 4734639Seric { 4747943Seric WORK *w = WorkQ; 4757881Seric 4767943Seric WorkQ = WorkQ->w_next; 47755012Seric dowork(w, e); 4787943Seric free(w->w_name); 4797943Seric free((char *) w); 4804639Seric } 48129866Seric 48229866Seric /* exit without the usual cleanup */ 48355467Seric e->e_id = NULL; 48455467Seric finis(); 4854634Seric } 4864634Seric /* 4874632Seric ** ORDERQ -- order the work queue. 4884632Seric ** 4894632Seric ** Parameters: 49024941Seric ** doall -- if set, include everything in the queue (even 49124941Seric ** the jobs that cannot be run because the load 49224941Seric ** average is too high). Otherwise, exclude those 49324941Seric ** jobs. 4944632Seric ** 4954632Seric ** Returns: 49610121Seric ** The number of request in the queue (not necessarily 49710121Seric ** the number of requests in WorkQ however). 4984632Seric ** 4994632Seric ** Side Effects: 5004632Seric ** Sets WorkQ to the queue of available work, in order. 5014632Seric */ 5024632Seric 50325687Seric # define NEED_P 001 50425687Seric # define NEED_T 002 5054632Seric 50624941Seric orderq(doall) 50724941Seric bool doall; 5084632Seric { 5096625Sglickman register struct direct *d; 5104632Seric register WORK *w; 5116625Sglickman DIR *f; 5124632Seric register int i; 51325687Seric WORK wlist[QUEUESIZE+1]; 51410070Seric int wn = -1; 5154632Seric extern workcmpf(); 5164632Seric 5174632Seric /* clear out old WorkQ */ 5184632Seric for (w = WorkQ; w != NULL; ) 5194632Seric { 5204632Seric register WORK *nw = w->w_next; 5214632Seric 5224632Seric WorkQ = nw; 5234632Seric free(w->w_name); 5244632Seric free((char *) w); 5254632Seric w = nw; 5264632Seric } 5274632Seric 5284632Seric /* open the queue directory */ 5298148Seric f = opendir("."); 5304632Seric if (f == NULL) 5314632Seric { 5328148Seric syserr("orderq: cannot open \"%s\" as \".\"", QueueDir); 53310070Seric return (0); 5344632Seric } 5354632Seric 5364632Seric /* 5374632Seric ** Read the work directory. 5384632Seric */ 5394632Seric 54010070Seric while ((d = readdir(f)) != NULL) 5414632Seric { 5429377Seric FILE *cf; 5434632Seric char lbuf[MAXNAME]; 54457642Seric extern bool shouldqueue(); 5454632Seric 5464632Seric /* is this an interesting entry? */ 5477812Seric if (d->d_name[0] != 'q' || d->d_name[1] != 'f') 5484632Seric continue; 5494632Seric 55058020Seric if (strlen(d->d_name) != 9) 55158020Seric { 55258020Seric if (Verbose) 55358020Seric printf("orderq: bogus qf name %s\n", d->d_name); 55458020Seric #ifdef LOG 55558020Seric if (LogLevel > 3) 55658020Seric syslog(LOG_NOTICE, "orderq: bogus qf name %s", 55758020Seric d->d_name); 55858020Seric #endif 55958020Seric if (strlen(d->d_name) >= MAXNAME) 56058020Seric d->d_name[MAXNAME - 1] = '\0'; 56158020Seric strcpy(lbuf, d->d_name); 56258020Seric lbuf[0] = 'Q'; 56358020Seric (void) rename(d->d_name, lbuf); 56458020Seric continue; 56558020Seric } 56658020Seric 56710070Seric /* yes -- open control file (if not too many files) */ 56825687Seric if (++wn >= QUEUESIZE) 56910070Seric continue; 5708148Seric cf = fopen(d->d_name, "r"); 5714632Seric if (cf == NULL) 5724632Seric { 5737055Seric /* this may be some random person sending hir msgs */ 5747055Seric /* syserr("orderq: cannot open %s", cbuf); */ 57510090Seric if (tTd(41, 2)) 57610090Seric printf("orderq: cannot open %s (%d)\n", 57710090Seric d->d_name, errno); 5787055Seric errno = 0; 57910090Seric wn--; 5804632Seric continue; 5814632Seric } 58225687Seric w = &wlist[wn]; 58325687Seric w->w_name = newstr(d->d_name); 5844632Seric 58525027Seric /* make sure jobs in creation don't clog queue */ 58625687Seric w->w_pri = 0x7fffffff; 58725687Seric w->w_ctime = 0; 58825027Seric 5894632Seric /* extract useful information */ 59025687Seric i = NEED_P | NEED_T; 59125687Seric while (i != 0 && fgets(lbuf, sizeof lbuf, cf) != NULL) 5924632Seric { 59324954Seric extern long atol(); 59424954Seric 59524941Seric switch (lbuf[0]) 5964632Seric { 59724941Seric case 'P': 59825687Seric w->w_pri = atol(&lbuf[1]); 59925687Seric i &= ~NEED_P; 6004632Seric break; 60125013Seric 60225013Seric case 'T': 60325687Seric w->w_ctime = atol(&lbuf[1]); 60425687Seric i &= ~NEED_T; 60525013Seric break; 6064632Seric } 6074632Seric } 6084632Seric (void) fclose(cf); 60924953Seric 61057438Seric if (!doall && shouldqueue(w->w_pri, w->w_ctime)) 61124953Seric { 61224953Seric /* don't even bother sorting this job in */ 61324953Seric wn--; 61424953Seric } 6154632Seric } 6166625Sglickman (void) closedir(f); 61710090Seric wn++; 6184632Seric 6194632Seric /* 6204632Seric ** Sort the work directory. 6214632Seric */ 6224632Seric 62325687Seric qsort((char *) wlist, min(wn, QUEUESIZE), sizeof *wlist, workcmpf); 6244632Seric 6254632Seric /* 6264632Seric ** Convert the work list into canonical form. 6279377Seric ** Should be turning it into a list of envelopes here perhaps. 6284632Seric */ 6294632Seric 63024981Seric WorkQ = NULL; 63125687Seric for (i = min(wn, QUEUESIZE); --i >= 0; ) 6324632Seric { 6334632Seric w = (WORK *) xalloc(sizeof *w); 6344632Seric w->w_name = wlist[i].w_name; 6354632Seric w->w_pri = wlist[i].w_pri; 63625013Seric w->w_ctime = wlist[i].w_ctime; 63724981Seric w->w_next = WorkQ; 63824981Seric WorkQ = w; 6394632Seric } 6404632Seric 6417677Seric if (tTd(40, 1)) 6424632Seric { 6434632Seric for (w = WorkQ; w != NULL; w = w->w_next) 6445037Seric printf("%32s: pri=%ld\n", w->w_name, w->w_pri); 6454632Seric } 64610070Seric 64710090Seric return (wn); 6484632Seric } 6494632Seric /* 6507677Seric ** WORKCMPF -- compare function for ordering work. 6514632Seric ** 6524632Seric ** Parameters: 6534632Seric ** a -- the first argument. 6544632Seric ** b -- the second argument. 6554632Seric ** 6564632Seric ** Returns: 65724981Seric ** -1 if a < b 65824981Seric ** 0 if a == b 65924981Seric ** +1 if a > b 6604632Seric ** 6614632Seric ** Side Effects: 6624632Seric ** none. 6634632Seric */ 6644632Seric 6654632Seric workcmpf(a, b) 6665037Seric register WORK *a; 6675037Seric register WORK *b; 6684632Seric { 66957438Seric long pa = a->w_pri; 67057438Seric long pb = b->w_pri; 67124941Seric 67224941Seric if (pa == pb) 6734632Seric return (0); 67424941Seric else if (pa > pb) 67524981Seric return (1); 67624981Seric else 67710121Seric return (-1); 6784632Seric } 6794632Seric /* 6804632Seric ** DOWORK -- do a work request. 6814632Seric ** 6824632Seric ** Parameters: 6834632Seric ** w -- the work request to be satisfied. 6844632Seric ** 6854632Seric ** Returns: 6864632Seric ** none. 6874632Seric ** 6884632Seric ** Side Effects: 6894632Seric ** The work request is satisfied if possible. 6904632Seric */ 6914632Seric 69255012Seric dowork(w, e) 6934632Seric register WORK *w; 69455012Seric register ENVELOPE *e; 6954632Seric { 6964632Seric register int i; 69724941Seric extern bool shouldqueue(); 69851920Seric extern bool readqf(); 6994632Seric 7007677Seric if (tTd(40, 1)) 7015037Seric printf("dowork: %s pri %ld\n", w->w_name, w->w_pri); 7024632Seric 7034632Seric /* 70424941Seric ** Ignore jobs that are too expensive for the moment. 7054632Seric */ 7064632Seric 70757438Seric if (shouldqueue(w->w_pri, w->w_ctime)) 7084632Seric { 70924941Seric if (Verbose) 71024967Seric printf("\nSkipping %s\n", w->w_name + 2); 7114632Seric return; 7124632Seric } 7134632Seric 71424941Seric /* 71524941Seric ** Fork for work. 71624941Seric */ 71724941Seric 71824941Seric if (ForkQueueRuns) 71924941Seric { 72024941Seric i = fork(); 72124941Seric if (i < 0) 72224941Seric { 72324941Seric syserr("dowork: cannot fork"); 72424941Seric return; 72524941Seric } 72624941Seric } 72724941Seric else 72824941Seric { 72924941Seric i = 0; 73024941Seric } 73124941Seric 7324632Seric if (i == 0) 7334632Seric { 7344632Seric /* 7354632Seric ** CHILD 7368148Seric ** Lock the control file to avoid duplicate deliveries. 7378148Seric ** Then run the file as though we had just read it. 7387350Seric ** We save an idea of the temporary name so we 7397350Seric ** can recover on interrupt. 7404632Seric */ 7414632Seric 7427763Seric /* set basic modes, etc. */ 7437356Seric (void) alarm(0); 74455012Seric clearenvelope(e, FALSE); 7454632Seric QueueRun = TRUE; 7469377Seric ErrorMode = EM_MAIL; 74755012Seric e->e_id = &w->w_name[2]; 7487876Seric # ifdef LOG 74958020Seric if (LogLevel > 76) 75055012Seric syslog(LOG_DEBUG, "%s: dowork, pid=%d", e->e_id, 7517881Seric getpid()); 75256795Seric # endif /* LOG */ 7537763Seric 7547763Seric /* don't use the headers from sendmail.cf... */ 75555012Seric e->e_header = NULL; 7567763Seric 75751920Seric /* read the queue control file -- return if locked */ 75855012Seric if (!readqf(e)) 7596980Seric { 76024941Seric if (ForkQueueRuns) 76124941Seric exit(EX_OK); 76224941Seric else 76324941Seric return; 7646980Seric } 7656980Seric 76655012Seric e->e_flags |= EF_INQUEUE; 76757642Seric eatheader(e, TRUE); 7686980Seric 7696980Seric /* do the delivery */ 77055012Seric if (!bitset(EF_FATALERRS, e->e_flags)) 77155012Seric sendall(e, SM_DELIVER); 7726980Seric 7736980Seric /* finish up and exit */ 77424941Seric if (ForkQueueRuns) 77524941Seric finis(); 77624941Seric else 77755012Seric dropenvelope(e); 7784632Seric } 77924941Seric else 78024941Seric { 78124941Seric /* 78224941Seric ** Parent -- pick up results. 78324941Seric */ 7844632Seric 78524941Seric errno = 0; 78624941Seric (void) waitfor(i); 78724941Seric } 7884632Seric } 7894632Seric /* 7904632Seric ** READQF -- read queue file and set up environment. 7914632Seric ** 7924632Seric ** Parameters: 7939377Seric ** e -- the envelope of the job to run. 7944632Seric ** 7954632Seric ** Returns: 79651920Seric ** TRUE if it successfully read the queue file. 79751920Seric ** FALSE otherwise. 7984632Seric ** 7994632Seric ** Side Effects: 80051920Seric ** The queue file is returned locked. 8014632Seric */ 8024632Seric 80351920Seric bool 80451920Seric readqf(e) 8059377Seric register ENVELOPE *e; 8064632Seric { 80717477Seric char *qf; 80817477Seric register FILE *qfp; 80954974Seric ADDRESS *ctladdr; 81056400Seric struct stat st; 81157135Seric char *bp; 81257135Seric char buf[MAXLINE]; 8139348Seric extern char *fgetfolded(); 81424954Seric extern long atol(); 81554974Seric extern ADDRESS *setctluser(); 81651937Seric # ifdef LOCKF 81751937Seric struct flock lfd; 81851937Seric # endif 8194632Seric 8204632Seric /* 82117468Seric ** Read and process the file. 8224632Seric */ 8234632Seric 82417477Seric qf = queuename(e, 'q'); 82551937Seric qfp = fopen(qf, "r+"); 82617477Seric if (qfp == NULL) 82717477Seric { 82840934Srick if (errno != ENOENT) 82940934Srick syserr("readqf: no control file %s", qf); 83051920Seric return FALSE; 83117477Seric } 83240934Srick 83356400Seric /* 83456400Seric ** Check the queue file for plausibility to avoid attacks. 83556400Seric */ 83656400Seric 83756400Seric if (fstat(fileno(qfp), &st) < 0) 83856400Seric { 83956400Seric /* must have been being processed by someone else */ 84056400Seric fclose(qfp); 84156400Seric return FALSE; 84256400Seric } 84356400Seric 84457135Seric if (st.st_uid != geteuid() || (st.st_mode & 07777) != FileMode) 84556400Seric { 84656400Seric # ifdef LOG 84756400Seric if (LogLevel > 0) 84856400Seric { 84956400Seric syslog(LOG_ALERT, "%s: bogus queue file, uid=%d, mode=%o", 85056400Seric e->e_id, st.st_uid, st.st_mode); 85156400Seric } 85256795Seric # endif /* LOG */ 85356400Seric fclose(qfp); 85456400Seric return FALSE; 85556400Seric } 85656400Seric 85751835Seric # ifdef LOCKF 85851937Seric lfd.l_type = F_WRLCK; 85951937Seric lfd.l_whence = lfd.l_start = lfd.l_len = 0; 86051937Seric if (fcntl(fileno(qfp), F_SETLK, &lfd) < 0) 86151835Seric # else 86240934Srick if (flock(fileno(qfp), LOCK_EX|LOCK_NB) < 0) 86351835Seric # endif 86440934Srick { 86540934Srick /* being processed by another queuer */ 86640934Srick if (Verbose) 86755012Seric printf("%s: locked\n", e->e_id); 86851920Seric # ifdef LOG 86958020Seric if (LogLevel > 19) 87055012Seric syslog(LOG_DEBUG, "%s: locked", e->e_id); 87156795Seric # endif /* LOG */ 87240934Srick (void) fclose(qfp); 87351920Seric return FALSE; 87440934Srick } 87540934Srick 87651920Seric /* save this lock */ 87751920Seric e->e_lockfp = qfp; 87851920Seric 87940934Srick /* do basic system initialization */ 88055012Seric initsys(e); 88140934Srick 88217477Seric FileName = qf; 8839377Seric LineNumber = 0; 88451920Seric if (Verbose) 8859377Seric printf("\nRunning %s\n", e->e_id); 88654974Seric ctladdr = NULL; 88757135Seric while ((bp = fgetfolded(buf, sizeof buf, qfp)) != NULL) 8884632Seric { 88957529Seric struct stat st; 89057529Seric 89126504Seric if (tTd(40, 4)) 89257135Seric printf("+++++ %s\n", bp); 89357135Seric switch (bp[0]) 8944632Seric { 89540973Sbostic case 'C': /* specify controlling user */ 89657135Seric ctladdr = setctluser(&bp[1]); 89740973Sbostic break; 89840973Sbostic 8994632Seric case 'R': /* specify recipient */ 90057135Seric sendtolist(&bp[1], ctladdr, &e->e_sendqueue, e); 9014632Seric break; 9024632Seric 90325687Seric case 'E': /* specify error recipient */ 90457135Seric sendtolist(&bp[1], ctladdr, &e->e_errorqueue, e); 90525687Seric break; 90625687Seric 9074632Seric case 'H': /* header */ 90857135Seric (void) chompheader(&bp[1], FALSE, e); 9094632Seric break; 9104632Seric 91110108Seric case 'M': /* message */ 91257135Seric e->e_message = newstr(&bp[1]); 91310108Seric break; 91410108Seric 9154632Seric case 'S': /* sender */ 91657135Seric setsender(newstr(&bp[1]), e); 9174632Seric break; 9184632Seric 9194632Seric case 'D': /* data file name */ 92057135Seric e->e_df = newstr(&bp[1]); 9219544Seric e->e_dfp = fopen(e->e_df, "r"); 9229544Seric if (e->e_dfp == NULL) 92358020Seric { 9249377Seric syserr("readqf: cannot open %s", e->e_df); 92558020Seric e->e_msgsize = -1; 92658020Seric } 92758020Seric else if (fstat(fileno(e->e_dfp), &st) >= 0) 92857529Seric e->e_msgsize = st.st_size; 9294632Seric break; 9304632Seric 9317860Seric case 'T': /* init time */ 93257135Seric e->e_ctime = atol(&bp[1]); 9334632Seric break; 9344632Seric 9354634Seric case 'P': /* message priority */ 93657135Seric e->e_msgpriority = atol(&bp[1]) + WkTimeFact; 9374634Seric break; 9384634Seric 93953400Seric case '$': /* define macro */ 94057135Seric define(bp[1], newstr(&bp[2]), e); 94153400Seric break; 94253400Seric 94324941Seric case '\0': /* blank line; ignore */ 94424941Seric break; 94524941Seric 9464632Seric default: 94724941Seric syserr("readqf(%s:%d): bad line \"%s\"", e->e_id, 94857135Seric LineNumber, bp); 9494632Seric break; 9504632Seric } 95157135Seric 95257135Seric if (bp != buf) 95357135Seric free(bp); 9544632Seric } 9559377Seric 9569377Seric FileName = NULL; 95724941Seric 95824941Seric /* 95924941Seric ** If we haven't read any lines, this queue file is empty. 96024941Seric ** Arrange to remove it without referencing any null pointers. 96124941Seric */ 96224941Seric 96324941Seric if (LineNumber == 0) 96424941Seric { 96524941Seric errno = 0; 96624941Seric e->e_flags |= EF_CLRQUEUE | EF_FATALERRS | EF_RESPONSE; 96724941Seric } 96851920Seric return TRUE; 9694632Seric } 9704632Seric /* 9719630Seric ** PRINTQUEUE -- print out a representation of the mail queue 9729630Seric ** 9739630Seric ** Parameters: 9749630Seric ** none. 9759630Seric ** 9769630Seric ** Returns: 9779630Seric ** none. 9789630Seric ** 9799630Seric ** Side Effects: 9809630Seric ** Prints a listing of the mail queue on the standard output. 9819630Seric */ 9825182Seric 9839630Seric printqueue() 9849630Seric { 9859630Seric register WORK *w; 9869630Seric FILE *f; 98710070Seric int nrequests; 9889630Seric char buf[MAXLINE]; 9899630Seric 9909630Seric /* 9919630Seric ** Read and order the queue. 9929630Seric */ 9939630Seric 99424941Seric nrequests = orderq(TRUE); 9959630Seric 9969630Seric /* 9979630Seric ** Print the work list that we have read. 9989630Seric */ 9999630Seric 10009630Seric /* first see if there is anything */ 100110070Seric if (nrequests <= 0) 10029630Seric { 100310070Seric printf("Mail queue is empty\n"); 10049630Seric return; 10059630Seric } 10069630Seric 100751920Seric CurrentLA = getla(); /* get load average */ 100840934Srick 100910096Seric printf("\t\tMail Queue (%d request%s", nrequests, nrequests == 1 ? "" : "s"); 101025687Seric if (nrequests > QUEUESIZE) 101125687Seric printf(", only %d printed", QUEUESIZE); 101224979Seric if (Verbose) 101325032Seric printf(")\n--QID-- --Size-- -Priority- ---Q-Time--- -----------Sender/Recipient-----------\n"); 101424979Seric else 101524979Seric printf(")\n--QID-- --Size-- -----Q-Time----- ------------Sender/Recipient------------\n"); 10169630Seric for (w = WorkQ; w != NULL; w = w->w_next) 10179630Seric { 10189630Seric struct stat st; 101910070Seric auto time_t submittime = 0; 102010070Seric long dfsize = -1; 102110108Seric char message[MAXLINE]; 102251937Seric # ifdef LOCKF 102351937Seric struct flock lfd; 102451937Seric # endif 102524941Seric extern bool shouldqueue(); 10269630Seric 102717468Seric f = fopen(w->w_name, "r"); 102817468Seric if (f == NULL) 102917468Seric { 103017468Seric errno = 0; 103117468Seric continue; 103217468Seric } 10339630Seric printf("%7s", w->w_name + 2); 103451835Seric # ifdef LOCKF 103551937Seric lfd.l_type = F_RDLCK; 103651937Seric lfd.l_whence = lfd.l_start = lfd.l_len = 0; 103751937Seric if (fcntl(fileno(f), F_GETLK, &lfd) < 0 || lfd.l_type != F_UNLCK) 103851835Seric # else 103940934Srick if (flock(fileno(f), LOCK_SH|LOCK_NB) < 0) 104051835Seric # endif 104110070Seric printf("*"); 104257438Seric else if (shouldqueue(w->w_pri, w->w_ctime)) 104324941Seric printf("X"); 104410070Seric else 104510070Seric printf(" "); 104610070Seric errno = 0; 104717468Seric 104810108Seric message[0] = '\0'; 10499630Seric while (fgets(buf, sizeof buf, f) != NULL) 10509630Seric { 105153400Seric register int i; 105253400Seric 10539630Seric fixcrlf(buf, TRUE); 10549630Seric switch (buf[0]) 10559630Seric { 105610108Seric case 'M': /* error message */ 105753400Seric if ((i = strlen(&buf[1])) >= sizeof message) 105853400Seric i = sizeof message; 105953400Seric bcopy(&buf[1], message, i); 106053400Seric message[i] = '\0'; 106110108Seric break; 106210108Seric 10639630Seric case 'S': /* sender name */ 106424979Seric if (Verbose) 106525027Seric printf("%8ld %10ld %.12s %.38s", dfsize, 106625027Seric w->w_pri, ctime(&submittime) + 4, 106724979Seric &buf[1]); 106824979Seric else 106924979Seric printf("%8ld %.16s %.45s", dfsize, 107024979Seric ctime(&submittime), &buf[1]); 107110108Seric if (message[0] != '\0') 107225027Seric printf("\n\t\t (%.60s)", message); 10739630Seric break; 107451920Seric 107540973Sbostic case 'C': /* controlling user */ 107654974Seric if (Verbose) 107754975Seric printf("\n\t\t\t\t (---%.34s---)", &buf[1]); 107840973Sbostic break; 10799630Seric 10809630Seric case 'R': /* recipient name */ 108124979Seric if (Verbose) 108225027Seric printf("\n\t\t\t\t\t %.38s", &buf[1]); 108324979Seric else 108424979Seric printf("\n\t\t\t\t %.45s", &buf[1]); 10859630Seric break; 10869630Seric 10879630Seric case 'T': /* creation time */ 108824941Seric submittime = atol(&buf[1]); 10899630Seric break; 109010070Seric 109110070Seric case 'D': /* data file name */ 109210070Seric if (stat(&buf[1], &st) >= 0) 109310070Seric dfsize = st.st_size; 109410070Seric break; 10959630Seric } 10969630Seric } 109710070Seric if (submittime == (time_t) 0) 109810070Seric printf(" (no control file)"); 10999630Seric printf("\n"); 110023098Seric (void) fclose(f); 11019630Seric } 11029630Seric } 11039630Seric 110456795Seric # endif /* QUEUE */ 110517468Seric /* 110617468Seric ** QUEUENAME -- build a file name in the queue directory for this envelope. 110717468Seric ** 110817468Seric ** Assigns an id code if one does not already exist. 110917468Seric ** This code is very careful to avoid trashing existing files 111017468Seric ** under any circumstances. 111117468Seric ** 111217468Seric ** Parameters: 111317468Seric ** e -- envelope to build it in/from. 111417468Seric ** type -- the file type, used as the first character 111517468Seric ** of the file name. 111617468Seric ** 111717468Seric ** Returns: 111817468Seric ** a pointer to the new file name (in a static buffer). 111917468Seric ** 112017468Seric ** Side Effects: 112151920Seric ** If no id code is already assigned, queuename will 112251920Seric ** assign an id code, create a qf file, and leave a 112351920Seric ** locked, open-for-write file pointer in the envelope. 112417468Seric */ 112517468Seric 112617468Seric char * 112717468Seric queuename(e, type) 112817468Seric register ENVELOPE *e; 112917468Seric char type; 113017468Seric { 113117468Seric static char buf[MAXNAME]; 113217468Seric static int pid = -1; 113317468Seric char c1 = 'A'; 113417468Seric char c2 = 'A'; 113517468Seric 113617468Seric if (e->e_id == NULL) 113717468Seric { 113817468Seric char qf[20]; 113917468Seric 114017468Seric /* find a unique id */ 114117468Seric if (pid != getpid()) 114217468Seric { 114317468Seric /* new process -- start back at "AA" */ 114417468Seric pid = getpid(); 114517468Seric c1 = 'A'; 114617468Seric c2 = 'A' - 1; 114717468Seric } 114817468Seric (void) sprintf(qf, "qfAA%05d", pid); 114917468Seric 115017468Seric while (c1 < '~' || c2 < 'Z') 115117468Seric { 115217468Seric int i; 115351937Seric # ifdef LOCKF 115451937Seric struct flock lfd; 115551937Seric # endif 115617468Seric 115717468Seric if (c2 >= 'Z') 115817468Seric { 115917468Seric c1++; 116017468Seric c2 = 'A' - 1; 116117468Seric } 116240934Srick qf[2] = c1; 116340934Srick qf[3] = ++c2; 116417468Seric if (tTd(7, 20)) 116540934Srick printf("queuename: trying \"%s\"\n", qf); 116617468Seric 116740934Srick i = open(qf, O_WRONLY|O_CREAT|O_EXCL, FileMode); 116851920Seric if (i < 0) 116951920Seric { 117051920Seric if (errno == EEXIST) 117151920Seric continue; 117251920Seric syserr("queuename: Cannot create \"%s\" in \"%s\"", 117351920Seric qf, QueueDir); 117451920Seric exit(EX_UNAVAILABLE); 117551920Seric } 117651920Seric # ifdef LOCKF 117751937Seric lfd.l_type = F_WRLCK; 117851937Seric lfd.l_whence = lfd.l_start = lfd.l_len = 0; 117951937Seric if (fcntl(i, F_SETLK, &lfd) >= 0) 118051920Seric # else 118151920Seric if (flock(i, LOCK_EX|LOCK_NB) >= 0) 118251920Seric # endif 118351920Seric { 118451920Seric e->e_lockfp = fdopen(i, "w"); 118540934Srick break; 118617468Seric } 118751920Seric 118851920Seric /* a reader got the file; abandon it and try again */ 118951920Seric (void) close(i); 119017468Seric } 119117468Seric if (c1 >= '~' && c2 >= 'Z') 119217468Seric { 119317468Seric syserr("queuename: Cannot create \"%s\" in \"%s\"", 119417468Seric qf, QueueDir); 119517468Seric exit(EX_OSERR); 119617468Seric } 119717468Seric e->e_id = newstr(&qf[2]); 119817468Seric define('i', e->e_id, e); 119917468Seric if (tTd(7, 1)) 120017468Seric printf("queuename: assigned id %s, env=%x\n", e->e_id, e); 120117468Seric # ifdef LOG 120258020Seric if (LogLevel > 93) 120317468Seric syslog(LOG_DEBUG, "%s: assigned id", e->e_id); 120456795Seric # endif /* LOG */ 120517468Seric } 120617468Seric 120717468Seric if (type == '\0') 120817468Seric return (NULL); 120917468Seric (void) sprintf(buf, "%cf%s", type, e->e_id); 121017468Seric if (tTd(7, 2)) 121117468Seric printf("queuename: %s\n", buf); 121217468Seric return (buf); 121317468Seric } 121417468Seric /* 121517468Seric ** UNLOCKQUEUE -- unlock the queue entry for a specified envelope 121617468Seric ** 121717468Seric ** Parameters: 121817468Seric ** e -- the envelope to unlock. 121917468Seric ** 122017468Seric ** Returns: 122117468Seric ** none 122217468Seric ** 122317468Seric ** Side Effects: 122417468Seric ** unlocks the queue for `e'. 122517468Seric */ 122617468Seric 122717468Seric unlockqueue(e) 122817468Seric ENVELOPE *e; 122917468Seric { 123051920Seric /* if there is a lock file in the envelope, close it */ 123151920Seric if (e->e_lockfp != NULL) 123251920Seric fclose(e->e_lockfp); 123351920Seric e->e_lockfp = NULL; 123451920Seric 123517468Seric /* remove the transcript */ 123617468Seric # ifdef LOG 123758020Seric if (LogLevel > 87) 123817468Seric syslog(LOG_DEBUG, "%s: unlock", e->e_id); 123956795Seric # endif /* LOG */ 124017468Seric if (!tTd(51, 4)) 124117468Seric xunlink(queuename(e, 'x')); 124217468Seric 124317468Seric } 124440973Sbostic /* 124554974Seric ** SETCTLUSER -- create a controlling address 124640973Sbostic ** 124754974Seric ** Create a fake "address" given only a local login name; this is 124854974Seric ** used as a "controlling user" for future recipient addresses. 124940973Sbostic ** 125040973Sbostic ** Parameters: 125154974Seric ** user -- the user name of the controlling user. 125240973Sbostic ** 125340973Sbostic ** Returns: 125454974Seric ** An address descriptor for the controlling user. 125540973Sbostic ** 125640973Sbostic ** Side Effects: 125740973Sbostic ** none. 125840973Sbostic */ 125940973Sbostic 126054974Seric ADDRESS * 126154974Seric setctluser(user) 126254974Seric char *user; 126340973Sbostic { 126454974Seric register ADDRESS *a; 126540973Sbostic struct passwd *pw; 126640973Sbostic 126740973Sbostic /* 126854974Seric ** See if this clears our concept of controlling user. 126940973Sbostic */ 127040973Sbostic 127154974Seric if (user == NULL || *user == '\0') 127254974Seric return NULL; 127340973Sbostic 127440973Sbostic /* 127554974Seric ** Set up addr fields for controlling user. 127640973Sbostic */ 127740973Sbostic 127854974Seric a = (ADDRESS *) xalloc(sizeof *a); 127954974Seric bzero((char *) a, sizeof *a); 128054974Seric if ((pw = getpwnam(user)) != NULL) 128140973Sbostic { 128240973Sbostic a->q_home = newstr(pw->pw_dir); 128340973Sbostic a->q_uid = pw->pw_uid; 128440973Sbostic a->q_gid = pw->pw_gid; 128557642Seric a->q_user = newstr(user); 128640973Sbostic } 128740973Sbostic else 128840973Sbostic { 128940973Sbostic a->q_uid = DefUid; 129040973Sbostic a->q_gid = DefGid; 129157642Seric a->q_user = newstr(DefUser); 129240973Sbostic } 129340973Sbostic 129440973Sbostic a->q_flags |= QGOODUID; /* flag as a "ctladdr" */ 129556328Seric a->q_mailer = LocalMailer; 129654974Seric return a; 129740973Sbostic } 1298