u_int acl::get_permissions (sfsauth_cred *cred, str *key, vec<sfs_idname> *groups) { vec<str> credstrings; u_int p = 0; // 3 kinds of access: anonymous, public key, unix credentials // anonymous means that the user wasn't running an agent or // for some reason the authd couldn't even return a public key if (key) credstrings.push_back (strbuf () << TYPEPK << ACLDIV << *key); if (cred) credstrings.push_back (strbuf () << TYPELOCALUSER << ACLDIV << cred->unixcred->username); if (groups) { for (unsigned int i = 0; i < groups->size (); i++) credstrings.push_back (strbuf () << TYPELOCALGROUP << ACLDIV << (*groups)[i]); } if (!cred && !key) credstrings.push_back (strbuf () << TYPESYS << ACLDIV << SYS_ANONYMOUS); str flattened_creds (""); for (u_int i = 0; i < credstrings.size (); i++) { warn ("CRED[%d]: %s\n", i, credstrings[i].cstr ()); flattened_creds = strbuf () << flattened_creds << credstrings[i]; } #if PCACHE //make hash out of acl and user; ask cache about hash str ua = strbuf () << armor32 (str (aclhash, sizeof (aclhash))) << flattened_creds; bzero (hashbuf, sizeof (hashbuf)); sha1_hash (hashbuf, ua.cstr (), ua.len ()); if (is_cached (hashbuf, p)) { warn << "Using cached perms (" << get_strpermissions (p) << ") for cache key "<< armor32 (str (hashbuf, sizeof (hashbuf))) << "\n"; return p; } else { warn << "Did not find cached perms (" << ua << ") for cache key " << armor32 (str (hashbuf, sizeof (hashbuf))) << "\n"; } #endif p = parse_acl (credstrings); #if PCACHE insert_cache (hashbuf, p); #endif return p; }
void copy_cache_record_and_overflow(bdd_manager *bddm, cache_record *old_cache, unsigned i, unsigned (*result_fn)(unsigned r)) { unsigned p, q, r, h; if (CACHE_FULL_BIN0(old_cache[i])) { CACHE_LOAD_BIN0(old_cache[i], p, q, r); h = HASH2(p, q, bddm->cache_mask); insert_cache(bddm, h, p, q, result_fn(r)); if (CACHE_FULL_BIN1(old_cache[i])) { CACHE_LOAD_BIN1(old_cache[i], p, q, r); h = HASH2(p, q, bddm->cache_mask); insert_cache(bddm, h, p, q, result_fn(r)); } } if (old_cache[i].next != 0) { copy_cache_record_and_overflow(bddm, old_cache, old_cache[i].next, result_fn); } }
int find_cache(struct cache **cache, char *uri) { struct cache *temp = &head; int flag = 0; while (temp->next != &tail) { if (!strcmp(temp->next->uri, uri)) { struct cache *target = temp->next; if (target->next != &tail) { pthread_mutex_lock(&temp->c_lock); pthread_mutex_lock(&target->c_lock); if (validate(temp, target)) { if (strcmp(target->uri, uri)) { flag = 0; } else { temp->next = target->next; *cache = target; target->valid = 0; flag = 1; } } pthread_mutex_unlock(&target->c_lock); pthread_mutex_unlock(&temp->c_lock); if (flag == 1) { target->valid = 1; while (!insert_cache(target)); break; } } else { if (validate(temp, target)) { *cache = target; flag = 1; break; } } } temp = temp->next; } return flag; }
void create_cache(char *buf, char *uri) { struct cache *cache = (struct cache *)Malloc(sizeof(struct cache)); pthread_mutex_init(&cache->c_lock, NULL); cache->data = (char *)Malloc(strlen(buf)); cache->uri = (char *)Malloc(strlen(uri)); cache->valid = 1; strcpy(cache->data, buf); strcpy(cache->uri, uri); pthread_mutex_lock(&s_lock); total_cache_size += strlen(cache->data); pthread_mutex_unlock(&s_lock); while (total_cache_size > MAX_CACHE_SIZE) evict_cache(); while (!insert_cache(cache)); }
void compile_dispatcher(NNF_NODE* node, Clause** learned_clause, DVtree* vtree, VtreeManager* vtree_manager, NnfManager* nnf_manager, SatState* sat_state) { //check cache VtreeCV item; if(lookup_cache(&item,vtree,vtree_manager)) { *node = item.node; *learned_clause = NULL; return; } //need to compile if(vtree_is_leaf(vtree)) compile_vtree_leaf(node,learned_clause,vtree,nnf_manager); else if(vtree_is_shannon_node(vtree)) compile_vtree_shannon(node,learned_clause,vtree,vtree_manager,nnf_manager,sat_state); else compile_vtree_decomposed(node,learned_clause,vtree,vtree_manager,nnf_manager,sat_state); //cache if a node is returned if(*learned_clause==NULL) { //otherwise, a node has not been returned item.node = *node; insert_cache(item,vtree,vtree_manager); } }