From ba4cc3faa3da1c799f5076835d59d81a08344b23 Mon Sep 17 00:00:00 2001 From: bartfaik04 Date: Sun, 1 Jun 2025 13:03:12 +0200 Subject: [PATCH] Support groupfolder scan --- src/definitions.h | 11 +++++++++++ src/locations.h | 8 -------- src/main.cpp | 6 ++---- src/usermanager.cpp | 14 ++++++++++++-- src/usermanager.h | 8 +++++--- 5 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 src/definitions.h delete mode 100644 src/locations.h diff --git a/src/definitions.h b/src/definitions.h new file mode 100644 index 0000000..4e755b9 --- /dev/null +++ b/src/definitions.h @@ -0,0 +1,11 @@ +#ifndef _LOCATIONS_H +#define _LOCATIONS_H + +#define LOGFILE "journalctl -u smbd --since now -f" + +#define USER_LOG_LOCATION 3 + +#define SCAN_CMD_USR "docker exec --user www-data nextcloud /var/www/html/occ files:scan --path=" +#define SCAN_CMD_GRP "docker exec --user www-data nextcloud /var/www/html/occ groupfolder:scan " + +#endif // _LOCATIONS_H \ No newline at end of file diff --git a/src/locations.h b/src/locations.h deleted file mode 100644 index 4b3bab0..0000000 --- a/src/locations.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _LOCATIONS_H -#define _LOCATIONS_H - -#define LOGFILE "journalctl -u smbd --since now -f" - -#define USER_LOG_LOCATION 3 - -#endif // _LOCATIONS_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0a16c9a..8974326 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,8 +12,6 @@ #include #include "usermanager.h" -#define SCAN_CMD_USR "docker exec --user www-data nextcloud /var/www/html/occ files:scan --path=" - userManager manager; std::condition_variable cv; std::mutex mtx; @@ -30,7 +28,7 @@ void readingThreadFunc() if (line.find('|') == std::string::npos) continue; - std::vector x = splitLogFile(line, '|'); + std::vector x = splitString(line, '|'); std::string user(x.at(USER_LOG_LOCATION)); { @@ -70,7 +68,7 @@ void scannerThreadFunc() } else if (child == 0) // child { - std::string cmd = (std::string(SCAN_CMD_USR) + user); + std::string cmd = userManager::getScanCommandFromUser(user); execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast(nullptr)); std::cerr << "Scan failed" << std::endl; _exit(EXIT_FAILURE); diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 8fcaaf4..8d1bf13 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -1,9 +1,9 @@ #include "usermanager.h" -std::vector splitLogFile(const std::string& input, char delimiter = '|') +std::vector splitString(const std::string& str, char delimiter = '|') { std::vector ret; - std::stringstream ss(input); + std::stringstream ss(str); std::string token; while (std::getline(ss, token, delimiter)) { @@ -11,4 +11,14 @@ std::vector splitLogFile(const std::string& input, char delimiter = } return ret; +} + +std::string userManager::getScanCommandFromUser(const std::string &user) +{ + if (user.find("__groupfolder") != std::string::npos) + { + return std::string(SCAN_CMD_GRP) + splitString(user, '/').back(); + } + + return std::string(SCAN_CMD_USR) + user; } \ No newline at end of file diff --git a/src/usermanager.h b/src/usermanager.h index 5a7ea14..ff4c4b4 100644 --- a/src/usermanager.h +++ b/src/usermanager.h @@ -7,9 +7,9 @@ #include #include #include -#include "locations.h" +#include "definitions.h" -std::vector splitLogFile(const std::string& input, char delimiter); +std::vector splitString(const std::string& input, char delimiter); class userManager { @@ -19,9 +19,11 @@ private: public: + static std::string getScanCommandFromUser(const std::string&); + void addUserFromLogLine(std::string &line) { - addUser(splitLogFile(line, '|').at(USER_LOG_LOCATION)); + addUser(splitString(line, '|').at(USER_LOG_LOCATION)); } void addUser(std::string &user)