summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-03-29 15:08:51 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-03-29 15:08:51 +0800
commit78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac (patch)
tree6b6badb25cef5e0e1deaef0d5573bc7bf57870ba
parent81e76ebd07b53b84d8f520025e8b546736df4d4e (diff)
downloadpttbbs-78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac.tar
pttbbs-78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac.tar.gz
pttbbs-78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac.tar.bz2
pttbbs-78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac.tar.lz
pttbbs-78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac.tar.xz
pttbbs-78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac.tar.zst
pttbbs-78e0fe9cf6fbf029ca96bf9b00df820f4148c7ac.zip
Add a fast passwd walk function.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5828 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/common/bbs/passwd.c18
-rw-r--r--pttbbs/include/cmbbs.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/pttbbs/common/bbs/passwd.c b/pttbbs/common/bbs/passwd.c
index 0318bc83..acc2813e 100644
--- a/pttbbs/common/bbs/passwd.c
+++ b/pttbbs/common/bbs/passwd.c
@@ -185,6 +185,24 @@ passwd_apply(void *ctx, int (*fptr) (void *ctx, int, userec_t *))
return 0;
}
+int
+passwd_fast_apply(void *ctx, int(*fptr)(void *ctx, int, userec_t *))
+{
+ int i, fd;
+ userec_t user;
+ if ((fd = open(fn_passwd, O_RDONLY)) < 0)
+ exit(1);
+ for (i = 0; i < MAX_USERS; i++) {
+ memset(&user, 0, sizeof(user));
+ if (read(fd, &user, sizeof(user)) != sizeof(user))
+ return -1;
+ if ((*fptr) (ctx, i, &user) < 0)
+ return -1;
+ }
+ close(fd);
+ return 0;
+}
+
// XXX NOTE: string in plain will be destroyed.
int
checkpasswd(const char *passwd, char *plain)
diff --git a/pttbbs/include/cmbbs.h b/pttbbs/include/cmbbs.h
index 5e6b8cbf..9d5bab43 100644
--- a/pttbbs/include/cmbbs.h
+++ b/pttbbs/include/cmbbs.h
@@ -106,6 +106,7 @@ int passwd_update(int num, userec_t *buf);
int passwd_query (int num, userec_t *buf);
int passwd_load_user(const char *userid, userec_t *buf);
int passwd_apply (void *data, int (*fptr)(void *, int, userec_t *));
+int passwd_fast_apply(void *ctx, int(*fptr)(void *ctx, int, userec_t *));
int checkpasswd (const char *passwd, char *test); // test will be destroyed
void logattempt (const char *uid, char type, time4_t now, const char *fromhost);
char*genpasswd (char *pw);