diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-05-29 19:29:45 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-05-29 19:29:45 +0000 |
commit | 154d22040ca20321a86ea0ba54a273ff37622c2b (patch) | |
tree | 2db3c0e54afc81d84d122a3899065b16c33f2d39 | |
parent | b70f81d3e019d369a491733fede64051e6b7e69c (diff) |
- introduce text_to_relayhost() which converts an url into a relayhost.
urls are of the form: [schema://]host[:ip]
not used, yet other commits are following ;-)
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/util.c | 59 |
2 files changed, 60 insertions, 2 deletions
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index d01914be273..bc5799edfba 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.293 2012/05/13 00:10:49 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.294 2012/05/29 19:29:44 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1231,3 +1231,4 @@ int rmtree(char *, int); int mvpurge(char *, char *); const char *parse_smtp_response(char *, size_t, char **, int *); int text_to_netaddr(struct netaddr *, char *); +int text_to_relayhost(struct relayhost *, char *); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index b83e7b4c814..1d724145d78 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.59 2012/05/23 22:46:58 gilles Exp $ */ +/* $OpenBSD: util.c,v 1.60 2012/05/29 19:29:44 gilles Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -464,6 +464,63 @@ text_to_netaddr(struct netaddr *netaddr, char *s) return 1; } +int +text_to_relayhost(struct relayhost *relay, char *s) +{ + u_int32_t i; + struct schema { + char *name; + u_int8_t flags; + } schemas [] = { + { "smtp://", 0 }, + { "smtps://", F_SMTPS }, + { "starttls://", F_STARTTLS }, + { "smtps+auth://", F_SMTPS|F_AUTH }, + { "starttls+auth://", F_STARTTLS|F_AUTH }, + { "ssl://", F_SMTPS|F_STARTTLS }, + { "ssl+auth://", F_SMTPS|F_STARTTLS|F_AUTH } + }; + const char *errstr = NULL; + char *p; + char *sep; + int len; + + for (i = 0; i < nitems(schemas); ++i) + if (strncasecmp(schemas[i].name, s, strlen(schemas[i].name)) == 0) + break; + + if (i == nitems(schemas)) { + /* there is a schema, but it's not recognized */ + if (strstr(s, "://")) + return 0; + + /* no schema, default to smtp:// */ + i = 0; + p = s; + } + else + p = s + strlen(schemas[i].name); + + relay->flags = schemas[i].flags; + + if ((sep = strrchr(p, ':')) != NULL) { + relay->port = strtonum(sep+1, 1, 0xffff, &errstr); + if (errstr) + return 0; + len = sep - p; + } + else + len = strlen(p); + + if (strlcpy(relay->hostname, p, sizeof (relay->hostname)) + >= sizeof (relay->hostname)) + return 0; + + relay->hostname[len] = 0; + + return 1; +} + /* * Check file for security. Based on usr.bin/ssh/auth.c. */ |