base.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * QEMU authorization framework base class
  3. *
  4. * Copyright (c) 2018 Red Hat, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifndef QAUTHZ_BASE_H
  21. #define QAUTHZ_BASE_H
  22. #include "qapi/error.h"
  23. #include "qom/object.h"
  24. #define TYPE_QAUTHZ "authz"
  25. OBJECT_DECLARE_TYPE(QAuthZ, QAuthZClass,
  26. QAUTHZ)
  27. /**
  28. * QAuthZ:
  29. *
  30. * The QAuthZ class defines an API contract to be used
  31. * for providing an authorization driver for services
  32. * with user identities.
  33. */
  34. struct QAuthZ {
  35. Object parent_obj;
  36. };
  37. struct QAuthZClass {
  38. ObjectClass parent_class;
  39. bool (*is_allowed)(QAuthZ *authz,
  40. const char *identity,
  41. Error **errp);
  42. };
  43. /**
  44. * qauthz_is_allowed:
  45. * @authz: the authorization object
  46. * @identity: the user identity to authorize
  47. * @errp: pointer to a NULL initialized error object
  48. *
  49. * Check if a user @identity is authorized. If an error
  50. * occurs this method will return false to indicate
  51. * denial, as well as setting @errp to contain the details.
  52. * Callers are recommended to treat the denial and error
  53. * scenarios identically. Specifically the error info in
  54. * @errp should never be fed back to the user being
  55. * authorized, it is merely for benefit of administrator
  56. * debugging.
  57. *
  58. * Returns: true if @identity is authorized, false if denied or if
  59. * an error occurred.
  60. */
  61. bool qauthz_is_allowed(QAuthZ *authz,
  62. const char *identity,
  63. Error **errp);
  64. /**
  65. * qauthz_is_allowed_by_id:
  66. * @authzid: ID of the authorization object
  67. * @identity: the user identity to authorize
  68. * @errp: pointer to a NULL initialized error object
  69. *
  70. * Check if a user @identity is authorized. If an error
  71. * occurs this method will return false to indicate
  72. * denial, as well as setting @errp to contain the details.
  73. * Callers are recommended to treat the denial and error
  74. * scenarios identically. Specifically the error info in
  75. * @errp should never be fed back to the user being
  76. * authorized, it is merely for benefit of administrator
  77. * debugging.
  78. *
  79. * Returns: true if @identity is authorized, false if denied or if
  80. * an error occurred.
  81. */
  82. bool qauthz_is_allowed_by_id(const char *authzid,
  83. const char *identity,
  84. Error **errp);
  85. #endif /* QAUTHZ_BASE_H */