// Loads PASSFILE into cache for all users. // Returns 0 on success, -1 on error. int load_ucache(void) { int fd, iscreate = 0, passwdfd, i; // Lock cache. fd = ucache_lock(); if (fd == -1) { return -1; } // Get shared memory. if (uidshm == NULL) { uidshm = attach_shm2("UCACHE_SHMKEY", 3696, sizeof(*uidshm), &iscreate); if(uidshm == NULL) exit(1); } log_usies("CACHE", "reload ucache", NULL); // Load PASSFILE. if ((passwdfd = open(PASSFILE, O_RDWR | O_CREAT, 0644)) == -1) { ucache_unlock(fd); exit(-1); } ftruncate(passwdfd, MAXUSERS * sizeof(struct userec)); close(passwdfd); if (get_records(PASSFILE, uidshm->passwd, sizeof(struct userec), 1, MAXUSERS) != MAXUSERS) { ucache_unlock(fd); return -1; } // Initialize 'userid' and hash. memset(uidshm->userid, 0, sizeof(uidshm->userid)); memset(uidshm->hash, 0, sizeof(uidshm->hash)); memset(uidshm->next, 0, sizeof(uidshm->next)); memset(uidshm->prev, 0, sizeof(uidshm->prev)); // Fill cache. int last = 0; for (i = 0; i < MAXUSERS; i++) { if (fillucache(&(uidshm->passwd[i]), i)) last = i; } uidshm->number = ++last; uidshm->uptime = time(NULL); // Unlock cache. ucache_unlock(fd); return 0; }
int getnewuserid(void) { struct userec user; memset(&user, 0, sizeof(user)); strlcpy(user.userid, "new", sizeof(user.userid)); int i = searchnewuser(); char buf[STRLEN]; snprintf(buf, sizeof(buf), "uid %d from %s", i, fromhost); log_usies("APPLY", genbuf, ¤tuser); if (i <= 0 || i > MAXUSERS) return i; substitut_record(PASSFILE, &user, sizeof(user), i); return i; }
void abort_bbs(int nothing) { extern int child_pid; if (child_pid) { kill(child_pid, SIGKILL); } editor_dump(); if (session_id()) { time_t stay; stay = time(0) - login_start_time; snprintf(genbuf, sizeof(genbuf), "Stay: %3ld", stay / 60); log_usies("AXXED", genbuf, ¤tuser); u_exit(); } exit(0); }
static void multi_user_check() { register userinfo_t *ui; register pid_t pid; char genbuf[3]; if(HAS_PERM(PERM_SYSOP)) return; /* don't check sysops */ if(cuser.userlevel) { if(!(ui = (userinfo_t *)search_ulist(cmpuids, usernum))) return; /* user isn't logged in */ pid = ui->pid; if(!pid /*|| (kill(pid, 0) == -1)*/) return; /* stale entry in utmp file */ getdata(b_lines - 1, 0, "您想刪除其他重複的 login (Y/N)嗎?[Y] ", genbuf, 3, LCECHO); if(genbuf[0] != 'n') { if(pid > 0) kill(pid, SIGHUP); log_usies("KICK ", cuser.username); } else { if(count_multi() >= 3) system_abort(); /* Goodbye(); */ } } else { /* allow multiple guest user */ if(count_multi() > 32) { outs("\n抱歉,目前已有太多 guest, 請稍後再試。\n"); pressanykey(); oflush(); exit(1); } } }
static void multi_user_check() { register user_info *ui; register pid_t pid; int cmpuids (); if (HAS_PERM(PERM_SYSOP)) return; /* wildcat:站長不限制 */ if (cuser.userlevel) { if (!(ui = (user_info *) search_ulist(cmpuids, usernum))) return; /* user isn't logged in */ pid = ui->pid; if (!pid || (kill(pid, 0) == -1)) return; /* stale entry in utmp file */ if (getans2(b_lines, 0, "您想刪除其他重複的 login 嗎?", 0, 2, 'y') != 'n') { kill(pid, SIGHUP); log_usies("KICK ", cuser.username); } else { int nums = MULTI_NUMS; if (HAS_PERM(PERM_BM)) nums += 2; if (count_multi() >= nums) system_abort(); } } else { /* guest的話 */ if (count_multi() > 512) { pressanykey("抱歉,目前已有太多 guest, 請稍後再試。"); oflush(); exit(1); } } }
void resolve_ucache() { struct stat st; int ftime; if (uidshm == NULL) { uidshm = attach_shm("UCACHE_SHMKEY", 3696, sizeof(*uidshm)); } if (stat(FLUSH, &st) < 0) { ftime = time(0) - 86400; } else ftime = st.st_mtime; if (uidshm->uptime < ftime||forceresolve) { log_usies("CACHE", "reload ucache"); /* uidshm->uptime = ftime; */ usernumber = 0; apply_record(PASSFILE, fillucache, sizeof(struct userec)); uidshm->number = usernumber; uidshm->uptime = ftime; } }
void resolve_boards() { struct stat st; time_t now; if (brdshm == NULL) { brdshm = attach_shm("BCACHE_SHMKEY", 3693, sizeof(*brdshm)); } numboards = brdshm->number; bcache = brdshm->bcache; now = time(0); if (stat(BOARDS, &st) < 0) { st.st_mtime = now - 3600; } if (brdshm->uptime < st.st_mtime || brdshm->uptime < now - 3600) { log_usies("CACHE", "reload bcache"); numboards = 0; apply_record(BOARDS, fillbcache, sizeof(struct boardheader)); brdshm->number = numboards; brdshm->uptime = now; } }
static void user_login(void) { char fname[STRLEN]; // SYSOP gets all permission bits when login. if (strcmp(currentuser.userid, "SYSOP") == 0) { currentuser.userlevel = ~0; substitut_record(PASSFILE, ¤tuser, sizeof(currentuser), usernum); } fromhost[sizeof(fromhost) - 1] = 0; //added by iamfat 2004.01.05 to avoid overflow log_usies("ENTER", fromhost, ¤tuser); SpecialID(currentuser.userid, fromhost, sizeof(fromhost)); u_enter(); report("Enter", currentuser.userid); #ifdef USE_NOTEPAD notepad_init(); if (strcmp(currentuser.userid, "guest") != 0) { if (DEFINE(DEF_NOTEPAD)) { int noteln; if (lastnote> currentuser.notedate) currentuser.noteline = 0; noteln = countln("etc/notepad"); if (currentuser.noteline == 0) { shownotepad(); } else if ((noteln - currentuser.noteline)> 0) { screen_move(0, 0); ansimore2("etc/notepad", NA, 0, noteln - currentuser.noteline + 1); terminal_getchar(); screen_clear(); } currentuser.noteline = noteln; write_defnotepad(); } } #endif if (show_statshm("etc/hotspot", 0)) { screen_flush(); pressanykey(); } if ((vote_flag(NULL, '\0', 2 /* 检查读过新的Welcome 没 */) == 0)) { if (dashf("Welcome")) { ansimore("Welcome", YEA); vote_flag(NULL, 'R', 2 /* 写入读过新的Welcome */); } } else { ansimore("Welcome2", YEA); } show_statshm("0Announce/bbslist/day", 1); screen_flush(); screen_move_clear(-2); if (currentuser.numlogins < 1) { currentuser.numlogins = 0; //% prints("\033[1;36m☆ 这是您第 \033[33m1\033[36m 次拜访本站,请记住今天吧。\n"); prints("\033[1;36m\xa1\xee \xd5\xe2\xca\xc7\xc4\xfa\xb5\xda \033[33m1\033[36m \xb4\xce\xb0\xdd\xb7\xc3\xb1\xbe\xd5\xbe\xa3\xac\xc7\xeb\xbc\xc7\xd7\xa1\xbd\xf1\xcc\xec\xb0\xc9\xa1\xa3\n"); //% prints("☆ 您第一次连入本站的时间为 \033[33m%s\033[m ", format_time(time(NULL), TIME_FORMAT_ZH)); prints("\xa1\xee \xc4\xfa\xb5\xda\xd2\xbb\xb4\xce\xc1\xac\xc8\xeb\xb1\xbe\xd5\xbe\xb5\xc4\xca\xb1\xbc\xe4\xce\xaa \033[33m%s\033[m ", format_time(fb_time(), TIME_FORMAT_ZH)); } else { prints( //% "\033[1;36m☆ 这是您第 \033[33m%d\033[36m 次拜访本站,上次您是从 \033[33m%s\033[36m 连往本站。\n", "\033[1;36m\xa1\xee \xd5\xe2\xca\xc7\xc4\xfa\xb5\xda \033[33m%d\033[36m \xb4\xce\xb0\xdd\xb7\xc3\xb1\xbe\xd5\xbe\xa3\xac\xc9\xcf\xb4\xce\xc4\xfa\xca\xc7\xb4\xd3 \033[33m%s\033[36m \xc1\xac\xcd\xf9\xb1\xbe\xd5\xbe\xa1\xa3\n", currentuser.numlogins + 1, currentuser.lasthost); //% prints("☆ 上次连线时间为 \033[33m%s\033[m ", format_time(currentuser.lastlogin, TIME_FORMAT_ZH)); prints("\xa1\xee \xc9\xcf\xb4\xce\xc1\xac\xcf\xdf\xca\xb1\xbc\xe4\xce\xaa \033[33m%s\033[m ", format_time(currentuser.lastlogin, TIME_FORMAT_ZH)); } terminal_getchar(); setuserfile(fname, BADLOGINFILE); if (ansimore(fname, NA) != -1) { //% if (askyn("您要删除以上密码输入错误的记录吗", NA, NA) == YEA) if (askyn("\xc4\xfa\xd2\xaa\xc9\xbe\xb3\xfd\xd2\xd4\xc9\xcf\xc3\xdc\xc2\xeb\xca\xe4\xc8\xeb\xb4\xed\xce\xf3\xb5\xc4\xbc\xc7\xc2\xbc\xc2\xf0", NA, NA) == YEA) unlink(fname); } set_safe_record(); tui_check_uinfo(¤tuser); strlcpy(currentuser.lasthost, fromhost, sizeof(currentuser.lasthost)); if (login_start_time - currentuser.lastlogin >= 20 * 60 || !strcmp(currentuser.userid, "guest") || currentuser.numlogins < 100) { currentuser.numlogins++; } session_basic_info_t *res = get_my_sessions(); update_user_stay(¤tuser, true, session_basic_info_count(res) > 1); session_basic_info_clear(res); #ifdef ALLOWGAME if (currentuser.money> 1000000) { currentuser.nummedals += currentuser.money / 10000; currentuser.money %= 1000000; } if ((signed int) (currentuser.money - currentuser.bet) < -4990 && currentuser.numlogins < 10 && currentuser.numposts < 10 && currentuser.nummedals == 0) currentuser.money += 1000; #endif if (currentuser.firstlogin == 0) { currentuser.firstlogin = time(NULL) - 7 * 86400; } substitut_record(PASSFILE, ¤tuser, sizeof(currentuser), usernum); extern char currmaildir[]; setmdir(currmaildir, currentuser.userid); check_register_info(); }
int Goodbye() { extern void movie(); char genbuf[200]; /* woju */ char ans[4]; setuserfile(genbuf, fn_writelog); if (more(genbuf, NA) != -1) { /* MH */ /* Àˬd¤ô²y°O¿ý®e¶q, ÁקK¦³¤H¡u¤Ù¿n¡v¤j¶q¤ô²y */ struct stat st; int writelog_limit; if (HAS_PERM(PERM_BM)) writelog_limit = MH_WRITELOGLIMIT_BM; else if (HAS_PERM(PERM_LOGINOK)) writelog_limit = MH_WRITELOGLIMIT_LOGINOK; else writelog_limit = MH_WRITELOGLIMIT_BASIC; do { char buf[80]; setuserfile(buf, fn_writelog); stat(buf, &st); if(!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT) && st.st_size / 1024 > writelog_limit) { my_outmsg_row("[1;41;37m±zªº¤ô²y°O¿ý¤w¶W¹L©w®e¶q¡AµLªk¿ï¾Ü¡u«O¯d¡v[0m", b_lines - 2); getdata(b_lines - 1, 0, "²M°£(C) ²¾¦Ü³Æ§Ñ¿ý(M) (C/M)?[M]", ans, 3, LCECHO, 0); } else { getdata(b_lines - 1, 0, "²M°£(C) ²¾¦Ü³Æ§Ñ¿ý(M) «O¯d(R) (C/M/R)?[R]", ans, 3, LCECHO, 0); } if (*ans == 'm') { fileheader mymail; char title[128], buf[80]; sethomepath(buf, cuser.userid); stampfile(buf, &mymail); mymail.savemode = 'H'; /* hold-mail flag */ mymail.filemode = FILE_READ; strcpy(mymail.owner, "[³Æ.§Ñ.¿ý]"); strcpy(mymail.title, "¼ö½u[37;41m°O¿ý[m"); if(mh_memoforward(cuser.userid, genbuf, &mymail, sizeof(mymail))) { sethomedir(title, cuser.userid); append_record(title, &mymail, sizeof(mymail)); /* MH: ³Æ§Ñ¿ý¥[¤W§@ªÌ¼ÐÃDµ¥¸ê°T...¤£µM¦b'x'Âà±H©Î¬Obuildirªº®ÉÔ ·|Äê±¼ */ #if 1 { FILE *src, *dst; char buf2[200]; time_t now; if((src = fopen(genbuf, "r")) == NULL) { sprintf(buf2, "errno: %d, genbuf:%s", errno, genbuf); log_usies("MH ", buf2); } if((dst = fopen(buf, "w")) == NULL) { sprintf(buf2, "errno: %d, buf:%s", errno, buf); log_usies("MH ", buf2); fclose(src); } now = time(NULL); sprintf(buf2, "§@ªÌ: %s\n¼ÐÃD: %s\n®É¶¡: %s\n", mymail.owner, mymail.title, ctime(&now)); fputs(buf2, dst); while(fgets(buf2, 199, src) != NULL) fputs(buf2, dst); fclose(src); fclose(dst); unlink(genbuf); } #else Rename(genbuf, buf); #endif } } else if (*ans == 'c') { char buf[80]; setuserfile(buf, fn_writelog); unlink(buf); } } while(!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT) && st.st_size / 1024 > writelog_limit && *ans != 'm' && *ans != 'c'); clear(); move(0, 0); prints("[1;44;33m °ª¶¯¤¤¾Ç-¬õ¼Ó¿v¹Ú [m"); movie(0); } /* */ getdata(b_lines - 1, 0, "±z½T©wnÂ÷¶}¡i " BOARDNAME " ¡j¶Ü(Y/N)¡H[N] ", genbuf, 3, LCECHO, 0); if (*genbuf != 'y') return 0; movie(999); if (cuser.userlevel) { getdata(b_lines - 1, 0, "(G)ÀH·¦Ó³u (M)¦«¹Ú¯¸ªø (N)¦X§@ªÀªº¨¥½×¼s³õ¡H[G] ", genbuf, 3, LCECHO, 0); if (genbuf[0] == 'm') mail_sysop(); else if (genbuf[0] == 'n') note(); } save_userrc(); #if 0 save_mailmsg(); #endif clear(); prints("[1;36m¿Ë·Rªº [33m%s(%s)[36m¡A§O§Ñ¤F¦A«×¥úÁ{[45;33m" " %s [40;36m¡I\n¥H¤U¬O±z¦b¯¸¤ºªºµù¥U¸ê®Æ:[0m\n", cuser.userid, cuser.username, BoardName); user_display(&cuser, 0); if (currmode) u_exit("EXIT "); pressanykey(); sleep(1); reset_tty(); exit(0); }
int main(int argc, char **argv) { bool pretend = (argc != 2) || (strcasecmp(argv[1], "-f") != 0); int fd; FILE *log, *data, *post; if (!pretend) { int fd = open(BBSHOME"/tmp/killuser", O_RDWR | O_CREAT | O_EXCL, 0600); if (fd < 0) return EXIT_FAILURE; unlink(BBSHOME"/tmp/killuser"); log = fopen(BBSHOME"/tomb/log", "w+"); if (!log) return EXIT_FAILURE; data = fopen(BBSHOME"/tomb/PASSWDS", "w+"); if (!data) return EXIT_FAILURE; post = fopen(BBSHOME"/tomb/post", "w+"); if (!post) return EXIT_FAILURE; log_usies("CLEAN", "dated users.", NULL); } fb_time_t now = time(NULL); struct userec user, zero; memset(&zero, 0, sizeof(zero)); char file[HOMELEN], buf[HOMELEN]; for (int i = 0; i < MAXUSERS; ++i) { getuserbyuid(&user, i + 1); int val = compute_user_value(&user); if (user.userid[0] != '\0' && val < 0) { user.userid[sizeof(user.userid) - 1] = '\0'; if (pretend) { puts(user.userid); continue; } post_add(post, &user, now); fwrite(&user, sizeof(user), 1, data); fprintf(log, "%s\n", user.userid); snprintf(file, sizeof(file), "mail/%c/%s", toupper(user.userid[0]), user.userid); snprintf(buf, sizeof(buf), "%s~", file); rename(file, buf); snprintf(file, sizeof(file), "home/%c/%s", toupper(user.userid[0]), user.userid); snprintf(buf, sizeof(buf), "%s~", file); rename(file, buf); substitut_record(PASSFILE, &zero, sizeof(zero), i + 1); del_uidshm(i + 1, user.userid); } } if (!pretend) { fclose(post); fclose(data); fclose(log); close(fd); } return EXIT_SUCCESS; }
int bbslogin_main(void) { char fname[STRLEN]; char buf[256], id[IDLEN + 1], pw[PASSLEN]; struct userec user; if (parse_post_data() < 0) return BBS_EINVAL; strlcpy(id, getparm("id"), sizeof(id)); if (*id == '\0') return login_screen(); strlcpy(pw, getparm("pw"), sizeof(pw)); if (loginok && !strcasecmp(id, currentuser.userid)) { const char *ref = get_login_referer(); printf("Location: %s\n\n", ref); return 0; } if (getuserec(id, &user) == 0) return BBS_ENOUSR; user.numlogins++; if (strcasecmp(id, "guest")) { int total; time_t stay, recent, now, t; if (!checkpasswd(user.passwd, pw)) { sprintf(buf, "%-12.12s %s @%s\n", user.userid, getdatestring(time(NULL), DATE_ZH), fromhost); sethomefile(fname, user.userid, "logins.bad"); file_append(fname, buf); file_append("logins.bad", buf); return BBS_EWPSWD; } total = check_multi(&user); if (!HAS_PERM2(PERM_SYSOPS, &user) && total >= 2) return BBS_ELGNQE; if (!HAS_PERM2(PERM_LOGIN, &user)) return BBS_EACCES; now = time(NULL); // Do not count frequent logins. if (now - user.lastlogin < 20 * 60 && user.numlogins >= 100) user.numlogins--; if (total > 1) { recent = user.lastlogout; if (user.lastlogin > recent) recent = user.lastlogin; stay = now - recent; if (stay < 0) stay = 0; } else { stay = 0; } t = user.lastlogin; user.lastlogin = now; user.stay += stay; #ifdef CHECK_FREQUENTLOGIN if (!HAS_PERM(PERM_SYSOPS) && abs(t - time(NULL)) < 10) { report("Too Frequent", user.userid); return BBS_ELFREQ; } #endif strlcpy(user.lasthost, fromhost, sizeof(user.lasthost)); save_user_data(&user); currentuser = user; } log_usies("ENTER", fromhost, &user); if (!loginok && strcasecmp(id, "guest")) wwwlogin(&user, getparm("ref")); return 0; }
static void user_login() { char ans[4], i; char genbuf[200]; struct tm *ptime, *tmp; time_t now; int a; /*** Heat:廣告詞 char *ADV[17] = { "記得唷!! 5/12在台大二活地下室見~~~", "你知道Ptt之夜是什麼嗎? 5/12號就要上演耶 快去問吧!", "5/12 Ptt之夜即將引爆 能不去嗎? 在台大二活地下室咩", "不來就落伍了 啥? 就Ptt之夜啊 很棒的晚會唷 時間:5/12", "差點忘了提醒你 5/12我們有約 就台大二活地下室咩!!", "Ptt是啥 想知嗎? 5/12在台大二活地下室告訴你唷", "來來來....5/12快到台大二活地下室去拿獎品吧~~", "去去去...到台大二活地下室去 就5/12麻 有粉多獎品耶", "喂喂喂 怎還楞在這!!快呼朋引伴大鬧ptt", "Ptt最佳豬腳 換你幹幹看 5/12來吧....*^_^*", "幹什麼幹什麼?? 你怎麼不曉得啥是Ptt之夜..老土唷", "累了嗎? 讓我們來為你來一段精采表演吧.. 5/12 Ptt之夜", "世紀末最屁力的晚會 就在台大二活地下室 5/12不見不散 gogo", "到底誰比較帥(美) 來比比吧 5/12Ptt之夜 一較高下", "台大二活地下室 5/12 聽說會有一場很棒的晚會唷 Ptt之夜", "台大二活地下室 5/12 你能不來嗎?粉多網友等著你耶", "5/12 台大二活地下室 是各約網友見面的好地方呢", }; char *ADV[] = { "7/17 @LIVE 亂彈, 何欣穗 的 入場卷要送給 ptt 的愛用者!", "欲知詳情請看 PttAct 板!!", }; ***/ log_usies("ENTER", getenv("RFC931") /* fromhost */ ); setproctitle("%s: %s", margs, cuser.userid); /* resolve all cache */ resolve_garbage(); /* get ptt cache */ resolve_fcache(); resolve_boards(); /* 初始化 uinfo、flag、mode */ setup_utmp(LOGIN); mysrand(); /* 初始化: random number 增加user跟時間的差異 */ currmode = MODE_STARTED; enter_uflag = cuser.uflag; /* get local time */ time(&now); ptime = localtime(&now); tmp = localtime(&cuser.lastlogin); if((a = utmpshm->number) > fcache->max_user) { sem_init(FROMSEM_KEY, &fcache_semid); sem_lock(SEM_ENTER, fcache_semid); fcache->max_user = a; fcache->max_time = now; sem_lock(SEM_LEAVE, fcache_semid); } #ifdef INITIAL_SETUP if(!getbnum(DEFAULT_BOARD)) { strcpy(currboard, "尚未選定"); } else #endif { brc_initial(DEFAULT_BOARD); set_board(); } /* 畫面處理開始 */ if(!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST))) do_aloha("<<上站通知>> -- 我來啦!"); if(ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month) { more("etc/Welcome_birth", NA); currutmp->birth = 1; } else { more("etc/Welcome_login", NA); // pressanykey(); // more("etc/CSIE_Week", NA); currutmp->birth = 0; } if(cuser.userlevel) { /* not guest */ move(t_lines - 4, 0); prints(" 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" " 我記得那天是 \033[1;33m%s\033[0;37m。\n", ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin)); currutmp->mind=rand()%8; /* 初始心情 */ pressanykey(); if(currutmp->birth && tmp->tm_mday != ptime->tm_mday) { more("etc/birth.post", YEA); brc_initial("WhoAmI"); set_board(); do_post(); } setuserfile(genbuf, str_badlogin); if(more(genbuf, NA) != -1) { getdata(b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]", ans, 3, LCECHO); if(*ans != 'n') unlink(genbuf); } check_register(); strncpy(cuser.lasthost, fromhost, 16); cuser.lasthost[15] = '\0'; restore_backup(); } else if(!strcmp(cuser.userid, STR_GUEST)) { char *nick[13] = { "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", "鐵罐", "考卷", "大美女"}; char *name[13] = { "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲"}; char *addr[13] = { "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", "遠方", "原本海", "NIKE", "蘇聯", "男八618室", "愛之味", "天上", "藍色珊瑚礁"}; i = login_start_time % 13; sprintf(cuser.username, "海邊漂來的%s", nick[(int)i]); sprintf(currutmp->username, cuser.username); sprintf(cuser.realname, name[(int)i]); sprintf(currutmp->realname, cuser.realname); sprintf(cuser.address, addr[(int)i]); cuser.sex = i % 8; currutmp->pager = 2; pressanykey(); } else pressanykey(); if(!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; reload_money(); passwd_update(usernum, &cuser); for(i = 0; i < NUMVIEWFILE; i++) if((cuser.loginview >> i) & 1) more(loginview_file[(int)i][0], YEA); }
static void user_login() { char genbuf [200]; struct tm *ptime, *tmp; time_t now = time(0); int a; extern struct FROMCACHE *fcache; extern int fcache_semid; log_usies("ENTER", fromhost); setproctitle("%s: %s", cuser.userid, fromhost); /* ------------------------ */ /* 初始化 uinfo、flag、mode */ /* ------------------------ */ setup_utmp(LOGIN); currmode = MODE_STARTED; enter_uflag = cuser.uflag; /* get local time */ tmp = localtime(&cuser.lastlogin); update_data(); /* wildcat: update user data */ /* Ptt check 同時上線人數 */ resolve_fcache(); resolve_utmp(); if ((a = utmpshm->number) > fcache->max_user) { sem_init(FROMSEM_KEY, &fcache_semid); sem_lock(SEM_ENTER, fcache_semid); fcache->max_user = a; fcache->max_time = now; sem_lock(SEM_LEAVE, fcache_semid); } #ifdef INITIAL_SETUP if (getbnum(DEFAULT_BOARD) == 0) { strcpy(currboard, "尚未選定"); } else #endif { brc_initial(DEFAULT_BOARD); set_board(); } /* ------------ */ /* 畫面處理開始 */ /* ------------ */ if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST))) { char buf [256]; time_t now; time(&now); sprintf(buf, "<<上站通知>> -- 我來囉! - %s", Etime(&now)); do_aloha(buf); } time(&now); ptime = localtime(&now); #ifdef CAMERA film_out(FILM_LOGIN, 0); #else more("etc/Welcome_login", NA); #endif #if 0 /* wildcat : 搬家通知用 */ if (belong(BBSHOME "/etc/oldip", fromhost)) { more(BBSHOME "/etc/removal"); abort_bbs(); } #endif if ((cuser.day == ptime->tm_mday) && (cuser.month == (ptime->tm_mon + 1))) currutmp->birth = 1; else currutmp->birth = 0; if (cuser.userlevel) { /* not guest */ move(t_lines - 3, 0); prints(" 歡迎您第 [1;33m%d[0;37m 度拜訪本站,\ 上次您是從 [1;33m%s[0;37m 連往本站,\n\ 我記得那天是 [1;33m%s[0;37m。\n", ++cuser.numlogins, cuser.lasthost, Etime(&cuser.lastlogin)); pressanykey(NULL); /* Ptt */ if (currutmp->birth == 1) { #ifdef CAMERA film_out(FILM_WEL_BIRTH, 0); #else more("etc/Welcome_birth", YEA); #endif brc_initial("Greeting"); set_board(); do_post(); } sethomefile(genbuf, cuser.userid, str_badlogin); if (more(genbuf, NA) != -1) { if (getans2(b_lines, 0, "您要刪除以上錯誤嘗試的記錄嗎?", 0, 2, 'y') != 'n') unlink(genbuf); } check_register(); strncpy(cuser.lasthost, fromhost, 24); substitute_record(fn_passwd, &cuser, sizeof(cuser), usernum); cuser.lasthost[23] = '\0'; restore_backup(); }
int kick_user( struct user_info *userinfo ) { int id, ind; struct user_info uin; struct userec kuinfo; char kickuser[40], buffer[40]; if (uinfo.mode != LUSERS && uinfo.mode != OFFLINE && uinfo.mode != FRIEND) { modify_user_mode(ADMIN); stand_title("踢使用者下站"); move(1, 0); usercomplete("输入使用者帐号: ", kickuser); if (*kickuser == '\0') { clear(); return 0; } if (!(id = getuser(kickuser))) { move(3, 0); prints("无效的用户 ID!"); clrtoeol(); pressreturn(); clear(); return 0; } move(1, 0); clrtoeol(); sprintf(genbuf,"踢掉使用者 : [%s].", kickuser); move(2, 0); if (askyn(genbuf, NA, NA) == NA) { move(2, 0); prints("取消踢使用者..\n"); pressreturn(); clear(); return 0; } search_record(PASSFILE, &kuinfo, sizeof(kuinfo), cmpuids, kickuser); ind = search_ulist(&uin, t_cmpuids, id); } else { uin = *userinfo; strcpy(kickuser, uin.userid); ind = YEA; } if (!ind||!uin.active||(uin.pid && kill(uin.pid, 0)==-1)) { if(uinfo.mode!=LUSERS&&uinfo.mode!=OFFLINE&&uinfo.mode!=FRIEND) { move(3, 0); prints("用户 [%s] 不在线上",kickuser); clrtoeol(); pressreturn(); clear(); } return 0; } kill(uin.pid, SIGHUP); //sprintf(buffer, "kicked %s", kickuser); //report(buffer); if(strcmp(currentuser.userid , kickuser)) { char secu[STRLEN]; sprintf(secu, "将用户[%s]踢下站", kickuser); securityreport(secu); } sprintf(genbuf, "%s (%s)", kuinfo.userid, kuinfo.username); log_usies("KICK ", genbuf); move(2, 0); if(uinfo.mode!=LUSERS&&uinfo.mode!=OFFLINE&&uinfo.mode!=FRIEND) { prints("用户 [%s] 已经被踢下站.\n",kickuser); pressreturn(); clear(); } return 1; }