1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* gnome-vfs-acl.h - ACL Handling for the GNOME Virtual File System.
Access Control List Object
Copyright (C) 2005 Christian Kellner
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Christian Kellner <gicmo@gnome.org>
*/
#include "gnome-vfs-acl.h"
/* ************************************************************************** */
/* GObject Stuff */
static GObjectClass *parent_class = NULL;
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
GNOME_VFS_TYPE_ACL, GnomeVFSACLPrivate))
G_DEFINE_TYPE (GnomeVFSACL, gnome_vfs_acl, G_TYPE_OBJECT);
struct _GnomeVFSACLPrivate {
GList *entries;
gboolean modified;
};
static void
gnome_vfs_acl_finalize (GObject *object)
{
GnomeVFSACL *acl;
GnomeVFSACLPrivate *priv;
GList *iter;
acl = GNOME_VFS_ACL (object);
priv = acl->priv;
for (iter = priv->entries; iter; iter = iter->next) {
GnomeVFSACE *ace;
ace = GNOME_VFS_ACE (iter->data);
g_object_unref (ace);
}
g_list_free (priv->entries);
if (G_OBJECT_CLASS (parent_class)->finalize)
(*G_OBJECT_CLASS (parent_class)->finalize) (object);
}
static void
gnome_vfs_acl_class_init (GnomeVFSACLClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GnomeVFSACLPrivate));
gobject_class->finalize = gnome_vfs_acl_finalize;
}
static void
gnome_vfs_acl_init (GnomeVFSACL *acl)
{
acl->priv = GET_PRIVATE (acl);
}
/* ************************************************************************** */
/* Public Interface */
/**
* gnome_vfs_acl_new:
*
* Creates a new #GnomeVFSACL object.
*
* Return value: The new #GnomeVFSACL
*
* Since: 2.16
**/
GnomeVFSACL *
gnome_vfs_acl_new (void)
{
GnomeVFSACL *acl;
acl = g_object_new (GNOME_VFS_TYPE_ACL, NULL);
return acl;
}
/**
* gnome_vfs_acl_clear:
* @acl: A valid #GnomeVFSACL object
*
* This will clear the #GnomeVFSACL object resetting it to a
* state exaclty as if it was newly created.
*
* Since: 2.16
**/
void
gnome_vfs_acl_clear (GnomeVFSACL *acl)
{
GnomeVFSACLPrivate *priv;
GnomeVFSACE *entry;
GList *iter;
priv = acl->priv;
entry = NULL;
for (iter = priv->entries; iter; iter = iter->next) {
entry = GNOME_VFS_ACE (iter->data);
g_object_unref (entry);
}
g_list_free (priv->entries);
priv->entries = NULL;
}
/**
* gnome_vfs_acl_set:
* @acl: A valid #GnomeVFSACL object
* @ace: A #GnomeVFSACE to set in @acl
*
* This will search the #GnomeVFSACL object specified at @acl for an
* existing #GnomeVFSACE that machtes @ace. If found it will update the
* permission on the object otherwise it will ref @ace and insert it
* into it's list.
*
* Since: 2.16
**/
void
gnome_vfs_acl_set (GnomeVFSACL *acl,
GnomeVFSACE *ace)
{
GnomeVFSACLPrivate *priv;
GnomeVFSACE *entry;
GList *iter;
g_return_if_fail (GNOME_VFS_IS_ACE (ace));
priv = acl->priv;
entry = NULL;
/* that could be made faster with some HashTable foo,
* not sure it is worth the effort, though */
for (iter = priv->entries; iter; iter = iter->next) {
entry = GNOME_VFS_ACE (iter->data);
if (gnome_vfs_ace_equal (entry, ace)) {
break;
}
}
if (iter == NULL) {
priv->entries = g_list_prepend (priv->entries, g_object_ref (ace));
} else {
gnome_vfs_ace_copy_perms (ace, entry);
}
}
/**
* gnome_vfs_acl_unset:
* @acl: A valid #GnomeVFSACL object
* @ace: A #GnomeVFSACE to remove from @acl
*
* This will search the #GnomeVFSACL object specified at @acl for an
* existing #GnomeVFSACE that machtes @ace. If found it will remove it
* from its internal list.
*
* Since: 2.16
**/
void
gnome_vfs_acl_unset (GnomeVFSACL *acl,
GnomeVFSACE *ace)
{
GnomeVFSACLPrivate *priv;
GnomeVFSACE *entry;
GList *iter;
priv = acl->priv;
entry = NULL;
/* that could be made faster with some HashTable foo,
* not sure it is worth the effort, though */
for (iter = priv->entries; iter; iter = iter->next) {
entry = GNOME_VFS_ACE (iter->data);
if (gnome_vfs_ace_equal (entry, ace)) {
break;
}
}
if (iter != NULL) {
g_object_unref (entry);
priv->entries = g_list_remove_link (priv->entries, iter);
}
}
/**
* gnome_vfs_acl_get_ace_list:
* @acl: A valid #GnomeVFSACL object
*
* This will create you a list of all #GnomeVFSACE objects that are
* contained in @acl.
*
* Return value: A newly created list you have to free with
* gnome_vfs_acl_get_ace_list.
*
* Since: 2.16
**/
GList*
gnome_vfs_acl_get_ace_list (GnomeVFSACL *acl)
{
GnomeVFSACLPrivate *priv;
GList *list;
priv = acl->priv;
list = g_list_copy (priv->entries);
g_list_foreach (list, (GFunc) g_object_ref, NULL);
return list;
}
/**
* gnome_vfs_ace_free_ace_list:
* @ace_list: A GList return by gnome_vfs_acl_get_ace_list
*
* This will unref all the #GnomeVFSACE in the list and free it
* afterwards
*
* Since: 2.16
**/
void
gnome_vfs_acl_free_ace_list (GList *ace_list)
{
g_list_foreach (ace_list, (GFunc) g_object_unref, NULL);
g_list_free (ace_list);
}
/* ************************************************************************** */
/* ************************************************************************** */
const char *
gnome_vfs_acl_kind_to_string (GnomeVFSACLKind kind)
{
const char *value;
if (kind < GNOME_VFS_ACL_KIND_SYS_LAST) {
switch (kind) {
case GNOME_VFS_ACL_USER:
value = "user";
break;
case GNOME_VFS_ACL_GROUP:
value = "group";
break;
case GNOME_VFS_ACL_OTHER:
value = "other";
break;
default:
value = "unknown";
break;
}
} else {
value = "unknown";
}
return value;
}
const char *
gnome_vfs_acl_perm_to_string (GnomeVFSACLPerm perm)
{
const char *value;
if (perm < GNOME_VFS_ACL_PERM_SYS_LAST) {
switch (perm) {
case GNOME_VFS_ACL_READ:
value = "read";
break;
case GNOME_VFS_ACL_WRITE:
value = "write";
break;
case GNOME_VFS_ACL_EXECUTE:
value = "execute";
break;
default:
value = "unknown";
break;
}
} else {
value = "unknown";
}
return value;
}
|