summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-06-04 19:54:03 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-06-04 19:54:03 +0800
commitafdcc476d6f19f96004acb1b96d99b61f2547e39 (patch)
tree620e84ba2a9a6d8777bcaa225b357f5da4bcff53
parent8ffc0739e079717275a19c60f3ecd99516d3398f (diff)
downloadpttbbs-afdcc476d6f19f96004acb1b96d99b61f2547e39.tar
pttbbs-afdcc476d6f19f96004acb1b96d99b61f2547e39.tar.gz
pttbbs-afdcc476d6f19f96004acb1b96d99b61f2547e39.tar.bz2
pttbbs-afdcc476d6f19f96004acb1b96d99b61f2547e39.tar.lz
pttbbs-afdcc476d6f19f96004acb1b96d99b61f2547e39.tar.xz
pttbbs-afdcc476d6f19f96004acb1b96d99b61f2547e39.tar.zst
pttbbs-afdcc476d6f19f96004acb1b96d99b61f2547e39.zip
- improve reg-email check procedure and error message
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4342 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/proto.h2
-rw-r--r--mbbsd/register.c119
-rw-r--r--mbbsd/user.c123
3 files changed, 132 insertions, 112 deletions
diff --git a/include/proto.h b/include/proto.h
index 55df5c00..70274b94 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -537,7 +537,7 @@ int regform_estimate_queuesize();
void new_register(void);
void check_register(void);
void check_birthday(void);
-// void check_register_notify(void);
+int check_regmail(char *email); // check and prompt for invalid reason; will str_lower() mail domain.
void delregcodefile(void);
char *genpasswd(char *pw);
diff --git a/mbbsd/register.c b/mbbsd/register.c
index 25918161..b26107c0 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -3,6 +3,7 @@
#define FN_REGISTER_LOG "register.log" // global registration history
#define FN_REJECT_NOTIFY "justify.reject"
+#define FN_NOTIN_WHITELIST_NOTICE "etc/whitemail.notice"
// Regform1 file name (deprecated)
#define fn_register "register.new"
@@ -854,6 +855,122 @@ new_register(void)
log_usies("REGISTER", fromhost);
}
+int
+check_regmail(char *email)
+{
+ FILE *fp;
+ char buf[128], *c;
+ int allow = 0;
+
+ c = strchr(email, '@');
+ if (c == NULL) return 0;
+
+ // reject multiple '@'
+ if (c != strrchr(email, '@'))
+ {
+ vmsg("E-Mail 的格式不正確。");
+ return 0;
+ }
+
+ // domain tolower
+ str_lower(c, c);
+
+ // allow list
+ allow = 0;
+ if ((fp = fopen("etc/whitemail", "rt")))
+ {
+ while (fgets(buf, sizeof(buf), fp)) {
+ if (buf[0] == '#')
+ continue;
+ chomp(buf);
+ c = buf+1;
+ // vmsgf("%c %s %s",buf[0], c, email);
+ switch(buf[0])
+ {
+ case 'A': if (strcasecmp(c, email) == 0) allow = 1; break;
+ case 'P': if (strcasestr(email, c)) allow = 1; break;
+ case 'S': if (strcasecmp(strstr(email, "@") + 1, c) == 0) allow = 1; break;
+ case '%': allow = 1; break; // allow all
+ // domain match (*@c | *@*.c)
+ case 'D': if (strlen(email) > strlen(c))
+ {
+ // c2 points to starting of possible c.
+ const char *c2 = email + strlen(email) - strlen(c);
+ if (strcasecmp(c2, c) != 0)
+ break;
+ c2--;
+ if (*c2 == '.' || *c2 == '@')
+ allow = 1;
+ }
+ break;
+ }
+ if (allow) break;
+ }
+ fclose(fp);
+ if (!allow)
+ {
+ // show whitemail notice if it exists.
+ if (dashf(FN_NOTIN_WHITELIST_NOTICE))
+ {
+ VREFSCR scr = vscr_save();
+ more(FN_NOTIN_WHITELIST_NOTICE, NA);
+ pressanykey();
+ vscr_restore(scr);
+ } else vmsg("抱歉,目前不接受此 Email 的註冊申請。");
+ return 0;
+ }
+ }
+
+ // reject list
+ allow = 1;
+ if ((fp = fopen("etc/banemail", "r"))) {
+ while (allow && fgets(buf, sizeof(buf), fp)) {
+ if (buf[0] == '#')
+ continue;
+ chomp(buf);
+ c = buf+1;
+ switch(buf[0])
+ {
+ case 'A': if (strcasecmp(c, email) == 0)
+ {
+ allow = 0;
+ // exact match
+ vmsg("此電子信箱已被禁止註冊");
+ }
+ break;
+ case 'P': if (strcasestr(email, c))
+ {
+ allow = 0;
+ vmsg("此信箱已被禁止用於註冊 (可能是免費信箱)");
+ }
+ break;
+ case 'S': if (strcasecmp(strstr(email, "@") + 1, c) == 0)
+ {
+ allow = 0;
+ vmsg("此信箱已被禁止用於註冊 (可能是免費信箱)");
+ }
+ break;
+ case 'D': if (strlen(email) > strlen(c))
+ {
+ // c2 points to starting of possible c.
+ const char *c2 = email + strlen(email) - strlen(c);
+ if (strcasecmp(c2, c) != 0)
+ break;
+ c2--;
+ if (*c2 == '.' || *c2 == '@')
+ {
+ vmsg("此信箱的網域已被禁止用於註冊 (可能是免費信箱)");
+ allow = 0;
+ }
+ }
+ break;
+ }
+ }
+ fclose(fp);
+ }
+ return allow;
+}
+
void
check_birthday(void)
{
@@ -1108,7 +1225,7 @@ toregister(char *email)
}
#endif
- else if (isvalidemail(email)) {
+ else if (check_regmail(email)) {
char yn[3];
#ifdef USE_EMAILDB
int email_count = emaildb_check_email(email, strlen(email));
diff --git a/mbbsd/user.c b/mbbsd/user.c
index fe8fede2..68f79a83 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -1,8 +1,6 @@
/* $Id$ */
#include "bbs.h"
-#define FN_NOTIN_WHITELIST_NOTICE "etc/whitemail.notice"
-
static char * const sex[8] = {
MSG_BIG_BOY, MSG_BIG_GIRL, MSG_LITTLE_BOY, MSG_LITTLE_GIRL,
MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME
@@ -603,7 +601,7 @@ uinfo_query(userec_t *u, int adminmode, int unum)
return;
case 'm':
- do {
+ while (1) {
getdata_str(y, 0, "電子信箱 [變動要重新認證]:", buf,
sizeof(x.email), DOECHO, x.email);
@@ -613,21 +611,27 @@ uinfo_query(userec_t *u, int adminmode, int unum)
if (!buf[0] || strcasecmp(buf, "x") == 0)
break;
- // TODO 這裡也要 emaildb_check
+ if (!check_regmail(buf))
+ continue;
+
+ // XXX 這裡也要 emaildb_check
#ifdef USE_EMAILDB
- if (isvalidemail(buf))
{
int email_count = emaildb_check_email(buf, strlen(buf));
+
if (email_count < 0)
vmsg("暫時不允許\ email 認證, 請稍後再試");
else if (email_count >= EMAILDB_LIMIT)
vmsg("指定的 E-Mail 已註冊過多帳號, 請使用其他 E-Mail");
- else // valid
- break;
+ else
+ break; // valid mail
+ // invalid mail
+ continue;
}
- continue;
#endif
- } while (!isvalidemail(buf) && vmsg("認證信箱不能用使用免費信箱"));
+ // valid mail.
+ break;
+ }
y++;
// admins may want to use special names
@@ -1324,107 +1328,6 @@ u_editplan(void)
return 0;
}
-int
-isvalidemail(char *email)
-{
- FILE *fp;
- char buf[128], *c;
- int allow = 0;
-
- c = strchr(email, '@');
- if (c == NULL) return 0;
-
- // reject multiple '@'
- if (c != strrchr(email, '@')) return 0;
-
- // domain tolower
- for (; *c != 0; ++c)
- if ('A' <= *c && *c <= 'Z')
- *c += 32;
-
- // allow list
- allow = 0;
- if ((fp = fopen("etc/whitemail", "rt")))
- {
- while (fgets(buf, sizeof(buf), fp)) {
- if (buf[0] == '#')
- continue;
- chomp(buf);
- c = buf+1;
- // vmsgf("%c %s %s",buf[0], c, email);
- switch(buf[0])
- {
- case 'A': if (strcasecmp(c, email) == 0) allow = 1; break;
- case 'P': if (strcasestr(email, c)) allow = 1; break;
- case 'S': if (strcasecmp(strstr(email, "@") + 1, c) == 0) allow = 1; break;
- case '%': allow = 1; break; // allow all
- // domain match (*@c | *@*.c)
- case 'D': if (strlen(email) > strlen(c))
- {
- // c2 points to starting of possible c.
- const char *c2 = email + strlen(email) - strlen(c);
- if (strcasecmp(c2, c) != 0)
- break;
- c2--;
- if (*c2 == '.' || *c2 == '@')
- allow = 1;
- }
- break;
- }
- if (allow) break;
- }
- fclose(fp);
- if (!allow)
- {
- // show whitemail notice if it exists.
- if (dashf(FN_NOTIN_WHITELIST_NOTICE))
- {
- VREFSCR scr = vscr_save();
- more(FN_NOTIN_WHITELIST_NOTICE, NA);
- pressanykey();
- vscr_restore(scr);
- }
- return 0;
- }
- }
-
- // reject list
- allow = 1;
- if ((fp = fopen("etc/banemail", "r"))) {
- while (allow && fgets(buf, sizeof(buf), fp)) {
- if (buf[0] == '#')
- continue;
- chomp(buf);
- c = buf+1;
- switch(buf[0])
- {
- case 'A': if (strcasecmp(c, email) == 0)
- allow = 0;
- break;
- case 'P': if (strcasestr(email, c))
- allow = 0;
- break;
- case 'S': if (strcasecmp(strstr(email, "@") + 1, c) == 0)
- allow = 0;
- break;
- case 'D': if (strlen(email) > strlen(c))
- {
- // c2 points to starting of possible c.
- const char *c2 = email + strlen(email) - strlen(c);
- if (strcasecmp(c2, c) != 0)
- break;
- c2--;
- if (*c2 == '.' || *c2 == '@')
- allow = 0;
- }
- break;
- }
- }
- fclose(fp);
- }
- return allow;
-}
-
/* 列出所有註冊使用者 */
struct ListAllUsetCtx {
int usercounter;