From 4404826b6a3baa886cace4a173ff61d72ccc20c2 Mon Sep 17 00:00:00 2001 From: kcwu Date: Wed, 22 Mar 2006 17:58:52 +0000 Subject: support DETECT_CLIENT, hash telnet sequence. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3298 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/cal.c | 9 +++++++++ mbbsd/mbbsd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) (limited to 'mbbsd') diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 100786b6..e21ce80f 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -440,6 +440,9 @@ p_sysinfo(void) char *cpuloadstr; int load; extern char *compile_time; +#ifdef DETECT_CLIENT + extern Fnv32_t client_code; +#endif load = cpuload(NULL); cpuloadstr = (load < 5 ? "良好" : (load < 20 ? "尚可" : "過重")); @@ -450,6 +453,9 @@ p_sysinfo(void) prints("您現在位於 " TITLE_COLOR BBSNAME ANSI_RESET " (" MYIP ")\n" "系統負載情況: %s\n" "線上服務人數: %d/%d\n" +#ifdef DETECT_CLIENT + "client code: %8.8X\n" +#endif "編譯時間: %s\n" "起始時間: %s\n", cpuloadstr, SHM->UTMPnumber, @@ -457,6 +463,9 @@ p_sysinfo(void) SHM->GV2.e.dymaxactive > 2000 ? SHM->GV2.e.dymaxactive : MAX_ACTIVE, #else MAX_ACTIVE, +#endif +#ifdef DETECT_CLIENT + client_code, #endif compile_time, ctime4(&start_time)); if (HasUserPerm(PERM_SYSOP)) { diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 6b071fd1..722c059f 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -33,6 +33,9 @@ static char remoteusername[40] = "?"; static unsigned char enter_uflag; static int use_shell_login_mode = 0; +#ifdef DETECT_CLIENT +Fnv32_t client_code=FNV1_32_INIT; +#endif #ifdef USE_RFORK #define fork() rfork(RFFDG | RFPROC | RFNOWAIT) @@ -718,6 +721,15 @@ login_query(void) } } multi_user_check(); +#ifdef DETECT_CLIENT + { + int fd = open("log/client_code",O_WRONLY | O_CREAT | O_APPEND, 0644); + if(fd>=0) { + write(fd, &client_code, sizeof(client_code)); + close(fd); + } + } +#endif } void @@ -1501,6 +1513,9 @@ shell_login(int argc, char *argv[], char *envp[]) #endif return 0; } +#ifdef DETECT_CLIENT + FNV1A_CHAR(123, client_code); +#endif return 1; } @@ -1813,6 +1828,19 @@ telnet_handler(unsigned char c) return NOP; } +#ifdef DETECT_CLIENT + /* hash client telnet sequences */ + if(cuser.userid[0]==0) { + if(iac_state == IAC_WAIT_SE) { + // skip suboption + } else { + if(iac_quote) + FNV1A_CHAR(IAC, client_code); + FNV1A_CHAR(c, client_code); + } + } +#endif + /* a special case is the top level iac. otherwise, iac is just a quote. */ if (iac_quote) { if(iac_state == IAC_NONE) @@ -1969,11 +1997,35 @@ telnet_handler(unsigned char c) { int w = (iac_buf[1] << 8) + (iac_buf[2]); int h = (iac_buf[3] << 8) + (iac_buf[4]); - term_resize(w, h); + term_resize(w, h); +#ifdef DETECT_CLIENT + if(cuser.userid[0]==0) { + FNV1A_CHAR(iac_buf[0], client_code); + if(w==80 && h==24) + FNV1A_CHAR(1, client_code); + else if(w==80) + FNV1A_CHAR(2, client_code); + else if(h==24) + FNV1A_CHAR(3, client_code); + else + FNV1A_CHAR(4, client_code); + FNV1A_CHAR(IAC, client_code); + FNV1A_CHAR(SE, client_code); + } +#endif } break; default: +#ifdef DETECT_CLIENT + if(cuser.userid[0]==0) { + int i; + for(i=0;i