Skip to content

Commit edbba2c

Browse files
committed
exch: avoid leaking delegate into SMTP FROM under Send-As powers
References: GXH-169
1 parent 06a4199 commit edbba2c

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

exch/emsmdb/common_util.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,8 +1458,11 @@ static BOOL common_util_get_propname(propid_t propid, PROPERTY_NAME **pppropname
14581458
return false;
14591459
}
14601460

1461+
/**
1462+
* @ev_from: address to use for Envelope-From
1463+
*/
14611464
ec_error_t cu_send_message(logon_object *plogon, message_object *msg,
1462-
bool b_submit) try
1465+
const char *ev_from) try
14631466
{
14641467
uint64_t message_id = msg->get_id();
14651468
MAIL imail;
@@ -1545,7 +1548,7 @@ ec_error_t cu_send_message(logon_object *plogon, message_object *msg,
15451548
}
15461549
}
15471550

1548-
auto ret = ems_send_mail(&imail, plogon->get_account(), rcpt_list);
1551+
auto ret = ems_send_mail(&imail, ev_from, rcpt_list);
15491552
if (ret != ecSuccess) {
15501553
mlog2(LV_ERR, "E-1280: failed to send %s via SMTP: %s",
15511554
log_id.c_str(), mapi_strerror(ret));

exch/emsmdb/common_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ BOOL common_util_convert_rule_actions(BOOL to_unicode, RULE_ACTIONS *pactions);
8989
extern void common_util_notify_receipt(const char *username, int type, message_content *brief);
9090
extern ec_error_t ems_send_mail(MAIL *, const char *sender, const std::vector<std::string> &rcpts);
9191
extern ec_error_t ems_send_vmail(vmime::shared_ptr<vmime::message>, const char *sender, const std::vector<std::string> &rcpts);
92-
extern ec_error_t cu_send_message(logon_object *, message_object *, bool submit);
92+
extern ec_error_t cu_send_message(logon_object *, message_object *, const char *ev_from);
9393
extern bool bounce_producer_make(bool (*)(const char *, char *, size_t), bool (*)(const char *, char *, size_t), bool (*)(const char *, char *, size_t), const char *user, message_content *, const char *bounce_type, MAIL *);
9494

9595
extern int (*common_util_add_timer)(const char *command, int interval);

exch/emsmdb/oxomsg.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ ec_error_t rop_submitmessage(uint8_t submit_flags, LOGMAP *plogmap,
425425
pmessage->reload();
426426
return ecSuccess;
427427
}
428-
429-
ret = cu_send_message(plogon, pmessage, true);
428+
429+
auto ev_from = repr_grant >= repr_grant::send_as ? delegator.c_str() : actor;
430+
ret = cu_send_message(plogon, pmessage, ev_from);
430431
if (ret != ecSuccess && ret != ecWarnWithErrors)
431432
exmdb_client->clear_submit(dir, pmessage->get_id(), b_unsent);
432433
else if (!b_delete)
@@ -664,7 +665,9 @@ ec_error_t rop_transportsend(TPROPVAL_ARRAY **pppropvals, LOGMAP *plogmap,
664665
}
665666
}
666667
}
667-
return cu_send_message(plogon, pmessage, false);
668+
669+
auto ev_from = repr_grant >= repr_grant::send_as ? delegator.c_str() : actor;
670+
return cu_send_message(plogon, pmessage, ev_from);
668671
} catch (const std::bad_alloc &) {
669672
mlog(LV_ERR, "E-2352: ENOMEM");
670673
return ecServerOOM;

exch/zcore/common_util.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ static BOOL common_util_get_propname(propid_t propid, PROPERTY_NAME **pppropname
10621062
}
10631063

10641064
ec_error_t cu_send_message(store_object *pstore, message_object *msg,
1065-
bool b_submit) try
1065+
const char *ev_from) try
10661066
{
10671067
uint64_t message_id = msg->get_id();
10681068
void *pvalue;
@@ -1143,8 +1143,7 @@ ec_error_t cu_send_message(store_object *pstore, message_object *msg,
11431143
}
11441144
}
11451145

1146-
auto ret = cu_send_mail(imail, g_smtp_url.c_str(),
1147-
pstore->get_account(), rcpt_list);
1146+
auto ret = cu_send_mail(imail, g_smtp_url.c_str(), ev_from, rcpt_list);
11481147
if (ret != ecSuccess) {
11491148
mlog(LV_ERR, "E-1194: failed to send %s via SMTP: %s",
11501149
log_id.c_str(), mapi_strerror(ret));

exch/zcore/common_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ BOOL common_util_load_file(const char *path, BINARY *pbin);
142142
extern BOOL common_util_convert_to_zrule_data(store_object *, TPROPVAL_ARRAY *);
143143
extern ec_error_t cu_remote_copy_message(store_object *s0, uint64_t message_id, store_object *s1, uint64_t folder_id1);
144144
extern ec_error_t cu_remote_copy_folder(store_object *s0, uint64_t folder_id, store_object *s1, uint64_t folder_id1, const char *new_name);
145-
extern ec_error_t cu_send_message(store_object *, message_object *, bool submit);
145+
extern ec_error_t cu_send_message(store_object *, message_object *, const char *ev_from);
146146
extern BOOL common_util_message_to_rfc822(store_object *, uint64_t inst_id, BINARY *eml);
147147
extern message_content *cu_rfc822_to_message(store_object *, unsigned int mxf_flags, BINARY *eml);
148148
extern BOOL common_util_message_to_ical(store_object *, uint64_t msg_id, BINARY *ical);

exch/zcore/zserver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3352,7 +3352,8 @@ ec_error_t zs_submitmessage(GUID hsession, uint32_t hmessage) try
33523352
return ecSuccess;
33533353
}
33543354
}
3355-
auto ret = cu_send_message(pstore, pmessage, TRUE);
3355+
auto ev_from = repr_grant >= repr_grant::send_as ? delegator.c_str() : actor;
3356+
auto ret = cu_send_message(pstore, pmessage, ev_from);
33563357
if (ret != ecSuccess) {
33573358
exmdb_client->clear_submit(pstore->get_dir(),
33583359
pmessage->get_id(), b_unsent);

0 commit comments

Comments
 (0)