diff options
author | Boian Bonev <bbonev@ipacct.com> | 2011-11-04 00:30:41 +0530 |
---|---|---|
committer | Boian Bonev <bbonev@ipacct.com> | 2011-11-04 00:30:41 +0530 |
commit | 754ed32a9979fd34ee5ceaab451ddd5810faabc6 (patch) | |
tree | 753e42261f4396c7ee6bc99b79df168039a6c796 | |
parent | a987cb67dcda1986b66434244afca24b50bff15d (diff) | |
download | MAC-Telnet-754ed32a9979fd34ee5ceaab451ddd5810faabc6.tar.gz MAC-Telnet-754ed32a9979fd34ee5ceaab451ddd5810faabc6.zip |
move trypassword inside the connection state; generate enckey only once per session
-rw-r--r-- | mactelnetd.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/mactelnetd.c b/mactelnetd.c index ba1aad6..d1842f8 100644 --- a/mactelnetd.c +++ b/mactelnetd.c @@ -84,8 +84,6 @@ static struct in_addr sourceip; static struct in_addr destip; static int sourceport; -static unsigned char trypassword[17]; - static time_t last_mndp_time = 0; /* Protocol data direction */ @@ -115,8 +113,10 @@ struct mt_connection { int slavefd; int pid; int wait_for_ack; + int have_enckey; char username[30]; + unsigned char trypassword[17]; unsigned char srcip[4]; unsigned char srcmac[6]; unsigned short srcport; @@ -412,7 +412,7 @@ static void user_login(struct mt_connection *curconn, struct mt_mactelnet_hdr *p } } - if (user == NULL || memcmp(md5sum, trypassword, 17) != 0) { + if (user == NULL || memcmp(md5sum, curconn->trypassword, 17) != 0) { syslog(LOG_NOTICE, "(%d) Invalid login by %s.", curconn->seskey, curconn->username); abort_connection(curconn, pkthdr, "Login failed, incorrect username or password\r\n"); @@ -542,20 +542,21 @@ static void handle_data_packet(struct mt_connection *curconn, struct mt_mactelne while (success) { if (cpkt.cptype == MT_CPTYPE_BEGINAUTH) { - int plen,i; - for (i = 0; i < 16; ++i) { - curconn->enckey[i] = rand() % 256; - } + if (!curconn->have_enckey) { + for (i = 0; i < 16; ++i) { + curconn->enckey[i] = rand() % 256; + } + curconn->have_enckey=1; + memset(curconn->trypassword, 0, sizeof(curconn->trypassword)); + } init_packet(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter); plen = add_control_packet(&pdata, MT_CPTYPE_ENCRYPTIONKEY, (curconn->enckey), 16); curconn->outcounter += plen; send_udp(curconn, &pdata); - memset(trypassword, 0, sizeof(trypassword)); - } else if (cpkt.cptype == MT_CPTYPE_USERNAME) { memcpy(curconn->username, cpkt.data, cpkt.length > 29 ? 29 : cpkt.length); @@ -579,7 +580,7 @@ static void handle_data_packet(struct mt_connection *curconn, struct mt_mactelne } else if (cpkt.cptype == MT_CPTYPE_PASSWORD) { - memcpy(trypassword, cpkt.data, 17); + memcpy(curconn->trypassword, cpkt.data, 17); got_pass_packet = 1; } else if (cpkt.cptype == MT_CPTYPE_PLAINDATA) { |