Introduce 'default' method type for credential helpers 77/38077/4
authorJacek Bukarewicz <j.bukarewicz@samsung.com>
Fri, 10 Apr 2015 14:06:46 +0000 (16:06 +0200)
committerJacek Bukarewicz <j.bukarewicz@samsung.com>
Tue, 14 Apr 2015 11:16:33 +0000 (13:16 +0200)
Default method type will be translated to a proper method read
from configuration file.

Change-Id: I7e37a6af62b8c7d3612863c3de0fe849c7112787

src/helpers/creds-dbus/CMakeLists.txt
src/helpers/creds-dbus/creds-dbus.cpp
src/helpers/creds-gdbus/CMakeLists.txt
src/helpers/creds-gdbus/creds-gdbus.cpp
src/helpers/creds-socket/CMakeLists.txt
src/helpers/creds-socket/creds-socket.cpp
src/include/cynara-creds-commons.h
src/include/cynara-creds-dbus.h
src/include/cynara-creds-gdbus.h
src/include/cynara-creds-socket.h

index 28030a9..0919fef 100644 (file)
@@ -50,6 +50,7 @@ SET_TARGET_PROPERTIES(
 
 TARGET_LINK_LIBRARIES(${TARGET_LIB_CREDS_DBUS}
     ${LIB_CREDS_DBUS_DEP_LIBRARIES}
+    ${TARGET_LIB_CREDS_COMMONS}
     )
 
 INSTALL(TARGETS ${TARGET_LIB_CREDS_DBUS} DESTINATION ${LIB_INSTALL_DIR})
index 4bca2a5..c93a7ca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 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.
@@ -37,6 +37,12 @@ int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueN
     if (connection == nullptr || uniqueName == nullptr || client == nullptr)
         return CYNARA_API_INVALID_PARAM;
 
+    if (method == cynara_client_creds::CLIENT_METHOD_DEFAULT) {
+        int ret = cynara_creds_get_default_client_method(&method);
+        if (ret != CYNARA_API_SUCCESS)
+            return ret;
+    }
+
     switch (method) {
         case cynara_client_creds::CLIENT_METHOD_SMACK:
             return getClientSmackLabel(connection, uniqueName, client);
@@ -53,6 +59,12 @@ int cynara_creds_dbus_get_user(DBusConnection *connection, const char *uniqueNam
     if (connection == nullptr || uniqueName == nullptr || user == nullptr)
         return CYNARA_API_INVALID_PARAM;
 
+    if (method == cynara_user_creds::USER_METHOD_DEFAULT) {
+        int ret = cynara_creds_get_default_user_method(&method);
+        if (ret != CYNARA_API_SUCCESS)
+            return ret;
+    }
+
     switch (method) {
         case cynara_user_creds::USER_METHOD_UID:
             return getUserId(connection, uniqueName, user);
index 1b7c3d0..92cf40c 100644 (file)
@@ -49,6 +49,7 @@ SET_TARGET_PROPERTIES(
 
 TARGET_LINK_LIBRARIES(${TARGET_LIB_CREDS_GDBUS}
     ${LIB_CREDS_GDBUS_DEP_LIBRARIES}
+    ${TARGET_LIB_CREDS_COMMONS}
     )
 
 INSTALL(TARGETS ${TARGET_LIB_CREDS_GDBUS} DESTINATION ${LIB_INSTALL_DIR})
index 80ee63d..a56c630 100644 (file)
@@ -68,6 +68,12 @@ int cynara_creds_gdbus_get_client(GDBusConnection *connection, const gchar *uniq
     if (connection == nullptr || uniqueName == nullptr || client == nullptr)
         return CYNARA_API_INVALID_PARAM;
 
+    if (method == cynara_client_creds::CLIENT_METHOD_DEFAULT) {
+        int ret = cynara_creds_get_default_client_method(&method);
+        if (ret != CYNARA_API_SUCCESS)
+            return ret;
+    }
+
     switch (method) {
         case cynara_client_creds::CLIENT_METHOD_SMACK:
             ret = call_dbus_daemon_method_str(connection, "GetConnectionSmackContext", uniqueName,
@@ -94,6 +100,12 @@ int cynara_creds_gdbus_get_user(GDBusConnection *connection, const gchar *unique
     if (connection == nullptr || uniqueName == nullptr || user == nullptr)
         return CYNARA_API_INVALID_PARAM;
 
+    if (method == cynara_user_creds::USER_METHOD_DEFAULT) {
+        int ret = cynara_creds_get_default_user_method(&method);
+        if (ret != CYNARA_API_SUCCESS)
+            return ret;
+    }
+
     if (method != cynara_user_creds::USER_METHOD_UID)
         return CYNARA_API_METHOD_NOT_SUPPORTED;
 
index 286d917..f171b84 100644 (file)
@@ -42,4 +42,8 @@ SET_TARGET_PROPERTIES(
         VERSION ${LIB_CREDS_SOCKET_VERSION}
     )
 
+TARGET_LINK_LIBRARIES(${TARGET_LIB_CREDS_SOCKET}
+    ${TARGET_LIB_CREDS_COMMONS}
+    )
+
 INSTALL(TARGETS ${TARGET_LIB_CREDS_SOCKET} DESTINATION ${LIB_INSTALL_DIR})
index fb5f963..e99e744 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 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.
@@ -38,6 +38,12 @@ int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds metho
     if (client == nullptr)
         return CYNARA_API_INVALID_PARAM;
 
+    if (method == cynara_client_creds::CLIENT_METHOD_DEFAULT) {
+        int ret = cynara_creds_get_default_client_method(&method);
+        if (ret != CYNARA_API_SUCCESS)
+            return ret;
+    }
+
     switch (method) {
         case cynara_client_creds::CLIENT_METHOD_SMACK:
             return getClientSmackLabel(socket_fd, client);
@@ -53,6 +59,12 @@ int cynara_creds_socket_get_user(int socket_fd, enum cynara_user_creds method, c
     if (user == nullptr)
         return CYNARA_API_INVALID_PARAM;
 
+    if (method == cynara_user_creds::USER_METHOD_DEFAULT) {
+        int ret = cynara_creds_get_default_user_method(&method);
+        if (ret != CYNARA_API_SUCCESS)
+            return ret;
+    }
+
     switch (method) {
         case cynara_user_creds::USER_METHOD_UID:
             return getUserId(socket_fd, user);
index 4c5c417..ac6a327 100644 (file)
 
 enum cynara_client_creds {
     CLIENT_METHOD_SMACK,
-    CLIENT_METHOD_PID
+    CLIENT_METHOD_PID,
+
+    CLIENT_METHOD_DEFAULT = 0xFFFF,
 };
 
 enum cynara_user_creds {
     USER_METHOD_UID,
-    USER_METHOD_GID
+    USER_METHOD_GID,
+
+    USER_METHOD_DEFAULT = 0xFFFF,
 };
 
 #ifdef __cplusplus
index 7f151f1..8600e2a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 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.
@@ -61,6 +61,7 @@ extern "C" {
  * \par Important notes:
  * Memory for returned client string is obtained with malloc(), and should be freed with free().
  * Allocated string is returned only, when function succeeds.
+ * If method is CLIENT_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
  *
  * \param[in] connection DBus connection to a bus. It manages incomming and outgoing messages
  * \param[in] uniqueName DBus identifier of the client
@@ -71,6 +72,8 @@ extern "C" {
  *         CYNARA_API_INVALID_PARAM when client is NULL or uniqueName or client has wrong
  *                                  value (i.e NULL or non-existing)
  *         CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
+ *         CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ *                                        there are errors in configuration file.
  *         CYNARA_API_OUT_OF_MEMORY when there was error allocating memory
  */
 int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueName,
@@ -103,6 +106,7 @@ int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueN
  * \par Important notes:
  * Memory for returned user string is obtained with malloc(), and should be freed with free().
  * Allocated string is returned only, when function succeeds.
+ * If method is USER_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
  *
  * \param[in] connection DBus connection to a bus. It manages incomming and outgoing messages
  * \param[in] uniqueName DBus identifier of the client invoked by the user
@@ -113,6 +117,8 @@ int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueN
  *         CYNARA_API_INVALID_PARAM when user is NULL or connection is not valid DBus connection or
  *                                  uniqueName does not represent a process conected to the DBus
  *         CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
+ *         CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ *                                        there are errors in configuration file.
  *         CYNARA_API_OUT_OF_MEMORY when there was error allocating memory
  */
 int cynara_creds_dbus_get_user(DBusConnection *connection, const char *uniqueName,
index c6ce2dd..c38de20 100644 (file)
@@ -60,6 +60,7 @@ extern "C" {
  * \par Important notes:
  * Memory for returned user string should be freed with g_free().
  * Allocated string is returned only, when function succeeds.
+ * If method is CLIENT_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
  *
  * \param[in] connection DBus connection to a bus. It manages incomming and outgoing messages
  * \param[in] uniqueName DBus identifier of the client
@@ -69,6 +70,8 @@ extern "C" {
  * \return CYNARA_API_SUCCESS on success
  *         CYNARA_API_INVALID_PARAM when client is NULL or uniqueName or client has wrong
  *                                  value (i.e NULL or non-existing)
+ *         CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ *                                        there are errors in configuration file.
  *         CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
  */
 int cynara_creds_gdbus_get_client(GDBusConnection *connection, const gchar *uniqueName,
@@ -101,6 +104,7 @@ int cynara_creds_gdbus_get_client(GDBusConnection *connection, const gchar *uniq
  * \par Important notes:
  * Memory for returned user string should be freed with g_free().
  * Allocated string is returned only, when function succeeds.
+ * If method is USER_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
  *
  * \param[in] connection DBus connection to a bus. It manages incomming and outgoing messages
  * \param[in] uniqueName DBus identifier of the client invoked by the user
@@ -110,6 +114,8 @@ int cynara_creds_gdbus_get_client(GDBusConnection *connection, const gchar *uniq
  * \return CYNARA_API_SUCCESS on success
  *         CYNARA_API_INVALID_PARAM when user is NULL or connection is not valid DBus connection or
  *                                  uniqueName does not represent a process conected to the DBus
+ *         CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ *                                        there are errors in configuration file.
  *         CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
  */
 int cynara_creds_gdbus_get_user(GDBusConnection *connection, const gchar *uniqueName,
index 252af26..1508055 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2015 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.
@@ -60,6 +60,7 @@ extern "C" {
  * \par Important notes:
  * Memory for returned client string is obtained with malloc(), and should be freed with free().
  * Allocated string is returned only, when function succeeds.
+ * If method is CLIENT_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
  *
  * \param[in] socket_fd Descriptor of open connected UNIX socket
  * \param[in] method Method of client identifier creation
@@ -69,6 +70,8 @@ extern "C" {
  *         CYNARA_API_INVALID_PARAM when client is NULL or socket_fd is not valid connected socket
  *                                  descriptor
  *         CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
+ *         CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ *                                        there are errors in configuration file.
  *         CYNARA_API_OUT_OF_MEMORY when there was error allocating memory
  */
 int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds method, char **client);
@@ -99,6 +102,7 @@ int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds metho
  * \par Important notes:
  * Memory for returned user string is obtained with malloc(), and should be freed with free().
  * Allocated string is returned only, when function succeeds.
+ * If method is USER_METHOD_DEFAULT then it will be chosen based on Cynara configuration file.
  *
  * \param[in] socket_fd Descriptor of open connected UNIX socket
  * \param[in] method Method of user identifier creation
@@ -108,6 +112,8 @@ int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds metho
  *         CYNARA_API_INVALID_PARAM when user is NULL or socket_fd is not valid connected socket
  *                                  descriptor
  *         CYNARA_API_METHOD_NOT_SUPPORTED when requested method is not supported
+ *         CYNARA_API_CONFIGURATION_ERROR if the configuration file can not be opened or
+ *                                        there are errors in configuration file.
  *         CYNARA_API_OUT_OF_MEMORY when there was error allocating memory
  */
 int cynara_creds_socket_get_user(int socket_fd, enum cynara_user_creds method, char **user);