summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2018-08-03 05:12:14 +0200
committerJan Holesovsky <kendy@collabora.com>2018-08-03 05:22:03 +0200
commitac7d67f43e2b82dcc841ca2ecae91e668eb90613 (patch)
treed7a6e9006e47fe3818ccba94b218d11c5770c4fc
parent521afe2e982378f821f01a81c265bc6b0ce4600a (diff)
Fix networking in the chroot.
The needed files were not copied, and consequently the hostname resolution did not work in the chroot. Change-Id: Id3dccc4f70cd1deeddb83c8e672f240e06748e34
-rw-r--r--kit/Kit.cpp52
-rwxr-xr-xloolwsd-systemplate-setup6
2 files changed, 30 insertions, 28 deletions
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index a6e386243..5a2148afa 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -190,6 +190,27 @@ namespace
}
}
+ void linkOrCopyFile(const char *fpath, Path newPath)
+ {
+ if (linkOrCopyVerboseLogging)
+ LOG_INF("Linking file \"" << fpath << "\" to \"" << newPath.toString() << "\"");
+ if (link(fpath, newPath.toString().c_str()) == -1)
+ {
+ LOG_INF("link(\"" << fpath << "\", \"" <<
+ newPath.toString() << "\") failed. Will copy.");
+ try
+ {
+ File(fpath).copyTo(newPath.toString());
+ }
+ catch (const std::exception& exc)
+ {
+ LOG_ERR("Copying of '" << fpath << "' to " << newPath.toString() <<
+ " failed: " << exc.what() << ". Exiting.");
+ std::_Exit(Application::EXIT_SOFTWARE);
+ }
+ }
+ }
+
int linkOrCopyFunction(const char *fpath,
const struct stat* /*sb*/,
int typeflag,
@@ -221,25 +242,7 @@ namespace
File(newPath.parent()).createDirectories();
if (shouldLinkFile(relativeOldPath))
- {
- if (linkOrCopyVerboseLogging)
- LOG_INF("Linking file \"" << fpath << "\" to \"" << newPath.toString() << "\"");
- if (link(fpath, newPath.toString().c_str()) == -1)
- {
- LOG_INF("link(\"" << fpath << "\", \"" <<
- newPath.toString() << "\") failed. Will copy.");
- try
- {
- File(fpath).copyTo(newPath.toString());
- }
- catch (const std::exception& exc)
- {
- LOG_ERR("Copying of '" << fpath << "' to " << newPath.toString() <<
- " failed: " << exc.what() << ". Exiting.");
- std::_Exit(Application::EXIT_SOFTWARE);
- }
- }
- }
+ linkOrCopyFile(fpath, newPath);
break;
case FTW_D:
{
@@ -2208,16 +2211,15 @@ void lokit_main(const std::string& childRoot,
bLoopMounted ? LinkOrCopyType::NoUsr : LinkOrCopyType::All);
linkOrCopy(loTemplate, jailLOInstallation, LinkOrCopyType::LO);
- // We need this because sometimes the hostname is not resolved
- const std::initializer_list<const char*> networkFiles = {"/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"};
- for (const auto& filename : networkFiles)
+ // Copy some needed files - makes the networking work in the
+ // chroot
+ const std::initializer_list<const char*> files = {"/etc/passwd", "/etc/group", "/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"};
+ for (const auto& filename : files)
{
const Poco::Path etcPath = Path(jailPath, filename);
const std::string etcPathString = etcPath.toString();
if (File(filename).exists() && !File(etcPathString).exists() )
- {
- linkOrCopy( filename, etcPath, LinkOrCopyType::All );
- }
+ linkOrCopyFile(filename, etcPath);
}
LOG_DBG("Initialized jail files.");
diff --git a/loolwsd-systemplate-setup b/loolwsd-systemplate-setup
index 3eed41ae6..986a83aee 100755
--- a/loolwsd-systemplate-setup
+++ b/loolwsd-systemplate-setup
@@ -21,10 +21,9 @@ cd / || exit 1
# into the template tree of system files for the chroot jails.
# First essential files and shared objects
-find etc/passwd etc/group etc/hosts \
- etc/resolv.conf \
- etc/ld.so.* \
+find etc/ld.so.* \
lib/ld-* lib64/ld-* \
+ lib64/libnss_* \
var/cache/fontconfig \
etc/fonts \
etc/localtime \
@@ -38,6 +37,7 @@ find etc/passwd etc/group etc/hosts \
find etc/fonts \
lib/ld-* lib64/ld-* \
+ lib64/libnss_* \
-type l 2>/dev/null
# Go through the LO shared objects and check what system libraries