diff --git a/Makefile.am b/Makefile.am index 0e78ce4..d97a98e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,9 +6,7 @@ dist_doc_DATA = README dist_man_MANS = mentohust.1 -SPEC = mentohust.spec - -EXTRA_DIST = @PACKAGE_NAME@.spec.in m4 $(SPEC) debian/changelog debian/compat debian/control debian/copyright debian/rules debian/watch +EXTRA_DIST = @PACKAGE_NAME@.spec.in m4 debian/changelog debian/compat debian/control debian/copyright debian/rules debian/watch rpm: dist @PACKAGE_NAME@.spec rpmbuild -bb \ @@ -18,7 +16,6 @@ rpm: dist @PACKAGE_NAME@.spec --define "_rpmdir `pwd`" \ --define "_srcrpmdir `pwd`" \ @PACKAGE_NAME@.spec - deb: debian/rules dpkg-buildpackage -rfakeroot -uc -b -d diff --git a/README b/README index 30b33e0..90131c6 100644 --- a/README +++ b/README @@ -3,14 +3,30 @@ #安装mentohust:建议Ubuntu用户使用Deb包安装,Fedora用户使用RPM包安装 #如果确定自己可以使用xrgsu认证成功,打开终端输入sudo mentohust运行即可 -#如果不确定,切换到锐捷所在目录,然后输入以下命令: +如果不确定,切换到锐捷所在目录,然后输入以下命令: sudo mkdir /etc/mentohust sudo cp ./8021x.exe /etc/mentohust -#如果准确按以上步骤操作后还是认证失败,请下载MentoHUSTTool,在Windows下抓包并保存为data.mpf, +sudo cp ./W32N55.dll /etc/mentohust +然后打开终端输入sudo mentohust运行。如果认证失败,再切换到锐捷所在目录,输入以下命令: +sudo cp ./SuConfig.dat /etc/mentohust +然后打开终端输入sudo mentohust运行即可。 +如果准确按以上步骤操作后还是认证失败,请下载MentoHUSTTool,在Windows下抓包并保存为data.mpf, 然后回到Linux,切换到data.mpf所在目录,输入以下命令: sudo cp ./data.mpf /etc/mentohust 然后打开终端输入sudo mentohust -f/etc/mentohust/data.mpf -w运行即可。以后也只需输入sudo mentohust。 +#您也可以按下面的方法操作: +1、静态IP用户请事先设置好IP; +2、打开终端,输入sudo mentohust,回车; +3、[正确]输入相应信息,如果认证成功,跳到第8步;如果提示“不允许使用的客户端类型”,按Ctrl+C结束认证; +4、打开终端,输入sudo mentohust -w -f'锐捷目录下任意文件路径',回车; +5、如果认证成功,跳到第8步;如果提示“客户端完整性被破坏”,按Ctrl+C结束认证; +6、将锐捷安装目录下的SuConfig.dat重命名为其他名字; +7、打开终端,输入sudo mentohust,回车; +8、如果是动态IP且不是Linux,打开相应设置去更新IP。 +9、以后认证只需打开终端,输入sudo mentohust,回车。 +10、要修改某些参数请输入mentohust -h查看帮助信息并据此修改,例如修改密码sudo mentohust -pNewPassword -w,要临时修改则不加-w参数。 + #如何退出:不以后台模式运行mentohust时,按Ctrl+C即可退出;后台运行时使用sudo mentohust -k退出认证。 #查看帮助信息请输入:mentohust -h diff --git a/autogen.sh b/autogen.sh index 2087787..44314d8 100755 --- a/autogen.sh +++ b/autogen.sh @@ -5,4 +5,4 @@ autopoint aclocal autoheader automake --add-missing -autoconf +autoconf \ No newline at end of file diff --git a/configure.ac b/configure.ac index 6eb3e75..d1d79f1 100644 --- a/configure.ac +++ b/configure.ac @@ -8,8 +8,7 @@ AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/myconfig.h]) AC_CONFIG_HEADERS([config.h]) -m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) - +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) # Checks for programs. AS_IF([test "x$prefix" = "xNONE"], [prefix="/usr"]) @@ -51,29 +50,25 @@ AC_ARG_ENABLE([notify], [AC_HELP_STRING([ --disable-notify], [Don't show notific AS_IF([test "x$enable_notify" = "xno"], [AC_DEFINE(NO_NOTIFY, [], [Define NO_NOTIFY to disable notification])], [AC_CHECK_LIB([dl], [dlsym])]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_TYPE_SIZE_T -# define GETTEXT_* variables +AS_IF([test -z "$enable_nls"], [enable_nls="yes"]) + GETTEXT_PACKAGE="$PACKAGE_NAME" AC_SUBST(GETTEXT_PACKAGE) -AC_SUBST(prefix) -AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Define to the read-only architecture-independent data directory.]) - +AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Package name for gettext.]) AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION(0.16.1) - # Checks for header files. -AC_CHECK_HEADERS([iconv.h arpa/inet.h fcntl.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h]) - +AC_CHECK_HEADERS([iconv.h arpa/inet.h fcntl.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h libintl.h locale.h]) +# Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_SIZE_T # Checks for library functions. -AC_CHECK_FUNCS([atexit memmove memset socket strrchr]) +AC_CHECK_FUNCS([atexit memmove memset socket strrchr setlocale]) -AC_CONFIG_FILES([Makefile po/Makefile.in src/Makefile mentohust.spec]) +AC_CONFIG_FILES([Makefile src/Makefile po/Makefile.in mentohust.spec]) -AC_MSG_RESULT([config result: host($host_os) pcap($with_pcap) notify($enable_notify) encode($enable_encodepass) arp($enable_arp)]) +AC_MSG_RESULT([config result: host($host_os) pcap($with_pcap) notify($enable_notify) encode($enable_encodepass) arp($enable_arp) nls($enable_nls)]) AC_OUTPUT diff --git a/po/LINGUAS b/po/LINGUAS index 22bdb91..2c4c454 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -1,2 +1 @@ -zh_CN - +en \ No newline at end of file diff --git a/po/Makevars b/po/Makevars index 5d1d484..65d5bbe 100644 --- a/po/Makevars +++ b/po/Makevars @@ -8,7 +8,7 @@ subdir = po top_builddir = .. # These options get passed to xgettext. -XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --from-code=UTF-8 +XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --from-code=UTF-8 # This is the copyright holder that gets inserted into the header of the # $(DOMAIN).pot file. Set this to the copyright holder of the surrounding @@ -18,7 +18,7 @@ XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --from-code=UTF-8 # or entity, or to disclaim their copyright. The empty string stands for # the public domain; in this case the translators are expected to disclaim # their copyright. -COPYRIGHT_HOLDER = Free Software Foundation, Inc. +COPYRIGHT_HOLDER = HustMoon Studio # This is the email address or URL to which the translators shall report # bugs in the untranslated strings: diff --git a/po/POTFILES.in b/po/POTFILES.in index 0a391bf..aebb9d9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,7 +1,6 @@ +# List of source files which contain translatable strings. src/dlfunc.c src/mentohust.c -src/mycheck.c src/myconfig.c src/myfunc.c -src/myini.c src/mystate.c diff --git a/po/zh_CN.po b/po/zh_CN.po deleted file mode 100644 index 5100496..0000000 --- a/po/zh_CN.po +++ /dev/null @@ -1,77 +0,0 @@ -# -# , 2010. -msgid "" -msgstr "" -"Project-Id-Version: mentohust 0.3.1\n" -"Report-Msgid-Bugs-To: http://code.google.com/p/mentohust/issues/list\n" -"POT-Creation-Date: 2010-03-29 05:12+0800\n" -"PO-Revision-Date: 2010-03-29 04:49+0800\n" -"Last-Translator: \n" -"Language-Team: Chinese (simplified)\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" - -#: src/dlfunc.c:50 -#, c-format -msgid "!!Failed to open libpcap, please check its existence.\n" -msgstr "!!打开libpcap失败,请检查是否已安装该库文件。\n" - -#: src/dlfunc.c:65 -#, c-format -msgid "!! Failed To Get libpcap function : %s\n" -msgstr "!! 从libpcap获取函数失败: %s\n" - -#: src/dlfunc.c:115 -#, fuzzy, c-format -msgid "!! cannot load libnotify, please check its exitence.\n" -msgstr "!! 打开libnotify失败,请检查是否已安装该库文件。\n" - -#: src/dlfunc.c:124 -#, fuzzy, c-format -msgid "!! Failed To Get libnotify function : %s\n" -msgstr "!! 从libp!! 从libnotify获取函数失败: %s\n" - -#: src/dlfunc.c:130 -#, c-format -msgid "!! Uable to initlize libnotify.\n" -msgstr "!! 初始化libnotify失败。\n" - -#: src/mentohust.c:77 -#, c-format -msgid "!! Failed to capture package, please check network connections!\n" -msgstr "!! 捕获数据包失败,请检查网络连接!\n" - -#: src/mentohust.c:81 src/myconfig.c:184 src/myconfig.c:196 -msgid "MentoHUST - Error Tips" -msgstr "MentoHUST - 错误提示" - -#: src/mentohust.c:81 -msgid "Failed to capture package, please check network connections!" -msgstr "捕获数据包失败,请检查网络连接!" - -#: src/myconfig.c:158 -#, c-format -msgid "" -"\n" -" Welcome to use MentoHUST\t Version: %s\n" -"Copyright (C) 2009-2010 HustMoon Studio\n" -"人到华中大,有甜亦有辣。明德厚学地,求是创新家。\n" -"Bug report to %s\n" -"\n" -msgstr "" -"\n" -" 欢迎使用MentoHUST\t版本: %s\n" -"Copyright (C) 2009-2010 HustMoon Studio\n" -"人到华中大,有甜亦有辣。明德厚学地,求是创新家。\n" -"Bug 报告到 to %s\n" -"\n" - -#: src/myconfig.c:184 -#, fuzzy -msgid "Failed to load libpacp, please check its existence!" -msgstr "载入libpcap失败, 请检查该库文件!" - -#: src/myconfig.c:196 -msgid "Nic not found!" -msgstr "找不到网卡!" diff --git a/src/Makefile.am b/src/Makefile.am index d158e9c..f1985f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,7 +6,7 @@ dist_sysconf_DATA = mentohust.conf mentohust_SOURCES = myini.c md5.c mycheck.c dlfunc.c myfunc.c mystate.c myconfig.c mentohust.c -mentohust_SOURCES += types.h myini.h md5.h mycheck.h dlfunc.h myfunc.h mystate.h myconfig.h +mentohust_SOURCES += i18n.h types.h myini.h md5.h mycheck.h dlfunc.h myfunc.h mystate.h myconfig.h mentohust_LDADD = $(LDADD) diff --git a/src/dlfunc.c b/src/dlfunc.c index 91a22dc..031870a 100644 --- a/src/dlfunc.c +++ b/src/dlfunc.c @@ -8,13 +8,8 @@ * 邮 箱:www.ehust@gmail.com * 日 期:2009.11.11 */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "i18n.h" #include "dlfunc.h" +#include "i18n.h" #ifndef NO_DYLOAD #include @@ -47,8 +42,7 @@ int load_libpcap(void) { error = dlerror(); } if (libpcap == NULL) { - printf(_("!!Failed to open libpcap, please check its existence.\n")); - //printf("!! 打开libpcap失败,请检查是否已安装该库文件。\n"); + printf(_("!! 打开libpcap失败,请检查是否已安装该库文件。\n")); return -1; } if ((pcap_findalldevs = dlsym(libpcap, "pcap_findalldevs"), error = dlerror()) != NULL @@ -62,8 +56,7 @@ int load_libpcap(void) { || (pcap_close = dlsym(libpcap, "pcap_close"), error = dlerror()) != NULL || (pcap_breakloop = dlsym(libpcap, "pcap_breakloop"), error = dlerror()) != NULL || (pcap_sendpacket = dlsym(libpcap, "pcap_sendpacket"), error = dlerror()) != NULL) { - printf(_("!! Failed To Get libpcap function : %s\n"), error); - //printf("!! 从libpcap获取函数失败: %s\n", error); + printf(_("!! 从libpcap获取函数失败: %s\n"), error); free_libpcap(); return -1; } @@ -112,8 +105,7 @@ int load_libnotify(void) { error = dlerror(); } if (libnotify == NULL) { - printf(_("!! cannot load libnotify, please check its exitence.\n")); - //printf("!! 打开libnotify失败,请检查是否已安装该库文件。\n"); + printf(_("!! 打开libnotify失败,请检查是否已安装该库文件。\n")); return -1; } if ((notify_init = dlsym(libnotify, "notify_init"), error = dlerror()) != NULL @@ -121,14 +113,12 @@ int load_libnotify(void) { || (notify_notification_show = dlsym(libnotify, "notify_notification_show"), error = dlerror()) != NULL || (notify_notification_update = dlsym(libnotify, "notify_notification_update"), error = dlerror()) != NULL || (notify_notification_set_timeout = dlsym(libnotify, "notify_notification_set_timeout"), error = dlerror()) != NULL) { - printf(_("!! Failed To Get libnotify function : %s\n"), error); - //printf("!! 从libnotify获取函数失败: %s\n", error); + printf(_("!! 从libnotify获取函数失败: %s\n"), error); free_libnotify(); return -1; } if (!notify_init("mentohust")) { - printf(_("!! Uable to initlize libnotify.\n")); - //printf("!! 初始化libnotify失败。\n"); + printf(_("!! 初始化libnotify失败。\n")); free_libnotify(); return -1; } @@ -161,4 +151,3 @@ void show_notify(const char *summary, char *body) { } #endif /* NO_NOTIFY */ - diff --git a/src/dlfunc.h b/src/dlfunc.h index eb482f1..83ef944 100644 --- a/src/dlfunc.h +++ b/src/dlfunc.h @@ -6,6 +6,9 @@ #ifndef HUSTMOON_DLFUNC_H #define HUSTMOON_DLFUNC_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include #include @@ -71,4 +74,3 @@ void show_notify(const char *summary, char *body); /* 显示通知:概要、正 #endif /* NO_NOTIFY */ #endif /* HUSTMOON_DLFUNC_H */ - diff --git a/src/i18n.h b/src/i18n.h index 25ebf3d..b0f21aa 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -7,21 +7,24 @@ #ifndef I18N_H_ #define I18N_H_ - +#ifdef HAVE_CONFIG_H +#include "config.h" +#else +#define GETTEXT_PACKAGE "mentohust" +#endif #ifdef ENABLE_NLS #include #include -#define _(String) gettext (String) -#define gettext_noop(String) String -#define N_(String) gettext_noop (String) +#define _(String) gettext(String) +#ifdef gettext_noop +#define N_(String) gettext_noop(String) +#else +#define N_(String) (String) +#endif #else #define _(String) (String) #define N_(String) (String) -#define setlocale(x,y) -#define textdomain(x) -#define bindtextdomain(x,y) #endif - #endif /* I18N_H_ */ diff --git a/src/mentohust.c b/src/mentohust.c index 149ce08..69aec4d 100644 --- a/src/mentohust.c +++ b/src/mentohust.c @@ -9,12 +9,10 @@ */ #ifdef HAVE_CONFIG_H #include "config.h" -#else -#define HAVE_ICONV_H #endif -#include "i18n.h" #include "myconfig.h" +#include "i18n.h" #include "mystate.h" #include "myfunc.h" #include "dlfunc.h" @@ -24,10 +22,6 @@ #include #include -#ifdef HAVE_ICONV_H -#include -#endif - extern pcap_t *hPcap; extern volatile int state; extern u_char *fillBuf; @@ -51,16 +45,10 @@ static void showCernetMsg(const u_char *buf); /* 显示赛尔服务器提示信 int main(int argc, char **argv) { - setlocale(LC_ALL, ""); +#ifdef ENABLE_NLS textdomain(GETTEXT_PACKAGE); - -#ifdef WIN32 - { - char realpath_str[1024]; - bindtextdomain(GETTEXT_PACKAGE,realpath(argv[0],realpath_str)); - } + setlocale(LC_ALL, ""); #endif - atexit(exit_handle); initConfig(argc, argv); signal(SIGALRM, sig_handle); /* 定时器 */ @@ -74,12 +62,10 @@ int main(int argc, char **argv) else switchState(ID_START); /* 开始认证 */ if (-1 == pcap_loop(hPcap, -1, pcap_handle, NULL)) { /* 开始捕获数据包 */ - printf(_("!! Failed to capture package, please check network connections!\n")); - //printf("!! 捕获数据包失败,请检查网络连接!\n"); + printf(_("!! 捕获数据包失败,请检查网络连接!\n")); #ifndef NO_NOTIFY if (showNotify) - show_notify(_("MentoHUST - Error Tips"), _("Failed to capture package, please check network connections!")); - //show_notify("MentoHUST - 错误提示", "捕获数据包失败,请检查网络连接!"); + show_notify(_("MentoHUST - 错误提示"), _("捕获数据包失败,请检查网络连接!")); #endif } exit(EXIT_FAILURE); @@ -101,7 +87,7 @@ static void exit_handle(void) #ifndef NO_DYLOAD free_libpcap(); #endif - printf(">> 认证已退出。\n"); + printf(_(">> 认证已退出。\n")); } static void sig_handle(int sig) @@ -111,10 +97,10 @@ static void sig_handle(int sig) if (-1 == switchState(state)) { pcap_breakloop(hPcap); - printf("!! 发送数据包失败, 请检查网络连接!\n"); + printf(_("!! 发送数据包失败, 请检查网络连接!\n")); #ifndef NO_NOTIFY if (showNotify) - show_notify("MentoHUST - 错误提示", "发送数据包失败, 请检查网络连接!"); + show_notify(_("MentoHUST - 错误提示"), _("发送数据包失败, 请检查网络连接!")); #endif exit(EXIT_FAILURE); } @@ -138,7 +124,7 @@ static void pcap_handle(u_char *user, const struct pcap_pkthdr *h, const u_char if (buf[0x0F]==0x00 && buf[0x12]==0x01 && buf[0x16]==0x01) { /* 验证用户名 */ if (startMode < 3) { memcpy(destMAC, buf+6, 6); - printf("** 认证MAC:\t%s\n", formatHex(destMAC, 6)); + printf(_("** 认证MAC:\t%s\n"), formatHex(destMAC, 6)); startMode += 3; /* 标记为已获取 */ } if (startMode==3 && memcmp(buf+0x17, "User name", 9)==0) /* 塞尔 */ @@ -148,7 +134,7 @@ static void pcap_handle(u_char *user, const struct pcap_pkthdr *h, const u_char else if (buf[0x0F]==0x00 && buf[0x12]==0x01 && buf[0x16]==0x04) /* 验证密码 */ switchState(ID_CHALLENGE); else if (buf[0x0F]==0x00 && buf[0x12]==0x03) { /* 认证成功 */ - printf(">> 认证成功!\n"); + printf(_(">> 认证成功!\n")); failCount = 0; if (!(startMode%3 == 2)) { getEchoKey(buf); @@ -167,15 +153,15 @@ static void pcap_handle(u_char *user, const struct pcap_pkthdr *h, const u_char switchState(ID_ECHO); else if (buf[0x0F]==0x00 && buf[0x12]==0x04) { /* 认证失败或被踢下线 */ if (state==ID_WAITECHO || state==ID_ECHO) { - printf(">> 认证掉线,开始重连!\n"); + printf(_(">> 认证掉线,开始重连!\n")); switchState(ID_START); } else if (buf[0x1b]!=0 || startMode%3==2) { - printf(">> 认证失败!\n"); + printf(_(">> 认证失败!\n")); if (startMode%3 != 2) showRuijieMsg(buf, h->caplen); if (maxFail && ++failCount>=maxFail) { - printf(">> 连续认证失败%u次,退出认证。\n", maxFail); + printf(_(">> 连续认证失败%u次,退出认证。\n"), maxFail); exit(EXIT_SUCCESS); } restart(); @@ -189,18 +175,16 @@ static void pcap_handle(u_char *user, const struct pcap_pkthdr *h, const u_char char str[50]; if (gateMAC[0] == 0xFF) { memcpy(gateMAC, buf+0x16, 6); - printf("** 网关MAC:\t%s\n", formatHex(gateMAC, 6)); - fflush(stdout); + printf(_("** 网关MAC:\t%s\n"), formatHex(gateMAC, 6)); sprintf(str, "arp -s %s %s", formatIP(gateway), formatHex(gateMAC, 6)); system(str); } else if (buf[0x15]==0x02 && *(u_int32_t *)(buf+0x26)==rip && memcmp(gateMAC, buf+0x16, 6)!=0) { - printf("** ARP欺骗:\t%s\n", formatHex(buf+0x16, 6)); - fflush(stdout); + printf(_("** ARP欺骗:\t%s\n"), formatHex(buf+0x16, 6)); #ifndef NO_NOTIFY if (showNotify) { - sprintf(str, "欺骗源: %s", formatHex(buf+0x16, 6)); - show_notify("MentoHUST - ARP提示", str); + sprintf(str, _("欺骗源: %s"), formatHex(buf+0x16, 6)); + show_notify(_("MentoHUST - ARP提示"), str); } #endif } @@ -209,78 +193,43 @@ static void pcap_handle(u_char *user, const struct pcap_pkthdr *h, const u_char #endif } -#ifndef MAC_OS -static char *gbk2utf(char *src, size_t srclen) /* GBK转UTF-8 */ -#else -static char *gbk2utf(const char *src, size_t srclen) /* GBK转UTF-8 */ -#endif -{ -#ifdef HAVE_ICONV_H - /* GBK一汉字俩字节,UTF-8一汉字3字节,二者ASCII字符均一字节 - 所以这样申请是足够的了,要记得释放 */ - size_t dstlen = srclen * 3 / 2 + 1; - size_t left = dstlen; - char *dst, *pdst; - int res; - iconv_t cd = iconv_open("utf-8", "gbk"); - if (cd == (iconv_t)-1) - return NULL; - dst = (char *)malloc(dstlen); - pdst = dst; - res = iconv(cd, &src, &srclen, &pdst, &left); - iconv_close(cd); - if (res == -1) - { - free(dst); - return NULL; - } - dst[dstlen-left] = '\0'; -#else - char *dst = (char *)malloc(srclen+1); - memcpy(dst, src, srclen); - dst[srclen] = '\0'; -#endif - return dst; -} - static void showRuijieMsg(const u_char *buf, unsigned bufLen) { char *serverMsg; int length = buf[0x1b]; - if (length > 0) - { + if (length > 0) { for (serverMsg=(char *)(buf+0x1c); *serverMsg=='\r'||*serverMsg=='\n'; serverMsg++,length--); /* 跳过开头的换行符 */ if (strlen(serverMsg) < length) length = strlen(serverMsg); - if (length>0 && (serverMsg=gbk2utf(serverMsg, length))!=NULL) - { - printf("$$ 系统提示:\t%s\n", serverMsg); + if (length>0 && (serverMsg=gbk2utf(serverMsg, length))!=NULL) { + if (strlen(serverMsg)) { + printf(_("$$ 系统提示:\t%s\n"), serverMsg); #ifndef NO_NOTIFY - if (showNotify) - show_notify("MentoHUST - 系统提示", serverMsg); + if (showNotify) + show_notify(_("MentoHUST - 系统提示"), serverMsg); #endif + } free(serverMsg); } } - if ((length=0x1c+buf[0x1b]+0x69+39) < bufLen) - { + if ((length=0x1c+buf[0x1b]+0x69+39) < bufLen) { serverMsg=(char *)(buf+length); if (buf[length-1]-2 > bufLen-length) length = bufLen - length; else length = buf[length-1]-2; for (; *serverMsg=='\r'||*serverMsg=='\n'; serverMsg++,length--); - if (length>0 && (serverMsg=gbk2utf(serverMsg, length))!=NULL) - { - printf("$$ 计费提示:\t%s\n", serverMsg); + if (length>0 && (serverMsg=gbk2utf(serverMsg, length))!=NULL) { + if (strlen(serverMsg)) { + printf(_("$$ 计费提示:\t%s\n"), serverMsg); #ifndef NO_NOTIFY - if (showNotify) - show_notify("MentoHUST - 计费提示", serverMsg); + if (showNotify) + show_notify(_("MentoHUST - 计费提示"), serverMsg); #endif + } free(serverMsg); } } - fflush(stdout); } static void showCernetMsg(const u_char *buf) @@ -291,12 +240,11 @@ static void showCernetMsg(const u_char *buf) length = strlen(serverMsg); if (length>0 && (serverMsg=gbk2utf(serverMsg, length))!=NULL) { - printf("$$ 系统提示:\t%s\n", serverMsg); + printf(_("$$ 系统提示:\t%s\n"), serverMsg); #ifndef NO_NOTIFY if (showNotify) - show_notify("MentoHUST - 系统提示", serverMsg); + show_notify(_("MentoHUST - 系统提示"), serverMsg); #endif free(serverMsg); } - fflush(stdout); } diff --git a/src/mentohust.conf b/src/mentohust.conf index cd294ee..718ddad 100644 --- a/src/mentohust.conf +++ b/src/mentohust.conf @@ -10,8 +10,8 @@ [MentoHUST] ;用户名,长度不超过64 Username= -;密码(简单加密) -EncodePass= +;密码 +Password= ;网卡 Nic= ;静态IP用户可以使用非本机IP diff --git a/src/mycheck.c b/src/mycheck.c index 8a4a7bb..758e267 100644 --- a/src/mycheck.c +++ b/src/mycheck.c @@ -4,14 +4,10 @@ * * 文件名称:mycheck.c * 摘 要:客户端校验算法 -* 作 者:kkHAIKE & HustMoon +* 作 者:kkHAIKE */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "i18n.h" #include "mycheck.h" +#include "myini.h" #include "md5.h" #include #include @@ -19,7 +15,6 @@ static BYTE *bin_8021x = NULL; static DWORD size_8021x; -static BYTE hex[][17]={"0123456789ABCDEF", "0123456789abcdef"}; #ifdef WORDS_BIGENDIAN WORD ltobs(WORD x) { @@ -35,6 +30,7 @@ DWORD ltobl(DWORD x) { #endif void hex_to_str(const BYTE *a, char *b, int hexsize, int upper) { + static const BYTE hex[][17]={"0123456789ABCDEF", "0123456789abcdef"}; BYTE *q = (BYTE *)b; int i; for (i=0; i= s_end) + return; + tmp[(m<<7)^n] = d; + } else { + d = tmp[(m<<7)^n]; + } + *dp++ = d; + if (dp >= d_end) { + return; + } + m = n; + n = d; + } + } +} + +int decodeConfig(const char *file, BYTE *dbuf, int dsize) { + char *sbuf; + int ssize = loadFile(&sbuf, file); + if (ssize < 0) + return -1; + decode_dat((BYTE *)sbuf, dbuf, ssize, dsize); + free(sbuf); + return 0; +} + void check_free() { if (bin_8021x) { free(bin_8021x); diff --git a/src/mycheck.h b/src/mycheck.h index ed51fd3..c3762e3 100644 --- a/src/mycheck.h +++ b/src/mycheck.h @@ -211,6 +211,7 @@ DWORD ltobl(DWORD x); #define LTOBL(x) (x) #endif +int decodeConfig(const char *file, BYTE *dbuf, int dsize); int check_init(const char *dataFile); void V2_check(const BYTE *seed, char *final_str); void check_free(); diff --git a/src/myconfig.c b/src/myconfig.c index 1a08624..920293b 100644 --- a/src/myconfig.c +++ b/src/myconfig.c @@ -14,8 +14,8 @@ static const char *VERSION = "0.3.1"; static const char *PACKAGE_BUGREPORT = "http://code.google.com/p/mentohust/issues/list"; #endif -#include "i18n.h" #include "myconfig.h" +#include "i18n.h" #include "myini.h" #include "myfunc.h" #include "dlfunc.h" @@ -35,9 +35,13 @@ static const char *PACKAGE_BUGREPORT = "http://code.google.com/p/mentohust/issue #define D_STARTMODE 0 /* 默认组播模式 */ #define D_DHCPMODE 0 /* 默认DHCP模式 */ #define D_DAEMONMODE 0 /* 默认daemon模式 */ -#define D_MAXFAIL 0 /* 默认允许失败次数 */ +#define D_MAXFAIL 8 /* 默认允许失败次数 */ +#ifdef MAC_OS +static const char *D_DHCPSCRIPT = "dhcping -v -t 15"; /* 默认DHCP脚本 */ +#else static const char *D_DHCPSCRIPT = "dhclient"; /* 默认DHCP脚本 */ +#endif static const char *CFG_FILE = "/etc/mentohust.conf"; /* 配置文件 */ static const char *LOG_FILE = "/tmp/mentohust.log"; /* 日志文件 */ static const char *LOCK_FILE = "/var/run/mentohust.pid"; /* 锁文件 */ @@ -155,16 +159,10 @@ void initConfig(int argc, char **argv) int exitFlag = 0; /* 0Nothing 1退出 2重启 */ int daemonMode = D_DAEMONMODE; /* 是否后台运行 */ - printf(_("\n Welcome to use MentoHUST\t Version: %s\n" + printf(_("\n欢迎使用MentoHUST\t版本: %s\n" "Copyright (C) 2009-2010 HustMoon Studio\n" "人到华中大,有甜亦有辣。明德厚学地,求是创新家。\n" "Bug report to %s\n\n"), VERSION, PACKAGE_BUGREPORT); - -// printf("\n欢迎使用MentoHUST\t版本: %s\n" -// "Copyright (C) 2009-2010 HustMoon Studio\n" -// "人到华中大,有甜亦有辣。明德厚学地,求是创新家。\n" -// "Bug report to %s\n\n", VERSION, PACKAGE_BUGREPORT); - saveFlag = (readFile(&daemonMode)==0 ? 0 : 1); readArg(argc, argv, &saveFlag, &exitFlag, &daemonMode); #ifndef NO_NOTIFY @@ -181,8 +179,7 @@ void initConfig(int argc, char **argv) if (load_libpcap() == -1) { #ifndef NO_NOTIFY if (showNotify) - show_notify(_("MentoHUST - Error Tips"),_("Failed to load libpacp, please check its existence!")); - //show_notify("MentoHUST - 错误提示", "载入libpcap失败, 请检查该库文件!"); + show_notify(_("MentoHUST - 错误提示"), _("载入libpcap失败, 请检查该库文件!")); #endif exit(EXIT_FAILURE); } @@ -193,7 +190,7 @@ void initConfig(int argc, char **argv) if (getAdapter() == -1) { /* 找不到(第一块)网卡? */ #ifndef NO_NOTIFY if (showNotify) - show_notify(_("MentoHUST - Error Tips"), _("Nic not found!")); + show_notify(_("MentoHUST - 错误提示"), _("找不到网卡!")); #endif exit(EXIT_FAILURE); } @@ -201,14 +198,14 @@ void initConfig(int argc, char **argv) if (userName[0]=='\0' || password[0]=='\0') /* 未写用户名密码? */ { saveFlag = 1; - printf("?? 请输入用户名: "); + printf(_("?? 请输入用户名: ")); scanf("%s", userName); - printf("?? 请输入密码: "); + printf(_("?? 请输入密码: ")); scanf("%s", password); - printf("?? 请选择组播地址(0标准 1锐捷私有 2赛尔): "); + printf(_("?? 请选择组播地址(0标准 1锐捷私有 2赛尔): ")); scanf("%u", &startMode); startMode %= 3; - printf("?? 请选择DHCP方式(0不使用 1二次认证 2认证后 3认证前): "); + printf(_("?? 请选择DHCP方式(0不使用 1二次认证 2认证后 3认证前): ")); scanf("%u", &dhcpMode); dhcpMode %= 4; } @@ -225,7 +222,7 @@ void initConfig(int argc, char **argv) if (fillHeader()==-1 || openPcap()==-1) { /* 获取IP、MAC,打开网卡 */ #ifndef NO_NOTIFY if (showNotify) - show_notify("MentoHUST - 错误提示", "获取MAC地址或打开网卡失败!"); + show_notify(_("MentoHUST - 错误提示"), _("获取MAC地址或打开网卡失败!")); #endif exit(EXIT_FAILURE); } @@ -235,21 +232,22 @@ void initConfig(int argc, char **argv) static int readFile(int *daemonMode) { - char tmp[16]; - char *buf = loadFile(CFG_FILE); - if (buf == NULL) + char tmp[16], *buf; + if (loadFile(&buf, CFG_FILE) < 0) return -1; getString(buf, "MentoHUST", "Username", "", userName, sizeof(userName)); +#ifdef NO_ENCODE_PASS getString(buf, "MentoHUST", "Password", "", password, sizeof(password)); -#ifndef NO_ENCODE_PASS - char pass[ACCOUNT_SIZE*4/3]; - if (password[0] == '\0') { - getString(buf, "MentoHUST", "EncodePass", "", pass, sizeof(pass)); - decodePass(password, pass); +#else + char pass[ACCOUNT_SIZE*4/3+1]; + getString(buf, "MentoHUST", "Password", "", pass, sizeof(pass)); + if (pass[0] == ' ') { + decodePass(password, pass+1); } else { - encodePass(pass, password); - setString(&buf, "MentoHUST", "Password", NULL); - setString(&buf, "MentoHUST", "EncodePass", pass); + strncpy(password, pass, sizeof(password)-1); + encodePass(pass+1, password); + pass[0] = ' '; + setString(&buf, "MentoHUST", "Password", pass); saveFile(buf, CFG_FILE); } #endif @@ -301,6 +299,10 @@ static void readArg(char argc, char **argv, int *saveFlag, int *exitFlag, int *d c = str[1]; if (c=='h' || c=='?' || strcmp(str, "--help")==0) showHelp(argv[0]); + else if (c == 'q') { + printSuConfig(str+2); + exit(EXIT_SUCCESS); + } else if (c == 'w') *saveFlag = 1; else if (c == 'k') { @@ -368,7 +370,7 @@ static void readArg(char argc, char **argv, int *saveFlag, int *exitFlag, int *d static void showHelp(const char *fileName) { char *helpString = - "用法:\t%s [-选项][参数]\n" + _("用法:\t%s [-选项][参数]\n" "选项:\t-h 显示本帮助信息\n" "\t-k -k(退出程序) 其他(重启程序)\n" "\t-w 保存参数到配置文件\n" @@ -381,9 +383,9 @@ static void showHelp(const char *fileName) "\t-s DNS[默认0.0.0.0]\n" "\t-o Ping主机[默认0.0.0.0,表示关闭该功能]\n" "\t-t 认证超时(秒)[默认8]\n" - "\t-e 响应间隔(秒)[默认30]\n" + "\t-e 心跳间隔(秒)[默认30]\n" "\t-r 失败等待(秒)[默认15]\n" - "\t-l 允许失败次数[默认0,表示无限制]\n" + "\t-l 允许失败次数[0表示无限制,默认8]\n" "\t-a 组播地址: 0(标准) 1(锐捷) 2(赛尔) [默认0]\n" "\t-d DHCP方式: 0(不使用) 1(二次认证) 2(认证后) 3(认证前) [默认0]\n" "\t-b 是否后台运行: 0(否) 1(是,关闭输出) 2(是,保留输出) 3(是,输出到文件) [默认0]\n" @@ -393,8 +395,9 @@ static void showHelp(const char *fileName) "\t-v 客户端版本号[默认0.00表示兼容xrgsu]\n" "\t-f 自定义数据文件[默认不使用]\n" "\t-c DHCP脚本[默认dhclient]\n" + "\t-q 显示SuConfig.dat的内容(如-q/path/SuConfig.dat)\n" "例如:\t%s -uusername -ppassword -neth0 -i192.168.0.1 -m255.255.255.0 -g0.0.0.0 -s0.0.0.0 -o0.0.0.0 -t8 -e30 -r15 -a0 -d1 -b0 -v4.10 -fdefault.mpf -cdhclient\n" - "注意:使用时请确保是以root权限运行!\n\n"; + "注意:使用时请确保是以root权限运行!\n\n"); printf(helpString, fileName, fileName); exit(EXIT_SUCCESS); } @@ -406,7 +409,7 @@ static int getAdapter() char errbuf[PCAP_ERRBUF_SIZE]; if (pcap_findalldevs(&alldevs, errbuf)==-1 || alldevs==NULL) { - printf("!! 查找网卡失败: %s\n", errbuf); + printf(_("!! 查找网卡失败: %s\n"), errbuf); return -1; } for (d=alldevs; d!=NULL; d=d->next) @@ -414,7 +417,7 @@ static int getAdapter() num++; if (!(d->flags & PCAP_IF_LOOPBACK) && strcmp(d->name, "any")!=0) { - printf("** 网卡[%d]:\t%s\n", num, d->name); + printf(_("** 网卡[%d]:\t%s\n"), num, d->name); avail++; i = num; } @@ -422,19 +425,19 @@ static int getAdapter() if (avail == 0) { pcap_freealldevs(alldevs); - printf("!! 找不到网卡!\n"); + printf(_("!! 找不到网卡!\n")); return -1; } if (avail > 1) { - printf("?? 请选择网卡[1-%d]: ", num); + printf(_("?? 请选择网卡[1-%d]: "), num); scanf("%d", &i); if (i < 1) i = 1; else if (i > num) i = num; } - printf("** 您选择了第[%d]块网卡。\n", i); + printf(_("** 您选择了第[%d]块网卡。\n"), i); for (d=alldevs; i>1; d=d->next, i--); strncpy(nic, d->name, sizeof(nic)-1); pcap_freealldevs(alldevs); @@ -443,31 +446,32 @@ static int getAdapter() static void printConfig() { - char *addr[] = {"标准", "锐捷", "赛尔"}; - char *dhcp[] = {"不使用", "二次认证", "认证后", "认证前"}; - printf("** 用户名:\t%s\n", userName); + char *addr[] = {_("标准"), _("锐捷"), _("赛尔")}; + char *dhcp[] = {_("不使用"), _("二次认证"), _("认证后"), _("认证前")}; + printf(_("** 用户名:\t%s\n"), userName); /* printf("** 密码:\t%s\n", password); */ - printf("** 网卡: \t%s\n", nic); + printf(_("** 网卡: \t%s\n"), nic); if (gateway) - printf("** 网关地址:\t%s\n", formatIP(gateway)); + printf(_("** 网关地址:\t%s\n"), formatIP(gateway)); if (dns) - printf("** DNS地址:\t%s\n", formatIP(dns)); + printf(_("** DNS地址:\t%s\n"), formatIP(dns)); if (pingHost) - printf("** 智能重连:\t%s\n", formatIP(pingHost)); - printf("** 认证超时:\t%u秒\n", timeout); - printf("** 响应间隔:\t%u秒\n", echoInterval); - printf("** 失败等待:\t%u秒\n", restartWait); - printf("** 允许失败:\t%u次\n", maxFail); - printf("** 组播地址:\t%s\n", addr[startMode]); - printf("** DHCP方式:\t%s\n", dhcp[dhcpMode]); + printf(_("** 智能重连:\t%s\n"), formatIP(pingHost)); + printf(_("** 认证超时:\t%u秒\n"), timeout); + printf(_("** 心跳间隔:\t%u秒\n"), echoInterval); + printf(_("** 失败等待:\t%u秒\n"), restartWait); + if (maxFail) + printf(_("** 允许失败:\t%u次\n"), maxFail); + printf(_("** 组播地址:\t%s\n"), addr[startMode]); + printf(_("** DHCP方式:\t%s\n"), dhcp[dhcpMode]); #ifndef NO_NOTIFY if (showNotify) - printf("** 通知超时:\t%d秒\n", showNotify); + printf(_("** 通知超时:\t%d秒\n"), showNotify); #endif if (bufType >= 2) - printf("** 数据文件:\t%s\n", dataFile); + printf(_("** 数据文件:\t%s\n"), dataFile); if (dhcpMode != 0) - printf("** DHCP脚本:\t%s\n", dhcpScript); + printf(_("** DHCP脚本:\t%s\n"), dhcpScript); } static int openPcap() @@ -476,7 +480,7 @@ static int openPcap() struct bpf_program fcode; if ((hPcap = pcap_open_live(nic, 2048, 1, 1000, buf)) == NULL) { - printf("!! 打开网卡%s失败: %s\n", nic, buf); + printf(_("!! 打开网卡%s失败: %s\n"), nic, buf); return -1; } fmt = formatHex(localMAC, 6); @@ -490,7 +494,7 @@ static int openPcap() if (pcap_compile(hPcap, &fcode, buf, 0, 0xffffffff) == -1 || pcap_setfilter(hPcap, &fcode) == -1) { - printf("!! 设置pcap过滤器失败: %s\n", pcap_geterr(hPcap)); + printf(_("!! 设置pcap过滤器失败: %s\n"), pcap_geterr(hPcap)); return -1; } pcap_freecode(&fcode); @@ -499,8 +503,8 @@ static int openPcap() static void saveConfig(int daemonMode) { - char *buf = loadFile(CFG_FILE); - if (buf == NULL) { + char *buf; + if (loadFile(&buf, CFG_FILE) < 0) { buf = (char *)malloc(1); buf[0] = '\0'; } @@ -531,15 +535,16 @@ static void saveConfig(int daemonMode) #ifdef NO_ENCODE_PASS setString(&buf, "MentoHUST", "Password", password); #else - char pass[ACCOUNT_SIZE*4/3]; - encodePass(pass, password); - setString(&buf, "MentoHUST", "EncodePass", pass); + char pass[ACCOUNT_SIZE*4/3+1]; + encodePass(pass+1, password); + pass[0] = ' '; + setString(&buf, "MentoHUST", "Password", pass); #endif setString(&buf, "MentoHUST", "Username", userName); if (saveFile(buf, CFG_FILE) != 0) - printf("!! 保存认证参数到%s失败!\n", CFG_FILE); + printf(_("!! 保存认证参数到%s失败!\n"), CFG_FILE); else - printf("** 认证参数已成功保存到%s.\n", CFG_FILE); + printf(_("** 认证参数已成功保存到%s.\n"), CFG_FILE); free(buf); } @@ -548,7 +553,7 @@ static void checkRunning(int exitFlag, int daemonMode) struct flock fl; lockfd = open (LOCK_FILE, O_RDWR|O_CREAT, LOCKMODE); if (lockfd < 0) { - perror("!! 打开锁文件失败"); /* perror真的很好啊,以前没用它真是太亏了 */ + perror(_("!! 打开锁文件失败")); goto error_exit; } fl.l_start = 0; @@ -556,37 +561,38 @@ static void checkRunning(int exitFlag, int daemonMode) fl.l_len = 0; fl.l_type = F_WRLCK; if (fcntl(lockfd, F_GETLK, &fl) < 0) { - perror("!! 获取文件锁失败"); + perror(_("!! 获取文件锁失败")); goto error_exit; } if (exitFlag) { if (fl.l_type != F_UNLCK) { - printf(">> 已发送退出信号给MentoHUST进程(PID=%d).\n", fl.l_pid); + printf(_(">> 已发送退出信号给MentoHUST进程(PID=%d).\n"), fl.l_pid); if (kill(fl.l_pid, SIGINT) == -1) - perror("!! 结束进程失败"); + perror(_("!! 结束进程失败")); } else - printf("!! 没有MentoHUST正在运行!\n"); + printf(_("!! 没有MentoHUST正在运行!\n")); if (exitFlag == 1) exit(EXIT_SUCCESS); } else if (fl.l_type != F_UNLCK) { - printf("!! MentoHUST已经运行(PID=%d)!\n", fl.l_pid); + printf(_("!! MentoHUST已经运行(PID=%d)!\n"), fl.l_pid); exit(EXIT_FAILURE); } if (daemonMode) { /* 貌似我过早进入后台模式了,就给个选项保留输出或者输出到文件吧 */ - printf(">> 进入后台运行模式,使用参数-k可退出认证。\n"); + printf(_(">> 进入后台运行模式,使用参数-k可退出认证。\n")); if (daemon(0, (daemonMode+1)%2)) - perror("!! 后台运行失败"); + perror(_("!! 后台运行失败")); else if (daemonMode == 3) { freopen(LOG_FILE, "w", stdout); + setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); freopen(LOG_FILE, "a", stderr); } } fl.l_type = F_WRLCK; fl.l_pid = getpid(); if (fcntl(lockfd, F_SETLKW, &fl) < 0) { - perror("!! 加锁失败"); + perror(_("!! 加锁失败")); goto error_exit; } return; @@ -594,7 +600,7 @@ static void checkRunning(int exitFlag, int daemonMode) error_exit: #ifndef NO_NOTIFY if (showNotify) - show_notify("MentoHUST - 错误提示", "操作锁文件失败,请检查是否为root权限!"); + show_notify(_("MentoHUST - 错误提示"), _("操作锁文件失败,请检查是否为root权限!")); #endif exit(EXIT_FAILURE); } diff --git a/src/myfunc.c b/src/myfunc.c index e2836b2..26a7444 100644 --- a/src/myfunc.c +++ b/src/myfunc.c @@ -8,10 +8,12 @@ */ #ifdef HAVE_CONFIG_H #include "config.h" +#else +#define HAVE_ICONV_H #endif -#include "i18n.h" #include "myfunc.h" +#include "i18n.h" #include "md5.h" #include "mycheck.h" #include @@ -29,6 +31,10 @@ #endif #include +#ifdef HAVE_ICONV_H +#include +#endif + const u_char STANDARD_ADDR[] = {0x01,0x80,0xC2,0x00,0x00,0x03}; const u_char RUIJIE_ADDR[] = {0x01,0xD0,0xF8,0x00,0x00,0x03}; static const char *DATAFILE = "/etc/mentohust/"; /* 默认数据文件(目录) */ @@ -60,6 +66,34 @@ static int setProperty(u_char type, const u_char *value, int length); /* 设置 static int readPacket(int type); /* 读取数据 */ static int Check(const u_char *md5Seed); /* 校验算法 */ +char *gbk2utf(char *src, size_t srclen) { +#ifdef HAVE_ICONV_H + /* GBK一汉字俩字节,UTF-8一汉字3字节,二者ASCII字符均一字节 + 所以这样申请是足够的了,要记得释放 */ + size_t dstlen = srclen * 3 / 2 + 1; + size_t left = dstlen; + char *dst, *pdst; + int res; + iconv_t cd = iconv_open("utf-8", "gbk"); + if (cd == (iconv_t)-1) + return NULL; + dst = (char *)malloc(dstlen); + pdst = dst; + res = iconv(cd, &src, &srclen, &pdst, &left); + iconv_close(cd); + if (res == -1) { + free(dst); + return NULL; + } + dst[dstlen-left] = '\0'; +#else + char *dst = (char *)malloc(srclen+1); + memcpy(dst, src, srclen); + dst[srclen] = '\0'; +#endif + return dst; +} + char *formatIP(u_int32_t ip) { static char tmp[16]; @@ -103,10 +137,20 @@ static int checkFile() { fileError: if (dataFile[strlen(dataFile)-1] != '/') - printf("!! 所选文件%s无效,改用内置数据认证。\n", dataFile); + printf(_("!! 所选文件%s无效,改用内置数据认证。\n"), dataFile); return -1; } +void printSuConfig(const char *SuConfig) { + char dbuf[2048], *text; + if (decodeConfig(SuConfig, (BYTE *)dbuf, sizeof(dbuf))) { + printf(_("!! 指定的SuConfig.dat文件无效。\n")); + } else if ((text=gbk2utf(dbuf, strlen(dbuf))) != NULL) { + printf("%s\n", text); + free(text); + } +} + static int getVersion() { char file[0x100], *p; DWORD ver; @@ -144,7 +188,7 @@ static int getAddress() int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { - printf("!! 创建套接字失败!\n"); + printf(_("!! 创建套接字失败!\n")); return -1; } strcpy(ifr.ifr_name, nic); @@ -179,7 +223,7 @@ static int getAddress() #ifndef NO_ARP gateMAC[0] = 0xFE; if (ioctl(sock, SIOCGIFADDR, &ifr) < 0) - printf("!! 在网卡%s上获取IP失败!\n", nic); + printf(_("!! 在网卡%s上获取IP失败!\n"), nic); else { rip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; if (gateway!=0 && (startMode%3!=2 || ((u_char *)&gateway)[3]!=0x02)) @@ -190,7 +234,7 @@ static int getAddress() #else if (dhcpMode!=0 || ip==-1) { if (ioctl(sock, SIOCGIFADDR, &ifr) < 0) - printf("!! 在网卡%s上获取IP失败!\n", nic); + printf(_("!! 在网卡%s上获取IP失败!\n"), nic); else ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; } @@ -198,20 +242,20 @@ static int getAddress() if (dhcpMode!=0 || mask==-1) { if (ioctl(sock, SIOCGIFNETMASK, &ifr) < 0) - printf("!! 在网卡%s上获取子网掩码失败!\n", nic); + printf(_("!! 在网卡%s上获取子网掩码失败!\n"), nic); else mask = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; } close(sock); - printf("** 本机MAC:\t%s\n", formatHex(localMAC, 6)); - printf("** 使用IP:\t%s\n", formatIP(ip)); - printf("** 子网掩码:\t%s\n", formatIP(mask)); + printf(_("** 本机MAC:\t%s\n"), formatHex(localMAC, 6)); + printf(_("** 使用IP:\t%s\n"), formatIP(ip)); + printf(_("** 子网掩码:\t%s\n"), formatIP(mask)); return 0; getMACError: close(sock); - printf("!! 在网卡%s上获取MAC失败!\n", nic); + printf(_("!! 在网卡%s上获取MAC失败!\n"), nic); return -1; } @@ -334,7 +378,7 @@ static int readPacket(int type) return 0; fileError: - printf("!! 所选文件%s无效,改用内置数据认证。\n", dataFile); + printf(_("!! 所选文件%s无效,改用内置数据认证。\n"), dataFile); bufType -= 2; if (bufType==1 && fillSize<0x1d7) { free(fillBuf); @@ -420,15 +464,15 @@ static int Check(const u_char *md5Seed) /* 客户端校验 */ { char final_str[129]; int value; - printf("** 客户端版本:\t%d.%d\n", fillBuf[0x3B], fillBuf[0x3C]); - printf("** MD5种子:\t%s\n", formatHex(md5Seed, 16)); + printf(_("** 客户端版本:\t%d.%d\n"), fillBuf[0x3B], fillBuf[0x3C]); + printf(_("** MD5种子:\t%s\n"), formatHex(md5Seed, 16)); value = check_init(dataFile); if (value == -1) { - printf("!! 缺少8021x.exe信息,客户端校验无法继续!\n"); + printf(_("!! 缺少8021x.exe信息,客户端校验无法继续!\n")); return 1; } V2_check(md5Seed, final_str); - printf("** V2校验值:\t%s\n", final_str); + printf(_("** V2校验值:\t%s\n"), final_str); setProperty(0x17, (u_char *)final_str, 32); check_free(); return 0; @@ -519,7 +563,7 @@ int isOnline() return -1; pingError: - perror("!! Ping主机出错,关闭该功能"); + perror(_("!! Ping主机出错,关闭该功能")); if (sock != -1) close(sock); pingHost = 0; diff --git a/src/myfunc.h b/src/myfunc.h index 9b7d68c..7f70835 100644 --- a/src/myfunc.h +++ b/src/myfunc.h @@ -10,8 +10,10 @@ #include +char *gbk2utf(char *src, size_t srclen); /* GBK转UTF-8 */ char *formatIP(u_int32_t ip); /* 格式化IP */ char *formatHex(const void *buf, int length); /* 格式化成十六进制形式 */ +void printSuConfig(const char *SuConfig); /* 显示锐捷配置文件 */ void newBuffer(); /* 检测数据文件有效性并分配内存 */ int fillHeader(); /* 填充网络地址及校验值部分 */ void fillStartPacket(); /* 填充Start包 */ diff --git a/src/myini.c b/src/myini.c index 8d822b8..1cc55c0 100644 --- a/src/myini.c +++ b/src/myini.c @@ -7,12 +7,6 @@ * 作 者:HustMoon@BYHH * 修 改:2009.10.8 */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "i18n.h" #include "myini.h" #include #include @@ -28,25 +22,23 @@ static int findKey(const char *buf, const char *section, const char *key, int *sectionStart, int *valueStart, unsigned long *valueSize); static int getSection(const char *buf, int inStart); -char *loadFile(const char *fileName) +long loadFile(char **buf, const char *fileName) { FILE *fp = NULL; long size = 0; - char *buf = NULL; if ((fp=fopen(fileName, "rb")) == NULL) - return NULL; + return -1; fseek(fp, 0, SEEK_END); size = ftell(fp); rewind(fp); - buf = (char *)malloc(size+1); - buf[size] = '\0'; - if (fread(buf, size, 1, fp) < 1) - { - free(buf); - buf = NULL; + *buf = (char *)malloc(size+1); + (*buf)[size] = '\0'; + if (fread(*buf, size, 1, fp) < 1) { + free(*buf); + size = -1; } fclose(fp); - return buf; + return size; } static void getLine(const char *buf, int inStart, int *lineStart, int *lineEnd) diff --git a/src/myini.h b/src/myini.h index 7f65710..b2caadf 100644 --- a/src/myini.h +++ b/src/myini.h @@ -17,7 +17,7 @@ extern "C" { #endif -char *loadFile(const char *fileName); /* 读取文件 */ +long loadFile(char **buf, const char *fileName); /* 读取文件 */ int getString(const char *buf, const char *section, const char *key, const char *defaultValue, char *value, unsigned long size); /* 读取字符串 */ int getInt(const char *buf, const char *section, const char *key, int defaultValue); /* 读取整数 */ diff --git a/src/mystate.c b/src/mystate.c index c14788b..789490e 100644 --- a/src/mystate.c +++ b/src/mystate.c @@ -7,13 +7,8 @@ * 作 者:HustMoon@BYHH * 邮 箱:www.ehust@gmail.com */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "i18n.h" #include "mystate.h" +#include "i18n.h" #include "myfunc.h" #include "dlfunc.h" #include @@ -80,16 +75,16 @@ int switchState(int type) switch (type) { case ID_START: - printf(">> 找不到服务器,重启认证!\n"); + printf(_(">> 找不到服务器,重启认证!\n")); break; case ID_IDENTITY: - printf(">> 发送用户名超时,重启认证!\n"); + printf(_(">> 发送用户名超时,重启认证!\n")); break; case ID_CHALLENGE: - printf(">> 发送密码超时,重启认证!\n"); + printf(_(">> 发送密码超时,重启认证!\n")); break; case ID_WAITECHO: - printf(">> 等候响应包超时,自行响应!\n"); + printf(_(">> 等候响应包超时,自行响应!\n")); return switchState(ID_ECHO); } return restart(); @@ -109,7 +104,7 @@ int switchState(int type) case ID_ECHO: if (pingHost && sendCount*echoInterval > 60) { /* 1分钟左右 */ if (isOnline() == -1) { - printf(">> 认证掉线,开始重连!\n"); + printf(_(">> 认证掉线,开始重连!\n")); return switchState(ID_START); } sendCount = 1; @@ -138,9 +133,9 @@ int restart() static int renewIP() { setTimer(0); /* 取消定时器 */ - printf(">> 正在获取IP...\n"); + printf(_(">> 正在获取IP...\n")); system(dhcpScript); - printf(">> 操作结束。\n"); + printf(_(">> 操作结束。\n")); dhcpMode += 3; /* 标记为已获取,123变为456,5不需再认证*/ if (fillHeader() == -1) exit(EXIT_FAILURE); @@ -163,7 +158,7 @@ static int sendStartPacket() { if (sendCount == 0) { - printf(">> 寻找服务器...\n"); + printf(_(">> 寻找服务器...\n")); memcpy(sendPacket, STANDARD_ADDR, 6); memcpy(sendPacket+0x06, localMAC, 6); *(u_int32_t *)(sendPacket+0x0C) = htonl(0x888E0101); @@ -175,7 +170,7 @@ static int sendStartPacket() } if (sendCount == 0) { - printf(">> 寻找服务器...\n"); + printf(_(">> 寻找服务器...\n")); fillStartPacket(); fillEtherAddr(0x888E0101); memcpy(sendPacket+0x12, fillBuf, fillSize); @@ -191,7 +186,7 @@ static int sendIdentityPacket() { if (sendCount == 0) { - printf(">> 发送用户名...\n"); + printf(_(">> 发送用户名...\n")); *(u_int16_t *)(sendPacket+0x0E) = htons(0x0100); *(u_int16_t *)(sendPacket+0x10) = *(u_int16_t *)(sendPacket+0x14) = htons(nameLen+30); sendPacket[0x12] = 0x02; @@ -207,7 +202,7 @@ static int sendIdentityPacket() } if (sendCount == 0) { - printf(">> 发送用户名...\n"); + printf(_(">> 发送用户名...\n")); fillEtherAddr(0x888E0100); nameLen = strlen(userName); *(u_int16_t *)(sendPacket+0x14) = *(u_int16_t *)(sendPacket+0x10) = htons(nameLen+5); @@ -228,7 +223,7 @@ static int sendChallengePacket() { if (sendCount == 0) { - printf(">> 发送密码...\n"); + printf(_(">> 发送密码...\n")); *(u_int16_t *)(sendPacket+0x0E) = htons(0x0100); *(u_int16_t *)(sendPacket+0x10) = *(u_int16_t *)(sendPacket+0x14) = htons(nameLen+22); sendPacket[0x12] = 0x02; @@ -243,7 +238,7 @@ static int sendChallengePacket() } if (sendCount == 0) { - printf(">> 发送密码...\n"); + printf(_(">> 发送密码...\n")); fillMd5Packet(capBuf+0x18); fillEtherAddr(0x888E0100); *(u_int16_t *)(sendPacket+0x14) = *(u_int16_t *)(sendPacket+0x10) = htons(nameLen+22); @@ -276,7 +271,7 @@ static int sendEchoPacket() 0x00,0x1E,0xFF,0xFF,0x37,0x77,0x7F,0x9F,0xFF,0xFF,0xD9,0x13,0xFF,0xFF,0x37,0x77, 0x7F,0x9F,0xFF,0xFF,0xF7,0x2B,0xFF,0xFF,0x37,0x77,0x7F,0x3F,0xFF }; - printf(">> 发送心跳包以保持在线...\n"); + printf(_(">> 发送心跳包以保持在线...\n")); fillEtherAddr(0x888E01BF); memcpy(sendPacket+0x10, echo, sizeof(echo)); setTimer(echoInterval);