move user-check.cpp, privilege-check.cpp to service directory 60/318360/2
authorDongsun Lee <ds73.lee@samsung.com>
Wed, 15 Jan 2025 07:34:30 +0000 (16:34 +0900)
committerDongsun Lee <ds73.lee@samsung.com>
Thu, 16 Jan 2025 05:17:01 +0000 (14:17 +0900)
Change-Id: I83e89e5fc7c25892c0b1368d88657652173f2d27

src/server/CMakeLists.txt
src/server/main/include/privilege-check.h [deleted file]
src/server/main/include/user-check.h [deleted file]
src/server/main/privilege-check.cpp [deleted file]
src/server/main/user-check.cpp [deleted file]
src/server/service/include/privilege-check.h [new file with mode: 0644]
src/server/service/include/user-check.h [new file with mode: 0644]
src/server/service/privilege-check.cpp [new file with mode: 0644]
src/server/service/user-check.cpp [new file with mode: 0644]

index 279d3f09d283ac9eb3a0f4f8e3ceceff684d3039..508be063b23d3f2885ea7b1478bf629591fb3262 100644 (file)
@@ -23,17 +23,17 @@ INCLUDE_DIRECTORIES(
 
 SET(SERVER_SOURCES
     main/generic-socket-manager.cpp
-    main/privilege-check.cpp
     main/server-main.cpp
     main/smack-check.cpp
     main/socket-manager.cpp
-    main/user-check.cpp
     service/password.cpp
     service/password-manager.cpp
     service/policy-file.cpp
     service/policy-manager.cpp
     service/plugin-loader.cpp
     service/plugin-manager.cpp
+    service/privilege-check.cpp
+    service/user-check.cpp
     plugin/generic-backend/password-file-buffer.cpp
     )
 
diff --git a/src/server/main/include/privilege-check.h b/src/server/main/include/privilege-check.h
deleted file mode 100644 (file)
index 532d314..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *  Authentication password
- *
- *  Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Contact: Jooseong Lee <jooseong.lee@samsung.com>
- *
- *  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 _PRIVILEGE_CHECK_H_
-#define _PRIVILEGE_CHECK_H_
-
-#include <memory>
-#include <string>
-
-#include <cynara-client.h>
-
-namespace AuthPasswd {
-
-const std::string  PLATFORM_PRIVILEGE = "http://tizen.org/privilege/internal/default/platform";
-
-class CynaraChecker {
-public:
-       // singleton pattern
-       static CynaraChecker& instance() {
-               static CynaraChecker inst; // created once
-               return inst;
-       }
-
-       // deletes copy constructor & copy assignment operator
-       CynaraChecker(const CynaraChecker&) = delete;
-       CynaraChecker& operator=(const CynaraChecker&) = delete;
-
-       // deletes move constructor & move assignment operator
-       CynaraChecker(CynaraChecker&&) = delete;
-       CynaraChecker& operator=(CynaraChecker&) = delete;
-
-       // calls cynara_finish();
-       ~CynaraChecker();
-
-       // checks if a client has the given privilege.
-       bool checkClientPrivilege(int sockfd, const std::string& privilege);
-
-private:
-       cynara* m_CynaraInstance;
-
-       // calls cynara_initialize()
-       CynaraChecker();
-};
-
-
-} // namespace AuthPasswd
-
-#endif // _PRIVILEGE_CHECK_H_
diff --git a/src/server/main/include/user-check.h b/src/server/main/include/user-check.h
deleted file mode 100644 (file)
index 54cb646..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *  Copyright (c) 2016 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
- */
-/*
- * @file        user-check.h
- * @author      Jooseong Lee (jooseong.lee@samsung.com)
- * @version     1.0
- * @brief       Get user id from socket file descriptor of client.
- */
-#pragma once
-
-namespace AuthPasswd {
-
-int socket_get_user(int sockfd, unsigned int &user);
-
-} // namespace AuthPasswd
-
diff --git a/src/server/main/privilege-check.cpp b/src/server/main/privilege-check.cpp
deleted file mode 100644 (file)
index 562f93d..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- *  Copyright (c) 2025 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
- */
-/*
- * @author       Dongsun Lee(ds73.lee@samsung.com)
- * @version      1.0
- * @brief        Check client's privilege
- */
-#include "privilege-check.h"
-
-#include <dpl/log/log.h>
-
-#include <cynara-creds-socket.h>
-#include <cynara-session.h>
-
-
-namespace AuthPasswd {
-
-struct string_free_deleter {
-       void operator()(char * p) const {
-               free(p);
-       }
-};
-
-static inline std::string cynara_error_to_string(int error) {
-       char buffer[256];
-       int ret = cynara_strerror(error, buffer, sizeof(buffer));
-       if(ret == CYNARA_API_SUCCESS)
-               return std::string(buffer);
-       return std::string("Can't translate error");
-}
-
-CynaraChecker::CynaraChecker()
-{
-       cynara_configuration* cynara_conf = nullptr;
-       int error = cynara_configuration_create(&cynara_conf);
-       if(error != CYNARA_API_SUCCESS) {
-               LogError("Can't initialize Cynara configuration: " << error);
-               throw std::runtime_error("Can't initialize Cynara configuration");
-       }
-
-       error = cynara_initialize(&m_CynaraInstance, cynara_conf);
-       cynara_configuration_destroy(cynara_conf);
-       if(error != CYNARA_API_SUCCESS) {
-               LogError("Can't initialize Cynara instance: " << error);
-               throw std::runtime_error("Can't initialize Cynara instance");
-       }
-
-       LogDebug("CynaraChecker: cynara_initialize() was done.");
-}
-
-CynaraChecker::~CynaraChecker()
-{
-       cynara_finish(m_CynaraInstance);
-       LogDebug("CynaraChecker: cynara_finish() was done.");
-}
-
-
-bool CynaraChecker::checkClientPrivilege(int sockfd, const std::string& privilege)
-{
-       int ret = 0;
-       char* tmp_str;
-       pid_t pid = 0;
-
-       std::unique_ptr<char, string_free_deleter> user;
-       std::unique_ptr<char, string_free_deleter> client;
-       std::unique_ptr<char, string_free_deleter> client_session;
-
-       /* Get user info */
-       tmp_str = nullptr;
-       ret = cynara_creds_socket_get_user(sockfd, USER_METHOD_DEFAULT, &tmp_str);
-       if(ret != CYNARA_API_SUCCESS) {
-               LogError("Can't get user from socket : " << ret << " - " << cynara_error_to_string(ret));
-               return false;
-       }
-       user.reset(tmp_str);
-
-       /* Get client info */
-       tmp_str = nullptr;
-       ret = cynara_creds_socket_get_client(sockfd, CLIENT_METHOD_DEFAULT, &tmp_str);
-       if(ret != CYNARA_API_SUCCESS) {
-               LogError("Can't get client from socket : " << ret << " - " << cynara_error_to_string(ret));
-               return false;
-       }
-       client.reset(tmp_str);
-
-       /* Get client PID from socket */
-       ret = cynara_creds_socket_get_pid(sockfd, &pid);
-       if(ret != CYNARA_API_SUCCESS) {
-               LogError("Can't get PID from socket : " << ret << " - " << cynara_error_to_string(ret));
-               return false;
-       }
-
-       client_session.reset(cynara_session_from_pid(pid));
-       if(!client_session) {
-               LogError("Can't get session identifier from PID");
-               return false;
-       }
-
-       LogDebug("Got new session from " << pid << " with user " << user.get() <<
-               ", client ID " << client.get() << " and session ID " << client_session.get());
-
-       ret = cynara_check(m_CynaraInstance, client.get(), client_session.get(), user.get(), privilege.c_str());
-
-       if(ret != CYNARA_API_ACCESS_ALLOWED) {
-               LogError("Application access denied for " << pid << ", privilege: " <<
-                        privilege <<  ", error:  - " << cynara_error_to_string(ret));
-               return false;
-       }
-
-       LogDebug("Access granted for " << pid << " with privilege " << privilege);
-       return true;
-}
-
-} // namespace AuthPasswd
diff --git a/src/server/main/user-check.cpp b/src/server/main/user-check.cpp
deleted file mode 100644 (file)
index 779864b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *  Copyright (c) 2016 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
- */
-/*
- * @file        user-check.cpp
- * @author      Jooseong Lee (jooseong.lee@samsung.com)
- * @version     1.0
- * @brief       Get user id from socket file descriptor of client.
- */
-#include "user-check.h"
-
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include <dpl/log/log.h>
-
-namespace AuthPasswd {
-
-int socket_get_user(int sockfd, unsigned int &user)
-{
-       struct ucred cr;
-       socklen_t len = sizeof(struct ucred);
-
-       if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cr, &len)) {
-               LogError("getsockopt() failed");
-               return 1;
-       }
-
-       user = cr.uid;
-       return 0;
-}
-
-} // namespace AuthPasswd
diff --git a/src/server/service/include/privilege-check.h b/src/server/service/include/privilege-check.h
new file mode 100644 (file)
index 0000000..532d314
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  Authentication password
+ *
+ *  Copyright (c) 2025 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Contact: Jooseong Lee <jooseong.lee@samsung.com>
+ *
+ *  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 _PRIVILEGE_CHECK_H_
+#define _PRIVILEGE_CHECK_H_
+
+#include <memory>
+#include <string>
+
+#include <cynara-client.h>
+
+namespace AuthPasswd {
+
+const std::string  PLATFORM_PRIVILEGE = "http://tizen.org/privilege/internal/default/platform";
+
+class CynaraChecker {
+public:
+       // singleton pattern
+       static CynaraChecker& instance() {
+               static CynaraChecker inst; // created once
+               return inst;
+       }
+
+       // deletes copy constructor & copy assignment operator
+       CynaraChecker(const CynaraChecker&) = delete;
+       CynaraChecker& operator=(const CynaraChecker&) = delete;
+
+       // deletes move constructor & move assignment operator
+       CynaraChecker(CynaraChecker&&) = delete;
+       CynaraChecker& operator=(CynaraChecker&) = delete;
+
+       // calls cynara_finish();
+       ~CynaraChecker();
+
+       // checks if a client has the given privilege.
+       bool checkClientPrivilege(int sockfd, const std::string& privilege);
+
+private:
+       cynara* m_CynaraInstance;
+
+       // calls cynara_initialize()
+       CynaraChecker();
+};
+
+
+} // namespace AuthPasswd
+
+#endif // _PRIVILEGE_CHECK_H_
diff --git a/src/server/service/include/user-check.h b/src/server/service/include/user-check.h
new file mode 100644 (file)
index 0000000..54cb646
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (c) 2016 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
+ */
+/*
+ * @file        user-check.h
+ * @author      Jooseong Lee (jooseong.lee@samsung.com)
+ * @version     1.0
+ * @brief       Get user id from socket file descriptor of client.
+ */
+#pragma once
+
+namespace AuthPasswd {
+
+int socket_get_user(int sockfd, unsigned int &user);
+
+} // namespace AuthPasswd
+
diff --git a/src/server/service/privilege-check.cpp b/src/server/service/privilege-check.cpp
new file mode 100644 (file)
index 0000000..562f93d
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ *  Copyright (c) 2025 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
+ */
+/*
+ * @author       Dongsun Lee(ds73.lee@samsung.com)
+ * @version      1.0
+ * @brief        Check client's privilege
+ */
+#include "privilege-check.h"
+
+#include <dpl/log/log.h>
+
+#include <cynara-creds-socket.h>
+#include <cynara-session.h>
+
+
+namespace AuthPasswd {
+
+struct string_free_deleter {
+       void operator()(char * p) const {
+               free(p);
+       }
+};
+
+static inline std::string cynara_error_to_string(int error) {
+       char buffer[256];
+       int ret = cynara_strerror(error, buffer, sizeof(buffer));
+       if(ret == CYNARA_API_SUCCESS)
+               return std::string(buffer);
+       return std::string("Can't translate error");
+}
+
+CynaraChecker::CynaraChecker()
+{
+       cynara_configuration* cynara_conf = nullptr;
+       int error = cynara_configuration_create(&cynara_conf);
+       if(error != CYNARA_API_SUCCESS) {
+               LogError("Can't initialize Cynara configuration: " << error);
+               throw std::runtime_error("Can't initialize Cynara configuration");
+       }
+
+       error = cynara_initialize(&m_CynaraInstance, cynara_conf);
+       cynara_configuration_destroy(cynara_conf);
+       if(error != CYNARA_API_SUCCESS) {
+               LogError("Can't initialize Cynara instance: " << error);
+               throw std::runtime_error("Can't initialize Cynara instance");
+       }
+
+       LogDebug("CynaraChecker: cynara_initialize() was done.");
+}
+
+CynaraChecker::~CynaraChecker()
+{
+       cynara_finish(m_CynaraInstance);
+       LogDebug("CynaraChecker: cynara_finish() was done.");
+}
+
+
+bool CynaraChecker::checkClientPrivilege(int sockfd, const std::string& privilege)
+{
+       int ret = 0;
+       char* tmp_str;
+       pid_t pid = 0;
+
+       std::unique_ptr<char, string_free_deleter> user;
+       std::unique_ptr<char, string_free_deleter> client;
+       std::unique_ptr<char, string_free_deleter> client_session;
+
+       /* Get user info */
+       tmp_str = nullptr;
+       ret = cynara_creds_socket_get_user(sockfd, USER_METHOD_DEFAULT, &tmp_str);
+       if(ret != CYNARA_API_SUCCESS) {
+               LogError("Can't get user from socket : " << ret << " - " << cynara_error_to_string(ret));
+               return false;
+       }
+       user.reset(tmp_str);
+
+       /* Get client info */
+       tmp_str = nullptr;
+       ret = cynara_creds_socket_get_client(sockfd, CLIENT_METHOD_DEFAULT, &tmp_str);
+       if(ret != CYNARA_API_SUCCESS) {
+               LogError("Can't get client from socket : " << ret << " - " << cynara_error_to_string(ret));
+               return false;
+       }
+       client.reset(tmp_str);
+
+       /* Get client PID from socket */
+       ret = cynara_creds_socket_get_pid(sockfd, &pid);
+       if(ret != CYNARA_API_SUCCESS) {
+               LogError("Can't get PID from socket : " << ret << " - " << cynara_error_to_string(ret));
+               return false;
+       }
+
+       client_session.reset(cynara_session_from_pid(pid));
+       if(!client_session) {
+               LogError("Can't get session identifier from PID");
+               return false;
+       }
+
+       LogDebug("Got new session from " << pid << " with user " << user.get() <<
+               ", client ID " << client.get() << " and session ID " << client_session.get());
+
+       ret = cynara_check(m_CynaraInstance, client.get(), client_session.get(), user.get(), privilege.c_str());
+
+       if(ret != CYNARA_API_ACCESS_ALLOWED) {
+               LogError("Application access denied for " << pid << ", privilege: " <<
+                        privilege <<  ", error:  - " << cynara_error_to_string(ret));
+               return false;
+       }
+
+       LogDebug("Access granted for " << pid << " with privilege " << privilege);
+       return true;
+}
+
+} // namespace AuthPasswd
diff --git a/src/server/service/user-check.cpp b/src/server/service/user-check.cpp
new file mode 100644 (file)
index 0000000..779864b
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ *  Copyright (c) 2016 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
+ */
+/*
+ * @file        user-check.cpp
+ * @author      Jooseong Lee (jooseong.lee@samsung.com)
+ * @version     1.0
+ * @brief       Get user id from socket file descriptor of client.
+ */
+#include "user-check.h"
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <dpl/log/log.h>
+
+namespace AuthPasswd {
+
+int socket_get_user(int sockfd, unsigned int &user)
+{
+       struct ucred cr;
+       socklen_t len = sizeof(struct ucred);
+
+       if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &cr, &len)) {
+               LogError("getsockopt() failed");
+               return 1;
+       }
+
+       user = cr.uid;
+       return 0;
+}
+
+} // namespace AuthPasswd