From: Krzysztof Jackiewicz Date: Fri, 6 Jun 2025 09:44:04 +0000 (+0200) Subject: Remove unused code X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7275aebab8abc0801c4f8d93500853757619e017;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Remove unused code Change-Id: Ib47bd8f50679fbd68051fc9d589694f9f843431a --- diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 08de6728..e4d05472 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -31,7 +31,6 @@ SET(COMMON_TARGET_TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/common/service_manager.cpp ${PROJECT_SOURCE_DIR}/src/common/memory.cpp ${PROJECT_SOURCE_DIR}/src/common/db_sqlite.cpp - ${PROJECT_SOURCE_DIR}/src/common/fs_label_manager.cpp ${PROJECT_SOURCE_DIR}/src/common/passwd_access.cpp ${PROJECT_SOURCE_DIR}/src/common/uds.cpp ${PROJECT_SOURCE_DIR}/src/common/message_pipe.cpp diff --git a/src/common/fs_label_manager.cpp b/src/common/fs_label_manager.cpp deleted file mode 100644 index aee1a14e..00000000 --- a/src/common/fs_label_manager.cpp +++ /dev/null @@ -1,197 +0,0 @@ -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace -{ -#if SMACK_ENABLED -static const char* get_xattr_name(enum smack_label_type type) -{ - switch (type) { - case SMACK_LABEL_ACCESS: - return XATTR_NAME_SMACK; - case SMACK_LABEL_EXEC: - return XATTR_NAME_SMACKEXEC; - case SMACK_LABEL_MMAP: - return XATTR_NAME_SMACKMMAP; - case SMACK_LABEL_TRANSMUTE: - return XATTR_NAME_SMACKTRANSMUTE; - case SMACK_LABEL_IPIN: - return XATTR_NAME_SMACKIPIN; - case SMACK_LABEL_IPOUT: - return XATTR_NAME_SMACKIPOUT; - default: - /* Should not reach this point */ - return nullptr; - } -} -#endif -} - -FsLabelManager::FsLabelManager(const std::string &path, const std::string &label) - : m_path(path) - , m_label(label) -{ - umount(m_path.c_str()); - rmdir(m_path.c_str()); - - std::string data = std::string("mode=0777,uid=0,smackfsdef=") + label; - - int ret = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Unable to make directory"); - - ret = mount("none", path.c_str(), "tmpfs", 0, data.c_str()); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Unable to mount filesystem"); - - if (m_path[m_path.length()-1] != '/') - m_path += '/'; -} - -FsLabelManager::~FsLabelManager() -{ - umount(m_path.c_str()); - rmdir(m_path.c_str()); -} - -void FsLabelManager::createFile(const std::string &relativePath) -{ - std::string path = m_path + relativePath; - - mode_t systemMask = umask(0000); - int fd = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); - umask(systemMask); - RUNNER_ASSERT_ERRNO_MSG(fd > -1, "Unable to create file for tests"); - - close(fd); - - int ret = chown(path.c_str(), OWNER_USER_ID, OWNER_GROUP_ID); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Unable to change file owner"); -} - -void FsLabelManager::createLink(const std::string &relativeLinkPath, const std::string &relativeRealPath) -{ - std::string linkPath = m_path + relativeLinkPath; - std::string realPath = m_path + relativeRealPath; - - int ret = unlink(linkPath.c_str()); - RUNNER_ASSERT_ERRNO_MSG(ret == 0 || errno == ENOENT, "Unable to unlink file"); - - ret = symlink(realPath.c_str(), linkPath.c_str()); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Unable to create symlink"); - - ret = lchown(linkPath.c_str(), OWNER_USER_ID, OWNER_GROUP_ID); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "Unable to change file owner"); -} - -void FsLabelManager::testSmackSetLabel(const std::string &relativePath, - const char *label, - enum smack_label_type labelType) -{ -#if SMACK_ENABLED - std::string path = m_path + relativePath; - - int ret = smack_setlabel(path.c_str(), label, labelType); - RUNNER_ASSERT_MSG(ret == 0, "Error in normal setting label " << label); - - checkLabel(path, label, labelType); -#else - (void)relativePath; - (void)label; - (void)labelType; -#endif -} - -void FsLabelManager::testSmackGetLabel(const std::string &relativePath, - const char *label, - enum smack_label_type labelType) -{ -#if SMACK_ENABLED - std::string path = m_path + relativePath; - - char *tmpLabel; - int ret = smack_getlabel(path.c_str(), &tmpLabel, labelType); - RUNNER_ASSERT_MSG(ret == 0, "Error in normal getting label"); - SmackLabelPtr labelPtr(tmpLabel); - - if (label == nullptr && !m_label.compare(tmpLabel)) - return; - RUNNER_ASSERT_MSG(label != nullptr, "Path should be related with file system default label. " - << tmpLabel << " != " << m_label); - - ret = strcmp(tmpLabel, label); - RUNNER_ASSERT_MSG(ret == 0, "Wrong label. " << tmpLabel << " != " << label); - - checkLabel(path, tmpLabel, labelType); -#else - (void)relativePath; - (void)label; - (void)labelType; -#endif -} - -void FsLabelManager::testSmackClearLabels(const std::string &relativePath) -{ - testSmackSetLabel(relativePath, nullptr, SMACK_LABEL_ACCESS); - testSmackGetLabel(relativePath, nullptr, SMACK_LABEL_ACCESS); - testSmackSetLabel(relativePath, nullptr, SMACK_LABEL_EXEC); - testSmackGetLabel(relativePath, nullptr, SMACK_LABEL_EXEC); -} - -void FsLabelManager::checkLabel(const std::string &path, - const char *label, - enum smack_label_type labelType) -{ -#if SMACK_ENABLED - char buf[SMACK_LABEL_LEN+2] = { 0, }; - int ret = getxattr(path.c_str(), get_xattr_name(labelType), buf, SMACK_LABEL_LEN+1); - RUNNER_ASSERT_ERRNO_MSG(ret > 0, "Error in getting xattr"); - - const char *tmpLabel; - if (label == nullptr) - tmpLabel = m_label.c_str(); - else - tmpLabel = label; - - ret = strncmp(tmpLabel, buf, SMACK_LABEL_LEN+1); - RUNNER_ASSERT_MSG(ret == 0, "Wrong label. " << tmpLabel << " != " << buf); -#else - (void)path; - (void)label; - (void)labelType; -#endif -} - -void FsLabelManager::checkLinkLabel(const std::string &path, - const char *label, - enum smack_label_type labelType) -{ -#if SMACK_ENABLED - char buf[SMACK_LABEL_LEN+2] = { 0, }; - int ret = lgetxattr(path.c_str(), get_xattr_name(labelType), buf, SMACK_LABEL_LEN+1); - RUNNER_ASSERT_ERRNO_MSG(ret > 0, "Error in getting xattr"); - - const char *tmpLabel; - if (label == nullptr) - tmpLabel = m_label.c_str(); - else - tmpLabel = label; - - ret = strncmp(tmpLabel, buf, SMACK_LABEL_LEN+1); - RUNNER_ASSERT_MSG(ret == 0, "Wrong label. " << tmpLabel << " != " << buf); -#else - (void)path; - (void)label; - (void)labelType; -#endif -} diff --git a/src/common/fs_label_manager.h b/src/common/fs_label_manager.h deleted file mode 100644 index b97a71fa..00000000 --- a/src/common/fs_label_manager.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 fs_label_manager.h - * @author Marcin Niesluchowski (m.niesluchow@samsung.com) - * @version 1.0 - * @brief Class for environment operations on file system. - */ -#ifndef _FS_LABEL_MANAGER_H_ -#define _FS_LABEL_MANAGER_H_ - -#include -#include - -class FsLabelManager -{ -public: - FsLabelManager() = delete; - FsLabelManager(const std::string &path, const std::string &label); - FsLabelManager(const FsLabelManager &second) = delete; - FsLabelManager& operator=(FsLabelManager &second) = delete; - - virtual ~FsLabelManager(); - - void createFile(const std::string &relativePath); - void createLink(const std::string &relativeLinkPath, const std::string &relativeRealPath); - - void testSmackSetLabel(const std::string &relativePath, - const char *label, - enum smack_label_type labelType); - - void testSmackGetLabel(const std::string &relativePath, - const char *label, - enum smack_label_type labelType); - - void testSmackClearLabels(const std::string &relativePath); - -private: - void checkLabel(const std::string &path, - const char *label, - enum smack_label_type labelType); - void checkLinkLabel(const std::string &path, - const char *label, - enum smack_label_type labelType); - - std::string m_path; - std::string m_label; -}; - -#endif // _FS_LABEL_MANAGER_H_