From: Simon Schubert Date: Thu, 27 Aug 2009 14:32:19 +0000 (+0200) Subject: dma: move sender into queue X-Git-Tag: v2.4.0~107^2~6 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/1c9e6b7b6cbc2f27d0c9e863141766ea93a9e20a dma: move sender into queue --- diff --git a/libexec/dma/dma.c b/libexec/dma/dma.c index d1f2493abe..037288a900 100644 --- a/libexec/dma/dma.c +++ b/libexec/dma/dma.c @@ -70,7 +70,7 @@ const char *logident_base; static int daemonize = 1; static char * -set_from(const char *osender) +set_from(struct queue *queue, const char *osender) { struct virtuser *v; char *sender; @@ -101,6 +101,7 @@ set_from(const char *osender) } out: + queue->sender = sender; return (sender); } @@ -117,7 +118,7 @@ read_aliases(void) } int -add_recp(struct queue *queue, const char *str, const char *sender, int expand) +add_recp(struct queue *queue, const char *str, int expand) { struct qitem *it, *tit; struct stritem *sit; @@ -133,7 +134,7 @@ add_recp(struct queue *queue, const char *str, const char *sender, int expand) if (it->addr == NULL) return (-1); - it->sender = sender; + it->sender = queue->sender; host = strrchr(it->addr, '@'); if (host != NULL && (strcmp(host + 1, hostname()) == 0 || @@ -156,7 +157,7 @@ add_recp(struct queue *queue, const char *str, const char *sender, int expand) if (strcmp(al->alias, it->addr) != 0) continue; SLIST_FOREACH(sit, &al->dests, next) { - if (add_recp(queue, sit->str, sender, 1) != 0) + if (add_recp(queue, sit->str, 1) != 0) return (-1); } aliased = 1; @@ -482,26 +483,26 @@ skipopts: if (read_aliases() != 0) errlog(1, "can not read aliases file `%s'", config->aliases); - if ((sender = set_from(sender)) == NULL) + if ((sender = set_from(&queue, sender)) == NULL) errlog(1, NULL); for (i = 0; i < argc; i++) { - if (add_recp(&queue, argv[i], sender, 1) != 0) + if (add_recp(&queue, argv[i], 1) != 0) errlogx(1, "invalid recipient `%s'", argv[i]); } if (LIST_EMPTY(&queue.queue)) errlogx(1, "no recipients"); - if (newspoolf(&queue, sender) != 0) + if (newspoolf(&queue) != 0) errlog(1, "can not create temp file"); setlogident("%s", queue.id); - if (readmail(&queue, sender, nodot) != 0) + if (readmail(&queue, nodot) != 0) errlog(1, "can not read mail"); - if (linkspool(&queue, sender) != 0) + if (linkspool(&queue) != 0) errlog(1, "can not create spools"); /* From here on the mail is safe. */ diff --git a/libexec/dma/dma.h b/libexec/dma/dma.h index 04cd28eea6..96fd9bde75 100644 --- a/libexec/dma/dma.h +++ b/libexec/dma/dma.h @@ -104,6 +104,7 @@ struct queue { char *id; FILE *mailf; char *tmpf; + const char *sender; }; struct config { @@ -174,12 +175,12 @@ int base64_encode(const void *, int, char **); int base64_decode(const char *, void *); /* dma.c */ -int add_recp(struct queue *, const char *, const char *, int); +int add_recp(struct queue *, const char *, int); void run_queue(struct queue *); /* spool.c */ -int newspoolf(struct queue *, const char *); -int linkspool(struct queue *, const char *); +int newspoolf(struct queue *); +int linkspool(struct queue *); int load_queue(struct queue *); void delqueue(struct qitem *); int aquirespool(struct qitem *); @@ -190,7 +191,7 @@ int deliver_local(struct qitem *, const char **errmsg); /* mail.c */ void bounce(struct qitem *, const char *); -int readmail(struct queue *, const char *, int); +int readmail(struct queue *, int); /* util.c */ const char *hostname(void); diff --git a/libexec/dma/mail.c b/libexec/dma/mail.c index 7f826b20f0..dd317e5b30 100644 --- a/libexec/dma/mail.c +++ b/libexec/dma/mail.c @@ -54,10 +54,11 @@ bounce(struct qitem *it, const char *reason) bzero(&bounceq, sizeof(bounceq)); LIST_INIT(&bounceq.queue); - if (add_recp(&bounceq, it->sender, "", 1) != 0) + bounceq.sender = ""; + if (add_recp(&bounceq, it->sender, 1) != 0) goto fail; - if (newspoolf(&bounceq, "") != 0) + if (newspoolf(&bounceq) != 0) goto fail; syslog(LOG_ERR, "delivery failed, bouncing as %s", bounceq.id); @@ -117,7 +118,7 @@ bounce(struct qitem *it, const char *reason) } } - if (linkspool(&bounceq, "") != 0) + if (linkspool(&bounceq) != 0) goto fail; /* bounce is safe */ @@ -133,7 +134,7 @@ fail: } int -readmail(struct queue *queue, const char *sender, int nodot) +readmail(struct queue *queue, int nodot) { char line[1000]; /* by RFC2822 */ size_t linelen; @@ -150,7 +151,7 @@ readmail(struct queue *queue, const char *sender, int nodot) "\tby %s (%s)\n" "\t%s\n", username, getuid(), - sender, + queue->sender, queue->id, hostname(), VERSION, rfc822date()); @@ -186,7 +187,7 @@ readmail(struct queue *queue, const char *sender, int nodot) queue->id, hostname()); } else if (!had_from) { had_from = 1; - snprintf(line, sizeof(line), "From: <%s>\n", sender); + snprintf(line, sizeof(line), "From: <%s>\n", queue->sender); } if (fwrite(line, strlen(line), 1, queue->mailf) != 1) return (-1); diff --git a/libexec/dma/spool.c b/libexec/dma/spool.c index 7988a1f1af..21818b270a 100644 --- a/libexec/dma/spool.c +++ b/libexec/dma/spool.c @@ -62,7 +62,7 @@ */ int -newspoolf(struct queue *queue, const char *sender) +newspoolf(struct queue *queue) { char fn[PATH_MAX+1]; struct stat st; @@ -95,7 +95,7 @@ newspoolf(struct queue *queue, const char *sender) if (queue->mailf == NULL) goto fail; - if (fprintf(queue->mailf, "%s\n", sender) < 0) + if (fprintf(queue->mailf, "%s\n", queue->sender) < 0) goto fail; hdrlen = ftello(queue->mailf); @@ -120,7 +120,7 @@ fail: } int -linkspool(struct queue *queue, const char *sender) +linkspool(struct queue *queue) { char line[1000]; /* by RFC2822 */ struct stat st; @@ -132,7 +132,7 @@ linkspool(struct queue *queue, const char *sender) goto delfiles; syslog(LOG_INFO, "new mail from user=%s uid=%d envelope_from=<%s>", - username, getuid(), sender); + username, getuid(), queue->sender); LIST_FOREACH(it, &queue->queue, next) { if (asprintf(&it->queueid, "%s.%"PRIxPTR, queue->id, (uintptr_t)it) <= 0) @@ -252,10 +252,11 @@ load_queue(struct queue *queue) goto skip_item; *addr++ = 0; - if (add_recp(&itmqueue, addr, sender, 0) != 0) + if (add_recp(&itmqueue, addr, 0) != 0) goto skip_item; it = LIST_FIRST(&itmqueue.queue); + it->sender = sender; it->queueid = queueid; it->queuefn = queuefn; it->mailfn = mailfn;