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
|
/*
* Copyright (c) 1999 The University of Utah and the Flux Group.
* All rights reserved.
*
* Contributed by the Computer Security Research division,
* INFOSEC Research and Technology Office, NSA.
*
* This file is part of the Flux OSKit. The OSKit is free software, also known
* as "open source;" you can redistribute it and/or modify it under the terms
* of the GNU General Public License (GPL), version 2, as published by the Free
* Software Foundation (FSF). To explore alternate licensing terms, contact
* the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
*
* The OSKit 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 GPL for more details. You should have
* received a copy of the GPL along with the OSKit; see the file COPYING. If
* not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
*/
/* FLASK */
#include "avdeftab.h"
#define AVDEFTAB_HASH(key) (key % AVDEFTAB_SIZE)
#define AVDEFTAB_EQ(key1,key2) (key1 == key2)
int
avdeftab_insert(avdeftab_t * h, unsigned int key, avdef_datum_t * datum)
{
int hvalue;
avdef_ptr_t cur, newnode;
if (!h)
return -ENOMEM;
hvalue = AVDEFTAB_HASH(key);
cur = h->htable[hvalue];
while (cur != NULL && !AVDEFTAB_EQ(cur->key, key))
cur = cur->next;
if (cur != NULL)
return -EEXIST;
newnode = (avdef_ptr_t) malloc(sizeof(struct avdef_node_t));
if (newnode == NULL)
return -ENOMEM;
newnode->key = key;
newnode->datum = *datum;
newnode->next = h->htable[hvalue];
h->htable[hvalue] = newnode;
h->nel++;
return 0;
}
avdef_datum_t *
avdeftab_search(avdeftab_t * h, unsigned int key)
{
int hvalue;
avdef_ptr_t cur;
if (!h)
return NULL;
hvalue = AVDEFTAB_HASH(key);
cur = h->htable[hvalue];
while (cur != NULL && !AVDEFTAB_EQ(cur->key, key))
cur = cur->next;
if (cur == NULL)
return NULL;
return &cur->datum;
}
static int
perm_destroy(hashtab_key_t key, hashtab_datum_t datum, void *p)
{
FREE(key, strlen(key) + 1);
FREE(datum, sizeof(perm_datum_t));
return 0;
}
int
constraint_expr_destroy(constraint_expr_t * expr)
{
expr->count--;
if (expr->count == 0) {
ebitmap_destroy(&expr->bitmap);
if (expr->left)
constraint_expr_destroy(expr->left);
if (expr->right)
constraint_expr_destroy(expr->right);
free(expr);
}
return 0;
}
void
avdeftab_destroy(avdeftab_t * h)
{
int i;
avdef_ptr_t cur, temp;
constraint_node_t *constraint, *ctemp;
if (!h)
return;
for (i = 0; i < AVDEFTAB_SIZE; i++) {
cur = h->htable[i];
while (cur != NULL) {
hashtab_map(cur->datum.private.table, perm_destroy, 0);
hashtab_destroy(cur->datum.private.table);
constraint = cur->datum.constraints;
while (constraint) {
constraint_expr_destroy(constraint->expr);
ctemp = constraint;
constraint = constraint->next;
free(ctemp);
}
temp = cur;
cur = cur->next;
free(temp);
}
}
}
int
avdeftab_map(avdeftab_t * h,
int (*apply) (unsigned int key,
avdef_datum_t * d,
void *args),
void *args)
{
int i, ret;
avdef_ptr_t cur;
if (!h)
return 0;
for (i = 0; i < AVDEFTAB_SIZE; i++) {
cur = h->htable[i];
while (cur != NULL) {
ret = apply(cur->key, &cur->datum, args);
if (ret)
return ret;
cur = cur->next;
}
}
return 0;
}
int
avdeftab_init(avdeftab_t * h)
{
int i;
for (i = 0; i < AVDEFTAB_SIZE; i++)
h->htable[i] = (avdef_ptr_t) NULL;
h->nel = 0;
h->ncons = 0;
return 0;
}
/* FLASK */
|