/* Test function */ void test_canread_filename(char* filename) { if (canread(filename) == True) printf("Can read %s (access)\n", filename); else printf("Can not read %s (access)\n", filename); }
static void RunDocBrowser(void) { char buf[FILEPATH_LEN_MAX]; Esnprintf(buf, sizeof(buf), "%s/edox", EDirBin()); if (!canexec(buf)) return; Esnprintf(buf, sizeof(buf), "%s/E-docs/MAIN", EDirRoot()); if (!canread(buf)) return; Esnprintf(buf, sizeof(buf), "%s/edox %s/E-docs", EDirBin(), EDirRoot()); Espawn(buf); }
static int processinput (int waitflag) { fd_set fdset; #ifndef FEATURE_MS struct timeval tz, *tzp; #else HANDLE evs[MAXIMUM_WAIT_OBJECTS]; int evn; #endif int n, rtn; int ioi; rtn = 0; while (Gprocessevents (FALSE, G_MANYEVENTS)) rtn = 1; #ifndef FEATURE_MS for (ioi = 0, n = 0; ioi < ion; ioi++) if ( iop[ioi].inuse && iop[ioi].ismonitored && FD_ISSET (fileno (iop[ioi].ifp), &inputfds) && canread (iop[ioi].ifp) ) GFXmonitorfile (ioi), n++; if (n || rtn) return 1; if (Gneedredraw) return 0; tz = (waitflag && !rtn) ? longwait : zerowait; tzp = &tz; fdset = inputfds; if ((n = select (FD_SETSIZE, &fdset, NULL, NULL, tzp)) <= 0) return rtn; rtn = 1; if (FD_ISSET (Gxfd, &fdset)) Gprocessevents (TRUE, G_MANYEVENTS), n--; if (!n) return rtn; Gsync (); for (ioi = 0; n > 0 && ioi < ion; ioi++) if ( iop[ioi].inuse && iop[ioi].ismonitored && FD_ISSET (fileno (iop[ioi].ifp), &fdset) ) GFXmonitorfile (ioi), n--; #else for (ioi = 0, n = 0, evn = 0; ioi < ion; ioi++) { if (!iop[ioi].inuse || !IOismonitored (ioi)) continue; if ( (iop[ioi].type == IO_FILE && canread (iop[ioi].ifp)) || (iop[ioi].type == IO_PIPE && iop[ioi].buf[0]) ) GFXmonitorfile (ioi), n++; if (iop[ioi].type != IO_PIPE) continue; evs[evn++] = iop[ioi].ifp; } if (n) return 1; if (Gneedredraw) return 0; n = MsgWaitForMultipleObjects ( evn, evs, FALSE, (waitflag && !rtn) ? 1 : 0, QS_ALLINPUT ); if (n == WAIT_TIMEOUT || n < WAIT_OBJECT_0 || n > WAIT_OBJECT_0 + evn) return rtn; if (n == WAIT_OBJECT_0 + evn) Gprocessevents (TRUE, G_MANYEVENTS); Gsync (); for (ioi = 0; ioi < ion; ioi++) if ( iop[ioi].inuse && IOismonitored (ioi) && (iop[ioi].type == IO_FILE || (iop[ioi].type == IO_PIPE && evs[n - WAIT_OBJECT_0] == iop[ioi].ifp)) ) GFXmonitorfile (ioi); #endif return rtn; }
int a_loadnames(MENU *pm,session_t *session){ FILE *fp; ITEM it; struct stat st; char buf[PATHLEN],name[PATHLEN],host[STRLEN],*p; int i; a_freenames(pm); memset(pm->p_item,0,(MAXITEMS*sizeof(ITEM**))); memset(pm->pool,0,(MAXITEMS*sizeof(ITEM*))); #ifdef ANN_COUNT sprintf(name,"%s/counter.person",pm->path); pm->count=0; if((fp=fopen(name,"r"))){ fgets(buf,PATHLEN,fp); if(isdigit(buf[0])) pm->count=atoi(buf); fclose(fp); } pm->count++; if((fp=fopen(name,"w"))){ fprintf(fp,"%d",pm->count); fclose(fp); } #endif /* ANN_COUNT */ sprintf(name,"%s/.Names",pm->path); if(stat(name,&st)==-1||!S_ISREG(st.st_mode)) return 0; pm->modified_time=st.st_mtime; if(!(fp=fopen(name,"r"))) return -1; pm->mtitle[MTITLE_LEN-1]=0; it.title[ITITLE_LEN-1]=0; it.fname[STRLEN-1]=0; host[STRLEN-1]=0; while(fgets(buf,PATHLEN,fp)){ if((p=strchr(buf,'\n'))) *p=0; if(!strncmp(buf,"Name=",5)){ strncpy(it.title,&buf[5],(ITITLE_LEN-1)); it.attachpos=0; host[0]=0; } else if(!strncmp(buf,"Path=",5)){ strncpy(it.fname,&buf[(buf[5]=='~'&&buf[6]=='/')?7:5],(STRLEN-1)); if(it.fname[0]=='.'&&it.fname[1]=='.') continue; if(strstr(it.fname,"!@#$%")){ strcpy(name,it.fname); if((p=strtok(name,"!@#$%"))) strncpy(host,p,(STRLEN-1)); if((p=strtok(NULL,"!@#$%"))) strncpy(it.fname,p,(STRLEN-1)); if((p=strtok(NULL,"!@#$%"))) it.port=atoi(p); } if(a_additem_base(pm,it.title,it.fname,(!host[0]?NULL:host),it.port,it.attachpos)==-2) break; } else if(!strncmp(buf,"# Title=",8)){ if(!(pm->mtitle[0])) strncpy(pm->mtitle,&buf[8],(MTITLE_LEN-1)); } else if(!strncmp(buf,"Host=",5)) strncpy(host,&buf[5],(STRLEN-1)); else if(!strncmp(buf,"Port=",5)) it.port=atoi(&buf[5]); else if(!strncmp(buf,"Attach=",7)) it.attachpos=atol(&buf[7]); else continue; } fclose(fp); for(i=0;i<pm->total;i++){ #ifdef ANN_CTRLK if(!canread(pm->level,pm->path,pm->pool[i]->fname,pm->pool[i]->title)) continue; #endif /* ANN_CTRLK */ if(session&&!HAS_PERM(session->currentuser,PERM_SYSOP)){ if(!HAS_PERM(session->currentuser,PERM_BOARDS)&&(p=strstr(pm->pool[i]->title,"(BM: BMS)"))){ if(!(p-pm->pool[i]->title<38)) continue; } if((p=strstr(pm->pool[i]->title,"(BM: SYSOPS)"))){ if(!(p-pm->pool[i]->title<38)) continue; } if(!HAS_PERM(session->currentuser,PERM_SECANC)&&(p=strstr(pm->pool[i]->title,"(BM: ZIXIAs)"))){ if(!(p-pm->pool[i]->title<38)) continue; } } pm->p_item[pm->num++]=&pm->pool[i]; } if(!(pm->now<pm->num)) pm->now=(pm->num-1); if(pm->now<0) pm->now=0; return 1; }
/* 返回值意义: -1 没有权限 0 有看的权限 1 有管理的权限 */ int ann_traverse_check(char *path, struct userec *user) { char *ptr; char *ptr2; size_t i = 0; char filename[256]; char buf[256], *fnameptr; char pathbuf[256]; char currpath[256]; char title[STRLEN]; FILE *fp; char board[STRLEN]; bool has_perm_boards = false, sysop_only = false; char *bmstr; int bms_level = 0; /* path parameter can not have leading '/' character */ if (path[0] == '/') return -1; board[0] = '\0'; if ((ptr = strstr(path, "groups/")) != NULL) ann_get_board(ptr, board, sizeof(board)); bzero(pathbuf, sizeof(pathbuf)); if (board[0] == '\0') { ptr = path; } else { const struct boardheader *bh; bh = getbcache(board); if (check_read_perm(user, bh) == 0) return -1; ann_get_path(board, filename, sizeof(filename)); snprintf(pathbuf, sizeof(pathbuf), "0Announce%s", filename); ptr = path + strlen(pathbuf); i = strlen(pathbuf); /* 如果是本版版主 则获得版主权限 TODO */ if (chk_currBM(bh->BM, user)) has_perm_boards = true; } /* 如果是站务 则获得版主权限 */ if (HAS_PERM(user, PERM_OBOARDS) || HAS_PERM(user, PERM_ANNOUNCE) || HAS_PERM(user, PERM_SYSOP)) has_perm_boards = true; /* 开始逐级判断权限 */ while (*ptr != '\0') { if (*ptr == '/') { snprintf(filename, sizeof(filename), "%s/.Names", pathbuf); } else { if (i < sizeof(pathbuf)) pathbuf[i] = *ptr; ptr++; i++; continue; } if ((fp = fopen(filename, "r")) == NULL) return -1; while (fgets(buf, sizeof(buf), fp) != NULL) { if ((ptr2 = strrchr(buf, '\n')) != NULL) *ptr2 = '\0'; if (strncmp(buf, "Name=", 5) == 0) { strncpy(title, buf + 5, sizeof(title) - 1); title[sizeof(title) - 1] = '\0'; continue; } if (strncmp(buf, "Path=~/", 7) == 0) fnameptr = buf + 7; else if (strncmp(buf, "Path=", 5) == 0) fnameptr = buf + 5; else continue; snprintf(currpath, sizeof(currpath), "%s/%s", pathbuf, fnameptr); if (strncmp(currpath, path, strlen(currpath)) != 0) continue; if (path[strlen(currpath)] != '/' && path[strlen(currpath)]!='\0' ) continue; /* 如果有指定BM 则按BM名单获得版主权限 */ bmstr = strstr(title, "(BM:"); if (bmstr != NULL) if (chk_currBM(bmstr + 4, user)) has_perm_boards = true; /* 如果指定BMS 则目录的版主权限级别升高 */ if (strstr(title, "(BM: BMS)")) bms_level++; /* 如果指定SYSOPS 则目录为仅站务可见 */ if (strstr(title, "(BM: SYSOPS)")) sysop_only = true; #ifdef ANN_CTRLK /* 如果Ctrl+K权限验证不通过 则禁止 */ if(!canread(has_perm_boards ? PERM_BOARDS : 0, pathbuf, fnameptr, title)) { fclose(fp); return -1; } #endif /* 如果在一级BMS目录下且用户不具备版主权限 则禁止 */ if ((bms_level >=1) && !HAS_PERM(user, PERM_BOARDS)) { fclose(fp); return -1; } /* 如果在二级BMS目录下且用户不具备本版版主权限 则禁止 */ if ((bms_level >=2) && !has_perm_boards) { fclose(fp); return -1; } /* 如果在SYSOPS目录下且用户不是站务 则禁止 */ if (sysop_only && !HAS_PERM(user, PERM_SYSOP)) { fclose(fp); return -1; } break; } if (feof(fp)) { fclose(fp); return -1; } fclose(fp); if (i < sizeof(pathbuf)) pathbuf[i] = *ptr; ptr++; i++; } return has_perm_boards ? 1 : 0; }
/* Runs the svn st command and deletes the files that fit */ void run(char* command) { FILE *fp; char cmd[STRING_LENGTH]; char filename[STRING_LENGTH]; char line[STRING_LENGTH]; char curdir[STRING_LENGTH]; char short_filename[STRING_LENGTH]; char slash[2]; int result; int i; int firstletterpos; #ifdef __linux__ strcpy(slash, "/"); #else strcpy(slash, "\\"); #endif getcwd(curdir, STRING_LENGTH); /* curdir = (curdir += slash) */ strcat(curdir, slash); fp = popen(command, "r"); while (fgets(line, sizeof line, fp)) { if ((line[0] == '?') || (line[0] == 'M') || (line[0] == 'I')) { /* Remove the newline at the end of the string */ line[strlen(line) - 1] = '\0'; /* filename (points to filename) = curdir (points to curdir) */ strcpy(filename, curdir); /* find the first letter */ firstletterpos = 8; for (i=1; i <= 8; i++) { if (line[i] != ' ') { #ifdef CENTOS firstletterpos = i - 1; #else firstletterpos = i; #endif } } /* short filename */ strcpy(short_filename, line + firstletterpos); /* filename (points to filename) += line[8:] */ strcat(filename, short_filename); if (canread(filename) && !isdir(filename)) { printf("Deleting %s\n", short_filename); #ifdef __linux__ sprintf(cmd, "rm %s", filename); #else sprintf(cmd, "del %s", filename); #endif /* printf("cmd #1: %s\n", cmd); */ result = system(cmd); } else { printf("Deleting %s%s\n", short_filename, slash); /* Try deleting the directory */ #ifdef __linux__ sprintf(cmd, "rm -rf %s", filename); #else sprintf(cmd, "rd %s /S /Q", filename); #endif result = system(cmd); if (result != True) { printf("Deleting %s failed.\n", filename); } } } } pclose(fp); }