OSDN Git Service

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