[SECIOTSW-454] Add skeleton codes for command/data path in sysfs 81/124081/6
authorSungbae Yoo <sungbae.yoo@samsung.com>
Tue, 11 Apr 2017 05:57:39 +0000 (14:57 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Wed, 12 Apr 2017 06:18:15 +0000 (15:18 +0900)
Change-Id: I3a08c8c830f1378734ae638ea5785e48267bc5e5
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
audittrail/Makefile
audittrail/dir.c [new file with mode: 0644]
audittrail/dir.h [new file with mode: 0644]
audittrail/main.c

index e4abc093aca6d8fa92f46346eafb14eaa4b0f9bb..956d7632929b05180078f03ab91f4e49a0d1af60 100644 (file)
@@ -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 (file)
index 0000000..9f7455a
--- /dev/null
@@ -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 <linux/fs.h>
+#include <linux/security.h>
+
+#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 (file)
index 0000000..b492179
--- /dev/null
@@ -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__
index 047c1656e0fa9f3ad9b74d03a15886f82c1d562c..2eb82e3d3e13ae600dd906268a96b8719005e276 100644 (file)
 #include <linux/module.h>
 
 #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");
 }