Compare commits
4 Commits
bcd071018f
...
v1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| d58a241abb | |||
| 2a9d92a3e3 | |||
| ba4cc3faa3 | |||
| 029d5716be |
2
Makefile
2
Makefile
@@ -1,2 +1,2 @@
|
||||
all:
|
||||
g++ -lrt -std=c++17 src/main.cpp src/usermanager.cpp src/guarder.cpp -o ncsambawatcher
|
||||
g++ -lrt -std=c++17 src/main.cpp src/usermanager.cpp -o ncsambawatcher
|
||||
18
configs/smb.24.04.conf
Normal file
18
configs/smb.24.04.conf
Normal file
@@ -0,0 +1,18 @@
|
||||
[global]
|
||||
|
||||
vfs objects = full_audit
|
||||
full_audit:prefix = %u|%I|%m|%S
|
||||
full_audit:success = mkdirat unlinkat renameat write
|
||||
full_audit:failure = none
|
||||
full_audit:facility = local5
|
||||
full_audit:priority = NOTICE
|
||||
|
||||
# Put this line only for the groupfolder's share
|
||||
[Some gorupfolder share]
|
||||
|
||||
full_audit:prefix = %u|%I|%m|__groupfolders/<group-folders-id>
|
||||
|
||||
# To disable logs for a specific share
|
||||
[A share]
|
||||
|
||||
vfs objects =
|
||||
11
src/definitions.h
Normal file
11
src/definitions.h
Normal file
@@ -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
|
||||
@@ -1 +0,0 @@
|
||||
#include "guarder.h"
|
||||
@@ -1,66 +0,0 @@
|
||||
#ifndef _GUARDER_H
|
||||
#define _GUARDER_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <unistd.h>
|
||||
|
||||
class guarder{
|
||||
private:
|
||||
const int shmid;
|
||||
const int semid;
|
||||
|
||||
void semaphoreOp(int op) {
|
||||
struct sembuf sb{};
|
||||
sb.sem_num = 0;
|
||||
sb.sem_op = op;
|
||||
sb.sem_flg = 0;
|
||||
semop(semid, &sb, 1);
|
||||
}
|
||||
|
||||
void setFlag(bool value)
|
||||
{
|
||||
semaphoreOp(-1);
|
||||
bool *flag = static_cast<bool *>(shmat(shmid, nullptr, 0));
|
||||
*flag = value;
|
||||
shmdt(flag);
|
||||
semaphoreOp(1);
|
||||
}
|
||||
|
||||
public:
|
||||
guarder() : shmid(shmget(IPC_PRIVATE, sizeof(bool), 0666 | IPC_CREAT)), semid(semget(IPC_PRIVATE, 1, 0666 | IPC_CREAT))
|
||||
{
|
||||
setFlagOff();
|
||||
}
|
||||
|
||||
void setFlagOff()
|
||||
{
|
||||
setFlag(false);
|
||||
}
|
||||
|
||||
void setFlagOn()
|
||||
{
|
||||
setFlag(true);
|
||||
}
|
||||
|
||||
bool isFlagOn()
|
||||
{
|
||||
semaphoreOp(-1);
|
||||
bool *flag = static_cast<bool *>(shmat(shmid, nullptr, 0));
|
||||
bool ret = *flag;
|
||||
shmdt(flag);
|
||||
semaphoreOp(1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
~guarder()
|
||||
{
|
||||
shmctl(shmid, IPC_RMID, nullptr);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // _GUARDER_H
|
||||
@@ -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
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <cstdio>
|
||||
#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<std::string> x = splitLogFile(line, '|');
|
||||
std::vector<std::string> 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<char *>(nullptr));
|
||||
std::cerr << "Scan failed" << std::endl;
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "usermanager.h"
|
||||
|
||||
std::vector<std::string> splitLogFile(const std::string& input, char delimiter = '|')
|
||||
std::vector<std::string> splitString(const std::string& str, char delimiter = '|')
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
std::stringstream ss(input);
|
||||
std::stringstream ss(str);
|
||||
std::string token;
|
||||
|
||||
while (std::getline(ss, token, delimiter)) {
|
||||
@@ -11,4 +11,14 @@ std::vector<std::string> 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;
|
||||
}
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <mutex>
|
||||
#include "locations.h"
|
||||
#include "definitions.h"
|
||||
|
||||
std::vector<std::string> splitLogFile(const std::string& input, char delimiter);
|
||||
std::vector<std::string> 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)
|
||||
|
||||
Reference in New Issue
Block a user