OSDN Git Service

Fix bugs of simultaneous connection.
[ffftp/ffftp.git] / tool.c
1 /*=============================================================================\r
2 *\r
3 *                                                                       ツール\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 #define STRICT\r
31 // IPv6対応\r
32 #include <winsock2.h>\r
33 #include <windows.h>\r
34 #include <stdio.h>\r
35 #include <stdlib.h>\r
36 #include <string.h>\r
37 #include <commctrl.h>\r
38 #include <windowsx.h>\r
39 \r
40 #include "common.h"\r
41 #include "resource.h"\r
42 \r
43 #include <htmlhelp.h>\r
44 #include "helpid.h"\r
45 \r
46 // UTF-8対応\r
47 #undef __MBSWRAPPER_H__\r
48 #include "mbswrapper.h"\r
49 \r
50 \r
51 /*===== プロトタイプ =====*/\r
52 \r
53 // 64ビット対応\r
54 //static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
55 static INT_PTR CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
56 \r
57 \r
58 /*===== 外部参照 =====*/\r
59 \r
60 extern HWND hHelpWin;\r
61 \r
62 \r
63 /*----- ワンタイムパスワード計算 ----------------------------------------------\r
64 *\r
65 *       Parameter\r
66 *               なし\r
67 *\r
68 *       Return Value\r
69 *               なし\r
70 *----------------------------------------------------------------------------*/\r
71 \r
72 void OtpCalcTool(void)\r
73 {\r
74         DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_calc_dlg), GetMainHwnd(), OtpCalcWinProc);\r
75         return;\r
76 }\r
77 \r
78 \r
79 /*----- ワンタイムパスワード計算ウインドウのコールバック ----------------------\r
80 *\r
81 *       Parameter\r
82 *               HWND hDlg : ウインドウハンドル\r
83 *               UINT message : メッセージ番号\r
84 *               WPARAM wParam : メッセージの WPARAM 引数\r
85 *               LPARAM lParam : メッセージの LPARAM 引数\r
86 *\r
87 *       Return Value\r
88 *               BOOL TRUE/FALSE\r
89 *----------------------------------------------------------------------------*/\r
90 \r
91 // 64ビット対応\r
92 //static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
93 static INT_PTR CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
94 {\r
95         char Tmp[41];\r
96         char *Pos;\r
97         int Seq;\r
98         int Type;\r
99         char Seed[MAX_SEED_LEN+1];\r
100         char Pass[PASSWORD_LEN+1];\r
101 \r
102         static const RADIOBUTTON AlgoButton[] = {\r
103                 { OTPCALC_MD4, MD4 },\r
104                 { OTPCALC_MD5, MD5 },\r
105                 { OTPCALC_SHA1, SHA1 }\r
106         };\r
107         #define ALGOBUTTONS     (sizeof(AlgoButton)/sizeof(RADIOBUTTON))\r
108 \r
109         switch (message)\r
110         {\r
111                 case WM_INITDIALOG :\r
112                         SendDlgItemMessage(hDlg, OTPCALC_KEY, EM_LIMITTEXT, 40, 0);\r
113                         SendDlgItemMessage(hDlg, OTPCALC_PASS, EM_LIMITTEXT, PASSWORD_LEN, 0);\r
114                         SetRadioButtonByValue(hDlg, MD4, AlgoButton, ALGOBUTTONS);\r
115                     return(TRUE);\r
116 \r
117                 case WM_COMMAND :\r
118                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
119                         {\r
120                                 case IDOK :\r
121                                         SendDlgItemMessage(hDlg, OTPCALC_KEY, WM_GETTEXT, 41, (LPARAM)Tmp);\r
122                                         SendDlgItemMessage(hDlg, OTPCALC_PASS, WM_GETTEXT, PASSWORD_LEN+1, (LPARAM)Pass);\r
123                                         Type = AskRadioButtonValue(hDlg, AlgoButton, ALGOBUTTONS);\r
124 \r
125                                         Pos = Tmp;\r
126                                         while(*Pos == ' ')\r
127                                                 Pos++;\r
128 \r
129                                         if(IsDigit(*Pos))\r
130                                         {\r
131                                                 Seq = atoi(Pos);\r
132                                                 /* Seed */\r
133                                                 if((Pos = GetNextField(Pos)) != NULL)\r
134                                                 {\r
135                                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == FFFTP_SUCCESS)\r
136                                                         {\r
137                                                                 Make6WordPass(Seq, Seed, Pass, Type, Tmp);\r
138                                                         }\r
139                                                         else\r
140                                                                 strcpy(Tmp, MSGJPN251);\r
141                                                 }\r
142                                                 else\r
143                                                         strcpy(Tmp, MSGJPN252);\r
144                                         }\r
145                                         else\r
146                                                 strcpy(Tmp, MSGJPN253);\r
147 \r
148                                         SendDlgItemMessage(hDlg, OTPCALC_RES, WM_SETTEXT, 0, (LPARAM)Tmp);\r
149                                         break;\r
150 \r
151                                 case IDCANCEL :\r
152                                         EndDialog(hDlg, NO);\r
153                                         break;\r
154 \r
155                                 case IDHELP :\r
156                                         hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000037);\r
157                                         break;\r
158                 }\r
159                         return(TRUE);\r
160         }\r
161     return(FALSE);\r
162 }\r
163 \r
164 \r
165 \r