From a86e4f3668d9cea4aa770a68a7c554d80a8672d2 Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Tue, 30 Nov 2010 04:44:12 -0800 Subject: [PATCH] Temporary function smack_create_default_config_files(). --- src/Makefile.am | 2 +- src/smack.h | 10 +++++++++ src/smack_misc.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/smack_misc.c diff --git a/src/Makefile.am b/src/Makefile.am index 8d84b34..8a21bfa 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,6 +2,6 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libsmack.la libsmack_la_LDFLAGS = -version-info 1:0 -libsmack_la_SOURCES = smack_internal.c smack_rules.c smack_xattr.c smack_labels.c +libsmack_la_SOURCES = smack_internal.c smack_rules.c smack_xattr.c smack_labels.c smack_misc.c EXTRA_DIST=smack_internal.h diff --git a/src/smack.h b/src/smack.h index 53d414a..e086d72 100644 --- a/src/smack.h +++ b/src/smack.h @@ -61,6 +61,16 @@ extern "C" { #endif /*! + * Create default config files for Smack. Creates only those files that + * don't yet exist. NOTE: this is temporary function and will be removed + * from API at some point. + * + * @return 0 when files are created succesfully and negative number on + * failure. + */ +extern int smack_create_default_config_files(); + +/*! * Create a new rule set. The returned rule set must be freed with * smack_rule_set_delete(). * diff --git a/src/smack_misc.c b/src/smack_misc.c new file mode 100644 index 0000000..2caaf35 --- /dev/null +++ b/src/smack_misc.c @@ -0,0 +1,65 @@ +/* + * 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 + */ + +#include "smack.h" +#include "smack_internal.h" +#include +#include +#include +#include + +#define SMACK_DIR_PATH "/etc/smack" + +int smack_create_default_config_files() +{ + int ret, fd; + + ret = access(SMACK_DIR_PATH, F_OK); + if (ret != 0 && errno != ENOENT) + return -1; + if (ret != 0) { + mkdir(SMACK_DIR_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + ret = access(SMACK_ACCESSES_PATH, F_OK); + if (ret != 0 && errno != ENOENT) + return -1; + if (ret != 0) { + fd = creat(SMACK_ACCESSES_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if (fd == -1) + return -1; + close(fd); + } + + ret = access(SMACK_LABELS_PATH, F_OK); + if (ret != 0 && errno != ENOENT) + return -1; + if (ret != 0) { + fd = creat(SMACK_LABELS_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if (fd == -1) + return -1; + close(fd); + } + + return 0; +} -- 2.7.4