diff options
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/admin.c | 4 | ||||
-rw-r--r-- | mbbsd/angel.c | 2 | ||||
-rw-r--r-- | mbbsd/assess.c | 6 | ||||
-rw-r--r-- | mbbsd/bbs.c | 10 | ||||
-rw-r--r-- | mbbsd/cache.c | 14 | ||||
-rw-r--r-- | mbbsd/cal.c | 4 | ||||
-rw-r--r-- | mbbsd/chc.c | 6 | ||||
-rw-r--r-- | mbbsd/go.c | 6 | ||||
-rw-r--r-- | mbbsd/gomo.c | 6 | ||||
-rw-r--r-- | mbbsd/mail.c | 2 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 6 | ||||
-rw-r--r-- | mbbsd/passwd.c | 243 | ||||
-rw-r--r-- | mbbsd/register.c | 12 | ||||
-rw-r--r-- | mbbsd/user.c | 16 |
14 files changed, 89 insertions, 248 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 90676799..ad986097 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -63,10 +63,10 @@ static int retrieve_backup(userec_t *user) if ((uid = searchuser(user->userid, user->userid))) { userec_t orig; - passwd_query(uid, &orig); + passwd_sync_query(uid, &orig); strlcpy(user->passwd, orig.passwd, sizeof(orig.passwd)); setumoney(uid, user->money); - passwd_update(uid, user); + passwd_sync_update(uid, user); return 0; } diff --git a/mbbsd/angel.c b/mbbsd/angel.c index fa53240f..e2eef9ec 100644 --- a/mbbsd/angel.c +++ b/mbbsd/angel.c @@ -270,7 +270,7 @@ FindAngel(void){ !angel_reject_me(u) && u->userid[0]){ strlcpy(cuser.myangel, u->userid, sizeof(cuser.myangel)); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); return 1; } }while(++trial < 5); diff --git a/mbbsd/assess.c b/mbbsd/assess.c index deacabf2..5fa25f0f 100644 --- a/mbbsd/assess.c +++ b/mbbsd/assess.c @@ -21,7 +21,7 @@ int inc_##_attr(const char *userid, int num) \ int uid = getuser(userid, &xuser);\ if( uid > 0 ){ \ inc(&xuser._attr, num); \ - passwd_update(uid, &xuser); \ + passwd_sync_update(uid, &xuser); \ return xuser._attr; }\ return 0;\ } @@ -51,7 +51,7 @@ void set_assess(const char *userid, unsigned char num, int type) xuser.badsale = num; break; } - passwd_update(uid, &xuser); + passwd_sync_update(uid, &xuser); } #endif @@ -260,7 +260,7 @@ u_fixgoodpost(void) cuser.goodpost = newgp; // update passwd file here? passwd_force_update(ALERT_PWD_GOODPOST); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); vmsgf("更新優文數目為%d。", newgp); } diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index d9ed7a86..549b46c7 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -232,7 +232,7 @@ save_violatelaw(void) // force overriding alerts if(currutmp) currutmp->alerts &= ~ALERT_PWD_PERM; - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); sendalert(cuser.userid, ALERT_PWD_PERM); log_filef("log/violation", LOG_CREAT, "%s %s pay-violation: $%d complete.\n", @@ -3256,12 +3256,12 @@ del_post(int ent, fileheader_t * fhdr, char *direct) mail_violatelaw(userid, BBSMNAME " 系統警察", "劣文累計 5 篇", "罰單一張"); kick_all(userid); - passwd_query(tusernum, &xuser); + passwd_sync_query(tusernum, &xuser); xuser.money = moneyof(tusernum); xuser.vl_count++; xuser.userlevel |= PERM_VIOLATELAW; xuser.timeviolatelaw = now; - passwd_update(tusernum, &xuser); + passwd_sync_update(tusernum, &xuser); } sendalert(userid, ALERT_PWD_BADPOST); mail_id(userid, genbuf, newpath, cuser.userid); @@ -3323,9 +3323,9 @@ del_post(int ent, fileheader_t * fhdr, char *direct) if (tusernum) { userec_t xuser; - passwd_query(tusernum, &xuser); + passwd_sync_query(tusernum, &xuser); xuser.numposts--; - passwd_update(tusernum, &xuser); + passwd_sync_update(tusernum, &xuser); sendalert_uid(tusernum, ALERT_PWD_POSTS); // TODO alert user? diff --git a/mbbsd/cache.c b/mbbsd/cache.c index ebbf164f..3860dd1f 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -6,9 +6,21 @@ #endif /* - * section - utmp cache + * section - user & utmp cache */ +int +getuser(const char *userid, userec_t *xuser) +{ + int uid; + + if ((uid = searchuser(userid, NULL))) { + passwd_sync_query(uid, xuser); + xuser->money = moneyof(uid); + } + return uid; +} + void getnewutmpent(const userinfo_t * up) { diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 23520a33..75ba8857 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -259,9 +259,9 @@ static int inmailbox(int m) { userec_t xuser; - passwd_query(usernum, &xuser); + passwd_sync_query(usernum, &xuser); cuser.exmailbox = xuser.exmailbox + m; - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); return cuser.exmailbox; } diff --git a/mbbsd/chc.c b/mbbsd/chc.c index 4df8e2d7..1b490699 100644 --- a/mbbsd/chc.c +++ b/mbbsd/chc.c @@ -848,9 +848,9 @@ chc(int s, ChessGameMode mode) /* Assume that info->user1 is me. */ info->user1.lose++; count_chess_elo_rating(&info->user1, &info->user2, 0.0); - passwd_query(usernum, &cuser); + passwd_sync_query(usernum, &cuser); chcusr_put(&cuser, &info->user1); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); } if (mode == CHESS_MODE_WATCH) @@ -905,7 +905,7 @@ chc_gameend(ChessInfo* info, ChessGameResult result) } currutmp->chess_elo_rating = user1->rating; chcusr_put(&cuser, user1); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); @@ -821,7 +821,7 @@ go_gameend(ChessInfo* info, ChessGameResult result) go_usr_put(&cuser, user1); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); @@ -936,9 +936,9 @@ gochess(int s, ChessGameMode mode) if (info->mode == CHESS_MODE_VERSUS) { /* Assume that info->user1 is me. */ info->user1.lose++; - passwd_query(usernum, &cuser); + passwd_sync_query(usernum, &cuser); go_usr_put(&cuser, &info->user1); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); } if (mode == CHESS_MODE_WATCH) diff --git a/mbbsd/gomo.c b/mbbsd/gomo.c index d68a61eb..575d4aee 100644 --- a/mbbsd/gomo.c +++ b/mbbsd/gomo.c @@ -412,7 +412,7 @@ gomo_gameend(ChessInfo* info, ChessGameResult result) gomoku_usr_put(&cuser, user1); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); @@ -535,9 +535,9 @@ gomoku(int s, ChessGameMode mode) if (info->mode == CHESS_MODE_VERSUS) { /* Assume that info->user1 is me. */ info->user1.lose++; - passwd_query(usernum, &cuser); + passwd_sync_query(usernum, &cuser); gomoku_usr_put(&cuser, &info->user1); - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); } if (mode == CHESS_MODE_WATCH) diff --git a/mbbsd/mail.c b/mbbsd/mail.c index c006bac6..e0185e4a 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1385,7 +1385,7 @@ static int mail_nooutmail(int ent GCC_UNUSED, fileheader_t * fhdr GCC_UNUSED, const char *direct GCC_UNUSED) { cuser.uflag2 ^= REJ_OUTTAMAIL; - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); return FULLUPDATE; } diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 5f27d0bd..4cdf284d 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -227,7 +227,7 @@ u_exit(const char *mode) cuser.badsale = currutmp->badsale; */ - // no need because in later passwd_update will reload money from SHM. + // no need because in later passwd_sync_update will reload money from SHM. // reload_money(); setflags(PAGER_FLAG, currutmp->pager != PAGER_ON); @@ -250,7 +250,7 @@ u_exit(const char *mode) cuser.numlogins = --cuser.numlogins; /* Leeym 上站停留時間限制式 */ } - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); purge_utmp(currutmp); log_usies(mode, NULL); } @@ -1335,7 +1335,7 @@ user_login(void) foreign_warning(); #endif - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); if(cuser.uflag2 & FAVNEW_FLAG) { fav_load(); diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 86a347ba..f4b7a654 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -1,74 +1,10 @@ /* $Id$ */ #include "bbs.h" -static int semid = -1; - -#ifndef SEM_R -#define SEM_R 0400 -#endif - -#ifndef SEM_A -#define SEM_A 0200 -#endif - -#ifndef __FreeBSD__ -#include <sys/sem.h> -union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ - unsigned short *array; /* array for GETALL & SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ -}; +#ifdef _BBS_UTIL_C_ +#error sorry, mbbsd/passwd.c does not support utility mode anymore. please use libcmbbs instead. #endif -int -passwd_init(void) -{ - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); - if (semid == -1) { - if (errno == EEXIST) { - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); - if (semid == -1) { - perror("semget"); - exit(1); - } - } else { - perror("semget"); - exit(1); - } - } else { - union semun s; - - s.val = 1; - if (semctl(semid, 0, SETVAL, s) == -1) { - perror("semctl"); - exit(1); - } - } - - return 0; -} - -int -passwd_update_money(int num) -/* update money only - Ptt: don't call it directly, call deumoney() */ -{ - int pwdfd; - int money=moneyof(num); - userec_t u; - if (num < 1 || num > MAX_USERS) - return -1; - - if ((pwdfd = open(fn_passwd, O_WRONLY)) < 0) - exit(1); - lseek(pwdfd, sizeof(userec_t) * (num - 1) + - ((char *)&u.money - (char *)&u), SEEK_SET); - write(pwdfd, &money, sizeof(int)); - close(pwdfd); - return 0; -} - void passwd_force_update(int flag) { @@ -77,24 +13,37 @@ passwd_force_update(int flag) currutmp->alerts &= ~flag; } +int +initcuser(const char *userid) +{ + usernum = passwd_load_user(userid, &cuser); + return usernum; +} + +// XXX I don't like the stupid synchronization here, +// but simply following previous work here... int -passwd_update(int num, userec_t * buf) +passwd_sync_update(int num, userec_t * buf) { - int pwdfd; + int alerts; + if (num < 1 || num > MAX_USERS) return -1; - buf->money = moneyof(num); - if(usernum == num && currutmp && ((pwdfd = currutmp->alerts) & ALERT_PWD)) + + if(usernum == num && currutmp && ((alerts = currutmp->alerts) & ALERT_PWD)) { userec_t u; - passwd_query(num, &u); - if(pwdfd & ALERT_PWD_BADPOST) + buf->money = moneyof(num); + if (passwd_sync_query(num, &u) != 0) + return -1; + + if(alerts & ALERT_PWD_BADPOST) cuser.badpost = buf->badpost = u.badpost; - if(pwdfd & ALERT_PWD_GOODPOST) + if(alerts & ALERT_PWD_GOODPOST) cuser.goodpost = buf->goodpost = u.goodpost; - if(pwdfd & ALERT_PWD_PERM) + if(alerts & ALERT_PWD_PERM) cuser.userlevel = buf->userlevel = u.userlevel; - if(pwdfd & ALERT_PWD_JUSTIFY) + if(alerts & ALERT_PWD_JUSTIFY) { memcpy(buf->justify, u.justify, sizeof(u.justify)); memcpy(cuser.justify, u.justify, sizeof(u.justify)); @@ -105,156 +54,36 @@ passwd_update(int num, userec_t * buf) currutmp->alerts &= ~ALERT_PWD; // ALERT_PWD_RELOAD: reload all! No need to write. - if (pwdfd & ALERT_PWD_RELOAD) + if (alerts & ALERT_PWD_RELOAD) { memcpy(&cuser, &u, sizeof(u)); return 0; } } - if ((pwdfd = open(fn_passwd, O_WRONLY)) < 0) - exit(1); - lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); - write(pwdfd, buf, sizeof(userec_t)); - close(pwdfd); -#ifndef _BBS_UTIL_C_ - if (latest_numposts != cuser.numposts) { + if (passwd_sync_update(num, buf) != 0) + return -1; + + if (currutmp && usernum > 0 && + latest_numposts != cuser.numposts) + { sendalert_uid(usernum, ALERT_PWD_POSTS); latest_numposts = cuser.numposts; } -#endif + return 0; } +// XXX I don't like the stupid synchronization here, +// but simply following previous work here... int -passwd_query(int num, userec_t * buf) +passwd_sync_query(int num, userec_t * buf) { - int pwdfd; - if (num < 1 || num > MAX_USERS) + if (passwd_sync_query(num, buf) < 0) return -1; - if ((pwdfd = open(fn_passwd, O_RDONLY)) < 0) - exit(1); - lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); - read(pwdfd, buf, sizeof(userec_t)); - close(pwdfd); if (buf == &cuser) latest_numposts = cuser.numposts; return 0; } - -int initcuser(const char *userid) -{ - // Ptt: setup cuser and usernum here - if(userid[0]=='\0' || - !(usernum = searchuser(userid, NULL)) || usernum > MAX_USERS) - return -1; - passwd_query(usernum, &cuser); - return usernum; -} - -int -passwd_apply(void *ctx, int (*fptr) (void *ctx, int, userec_t *)) -{ - int i; - userec_t user; - for (i = 0; i < MAX_USERS; i++) { - passwd_query(i + 1, &user); - if ((*fptr) (ctx, i, &user) < 0) - return -1; - } - return 0; -} - -void -passwd_lock(void) -{ - struct sembuf buf = {0, -1, SEM_UNDO}; - - if (semop(semid, &buf, 1)) { - perror("semop"); - exit(1); - } -} - -void -passwd_unlock(void) -{ - struct sembuf buf = {0, 1, SEM_UNDO}; - - if (semop(semid, &buf, 1)) { - perror("semop"); - exit(1); - } -} - -// XXX NOTE: string in plain will be destroyed. -int -checkpasswd(const char *passwd, char *plain) -{ - int ok; - char *pw; - - ok = 0; - pw = fcrypt(plain, passwd); - if(pw && strcmp(pw, passwd)==0) - ok = 1; - memset(plain, 0, strlen(plain)); - - return ok; -} - -char * -genpasswd(char *pw) -{ - if (pw[0]) { - char saltc[2], c; - int i; - - i = 9 * getpid(); - saltc[0] = i & 077; - saltc[1] = (i >> 6) & 077; - - for (i = 0; i < 2; i++) { - c = saltc[i] + '.'; - if (c > '9') - c += 7; - if (c > 'Z') - c += 6; - saltc[i] = c; - } - return fcrypt(pw, saltc); - } - return ""; -} - - -void -logattempt(const char *uid, char type, time4_t now, const char *loghost) -{ - char fname[PATHLEN]; - int fd, len; - char genbuf[200]; - - snprintf(genbuf, sizeof(genbuf), "%c%-12s[%s] ?@%s\n", type, uid, - Cdate(&now), loghost); - len = strlen(genbuf); - // log to public (BBSHOME) - if ((fd = open(FN_BADLOGIN, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { - write(fd, genbuf, len); - close(fd); - } - // log to user private log - if (type == '-') { - snprintf(genbuf, sizeof(genbuf), - "[%s] %s\n", Cdate(&now), loghost); - len = strlen(genbuf); - sethomefile(fname, uid, FN_BADLOGIN); - if ((fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { - write(fd, genbuf, len); - close(fd); - } - } -} - diff --git a/mbbsd/register.c b/mbbsd/register.c index 473f2f57..eaa85fb2 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -585,7 +585,7 @@ setupnewuser(const userec_t *user) /* 不曉得為什麼要從 2 開始... Ptt:因為SYSOP在1 */ for (uid = 2; uid <= MAX_USERS; uid++) { - passwd_query(uid, &utmp); + passwd_sync_query(uid, &utmp); // tolerate for one year. check_and_expire_account(uid, &utmp, 365*12*60); } @@ -611,7 +611,7 @@ setupnewuser(const userec_t *user) SHM->money[uid - 1] = user->money; - if (passwd_update(uid, (userec_t *)user) == -1) { + if (passwd_sync_update(uid, (userec_t *)user) == -1) { passwd_unlock(); vmsg("客滿了,再見!"); exit(1); @@ -1030,7 +1030,7 @@ check_register(void) { xun = atoi(buf+1); if (xun < 0 || xun >= MAX_USERS || - passwd_query(xun, &u) < 0 || + passwd_sync_query(xun, &u) < 0 || !(u.userlevel & (PERM_ACCOUNTS | PERM_ACCTREG))) memset(&u, 0, sizeof(u)); // now u is valid only if reference is loaded with account sysop. @@ -1532,7 +1532,7 @@ u_register(void) toregister(email); // update cuser - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); return FULLUPDATE; } @@ -1738,7 +1738,7 @@ regform_accept(const char *userid, const char *justify) unlink(buf); // update password file - passwd_update(unum, &muser); + passwd_sync_update(unum, &muser); // alert online users? if (search_ulist(unum)) @@ -1777,7 +1777,7 @@ regform_reject(const char *userid, const char *reason, const RegformEntry *pre) // handle files // update password file - passwd_update(unum, &muser); + passwd_sync_update(unum, &muser); // alert online users? if (search_ulist(unum)) diff --git a/mbbsd/user.c b/mbbsd/user.c index 7ef3578f..0111869c 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -35,7 +35,7 @@ kill_user(int num, const char *userid) memset(&u, 0, sizeof(userec_t)); log_usies("KILL", getuserid(num)); setuserid(num, ""); - passwd_update(num, &u); + passwd_sync_update(num, &u); return 0; } int @@ -67,7 +67,7 @@ u_loginview(void) if (pbits != cuser.loginview) { cuser.loginview = pbits; - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); } return 0; } @@ -80,7 +80,7 @@ int u_cancelbadpost(void) if(search_ulistn(usernum,2)) {vmsg("請登出其他視窗, 否則不受理."); return 0;} - passwd_query(usernum, &cuser); + passwd_sync_query(usernum, &cuser); if (currutmp && (currutmp->alerts & ALERT_PWD)) currutmp->alerts &= ~ALERT_PWD; @@ -105,7 +105,7 @@ int u_cancelbadpost(void) { int prev = cuser.badpost--; cuser.timeremovebadpost = now; - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); log_filef("log/cancelbadpost.log", LOG_CREAT, "%s %s 刪除一篇劣文 (%d -> %d 篇)\n", Cdate(&now), cuser.userid, prev, cuser.badpost); @@ -340,7 +340,7 @@ violate_law(userec_t * u, int unum) u->userlevel |= PERM_VIOLATELAW; u->timeviolatelaw = now; u->vl_count++; - passwd_update(unum, u); + passwd_sync_update(unum, u); post_violatelaw(u->userid, cuser.userid, reason, "罰單處份"); mail_violatelaw(u->userid, "站務警察", reason, "罰單處份"); } @@ -527,7 +527,7 @@ void Customize(void) if(dirty) { - passwd_update(usernum, &cuser); + passwd_sync_update(usernum, &cuser); outs("設定已儲存。\n"); } else { outs("結束設定。\n"); @@ -942,7 +942,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) break; } else { userec_t atuser; - passwd_query(uid, &atuser); + passwd_sync_query(uid, &atuser); if (now - atuser.firstlogin < 6 * 30 * 24 * 60 * 60) { outs("\n註冊未超過半年,請重新輸入\n"); i--; @@ -1101,7 +1101,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) setumoney(unum, x.money); } - passwd_update(unum, &x); + passwd_sync_update(unum, &x); if (adminmode) { |