Hi
I had a discussion about a way to use different passwords for smtpd auth
then for the rest of the system. In this dicousion it was noticed that
the username result of a credentials table is ignored.
This might leeds to problems when you want multible users/devices share
one account and check the sender. You either need to share the password
between all users/devices or your sender table. Alternative you could
have uniuqe usernames per user/device and your sender table needs to
know about them.
What do you think about changing this? So you have multible auth names
and the result of the credentials query sets the username. This way you
could simpler use a shared accout or have passwords per device without
the senders table need to know about the mapping username to actual user.
I have attached a patch for this. Only implemented for credentials
tables and not tested. It's mostly to have some code to discuss about.
To support auth tables the protocoll need a change. I would say it's
possible to do this in a backwards compatible way. I'm not sure, if the
reporting api also need a change.
Philipp
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 8c40f7b1..e0842c7c 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -44,7 +44,7 @@
static void lka_imsg(struct mproc *, struct imsg *);
static void lka_shutdown(void);
static void lka_sig_handler(int, short, void *);
-static int lka_authenticate(const char *, const char *, const char *);
+static int lka_authenticate(const char *, const char *, const char *, char *,
size_t);
static int lka_credentials(const char *, const char *, char *, size_t);
static int lka_userinfo(const char *, const char *, struct userinfo *);
static int lka_addrname(const char *, const struct sockaddr *,
@@ -69,6 +69,7 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
union lookup lk;
char buf[LINE_MAX];
const char *tablename, *username, *password, *label,
*procname;
+ char resultuser[SMTPD_MAXMAILADDRSIZE];
uint64_t reqid;
int v;
struct timeval tv;
@@ -171,7 +172,8 @@ lka_imsg(struct mproc *p, struct imsg *imsg)
return;
}
- ret = lka_authenticate(tablename, username, password);
+ resultuser[0] = 0;
+ ret = lka_authenticate(tablename, username, password,
resultuser, sizeof(resultuser));
m_create(p, IMSG_SMTP_AUTHENTICATE, 0, 0, -1);
m_add_id(p, reqid);
@@ -733,7 +735,7 @@ reset:
static int
-lka_authenticate(const char *tablename, const char *user, const char *password)
+lka_authenticate(const char *tablename, const char *user, const char
*password, char *resultuser, size_t resultuserlen)
{
struct table *table;
char offloadkey[LINE_MAX];
@@ -755,6 +757,7 @@ lka_authenticate(const char *tablename, const char *user,
const char *password)
tablename, user);
return (LKA_TEMPFAIL);
}
+ strncpy(resultuser, user, resultuserlen-1);
switch (table_match(table, K_AUTH, offloadkey)) {
case -1:
log_warnx("warn: user credentials lookup fail for
%s:%s",
@@ -775,6 +778,7 @@ lka_authenticate(const char *tablename, const char *user,
const char *password)
case 0:
return (LKA_PERMFAIL);
default:
+ strncpy(resultuser, lk.creds.username, resultuserlen-1);
if (crypt_checkpass(password, lk.creds.password) == 0)
return (LKA_OK);
return (LKA_PERMFAIL);
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index 4934ee85..833edf3e 100644
--- a/usr.sbin/smtpd/smtp_session.c
+++ b/usr.sbin/smtpd/smtp_session.c
@@ -711,6 +711,8 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg)
{
struct smtp_session *s;
struct smtp_rcpt *rcpt;
+ const char *resultuser;
+ char authname[SMTPD_MAXMAILADDRSIZE];
char user[SMTPD_MAXMAILADDRSIZE];
char tmp[SMTP_LINE_MAX];
struct msg m;
@@ -958,15 +960,19 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg)
m_msg(&m, imsg);
m_get_id(&m, &reqid);
m_get_int(&m, &success);
+ m_get_string(&m, &resultuser);
m_end(&m);
s = tree_xpop(&wait_parent_auth, reqid);
- strnvis(user, s->username, sizeof user, VIS_WHITE | VIS_SAFE);
+ strnvis(authname, s->username, sizeof user, VIS_WHITE |
VIS_SAFE);
if (success == LKA_OK) {
+ strncpy(s->username, resultuser, sizeof(s->username)-1);
+ strnvis(user, s->username, sizeof user, VIS_WHITE |
VIS_SAFE);
log_info("%016"PRIx64" smtp "
"authentication user=%s "
+ "authenticated user=%s "
"result=ok",
- s->id, user);
+ s->id, authname, user);
s->flags |= SF_AUTHENTICATED;
smtp_report_link_auth(s, user, "pass");
smtp_reply(s, "235 %s Authentication succeeded",
@@ -977,7 +983,7 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg)
"authentication user=%s "
"result=permfail",
s->id, user);
- smtp_report_link_auth(s, user, "fail");
+ smtp_report_link_auth(s, authname, "fail");
smtp_auth_failure_pause(s);
return;
}
@@ -986,7 +992,7 @@ smtp_session_imsg(struct mproc *p, struct imsg *imsg)
"authentication user=%s "
"result=tempfail",
s->id, user);
- smtp_report_link_auth(s, user, "error");
+ smtp_report_link_auth(s, authname, "error");
smtp_reply(s, "421 %s Temporary failure",
esc_code(ESC_STATUS_TEMPFAIL,
ESC_OTHER_MAIL_SYSTEM_STATUS));
}
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 2365b1ee..616a81e6 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -240,6 +240,7 @@ parent_imsg(struct mproc *p, struct imsg *imsg)
m_create(p, IMSG_LKA_AUTHENTICATE, 0, 0, -1);
m_add_id(p, reqid);
m_add_int(p, ret);
+ m_add_string(p, username);
m_close(p);
return;