See Helper functions for that int user_perm (XML * user, const char * class, const char * object, const char * permission) { XML * group; XML * child; child = xml_firstelem (user); while (child) { if (!strcmp (child->name, "object")) { if (!strcmp (xml_attrval (child, "class"), class) && !strcmp (xml_attrval (child, "object"), object)) { if (_user_perm_cmp (xml_attrval (child, "permission"), permission)) return (1); } } else if (!strcmp (child->name, "group")) { if (!strcmp (xml_attrval (child, "name"), "admin")) return (1); group = group_get (xml_attrval (child, "name")); if (group) { if (user_perm (group, class, object, permission)) { xml_free (group); return (1); } xml_free (group); } } else if (!strcmp (child->name, "group-include")) { if (_user_perm_cmp (xml_attrval (child, "permission"), permission)) { group = group_get (xml_attrval (child, "name")); if (group) { if (user_perm (group, class, object, permission)) { xml_free (group); return (1); } xml_free (group); } } } child = xml_nextelem (child); } if (strcmp (user->name, "group") && strcmp (xml_attrval (user, "name"), "everybody")) { group = group_get ("everybody"); if (group) { if (user_perm (group, class, object, permission)) { xml_free (group); return (1); } xml_free (group); } } return (0); } |
user_perm_group
, which just takes the name of a group which owns the object
in question. (Thus having the named permission on the group will automatically count as having (at least) that
permission on the object.) This saves a great deal of overhead if we can assume that objects always are
owned by single groups, which works well for the task manager.
int user_perm_group (XML * user, const char * groupname, const char * permission) { XML * group; XML * child; if (!strcmp (groupname, "everybody")) return (1); if (!strcmp (groupname, "")) return (1); child = xml_firstelem (user); while (child) { if (!strcmp (child->name, "group")) { if (!strcmp (xml_attrval (child, "name"), "admin")) return (1); if (!strcmp (xml_attrval (child, "name"), groupname)) return (1); group = group_get (xml_attrval (child, "name")); if (group) { if (user_perm_group (group, groupname, permission)) { xml_free (group); return (1); } xml_free (group); } } else if (!strcmp (child->name, "group-include")) { if (_user_perm_cmp (xml_attrval (child, "permission"), permission)) { if (!strcmp (xml_attrval (child, "name"), groupname)) return (1); group = group_get (xml_attrval (child, "name")); if (group) { if (user_perm_group (group, groupname, permission)) { xml_free (group); return (1); } xml_free (group); } } } child = xml_nextelem (child); } if (strcmp (user->name, "group") && strcmp (xml_attrval (user, "name"), "everybody")) { group = group_get ("everybody"); if (group) { if (user_perm_group (group, groupname, permission)) { xml_free (group); return (1); } xml_free (group); } } return (0); } |
int _user_perm_cmp (const char * perm1, const char * permission) { if (!strcmp (perm1, "own")) return (1); if (!strcmp (perm1, permission)) return (1); if (!strcmp (permission, "view")) return (1); return (0); } |
This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license. |