OSDN Git Service

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