From f409c172e8b26f3846449a363414874960f30d1d Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Mon, 27 May 2013 09:54:19 +0300 Subject: [PATCH] Added follow parameter to smack_new_label_from_path() Added follow parameter to smack_new_label_from_path() so that it is useful for coreutils commands. Signed-off-by: Jarkko Sakkinen --- libsmack/libsmack.c | 11 ++++++++--- libsmack/sys/smack.h | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libsmack/libsmack.c b/libsmack/libsmack.c index 0e9da03..7e86a5a 100644 --- a/libsmack/libsmack.c +++ b/libsmack/libsmack.c @@ -37,6 +37,7 @@ #include #include #include +#include #define ACC_LEN 5 #define LOAD_LEN (2 * (SMACK_LABEL_LEN + 1) + 2 * ACC_LEN + 1) @@ -540,13 +541,15 @@ int smack_new_label_from_socket(int fd, char **label) return 0; } -int smack_new_label_from_path(const char *path, const char *xattr, +int smack_new_label_from_path(const char *path, const char *xattr, int follow, const char **label) { char *result; ssize_t ret = 0; - ret = getxattr(path, xattr, NULL, 0); + ret = follow ? + lgetxattr(path, xattr, NULL, 0) : + getxattr(path, xattr, NULL, 0); if (ret < 0 && errno != ERANGE) return -1; @@ -554,7 +557,9 @@ int smack_new_label_from_path(const char *path, const char *xattr, if (result == NULL) return -1; - ret = getxattr(path, xattr, result, ret); + ret = follow ? + lgetxattr(path, xattr, result, ret) : + getxattr(path, xattr, result, ret); if (ret < 0) { free(result); return -1; diff --git a/libsmack/sys/smack.h b/libsmack/sys/smack.h index 73392f7..c736a53 100644 --- a/libsmack/sys/smack.h +++ b/libsmack/sys/smack.h @@ -200,15 +200,18 @@ int smack_new_label_from_self(char **label); int smack_new_label_from_socket(int fd, char **label); /*! - * Get the label that is contained in an extended attribute. + * Get the SMACK label that is contained in an extended attribute. * Caller is responsible of freeing the returned label. * * @param path path of the file - * @param xattr extended attribute containing the label + * @param xattr extended attribute containing the SMACK label + * @param follow whether or not to follow symbolic link * @param label returned label * @return 0 on success and negative value on failure. */ -int smack_new_label_from_path(const char *path, const char *xattr, +int smack_new_label_from_path(const char *path, + const char *xattr, + int follow, const char **label); /*! -- 2.7.4