int bbsfadd_main(void) { if (!loginok) return BBS_ELGNREQ; const char *id = getparm("id"); const char *desc = getparm("desc"); if (*id != '\0') { override_t ov; memset(&ov, 0, sizeof(ov)); strlcpy(ov.id, id, sizeof(ov.id)); if (!searchuser(ov.id)) return BBS_ENOUSR; strlcpy(ov.exp, desc, sizeof(ov.exp)); char file[HOMELEN]; sethomefile(file, currentuser.userid, "friends"); if (get_num_records(file, sizeof(ov)) == MAXFRIENDS) return BBS_EFRNDQE; // TODO: be atomic if (!search_record(file, NULL, sizeof(ov), cmpname, ov.id)) append_record(file, &ov, sizeof(ov)); printf("Location: fall\n\n"); return 0; } xml_header("bbs"); printf("<bbsfadd "); print_session(); printf(">%s</bbsfadd>", id); return 0; }
static int retrieve_backup(userec_t *user) { int uid; char src[PATHLEN], dst[PATHLEN]; char ans; if ((uid = searchuser(user->userid, user->userid))) { userec_t orig; passwd_sync_query(uid, &orig); strlcpy(user->passwd, orig.passwd, sizeof(orig.passwd)); setumoney(uid, user->money); passwd_sync_update(uid, user); return 0; } ans = vans("目前的 PASSWD 檔沒有此 ID,新增嗎?[y/N]"); if (ans != 'y') { vmsg("目前的 PASSWDS 檔沒有此 ID,請先新增此帳號"); return -1; } if (setupnewuser((const userec_t *)user) >= 0) { sethomepath(dst, user->userid); if (!dashd(dst)) { snprintf(src, sizeof(src), "tmp/%s", user->userid); if (!dashd(src) || !Rename(src, dst)) mkuserdir(user->userid); } return 0; } return -1; }
// Similar to 'getuserec', // but stores result in global variable 'lookupuser'. int getuser(const char *userid) { int uid = searchuser(userid); if (uid == 0) return 0; lookupuser = uidshm->passwd[uid - 1]; return uid; }
// Gets struct userec in cache for all users according to 'userid'. // struct userec is stored in *'u'. Returns uid. int getuserec(const char *userid, struct userec *u) { int uid = searchuser(userid); if (uid == 0) return 0; *u = uidshm->passwd[uid - 1]; return uid; }
/* int apply_users(func) void (*func)() ; { register int i ; resolve_ucache() ; for(i=0; i < uidshm->number; i++) (*func)(uidshm->userid[i],i+1) ; return 0 ; } */ int getuser(char* userid) { int uid = searchuser(userid); if (uid == 0) return 0; get_record(PASSFILE, &lookupuser, sizeof(lookupuser), uid); return uid; }
int update_user_score(const char* userid, int score) { int uidx = searchuser(userid) - 1; if(uidx < 0) return -1; userlist[uidx]->score += score; scorelist[uidx].base_score = userlist[uidx]->score; return uidx; }
static int check_multi(const struct userec *user) { int i, total = 0; int uid = searchuser(user->userid); for (i = 0; i < MAXACTIVE; i++) { if (utmpshm->uinfo[i].active == 0) continue; if (utmpshm->uinfo[i].uid == uid) total++; } return total; }
int getfriendstr(struct userec* user,struct user_info* puinfo,session_t * session) { int nf; int i; struct friends *friendsdata; char buf[60]; puinfo->friendsnum=0; if (session->topfriend != NULL) { free(session->topfriend); session->topfriend = NULL; } sethomefile(buf, user->userid, "friends"); nf = get_num_records(buf, sizeof(struct friends)); if (nf <= 0) return 0; if (nf>MAXFRIENDS) nf=MAXFRIENDS; friendsdata = (struct friends *) calloc(nf,sizeof(struct friends)); get_records(buf, friendsdata, sizeof(struct friends), 1, nf); for (i = 0; i < nf; i++) { friendsdata[i].id[IDLEN] = 0; friendsdata[i].exp[LEN_FRIEND_EXP-1] = 0; if (id_invalid(friendsdata[i].id)||(searchuser(friendsdata[i].id)==0)) { memcpy(&friendsdata[i], &friendsdata[nf - 1], sizeof(struct friends)); nf--; } } qsort(friendsdata, nf, sizeof(friendsdata[0]), cmpfuid); /*For Bi_Search */ session->topfriend = (struct friends_info *) calloc(nf,sizeof(struct friends_info)); for (i = 0; i < nf; i++) { puinfo->friends_uid[i] = searchuser(friendsdata[i].id); strcpy(session->topfriend[i].exp, friendsdata[i].exp); } free(friendsdata); puinfo->friendsnum=nf; return 0; }
void informBM(char *userid, boardheader_t *bptr, int nEXP) { int uid, i; char filename[256], buf[64]; fileheader_t mymail; FILE *fp; if( !(uid = searchuser(userid, userid)) ) return; sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid); stampfile(filename, &mymail); if( (fp = fopen(filename, "w")) == NULL ) return; printf("brdname: %s, BM: %s\n", bptr->brdname, userid); fprintf(fp, "作者: 系統通知.\n" "標題: 警告: 貴板板友即將過期/已經過期\n" "時間: %s\n" " %s 的板主您好: \n" " 下列貴板板友即將過期或已經過期:\n" "------------------------------------------------------------\n", CTIMEx(buf, now), bptr->brdname); for( i = 0 ; i < nEXP ; ++i ) if( explist[i].expire == -1 ) fprintf(fp, "%-15s 已經過期\n", explist[i].userid); else fprintf(fp, "%-15s 即將在 %s 過期\n", explist[i].userid, CTIMEx(buf, explist[i].expire)); fprintf(fp, "------------------------------------------------------------\n" "說明:\n" " 為了節省系統資源, 系統將自動清除掉超過四個月未上站\n" "的使用者. 此時若有某位您不認識的使用者恰好註冊了該帳號,\n" "將會視為貴板板友而放行進入.\n" " 建議您暫時將這些使用者自貴板的板友名單中移除.\n" "\n" " 這封信件是由程式自動發出, 請不要直接回覆這封信. 若\n" "您有相關問題請麻煩至看板 SYSOP, 或是直接與看板總管聯繫. :)\n" "\n" BBSNAME "站長群敬上" ); fclose(fp); strcpy(mymail.title, "警告: 貴板板友即將過期/已經過期"); strcpy(mymail.owner, "系統通知."); sprintf(filename, BBSHOME "/home/%c/%s/.DIR", userid[0], userid); mailalertuid(uid); append_record(filename, &mymail, sizeof(mymail)); }
void clear_aloha(char *direct) { char fname [PATHLEN]; char newfname [PATHLEN]; FILE *fp, *newfp; PAL pal; int count_r = 0, count_w = 0; sprintf(fname, "%s/%s", direct, FN_ALOHA); sprintf(newfname, "%s/%s.new", direct, FN_ALOHA); if(!(fp = fopen(fname, "r"))) { ca_log("%s: cannot open", fname); return; } if(!(newfp = fopen(newfname, "w"))) { fclose(fp); ca_log("%s: cannot open", newfname); return; } while(fread(&pal, sizeof(PAL), 1, fp) != 0) { count_r++; if(!pal.userid[0] || !searchuser(pal.userid)) continue; fwrite(&pal, sizeof(PAL), 1, newfp); count_w++; } ca_log("%s: delete %d bad records.", fname, count_r - count_w); fclose(fp); fclose(newfp); if(count_r - count_w != 0) { f_mv(fname, newfname); } else unlink(newfname); return; }
void setup_utmp(int mode) { user_info uinfo; char buf [80]; memset(&uinfo, 0, sizeof(uinfo)); uinfo.pid = currpid = getpid(); uinfo.uid = searchuser(cuser.userid); uinfo.mode = currstat = mode; uinfo.msgcount = 0; if (cuser.userlevel & PERM_BM) check_BM(); /* Ptt 自動取下離職板主權力 */ uinfo.userlevel = cuser.userlevel; uinfo.lastact = time(NULL); strcpy(uinfo.userid, cuser.userid); strcpy(uinfo.realname, cuser.realname); strcpy(uinfo.username, cuser.username); strcpy(uinfo.feeling, cuser.feeling); strncpy(uinfo.from, fromhost, 23); uinfo.invisible = cuser.invisible % 2; uinfo.pager = cuser.pager % 5; uinfo.brc_id = 0; uinfo.sex = cuser.sex; /* Ptt WHERE */ #ifdef WHERE uinfo.from_alias = where(fromhost); #else uinfo.from_alias = 0; #endif sethomefile(buf, cuser.userid, "remoteuser"); if (enter_uflag & CLOAK_FLAG) uinfo.invisible = YEA; getnewutmpent(&uinfo); friend_load(); }
void call_listen(chatcontext * pthis, const char *arg) { /* added by Luzi 1997.11.28 */ char path[40]; char uident[IDLEN + 1]; char ignoreuser[IDLEN + 1]; int nIdx; if (!*arg) { printchatline(pthis, "*** 请输入用户的ID ***"); } else if (!strcasecmp(arg, getCurrentUser()->userid)) printchatline(pthis, "*** 这是你自己的ID ***"); else { strncpy(uident, arg, IDLEN + 1); uident[IDLEN] = 0; if (!searchuser(uident)) /* change getuser -> searchuser, by dong, 1999.10.26 */ printchatline(pthis, "*** 没有这个ID ***"); else { sethomefile(path, getCurrentUser()->userid, "/ignores"); nIdx = search_record(path, ignoreuser, IDLEN + 1, (RECORD_FUNC_ARG) cmpinames, uident); if (nIdx <= 0) printchatline(pthis, "*** 该用户的聊天讯息没有被忽略啊 ***"); else if (delete_record(path, IDLEN + 1, nIdx, NULL, NULL) == 0) { bbslog("user", "listen %s", uident); printchatline(pthis, "*** 已恢复对该用户聊天讯息的接收 ***"); sprintf(uident, "/listen %s\n", uident); chat_send(pthis, uident); } else { bbslog("3error", "listen %s failed", uident); printchatline(pthis, "*** system error ***"); } } } }
int get_user_score(const char* userid) { struct userscore u_score[MAXUSERS]; int fd; int uidx; int flag; uidx = searchuser(userid) - 1; fd = open(".SCORES", O_RDONLY, 0655); if(fd < 0) { return 0; } flag = read(fd, u_score, sizeof(struct userscore)*MAXUSERS); close(fd); if(flag <= 0) { return 0; } if(u_score[uidx].userid[0] == 0) { return 0; } return u_score[uidx].base_score + u_score[uidx].ex_score; }
static void do_aloha(char *hello) { FILE *fp; char userid[80]; char genbuf[200]; setuserfile(genbuf, "aloha"); if((fp = fopen(genbuf, "r"))) { sprintf(genbuf, hello); while(fgets(userid, 80, fp)) { userinfo_t *uentp; int tuid; if((tuid = searchuser(userid)) && tuid != usernum && (uentp = (userinfo_t *)search_ulistn(cmpuids, tuid, 1)) && ((uentp->userlevel & PERM_SYSOP) || ((!currutmp->invisible || uentp->userlevel & PERM_SEECLOAK) && !(is_rejected(uentp) & 1)))) { my_write(uentp->pid, genbuf, uentp->userid, 2); } } fclose(fp); } }
int main(int argc, char *argv[]) { int fd; angel_beats_data req = {0}; angel_beats_report rpt = {0}; angel_beats_uid_list list = {0}; attach_SHM(); if (argc < 2) { fprintf(stderr, "Usage: %s operation [uid]\n", argv[0]); return 0; } if ( (fd = toconnect(ANGELBEATS_ADDR)) < 0 ) { perror("toconnect"); return 1; } // start commands if (strcmp(argv[1], "reload") == 0) { req.operation = ANGELBEATS_REQ_RELOAD; } else if (strcmp(argv[1], "suggest") == 0) { req.operation = ANGELBEATS_REQ_SUGGEST; if (argc > 2) { req.operation = ANGELBEATS_REQ_SUGGEST_AND_LINK; req.master_uid = searchuser(argv[2], NULL); } } else if (strcmp(argv[1], "unlink") == 0) { if (argc != 3) { printf("need target id.\n"); return -1; } req.operation = ANGELBEATS_REQ_REMOVE_LINK; req.master_uid = 0; // anyone, just unlink req.angel_uid = searchuser(argv[2], NULL); if (!req.angel_uid) { printf("invalid user id: %s\n", argv[2]); return -1; } } else if (strcmp(argv[1], "report") == 0) { req.operation = ANGELBEATS_REQ_REPORT; if (argc > 2 && !(req.angel_uid = searchuser(argv[2], NULL))) { printf("invalid user id: %s\n", argv[2]); return -1; } } else if (strcmp(argv[1], "list") == 0) { req.operation = ANGELBEATS_REQ_GET_ONLINE_LIST; } else if (strcmp(argv[1], "save") == 0) { req.operation = ANGELBEATS_REQ_SAVE_STATE; } else if (strcmp(argv[1], "perf") == 0) { req.operation = ANGELBEATS_REQ_EXPORT_PERF; } else { fprintf(stderr, "Sorry, unknown command: %s\n", argv[1]); return 0; } req.cb = sizeof(req); if (towrite(fd, &req, sizeof(req)) != sizeof(req)) { perror("towrite"); return 1; } if (req.operation == ANGELBEATS_REQ_REPORT) { if (toread(fd, &rpt, sizeof(rpt)) != sizeof(rpt)) { perror("toread"); return 1; } assert(rpt.cb == sizeof(rpt)); printf("total_angels=%d\n" "total_online_angels=%d\n" "total_active_angels=%d\n" "min_masters_of_online_angels=%d\n" "max_masters_of_online_angels=%d\n" "min_masters_of_active_angels=%d\n" "max_masters_of_active_angels=%d\n" "my_index=%d\n" "my_active_index=%d\n" "my_active_masters=%d\n", rpt.total_angels, rpt.total_online_angels, rpt.total_active_angels, rpt.min_masters_of_online_angels, rpt.max_masters_of_online_angels, rpt.min_masters_of_active_angels, rpt.max_masters_of_active_angels, rpt.my_index, rpt.my_active_index, rpt.my_active_masters); } else if (req.operation == ANGELBEATS_REQ_GET_ONLINE_LIST) { int i; if (toread(fd, &list, sizeof(list)) != sizeof(list)) { perror("toread"); return 1; } assert(list.cb == sizeof(list)); printf("angels=%d\n", list.angels); for (i = 0; i < list.angels; i++) { printf("%3d. %s\n", i + 1, getuserid(list.uids[i])); } } else { if (toread(fd, &req, sizeof(req)) != sizeof(req)) { perror("toread"); return 1; } printf("result: angel_uid=%d\n", req.angel_uid); } return 0; }
int x_love() { char buf1[200], save_title[TTLEN + 1]; char receiver[61], path[STRLEN] = "home/"; int x, y = 0, tline = 0, poem = 0; FILE *fp, *fpo; time_t timenow; struct tm *gtime; fileheader_t mhdr; setutmpmode(LOVE); time(&timenow); gtime = localtime(&timenow); sprintf(buf1,"%c/%s/love%d%d", cuser.userid[0], cuser.userid,gtime->tm_sec,gtime->tm_min); strcat(path,buf1); move(1,0); clrtobot(); outs("\n歡迎使用情書產生器 v0.00 版 \n"); outs("有何難以啟齒的話,交由系統幫你說吧.\n爸爸說 : 濫情不犯法.\n"); if(!getdata(7, 0, "收信人:", receiver, 60, DOECHO)) return 0; if(receiver[0] && !(searchuser(receiver) && getdata(8, 0, "主 題:", save_title, TTLEN, DOECHO))) { move(10, 0); outs("收信人或主題不正確, 情書無法傳遞. "); pressanykey(); return 0; } fpo = fopen(path, "w"); fprintf(fpo, "\n"); if((fp = fopen(DATA, "r"))) { while(fgets(buf1,100, fp)) { switch(buf1[0]) { case '#': break; case '@': if(!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4)) tline=3; else if(!strncmp(buf1,"@poem",5)) { poem = 1; tline = 1; fprintf(fpo, "\n\n"); } else tline=2; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': sscanf(buf1,"%d",&x); y = (rand() % (x - 1)) * tline; break; default: if(!poem) { if(y > 0) y = y - 1; else { if(tline > 0) { fprintf(fpo, "%s", buf1); tline--; } } } else { if(buf1[0] == '$') y--; else if(y == 0) fprintf(fpo,"%s",buf1); } } } fclose(fp); fclose(fpo); if(vedit(path, YEA, NULL) == -1) { unlink(path); clear(); outs("\n\n 放棄寄情書\n"); pressanykey(); return -2; } sethomepath(buf1, receiver); stampfile(buf1, &mhdr); Rename(path, buf1); strncpy(mhdr.title, save_title, TTLEN); strcpy(mhdr.owner, cuser.userid); mhdr.savemode = '\0'; sethomedir(path, receiver ); if(append_record(path, &mhdr, sizeof(mhdr)) == -1) return -1; hold_mail(buf1, receiver); return 1; } return 0; }
void new_register() { struct userec newuser; int allocid, do_try, flag; char buf[STRLEN]; /* temp !!!!!*/ #ifdef SECONDSITE prints("不接受新帐号注册!!!\n"); oflush(); sleep(2); exit(-1); #else /* prints("Sorry, we don't accept newusers due to system problem, we'll fixit ASAP\n"); oflush(); sleep(2); exit(-1); */ memset(&newuser, 0, sizeof(newuser)); getdata(0, 0, "使用GB编码阅读?(\xa8\xcf\xa5\xce BIG5\xbd\x58\xbe\x5c\xc5\xaa\xbd\xd0\xbf\xefN)(Y/N)? [Y]: ", buf, 4, DOECHO, NULL, true); if (*buf == 'n' || *buf == 'N') if (!convcode) switch_code(); ansimore("etc/register", false); do_try = 0; while (1) { if (++do_try >= 10) { prints("\n掰掰,按太多下 <Enter> 了...\n"); refresh(); longjmp(byebye, -1); } getdata(0, 0, "请输入代号: ", newuser.userid, IDLEN + 1, DOECHO, NULL, true); flag = 1; if (id_invalid(newuser.userid) == 1) { prints("帐号必须由英文字母或数字组成,并且第一个字符必须是英文字母!\n"); /* prints("帐号必须由英文字母或数字,而且帐号第一个字是英文字母!\n"); */ flag = 0; } if (flag) { if (strlen(newuser.userid) < 2) { prints("代号至少需有两个英文字母!\n"); } else if ((strcasecmp(newuser.userid, "SYSOP") == 0) && (strcmp(newuser.userid, "SYSOP") != 0) && searchuser("SYSOP") == 0) { prints("抱歉,本站只允许注册*全部*大写的SYSOP用户ID。\n"); } else if (!strcasecmp(newuser.userid, "guest") && strcmp(newuser.userid, "guest") && !searchuser("guest")) { prints("抱歉,本站只允许注册*全部*小写的guest用户ID。\n"); } else if ((*newuser.userid == '\0') || bad_user_id(newuser.userid) || (strcasecmp(newuser.userid, "SYSOPS") == 0) || (strcasecmp(newuser.userid, "BMS") == 0)) { prints("抱歉,本站暂不提供此帐号注册。\n"); } else if (searchuser(newuser.userid) != 0) { /*( dosearchuser( newuser.userid ) ) midified by dong , 1998.12.2, change getuser -> searchuser , 1999.10.26 */ prints("此帐号已经有人使用\n"); } else { /*--- ---*/ struct stat lst; time_t lnow; lnow = time(NULL); sethomepath(genbuf, newuser.userid); if (!stat(genbuf, &lst) && S_ISDIR(lst.st_mode) && (lnow - lst.st_ctime < SEC_DELETED_OLDHOME /* 3600*24*30 */)) { prints("目前无法注册帐号%s,请与系统管理人员联系。\n", newuser.userid); sprintf(genbuf, "IP %s new id %s failed[home changed in past 30 days]", getSession()->fromhost, newuser.userid); bbslog("user","%s",genbuf); } else { /* etnlegend, 2006.10.14, 新用户可能继承原有同名用户信件... */ sethomepath(genbuf,newuser.userid); my_f_rm(genbuf); setmailpath(genbuf,newuser.userid); my_f_rm(genbuf); break; } } } } newuser.firstlogin = newuser.lastlogin = time(NULL) - 13 * 60 * 24; do_try = 0; while (1) { char passbuf[STRLEN], passbuf2[STRLEN]; if (++do_try >= 10) { prints("\n掰掰,按太多下 <Enter> 了...\n"); refresh(); longjmp(byebye, -1); } getdata(0, 0, "请设定您的密码: ", passbuf, 39, NOECHO, NULL, true); if (strlen(passbuf) < 4 || !strcmp(passbuf, newuser.userid)) { prints("密码太短或与使用者代号相同, 请重新输入\n"); continue; } getdata(0, 0, "请再输入一次你的密码: ", passbuf2, 39, NOECHO, NULL, true); if (strcmp(passbuf, passbuf2) != 0) { prints("密码输入错误, 请重新输入密码.\n"); continue; } setpasswd(passbuf, &newuser); #ifdef NEWSMTH strcpy(getSession()->passwd, passbuf); #endif break; } if (searchuser(newuser.userid) != 0) { prints("此帐号已经有人使用\n"); refresh(); longjmp(byebye, -1); } newuser.userlevel = PERM_BASIC; newuser.userdefine[0] = -1; newuser.userdefine[1] = -1; /* newuser.userdefine&=~DEF_MAILMSG; newuser.userdefine&=~DEF_EDITMSG; */ SET_UNDEFINE(&newuser, DEF_NOTMSGFRIEND); if (convcode) SET_UNDEFINE(&newuser, DEF_USEGB); SET_UNDEFINE(&newuser, DEF_SHOWREALUSERDATA); newuser.exittime = time(NULL) - 100; /*newuser.unuse2 = -1;*/ newuser.flags |= PAGER_FLAG; newuser.title = 0; newuser.firstlogin = newuser.lastlogin = time(NULL); allocid = getnewuserid2(newuser.userid); if (allocid > MAXUSERS || allocid <= 0) { prints("抱歉, 由于某些系统原因, 无法注册新的帐号.\n\r"); oflush(); sleep(2); exit(1); } newbbslog(BBSLOG_USIES, "APPLY: %s uid %d from %s", newuser.userid, allocid, getSession()->fromhost); update_user(&newuser, allocid, 1); if (!dosearchuser(newuser.userid)) { /* change by KCN 1999.09.08 fprintf(stderr,"User failed to create\n") ; */ prints("User failed to create %d-%s\n", allocid, newuser.userid); oflush(); exit(1); } bbslog("user","%s","new account"); #endif /* SECONDSITE */ }
void call_ignore(chatcontext * pthis, const char *arg) { /* added by Luzi 1997.11.28 */ char buf[STRLEN], buf2[76]; FILE *fp; char uident[IDLEN + 1]; char path[40]; char ignoreuser[IDLEN + 1]; int nIdx; sethomefile(path, getCurrentUser()->userid, "/ignores"); if (!*arg) { nIdx = 0; if ((fp = fopen(path, "r")) != NULL) { strcpy(buf2, "【忽略其讯息的用户ID列表】"); while (fread(buf, IDLEN + 1, 1, fp) > -0) { if (nIdx % 4 == 0) { printchatline(pthis, buf2); *buf2 = '\0'; } nIdx++; sprintf(buf2 + strlen(buf2), " %-13s", buf); } fclose(fp); } if (nIdx > 0) printchatline(pthis, buf2); else printchatline(pthis, "*** 尚未设定忽略用户的名单 ***"); } else if (!strcasecmp(arg, getCurrentUser()->userid)) printchatline(pthis, "*** 无法忽略自己的信息 ***"); else { strncpy(uident, arg, IDLEN + 1); uident[IDLEN] = 0; if (!searchuser(uident)) /* change getuser -> searchuser, by dong, 1999.10.26 */ printchatline(pthis, "*** 没有这个 ID ***"); else { nIdx = search_record(path, ignoreuser, IDLEN + 1, (RECORD_FUNC_ARG) cmpinames, uident); if (nIdx > 0) printchatline(pthis, "*** 该ID已经被忽略了 ***"); else { fp = fopen(path, "r"); if (fp != NULL) { fseek(fp, 0, SEEK_END); if (ftell(fp) >= (IDLEN + 1) * MAX_IGNORE) { fclose(fp); printchatline(pthis, "*** 忽略用户名单已满 ***"); return; } fclose(fp); } if (append_record(path, uident, IDLEN + 1) == 0) { printchatline(pthis, "*** 忽略已经设定 ***"); bbslog("user", "ignore %s", uident); sprintf(buf, "/ignore %s", uident); chat_send(pthis, buf); } else { printchatline(pthis, "*** 系统错误 ***"); bbslog("3error", "ignore %s failed", uident); } } } } }
int main(void) { FILE *fp, *ftmp; int i = 0, num; // char *currboard[3] = {"CCK-CHUHEN", "CCK-GENERAL", "CCK-FREE"}; // char *kingdom[3] = {"·¡º~¬Ó´Â", "±N«Ó«ÒÁp", "³p»»¤ý´Â"}; char file1[80], file2[80], line[256], str[256]; time_t dtime; boardheader_t brd; int brdfd; setgid(BBSGID); setuid(BBSUID); chdir(BBSHOME); attach_SHM(); time(&dtime); if ((brdfd = open(BBSHOME "/" FN_BOARD, O_RDONLY)) == -1){ perror("open " BBSHOME "/" FN_BOARD); return 0; } while(read(brdfd, &brd, sizeof(brd)) == sizeof(brd)) { const char* photo_fname = 0; const char* chess_name = 0; char kingdom_name[256]; int bid; // struct stat st; switch(brd.chesscountry){ case CHESSCODE_FIVE: photo_fname = "photo_fivechess"; chess_name = "¤¤l´Ñ"; break; case CHESSCODE_CCHESS: photo_fname = "photo_cchess"; chess_name = "¶H´Ñ"; break; case CHESSCODE_GO: photo_fname = "photo_go"; chess_name = "³ò´Ñ"; break; case CHESSCODE_REVERSI: photo_fname = "photo_reversi"; chess_name = "¶Â¥Õ´Ñ"; break; default: continue; } bid = getbnum(brd.brdname); setapath(str, brd.brdname); sprintf(file1, "%s/chess_list", str); printf("apath = %s\n", str); /* if (stat(file1, &st) == 0 && st.st_mtime > (dtime - UPDATE_FREQUENCY * 60)) continue; */ sprintf(file2, "%s/chess_list.tmp", str); if ((ftmp = fopen(file2, "w")) == NULL) continue; if ((fp = fopen(file1, "r"))) { char *p; char userid[IDLEN + 1], buf[256], name[11]; char date[11], other[IDLEN + 1]; int namelen; fgets(kingdom_name, 256, fp); fputs(kingdom_name, ftmp); chomp(kingdom_name); while (fgets(buf, sizeof(buf), fp)) { i = 0; strcpy(line, buf); p = strtok(buf, " "); name[0] = '\0'; if (p && *p != '#' && searchuser(p, userid)) { i = 1; if ((p = strtok(NULL, " "))) strlcpy(name, p, sizeof(name)); else i = 0; if ((p = strtok(NULL, " "))) strlcpy(date, p, sizeof(date)); else i = 0; if ((p = strtok(NULL, " "))) strlcpy(other, p, sizeof(other)); else i = 0; } if (!strcmp("°£¦W", name)) { sethomefile(buf, userid, photo_fname); unlink(buf); continue; } if (i == 0) { fprintf(ftmp, "%s", line); continue; } namelen = strlen(name); setapath(str, brd.brdname); sprintf(buf, "%s/chess_photo/.DIR", str); num = get_num_records(buf, sizeof(fileheader_t)); for (i = 1; i <= num; i++) { fileheader_t item; if (get_record(buf, &item, sizeof item, i) != -1) { FILE *fp1; if (!strncmp(item.title + 3, name, namelen) && (item.title[namelen + 3] == '\0' || item.title[namelen + 3] == ' ') ) { sethomefile(buf, userid, photo_fname); if ((fp1 = fopen(buf, "w"))) { sprintf(buf, "%s/chess_photo/%s", str, item.filename); f_suck6(fp1, buf); fprintf(fp1, "%d\n", bid); if (strcmp("«R¸¸", name)) fprintf(fp1, "<©ÒÄݤý°ê> %s (%s)\n", kingdom_name, chess_name); else fprintf(fp1, "<«R¸¸¤ý°ê> %s\n", kingdom_name); fprintf(fp1, "<²{¦b¶¥¯Å> %s\n", name); fprintf(fp1, "<¥[¤J¤é´Á> %s\n", date); if (strcmp("«R¸¸", name)) { int level; fprintf(fp1, "<¤ý°êµ¥¯Å> "); level = atoi(other); for (i = 0; i < level; i++) fprintf(fp1, "%s", "¡¹"); } else { chomp(other); fprintf(fp1, "<³Q½Ö«R¸¸> %s", other); } fprintf(fp1, "\n<¦Û§Ú»¡©ú> \n"); fclose(fp1); } break; } } } if (i > num) // level photo not found fprintf(ftmp, "%s", line); else fprintf(ftmp, "#%s", line); } fclose(fp); fclose(ftmp); rename(file2, file1); } else { fclose(ftmp); } } return 0; }
int utmpfix(int argc, char **argv) { int i, fast = 0, nownum = SHM->UTMPnumber; int which, nactive = 0, dofork = 1, daemonsleep = 0; time_t now; const char *clean; char buf[1024]; IDLE_t idle[USHM_SIZE]; char changeflag = 0; time_t idletimeout = IDLE_TIMEOUT; int lowerbound = 100, upperbound = 0; char ch; int killtop = 0; struct { pid_t pid; int where; } killlist[USHM_SIZE]; while( (ch = getopt(argc, argv, "nt:l:FD:u:")) != -1 ) switch( ch ){ case 'n': fast = 1; break; case 't': idletimeout = atoi(optarg); break; case 'l': lowerbound = atoi(optarg); break; case 'F': dofork = 0; break; case 'D': daemonsleep = atoi(optarg); break; case 'u': upperbound = atoi(optarg); break; default: printf("usage:\tshmctl\tutmpfix [-n] [-t timeout] [-F] [-D sleep]\n"); return 1; } if( daemonsleep ) switch( fork() ){ case -1: perror("fork()"); return 0; case 0: break; default: return 0; } if( daemonsleep || dofork ){ int times = 1000, status; pid_t pid; while( daemonsleep ? 1 : times-- ) switch( pid = fork() ){ case -1: sleep(1); break; case 0: #ifndef VALGRIND setproctitle("utmpfix"); #endif goto DoUtmpfix; default: #ifndef VALGRIND setproctitle(daemonsleep ? "utmpfixd(wait for %d)" : "utmpfix(wait for %d)", (int)pid); #endif waitpid(pid, &status, 0); if( WIFEXITED(status) && !daemonsleep ) return 0; if( !WIFEXITED(status) ){ /* last utmpfix fails, so SHM->UTMPbusystate is holded */ SHM->UTMPbusystate = 0; } } return 0; // never reach } DoUtmpfix: killtop=0; changeflag=0; for( i = 0 ; i < 5 ; ++i ) if( !SHM->UTMPbusystate ) break; else{ puts("utmpshm is busy...."); sleep(1); } SHM->UTMPbusystate = 1; printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); nownum = SHM->UTMPnumber; now = time(NULL); for( i = 0, nactive = 0 ; i < USHM_SIZE ; ++i ) if( SHM->uinfo[i].pid ){ idle[nactive].index = i; idle[nactive].idle = now - SHM->uinfo[i].lastact; ++nactive; } if( !fast ) qsort(idle, nactive, sizeof(IDLE_t), sfIDLE); #define addkilllist(a) \ do { \ pid_t pid=SHM->uinfo[(a)].pid; \ if(pid > 0) { \ killlist[killtop].where = (a); \ killlist[killtop++].pid = pid; \ } \ } while( 0 ) for( i = 0 ; i < nactive ; ++i ){ which = idle[i].index; clean = NULL; if( !isalpha(SHM->uinfo[which].userid[0]) ){ clean = "userid error"; addkilllist(which); } else if( memchr(SHM->uinfo[which].userid, '\0', IDLEN + 1) == NULL ){ clean = "userid without z"; addkilllist(which); } else if( SHM->uinfo[which].friendtotal > MAX_FRIEND || SHM->uinfo[which].friendtotal<0 ){ clean = "too many/less friend"; addkilllist(which); } else if( searchuser(SHM->uinfo[which].userid, NULL) == 0 ){ clean = "user not exist"; addkilllist(which); } else if( kill(SHM->uinfo[which].pid, 0) < 0 ){ /* 此條件應放最後; 其他欄位沒問題但 process 不存在才 purge_utmp */ clean = "process error"; purge_utmp(&SHM->uinfo[which]); } #ifdef DOTIMEOUT else if( (strcasecmp(SHM->uinfo[which].userid, STR_GUEST)==0 && idle[i].idle > 60*15) || (!fast && nownum > lowerbound && idle[i].idle > idletimeout ) ) { sprintf(buf, "timeout(%s", ctime4(&SHM->uinfo[which].lastact)); buf[strlen(buf) - 1] = 0; strcat(buf, ")"); clean = buf; addkilllist(which); purge_utmp(&SHM->uinfo[which]); printf("%s\n", buf); --nownum; continue; } #endif if( clean ){ printf("clean %06d(%s), userid: %s\n", i, clean, SHM->uinfo[which].userid); memset(&SHM->uinfo[which], 0, sizeof(userinfo_t)); --nownum; changeflag = 1; } } for( i = 0 ; i < killtop ; ++i ){ printf("sending SIGHUP to %d\n", (int)killlist[i].pid); kill(killlist[i].pid, SIGHUP); } sleep(3); for( i = 0 ; i < killtop ; ++i ) // FIXME 前面已經 memset 把 SHM->uinfo[which] 清掉了, 此處檢查 pid 無用 if( SHM->uinfo[killlist[i].where].pid == killlist[i].pid && kill(killlist[i].pid, 0) == 0 ){ // still alive printf("sending SIGKILL to %d\n", (int)killlist[i].pid); kill(killlist[i].pid, SIGKILL); purge_utmp(&SHM->uinfo[killlist[i].where]); } SHM->UTMPbusystate = 0; if( changeflag ) SHM->UTMPneedsort = 1; if( daemonsleep ){ do{ sleep(daemonsleep); } while( upperbound && SHM->UTMPnumber < upperbound ); goto DoUtmpfix; /* XXX: goto */ } return 0; }
static int wwwlogin(struct userec *user, const char *ref) { if (!(currentuser.userlevel & PERM_REGISTER)) { char file[HOMELEN]; sethomefile(file, currentuser.userid, "register"); if (dashf(file)) { currentuser.userlevel |= PERM_DEFAULT; save_user_data(¤tuser); } } struct user_info info; memset(&info, 0, sizeof(info)); info.active = 1; info.uid = searchuser(user->userid); info.pid = getpid(); info.mode = WWW | LOGIN; if (HAS_PERM(PERM_LOGINCLOAK) && (currentuser.flags[0] & CLOAK_FLAG)) info.invisible = YEA; info.pager = 0; if (DEFINE(DEF_FRIENDCALL)) info.pager |= FRIEND_PAGER; if (DEFINE(PAGER_FLAG)) { info.pager |= ALL_PAGER; info.pager |= FRIEND_PAGER; } if (DEFINE(DEF_FRIENDMSG)) info.pager |= FRIENDMSG_PAGER; if (DEFINE(DEF_ALLMSG)) { info.pager |= ALLMSG_PAGER; info.pager |= FRIENDMSG_PAGER; } // TODO:... strlcpy(info.from, fromhost, 24); // login start.. #ifdef SPARC *(int*)(info.from + 30) = time(NULL); #else *(int*)(info.from + 32) = time(NULL); #endif info.from[22] = DEFINE(DEF_NOTHIDEIP) ? 'S' : 'H'; info.idle_time = time(NULL); strlcpy(info.username, user->username, sizeof(info.username)); strlcpy(info.userid, user->userid, sizeof(info.userid)); int utmpkey = rand() % 100000000; info.utmpkey = utmpkey; int fd = open("tmp/.UTMP.lock", O_RDWR | O_CREAT, 0600); if (fd < 0) return BBS_EINTNL; if (fb_flock(fd, LOCK_EX) == -1) { close(fd); return BBS_EINTNL; } struct user_info *up = utmpshm->uinfo; int n; for (n = 0; n < MAXACTIVE; n++, up++) { if (!up->active) { *up = info; uidshm->status[up->uid - 1]++; break; } } fb_flock(fd, LOCK_UN); close(fd); if (n >= MAXACTIVE) return BBS_E2MANY; const char *referer = ref; if (*referer == '\0') referer = "sec"; // TODO: these cookies should be merged into one. printf("Content-type: text/html; charset=%s\n" "Set-cookie: utmpnum=%d\nSet-cookie: utmpkey=%d\n" "Set-cookie: utmpuserid=%s\nLocation: %s\n\n", CHARSET, n + 1, utmpkey, currentuser.userid, referer); return 0; }
int login(struct userec *user) { char buf[80]; int tmp; struct user_info *u; struct user_info ui; int utmpent; memset(&ui, 0, sizeof(struct user_info)); ui.active = true; /* Bigman 2000.8.29 智囊团能够隐身 */ if ((HAS_PERM(user, PERM_CHATCLOAK) || HAS_PERM(user, PERM_CLOAK)) && (user->flags & CLOAK_FLAG)) ui.invisible = true; ui.pager = 0; if (DEFINE(user, DEF_FRIENDCALL)) { ui.pager |= FRIEND_PAGER; } if (user->flags & PAGER_FLAG) { ui.pager |= ALL_PAGER; ui.pager |= FRIEND_PAGER; } if (DEFINE(user, DEF_FRIENDMSG)) { ui.pager |= FRIENDMSG_PAGER; } if (DEFINE(user, DEF_ALLMSG)) { ui.pager |= ALLMSG_PAGER; ui.pager |= FRIENDMSG_PAGER; } ui.uid = searchuser(user->userid); strncpy(ui.from, getSession()->fromhost, IPLEN); ui.logintime = time(0); /* for counting user's stay time */ /* refer to bbsfoot.c for details */ ui.freshtime = time(0); ui.mode = WEBEXPLORE; strncpy(ui.userid, user->userid, 20); { struct userdata ud; read_userdata(user->userid, &ud); strncpy(ui.realname, ud.realname, 20); } strncpy(ui.username, user->username, 40); utmpent = getnewutmpent(&ui, 1); if (utmpent == -1) { fprintf(stderr, "抱歉,目前在线用户数已达上限,无法登录。"); exit(-1); } /*u = get_user_info(utmpent);*/ u = &(utmpshm->uinfo[utmpent-1]); u->pid = 1; tmp = rand() % 100000000; u->utmpkey = tmp; getfriendstr(user,u, getSession()); /*setcurruinfo(u);*/ /*u_info = ui;*/ /*if (addto_msglist(get_utmpent_num(getcurruinfo()), getcurruserid()) < 0) http_fatal("无法添加当前用户到消息列表中");*/ sprintf(buf, "%d", utmpent); printf("UTMPNUM = %s\n", buf); sprintf(buf, "%d", tmp); printf("UTMPKEY = %s\n", buf); printf("UTMPUSERID = %s\n", user->userid); return 0; }