OSDN Git Service

Change intervals between keep alive packets.
[ffftp/ffftp.git] / connect.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 #include <stdio.h>\r
32 #include <stddef.h>\r
33 #include <stdlib.h>\r
34 #include <stdarg.h>\r
35 #include <string.h>\r
36 #include <mbstring.h>\r
37 #include <time.h>\r
38 // IPv6対応\r
39 //#include <winsock.h>\r
40 #include <winsock2.h>\r
41 // 切断対策\r
42 #include <mstcpip.h>\r
43 #include <windowsx.h>\r
44 #include <commctrl.h>\r
45 \r
46 #include "common.h"\r
47 #include "resource.h"\r
48 \r
49 #include <htmlhelp.h>\r
50 #include "helpid.h"\r
51 \r
52 // UTF-8対応\r
53 #undef __MBSWRAPPER_H__\r
54 #include "mbswrapper.h"\r
55 \r
56 \r
57 /*===== プロトタイプ =====*/\r
58 \r
59 // 64ビット対応\r
60 //static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
61 static INT_PTR CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
62 // 同時接続対応\r
63 //static int SendInitCommand(char *Cmd);\r
64 static int SendInitCommand(SOCKET Socket, char *Cmd, int *CancelCheckWork);\r
65 static void AskUseFireWall(char *Host, int *Fire, int *Pasv, int *List);\r
66 static void SaveCurrentSetToHistory(void);\r
67 static int ReConnectSkt(SOCKET *Skt);\r
68 // 暗号化通信対応\r
69 // 同時接続対応\r
70 //static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security);\r
71 static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security, int *CancelCheckWork);\r
72 static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security, int *CancelCheckWork);\r
73 static int CheckOneTimePassword(char *Pass, char *Reply, int Type);\r
74 static BOOL CALLBACK BlkHookFnc(void);\r
75 static int Socks5MakeCmdPacket(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, ulong IP, char *Host, ushort Port);\r
76 // IPv6対応\r
77 static int Socks5MakeCmdPacketIPv6(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, char *IP, char *Host, ushort Port);\r
78 static int SocksSendCmd(SOCKET Socket, void *Data, int Size, int *CancelCheckWork);\r
79 // 同時接続対応\r
80 //static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet);\r
81 static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet, int *CancelCheckWork);\r
82 // 同時接続対応\r
83 //static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet);\r
84 static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet, int *CancelCheckWork);\r
85 static int Socks5SelMethod(SOCKET Socket, int *CancelCheckWork);\r
86 \r
87 /*===== 外部参照 =====*/\r
88 \r
89 extern char FilterStr[FILTER_EXT_LEN+1];\r
90 extern char TitleHostName[HOST_ADRS_LEN+1];\r
91 extern int CancelFlg;\r
92 \r
93 /* 設定値 */\r
94 extern char UserMailAdrs[USER_MAIL_LEN+1];\r
95 extern char FwallHost[HOST_ADRS_LEN+1];\r
96 extern char FwallUser[USER_NAME_LEN+1];\r
97 extern char FwallPass[PASSWORD_LEN+1];\r
98 extern int FwallPort;\r
99 extern int FwallType;\r
100 extern int FwallDefault;\r
101 extern int FwallSecurity;\r
102 extern int FwallResolv;\r
103 extern int FwallLower;\r
104 extern int FwallDelimiter;\r
105 extern int PasvDefault;\r
106 extern int QuickAnonymous;\r
107 // 切断対策\r
108 extern int TimeOut;\r
109 \r
110 /*===== ローカルなワーク =====*/\r
111 \r
112 static int Anonymous;\r
113 static int TryConnect = NO;\r
114 static SOCKET CmdCtrlSocket = INVALID_SOCKET;\r
115 static SOCKET TrnCtrlSocket = INVALID_SOCKET;\r
116 static HOSTDATA CurHost;\r
117 \r
118 /* 接続中の接続先、SOCKSサーバのアドレス情報を保存しておく */\r
119 /* この情報はlistenソケットを取得する際に用いる */\r
120 // IPv6対応\r
121 //static struct sockaddr_in SocksSockAddr;      /* SOCKSサーバのアドレス情報 */\r
122 //static struct sockaddr_in CurSockAddr;                /* 接続先ホストのアドレス情報 */\r
123 \r
124 static int UseIPadrs;\r
125 static char DomainName[HOST_ADRS_LEN+1];\r
126 \r
127 #if defined(HAVE_TANDEM)\r
128 static int Oss = NO;  /* OSS ファイルシステムへアクセスしている場合は YES */\r
129 #endif\r
130 \r
131 \r
132 \r
133 /*----- ホスト一覧を使ってホストへ接続 ----------------------------------------\r
134 *\r
135 *       Parameter\r
136 *               int Type : ダイアログのタイプ (DLG_TYPE_xxx)\r
137 *               int Num : 接続するホスト番号(0~, -1=ダイアログを出す)\r
138 \r
139 *       Return Value\r
140 *               なし\r
141 *----------------------------------------------------------------------------*/\r
142 \r
143 void ConnectProc(int Type, int Num)\r
144 {\r
145         int Save;\r
146         int LFSort;\r
147         int LDSort;\r
148         int RFSort;\r
149         int RDSort;\r
150 \r
151         SaveBookMark();\r
152         SaveCurrentSetToHost();\r
153 \r
154         if((Num >= 0) || (SelectHost(Type) == YES))\r
155         {\r
156                 if(Num >= 0)\r
157                         SetCurrentHost(Num);\r
158 \r
159                 /* 接続中なら切断する */\r
160                 if(CmdCtrlSocket != INVALID_SOCKET)\r
161                         DisconnectProc();\r
162 \r
163                 SetTaskMsg("----------------------------");\r
164 \r
165                 InitPWDcommand();\r
166                 CopyHostFromList(AskCurrentHost(), &CurHost);\r
167                 // UTF-8対応\r
168                 CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
169                 // IPv6対応\r
170                 CurHost.CurNetType = CurHost.NetType;\r
171 \r
172                 if(ConnectRas(CurHost.Dialup, CurHost.DialupAlways, CurHost.DialupNotify, CurHost.DialEntry) == FFFTP_SUCCESS)\r
173                 {\r
174                         SetHostKanaCnvImm(CurHost.KanaCnv);\r
175                         SetHostKanjiCodeImm(CurHost.KanjiCode);\r
176                         SetSyncMoveMode(CurHost.SyncMove);\r
177 \r
178                         if((AskSaveSortToHost() == YES) && (CurHost.Sort != SORT_NOTSAVED))\r
179                         {\r
180                                 DecomposeSortType(CurHost.Sort, &LFSort, &LDSort, &RFSort, &RDSort);\r
181                                 SetSortTypeImm(LFSort, LDSort, RFSort, RDSort);\r
182                                 ReSortDispList(WIN_LOCAL, &CancelFlg);\r
183                         }\r
184 \r
185                         Save = NO;\r
186                         if(strlen(CurHost.PassWord) > 0)\r
187                                 Save = YES;\r
188 \r
189                         DisableUserOpe();\r
190                         // 暗号化通信対応\r
191                         // 同時接続対応\r
192 //                      CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, Save, CurHost.Security);\r
193                         CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, Save, CurHost.Security, &CancelFlg);\r
194                         TrnCtrlSocket = CmdCtrlSocket;\r
195 \r
196                         if(CmdCtrlSocket != INVALID_SOCKET)\r
197                         {\r
198                                 // 暗号化通信対応\r
199                                 switch(CurHost.CryptMode)\r
200                                 {\r
201                                 case CRYPT_NONE:\r
202                                         if(CurHost.UseFTPIS != NO || CurHost.UseSFTP != NO)\r
203                                         {\r
204                                                 if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savecrypt_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
205                                                         SetHostExcryption(AskCurrentHost(), CurHost.UseNoEncryption, CurHost.UseFTPES, NO, NO);\r
206                                         }\r
207                                         break;\r
208                                 case CRYPT_FTPES:\r
209                                         if(CurHost.UseNoEncryption != NO || CurHost.UseFTPIS != NO || CurHost.UseSFTP != NO)\r
210                                         {\r
211                                                 if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savecrypt_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
212                                                         SetHostExcryption(AskCurrentHost(), NO, CurHost.UseFTPES, NO, NO);\r
213                                         }\r
214                                         break;\r
215                                 case CRYPT_FTPIS:\r
216                                         if(CurHost.UseNoEncryption != NO || CurHost.UseFTPES != NO || CurHost.UseSFTP != NO)\r
217                                         {\r
218                                                 if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savecrypt_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
219                                                         SetHostExcryption(AskCurrentHost(), NO, NO, CurHost.UseFTPIS, NO);\r
220                                         }\r
221                                         break;\r
222                                 case CRYPT_SFTP:\r
223                                         if(CurHost.UseNoEncryption != NO || CurHost.UseFTPES != NO || CurHost.UseFTPIS != NO)\r
224                                         {\r
225                                                 if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savecrypt_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
226                                                         SetHostExcryption(AskCurrentHost(), NO, NO, NO, CurHost.UseSFTP);\r
227                                         }\r
228                                         break;\r
229                                 }\r
230 \r
231                                 // UTF-8対応\r
232                                 if(CurHost.CurNameKanjiCode == KANJI_AUTO)\r
233                                 {\r
234                                         if(DoDirListCmdSkt("", "", 999, &CancelFlg) == FTP_COMPLETE)\r
235                                                 CurHost.CurNameKanjiCode = AnalyzeNameKanjiCode(999);\r
236                                 }\r
237 \r
238                                 strcpy(TitleHostName, CurHost.HostName);\r
239                                 DispWindowTitle();\r
240                                 SoundPlay(SND_CONNECT);\r
241 \r
242                                 SendInitCommand(CmdCtrlSocket, CurHost.InitCmd, &CancelFlg);\r
243 \r
244                                 if(strlen(CurHost.LocalInitDir) > 0)\r
245                                 {\r
246                                         DoLocalCWD(CurHost.LocalInitDir);\r
247                                         GetLocalDirForWnd();\r
248                                 }\r
249                                 InitTransCurDir();\r
250                                 DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
251 \r
252                                 LoadBookMark();\r
253                                 GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
254                         }\r
255                         else\r
256                                 SoundPlay(SND_ERROR);\r
257 \r
258                         EnableUserOpe();\r
259                 }\r
260                 else\r
261                         SetTaskMsg(MSGJPN001);\r
262         }\r
263         return;\r
264 }\r
265 \r
266 \r
267 /*----- ホスト名を入力してホストへ接続 ----------------------------------------\r
268 *\r
269 *       Parameter\r
270 *               なし\r
271 *\r
272 *       Return Value\r
273 *               なし\r
274 *----------------------------------------------------------------------------*/\r
275 \r
276 void QuickConnectProc(void)\r
277 {\r
278         char Tmp[FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1 + 2];\r
279         char File[FMAX_PATH+1];\r
280 \r
281         SaveBookMark();\r
282         SaveCurrentSetToHost();\r
283 \r
284         if(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(hostname_dlg), GetMainHwnd(), QuickConDialogCallBack, (LPARAM)Tmp) == YES)\r
285         {\r
286                 /* 接続中なら切断する */\r
287                 if(CmdCtrlSocket != INVALID_SOCKET)\r
288                         DisconnectProc();\r
289 \r
290                 SetTaskMsg("----------------------------");\r
291 \r
292                 InitPWDcommand();\r
293                 CopyDefaultHost(&CurHost);\r
294                 // UTF-8対応\r
295                 CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
296                 // IPv6対応\r
297                 CurHost.CurNetType = CurHost.NetType;\r
298                 if(SplitUNCpath(Tmp, CurHost.HostAdrs, CurHost.RemoteInitDir, File, CurHost.UserName, CurHost.PassWord, &CurHost.Port) == FFFTP_SUCCESS)\r
299                 {\r
300                         if(strlen(CurHost.UserName) == 0)\r
301                         {\r
302                                 strcpy(CurHost.UserName, Tmp + FMAX_PATH+1);\r
303                                 strcpy(CurHost.PassWord, Tmp + FMAX_PATH+1 + USER_NAME_LEN+1);\r
304                         }\r
305 \r
306                         SetCurrentHost(HOSTNUM_NOENTRY);\r
307                         AskUseFireWall(CurHost.HostAdrs, &CurHost.FireWall, &CurHost.Pasv, &CurHost.ListCmdOnly);\r
308                         CurHost.FireWall = (int)Tmp[FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1];\r
309                         CurHost.Pasv = (int)Tmp[FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1 + 1];\r
310 \r
311                         SetHostKanaCnvImm(CurHost.KanaCnv);\r
312                         SetHostKanjiCodeImm(CurHost.KanjiCode);\r
313                         SetSyncMoveMode(CurHost.SyncMove);\r
314 \r
315                         DisableUserOpe();\r
316                         // 暗号化通信対応\r
317                         // 同時接続対応\r
318 //                      CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
319                         CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security, &CancelFlg);\r
320                         TrnCtrlSocket = CmdCtrlSocket;\r
321 \r
322                         if(CmdCtrlSocket != INVALID_SOCKET)\r
323                         {\r
324                                 // UTF-8対応\r
325                                 if(CurHost.CurNameKanjiCode == KANJI_AUTO)\r
326                                 {\r
327                                         if(DoDirListCmdSkt("", "", 999, &CancelFlg) == FTP_COMPLETE)\r
328                                                 CurHost.CurNameKanjiCode = AnalyzeNameKanjiCode(999);\r
329                                 }\r
330 \r
331                                 strcpy(TitleHostName, CurHost.HostAdrs);\r
332                                 DispWindowTitle();\r
333                                 SoundPlay(SND_CONNECT);\r
334 \r
335                                 InitTransCurDir();\r
336                                 DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
337 \r
338                                 GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
339                                 EnableUserOpe();\r
340 \r
341                                 if(strlen(File) > 0)\r
342                                         DirectDownloadProc(File);\r
343                         }\r
344                         else\r
345                         {\r
346                                 SoundPlay(SND_ERROR);\r
347                                 EnableUserOpe();\r
348                         }\r
349                 }\r
350         }\r
351         return;\r
352 }\r
353 \r
354 \r
355 /*----- クイック接続ダイアログのコールバック ----------------------------------\r
356 *\r
357 *       Parameter\r
358 *               HWND hDlg : ウインドウハンドル\r
359 *               UINT message : メッセージ番号\r
360 *               WPARAM wParam : メッセージの WPARAM 引数\r
361 *               LPARAM lParam : メッセージの LPARAM 引数\r
362 *\r
363 *       Return Value\r
364 *               BOOL TRUE/FALSE\r
365 *----------------------------------------------------------------------------*/\r
366 \r
367 // 64ビット対応\r
368 //static BOOL CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
369 static INT_PTR CALLBACK QuickConDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
370 {\r
371         static char *Buf;\r
372         int i;\r
373         HISTORYDATA Tmp;\r
374 \r
375 //char Str[HOST_ADRS_LEN+USER_NAME_LEN+INIT_DIR_LEN+5+1];\r
376 \r
377         switch (iMessage)\r
378         {\r
379                 case WM_INITDIALOG :\r
380                         SendDlgItemMessage(hDlg, QHOST_HOST, CB_LIMITTEXT, FMAX_PATH, 0);\r
381                         SendDlgItemMessage(hDlg, QHOST_HOST, WM_SETTEXT, 0, (LPARAM)"");\r
382                         SendDlgItemMessage(hDlg, QHOST_USER, EM_LIMITTEXT, USER_NAME_LEN, 0);\r
383                         if(QuickAnonymous == YES)\r
384                         {\r
385                                 SendDlgItemMessage(hDlg, QHOST_USER, WM_SETTEXT, 0, (LPARAM)"anonymous");\r
386                                 SendDlgItemMessage(hDlg, QHOST_PASS, WM_SETTEXT, 0, (LPARAM)UserMailAdrs);\r
387                         }\r
388                         else\r
389                         {\r
390                                 SendDlgItemMessage(hDlg, QHOST_USER, WM_SETTEXT, 0, (LPARAM)"");\r
391                                 SendDlgItemMessage(hDlg, QHOST_PASS, WM_SETTEXT, 0, (LPARAM)"");\r
392                         }\r
393                         SendDlgItemMessage(hDlg, QHOST_PASS, EM_LIMITTEXT, PASSWORD_LEN, 0);\r
394                         SendDlgItemMessage(hDlg, QHOST_FWALL, BM_SETCHECK, FwallDefault, 0);\r
395                         SendDlgItemMessage(hDlg, QHOST_PASV, BM_SETCHECK, PasvDefault, 0);\r
396                         for(i = 0; i < HISTORY_MAX; i++)\r
397                         {\r
398                                 if(GetHistoryByNum(i, &Tmp) == FFFTP_SUCCESS)\r
399                                 {\r
400 //sprintf(Str, "%s (%s) %s", Tmp.HostAdrs, Tmp.UserName, Tmp.RemoteInitDir);\r
401 //SendDlgItemMessage(hDlg, QHOST_HOST, CB_ADDSTRING, 0, (LPARAM)Str);\r
402                                         SendDlgItemMessage(hDlg, QHOST_HOST, CB_ADDSTRING, 0, (LPARAM)Tmp.HostAdrs);\r
403                                 }\r
404                         }\r
405                         Buf = (char *)lParam;\r
406                         return(TRUE);\r
407 \r
408                 case WM_COMMAND :\r
409                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
410                         {\r
411                                 case IDOK :\r
412                                         SendDlgItemMessage(hDlg, QHOST_HOST, WM_GETTEXT, FMAX_PATH+1, (LPARAM)Buf);\r
413                                         SendDlgItemMessage(hDlg, QHOST_USER, WM_GETTEXT, USER_NAME_LEN+1, (LPARAM)Buf + FMAX_PATH+1);\r
414                                         SendDlgItemMessage(hDlg, QHOST_PASS, WM_GETTEXT, PASSWORD_LEN+1, (LPARAM)Buf + FMAX_PATH+1 + USER_NAME_LEN+1);\r
415                                         *(Buf + FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1) = (char)SendDlgItemMessage(hDlg, QHOST_FWALL, BM_GETCHECK, 0, 0);\r
416                                         *(Buf + FMAX_PATH+1 + USER_NAME_LEN+1 + PASSWORD_LEN+1+1) = (char)SendDlgItemMessage(hDlg, QHOST_PASV, BM_GETCHECK, 0, 0);\r
417                                         EndDialog(hDlg, YES);\r
418                                         break;\r
419 \r
420                                 case IDCANCEL :\r
421                                         EndDialog(hDlg, NO);\r
422                                         break;\r
423 \r
424 //                              case QHOST_HOST :\r
425 //                                      if(HIWORD(wParam) == CBN_EDITCHANGE)\r
426 //                                              DoPrintf("EDIT");\r
427 //                                      break;\r
428                         }\r
429             return(TRUE);\r
430         }\r
431         return(FALSE);\r
432 }\r
433 \r
434 \r
435 /*----- 指定したホスト名でホストへ接続 ----------------------------------------\r
436 *\r
437 *       Parameter\r
438 *               char *unc : UNC文字列\r
439 *               int Kanji : ホストの漢字コード (KANJI_xxx)\r
440 *               int Kana : 半角かな→全角変換モード (YES/NO)\r
441 *               int Fkanji : ファイル名の漢字コード (KANJI_xxx)\r
442 *               int TrMode : 転送モード (TYPE_xx)\r
443 *\r
444 *       Return Value\r
445 *               なし\r
446 *----------------------------------------------------------------------------*/\r
447 \r
448 void DirectConnectProc(char *unc, int Kanji, int Kana, int Fkanji, int TrMode)\r
449 {\r
450         char Host[HOST_ADRS_LEN+1];\r
451         char Path[FMAX_PATH+1];\r
452         char File[FMAX_PATH+1];\r
453         char User[USER_NAME_LEN+1];\r
454         char Pass[PASSWORD_LEN+1];\r
455         int Port;\r
456 \r
457         SaveBookMark();\r
458         SaveCurrentSetToHost();\r
459 \r
460         /* 接続中なら切断する */\r
461         if(CmdCtrlSocket != INVALID_SOCKET)\r
462                 DisconnectProc();\r
463 \r
464         SetTaskMsg("----------------------------");\r
465 \r
466         InitPWDcommand();\r
467         if(SplitUNCpath(unc, Host, Path, File, User, Pass, &Port) == FFFTP_SUCCESS)\r
468         {\r
469                 if(strlen(User) == 0)\r
470                 {\r
471                         strcpy(User, "anonymous");\r
472                         strcpy(Pass, UserMailAdrs);\r
473                 }\r
474 \r
475                 CopyDefaultHost(&CurHost);\r
476 \r
477                 SetCurrentHost(HOSTNUM_NOENTRY);\r
478                 strcpy(CurHost.HostAdrs, Host);\r
479                 strcpy(CurHost.UserName, User);\r
480                 strcpy(CurHost.PassWord, Pass);\r
481                 strcpy(CurHost.RemoteInitDir, Path);\r
482                 AskUseFireWall(CurHost.HostAdrs, &CurHost.FireWall, &CurHost.Pasv, &CurHost.ListCmdOnly);\r
483                 CurHost.Port = Port;\r
484                 CurHost.KanjiCode = Kanji;\r
485                 CurHost.KanaCnv = Kana;\r
486                 CurHost.NameKanjiCode = Fkanji;\r
487                 CurHost.KanaCnv = YES;                  /* とりあえず */\r
488                 // UTF-8対応\r
489                 CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
490                 // IPv6対応\r
491                 CurHost.CurNetType = CurHost.NetType;\r
492 \r
493                 SetHostKanaCnvImm(CurHost.KanaCnv);\r
494                 SetHostKanjiCodeImm(CurHost.KanjiCode);\r
495                 SetSyncMoveMode(CurHost.SyncMove);\r
496 \r
497                 if(TrMode != TYPE_DEFAULT)\r
498                 {\r
499                         SetTransferTypeImm(TrMode);\r
500                         DispTransferType();\r
501                 }\r
502 \r
503                 DisableUserOpe();\r
504                 // 暗号化通信対応\r
505                 // 同時接続対応\r
506 //              CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
507                 CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security, &CancelFlg);\r
508                 TrnCtrlSocket = CmdCtrlSocket;\r
509 \r
510                 if(CmdCtrlSocket != INVALID_SOCKET)\r
511                 {\r
512                         // UTF-8対応\r
513                         if(CurHost.CurNameKanjiCode == KANJI_AUTO)\r
514                         {\r
515                                 if(DoDirListCmdSkt("", "", 999, &CancelFlg) == FTP_COMPLETE)\r
516                                         CurHost.CurNameKanjiCode = AnalyzeNameKanjiCode(999);\r
517                         }\r
518 \r
519                         strcpy(TitleHostName, CurHost.HostAdrs);\r
520                         DispWindowTitle();\r
521                         SoundPlay(SND_CONNECT);\r
522 \r
523                         InitTransCurDir();\r
524                         DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
525 \r
526                         GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
527                         EnableUserOpe();\r
528 \r
529                         if(strlen(File) > 0)\r
530                                 DirectDownloadProc(File);\r
531                         else\r
532                                 ResetAutoExitFlg();\r
533                 }\r
534                 else\r
535                 {\r
536                         SoundPlay(SND_ERROR);\r
537                         EnableUserOpe();\r
538                 }\r
539         }\r
540         return;\r
541 }\r
542 \r
543 \r
544 /*----- ホストのヒストリで指定されたホストへ接続 ------------------------------\r
545 *\r
546 *       Parameter\r
547 *               int MenuCmd : 取り出すヒストリに割り当てられたメニューコマンド\r
548 *\r
549 *       Return Value\r
550 *               なし\r
551 *----------------------------------------------------------------------------*/\r
552 \r
553 void HistoryConnectProc(int MenuCmd)\r
554 {\r
555         HISTORYDATA Hist;\r
556         int LFSort;\r
557         int LDSort;\r
558         int RFSort;\r
559         int RDSort;\r
560 \r
561         if(GetHistoryByCmd(MenuCmd, &Hist) == FFFTP_SUCCESS)\r
562         {\r
563                 SaveBookMark();\r
564                 SaveCurrentSetToHost();\r
565 \r
566                 /* 接続中なら切断する */\r
567                 if(CmdCtrlSocket != INVALID_SOCKET)\r
568                         DisconnectProc();\r
569 \r
570                 SetTaskMsg("----------------------------");\r
571 \r
572                 InitPWDcommand();\r
573                 CopyHistoryToHost(&Hist, &CurHost);\r
574                 // UTF-8対応\r
575                 CurHost.CurNameKanjiCode = CurHost.NameKanjiCode;\r
576                 // IPv6対応\r
577                 CurHost.CurNetType = CurHost.NetType;\r
578 \r
579                 if(ConnectRas(CurHost.Dialup, CurHost.DialupAlways, CurHost.DialupNotify, CurHost.DialEntry) == FFFTP_SUCCESS)\r
580                 {\r
581                         SetCurrentHost(HOSTNUM_NOENTRY);\r
582                         SetHostKanaCnvImm(CurHost.KanaCnv);\r
583                         SetHostKanjiCodeImm(CurHost.KanjiCode);\r
584                         SetSyncMoveMode(CurHost.SyncMove);\r
585 \r
586                         DecomposeSortType(CurHost.Sort, &LFSort, &LDSort, &RFSort, &RDSort);\r
587                         SetSortTypeImm(LFSort, LDSort, RFSort, RDSort);\r
588                         ReSortDispList(WIN_LOCAL, &CancelFlg);\r
589 \r
590                         SetTransferTypeImm(Hist.Type);\r
591                         DispTransferType();\r
592 \r
593                         DisableUserOpe();\r
594                         // 暗号化通信対応\r
595                         // 同時接続対応\r
596 //                      CmdCtrlSocket = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security);\r
597                         CmdCtrlSocket = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security, &CancelFlg);\r
598                         TrnCtrlSocket = CmdCtrlSocket;\r
599 \r
600                         if(CmdCtrlSocket != INVALID_SOCKET)\r
601                         {\r
602                                 // UTF-8対応\r
603                                 if(CurHost.CurNameKanjiCode == KANJI_AUTO)\r
604                                 {\r
605                                         if(DoDirListCmdSkt("", "", 999, &CancelFlg) == FTP_COMPLETE)\r
606                                                 CurHost.CurNameKanjiCode = AnalyzeNameKanjiCode(999);\r
607                                 }\r
608 \r
609                                 strcpy(TitleHostName, CurHost.HostAdrs);\r
610                                 DispWindowTitle();\r
611                                 SoundPlay(SND_CONNECT);\r
612 \r
613                                 SendInitCommand(CmdCtrlSocket, CurHost.InitCmd, &CancelFlg);\r
614 \r
615                                 DoLocalCWD(CurHost.LocalInitDir);\r
616                                 GetLocalDirForWnd();\r
617 \r
618                                 InitTransCurDir();\r
619                                 DoCWD(CurHost.RemoteInitDir, YES, YES, YES);\r
620 \r
621                                 GetRemoteDirForWnd(CACHE_NORMAL, &CancelFlg);\r
622                         }\r
623                         else\r
624                                 SoundPlay(SND_ERROR);\r
625 \r
626                         EnableUserOpe();\r
627                 }\r
628                 else\r
629                         SetTaskMsg(MSGJPN002);\r
630         }\r
631         else\r
632                 SoundPlay(SND_ERROR);\r
633 \r
634         return;\r
635 }\r
636 \r
637 \r
638 /*----- ホストの初期化コマンドを送る ------------------------------------------\r
639 *\r
640 *       Parameter\r
641 *               int Cmd : 初期化コマンドス\r
642 *\r
643 *       Return Value\r
644 *               なし\r
645 *\r
646 *       NOte\r
647 *               初期化コマンドは以下のようなフォーマットであること\r
648 *                       cmd1\0\r
649 *                       cmd1\r\ncmd2\r\n\0\r
650 *----------------------------------------------------------------------------*/\r
651 \r
652 // 同時接続対応\r
653 //static int SendInitCommand(char *Cmd)\r
654 static int SendInitCommand(SOCKET Socket, char *Cmd, int *CancelCheckWork)\r
655 {\r
656         char Tmp[INITCMD_LEN+1];\r
657         char *Pos;\r
658 \r
659         while(strlen(Cmd) > 0)\r
660         {\r
661                 strcpy(Tmp, Cmd);\r
662                 if((Pos = strchr(Tmp, '\r')) != NULL)\r
663                         *Pos = NUL;\r
664                 if(strlen(Tmp) > 0)\r
665 //                      DoQUOTE(Tmp);\r
666                         DoQUOTE(Socket, Tmp, CancelCheckWork);\r
667 \r
668                 if((Cmd = strchr(Cmd, '\n')) != NULL)\r
669                         Cmd++;\r
670                 else\r
671                         break;\r
672         }\r
673         return(0);\r
674 }\r
675 \r
676 \r
677 /*----- 指定のホストはFireWallを使う設定かどうかを返す ------------------------\r
678 *\r
679 *       Parameter\r
680 *               char *Hots : ホスト名\r
681 *               int *Fire : FireWallを使うかどうかを返すワーク\r
682 *               int *Pasv : PASVモードを返すワーク\r
683 *               int *List : LISTコマンドのみ使用フラグ\r
684 *\r
685 *       Return Value\r
686 *               なし\r
687 *----------------------------------------------------------------------------*/\r
688 \r
689 static void AskUseFireWall(char *Host, int *Fire, int *Pasv, int *List)\r
690 {\r
691         int i;\r
692         HOSTDATA Tmp;\r
693 \r
694         *Fire = FwallDefault;\r
695         *Pasv = PasvDefault;\r
696         // NLSTを送ってしまうバグ修正(ただしNLSTを使うべきホストへクイック接続できなくなる)\r
697 //      *List = NO;\r
698 \r
699         i = 0;\r
700         while(CopyHostFromList(i, &Tmp) == FFFTP_SUCCESS)\r
701         {\r
702                 if(strcmp(Host, Tmp.HostAdrs) == 0)\r
703                 {\r
704                         *Fire = Tmp.FireWall;\r
705                         *Pasv = Tmp.Pasv;\r
706                         *List = Tmp.ListCmdOnly;\r
707                         break;\r
708                 }\r
709                 i++;\r
710         }\r
711         return;\r
712 }\r
713 \r
714 \r
715 /*----- 接続しているホストのアドレスを返す ------------------------------------\r
716 *\r
717 *       Parameter\r
718 *               なし\r
719 *\r
720 *       Return Value\r
721 *               char *ホストのアドレス\r
722 *----------------------------------------------------------------------------*/\r
723 \r
724 char *AskHostAdrs(void)\r
725 {\r
726         return(CurHost.HostAdrs);\r
727 }\r
728 \r
729 \r
730 /*----- 接続しているホストのポートを返す --------------------------------------\r
731 *\r
732 *       Parameter\r
733 *               なし\r
734 *\r
735 *       Return Value\r
736 *               int ホストのポート\r
737 *----------------------------------------------------------------------------*/\r
738 \r
739 int AskHostPort(void)\r
740 {\r
741         return(CurHost.Port);\r
742 }\r
743 \r
744 /*----- 接続しているホストのファイル名の漢字コードを返す ----------------------\r
745 *\r
746 *       Parameter\r
747 *               なし\r
748 *\r
749 *       Return Value\r
750 *               int 漢字コード (KANJI_xxx)\r
751 *----------------------------------------------------------------------------*/\r
752 \r
753 int AskHostNameKanji(void)\r
754 {\r
755         // UTF-8対応\r
756 //      if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
757 //              CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
758 //\r
759 //      return(CurHost.NameKanjiCode);\r
760         return(CurHost.CurNameKanjiCode);\r
761 }\r
762 \r
763 \r
764 /*----- 接続しているホストのファイル名の半角カナ変換フラグを返す --------------\r
765 *\r
766 *       Parameter\r
767 *               なし\r
768 *\r
769 *       Return Value\r
770 *               int 半角カナを全角に変換するかどうか (YES/NO)\r
771 *----------------------------------------------------------------------------*/\r
772 \r
773 int AskHostNameKana(void)\r
774 {\r
775         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
776                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
777 \r
778         return(CurHost.NameKanaCnv);\r
779 }\r
780 \r
781 \r
782 /*----- 接続しているホストのLISTコマンドモードを返す --------------------------\r
783 *\r
784 *       Parameter\r
785 *               なし\r
786 *\r
787 *       Return Value\r
788 *               int LISTコマンドモード (YES/NO)\r
789 *----------------------------------------------------------------------------*/\r
790 \r
791 int AskListCmdMode(void)\r
792 {\r
793         if(CurHost.HostType == HTYPE_VMS)\r
794                 return(YES);\r
795         else\r
796         {\r
797                 if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
798                         CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
799                 return(CurHost.ListCmdOnly);\r
800         }\r
801 }\r
802 \r
803 \r
804 /*----- 接続しているホストでNLST -Rを使うかどうかを返す ------------------------\r
805 *\r
806 *       Parameter\r
807 *               なし\r
808 *\r
809 *       Return Value\r
810 *               int NLST -Rを使うかどうか (YES/NO)\r
811 *----------------------------------------------------------------------------*/\r
812 \r
813 int AskUseNLST_R(void)\r
814 {\r
815         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
816                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
817 \r
818         return(CurHost.UseNLST_R);\r
819 }\r
820 \r
821 \r
822 /*----- 接続しているホストのChmodコマンドを返す -------------------------------\r
823 *\r
824 *       Parameter\r
825 *               なし\r
826 *\r
827 *       Return Value\r
828 *               char *Chmodコマンド\r
829 *----------------------------------------------------------------------------*/\r
830 \r
831 char *AskHostChmodCmd(void)\r
832 {\r
833         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
834                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
835 \r
836         return(CurHost.ChmodCmd);\r
837 }\r
838 \r
839 \r
840 /*----- 接続しているホストのタイムゾーンを返す --------------------------------\r
841 *\r
842 *       Parameter\r
843 *               なし\r
844 *\r
845 *       Return Value\r
846 *               int タイムゾーン\r
847 *----------------------------------------------------------------------------*/\r
848 \r
849 int AskHostTimeZone(void)\r
850 {\r
851         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
852                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
853 \r
854         return(CurHost.TimeZone);\r
855 }\r
856 \r
857 \r
858 /*----- 接続しているホストのPASVモードを返す ----------------------------------\r
859 *\r
860 *       Parameter\r
861 *               なし\r
862 *\r
863 *       Return Value\r
864 *               int PASVモードかどうか (YES/NO)\r
865 *----------------------------------------------------------------------------*/\r
866 \r
867 int AskPasvMode(void)\r
868 {\r
869         return(CurHost.Pasv);\r
870 }\r
871 \r
872 \r
873 /*----- 接続しているホストのLNSTファイル名を返す ------------------------------\r
874 *\r
875 *       Parameter\r
876 *               なし\r
877 *\r
878 *       Return Value\r
879 *               char *ファイル名/オプション\r
880 *----------------------------------------------------------------------------*/\r
881 \r
882 char *AskHostLsName(void)\r
883 {\r
884         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
885                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
886 \r
887         return(CurHost.LsName);\r
888 }\r
889 \r
890 \r
891 /*----- 接続しているホストのホストタイプを返す --------------------------------\r
892 *\r
893 *       Parameter\r
894 *               なし\r
895 *\r
896 *       Return Value\r
897 *               char *ファイル名/オプション\r
898 *----------------------------------------------------------------------------*/\r
899 \r
900 int AskHostType(void)\r
901 {\r
902         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
903                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
904 \r
905 #if defined(HAVE_TANDEM)\r
906         /* OSS ファイルシステムは UNIX ファイルシステムと同じでいいので AUTO を返す\r
907            ただし、Guardian ファイルシステムに戻ったときにおかしくならないように\r
908            CurHost.HostType 変数は更新しない */\r
909         if(CurHost.HostType == HTYPE_TANDEM && Oss == YES)\r
910                 return(HTYPE_AUTO);\r
911 #endif\r
912 \r
913         return(CurHost.HostType);\r
914 }\r
915 \r
916 \r
917 /*----- 接続しているホストはFireWallを使うホストかどうかを返す ----------------\r
918 *\r
919 *       Parameter\r
920 *               なし\r
921 *\r
922 *       Return Value\r
923 *               int FireWallを使うかどうか (YES/NO)\r
924 *----------------------------------------------------------------------------*/\r
925 \r
926 int AskHostFireWall(void)\r
927 {\r
928         return(CurHost.FireWall);\r
929 }\r
930 \r
931 \r
932 /*----- 接続しているホストでフルパスでファイルアクセスしないかどうかを返す ----\r
933 *\r
934 *       Parameter\r
935 *               なし\r
936 *\r
937 *       Return Value\r
938 *               int フルパスでアクセスしない (YES=フルパス禁止/NO)\r
939 *----------------------------------------------------------------------------*/\r
940 \r
941 int AskNoFullPathMode(void)\r
942 {\r
943         if(CurHost.HostType == HTYPE_VMS)\r
944                 return(YES);\r
945         else\r
946                 return(CurHost.NoFullPath);\r
947 }\r
948 \r
949 \r
950 /*----- 接続しているユーザ名を返す --------------------------------------------\r
951 *\r
952 *       Parameter\r
953 *               なし\r
954 *\r
955 *       Return Value\r
956 *               char *ユーザ名\r
957 *----------------------------------------------------------------------------*/\r
958 \r
959 char *AskHostUserName(void)\r
960 {\r
961         return(CurHost.UserName);\r
962 }\r
963 \r
964 \r
965 /*----- 現在の設定をホストの設定にセットする ----------------------------------\r
966 *\r
967 *       Parameter\r
968 *               なし\r
969 *\r
970 *       Return Value\r
971 *               なし\r
972 *\r
973 *       Note\r
974 *               カレントディレクトリ、ソート方法をホストの設定にセットする\r
975 *----------------------------------------------------------------------------*/\r
976 \r
977 void SaveCurrentSetToHost(void)\r
978 {\r
979         int Host;\r
980         char LocDir[FMAX_PATH+1];\r
981         char HostDir[FMAX_PATH+1];\r
982 \r
983         if(TrnCtrlSocket != INVALID_SOCKET)\r
984         {\r
985                 if((Host = AskCurrentHost()) != HOSTNUM_NOENTRY)\r
986                 {\r
987                         CopyHostFromListInConnect(Host, &CurHost);\r
988                         if(CurHost.LastDir == YES)\r
989                         {\r
990                                 AskLocalCurDir(LocDir, FMAX_PATH);\r
991                                 AskRemoteCurDir(HostDir, FMAX_PATH);\r
992                                 SetHostDir(AskCurrentHost(), LocDir, HostDir);\r
993                         }\r
994                         SetHostSort(AskCurrentHost(), AskSortType(ITEM_LFILE), AskSortType(ITEM_LDIR), AskSortType(ITEM_RFILE), AskSortType(ITEM_RDIR));\r
995                 }\r
996         }\r
997         return;\r
998 }\r
999 \r
1000 \r
1001 /*----- 現在の設定をヒストリにセットする --------------------------------------\r
1002 *\r
1003 *       Parameter\r
1004 *               なし\r
1005 *\r
1006 *       Return Value\r
1007 *               なし\r
1008 *----------------------------------------------------------------------------*/\r
1009 \r
1010 static void SaveCurrentSetToHistory(void)\r
1011 {\r
1012         char LocDir[FMAX_PATH+1];\r
1013         char HostDir[FMAX_PATH+1];\r
1014 \r
1015         AskLocalCurDir(LocDir, FMAX_PATH);\r
1016         AskRemoteCurDir(HostDir, FMAX_PATH);\r
1017         strcpy(CurHost.LocalInitDir, LocDir);\r
1018         strcpy(CurHost.RemoteInitDir, HostDir);\r
1019 \r
1020         CurHost.Sort = AskSortType(ITEM_LFILE) * 0x1000000 | AskSortType(ITEM_LDIR) * 0x10000 | AskSortType(ITEM_RFILE) * 0x100 | AskSortType(ITEM_RDIR);\r
1021 \r
1022         CurHost.KanjiCode = AskHostKanjiCode();\r
1023         CurHost.KanaCnv = AskHostKanaCnv();\r
1024 \r
1025         CurHost.SyncMove = AskSyncMoveMode();\r
1026 \r
1027         AddHostToHistory(&CurHost, AskTransferType());\r
1028         SetAllHistoryToMenu();\r
1029 \r
1030         return;\r
1031 }\r
1032 \r
1033 \r
1034 /*----- コマンドコントロールソケットの再接続 ----------------------------------\r
1035 *\r
1036 *       Parameter\r
1037 *               なし\r
1038 *\r
1039 *       Return Value\r
1040 *               int ステータス\r
1041 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1042 *----------------------------------------------------------------------------*/\r
1043 \r
1044 int ReConnectCmdSkt(void)\r
1045 {\r
1046         int Sts;\r
1047 \r
1048 \r
1049         if(CmdCtrlSocket != TrnCtrlSocket)\r
1050                 do_closesocket(TrnCtrlSocket);\r
1051         TrnCtrlSocket = INVALID_SOCKET;\r
1052 \r
1053         Sts = ReConnectSkt(&CmdCtrlSocket);\r
1054 \r
1055         TrnCtrlSocket = CmdCtrlSocket;\r
1056 \r
1057         return(Sts);\r
1058 }\r
1059 \r
1060 \r
1061 /*----- 転送コントロールソケットの再接続 --------------------------------------\r
1062 *\r
1063 *       Parameter\r
1064 *               なし\r
1065 *\r
1066 *       Return Value\r
1067 *               int ステータス\r
1068 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1069 *----------------------------------------------------------------------------*/\r
1070 \r
1071 //int ReConnectTrnSkt(void)\r
1072 //{\r
1073 //      return(ReConnectSkt(&TrnCtrlSocket));\r
1074 //}\r
1075 // 同時接続対応\r
1076 int ReConnectTrnSkt(SOCKET *Skt, int *CancelCheckWork)\r
1077 {\r
1078 //      char Path[FMAX_PATH+1];\r
1079         int Sts;\r
1080         // 暗号化通信対応\r
1081         HOSTDATA HostData;\r
1082 \r
1083         Sts = FFFTP_FAIL;\r
1084 \r
1085         SetTaskMsg(MSGJPN003);\r
1086 \r
1087 //      DisableUserOpe();\r
1088         /* 現在のソケットは切断 */\r
1089         if(*Skt != INVALID_SOCKET)\r
1090                 do_closesocket(*Skt);\r
1091         /* 再接続 */\r
1092         // 暗号化通信対応\r
1093         HostData = CurHost;\r
1094         if(HostData.CryptMode != CRYPT_NONE)\r
1095                 HostData.UseNoEncryption = NO;\r
1096         if(HostData.CryptMode != CRYPT_FTPES)\r
1097                 HostData.UseFTPES = NO;\r
1098         if(HostData.CryptMode != CRYPT_FTPIS)\r
1099                 HostData.UseFTPIS = NO;\r
1100         if(HostData.CryptMode != CRYPT_SFTP)\r
1101                 HostData.UseSFTP = NO;\r
1102         // UTF-8対応\r
1103         HostData.CurNameKanjiCode = HostData.NameKanjiCode;\r
1104         // IPv6対応\r
1105         HostData.CurNetType = HostData.NetType;\r
1106         // 同時接続対応\r
1107         HostData.NoDisplayUI = YES;\r
1108         // 暗号化通信対応\r
1109         // 同時接続対応\r
1110 //      if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
1111         if((*Skt = DoConnect(&HostData, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security, CancelCheckWork)) != INVALID_SOCKET)\r
1112         {\r
1113                 SendInitCommand(*Skt, CurHost.InitCmd, CancelCheckWork);\r
1114 //              AskRemoteCurDir(Path, FMAX_PATH);\r
1115 //              DoCWD(Path, YES, YES, YES);\r
1116                 Sts = FFFTP_SUCCESS;\r
1117         }\r
1118         else\r
1119                 SoundPlay(SND_ERROR);\r
1120 \r
1121 //      EnableUserOpe();\r
1122         return(Sts);\r
1123 }\r
1124 \r
1125 \r
1126 /*----- 回線の再接続 ----------------------------------------------------------\r
1127 *\r
1128 *       Parameter\r
1129 *               SOCKET *Skt : 接続したソケットを返すワーク\r
1130 *\r
1131 *       Return Value\r
1132 *               int ステータス\r
1133 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1134 *----------------------------------------------------------------------------*/\r
1135 \r
1136 static int ReConnectSkt(SOCKET *Skt)\r
1137 {\r
1138         char Path[FMAX_PATH+1];\r
1139         int Sts;\r
1140 \r
1141         Sts = FFFTP_FAIL;\r
1142 \r
1143         SetTaskMsg(MSGJPN003);\r
1144 \r
1145         DisableUserOpe();\r
1146         /* 現在のソケットは切断 */\r
1147         if(*Skt != INVALID_SOCKET)\r
1148                 do_closesocket(*Skt);\r
1149         /* 再接続 */\r
1150         // 暗号化通信対応\r
1151         // 同時接続対応\r
1152 //      if((*Skt = DoConnect(CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security)) != INVALID_SOCKET)\r
1153         if((*Skt = DoConnect(&CurHost, CurHost.HostAdrs, CurHost.UserName, CurHost.PassWord, CurHost.Account, CurHost.Port, CurHost.FireWall, NO, CurHost.Security, &CancelFlg)) != INVALID_SOCKET)\r
1154         {\r
1155                 SendInitCommand(*Skt, CurHost.InitCmd, &CancelFlg);\r
1156                 AskRemoteCurDir(Path, FMAX_PATH);\r
1157                 DoCWD(Path, YES, YES, YES);\r
1158                 Sts = FFFTP_SUCCESS;\r
1159         }\r
1160         else\r
1161                 SoundPlay(SND_ERROR);\r
1162 \r
1163         EnableUserOpe();\r
1164         return(Sts);\r
1165 }\r
1166 \r
1167 \r
1168 /*----- コマンドコントロールソケットを返す ------------------------------------\r
1169 *\r
1170 *       Parameter\r
1171 *               なし\r
1172 *\r
1173 *       Return Value\r
1174 *               SOCKET コマンドコントロールソケット\r
1175 *----------------------------------------------------------------------------*/\r
1176 \r
1177 SOCKET AskCmdCtrlSkt(void)\r
1178 {\r
1179         return(CmdCtrlSocket);\r
1180 }\r
1181 \r
1182 \r
1183 /*----- 転送コントロールソケットを返す ----------------------------------------\r
1184 *\r
1185 *       Parameter\r
1186 *               なし\r
1187 *\r
1188 *       Return Value\r
1189 *               SOCKET 転送コントロールソケット\r
1190 *----------------------------------------------------------------------------*/\r
1191 \r
1192 SOCKET AskTrnCtrlSkt(void)\r
1193 {\r
1194         return(TrnCtrlSocket);\r
1195 }\r
1196 \r
1197 \r
1198 /*----- コマンド/転送コントロールソケットの共有を解除 ------------------------\r
1199 *\r
1200 *       Parameter\r
1201 *               なし\r
1202 *\r
1203 *       Return Value\r
1204 *               なし\r
1205 *----------------------------------------------------------------------------*/\r
1206 \r
1207 void SktShareProh(void)\r
1208 {\r
1209         if(CmdCtrlSocket == TrnCtrlSocket)\r
1210         {\r
1211 \r
1212 //SetTaskMsg("############### SktShareProh");\r
1213 \r
1214                 // 同時接続対応\r
1215 //              CmdCtrlSocket = INVALID_SOCKET;\r
1216 //              ReConnectSkt(&CmdCtrlSocket);\r
1217                 if(CurHost.ReuseCmdSkt == YES)\r
1218                 {\r
1219                         CmdCtrlSocket = INVALID_SOCKET;\r
1220                         ReConnectSkt(&CmdCtrlSocket);\r
1221                 }\r
1222         }\r
1223         return;\r
1224 }\r
1225 \r
1226 \r
1227 /*----- コマンド/転送コントロールソケットの共有が解除されているかチェック ----\r
1228 *\r
1229 *       Parameter\r
1230 *               なし\r
1231 *\r
1232 *       Return Value\r
1233 *               int ステータス\r
1234 *                       YES=共有解除/NO=共有\r
1235 *----------------------------------------------------------------------------*/\r
1236 \r
1237 int AskShareProh(void)\r
1238 {\r
1239         int Sts;\r
1240 \r
1241         Sts = YES;\r
1242         // 同時接続対応\r
1243 //      if(CmdCtrlSocket == TrnCtrlSocket)\r
1244         if(CmdCtrlSocket == TrnCtrlSocket || TrnCtrlSocket == INVALID_SOCKET)\r
1245                 Sts = NO;\r
1246 \r
1247         return(Sts);\r
1248 }\r
1249 \r
1250 \r
1251 /*----- ホストから切断 --------------------------------------------------------\r
1252 *\r
1253 *       Parameter\r
1254 *               なし\r
1255 *\r
1256 *       Return Value\r
1257 *               なし\r
1258 *----------------------------------------------------------------------------*/\r
1259 \r
1260 void DisconnectProc(void)\r
1261 {\r
1262 \r
1263 //SetTaskMsg("############### Disconnect Cmd=%x, Trn=%x", CmdCtrlSocket,TrnCtrlSocket);\r
1264 \r
1265         if((CmdCtrlSocket != INVALID_SOCKET) && (CmdCtrlSocket != TrnCtrlSocket))\r
1266         {\r
1267                 // 同時接続対応\r
1268 //              DoQUIT(CmdCtrlSocket);\r
1269                 DoQUIT(CmdCtrlSocket, &CancelFlg);\r
1270                 DoClose(CmdCtrlSocket);\r
1271         }\r
1272 \r
1273         if(TrnCtrlSocket != INVALID_SOCKET)\r
1274         {\r
1275                 // 同時接続対応\r
1276 //              DoQUIT(TrnCtrlSocket);\r
1277                 DoQUIT(TrnCtrlSocket, &CancelFlg);\r
1278                 DoClose(TrnCtrlSocket);\r
1279 \r
1280                 SaveCurrentSetToHistory();\r
1281 \r
1282                 EraseRemoteDirForWnd();\r
1283                 SetTaskMsg(MSGJPN004);\r
1284         }\r
1285 \r
1286         TrnCtrlSocket = INVALID_SOCKET;\r
1287         CmdCtrlSocket = INVALID_SOCKET;\r
1288 \r
1289         DispWindowTitle();\r
1290         MakeButtonsFocus();\r
1291         ClearBookMark();\r
1292 \r
1293         return;\r
1294 }\r
1295 \r
1296 \r
1297 /*----- ソケットが強制切断されたときの処理 ------------------------------------\r
1298 *\r
1299 *       Parameter\r
1300 *               なし\r
1301 *\r
1302 *       Return Value\r
1303 *               なし\r
1304 *----------------------------------------------------------------------------*/\r
1305 \r
1306 void DisconnectSet(void)\r
1307 {\r
1308         CmdCtrlSocket = INVALID_SOCKET;\r
1309         TrnCtrlSocket = INVALID_SOCKET;\r
1310 \r
1311         EraseRemoteDirForWnd();\r
1312         DispWindowTitle();\r
1313         MakeButtonsFocus();\r
1314         SetTaskMsg(MSGJPN005);\r
1315         return;\r
1316 }\r
1317 \r
1318 \r
1319 /*----- ホストに接続中かどうかを返す ------------------------------------------\r
1320 *\r
1321 *       Parameter\r
1322 *               なし\r
1323 *\r
1324 *       Return Value\r
1325 *               int ステータス (YES/NO)\r
1326 *----------------------------------------------------------------------------*/\r
1327 \r
1328 int AskConnecting(void)\r
1329 {\r
1330         int Sts;\r
1331 \r
1332         Sts = NO;\r
1333         if(TrnCtrlSocket != INVALID_SOCKET)\r
1334                 Sts = YES;\r
1335 \r
1336         return(Sts);\r
1337 }\r
1338 \r
1339 \r
1340 #if defined(HAVE_TANDEM)\r
1341 /*----- 接続している本当のホストのホストタイプを返す --------------------------\r
1342 *\r
1343 *       Parameter\r
1344 *               なし\r
1345 *\r
1346 *       Return Value\r
1347 *               char *ファイル名/オプション\r
1348 *----------------------------------------------------------------------------*/\r
1349 \r
1350 int AskRealHostType(void)\r
1351 {\r
1352         if(AskCurrentHost() != HOSTNUM_NOENTRY)\r
1353                 CopyHostFromListInConnect(AskCurrentHost(), &CurHost);\r
1354 \r
1355         return(CurHost.HostType);\r
1356 }\r
1357 \r
1358 /*----- OSS ファイルシステムにアクセスしているかどうかのフラグを変更する ------\r
1359 *\r
1360 *       Parameter\r
1361 *               int ステータス (YES/NO)\r
1362 *\r
1363 *       Return Value\r
1364 *               int ステータス (YES/NO)\r
1365 *----------------------------------------------------------------------------*/\r
1366 \r
1367 int SetOSS(int wkOss)\r
1368 {\r
1369         if(Oss != wkOss) {\r
1370                 if (wkOss == YES) {\r
1371                         strcpy(CurHost.InitCmd, "OSS");\r
1372                 } else {\r
1373                         strcpy(CurHost.InitCmd, "GUARDIAN");\r
1374                 }\r
1375         }\r
1376         Oss = wkOss;\r
1377         return(Oss);\r
1378 }\r
1379 \r
1380 /*----- OSS ファイルシステムにアクセスしているかどうかを返す ------------------\r
1381 *\r
1382 *       Parameter\r
1383 *               なし\r
1384 *\r
1385 *       Return Value\r
1386 *               int ステータス (YES/NO)\r
1387 *----------------------------------------------------------------------------*/\r
1388 \r
1389 int AskOSS(void)\r
1390 {\r
1391         return(Oss);\r
1392 }\r
1393 #endif /* HAVE_TANDEM */\r
1394 \r
1395 \r
1396 /*----- ホストへ接続する ------------------------------------------------------\r
1397 *\r
1398 *       Parameter\r
1399 *               char *Host : ホスト名\r
1400 *               char *User : ユーザ名\r
1401 *               char *Pass : パスワード\r
1402 *               char *Acct : アカウント\r
1403 *               int Port : ポート\r
1404 *               int Fwall : FireWallを使うかどうか (YES/NO)\r
1405 *               int SavePass : パスワードを再入力した時に保存するかどうか (YES/NO)\r
1406 *               int Security : セキュリティ (SECURITY_xxx, MDx)\r
1407 *\r
1408 *       Return Value\r
1409 *               SOCKET ソケット\r
1410 *\r
1411 *       Note\r
1412 *               ホスト名、ユーザ名、パスワードが指定されていなかったときは、接続に使用\r
1413 *               したものをコピーしてかえす\r
1414 *                       char *Host : ホスト名\r
1415 *                       char *User : ユーザ名\r
1416 *                       char *Pass : パスワード\r
1417 *                       char *Acct : アカウント\r
1418 *\r
1419 *               FireWallは次のように動作する\r
1420 *                       TYPE1   Connect fire → USER user(f) → PASS pass(f) → SITE host → USER user(h) →      PASS pass(h) → ACCT acct\r
1421 *                       TYPE2   Connect fire → USER user(f) → PASS pass(f) →              USER user(h)@host → PASS pass(h) → ACCT acct\r
1422 *                       TYPE3   Connect fire →                                              USER user(h)@host → PASS pass(h) → ACCT acct\r
1423 *                       TYPE4   Connect fire →                                 OPEN host → USER user(h) →      PASS pass(h) → ACCT acct\r
1424 *                       TYPE5   SOCKS4\r
1425 *                       none    Connect host →                                              USER user(h) →      PASS pass(h) → ACCT acct\r
1426 *----------------------------------------------------------------------------*/\r
1427 \r
1428 // 暗号化通信対応\r
1429 static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security, int *CancelCheckWork)\r
1430 {\r
1431         int Sts;\r
1432         int Flg;\r
1433         int Anony;\r
1434         SOCKET ContSock;\r
1435         char Buf[1024];\r
1436         char Reply[1024];\r
1437         int Continue;\r
1438         int ReInPass;\r
1439         char *Tmp;\r
1440         int HostPort;\r
1441         static const char *SiteTbl[4] = { "SITE", "site", "OPEN", "open" };\r
1442         char TmpBuf[ONELINE_BUF_SIZE];\r
1443         struct linger LingerOpt;\r
1444         struct tcp_keepalive KeepAlive;\r
1445         DWORD dwTmp;\r
1446 \r
1447         // 暗号化通信対応\r
1448         ContSock = INVALID_SOCKET;\r
1449 \r
1450         if(CryptMode == CRYPT_NONE || CryptMode == CRYPT_FTPES || CryptMode == CRYPT_FTPIS)\r
1451         {\r
1452                 if(Fwall == YES)\r
1453                         Fwall = FwallType;\r
1454                 else\r
1455                         Fwall = FWALL_NONE;\r
1456 \r
1457                 TryConnect = YES;\r
1458                 // 暗号化通信対応\r
1459 //              CancelFlg = NO;\r
1460 #if 0\r
1461 //              WSASetBlockingHook(BlkHookFnc);\r
1462 #endif\r
1463 \r
1464                 ContSock = INVALID_SOCKET;\r
1465 \r
1466                 HostPort = Port;\r
1467                 Tmp = Host;\r
1468                 if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
1469                    (Fwall == FWALL_SIDEWINDER) ||\r
1470                    (Fwall == FWALL_FU_FP))\r
1471                 {\r
1472                         Tmp = FwallHost;\r
1473                         Port = FwallPort;\r
1474                 }\r
1475 \r
1476                 if(strlen(Tmp) != 0)\r
1477                 {\r
1478                         // 同時接続対応\r
1479 //                      if((ContSock = connectsock(Tmp, Port, "", &CancelFlg)) != INVALID_SOCKET)\r
1480                         if((ContSock = connectsock(Tmp, Port, "", CancelCheckWork)) != INVALID_SOCKET)\r
1481                         {\r
1482                                 // バッファを無効\r
1483 #ifdef DISABLE_CONTROL_NETWORK_BUFFERS\r
1484                                 int BufferSize = 0;\r
1485                                 setsockopt(ContSock, SOL_SOCKET, SO_SNDBUF, (char*)&BufferSize, sizeof(int));\r
1486                                 setsockopt(ContSock, SOL_SOCKET, SO_RCVBUF, (char*)&BufferSize, sizeof(int));\r
1487 #endif\r
1488                                 // FTPIS対応\r
1489 //                              while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM)\r
1490 //                                      ;\r
1491                                 if(CryptMode == CRYPT_FTPIS)\r
1492                                 {\r
1493                                         if(AttachSSL(ContSock, INVALID_SOCKET, CancelCheckWork))\r
1494                                         {\r
1495                                                 while((Sts = ReadReplyMessage(ContSock, Buf, 1024, CancelCheckWork, TmpBuf) / 100) == FTP_PRELIM)\r
1496                                                         ;\r
1497                                         }\r
1498                                         else\r
1499                                                 Sts = FTP_ERROR;\r
1500                                 }\r
1501                                 else\r
1502                                 {\r
1503                                         while((Sts = ReadReplyMessage(ContSock, Buf, 1024, CancelCheckWork, TmpBuf) / 100) == FTP_PRELIM)\r
1504                                                 ;\r
1505                                 }\r
1506 \r
1507                                 if(Sts == FTP_COMPLETE)\r
1508                                 {\r
1509                                         Flg = 1;\r
1510                                         if(setsockopt(ContSock, SOL_SOCKET, SO_OOBINLINE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1511                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1512                                         // データ転送用ソケットのTCP遅延転送が無効されているので念のため\r
1513                                         if(setsockopt(ContSock, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1514                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1515 //#pragma aaa\r
1516                                         Flg = 1;\r
1517                                         if(setsockopt(ContSock, SOL_SOCKET, SO_KEEPALIVE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1518                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1519                                         // 切断対策\r
1520                                         if(TimeOut > 0)\r
1521                                         {\r
1522                                                 KeepAlive.onoff = 1;\r
1523                                                 KeepAlive.keepalivetime = TimeOut * 1000;\r
1524                                                 KeepAlive.keepaliveinterval = 1000;\r
1525                                                 if(WSAIoctl(ContSock, SIO_KEEPALIVE_VALS, &KeepAlive, sizeof(struct tcp_keepalive), NULL, 0, &dwTmp, NULL, NULL) == SOCKET_ERROR)\r
1526                                                         ReportWSError("WSAIoctl", WSAGetLastError());\r
1527                                         }\r
1528                                         LingerOpt.l_onoff = 1;\r
1529                                         LingerOpt.l_linger = 90;\r
1530                                         if(setsockopt(ContSock, SOL_SOCKET, SO_LINGER, (LPSTR)&LingerOpt, sizeof(LingerOpt)) == SOCKET_ERROR)\r
1531                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1532 ///////\r
1533 \r
1534 \r
1535                                         /*===== 認証を行なう =====*/\r
1536 \r
1537                                         Sts = FTP_COMPLETE;\r
1538                                         if((Fwall == FWALL_FU_FP_SITE) ||\r
1539                                            (Fwall == FWALL_FU_FP_USER) ||\r
1540                                            (Fwall == FWALL_FU_FP))\r
1541                                         {\r
1542                                                 // 同時接続対応\r
1543 //                                              if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
1544                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
1545                                                 {\r
1546                                                         CheckOneTimePassword(FwallPass, Reply, FwallSecurity);\r
1547                                                         // 同時接続対応\r
1548 //                                                      Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1549                                                         Sts = command(ContSock, NULL, CancelCheckWork, "PASS %s", Reply) / 100;\r
1550                                                 }\r
1551                                         }\r
1552                                         else if(Fwall == FWALL_SIDEWINDER)\r
1553                                         {\r
1554                                                 // 同時接続対応\r
1555 //                                              Sts = command(ContSock, Reply, &CancelFlg, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
1556                                                 Sts = command(ContSock, Reply, CancelCheckWork, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
1557                                         }\r
1558                                         if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1559                                         {\r
1560                                                 SetTaskMsg(MSGJPN006);\r
1561                                                 DoClose(ContSock);\r
1562                                                 ContSock = INVALID_SOCKET;\r
1563                                         }\r
1564                                         else\r
1565                                         {\r
1566                                                 if((Fwall == FWALL_FU_FP_SITE) || (Fwall == FWALL_OPEN))\r
1567                                                 {\r
1568                                                         Flg = 0;\r
1569                                                         if(Fwall == FWALL_OPEN)\r
1570                                                                 Flg = 2;\r
1571                                                         if(FwallLower == YES)\r
1572                                                                 Flg++;\r
1573 \r
1574                                                         if(HostPort == PORT_NOR)\r
1575                                                                 // 同時接続対応\r
1576 //                                                              Sts = command(ContSock, NULL, &CancelFlg, "%s %s", SiteTbl[Flg], Host) / 100;\r
1577                                                                 Sts = command(ContSock, NULL, CancelCheckWork, "%s %s", SiteTbl[Flg], Host) / 100;\r
1578                                                         else\r
1579                                                                 // 同時接続対応\r
1580 //                                                              Sts = command(ContSock, NULL, &CancelFlg, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
1581                                                                 Sts = command(ContSock, NULL, CancelCheckWork, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
1582                                                 }\r
1583 \r
1584                                                 if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1585                                                 {\r
1586                                                         SetTaskMsg(MSGJPN007, Host);\r
1587                                                         DoClose(ContSock);\r
1588                                                         ContSock = INVALID_SOCKET;\r
1589                                                 }\r
1590                                                 else\r
1591                                                 {\r
1592                                                         Anony = NO;\r
1593                                                         // 同時接続対応\r
1594 //                                                      if((strlen(User) != 0) || \r
1595 //                                                         (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1596                                                         if((strlen(User) != 0) || \r
1597                                                            ((HostData->NoDisplayUI == NO) && (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1598                                                         {\r
1599                                                                 if(Anony == YES)\r
1600                                                                 {\r
1601                                                                         strcpy(User, "anonymous");\r
1602                                                                         strcpy(Pass, UserMailAdrs);\r
1603                                                                 }\r
1604 \r
1605                                                                 if((Fwall == FWALL_FU_FP_USER) || (Fwall == FWALL_USER))\r
1606                                                                 {\r
1607                                                                         if(HostPort == PORT_NOR)\r
1608                                                                                 sprintf(Buf, "%s%c%s", User, FwallDelimiter, Host);\r
1609                                                                         else\r
1610                                                                                 sprintf(Buf, "%s%c%s %d", User, FwallDelimiter, Host, HostPort);\r
1611                                                                 }\r
1612                                                                 else\r
1613                                                                         strcpy(Buf, User);\r
1614 \r
1615                                                                 // FTPES対応\r
1616                                                                 if(CryptMode == CRYPT_FTPES)\r
1617                                                                 {\r
1618                                                                         if(IsOpenSSLLoaded() && (Sts = command(ContSock, Reply, CancelCheckWork, "AUTH TLS")) == 234)\r
1619                                                                         {\r
1620                                                                                 if(AttachSSL(ContSock, INVALID_SOCKET, CancelCheckWork))\r
1621                                                                                 {\r
1622                                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "PBSZ 0")) == 200)\r
1623                                                                                         {\r
1624                                                                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "PROT P")) == 200)\r
1625                                                                                                 {\r
1626                                                                                                 }\r
1627                                                                                                 else\r
1628                                                                                                         Sts = FTP_ERROR;\r
1629                                                                                         }\r
1630                                                                                         else\r
1631                                                                                                 Sts = FTP_ERROR;\r
1632                                                                                 }\r
1633                                                                                 else\r
1634                                                                                         Sts = FTP_ERROR;\r
1635                                                                         }\r
1636                                                                         else\r
1637                                                                                 Sts = FTP_ERROR;\r
1638                                                                 }\r
1639 \r
1640                                                                 // FTPIS対応\r
1641                                                                 // "PBSZ 0"と"PROT P"は黙示的に設定されているはずだが念のため\r
1642                                                                 if(CryptMode == CRYPT_FTPIS)\r
1643                                                                 {\r
1644                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "PBSZ 0")) == 200)\r
1645                                                                         {\r
1646                                                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "PROT P")) == 200)\r
1647                                                                                 {\r
1648                                                                                 }\r
1649                                                                         }\r
1650                                                                 }\r
1651 \r
1652                                                                 ReInPass = NO;\r
1653                                                                 do\r
1654                                                                 {\r
1655                                                                         // FTPES対応\r
1656                                                                         if(Sts == FTP_ERROR)\r
1657                                                                                 break;\r
1658                                                                         Continue = NO;\r
1659                                                                         // 同時接続対応\r
1660 //                                                                      if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
1661                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
1662                                                                         {\r
1663                                                                                 // 同時接続対応\r
1664 //                                                                              if((strlen(Pass) != 0) || \r
1665 //                                                                                 (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1666                                                                                 if((strlen(Pass) != 0) || \r
1667                                                                                    ((HostData->NoDisplayUI == NO) && (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1668                                                                                 {\r
1669                                                                                         CheckOneTimePassword(Pass, Reply, Security);\r
1670 \r
1671                                                                                         /* パスワードがスペース1個の時はパスワードの実体なしとする */\r
1672                                                                                         if(strcmp(Reply, " ") == 0)\r
1673                                                                                                 strcpy(Reply, "");\r
1674 \r
1675                                                                                         // 同時接続対応\r
1676 //                                                                                      Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1677                                                                                         Sts = command(ContSock, NULL, CancelCheckWork, "PASS %s", Reply) / 100;\r
1678                                                                                         if(Sts == FTP_ERROR)\r
1679                                                                                         {\r
1680                                                                                                 strcpy(Pass, "");\r
1681                                                                                                 // 同時接続対応\r
1682 //                                                                                              if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
1683                                                                                                 if(HostData->NoDisplayUI == NO && InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
1684                                                                                                         Continue = YES;\r
1685                                                                                                 else\r
1686                                                                                                         DoPrintf("No password specified.");\r
1687                                                                                                 ReInPass = YES;\r
1688                                                                                         }\r
1689                                                                                         else if(Sts == FTP_CONTINUE)\r
1690                                                                                         {\r
1691                                                                                                 // 同時接続対応\r
1692 //                                                                                              if((strlen(Acct) != 0) || \r
1693 //                                                                                                 (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1694                                                                                                 if((strlen(Acct) != 0) || \r
1695                                                                                                    ((HostData->NoDisplayUI == NO) && (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1696                                                                                                 {\r
1697                                                                                                         // 同時接続対応\r
1698 //                                                                                                      Sts = command(ContSock, NULL, &CancelFlg, "ACCT %s", Acct) / 100;\r
1699                                                                                                         Sts = command(ContSock, NULL, CancelCheckWork, "ACCT %s", Acct) / 100;\r
1700                                                                                                 }\r
1701                                                                                                 else\r
1702                                                                                                         DoPrintf("No account specified");\r
1703                                                                                         }\r
1704                                                                                 }\r
1705                                                                                 else\r
1706                                                                                 {\r
1707                                                                                         Sts = FTP_ERROR;\r
1708                                                                                         DoPrintf("No password specified.");\r
1709                                                                                 }\r
1710                                                                         }\r
1711                                                                         // FTPES対応\r
1712                                                                         if(Continue == YES)\r
1713                                                                                 Sts = FTP_COMPLETE;\r
1714                                                                 }\r
1715                                                                 while(Continue == YES);\r
1716                                                         }\r
1717                                                         else\r
1718                                                         {\r
1719                                                                 Sts = FTP_ERROR;\r
1720                                                                 DoPrintf("No user name specified");\r
1721                                                         }\r
1722 \r
1723                                                         if(Sts != FTP_COMPLETE)\r
1724                                                         {\r
1725                                                                 SetTaskMsg(MSGJPN008, Host);\r
1726                                                                 DoClose(ContSock);\r
1727                                                                 ContSock = INVALID_SOCKET;\r
1728                                                         }\r
1729                                                         else if((SavePass == YES) && (ReInPass == YES))\r
1730                                                         {\r
1731                                                                 // 同時接続対応\r
1732 //                                                              if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
1733                                                                 if(HostData->NoDisplayUI == NO && DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
1734                                                                         SetHostPassword(AskCurrentHost(), Pass);\r
1735                                                         }\r
1736                                                 }\r
1737                                         }\r
1738                                 }\r
1739                                 else\r
1740                                 {\r
1741 //#pragma aaa\r
1742                                         SetTaskMsg(MSGJPN009/*"接続できません(1) %x", ContSock*/);\r
1743                                         DoClose(ContSock);\r
1744                                         ContSock = INVALID_SOCKET;\r
1745                                 }\r
1746                         }\r
1747                 }\r
1748                 else\r
1749                 {\r
1750 \r
1751                         if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
1752                            (Fwall == FWALL_FU_FP))\r
1753                                 SetTaskMsg(MSGJPN010);\r
1754                         else\r
1755                                 SetTaskMsg(MSGJPN011);\r
1756                 }\r
1757 \r
1758 #if 0\r
1759 //              WSAUnhookBlockingHook();\r
1760 #endif\r
1761                 TryConnect = NO;\r
1762 \r
1763                 // FEAT対応\r
1764                 // ホストの機能を確認\r
1765                 if(ContSock != INVALID_SOCKET)\r
1766                 {\r
1767                         if((Sts = command(ContSock, Reply, CancelCheckWork, "FEAT")) == 211)\r
1768                         {\r
1769                                 // 改行文字はReadReplyMessageで消去されるため区切り文字に空白を使用\r
1770                                 // UTF-8対応\r
1771                                 if(strstr(Reply, " UTF8 "))\r
1772                                         HostData->Feature |= FEATURE_UTF8;\r
1773                                 // MLST対応\r
1774                                 if(strstr(Reply, " MLST ") || strstr(Reply, " MLSD "))\r
1775                                         HostData->Feature |= FEATURE_MLSD;\r
1776                                 // IPv6対応\r
1777                                 if(strstr(Reply, " EPRT ") || strstr(Reply, " EPSV "))\r
1778                                         HostData->Feature |= FEATURE_EPRT | FEATURE_EPSV;\r
1779                                 // ホスト側の日時取得\r
1780                                 if(strstr(Reply, " MDTM "))\r
1781                                         HostData->Feature |= FEATURE_MDTM;\r
1782                                 // ホスト側の日時設定\r
1783                                 if(strstr(Reply, " MFMT "))\r
1784                                         HostData->Feature |= FEATURE_MFMT;\r
1785                         }\r
1786                         // UTF-8対応\r
1787                         if(HostData->CurNameKanjiCode == KANJI_AUTO && (HostData->Feature & FEATURE_UTF8))\r
1788                         {\r
1789                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "OPTS UTF8 ON")) == 200)\r
1790                                         HostData->CurNameKanjiCode = KANJI_UTF8N;\r
1791                         }\r
1792                 }\r
1793         }\r
1794         else if(CryptMode == CRYPT_SFTP)\r
1795         {\r
1796                 // TODO:\r
1797                 // テストコード\r
1798                 // ログイン成功を確認\r
1799 #define strrcmp(_Str1, _Str2) (strcmp(strstr(_Str1, _Str2) ? strstr(_Str1, _Str2) : "", _Str2))\r
1800                 size_t r;\r
1801                 ContSock = SFTP_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);\r
1802                 SFTP_SetTimeoutCallback(ContSock, SSLTimeoutCallback);\r
1803                 while(1)\r
1804                 {\r
1805                         r = SFTP_recv(ContSock, Reply, 1024, 0);\r
1806                         if(r == SOCKET_ERROR)\r
1807                                 break;\r
1808                         if(r <= 0)\r
1809                                 continue;\r
1810                         Reply[r] = '\0';\r
1811                         SetTaskMsg("%s", Reply);\r
1812                         if(strrcmp(Reply, "psftp> ") == 0)\r
1813                                 break;\r
1814                 }\r
1815                 r = SFTP_send(ContSock, "open \"", strlen("open \""), 0);\r
1816                 r = SFTP_send(ContSock, Host, strlen(Host), 0);\r
1817                 r = SFTP_send(ContSock, "\"\r\n", strlen("\"\r\n"), 0);\r
1818                 while(1)\r
1819                 {\r
1820                         r = SFTP_recv(ContSock, Reply, 1024, 0);\r
1821                         if(r == SOCKET_ERROR)\r
1822                                 break;\r
1823                         if(r <= 0)\r
1824                                 continue;\r
1825                         Reply[r] = '\0';\r
1826                         SetTaskMsg("%s", Reply);\r
1827                         if(strrcmp(Reply, "Store key in cache? (y/n) ") == 0)\r
1828                         {\r
1829                                 r = SFTP_send(ContSock, "n\r\n", strlen("n\r\n"), 0);\r
1830                         }\r
1831                         if(strrcmp(Reply, "Update cached key? (y/n, Return cancels connection) ") == 0)\r
1832                         {\r
1833                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1834                         }\r
1835                         if(strrcmp(Reply, "login as: ") == 0)\r
1836                         {\r
1837                                 r = SFTP_send(ContSock, User, strlen(User), 0);\r
1838                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1839                         }\r
1840                         if(strrcmp(Reply, "password: ") == 0)\r
1841                         {\r
1842                                 r = SFTP_send(ContSock, Pass, strlen(Pass), 0);\r
1843                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1844                         }\r
1845                         if(strrcmp(Reply, "psftp> ") == 0)\r
1846                                 break;\r
1847                         Sleep(1);\r
1848                 }\r
1849                 SFTP_closesocket(ContSock);\r
1850                 ContSock = INVALID_SOCKET;\r
1851         }\r
1852 \r
1853         return(ContSock);\r
1854 }\r
1855 \r
1856 // 同時接続対応\r
1857 //static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security)\r
1858 static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security, int *CancelCheckWork)\r
1859 {\r
1860         SOCKET ContSock;\r
1861         ContSock = INVALID_SOCKET;\r
1862         *CancelCheckWork = NO;\r
1863         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseSFTP == YES)\r
1864         {\r
1865                 SetTaskMsg(MSGJPN317);\r
1866                 if((ContSock = DoConnectCrypt(CRYPT_SFTP, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1867                         HostData->CryptMode = CRYPT_SFTP;\r
1868         }\r
1869         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseFTPIS == YES)\r
1870         {\r
1871                 SetTaskMsg(MSGJPN316);\r
1872                 if((ContSock = DoConnectCrypt(CRYPT_FTPIS, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1873                         HostData->CryptMode = CRYPT_FTPIS;\r
1874         }\r
1875         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseFTPES == YES)\r
1876         {\r
1877                 SetTaskMsg(MSGJPN315);\r
1878                 if((ContSock = DoConnectCrypt(CRYPT_FTPES, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1879                         HostData->CryptMode = CRYPT_FTPES;\r
1880         }\r
1881         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseNoEncryption == YES)\r
1882         {\r
1883                 SetTaskMsg(MSGJPN314);\r
1884                 if((ContSock = DoConnectCrypt(CRYPT_NONE, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1885                         HostData->CryptMode = CRYPT_NONE;\r
1886         }\r
1887         return ContSock;\r
1888 }\r
1889 \r
1890 \r
1891 /*----- ワンタイムパスワードのチェック ----------------------------------------\r
1892 *\r
1893 *       Parameter\r
1894 *               chat *Pass : パスワード/パスフレーズ\r
1895 *               char *Reply : USERコマンドを送ったあとのリプライ文字列\r
1896 *                                               /PASSコマンドで送るパスワードを返すバッファ\r
1897 *               int Type : タイプ (SECURITY_xxx, MDx)\r
1898 *\r
1899 *       Return Value\r
1900 *               int ステータス\r
1901 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1902 *\r
1903 *       Note\r
1904 *               ワンタイムパスワードでない時はPassをそのままReplyにコピー\r
1905 *----------------------------------------------------------------------------*/\r
1906 \r
1907 static int CheckOneTimePassword(char *Pass, char *Reply, int Type)\r
1908 {\r
1909         int Sts;\r
1910         char *Pos;\r
1911         int Seq;\r
1912         char Seed[MAX_SEED_LEN+1];\r
1913         int i;\r
1914 \r
1915         Sts = FFFTP_SUCCESS;\r
1916         Pos = NULL;\r
1917 \r
1918         if(Type == SECURITY_AUTO)\r
1919         {\r
1920                 if((Pos = stristr(Reply, "otp-md5")) != NULL)\r
1921                 {\r
1922                         Type = MD5;\r
1923                         SetTaskMsg(MSGJPN012);\r
1924                 }\r
1925                 else if((Pos = stristr(Reply, "otp-sha1")) != NULL)\r
1926                 {\r
1927                         Type = SHA1;\r
1928                         SetTaskMsg(MSGJPN013);\r
1929                 }\r
1930                 else if(((Pos = stristr(Reply, "otp-md4")) != NULL) || ((Pos = stristr(Reply, "s/key")) != NULL))\r
1931                 {\r
1932                         Type = MD4;\r
1933                         SetTaskMsg(MSGJPN014);\r
1934                 }\r
1935         }\r
1936         else\r
1937                 Pos = GetNextField(Reply);\r
1938 \r
1939         if((Type == MD4) || (Type == MD5) || (Type == SHA1))\r
1940         {\r
1941                 /* シーケンス番号を見つけるループ */\r
1942                 DoPrintf("Analize OTP");\r
1943                 DoPrintf("%s", Pos);\r
1944                 Sts = FFFTP_FAIL;\r
1945                 while((Pos = GetNextField(Pos)) != NULL)\r
1946                 {\r
1947                         if(IsDigit(*Pos))\r
1948                         {\r
1949                                 Seq = atoi(Pos);\r
1950                                 DoPrintf("Sequence=%d", Seq);\r
1951 \r
1952                                 /* Seed */\r
1953                                 if((Pos = GetNextField(Pos)) != NULL)\r
1954                                 {\r
1955                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == FFFTP_SUCCESS)\r
1956                                         {\r
1957                                                 /* Seedは英数字のみ有効とする */\r
1958                                                 for(i = strlen(Seed)-1; i >= 0; i--)\r
1959                                                 {\r
1960                                                         if((IsAlpha(Seed[i]) == 0) && (IsDigit(Seed[i]) == 0))\r
1961                                                                 Seed[i] = NUL;\r
1962                                                 }\r
1963                                                 if(strlen(Seed) > 0)\r
1964                                                 {\r
1965                                                         DoPrintf("Seed=%s", Seed);\r
1966                                                         Make6WordPass(Seq, Seed, Pass, Type, Reply);\r
1967                                                         DoPrintf("Response=%s", Reply);\r
1968 \r
1969                                                         /* シーケンス番号のチェックと警告 */\r
1970                                                         if(Seq <= 10)\r
1971                                                                 DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_notify_dlg), GetMainHwnd(), ExeEscDialogProc);\r
1972 \r
1973                                                         Sts = FFFTP_SUCCESS;\r
1974                                                 }\r
1975                                         }\r
1976                                 }\r
1977                                 break;\r
1978                         }\r
1979                 }\r
1980 \r
1981                 if(Sts == FFFTP_FAIL)\r
1982                         SetTaskMsg(MSGJPN015);\r
1983         }\r
1984         else\r
1985         {\r
1986                 strcpy(Reply, Pass);\r
1987                 DoPrintf("No OTP used.");\r
1988         }\r
1989         return(Sts);\r
1990 }\r
1991 \r
1992 \r
1993 \r
1994 \r
1995 \r
1996 \r
1997 \r
1998 \r
1999 \r
2000 \r
2001 \r
2002 \r
2003 \r
2004 \r
2005 /*----- ソケットを接続する ----------------------------------------------------\r
2006 *\r
2007 *       Parameter\r
2008 *               char *host : ホスト名\r
2009 *               int port : ポート番号\r
2010 *               char *PreMsg : メッセージの前半部分\r
2011 *\r
2012 *       Return Value\r
2013 *               SOCKET ソケット\r
2014 *----------------------------------------------------------------------------*/\r
2015 \r
2016 // IPv6対応\r
2017 typedef SOCKET (__cdecl* LPCONNECTSOCK)(char*, int, char*, int*);\r
2018 \r
2019 typedef struct\r
2020 {\r
2021         HANDLE h;\r
2022         DWORD ExitCode;\r
2023         char *host;\r
2024         int port;\r
2025         char *PreMsg;\r
2026         int CancelCheckWork;\r
2027         LPCONNECTSOCK f;\r
2028         SOCKET s;\r
2029 } CONNECTSOCKDATA;\r
2030 \r
2031 DWORD WINAPI connectsockThreadProc(LPVOID lpParameter)\r
2032 {\r
2033         CONNECTSOCKDATA* pData;\r
2034         pData = (CONNECTSOCKDATA*)lpParameter;\r
2035         pData->s = pData->f(pData->host, pData->port, pData->PreMsg, &pData->CancelCheckWork);\r
2036         return 0;\r
2037 }\r
2038 \r
2039 // IPv6対応\r
2040 SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2041 {\r
2042         SOCKET Result;\r
2043         CONNECTSOCKDATA DataIPv4;\r
2044         CONNECTSOCKDATA DataIPv6;\r
2045         Result = INVALID_SOCKET;\r
2046         switch(CurHost.CurNetType)\r
2047         {\r
2048         case NTYPE_AUTO:\r
2049 //              if((Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
2050 //                      CurHost.CurNetType = NTYPE_IPV4;\r
2051 //              else if((Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
2052 //                      CurHost.CurNetType = NTYPE_IPV6;\r
2053                 DataIPv4.host = host;\r
2054                 DataIPv4.port = port;\r
2055                 DataIPv4.PreMsg = PreMsg;\r
2056                 DataIPv4.CancelCheckWork = *CancelCheckWork;\r
2057                 DataIPv4.f = connectsockIPv4;\r
2058                 DataIPv4.h = CreateThread(NULL, 0, connectsockThreadProc, &DataIPv4, 0, NULL);\r
2059                 DataIPv6.host = host;\r
2060                 DataIPv6.port = port;\r
2061                 DataIPv6.PreMsg = PreMsg;\r
2062                 DataIPv6.CancelCheckWork = *CancelCheckWork;\r
2063                 DataIPv6.f = connectsockIPv6;\r
2064                 DataIPv6.h = CreateThread(NULL, 0, connectsockThreadProc, &DataIPv6, 0, NULL);\r
2065                 while(1)\r
2066                 {\r
2067                         if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode))\r
2068                         {\r
2069                                 if(DataIPv4.ExitCode != STILL_ACTIVE)\r
2070                                 {\r
2071                                         if(DataIPv4.s != INVALID_SOCKET)\r
2072                                         {\r
2073                                                 Result = DataIPv4.s;\r
2074                                                 CurHost.CurNetType = NTYPE_IPV4;\r
2075                                                 break;\r
2076                                         }\r
2077                                 }\r
2078                         }\r
2079                         if(GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
2080                         {\r
2081                                 if(DataIPv6.ExitCode != STILL_ACTIVE)\r
2082                                 {\r
2083                                         if(DataIPv6.s != INVALID_SOCKET)\r
2084                                         {\r
2085                                                 Result = DataIPv6.s;\r
2086                                                 CurHost.CurNetType = NTYPE_IPV6;\r
2087                                                 break;\r
2088                                         }\r
2089                                 }\r
2090                         }\r
2091                         if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode) && GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
2092                         {\r
2093                                 if(DataIPv4.ExitCode != STILL_ACTIVE && DataIPv6.ExitCode != STILL_ACTIVE)\r
2094                                 {\r
2095                                         if(DataIPv4.s == INVALID_SOCKET && DataIPv6.s == INVALID_SOCKET)\r
2096                                                 break;\r
2097                                 }\r
2098                         }\r
2099                         DataIPv4.CancelCheckWork = *CancelCheckWork;\r
2100                         DataIPv6.CancelCheckWork = *CancelCheckWork;\r
2101                         BackgrndMessageProc();\r
2102                         Sleep(1);\r
2103                 }\r
2104                 while(1)\r
2105                 {\r
2106                         if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode) && GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
2107                         {\r
2108                                 if(DataIPv4.ExitCode != STILL_ACTIVE && DataIPv6.ExitCode != STILL_ACTIVE)\r
2109                                 {\r
2110                                         CloseHandle(DataIPv4.h);\r
2111                                         CloseHandle(DataIPv6.h);\r
2112                                         break;\r
2113                                 }\r
2114                         }\r
2115                         DataIPv4.CancelCheckWork = YES;\r
2116                         DataIPv6.CancelCheckWork = YES;\r
2117                         BackgrndMessageProc();\r
2118                         Sleep(1);\r
2119                 }\r
2120                 break;\r
2121         case NTYPE_IPV4:\r
2122                 Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork);\r
2123                 CurHost.CurNetType = NTYPE_IPV4;\r
2124                 break;\r
2125         case NTYPE_IPV6:\r
2126                 Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork);\r
2127                 CurHost.CurNetType = NTYPE_IPV6;\r
2128                 break;\r
2129         }\r
2130         return Result;\r
2131 }\r
2132 \r
2133 \r
2134 // IPv6対応\r
2135 //SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2136 SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2137 {\r
2138         // IPv6対応\r
2139         struct sockaddr_in SocksSockAddr;       /* SOCKSサーバのアドレス情報 */\r
2140         struct sockaddr_in CurSockAddr;         /* 接続先ホストのアドレス情報 */\r
2141         struct sockaddr_in saSockAddr;\r
2142         char HostEntry[MAXGETHOSTSTRUCT];\r
2143         struct hostent *pHostEntry;\r
2144         SOCKET sSocket;\r
2145         int Len;\r
2146         int Fwall;\r
2147         SOCKS4CMD Socks4Cmd;\r
2148         SOCKS4REPLY Socks4Reply;\r
2149         SOCKS5REQUEST Socks5Cmd;\r
2150         SOCKS5REPLY Socks5Reply;\r
2151 \r
2152         //////////////////////////////\r
2153         // ホスト名解決と接続の準備\r
2154         //////////////////////////////\r
2155 \r
2156         Fwall = FWALL_NONE;\r
2157         if(AskHostFireWall() == YES)\r
2158                 Fwall = FwallType;\r
2159 \r
2160         sSocket = INVALID_SOCKET;\r
2161 \r
2162         UseIPadrs = YES;\r
2163         strcpy(DomainName, host);\r
2164         memset(&CurSockAddr, 0, sizeof(CurSockAddr));\r
2165         CurSockAddr.sin_port = htons((u_short)port);\r
2166         CurSockAddr.sin_family = AF_INET;\r
2167         if((CurSockAddr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)\r
2168         {\r
2169                 // ホスト名が指定された\r
2170                 // ホスト名からアドレスを求める\r
2171                 if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
2172                    (FwallResolv == YES))\r
2173                 {\r
2174                         // ホスト名解決はSOCKSサーバに任せる\r
2175                         pHostEntry = NULL;\r
2176                 }\r
2177                 else\r
2178                 {\r
2179                         // アドレスを取得\r
2180                         // IPv6対応\r
2181 //                      SetTaskMsg(MSGJPN016, DomainName);\r
2182                         SetTaskMsg(MSGJPN016, DomainName, MSGJPN333);\r
2183                         // IPv6対応\r
2184 //                      pHostEntry = do_gethostbyname(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2185                         pHostEntry = do_gethostbynameIPv4(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2186                 }\r
2187 \r
2188                 if(pHostEntry != NULL)\r
2189                 {\r
2190                         memcpy((char *)&CurSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2191                         // IPv6対応\r
2192 //                      SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
2193                         SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port), MSGJPN333);\r
2194                 }\r
2195                 else\r
2196                 {\r
2197                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2198                         {\r
2199                                 UseIPadrs = NO;\r
2200                                 // IPv6対応\r
2201 //                              SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port));\r
2202                                 SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port), MSGJPN333);\r
2203                         }\r
2204                         else\r
2205                         {\r
2206                                 // IPv6対応\r
2207 //                              SetTaskMsg(MSGJPN019, host);\r
2208                                 SetTaskMsg(MSGJPN019, host, MSGJPN333);\r
2209                                 return(INVALID_SOCKET);\r
2210                         }\r
2211                 }\r
2212         }\r
2213         else\r
2214                 // IPv6対応\r
2215 //              SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
2216                 SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port), MSGJPN333);\r
2217 \r
2218         if((Fwall == FWALL_SOCKS4) || (Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2219         {\r
2220                 // SOCKSを使う\r
2221                 // SOCKSに接続する準備\r
2222                 if(Fwall == FWALL_SOCKS4)\r
2223                 {\r
2224                         Socks4Cmd.Ver = SOCKS4_VER;\r
2225                         Socks4Cmd.Cmd = SOCKS4_CMD_CONNECT;\r
2226                         Socks4Cmd.Port = CurSockAddr.sin_port;\r
2227                         Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
2228                         strcpy(Socks4Cmd.UserID, FwallUser);\r
2229                         Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
2230                 }\r
2231                 else\r
2232                 {\r
2233                         Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
2234                 }\r
2235 \r
2236                 memset(&SocksSockAddr, 0, sizeof(SocksSockAddr));\r
2237                 if((SocksSockAddr.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE)\r
2238                 {\r
2239                         // IPv6対応\r
2240 //                      if((pHostEntry = do_gethostbyname(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2241                         if((pHostEntry = do_gethostbynameIPv4(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2242                                 memcpy((char *)&SocksSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2243                         else\r
2244                         {\r
2245                                 // IPv6対応\r
2246 //                              SetTaskMsg(MSGJPN021, FwallHost);\r
2247                                 SetTaskMsg(MSGJPN021, FwallHost, MSGJPN333);\r
2248                                 return INVALID_SOCKET;\r
2249                         }\r
2250                 }\r
2251                 SocksSockAddr.sin_port = htons((u_short)FwallPort);\r
2252                 SocksSockAddr.sin_family = AF_INET;\r
2253                 // IPv6対応\r
2254 //              SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port));\r
2255                 SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port), MSGJPN333);\r
2256                 // connectで接続する先はSOCKSサーバ\r
2257                 memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr));\r
2258         }\r
2259         else\r
2260         {\r
2261                 // connectで接続するのは接続先のホスト\r
2262                 memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr));\r
2263         }\r
2264 \r
2265         /////////////\r
2266         // 接続実行\r
2267         /////////////\r
2268 \r
2269         if((sSocket = do_socket(AF_INET, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
2270         {\r
2271                 // ソケットにデータを付与\r
2272                 SetAsyncTableDataIPv4(sSocket, &CurSockAddr, &SocksSockAddr);\r
2273                 if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2274                 {\r
2275                         if(Fwall == FWALL_SOCKS4)\r
2276                         {\r
2277                                 Socks4Reply.Result = -1;\r
2278                                 // 同時接続対応\r
2279 //                              if((SocksSendCmd(sSocket, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2280 //                                 (Socks4GetCmdReply(sSocket, &Socks4Reply) != FFFTP_SUCCESS) || \r
2281 //                                 (Socks4Reply.Result != SOCKS4_RES_OK))\r
2282                                 if((SocksSendCmd(sSocket, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2283                                    (Socks4GetCmdReply(sSocket, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2284                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
2285                                 {\r
2286                                         // IPv6対応\r
2287 //                                      SetTaskMsg(MSGJPN023, Socks4Reply.Result);\r
2288                                         SetTaskMsg(MSGJPN023, Socks4Reply.Result, MSGJPN333);\r
2289                                         DoClose(sSocket);\r
2290                                         sSocket = INVALID_SOCKET;\r
2291                                 }\r
2292                         }\r
2293                         else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2294                         {\r
2295                                 if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
2296                                 {\r
2297                                         DoClose(sSocket);\r
2298                                         sSocket = INVALID_SOCKET;\r
2299                                 }\r
2300 \r
2301                                 Socks5Reply.Result = -1;\r
2302                                 // 同時接続対応\r
2303 //                              if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2304 //                                 (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
2305 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2306                                 if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2307                                    (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2308                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2309                                 {\r
2310                                         // IPv6対応\r
2311 //                                      SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
2312                                         SetTaskMsg(MSGJPN024, Socks5Reply.Result, MSGJPN333);\r
2313                                         DoClose(sSocket);\r
2314                                         sSocket = INVALID_SOCKET;\r
2315                                 }\r
2316 \r
2317                         }\r
2318 \r
2319                         if(sSocket != INVALID_SOCKET)\r
2320                                 // IPv6対応\r
2321 //                              SetTaskMsg(MSGJPN025);\r
2322                                 SetTaskMsg(MSGJPN025, MSGJPN333);\r
2323                 }\r
2324                 else\r
2325                 {\r
2326 //#pragma aaa\r
2327                         // IPv6対応\r
2328 //                      SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
2329                         SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/, MSGJPN333);\r
2330                         DoClose(sSocket);\r
2331                         sSocket = INVALID_SOCKET;\r
2332                 }\r
2333         }\r
2334         else\r
2335                 // IPv6対応\r
2336 //              SetTaskMsg(MSGJPN027);\r
2337                 SetTaskMsg(MSGJPN027, MSGJPN333);\r
2338 \r
2339         return(sSocket);\r
2340 }\r
2341 \r
2342 \r
2343 SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2344 {\r
2345         struct sockaddr_in6 SocksSockAddr;      /* SOCKSサーバのアドレス情報 */\r
2346         struct sockaddr_in6 CurSockAddr;                /* 接続先ホストのアドレス情報 */\r
2347         struct sockaddr_in6 saSockAddr;\r
2348         char HostEntry[MAXGETHOSTSTRUCT];\r
2349         struct hostent *pHostEntry;\r
2350         SOCKET sSocket;\r
2351         int Len;\r
2352         int Fwall;\r
2353         SOCKS5REQUEST Socks5Cmd;\r
2354         SOCKS5REPLY Socks5Reply;\r
2355 \r
2356         //////////////////////////////\r
2357         // ホスト名解決と接続の準備\r
2358         //////////////////////////////\r
2359 \r
2360         Fwall = FWALL_NONE;\r
2361         if(AskHostFireWall() == YES)\r
2362                 Fwall = FwallType;\r
2363 \r
2364         sSocket = INVALID_SOCKET;\r
2365 \r
2366         UseIPadrs = YES;\r
2367         strcpy(DomainName, host);\r
2368         memset(&CurSockAddr, 0, sizeof(CurSockAddr));\r
2369         CurSockAddr.sin6_port = htons((u_short)port);\r
2370         CurSockAddr.sin6_family = AF_INET6;\r
2371         CurSockAddr.sin6_addr = inet6_addr(host);\r
2372         if(memcmp(&CurSockAddr.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
2373         {\r
2374                 // ホスト名が指定された\r
2375                 // ホスト名からアドレスを求める\r
2376                 if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
2377                    (FwallResolv == YES))\r
2378                 {\r
2379                         // ホスト名解決はSOCKSサーバに任せる\r
2380                         pHostEntry = NULL;\r
2381                 }\r
2382                 else\r
2383                 {\r
2384                         // アドレスを取得\r
2385                         SetTaskMsg(MSGJPN016, DomainName, MSGJPN334);\r
2386                         pHostEntry = do_gethostbynameIPv6(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2387                 }\r
2388 \r
2389                 if(pHostEntry != NULL)\r
2390                 {\r
2391                         memcpy((char *)&CurSockAddr.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2392                         SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet6_ntoa(CurSockAddr.sin6_addr), ntohs(CurSockAddr.sin6_port), MSGJPN334);\r
2393                 }\r
2394                 else\r
2395                 {\r
2396                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2397                         {\r
2398                                 UseIPadrs = NO;\r
2399                                 SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin6_port), MSGJPN334);\r
2400                         }\r
2401                         else\r
2402                         {\r
2403                                 SetTaskMsg(MSGJPN019, host, MSGJPN334);\r
2404                                 return(INVALID_SOCKET);\r
2405                         }\r
2406                 }\r
2407         }\r
2408         else\r
2409                 SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddr.sin6_addr), ntohs(CurSockAddr.sin6_port), MSGJPN334);\r
2410 \r
2411         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2412         {\r
2413                 // SOCKSを使う\r
2414                 // SOCKSに接続する準備\r
2415                 {\r
2416                         Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, (char*)&CurSockAddr.sin6_addr, DomainName, CurSockAddr.sin6_port);\r
2417                 }\r
2418 \r
2419                 memset(&SocksSockAddr, 0, sizeof(SocksSockAddr));\r
2420                 SocksSockAddr.sin6_addr = inet6_addr(FwallHost);\r
2421                 if(memcmp(&SocksSockAddr.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
2422                 {\r
2423                         if((pHostEntry = do_gethostbynameIPv6(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2424                                 memcpy((char *)&SocksSockAddr.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2425                         else\r
2426                         {\r
2427                                 SetTaskMsg(MSGJPN021, FwallHost, MSGJPN334);\r
2428                                 return INVALID_SOCKET;\r
2429                         }\r
2430                 }\r
2431                 SocksSockAddr.sin6_port = htons((u_short)FwallPort);\r
2432                 SocksSockAddr.sin6_family = AF_INET6;\r
2433                 SetTaskMsg(MSGJPN022, inet6_ntoa(SocksSockAddr.sin6_addr), ntohs(SocksSockAddr.sin6_port), MSGJPN334);\r
2434                 // connectで接続する先はSOCKSサーバ\r
2435                 memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr));\r
2436         }\r
2437         else\r
2438         {\r
2439                 // connectで接続するのは接続先のホスト\r
2440                 memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr));\r
2441         }\r
2442 \r
2443         /////////////\r
2444         // 接続実行\r
2445         /////////////\r
2446 \r
2447         if((sSocket = do_socket(AF_INET6, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
2448         {\r
2449                 // ソケットにデータを付与\r
2450                 SetAsyncTableDataIPv6(sSocket, &CurSockAddr, &SocksSockAddr);\r
2451                 if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2452                 {\r
2453                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2454                         {\r
2455                                 if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
2456                                 {\r
2457                                         DoClose(sSocket);\r
2458                                         sSocket = INVALID_SOCKET;\r
2459                                 }\r
2460 \r
2461                                 Socks5Reply.Result = -1;\r
2462                                 // 同時接続対応\r
2463 //                              if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2464 //                                 (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
2465 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2466                                 if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2467                                    (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2468                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2469                                 {\r
2470                                         SetTaskMsg(MSGJPN024, Socks5Reply.Result, MSGJPN334);\r
2471                                         DoClose(sSocket);\r
2472                                         sSocket = INVALID_SOCKET;\r
2473                                 }\r
2474 \r
2475                         }\r
2476 \r
2477                         if(sSocket != INVALID_SOCKET)\r
2478                                 SetTaskMsg(MSGJPN025, MSGJPN334);\r
2479                 }\r
2480                 else\r
2481                 {\r
2482 //#pragma aaa\r
2483                         SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/, MSGJPN334);\r
2484                         DoClose(sSocket);\r
2485                         sSocket = INVALID_SOCKET;\r
2486                 }\r
2487         }\r
2488         else\r
2489                 SetTaskMsg(MSGJPN027, MSGJPN334);\r
2490 \r
2491         return(sSocket);\r
2492 }\r
2493 \r
2494 \r
2495 /*----- リッスンソケットを取得 ------------------------------------------------\r
2496 *\r
2497 *       Parameter\r
2498 *               SOCKET ctrl_skt : コントロールソケット\r
2499 *\r
2500 *       Return Value\r
2501 *               SOCKET リッスンソケット\r
2502 *----------------------------------------------------------------------------*/\r
2503 \r
2504 // IPv6対応\r
2505 SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)\r
2506 {\r
2507         SOCKET Result;\r
2508         Result = INVALID_SOCKET;\r
2509         switch(CurHost.CurNetType)\r
2510         {\r
2511         case NTYPE_IPV4:\r
2512                 Result = GetFTPListenSocketIPv4(ctrl_skt, CancelCheckWork);\r
2513                 break;\r
2514         case NTYPE_IPV6:\r
2515                 Result = GetFTPListenSocketIPv6(ctrl_skt, CancelCheckWork);\r
2516                 break;\r
2517         }\r
2518         return Result;\r
2519 }\r
2520 \r
2521 \r
2522 // IPv6対応\r
2523 //SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)\r
2524 SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork)\r
2525 {\r
2526         // IPv6対応\r
2527         struct sockaddr_in SocksSockAddr;       /* SOCKSサーバのアドレス情報 */\r
2528         struct sockaddr_in CurSockAddr;         /* 接続先ホストのアドレス情報 */\r
2529     SOCKET listen_skt;\r
2530     int iLength;\r
2531     char *a,*p;\r
2532         struct sockaddr_in saCtrlAddr;\r
2533         struct sockaddr_in saTmpAddr;\r
2534         SOCKS4CMD Socks4Cmd;\r
2535         SOCKS4REPLY Socks4Reply;\r
2536         SOCKS5REQUEST Socks5Cmd;\r
2537         SOCKS5REPLY Socks5Reply;\r
2538 \r
2539         int Len;\r
2540         int Fwall;\r
2541 \r
2542         // ソケットにデータを付与\r
2543         GetAsyncTableDataIPv4(ctrl_skt, &CurSockAddr, &SocksSockAddr);\r
2544 \r
2545         Fwall = FWALL_NONE;\r
2546         if(AskHostFireWall() == YES)\r
2547                 Fwall = FwallType;\r
2548 \r
2549         if((listen_skt = do_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)\r
2550         {\r
2551                 if(Fwall == FWALL_SOCKS4)\r
2552                 {\r
2553                         /*===== SOCKS4を使う =====*/\r
2554                         DoPrintf("Use SOCKS4 BIND");\r
2555                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2556                         {\r
2557                                 Socks4Cmd.Ver = SOCKS4_VER;\r
2558                                 Socks4Cmd.Cmd = SOCKS4_CMD_BIND;\r
2559                                 Socks4Cmd.Port = CurSockAddr.sin_port;\r
2560                                 Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
2561                                 strcpy(Socks4Cmd.UserID, FwallUser);\r
2562                                 Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
2563 \r
2564                                 Socks4Reply.Result = -1;\r
2565                                 // 同時接続対応\r
2566 //                              if((SocksSendCmd(listen_skt, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2567 //                                 (Socks4GetCmdReply(listen_skt, &Socks4Reply) != FFFTP_SUCCESS) || \r
2568 //                                 (Socks4Reply.Result != SOCKS4_RES_OK))\r
2569                                 if((SocksSendCmd(listen_skt, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2570                                    (Socks4GetCmdReply(listen_skt, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2571                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
2572                                 {\r
2573                                         // IPv6対応\r
2574 //                                      SetTaskMsg(MSGJPN028, Socks4Reply.Result);\r
2575                                         SetTaskMsg(MSGJPN028, Socks4Reply.Result, MSGJPN333);\r
2576                                         DoClose(listen_skt);\r
2577                                         listen_skt = INVALID_SOCKET;\r
2578                                 }\r
2579 \r
2580                                 if(Socks4Reply.AdrsInt == 0)\r
2581                                         Socks4Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2582 \r
2583                                 a = (char *)&Socks4Reply.AdrsInt;\r
2584                                 p = (char *)&Socks4Reply.Port;\r
2585                         }\r
2586                 }\r
2587                 else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2588                 {\r
2589                         /*===== SOCKS5を使う =====*/\r
2590                         DoPrintf("Use SOCKS5 BIND");\r
2591                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2592                         {\r
2593                                 if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL)\r
2594                                 {\r
2595                                         DoClose(listen_skt);\r
2596                                         listen_skt = INVALID_SOCKET;\r
2597                                         return(listen_skt);\r
2598                                 }\r
2599 \r
2600                                 Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
2601 \r
2602                                 Socks5Reply.Result = -1;\r
2603                                 // 同時接続対応\r
2604 //                              if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2605 //                                 (Socks5GetCmdReply(listen_skt, &Socks5Reply) != FFFTP_SUCCESS) || \r
2606 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2607                                 if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2608                                    (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2609                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2610                                 {\r
2611                                         // IPv6対応\r
2612 //                                      SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
2613                                         SetTaskMsg(MSGJPN029, Socks5Reply.Result, MSGJPN333);\r
2614                                         DoClose(listen_skt);\r
2615                                         listen_skt = INVALID_SOCKET;\r
2616                                 }\r
2617 \r
2618                                 // IPv6対応\r
2619 //                              if(Socks5Reply.AdrsInt == 0)\r
2620 //                                      Socks5Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2621 \r
2622                                 // IPv6対応\r
2623 //                              a = (char *)&Socks5Reply.AdrsInt;\r
2624 //                              p = (char *)&Socks5Reply.Port;\r
2625                                 a = (char *)&Socks5Reply._dummy[0];\r
2626                                 p = (char *)&Socks5Reply._dummy[4];\r
2627                         }\r
2628                 }\r
2629                 else\r
2630                 {\r
2631                         /*===== SOCKSを使わない =====*/\r
2632                         DoPrintf("Use normal BIND");\r
2633                         saCtrlAddr.sin_port = htons(0);\r
2634                         saCtrlAddr.sin_family = AF_INET;\r
2635                         saCtrlAddr.sin_addr.s_addr = 0;\r
2636 \r
2637                         if(bind(listen_skt, (struct sockaddr *)&saCtrlAddr, sizeof(struct sockaddr)) != SOCKET_ERROR)\r
2638                         {\r
2639                                 iLength = sizeof(saCtrlAddr);\r
2640                                 if(getsockname(listen_skt, (struct sockaddr *)&saCtrlAddr, &iLength) != SOCKET_ERROR)\r
2641                                 {\r
2642                                         if(do_listen(listen_skt, 1) == 0)\r
2643                                         {\r
2644                                                 iLength = sizeof(saTmpAddr);\r
2645                                                 if(getsockname(ctrl_skt, (struct sockaddr *)&saTmpAddr, &iLength) == SOCKET_ERROR)\r
2646                                                         ReportWSError("getsockname", WSAGetLastError());\r
2647 \r
2648                                                 a = (char *)&saTmpAddr.sin_addr;\r
2649                                                 p = (char *)&saCtrlAddr.sin_port;\r
2650                                         }\r
2651                                         else\r
2652                                         {\r
2653                                                 ReportWSError("listen", WSAGetLastError());\r
2654                                                 do_closesocket(listen_skt);\r
2655                                                 listen_skt = INVALID_SOCKET;\r
2656                                         }\r
2657                                 }\r
2658                                 else\r
2659                                 {\r
2660                                         ReportWSError("getsockname", WSAGetLastError());\r
2661                                         do_closesocket(listen_skt);\r
2662                                         listen_skt = INVALID_SOCKET;\r
2663                                 }\r
2664                         }\r
2665                         else\r
2666                         {\r
2667                                 ReportWSError("bind", WSAGetLastError());\r
2668                                 do_closesocket(listen_skt);\r
2669                                 listen_skt = INVALID_SOCKET;\r
2670                         }\r
2671 \r
2672                         if(listen_skt == INVALID_SOCKET)\r
2673                                 // IPv6対応\r
2674 //                              SetTaskMsg(MSGJPN030);\r
2675                                 SetTaskMsg(MSGJPN030, MSGJPN333);\r
2676                 }\r
2677         }\r
2678         else\r
2679                 ReportWSError("socket create", WSAGetLastError());\r
2680 \r
2681         if(listen_skt != INVALID_SOCKET)\r
2682         {\r
2683 #define  UC(b)  (((int)b)&0xff)\r
2684                 // 同時接続対応\r
2685 //              if((command(ctrl_skt,NULL, &CancelFlg, "PORT %d,%d,%d,%d,%d,%d",\r
2686 //                              UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2687 //                              UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2688                 if((command(ctrl_skt,NULL, CancelCheckWork, "PORT %d,%d,%d,%d,%d,%d",\r
2689                                 UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2690                                 UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2691                 {\r
2692                         // IPv6対応\r
2693 //                      SetTaskMsg(MSGJPN031);\r
2694                         SetTaskMsg(MSGJPN031, MSGJPN333);\r
2695                         do_closesocket(listen_skt);\r
2696                         listen_skt = INVALID_SOCKET;\r
2697                 }\r
2698 //              else\r
2699 //                      DoPrintf("Skt=%u : listener %s port %u",listen_skt,inet_ntoa(saCtrlAddr.sin_addr),ntohs(saCtrlAddr.sin_port));\r
2700         }\r
2701 \r
2702         return(listen_skt);\r
2703 }\r
2704 \r
2705 \r
2706 SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork)\r
2707 {\r
2708         struct sockaddr_in6 SocksSockAddr;      /* SOCKSサーバのアドレス情報 */\r
2709         struct sockaddr_in6 CurSockAddr;                /* 接続先ホストのアドレス情報 */\r
2710     SOCKET listen_skt;\r
2711     int iLength;\r
2712     char *a,*p;\r
2713         struct sockaddr_in6 saCtrlAddr;\r
2714         struct sockaddr_in6 saTmpAddr;\r
2715         SOCKS5REQUEST Socks5Cmd;\r
2716         SOCKS5REPLY Socks5Reply;\r
2717 \r
2718         int Len;\r
2719         int Fwall;\r
2720 \r
2721         char Adrs[40];\r
2722 \r
2723         // ソケットにデータを付与\r
2724         GetAsyncTableDataIPv6(ctrl_skt, &CurSockAddr, &SocksSockAddr);\r
2725 \r
2726         Fwall = FWALL_NONE;\r
2727         if(AskHostFireWall() == YES)\r
2728                 Fwall = FwallType;\r
2729 \r
2730         if((listen_skt = do_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)\r
2731         {\r
2732                 if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2733                 {\r
2734                         /*===== SOCKS5を使う =====*/\r
2735                         DoPrintf("Use SOCKS5 BIND");\r
2736                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2737                         {\r
2738                                 if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL)\r
2739                                 {\r
2740                                         DoClose(listen_skt);\r
2741                                         listen_skt = INVALID_SOCKET;\r
2742                                         return(listen_skt);\r
2743                                 }\r
2744 \r
2745                                 Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, (char*)&CurSockAddr.sin6_addr, DomainName, CurSockAddr.sin6_port);\r
2746 \r
2747                                 Socks5Reply.Result = -1;\r
2748                                 // 同時接続対応\r
2749 //                              if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2750 //                                 (Socks5GetCmdReply(listen_skt, &Socks5Reply) != FFFTP_SUCCESS) || \r
2751 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2752                                 if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2753                                    (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2754                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2755                                 {\r
2756                                         SetTaskMsg(MSGJPN029, Socks5Reply.Result, MSGJPN334);\r
2757                                         DoClose(listen_skt);\r
2758                                         listen_skt = INVALID_SOCKET;\r
2759                                 }\r
2760 \r
2761                                 // IPv6対応\r
2762 //                              if(Socks5Reply.AdrsInt == 0)\r
2763 //                                      Socks5Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2764 \r
2765                                 // IPv6対応\r
2766 //                              a = (char *)&Socks5Reply.AdrsInt;\r
2767 //                              p = (char *)&Socks5Reply.Port;\r
2768                                 a = (char *)&Socks5Reply._dummy[0];\r
2769                                 p = (char *)&Socks5Reply._dummy[16];\r
2770                         }\r
2771                 }\r
2772                 else\r
2773                 {\r
2774                         /*===== SOCKSを使わない =====*/\r
2775                         DoPrintf("Use normal BIND");\r
2776                         saCtrlAddr.sin6_port = htons(0);\r
2777                         saCtrlAddr.sin6_family = AF_INET6;\r
2778                         memset(&saCtrlAddr.sin6_addr, 0, 16);\r
2779 \r
2780                         if(bind(listen_skt, (struct sockaddr *)&saCtrlAddr, sizeof(struct sockaddr_in6)) != SOCKET_ERROR)\r
2781                         {\r
2782                                 iLength = sizeof(saCtrlAddr);\r
2783                                 if(getsockname(listen_skt, (struct sockaddr *)&saCtrlAddr, &iLength) != SOCKET_ERROR)\r
2784                                 {\r
2785                                         if(do_listen(listen_skt, 1) == 0)\r
2786                                         {\r
2787                                                 iLength = sizeof(saTmpAddr);\r
2788                                                 if(getsockname(ctrl_skt, (struct sockaddr *)&saTmpAddr, &iLength) == SOCKET_ERROR)\r
2789                                                         ReportWSError("getsockname", WSAGetLastError());\r
2790 \r
2791                                                 a = (char *)&saTmpAddr.sin6_addr;\r
2792                                                 p = (char *)&saCtrlAddr.sin6_port;\r
2793                                         }\r
2794                                         else\r
2795                                         {\r
2796                                                 ReportWSError("listen", WSAGetLastError());\r
2797                                                 do_closesocket(listen_skt);\r
2798                                                 listen_skt = INVALID_SOCKET;\r
2799                                         }\r
2800                                 }\r
2801                                 else\r
2802                                 {\r
2803                                         ReportWSError("getsockname", WSAGetLastError());\r
2804                                         do_closesocket(listen_skt);\r
2805                                         listen_skt = INVALID_SOCKET;\r
2806                                 }\r
2807                         }\r
2808                         else\r
2809                         {\r
2810                                 ReportWSError("bind", WSAGetLastError());\r
2811                                 do_closesocket(listen_skt);\r
2812                                 listen_skt = INVALID_SOCKET;\r
2813                         }\r
2814 \r
2815                         if(listen_skt == INVALID_SOCKET)\r
2816                                 SetTaskMsg(MSGJPN030, MSGJPN334);\r
2817                 }\r
2818         }\r
2819         else\r
2820                 ReportWSError("socket create", WSAGetLastError());\r
2821 \r
2822         if(listen_skt != INVALID_SOCKET)\r
2823         {\r
2824 #define  UC(b)  (((int)b)&0xff)\r
2825                 // 同時接続対応\r
2826 //              if((command(ctrl_skt,NULL, &CancelFlg, "PORT %d,%d,%d,%d,%d,%d",\r
2827 //                              UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2828 //                              UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2829                 if((command(ctrl_skt,NULL, CancelCheckWork, "EPRT |2|%s|%d|",\r
2830                                 AddressToStringIPv6(Adrs, a),\r
2831                                 (UC(p[0]) << 8) | UC(p[1])) / 100) != FTP_COMPLETE)\r
2832                 {\r
2833                         SetTaskMsg(MSGJPN031, MSGJPN334);\r
2834                         do_closesocket(listen_skt);\r
2835                         listen_skt = INVALID_SOCKET;\r
2836                 }\r
2837 //              else\r
2838 //                      DoPrintf("Skt=%u : listener %s port %u",listen_skt,inet_ntoa(saCtrlAddr.sin_addr),ntohs(saCtrlAddr.sin_port));\r
2839         }\r
2840 \r
2841         return(listen_skt);\r
2842 }\r
2843 \r
2844 \r
2845 /*----- ホストへ接続処理中かどうかを返す---------------------------------------\r
2846 *\r
2847 *       Parameter\r
2848 *               なし\r
2849 *\r
2850 *       Return Value\r
2851 *               int ステータス\r
2852 *                       YES/NO\r
2853 *----------------------------------------------------------------------------*/\r
2854 \r
2855 int AskTryingConnect(void)\r
2856 {\r
2857         return(TryConnect);\r
2858 }\r
2859 \r
2860 \r
2861 #if 0\r
2862 ///*----- ブロッキングコールのフックコールバック --------------------------------\r
2863 //*\r
2864 //*     Parameter\r
2865 //*             なし\r
2866 //*\r
2867 //*     Return Value\r
2868 //*             BOOL FALSE\r
2869 //*----------------------------------------------------------------------------*/\r
2870 //\r
2871 //static BOOL CALLBACK BlkHookFnc(void)\r
2872 //{\r
2873 //      BackgrndMessageProc();\r
2874 //\r
2875 //      if(CancelFlg == YES)\r
2876 //      {\r
2877 //              SetTaskMsg(MSGJPN032);\r
2878 //              WSACancelBlockingCall();\r
2879 //              CancelFlg = NO;\r
2880 //      }\r
2881 //      return(FALSE);\r
2882 //}\r
2883 #endif\r
2884 \r
2885 \r
2886 \r
2887 /*----- SOCKS5のコマンドパケットを作成する ------------------------------------\r
2888 *\r
2889 *       Parameter\r
2890 *               SOCKS5REQUEST *Packet : パケットを作成するワーク\r
2891 *               char Cmd : コマンド\r
2892 *               int ValidIP : IPアドレスを使うかどうか(YES/NO)\r
2893 *               ulong IP : IPアドレス\r
2894 *               char *Host : ホスト名\r
2895 *               ushort Port : ポート\r
2896 *\r
2897 *       Return Value\r
2898 *               int コマンドパケットの長さ\r
2899 *----------------------------------------------------------------------------*/\r
2900 \r
2901 static int Socks5MakeCmdPacket(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, ulong IP, char *Host, ushort Port)\r
2902 {\r
2903         uchar *Pos;\r
2904         int Len;\r
2905         int TotalLen;\r
2906 \r
2907         Pos = (uchar *)Packet;\r
2908         Pos += SOCKS5REQUEST_SIZE;\r
2909         TotalLen = SOCKS5REQUEST_SIZE + 2;      /* +2はポートの分 */\r
2910 \r
2911         Packet->Ver = SOCKS5_VER;\r
2912         Packet->Cmd = Cmd;\r
2913         Packet->Rsv = 0;\r
2914         if(ValidIP == YES)\r
2915         {\r
2916                 /* IPアドレスを指定 */\r
2917                 Packet->Type = SOCKS5_ADRS_IPV4;\r
2918                 *((ulong *)Pos) = IP;\r
2919                 Pos += 4;\r
2920                 TotalLen += 4;\r
2921         }\r
2922         else\r
2923         {\r
2924                 /* ホスト名を指定 */\r
2925                 Packet->Type = SOCKS5_ADRS_NAME;\r
2926                 Len = strlen(Host);\r
2927                 *Pos++ = Len;\r
2928                 strcpy(Pos, Host);\r
2929                 Pos += Len;\r
2930                 TotalLen += Len + 1;\r
2931         }\r
2932         *((ushort *)Pos) = Port;\r
2933 \r
2934         return(TotalLen);\r
2935 }\r
2936 \r
2937 \r
2938 // IPv6対応\r
2939 static int Socks5MakeCmdPacketIPv6(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, char *IP, char *Host, ushort Port)\r
2940 {\r
2941         uchar *Pos;\r
2942         int Len;\r
2943         int TotalLen;\r
2944 \r
2945         Pos = (uchar *)Packet;\r
2946         Pos += SOCKS5REQUEST_SIZE;\r
2947         TotalLen = SOCKS5REQUEST_SIZE + 2;      /* +2はポートの分 */\r
2948 \r
2949         Packet->Ver = SOCKS5_VER;\r
2950         Packet->Cmd = Cmd;\r
2951         Packet->Rsv = 0;\r
2952         if(ValidIP == YES)\r
2953         {\r
2954                 /* IPアドレスを指定 */\r
2955                 Packet->Type = SOCKS5_ADRS_IPV6;\r
2956                 memcpy(Pos, IP, 16);\r
2957                 Pos += 16;\r
2958                 TotalLen += 16;\r
2959         }\r
2960         else\r
2961         {\r
2962                 /* ホスト名を指定 */\r
2963                 Packet->Type = SOCKS5_ADRS_NAME;\r
2964                 Len = strlen(Host);\r
2965                 *Pos++ = Len;\r
2966                 strcpy(Pos, Host);\r
2967                 Pos += Len;\r
2968                 TotalLen += Len + 1;\r
2969         }\r
2970         *((ushort *)Pos) = Port;\r
2971 \r
2972         return(TotalLen);\r
2973 }\r
2974 \r
2975 \r
2976 /*----- SOCKSのコマンドを送る -------------------------------------------------\r
2977 *\r
2978 *       Parameter\r
2979 *               SOCKET Socket : ソケット\r
2980 *               void *Data : 送るデータ\r
2981 *               int Size : サイズ\r
2982 *\r
2983 *       Return Value\r
2984 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2985 *----------------------------------------------------------------------------*/\r
2986 \r
2987 static int SocksSendCmd(SOCKET Socket, void *Data, int Size, int *CancelCheckWork)\r
2988 {\r
2989         int Ret;\r
2990 \r
2991         Ret = SendData(Socket, (char *)Data, Size, 0, CancelCheckWork);\r
2992 \r
2993         if(Ret != FFFTP_SUCCESS)\r
2994                 SetTaskMsg(MSGJPN033, *((short *)Data));\r
2995 \r
2996         return(Ret);\r
2997 }\r
2998 \r
2999 \r
3000 /*----- SOCKS5のコマンドに対するリプライパケットを受信する --------------------\r
3001 *\r
3002 *       Parameter\r
3003 *               SOCKET Socket : ソケット\r
3004 *               SOCKS5REPLY *Packet : パケット\r
3005 *\r
3006 *       Return Value\r
3007 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
3008 *----------------------------------------------------------------------------*/\r
3009 \r
3010 // 同時接続対応\r
3011 //static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet)\r
3012 static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet, int *CancelCheckWork)\r
3013 {\r
3014         uchar *Pos;\r
3015         int Len;\r
3016         int Ret;\r
3017 \r
3018         Pos = (uchar *)Packet;\r
3019         Pos += SOCKS5REPLY_SIZE;\r
3020 \r
3021         // 同時接続対応\r
3022 //      if((Ret = ReadNchar(Socket, (char *)Packet, SOCKS5REPLY_SIZE, &CancelFlg)) == FFFTP_SUCCESS)\r
3023         if((Ret = ReadNchar(Socket, (char *)Packet, SOCKS5REPLY_SIZE, CancelCheckWork)) == FFFTP_SUCCESS)\r
3024         {\r
3025                 if(Packet->Type == SOCKS5_ADRS_IPV4)\r
3026                         Len = 4 + 2;\r
3027                 else if(Packet->Type == SOCKS5_ADRS_IPV6)\r
3028                         Len = 16 + 2;\r
3029                 else\r
3030                 {\r
3031                         // 同時接続対応\r
3032 //                      if((Ret = ReadNchar(Socket, (char *)Pos, 1, &CancelFlg)) == FFFTP_SUCCESS)\r
3033                         if((Ret = ReadNchar(Socket, (char *)Pos, 1, CancelCheckWork)) == FFFTP_SUCCESS)\r
3034                         {\r
3035                                 Len = *Pos + 2;\r
3036                                 Pos++;\r
3037                         }\r
3038                 }\r
3039 \r
3040                 if(Ret == FFFTP_SUCCESS)\r
3041                         // 同時接続対応\r
3042 //                      Ret = ReadNchar(Socket, (char *)Pos, Len, &CancelFlg);\r
3043                         Ret = ReadNchar(Socket, (char *)Pos, Len, CancelCheckWork);\r
3044         }\r
3045 \r
3046         if(Ret != FFFTP_SUCCESS)\r
3047                 SetTaskMsg(MSGJPN034);\r
3048 \r
3049         return(Ret);\r
3050 }\r
3051 \r
3052 \r
3053 /*----- SOCKS4のコマンドに対するリプライパケットを受信する --------------------\r
3054 *\r
3055 *       Parameter\r
3056 *               SOCKET Socket : ソケット\r
3057 *               SOCKS5REPLY *Packet : パケット\r
3058 *\r
3059 *       Return Value\r
3060 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
3061 *----------------------------------------------------------------------------*/\r
3062 \r
3063 // 同時接続対応\r
3064 //static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet)\r
3065 static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet, int *CancelCheckWork)\r
3066 {\r
3067         int Ret;\r
3068 \r
3069         // 同時接続対応\r
3070 //      Ret = ReadNchar(Socket, (char *)Packet, SOCKS4REPLY_SIZE, &CancelFlg);\r
3071         Ret = ReadNchar(Socket, (char *)Packet, SOCKS4REPLY_SIZE, CancelCheckWork);\r
3072 \r
3073         if(Ret != FFFTP_SUCCESS)\r
3074                 DoPrintf(MSGJPN035);\r
3075 \r
3076         return(Ret);\r
3077 }\r
3078 \r
3079 \r
3080 /*----- SOCKS5の認証を行う ----------------------------------------------------\r
3081 *\r
3082 *       Parameter\r
3083 *               SOCKET Socket : ソケット\r
3084 *\r
3085 *       Return Value\r
3086 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
3087 *----------------------------------------------------------------------------*/\r
3088 \r
3089 static int Socks5SelMethod(SOCKET Socket, int *CancelCheckWork)\r
3090 {\r
3091         int Ret;\r
3092         SOCKS5METHODREQUEST Socks5Method;\r
3093         SOCKS5METHODREPLY Socks5MethodReply;\r
3094         SOCKS5USERPASSSTATUS Socks5Status;\r
3095         char Buf[USER_NAME_LEN + PASSWORD_LEN + 4];\r
3096         int Len;\r
3097         int Len2;\r
3098 \r
3099         Ret = FFFTP_SUCCESS;\r
3100         Socks5Method.Ver = SOCKS5_VER;\r
3101         Socks5Method.Num = 1;\r
3102         if(FwallType == FWALL_SOCKS5_NOAUTH)\r
3103                 Socks5Method.Methods[0] = SOCKS5_AUTH_NONE;\r
3104         else\r
3105                 Socks5Method.Methods[0] = SOCKS5_AUTH_USER;\r
3106 \r
3107         // 同時接続対応\r
3108 //      if((SocksSendCmd(Socket, &Socks5Method, SOCKS5METHODREQUEST_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3109 //         (ReadNchar(Socket, (char *)&Socks5MethodReply, SOCKS5METHODREPLY_SIZE, &CancelFlg) != FFFTP_SUCCESS) ||\r
3110 //         (Socks5MethodReply.Method == (uchar)0xFF))\r
3111         if((SocksSendCmd(Socket, &Socks5Method, SOCKS5METHODREQUEST_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3112            (ReadNchar(Socket, (char *)&Socks5MethodReply, SOCKS5METHODREPLY_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3113            (Socks5MethodReply.Method == (uchar)0xFF))\r
3114         {\r
3115                 SetTaskMsg(MSGJPN036);\r
3116                 Ret = FFFTP_FAIL;\r
3117         }\r
3118         else if(Socks5MethodReply.Method == SOCKS5_AUTH_USER)\r
3119         {\r
3120                 DoPrintf("SOCKS5 User/Pass Authentication");\r
3121                 Buf[0] = SOCKS5_USERAUTH_VER;\r
3122                 Len = strlen(FwallUser);\r
3123                 Len2 = strlen(FwallPass);\r
3124                 Buf[1] = Len;\r
3125                 strcpy(Buf+2, FwallUser);\r
3126                 Buf[2 + Len] = Len2;\r
3127                 strcpy(Buf+3+Len, FwallPass);\r
3128 \r
3129                 // 同時接続対応\r
3130 //              if((SocksSendCmd(Socket, &Buf, Len+Len2+3, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3131 //                 (ReadNchar(Socket, (char *)&Socks5Status, SOCKS5USERPASSSTATUS_SIZE, &CancelFlg) != FFFTP_SUCCESS) ||\r
3132 //                 (Socks5Status.Status != 0))\r
3133                 if((SocksSendCmd(Socket, &Buf, Len+Len2+3, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3134                    (ReadNchar(Socket, (char *)&Socks5Status, SOCKS5USERPASSSTATUS_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3135                    (Socks5Status.Status != 0))\r
3136                 {\r
3137                         SetTaskMsg(MSGJPN037);\r
3138                         Ret = FFFTP_FAIL;\r
3139                 }\r
3140         }\r
3141         else\r
3142                 DoPrintf("SOCKS5 No Authentication");\r
3143 \r
3144         return(Ret);\r
3145 }\r
3146 \r
3147 \r
3148 /*----- SOCKSのBINDの第2リプライメッセージを受け取る -------------------------\r
3149 *\r
3150 *       Parameter\r
3151 *               SOCKET Socket : ソケット\r
3152 *               SOCKET *Data : データソケットを返すワーク\r
3153 *\r
3154 *       Return Value\r
3155 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
3156 *----------------------------------------------------------------------------*/\r
3157 \r
3158 // 同時接続対応\r
3159 //int SocksGet2ndBindReply(SOCKET Socket, SOCKET *Data)\r
3160 int SocksGet2ndBindReply(SOCKET Socket, SOCKET *Data, int *CancelCheckWork)\r
3161 {\r
3162         int Ret;\r
3163         char Buf[300];\r
3164 \r
3165         Ret = FFFTP_FAIL;\r
3166         if((AskHostFireWall() == YES) && (FwallType == FWALL_SOCKS4))\r
3167         {\r
3168                 // 同時接続対応\r
3169 //              Socks4GetCmdReply(Socket, (SOCKS4REPLY *)Buf);\r
3170                 Socks4GetCmdReply(Socket, (SOCKS4REPLY *)Buf, CancelCheckWork);\r
3171                 *Data = Socket;\r
3172                 Ret = FFFTP_SUCCESS;\r
3173         }\r
3174         else if((AskHostFireWall() == YES) &&\r
3175                         ((FwallType == FWALL_SOCKS5_NOAUTH) || (FwallType == FWALL_SOCKS5_USER)))\r
3176         {\r
3177                 // 同時接続対応\r
3178 //              Socks5GetCmdReply(Socket, (SOCKS5REPLY *)Buf);\r
3179                 Socks5GetCmdReply(Socket, (SOCKS5REPLY *)Buf, CancelCheckWork);\r
3180                 *Data = Socket;\r
3181                 Ret = FFFTP_SUCCESS;\r
3182         }\r
3183         return(Ret);\r
3184 }\r
3185 \r
3186 \r
3187 \r
3188 // 暗号化通信対応\r
3189 int AskCryptMode(void)\r
3190 {\r
3191         return(CurHost.CryptMode);\r
3192 }\r
3193 \r
3194 int AskUseNoEncryption(void)\r
3195 {\r
3196         return(CurHost.UseNoEncryption);\r
3197 }\r
3198 \r
3199 int AskUseFTPES(void)\r
3200 {\r
3201         return(CurHost.UseFTPES);\r
3202 }\r
3203 \r
3204 int AskUseFTPIS(void)\r
3205 {\r
3206         return(CurHost.UseFTPIS);\r
3207 }\r
3208 \r
3209 int AskUseSFTP(void)\r
3210 {\r