libsmack: revert smack_new_label_from_self()
authorJarkko Sakkinen <jarkko.sakkinen@iki.fi>
Tue, 13 Dec 2011 09:52:08 +0000 (11:52 +0200)
committerJarkko Sakkinen <jarkko.sakkinen@iki.fi>
Tue, 13 Dec 2011 09:54:24 +0000 (11:54 +0200)
Reverted smack_new_label_from_self() back. Removed
smack_set_self_label as it is not needed.

libsmack/libsmack.c
libsmack/sys/smack.h
utils/Makefile.am
utils/smackself.c [deleted file]

index fafc8d7..1b96524 100644 (file)
@@ -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;
 }
 
index 2944ad0..797cccd 100644 (file)
@@ -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
index a54942e..17230e5 100644 (file)
@@ -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 (file)
index 1d98d8b..0000000
+++ /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 <brian.mcgillion@intel.com>
- * Jarkko Sakkinen <jarkko.sakkinen@intel.com>
- */
-
-#include <sys/smack.h>
-#include <stdio.h>
-#include <stdlib.h>
-#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;
-}