Skip to content

Commit

Permalink
lokit: mount childroot/tmp/incoming/templates over instdir/share/comm…
Browse files Browse the repository at this point in the history
…on/template/presnt

- once we can download the templates from remote server it can be access
by lokit and gets added to MasterSlides impress

Signed-off-by: Rashesh <rashesh.padia@collabora.com>
Change-Id: I55cb4f340f66d353594331e25debd7124f25f042
  • Loading branch information
Rash419 committed Nov 14, 2024
1 parent 0381969 commit 9253478
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
4 changes: 3 additions & 1 deletion common/JailUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ void setupChildRoot(bool bindMount, const std::string& childRoot, const std::str
{
// Start with a clean slate.
cleanupJails(childRoot);
createJailPath(childRoot + CHILDROOT_TMP_INCOMING_PATH);

createJailPath(childRoot + CHILDROOT_TMP_INCOMING_PATH + "/fonts");
createJailPath(childRoot + CHILDROOT_TMP_INCOMING_PATH + "/templates");

disableBindMounting(); // Clear to avoid surprises.

Expand Down
32 changes: 32 additions & 0 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3189,6 +3189,10 @@ void lokit_main(
const std::string tmpSubDir = Poco::Path(tempRoot, "cool-" + jailId).toString();
const std::string jailTmpDir = Poco::Path(jailPath, "tmp").toString();

const std::string tmpIncoming = Poco::Path(childRoot, JailUtil::CHILDROOT_TMP_INCOMING_PATH).toString();
const std::string sharedTemplate = Poco::Path(tmpIncoming, "templates").toString();
const std::string loJailDestImpressTemplatePath = Poco::Path(loJailDestPath, "share/template/common/presnt").toString();

const std::string sysTemplateSubDir = Poco::Path(tempRoot, "systemplate-" + jailId).toString();
const std::string jailEtcDir = Poco::Path(jailPath, "etc").toString();

Expand Down Expand Up @@ -3248,6 +3252,34 @@ void lokit_main(
return false;
}

// copy default tempates from 'common' dir to shared templates dir
// TODO: maybe I shouldn't copy if whole point to mounting is that we don't require copying. Maybe symlink it
auto defaultTemplates = FileUtil::getDirEntries(loJailDestImpressTemplatePath);
for (auto& name : defaultTemplates)
{
std::string sourcePath = loJailDestImpressTemplatePath;
sourcePath.append("/");
sourcePath.append(name);
std::string destPath = sharedTemplate;
destPath.append("/");
destPath.append(name);
if (!FileUtil::copy(sourcePath, destPath, false, false))
{
LOG_WRN("Failed to copy default impress template from ["
<< sourcePath << "] to [" << sharedTemplate << ']');
}
}

// mount the shared templates over the lo shared templates' 'common' dir
if (!JailUtil::bind(sharedTemplate, loJailDestImpressTemplatePath) ||
!JailUtil::remountReadonly(sharedTemplate, loJailDestImpressTemplatePath))
{
// TODO: actually do this link on failure
LOG_WRN("Failed to mount [" << sharedTemplate << "] -> [" << sharedTemplate
<< "], will link contents");
return false;
}

// tmpdir inside the jail for added sercurity.
Poco::File(tmpSubDir).createDirectories();
LOG_INF("Mounting random temp dir " << tmpSubDir << " -> " << jailTmpDir);
Expand Down
18 changes: 17 additions & 1 deletion wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ std::string COOLWSD::ServerName;
std::string COOLWSD::FileServerRoot;
std::string COOLWSD::ServiceRoot;
std::string COOLWSD::TmpFontDir;
std::string COOLWSD::TmpTemplateDir;
std::string COOLWSD::LOKitVersion;
std::string COOLWSD::ConfigFile = COOLWSD_CONFIGDIR "/coolwsd.xml";
std::string COOLWSD::ConfigDir = COOLWSD_CONFIGDIR "/conf.d";
Expand Down Expand Up @@ -1340,6 +1341,8 @@ void COOLWSD::innerInitialize(Poco::Util::Application& self)
{ "extra_export_formats.impress_png", "false" },
{ "extra_export_formats.impress_svg", "false" },
{ "extra_export_formats.impress_tiff", "false" },
{ "remote_template_config.url", ""},
{ "remote_font_config.url", ""},
};

// Set default values, in case they are missing from the config file.
Expand Down Expand Up @@ -3600,7 +3603,8 @@ int COOLWSD::innerMain()
assert(Server && "The COOLWSDServer instance does not exist.");
Server->findClientPort();

TmpFontDir = ChildRoot + JailUtil::CHILDROOT_TMP_INCOMING_PATH;
TmpFontDir = ChildRoot + JailUtil::CHILDROOT_TMP_INCOMING_PATH + "/fonts";
TmpTemplateDir = ChildRoot + JailUtil::CHILDROOT_TMP_INCOMING_PATH + "/templates";

// Start the internal prisoner server and spawn forkit,
// which in turn forks first child.
Expand Down Expand Up @@ -3672,6 +3676,18 @@ int COOLWSD::innerMain()
{
LOG_DBG("No remote_font_config");
}

std::unique_ptr<RemoteTemplateConfigPoll> remoteTemplateConfigThread;
try
{
// Fetch font settings from server if configured
remoteTemplateConfigThread = std::make_unique<RemoteTemplateConfigPoll>(config());
remoteTemplateConfigThread->start();
}
catch (const Poco::Exception&)
{
LOG_DBG("No remote_template_config");
}
#endif

// URI with /contents are public and we don't need to anonymize them.
Expand Down
1 change: 1 addition & 0 deletions wsd/COOLWSD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class COOLWSD final : public Poco::Util::ServerApplication,
static std::string FileServerRoot;
static std::string ServiceRoot; ///< There are installations that need prefixing every page with some path.
static std::string TmpFontDir;
static std::string TmpTemplateDir;
static std::string LOKitVersion;
static bool EnableTraceEventLogging;
static bool EnableAccessibility;
Expand Down

0 comments on commit 9253478

Please sign in to comment.