Commit Diff


commit - e30dd6929ed750a3228af965628c6bf9ff4bc357
commit + 1a5c543c8a22af0430f2be05666dd5b100f9df8f
blob - eb194087ab831b51d259be96c06fbee8f9c2c8d5
blob + aca5e1901fda690633dd36e634a4b8f4af42ac35
--- Symbols.list
+++ Symbols.list
@@ -42,7 +42,9 @@ osmtpd_local_session
 osmtpd_local_message
 osmtpd_need
 osmtpd_run
-osmtpd_warn
-osmtpd_warnx
 osmtpd_err
 osmtpd_errx
+osmtpd_warn
+osmtpd_warnx
+osmtpd_info
+osmtpd_debug
blob - a1e0cfb4a13324f479e90d29462ef19121fa7a44
blob + 99c382cadf90978f44b08bfc294f4976ffef2b19
--- opensmtpd.c
+++ opensmtpd.c
@@ -583,6 +583,7 @@ static int needs;
 static int ready = 0;
 /* Default from smtpd */
 static int session_timeout = 300;
+int version_major, version_minor;
 
 RB_HEAD(osmtpd_sessions, osmtpd_session) osmtpd_sessions = RB_INITIALIZER(NULL);
 RB_PROTOTYPE_STATIC(osmtpd_sessions, osmtpd_session, entry, osmtpd_session_cmp);
@@ -1042,37 +1043,13 @@ osmtpd_run(void)
 	event_base_free(evbase);
 }
 
-void
-osmtpd_warn(struct osmtpd_ctx *ctx, const char *fmt, ...)
-{
-	va_list ap;
-
-	if (ctx)
-		fprintf(stderr, "%016"PRIx64, ctx->reqid);
-	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-	fprintf(stderr, ": %s\n", strerror(errno));
-}
-
-void
-osmtpd_warnx(struct osmtpd_ctx *ctx, const char *fmt, ...)
-{
-	va_list ap;
-
-	if (ctx)
-		fprintf(stderr, "%016"PRIx64, ctx->reqid);
-	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-	fprintf(stderr, "\n");
-}
-
 __dead void
 osmtpd_err(int eval, const char *fmt, ...)
 {
 	va_list ap;
 
+	if (version_major == 0 && version_minor >= 8)
+		fprintf(stderr, "FATAL|");
 	va_start(ap, fmt);
 	vfprintf(stderr, fmt, ap);
 	va_end(ap);
@@ -1085,6 +1062,8 @@ osmtpd_errx(int eval, const char *fmt, ...)
 {
 	va_list ap;
 
+	if (version_major == 0 && version_minor >= 8)
+		fprintf(stderr, "FATAL|");
 	va_start(ap, fmt);
 	vfprintf(stderr, fmt, ap);
 	va_end(ap);
@@ -1092,6 +1071,66 @@ osmtpd_errx(int eval, const char *fmt, ...)
 	exit(eval);
 }
 
+void
+osmtpd_warn(struct osmtpd_ctx *ctx, const char *fmt, ...)
+{
+	va_list ap;
+
+	if (version_major == 0 && version_minor >= 8)
+		fprintf(stderr, "WARN|");
+	if (ctx)
+		fprintf(stderr, "%016"PRIx64" ", ctx->reqid);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, ": %s\n", strerror(errno));
+}
+
+void
+osmtpd_warnx(struct osmtpd_ctx *ctx, const char *fmt, ...)
+{
+	va_list ap;
+
+	if (version_major == 0 && version_minor >= 8)
+		fprintf(stderr, "WARN|");
+	if (ctx)
+		fprintf(stderr, "%016"PRIx64" ", ctx->reqid);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, "\n");
+}
+
+void
+osmtpd_info(struct osmtpd_ctx *ctx, const char *fmt, ...)
+{
+	va_list ap;
+
+	if (version_major == 0 && version_minor >= 8)
+		fprintf(stderr, "INFO|");
+	if (ctx)
+		fprintf(stderr, "%016"PRIx64" ", ctx->reqid);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, "\n");
+}
+
+void
+osmtpd_debug(struct osmtpd_ctx *ctx, const char *fmt, ...)
+{
+	va_list ap;
+
+	if (version_major == 0 && version_minor >= 8)
+		fprintf(stderr, "DEBUG|");
+	if (ctx)
+		fprintf(stderr, "%016"PRIx64" ", ctx->reqid);
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	fprintf(stderr, "\n");
+}
+
 static void
 osmtpd_newline(struct io *io, int ev, __unused void *arg)
 {
@@ -1100,7 +1139,7 @@ osmtpd_newline(struct io *io, int ev, __unused void *a
 	struct osmtpd_session *ctx, search;
 	enum osmtpd_type type;
 	enum osmtpd_phase phase;
-	int version_major, version_minor, incoming;
+	int major, minor, incoming;
 	struct timespec tm;
 	char *line = NULL;
 	const char *errstr = NULL;
@@ -1161,21 +1200,29 @@ osmtpd_newline(struct io *io, int ev, __unused void *a
 			osmtpd_errx(1, "Invalid line received: unknown message "
 			    "type: %s", linedup);
 		line = end;
-		version_major = strtoul(line, &end, 10);
+		major = strtoul(line, &end, 10);
 		if (line == end || end[0] != '.')
 			osmtpd_errx(1, "Invalid protocol received: %s",
 			    linedup);
 		line = end + 1;
-		version_minor = strtoul(line, &end, 10);
+		minor = strtoul(line, &end, 10);
 		if (end[0] == '\0')
 			osmtpd_errx(1, "Invalid line received: missing time: "
 			    "%s", linedup);
 		if (line == end || end[0] != '|')
 			osmtpd_errx(1, "Invalid protocol received: %s",
 			    linedup);
-		if (version_major != 0)
+		if (major != 0)
 			osmtpd_errx(1, "Unsupported protocol received: %s",
 			    linedup);
+		if (version_major == 0 && version_minor == 0) {
+			version_major = major;
+			version_minor = minor;
+		} else {
+			if (version_major != major && version_minor != minor)
+				osmtpd_errx(1, "Unexpected protocol version "
+				    "change: %s", linedup);
+		}
 		line = end + 1;
 		if ((end = strchr(line, '.')) == NULL)
 			osmtpd_errx(1, "Invalid line received: invalid "
@@ -1254,8 +1301,8 @@ osmtpd_newline(struct io *io, int ev, __unused void *a
 		}
 		ctx->ctx.type = type;
 		ctx->ctx.phase = phase;
-		ctx->ctx.version_major = version_major;
-		ctx->ctx.version_minor = version_minor;
+		ctx->ctx.version_major = major;
+		ctx->ctx.version_minor = minor;
 		ctx->ctx.incoming = incoming;
 		ctx->ctx.tm.tv_sec = tm.tv_sec;
 		ctx->ctx.tm.tv_nsec = tm.tv_nsec;
blob - 896e673647d159912ecf1f58dbe22bef9c4abe33
blob + cf4f0b186f27d77da89cbafb9964dd9a0ed8acd1
--- opensmtpd.h
+++ opensmtpd.h
@@ -191,7 +191,15 @@ void osmtpd_filter_rewrite(struct osmtpd_ctx *, const 
 void osmtpd_filter_dataline(struct osmtpd_ctx *, const char *, ...)
 	__attribute__((__format__ (printf, 2, 3)));
 void osmtpd_run(void);
-void osmtpd_warn(struct osmtpd_ctx *, const char *fmt, ...);
-void osmtpd_warnx(struct osmtpd_ctx *, const char *fmt, ...);
-__dead void osmtpd_err(int eval, const char *fmt, ...);
-__dead void osmtpd_errx(int eval, const char *fmt, ...);
+__dead void osmtpd_err(int eval, const char *, ...)
+	__attribute__((__format__ (printf, 2, 3)));
+__dead void osmtpd_errx(int eval, const char *, ...)
+	__attribute__((__format__ (printf, 2, 3)));
+void osmtpd_warn(struct osmtpd_ctx *, const char *, ...)
+	__attribute__((__format__ (printf, 2, 3)));
+void osmtpd_warnx(struct osmtpd_ctx *, const char *, ...)
+	__attribute__((__format__ (printf, 2, 3)));
+void osmtpd_info(struct osmtpd_ctx *, const char *, ...)
+	__attribute__((__format__ (printf, 2, 3)));
+void osmtpd_debug(struct osmtpd_ctx *, const char *, ...)
+	__attribute__((__format__ (printf, 2, 3)));
blob - 6c0e36706ae75c060061057f6368b1b3710f9650
blob + a164e14e426de0542622975ebe679e13fba7caf2
--- osmtpd_run.3
+++ osmtpd_run.3
@@ -59,10 +59,12 @@
 .Nm osmtpd_filter_rewrite ,
 .Nm osmtpd_filter_dataline ,
 .Nm osmtpd_run ,
-.Nm osmtpd_warn ,
-.Nm osmtpd_warnx ,
 .Nm osmtpd_err ,
 .Nm osmtpd_errx
+.Nm osmtpd_warn ,
+.Nm osmtpd_warnx ,
+.Nm osmtpd_info ,
+.Nm osmtpd_debug ,
 .Nd C filter API for
 .Xr smtpd 8
 .Sh SYNOPSIS
@@ -238,13 +240,17 @@
 .Ft void
 .Fn osmtpd_run void
 .Ft void
-.Fn osmtpd_warn "struct osmtpd_ctx *ctx" "const char *fmt" ...
-.Ft void
-.Fn osmtpd_warnx "struct osmtpd_ctx *ctx" "const char *fmt" ...
-.Ft void
 .Fn osmtpd_err "int eval" "const char *fmt" ...
 .Ft void
 .Fn osmtpd_errx "int eval" "const char *fmt" ...
+.Ft void
+.Fn osmtpd_warn "struct osmtpd_ctx *ctx" "const char *fmt" ...
+.Ft void
+.Fn osmtpd_warnx "struct osmtpd_ctx *ctx" "const char *fmt" ...
+.Ft void
+.Fn osmtpd_info "struct osmtpd_ctx *ctx" "const char *fmt" ...
+.Ft void
+.Fn osmtpd_debug "struct osmtpd_ctx *ctx" "const char *fmt" ...
 .Sh DESCRIPTION
 The
 .Nm osmtpd
@@ -528,24 +534,30 @@ functions' callbacks without argument can't use
 callback can only use osmtpd_filter_dataline.
 .El
 .Pp
+.Nm osmtpd_err ,
+.Nm osmtpd_errx ,
 .Nm osmtpd_warn ,
 .Nm osmtpd_warnx ,
-.Nm osmtpd_err
+.Nm osmtpd_info ,
 and
-.Nm osmtpd_errx
-can be used as a standin for
-.Xr warn 3
-,
-.Xr warnx 3
-,
-.Xr err 3
+.Nm osmtpd_debug
+are used for logging to
+.Xr smtpd 8
+at
+.Xr syslog 3
+levels
+.Dv LOG_CRIT ,
+.Dv LOG_WARNING ,
+.Dv LOG_INFO,
 and
-.Xr errx 3
-without printing the program name to stderr.
+.Dv LOG_DEBUG
+respectively.
 Additionally,
-.Nm osmtpd_warn
+.Nm osmtpd_warn ,
+.Nm osmtpd_warnx ,
+.Nm osmtpd_info ,
 and
-.Nm osmtpd_warnx
+.Nm osmtpd_debug
 prints the request ID on the logline when
 .Fa ctx
 is not
blob - b52599a164f6872e7c8b55a4df1f1c6e25ae4012
blob + c6e3f4d3fc0f2f8d389c125024f1331410205e64
--- shlib_version
+++ shlib_version
@@ -1,2 +1,2 @@
 major=2
-minor=0
+minor=1