Change SMACK label of the log file 90/237390/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 30 Jun 2020 03:53:53 +0000 (12:53 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 30 Jun 2020 03:57:13 +0000 (12:57 +0900)
Change-Id: Ib07f8c8b69065a817626557c2f1dc18698ff9941
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
packaging/launchpad.spec
src/common/inc/launchpad_logger.h [deleted file]
src/common/src/launchpad_logger.c [deleted file]
src/launchpad/CMakeLists.txt
src/launchpad/inc/launchpad_logger.h [new file with mode: 0644]
src/launchpad/src/launchpad_logger.c [new file with mode: 0644]

index 0c0cb555ae283c3661242a9f200275796d87a7bb..198bc4690c04fdc3605a9cfac8dfd3cbb049ea5f 100644 (file)
@@ -30,6 +30,7 @@ BuildRequires:  pkgconfig(tanchor)
 BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(iniparser)
 BuildRequires:  pkgconfig(libxml-2.0)
+BuildRequires:  pkgconfig(libsmack)
 
 Requires(post): /sbin/ldconfig
 Requires(post): /usr/bin/systemctl
diff --git a/src/common/inc/launchpad_logger.h b/src/common/inc/launchpad_logger.h
deleted file mode 100644 (file)
index a54ebb7..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LAUNCHPAD_LOGGER_H__
-#define __LAUNCHPAD_LOGGER_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define LAUNCHPAD_LOG_MAX_STRING_SIZE 128
-
-typedef struct logger_s *logger_h;
-
-int _logger_create(const char *path, logger_h *handle);
-
-int _logger_destroy(logger_h handle);
-
-int _logger_print(logger_h handle, const char *tag, const char *format, ...);
-
-int _logger_get_fd(logger_h handle, int *fd);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __LAUNCHPAD_LOGGER_H__ */
diff --git a/src/common/src/launchpad_logger.c b/src/common/src/launchpad_logger.c
deleted file mode 100644 (file)
index a4e6b7f..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <errno.h>
-#include <fcntl.h>
-#include <grp.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "launchpad_logger.h"
-#include "log_private.h"
-
-#define LAUNCHPAD_LOG_APPFW_PATH "/var/log/appfw"
-#define LAUNCHPAD_LOG_PATH "/var/log/appfw/launchpad"
-#define LAUNCHPAD_LOG_MAX_SIZE 2500
-#define LAUNCHPAD_LOG_MAX_BUFFER_SIZE 256
-
-struct logger_s {
-       int fd;
-       int index;
-};
-
-static int __create_directory(const char *path)
-{
-       mode_t mode;
-       int ret;
-
-       ret = access(path, F_OK);
-       if (ret == 0)
-               return 0;
-
-       mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
-       ret = mkdir(path, mode);
-       if (ret < 0) {
-               ret = -errno;
-               _E("Failed to create directory(%s). errno(%d)", path, errno);
-               return ret;
-       }
-
-       return 0;
-}
-
-static int __create_launchpad_directories(void)
-{
-       int ret;
-
-       ret = __create_directory(LAUNCHPAD_LOG_APPFW_PATH);
-       if (ret < 0)
-               return ret;
-
-       ret = __create_directory(LAUNCHPAD_LOG_PATH);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int _logger_create(const char *path, logger_h *handle)
-{
-       struct logger_s *logger;
-       off_t offset;
-       int ret;
-
-       if (!path || !handle) {
-               _E("Invalid parameter");
-               return -EINVAL;
-       }
-
-       ret = __create_launchpad_directories();
-       if (ret < 0)
-               return ret;
-
-       logger = calloc(1, sizeof(struct logger_s));
-       if (!logger) {
-               _E("Out of memory");
-               return -ENOMEM;
-       }
-
-       logger->fd = open(path, O_CREAT | O_WRONLY, 0640);
-       if (logger->fd < 0) {
-               ret = -errno;
-               _E("Failed to open path(%s), errno(%d)", path, errno);
-               _logger_destroy(logger);
-               return ret;
-       }
-
-       offset = lseek(logger->fd, 0, SEEK_END);
-       if (offset != 0) {
-               logger->index = (int)(offset / LAUNCHPAD_LOG_MAX_STRING_SIZE);
-               if (logger->index >= LAUNCHPAD_LOG_MAX_SIZE) {
-                       logger->index = 0;
-                       lseek(logger->fd, 0, SEEK_SET);
-               }
-       }
-
-       *handle = logger;
-
-       return 0;
-}
-
-int _logger_destroy(logger_h handle)
-{
-       if (!handle) {
-               _E("Invalid parameter");
-               return -EINVAL;
-       }
-
-       if (handle->fd > 0)
-               close(handle->fd);
-
-       free(handle);
-
-       return 0;
-}
-
-int _logger_print(logger_h handle, const char *tag, const char *format, ...)
-{
-       char buf[LAUNCHPAD_LOG_MAX_BUFFER_SIZE];
-       char format_buf[128];
-       struct tm tm = { 0, };
-       time_t t;
-       ssize_t ret;
-       va_list ap;
-       off_t offset;
-
-       if (!handle || !tag || !format) {
-               _E("Invalid parameter");
-               return -EINVAL;
-       }
-
-       t = time(NULL);
-       localtime_r(&t, &tm);
-
-       if (handle->index != 0)
-               offset = lseek(handle->fd, 0, SEEK_CUR);
-       else
-               offset = lseek(handle->fd, 0, SEEK_SET);
-
-       if (offset == -1)
-               _E("lseek() is failed. errno(%d)", errno);
-
-       va_start(ap, format);
-       vsnprintf(format_buf, sizeof(format_buf), format, ap);
-       va_end(ap);
-
-       snprintf(buf, sizeof(buf),
-                       "[%6d] %04d-%02d-%02d %02d:%02d:%02d %-16s %-100s\n",
-                       handle->index,
-                       tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
-                       tm.tm_hour, tm.tm_min, tm.tm_sec,
-                       tag, format_buf);
-       ret = write(handle->fd, buf, strlen(buf));
-       if (ret < 0) {
-               ret = -errno;
-               _E("Failed to write log message. errno(%d)", errno);
-               return ret;
-       }
-
-       if (++handle->index >= LAUNCHPAD_LOG_MAX_SIZE)
-               handle->index = 0;
-
-       return ret;
-}
-
-int _logger_get_fd(logger_h handle, int *fd)
-{
-       if (!handle || !fd) {
-               _E("Invalid parameter");
-               return -EINVAL;
-       }
-
-       *fd = handle->fd;
-
-       return 0;
-}
index 39ce5c8e0106a474f58c845568812dafd2ee2215..ad10ae02af822ae7afd643feb3afbee455fcc2b0 100644 (file)
@@ -10,6 +10,7 @@ PKG_CHECK_MODULES(LAUNCHPAD_PROCESS_POOL_PKGS REQUIRED
        gio-2.0
        iniparser
        libcap
+       libsmack
        libsystemd
        libtzplatform-config
        security-manager
diff --git a/src/launchpad/inc/launchpad_logger.h b/src/launchpad/inc/launchpad_logger.h
new file mode 100644 (file)
index 0000000..a54ebb7
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LAUNCHPAD_LOGGER_H__
+#define __LAUNCHPAD_LOGGER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LAUNCHPAD_LOG_MAX_STRING_SIZE 128
+
+typedef struct logger_s *logger_h;
+
+int _logger_create(const char *path, logger_h *handle);
+
+int _logger_destroy(logger_h handle);
+
+int _logger_print(logger_h handle, const char *tag, const char *format, ...);
+
+int _logger_get_fd(logger_h handle, int *fd);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __LAUNCHPAD_LOGGER_H__ */
diff --git a/src/launchpad/src/launchpad_logger.c b/src/launchpad/src/launchpad_logger.c
new file mode 100644 (file)
index 0000000..0a32b7e
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/smack.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "launchpad_logger.h"
+#include "log_private.h"
+
+#define LAUNCHPAD_LOG_APPFW_PATH "/var/log/appfw"
+#define LAUNCHPAD_LOG_PATH "/var/log/appfw/launchpad"
+#define LAUNCHPAD_LOG_MAX_SIZE 2500
+#define LAUNCHPAD_LOG_MAX_BUFFER_SIZE 256
+
+struct logger_s {
+       int fd;
+       int index;
+};
+
+static int __set_smack_label(const char *path, const char *label)
+{
+       int ret;
+
+       ret = smack_setlabel(path, label, SMACK_LABEL_ACCESS);
+       if (ret != 0) {
+               ret = -errno;
+               _E("smack_setlabel() is failed. path(%s), label(%s), errno(%d)",
+                               path, label, errno);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int __create_directory(const char *path)
+{
+       mode_t mode;
+       int ret;
+
+       ret = access(path, F_OK);
+       if (ret == 0)
+               return 0;
+
+       mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP;
+       ret = mkdir(path, mode);
+       if (ret < 0) {
+               ret = -errno;
+               _E("Failed to create directory(%s). errno(%d)", path, errno);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int __create_launchpad_directories(void)
+{
+       int ret;
+
+       ret = __create_directory(LAUNCHPAD_LOG_APPFW_PATH);
+       if (ret < 0)
+               return ret;
+
+       ret = __set_smack_label(LAUNCHPAD_LOG_APPFW_PATH, "_");
+       if (ret < 0)
+               return ret;
+
+       ret = __create_directory(LAUNCHPAD_LOG_PATH);
+       if (ret < 0)
+               return ret;
+
+       ret = __set_smack_label(LAUNCHPAD_LOG_PATH, "User");
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int _logger_create(const char *path, logger_h *handle)
+{
+       struct logger_s *logger;
+       off_t offset;
+       int ret;
+
+       if (!path || !handle) {
+               _E("Invalid parameter");
+               return -EINVAL;
+       }
+
+       ret = __create_launchpad_directories();
+       if (ret < 0)
+               return ret;
+
+       logger = calloc(1, sizeof(struct logger_s));
+       if (!logger) {
+               _E("Out of memory");
+               return -ENOMEM;
+       }
+
+       logger->fd = open(path, O_CREAT | O_WRONLY, 0640);
+       if (logger->fd < 0) {
+               ret = -errno;
+               _E("Failed to open path(%s), errno(%d)", path, errno);
+               _logger_destroy(logger);
+               return ret;
+       }
+
+       ret = __set_smack_label(path, "User");
+       if (ret < 0) {
+               _logger_destroy(logger);
+               return ret;
+       }
+
+       offset = lseek(logger->fd, 0, SEEK_END);
+       if (offset != 0) {
+               logger->index = (int)(offset / LAUNCHPAD_LOG_MAX_STRING_SIZE);
+               if (logger->index >= LAUNCHPAD_LOG_MAX_SIZE) {
+                       logger->index = 0;
+                       lseek(logger->fd, 0, SEEK_SET);
+               }
+       }
+
+       *handle = logger;
+
+       return 0;
+}
+
+int _logger_destroy(logger_h handle)
+{
+       if (!handle) {
+               _E("Invalid parameter");
+               return -EINVAL;
+       }
+
+       if (handle->fd > 0)
+               close(handle->fd);
+
+       free(handle);
+
+       return 0;
+}
+
+int _logger_print(logger_h handle, const char *tag, const char *format, ...)
+{
+       char buf[LAUNCHPAD_LOG_MAX_BUFFER_SIZE];
+       char format_buf[128];
+       struct tm tm = { 0, };
+       time_t t;
+       ssize_t ret;
+       va_list ap;
+       off_t offset;
+
+       if (!handle || !tag || !format) {
+               _E("Invalid parameter");
+               return -EINVAL;
+       }
+
+       t = time(NULL);
+       localtime_r(&t, &tm);
+
+       if (handle->index != 0)
+               offset = lseek(handle->fd, 0, SEEK_CUR);
+       else
+               offset = lseek(handle->fd, 0, SEEK_SET);
+
+       if (offset == -1)
+               _E("lseek() is failed. errno(%d)", errno);
+
+       va_start(ap, format);
+       vsnprintf(format_buf, sizeof(format_buf), format, ap);
+       va_end(ap);
+
+       snprintf(buf, sizeof(buf),
+                       "[%6d] %04d-%02d-%02d %02d:%02d:%02d %-16s %-100s\n",
+                       handle->index,
+                       tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+                       tm.tm_hour, tm.tm_min, tm.tm_sec,
+                       tag, format_buf);
+       ret = write(handle->fd, buf, strlen(buf));
+       if (ret < 0) {
+               ret = -errno;
+               _E("Failed to write log message. errno(%d)", errno);
+               return ret;
+       }
+
+       if (++handle->index >= LAUNCHPAD_LOG_MAX_SIZE)
+               handle->index = 0;
+
+       return ret;
+}
+
+int _logger_get_fd(logger_h handle, int *fd)
+{
+       if (!handle || !fd) {
+               _E("Invalid parameter");
+               return -EINVAL;
+       }
+
+       *fd = handle->fd;
+
+       return 0;
+}