1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "qemu/osdep.h"
22#include "authz/base.h"
23#include "authz/trace.h"
24
25bool qauthz_is_allowed(QAuthZ *authz,
26 const char *identity,
27 Error **errp)
28{
29 QAuthZClass *cls = QAUTHZ_GET_CLASS(authz);
30 bool allowed;
31
32 allowed = cls->is_allowed(authz, identity, errp);
33 trace_qauthz_is_allowed(authz, identity, allowed);
34
35 return allowed;
36}
37
38
39bool qauthz_is_allowed_by_id(const char *authzid,
40 const char *identity,
41 Error **errp)
42{
43 QAuthZ *authz;
44 Object *obj;
45 Object *container;
46
47 container = object_get_objects_root();
48 obj = object_resolve_path_component(container,
49 authzid);
50 if (!obj) {
51 error_setg(errp, "Cannot find QAuthZ object ID %s",
52 authzid);
53 return false;
54 }
55
56 if (!object_dynamic_cast(obj, TYPE_QAUTHZ)) {
57 error_setg(errp, "Object '%s' is not a QAuthZ subclass",
58 authzid);
59 return false;
60 }
61
62 authz = QAUTHZ(obj);
63
64 return qauthz_is_allowed(authz, identity, errp);
65}
66
67
68static const TypeInfo authz_info = {
69 .parent = TYPE_OBJECT,
70 .name = TYPE_QAUTHZ,
71 .instance_size = sizeof(QAuthZ),
72 .class_size = sizeof(QAuthZClass),
73 .abstract = true,
74};
75
76static void qauthz_register_types(void)
77{
78 type_register_static(&authz_info);
79}
80
81type_init(qauthz_register_types)
82
83