Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20190714' into staging
[qemu/ar7.git] / authz / simple.c
blob008912d24735a788ffaa083aa96786dd6ec18537
1 /*
2 * QEMU simple authorization driver
4 * Copyright (c) 2018 Red Hat, Inc.
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 of the License, or (at your option) any later version.
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.
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/>.
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"
27 static bool qauthz_simple_is_allowed(QAuthZ *authz,
28 const char *identity,
29 Error **errp)
31 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(authz);
33 trace_qauthz_simple_is_allowed(authz, sauthz->identity, identity);
34 return g_str_equal(identity, sauthz->identity);
37 static void
38 qauthz_simple_prop_set_identity(Object *obj,
39 const char *value,
40 Error **errp G_GNUC_UNUSED)
42 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);
44 g_free(sauthz->identity);
45 sauthz->identity = g_strdup(value);
49 static char *
50 qauthz_simple_prop_get_identity(Object *obj,
51 Error **errp G_GNUC_UNUSED)
53 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);
55 return g_strdup(sauthz->identity);
59 static void
60 qauthz_simple_finalize(Object *obj)
62 QAuthZSimple *sauthz = QAUTHZ_SIMPLE(obj);
64 g_free(sauthz->identity);
68 static void
69 qauthz_simple_class_init(ObjectClass *oc, void *data)
71 QAuthZClass *authz = QAUTHZ_CLASS(oc);
73 authz->is_allowed = qauthz_simple_is_allowed;
75 object_class_property_add_str(oc, "identity",
76 qauthz_simple_prop_get_identity,
77 qauthz_simple_prop_set_identity,
78 NULL);
82 QAuthZSimple *qauthz_simple_new(const char *id,
83 const char *identity,
84 Error **errp)
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));
95 static 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 },
109 static void
110 qauthz_simple_register_types(void)
112 type_register_static(&qauthz_simple_info);
116 type_init(qauthz_simple_register_types);