summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2009-01-27 15:50:16 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2009-01-27 15:50:16 +0000
commit1fa0acbd00211dd8b889e3aa415d3d67e3f8f2cc (patch)
tree047fd73f1ab696832ff167140e975992d83e2add /usr.sbin
parentc36ec2b55536d80e2fd7bd3318c2c29c0220b449 (diff)
*** empty log message ***
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/util.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index b6c5d039d06..360bd8297bc 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.6 2009/01/08 19:17:31 jacekm Exp $ */
+/* $OpenBSD: util.c,v 1.7 2009/01/27 15:50:15 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -78,6 +78,17 @@ safe_getpwnam(const char *name)
return ret;
}
+struct passwd *
+safe_getpwuid(uid_t uid)
+{
+ struct passwd *ret;
+
+ ret = getpwuid(uid);
+ endpwent();
+
+ return ret;
+}
+
int
hostname_match(char *hostname, char *pattern)
{
@@ -99,3 +110,53 @@ hostname_match(char *hostname, char *pattern)
return (*hostname == '\0' && *pattern == '\0');
}
+
+int
+recipient_to_path(struct path *path, char *recipient)
+{
+ size_t len;
+ char *username;
+ char *hostname;
+
+ username = recipient;
+ hostname = strchr(username, '@');
+
+ if (username[0] == '\0') {
+ *path->user = '\0';
+ *path->domain = '\0';
+ return 1;
+ }
+
+ if (hostname == NULL) {
+ if (strcasecmp(username, "postmaster") != 0)
+ return 0;
+ hostname = "localhost";
+ } else {
+ *hostname++ = '\0';
+ }
+
+ if (strlcpy(path->user, username, sizeof(path->user))
+ >= MAX_LOCALPART_SIZE)
+ return 0;
+
+ if (strlcpy(path->domain, hostname, sizeof(path->domain))
+ >= MAX_DOMAINPART_SIZE)
+ return 0;
+
+ return 1;
+}
+
+int
+session_set_path(struct path *path, char *line)
+{
+ size_t len;
+ char *username;
+ char *hostname;
+
+ len = strlen(line);
+ if (*line != '<' || line[len - 1] != '>')
+ return 0;
+ line[len - 1] = '\0';
+
+ return recipient_to_path(path, line+1);
+}