PageRenderTime 44ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/helpers/creds-dbus/creds-dbus.cpp

https://gitlab.com/admin-github-cloud/cynara
C++ | 84 lines | 49 code | 12 blank | 23 comment | 26 complexity | c16d4b104a206e45936ea79847989007 MD5 | raw file
  1. /*
  2. * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License
  15. */
  16. /**
  17. * @file src/helpers/creds-dbus/creds-dbus.cpp
  18. * @author Radoslaw Bartosiak <r.bartosiak@samsung.com>
  19. * @author Aleksander Zdyb <a.zdyb@samsung.com>
  20. * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  21. * @version 1.0
  22. * @brief Implementation of external libcynara-creds-dbus API
  23. */
  24. #include <attributes/attributes.h>
  25. #include <creds-dbus-inner.h>
  26. #include <cynara-creds-commons.h>
  27. #include <cynara-creds-dbus.h>
  28. #include <cynara-error.h>
  29. CYNARA_API
  30. int cynara_creds_dbus_get_client(DBusConnection *connection, const char *uniqueName,
  31. enum cynara_client_creds method, char **client) {
  32. if (connection == nullptr || uniqueName == nullptr || client == nullptr)
  33. return CYNARA_API_INVALID_PARAM;
  34. if (method == cynara_client_creds::CLIENT_METHOD_DEFAULT) {
  35. int ret = cynara_creds_get_default_client_method(&method);
  36. if (ret != CYNARA_API_SUCCESS)
  37. return ret;
  38. }
  39. switch (method) {
  40. case cynara_client_creds::CLIENT_METHOD_SMACK:
  41. return getClientSmackLabel(connection, uniqueName, client);
  42. case cynara_client_creds::CLIENT_METHOD_PID:
  43. return getClientPid(connection, uniqueName, client);
  44. default:
  45. return CYNARA_API_METHOD_NOT_SUPPORTED;
  46. }
  47. }
  48. CYNARA_API
  49. int cynara_creds_dbus_get_user(DBusConnection *connection, const char *uniqueName,
  50. enum cynara_user_creds method, char **user) {
  51. if (connection == nullptr || uniqueName == nullptr || user == nullptr)
  52. return CYNARA_API_INVALID_PARAM;
  53. if (method == cynara_user_creds::USER_METHOD_DEFAULT) {
  54. int ret = cynara_creds_get_default_user_method(&method);
  55. if (ret != CYNARA_API_SUCCESS)
  56. return ret;
  57. }
  58. switch (method) {
  59. case cynara_user_creds::USER_METHOD_UID:
  60. return getUserId(connection, uniqueName, user);
  61. case cynara_user_creds::USER_METHOD_GID:
  62. return getUserGid(connection, uniqueName, user);
  63. default:
  64. return CYNARA_API_METHOD_NOT_SUPPORTED;
  65. }
  66. }
  67. CYNARA_API
  68. int cynara_creds_dbus_get_pid(DBusConnection *connection, const char *uniqueName, pid_t *pid) {
  69. if (connection == nullptr || uniqueName == nullptr)
  70. return CYNARA_API_INVALID_PARAM;
  71. return getPid(connection, uniqueName, pid);
  72. }