summaryrefslogtreecommitdiffstats
path: root/common/bbs/passwd.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-06-12 20:22:07 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-06-12 20:22:07 +0800
commit2f6959aecaaaed4980f7c8740f2fae2c8fc326ca (patch)
treed3d59847cadac9939bc0e9945530cfd1b7a5caeb /common/bbs/passwd.c
parentc5f8e88cde8ad8120fd5e2bdaddd2f5591502aa8 (diff)
downloadpttbbs-2f6959aecaaaed4980f7c8740f2fae2c8fc326ca.tar
pttbbs-2f6959aecaaaed4980f7c8740f2fae2c8fc326ca.tar.gz
pttbbs-2f6959aecaaaed4980f7c8740f2fae2c8fc326ca.tar.bz2
pttbbs-2f6959aecaaaed4980f7c8740f2fae2c8fc326ca.tar.lz
pttbbs-2f6959aecaaaed4980f7c8740f2fae2c8fc326ca.tar.xz
pttbbs-2f6959aecaaaed4980f7c8740f2fae2c8fc326ca.tar.zst
pttbbs-2f6959aecaaaed4980f7c8740f2fae2c8fc326ca.zip
* refine cmbbs: move util_passwd.o to cmbbs/passwd.c.
* note: in order to workaround the buggy/dirty synchronization hacks, changed 'passwd_query' and 'passwd_update' to passwd_sync_*. * util/* and daemon/* use directly passwd_query/update, and mbbsd should use passwd_sync_*. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4574 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'common/bbs/passwd.c')
-rw-r--r--common/bbs/passwd.c135
1 files changed, 60 insertions, 75 deletions
diff --git a/common/bbs/passwd.c b/common/bbs/passwd.c
index 3c41793d..3e55d4d2 100644
--- a/common/bbs/passwd.c
+++ b/common/bbs/passwd.c
@@ -1,12 +1,31 @@
/* $Id$ */
+#include <assert.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
+#include <sys/shm.h>
#include <sys/sem.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include "common.h"
+#include "var.h"
#include "cmbbs.h"
-#if 0
+//////////////////////////////////////////////////////////////////////////
+// This is shared by utility library and core BBS,
+// so do not put code using currutmp/cuser here.
+//////////////////////////////////////////////////////////////////////////
+
+// these cannot be used!
+#define currutmp YOU_FAILED
+#define usernum YOU_FAILED
+#define cuser YOU_FAILED
+#define abort_bbs YOU_FAILED
+#define log_usies YOU_FAILED
static int semid = -1;
@@ -28,6 +47,8 @@ union semun {
};
#endif
+// semaphore based PASSWD locking
+
int
passwd_init(void)
{
@@ -56,6 +77,30 @@ passwd_init(void)
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);
+ }
+}
+
+// updateing passwd/userec_t
+
int
passwd_update_money(int num)
/* update money only
@@ -76,60 +121,19 @@ passwd_update_money(int num)
return 0;
}
-void
-passwd_force_update(int flag)
-{
- if(!currutmp || (currutmp->alerts & ALERT_PWD) == 0)
- return;
- currutmp->alerts &= ~flag;
-}
-
int
passwd_update(int num, userec_t * buf)
{
int pwdfd;
if (num < 1 || num > MAX_USERS)
return -1;
- buf->money = moneyof(num);
- if(usernum == num && currutmp && ((pwdfd = currutmp->alerts) & ALERT_PWD))
- {
- userec_t u;
- passwd_query(num, &u);
- if(pwdfd & ALERT_PWD_BADPOST)
- cuser.badpost = buf->badpost = u.badpost;
- if(pwdfd & ALERT_PWD_GOODPOST)
- cuser.goodpost = buf->goodpost = u.goodpost;
- if(pwdfd & ALERT_PWD_PERM)
- cuser.userlevel = buf->userlevel = u.userlevel;
- if(pwdfd & ALERT_PWD_JUSTIFY)
- {
- memcpy(buf->justify, u.justify, sizeof(u.justify));
- memcpy(cuser.justify, u.justify, sizeof(u.justify));
- memcpy(buf->email, u.email, sizeof(u.email));
- memcpy(cuser.email, u.email, sizeof(u.email));
- }
- cuser.numposts += u.numposts - latest_numposts;
- currutmp->alerts &= ~ALERT_PWD;
-
- // ALERT_PWD_RELOAD: reload all! No need to write.
- if (pwdfd & 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) {
- sendalert_uid(usernum, ALERT_PWD_POSTS);
- latest_numposts = cuser.numposts;
- }
-#endif
return 0;
}
@@ -145,20 +149,24 @@ passwd_query(int num, userec_t * buf)
read(pwdfd, buf, sizeof(userec_t));
close(pwdfd);
- if (buf == &cuser)
- latest_numposts = cuser.numposts;
-
return 0;
}
-int initcuser(const char *userid)
+int
+passwd_load_user(const char *userid, userec_t *buf)
{
- // Ptt: setup cuser and usernum here
- if(userid[0]=='\0' ||
- !(usernum = searchuser(userid, NULL)) || usernum > MAX_USERS)
+ int unum = 0;
+
+ if( !userid ||
+ !userid[0] ||
+ !(unum = searchuser(userid, NULL)) ||
+ unum > MAX_USERS)
return -1;
- passwd_query(usernum, &cuser);
- return usernum;
+
+ if (passwd_query(unum, buf) != 0)
+ return -1;
+
+ return unum;
}
int
@@ -174,28 +182,6 @@ passwd_apply(void *ctx, int (*fptr) (void *ctx, int, userec_t *))
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)
@@ -265,4 +251,3 @@ logattempt(const char *uid, char type, time4_t now, const char *loghost)
}
}
-#endif