#define KERNEL_FORMAT "%-23s %-23s %5s"
#define READ_BUF_SIZE 512
#define SMACKFS_MNT "/smack"
+#define SELF_LABEL_FILE "/proc/self/attr/current"
struct smack_rule {
char subject[LABEL_LEN + 1];
return label;
}
+char *smack_get_self_label()
+{
+ char *label;
+ int fd;
+ int ret;
+
+ label = calloc(LABEL_LEN + 1, 1);
+ if (label == NULL)
+ return NULL;
+
+ fd = open(SELF_LABEL_FILE, O_RDONLY);
+ if (fd < 0) {
+ free(label);
+ return NULL;
+ }
+
+ ret = read(fd, label, LABEL_LEN);
+ close(fd);
+ if (ret < 0) {
+ free(label);
+ return NULL;
+ }
+
+ return label;
+}
+
inline int access_type_to_int(const char *access_type)
{
int i, count;
*/
extern char *smack_get_peer_label(int fd);
+/*!
+ * Allow a process to determine its own smack label
+ *
+ * @return The label of the process, NULL on error.
+ */
+extern char *smack_get_self_label();
+
#ifdef __cplusplus
}
#endif
AM_CPPFLAGS = -I../src
-noinst_PROGRAMS = smackctl smackaccess
+noinst_PROGRAMS = smackctl smackaccess smackselflabel
smackctl_SOURCES = smackctl.c
smackctl_LDADD = -L$(top_builddir)/src/.libs -lsmack
smackaccess_SOURCES = smackaccess.c
smackaccess_LDADD = -L$(top_builddir)/src/.libs -lsmack
+
+smackselflabel_SOURCES = smackselflabel.c
+smackselflabel_LDADD = -L$(top_builddir)/src/.libs -lsmack
--- /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>
+ */
+
+#include <smack.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ char *own_label;
+
+ own_label = smack_get_self_label();
+ if (own_label)
+ printf("Own_label: '%s'\n", own_label);
+ else
+ printf("Error reading label\n");
+
+ free(own_label);
+
+ return EXIT_SUCCESS;
+}