From af4614232a96c7376522ebaecf53c158e1088159 Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Wed, 24 Nov 2010 09:57:07 -0800 Subject: [PATCH] Known labels support. --- src/Makefile.am | 2 +- src/smack_internal.c | 18 ++++++++++++++++++ src/smack_internal.h | 39 +++++++++++++++++++++++++++++++++++++++ src/smack_labels.c | 22 +++++++++++++++++++--- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/smack_internal.c create mode 100644 src/smack_internal.h diff --git a/src/Makefile.am b/src/Makefile.am index 832f583..a7ccc92 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,4 +2,4 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libsmack.la libsmack_la_LDFLAGS = -version-info 1:0 -libsmack_la_SOURCES = smack_rules.c smack_xattr.c smack_labels.c +libsmack_la_SOURCES = smack_internal.c smack_rules.c smack_xattr.c smack_labels.c diff --git a/src/smack_internal.c b/src/smack_internal.c new file mode 100644 index 0000000..2296352 --- /dev/null +++ b/src/smack_internal.c @@ -0,0 +1,18 @@ +#include +#include "smack_internal.h" + +#define KNOWN_LABELS_COUNT 4 + +static const char *known_labels[] = { "_", "^", "*", "@" }; + +const char *get_known_label(const char *label) +{ + int i; + + for (i = 0; i < KNOWN_LABELS_COUNT; i++) + if (strcmp(label, known_labels[i]) == 0) + return known_labels[i]; + + return NULL; +} + diff --git a/src/smack_internal.h b/src/smack_internal.h new file mode 100644 index 0000000..1367364 --- /dev/null +++ b/src/smack_internal.h @@ -0,0 +1,39 @@ +/* + * This file is part of libsmack + * + * Copyright (C) 2010 Nokia 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: + * Jarkko Sakkinen + */ + +#ifndef SMACK_INTERNAL_H +#define SMACK_INTERNAL_H + +#define SMACK_PROC_PATH "/proc/%d/attr/current" + +#define SMACK64_LEN 23 + +#define ACC_R 1 +#define ACC_W 2 +#define ACC_X 4 +#define ACC_A 16 +#define ACC_LEN 4 + +const char *get_known_label(const char *label); + +#endif // SMACK_INTERNAL_H diff --git a/src/smack_labels.c b/src/smack_labels.c index 0c6bfdc..55048d0 100644 --- a/src/smack_labels.c +++ b/src/smack_labels.c @@ -119,8 +119,9 @@ int smack_label_set_add(SmackLabelSet handle, const char *long_name) char sl[SMACK64_LEN + 1]; int pos, len ,ret; - if (long_name == NULL || strlen(long_name) == 0) - return -EPERM; + if (strlen(long_name) == 0 || + get_known_label(long_name) != NULL) + return -EINVAL; len = strlen(long_name); pos = (len > SMACK64_LEN) ? len - SMACK64_LEN : 0; @@ -130,7 +131,7 @@ int smack_label_set_add(SmackLabelSet handle, const char *long_name) ret = add_label(&handle->label_by_long_name, &handle->label_by_short_name, long_name, sl); - return ret == 0 ? 0 : -1; + return ret; } int smack_label_set_remove(SmackLabelSet handle, const char *long_name) @@ -154,6 +155,11 @@ int smack_label_set_remove(SmackLabelSet handle, const char *long_name) const char *smack_label_set_get(SmackLabelSet handle, const char *long_name) { struct smack_label *l; + const char *res; + + res = get_known_label(long_name); + if (res != NULL) + return res; HASH_FIND(long_name_hh, handle->label_by_long_name, long_name, strlen(long_name), l); @@ -167,6 +173,11 @@ const char *smack_label_set_to_short_name(SmackLabelSet handle, const char *long_name) { struct smack_label *l; + const char *res; + + res = get_known_label(long_name); + if (res != NULL) + return res; HASH_FIND(long_name_hh, handle->label_by_long_name, long_name, strlen(long_name), l); @@ -180,6 +191,11 @@ const char *smack_label_set_to_long_name(SmackLabelSet handle, const char *short_name) { struct smack_label *l; + const char *res; + + res = get_known_label(short_name); + if (res != NULL) + return res; HASH_FIND(short_name_hh, handle->label_by_short_name, short_name, strlen(short_name), l); -- 2.7.4