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/simple.h"
23#include "trace.h"
24#include "qemu/module.h"
25#include "qom/object_interfaces.h"
26
27static bool qauthz_simple_is_allowed(QAuthZ *authz,
28 const char *identity,
29 Error **errp)
30{
31 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(authz);
32
33 trace_qauthz_simple_is_allowed(authz, sauthz->identity, identity);
34 return g_str_equal(identity, sauthz->identity);
35}
36
37static void
38qauthz_simple_prop_set_identity(Object *obj,
39 const char *value,
40 Error **errp G_GNUC_UNUSED)
41{
42 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);
43
44 g_free(sauthz->identity);
45 sauthz->identity = g_strdup(value);
46}
47
48
49static char *
50qauthz_simple_prop_get_identity(Object *obj,
51 Error **errp G_GNUC_UNUSED)
52{
53 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);
54
55 return g_strdup(sauthz->identity);
56}
57
58
59static void
60qauthz_simple_finalize(Object *obj)
61{
62 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);
63
64 g_free(sauthz->identity);
65}
66
67
68static void
69qauthz_simple_class_init(ObjectClass *oc, void *data)
70{
71 QAuthZClass *authz = QAUTHZ_CLASS(oc);
72
73 authz->is_allowed = qauthz_simple_is_allowed;
74
75 object_class_property_add_str(oc, "identity",
76 qauthz_simple_prop_get_identity,
77 qauthz_simple_prop_set_identity,
78 NULL);
79}
80
81
82QAuthZSimple *qauthz_simple_new(const char *id,
83 const char *identity,
84 Error **errp)
85{
86 return QAUTHZ_SIMPLE(
87 object_new_with_props(TYPE_QAUTHZ_SIMPLE,
88 object_get_objects_root(),
89 id, errp,
90 "identity", identity,
91 NULL));
92}
93
94
95static const TypeInfo qauthz_simple_info = {
96 .parent = TYPE_QAUTHZ,
97 .name = TYPE_QAUTHZ_SIMPLE,
98 .instance_size = sizeof(QAuthZSimple),
99 .instance_finalize = qauthz_simple_finalize,
100 .class_size = sizeof(QAuthZSimpleClass),
101 .class_init = qauthz_simple_class_init,
102 .interfaces = (InterfaceInfo[]) {
103 { TYPE_USER_CREATABLE },
104 { }
105 }
106};
107
108
109static void
110qauthz_simple_register_types(void)
111{
112 type_register_static(&qauthz_simple_info);
113}
114
115
116type_init(qauthz_simple_register_types);
117