summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpea <pea@cvs.openbsd.org>2009-03-12 11:08:27 +0000
committerpea <pea@cvs.openbsd.org>2009-03-12 11:08:27 +0000
commitcf360fc2afa75eb5959e477758632a9abfa76938 (patch)
tree9528e93c26e10e3b757fa85a7d136e4edc2d3417
parent406cac47aeec68b6da9dc6a1186e3e63599a8923 (diff)
Add new function time_to_text to correctly display the date.
Use it to display the date in received from header and when we store headers. ok jacekm@
-rw-r--r--usr.sbin/smtpd/mta.c6
-rw-r--r--usr.sbin/smtpd/smtpd.h3
-rw-r--r--usr.sbin/smtpd/store.c16
-rw-r--r--usr.sbin/smtpd/util.c30
4 files changed, 39 insertions, 16 deletions
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index e68ffae6dad..54631222150 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.33 2009/03/10 22:33:26 jacekm Exp $ */
+/* $OpenBSD: mta.c,v 1.34 2009/03/12 11:08:26 pea Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -885,9 +885,11 @@ mta_reply_handler(struct bufferevent *bev, void *arg)
batchp->session_helo, batchp->session_hostname,
ss_to_text(&batchp->session_ss));
- session_respond(sessionp, "\tby %s with ESMTP id %s",
+ session_respond(sessionp, "\tby %s with ESMTP id %s;",
batchp->env->sc_hostname, batchp->message_id);
+ session_respond(sessionp, "\t%s", time_to_text(batchp->creation));
+
if (sessionp->s_flags & F_SECURE) {
session_respond(sessionp, "X-OpenSMTPD-Cipher: %s",
SSL_get_cipher(sessionp->s_ssl));
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 8a6efc26dd3..d3d0bcb8ffb 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.90 2009/03/10 22:33:26 jacekm Exp $ */
+/* $OpenBSD: smtpd.h,v 1.91 2009/03/12 11:08:26 pea Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -959,4 +959,5 @@ int valid_domainpart(char *);
char *ss_to_text(struct sockaddr_storage *);
int valid_message_id(char *);
int valid_message_uid(char *);
+char *time_to_text(time_t);
int secure_file(int, char *, struct passwd *);
diff --git a/usr.sbin/smtpd/store.c b/usr.sbin/smtpd/store.c
index 312e026f6f9..512040ccaf8 100644
--- a/usr.sbin/smtpd/store.c
+++ b/usr.sbin/smtpd/store.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: store.c,v 1.15 2009/03/03 15:47:28 gilles Exp $ */
+/* $OpenBSD: store.c,v 1.16 2009/03/12 11:08:26 pea Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -89,18 +89,10 @@ store_write_header(struct batch *batchp, struct message *messagep, FILE *fp,
int finalize)
{
time_t tm;
- char timebuf[26]; /* current time */
- char ctimebuf[26]; /* creation time */
void *p;
char addrbuf[INET6_ADDRSTRLEN];
tm = time(NULL);
- ctime_r(&tm, timebuf);
- timebuf[strcspn(timebuf, "\n")] = '\0';
-
- tm = time(&messagep->creation);
- ctime_r(&tm, ctimebuf);
- ctimebuf[strcspn(ctimebuf, "\n")] = '\0';
if (messagep->session_ss.ss_family == PF_INET) {
struct sockaddr_in *ssin = (struct sockaddr_in *)&messagep->session_ss;
@@ -117,13 +109,13 @@ store_write_header(struct batch *batchp, struct message *messagep, FILE *fp,
if (messagep->recipient.rule.r_action != A_MBOX) {
if (batchp->type & T_DAEMON_BATCH) {
if (fprintf(fp, "From %s@%s %s\n", "MAILER-DAEMON",
- batchp->env->sc_hostname, timebuf) == -1) {
+ batchp->env->sc_hostname, time_to_text(tm)) == -1) {
return 0;
}
}
else {
if (fprintf(fp, "From %s@%s %s\n",
- messagep->sender.user, messagep->sender.domain, timebuf) == -1)
+ messagep->sender.user, messagep->sender.domain, time_to_text(tm)) == -1)
return 0;
}
}
@@ -134,7 +126,7 @@ store_write_header(struct batch *batchp, struct message *messagep, FILE *fp,
messagep->session_helo, messagep->session_hostname,
messagep->session_ss.ss_family == PF_INET ? "" : "IPv6:", addrbuf,
batchp->env->sc_hostname, messagep->message_id,
- messagep->sender.user, messagep->sender.domain, ctimebuf,
+ messagep->sender.user, messagep->sender.domain, time_to_text(messagep->creation),
finalize ? "\n" : "") == -1) {
return 0;
}
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 3f8b606d88a..204946ed8c2 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.18 2009/03/10 01:25:42 jacekm Exp $ */
+/* $OpenBSD: util.c,v 1.19 2009/03/12 11:08:26 pea Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "smtpd.h"
@@ -263,6 +264,33 @@ valid_message_uid(char *muid)
return (cnt != 0);
}
+char *
+time_to_text(time_t when)
+{
+ struct tm *lt;
+ static char buf[40];
+ char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+ char *month[] = {"Jan","Feb","Mar","Apr","May","Jun",
+ "Jul","Aug","Sep","Oct","Nov","Dec"};
+
+ lt = localtime(&when);
+ if (lt == NULL || when == 0)
+ fatalx("time_to_text: localtime");
+
+ /* We do not use strftime because it is subject to locale substitution*/
+ if (! bsnprintf(buf, sizeof(buf), "%s, %d %s %d %02d:%02d:%02d %c%02d%02d (%s)",
+ day[lt->tm_wday], lt->tm_mday, month[lt->tm_mon],
+ lt->tm_year + 1900,
+ lt->tm_hour, lt->tm_min, lt->tm_sec,
+ lt->tm_gmtoff >= 0 ? '+' : '-',
+ abs((int)lt->tm_gmtoff / 3600),
+ abs((int)lt->tm_gmtoff % 3600) / 60,
+ lt->tm_zone))
+ fatalx("time_to_text: bsnprintf");
+
+ return buf;
+}
+
/*
* Check file for security. Based on usr.bin/ssh/auth.c.
*/