From: Stefan Sperling Subject: tweak gotd.conf email sender syntax To: Robert Nagy Cc: gameoftrees@openbsd.org Date: Thu, 19 Nov 2026 10:16:57 +0100 Hi Robert, I would like to change the gotd.conf syntax you added as follows. Is this fine with you? change syntax for per-user sender addresses in gotd email notifications The new syntax is: email from authenticated user at "example.com" instead of: email from "$USER@example.com" Avoids having to manually parse and expand the address and thus simplifies the implementation. M gotd/gotd.c | 2+ 0- M gotd/gotd.conf.5 | 22+ 6- M gotd/gotd.h | 2+ 0- M gotd/imsg.c | 2+ 0- M gotd/notify.c | 21+ 45- M gotd/parse.y | 144+ 19- M regress/gotd/Makefile | 1+ 1- 7 files changed, 194 insertions(+), 71 deletions(-) commit - 3cdc802ab19f8bf84497703a8cb297eddf6a51d5b864b00402ee391916f56125 commit + 6a6258782ebca8127b64a80676afa2028a91e699fd612853ab12c09cf38859d6 blob - 15a965dd66a0beb2d432f098de25e9bd8d11035eb793264a45459cb2ad1df6ef blob + 020cf9a5498c6814576b58635fa4a68d35a7a334504e141e6eba52992d2d2b9f --- gotd/gotd.c +++ gotd/gotd.c @@ -1623,6 +1623,8 @@ send_notification_target_email(struct gotd_imsgev *iev memset(&itarget, 0, sizeof(itarget)); + itarget.sender_is_domain_name = + target->conf.email.sender_is_domain_name; if (target->conf.email.sender) itarget.sender_len = strlen(target->conf.email.sender); else blob - 44db84a725755773bc36bea63eeb1c3ed668cedfe5e17ffadc68c8ede0c785e2 blob + 4e8295ea6c4e4f01fe67e6a1745b3472decdca9cdf04acd3d1eae6ad07d1df1b --- gotd/gotd.conf.5 +++ gotd/gotd.conf.5 @@ -326,7 +326,7 @@ If neither a nor a .Ic reference namespace are specified then changes to any reference will trigger notifications. -.It Ic email Oo Ic from Ar sender Oc Ic to Ar recipient Oo Ic reply to Ar responder Oc Oo Ic relay Ar hostname Oo Ic port Ar port Oc Oc +.It Ic email Oo Ic from Ar sender | Ic from Ic authenticated Ic user Ic at Ar domain Oc Ic to Ar recipient Oo Ic reply to Ar responder Oc Oo Ic relay Ar hostname Oo Ic port Ar port Oc Oc Send notifications via email to the specified .Ar recipient . This directive may be specified multiple times to build a list of @@ -335,12 +335,28 @@ recipients to send notifications to. The .Ar recipient must be an email addresses that accepts mail. -The -.Ar sender -will be used as the From address. -If not specified, the sender defaults to an email address composed of the user -account running +.Pp +The From address can be configured in two ways: +Either by setting a fixed email address with +.Ic from Ar sender , +or by setting +.Ic from authenticated user at Ar domain +which asks .Xr gotd 8 +to construct a From address by combining the authenticated user's login name +with the provided domain name. +For example, setting +.Ar domain +to +.Dq example.com +would result in the sender +.Dq username@example.com , +where the username is authenticated. +Unlike the email addresses given in Git commit objects, an address using +the authenticated username cannot be spoofed. +If the From address is not configured, the sender defaults to an email +address composed of the user account running +.Xr gotd 8 and the local hostname. .Pp If a blob - 5740104e480e31cf2c0fc08857f2aa9f7a8ee1bb2bd281514d9c03ec50a8d096 blob + a8f6a30ee94af344ba046c94d5affa640694023bb77e93ba761994dc0eaaae44 --- gotd/gotd.h +++ gotd/gotd.h @@ -117,6 +117,7 @@ struct gotd_notification_target { char *responder; char *hostname; char *port; + int sender_is_domain_name; } email; struct { int tls; @@ -628,6 +629,7 @@ struct gotd_imsg_pathlist_elem { /* Structure for GOTD_IMSG_NOTIFICATION_TARGET_EMAIL. */ struct gotd_imsg_notitfication_target_email { + int sender_is_domain_name; size_t sender_len; size_t recipient_len; size_t responder_len; blob - 79de21c623b4c681a38d9eaca1da38b6f3997505be2fb38c6ce0334bb11efba3 blob + bc622dd9f05cd05978150be9885697fa14770e79a7a36f6b9535c06a10d68879 --- gotd/imsg.c +++ gotd/imsg.c @@ -220,6 +220,8 @@ gotd_imsg_recv_notification_target_email(char **repo_n target->type = GOTD_NOTIFICATION_VIA_EMAIL; + target->conf.email.sender_is_domain_name = + itarget.sender_is_domain_name; if (itarget.sender_len) { target->conf.email.sender = strndup(imsg->data + sizeof(itarget), itarget.sender_len); blob - fb5bd08ebb32136b35dff1d15f97666c4677096828da575491781bff62ba766f blob + 0d4e115dec8b33d3c5724da8592c70ea16532857e27f8374c7beb84edd882f1e --- gotd/notify.c +++ gotd/notify.c @@ -241,62 +241,38 @@ done: prog, pid, err->msg); } -static char * -expand_email_sender(const char *sender, const char *username) -{ - const char *var = "$USER", *p, *s; - size_t varlen = strlen(var), userlen = strlen(username); - size_t n = 0, len; - char *expanded, *q; - - for (p = strstr(sender, var); p != NULL; p = strstr(p + varlen, var)) - n++; - - len = strlen(sender) - n * varlen + n * userlen; - expanded = malloc(len + 1); - if (expanded == NULL) { - log_warn("%s: malloc", gotd_notify.title); - return NULL; - } - - q = expanded; - s = sender; - while ((p = strstr(s, var)) != NULL) { - memcpy(q, s, p - s); - q += p - s; - memcpy(q, username, userlen); - q += userlen; - s = p + varlen; - } - strlcpy(q, s, len + 1 - (q - expanded)); - - return expanded; -} - static void notify_email(struct gotd_notification_target *target, const char *subject_line, const char *username, int fd) { const char *argv[13]; char *sender = NULL; - int i = 0; + char buf[512]; + int i = 0, ret; argv[i++] = GOTD_PATH_PROG_NOTIFY_EMAIL; - if (strstr(target->conf.email.sender, "$USER") == NULL) { + if (target->conf.email.sender_is_domain_name) { + ret = snprintf(buf, sizeof(buf), "%s@%s", username, + target->conf.email.sender); + if (ret < 0) { + log_warnx("%s: encountered %s with email notification " + "sender: %s@%s", gotd_notify.title, strerror(errno), + username, target->conf.email.sender); + return; + } + if (ret >= sizeof(buf)) { + log_warnx("%s: email notification sender too long " + "(exceeds %zu bytes): %s@%s ", gotd_notify.title, + sizeof(buf) - 1, username, + target->conf.email.sender); + return; + } argv[i++] = "-f"; + argv[i++] = buf; + } else { + argv[i++] = "-f"; argv[i++] = target->conf.email.sender; - } else { - sender = expand_email_sender(target->conf.email.sender, - username); - if (sender) { - argv[i++] = "-f"; - argv[i++] = sender; - } else { - log_warnx("%s: cannot expand address '%s'; using " - "the default instead", gotd_notify.title, - target->conf.email.sender); - } } if (target->conf.email.responder) { blob - d7a183f555b4da323759f5c41788b5822ee7eb86f8765bde9abca033dfca5862 blob + f81a13c425aaf72e3f7b5e35a83252876af2c86f3192024742b8cadc151ac362 --- gotd/parse.y +++ gotd/parse.y @@ -116,7 +116,7 @@ static int conf_notify_branch(struct gotd_repo *, static int conf_notify_ref_namespace(struct gotd_repo *, char *); static int conf_notify_email(struct gotd_repo *, - char *, char *, char *, char *, char *); + char *, char *, char *, char *, char *, int); static int conf_notify_http(struct gotd_repo *, char *, char *, char *, int); static enum gotd_procid gotd_proc_id; @@ -136,7 +136,7 @@ typedef struct { %token RO RW CONNECTION LIMIT REQUEST TIMEOUT %token PROTECT NAMESPACE BRANCH TAG REFERENCE RELAY PORT %token OBJECTSIZE -%token NOTIFY EMAIL FROM REPLY TO URL INSECURE HMAC AUTH +%token NOTIFY EMAIL FROM REPLY TO URL INSECURE HMAC AUTH AUTHENTICATED AT %token STRING %token NUMBER @@ -382,7 +382,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - NULL, NULL, NULL)) { + NULL, NULL, NULL, 0)) { free($3); YYERROR; } @@ -392,7 +392,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - NULL, NULL, NULL)) { + NULL, NULL, NULL, 0)) { free($3); free($5); YYERROR; @@ -404,7 +404,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING REPLY TO STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - $6, NULL, NULL)) { + $6, NULL, NULL, 0)) { free($3); free($6); YYERROR; @@ -416,7 +416,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING REPLY TO STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - $8, NULL, NULL)) { + $8, NULL, NULL, 0)) { free($3); free($5); free($8); @@ -430,7 +430,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING RELAY STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - NULL, $5, NULL)) { + NULL, $5, NULL, 0)) { free($3); free($5); YYERROR; @@ -442,7 +442,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING RELAY STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - NULL, $7, NULL)) { + NULL, $7, NULL, 0)) { free($3); free($5); free($7); @@ -456,7 +456,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING REPLY TO STRING RELAY STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - $6, $8, NULL)) { + $6, $8, NULL, 0)) { free($3); free($6); free($8); @@ -470,7 +470,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING REPLY TO STRING RELAY STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - $8, $10, NULL)) { + $8, $10, NULL, 0)) { free($3); free($5); free($8); @@ -486,7 +486,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING RELAY STRING PORT STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - NULL, $5, $7)) { + NULL, $5, $7, 0)) { free($3); free($5); free($7); @@ -500,7 +500,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING RELAY STRING PORT STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - NULL, $7, $9)) { + NULL, $7, $9, 0)) { free($3); free($5); free($7); @@ -516,7 +516,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING REPLY TO STRING RELAY STRING PORT STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - $6, $8, $10)) { + $6, $8, $10, 0)) { free($3); free($6); free($8); @@ -532,7 +532,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING REPLY TO STRING RELAY STRING PORT STRING { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - $8, $10, $12)) { + $8, $10, $12, 0)) { free($3); free($5); free($8); @@ -550,7 +550,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING RELAY STRING PORT NUMBER { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - NULL, $5, port_sprintf($7))) { + NULL, $5, port_sprintf($7), 0)) { free($3); free($5); YYERROR; @@ -562,7 +562,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING RELAY STRING PORT NUMBER { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - NULL, $7, port_sprintf($9))) { + NULL, $7, port_sprintf($9), 0)) { free($3); free($5); free($7); @@ -576,7 +576,7 @@ notifyflags : BRANCH STRING { | EMAIL TO STRING REPLY TO STRING RELAY STRING PORT NUMBER { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, NULL, $3, - $6, $8, port_sprintf($10))) { + $6, $8, port_sprintf($10), 0)) { free($3); free($6); free($8); @@ -590,7 +590,7 @@ notifyflags : BRANCH STRING { | EMAIL FROM STRING TO STRING REPLY TO STRING RELAY STRING PORT NUMBER { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_email(new_repo, $3, $5, - $8, $10, port_sprintf($12))) { + $8, $10, port_sprintf($12), 0)) { free($3); free($5); free($8); @@ -625,6 +625,126 @@ notifyflags : BRANCH STRING { free($2); free($4); } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + NULL, NULL, NULL, 1)) { + free($6); + free($8); + YYERROR; + } + } + free($6); + free($8); + } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING REPLY TO STRING { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + $11, NULL, NULL, 1)) { + free($6); + free($8); + free($11); + YYERROR; + } + } + free($6); + free($8); + free($11); + } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING RELAY STRING { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + NULL, $10, NULL, 1)) { + free($6); + free($8); + free($10); + YYERROR; + } + } + free($6); + free($8); + free($10); + } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING REPLY TO STRING RELAY STRING { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + $11, $13, NULL, 1)) { + free($6); + free($8); + free($11); + free($13); + YYERROR; + } + } + free($6); + free($8); + free($11); + free($13); + } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING RELAY STRING PORT STRING { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + NULL, $10, $12, 1)) { + free($6); + free($8); + free($10); + free($12); + YYERROR; + } + } + free($6); + free($8); + free($10); + free($12); + } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING REPLY TO STRING RELAY STRING PORT STRING { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + $11, $13, $15, 1)) { + free($6); + free($8); + free($11); + free($13); + free($15); + YYERROR; + } + } + free($6); + free($8); + free($11); + free($13); + free($15); + } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING RELAY STRING PORT NUMBER { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + NULL, $10, port_sprintf($12), 1)) { + free($6); + free($8); + free($10); + YYERROR; + } + } + free($6); + free($8); + free($10); + } + | EMAIL FROM AUTHENTICATED USER AT STRING TO STRING REPLY TO STRING RELAY STRING PORT NUMBER { + if (gotd_proc_id == GOTD_PROC_GOTD) { + if (conf_notify_email(new_repo, $6, $8, + $11, $13, port_sprintf($15), 1)) { + free($6); + free($8); + free($11); + free($13); + YYERROR; + } + } + free($6); + free($8); + free($11); + free($13); + } | URL STRING AUTH STRING INSECURE { if (gotd_proc_id == GOTD_PROC_GOTD) { if (conf_notify_http(new_repo, $2, $4, NULL, @@ -828,7 +948,9 @@ lookup(char *s) { /* This has to be sorted always. */ static const struct keywords keywords[] = { + { "at", AT }, { "auth", AUTH }, + { "authenticated", AUTHENTICATED }, { "branch", BRANCH }, { "connection", CONNECTION }, { "deny", DENY }, @@ -1591,7 +1713,8 @@ conf_notify_ref_namespace(struct gotd_repo *repo, char static int conf_notify_email(struct gotd_repo *repo, char *sender, char *recipient, - char *responder, char *hostname, char *port) + char *responder, char *hostname, char *port, + int sender_is_domain_name) { struct gotd_notification_target *target; @@ -1633,6 +1756,8 @@ conf_notify_email(struct gotd_repo *repo, char *sender fatal("strdup"); } + target->conf.email.sender_is_domain_name = sender_is_domain_name; + STAILQ_INSERT_TAIL(&repo->notification_targets, target, entry); return 0; } blob - e452a011285e97757a240faf267fbcc0f04cf44f0d43b1e49614432cf15aa7ac blob + 920e6664d9537cf1fa9458b485afd10cd1eaf76e72edda1302931521e7c0bafe --- regress/gotd/Makefile +++ regress/gotd/Makefile @@ -220,7 +220,7 @@ start_gotd_email_notification_from: ensure_root @echo ' path "$(GOTD_TEST_REPO)"' >> $(PWD)/gotd.conf @echo ' permit rw $(GOTD_DEVUSER)' >> $(PWD)/gotd.conf @echo ' notify {' >> $(PWD)/gotd.conf - @echo -n ' email from "$$USER@$(GOTD_HOSTNAME)"' >> $(PWD)/gotd.conf + @echo -n ' email from authenticated user at $(GOTD_HOSTNAME)' >> $(PWD)/gotd.conf @echo -n ' to ${GOTD_DEVUSER}' >> $(PWD)/gotd.conf @echo ' relay 127.0.0.1 port ${GOTD_TEST_SMTP_PORT}' >> $(PWD)/gotd.conf @echo " }" >> $(PWD)/gotd.conf