summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-03 02:54:28 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-07-03 02:54:28 +0800
commit0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3 (patch)
treed50bbe7db0b6978dbb9eed9df40bc9096f777de6
parent7f55953786fb554ae09961d62e07a466975a6967 (diff)
downloadpttbbs-0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3.tar
pttbbs-0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3.tar.gz
pttbbs-0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3.tar.bz2
pttbbs-0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3.tar.lz
pttbbs-0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3.tar.xz
pttbbs-0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3.tar.zst
pttbbs-0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3.zip
secure .PASSWD
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@406 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/mbbsd/passwd.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c
index 46ea1529..7e877ac4 100644
--- a/pttbbs/mbbsd/passwd.c
+++ b/pttbbs/mbbsd/passwd.c
@@ -1,4 +1,4 @@
-/* $Id: passwd.c,v 1.3 2002/06/30 14:33:14 in2 Exp $ */
+/* $Id: passwd.c,v 1.4 2002/07/02 18:54:28 in2 Exp $ */
#include "bbs.h"
static int semid = -1;
@@ -20,10 +20,7 @@ union semun {
};
#endif
-int PASSWDfd;
int passwd_mmap() {
- if( (PASSWDfd = open(fn_passwd, O_RDWR)) < 0 || PASSWDfd <= 1 )
- return -1;
semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL);
if(semid == -1) {
if(errno == EEXIST) {
@@ -60,19 +57,27 @@ int passwd_update_money(int num) {
}
int passwd_update(int num, userec_t *buf) {
+ int pwdfd;
if(num < 1 || num > MAX_USERS)
return -1;
buf->money = moneyof(num);
- lseek(PASSWDfd, sizeof(userec_t) * (num - 1), SEEK_SET);
- write(PASSWDfd, buf, sizeof(userec_t));
+ if( (pwdfd = open(fn_passwd, O_RDWR)) < 0 )
+ exit(1);
+ lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET);
+ write(pwdfd, buf, sizeof(userec_t));
+ close(pwdfd);
return 0;
}
int passwd_query(int num, userec_t *buf) {
+ int pwdfd;
if(num < 1 || num > MAX_USERS)
return -1;
- lseek(PASSWDfd, sizeof(userec_t) * (num - 1), SEEK_SET);
- read(PASSWDfd, buf, sizeof(userec_t));
+ 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);
return 0;
}