checkLabel(path, label, labelType);
}
-void FsLabelManager::testSmackLSetLabel(const std::string &relativePath,
- const char *label,
- enum smack_label_type labelType)
-{
- std::string path = m_path + relativePath;
-
- int ret = smack_lsetlabel(path.c_str(), label, labelType);
- RUNNER_ASSERT_MSG(ret == 0, "Error in link setting label " << label);
-
- checkLinkLabel(path, label, labelType);
-}
-
-void FsLabelManager::testSmackFSetLabel(const std::string &relativePath,
- const char *label,
- enum smack_label_type labelType)
-{
- std::string path = m_path + relativePath;
-
- int fd = open(path.c_str(), O_WRONLY);
- RUNNER_ASSERT_ERRNO_MSG(fd > -1, "Unable to open file");
-
- int ret = smack_fsetlabel(fd, label, labelType);
- close(fd);
- RUNNER_ASSERT_MSG(ret == 0, "Error in fd setting " << label);
-
- checkLabel(path, label, labelType);
-}
-
void FsLabelManager::testSmackGetLabel(const std::string &relativePath,
const char *label,
enum smack_label_type labelType)
checkLabel(path, tmpLabel, labelType);
}
-void FsLabelManager::testSmackLGetLabel(const std::string &relativePath,
- const char *label,
- enum smack_label_type labelType)
-{
- std::string path = m_path + relativePath;
-
- char *tmpLabel;
- int ret = smack_lgetlabel(path.c_str(), &tmpLabel, labelType);
- RUNNER_ASSERT_MSG(ret == 0, "Error in link 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);
-
- checkLinkLabel(path, tmpLabel, labelType);
-}
-
-void FsLabelManager::testSmackFGetLabel(const std::string &relativePath,
- const char *label,
- enum smack_label_type labelType)
-{
- std::string path = m_path + relativePath;
- int fd = open(path.c_str(), O_WRONLY);
- RUNNER_ASSERT_ERRNO_MSG(fd > -1, "Unable to open file");
-
- char *tmpLabel;
- int ret = smack_fgetlabel(fd, &tmpLabel, labelType);
- close(fd);
- RUNNER_ASSERT_MSG(ret == 0, "Error in fd getting label");
- SmackLabelPtr labelPtr(tmpLabel);
-
- if (label == nullptr && !m_label.compare(tmpLabel))
- return;
- RUNNER_ASSERT_MSG(label != nullptr, "Fd 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);
-}
-
void FsLabelManager::testSmackClearLabels(const std::string &relativePath)
{
testSmackSetLabel(relativePath, nullptr, SMACK_LABEL_ACCESS);
void testSmackSetLabel(const std::string &relativePath,
const char *label,
enum smack_label_type labelType);
- void testSmackLSetLabel(const std::string &relativePath,
- const char *label,
- enum smack_label_type labelType);
- void testSmackFSetLabel(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 testSmackLGetLabel(const std::string &relativePath,
- const char *label,
- enum smack_label_type labelType);
- void testSmackFGetLabel(const std::string &relativePath,
- const char *label,
- enum smack_label_type labelType);
void testSmackClearLabels(const std::string &relativePath);
nftw_expected_label.c_str(), nftw_expected_transmute, nftw_expected_exec);
}
-int nftw_check_labels_non_app_dir(const char *fpath, const struct stat* /*sb*/,
- int /*typeflag*/, struct FTW* /*ftwbuf*/)
-{
- int result;
- CStringPtr labelPtr;
- char* label = nullptr;
-
- /* ACCESS */
- result = smack_lgetlabel(fpath, &label, SMACK_LABEL_ACCESS);
- labelPtr.reset(label);
- RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
- result = strcmp("canary_label", labelPtr.get());
- RUNNER_ASSERT_MSG(result == 0, "ACCESS label on " << fpath << " is overwritten");
-
- /* EXEC */
- result = smack_lgetlabel(fpath, &label, SMACK_LABEL_EXEC);
- labelPtr.reset(label);
- RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
- result = strcmp("canary_label", labelPtr.get());
- RUNNER_ASSERT_MSG(result == 0, "EXEC label on " << fpath << " is overwritten");
-
- /* TRANSMUTE */
- result = smack_lgetlabel(fpath, &label, SMACK_LABEL_TRANSMUTE);
- labelPtr.reset(label);
- RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
- RUNNER_ASSERT_MSG(labelPtr.get() == nullptr, "TRANSMUTE label on " << fpath << " is set");
-
- return 0;
-}
-
int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
int /*typeflag*/, struct FTW* /*ftwbuf*/)
{