PageRenderTime 33ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/src/helpers/creds-socket/creds-socket.cpp

https://gitlab.com/github-cloud-corporation/cynara
C++ | 81 lines | 47 code | 11 blank | 23 comment | 14 complexity | 15bca92fa8e144c7a0ac2f6251bf1282 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-socket/creds-socket.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-socket API
  23. */
  24. #include <sys/socket.h>
  25. #include <sys/types.h>
  26. #include <attributes/attributes.h>
  27. #include <creds-socket-inner.h>
  28. #include <cynara-creds-commons.h>
  29. #include <cynara-creds-socket.h>
  30. #include <cynara-error.h>
  31. CYNARA_API
  32. int cynara_creds_socket_get_client(int socket_fd, enum cynara_client_creds method, char **client) {
  33. if (client == nullptr)
  34. return CYNARA_API_INVALID_PARAM;
  35. if (method == cynara_client_creds::CLIENT_METHOD_DEFAULT) {
  36. int ret = cynara_creds_get_default_client_method(&method);
  37. if (ret != CYNARA_API_SUCCESS)
  38. return ret;
  39. }
  40. switch (method) {
  41. case cynara_client_creds::CLIENT_METHOD_SMACK:
  42. return getClientSmackLabel(socket_fd, client);
  43. case cynara_client_creds::CLIENT_METHOD_PID:
  44. return getClientPid(socket_fd, client);
  45. default:
  46. return CYNARA_API_METHOD_NOT_SUPPORTED;
  47. }
  48. }
  49. CYNARA_API
  50. int cynara_creds_socket_get_user(int socket_fd, enum cynara_user_creds method, char **user) {
  51. if (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(socket_fd, user);
  61. case cynara_user_creds::USER_METHOD_GID:
  62. return getUserGid(socket_fd, user);
  63. default:
  64. return CYNARA_API_METHOD_NOT_SUPPORTED;
  65. }
  66. }
  67. CYNARA_API
  68. int cynara_creds_socket_get_pid(int socket_fd, pid_t *pid) {
  69. return getPid(socket_fd, pid);
  70. }