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;
}
/*!
* 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
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
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
+++ /dev/null
-/*
- * 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;
-}