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