summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-09-22 12:24:07 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-09-22 12:24:07 +0000
commit849dd7297d7a8729f4fc89b9322ebaad270aa091 (patch)
tree32c8f617a4e9b0bc2010bacea5615a7449f96ae2 /usr.sbin
parent747c5ea91afe52b357280296056dc0511e55764b (diff)
When at MAIL FROM stage, handle the case when STARTTLS is required but not
available. Also, make the client_next_state() calls across the code more idiomatic.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/client.c34
-rw-r--r--usr.sbin/smtpd/client.h3
2 files changed, 18 insertions, 19 deletions
diff --git a/usr.sbin/smtpd/client.c b/usr.sbin/smtpd/client.c
index 034c01c16f5..7e89f327902 100644
--- a/usr.sbin/smtpd/client.c
+++ b/usr.sbin/smtpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.4 2009/09/17 23:51:23 jacekm Exp $ */
+/* $OpenBSD: client.c,v 1.5 2009/09/22 12:24:06 jacekm Exp $ */
/*
* Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
@@ -81,11 +81,13 @@ client_init(int fd, char *ehlo)
sp->exts[CLIENT_EXT_STARTTLS].want = 1;
sp->exts[CLIENT_EXT_STARTTLS].must = 1;
sp->exts[CLIENT_EXT_STARTTLS].state = CLIENT_STARTTLS;
+ sp->exts[CLIENT_EXT_STARTTLS].name = "STARTTLS";
#endif
sp->exts[CLIENT_EXT_AUTH].want = 0;
sp->exts[CLIENT_EXT_AUTH].must = 0;
sp->exts[CLIENT_EXT_AUTH].state = CLIENT_AUTH;
+ sp->exts[CLIENT_EXT_AUTH].name = "AUTH";
rv = 0;
done:
@@ -466,7 +468,8 @@ client_read(struct smtp_client *sp)
break;
}
- sp->state = client_next_state(sp);
+ if ((sp->state = client_next_state(sp)) == 0)
+ return (CLIENT_ERROR);
break;
case CLIENT_HELO:
@@ -479,10 +482,8 @@ client_read(struct smtp_client *sp)
case CLIENT_STARTTLS:
if (*sp->reply != '2') {
sp->exts[CLIENT_EXT_STARTTLS].fail = 1;
- if (client_next_state(sp))
- sp->state = client_next_state(sp);
- else
- goto done;
+ if ((sp->state = client_next_state(sp)) == 0)
+ return (CLIENT_ERROR);
} else
sp->state = CLIENT_SSL_INIT;
break;
@@ -493,10 +494,8 @@ client_read(struct smtp_client *sp)
else
sp->exts[CLIENT_EXT_AUTH].done = 1;
- if (client_next_state(sp))
- sp->state = client_next_state(sp);
- else
- goto done;
+ if ((sp->state = client_next_state(sp)) == 0)
+ return (CLIENT_ERROR);
break;
case CLIENT_MAILFROM:
@@ -705,14 +704,10 @@ client_ssl_connect(struct smtp_client *sp)
SSL_free(sp->ssl_state);
sp->ssl_state = NULL;
- if (client_next_state(sp)) {
- sp->state = client_next_state(sp);
- return (CLIENT_WANT_WRITE);
- } else {
- strlcpy(sp->ebuf, "130 SSL_connect error",
- sizeof(sp->ebuf));
+ if ((sp->state = client_next_state(sp)) == 0)
return (CLIENT_ERROR);
- }
+ else
+ return (CLIENT_WANT_WRITE);
} else {
strlcpy(sp->ebuf, "130 SSL_connect error", sizeof(sp->ebuf));
return (CLIENT_ERROR);
@@ -807,8 +802,11 @@ client_next_state(struct smtp_client *sp)
if (e->want && !e->done) {
if (e->have && !e->fail)
return (e->state);
- else if (e->must)
+ else if (e->must) {
+ snprintf(sp->ebuf, sizeof(sp->ebuf),
+ "150 Could not use %s", e->name);
return (0);
+ }
}
}
diff --git a/usr.sbin/smtpd/client.h b/usr.sbin/smtpd/client.h
index 3bc8bf01d63..14fefbe2e5f 100644
--- a/usr.sbin/smtpd/client.h
+++ b/usr.sbin/smtpd/client.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.h,v 1.3 2009/09/15 16:50:06 jacekm Exp $ */
+/* $OpenBSD: client.h,v 1.4 2009/09/22 12:24:06 jacekm Exp $ */
/*
* Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
@@ -67,6 +67,7 @@ struct client_ext {
short must;
short done;
short fail;
+ char *name;
int state;
};