WIP/sandboxing #29
@ -24,7 +24,7 @@ int CommandList::handle(QStringList arguments)
|
|||||||
|
|
||||||
QStringList files = parser.positionalArguments();
|
QStringList files = parser.positionalArguments();
|
||||||
QString queryStrings = files.join(' ');
|
QString queryStrings = files.join(' ');
|
||||||
auto results = dbService->search(LooqsQuery::build(queryStrings));
|
auto results = dbService->search(LooqsQuery::build(queryStrings, TokenType::FILTER_PATH_CONTAINS, false));
|
||||||
|
|
||||||
for(SearchResult &result : results)
|
for(SearchResult &result : results)
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@ int CommandSearch::handle(QStringList arguments)
|
|||||||
|
|
||||||
QStringList files = parser.positionalArguments();
|
QStringList files = parser.positionalArguments();
|
||||||
QString queryStrings = files.join(' ');
|
QString queryStrings = files.join(' ');
|
||||||
LooqsQuery query = LooqsQuery::build(queryStrings);
|
LooqsQuery query = LooqsQuery::build(queryStrings, TokenType::FILTER_PATH_CONTAINS, false);
|
||||||
bool reverse = parser.isSet("reverse");
|
bool reverse = parser.isSet("reverse");
|
||||||
if(reverse)
|
if(reverse)
|
||||||
{
|
{
|
||||||
|
32
gui/main.cpp
32
gui/main.cpp
@ -16,6 +16,7 @@ int main(int argc, char *argv[])
|
|||||||
QString socketPath = "/tmp/looqs-spawner";
|
QString socketPath = "/tmp/looqs-spawner";
|
||||||
if(argc > 1)
|
if(argc > 1)
|
||||||
{
|
{
|
||||||
|
Common::setupAppInfo();
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
QString arg = argv[1];
|
QString arg = argv[1];
|
||||||
if(arg == "ipc")
|
if(arg == "ipc")
|
||||||
@ -24,7 +25,7 @@ int main(int argc, char *argv[])
|
|||||||
qDebug() << "Launching ipc";
|
qDebug() << "Launching ipc";
|
||||||
if(!ipcserver->startSpawner(socketPath))
|
if(!ipcserver->startSpawner(socketPath))
|
||||||
{
|
{
|
||||||
qDebug() << "Error failed to spawn";
|
qCritical() << "Error failed to spawn";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
qDebug() << "Launched";
|
qDebug() << "Launched";
|
||||||
@ -42,15 +43,38 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct exile_policy *policy = exile_init_policy();
|
struct exile_policy *policy = exile_init_policy();
|
||||||
|
if(policy == NULL)
|
||||||
|
{
|
||||||
|
qCritical() << "Failed to init policy for sandbox";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
std::string appDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation).toStdString();
|
std::string appDataLocation = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation).toStdString();
|
||||||
std::string cacheDataLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toStdString();
|
std::string cacheDataLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toStdString();
|
||||||
std::string sockPath = socketPath.toStdString();
|
std::string sockPath = socketPath.toStdString();
|
||||||
policy->namespace_options = EXILE_UNSHARE_NETWORK | EXILE_UNSHARE_USER;
|
policy->namespace_options = EXILE_UNSHARE_NETWORK | EXILE_UNSHARE_USER;
|
||||||
|
policy->vow_promises = EXILE_SYSCALL_VOW_THREAD | EXILE_SYSCALL_VOW_CPATH | EXILE_SYSCALL_VOW_WPATH |
|
||||||
|
EXILE_SYSCALL_VOW_RPATH | EXILE_SYSCALL_VOW_UNIX | EXILE_SYSCALL_VOW_STDIO |
|
||||||
|
EXILE_SYSCALL_VOW_PROT_EXEC | EXILE_SYSCALL_VOW_PROC | EXILE_SYSCALL_VOW_SHM |
|
||||||
|
EXILE_SYSCALL_VOW_FSNOTIFY | EXILE_SYSCALL_VOW_IOCTL;
|
||||||
|
|
||||||
exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_REMOVE_FILE, "/");
|
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_REMOVE_FILE, "/") != 0)
|
||||||
exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, appDataLocation.c_str());
|
{
|
||||||
exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, cacheDataLocation.c_str());
|
qCritical() << "Failed to append a path to the path policy";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, appDataLocation.c_str()) !=
|
||||||
|
0)
|
||||||
|
{
|
||||||
|
qCritical() << "Failed to append a path to the path policy";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
|
||||||
|
cacheDataLocation.c_str()) != 0)
|
||||||
|
{
|
||||||
|
qCritical() << "Failed to append a path to the path policy";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
int ret = exile_enable_policy(policy);
|
int ret = exile_enable_policy(policy);
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
{
|
{
|
||||||
|
@ -166,8 +166,13 @@ void MainWindow::lineEditReturnPressed()
|
|||||||
[&, q]()
|
[&, q]()
|
||||||
{
|
{
|
||||||
SqliteSearch searcher(db);
|
SqliteSearch searcher(db);
|
||||||
this->currentQuery = LooqsQuery::build(q);
|
this->contentSearchQuery = LooqsQuery::build(q, TokenType::FILTER_CONTENT_CONTAINS, true);
|
||||||
return searcher.search(this->currentQuery);
|
|
||||||
|
LooqsQuery filesQuery = LooqsQuery::build(q, TokenType::FILTER_PATH_CONTAINS, false);
|
||||||
|
QVector<SearchResult> results;
|
||||||
|
results.append(searcher.search(filesQuery));
|
||||||
|
results.append(searcher.search(this->contentSearchQuery));
|
||||||
|
return results;
|
||||||
});
|
});
|
||||||
searchWatcher.setFuture(searchFuture);
|
searchWatcher.setFuture(searchFuture);
|
||||||
}
|
}
|
||||||
@ -243,7 +248,7 @@ void MainWindow::makePdfPreview(int page)
|
|||||||
|
|
||||||
QVector<QString> wordsToHighlight;
|
QVector<QString> wordsToHighlight;
|
||||||
QRegularExpression extractor(R"#("([^"]*)"|(\w+))#");
|
QRegularExpression extractor(R"#("([^"]*)"|(\w+))#");
|
||||||
for(const Token &token : this->currentQuery.getTokens())
|
for(const Token &token : this->contentSearchQuery.getTokens())
|
||||||
{
|
{
|
||||||
if(token.type == FILTER_CONTENT_CONTAINS)
|
if(token.type == FILTER_CONTENT_CONTAINS)
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ class MainWindow : public QMainWindow
|
|||||||
unsigned int processedPdfPreviews;
|
unsigned int processedPdfPreviews;
|
||||||
void handleSearchResults(const QVector<SearchResult> &results);
|
void handleSearchResults(const QVector<SearchResult> &results);
|
||||||
void handleSearchError(QString error);
|
void handleSearchError(QString error);
|
||||||
LooqsQuery currentQuery;
|
LooqsQuery contentSearchQuery;
|
||||||
int pdfPreviewsPerPage;
|
int pdfPreviewsPerPage;
|
||||||
void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo);
|
void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo);
|
||||||
void ipcDocOpen(QString path, int num);
|
void ipcDocOpen(QString path, int num);
|
||||||
|
@ -157,15 +157,15 @@ void LooqsQuery::addToken(Token t)
|
|||||||
* thus, "Downloads zip" becomes essentailly "path.contains:(Downloads) AND path.contains:(zip)"
|
* thus, "Downloads zip" becomes essentailly "path.contains:(Downloads) AND path.contains:(zip)"
|
||||||
*
|
*
|
||||||
* TODO: It's a bit ugly still*/
|
* TODO: It's a bit ugly still*/
|
||||||
LooqsQuery LooqsQuery::build(QString expression)
|
LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, bool mergeLoneWords)
|
||||||
{
|
{
|
||||||
if(!checkParanthesis(expression))
|
if(!checkParanthesis(expression))
|
||||||
{
|
{
|
||||||
throw LooqsGeneralException("Invalid paranthesis");
|
throw LooqsGeneralException("Invalid paranthesis");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList loneWords;
|
||||||
LooqsQuery result;
|
LooqsQuery result;
|
||||||
// TODO: merge lonewords
|
|
||||||
QRegularExpression rx("((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([\\w,])+)|(?<boolean>AND|OR)"
|
QRegularExpression rx("((?<filtername>(\\.|\\w)+):(?<args>\\((?<innerargs>[^\\)]+)\\)|([\\w,])+)|(?<boolean>AND|OR)"
|
||||||
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>\\w+))");
|
"|(?<negation>!)|(?<bracket>\\(|\\))|(?<loneword>\\w+))");
|
||||||
QRegularExpressionMatchIterator i = rx.globalMatch(expression);
|
QRegularExpressionMatchIterator i = rx.globalMatch(expression);
|
||||||
@ -233,7 +233,14 @@ LooqsQuery LooqsQuery::build(QString expression)
|
|||||||
|
|
||||||
if(loneword != "")
|
if(loneword != "")
|
||||||
{
|
{
|
||||||
result.addToken(Token(FILTER_PATH_CONTAINS, loneword));
|
if(mergeLoneWords)
|
||||||
|
{
|
||||||
|
loneWords.append(loneword);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.addToken(Token(loneWordsTokenType, loneword));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(filtername != "")
|
if(filtername != "")
|
||||||
@ -292,6 +299,11 @@ LooqsQuery LooqsQuery::build(QString expression)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mergeLoneWords)
|
||||||
|
{
|
||||||
|
result.addToken(Token(loneWordsTokenType, loneWords.join(' ')));
|
||||||
|
}
|
||||||
|
|
||||||
bool contentsearch = (result.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT;
|
bool contentsearch = (result.getTokensMask() & FILTER_CONTENT) == FILTER_CONTENT;
|
||||||
bool sortsForContent = std::any_of(result.sortConditions.begin(), result.sortConditions.end(),
|
bool sortsForContent = std::any_of(result.sortConditions.begin(), result.sortConditions.end(),
|
||||||
[](SortCondition c) { return c.field == CONTENT_TEXT; });
|
[](SortCondition c) { return c.field == CONTENT_TEXT; });
|
||||||
|
@ -54,7 +54,7 @@ class LooqsQuery
|
|||||||
}
|
}
|
||||||
void addSortCondition(SortCondition sc);
|
void addSortCondition(SortCondition sc);
|
||||||
static bool checkParanthesis(QString query);
|
static bool checkParanthesis(QString query);
|
||||||
static LooqsQuery build(QString query);
|
static LooqsQuery build(QString query, TokenType loneWordsTokenType, bool mergeLoneWords);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOOQSQUERY_H
|
#endif // LOOQSQUERY_H
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit d742397b522eb91513bab54a3aa992dfb7121462
|
Subproject commit 4824c6eaa9043878daaba7b3778338f5bf913f06
|
Loading…
Reference in New Issue
Block a user