listfile.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * QEMU list file authorization driver
  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_LISTFILE_H
  21. #define QAUTHZ_LISTFILE_H
  22. #include "authz/list.h"
  23. #include "qemu/filemonitor.h"
  24. #include "qom/object.h"
  25. #define TYPE_QAUTHZ_LIST_FILE "authz-list-file"
  26. OBJECT_DECLARE_SIMPLE_TYPE(QAuthZListFile,
  27. QAUTHZ_LIST_FILE)
  28. /**
  29. * QAuthZListFile:
  30. *
  31. * This authorization driver provides a file mechanism
  32. * for granting access by matching user names against a
  33. * file of globs. Each match rule has an associated policy
  34. * and a catch all policy applies if no rule matches
  35. *
  36. * To create an instance of this class via QMP:
  37. *
  38. * {
  39. * "execute": "object-add",
  40. * "arguments": {
  41. * "qom-type": "authz-list-file",
  42. * "id": "authz0",
  43. * "props": {
  44. * "filename": "/etc/qemu/myvm-vnc.acl",
  45. * "refresh": true
  46. * }
  47. * }
  48. * }
  49. *
  50. * If 'refresh' is 'yes', inotify is used to monitor for changes
  51. * to the file and auto-reload the rules.
  52. *
  53. * The myvm-vnc.acl file should contain the parameters for
  54. * the QAuthZList object in JSON format:
  55. *
  56. * {
  57. * "rules": [
  58. * { "match": "fred", "policy": "allow", "format": "exact" },
  59. * { "match": "bob", "policy": "allow", "format": "exact" },
  60. * { "match": "danb", "policy": "deny", "format": "exact" },
  61. * { "match": "dan*", "policy": "allow", "format": "glob" }
  62. * ],
  63. * "policy": "deny"
  64. * }
  65. *
  66. * The object can be created on the command line using
  67. *
  68. * -object authz-list-file,id=authz0,\
  69. * filename=/etc/qemu/myvm-vnc.acl,refresh=yes
  70. *
  71. */
  72. struct QAuthZListFile {
  73. QAuthZ parent_obj;
  74. QAuthZ *list;
  75. char *filename;
  76. bool refresh;
  77. QFileMonitor *file_monitor;
  78. int64_t file_watch;
  79. };
  80. QAuthZListFile *qauthz_list_file_new(const char *id,
  81. const char *filename,
  82. bool refresh,
  83. Error **errp);
  84. #endif /* QAUTHZ_LISTFILE_H */