int utmp_logout(int *utmpent, struct user_info *up) { if (*utmpent < 0) { errlog("reenter update_utmp2!"); } else if (!binfo->utmpshm->uinfo[*utmpent - 1].active) errlog("release a empty record! %d", *utmpent); else { remove_uindex(binfo->utmpshm->uinfo[*utmpent - 1].uid, *utmpent); memcpy(&(binfo->utmpshm->uinfo[*utmpent - 1]), up, sizeof (struct user_info)); binfo->utmpshm->guesthash_next[*utmpent] = binfo->utmpshm->guesthash_head[0]; binfo->utmpshm->guesthash_head[0] = *utmpent; binfo->utmpshm->activeuser--; } *utmpent = -1; return 0; }
int bbslogout_main() { struct userec *tmp; int st; char buf[50]; int uid; html_header(1); //modified by safari@20091222 if (!loginok) { redirect(FIRST_PAGE); http_quit(); //http_fatal("你没有登录"); } if (isguest) http_fatal("guest不带注销的"); tmp = getuser(currentuser.userid); currentuser.numposts = tmp->numposts; currentuser.userlevel = tmp->userlevel; currentuser.numlogins = tmp->numlogins; currentuser.stay = tmp->stay; if (now_t > w_info->login_start_time) { st = now_t - w_info->login_start_time; if (st > 86400) errlog("Strange long stay time,%d!, logout, %s", st, currentuser.userid); else { currentuser.stay += st; sprintf(buf, "%s exitbbs %d", currentuser.userid, st); newtrace(buf); } } save_user_data(¤tuser); uid = u_info->uid; remove_uindex(u_info->uid, utmpent); bzero(u_info, sizeof (struct user_info)); if ((currentuser.userlevel & PERM_BOARDS) && count_uindex(uid)==0) setbmstatus(¤tuser, 0); redirect(FIRST_PAGE); return 0; }
char * wwwlogin(struct userec *user, int ipmask) { FILE *fp, *fp1; int n, dolog = 0, st, clubnum, uid, i, nsearch; struct user_info *u; char ULIST[STRLEN]; char genbuf[256], *urlbase, fname[80]; uid = getusernum(user->userid) + 1; if ((urlbase = check_multi(user->userid, uid))) return urlbase; if (strcasecmp(user->userid, "guest") && count_uindex(uid) >= 3) http_fatal("您已经登录了三个帐号,不能再登录了"); // 如果要限制WWW登录窗口数 就打开这个注释. lepton gethostname(genbuf, 256); sprintf(ULIST, MY_BBS_HOME "/%s.%s", ULIST_BASE, genbuf); fp = fopen(ULIST, "a"); flock(fileno(fp), LOCK_EX); nsearch = NSEARCH; //if (strcasecmp(user->userid, "guest")) // nsearch = MAXACTIVE / 4; for (i = 0, n = iphash(fromhost) * (MAXACTIVE / NHASH); i < nsearch; i++, n++) { if (n >= MAXACTIVE) n = 0; u = &(shm_utmp->uinfo[n]); if (u->active && u->pid == 1 && ((now_t - u->lasttime) > 20 * 60 || u->wwwinfo.iskicked)) { st = u->lasttime - u->wwwinfo.login_start_time; if (st > 86400) { errlog("Strange long stay time,%d!, drop %s", st, u->userid); st = 86400; } sprintf(genbuf, "%s drop %d www", u->userid, st); newtrace(genbuf); remove_uindex(u->uid, n + 1); bzero(u, sizeof (struct user_info)); } if (!dolog && u->active == 0) { u_info = u; bzero(u, sizeof (struct user_info)); u->active = 1; u->uid = uid; u->pid = 1; //u->pid = thispid; //modify by mintbaggio@BMY for kill www user u->mode = LOGIN; if (strcasecmp(user->userid, "guest")) u_info->unreadmsg = get_unreadmsg(user->userid); else u_info->unreadmsg = 0; u->userlevel = user->userlevel; u->lasttime = now_t; u->curboard = 0; if (user_perm(user, PERM_LOGINCLOAK) && (user->flags[0] & CLOAK_FLAG)) u->invisible = YEA; u->pager = 0; if (user->userdefine & DEF_FRIENDCALL) u->pager |= FRIEND_PAGER; if (user->flags[0] & PAGER_FLAG) { u->pager |= ALL_PAGER; u->pager |= FRIEND_PAGER; } if (user->userdefine & DEF_FRIENDMSG) u->pager |= FRIENDMSG_PAGER; if (user->userdefine & DEF_ALLMSG) { u->pager |= ALLMSG_PAGER; u->pager |= FRIENDMSG_PAGER; } strsncpy(u->from, fromhost, 24); strsncpy(u->username, user->username, NAMELEN); strsncpy(u->userid, user->userid, IDLEN + 1); getrandomstr(u->sessionid); if (strcasecmp(user->userid, "guest")) initfriends(u); else memset(u->friend, 0, sizeof (u->friend)); urlbase = makeurlbase(n); w_info = &(u_info->wwwinfo); w_info->login_start_time = now_t; w_info->ipmask = ipmask; if (strcasecmp(user->userid, "guest")) { sethomefile(fname, user->userid, "clubrights"); if ((fp1 = fopen(fname, "r")) == NULL) { memset(u_info->clubrights, 0, 4 * sizeof (int)); } else { while (fgets(genbuf, STRLEN, fp1) != NULL) { clubnum = atoi(genbuf); u_info->clubrights[clubnum / 32] |= (1 << clubnum % 32); } fclose(fp1); } set_my_cookie(); } else { memset(u_info->clubrights, 0, 4 * sizeof (int)); w_info->t_lines = 20; w_info->att_mode = 0; w_info->doc_mode = 1; } dolog = 1; add_uindex(u->uid, n + 1); } }
static void utmp_kickidle() { int now; pid_t pid; int n, h, i; struct user_info *uentp, *u; now = time(NULL); if (now < binfo->utmpshm->uptime + 60) return; binfo->utmpshm->uptime = now; for (n = 0; n < MAXACTIVE; n++) { uentp = &(binfo->utmpshm->uinfo[n]); pid = uentp->pid; if (pid == 0) continue; if (uentp->active == 0) continue; if (pid == 1) //www //web session 长度,单位为秒 if ((now - uentp->lasttime < 60 * 60) && !uentp->wwwinfo.iskicked) continue; //telnet ssh 发呆长度,单位为秒 if (pid > 1 && now - uentp->lasttime < 3600) continue; if (pid > 1 && kill(pid, 0) == 0) { //如果进程存在 #ifdef DOTIMEOUT if (now - uentp->lasttime > ((uentp->ext_idle) ? IDLE_TIMEOUT * 3 : IDLE_TIMEOUT)) { kill(pid, SIGHUP); } continue; } #endif if (!strcasecmp(uentp->userid, "guest") && uentp->pid == 1) { u = &(binfo->utmpshm->uinfo[n]); h = utmp_iphash(u->from); i = binfo->utmpshm->guesthash_head[h]; if (i == n + 1) { binfo->utmpshm->guesthash_head[h] = binfo->utmpshm->guesthash_next[i]; } else { while (binfo->utmpshm->guesthash_next[i] != 0) { if (binfo->utmpshm->guesthash_next[i] == n + 1) { binfo->utmpshm-> guesthash_next[i] = binfo->utmpshm-> guesthash_next[n + 1]; break; } else { i = binfo->utmpshm-> guesthash_next[i]; } } } binfo->utmpshm->wwwguestnum--; } binfo->utmpshm->guesthash_next[n + 1] = binfo->utmpshm->guesthash_head[0]; binfo->utmpshm->guesthash_head[0] = n + 1; binfo->utmpshm->activeuser--; remove_uindex(uentp->uid, n + 1); uentp->active = 0; uentp->pid = 0; uentp->invisible = 1; uentp->sockactive = 0; uentp->sockaddr = 0; uentp->destuid = 0; uentp->lasttime = 0; } }