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                                         KeepAlive.onoff = 1;\r
1521                                         KeepAlive.keepalivetime = TimeOut * 1000;\r
1522                                         KeepAlive.keepaliveinterval = 1000;\r
1523                                         if(WSAIoctl(ContSock, SIO_KEEPALIVE_VALS, &KeepAlive, sizeof(struct tcp_keepalive), NULL, 0, &dwTmp, NULL, NULL) == SOCKET_ERROR)\r
1524                                                 ReportWSError("WSAIoctl", WSAGetLastError());\r
1525                                         LingerOpt.l_onoff = 1;\r
1526                                         LingerOpt.l_linger = 90;\r
1527                                         if(setsockopt(ContSock, SOL_SOCKET, SO_LINGER, (LPSTR)&LingerOpt, sizeof(LingerOpt)) == SOCKET_ERROR)\r
1528                                                 ReportWSError("setsockopt", WSAGetLastError());\r
1529 ///////\r
1530 \r
1531 \r
1532                                         /*===== 認証を行なう =====*/\r
1533 \r
1534                                         Sts = FTP_COMPLETE;\r
1535                                         if((Fwall == FWALL_FU_FP_SITE) ||\r
1536                                            (Fwall == FWALL_FU_FP_USER) ||\r
1537                                            (Fwall == FWALL_FU_FP))\r
1538                                         {\r
1539                                                 // 同時接続対応\r
1540 //                                              if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
1541                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "USER %s", FwallUser) / 100) == FTP_CONTINUE)\r
1542                                                 {\r
1543                                                         CheckOneTimePassword(FwallPass, Reply, FwallSecurity);\r
1544                                                         // 同時接続対応\r
1545 //                                                      Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1546                                                         Sts = command(ContSock, NULL, CancelCheckWork, "PASS %s", Reply) / 100;\r
1547                                                 }\r
1548                                         }\r
1549                                         else if(Fwall == FWALL_SIDEWINDER)\r
1550                                         {\r
1551                                                 // 同時接続対応\r
1552 //                                              Sts = command(ContSock, Reply, &CancelFlg, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
1553                                                 Sts = command(ContSock, Reply, CancelCheckWork, "USER %s:%s%c%s", FwallUser, FwallPass, FwallDelimiter, Host) / 100;\r
1554                                         }\r
1555                                         if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1556                                         {\r
1557                                                 SetTaskMsg(MSGJPN006);\r
1558                                                 DoClose(ContSock);\r
1559                                                 ContSock = INVALID_SOCKET;\r
1560                                         }\r
1561                                         else\r
1562                                         {\r
1563                                                 if((Fwall == FWALL_FU_FP_SITE) || (Fwall == FWALL_OPEN))\r
1564                                                 {\r
1565                                                         Flg = 0;\r
1566                                                         if(Fwall == FWALL_OPEN)\r
1567                                                                 Flg = 2;\r
1568                                                         if(FwallLower == YES)\r
1569                                                                 Flg++;\r
1570 \r
1571                                                         if(HostPort == PORT_NOR)\r
1572                                                                 // 同時接続対応\r
1573 //                                                              Sts = command(ContSock, NULL, &CancelFlg, "%s %s", SiteTbl[Flg], Host) / 100;\r
1574                                                                 Sts = command(ContSock, NULL, CancelCheckWork, "%s %s", SiteTbl[Flg], Host) / 100;\r
1575                                                         else\r
1576                                                                 // 同時接続対応\r
1577 //                                                              Sts = command(ContSock, NULL, &CancelFlg, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
1578                                                                 Sts = command(ContSock, NULL, CancelCheckWork, "%s %s %d", SiteTbl[Flg], Host, HostPort) / 100;\r
1579                                                 }\r
1580 \r
1581                                                 if((Sts != FTP_COMPLETE) && (Sts != FTP_CONTINUE))\r
1582                                                 {\r
1583                                                         SetTaskMsg(MSGJPN007, Host);\r
1584                                                         DoClose(ContSock);\r
1585                                                         ContSock = INVALID_SOCKET;\r
1586                                                 }\r
1587                                                 else\r
1588                                                 {\r
1589                                                         Anony = NO;\r
1590                                                         // 同時接続対応\r
1591 //                                                      if((strlen(User) != 0) || \r
1592 //                                                         (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1593                                                         if((strlen(User) != 0) || \r
1594                                                            ((HostData->NoDisplayUI == NO) && (InputDialogBox(username_dlg, GetMainHwnd(), NULL, User, USER_NAME_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1595                                                         {\r
1596                                                                 if(Anony == YES)\r
1597                                                                 {\r
1598                                                                         strcpy(User, "anonymous");\r
1599                                                                         strcpy(Pass, UserMailAdrs);\r
1600                                                                 }\r
1601 \r
1602                                                                 if((Fwall == FWALL_FU_FP_USER) || (Fwall == FWALL_USER))\r
1603                                                                 {\r
1604                                                                         if(HostPort == PORT_NOR)\r
1605                                                                                 sprintf(Buf, "%s%c%s", User, FwallDelimiter, Host);\r
1606                                                                         else\r
1607                                                                                 sprintf(Buf, "%s%c%s %d", User, FwallDelimiter, Host, HostPort);\r
1608                                                                 }\r
1609                                                                 else\r
1610                                                                         strcpy(Buf, User);\r
1611 \r
1612                                                                 // FTPES対応\r
1613                                                                 if(CryptMode == CRYPT_FTPES)\r
1614                                                                 {\r
1615                                                                         if(IsOpenSSLLoaded() && (Sts = command(ContSock, Reply, CancelCheckWork, "AUTH TLS")) == 234)\r
1616                                                                         {\r
1617                                                                                 if(AttachSSL(ContSock, INVALID_SOCKET, CancelCheckWork))\r
1618                                                                                 {\r
1619                                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "PBSZ 0")) == 200)\r
1620                                                                                         {\r
1621                                                                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "PROT P")) == 200)\r
1622                                                                                                 {\r
1623                                                                                                 }\r
1624                                                                                                 else\r
1625                                                                                                         Sts = FTP_ERROR;\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 \r
1637                                                                 // FTPIS対応\r
1638                                                                 // "PBSZ 0"と"PROT P"は黙示的に設定されているはずだが念のため\r
1639                                                                 if(CryptMode == CRYPT_FTPIS)\r
1640                                                                 {\r
1641                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "PBSZ 0")) == 200)\r
1642                                                                         {\r
1643                                                                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "PROT P")) == 200)\r
1644                                                                                 {\r
1645                                                                                 }\r
1646                                                                         }\r
1647                                                                 }\r
1648 \r
1649                                                                 ReInPass = NO;\r
1650                                                                 do\r
1651                                                                 {\r
1652                                                                         // FTPES対応\r
1653                                                                         if(Sts == FTP_ERROR)\r
1654                                                                                 break;\r
1655                                                                         Continue = NO;\r
1656                                                                         // 同時接続対応\r
1657 //                                                                      if((Sts = command(ContSock, Reply, &CancelFlg, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
1658                                                                         if((Sts = command(ContSock, Reply, CancelCheckWork, "USER %s", Buf) / 100) == FTP_CONTINUE)\r
1659                                                                         {\r
1660                                                                                 // 同時接続対応\r
1661 //                                                                              if((strlen(Pass) != 0) || \r
1662 //                                                                                 (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1663                                                                                 if((strlen(Pass) != 0) || \r
1664                                                                                    ((HostData->NoDisplayUI == NO) && (InputDialogBox(passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1665                                                                                 {\r
1666                                                                                         CheckOneTimePassword(Pass, Reply, Security);\r
1667 \r
1668                                                                                         /* パスワードがスペース1個の時はパスワードの実体なしとする */\r
1669                                                                                         if(strcmp(Reply, " ") == 0)\r
1670                                                                                                 strcpy(Reply, "");\r
1671 \r
1672                                                                                         // 同時接続対応\r
1673 //                                                                                      Sts = command(ContSock, NULL, &CancelFlg, "PASS %s", Reply) / 100;\r
1674                                                                                         Sts = command(ContSock, NULL, CancelCheckWork, "PASS %s", Reply) / 100;\r
1675                                                                                         if(Sts == FTP_ERROR)\r
1676                                                                                         {\r
1677                                                                                                 strcpy(Pass, "");\r
1678                                                                                                 // 同時接続対応\r
1679 //                                                                                              if(InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
1680                                                                                                 if(HostData->NoDisplayUI == NO && InputDialogBox(re_passwd_dlg, GetMainHwnd(), NULL, Pass, PASSWORD_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)\r
1681                                                                                                         Continue = YES;\r
1682                                                                                                 else\r
1683                                                                                                         DoPrintf("No password specified.");\r
1684                                                                                                 ReInPass = YES;\r
1685                                                                                         }\r
1686                                                                                         else if(Sts == FTP_CONTINUE)\r
1687                                                                                         {\r
1688                                                                                                 // 同時接続対応\r
1689 //                                                                                              if((strlen(Acct) != 0) || \r
1690 //                                                                                                 (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES))\r
1691                                                                                                 if((strlen(Acct) != 0) || \r
1692                                                                                                    ((HostData->NoDisplayUI == NO) && (InputDialogBox(account_dlg, GetMainHwnd(), NULL, Acct, ACCOUNT_LEN+1, &Anony, IDH_HELP_TOPIC_0000001) == YES)))\r
1693                                                                                                 {\r
1694                                                                                                         // 同時接続対応\r
1695 //                                                                                                      Sts = command(ContSock, NULL, &CancelFlg, "ACCT %s", Acct) / 100;\r
1696                                                                                                         Sts = command(ContSock, NULL, CancelCheckWork, "ACCT %s", Acct) / 100;\r
1697                                                                                                 }\r
1698                                                                                                 else\r
1699                                                                                                         DoPrintf("No account specified");\r
1700                                                                                         }\r
1701                                                                                 }\r
1702                                                                                 else\r
1703                                                                                 {\r
1704                                                                                         Sts = FTP_ERROR;\r
1705                                                                                         DoPrintf("No password specified.");\r
1706                                                                                 }\r
1707                                                                         }\r
1708                                                                         // FTPES対応\r
1709                                                                         if(Continue == YES)\r
1710                                                                                 Sts = FTP_COMPLETE;\r
1711                                                                 }\r
1712                                                                 while(Continue == YES);\r
1713                                                         }\r
1714                                                         else\r
1715                                                         {\r
1716                                                                 Sts = FTP_ERROR;\r
1717                                                                 DoPrintf("No user name specified");\r
1718                                                         }\r
1719 \r
1720                                                         if(Sts != FTP_COMPLETE)\r
1721                                                         {\r
1722                                                                 SetTaskMsg(MSGJPN008, Host);\r
1723                                                                 DoClose(ContSock);\r
1724                                                                 ContSock = INVALID_SOCKET;\r
1725                                                         }\r
1726                                                         else if((SavePass == YES) && (ReInPass == YES))\r
1727                                                         {\r
1728                                                                 // 同時接続対応\r
1729 //                                                              if(DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
1730                                                                 if(HostData->NoDisplayUI == NO && DialogBox(GetFtpInst(), MAKEINTRESOURCE(savepass_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
1731                                                                         SetHostPassword(AskCurrentHost(), Pass);\r
1732                                                         }\r
1733                                                 }\r
1734                                         }\r
1735                                 }\r
1736                                 else\r
1737                                 {\r
1738 //#pragma aaa\r
1739                                         SetTaskMsg(MSGJPN009/*"接続できません(1) %x", ContSock*/);\r
1740                                         DoClose(ContSock);\r
1741                                         ContSock = INVALID_SOCKET;\r
1742                                 }\r
1743                         }\r
1744                 }\r
1745                 else\r
1746                 {\r
1747 \r
1748                         if(((Fwall >= FWALL_FU_FP_SITE) && (Fwall <= FWALL_OPEN)) ||\r
1749                            (Fwall == FWALL_FU_FP))\r
1750                                 SetTaskMsg(MSGJPN010);\r
1751                         else\r
1752                                 SetTaskMsg(MSGJPN011);\r
1753                 }\r
1754 \r
1755 #if 0\r
1756 //              WSAUnhookBlockingHook();\r
1757 #endif\r
1758                 TryConnect = NO;\r
1759 \r
1760                 // FEAT対応\r
1761                 // ホストの機能を確認\r
1762                 if(ContSock != INVALID_SOCKET)\r
1763                 {\r
1764                         if((Sts = command(ContSock, Reply, CancelCheckWork, "FEAT")) == 211)\r
1765                         {\r
1766                                 // 改行文字はReadReplyMessageで消去されるため区切り文字に空白を使用\r
1767                                 // UTF-8対応\r
1768                                 if(strstr(Reply, " UTF8 "))\r
1769                                         HostData->Feature |= FEATURE_UTF8;\r
1770                                 // MLST対応\r
1771                                 if(strstr(Reply, " MLST ") || strstr(Reply, " MLSD "))\r
1772                                         HostData->Feature |= FEATURE_MLSD;\r
1773                                 // IPv6対応\r
1774                                 if(strstr(Reply, " EPRT ") || strstr(Reply, " EPSV "))\r
1775                                         HostData->Feature |= FEATURE_EPRT | FEATURE_EPSV;\r
1776                         }\r
1777                         // UTF-8対応\r
1778                         if(HostData->CurNameKanjiCode == KANJI_AUTO && (HostData->Feature & FEATURE_UTF8))\r
1779                         {\r
1780                                 if((Sts = command(ContSock, Reply, CancelCheckWork, "OPTS UTF8 ON")) == 200)\r
1781                                         HostData->CurNameKanjiCode = KANJI_UTF8N;\r
1782                         }\r
1783                 }\r
1784         }\r
1785         else if(CryptMode == CRYPT_SFTP)\r
1786         {\r
1787                 // TODO:\r
1788                 // テストコード\r
1789                 // ログイン成功を確認\r
1790 #define strrcmp(_Str1, _Str2) (strcmp(strstr(_Str1, _Str2) ? strstr(_Str1, _Str2) : "", _Str2))\r
1791                 size_t r;\r
1792                 ContSock = SFTP_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);\r
1793                 SFTP_SetTimeoutCallback(ContSock, SSLTimeoutCallback);\r
1794                 while(1)\r
1795                 {\r
1796                         r = SFTP_recv(ContSock, Reply, 1024, 0);\r
1797                         if(r == SOCKET_ERROR)\r
1798                                 break;\r
1799                         if(r <= 0)\r
1800                                 continue;\r
1801                         Reply[r] = '\0';\r
1802                         SetTaskMsg("%s", Reply);\r
1803                         if(strrcmp(Reply, "psftp> ") == 0)\r
1804                                 break;\r
1805                 }\r
1806                 r = SFTP_send(ContSock, "open \"", strlen("open \""), 0);\r
1807                 r = SFTP_send(ContSock, Host, strlen(Host), 0);\r
1808                 r = SFTP_send(ContSock, "\"\r\n", strlen("\"\r\n"), 0);\r
1809                 while(1)\r
1810                 {\r
1811                         r = SFTP_recv(ContSock, Reply, 1024, 0);\r
1812                         if(r == SOCKET_ERROR)\r
1813                                 break;\r
1814                         if(r <= 0)\r
1815                                 continue;\r
1816                         Reply[r] = '\0';\r
1817                         SetTaskMsg("%s", Reply);\r
1818                         if(strrcmp(Reply, "Store key in cache? (y/n) ") == 0)\r
1819                         {\r
1820                                 r = SFTP_send(ContSock, "n\r\n", strlen("n\r\n"), 0);\r
1821                         }\r
1822                         if(strrcmp(Reply, "Update cached key? (y/n, Return cancels connection) ") == 0)\r
1823                         {\r
1824                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1825                         }\r
1826                         if(strrcmp(Reply, "login as: ") == 0)\r
1827                         {\r
1828                                 r = SFTP_send(ContSock, User, strlen(User), 0);\r
1829                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1830                         }\r
1831                         if(strrcmp(Reply, "password: ") == 0)\r
1832                         {\r
1833                                 r = SFTP_send(ContSock, Pass, strlen(Pass), 0);\r
1834                                 r = SFTP_send(ContSock, "\r\n", strlen("\r\n"), 0);\r
1835                         }\r
1836                         if(strrcmp(Reply, "psftp> ") == 0)\r
1837                                 break;\r
1838                         Sleep(1);\r
1839                 }\r
1840                 SFTP_closesocket(ContSock);\r
1841                 ContSock = INVALID_SOCKET;\r
1842         }\r
1843 \r
1844         return(ContSock);\r
1845 }\r
1846 \r
1847 // 同時接続対応\r
1848 //static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security)\r
1849 static SOCKET DoConnect(HOSTDATA* HostData, char *Host, char *User, char *Pass, char *Acct, int Port, int Fwall, int SavePass, int Security, int *CancelCheckWork)\r
1850 {\r
1851         SOCKET ContSock;\r
1852         ContSock = INVALID_SOCKET;\r
1853         *CancelCheckWork = NO;\r
1854         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseSFTP == YES)\r
1855         {\r
1856                 SetTaskMsg(MSGJPN317);\r
1857                 if((ContSock = DoConnectCrypt(CRYPT_SFTP, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1858                         HostData->CryptMode = CRYPT_SFTP;\r
1859         }\r
1860         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseFTPIS == YES)\r
1861         {\r
1862                 SetTaskMsg(MSGJPN316);\r
1863                 if((ContSock = DoConnectCrypt(CRYPT_FTPIS, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1864                         HostData->CryptMode = CRYPT_FTPIS;\r
1865         }\r
1866         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseFTPES == YES)\r
1867         {\r
1868                 SetTaskMsg(MSGJPN315);\r
1869                 if((ContSock = DoConnectCrypt(CRYPT_FTPES, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1870                         HostData->CryptMode = CRYPT_FTPES;\r
1871         }\r
1872         if(*CancelCheckWork == NO && ContSock == INVALID_SOCKET && HostData->UseNoEncryption == YES)\r
1873         {\r
1874                 SetTaskMsg(MSGJPN314);\r
1875                 if((ContSock = DoConnectCrypt(CRYPT_NONE, HostData, Host, User, Pass, Acct, Port, Fwall, SavePass, Security, CancelCheckWork)) != INVALID_SOCKET)\r
1876                         HostData->CryptMode = CRYPT_NONE;\r
1877         }\r
1878         return ContSock;\r
1879 }\r
1880 \r
1881 \r
1882 /*----- ワンタイムパスワードのチェック ----------------------------------------\r
1883 *\r
1884 *       Parameter\r
1885 *               chat *Pass : パスワード/パスフレーズ\r
1886 *               char *Reply : USERコマンドを送ったあとのリプライ文字列\r
1887 *                                               /PASSコマンドで送るパスワードを返すバッファ\r
1888 *               int Type : タイプ (SECURITY_xxx, MDx)\r
1889 *\r
1890 *       Return Value\r
1891 *               int ステータス\r
1892 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1893 *\r
1894 *       Note\r
1895 *               ワンタイムパスワードでない時はPassをそのままReplyにコピー\r
1896 *----------------------------------------------------------------------------*/\r
1897 \r
1898 static int CheckOneTimePassword(char *Pass, char *Reply, int Type)\r
1899 {\r
1900         int Sts;\r
1901         char *Pos;\r
1902         int Seq;\r
1903         char Seed[MAX_SEED_LEN+1];\r
1904         int i;\r
1905 \r
1906         Sts = FFFTP_SUCCESS;\r
1907         Pos = NULL;\r
1908 \r
1909         if(Type == SECURITY_AUTO)\r
1910         {\r
1911                 if((Pos = stristr(Reply, "otp-md5")) != NULL)\r
1912                 {\r
1913                         Type = MD5;\r
1914                         SetTaskMsg(MSGJPN012);\r
1915                 }\r
1916                 else if((Pos = stristr(Reply, "otp-sha1")) != NULL)\r
1917                 {\r
1918                         Type = SHA1;\r
1919                         SetTaskMsg(MSGJPN013);\r
1920                 }\r
1921                 else if(((Pos = stristr(Reply, "otp-md4")) != NULL) || ((Pos = stristr(Reply, "s/key")) != NULL))\r
1922                 {\r
1923                         Type = MD4;\r
1924                         SetTaskMsg(MSGJPN014);\r
1925                 }\r
1926         }\r
1927         else\r
1928                 Pos = GetNextField(Reply);\r
1929 \r
1930         if((Type == MD4) || (Type == MD5) || (Type == SHA1))\r
1931         {\r
1932                 /* シーケンス番号を見つけるループ */\r
1933                 DoPrintf("Analize OTP");\r
1934                 DoPrintf("%s", Pos);\r
1935                 Sts = FFFTP_FAIL;\r
1936                 while((Pos = GetNextField(Pos)) != NULL)\r
1937                 {\r
1938                         if(IsDigit(*Pos))\r
1939                         {\r
1940                                 Seq = atoi(Pos);\r
1941                                 DoPrintf("Sequence=%d", Seq);\r
1942 \r
1943                                 /* Seed */\r
1944                                 if((Pos = GetNextField(Pos)) != NULL)\r
1945                                 {\r
1946                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == FFFTP_SUCCESS)\r
1947                                         {\r
1948                                                 /* Seedは英数字のみ有効とする */\r
1949                                                 for(i = strlen(Seed)-1; i >= 0; i--)\r
1950                                                 {\r
1951                                                         if((IsAlpha(Seed[i]) == 0) && (IsDigit(Seed[i]) == 0))\r
1952                                                                 Seed[i] = NUL;\r
1953                                                 }\r
1954                                                 if(strlen(Seed) > 0)\r
1955                                                 {\r
1956                                                         DoPrintf("Seed=%s", Seed);\r
1957                                                         Make6WordPass(Seq, Seed, Pass, Type, Reply);\r
1958                                                         DoPrintf("Response=%s", Reply);\r
1959 \r
1960                                                         /* シーケンス番号のチェックと警告 */\r
1961                                                         if(Seq <= 10)\r
1962                                                                 DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_notify_dlg), GetMainHwnd(), ExeEscDialogProc);\r
1963 \r
1964                                                         Sts = FFFTP_SUCCESS;\r
1965                                                 }\r
1966                                         }\r
1967                                 }\r
1968                                 break;\r
1969                         }\r
1970                 }\r
1971 \r
1972                 if(Sts == FFFTP_FAIL)\r
1973                         SetTaskMsg(MSGJPN015);\r
1974         }\r
1975         else\r
1976         {\r
1977                 strcpy(Reply, Pass);\r
1978                 DoPrintf("No OTP used.");\r
1979         }\r
1980         return(Sts);\r
1981 }\r
1982 \r
1983 \r
1984 \r
1985 \r
1986 \r
1987 \r
1988 \r
1989 \r
1990 \r
1991 \r
1992 \r
1993 \r
1994 \r
1995 \r
1996 /*----- ソケットを接続する ----------------------------------------------------\r
1997 *\r
1998 *       Parameter\r
1999 *               char *host : ホスト名\r
2000 *               int port : ポート番号\r
2001 *               char *PreMsg : メッセージの前半部分\r
2002 *\r
2003 *       Return Value\r
2004 *               SOCKET ソケット\r
2005 *----------------------------------------------------------------------------*/\r
2006 \r
2007 // IPv6対応\r
2008 typedef SOCKET (__cdecl* LPCONNECTSOCK)(char*, int, char*, int*);\r
2009 \r
2010 typedef struct\r
2011 {\r
2012         HANDLE h;\r
2013         DWORD ExitCode;\r
2014         char *host;\r
2015         int port;\r
2016         char *PreMsg;\r
2017         int CancelCheckWork;\r
2018         LPCONNECTSOCK f;\r
2019         SOCKET s;\r
2020 } CONNECTSOCKDATA;\r
2021 \r
2022 DWORD WINAPI connectsockThreadProc(LPVOID lpParameter)\r
2023 {\r
2024         CONNECTSOCKDATA* pData;\r
2025         pData = (CONNECTSOCKDATA*)lpParameter;\r
2026         pData->s = pData->f(pData->host, pData->port, pData->PreMsg, &pData->CancelCheckWork);\r
2027         return 0;\r
2028 }\r
2029 \r
2030 // IPv6対応\r
2031 SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2032 {\r
2033         SOCKET Result;\r
2034         CONNECTSOCKDATA DataIPv4;\r
2035         CONNECTSOCKDATA DataIPv6;\r
2036         Result = INVALID_SOCKET;\r
2037         switch(CurHost.CurNetType)\r
2038         {\r
2039         case NTYPE_AUTO:\r
2040 //              if((Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
2041 //                      CurHost.CurNetType = NTYPE_IPV4;\r
2042 //              else if((Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork)) != INVALID_SOCKET)\r
2043 //                      CurHost.CurNetType = NTYPE_IPV6;\r
2044                 DataIPv4.host = host;\r
2045                 DataIPv4.port = port;\r
2046                 DataIPv4.PreMsg = PreMsg;\r
2047                 DataIPv4.CancelCheckWork = *CancelCheckWork;\r
2048                 DataIPv4.f = connectsockIPv4;\r
2049                 DataIPv4.h = CreateThread(NULL, 0, connectsockThreadProc, &DataIPv4, 0, NULL);\r
2050                 DataIPv6.host = host;\r
2051                 DataIPv6.port = port;\r
2052                 DataIPv6.PreMsg = PreMsg;\r
2053                 DataIPv6.CancelCheckWork = *CancelCheckWork;\r
2054                 DataIPv6.f = connectsockIPv6;\r
2055                 DataIPv6.h = CreateThread(NULL, 0, connectsockThreadProc, &DataIPv6, 0, NULL);\r
2056                 while(1)\r
2057                 {\r
2058                         if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode))\r
2059                         {\r
2060                                 if(DataIPv4.ExitCode != STILL_ACTIVE)\r
2061                                 {\r
2062                                         if(DataIPv4.s != INVALID_SOCKET)\r
2063                                         {\r
2064                                                 Result = DataIPv4.s;\r
2065                                                 CurHost.CurNetType = NTYPE_IPV4;\r
2066                                                 break;\r
2067                                         }\r
2068                                 }\r
2069                         }\r
2070                         if(GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
2071                         {\r
2072                                 if(DataIPv6.ExitCode != STILL_ACTIVE)\r
2073                                 {\r
2074                                         if(DataIPv6.s != INVALID_SOCKET)\r
2075                                         {\r
2076                                                 Result = DataIPv6.s;\r
2077                                                 CurHost.CurNetType = NTYPE_IPV6;\r
2078                                                 break;\r
2079                                         }\r
2080                                 }\r
2081                         }\r
2082                         if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode) && GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
2083                         {\r
2084                                 if(DataIPv4.ExitCode != STILL_ACTIVE && DataIPv6.ExitCode != STILL_ACTIVE)\r
2085                                 {\r
2086                                         if(DataIPv4.s == INVALID_SOCKET && DataIPv6.s == INVALID_SOCKET)\r
2087                                                 break;\r
2088                                 }\r
2089                         }\r
2090                         DataIPv4.CancelCheckWork = *CancelCheckWork;\r
2091                         DataIPv6.CancelCheckWork = *CancelCheckWork;\r
2092                         BackgrndMessageProc();\r
2093                         Sleep(1);\r
2094                 }\r
2095                 while(1)\r
2096                 {\r
2097                         if(GetExitCodeThread(DataIPv4.h, &DataIPv4.ExitCode) && GetExitCodeThread(DataIPv6.h, &DataIPv6.ExitCode))\r
2098                         {\r
2099                                 if(DataIPv4.ExitCode != STILL_ACTIVE && DataIPv6.ExitCode != STILL_ACTIVE)\r
2100                                 {\r
2101                                         CloseHandle(DataIPv4.h);\r
2102                                         CloseHandle(DataIPv6.h);\r
2103                                         break;\r
2104                                 }\r
2105                         }\r
2106                         DataIPv4.CancelCheckWork = YES;\r
2107                         DataIPv6.CancelCheckWork = YES;\r
2108                         BackgrndMessageProc();\r
2109                         Sleep(1);\r
2110                 }\r
2111                 break;\r
2112         case NTYPE_IPV4:\r
2113                 Result = connectsockIPv4(host, port, PreMsg, CancelCheckWork);\r
2114                 CurHost.CurNetType = NTYPE_IPV4;\r
2115                 break;\r
2116         case NTYPE_IPV6:\r
2117                 Result = connectsockIPv6(host, port, PreMsg, CancelCheckWork);\r
2118                 CurHost.CurNetType = NTYPE_IPV6;\r
2119                 break;\r
2120         }\r
2121         return Result;\r
2122 }\r
2123 \r
2124 \r
2125 // IPv6対応\r
2126 //SOCKET connectsock(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2127 SOCKET connectsockIPv4(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2128 {\r
2129         // IPv6対応\r
2130         struct sockaddr_in SocksSockAddr;       /* SOCKSサーバのアドレス情報 */\r
2131         struct sockaddr_in CurSockAddr;         /* 接続先ホストのアドレス情報 */\r
2132         struct sockaddr_in saSockAddr;\r
2133         char HostEntry[MAXGETHOSTSTRUCT];\r
2134         struct hostent *pHostEntry;\r
2135         SOCKET sSocket;\r
2136         int Len;\r
2137         int Fwall;\r
2138         SOCKS4CMD Socks4Cmd;\r
2139         SOCKS4REPLY Socks4Reply;\r
2140         SOCKS5REQUEST Socks5Cmd;\r
2141         SOCKS5REPLY Socks5Reply;\r
2142 \r
2143         //////////////////////////////\r
2144         // ホスト名解決と接続の準備\r
2145         //////////////////////////////\r
2146 \r
2147         Fwall = FWALL_NONE;\r
2148         if(AskHostFireWall() == YES)\r
2149                 Fwall = FwallType;\r
2150 \r
2151         sSocket = INVALID_SOCKET;\r
2152 \r
2153         UseIPadrs = YES;\r
2154         strcpy(DomainName, host);\r
2155         memset(&CurSockAddr, 0, sizeof(CurSockAddr));\r
2156         CurSockAddr.sin_port = htons((u_short)port);\r
2157         CurSockAddr.sin_family = AF_INET;\r
2158         if((CurSockAddr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)\r
2159         {\r
2160                 // ホスト名が指定された\r
2161                 // ホスト名からアドレスを求める\r
2162                 if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
2163                    (FwallResolv == YES))\r
2164                 {\r
2165                         // ホスト名解決はSOCKSサーバに任せる\r
2166                         pHostEntry = NULL;\r
2167                 }\r
2168                 else\r
2169                 {\r
2170                         // アドレスを取得\r
2171                         // IPv6対応\r
2172 //                      SetTaskMsg(MSGJPN016, DomainName);\r
2173                         SetTaskMsg(MSGJPN016, DomainName, MSGJPN333);\r
2174                         // IPv6対応\r
2175 //                      pHostEntry = do_gethostbyname(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2176                         pHostEntry = do_gethostbynameIPv4(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2177                 }\r
2178 \r
2179                 if(pHostEntry != NULL)\r
2180                 {\r
2181                         memcpy((char *)&CurSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2182                         // IPv6対応\r
2183 //                      SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
2184                         SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port), MSGJPN333);\r
2185                 }\r
2186                 else\r
2187                 {\r
2188                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2189                         {\r
2190                                 UseIPadrs = NO;\r
2191                                 // IPv6対応\r
2192 //                              SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port));\r
2193                                 SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin_port), MSGJPN333);\r
2194                         }\r
2195                         else\r
2196                         {\r
2197                                 // IPv6対応\r
2198 //                              SetTaskMsg(MSGJPN019, host);\r
2199                                 SetTaskMsg(MSGJPN019, host, MSGJPN333);\r
2200                                 return(INVALID_SOCKET);\r
2201                         }\r
2202                 }\r
2203         }\r
2204         else\r
2205                 // IPv6対応\r
2206 //              SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port));\r
2207                 SetTaskMsg(MSGJPN020, PreMsg, inet_ntoa(CurSockAddr.sin_addr), ntohs(CurSockAddr.sin_port), MSGJPN333);\r
2208 \r
2209         if((Fwall == FWALL_SOCKS4) || (Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2210         {\r
2211                 // SOCKSを使う\r
2212                 // SOCKSに接続する準備\r
2213                 if(Fwall == FWALL_SOCKS4)\r
2214                 {\r
2215                         Socks4Cmd.Ver = SOCKS4_VER;\r
2216                         Socks4Cmd.Cmd = SOCKS4_CMD_CONNECT;\r
2217                         Socks4Cmd.Port = CurSockAddr.sin_port;\r
2218                         Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
2219                         strcpy(Socks4Cmd.UserID, FwallUser);\r
2220                         Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
2221                 }\r
2222                 else\r
2223                 {\r
2224                         Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
2225                 }\r
2226 \r
2227                 memset(&SocksSockAddr, 0, sizeof(SocksSockAddr));\r
2228                 if((SocksSockAddr.sin_addr.s_addr = inet_addr(FwallHost)) == INADDR_NONE)\r
2229                 {\r
2230                         // IPv6対応\r
2231 //                      if((pHostEntry = do_gethostbyname(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2232                         if((pHostEntry = do_gethostbynameIPv4(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2233                                 memcpy((char *)&SocksSockAddr.sin_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2234                         else\r
2235                         {\r
2236                                 // IPv6対応\r
2237 //                              SetTaskMsg(MSGJPN021, FwallHost);\r
2238                                 SetTaskMsg(MSGJPN021, FwallHost, MSGJPN333);\r
2239                                 return INVALID_SOCKET;\r
2240                         }\r
2241                 }\r
2242                 SocksSockAddr.sin_port = htons((u_short)FwallPort);\r
2243                 SocksSockAddr.sin_family = AF_INET;\r
2244                 // IPv6対応\r
2245 //              SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port));\r
2246                 SetTaskMsg(MSGJPN022, inet_ntoa(SocksSockAddr.sin_addr), ntohs(SocksSockAddr.sin_port), MSGJPN333);\r
2247                 // connectで接続する先はSOCKSサーバ\r
2248                 memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr));\r
2249         }\r
2250         else\r
2251         {\r
2252                 // connectで接続するのは接続先のホスト\r
2253                 memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr));\r
2254         }\r
2255 \r
2256         /////////////\r
2257         // 接続実行\r
2258         /////////////\r
2259 \r
2260         if((sSocket = do_socket(AF_INET, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
2261         {\r
2262                 // ソケットにデータを付与\r
2263                 SetAsyncTableDataIPv4(sSocket, &CurSockAddr, &SocksSockAddr);\r
2264                 if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2265                 {\r
2266                         if(Fwall == FWALL_SOCKS4)\r
2267                         {\r
2268                                 Socks4Reply.Result = -1;\r
2269                                 // 同時接続対応\r
2270 //                              if((SocksSendCmd(sSocket, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2271 //                                 (Socks4GetCmdReply(sSocket, &Socks4Reply) != FFFTP_SUCCESS) || \r
2272 //                                 (Socks4Reply.Result != SOCKS4_RES_OK))\r
2273                                 if((SocksSendCmd(sSocket, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2274                                    (Socks4GetCmdReply(sSocket, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2275                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
2276                                 {\r
2277                                         // IPv6対応\r
2278 //                                      SetTaskMsg(MSGJPN023, Socks4Reply.Result);\r
2279                                         SetTaskMsg(MSGJPN023, Socks4Reply.Result, MSGJPN333);\r
2280                                         DoClose(sSocket);\r
2281                                         sSocket = INVALID_SOCKET;\r
2282                                 }\r
2283                         }\r
2284                         else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2285                         {\r
2286                                 if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
2287                                 {\r
2288                                         DoClose(sSocket);\r
2289                                         sSocket = INVALID_SOCKET;\r
2290                                 }\r
2291 \r
2292                                 Socks5Reply.Result = -1;\r
2293                                 // 同時接続対応\r
2294 //                              if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2295 //                                 (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
2296 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2297                                 if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2298                                    (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2299                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2300                                 {\r
2301                                         // IPv6対応\r
2302 //                                      SetTaskMsg(MSGJPN024, Socks5Reply.Result);\r
2303                                         SetTaskMsg(MSGJPN024, Socks5Reply.Result, MSGJPN333);\r
2304                                         DoClose(sSocket);\r
2305                                         sSocket = INVALID_SOCKET;\r
2306                                 }\r
2307 \r
2308                         }\r
2309 \r
2310                         if(sSocket != INVALID_SOCKET)\r
2311                                 // IPv6対応\r
2312 //                              SetTaskMsg(MSGJPN025);\r
2313                                 SetTaskMsg(MSGJPN025, MSGJPN333);\r
2314                 }\r
2315                 else\r
2316                 {\r
2317 //#pragma aaa\r
2318                         // IPv6対応\r
2319 //                      SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/);\r
2320                         SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/, MSGJPN333);\r
2321                         DoClose(sSocket);\r
2322                         sSocket = INVALID_SOCKET;\r
2323                 }\r
2324         }\r
2325         else\r
2326                 // IPv6対応\r
2327 //              SetTaskMsg(MSGJPN027);\r
2328                 SetTaskMsg(MSGJPN027, MSGJPN333);\r
2329 \r
2330         return(sSocket);\r
2331 }\r
2332 \r
2333 \r
2334 SOCKET connectsockIPv6(char *host, int port, char *PreMsg, int *CancelCheckWork)\r
2335 {\r
2336         struct sockaddr_in6 SocksSockAddr;      /* SOCKSサーバのアドレス情報 */\r
2337         struct sockaddr_in6 CurSockAddr;                /* 接続先ホストのアドレス情報 */\r
2338         struct sockaddr_in6 saSockAddr;\r
2339         char HostEntry[MAXGETHOSTSTRUCT];\r
2340         struct hostent *pHostEntry;\r
2341         SOCKET sSocket;\r
2342         int Len;\r
2343         int Fwall;\r
2344         SOCKS5REQUEST Socks5Cmd;\r
2345         SOCKS5REPLY Socks5Reply;\r
2346 \r
2347         //////////////////////////////\r
2348         // ホスト名解決と接続の準備\r
2349         //////////////////////////////\r
2350 \r
2351         Fwall = FWALL_NONE;\r
2352         if(AskHostFireWall() == YES)\r
2353                 Fwall = FwallType;\r
2354 \r
2355         sSocket = INVALID_SOCKET;\r
2356 \r
2357         UseIPadrs = YES;\r
2358         strcpy(DomainName, host);\r
2359         memset(&CurSockAddr, 0, sizeof(CurSockAddr));\r
2360         CurSockAddr.sin6_port = htons((u_short)port);\r
2361         CurSockAddr.sin6_family = AF_INET6;\r
2362         CurSockAddr.sin6_addr = inet6_addr(host);\r
2363         if(memcmp(&CurSockAddr.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
2364         {\r
2365                 // ホスト名が指定された\r
2366                 // ホスト名からアドレスを求める\r
2367                 if(((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER)) &&\r
2368                    (FwallResolv == YES))\r
2369                 {\r
2370                         // ホスト名解決はSOCKSサーバに任せる\r
2371                         pHostEntry = NULL;\r
2372                 }\r
2373                 else\r
2374                 {\r
2375                         // アドレスを取得\r
2376                         SetTaskMsg(MSGJPN016, DomainName, MSGJPN334);\r
2377                         pHostEntry = do_gethostbynameIPv6(host, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork);\r
2378                 }\r
2379 \r
2380                 if(pHostEntry != NULL)\r
2381                 {\r
2382                         memcpy((char *)&CurSockAddr.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2383                         SetTaskMsg(MSGJPN017, PreMsg, DomainName, inet6_ntoa(CurSockAddr.sin6_addr), ntohs(CurSockAddr.sin6_port), MSGJPN334);\r
2384                 }\r
2385                 else\r
2386                 {\r
2387                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2388                         {\r
2389                                 UseIPadrs = NO;\r
2390                                 SetTaskMsg(MSGJPN018, PreMsg, DomainName, ntohs(CurSockAddr.sin6_port), MSGJPN334);\r
2391                         }\r
2392                         else\r
2393                         {\r
2394                                 SetTaskMsg(MSGJPN019, host, MSGJPN334);\r
2395                                 return(INVALID_SOCKET);\r
2396                         }\r
2397                 }\r
2398         }\r
2399         else\r
2400                 SetTaskMsg(MSGJPN020, PreMsg, inet6_ntoa(CurSockAddr.sin6_addr), ntohs(CurSockAddr.sin6_port), MSGJPN334);\r
2401 \r
2402         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2403         {\r
2404                 // SOCKSを使う\r
2405                 // SOCKSに接続する準備\r
2406                 {\r
2407                         Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_CONNECT, UseIPadrs, (char*)&CurSockAddr.sin6_addr, DomainName, CurSockAddr.sin6_port);\r
2408                 }\r
2409 \r
2410                 memset(&SocksSockAddr, 0, sizeof(SocksSockAddr));\r
2411                 SocksSockAddr.sin6_addr = inet6_addr(FwallHost);\r
2412                 if(memcmp(&SocksSockAddr.sin6_addr, &IN6ADDR_NONE, sizeof(struct in6_addr)) == 0)\r
2413                 {\r
2414                         if((pHostEntry = do_gethostbynameIPv6(FwallHost, HostEntry, MAXGETHOSTSTRUCT, CancelCheckWork)) != NULL)\r
2415                                 memcpy((char *)&SocksSockAddr.sin6_addr, pHostEntry->h_addr, pHostEntry->h_length);\r
2416                         else\r
2417                         {\r
2418                                 SetTaskMsg(MSGJPN021, FwallHost, MSGJPN334);\r
2419                                 return INVALID_SOCKET;\r
2420                         }\r
2421                 }\r
2422                 SocksSockAddr.sin6_port = htons((u_short)FwallPort);\r
2423                 SocksSockAddr.sin6_family = AF_INET6;\r
2424                 SetTaskMsg(MSGJPN022, inet6_ntoa(SocksSockAddr.sin6_addr), ntohs(SocksSockAddr.sin6_port), MSGJPN334);\r
2425                 // connectで接続する先はSOCKSサーバ\r
2426                 memcpy(&saSockAddr, &SocksSockAddr, sizeof(SocksSockAddr));\r
2427         }\r
2428         else\r
2429         {\r
2430                 // connectで接続するのは接続先のホスト\r
2431                 memcpy(&saSockAddr, &CurSockAddr, sizeof(CurSockAddr));\r
2432         }\r
2433 \r
2434         /////////////\r
2435         // 接続実行\r
2436         /////////////\r
2437 \r
2438         if((sSocket = do_socket(AF_INET6, SOCK_STREAM, TCP_PORT)) != INVALID_SOCKET)\r
2439         {\r
2440                 // ソケットにデータを付与\r
2441                 SetAsyncTableDataIPv6(sSocket, &CurSockAddr, &SocksSockAddr);\r
2442                 if(do_connect(sSocket, (struct sockaddr *)&saSockAddr, sizeof(saSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2443                 {\r
2444                         if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2445                         {\r
2446                                 if(Socks5SelMethod(sSocket, CancelCheckWork) == FFFTP_FAIL)\r
2447                                 {\r
2448                                         DoClose(sSocket);\r
2449                                         sSocket = INVALID_SOCKET;\r
2450                                 }\r
2451 \r
2452                                 Socks5Reply.Result = -1;\r
2453                                 // 同時接続対応\r
2454 //                              if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2455 //                                 (Socks5GetCmdReply(sSocket, &Socks5Reply) != FFFTP_SUCCESS) || \r
2456 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2457                                 if((SocksSendCmd(sSocket, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2458                                    (Socks5GetCmdReply(sSocket, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2459                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2460                                 {\r
2461                                         SetTaskMsg(MSGJPN024, Socks5Reply.Result, MSGJPN334);\r
2462                                         DoClose(sSocket);\r
2463                                         sSocket = INVALID_SOCKET;\r
2464                                 }\r
2465 \r
2466                         }\r
2467 \r
2468                         if(sSocket != INVALID_SOCKET)\r
2469                                 SetTaskMsg(MSGJPN025, MSGJPN334);\r
2470                 }\r
2471                 else\r
2472                 {\r
2473 //#pragma aaa\r
2474                         SetTaskMsg(MSGJPN026/*"接続できません(2) %x", sSocket*/, MSGJPN334);\r
2475                         DoClose(sSocket);\r
2476                         sSocket = INVALID_SOCKET;\r
2477                 }\r
2478         }\r
2479         else\r
2480                 SetTaskMsg(MSGJPN027, MSGJPN334);\r
2481 \r
2482         return(sSocket);\r
2483 }\r
2484 \r
2485 \r
2486 /*----- リッスンソケットを取得 ------------------------------------------------\r
2487 *\r
2488 *       Parameter\r
2489 *               SOCKET ctrl_skt : コントロールソケット\r
2490 *\r
2491 *       Return Value\r
2492 *               SOCKET リッスンソケット\r
2493 *----------------------------------------------------------------------------*/\r
2494 \r
2495 // IPv6対応\r
2496 SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)\r
2497 {\r
2498         SOCKET Result;\r
2499         Result = INVALID_SOCKET;\r
2500         switch(CurHost.CurNetType)\r
2501         {\r
2502         case NTYPE_IPV4:\r
2503                 Result = GetFTPListenSocketIPv4(ctrl_skt, CancelCheckWork);\r
2504                 break;\r
2505         case NTYPE_IPV6:\r
2506                 Result = GetFTPListenSocketIPv6(ctrl_skt, CancelCheckWork);\r
2507                 break;\r
2508         }\r
2509         return Result;\r
2510 }\r
2511 \r
2512 \r
2513 // IPv6対応\r
2514 //SOCKET GetFTPListenSocket(SOCKET ctrl_skt, int *CancelCheckWork)\r
2515 SOCKET GetFTPListenSocketIPv4(SOCKET ctrl_skt, int *CancelCheckWork)\r
2516 {\r
2517         // IPv6対応\r
2518         struct sockaddr_in SocksSockAddr;       /* SOCKSサーバのアドレス情報 */\r
2519         struct sockaddr_in CurSockAddr;         /* 接続先ホストのアドレス情報 */\r
2520     SOCKET listen_skt;\r
2521     int iLength;\r
2522     char *a,*p;\r
2523         struct sockaddr_in saCtrlAddr;\r
2524         struct sockaddr_in saTmpAddr;\r
2525         SOCKS4CMD Socks4Cmd;\r
2526         SOCKS4REPLY Socks4Reply;\r
2527         SOCKS5REQUEST Socks5Cmd;\r
2528         SOCKS5REPLY Socks5Reply;\r
2529 \r
2530         int Len;\r
2531         int Fwall;\r
2532 \r
2533         // ソケットにデータを付与\r
2534         GetAsyncTableDataIPv4(ctrl_skt, &CurSockAddr, &SocksSockAddr);\r
2535 \r
2536         Fwall = FWALL_NONE;\r
2537         if(AskHostFireWall() == YES)\r
2538                 Fwall = FwallType;\r
2539 \r
2540         if((listen_skt = do_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)\r
2541         {\r
2542                 if(Fwall == FWALL_SOCKS4)\r
2543                 {\r
2544                         /*===== SOCKS4を使う =====*/\r
2545                         DoPrintf("Use SOCKS4 BIND");\r
2546                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2547                         {\r
2548                                 Socks4Cmd.Ver = SOCKS4_VER;\r
2549                                 Socks4Cmd.Cmd = SOCKS4_CMD_BIND;\r
2550                                 Socks4Cmd.Port = CurSockAddr.sin_port;\r
2551                                 Socks4Cmd.AdrsInt = CurSockAddr.sin_addr.s_addr;\r
2552                                 strcpy(Socks4Cmd.UserID, FwallUser);\r
2553                                 Len = offsetof(SOCKS4CMD, UserID) + strlen(FwallUser) + 1;\r
2554 \r
2555                                 Socks4Reply.Result = -1;\r
2556                                 // 同時接続対応\r
2557 //                              if((SocksSendCmd(listen_skt, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2558 //                                 (Socks4GetCmdReply(listen_skt, &Socks4Reply) != FFFTP_SUCCESS) || \r
2559 //                                 (Socks4Reply.Result != SOCKS4_RES_OK))\r
2560                                 if((SocksSendCmd(listen_skt, &Socks4Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2561                                    (Socks4GetCmdReply(listen_skt, &Socks4Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2562                                    (Socks4Reply.Result != SOCKS4_RES_OK))\r
2563                                 {\r
2564                                         // IPv6対応\r
2565 //                                      SetTaskMsg(MSGJPN028, Socks4Reply.Result);\r
2566                                         SetTaskMsg(MSGJPN028, Socks4Reply.Result, MSGJPN333);\r
2567                                         DoClose(listen_skt);\r
2568                                         listen_skt = INVALID_SOCKET;\r
2569                                 }\r
2570 \r
2571                                 if(Socks4Reply.AdrsInt == 0)\r
2572                                         Socks4Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2573 \r
2574                                 a = (char *)&Socks4Reply.AdrsInt;\r
2575                                 p = (char *)&Socks4Reply.Port;\r
2576                         }\r
2577                 }\r
2578                 else if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2579                 {\r
2580                         /*===== SOCKS5を使う =====*/\r
2581                         DoPrintf("Use SOCKS5 BIND");\r
2582                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2583                         {\r
2584                                 if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL)\r
2585                                 {\r
2586                                         DoClose(listen_skt);\r
2587                                         listen_skt = INVALID_SOCKET;\r
2588                                         return(listen_skt);\r
2589                                 }\r
2590 \r
2591                                 Len = Socks5MakeCmdPacket(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, CurSockAddr.sin_addr.s_addr, DomainName, CurSockAddr.sin_port);\r
2592 \r
2593                                 Socks5Reply.Result = -1;\r
2594                                 // 同時接続対応\r
2595 //                              if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2596 //                                 (Socks5GetCmdReply(listen_skt, &Socks5Reply) != FFFTP_SUCCESS) || \r
2597 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2598                                 if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2599                                    (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2600                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2601                                 {\r
2602                                         // IPv6対応\r
2603 //                                      SetTaskMsg(MSGJPN029, Socks5Reply.Result);\r
2604                                         SetTaskMsg(MSGJPN029, Socks5Reply.Result, MSGJPN333);\r
2605                                         DoClose(listen_skt);\r
2606                                         listen_skt = INVALID_SOCKET;\r
2607                                 }\r
2608 \r
2609                                 // IPv6対応\r
2610 //                              if(Socks5Reply.AdrsInt == 0)\r
2611 //                                      Socks5Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2612 \r
2613                                 // IPv6対応\r
2614 //                              a = (char *)&Socks5Reply.AdrsInt;\r
2615 //                              p = (char *)&Socks5Reply.Port;\r
2616                                 a = (char *)&Socks5Reply._dummy[0];\r
2617                                 p = (char *)&Socks5Reply._dummy[4];\r
2618                         }\r
2619                 }\r
2620                 else\r
2621                 {\r
2622                         /*===== SOCKSを使わない =====*/\r
2623                         DoPrintf("Use normal BIND");\r
2624                         saCtrlAddr.sin_port = htons(0);\r
2625                         saCtrlAddr.sin_family = AF_INET;\r
2626                         saCtrlAddr.sin_addr.s_addr = 0;\r
2627 \r
2628                         if(bind(listen_skt, (struct sockaddr *)&saCtrlAddr, sizeof(struct sockaddr)) != SOCKET_ERROR)\r
2629                         {\r
2630                                 iLength = sizeof(saCtrlAddr);\r
2631                                 if(getsockname(listen_skt, (struct sockaddr *)&saCtrlAddr, &iLength) != SOCKET_ERROR)\r
2632                                 {\r
2633                                         if(do_listen(listen_skt, 1) == 0)\r
2634                                         {\r
2635                                                 iLength = sizeof(saTmpAddr);\r
2636                                                 if(getsockname(ctrl_skt, (struct sockaddr *)&saTmpAddr, &iLength) == SOCKET_ERROR)\r
2637                                                         ReportWSError("getsockname", WSAGetLastError());\r
2638 \r
2639                                                 a = (char *)&saTmpAddr.sin_addr;\r
2640                                                 p = (char *)&saCtrlAddr.sin_port;\r
2641                                         }\r
2642                                         else\r
2643                                         {\r
2644                                                 ReportWSError("listen", WSAGetLastError());\r
2645                                                 do_closesocket(listen_skt);\r
2646                                                 listen_skt = INVALID_SOCKET;\r
2647                                         }\r
2648                                 }\r
2649                                 else\r
2650                                 {\r
2651                                         ReportWSError("getsockname", WSAGetLastError());\r
2652                                         do_closesocket(listen_skt);\r
2653                                         listen_skt = INVALID_SOCKET;\r
2654                                 }\r
2655                         }\r
2656                         else\r
2657                         {\r
2658                                 ReportWSError("bind", WSAGetLastError());\r
2659                                 do_closesocket(listen_skt);\r
2660                                 listen_skt = INVALID_SOCKET;\r
2661                         }\r
2662 \r
2663                         if(listen_skt == INVALID_SOCKET)\r
2664                                 // IPv6対応\r
2665 //                              SetTaskMsg(MSGJPN030);\r
2666                                 SetTaskMsg(MSGJPN030, MSGJPN333);\r
2667                 }\r
2668         }\r
2669         else\r
2670                 ReportWSError("socket create", WSAGetLastError());\r
2671 \r
2672         if(listen_skt != INVALID_SOCKET)\r
2673         {\r
2674 #define  UC(b)  (((int)b)&0xff)\r
2675                 // 同時接続対応\r
2676 //              if((command(ctrl_skt,NULL, &CancelFlg, "PORT %d,%d,%d,%d,%d,%d",\r
2677 //                              UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2678 //                              UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2679                 if((command(ctrl_skt,NULL, CancelCheckWork, "PORT %d,%d,%d,%d,%d,%d",\r
2680                                 UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2681                                 UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2682                 {\r
2683                         // IPv6対応\r
2684 //                      SetTaskMsg(MSGJPN031);\r
2685                         SetTaskMsg(MSGJPN031, MSGJPN333);\r
2686                         do_closesocket(listen_skt);\r
2687                         listen_skt = INVALID_SOCKET;\r
2688                 }\r
2689 //              else\r
2690 //                      DoPrintf("Skt=%u : listener %s port %u",listen_skt,inet_ntoa(saCtrlAddr.sin_addr),ntohs(saCtrlAddr.sin_port));\r
2691         }\r
2692 \r
2693         return(listen_skt);\r
2694 }\r
2695 \r
2696 \r
2697 SOCKET GetFTPListenSocketIPv6(SOCKET ctrl_skt, int *CancelCheckWork)\r
2698 {\r
2699         struct sockaddr_in6 SocksSockAddr;      /* SOCKSサーバのアドレス情報 */\r
2700         struct sockaddr_in6 CurSockAddr;                /* 接続先ホストのアドレス情報 */\r
2701     SOCKET listen_skt;\r
2702     int iLength;\r
2703     char *a,*p;\r
2704         struct sockaddr_in6 saCtrlAddr;\r
2705         struct sockaddr_in6 saTmpAddr;\r
2706         SOCKS5REQUEST Socks5Cmd;\r
2707         SOCKS5REPLY Socks5Reply;\r
2708 \r
2709         int Len;\r
2710         int Fwall;\r
2711 \r
2712         char Adrs[40];\r
2713 \r
2714         // ソケットにデータを付与\r
2715         GetAsyncTableDataIPv6(ctrl_skt, &CurSockAddr, &SocksSockAddr);\r
2716 \r
2717         Fwall = FWALL_NONE;\r
2718         if(AskHostFireWall() == YES)\r
2719                 Fwall = FwallType;\r
2720 \r
2721         if((listen_skt = do_socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) != INVALID_SOCKET)\r
2722         {\r
2723                 if((Fwall == FWALL_SOCKS5_NOAUTH) || (Fwall == FWALL_SOCKS5_USER))\r
2724                 {\r
2725                         /*===== SOCKS5を使う =====*/\r
2726                         DoPrintf("Use SOCKS5 BIND");\r
2727                         if(do_connect(listen_skt, (struct sockaddr *)&SocksSockAddr, sizeof(SocksSockAddr), CancelCheckWork) != SOCKET_ERROR)\r
2728                         {\r
2729                                 if(Socks5SelMethod(listen_skt, CancelCheckWork) == FFFTP_FAIL)\r
2730                                 {\r
2731                                         DoClose(listen_skt);\r
2732                                         listen_skt = INVALID_SOCKET;\r
2733                                         return(listen_skt);\r
2734                                 }\r
2735 \r
2736                                 Len = Socks5MakeCmdPacketIPv6(&Socks5Cmd, SOCKS5_CMD_BIND, UseIPadrs, (char*)&CurSockAddr.sin6_addr, DomainName, CurSockAddr.sin6_port);\r
2737 \r
2738                                 Socks5Reply.Result = -1;\r
2739                                 // 同時接続対応\r
2740 //                              if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2741 //                                 (Socks5GetCmdReply(listen_skt, &Socks5Reply) != FFFTP_SUCCESS) || \r
2742 //                                 (Socks5Reply.Result != SOCKS5_RES_OK))\r
2743                                 if((SocksSendCmd(listen_skt, &Socks5Cmd, Len, CancelCheckWork) != FFFTP_SUCCESS) ||\r
2744                                    (Socks5GetCmdReply(listen_skt, &Socks5Reply, CancelCheckWork) != FFFTP_SUCCESS) || \r
2745                                    (Socks5Reply.Result != SOCKS5_RES_OK))\r
2746                                 {\r
2747                                         SetTaskMsg(MSGJPN029, Socks5Reply.Result, MSGJPN334);\r
2748                                         DoClose(listen_skt);\r
2749                                         listen_skt = INVALID_SOCKET;\r
2750                                 }\r
2751 \r
2752                                 // IPv6対応\r
2753 //                              if(Socks5Reply.AdrsInt == 0)\r
2754 //                                      Socks5Reply.AdrsInt = SocksSockAddr.sin_addr.s_addr;\r
2755 \r
2756                                 // IPv6対応\r
2757 //                              a = (char *)&Socks5Reply.AdrsInt;\r
2758 //                              p = (char *)&Socks5Reply.Port;\r
2759                                 a = (char *)&Socks5Reply._dummy[0];\r
2760                                 p = (char *)&Socks5Reply._dummy[16];\r
2761                         }\r
2762                 }\r
2763                 else\r
2764                 {\r
2765                         /*===== SOCKSを使わない =====*/\r
2766                         DoPrintf("Use normal BIND");\r
2767                         saCtrlAddr.sin6_port = htons(0);\r
2768                         saCtrlAddr.sin6_family = AF_INET6;\r
2769                         memset(&saCtrlAddr.sin6_addr, 0, 16);\r
2770 \r
2771                         if(bind(listen_skt, (struct sockaddr *)&saCtrlAddr, sizeof(struct sockaddr_in6)) != SOCKET_ERROR)\r
2772                         {\r
2773                                 iLength = sizeof(saCtrlAddr);\r
2774                                 if(getsockname(listen_skt, (struct sockaddr *)&saCtrlAddr, &iLength) != SOCKET_ERROR)\r
2775                                 {\r
2776                                         if(do_listen(listen_skt, 1) == 0)\r
2777                                         {\r
2778                                                 iLength = sizeof(saTmpAddr);\r
2779                                                 if(getsockname(ctrl_skt, (struct sockaddr *)&saTmpAddr, &iLength) == SOCKET_ERROR)\r
2780                                                         ReportWSError("getsockname", WSAGetLastError());\r
2781 \r
2782                                                 a = (char *)&saTmpAddr.sin6_addr;\r
2783                                                 p = (char *)&saCtrlAddr.sin6_port;\r
2784                                         }\r
2785                                         else\r
2786                                         {\r
2787                                                 ReportWSError("listen", WSAGetLastError());\r
2788                                                 do_closesocket(listen_skt);\r
2789                                                 listen_skt = INVALID_SOCKET;\r
2790                                         }\r
2791                                 }\r
2792                                 else\r
2793                                 {\r
2794                                         ReportWSError("getsockname", WSAGetLastError());\r
2795                                         do_closesocket(listen_skt);\r
2796                                         listen_skt = INVALID_SOCKET;\r
2797                                 }\r
2798                         }\r
2799                         else\r
2800                         {\r
2801                                 ReportWSError("bind", WSAGetLastError());\r
2802                                 do_closesocket(listen_skt);\r
2803                                 listen_skt = INVALID_SOCKET;\r
2804                         }\r
2805 \r
2806                         if(listen_skt == INVALID_SOCKET)\r
2807                                 SetTaskMsg(MSGJPN030, MSGJPN334);\r
2808                 }\r
2809         }\r
2810         else\r
2811                 ReportWSError("socket create", WSAGetLastError());\r
2812 \r
2813         if(listen_skt != INVALID_SOCKET)\r
2814         {\r
2815 #define  UC(b)  (((int)b)&0xff)\r
2816                 // 同時接続対応\r
2817 //              if((command(ctrl_skt,NULL, &CancelFlg, "PORT %d,%d,%d,%d,%d,%d",\r
2818 //                              UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]),\r
2819 //                              UC(p[0]), UC(p[1])) / 100) != FTP_COMPLETE)\r
2820                 if((command(ctrl_skt,NULL, CancelCheckWork, "EPRT |2|%s|%d|",\r
2821                                 AddressToStringIPv6(Adrs, a),\r
2822                                 (UC(p[0]) << 8) | UC(p[1])) / 100) != FTP_COMPLETE)\r
2823                 {\r
2824                         SetTaskMsg(MSGJPN031, MSGJPN334);\r
2825                         do_closesocket(listen_skt);\r
2826                         listen_skt = INVALID_SOCKET;\r
2827                 }\r
2828 //              else\r
2829 //                      DoPrintf("Skt=%u : listener %s port %u",listen_skt,inet_ntoa(saCtrlAddr.sin_addr),ntohs(saCtrlAddr.sin_port));\r
2830         }\r
2831 \r
2832         return(listen_skt);\r
2833 }\r
2834 \r
2835 \r
2836 /*----- ホストへ接続処理中かどうかを返す---------------------------------------\r
2837 *\r
2838 *       Parameter\r
2839 *               なし\r
2840 *\r
2841 *       Return Value\r
2842 *               int ステータス\r
2843 *                       YES/NO\r
2844 *----------------------------------------------------------------------------*/\r
2845 \r
2846 int AskTryingConnect(void)\r
2847 {\r
2848         return(TryConnect);\r
2849 }\r
2850 \r
2851 \r
2852 #if 0\r
2853 ///*----- ブロッキングコールのフックコールバック --------------------------------\r
2854 //*\r
2855 //*     Parameter\r
2856 //*             なし\r
2857 //*\r
2858 //*     Return Value\r
2859 //*             BOOL FALSE\r
2860 //*----------------------------------------------------------------------------*/\r
2861 //\r
2862 //static BOOL CALLBACK BlkHookFnc(void)\r
2863 //{\r
2864 //      BackgrndMessageProc();\r
2865 //\r
2866 //      if(CancelFlg == YES)\r
2867 //      {\r
2868 //              SetTaskMsg(MSGJPN032);\r
2869 //              WSACancelBlockingCall();\r
2870 //              CancelFlg = NO;\r
2871 //      }\r
2872 //      return(FALSE);\r
2873 //}\r
2874 #endif\r
2875 \r
2876 \r
2877 \r
2878 /*----- SOCKS5のコマンドパケットを作成する ------------------------------------\r
2879 *\r
2880 *       Parameter\r
2881 *               SOCKS5REQUEST *Packet : パケットを作成するワーク\r
2882 *               char Cmd : コマンド\r
2883 *               int ValidIP : IPアドレスを使うかどうか(YES/NO)\r
2884 *               ulong IP : IPアドレス\r
2885 *               char *Host : ホスト名\r
2886 *               ushort Port : ポート\r
2887 *\r
2888 *       Return Value\r
2889 *               int コマンドパケットの長さ\r
2890 *----------------------------------------------------------------------------*/\r
2891 \r
2892 static int Socks5MakeCmdPacket(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, ulong IP, char *Host, ushort Port)\r
2893 {\r
2894         uchar *Pos;\r
2895         int Len;\r
2896         int TotalLen;\r
2897 \r
2898         Pos = (uchar *)Packet;\r
2899         Pos += SOCKS5REQUEST_SIZE;\r
2900         TotalLen = SOCKS5REQUEST_SIZE + 2;      /* +2はポートの分 */\r
2901 \r
2902         Packet->Ver = SOCKS5_VER;\r
2903         Packet->Cmd = Cmd;\r
2904         Packet->Rsv = 0;\r
2905         if(ValidIP == YES)\r
2906         {\r
2907                 /* IPアドレスを指定 */\r
2908                 Packet->Type = SOCKS5_ADRS_IPV4;\r
2909                 *((ulong *)Pos) = IP;\r
2910                 Pos += 4;\r
2911                 TotalLen += 4;\r
2912         }\r
2913         else\r
2914         {\r
2915                 /* ホスト名を指定 */\r
2916                 Packet->Type = SOCKS5_ADRS_NAME;\r
2917                 Len = strlen(Host);\r
2918                 *Pos++ = Len;\r
2919                 strcpy(Pos, Host);\r
2920                 Pos += Len;\r
2921                 TotalLen += Len + 1;\r
2922         }\r
2923         *((ushort *)Pos) = Port;\r
2924 \r
2925         return(TotalLen);\r
2926 }\r
2927 \r
2928 \r
2929 // IPv6対応\r
2930 static int Socks5MakeCmdPacketIPv6(SOCKS5REQUEST *Packet, char Cmd, int ValidIP, char *IP, char *Host, ushort Port)\r
2931 {\r
2932         uchar *Pos;\r
2933         int Len;\r
2934         int TotalLen;\r
2935 \r
2936         Pos = (uchar *)Packet;\r
2937         Pos += SOCKS5REQUEST_SIZE;\r
2938         TotalLen = SOCKS5REQUEST_SIZE + 2;      /* +2はポートの分 */\r
2939 \r
2940         Packet->Ver = SOCKS5_VER;\r
2941         Packet->Cmd = Cmd;\r
2942         Packet->Rsv = 0;\r
2943         if(ValidIP == YES)\r
2944         {\r
2945                 /* IPアドレスを指定 */\r
2946                 Packet->Type = SOCKS5_ADRS_IPV6;\r
2947                 memcpy(Pos, IP, 16);\r
2948                 Pos += 16;\r
2949                 TotalLen += 16;\r
2950         }\r
2951         else\r
2952         {\r
2953                 /* ホスト名を指定 */\r
2954                 Packet->Type = SOCKS5_ADRS_NAME;\r
2955                 Len = strlen(Host);\r
2956                 *Pos++ = Len;\r
2957                 strcpy(Pos, Host);\r
2958                 Pos += Len;\r
2959                 TotalLen += Len + 1;\r
2960         }\r
2961         *((ushort *)Pos) = Port;\r
2962 \r
2963         return(TotalLen);\r
2964 }\r
2965 \r
2966 \r
2967 /*----- SOCKSのコマンドを送る -------------------------------------------------\r
2968 *\r
2969 *       Parameter\r
2970 *               SOCKET Socket : ソケット\r
2971 *               void *Data : 送るデータ\r
2972 *               int Size : サイズ\r
2973 *\r
2974 *       Return Value\r
2975 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2976 *----------------------------------------------------------------------------*/\r
2977 \r
2978 static int SocksSendCmd(SOCKET Socket, void *Data, int Size, int *CancelCheckWork)\r
2979 {\r
2980         int Ret;\r
2981 \r
2982         Ret = SendData(Socket, (char *)Data, Size, 0, CancelCheckWork);\r
2983 \r
2984         if(Ret != FFFTP_SUCCESS)\r
2985                 SetTaskMsg(MSGJPN033, *((short *)Data));\r
2986 \r
2987         return(Ret);\r
2988 }\r
2989 \r
2990 \r
2991 /*----- SOCKS5のコマンドに対するリプライパケットを受信する --------------------\r
2992 *\r
2993 *       Parameter\r
2994 *               SOCKET Socket : ソケット\r
2995 *               SOCKS5REPLY *Packet : パケット\r
2996 *\r
2997 *       Return Value\r
2998 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
2999 *----------------------------------------------------------------------------*/\r
3000 \r
3001 // 同時接続対応\r
3002 //static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet)\r
3003 static int Socks5GetCmdReply(SOCKET Socket, SOCKS5REPLY *Packet, int *CancelCheckWork)\r
3004 {\r
3005         uchar *Pos;\r
3006         int Len;\r
3007         int Ret;\r
3008 \r
3009         Pos = (uchar *)Packet;\r
3010         Pos += SOCKS5REPLY_SIZE;\r
3011 \r
3012         // 同時接続対応\r
3013 //      if((Ret = ReadNchar(Socket, (char *)Packet, SOCKS5REPLY_SIZE, &CancelFlg)) == FFFTP_SUCCESS)\r
3014         if((Ret = ReadNchar(Socket, (char *)Packet, SOCKS5REPLY_SIZE, CancelCheckWork)) == FFFTP_SUCCESS)\r
3015         {\r
3016                 if(Packet->Type == SOCKS5_ADRS_IPV4)\r
3017                         Len = 4 + 2;\r
3018                 else if(Packet->Type == SOCKS5_ADRS_IPV6)\r
3019                         Len = 16 + 2;\r
3020                 else\r
3021                 {\r
3022                         // 同時接続対応\r
3023 //                      if((Ret = ReadNchar(Socket, (char *)Pos, 1, &CancelFlg)) == FFFTP_SUCCESS)\r
3024                         if((Ret = ReadNchar(Socket, (char *)Pos, 1, CancelCheckWork)) == FFFTP_SUCCESS)\r
3025                         {\r
3026                                 Len = *Pos + 2;\r
3027                                 Pos++;\r
3028                         }\r
3029                 }\r
3030 \r
3031                 if(Ret == FFFTP_SUCCESS)\r
3032                         // 同時接続対応\r
3033 //                      Ret = ReadNchar(Socket, (char *)Pos, Len, &CancelFlg);\r
3034                         Ret = ReadNchar(Socket, (char *)Pos, Len, CancelCheckWork);\r
3035         }\r
3036 \r
3037         if(Ret != FFFTP_SUCCESS)\r
3038                 SetTaskMsg(MSGJPN034);\r
3039 \r
3040         return(Ret);\r
3041 }\r
3042 \r
3043 \r
3044 /*----- SOCKS4のコマンドに対するリプライパケットを受信する --------------------\r
3045 *\r
3046 *       Parameter\r
3047 *               SOCKET Socket : ソケット\r
3048 *               SOCKS5REPLY *Packet : パケット\r
3049 *\r
3050 *       Return Value\r
3051 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
3052 *----------------------------------------------------------------------------*/\r
3053 \r
3054 // 同時接続対応\r
3055 //static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet)\r
3056 static int Socks4GetCmdReply(SOCKET Socket, SOCKS4REPLY *Packet, int *CancelCheckWork)\r
3057 {\r
3058         int Ret;\r
3059 \r
3060         // 同時接続対応\r
3061 //      Ret = ReadNchar(Socket, (char *)Packet, SOCKS4REPLY_SIZE, &CancelFlg);\r
3062         Ret = ReadNchar(Socket, (char *)Packet, SOCKS4REPLY_SIZE, CancelCheckWork);\r
3063 \r
3064         if(Ret != FFFTP_SUCCESS)\r
3065                 DoPrintf(MSGJPN035);\r
3066 \r
3067         return(Ret);\r
3068 }\r
3069 \r
3070 \r
3071 /*----- SOCKS5の認証を行う ----------------------------------------------------\r
3072 *\r
3073 *       Parameter\r
3074 *               SOCKET Socket : ソケット\r
3075 *\r
3076 *       Return Value\r
3077 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
3078 *----------------------------------------------------------------------------*/\r
3079 \r
3080 static int Socks5SelMethod(SOCKET Socket, int *CancelCheckWork)\r
3081 {\r
3082         int Ret;\r
3083         SOCKS5METHODREQUEST Socks5Method;\r
3084         SOCKS5METHODREPLY Socks5MethodReply;\r
3085         SOCKS5USERPASSSTATUS Socks5Status;\r
3086         char Buf[USER_NAME_LEN + PASSWORD_LEN + 4];\r
3087         int Len;\r
3088         int Len2;\r
3089 \r
3090         Ret = FFFTP_SUCCESS;\r
3091         Socks5Method.Ver = SOCKS5_VER;\r
3092         Socks5Method.Num = 1;\r
3093         if(FwallType == FWALL_SOCKS5_NOAUTH)\r
3094                 Socks5Method.Methods[0] = SOCKS5_AUTH_NONE;\r
3095         else\r
3096                 Socks5Method.Methods[0] = SOCKS5_AUTH_USER;\r
3097 \r
3098         // 同時接続対応\r
3099 //      if((SocksSendCmd(Socket, &Socks5Method, SOCKS5METHODREQUEST_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3100 //         (ReadNchar(Socket, (char *)&Socks5MethodReply, SOCKS5METHODREPLY_SIZE, &CancelFlg) != FFFTP_SUCCESS) ||\r
3101 //         (Socks5MethodReply.Method == (uchar)0xFF))\r
3102         if((SocksSendCmd(Socket, &Socks5Method, SOCKS5METHODREQUEST_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3103            (ReadNchar(Socket, (char *)&Socks5MethodReply, SOCKS5METHODREPLY_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3104            (Socks5MethodReply.Method == (uchar)0xFF))\r
3105         {\r
3106                 SetTaskMsg(MSGJPN036);\r
3107                 Ret = FFFTP_FAIL;\r
3108         }\r
3109         else if(Socks5MethodReply.Method == SOCKS5_AUTH_USER)\r
3110         {\r
3111                 DoPrintf("SOCKS5 User/Pass Authentication");\r
3112                 Buf[0] = SOCKS5_USERAUTH_VER;\r
3113                 Len = strlen(FwallUser);\r
3114                 Len2 = strlen(FwallPass);\r
3115                 Buf[1] = Len;\r
3116                 strcpy(Buf+2, FwallUser);\r
3117                 Buf[2 + Len] = Len2;\r
3118                 strcpy(Buf+3+Len, FwallPass);\r
3119 \r
3120                 // 同時接続対応\r
3121 //              if((SocksSendCmd(Socket, &Buf, Len+Len2+3, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3122 //                 (ReadNchar(Socket, (char *)&Socks5Status, SOCKS5USERPASSSTATUS_SIZE, &CancelFlg) != FFFTP_SUCCESS) ||\r
3123 //                 (Socks5Status.Status != 0))\r
3124                 if((SocksSendCmd(Socket, &Buf, Len+Len2+3, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3125                    (ReadNchar(Socket, (char *)&Socks5Status, SOCKS5USERPASSSTATUS_SIZE, CancelCheckWork) != FFFTP_SUCCESS) ||\r
3126                    (Socks5Status.Status != 0))\r
3127                 {\r
3128                         SetTaskMsg(MSGJPN037);\r
3129                         Ret = FFFTP_FAIL;\r
3130                 }\r
3131         }\r
3132         else\r
3133                 DoPrintf("SOCKS5 No Authentication");\r
3134 \r
3135         return(Ret);\r
3136 }\r
3137 \r
3138 \r
3139 /*----- SOCKSのBINDの第2リプライメッセージを受け取る -------------------------\r
3140 *\r
3141 *       Parameter\r
3142 *               SOCKET Socket : ソケット\r
3143 *               SOCKET *Data : データソケットを返すワーク\r
3144 *\r
3145 *       Return Value\r
3146 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
3147 *----------------------------------------------------------------------------*/\r
3148 \r
3149 // 同時接続対応\r
3150 //int SocksGet2ndBindReply(SOCKET Socket, SOCKET *Data)\r
3151 int SocksGet2ndBindReply(SOCKET Socket, SOCKET *Data, int *CancelCheckWork)\r
3152 {\r
3153         int Ret;\r
3154         char Buf[300];\r
3155 \r
3156         Ret = FFFTP_FAIL;\r
3157         if((AskHostFireWall() == YES) && (FwallType == FWALL_SOCKS4))\r
3158         {\r
3159                 // 同時接続対応\r
3160 //              Socks4GetCmdReply(Socket, (SOCKS4REPLY *)Buf);\r
3161                 Socks4GetCmdReply(Socket, (SOCKS4REPLY *)Buf, CancelCheckWork);\r
3162                 *Data = Socket;\r
3163                 Ret = FFFTP_SUCCESS;\r
3164         }\r
3165         else if((AskHostFireWall() == YES) &&\r
3166                         ((FwallType == FWALL_SOCKS5_NOAUTH) || (FwallType == FWALL_SOCKS5_USER)))\r
3167         {\r
3168                 // 同時接続対応\r
3169 //              Socks5GetCmdReply(Socket, (SOCKS5REPLY *)Buf);\r
3170                 Socks5GetCmdReply(Socket, (SOCKS5REPLY *)Buf, CancelCheckWork);\r
3171                 *Data = Socket;\r
3172                 Ret = FFFTP_SUCCESS;\r
3173         }\r
3174         return(Ret);\r
3175 }\r
3176 \r
3177 \r
3178 \r
3179 // 暗号化通信対応\r
3180 int AskCryptMode(void)\r
3181 {\r
3182         return(CurHost.CryptMode);\r
3183 }\r
3184 \r
3185 int AskUseNoEncryption(void)\r
3186 {\r
3187         return(CurHost.UseNoEncryption);\r
3188 }\r
3189 \r
3190 int AskUseFTPES(void)\r
3191 {\r
3192         return(CurHost.UseFTPES);\r
3193 }\r
3194 \r
3195 int AskUseFTPIS(void)\r
3196 {\r
3197         return(CurHost.UseFTPIS);\r
3198 }\r
3199 \r
3200 int AskUseSFTP(void)\r
3201 {\r
3202         return(CurHost.UseSFTP);\r
3203 }\r
3204 \r
3205 char *AskPrivateKey(void)\r
3206 {\r
3207         return(CurHost.PrivateKey);\r
3208 }\r
3209 \r
3210 // 同時接続対応\r
3211 int AskMaxThreadCount(void)\r
3212 {\r
3213         return(CurHost.MaxThreadCount);\r
3214 }\r
3215 \r
3216 int AskReuseCmdSkt(void)\r
3217 {\r
3218         return(CurHost.ReuseCmdSkt);\r
3219 }\r
3220 \r
3221 // FEAT対応\r