diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2010-04-21 21:47:40 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2010-04-21 21:47:40 +0000 |
commit | f209e1c2b2287d23574cf017ff6687e5d0a1ff4e (patch) | |
tree | 61e5b3dd59b80c893ffba80f5e69fe03708491cc /usr.sbin/smtpd/lka.c | |
parent | 6eefdaa84a48152289e968a9f5ea3d8324a4404c (diff) |
introduce first map parser for maps of kind K_SECRETS !
map_parse_secret() converts a map value into a struct map_secret. lka no
longer needs to do any parsing, it simply calls map_lookup() with kind
K_SECRETS, checks if it returned a !NULL value, and call lka_encode_secret
to safely do the base64 encoding.
Diffstat (limited to 'usr.sbin/smtpd/lka.c')
-rw-r--r-- | usr.sbin/smtpd/lka.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 0d5376f6125..0dfdbe2990d 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.105 2010/04/21 19:53:15 gilles Exp $ */ +/* $OpenBSD: lka.c,v 1.106 2010/04/21 21:47:38 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -56,7 +56,7 @@ struct lkasession *lka_session_init(struct smtpd *, struct submit_status *); void lka_request_forwardfile(struct smtpd *, struct lkasession *, char *); void lka_clear_expandtree(struct expandtree *); void lka_clear_deliverylist(struct deliverylist *); -int lka_encode_credentials(char *, size_t, char *); +int lka_encode_credentials(char *, size_t, struct map_secret *); size_t lka_expand(char *, size_t, struct path *); void lka_rcpt_action(struct smtpd *, char *, struct path *); void lka_session_destroy(struct smtpd *, struct lkasession *); @@ -127,25 +127,27 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) if (iev->proc == PROC_MTA) { switch (imsg->hdr.type) { - case IMSG_LKA_SECRET: + case IMSG_LKA_SECRET: { + struct map_secret *map_secret; secret = imsg->data; map = map_findbyname(env, "secrets"); if (map == NULL) fatalx("lka: secrets map not found"); - tmp = map_lookup(env, map->m_id, secret->host, K_SECRETS); + map_secret = map_lookup(env, map->m_id, secret->host, K_SECRETS); log_debug("lka: %s secret lookup (%d)", secret->host, - tmp != NULL); + map_secret != NULL); secret->secret[0] = '\0'; - if (tmp == NULL) + if (map_secret == NULL) log_warnx("%s secret not found", secret->host); else if (lka_encode_credentials(secret->secret, - sizeof secret->secret, tmp) == 0) + sizeof secret->secret, map_secret) == 0) log_warnx("%s secret parse fail", secret->host); imsg_compose_event(iev, IMSG_LKA_SECRET, 0, 0, -1, secret, sizeof *secret); - free(tmp); + free(map_secret); return; } + } } if (iev->proc == PROC_PARENT) { @@ -795,16 +797,13 @@ lka_clear_deliverylist(struct deliverylist *deliverylist) } int -lka_encode_credentials(char *dst, size_t size, char *user) +lka_encode_credentials(char *dst, size_t size, struct map_secret *map_secret) { - char *pass, *buf; + char *buf; int buflen; - if ((pass = strchr(user, ':')) == NULL) - return 0; - *pass++ = '\0'; - - if ((buflen = asprintf(&buf, "%c%s%c%s", '\0', user, '\0', pass)) == -1) + if ((buflen = asprintf(&buf, "%c%s%c%s", '\0', map_secret->username, + '\0', map_secret->password)) == -1) fatal(NULL); if (__b64_ntop((unsigned char *)buf, buflen, dst, size) == -1) { |