Preparation of credential check mechanism.
Credential check (for privilege & remove file permission) is
essential and can be gotten from connection and we can retrieve
it in service level smoothly
Change-Id: Ib577e6e39bf52a868c2d52156a02f906b94ae46e
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
ThrowExc(EngineError, "global deinit wp engine. ret: " << ret);
}
-RawBuffer Logic::dispatch(const RawBuffer &in)
-{
- auto info = getRequestInfo(in);
-
- INFO("Request dispatch! CommandId: " << static_cast<int>(info.first));
-
- switch (info.first) {
- // Content scanning
- case CommandId::SCAN_DATA: {
- CsContextShPtr cptr;
- RawBuffer data;
- info.second.Deserialize(cptr, data);
-
- return scanData(*cptr, data);
- }
-
- case CommandId::SCAN_FILE: {
- CsContextShPtr cptr;
- std::string filepath;
- info.second.Deserialize(cptr, filepath);
- return scanFile(*cptr, filepath);
- }
-
- case CommandId::GET_SCANNABLE_FILES: {
- std::string dir;
- info.second.Deserialize(dir);
- return getScannableFiles(dir);
- }
-
- case CommandId::JUDGE_STATUS: {
- std::string filepath;
- int intAction;
- info.second.Deserialize(filepath, intAction);
- return judgeStatus(filepath, static_cast<csr_cs_action_e>(intAction));
- }
-
- case CommandId::GET_DETECTED: {
- std::string filepath;
- info.second.Deserialize(filepath);
- return getDetected(filepath);
- }
-
- case CommandId::GET_DETECTED_LIST: {
- StrSet dirSet;
- info.second.Deserialize(dirSet);
- return getDetectedList(dirSet);
- }
-
- case CommandId::GET_IGNORED: {
- std::string filepath;
- info.second.Deserialize(filepath);
- return getIgnored(filepath);
- }
-
- case CommandId::GET_IGNORED_LIST: {
- StrSet dirSet;
- info.second.Deserialize(dirSet);
- return getIgnoredList(dirSet);
- }
-
- // Web protection
- /* TODO: should we separate command->logic mapping of CS and WP ? */
- case CommandId::CHECK_URL: {
- WpContextShPtr cptr;
- std::string url;
- info.second.Deserialize(cptr, url);
- return checkUrl(*cptr, url);
- }
-
- default:
- ThrowExc(InternalError, "Command id[" << static_cast<int>(info.first) <<
- "] isn't in range.");
- }
-}
-
-std::pair<CommandId, BinaryQueue> Logic::getRequestInfo(const RawBuffer &data)
-{
- CommandId id;
-
- BinaryQueue q;
- q.push(data);
- q.Deserialize(id);
-
- return std::make_pair(id, std::move(q));
-}
-
RawBuffer Logic::scanData(const CsContext &context, const RawBuffer &data)
{
CsEngineContext engineContext(m_cs);
return BinaryQueue::Serialize(ret, d).pop();
}
-RawBuffer Logic::scanFileHelper(const CsContext &context,
- const std::string &filepath)
+RawBuffer Logic::scanFileHelper(const CsContext &context, const std::string &filepath)
{
CsEngineContext engineContext(m_cs);
auto &c = engineContext.get();
RawBuffer Logic::getScannableFiles(const std::string &dir)
{
auto lastScanTime = m_db->getLastScanTime(dir, m_csDataVersion);
- auto visitor = (lastScanTime == -1) ?
- FsVisitor::create(dir) : FsVisitor::create(dir, lastScanTime);
+ auto visitor = FsVisitor::create(dir, lastScanTime);
StrSet fileset;
while (auto file = visitor->next()) {
return BinaryQueue::Serialize(CSR_ERROR_NONE, fileset).pop();
}
-RawBuffer Logic::judgeStatus(const std::string &filepath,
- csr_cs_action_e action)
+RawBuffer Logic::judgeStatus(const std::string &filepath, csr_cs_action_e action)
{
auto history = m_db->getDetectedMalware(filepath);
return BinaryQueue::Serialize(ret, wr).pop();
}
-csr_cs_user_response_e Logic::getUserResponse(const CsContext &c,
- const CsDetected &d)
+csr_cs_user_response_e Logic::getUserResponse(const CsContext &c, const CsDetected &d)
{
if (c.askUser == CSR_CS_NOT_ASK_USER)
return CSR_CS_NO_ASK_USER;
return askUser.cs(cid, c.popupMessage, d);
}
-csr_wp_user_response_e Logic::getUserResponse(const WpContext &c,
- const std::string &url, const WpResult &wr)
+csr_wp_user_response_e Logic::getUserResponse(const WpContext &c, const std::string &url,
+ const WpResult &wr)
{
if (c.askUser == CSR_WP_NOT_ASK_USER)
return CSR_WP_NO_ASK_USER;
#include "common/wp-context.h"
#include "common/cs-detected.h"
#include "common/wp-result.h"
-#include "common/command-id.h"
-#include "common/binary-queue.h"
#include "db/manager.h"
#include "service/cs-loader.h"
#include "service/wp-loader.h"
Logic();
virtual ~Logic();
- RawBuffer dispatch(const RawBuffer &);
-
-private:
- std::pair<CommandId, BinaryQueue> getRequestInfo(const RawBuffer &);
-
RawBuffer scanData(const CsContext &context, const RawBuffer &data);
RawBuffer scanFile(const CsContext &context, const std::string &filepath);
- RawBuffer scanFileHelper(const CsContext &context, const std::string &filepath);
RawBuffer getScannableFiles(const std::string &dir);
RawBuffer judgeStatus(const std::string &filepath, csr_cs_action_e action);
RawBuffer getDetected(const std::string &filepath);
RawBuffer checkUrl(const WpContext &context, const std::string &url);
+private:
+ RawBuffer scanFileHelper(const CsContext &context, const std::string &filepath);
CsDetected convert(csre_cs_detected_h &);
WpResult convert(csre_wp_check_result_h &);
*/
#include "service/server-service.h"
+#include <string>
+#include <vector>
+
+#include "common/command-id.h"
#include "common/audit/logger.h"
+#include "common/exception.h"
+#include "common/cs-context.h"
+#include "common/wp-context.h"
+
+#include "csr/content-screening-types.h"
namespace Csr {
{
}
+RawBuffer ServerService::process(const ConnShPtr &, RawBuffer &data)
+{
+ CommandId id;
+
+ BinaryQueue q;
+ q.push(data);
+ q.Deserialize(id);
+
+ switch (id) {
+ case CommandId::SCAN_DATA: {
+ CsContextShPtr cptr;
+ RawBuffer data;
+ q.Deserialize(cptr, data);
+
+ return m_logic.scanData(*cptr, data);
+ }
+
+ case CommandId::SCAN_FILE: {
+ CsContextShPtr cptr;
+ std::string filepath;
+ q.Deserialize(cptr, filepath);
+
+ return m_logic.scanFile(*cptr, filepath);
+ }
+
+ case CommandId::GET_SCANNABLE_FILES: {
+ std::string dir;
+ q.Deserialize(dir);
+
+ return m_logic.getScannableFiles(dir);
+ }
+
+ case CommandId::JUDGE_STATUS: {
+ std::string filepath;
+ int intAction;
+ q.Deserialize(filepath, intAction);
+
+ return m_logic.judgeStatus(filepath, static_cast<csr_cs_action_e>(intAction));
+ }
+
+ case CommandId::GET_DETECTED: {
+ std::string filepath;
+ q.Deserialize(filepath);
+
+ return m_logic.getDetected(filepath);
+ }
+
+ case CommandId::GET_DETECTED_LIST: {
+ StrSet dirSet;
+ q.Deserialize(dirSet);
+
+ return m_logic.getDetectedList(dirSet);
+ }
+
+ case CommandId::GET_IGNORED: {
+ std::string filepath;
+ q.Deserialize(filepath);
+
+ return m_logic.getIgnored(filepath);
+ }
+
+ case CommandId::GET_IGNORED_LIST: {
+ StrSet dirSet;
+ q.Deserialize(dirSet);
+
+ return m_logic.getIgnoredList(dirSet);
+ }
+
+ // Web protection
+ /* TODO: should we separate command->logic mapping of CS and WP ? */
+ case CommandId::CHECK_URL: {
+ WpContextShPtr cptr;
+ std::string url;
+ q.Deserialize(cptr, url);
+
+ return m_logic.checkUrl(*cptr, url);
+ }
+
+ default:
+ ThrowExc(InternalError, "Command isn't in range: " << static_cast<int>(id));
+ }
+}
+
void ServerService::onMessageProcess(const ConnShPtr &connection)
{
DEBUG("let's dispatch it to worker threads.");
auto process = [&](RawBuffer & buffer) {
- connection->send(m_logic.dispatch(buffer));
+ connection->send(this->process(connection, buffer));
};
m_workqueue.submit(std::bind(process, connection->receive()));
#pragma once
#include "common/service.h"
+#include "common/types.h"
#include "service/logic.h"
#include "service/thread-pool.h"
private:
virtual void onMessageProcess(const ConnShPtr &) override;
+ RawBuffer process(const ConnShPtr &, RawBuffer &);
+
Logic m_logic;
ThreadPool m_workqueue;
};
#include "common/audit/logger.h"
#include "common/exception.h"
#include "ui/common.h"
+#include "popup.h"
#include "csr/content-screening-types.h"
#include "csr/web-protection-types.h"
g_callbackRegistry[*rp] = std::move(func);
}
-bool isCsCommand(const CommandId &cid)
-{
- switch (cid) {
- case CommandId::CS_PROMPT_DATA:
- case CommandId::CS_PROMPT_APP:
- case CommandId::CS_PROMPT_FILE:
- case CommandId::CS_NOTIFY_DATA:
- case CommandId::CS_NOTIFY_APP:
- case CommandId::CS_NOTIFY_FILE:
- return true;
-
- case CommandId::WP_PROMPT:
- case CommandId::WP_NOTIFY:
- return false;
-
- default:
- ThrowExc(InternalError, "Protocol error. unknown popup-service command id.");
- }
-}
-
void addButton(int *rp, const std::string &buttonPart,
const std::string &buttonText,
Popup &popup, RawBuffer &result)
{
}
-RawBuffer Logic::dispatch(const RawBuffer &in)
-{
- auto info = getRequestInfo(in);
- INFO("Request dispatch on popup-service. CommandId: " << static_cast<int>
- (info.first));
-
- if (isCsCommand(info.first)) {
- std::string message;
- CsDetected d;
- info.second.Deserialize(message, d);
-
- switch (info.first) {
- case CommandId::CS_PROMPT_DATA:
- return csPromptData(message, d);
-
- case CommandId::CS_PROMPT_APP:
- return csPromptApp(message, d);
-
- case CommandId::CS_PROMPT_FILE:
- return csPromptFile(message, d);
-
- case CommandId::CS_NOTIFY_DATA:
- return csNotifyData(message, d);
-
- case CommandId::CS_NOTIFY_APP:
- return csNotifyApp(message, d);
-
- case CommandId::CS_NOTIFY_FILE:
- return csNotifyFile(message, d);
-
- default:
- ThrowExc(InternalError, "protocol error. invalid ui command id.");
- }
- } else {
- std::string message;
- UrlItem item;
- info.second.Deserialize(message, item);
-
- switch (info.first) {
- case CommandId::WP_PROMPT:
- return wpPrompt(message, item);
-
- case CommandId::WP_NOTIFY:
- return wpNotify(message, item);
-
- default:
- ThrowExc(InternalError, "protocol error. invalid ui command id.");
- }
- }
-}
-
-std::pair<CommandId, BinaryQueue> Logic::getRequestInfo(const RawBuffer &data)
-{
- BinaryQueue q;
- q.push(data);
-
- int int_id;
- q.Deserialize(int_id);
-
- return std::make_pair(static_cast<CommandId>(int_id), std::move(q));
-}
-
RawBuffer Logic::csPromptData(const std::string &message,
const CsDetected &d) const
{
#pragma once
#include <string>
-#include <functional>
-#include <utility>
#include "common/types.h"
#include "common/cs-detected.h"
-#include "common/binary-queue.h"
#include "ui/common.h"
-#include "popup.h"
namespace Csr {
namespace Ui {
Logic();
virtual ~Logic();
- RawBuffer dispatch(const RawBuffer &);
-
-private:
- std::pair<CommandId, BinaryQueue> getRequestInfo(const RawBuffer &);
-
RawBuffer csPromptData(const std::string &, const CsDetected &) const;
RawBuffer csPromptApp(const std::string &, const CsDetected &) const;
RawBuffer csPromptFile(const std::string &, const CsDetected &) const;
*/
#include "popup-service.h"
+#include "common/binary-queue.h"
#include "common/audit/logger.h"
+#include "common/exception.h"
+#include "common/cs-detected.h"
namespace Csr {
namespace Ui {
+namespace {
+
+bool isCsCommand(const CommandId &cid)
+{
+ switch (cid) {
+ case CommandId::CS_PROMPT_DATA:
+ case CommandId::CS_PROMPT_APP:
+ case CommandId::CS_PROMPT_FILE:
+ case CommandId::CS_NOTIFY_DATA:
+ case CommandId::CS_NOTIFY_APP:
+ case CommandId::CS_NOTIFY_FILE:
+ return true;
+
+ case CommandId::WP_PROMPT:
+ case CommandId::WP_NOTIFY:
+ return false;
+
+ default:
+ ThrowExc(InternalError, "Protocol error. unknown popup-service command id.");
+ }
+}
+
+} // namespace nonymous
+
PopupService::PopupService(const std::string &address) : Service(address)
{
}
{
}
+RawBuffer PopupService::process(const ConnShPtr &, RawBuffer &data)
+{
+ BinaryQueue q;
+ q.push(data);
+
+ int intCid;
+ q.Deserialize(intCid);
+
+ INFO("Request dispatch on popup-service. CommandId: " << static_cast<int>(intCid));
+
+ if (isCsCommand(static_cast<Ui::CommandId>(intCid))) {
+ std::string message;
+ CsDetected d;
+ q.Deserialize(message, d);
+
+ switch (static_cast<Ui::CommandId>(intCid)) {
+ case CommandId::CS_PROMPT_DATA:
+ return m_logic.csPromptData(message, d);
+
+ case CommandId::CS_PROMPT_APP:
+ return m_logic.csPromptApp(message, d);
+
+ case CommandId::CS_PROMPT_FILE:
+ return m_logic.csPromptFile(message, d);
+
+ case CommandId::CS_NOTIFY_DATA:
+ return m_logic.csNotifyData(message, d);
+
+ case CommandId::CS_NOTIFY_APP:
+ return m_logic.csNotifyApp(message, d);
+
+ case CommandId::CS_NOTIFY_FILE:
+ return m_logic.csNotifyFile(message, d);
+
+ default:
+ ThrowExc(InternalError, "protocol error. invalid ui command id.");
+ }
+ } else {
+ std::string message;
+ UrlItem item;
+ q.Deserialize(message, item);
+
+ switch (static_cast<Ui::CommandId>(intCid)) {
+ case CommandId::WP_PROMPT:
+ return m_logic.wpPrompt(message, item);
+
+ case CommandId::WP_NOTIFY:
+ return m_logic.wpNotify(message, item);
+
+ default:
+ ThrowExc(InternalError, "protocol error. invalid ui command id.");
+ }
+ }
+}
+
void PopupService::onMessageProcess(const ConnShPtr &connection)
{
DEBUG("process message on popup service");
- connection->send(m_logic.dispatch(connection->receive()));
+ auto in = connection->receive();
+ connection->send(this->process(connection, in));
DEBUG("process done on popup service");
}
#include <string>
#include "common/service.h"
+#include "common/types.h"
#include "logic.h"
namespace Csr {
private:
virtual void onMessageProcess(const ConnShPtr &) override;
+
+ RawBuffer process(const ConnShPtr &, RawBuffer &);
+
Logic m_logic;
};