回精華區
作者tandrian.bbs@ntcb.twbbs.org.tw (幻域魔城), 看板: plan
標題[功能] 限制guest帳號
時間幻御魔城 (Sat Aug 17 20:36:32 2002) Updated: 2004/06/24
※ guest 總人數限制

: config.h

+ #define MAXGUEST        (3)             /* 最多參觀者  */

: bbsd.c:login_user()

    else
    {                           /* guest */
      if (acct_load(&cuser, uid) < 0)
      {
        vmsg(err_uid);
        continue;
      }
+     if (utmp_count(cuser.userno, 0) >= MAXGUEST)
+       login_abort("\n" STR_GUEST " 帳號已經爆滿了....再見 ...");
      logattempt(' ', content);
      cuser.userlevel = 0;
      cuser.ufo = UFO_DEFAULT_GUEST;

※ 同 ip 的 guest 總人數限制

: config.h

+ #define MAXGUEST        (3)             /* 最多參觀者  */

: bbsd.c:login_user()

    else
    {                           /* guest */
      if (acct_load(&cuser, uid) < 0)
      {
        vmsg(err_uid);
        continue;
      }
+     if (utmp_ipcount(cuser.userno, &tn_addr) >= MAXGUEST)
+       login_abort("\n" STR_GUEST " 帳號已經爆滿了....再見 ...");
      logattempt(' ', content);
      cuser.userlevel = 0;
      cuser.ufo = UFO_DEFAULT_GUEST;

: maple.p

+int utmp_ipcount(int userno, u_long *address);

: cache.c 於 utmp_count() 下新增這函式

int
utmp_ipcount(userno, address)
  int userno;
  u_long *address;
{
  UTMP *uentp, *uceil;
  int count;
  uschar *addr;
  u_long in_addr;

  count = 0;
  addr = (uschar *) address;
  in_addr = (addr[0] << 24) + (addr[1] << 16) + (addr[2] << 8) + addr[3];
  uentp = ushm->uslot;
  uceil = (void *) uentp + ushm->offset;
  do
  {
    if (uentp->userno == userno && uentp->in_addr == in_addr)
      count++;
  } while (++uentp <= uceil);
  return count;
}

--
    ╦═╗ ╬══ ╔══ ╠═╗  □ Origin: 幻域魔城 - ntcb.twbbs.org
    ╝  ╚ ╚══ ╚══ ╚═╝  □ From: 218-32-98-sparc49.pchome.com
精華選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻