From: Sungbae Yoo Date: Tue, 11 Apr 2017 05:57:39 +0000 (+0900) Subject: [SECIOTSW-454] Add skeleton codes for command/data path in sysfs X-Git-Tag: submit/tizen/20171212.052346~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=16259fda161b183f7403df041036592568eb85df;p=platform%2Fcore%2Fsecurity%2Faudit-trail.git [SECIOTSW-454] Add skeleton codes for command/data path in sysfs Change-Id: I3a08c8c830f1378734ae638ea5785e48267bc5e5 Signed-off-by: Sungbae Yoo --- diff --git a/audittrail/Makefile b/audittrail/Makefile index e4abc09..956d763 100644 --- a/audittrail/Makefile +++ b/audittrail/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_AUDITTRAIL) = audittrail.o audittrail-objs += main.o +audittrail-objs += dir.o diff --git a/audittrail/dir.c b/audittrail/dir.c new file mode 100644 index 0000000..9f7455a --- /dev/null +++ b/audittrail/dir.c @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include + +#include "log.h" +#include "dir.h" + +static struct dentry *audittrail_dir = NULL; +static struct dentry *audittrail_command = NULL; +static struct dentry *audittrail_buffer = NULL; + +static int audittrail_command_open(struct inode * inode, struct file *file) +{ + if ((file->f_flags & O_ACCMODE) != O_WRONLY) + return -EACCES; + + return 0; +} + +static ssize_t audittrail_command_write(struct file *file, const char __user *buf, + size_t datalen, loff_t *ppos) +{ + return -EINVAL; +} + +static const struct file_operations audittrail_command_ops = { + .open = audittrail_command_open, + .write = audittrail_command_write, +}; + +static int audittrail_buffer_open(struct inode * inode, struct file *file) +{ + return 0; +} + +static ssize_t audittrail_buffer_read(struct file *file, + char __user *buf, + size_t datalen, loff_t *ppos) +{ + return -EINVAL; +} + +static ssize_t audittrail_buffer_write(struct file *file, + const char __user *buf, + size_t datalen, loff_t *ppos) +{ + return -EINVAL; +} + +static int audittrail_buffer_release(struct inode *inode, struct file *file) +{ + return 0; +} + +static const struct file_operations audittrail_buffer_ops = { + .open = audittrail_buffer_open, + .read = audittrail_buffer_read, + .write = audittrail_buffer_write, + .release = audittrail_buffer_release, +}; + + +int audittrail_dir_create(void) +{ + audittrail_dir = securityfs_create_dir("audittrail", NULL); + if (IS_ERR(audittrail_dir)) + goto err; + + audittrail_command = + securityfs_create_file("command", + S_IWUSR | S_IWGRP, audittrail_dir, NULL, + &audittrail_command_ops); + if (IS_ERR(audittrail_command)) + goto err; + + audittrail_buffer = + securityfs_create_file("buffer", + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, + audittrail_dir, NULL, + &audittrail_buffer_ops); + if (IS_ERR(audittrail_buffer)) + goto err; + + return 0; + +err: + audittrail_dir_destroy(); + return -1; +} + +void audittrail_dir_destroy(void) +{ + securityfs_remove(audittrail_buffer); + securityfs_remove(audittrail_command); + securityfs_remove(audittrail_dir); +} diff --git a/audittrail/dir.h b/audittrail/dir.h new file mode 100644 index 0000000..b492179 --- /dev/null +++ b/audittrail/dir.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ +#ifndef __AUDITTRAIL_DIR_H__ +#define __AUDITTRAIL_DIR_H__ + +int audittrail_dir_create(void); +void audittrail_dir_destroy(void); + +#endif //! __AUDITTRAIL_DIR_H__ diff --git a/audittrail/main.c b/audittrail/main.c index 047c165..2eb82e3 100644 --- a/audittrail/main.c +++ b/audittrail/main.c @@ -19,16 +19,26 @@ #include #include "log.h" +#include "dir.h" int audittrail_init(void) { AUDITTRAIL_INFO("loaded"); + if (audittrail_dir_create() != 0) { + AUDITTRAIL_ERROR("failed to create auditfs"); + return -1; + } + + AUDITTRAIL_INFO("auditfs ready"); + return 0; } void audittrail_exit(void) { + audittrail_dir_destroy(); + AUDITTRAIL_INFO("unloaded"); }