int delHT(struct HT *ht, void *data) { int h; h = ((*(ht->hash))(data)) % ht->nb_lists; ht->lists[h] = del_entry(ht->lists[h], data, ht->cmpdata, ht->deldata); return 1; }
static int del_file(direntry_t *entry, MainParam_t *mp) { char shortname[13]; direntry_t subEntry; Stream_t *SubDir; Arg_t *arg = (Arg_t *) mp->arg; MainParam_t sonmp; int ret; int r; sonmp = *mp; sonmp.arg = mp->arg; r = 0; if (IS_DIR(entry)){ /* a directory */ SubDir = OpenFileByDirentry(entry); initializeDirentry(&subEntry, SubDir); ret = 0; while((r=vfat_lookup(&subEntry, "*", 1, ACCEPT_DIR | ACCEPT_PLAIN, shortname, NULL)) == 0 ){ if(shortname[0] != DELMARK && shortname[0] && shortname[0] != '.' ){ if(arg->deltype != 2){ fprintf(stderr, "Directory "); fprintPwd(stderr, entry,0); fprintf(stderr," non empty\n"); ret = ERROR_ONE; break; } if(got_signal) { ret = ERROR_ONE; break; } ret = del_file(&subEntry, &sonmp); if( ret & ERROR_ONE) break; ret = 0; } } FREE(&SubDir); if (r == -2) return ERROR_ONE; if(ret) return ret; } return del_entry(entry, mp); }
int do_unlink(char *name) { char *basename; int namelen; struct m_inode *dir,*inode; // struct buffer_head *bh; struct dir_entry *de; if(!(dir = dir_namei(name,&basename,&namelen))) { //no such file or direntry return -ENOENT; } if(!namelen) { iput(dir); return -ENOENT; } //删除目录项 if((del_entry(dir,basename,namelen,&de)) != 0) { printk("no such file"); iput(dir); return -ENOENT; } if(!(inode = iget(dir->i_dev,de->inode_num))) { iput(dir); return -ENOENT; } //not permit to del direntry if(S_ISDIR(inode->i_mode)) { iput(inode); iput(dir); return -EPERM; } if(--(inode->i_count)) { printk("deleting using file\n"); return -EMLINK; } de->inode_num = 0; inode->i_dirt = 1; iput(inode); iput(dir); printk("delete file successful\n"); return 0; }
main () { char choice; init_db (); /* initialize "database" */ while (1) { choice = menu_sel (); switch (choice) { case 1: add_entry (); break; case 2: del_entry (); break; case 3: list_db (); break; case 4: exit (0); /* exit the program */ } /* switch */ } /* while */ } /* main */
void fab_op(CALL *call,int op,const struct atm_qos *qos, void (*callback)(CALL *call,int cause,void *more,void *user),void *user) { int error,error2; diag(COMPONENT,DIAG_INFO,"fab_op%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", !op ? " FREE" : "",op & RM_RSV(_RM_ANY) ? " RM_RSV:" : "", op & RM_IN_TX ? " IN_TX" : "",op & RM_IN_RX ? " IN_RX" : "", op & RM_OUT_TX ? " OUT_TX" : "",op & RM_OUT_RX ? " OUT_RX" : "", op & RM_PATH_TX ? " PATH_TX" : "",op & RM_PATH_RX ? " PATH_RX" : "", op & RM_CLAIM(_RM_ANY) ? " RM_CLAIM:" : "", op & _RM_SHIFT(RM_IN_TX) ? " IN_TX" : "", op & _RM_SHIFT(RM_IN_RX) ? " IN_RX" : "", op & _RM_SHIFT(RM_OUT_TX) ? " OUT_TX" : "", op & _RM_SHIFT(RM_OUT_RX) ? " OUT_RX" : "", op & _RM_SHIFT(RM_PATH_TX) ? " PATH_TX" : "", op & _RM_SHIFT(RM_PATH_RX) ? " PATH_RX" : ""); if (op & (RM_RSV(RM_IN) | RM_CLAIM(RM_IN))) { if (!check_ci(&call->in.pvc)) { callback(call,ATM_CV_CI_UNAVAIL,NULL,user); return; } call->in.qos = *qos; } if (op & (RM_RSV(RM_OUT) | RM_CLAIM(RM_OUT))) { if (!check_ci(&call->out.pvc)) { callback(call,ATM_CV_CI_UNAVAIL,NULL,user); return; } call->out.qos = *qos; } if (op & RM_CLAIM(RM_PATH)) { error = 0; if (call->in.qos.txtp.traffic_class != ATM_NONE) error = add_entry(&call->in.pvc,&call->out.pvc); if (!error) { if (call->in.qos.rxtp.traffic_class != ATM_NONE) error = add_entry(&call->out.pvc,&call->in.pvc); if (error && call->in.qos.txtp.traffic_class != ATM_NONE) { error2 = del_entry(&call->in.pvc,&call->out.pvc); if (error2) diag(COMPONENT,DIAG_ERROR,"del_entry: %s",strerror(error2)); } } if (error) { diag(COMPONENT,DIAG_ERROR,"add_entry: %s",strerror(error)); callback(call,ATM_CV_RES_UNAVAIL,NULL,user); return; } PRV(call)->active = 1; } if (!op && PRV(call)->active) { error = error2 = 0; if (call->in.qos.txtp.traffic_class != ATM_NONE) { error = del_entry(&call->in.pvc,&call->out.pvc); if (error) diag(COMPONENT,DIAG_ERROR,"del_entry: %s",strerror(error)); } if (call->in.qos.rxtp.traffic_class != ATM_NONE) { error2 = del_entry(&call->out.pvc,&call->in.pvc); if (error2) diag(COMPONENT,DIAG_ERROR,"del_entry: %s",strerror(error2)); } if (error || error2) { callback(call,ATM_CV_TEMP_FAIL,NULL,user); return; } } callback(call,0,NULL,user); }
int main() { int i, gsiproxylimit_i = 1, delegation = 0; char *cmd, *dir_uri, *file, *dir_path, *admin_file, *dn = NULL, *help_uri, *p, *content_type, *request_uri, *button, *grst_auri_i, *grst_valid_i, *gsiproxylimit, buf[12]; GRSTgaclCred *cred; GRSTgaclUser *user = NULL; GRSTgaclAcl *acl; GRSTgaclPerm perm = GRST_PERM_NONE; help_uri = getenv("REDIRECT_GRST_HELP_URI"); /* can be NULL */ admin_file = getenv("REDIRECT_GRST_ADMIN_FILE"); dir_path = getenv("REDIRECT_GRST_DIR_PATH"); request_uri = getenv("REQUEST_URI"); if ((dir_path == NULL) || (admin_file == NULL) || (request_uri == NULL)) { puts("Status: 500 Internal Server Error\nContent-type: text/plain\n\n" "REDIRECT_GRST_DIR_PATH or REDIRECT_GRST_ADMIN_FILE " "or REQUEST_URI missing"); return -1; } GRSTgaclInit(); gsiproxylimit = getenv("REDIRECT_GRST_GSIPROXY_LIMIT"); if (gsiproxylimit != NULL) sscanf(gsiproxylimit, "%d", &gsiproxylimit_i); grst_auri_i = getenv("GRST_CRED_AURI_0"); grst_valid_i = getenv("GRST_CRED_VALID_0"); if ((grst_auri_i != NULL) && (strncmp(grst_auri_i, "dn:", 3) == 0)) { dn = &grst_auri_i[3]; sscanf(grst_valid_i, "notbefore=%*ld notafter=%*ld delegation=%d nist-loa=%*d", &delegation); if (delegation <= gsiproxylimit_i) { cred = GRSTgaclCredCreate(grst_auri_i, NULL); user = GRSTgaclUserNew(cred); /* User has a cert so check for VOMS attributes etc */ for (i=1; ; i++) { sprintf (buf, "GRST_CRED_%d", i); grst_auri_i = getenv(buf); if (grst_auri_i == NULL) break; cred = GRSTgaclCredCreate(grst_auri_i, NULL); GRSTgaclUserAddCred(user, cred); } /* no more VOMS attributes etc found */ } } else if ((dn = getenv("SSL_CLIENT_S_DN")) != NULL) { cred = GRSTgaclCredCreate("dn:", GRSThttpUrlMildencode(dn)); user = GRSTgaclUserNew(cred); } if (GRSTgaclUserHasAURI(user, getenv("REDIRECT_GRST_ADMIN_LIST"))) perm = GRST_PERM_ALL; else { p = getenv("REMOTE_HOST"); if (p != NULL) { cred = GRSTgaclCredCreate("dns:", p); if (user == NULL) user = GRSTgaclUserNew(cred); else GRSTgaclUserAddCred(user, cred); } acl = GRSTgaclAclLoadforFile(dir_path); if (acl != NULL) perm = GRSTgaclAclTestUser(acl, user); } /* we're relying on being a CGI with all this un-free()ed strdup()ing */ dir_uri = strdup(request_uri); p = rindex(dir_uri, '?'); if (p != NULL) *p = '\0'; p = rindex(dir_uri, '/'); if (p != NULL) p[1] = '\0'; content_type = getenv("CONTENT_TYPE"); if ((content_type != NULL) && (GRSTstrCmpShort(content_type, "multipart/form-data; boundary=") == 0)) { uploadfile(dn, perm, help_uri, dir_path, dir_uri, admin_file); return 0; } cmd = GRSThttpGetCGI("cmd"); button = GRSThttpGetCGI("button"); file = GRSThttpGetCGI("file"); if ((index(file, '/') != NULL) || (index(file, '<') != NULL) || (index(file, '>') != NULL) || (index(file, '&') != NULL) || (index(file, '"') != NULL)) file[0] = '\0'; /* file and directory functions in grst_admin_file.c */ if (strcmp(cmd, "header") == 0) justheader(dn, perm, help_uri, dir_path, dir_uri, admin_file); else if (strcmp(cmd, "footer") == 0) justfooter(dn, perm, help_uri, dir_path, dir_uri, admin_file); else if (strcmp(cmd, "managedir") == 0) managedir(dn, perm, help_uri, dir_path, dir_uri, admin_file); else if (strcmp(cmd, "print") == 0) printfile(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "history") == 0) filehistory(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "managednlists") == 0) managednlists(user, dn, perm, help_uri, dir_path, dir_uri, admin_file); else if (strcmp(cmd, "editdnlist") == 0) editdnlistform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "edit") == 0) { if ((strcasecmp(button, "new directory") == 0) || (strcasecmp(button, "Create") == 0)) newdirectory(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else editfileform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); } else if (strcmp(cmd, "editaction") == 0) editfileaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "editdnlistaction") == 0) editdnlistaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "delete") == 0) deletefileform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "deleteaction") == 0) deletefileaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "rename") == 0) renameform(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "renameaction") == 0) renameaction(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "ziplist") == 0) ziplist(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "unzipfile") == 0) unzipfile(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "create_acl") == 0) create_acl(dn, perm, help_uri, dir_path, file, dir_uri, admin_file); /* GACL functions in grst_admin_gacl.c */ else if (strcmp(cmd, "show_acl") == 0) show_acl(0, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "admin_acl") == 0) show_acl(1, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "acl_history") == 0) show_acl(2, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd, "revert_acl") == 0) revert_acl(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); //show_acl(2, user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"new_entry_form")==0) new_entry_form(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"new_entry")==0) new_entry(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"del_entry_sure")==0) del_entry_sure(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"del_entry")==0) del_entry(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"edit_entry_form")==0) edit_entry_form(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"edit_entry")==0) edit_entry(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"add_cred_form")==0) add_cred_form(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"add_cred")==0) add_cred(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"del_cred_sure")==0) del_cred_sure(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); else if (strcmp(cmd,"del_cred")==0) del_cred(user, dn, perm, help_uri, dir_path, file, dir_uri, admin_file); /* you what? */ else GRSThttpError("500 Internal Server Error"); }