summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-03-23 01:58:52 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-03-23 01:58:52 +0800
commit4404826b6a3baa886cace4a173ff61d72ccc20c2 (patch)
tree18cbb827f6468f3a28d8e22b3763a7ac11d4b34c
parenta83cd092223f8efd9cd6bd8cd3d02134ad26c372 (diff)
downloadpttbbs-4404826b6a3baa886cace4a173ff61d72ccc20c2.tar
pttbbs-4404826b6a3baa886cace4a173ff61d72ccc20c2.tar.gz
pttbbs-4404826b6a3baa886cace4a173ff61d72ccc20c2.tar.bz2
pttbbs-4404826b6a3baa886cace4a173ff61d72ccc20c2.tar.lz
pttbbs-4404826b6a3baa886cace4a173ff61d72ccc20c2.tar.xz
pttbbs-4404826b6a3baa886cace4a173ff61d72ccc20c2.tar.zst
pttbbs-4404826b6a3baa886cace4a173ff61d72ccc20c2.zip
support DETECT_CLIENT, hash telnet sequence.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3298 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/bbs.h1
-rw-r--r--include/fnv_hash.h5
-rw-r--r--mbbsd/cal.c9
-rw-r--r--mbbsd/mbbsd.c54
4 files changed, 68 insertions, 1 deletions
diff --git a/include/bbs.h b/include/bbs.h
index 4931ef99..43352242 100644
--- a/include/bbs.h
+++ b/include/bbs.h
@@ -53,6 +53,7 @@ typedef time_t time4_t;
#include "modes.h"
#include "chess.h"
#include "proto.h"
+#include "fnv_hash.h"
#ifdef ASSESS
#include "assess.h"
diff --git a/include/fnv_hash.h b/include/fnv_hash.h
index 9d8851bd..837fd66c 100644
--- a/include/fnv_hash.h
+++ b/include/fnv_hash.h
@@ -1,3 +1,5 @@
+#ifndef _FNV_HASH_H_
+#define _FNV_HASH_H_
/*
* Fowler / Noll / Vo Hash (FNV Hash)
* http://www.isthe.com/chongo/tech/comp/fnv/
@@ -105,3 +107,6 @@ fnv1a_64_strcase(const char *str, Fnv64_t hval)
}
return hval;
}
+
+#define FNV1A_CHAR(c,hval) do { hval^=(unsigned char)c; hval*=FNV_32_PRIME; } while(0)
+#endif
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,
@@ -458,6 +464,9 @@ p_sysinfo(void)
#else
MAX_ACTIVE,
#endif
+#ifdef DETECT_CLIENT
+ client_code,
+#endif
compile_time, ctime4(&start_time));
if (HasUserPerm(PERM_SYSOP)) {
struct rusage ru;
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<iac_buflen;i++)
+ FNV1A_CHAR(iac_buf[i], client_code);
+ FNV1A_CHAR(IAC, client_code);
+ FNV1A_CHAR(SE, client_code);
+ }
+#endif
break;
}
return 1;