作者amaki.bbs@luna.twbbs.org (午覺羊) 看板: plan
標題[修正]站長改ID跟改userno也要順便改.USR
時間月下夜想 (2003/12/15 Mon 22:16:09) Updated: 2004/01/28
這篇是配合把.USR放入shm那篇patch的修正。
: maple / acct.c
extern BCACHE *bshm;
+extern SCACHE *schema_shm;
acct_setup()前面抄上這支
static void /* amaki.031120: 處理站長變更ID與userno */
schema_rename(old, new)
ACCT *old, *new;
{
int scheno;
SCHEMA u, *p;
if (old->userno == new->userno) /* 沒變更userno的處理 */
{
scheno = old->userno - 1;
memset(&u, 0, sizeof(SCHEMA));
u.uptime = time(0);
strcpy(u.userid, new->userid);
rec_put(FN_SCHEMA, &u, sizeof(SCHEMA), scheno, NULL);
p = schema_shm->schema + scheno;
memcpy(p, &u, sizeof(SCHEMA));
}
else /* 有變更userno的處理 */
{
/* amaki: 先把新的寫進去 */
scheno = new->userno - 1;
memset(&u, 0, sizeof(SCHEMA));
u.uptime = time(0);
strcpy(u.userid, new->userid);
rec_put(FN_SCHEMA, &u, sizeof(SCHEMA), scheno, NULL);
p = schema_shm->schema + scheno;
memcpy(p, &u, sizeof(SCHEMA));
/* 再寫舊的 */
scheno = old->userno - 1;
memset(&u, 0, sizeof(SCHEMA));
u.uptime = time(0);
rec_put(FN_SCHEMA, &u, sizeof(SCHEMA), scheno, NULL);
p = schema_shm->schema + scheno;
memcpy(p, &u, sizeof(SCHEMA));
}
}
改acct_setup()
void
acct_setup(u, adm)
ACCT *u;
int adm;
{
ACCT x;
+ SCHEMA *schema;
! int i, num, ID_dirty = 0;
......
......
vget(i, 0, "使用者代號(不改請按 Enter):", str, IDLEN + 1, GCARRY);
if (!str_cmp(str, u->userid))
break;
+ if (!acct_userno(str))
+ {
+ ID_dirty = 1; /* amaki.031120: 改了ID連SCHEMA也要一起改 */
+ break;
+ }
vmsg("錯誤!已有相同 ID 的使用者");
}
......
......
vget(++i, 0, "用戶編號:", buf, 10, GCARRY);
if ((num = atoi(buf)) > 0)
- x.userno = num;
+ {
+ schema = schema_shm->schema + (num - 1);
+ if (num == u->userno || !*schema->userid)
+ {
+ x.userno = num;
+ ID_dirty = (num == u->userno) ? ID_dirty : 1;
+ }
+ else
+ zmsg("這個編號已經有人使用!");
+ }
......
......
}
+ if (ID_dirty)
+ schema_rename(u, &x);
memcpy(u, &x, sizeof(x));
acct_save(u, adm);
: maple / bbsd.c 新註冊帳號也要寫入shm
#define MAXPORTS 1
static int myports[MAXPORTS] = {23 /* , 3456 */};
extern UCACHE *ushm;
+extern SCACHE *schema_shm;
改acct_apply()
static void
acct_apply()
{
! SCHEMA slot, *p;
char buf[80];
char *userid;
int try, fd;
......
......
fd = open(FN_SCHEMA, O_RDWR | O_CREAT, 0600);
{
/* flock(fd, LOCK_EX); */
/* Thor.981205: 用 fcntl 取代flock, POSIX標準用法 */
f_exlock(fd);
cuser.userno = try = uniq_userno(fd);
write(fd, &slot, sizeof(slot));
+ p = schema_shm->schema + (cuser.userno - 1);
+ memcpy(p, &slot, sizeof(SCHEMA));
/* flock(fd, LOCK_UN); */
/* Thor.981205: 用 fcntl 取代flock, POSIX標準用法 */
f_unlock(fd);
}
close(fd);
--
Origin: luna.twbbs.org