From 2384ebfff4f0b7dc6c2cf3fc4b886e67a1769fc2 Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Tue, 13 Dec 2011 11:52:08 +0200 Subject: [PATCH] libsmack: revert smack_new_label_from_self() Reverted smack_new_label_from_self() back. Removed smack_set_self_label as it is not needed. --- libsmack/libsmack.c | 33 +++++++++++++-------------------- libsmack/sys/smack.h | 15 ++++----------- utils/Makefile.am | 5 +---- utils/smackself.c | 45 --------------------------------------------- 4 files changed, 18 insertions(+), 80 deletions(-) delete mode 100644 utils/smackself.c diff --git a/libsmack/libsmack.c b/libsmack/libsmack.c index fafc8d7..1b96524 100644 --- a/libsmack/libsmack.c +++ b/libsmack/libsmack.c @@ -243,37 +243,30 @@ int smack_have_access(const char *subject, const char *object, return buf[0] == '1'; } -ssize_t smack_get_self_label(char *buf, size_t count) +int smack_new_label_from_self(char **label) { + char *result; int fd; int ret; - fd = open(SELF_LABEL_FILE, O_RDONLY); - if (fd < 0) - return -1; - - ret = read(fd, buf, count); - close(fd); - if (ret < 0) + result = calloc(LABEL_LEN + 1, 1); + if (result == NULL) return -1; - return count; -} - -int smack_set_self_label(char *label) -{ - int fd; - - fd = open(SELF_LABEL_FILE, O_WRONLY); - if (fd < 0) + fd = open(SELF_LABEL_FILE, O_RDONLY); + if (fd < 0) { + free(result); return -1; + } - if (write(fd, label, strlen(label)) < 0) { - close(fd); + ret = read(fd, result, LABEL_LEN); + close(fd); + if (ret < 0) { + free(result); return -1; } - close(fd); + *label = result; return 0; } diff --git a/libsmack/sys/smack.h b/libsmack/sys/smack.h index 2944ad0..797cccd 100644 --- a/libsmack/sys/smack.h +++ b/libsmack/sys/smack.h @@ -114,19 +114,12 @@ int smack_have_access(const char *subject, const char *object, /*! * Get the label that is associated with the callers process. + * Caller is responsible of freeing the returned label. * - * @param buf character buffer where label is read - * @param count length of the buffer - * @return label length on success and negative value on failure. + * @param label returned label + * @return 0 on success and negative value on failure. */ -ssize_t smack_get_self_label(char *buf, size_t count); - -/*! - * Set the label that is associated with the callers process. - * - * @param label new label for callers process - */ -int smack_set_self_label(char *label); +int smack_new_label_from_self(char **label); /*! * Get the label that is associated with a peer on the other end of an diff --git a/utils/Makefile.am b/utils/Makefile.am index a54942e..17230e5 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1,5 +1,5 @@ instdir = ${bindir} -bin_PROGRAMS = smackctl smackaccess smackself smackload smackcipso smackd chsmack +bin_PROGRAMS = smackctl smackaccess smackload smackcipso smackd chsmack AM_CPPFLAGS = \ -I$(top_srcdir)/libsmack @@ -9,9 +9,6 @@ smackctl_LDADD = ../libsmack/libsmack.la smackaccess_SOURCES = smackaccess.c smackaccess_LDADD = ../libsmack/libsmack.la -smackself_SOURCES = smackself.c -smackself_LDADD = ../libsmack/libsmack.la - smackload_SOURCES = smackload.c common.c smackload_LDADD = ../libsmack/libsmack.la diff --git a/utils/smackself.c b/utils/smackself.c deleted file mode 100644 index 1d98d8b..0000000 --- a/utils/smackself.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of libsmack - * - * Copyright (C) 2011 Intel Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - * Authors: - * Brian McGillion - * Jarkko Sakkinen - */ - -#include -#include -#include -#include "common.h" - -int main(int argc, char **argv) -{ - char label[LABEL_LEN + 1]; - int len; - - len = smack_get_self_label(label, LABEL_LEN); - if (len < 0) { - perror("smack_get_self_label"); - return EXIT_FAILURE; - } - - label[len] = '\0'; - - printf("%s", label); - return EXIT_SUCCESS; -} -- 2.7.4