1 /*
2  * libvirt-gconfig-storage-permissions.c: libvirt storage permissions configuration
3  *
4  * Copyright (C) 2011 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
18  * <http://www.gnu.org/licenses/>.
19  *
20  * Author: Christophe Fergeau <cfergeau@redhat.com>
21  */
22 
23 #include <config.h>
24 
25 #include "libvirt-gconfig/libvirt-gconfig.h"
26 #include "libvirt-gconfig/libvirt-gconfig-private.h"
27 
28 #define GVIR_CONFIG_STORAGE_PERMISSIONS_GET_PRIVATE(obj)                         \
29         (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_STORAGE_PERMISSIONS, GVirConfigStoragePermissionsPrivate))
30 
31 struct _GVirConfigStoragePermissionsPrivate
32 {
33     gboolean unused;
34 };
35 
36 G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigStoragePermissions, gvir_config_storage_permissions, GVIR_CONFIG_TYPE_OBJECT);
37 
38 
gvir_config_storage_permissions_class_init(GVirConfigStoragePermissionsClass * klass G_GNUC_UNUSED)39 static void gvir_config_storage_permissions_class_init(GVirConfigStoragePermissionsClass *klass G_GNUC_UNUSED)
40 {
41 }
42 
43 
gvir_config_storage_permissions_init(GVirConfigStoragePermissions * perms)44 static void gvir_config_storage_permissions_init(GVirConfigStoragePermissions *perms)
45 {
46     perms->priv = GVIR_CONFIG_STORAGE_PERMISSIONS_GET_PRIVATE(perms);
47 }
48 
49 
gvir_config_storage_permissions_new(void)50 GVirConfigStoragePermissions *gvir_config_storage_permissions_new(void)
51 {
52     GVirConfigObject *object;
53 
54     object = gvir_config_object_new(GVIR_CONFIG_TYPE_STORAGE_PERMISSIONS,
55                                     "permissions", NULL);
56     return GVIR_CONFIG_STORAGE_PERMISSIONS(object);
57 }
58 
gvir_config_storage_permissions_new_from_xml(const gchar * xml,GError ** error)59 GVirConfigStoragePermissions *gvir_config_storage_permissions_new_from_xml(const gchar *xml,
60                                                                            GError **error)
61 {
62     GVirConfigObject *object;
63 
64     object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_STORAGE_PERMISSIONS,
65                                              "permissions", NULL,
66                                              xml, error);
67     return GVIR_CONFIG_STORAGE_PERMISSIONS(object);
68 }
69 
70 /**
71  * gvir_config_storage_permissions_get_group:
72  * @perms: a #GVirConfigStoragePermissions
73  *
74  * Gets the numeric group ID associated with @perms.
75  *
76  * Returns: numeric group ID
77  */
gvir_config_storage_permissions_get_group(GVirConfigStoragePermissions * perms)78 guint gvir_config_storage_permissions_get_group(GVirConfigStoragePermissions *perms)
79 {
80     g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms), 0);
81 
82     return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(perms),
83                                                       "group");
84 }
85 
gvir_config_storage_permissions_set_group(GVirConfigStoragePermissions * perms,guint group)86 void gvir_config_storage_permissions_set_group(GVirConfigStoragePermissions *perms,
87                                                guint group)
88 {
89     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
90 
91     gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(perms),
92                                                "group", group);
93 }
94 
95 /**
96  * gvir_config_storage_permissions_get_label:
97  * @perms: a #GVirConfigStoragePermissions
98  *
99  * Gets the MAC label string associated with @perms.
100  *
101  * Returns: MAC label string.
102  */
gvir_config_storage_permissions_get_label(GVirConfigStoragePermissions * perms)103 const char *gvir_config_storage_permissions_get_label(GVirConfigStoragePermissions *perms)
104 {
105     g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms), NULL);
106 
107     return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(perms),
108                                                "label");
109 }
110 /**
111  * gvir_config_storage_permissions_set_label:
112  * @label: (allow-none):
113  */
gvir_config_storage_permissions_set_label(GVirConfigStoragePermissions * perms,const char * label)114 void gvir_config_storage_permissions_set_label(GVirConfigStoragePermissions *perms,
115                                                const char *label)
116 {
117     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
118 
119     gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(perms),
120                                         "label", label);
121 }
122 
123 /**
124  * gvir_config_storage_permissions_get_mode:
125  * @perms: a #GVirConfigStoragePermissions
126  *
127  * Gets the octal permission set associated with @perms.
128  *
129  * Returns: permission set
130  */
gvir_config_storage_permissions_get_mode(GVirConfigStoragePermissions * perms)131 guint gvir_config_storage_permissions_get_mode(GVirConfigStoragePermissions *perms)
132 {
133     g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms), 0);
134 
135     return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(perms),
136                                                       "mode");
137 }
138 
gvir_config_storage_permissions_set_mode(GVirConfigStoragePermissions * perms,guint mode)139 void gvir_config_storage_permissions_set_mode(GVirConfigStoragePermissions *perms,
140                                               guint mode)
141 {
142     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
143 
144     gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(perms),
145                                                "mode", mode);
146 }
147 
148 /**
149  * gvir_config_storage_permissions_get_owner:
150  * @perms: a #GVirConfigStoragePermissions
151  *
152  * Gets the numeric user ID associated with @perms.
153  *
154  * Returns: numeric user ID.
155  */
gvir_config_storage_permissions_get_owner(GVirConfigStoragePermissions * perms)156 guint gvir_config_storage_permissions_get_owner(GVirConfigStoragePermissions *perms)
157 {
158     g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms), 0);
159 
160     return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(perms),
161                                                       "owner");
162 }
163 
gvir_config_storage_permissions_set_owner(GVirConfigStoragePermissions * perms,guint owner)164 void gvir_config_storage_permissions_set_owner(GVirConfigStoragePermissions *perms,
165                                                guint owner)
166 {
167     g_return_if_fail(GVIR_CONFIG_IS_STORAGE_PERMISSIONS(perms));
168 
169     gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(perms),
170                                                "owner", owner);
171 }
172