Hi everybody,
The following diff adds sender expansions to OpenSMTPD.
%U for sender localpart
%D for sender domainpart
--- lka.c.orig Sun Jun 20 12:56:26 2010
+++ lka.c Sun Sep 5 16:41:37 2010
@@ -55,11 +55,11 @@
struct lkasession *lka_session_init(struct smtpd *, struct message *);
void lka_request_forwardfile(struct smtpd *, struct
lkasession *, struct path *); void
lka_clear_expandtree(struct expandtree *); void
lka_clear_deliverylist(struct deliverylist *); char
*lka_encode_secret(struct map_secret *); -size_t
lka_expand(char *, size_t, struct path *); +size_t
lka_expand(char *, size_t, struct path *,struct path *);
void lka_rcpt_action(struct smtpd *, char *, struct path
*); void lka_session_destroy(struct smtpd *, struct
lkasession *); void lka_expansion_done(struct smtpd *,
struct lkasession *); void lka_session_fail(struct smtpd
*, struct lkasession *); void lka_queue_append(struct
smtpd *, struct lkasession *, int); @@ -370,20 +370,19 @@ {
return 1;
}
size_t
-lka_expand(char *buf, size_t len, struct path *path)
+lka_expand(char *buf, size_t len, struct path *path, struct path
*sender) {
char *p, *pbuf;
struct rule r;
size_t ret;
struct passwd *pw;
bzero(r.r_value.path, MAXPATHLEN);
pbuf = r.r_value.path;
-
ret = 0;
for (p = path->rule.r_value.path; *p != '\0'; ++p) {
if (p == path->rule.r_value.path && *p == '~') {
if (*(p + 1) == '/' || *(p + 1) == '\0') {
pw = getpwnam(path->pw_name);
@@ -422,10 +421,26 @@
pbuf += strlen(pw->pw_dir);
p += strlen(username);
continue;
}
}
+ if (strncmp(p, "%U", 2) == 0) {
+ ret += strlcat(pbuf, sender->user, len);
+ if (ret >= len)
+ return ret;
+ pbuf += strlen (sender->user);
+ ++p;
+ continue;
+ }
+ if (strncmp(p,"%D",2) == 0) {
+ ret += strlcat(pbuf, sender->domain, len);
+ if (ret >= len)
+ return ret;
+ pbuf += strlen(sender->domain);
+ ++p;
+ continue;
+ }
if (strncmp(p, "%a", 2) == 0) {
ret += strlcat(pbuf, path->user, len);
if (ret >= len)
return ret;
pbuf += strlen(path->user);
@@ -680,11 +695,11 @@
return;
}
/* send next item to queue */
message = s->message;
- lka_expand(path->rule.r_value.path,
sizeof(path->rule.r_value.path), path);
+ lka_expand(path->rule.r_value.path,
sizeof(path->rule.r_value.path), path, &message.sender);
message.recipient = *path; sep = strchr(message.session_hostname, '@');
if (sep) {
*sep = '\0';
uid = strtonum(message.session_hostname, 0, UID_MAX,
&errstr);
--
With best regards,
Gregory Edigarov