summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-19 21:47:41 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-19 21:47:41 +0800
commit07a3f1656ee0471d07138865feace636163d422a (patch)
treee9da02b2e5cb52d03474b6c2e02ed6c377de7f77 /mbbsd
parent07d2f9e8f641a93977a34f60d9ee187ab0268a1a (diff)
downloadpttbbs-07a3f1656ee0471d07138865feace636163d422a.tar
pttbbs-07a3f1656ee0471d07138865feace636163d422a.tar.gz
pttbbs-07a3f1656ee0471d07138865feace636163d422a.tar.bz2
pttbbs-07a3f1656ee0471d07138865feace636163d422a.tar.lz
pttbbs-07a3f1656ee0471d07138865feace636163d422a.tar.xz
pttbbs-07a3f1656ee0471d07138865feace636163d422a.tar.zst
pttbbs-07a3f1656ee0471d07138865feace636163d422a.zip
* move ambiguous id check into (emaildb/regcheckd) daemon
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4755 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/Makefile2
-rw-r--r--mbbsd/emaildb.c34
-rw-r--r--mbbsd/register.c68
3 files changed, 37 insertions, 67 deletions
diff --git a/mbbsd/Makefile b/mbbsd/Makefile
index 06fda265..7be123e0 100644
--- a/mbbsd/Makefile
+++ b/mbbsd/Makefile
@@ -37,7 +37,7 @@ CFLAGS+= -DLOG_CRAWLER
.endif
.if !defined(WITHOUT_EMAILDB) && defined(WITH_EMAILDB)
-CFLAGS+= -DUSE_EMAILDB
+CFLAGS+= -DUSE_EMAILDB -DUSE_REGCHECKD
.endif
.if !defined(WITHOUT_BBSLUA_USAGE) && defined(WITH_BBSLUA_USAGE)
diff --git a/mbbsd/emaildb.c b/mbbsd/emaildb.c
index ce493ecc..282b2727 100644
--- a/mbbsd/emaildb.c
+++ b/mbbsd/emaildb.c
@@ -71,6 +71,40 @@ int emaildb_update_email(char * userid, int userid_len, char * email, int email_
return result;
}
+// XXX move to regcheck someday
+int regcheck_ambiguous_userid_exist(const char *userid)
+{
+ int result = -1;
+ int fd = -1;
+ regmaildb_req req = {0};
+
+ // initialize request
+ req.cb = sizeof(req);
+ req.operation = REGCHECK_REQ_AMBIGUOUS;
+ strlcpy(req.userid, userid, sizeof(req.userid));
+ strlcpy(req.email, "ambiguous@check.non-exist", sizeof(req.email));
+
+ if ( (fd = toconnect(REGMAILD_ADDR)) < 0 )
+ {
+ // perror("toconnect");
+ return -1;
+ }
+
+ if (towrite(fd, &req, sizeof(req)) != sizeof(req)) {
+ // perror("towrite");
+ close(fd);
+ return -1;
+ }
+
+ if (toread(fd, &result, sizeof(result)) != sizeof(result)) {
+ // perror("toread");
+ close(fd);
+ return -1;
+ }
+
+ return result;
+}
+
#endif
// vim:et
diff --git a/mbbsd/register.c b/mbbsd/register.c
index 207325f4..2f4bffcc 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -632,70 +632,6 @@ setupnewuser(const userec_t *user)
return uid;
}
-void
-build_unambiguous_userid(char *uid)
-{
- int i = 0;
- const char *ambtbl[] = {
- "0Oo",
- "1Il",
- NULL
- };
-
- for (i = 0; ambtbl[i]; )
- {
- size_t pos = strcspn(uid, ambtbl[i]);
- if (!uid[pos])
- {
- i++;
- continue;
- }
- uid[pos] = ambtbl[i][0];
- uid += (pos+1); // skip the processed character
- }
-}
-
-int
-find_ambiguous_userid(const char *userid)
-{
- const char *ambchars = "0Oo1Il";
- size_t uidlen = 0, iamb;
- char ambuid[IDLEN+1], shmuid[IDLEN+1];
- int i;
-
- assert(userid && *userid);
-
- // if NULL, found nothing.
- iamb = strcspn(userid, ambchars);
- if (!userid[iamb])
- return 0;
-
- // build un-ambiguous uid
- uidlen = strlcpy(ambuid, userid, sizeof(ambuid));
- build_unambiguous_userid(ambuid);
-
- for (i = 0; i < MAX_USERS; i++)
- {
- const char *ruid = SHM->userid[i];
-
- // quick test: same non-amb prefix, and remote uid has amb characters
- if (iamb > 0 && tolower(*ruid) != tolower(*ambuid))
- continue;
- if (!ruid[strcspn(ruid, ambchars)])
- continue;
-
- // copy and check remote uid length
- if (strlcpy(shmuid, ruid, sizeof(shmuid)) != uidlen)
- continue;
-
- build_unambiguous_userid(shmuid);
- if (strcasecmp(shmuid, ambuid) == 0)
- return 1;
- }
-
- return 0;
-}
-
/////////////////////////////////////////////////////////////////////////////
// New Registration (Phase 1: Create Account)
/////////////////////////////////////////////////////////////////////////////
@@ -769,8 +705,8 @@ new_register(void)
}
else if (reserved_user_id(passbuf))
outs("此代號已由系統保留,請使用別的代號\n");
-#ifndef NO_CHECK_AMBIGUOUS_USERID
- else if (find_ambiguous_userid(passbuf))
+#if !defined(NO_CHECK_AMBIGUOUS_USERID) && defined(USE_REGCHECKD)
+ else if (check_ambiguous_userid_exist(passbuf) > 0) // ignore if error occurs
outs("此代號過於近似它人帳號,請改用別的代號。\n");
#endif
else // success