OSDN Git Service

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