diff options
-rw-r--r-- | common/bbs/string.c | 29 | ||||
-rw-r--r-- | include/cmbbs.h | 1 | ||||
-rw-r--r-- | include/proto.h | 1 | ||||
-rw-r--r-- | mbbsd/admin.c | 4 | ||||
-rw-r--r-- | mbbsd/bbs.c | 16 | ||||
-rw-r--r-- | upgrade/merge_sob.c | 24 |
6 files changed, 55 insertions, 20 deletions
diff --git a/common/bbs/string.c b/common/bbs/string.c index 60b03b37..22c93abb 100644 --- a/common/bbs/string.c +++ b/common/bbs/string.c @@ -1,6 +1,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <assert.h> +#include <ctype.h> #include "cmbbs.h" void obfuscate_ipstr(char *s) @@ -12,3 +14,30 @@ void obfuscate_ipstr(char *s) *s++ = '*'; *s = 0; } + +bool +is_valid_brdname(const char *brdname) +{ + int i; + char ch; + int len; + + assert(brdname); + + len = strlen(brdname); + if (len < 2 || len > IDLEN) + return false; + + for (i = 0; i < len; i++) { + char ch = brdname[i]; + if (i == 0) { + if (!isalpha((int)ch)) + return false; + } else { + if (!isalnum(ch) && ch != '_' && ch != '-' && ch != '.') + return false; + } + } + return true; +} + diff --git a/include/cmbbs.h b/include/cmbbs.h index 6683975e..1ae86161 100644 --- a/include/cmbbs.h +++ b/include/cmbbs.h @@ -27,6 +27,7 @@ extern const char* money_level(int money); /* string.c */ extern void obfuscate_ipstr(char *s); +extern bool is_valid_brdname(const char *brdname); /* time.c */ extern const char *Now(); // m3 flavor time string diff --git a/include/proto.h b/include/proto.h index e0825f08..c30835a5 100644 --- a/include/proto.h +++ b/include/proto.h @@ -61,7 +61,6 @@ int inc_badsale(const char *, int num); /* bbs */ void delete_allpost(const char *userid); -int invalid_brdname(const char *brd); int del_range(int ent, const fileheader_t *fhdr, const char *direct); int cmpfowner(fileheader_t *fhdr); int b_note_edit_bname(int bid); diff --git a/mbbsd/admin.c b/mbbsd/admin.c index b6a5b963..84bf25ea 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -610,7 +610,7 @@ m_mod_board(char *bname) if (getbnum(genbuf)) { move(3, 0); outs("錯誤! 板名雷同"); - } else if ( !invalid_brdname(genbuf) ){ + } else if ( is_valid_brdname(genbuf) ){ strlcpy(newbh.brdname, genbuf, sizeof(newbh.brdname)); break; } @@ -927,7 +927,7 @@ m_newbrd(int whatclass, int recover) if (!getdata(3, 0, msg_bid, newboard.brdname, sizeof(newboard.brdname), DOECHO)) return -1; - } while (invalid_brdname(newboard.brdname)); + } while (!is_valid_brdname(newboard.brdname)); do { getdata(6, 0, "看板類別:", genbuf, 5, DOECHO); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 2f0686e3..d9ed7a86 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1363,22 +1363,6 @@ do_generalboardreply(/*const*/ fileheader_t * fhdr) *quote_file = 0; } - -int -invalid_brdname(const char *brd) -{ - register char ch, rv=0; - - ch = *brd++; - if (!isalpha((int)ch)) - rv = 2; - while ((ch = *brd++)) { - if (not_alnum(ch) && ch != '_' && ch != '-' && ch != '.') - return (1|rv); - } - return rv; -} - int b_call_in(int ent, const fileheader_t * fhdr, const char *direct) { diff --git a/upgrade/merge_sob.c b/upgrade/merge_sob.c index 91b97e37..4a78f112 100644 --- a/upgrade/merge_sob.c +++ b/upgrade/merge_sob.c @@ -197,6 +197,23 @@ m_sob(void) return 0; } +// sob 允許板名用 a-zA-Z0-9_.- 開頭 +// ptt 只允許用 a-zA-Z +static int +is_valid_sob_brdname(const char *brd) +{ + register char ch, rv=0; + + ch = *brd; + if (!isalpha((int)ch)) + rv = 2; + while ((ch = *brd++)) { + if (not_alnum(ch) && ch != '_' && ch != '-' && ch != '.') + return (1|rv); + } + return rv; +} + void m_sob_brd(char *bname, char *fromdir) { @@ -208,8 +225,13 @@ m_sob_brd(char *bname, char *fromdir) if(!getdata(20,0, "SOB的板名 [英文大小寫要完全正確]:", fbname, 20, DOECHO)) return; + } while(!is_valid_sob_brdname(fbname)); + + if (!is_valid_brdname(fbname)) { + // TODO ask for alternative name + vmsg("非系統允許的板名, 暫不支援"); + return; } - while((invalid_brdname(fbname)&1)); sprintf(buf, "sob/man/%s.tar.gz", fbname); if(!dashf(buf)) |