# Others
security-containers.pc
-doc/*/
+doc/html
CMAKE_MINIMUM_REQUIRED (VERSION 2.6.2)
PROJECT(security-containers)
+
## pkgconfig ###################################################################
INCLUDE(FindPkgConfig)
+
## default CMAKE_INSTALL_* variables ###########################################
INCLUDE(GNUInstallDirs)
-## File names ##################################################################
-SET(SERVER_CODENAME "${PROJECT_NAME}-server")
-SET(CLIENT_CODENAME "${PROJECT_NAME}-client")
-
-
-## Generate the pc file ########################################################
-CONFIGURE_FILE(security-containers.pc.in security-containers.pc @ONLY)
-
## Compiler flags, depending on the build type #################################
IF(NOT CMAKE_BUILD_TYPE)
## Subdirectories ##############################################################
-SET(CLIENT_FOLDER ${PROJECT_SOURCE_DIR}/src/client)
-SET(SERVER_FOLDER ${PROJECT_SOURCE_DIR}/src/server)
+SET(COMMON_FOLDER ${PROJECT_SOURCE_DIR}/common)
+SET(CLIENT_FOLDER ${PROJECT_SOURCE_DIR}/client)
+SET(SERVER_FOLDER ${PROJECT_SOURCE_DIR}/server)
+SET(UNIT_TESTS_FOLDER ${PROJECT_SOURCE_DIR}/unit_tests)
IF(NOT DEFINED SYSCONF_INSTALL_DIR)
SET(SYSCONF_INSTALL_DIR "/etc")
SET(SC_CONFIG_INSTALL_DIR ${SYSCONF_INSTALL_DIR}/security-containers)
-ADD_SUBDIRECTORY(src)
-
-
-## Installations ###############################################################
-INSTALL(FILES ${CLIENT_FOLDER}/include/security-containers-client.h
- DESTINATION ${INCLUDE_INSTALL_DIR}/security-containers)
-
-INSTALL(FILES ${CMAKE_BINARY_DIR}/security-containers.pc
- DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-INSTALL(FILES ${SERVER_FOLDER}/config/daemon.conf
- DESTINATION ${SC_CONFIG_INSTALL_DIR})
-
-INSTALL(FILES ${SERVER_FOLDER}/config/containers/xminimal.conf
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/containers)
+ADD_SUBDIRECTORY(${CLIENT_FOLDER})
+ADD_SUBDIRECTORY(${SERVER_FOLDER})
+ADD_SUBDIRECTORY(${UNIT_TESTS_FOLDER})
-INSTALL(FILES ${SERVER_FOLDER}/config/libvirt-config/xminimal.xml
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/libvirt-config)
--- /dev/null
+# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# @file CMakeLists.txt
+# @author Jan Olszak (j.olszak@samsung.com)
+#
+
+MESSAGE(STATUS "Generating makefile for the Client...")
+FILE(GLOB project_SRCS *.cpp *.hpp)
+FILE(GLOB_RECURSE common_SRCS ${COMMON_FOLDER}/*.cpp ${COMMON_FOLDER}/*.hpp)
+
+
+## Setup target ################################################################
+SET(CLIENT_CODENAME "${PROJECT_NAME}-client")
+ADD_LIBRARY(${CLIENT_CODENAME} SHARED ${project_SRCS})
+
+
+## Link libraries ##############################################################
+INCLUDE_DIRECTORIES(${COMMON_FOLDER})
+
+
+## Generate the pc file ########################################################
+CONFIGURE_FILE(security-containers.pc.in
+ ${CMAKE_BINARY_DIR}/security-containers.pc @ONLY)
+
+
+## Install #####################################################################
+INSTALL(FILES ${CMAKE_BINARY_DIR}/security-containers.pc
+ DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+INSTALL(TARGETS ${CLIENT_CODENAME}
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ COMPONENT RuntimeLibraries)
+
+INSTALL(FILES security-containers-client.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/security-containers)
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Bumjin Im <bj.im@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+/**
+ * @file
+ * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
+ * @brief Exceptions for the client
+ */
+
+
+#ifndef CLIENT_EXCEPTION_HPP
+#define CLIENT_EXCEPTION_HPP
+
+#include "base-exception.hpp"
+
+
+namespace security_containers {
+
+
+/**
+ * @brief Base class for exceptions in Security Containers Client
+ */
+struct ClientException: public SecurityContainersException {
+ using SecurityContainersException::SecurityContainersException;
+};
+
+
+}
+
+
+#endif // CLIENT_EXCEPTION_HPP
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Bumjin Im <bj.im@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+
+/**
+ * @file
+ * @author Jan Olszak (j.olszak@samsung.com)
+ * @brief Main file for the Security Containers Client
+ */
+
+#include "exception.hpp"
/**
* @file security-containers-client.h
* @author Jan Olszak (j.olszak@samsung.com)
- * @brief This file contains the API for Security Containers Client
+ * @brief This file contains the public API for Security Containers Client
*/
#ifndef SECURITY_CONTAINERS_CLIENT_H
*/
/**
- * @file base-exception.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Security containers base exception
*/
-#ifndef BASE_EXCEPTION_HPP
-#define BASE_EXCEPTION_HPP
+#ifndef COMMON_BASE_EXCEPTION_HPP
+#define COMMON_BASE_EXCEPTION_HPP
#include <stdexcept>
+
namespace security_containers {
+
/**
* Base class security containers exceptions
*/
SecurityContainersException() : std::runtime_error(std::string()) {}
};
+
} // namespace security_containers
-#endif // BASE_EXCEPTION_HPP
+
+#endif // COMMON_BASE_EXCEPTION_HPP
*/
/**
- * @file scs-configuration.cpp
+ * @file
* @author Michal Witanowski (m.witanowski@samsung.com)
* @brief Helper class for parsing and storing configurations in JSON format.
*/
-#include "scs-exception.hpp"
-#include "log.hpp"
-#include "scs-configuration.hpp"
+#include "log/logger.hpp"
+#include "config/configuration.hpp"
+#include "config/exception.hpp"
+
#include <string.h>
#include <fstream>
+
namespace security_containers {
+namespace config {
void ConfigurationBase::parseStr(const std::string& str)
return std::string(json_object_get_string(obj));
}
+} // namespace config
} // namespace security_containers
/**
- * @file scs-configuration.hpp
+ * @file
* @author Michal Witanowski (m.witanowski@samsung.com)
* @brief Helper class for parsing and storing configurations in JSON format.
*/
-#ifndef SECURITY_CONTAINERS_SERVER_CONFIG_HPP
-#define SECURITY_CONTAINERS_SERVER_CONFIG_HPP
+#ifndef COMMON_CONFIG_CONFIGURATION_HPP
+#define COMMON_CONFIG_CONFIGURATION_HPP
+
+#include "log/logger.hpp"
+#include "config/exception.hpp"
-#include "log.hpp"
-#include "scs-exception.hpp"
#include <json/json.h>
#include <string>
#include <vector>
+
namespace security_containers {
+namespace config {
+
enum class ConfigProcessMode : int {
Read,
Write
};
-#define CONFIG_REGISTER void process(json_object* obj, ConfigProcessMode mode)
+#define CONFIG_REGISTER \
+ void process(json_object* obj, security_containers::config::ConfigProcessMode mode)
/**
* Use this macro to declare config value (class attribute). Declare means that it will be
* Currently supported types are:
* int, bool, double, std::string and std::vector of all the mentioned.
*/
-#define CONFIG_VALUE(name) if (mode == ConfigProcessMode::Read) \
- readValue(obj, name, #name); \
- else \
- writeValue(obj, name, #name);
+#define CONFIG_VALUE(name) \
+ if (mode == security_containers::config::ConfigProcessMode::Read) \
+ readValue(obj, name, #name); \
+ else \
+ writeValue(obj, name, #name);
/**
* Use this macro to declare configuration sub object (nested config tree).
* The type of passed argument must inherit from ConfigurationBase or be std::vector of such type.
*/
-#define CONFIG_SUB_OBJECT(name) if (mode == ConfigProcessMode::Read) \
- readSubObj(obj, name, #name); \
- else \
- writeSubObj(obj, name, #name);
+#define CONFIG_SUB_OBJECT(name) \
+ if (mode == security_containers::config::ConfigProcessMode::Read) \
+ readSubObj(obj, name, #name); \
+ else \
+ writeSubObj(obj, name, #name);
/**
@brief Override this abstract class to enable reading/writing a class members from/to JSON
static json_object* getJsonObjFromValue(const T& val);
};
+
+} // namespace config
} // namespace security_containers
-#endif // SECURITY_CONTAINERS_SERVER_CONFIG_HPP
+
+#endif // COMMON_CONFIG_CONFIGURATION_HPP
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Bumjin Im <bj.im@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+/**
+ * @file
+ * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
+ * @brief Exceptions for the configuration
+ */
+
+
+#ifndef COMMON_CONFIG_EXCEPTION_HPP
+#define COMMON_CONFIG_EXCEPTION_HPP
+
+#include "base-exception.hpp"
+
+
+namespace security_containers {
+namespace config {
+
+
+/**
+ * Base class for exceptions in configuration.
+ * Error occured during a config file parsing,
+ * e.g. syntax error
+ */
+struct ConfigException: public SecurityContainersException {
+ using SecurityContainersException::SecurityContainersException;
+};
+
+
+} // namespace config
+} // namespace security_containers
+
+
+#endif // COMMON_CONFIG_EXCEPTION_HPP
*/
/**
- * @file dbus-connection.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Dbus connection class
*/
-#include "dbus-connection.hpp"
-#include "dbus-exception.hpp"
-#include "log.hpp"
+#include "dbus/connection.hpp"
+#include "dbus/exception.hpp"
+#include "log/logger.hpp"
+
namespace security_containers {
namespace dbus {
+
namespace {
const std::string SYSTEM_BUS_ADDRESS = "unix:path=/var/run/dbus/system_bus_socket";
return GVariantPtr(result, g_variant_unref);
}
+
} // namespace dbus
} // namespace security_containers
*/
/**
- * @file dbus-connection.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Dbus connection class
*/
-#ifndef DBUS_CONNECTION_HPP
-#define DBUS_CONNECTION_HPP
+#ifndef COMMON_DBUS_CONNECTION_HPP
+#define COMMON_DBUS_CONNECTION_HPP
#include <memory>
#include <string>
#include <functional>
#include <gio/gio.h>
+
namespace security_containers {
namespace dbus {
+
typedef std::unique_ptr<GVariant, void(*)(GVariant*)> GVariantPtr;
/**
gpointer userData);
};
+
} // namespace dbus
} // namespace security_containers
-#endif //DBUS_CONNECTION_HPP
+
+#endif // COMMON_DBUS_CONNECTION_HPP
*/
/**
- * @file dbus-exception.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Dbus exceptions
*/
-#ifndef DBUS_EXCEPTION_HPP
-#define DBUS_EXCEPTION_HPP
+#ifndef COMMON_DBUS_EXCEPTION_HPP
+#define COMMON_DBUS_EXCEPTION_HPP
#include "base-exception.hpp"
+
namespace security_containers {
namespace dbus {
+
/**
* Base class for dbus exceptions
*/
using DbusException::DbusException;
};
+
} // namespace dbus
} // namespace security_containers
-#endif // DBUS_EXCEPTION_HPP
+
+#endif // COMMON_DBUS_EXCEPTION_HPP
*/
/**
- * @file log-backend-null.hpp
+ * @file
* @author Pawel Broda (p.broda@partner.samsung.com)
* @brief Null backend for logger
*/
-#ifndef LOG_BACKEND_NULL_HPP
-#define LOG_BACKEND_NULL_HPP
+#ifndef COMMON_LOG_BACKEND_NULL_HPP
+#define COMMON_LOG_BACKEND_NULL_HPP
+
+#include "log/backend.hpp"
-#include "log-backend.hpp"
namespace security_containers {
namespace log {
+
/**
Null logging backend
*/
void log(const std::string& /*message*/) override {}
};
+
} // namespace log
} // namespace security_containers
-#endif // LOG_BACKEND_NULL_HPP
+
+#endif // COMMON_LOG_BACKEND_NULL_HPP
*/
/**
- * @file log-backend-stderr.cpp
+ * @file
* @author Pawel Broda (p.broda@partner.samsung.com)
* @brief Stderr backend for logger
*/
-
-#include "log-backend-stderr.hpp"
+#include "log/backend-stderr.hpp"
#include <stdio.h>
+
namespace security_containers {
namespace log {
+
void StderrBackend::log(const std::string& message)
{
fprintf(stderr, "%s", message.c_str());
}
+
} // namespace log
} // namespace security_containers
*/
/**
- * @file log-backend-stderr.hpp
+ * @file
* @author Pawel Broda (p.broda@partner.samsung.com)
* @brief Stderr backend for logger
*/
+#ifndef COMMON_LOG_BACKEND_STDERR_HPP
+#define COMMON_LOG_BACKEND_STDERR_HPP
-#ifndef LOG_BACKEND_STDERR_HPP
-#define LOG_BACKEND_STDERR_HPP
+#include "log/backend.hpp"
-#include "log-backend.hpp"
namespace security_containers {
namespace log {
+
/**
Stderr logging backend
*/
void log(const std::string& message) override;
};
+
} // namespace log
} // namespace security_containers
-#endif // LOG_BACKEND_STDERR_HPP
+
+#endif // COMMON_LOG_BACKEND_STDERR_HPP
*/
/**
- * @file log-backend.hpp
+ * @file
* @author Pawel Broda (p.broda@partner.samsung.com)
* @brief Logging backend
*/
-#ifndef LOG_BACKEND_HPP
-#define LOG_BACKEND_HPP
+#ifndef COMMON_LOG_BACKEND_HPP
+#define COMMON_LOG_BACKEND_HPP
#include <string>
+
namespace security_containers {
namespace log {
+
/**
Abstract class for logger
*/
virtual ~LogBackend() {}
};
+
} // namespace log
} // namespace security_containers
-#endif // LOG_BACKEND_HPP
+
+#endif // COMMON_LOG_BACKEND_HPP
*/
/**
- * @file log.cpp
+ * @file
* @author Pawel Broda (p.broda@partner.samsung.com)
* @brief Logger
*/
-#include "log.hpp"
-#include "log-backend-null.hpp"
+#include "log/logger.hpp"
+#include "log/backend-null.hpp"
#include <iomanip>
#include <memory>
#include <mutex>
+
namespace security_containers {
namespace log {
+
namespace {
volatile LogLevel gLogLevel = LogLevel::DEBUG;
*/
/**
- * @file log.hpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Logger
*/
-#ifndef LOG_HPP
-#define LOG_HPP
+#ifndef COMMON_LOG_LOGGER_HPP
+#define COMMON_LOG_LOGGER_HPP
-#include "log-backend.hpp"
+#include "log/backend.hpp"
#include <sstream>
#include <string.h>
+
namespace security_containers {
namespace log {
+
enum class LogLevel {
TRACE, DEBUG, INFO, WARN, ERROR
};
#define LOGT(MESSAGE) LOG(TRACE, MESSAGE)
-#endif // LOG_HPP
+#endif // COMMON_LOG_LOGGER_HPP
*/
/**
- * @file utils-file-wait.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Wait for file utility function
*/
-#include "utils-file-wait.hpp"
-#include "log.hpp"
+#include "utils/file-wait.hpp"
+#include "log/logger.hpp"
+
#include <sys/stat.h>
#include <unistd.h>
#include <stdexcept>
+
namespace security_containers {
namespace utils {
+
const unsigned int GRANULARITY = 10;
void waitForFile(const std::string& filename, const unsigned int timeoutMs)
}
}
+
} // namespace utils
} // namespace security_containers
*/
/**
- * @file utils-file-wait.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Wait for file utility function
*/
-#ifndef UTILS_FILE_WAIT_HPP
-#define UTILS_FILE_WAIT_HPP
+#ifndef COMMON_UTILS_FILE_WAIT_HPP
+#define COMMON_UTILS_FILE_WAIT_HPP
#include <string>
+
namespace security_containers {
namespace utils {
+
//TODO It is used in unit tests now, but it is unclear
// whether the same solution will be used in daemon.
void waitForFile(const std::string& filename, const unsigned int timeoutMs);
+
} // namespace utils
} // namespace security_containers
-#endif // UTILS_FILE_WAIT_HPP
+
+#endif // COMMON_UTILS_FILE_WAIT_HPP
*/
/**
- * @file utils-glib-loop.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief C++ wrapper of glib main loop
*/
-#include "utils-glib-loop.hpp"
+#include "utils/glib-loop.hpp"
+
#include <glib.h>
+
namespace security_containers {
namespace utils {
+
ScopedGlibLoop::ScopedGlibLoop()
: mLoop(g_main_loop_new(NULL, FALSE), g_main_loop_unref)
{
mLoopThread.join();
}
+
} // namespace utils
} // namespace security_containers
*/
/**
- * @file utils-glib-loop.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief C++ wrapper of glib main loop
*/
-#ifndef UTILS_GLIB_LOOP_HPP
-#define UTILS_GLIB_LOOP_HPP
+#ifndef COMMON_UTILS_GLIB_LOOP_HPP
+#define COMMON_UTILS_GLIB_LOOP_HPP
#include <thread>
#include <memory>
struct _GMainLoop;
typedef struct _GMainLoop GMainLoop;
+
namespace security_containers {
namespace utils {
+
/**
* Glib loop controller. Loop is running in separate thread.
*/
std::thread mLoopThread;
};
+
} // namespace utils
} // namespace security_containers
-#endif //UTILS_GLIB_LOOP_HPP
+
+#endif // COMMON_UTILS_GLIB_LOOP_HPP
*/
/**
- * @file utils-latch.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Synchronization latch
*/
-#include "utils-latch.hpp"
+#include "utils/latch.hpp"
+
namespace security_containers {
namespace utils {
+
Latch::Latch()
: mCount(0)
{
return mCount == 0;
}
+
} // namespace utils
} // namespace security_containers
*/
/**
- * @file utils-latch.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Synchronization latch
*/
-#ifndef UTILS_LATCH_HPP
-#define UTILS_LATCH_HPP
+#ifndef COMMON_UTILS_LATCH_HPP
+#define COMMON_UTILS_LATCH_HPP
#include <mutex>
#include <condition_variable>
+
namespace security_containers {
namespace utils {
+
/**
* A synchronization aid that allows one thread to wait until
* an operation being performed in other thread completes.
int mCount;
};
+
} // namespace utils
} // namespace security_containers
-#endif // UTILS_LATCH_HPP
+
+#endif // COMMON_UTILS_LATCH_HPP
*/
/**
- * @file utils.hpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
- * @brief Utility function declaration
+ * @brief Path utility functions declaration
*/
+#ifndef COMMON_UTILS_PATHS_HPP
+#define COMMON_UTILS_PATHS_HPP
#include <string>
#include <vector>
namespace security_containers {
namespace utils {
+
template <class ...Paths> std::string createFilePath(const Paths& ... paths)
{
std::vector<std::string> pathVec = {paths...};
return path;
}
+
} // namespace utils
} // namespace security_containers
+
+
+#endif // COMMON_UTILS_PATHS_HPP
# If left blank the directory from which doxygen is run is used as the
# path to strip.
-STRIP_FROM_PATH = ../src/
+STRIP_FROM_PATH =
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
# the path mentioned in the documentation of a class, which tells
# definition is used. Otherwise one should specify the include paths that
# are normally passed to the compiler using the -I flag.
-STRIP_FROM_INC_PATH = ../src/
+STRIP_FROM_INC_PATH =
# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
# (but less readable) file names. This can be useful if your file system
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = ../src/
+INPUT = ../common ../client ../server
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
%install
%make_install
-mkdir -p %{buildroot}/etc/security-containers/config/libvirt-config/
%clean
rm -rf %{buildroot}
%attr(755,root,root) %{script_dir}/sc_all_tests.py
%attr(755,root,root) %{script_dir}/sc_launch_test.py
%{script_dir}/sc_test_parser.py
-%config %attr(644,root,root) /etc/security-containers/tests/ut-scs-container-manager/*.conf
-%config %attr(644,root,root) /etc/security-containers/tests/ut-scs-container-manager/containers/*.conf
-%config %attr(644,root,root) /etc/security-containers/tests/ut-scs-container-manager/libvirt-config/*.xml
-%config %attr(644,root,root) /etc/security-containers/tests/ut-scs-container/containers/*.conf
-%config %attr(644,root,root) /etc/security-containers/tests/ut-scs-container/libvirt-config/*.xml
-%config %attr(644,root,root) /etc/security-containers/tests/ut-scs-container-admin/containers/*.conf
-%config %attr(644,root,root) /etc/security-containers/tests/ut-scs-container-admin/libvirt-config/*.xml
-%config %attr(644,root,root) /etc/security-containers/tests/ut-dbus-connection/*.conf
+%config %attr(644,root,root) /etc/security-containers/tests/dbus/ut-connection/*.conf
+%config %attr(644,root,root) /etc/security-containers/tests/server/ut-containers-manager/*.conf
+%config %attr(644,root,root) /etc/security-containers/tests/server/ut-containers-manager/containers/*.conf
+%config %attr(644,root,root) /etc/security-containers/tests/server/ut-containers-manager/libvirt-config/*.xml
+%config %attr(644,root,root) /etc/security-containers/tests/server/ut-container/containers/*.conf
+%config %attr(644,root,root) /etc/security-containers/tests/server/ut-container/libvirt-config/*.xml
+%config %attr(644,root,root) /etc/security-containers/tests/server/ut-container-admin/containers/*.conf
+%config %attr(644,root,root) /etc/security-containers/tests/server/ut-container-admin/libvirt-config/*.xml
#
MESSAGE(STATUS "Generating makefile for the Server...")
-FILE(GLOB_RECURSE project_SRCS *.cpp *.cxx *.cc *.C *.c *.h *.hpp)
+FILE(GLOB project_SRCS *.cpp *.hpp)
+FILE(GLOB_RECURSE common_SRCS ${COMMON_FOLDER}/*.cpp ${COMMON_FOLDER}/*.hpp)
+
## Setup target ################################################################
SET(SERVER_CODENAME "${PROJECT_NAME}-server")
-ADD_EXECUTABLE(${SERVER_CODENAME} ${project_SRCS} )
+ADD_EXECUTABLE(${SERVER_CODENAME} ${project_SRCS} ${common_SRCS})
+
## Link libraries ##############################################################
FIND_PACKAGE (Boost COMPONENTS program_options REQUIRED)
PKG_CHECK_MODULES(SERVER_DEPS REQUIRED libvirt json gio-2.0)
-INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(${COMMON_FOLDER} ${SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${SERVER_CODENAME} ${SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES})
+
+## Subdirectories ##############################################################
+ADD_SUBDIRECTORY(configs)
+
+
## Install #####################################################################
INSTALL(TARGETS ${SERVER_CODENAME} DESTINATION bin)
#
#
# @file CMakeLists.txt
-# @author Jan Olszak (j.olszak@samsung.com)
+# @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
#
-ADD_SUBDIRECTORY(client)
-ADD_SUBDIRECTORY(server)
-ADD_SUBDIRECTORY(scripts)
+MESSAGE(STATUS "Installing configs to " ${SC_CONFIG_INSTALL_DIR})
+
+
+## Installations ###############################################################
+INSTALL(FILES daemon.conf
+ DESTINATION ${SC_CONFIG_INSTALL_DIR})
+
+INSTALL(FILES containers/xminimal.conf
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/containers)
+
+INSTALL(FILES libvirt-config/xminimal.xml
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/libvirt-config)
*/
/**
- * @file scs-container-admin.cpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Implementation of class for administrating one container
*/
-#include "scs-container-admin.hpp"
-#include "scs-exception.hpp"
-#include "log.hpp"
+#include "container-admin.hpp"
+#include "exception.hpp"
+#include "log/logger.hpp"
#include <assert.h>
#include <string>
#include <memory>
#include <cstdint>
+
namespace security_containers {
+
const std::uint64_t DEFAULT_CPU_SHARES = 1024;
const std::uint64_t DEFAULT_VCPU_PERIOD_MS = 100000;
std::ifstream t(mConfig.config);
if (!t.is_open()) {
LOGE("libvirt config file is missing");
- throw ConfigException();
+ throw config::ConfigException();
}
std::string libvirtConfig((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
define(libvirtConfig);
return quota;
}
+
} // namespace security_containers
*/
/**
- * @file scs-container-admin.hpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Declaration of the class for administrating one container
*/
-#ifndef SECURITY_CONTAINERS_SERVER_CONTAINER_ADMIN_HPP
-#define SECURITY_CONTAINERS_SERVER_CONTAINER_ADMIN_HPP
+#ifndef SERVER_CONTAINER_ADMIN_HPP
+#define SERVER_CONTAINER_ADMIN_HPP
-#include "scs-container-config.hpp"
+#include "container-config.hpp"
#include <string>
#include <cstdint>
#include <libvirt/libvirt.h>
+
namespace security_containers {
+
enum class SchedulerLevel {
FOREGROUND,
BACKGROUND
int getState(); // get the libvirt's domain state
void setSchedulerParams(std::uint64_t cpuShares, std::uint64_t vcpuPeriod, std::int64_t vcpuQuota);
};
+
+
}
-#endif // SECURITY_CONTAINERS_SERVER_CONTAINER_ADMIN_HPP
+
+
+#endif // SERVER_CONTAINER_ADMIN_HPP
*/
/**
- * @file scs-container-config.hpp
+ * @file
* @author Michal Witanowski (m.witanowski@samsung.com)
* @brief Declaration of the class for storing container configuration
*/
-#ifndef SECURITY_CONTAINERS_SERVER_CONTAINER_CONFIG_HPP
-#define SECURITY_CONTAINERS_SERVER_CONTAINER_CONFIG_HPP
+#ifndef SERVER_CONTAINER_CONFIG_HPP
+#define SERVER_CONTAINER_CONFIG_HPP
+
+#include "config/configuration.hpp"
-#include "scs-configuration.hpp"
#include <string>
+
namespace security_containers {
-struct ContainerConfig : public ConfigurationBase {
+
+struct ContainerConfig : public config::ConfigurationBase {
/**
* Privilege of the container.
* The smaller the value the more important the container
}
};
+
}
-#endif // SECURITY_CONTAINERS_SERVER_CONTAINER_CONFIG_HPP
+
+#endif // SERVER_CONTAINER_CONFIG_HPP
*/
/**
- * @file scs-container.cpp
+ * @file
* @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
* @brief Implementation of class for managing one container
*/
-#include "scs-container.hpp"
-#include "utils.hpp"
-#include "log.hpp"
+#include "container.hpp"
+#include "log/logger.hpp"
+#include "utils/paths.hpp"
#include <assert.h>
#include <string>
+
namespace security_containers {
+
Container::Container(const std::string& containerConfigPath)
{
mConfig.parseFile(containerConfigPath);
mAdmin.reset(new ContainerAdmin(mConfig));
}
-
Container::~Container()
{
}
-
std::string Container::getId()
{
return mAdmin->getId();
}
-
int Container::getPrivilege()
{
return mConfig.privilege;
}
-
void Container::start()
{
return mAdmin->start();
}
-
void Container::stop()
{
return mAdmin->stop();
}
-
void Container::goForeground()
{
mAdmin->setSchedulerLevel(SchedulerLevel::FOREGROUND);
}
-
void Container::goBackground()
{
mAdmin->setSchedulerLevel(SchedulerLevel::BACKGROUND);
}
-
bool Container::isRunning()
{
return mAdmin->isRunning();
}
-
bool Container::isStopped()
{
return mAdmin->isStopped();
}
-
bool Container::isPaused()
{
return mAdmin->isPaused();
*/
/**
- * @file scs-container.hpp
+ * @file
* @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
* @brief Declaration of the class for managing one container
*/
-#ifndef SECURITY_CONTAINERS_SERVER_CONTAINER_HPP
-#define SECURITY_CONTAINERS_SERVER_CONTAINER_HPP
+#ifndef SERVER_CONTAINER_HPP
+#define SERVER_CONTAINER_HPP
-#include "scs-container-config.hpp"
-#include "scs-container-admin.hpp"
+#include "container-config.hpp"
+#include "container-admin.hpp"
#include <string>
#include <memory>
+
namespace security_containers {
+
class Container {
public:
std::unique_ptr<ContainerAdmin> mAdmin;
};
+
}
-#endif // SECURITY_CONTAINERS_SERVER_CONTAINER_HPP
+
+#endif // SERVER_CONTAINER_HPP
*/
/**
- * @file scs-container-manager-config.hpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Declaration of the class for storing container manager configuration
*/
-#ifndef SECURITY_CONTAINERS_SERVER_CONTAINER_MANAGER_CONFIG_HPP
-#define SECURITY_CONTAINERS_SERVER_CONTAINER_MANAGER_CONFIG_HPP
+#ifndef SERVER_CONTAINERS_MANAGER_CONFIG_HPP
+#define SERVER_CONTAINERS_MANAGER_CONFIG_HPP
+
+#include "config/configuration.hpp"
-#include "scs-configuration.hpp"
#include <string>
#include <vector>
+
namespace security_containers {
-const std::string CONTAINER_MANAGER_CONFIG_PATH = "/etc/security-containers/config/daemon.conf";
-struct ContainerManagerConfig : public ConfigurationBase {
+const std::string CONTAINERS_MANAGER_CONFIG_PATH = "/etc/security-containers/config/daemon.conf";
+
+struct ContainersManagerConfig : public config::ConfigurationBase {
/**
* List of containers' configs that we manage.
* File paths can be relative to the ContainerManager config file.
}
};
-}
-#endif // SECURITY_CONTAINERS_SERVER_CONTAINER_MANAGER_CONFIG_HPP
+} // namespace security_containers
+
+
+#endif // SERVER_CONTAINERS_MANAGER_CONFIG_HPP
*/
/**
- * @file scs-container-manager.cpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Definition of the class for managing containers
*/
-#include "scs-container-manager.hpp"
-#include "scs-container-admin.hpp"
-#include "scs-exception.hpp"
-#include "utils.hpp"
-#include "log.hpp"
+#include "containers-manager.hpp"
+#include "container-admin.hpp"
+#include "exception.hpp"
+#include "utils/paths.hpp"
+#include "log/logger.hpp"
#include <assert.h>
#include <string>
#include <climits>
+
namespace security_containers {
-ContainerManager::ContainerManager(const std::string& managerConfigPath)
+ContainersManager::ContainersManager(const std::string& managerConfigPath)
{
mConfig.parseFile(managerConfigPath);
connect();
}
-ContainerManager::~ContainerManager()
+ContainersManager::~ContainersManager()
{
try {
stopAll();
}
-void ContainerManager::focus(const std::string& containerId)
+void ContainersManager::focus(const std::string& containerId)
{
/* try to access the object first to throw immediately if it doesn't exist */
ContainerMap::mapped_type& foregroundContainer = mContainers.at(containerId);
}
-void ContainerManager::startAll()
+void ContainersManager::startAll()
{
bool isForegroundFound = false;
}
-void ContainerManager::stopAll()
+void ContainersManager::stopAll()
{
for (auto& container : mContainers) {
container.second->stop();
}
-std::string ContainerManager::getRunningForegroundContainerId()
+std::string ContainersManager::getRunningForegroundContainerId()
{
for (auto& container : mContainers) {
if (container.first == mConfig.foregroundId &&
}
-void ContainerManager::connect()
+void ContainersManager::connect()
{
assert(mVir == NULL);
}
-void ContainerManager::disconnect()
+void ContainersManager::disconnect()
{
if (mVir == NULL) {
return;
*/
/**
- * @file scs-container-manager.hpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Declaration of the class for managing many containers
*/
-#ifndef SECURITY_CONTAINERS_SERVER_CONTAINER_MANAGER_HPP
-#define SECURITY_CONTAINERS_SERVER_CONTAINER_MANAGER_HPP
+#ifndef SERVER_CONTAINERS_MANAGER_HPP
+#define SERVER_CONTAINERS_MANAGER_HPP
-#include "scs-container.hpp"
-#include "scs-container-manager-config.hpp"
+#include "container.hpp"
+#include "containers-manager-config.hpp"
#include <string>
#include <unordered_map>
-
#include <libvirt/libvirt.h>
+
namespace security_containers {
-class ContainerManager final {
+
+class ContainersManager final {
public:
- ContainerManager(const std::string& managerConfigPath);
- ~ContainerManager();
+ ContainersManager(const std::string& managerConfigPath);
+ ~ContainersManager();
/**
* Focus this container, put it to the foreground.
std::string getRunningForegroundContainerId();
private:
- ContainerManagerConfig mConfig;
+ ContainersManagerConfig mConfig;
// TODO: secure this pointer from exceptions (e.g. in constructor)
virConnectPtr mVir = NULL; // pointer to the connection with libvirt
typedef std::unordered_map<std::string, std::unique_ptr<Container>> ContainerMap;
void connect();
void disconnect();
};
+
+
}
-#endif // SECURITY_CONTAINERS_SERVER_CONTAINER_MANAGER_HPP
+
+
+#endif // SERVER_CONTAINERS_MANAGER_HPP
*/
/**
- * @file scs-exception.hpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Exceptions for the server
*/
-#ifndef SECURITY_CONTAINERS_SERVER_EXCEPTION_HPP
-#define SECURITY_CONTAINERS_SERVER_EXCEPTION_HPP
+#ifndef SERVER_EXCEPTION_HPP
+#define SERVER_EXCEPTION_HPP
#include "base-exception.hpp"
+
namespace security_containers {
+
/**
* Base class for exceptions in Security Containers Server
*/
using ServerException::ServerException;
};
-/**
- * Error occured during a config file parsing,
- * e.g. syntax error
- */
-struct ConfigException: public ServerException {
- using ServerException::ServerException;
-};
}
-#endif // SECURITY_CONTAINERS_SERVER_EXCEPTION_HPP
+
+#endif // SERVER_EXCEPTION_HPP
/**
- * @file main.cpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Main file for the Security Containers Daemon
*/
-#include "log.hpp"
-#include "log-backend-stderr.hpp"
-#include "utils-glib-loop.hpp"
-#include "utils-latch.hpp"
+#include "log/logger.hpp"
+#include "log/backend-stderr.hpp"
+#include "utils/glib-loop.hpp"
+#include "utils/latch.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
namespace security_containers {
namespace {
+
utils::Latch signalLatch;
void signalHandler(int sig)
} // namespace
} // namespace security_containers
+
namespace {
+
const std::string PROGRAM_NAME_AND_VERSION =
"Security Containers Server " PROGRAM_VERSION;
} // namespace
+
int main(int argc, char* argv[])
{
try {
+++ /dev/null
-# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#
-# @file CMakeLists.txt
-# @author Jan Olszak (j.olszak@samsung.com)
-#
-
-INCLUDE_DIRECTORIES ("${CLIENT_FOLDER}/include")
-ADD_SUBDIRECTORY(src)
\ No newline at end of file
+++ /dev/null
-#ifndef SC_CLIENT_H
-#define SC_CLIENT_H
-
-#endif /*SC_CLIENT_H*/
+++ /dev/null
-#ifndef SECURITY_CONTAINERS_CLIENT_EXCEPTION_HPP
-#define SECURITY_CONTAINERS_CLIENT_EXCEPTION_HPP
-
-#include <stdexcept>
-
-namespace security_containers {
-
-/**
- * @brief Base class for exceptions in Security Containers Client
- */
-struct ClientException: public std::runtime_error {
- ServerException(const std::string& mess = "Security Containers Client Exception"):
- std::runtime_error(mess) {};
-};
-
-}
-
-#endif // SECURITY_CONTAINERS_CLIENT_EXCEPTION_HPP
+++ /dev/null
-#include <sc-client.hpp>
\ No newline at end of file
+++ /dev/null
-# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#
-# @file CMakeLists.txt
-# @author Jan Olszak (j.olszak@samsung.com)
-#
-
-INCLUDE_DIRECTORIES ("${SERVER_FOLDER}/include")
-ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(unit_tests)
+++ /dev/null
-#ifndef SECURITY_CONTAINERS_SERVER_SCS_H
-#define SECURITY_CONTAINERS_SERVER_SCS_H
-
-#endif // SECURITY_CONTAINERS_SERVER_SCS_H
+++ /dev/null
-# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#
-# @file CMakeLists.txt
-# @author Jan Olszak (j.olszak@samsung.com)
-#
-
-MESSAGE(STATUS "Generating makefile for the Server unit tests...")
-FILE(GLOB_RECURSE project_SRCS *.cpp)
-FILE(GLOB src_SRCS ${SERVER_FOLDER}/src/dbus-connection.cpp
- ${SERVER_FOLDER}/src/log.cpp
- ${SERVER_FOLDER}/src/log-backend.cpp
- ${SERVER_FOLDER}/src/log-backend-stderr.cpp
- ${SERVER_FOLDER}/src/scs-container-admin.cpp
- ${SERVER_FOLDER}/src/scs-container.cpp
- ${SERVER_FOLDER}/src/scs-container-manager.cpp
- ${SERVER_FOLDER}/src/scs-configuration.cpp
- ${SERVER_FOLDER}/src/utils-glib-loop.cpp
- ${SERVER_FOLDER}/src/utils-file-wait.cpp
- ${SERVER_FOLDER}/src/utils-latch.cpp)
-
-
-## Setup target ################################################################
-SET(UT_SERVER_CODENAME "${PROJECT_NAME}-server-unit-tests")
-ADD_EXECUTABLE(${UT_SERVER_CODENAME} ${project_SRCS} ${src_SRCS})
-
-## Link libraries ##############################################################
-FIND_PACKAGE (Boost COMPONENTS unit_test_framework REQUIRED)
-
-PKG_CHECK_MODULES(UT_SERVER_DEPS REQUIRED libvirt json gio-2.0)
-
-INCLUDE_DIRECTORIES(SYSTEM ${UT_SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
-TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES})
-
-## Install #####################################################################
-INSTALL(TARGETS ${UT_SERVER_CODENAME} DESTINATION bin)
-
-FILE(GLOB manager_manager_CONF ${SERVER_FOLDER}/unit_tests/config/ut-scs-container-manager/*.conf)
-FILE(GLOB manager_container_CONF ${SERVER_FOLDER}/unit_tests/config/ut-scs-container-manager/containers/*.conf)
-FILE(GLOB manager_admin_CONF ${SERVER_FOLDER}/unit_tests/config/ut-scs-container-manager/libvirt-config/*.xml)
-
-FILE(GLOB container_container_CONF ${SERVER_FOLDER}/unit_tests/config/ut-scs-container/containers/*.conf)
-FILE(GLOB container_admin_CONF ${SERVER_FOLDER}/unit_tests/config/ut-scs-container/libvirt-config/*.xml)
-
-FILE(GLOB admin_container_CONF ${SERVER_FOLDER}/unit_tests/config/ut-scs-container-admin/containers/*.conf)
-FILE(GLOB admin_admin_CONF ${SERVER_FOLDER}/unit_tests/config/ut-scs-container-admin/libvirt-config/*.xml)
-
-FILE(GLOB dbus_CONF ${SERVER_FOLDER}/unit_tests/config/ut-dbus-connection/*.conf)
-
-INSTALL(FILES ${manager_manager_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-scs-container-manager)
-INSTALL(FILES ${manager_container_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-scs-container-manager/containers)
-INSTALL(FILES ${manager_admin_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-scs-container-manager/libvirt-config)
-
-INSTALL(FILES ${container_container_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-scs-container/containers)
-INSTALL(FILES ${container_admin_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-scs-container/libvirt-config)
-
-INSTALL(FILES ${admin_container_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-scs-container-admin/containers)
-INSTALL(FILES ${admin_admin_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-scs-container-admin/libvirt-config)
-
-INSTALL(FILES ${dbus_CONF}
- DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/ut-dbus-connection)
+++ /dev/null
-{
- "privilege" : 10,
- "config" : "/etc/security-containers/tests/ut-scs-container-admin/libvirt-config/buggy.xml",
- "cpuQuotaForeground" : -1,
- "cpuQuotaBackground" : 1000
-}
+++ /dev/null
-{
- "privilege" : 10,
- "config" : "/etc/security-containers/tests/ut-scs-container-admin/libvirt-config/test.xml",
- "cpuQuotaForeground" : -1,
- "cpuQuotaBackground" : 1000
-}
--- /dev/null
+# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# @file CMakeLists.txt
+# @author Jan Olszak (j.olszak@samsung.com)
+#
+
+MESSAGE(STATUS "Generating makefile for the Unit Tests...")
+FILE(GLOB_RECURSE project_SRCS *.cpp *.hpp)
+FILE(GLOB_RECURSE common_SRCS ${COMMON_FOLDER}/*.cpp ${COMMON_FOLDER}/*.hpp)
+FILE(GLOB server_SRCS ${SERVER_FOLDER}/*.cpp ${SERVER_FOLDER}/*.hpp)
+
+FILE(GLOB main_SRC ${SERVER_FOLDER}/main.cpp)
+LIST(REMOVE_ITEM server_SRCS ${main_SRC})
+
+
+## Setup target ################################################################
+SET(UT_SERVER_CODENAME "${PROJECT_NAME}-server-unit-tests")
+ADD_EXECUTABLE(${UT_SERVER_CODENAME} ${project_SRCS} ${common_SRCS} ${server_SRCS})
+
+
+## Link libraries ##############################################################
+FIND_PACKAGE (Boost COMPONENTS unit_test_framework REQUIRED)
+
+PKG_CHECK_MODULES(UT_SERVER_DEPS REQUIRED libvirt json gio-2.0)
+INCLUDE_DIRECTORIES(${COMMON_FOLDER} ${SERVER_FOLDER} ${UNIT_TESTS_FOLDER}
+ ${UT_SERVER_DEPS_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
+TARGET_LINK_LIBRARIES(${UT_SERVER_CODENAME} ${UT_SERVER_DEPS_LIBRARIES} ${Boost_LIBRARIES})
+
+
+## Subdirectories ##############################################################
+ADD_SUBDIRECTORY(scripts)
+ADD_SUBDIRECTORY(dbus/configs)
+ADD_SUBDIRECTORY(server/configs)
+
+
+## Install #####################################################################
+INSTALL(TARGETS ${UT_SERVER_CODENAME} DESTINATION bin)
/**
- * @file ut-scs-configuration.cpp
+ * @file
* @author Michal Witanowski (m.witanowski@samsung.com)
* @brief Unit test of ConfigurationBase
*/
#include "ut.hpp"
-#include "scs-configuration.hpp"
+#include "config/configuration.hpp"
using namespace security_containers;
+using namespace security_containers::config;
BOOST_AUTO_TEST_SUITE(ConfigSuite)
#
#
# @file CMakeLists.txt
-# @author Jan Olszak (j.olszak@samsung.com)
+# @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
#
-MESSAGE(STATUS "Generating makefile for the Client...")
-FILE(GLOB_RECURSE project_SRCS *.cpp *.cxx *.cc *.C *.c *.h *.hpp)
+MESSAGE(STATUS "Installing configs for the DBus Unit Tests to " ${SC_CONFIG_INSTALL_DIR})
+FILE(GLOB dbus_CONF ut-connection/*.conf)
-ADD_LIBRARY(${CLIENT_CODENAME} SHARED ${project_SRCS})
-INSTALL(TARGETS ${CLIENT_CODENAME}
- DESTINATION ${CMAKE_INSTALL_LIBDIR}
- COMPONENT RuntimeLibraries)
+
+## Install #####################################################################
+INSTALL(FILES ${dbus_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/dbus/ut-connection)
*/
/**
- * @file dbus-test-client.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Example dbus api client
*/
-#include "dbus-test-client.hpp"
-#include "dbus-connection.hpp"
-#include "dbus-test-common.hpp"
+#include "dbus/test-client.hpp"
+#include "dbus/test-common.hpp"
+
+#include "dbus/connection.hpp"
+
namespace security_containers {
+
DbusTestClient::DbusTestClient()
{
mConnection = dbus::DbusConnection::create(DBUS_ADDRESS);
"()");
}
+
} // namespace security_containers
*/
/**
- * @file dbus-test-client.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Example dbus api client
*/
-#ifndef DBUS_TEST_CLIENT_HPP
-#define DBUS_TEST_CLIENT_HPP
+#ifndef UNIT_TESTS_DBUS_TEST_CLIENT_HPP
+#define UNIT_TESTS_DBUS_TEST_CLIENT_HPP
+
+#include "dbus/connection.hpp" //TODO dbus/connection-iface.h
-#include "dbus-connection.hpp" //TODO dbus-connection-iface.h
#include <string>
#include <memory>
+
namespace security_containers {
+
/**
* Simple dbus client for test purposes.
* Class used to test all possible kinds of dbus calls.
dbus::DbusConnection::Pointer mConnection;
};
+
} // namespace security_containers
-#endif //DBUS_TEST_CLIENT_HPP
+
+#endif // UNIT_TESTS_DBUS_TEST_CLIENT_HPP
*/
/**
- * @file dbus-test-common.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Common definitions for dbus tests
*/
-#ifndef DBUS_TEST_COMMON_HPP
-#define DBUS_TEST_COMMON_HPP
+#ifndef UNIT_TESTS_DBUS_TEST_COMMON_HPP
+#define UNIT_TESTS_DBUS_TEST_COMMON_HPP
#include <string>
+
namespace security_containers {
+
const std::string DBUS_SOCKET_FILE = "/tmp/container_socket";
const std::string DBUS_ADDRESS = "unix:path=" + DBUS_SOCKET_FILE;
" </interface>"
"</node>";
+
} // namespace security_containers
-#endif //DBUS_TEST_COMMON_HPP
+
+#endif // UNIT_TESTS_DBUS_TEST_COMMON_HPP
*/
/**
- * @file dbus-test-server.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Example dbus api server
*/
-#include "dbus-test-server.hpp"
-#include "dbus-connection.hpp"
-#include "dbus-exception.hpp"
-#include "dbus-test-common.hpp"
-#include "log.hpp"
+#include "dbus/test-server.hpp"
+#include "dbus/test-common.hpp"
+
+#include "dbus/connection.hpp"
+#include "dbus/exception.hpp"
+#include "log/logger.hpp"
+
namespace security_containers {
+
DbusTestServer::DbusTestServer()
: mNameAcquired(false)
, mPendingDisconnect(false)
}
}
+
} // namespace security_containers
*/
/**
- * @file dbus-test-server.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Example dbus api server
*/
-#ifndef DBUS_TEST_SERVER_HPP
-#define DBUS_TEST_SERVER_HPP
+#ifndef UNIT_TESTS_DBUS_TEST_SERVER_HPP
+#define UNIT_TESTS_DBUS_TEST_SERVER_HPP
+
+#include "dbus/connection.hpp" // TODO dbus-connection-iface.h
-#include "dbus-connection.hpp" // TODO dbus-connection-iface.h
#include <string>
#include <memory>
#include <mutex>
#include <condition_variable>
+
namespace security_containers {
+
/**
* Simple dbus server for test purposes.
* Class used to test all possible kinds of callbacks.
dbus::MethodResultBuilder& result);
};
+
} // namespace security_containers
-#endif //DBUS_TEST_SERVER_HPP
+
+#endif // UNIT_TESTS_DBUS_TEST_SERVER_HPP
*/
/**
- * @file ut-dbus-connection.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Dbus connection unit tests
*/
#include "ut.hpp"
-#include "dbus-connection.hpp"
-#include "dbus-exception.hpp"
-#include "utils-scoped-daemon.hpp"
-#include "utils-glib-loop.hpp"
-#include "utils-file-wait.hpp"
-#include "utils-latch.hpp"
-#include "dbus-test-server.hpp"
-#include "dbus-test-client.hpp"
-#include "dbus-test-common.hpp"
-#include "log.hpp"
+#include "dbus/test-server.hpp"
+#include "dbus/test-client.hpp"
+#include "dbus/test-common.hpp"
+#include "utils/scoped-daemon.hpp"
+
+#include "dbus/connection.hpp"
+#include "dbus/exception.hpp"
+#include "utils/glib-loop.hpp"
+#include "utils/file-wait.hpp"
+#include "utils/latch.hpp"
+#include "log/logger.hpp"
+
#include <thread>
#include <mutex>
#include <condition_variable>
const char* DBUS_DAEMON_PROC = "/bin/dbus-daemon";
const char* const DBUS_DAEMON_ARGS[] = {
DBUS_DAEMON_PROC,
- "--config-file=/etc/security-containers/tests/ut-dbus-connection/ut-dbus.conf",
+ "--config-file=/etc/security-containers/tests/dbus/ut-connection/ut-dbus.conf",
"--nofork",
NULL
};
/**
- * @file ut-log.cpp
+ * @file
* @author Pawel Broda (p.broda@partner.samsung.com)
* @brief Unit tests of the log utility
*/
#include "ut.hpp"
-#include "log.hpp"
-#include "log-backend.hpp"
-#include "log-backend-stderr.hpp"
+
+#include "log/logger.hpp"
+#include "log/backend.hpp"
+#include "log/backend-stderr.hpp"
BOOST_AUTO_TEST_SUITE(LogSuite)
MESSAGE(STATUS "Installing scripts to " ${SCRIPT_INSTALL_DIR})
FILE(GLOB_RECURSE scripts *.py)
+
+## Install #####################################################################
INSTALL(PROGRAMS ${scripts} DESTINATION ${SCRIPT_INSTALL_DIR})
--- /dev/null
+# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# @file CMakeLists.txt
+# @author Jan Olszak (j.olszak@samsung.com)
+#
+
+MESSAGE(STATUS "Installing configs for the Server Unit Tests to " ${SC_CONFIG_INSTALL_DIR})
+FILE(GLOB manager_manager_CONF ut-containers-manager/*.conf)
+FILE(GLOB manager_container_CONF ut-containers-manager/containers/*.conf)
+FILE(GLOB manager_admin_CONF ut-containers-manager/libvirt-config/*.xml)
+
+FILE(GLOB container_container_CONF ut-container/containers/*.conf)
+FILE(GLOB container_admin_CONF ut-container/libvirt-config/*.xml)
+
+FILE(GLOB admin_container_CONF ut-container-admin/containers/*.conf)
+FILE(GLOB admin_admin_CONF ut-container-admin/libvirt-config/*.xml)
+
+
+## Install #####################################################################
+INSTALL(FILES ${manager_manager_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/server/ut-containers-manager)
+INSTALL(FILES ${manager_container_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/server/ut-containers-manager/containers)
+INSTALL(FILES ${manager_admin_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/server/ut-containers-manager/libvirt-config)
+
+INSTALL(FILES ${container_container_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/server/ut-container/containers)
+INSTALL(FILES ${container_admin_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/server/ut-container/libvirt-config)
+
+INSTALL(FILES ${admin_container_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/server/ut-container-admin/containers)
+INSTALL(FILES ${admin_admin_CONF}
+ DESTINATION ${SC_CONFIG_INSTALL_DIR}/tests/server/ut-container-admin/libvirt-config)
--- /dev/null
+{
+ "privilege" : 10,
+ "config" : "/etc/security-containers/tests/server/ut-container-admin/libvirt-config/buggy.xml",
+ "cpuQuotaForeground" : -1,
+ "cpuQuotaBackground" : 1000
+}
--- /dev/null
+{
+ "privilege" : 10,
+ "config" : "/etc/security-containers/tests/server/ut-container-admin/libvirt-config/test.xml",
+ "cpuQuotaForeground" : -1,
+ "cpuQuotaBackground" : 1000
+}
/**
- * @file ut-scs-container-admin.cpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Unit tests of the ContainerAdmin class
*/
#include "ut.hpp"
-#include "scs-container-admin.hpp"
-#include "scs-exception.hpp"
+
+#include "container-admin.hpp"
+#include "exception.hpp"
#include <memory>
#include <string>
BOOST_AUTO_TEST_SUITE(ContainerAdminSuite)
using namespace security_containers;
+using namespace security_containers::config;
-const std::string TEST_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container-admin/containers/test.conf";
-const std::string BUGGY_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container-admin/containers/buggy.conf";
-const std::string MISSING_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container-admin/containers/missing.conf";
+const std::string TEST_CONFIG_PATH = "/etc/security-containers/tests/server/ut-container-admin/containers/test.conf";
+const std::string BUGGY_CONFIG_PATH = "/etc/security-containers/tests/server/ut-container-admin/containers/buggy.conf";
+const std::string MISSING_CONFIG_PATH = "/etc/security-containers/tests/server/ut-container-admin/containers/missing.conf";
BOOST_AUTO_TEST_CASE(ConstructorTest)
/**
- * @file ut-scs-container.cpp
+ * @file
* @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
* @brief Unit tests of the Container class
*/
#include "ut.hpp"
-#include "scs-container.hpp"
-#include "scs-exception.hpp"
+
+#include "container.hpp"
+#include "exception.hpp"
#include <memory>
#include <string>
BOOST_AUTO_TEST_SUITE(ContainerSuite)
using namespace security_containers;
+using namespace security_containers::config;
-const std::string TEST_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container/containers/test.conf";
-const std::string BUGGY_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container/containers/buggy.conf";
+const std::string TEST_CONFIG_PATH = "/etc/security-containers/tests/server/ut-container/containers/test.conf";
+const std::string BUGGY_CONFIG_PATH = "/etc/security-containers/tests/server/ut-container/containers/buggy.conf";
const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/config.conf";
BOOST_AUTO_TEST_CASE(BuggyConfigTest)
{
- BOOST_REQUIRE_THROW(Container c(BUGGY_CONFIG_PATH), ServerException);
+ BOOST_REQUIRE_THROW(Container c(BUGGY_CONFIG_PATH), ConfigException);
}
BOOST_AUTO_TEST_CASE(MissingConfigTest)
/**
- * @file ut-scs-container.cpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
- * @brief Unit tests of the Container class
+ * @brief Unit tests of the ContainersManager class
*/
#include "ut.hpp"
-#include "scs-container-manager.hpp"
-#include "scs-exception.hpp"
+
+#include "containers-manager.hpp"
+#include "exception.hpp"
#include <memory>
#include <string>
-BOOST_AUTO_TEST_SUITE(ContainerManagerSuite)
+BOOST_AUTO_TEST_SUITE(ContainersManagerSuite)
using namespace security_containers;
+using namespace security_containers::config;
-const std::string TEST_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container-manager/test-daemon.conf";
-const std::string BUGGY_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container-manager/buggy-daemon.conf";
-const std::string BUGGY_FOREGROUND_CONFIG_PATH = "/etc/security-containers/tests/ut-scs-container-manager/buggy-foreground-daemon.conf";
+const std::string TEST_CONFIG_PATH = "/etc/security-containers/tests/server/ut-containers-manager/test-daemon.conf";
+const std::string BUGGY_CONFIG_PATH = "/etc/security-containers/tests/server/ut-containers-manager/buggy-daemon.conf";
+const std::string BUGGY_FOREGROUND_CONFIG_PATH = "/etc/security-containers/tests/server/ut-containers-manager/buggy-foreground-daemon.conf";
const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/missing-daemon.conf";
BOOST_AUTO_TEST_CASE(ConstructorTest)
{
- BOOST_REQUIRE_NO_THROW(ContainerManager cm(TEST_CONFIG_PATH););
+ BOOST_REQUIRE_NO_THROW(ContainersManager cm(TEST_CONFIG_PATH););
}
BOOST_AUTO_TEST_CASE(DestructorTest)
{
- std::unique_ptr<ContainerManager> cm(new ContainerManager(TEST_CONFIG_PATH));
+ std::unique_ptr<ContainersManager> cm(new ContainersManager(TEST_CONFIG_PATH));
BOOST_REQUIRE_NO_THROW(cm.reset());
}
BOOST_AUTO_TEST_CASE(BuggyConfigTest)
{
- BOOST_REQUIRE_THROW(ContainerManager cm(BUGGY_CONFIG_PATH), ConfigException);
+ BOOST_REQUIRE_THROW(ContainersManager cm(BUGGY_CONFIG_PATH), ConfigException);
}
BOOST_AUTO_TEST_CASE(MissingConfigTest)
{
- BOOST_REQUIRE_THROW(ContainerManager cm(MISSING_CONFIG_PATH), ConfigException);
+ BOOST_REQUIRE_THROW(ContainersManager cm(MISSING_CONFIG_PATH), ConfigException);
}
BOOST_AUTO_TEST_CASE(StartAllTest)
{
- ContainerManager cm(TEST_CONFIG_PATH);
+ ContainersManager cm(TEST_CONFIG_PATH);
BOOST_REQUIRE_NO_THROW(cm.startAll());
BOOST_CHECK(cm.getRunningForegroundContainerId() == "console1");
}
BOOST_AUTO_TEST_CASE(BuggyForegroundTest)
{
- ContainerManager cm(BUGGY_FOREGROUND_CONFIG_PATH);
+ ContainersManager cm(BUGGY_FOREGROUND_CONFIG_PATH);
BOOST_REQUIRE_NO_THROW(cm.startAll());
BOOST_CHECK(cm.getRunningForegroundContainerId() == "console2");
}
BOOST_AUTO_TEST_CASE(StopAllTest)
{
- ContainerManager cm(TEST_CONFIG_PATH);
+ ContainersManager cm(TEST_CONFIG_PATH);
BOOST_REQUIRE_NO_THROW(cm.startAll());
BOOST_REQUIRE_NO_THROW(cm.stopAll());
BOOST_CHECK(cm.getRunningForegroundContainerId().empty());
BOOST_AUTO_TEST_CASE(FocusTest)
{
- ContainerManager cm(TEST_CONFIG_PATH);
+ ContainersManager cm(TEST_CONFIG_PATH);
BOOST_REQUIRE_NO_THROW(cm.startAll());
BOOST_REQUIRE_NO_THROW(cm.focus("console2"));
BOOST_CHECK(cm.getRunningForegroundContainerId() == "console2");
/**
- * @file ut-main.cpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Main file for the Security Containers Daemon unit tests
*/
-#include "log.hpp"
-#include "log-backend-stderr.hpp"
+#define BOOST_TEST_MAIN init_unit_test_suite
+#include "ut.hpp"
-#include <boost/test/included/unit_test.hpp>
-#include <boost/test/unit_test.hpp> // for unit_test framework
+#include "log/logger.hpp"
+#include "log/backend-stderr.hpp"
using namespace boost::unit_test;
using namespace security_containers::log;
-test_suite* init_unit_test_suite(int /*argc*/, char** /*argv*/)
+test_suite* BOOST_TEST_MAIN(int /*argc*/, char** /*argv*/)
{
Logger::setLogLevel(LogLevel::TRACE);
Logger::setLogBackend(new StderrBackend());
*/
/**
- * @file ut.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Common unit tests include file
*/
-#ifndef SECURITY_CONTAINERS_UT_HPP
-#define SECURITY_CONTAINERS_UT_HPP
+#ifndef UNIT_TESTS_UT_HPP
+#define UNIT_TESTS_UT_HPP
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
-#endif //SECURITY_CONTAINERS_UT_HPP
+#endif // UNIT_TESTS_UT_HPP
*/
/**
- * @file utils-scoped-daemon.cpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Starts external daemon in constructor, stops it in destructor
*/
-#include "utils-scoped-daemon.hpp"
-#include "log.hpp"
+#include "utils/scoped-daemon.hpp"
+
+#include "log/logger.hpp"
+
#include <unistd.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <stdexcept>
+
namespace security_containers {
namespace utils {
+
/*
* Scoped Daemon - sequence diagram.
*
mPid = -1;
}
+
} // namespace utils
} // namespace security_containers
*/
/**
- * @file utils-scoped-daemon.hpp
+ * @file
* @author Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
* @brief Starts external daemon in constructor, stops it in destructor
*/
-#ifndef UTILS_SCOPED_DAEMON_HPP
-#define UTILS_SCOPED_DAEMON_HPP
+#ifndef UNIT_TESTS_UTILS_SCOPED_DAEMON_HPP
+#define UNIT_TESTS_UTILS_SCOPED_DAEMON_HPP
#include <sys/types.h>
+
namespace security_containers {
namespace utils {
+
/**
* External daemon launcher helper.
*/
pid_t mPid;
};
+
} // namespace utils
} // namespace security_containers
-#endif // UTILS_SCOPED_DAEMON_HPP
+
+#endif // UNIT_TESTS_UTILS_SCOPED_DAEMON_HPP
/**
- * @file ut-utils.cpp
+ * @file
* @author Jan Olszak (j.olszak@samsung.com)
* @brief Unit tests of utils
*/
#include "ut.hpp"
-#include "utils.hpp"
+
+#include "utils/paths.hpp"
#include <memory>