return ret;
}
+ssize_t smack_new_label_from_file(int fd, const char *xattr,
+ char **label)
+{
+ char buf[SMACK_LABEL_LEN + 1];
+ char *result;
+ ssize_t ret = 0;
+
+ ret = fgetxattr(fd, xattr, buf, SMACK_LABEL_LEN + 1);
+ if (ret < 0)
+ return -1;
+ buf[ret] = '\0';
+
+ result = calloc(ret + 1, 1);
+ if (result == NULL)
+ return -1;
+
+ ret = get_label(result, buf, NULL);
+ if (ret < 0) {
+ free(result);
+ return -1;
+ }
+
+ *label = result;
+ return ret;
+}
+
int smack_set_label_for_path(const char *path,
const char *xattr,
int follow,
return ret;
}
+int smack_set_label_for_file(int fd,
+ const char *xattr,
+ const char *label)
+{
+ int len;
+ int ret;
+
+ len = (int)smack_label_length(label);
+ if (len < 0)
+ return -2;
+
+ ret = fsetxattr(fd, xattr, label, len, 0);
+ return ret;
+}
+
int smack_remove_label_for_path(const char *path,
const char *xattr,
int follow)
return follow ? removexattr(path, xattr) : lremovexattr(path, xattr);
}
+int smack_remove_label_for_file(int fd, const char *xattr)
+{
+ return fremovexattr(fd, xattr);
+}
+
int smack_set_label_for_self(const char *label)
{
int len;
smack_label_length;
smack_set_label_for_path;
smack_remove_label_for_path;
- smack_load_policy;
+ smack_load_policy;
+ smack_new_label_from_file;
+ smack_set_label_for_file;
+ smack_remove_label_for_file;
local:
*;
} LIBSMACK_1.0;
char **label);
/*!
+ * Get the SMACK label that is contained in an extended attribute.
+ * Caller is responsible of freeing the returned label.
+ *
+ * @param fd opened file descriptor of the file
+ * @param xattr the extended attribute containing the SMACK label
+ * @param label output variable for the returned label
+ * @return Returns length of the label on success and negative value
+ * on failure.
+ */
+ssize_t smack_new_label_from_file(int fd,
+ const char *xattr,
+ char **label);
+
+/*!
* Set the SMACK label in an extended attribute.
*
* @param path path of the file
const char *label);
/*!
+ * Set the SMACK label in an extended attribute.
+ *
+ * @param fd opened file descriptor of the file
+ * @param xattr the extended attribute containing the SMACK label
+ * @param label output variable for the returned label
+ * @return Returns length of the label on success and negative value
+ * on failure.
+ */
+int smack_set_label_for_file(int fd,
+ const char *xattr,
+ const char *label);
+
+/*!
* Remove the SMACK label in an extended attribute.
*
* @param path path of the file
int follow);
/*!
+ * Remove the SMACK label in an extended attribute.
+ *
+ * @param fd opened file descriptor of the file
+ * @param xattr the extended attribute containing the SMACK label
+ * @return Returns 0 on success and negative on failure.
+ */
+int smack_remove_label_for_file(int fd, const char *xattr);
+
+/*!
* Set the label associated with the callers process. The caller must have
* CAP_MAC_ADMIN POSIX capability in order to do this.
*