summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto.h3
-rw-r--r--mbbsd/Makefile2
-rw-r--r--mbbsd/emaildb.c34
-rw-r--r--mbbsd/register.c68
4 files changed, 40 insertions, 67 deletions
diff --git a/include/proto.h b/include/proto.h
index a2782513..400a6db7 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -191,6 +191,9 @@ const char *ask_tmpbuf(int y);
int emaildb_check_email(char * email, int email_len);
int emaildb_update_email(char * userid, int userid_len, char * email, int email_len);
#endif
+#ifdef USE_REGCHECKD
+int regcheck_ambiguous_userid_exist(const char *userid);
+#endif
/* fav */
void fav_set_old_folder(fav_t *fp);
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