Skip to content

Commit 85bba89

Browse files
committed
exmdb: make message creation RPCs support EML midstrs with subdirs
References: GXL-411
1 parent 6e486ff commit 85bba89

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

exch/exmdb/common_util.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4694,6 +4694,11 @@ static errno_t copy_eml_ext(const char *old_midstr, std::string &new_midstr) try
46944694
new_midstr = fmt::format("{}.x{}.{}", time(nullptr), common_util_sequence_ID(), get_host_ID());
46954695
auto old_eml = fmt::format("{}/eml/{}", basedir, old_midstr);
46964696
auto new_eml = fmt::format("{}/eml/{}", basedir, new_midstr);
4697+
auto ret = gx_mkbasedir(new_eml.c_str(), FMODE_PRIVATE | S_IXUSR | S_IXGRP);
4698+
if (ret < 0) {
4699+
mlog(LV_ERR, "E-1493: mkbasedir for %s: %s", new_eml.c_str(), strerror(-ret));
4700+
return -ret;
4701+
}
46974702
/*
46984703
* Partial mailboxes (without cid/-like directories) are
46994704
* normal for debugging, don't warn in that case.
@@ -4707,6 +4712,11 @@ static errno_t copy_eml_ext(const char *old_midstr, std::string &new_midstr) try
47074712
}
47084713
auto old_ext = fmt::format("{}/ext/{}", basedir, old_midstr);
47094714
auto new_ext = fmt::format("{}/ext/{}", basedir, new_midstr);
4715+
ret = gx_mkbasedir(new_ext.c_str(), FMODE_PRIVATE | S_IXUSR | S_IXGRP);
4716+
if (ret < 0) {
4717+
mlog(LV_ERR, "E-1495: mkbasedir for %s: %s", new_ext.c_str(), strerror(-ret));
4718+
return -ret;
4719+
}
47104720
if (link(old_ext.c_str(), new_ext.c_str()) < 0) {
47114721
int se = errno;
47124722
if (errno != ENOENT || g_dbg_synth_content == 0)

exch/exmdb/message.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,7 +3104,12 @@ static ec_error_t op_delegate(const rulexec_in &rp, seen_list &seen,
31043104
auto mid_string = fmt::format("{}.x{}.{}", time(nullptr),
31053105
common_util_sequence_ID(), get_host_ID());
31063106
auto eml_path = maildir + "/eml/"s + mid_string;
3107-
auto ret = HX_copy_file(tmp_path1, eml_path.c_str(), 0);
3107+
auto ret = gx_mkbasedir(eml_path.c_str(), FMODE_PRIVATE | S_IXUSR | S_IXGRP);
3108+
if (ret < 0) {
3109+
mlog(LV_ERR, "E-1492: mkbasedir for %s: %s", eml_path.c_str(), strerror(-ret));
3110+
continue;
3111+
}
3112+
ret = HX_copy_file(tmp_path1, eml_path.c_str(), 0);
31083113
if (ret < 0) {
31093114
mlog(LV_ERR, "E-1606: HX_copy_file %s -> %s: %s",
31103115
tmp_path1, eml_path.c_str(), strerror(-ret));
@@ -3410,7 +3415,12 @@ static ec_error_t opx_delegate(const rulexec_in &rp, const rule_node &rule,
34103415
auto mid_string = fmt::format("{}.x{}.{}", time(nullptr),
34113416
common_util_sequence_ID(), get_host_ID());
34123417
auto eml_path = maildir + "/eml/"s + mid_string;
3413-
auto ret = HX_copy_file(tmp_path1, eml_path.c_str(), 0);
3418+
auto ret = gx_mkbasedir(eml_path.c_str(), FMODE_PRIVATE | S_IXUSR | S_IXGRP);
3419+
if (ret < 0) {
3420+
mlog(LV_ERR, "E-1493: mkbasedir for %s: %s", eml_path.c_str(), strerror(-ret));
3421+
continue;
3422+
}
3423+
ret = HX_copy_file(tmp_path1, eml_path.c_str(), 0);
34143424
if (ret < 0) {
34153425
mlog(LV_ERR, "E-1607: HX_copy_file %s -> %s: %s",
34163426
tmp_path1, eml_path.c_str(), strerror(-ret));
@@ -3766,6 +3776,11 @@ BOOL exmdb_server::deliver_message(const char *dir, const char *from_address,
37663776
snprintf(tmp_path, std::size(tmp_path), "%s/ext/%s",
37673777
exmdb_server::get_dir(), mid_string);
37683778
auto djson = json_to_str(std::move(newdigest));
3779+
auto ret = gx_mkbasedir(tmp_path, FMODE_PRIVATE | S_IXUSR | S_IXGRP);
3780+
if (ret < 0) {
3781+
mlog(LV_ERR, "E-1942: mkbasedir for %s: %s", tmp_path, strerror(-ret));
3782+
return false;
3783+
}
37693784
wrapfd fd = open(tmp_path, O_CREAT | O_TRUNC | O_WRONLY, FMODE_PRIVATE);
37703785
if (fd.get() >= 0) {
37713786
if (HXio_fullwrite(fd.get(), djson.c_str(), djson.size()) < 0 ||
@@ -3900,6 +3915,11 @@ BOOL exmdb_server::write_message(const char *dir, cpid_t cpid,
39003915
if (json_from_str(digest_stream, digest) &&
39013916
digest["file"].asString().size() > 0) {
39023917
std::string ext_file = exmdb_server::get_dir() + "/ext/"s + digest["file"].asString();
3918+
auto ret = gx_mkbasedir(ext_file.c_str(), FMODE_PRIVATE);
3919+
if (ret < 0) {
3920+
mlog(LV_ERR, "E-1944: mkbasedir for %s: %s", ext_file.c_str(), strerror(-ret));
3921+
return false;
3922+
}
39033923
wrapfd fd = open(ext_file.c_str(), O_CREAT | O_TRUNC | O_WRONLY, FMODE_PRIVATE);
39043924
if (fd.get() >= 0) {
39053925
if (HXio_fullwrite(fd.get(), digest_stream.c_str(), digest_stream.size()) < 0 ||

exch/exmdb/store2.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,14 @@ BOOL exmdb_server::imapfile_write(const char *dir, const std::string &type,
652652
auto wrret = HXio_fullwrite(fd, data.data(), data.size());
653653
if (wrret < 0 || static_cast<size_t>(wrret) != data.size())
654654
return false;
655+
655656
auto tgt = fmt::format("{}/{}/{}", dir, type, mid);
657+
auto ret = gx_mkbasedir(mid.c_str(), FMODE_PRIVATE);
658+
if (ret < 0) {
659+
mlog(LV_ERR, "E-1941: mkdir %s: %s", mid.c_str(), strerror(-ret));
660+
return false;
661+
}
662+
656663
auto err = tf.link_to(tgt.c_str());
657664
if (err != 0) {
658665
mlog(LV_ERR, "E-1752: link_to %s: %s", tgt.c_str(), strerror(errno));

mda/exmdb_local/exmdb_local.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ delivery_status exmdb_local_deliverquota(MESSAGE_CONTEXT *pcontext,
288288
}
289289
auto mid_string = fmt::format("{}.l{}.{}", time(nullptr), sequence_ID, hostname);
290290
auto eml_path = mres.maildir + "/eml/" + mid_string;
291+
292+
auto iret = gx_mkbasedir(eml_path.c_str(), FMODE_PRIVATE | S_IXUSR | S_IXGRP);
293+
if (iret < 0) {
294+
mlog(LV_ERR, "E-1493: mkbasedir for %s: %s", eml_path.c_str(), strerror(-iret));
295+
return delivery_status::temp_fail;
296+
}
291297
wrapfd fd = open(eml_path.c_str(), O_CREAT | O_RDWR | O_TRUNC, FMODE_PRIVATE);
292298
if (fd.get() < 0) {
293299
auto se = errno;

0 commit comments

Comments
 (0)