Commit afe4bae9 authored by jan.koester's avatar jan.koester
Browse files

test

parent c1c0df9c
Loading
Loading
Loading
Loading
+12 −0
Changes for src/config.cpp: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <pwd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>

#if __has_include(<sys/uid_r.h>)
@@ -164,6 +165,17 @@ std::string tr(const std::string &lang, const char *en, const char *de, std::ini
    return out;
}

void loadModule(const std::string &name) {
    pid_t pid = fork();
    if (pid == 0) {
        execl("/bin/modprobe", "modprobe", "-q", "--", name.c_str(), (char *)nullptr);
        _exit(127);
    }
    if (pid > 0)
        while (waitpid(pid, nullptr, 0) < 0 && errno == EINTR) {
        }
}

bool underRoot(const std::string &path, const std::string &root) {
    if (root == "/") return true;
    return path == root || (path.size() > root.size() && path.compare(0, root.size(), root) == 0 &&
+3 −0
Changes for src/config.h: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -144,6 +144,9 @@ std::string tr(const std::string &lang, const char *en, const char *de, std::ini
// given), else why not (in lang). Normalizes it (path without trailing /).
std::string checkShare(Share &share, const Config &cfg, const std::string &oldName = "", const std::string &lang = "en");
std::string checkSettings(const Settings &s, const std::string &lang = "en");
// modprobe -q NAME, waited for: ksmbd, nfsd and LIO may be modules the
// kernel doesn't load by itself
void loadModule(const std::string &name);
// whether path is root or below it
bool underRoot(const std::string &path, const std::string &root);

+3 −0
Changes for src/iscsi.cpp: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -236,6 +236,9 @@ std::vector<IscsiDevice> iscsiDevices(const Config &cfg) {
}

bool IscsiServer::start(std::string &err) {
    // target_core_mod (with configfs) makes /sys/kernel/config/target; the
    // iSCSI fabric and the backstores it loads itself
    if (!exists(Target) && !exists("/sys/module/target_core_mod")) loadModule("target_core_mod");
    if (!exists(Target)) {
        // the kernel makes /sys/kernel/config only when it has configfs
        if (!exists(ConfigFs)) {
+2 −0
Changes for src/nfs.cpp: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -203,6 +203,8 @@ bool NfsServer::start(std::string &err) {
    std::string threads = std::string(NfsdFs) + "/threads";
    struct stat st;
    if (stat(threads.c_str(), &st) != 0) {
        // the nfsd module makes /proc/fs/nfsd, mounting there can't load it
        if (access("/sys/module/nfsd", F_OK) != 0) loadModule("nfsd");
        mkdirs(NfsdFs, 0755);
        if (mount("nfsd", NfsdFs, "nfsd", 0, nullptr) != 0) {
            err = errno == ENODEV ? "this kernel has no knfsd (CONFIG_NFSD)"
+2 −0
Changes for src/smb.cpp: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -572,6 +572,8 @@ bool SmbServer::send(int cmd, const void *payload, size_t len, bool ack, std::st

bool SmbServer::start(std::string &err) {
    close();
    // ksmbd's generic netlink family has no module alias
    if (access("/sys/module/ksmbd", F_OK) != 0) loadModule("ksmbd");
    _fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_GENERIC);
    if (_fd < 0) {
        err = std::string("netlink socket: ") + strerror(errno);