static void delete_marked_cache_groups() { cache_group* cache_group; cache* cache; struct listnode *cache_group_node, *cache_node; struct listnode *next_node, *next_cache_node; for (ALL_LIST_ELEMENTS(cache_group_list, cache_group_node, next_node, cache_group)) { for (ALL_LIST_ELEMENTS(cache_group->cache_config_list, cache_node, next_cache_node, cache)) { if (cache->delete_flag) { listnode_delete(cache_group->cache_config_list, cache); delete_cache(cache); } } if (listcount(cache_group->cache_config_list) == 0 || cache_group->delete_flag) { listnode_delete(cache_group_list, cache_group); delete_cache_group(cache_group); } } }
int main(int argc, char *argv[]) { int listenfd; socklen_t clientlen; struct sockaddr_storage clientaddr; pthread_t tid; init_cache(); signal(SIGPIPE, SIG_IGN); /* Check command line args */ if (argc != 2) { fprintf(stderr, "usage: %s <port>\n", argv[0]); exit(1); } listenfd = Open_listenfd(argv[1]); while (1) { int *connfdp = Malloc(sizeof(int)); clientlen = sizeof(clientaddr); *connfdp = Accept(listenfd, (SA *)&clientaddr, &clientlen); Pthread_create(&tid, NULL, doit_thread, connfdp); } delete_cache(); return 0; }
int recv_un(int sockfd, struct hwaddr *hwaddr_info) { int n; char *rec; size_t len; //n = recvfrom(sockfd, hwaddr_info, sizeof(struct hwaddr), 0, (SA *)&sa, &len); printf("----->ARP: !!!Receiving from domain socket.\n"); n = recv(sockfd, hwaddr_info, sizeof(struct hwaddr), 0); //n = Recv(sockfd, rec, 3, 0); //printf("Received %d bytes\n", n); //printf("Requested IP: %s\n", hwaddr_info->sll_ip); //printf("Hard Type: %d\n", (int)hwaddr_info->sll_hatype); //puts(rec); if (n == 0 ) { delete_cache(sockfd); close(sockfd); puts("----->ARP: Time out occurred, cleaning up cache and close connection..."); } else if (n < 0){ puts("recvfrom error"); return -1; } return n; }
int main(int argc,char *argv[]) { parse_arg(argc,argv); Cache* C = make_cache(); caching(C,trace_file); printSummary(C->num_of_hit,C->num_of_miss,C->num_of_evict); delete_cache(C); return 0; }
void Delete_Caches(void) { CDS *cds = CDS_root; while (cds != NULL) { CDS *old = cds; cds = cds->next; delete_cache(old); } }
void delete_cachelist(cachelist_param_t **cachelist) { cache_param_t *cachePtr, *cacheNext; cachePtr = (*cachelist)->first; while( cachePtr != NULL){ cacheNext=cachePtr->next; delete_cache( &cachePtr); cachePtr=cacheNext; } free( *cachelist); }
static void test1(void) { printf("***************************\n" "* TEST 1 *\n" "***************************\n"); init_cache(&cache); printf("\n--- Initial cache ---\n"); print_all_cache(stdout, &cache); test_elem(A, 1, 1); test_elem(A, 1, 1); printf("\n--- After addition ---\n"); print_all_cache(stdout, &cache); test_elem(B, 2, 2); test_elem(B, 2, 2); printf("\n--- After more addition ---\n"); print_all_cache(stdout, &cache); cache_push(&cache); cache_push(&cache); printf("\n--- Push: level 2 ---\n"); print_all_cache(stdout, &cache); test_elem(A, 0, 1); test_elem(A, 0, 1); test_elem(A, 1, 0); test_elem(A, 1, 0); printf("\n--- Content ---\n"); print_all_cache(stdout, &cache); cache_push(&cache); printf("\n--- Push: level 3 ---\n"); print_all_cache(stdout, &cache); cache_pop(&cache); printf("\n--- Pop: level 2 ---\n"); print_all_cache(stdout, &cache); cache_pop(&cache); printf("\n--- Pop: level 1 ---\n"); print_all_cache(stdout, &cache); cache_pop(&cache); printf("\n--- Pop: level 0 ---\n"); print_all_cache(stdout, &cache); delete_cache(&cache); }
int main(int argc, char* argv[]) { if (argc != 5) { printf("usage: cache-sim <set bits> <associativity> <block bits> <tracefile>\n"); exit(1); } int sets = atoi(argv[1]); int lines = atoi(argv[2]); int blocks = atoi(argv[3]); char* file = argv[4]; Cache* cache = make_cache(sets, lines, blocks); CPU* cpu = make_cpu(cache, file); run_cpu(cpu); delete_cpu(cpu); delete_cache(cache); }
static void dist_table_free(void *vdep) { DistEntry *dep = (DistEntry *) vdep; if(dep == erts_this_dist_entry) return; ASSERT(is_nil(dep->cid)); ASSERT(dep->nlinks == NULL); ASSERT(dep->node_links == NULL); ASSERT(dep->monitors == NULL); /* Link out */ /* All dist entries about to be removed are "not connected" */ if(dep->prev) { ASSERT(is_in_de_list(dep, erts_not_connected_dist_entries)); dep->prev->next = dep->next; } else { ASSERT(erts_not_connected_dist_entries == dep); erts_not_connected_dist_entries = dep->next; } if(dep->next) dep->next->prev = dep->prev; ASSERT(erts_no_of_not_connected_dist_entries > 0); erts_no_of_not_connected_dist_entries--; delete_cache((DistEntry *) dep); #ifdef DEBUG sys_memset(vdep, 0x77, sizeof(DistEntry)); #endif erts_free(ERTS_ALC_T_DIST_ENTRY, (void *) dep); ASSERT(dist_entries > 1); dist_entries--; }
static void test2(void) { uint16_t tag; int32_t x, y; uint32_t i; cache_elem_t *e0, *e1; uint32_t level; printf("***************************\n" "* TEST 2 *\n" "***************************\n"); level = 1; init_cache(&cache); printf("---- INITIAL ----\n"); print_cache_stack(stdout, &cache); print_cache_bank(stdout, &cache); printf("\n"); for (i=0; i<4000; i++) { tag = (uint16_t) (random() % NUMTAGS); x = (int32_t) (random() % 20); y = (int32_t) (random() % 20); e0 = cache_find(&cache, tag, x, y); e1 = cache_get(&cache, tag, x, y); if (e0 == NULL && e1->flag != NEW_CACHE_ELEM) { printf("*** caching bug ***\n"); printf(" element: [%s %"PRId32" %"PRId32"]\n", tag2string[tag], x, y); printf(" find: returned NULL\n"); printf(" get: returned %p: ", e1); print_cache_elem(stdout, e1); printf("\n"); } if (e0 != NULL && e1 != e0) { printf("*** caching bug ***\n"); printf(" element: [%s %"PRId32" %"PRId32"]\n", tag2string[tag], x, y); printf(" find: returned %p: ", e0); print_cache_elem(stdout, e0); printf("\n"); printf(" get: returned %p: ", e1); print_cache_elem(stdout, e1); printf("\n"); } if (e1->flag == NEW_CACHE_ELEM) { e1->flag = (uint16_t) level; } if (i % 100 == 49) { printf("\n--- Push to level %"PRIu32" ---\n", level); cache_push(&cache); level ++; print_cache_stack(stdout, &cache); print_cache_bank(stdout, &cache); } } printf("\n--- After random additions (level = %"PRIu32") ---\n", level); print_all_cache(stdout, &cache); print_cache_stack(stdout, &cache); print_cache_bank(stdout, &cache); while (level > 1) { level --; printf("\n--- Pop to level %"PRIu32" ---\n", level); cache_pop(&cache); print_all_cache(stdout, &cache); print_cache_stack(stdout, &cache); print_cache_bank(stdout, &cache); } printf("\n--- After reset ---\n"); reset_cache(&cache); print_all_cache(stdout, &cache); print_cache_stack(stdout, &cache); print_cache_bank(stdout, &cache); delete_cache(&cache); }
int find_entry (DN object, common_args *ca, DN acl_who, struct dn_seq *dn_stack, int master, Entry *ent_p, struct DSError *err, struct di_block **di_p, int optype) { int deref = FALSE; extern time_t cache_timeout; DN dn_found; int res; DLOG (log_dsap,LLOG_TRACE,("find_entry")); err->dse_type = DSE_NOERROR; if ((ca->ca_servicecontrol.svc_options & SVC_OPT_DONTDEREFERENCEALIAS) == 0) deref = TRUE; if ((ca->ca_servicecontrol.svc_options & SVC_OPT_DONTUSECOPY) != 0) master = TRUE; switch(really_find_entry(object,deref,dn_stack,master,ent_p,err,di_p)) { case DS_OK: DLOG(log_dsap, LLOG_DEBUG, ("find_entry - rfe: OK")); /* Have set up ent_p continue processing */ break; case DS_CONTINUE: DLOG(log_dsap, LLOG_DEBUG, ("find_entry - rfe: CONT")); #ifdef DEBUG di_list_log((*di_p)); #endif /* Have set up di_blocks of DSAs to be questioned */ return(DS_CONTINUE); case DS_X500_ERROR: DLOG(log_dsap, LLOG_DEBUG, ("find_entry - rfe: X500_ERROR")); /* Have set up an error */ return(DS_X500_ERROR); default: /* Scream */ LLOG(log_dsap, LLOG_EXCEPTIONS, ("really_find_entry failed in find_entry 1")); return(DS_ERROR_LOCAL); } dn_found = get_copy_dn (*ent_p); /* if the returned entry is a CONSTRUCTOR, return a referral */ if ((*ent_p)->e_data == E_TYPE_CONSTRUCTOR) { DLOG(log_dsap, LLOG_DEBUG, ("find_entry - constructor")); res = constructor_dsa_info(dn_found,dn_stack,FALSE,(*ent_p),err,di_p); dn_free (dn_found); return (res); } /* if the returned entry is a COPY, - check service controls */ if (((*ent_p)->e_data != E_DATA_MASTER) && (master)) { /* DSAs are special for read/modify */ if ((optype == OP_READ) || (optype == OP_MODIFYRDN) || (optype == OP_MODIFYENTRY)) { if ((quipu_ctx_supported (*ent_p) > 2) && (quipu_version_7 (*ent_p))) { if (dn_cmp (dn_found, mydsadn) == 0) goto out; mk_ref: ; (*di_p) = di_alloc(); (*di_p)->di_type = DI_TASK; (*di_p)->di_dn = dn_found; (*di_p)->di_target = dn_cpy(dn_found); (*di_p)->di_reftype = RT_UNDEFINED; (*di_p)->di_rdn_resolved = CR_RDNRESOLVED_NOTDEFINED; (*di_p)->di_aliasedRDNs = CR_NOALIASEDRDNS; (*di_p)->di_entry = *ent_p; (*ent_p)->e_refcount++; (*di_p)->di_state = DI_COMPLETE; return DS_CONTINUE; } } DLOG(log_dsap, LLOG_DEBUG, ("find_entry - slave master needed")); res = constructor_dsa_info(dn_found,dn_stack,TRUE,(*ent_p),err,di_p); dn_free (dn_found); return (res); } else if ( ((optype == OP_MODIFYRDN) || (optype == OP_MODIFYENTRY)) && (quipu_ctx_supported (*ent_p) > 2) && quipu_version_7 (*ent_p) && (dn_cmp (dn_found, mydsadn) != 0)) goto mk_ref; #ifdef WRONG_BEHAVIOUR /* if this is right, we need to make sure that dsa_info */ /* pick ups the correct external reference */ if ((*ent_p)->e_external && ((*ent_p)->e_reftype != RT_NONSPECIFICSUBORDINATE)) { res = constructor_dsa_info(dn_found,dn_stack,TRUE,(*ent_p),err,di_p); dn_free (dn_found); return (res); } #endif if (((*ent_p)->e_data == E_TYPE_CACHE_FROM_MASTER) && (timenow - (*ent_p)->e_age > cache_timeout)) { DLOG(log_dsap, LLOG_DEBUG, ("find_entry - cache timed out")); res = constructor_dsa_info(dn_found,dn_stack,TRUE,(*ent_p),err,di_p); delete_cache (dn_found); dn_free (dn_found); return (res); } out: ; dn_free (dn_found); if ((*ent_p)->e_parent == NULLENTRY) { DLOG(log_dsap, LLOG_DEBUG, ("find_entry: (*ent_p)->e_parent is NULLENTRY")); return (DS_OK); /* no acl for root entry */ } if (check_acl (acl_who,ACL_DETECT, (*ent_p)->e_parent->e_acl->ac_child, object) == NOTOK) { err->dse_type = DSE_SECURITYERROR; err->ERR_SECURITY.DSE_sc_problem = DSE_SC_ACCESSRIGHTS; return (DS_X500_ERROR); } if (check_acl (acl_who,ACL_DETECT, (*ent_p)->e_acl->ac_entry, object) == NOTOK) { err->dse_type = DSE_SECURITYERROR; err->ERR_SECURITY.DSE_sc_problem = DSE_SC_ACCESSRIGHTS; return (DS_X500_ERROR); } return (DS_OK); }
/* Run Command: ./sim_cache <Block Size> <L1 Size> <L1 Associativity> <Victim Cache Number of Blocks> <L2 Size> <L2 Associativity> <Trace File> */ int main(int argc, char *argv[]) { if(argc <= 7) { printf("Usage: ./sim_cache <Block Size> <L1 Size> <L1 Associativity> <Victim Cache Number of Blocks> <L2 Size> <L2 Associativity> <Trace File>.\n"); return 0; } unsigned int blocksize = atoi(argv[1]); unsigned int L1_size = atoi(argv[2]); unsigned int L1_assoc = atoi(argv[3]); unsigned int L1_vc_blocks = atoi(argv[4]); unsigned int L2_size = atoi(argv[5]); unsigned int L2_assoc = atoi(argv[6]); struct cache *L1 = (struct cache*)malloc(sizeof(struct cache)); struct cache *L2 = NULL; struct cache *vc = NULL; L1 = create_cache(blocksize,L1_assoc,L1_size,"L1"); if(L1_vc_blocks > 0) { vc = (struct cache*)malloc(sizeof(struct cache)); vc = create_cache(blocksize,L1_vc_blocks,L1_vc_blocks*blocksize,"VC"); L1->vc = vc; } if(L2_size > 0 && L2_assoc >= 1) { L2 = (struct cache*)malloc(sizeof(struct cache)); L2 = create_cache(blocksize,L2_assoc,L2_size,"L2"); L1->next = L2; } if(L1_vc_blocks > 0 && L2_size > 0 && L2_assoc >= 1) { vc->next = L2; } strcpy(L1->trace,argv[7]); FILE *trace = fopen(argv[7],"r"); if(trace == NULL) { printf("Error: Could not open file.\n"); return 0; } char str[12],address[12]; unsigned long num_addr; int i; unsigned int instr = 0; print_simulator_config(L1); while(fgets(str, 12, trace) != NULL) { for(i=0;i<strlen(str);i++) if(str[i] == '\n') str[i] = '\0'; for(i=2;i<=strlen(str);i++) { address[i-2] = str[i]; } address[i-2] = '\0'; num_addr = (int)strtoul(address, NULL, 16); instr++; if(str[0] == 'r') { if (DEBUG == 1 ) {printf("----------------------------------------\n");} if (DEBUG == 1 ) {printf("# %d: read %lx\n",instr,num_addr);} access_cache(L1,num_addr, str[0]); } else if(str[0] == 'w') { if (DEBUG == 1 ) {printf("----------------------------------------\n");} if (DEBUG == 1 ) {printf("# %d: write %lx\n",instr,num_addr);} access_cache(L1,num_addr, str[0]); } else if(str[0] == ' ') { printf("Null character in trace"); } //DEBUG HELP: print_cache(L1); //DEBUG HELP: print_cache(L1->vc); //DEBUG HELP: print_cache(L2); } fclose(trace); printf("===== L1 contents =====\n"); print_cache(L1); if(L1_vc_blocks > 0) { printf("\n===== VC contents =====\n"); print_cache(vc); } if(L2_size >= 0 && L2_assoc >= 1) { printf("\n===== L2 contents =====\n"); print_cache(L1->next); } print_simulation_summary(L1); if(L2_size > 0 && L2_assoc >= 1) { delete_cache(L2); } else { free(L2); } if(L1_vc_blocks > 0) { delete_cache(vc); } else { free(vc); } delete_cache(L1); return 0; }
static int do_rm_cache(char **arg, char reply[REPLY_MAX]) { return delete_cache(arg[0]); /* pkgname */ }
void FeProblem::assemble(_Vector *rhs, _Matrix *jac, Tuple<Solution*> u_ext) { // Sanity checks. if (!have_spaces) error("You have to call set_spaces() before calling assemble()."); for (int i=0; i<this->wf->neq; i++) { if (this->spaces[i] == NULL) error("A space is NULL in assemble()."); } int k, m, n, marker; AUTOLA_CL(AsmList, al, wf->neq); AsmList *am, *an; bool bnd[4]; AUTOLA_OR(bool, nat, wf->neq); AUTOLA_OR(bool, isempty, wf->neq); EdgePos ep[4]; reset_warn_order(); // create slave pss's for test functions, init quadrature points AUTOLA_OR(PrecalcShapeset*, spss, wf->neq); PrecalcShapeset *fu, *fv; AUTOLA_CL(RefMap, refmap, wf->neq); for (int i = 0; i < wf->neq; i++) { spss[i] = new PrecalcShapeset(pss[i]); pss [i]->set_quad_2d(&g_quad_2d_std); spss[i]->set_quad_2d(&g_quad_2d_std); refmap[i].set_quad_2d(&g_quad_2d_std); } // initialize buffer buffer = NULL; mat_size = 0; get_matrix_buffer(9); // obtain a list of assembling stages std::vector<WeakForm::Stage> stages; wf->get_stages(spaces, NULL, stages, jac == NULL); // Loop through all assembling stages -- the purpose of this is increased performance // in multi-mesh calculations, where, e.g., only the right hand side uses two meshes. // In such a case, the matrix forms are assembled over one mesh, and only the rhs // traverses through the union mesh. On the other hand, if you don't use multi-mesh // at all, there will always be only one stage in which all forms are assembled as usual. Traverse trav; for (unsigned ss = 0; ss < stages.size(); ss++) { WeakForm::Stage* s = &stages[ss]; for (unsigned i = 0; i < s->idx.size(); i++) s->fns[i] = pss[s->idx[i]]; for (unsigned i = 0; i < s->ext.size(); i++) s->ext[i]->set_quad_2d(&g_quad_2d_std); trav.begin(s->meshes.size(), &(s->meshes.front()), &(s->fns.front())); // assemble one stage Element** e; while ((e = trav.get_next_state(bnd, ep)) != NULL) { // find a non-NULL e[i] Element* e0; for (unsigned int i = 0; i < s->idx.size(); i++) if ((e0 = e[i]) != NULL) break; if (e0 == NULL) continue; // set maximum integration order for use in integrals, see limit_order() update_limit_table(e0->get_mode()); // obtain assembly lists for the element at all spaces, set appropriate mode for each pss memset(isempty, 0, sizeof(bool) * wf->neq); for (unsigned int i = 0; i < s->idx.size(); i++) { int j = s->idx[i]; if (e[i] == NULL) { isempty[j] = true; continue; } spaces[j]->get_element_assembly_list(e[i], al+j); spss[j]->set_active_element(e[i]); spss[j]->set_master_transform(); refmap[j].set_active_element(e[i]); refmap[j].force_transform(pss[j]->get_transform(), pss[j]->get_ctm()); u_ext[j]->set_active_element(e[i]); u_ext[j]->force_transform(pss[j]->get_transform(), pss[j]->get_ctm()); } marker = e0->marker; init_cache(); //// assemble volume matrix forms ////////////////////////////////////// if (jac != NULL) { for (unsigned ww = 0; ww < s->mfvol.size(); ww++) { WeakForm::MatrixFormVol* mfv = s->mfvol[ww]; if (isempty[mfv->i] || isempty[mfv->j]) continue; if (mfv->area != H2D_ANY && !wf->is_in_area(marker, mfv->area)) continue; m = mfv->i; fv = spss[m]; am = &al[m]; n = mfv->j; fu = pss[n]; an = &al[n]; bool tra = (m != n) && (mfv->sym != 0); bool sym = (m == n) && (mfv->sym == 1); // assemble the local stiffness matrix for the form mfv scalar bi, **mat = get_matrix_buffer(std::max(am->cnt, an->cnt)); for (int i = 0; i < am->cnt; i++) { if (!tra && (k = am->dof[i]) < 0) continue; fv->set_active_shape(am->idx[i]); if (!sym) // unsymmetric block { for (int j = 0; j < an->cnt; j++) { fu->set_active_shape(an->idx[j]); bi = eval_form(mfv, u_ext, fu, fv, refmap+n, refmap+m) * an->coef[j] * am->coef[i]; if (an->dof[j] >= 0) mat[i][j] = bi; } } else // symmetric block { for (int j = 0; j < an->cnt; j++) { if (j < i && an->dof[j] >= 0) continue; fu->set_active_shape(an->idx[j]); bi = eval_form(mfv, u_ext, fu, fv, refmap+n, refmap+m) * an->coef[j] * am->coef[i]; if (an->dof[j] >= 0) mat[i][j] = mat[j][i] = bi; } } } // insert the local stiffness matrix into the global one jac->add(am->cnt, an->cnt, mat, am->dof, an->dof); // insert also the off-diagonal (anti-)symmetric block, if required if (tra) { if (mfv->sym < 0) chsgn(mat, am->cnt, an->cnt); transpose(mat, am->cnt, an->cnt); jac->add(am->cnt, an->cnt, mat, am->dof, an->dof); } } } //// assemble volume linear forms //////////////////////////////////////// if (rhs != NULL) { for (unsigned int ww = 0; ww < s->vfvol.size(); ww++) { WeakForm::VectorFormVol* vfv = s->vfvol[ww]; if (isempty[vfv->i]) continue; if (vfv->area != H2D_ANY && !wf->is_in_area(marker, vfv->area)) continue; m = vfv->i; fv = spss[m]; am = &al[m]; for (int i = 0; i < am->cnt; i++) { if (am->dof[i] < 0) continue; fv->set_active_shape(am->idx[i]); rhs->add(am->dof[i], eval_form(vfv, u_ext, fv, refmap + m) * am->coef[i]); } } } // assemble surface integrals now: loop through boundary edges of the element for (unsigned int edge = 0; edge < e0->nvert; edge++) { if (!bnd[edge]) continue; marker = ep[edge].marker; // obtain the list of shape functions which are nonzero on this edge for (unsigned int i = 0; i < s->idx.size(); i++) { if (e[i] == NULL) continue; int j = s->idx[i]; if ((nat[j] = (spaces[j]->bc_type_callback(marker) == BC_NATURAL))) spaces[j]->get_edge_assembly_list(e[i], edge, al + j); } // assemble surface matrix forms /////////////////////////////////// if (jac != NULL) { for (unsigned int ww = 0; ww < s->mfsurf.size(); ww++) { WeakForm::MatrixFormSurf* mfs = s->mfsurf[ww]; if (isempty[mfs->i] || isempty[mfs->j]) continue; if (mfs->area != H2D_ANY && !wf->is_in_area(marker, mfs->area)) continue; m = mfs->i; fv = spss[m]; am = &al[m]; n = mfs->j; fu = pss[n]; an = &al[n]; if (!nat[m] || !nat[n]) continue; ep[edge].base = trav.get_base(); ep[edge].space_v = spaces[m]; ep[edge].space_u = spaces[n]; scalar bi, **mat = get_matrix_buffer(std::max(am->cnt, an->cnt)); for (int i = 0; i < am->cnt; i++) { if ((k = am->dof[i]) < 0) continue; fv->set_active_shape(am->idx[i]); for (int j = 0; j < an->cnt; j++) { fu->set_active_shape(an->idx[j]); bi = eval_form(mfs, u_ext, fu, fv, refmap+n, refmap+m, ep+edge) * an->coef[j] * am->coef[i]; if (an->dof[j] >= 0) mat[i][j] = bi; } } jac->add(am->cnt, an->cnt, mat, am->dof, an->dof); } } // assemble surface linear forms ///////////////////////////////////// if (rhs != NULL) { for (unsigned ww = 0; ww < s->vfsurf.size(); ww++) { WeakForm::VectorFormSurf* vfs = s->vfsurf[ww]; if (isempty[vfs->i]) continue; if (vfs->area != H2D_ANY && !wf->is_in_area(marker, vfs->area)) continue; m = vfs->i; fv = spss[m]; am = &al[m]; if (!nat[m]) continue; ep[edge].base = trav.get_base(); ep[edge].space_v = spaces[m]; for (int i = 0; i < am->cnt; i++) { if (am->dof[i] < 0) continue; fv->set_active_shape(am->idx[i]); rhs->add(am->dof[i], eval_form(vfs, u_ext, fv, refmap+m, ep+edge) * am->coef[i]); } } } } delete_cache(); } trav.finish(); } for (int i = 0; i < wf->neq; i++) delete spss[i]; delete [] buffer; buffer = NULL; mat_size = 0; }
int call_modify (int argc, char **argv) { struct ds_modifyentry_arg mod_arg; struct DSError error; struct entrymod *emnew, *ems_append(), *modify_avs(); Attr_Sequence as, #ifdef TURBO_DISK fget_attributes (), #else get_attributes (), #endif temp, trail = NULLATTR; AV_Sequence avst = NULLAV; extern AttributeType at_objectclass; extern int parse_status; Entry entry_ptr; FILE *fd; char draft_flag = FALSE; char noedit_flag = FALSE; int x; DN moddn; char *home; RDN new_rdn; struct list_element *start = 0 ; struct list_element *last ; struct list_element *l_temp ; /* char add = FALSE ; char rem = FALSE ; */ if ((argc = service_control (OPT, argc, argv, &mod_arg.mea_common)) == -1) return; mod_arg.mea_changes = NULLMOD; new_draft = FALSE; if (home = getenv ("DISHDRAFT")) strcpy (fname, home); else if (dad_flag) { strcpy (fname, "/tmp/dishXXXXXX"); unlink (mktemp (fname)); } else if (home = getenv ("HOME")) sprintf (fname, "%s/.dishdraft", home); else strcpy (fname, "./.dishdraft"); for (x=1; x<argc; x++) { if (test_arg (argv[x], "-draft",1)) { draft_flag = 1; shuffle_up (argc--,argv,x); if (x == argc) { ps_printf (OPT, "Draft file name missing\n"); Usage (argv[0]); return; } strcpy (fname, argv[x]); shuffle_up (argc--,argv,x--); } else if (test_arg (argv[x], "-newdraft",2)) { new_draft = TRUE; shuffle_up (argc--,argv,x--); } else if (test_arg (argv[x], "-noedit",3)) { noedit_flag = TRUE; shuffle_up (argc--,argv,x--); } else if (move (argv[x]) == OK) shuffle_up (argc--,argv,x--); else if (test_arg(argv[x], "-remove", 3)) { shuffle_up (argc--, argv, x); if (x == argc) { ps_printf(OPT, "Attribute to remove missing\n") ; Usage(argv[0]) ; return ; } l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ; l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1)); strcpy (l_temp->mod, argv[x]) ; l_temp->add = 0 ; l_temp->next = 0 ; if (start == 0) { start = last = l_temp ; } else { last->next = l_temp ; last = l_temp ; } shuffle_up (argc--,argv,x--); } else if (test_arg(argv[x], "-add", 2)) { shuffle_up (argc--, argv, x); if (x == argc) { ps_printf(OPT, "Attribute to insert missing\n") ; Usage(argv[0]) ; return ; } l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ; l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1)); strcpy (l_temp->mod, argv[x]) ; l_temp->add = 1 ; l_temp->next = 0 ; if (start == 0) { start = last = l_temp ; } else { last->next = l_temp ; last = l_temp ; } shuffle_up (argc--,argv,x--); } } if (dad_flag && (draft_flag || noedit_flag)) { ps_printf (OPT, "operation not allowed when using directory assistance server!\n"); return; } /* read attributes we want to modify */ if ((argc = read_cache_aux (argc, argv, FALSE, &mod_arg.mea_common)) <0 ) return; if (argc != 1) { ps_printf (OPT,"Unknown option %s\n",argv[1]); Usage (argv[0]); return; } if (start != 0) { if (build_modify(start, &mod_arg) == NOTOK) { return ; } while (ds_modifyentry (&mod_arg, &error) != DS_OK) { if (dish_error (OPT, &error) == 0) { return ; } mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name ; } ps_print (RPS, "Modified "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\n"); delete_cache (dn); /* re-cache when next read */ return ; } if (!draft_flag) { if (mod_template (fname,noedit_flag) != OK) return; noedit_flag = FALSE; } else { new_draft = TRUE; /* Ugh ! */ mod_template ("/dev/null",TRUE); } if (! noedit_flag) if (editentry (1, argv) != OK) { make_old (fname,draft_flag); return; } /* now parse the files */ if ((fd = fopen (fname, "r")) == (FILE *) NULL) { ps_printf (OPT, "Can't open draft entry %s\n", fname); return; } entry_ptr = get_default_entry (NULLENTRY); #ifdef TURBO_DISK entry_ptr->e_attributes = fget_attributes (fd); #else entry_ptr->e_attributes = get_attributes (fd); #endif fclose (fd); if (parse_status != 0) return; mod_arg.mea_object = dn; for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent) ; entry_ptr->e_name = rdn_cpy (moddn->dn_rdn); /* add rdn as attribute */ for (new_rdn = entry_ptr->e_name; new_rdn != NULLRDN; new_rdn = new_rdn->rdn_next) { avst = avs_comp_new (AttrV_cpy (&new_rdn->rdn_av)); temp = as_comp_new (AttrT_cpy (new_rdn->rdn_at), avst, NULLACL_INFO); entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp); } for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; trail = as->attr_link; as->attr_link = NULLATTR; temp = current_entry->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) { /* found it - does it need changing ? */ if (avs_cmp (as->attr_value, temp->attr_value) != 0) emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type); break; } if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_ADDATTRIBUTE; emnew->em_what = as_cpy(as); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); as->attr_link = trail; } /* remove attribute missing in new entry */ for (as = current_entry->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; temp = entry_ptr->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) break; if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_REMOVEATTRIBUTE; emnew->em_what = as_comp_new(as->attr_type,NULLAV,NULLACL_INFO); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); } if (mod_arg.mea_changes == NULLMOD) { ps_print (RPS, "The draft entry and the entry for "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\nare exactly the same - no change made!!!\n"); entry_free (entry_ptr); make_old (fname,draft_flag); return; } if (rebind () != OK) { entry_free (entry_ptr); return; } /* * If this operation is time-stamped, it may have expired while the user * was editing the entry. Re-calculate the time-stamp. Modify is the only * dish command where this needs to be done. */ if ((mod_arg.mea_common.ca_security != (struct security_parms *) 0) && (mod_arg.mea_common.ca_security->sp_time != NULLCP)) { char *new_version(); free(mod_arg.mea_common.ca_security->sp_time); mod_arg.mea_common.ca_security->sp_time = new_version(); } /* If security parameters are present, take this to mean that strong * authentication is required. This disallows 'parms + no signature' * (pointless) and 'signature + no parms' (security risk). */ if (mod_arg.mea_common.ca_security != (struct security_parms *) 0) { extern struct SecurityServices *dsap_security; mod_arg.mea_common.ca_sig = (dsap_security->serv_sign)((caddr_t)&mod_arg, _ZModifyEntryArgumentDataDAS, &_ZDAS_mod); } while (ds_modifyentry (&mod_arg, &error) != DS_OK) { if (dish_error (OPT, &error) == 0) { entry_free (entry_ptr); return; } mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name; } ps_print (RPS, "Modified "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\n"); delete_cache (dn); /* re-cache when next read */ entry_free (entry_ptr); ems_part_free (mod_arg.mea_changes); make_old (fname,draft_flag); }
static int do_rm_cache(char **arg, char reply[REPLY_MAX]) { return delete_cache(arg[0], atoi(arg[1])); /* pkgname, userid */ }
main() { struct passwd *pw_entry ; struct passwd *getpwuid() ; struct stat buf ; int i = 1 ; int uid ; int um ; char pass1[LINESIZE] ; char pass2[LINESIZE] ; char Read_in_Stuff[LINESIZE] ; char **vecptr ; char *tmpdraft ; char home_dir[LINESIZE] ; char *p, *part1, *part2 ; char quipurc_file[100] ; char tailor_file[100] ; char user_name[9] ; char *localptr = Local ; char print_format = EDBOUT ; EntryInfo *ptr ; static CommonArgs ca = default_common_args; vecptr = (char **) malloc(100) ; vecptr[0] = malloc (LINESIZE) ; (void) strcpy(vecptr[0], "showentry") ; (void) strcpy(pass1, "x") ; (void) strcpy(pass2, "y") ; tmpdraft = malloc (LINESIZE) ; (void) strcpy(tmpdraft, "/tmp/dish-") ; if ((opt = ps_alloc (std_open)) == NULLPS) fatal (-62, "ps_alloc failed"); if (std_setup (opt, stderr) == NOTOK) fatal (-63, "std_setup failed"); if ((rps = ps_alloc (std_open)) == NULLPS) fatal (-64, "ps_alloc 2 failed"); if (std_setup (rps, stdout) == NOTOK) fatal (-65, "std_setup 2 failed"); (void) strcpy(filterstring, "userid=") ; /* Sort out files, userids etc. */ uid=getuid() ; if ((pw_entry=getpwuid(uid)) == 0) { ps_printf(rps, "Who are you? (no name for your uid number)\n") ; exit(1) ; } (void) strcpy(user_name, pw_entry->pw_name) ; (void) strcat(tmpdraft, user_name) ; if (getenv("HOME") == 0) { ps_printf(rps, "No home directory?!!") ; (void) strcpy(home_dir, pw_entry->pw_dir) ; } else { (void) strcpy(home_dir, getenv("HOME")) ; } (void) strcpy(quipurc_file, home_dir) ; (void) strcat(quipurc_file, "/.quipurc") ; (void) strcpy(tailor_file, isodefile ("dishinit", 1)); Manager[0] = 0; Password[0] = 0; Local[0] = 0; (void) stat(tailor_file, &buf) ; (void) seteuid(buf.st_uid) ; /* set effective to enable */ /* us to read protected file */ if ((fp_tailor = fopen(tailor_file, "r")) == 0) { ps_print(rps, "Can't open Tailor File. Abort.\n") ; exit(1) ; } while (fgets (Read_in_Stuff, LINESIZE, fp_tailor) != 0) { if (!strcmp(Read_in_Stuff, "##Anything after this line is copied into the users ~/.quipurc file\n")) { break ; } p = SkipSpace (Read_in_Stuff); if (( *p == '#') || (*p == '\0')) continue; /* ignore comments and blanks */ part1 = p; if ((part2 = index (p,':')) == NULLCP) { ps_printf (opt,"Seperator missing '%s'. Ignoring..\n",p); } *part2++ = '\0'; part2 = TidyString (part2); if (lexequ(part1, "manager") == 0) { (void) strcpy(Manager, part2) ; } else if (lexequ(part1, "password") == 0) { (void) strcpy(Password, part2) ; } else if (lexequ(part1, "local") == 0) { (void) strcpy(Local, part2) ; } else { ps_printf(rps, "Error in tailor. What's a %s?\n", part1) ; } } (void) setuid(uid) ; /* Restore Userid to original user. */ /* create ~/.quipurc file. NB this does eradicate anything in there. * (Theoretically nothing.) */ if (Manager[0] == 0) { ps_print(rps, "Can't find out the managers name\n") ; exit(1) ; } if (Password[0] == 0) { ps_print(rps, "Can't find out the managers password\n") ; exit(1) ; } if (Local[0] == 0) { ps_print(rps, "Can't find out where to search\n") ; exit(1) ; } um = umask(0177) ; if ((fp_quipurc = fopen(quipurc_file, "w")) == 0) { ps_printf(rps, "Can't open ~/.quipurc. Aborting..\n") ; exit(1) ; } (void) umask(um) ; if ((fileps = ps_alloc(std_open)) == NULLPS) { fatal (-66, "ps_alloc 2 failed"); } if (std_setup (fileps, fp_quipurc) == NOTOK) { fatal (-67, "std_setup 2 failed"); } /* Sorting out the bind section */ quipu_syntaxes() ; /* set up the needed function pointers */ dsap_init(&i, &vecptr) ; (void) strcpy(bindarg.dba_passwd, Password) ; bindarg.dba_version = DBA_VERSION_V1988; bindarg.dba_passwd_len = strlen(bindarg.dba_passwd) ; if ((bindarg.dba_dn = str2dn (Manager)) == NULLDN) { ps_printf (opt,"Invalid Manager name %s (???!)\n",Manager) ; exit(1) ; } if (ds_bind (&bindarg, &binderr, &bindresult) != OK) { ps_printf(rps, "Can't bind as the manager.\n") ; exit(1); } /* Hopefully, should be successfully bound */ /* * We now call the search stuff with the right bits, to see if we can get a * match of uid='user_name'. Once there, we echo lots of information from * their entry out to the .quipurc file. * Hopefully there should only be one match. This assumes that ALL dir info * up to date, and that SG do not allow multiple users with the same login. */ /* set up the appropriate structures and defaults. */ search_arg.sra_common = ca; /* struct copy */ search_arg.sra_common.ca_servicecontrol.svc_sizelimit = 2 ; search_arg.sra_eis.eis_allattributes = FALSE ; search_arg.sra_searchaliases = FALSE; search_arg.sra_subset = SRA_ONELEVEL; search_arg.sra_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES ; search_arg.sra_eis.eis_select = NULLATTR ; search_arg.sra_eis.eis_allattributes = TRUE ; search_arg.sra_filter = filter_alloc() ; /* Default filter. */ search_arg.sra_filter->flt_next = NULLFILTER; search_arg.sra_filter->flt_type = FILTER_ITEM; search_arg.sra_filter->FUFILT = NULLFILTER; if (*localptr == '@') { localptr++; } if ((search_arg.sra_baseobject = str2dn(localptr)) == NULLDN) { ps_printf (opt,"Invalid sequence in username %s.\n", localptr); exit(1) ; } (void) strcat(filterstring, user_name) ; search_arg.sra_filter->flt_un.flt_un_item.fi_type = FILTERITEM_EQUALITY ; if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type = AttrT_new ("userid")) == NULLAttrT) { ps_printf(rps, "Oops, userid is not a valid attr type. ABORT!!\n") ; exit(1) ; } if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_value = str2AttrV (user_name, search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type->oa_syntax)) == NULLAttrV) { ps_printf(rps, "%s is not a valid attribute value.\n", user_name) ; } /* call search */ /* We now ought to be in the right place, and with the search stuff set, * ready to call search, and receive one (or no) entry back, which then * gets processed accordingly. */ if (ds_search (&search_arg, &search_error, &search_result) != DS_OK) { ps_printf(rps, "Search failed...\n") ; exit (1) ; /* This is not the same as coming back with */ /* message "search failed to find anything. */ } /* If the user does not exist in the DIT, print out the limited .quipurc * and the warning message, and allow the user to play DISH. */ if (search_result.CSR_entries == NULLENTRYINFO) { ps_printf(opt, "Unfortunately, you seem to have no entry in\n") ; ps_printf(opt, "the directory. Contact '%s' who should be able to help.\n", Manager) ; ps_printf(opt, "In the mean time, you can read, but not write.\n") ; } else { ptr = search_result.CSR_entries ; dn = dn_cpy(ptr->ent_dn) ; /* Essence of move user_name. */ /* collect the info and put it into current_entry */ /* Set up the desired attribute type to be read*/ /* from read.c */ if ((at = AttrT_new ("userPassword")) != NULLAttrT) { as_flag = as_merge (as_flag, as_comp_new (AttrT_cpy (at), NULLAV, NULLACL_INFO)); } else { ps_printf(rps, "Oops, Serious error. unknown attribute type 'userPassword'.\n") ; exit(1) ; } if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY) { read_arg.rda_common = ca; /* struct copy */ read_arg.rda_object = dn; read_arg.rda_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES; read_arg.rda_eis.eis_allattributes = TRUE ; read_arg.rda_eis.eis_select = NULLATTR ; if (ds_read (&read_arg, &read_error, &read_result) != DS_OK) { ps_printf(rps, "We even seem to be having problems reading\n" ) ; ps_printf(rps, "an entry we searched and found!! HELP!!\n") ; exit(1) ; } if (read_result.rdr_entry.ent_attr == NULLATTR) { ps_printf(rps, "No attributes present. Even though\n") ; ps_printf(rps, "we found you by userid attribute!!! HELP!!\n") ; exit (1) ; } cache_entry (&(read_result.rdr_entry), read_arg.rda_eis.eis_allattributes, TRUE) ; } if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY) { ps_printf(rps, "We still have nothing.Even after reading? Abort.\n") ; exit(1) ; } ps_printf(fileps, "username: "******"\n") ; ps_printf(fileps, "me: ") ; dn_print(fileps, dn, EDBOUT) ; ps_printf(fileps, "\n") ; /* now showattribute -nokey to display it. */ ps_printf(fileps, "password: "******"You need a password...\n") ; (void) strcpy(pass1, getpassword("Enter Password: "******"Re-enter password: "******"\nMismatch - Try again.\n") ; } } ps_printf(fileps, "%s\n", pass1) ; um = umask(0177) ; if ((fp_draft = fopen(tmpdraft, "w")) == 0) { ps_print(rps, "Can't open draft file... Abort.\n") ; exit(1) ; } (void) umask(um) ; (void) fprintf(fp_draft, "UserPassword = %s\n", pass1) ; (void) fprintf(fp_draft, "acl = self # write # attributes # acl $ userPassword\n") ; (void) fprintf(fp_draft, "acl = others # compare # attributes # acl $ userPassword\n\n") ; (void) fclose(fp_draft) ; if ((fp_draft = fopen (tmpdraft, "r")) == NULL) { ps_printf (opt, "Can't open draft entry %s\n", tmpdraft); exit(1) ; } entry_ptr = get_default_entry (NULLENTRY); #ifdef TURBO_DISK entry_ptr->e_attributes = fget_attributes (fp_draft); #else entry_ptr->e_attributes = get_attributes (fp_draft); #endif (void) fclose (fp_draft); mod_arg.mea_common = ca; /* struct copy */ mod_arg.mea_object = dn; for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent) ; entry_ptr->e_name = rdn_cpy (moddn->dn_rdn); /* add rdn as attribute */ avst = avs_comp_new (AttrV_cpy (&entry_ptr->e_name->rdn_av)); temp = as_comp_new (AttrT_cpy (entry_ptr->e_name->rdn_at), avst, NULLACL_INFO); entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp); for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; trail = as->attr_link; as->attr_link = NULLATTR; temp = current_entry->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) { /* found it - does it need changing ? */ if (avs_cmp (as->attr_value, temp->attr_value) != 0) emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type); break; } if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_ADDATTRIBUTE; emnew->em_what = as_cpy(as); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) { mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); } as->attr_link = trail; } while (ds_modifyentry (&mod_arg, &mod_error) != DS_OK) { if (dish_error (opt, &mod_error) == 0) { ps_printf(rps,"We have a dish error. Bye.\n") ; entry_free (entry_ptr); exit(1) ; } mod_arg.mea_object = mod_error.ERR_REFERRAL.DSE_ref_candidates->cr_name; } ps_print (rps, "Modified "); dn_print (rps, dn, EDBOUT); ps_print (rps, "\n"); delete_cache (dn); /* re-cache when next read */ entry_free (entry_ptr); ems_part_free (mod_arg.mea_changes); } } while(fgets(Read_in_Stuff, LINESIZE, fp_tailor) != 0) { fputs(Read_in_Stuff, fp_quipurc) ; } (void) fclose(fp_quipurc) ; (void) fclose(fp_tailor) ; /* (void) fprintf(fp_quipurc, "dsap: local_dit \"%s\"\n", Local) ; (void) fprintf(fp_quipurc, "notype: acl\n") ; (void) fprintf(fp_quipurc, "notype: treestructure\n") ; (void) fprintf(fp_quipurc, "notype: masterdsa\n") ; (void) fprintf(fp_quipurc, "notype: slavedsa\n") ; (void) fprintf(fp_quipurc, "notype: objectclass\n") ; (void) fprintf(fp_quipurc, "cache_time: 30\n") ; (void) fprintf(fp_quipurc, "connect_time: 2\n") ; */ (void) ds_unbind() ; (void) unlink(tmpdraft) ; }