*/
std::string getSmackLabelFromPath(const std::string &path);
+/**
+ * Returns smack label for given file descriptor
+ *
+ * @param[in] fd file descriptor
+ * @return resulting Smack label
+ */
+std::string getSmackLabelFromFd(int fd);
+
/**
* Returns smack label for current process
*
*/
std::string getSmackLabelFromSelf(void);
+/**
+ * Set up smack label for given file descriptor
+ *
+ * @param[in] fd file descriptor
+ * @param[in] label new smack label for file
+ */
+void setSmackLabelForFd(int fd, const std::string &label);
+
} // namespace SmackLabels
} // namespace SecurityManager
std::ofstream fstream;
openAndLockNameFile(nameFile, fstream);
- if (smack_set_label_for_file(getFd(fstream), XATTR_NAME_SMACK, "_") != 0)
- ThrowMsg(PermissibleSetException::FileInitError,
- "Unable to set Smack label for user permissible file");
+ SmackLabels::setSmackLabelForFd(getFd(fstream), "_");
markPermissibleFileValid(getFd(fstream), nameFile, true);
}
#include "privilege_db.h"
#include "cynara.h"
#include "permissible-set.h"
+#include "smack-exceptions.h"
#include "smack-rules.h"
#include "smack-labels.h"
#include "security-manager.h"
} catch (const PermissibleSet::PermissibleSetException::FileInitError &e) {
LogError("Error while adding user: " << e.DumpToString());
return SECURITY_MANAGER_ERROR_SETTING_FILE_LABEL_FAILED;
+ } catch (const SmackException::FileError &e) {
+ LogError("Error while adding user: " << e.DumpToString());
+ return SECURITY_MANAGER_ERROR_SETTING_FILE_LABEL_FAILED;
} catch (const std::exception &e) {
LogError("Memory allocation error while adding user: " << e.what());
return SECURITY_MANAGER_ERROR_SERVER_ERROR;
static inline void pathSetSmack(const char *path, const std::string &label,
const char *xattr_name)
{
- if (lsetxattr(path, xattr_name, label.c_str(), label.length(), 0)) {
- LogError("lsetxattr failed.");
- ThrowMsg(SmackException::FileError, "lsetxattr failed.");
+ if (smack_set_label_for_path(path, xattr_name, 0, label.c_str())) {
+ LogError("smack_set_label_for_path failed. Path: " << path << " Label:" << label);
+ ThrowMsg(SmackException::FileError,
+ "smack_set_label_for_path failed failed. Path: " << path << " Label: " << label);
}
}
return getSmackLabel(&smack_new_label_from_path, path.c_str(), XATTR_NAME_SMACK, true);
}
+std::string getSmackLabelFromFd(int fd)
+{
+ return getSmackLabel(&smack_new_label_from_file, fd, XATTR_NAME_SMACK);
+}
+
std::string getSmackLabelFromSelf(void)
{
return getSmackLabel(&smack_new_label_from_self);
return "User::Author::" + std::to_string(authorId);
}
+void setSmackLabelForFd(int fd, const std::string &label)
+{
+ if (smack_set_label_for_file(fd, XATTR_NAME_SMACK, label.c_str())) {
+ LogError("smack_set_label_for_file failed.");
+ ThrowMsg(SmackException::FileError, "smack_set_label_for_file failed.");
+ }
+}
+
} // namespace SmackLabels
} // namespace SecurityManager